Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 2 | /* drivers/rtc/rtc-v3020.c |
| 3 | * |
| 4 | * Copyright (C) 2006 8D Technologies inc. |
| 5 | * Copyright (C) 2004 Compulab Ltd. |
| 6 | * |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 7 | * Driver for the V3020 RTC |
| 8 | * |
| 9 | * Changelog: |
| 10 | * |
| 11 | * 10-May-2006: Raphael Assenat <raph@8d.com> |
| 12 | * - Converted to platform driver |
| 13 | * - Use the generic rtc class |
| 14 | * |
| 15 | * ??-???-2004: Someone at Compulab |
Sachin Kamat | de2edf3 | 2013-07-03 15:06:05 -0700 | [diff] [blame] | 16 | * - Initial driver creation. |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 17 | */ |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/rtc.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/bcd.h> |
Alexandre Belloni | cd9b518 | 2016-06-27 00:03:03 +0200 | [diff] [blame] | 24 | #include <linux/platform_data/rtc-v3020.h> |
Mike Rapoport | f3d79b2 | 2007-09-11 15:23:45 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 26 | #include <linux/gpio.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 28 | |
Mike Rapoport | c08cf9d | 2009-03-31 15:24:59 -0700 | [diff] [blame] | 29 | #include <linux/io.h> |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 30 | |
| 31 | #undef DEBUG |
| 32 | |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 33 | struct v3020; |
| 34 | |
| 35 | struct v3020_chip_ops { |
| 36 | int (*map_io)(struct v3020 *chip, struct platform_device *pdev, |
| 37 | struct v3020_platform_data *pdata); |
| 38 | void (*unmap_io)(struct v3020 *chip); |
| 39 | unsigned char (*read_bit)(struct v3020 *chip); |
| 40 | void (*write_bit)(struct v3020 *chip, unsigned char bit); |
| 41 | }; |
| 42 | |
| 43 | #define V3020_CS 0 |
| 44 | #define V3020_WR 1 |
| 45 | #define V3020_RD 2 |
| 46 | #define V3020_IO 3 |
| 47 | |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 48 | struct v3020 { |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 49 | /* MMIO access */ |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 50 | void __iomem *ioaddress; |
| 51 | int leftshift; |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 52 | |
| 53 | /* GPIO access */ |
Jingoo Han | 6c95fa8 | 2013-02-22 11:19:15 +0900 | [diff] [blame] | 54 | struct gpio *gpio; |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 55 | |
Julia Lawall | 7432a85 | 2015-12-11 18:50:50 +0100 | [diff] [blame] | 56 | const struct v3020_chip_ops *ops; |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 57 | |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 58 | struct rtc_device *rtc; |
| 59 | }; |
| 60 | |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 61 | |
| 62 | static int v3020_mmio_map(struct v3020 *chip, struct platform_device *pdev, |
| 63 | struct v3020_platform_data *pdata) |
| 64 | { |
| 65 | if (pdev->num_resources != 1) |
| 66 | return -EBUSY; |
| 67 | |
| 68 | if (pdev->resource[0].flags != IORESOURCE_MEM) |
| 69 | return -EBUSY; |
| 70 | |
| 71 | chip->leftshift = pdata->leftshift; |
| 72 | chip->ioaddress = ioremap(pdev->resource[0].start, 1); |
| 73 | if (chip->ioaddress == NULL) |
| 74 | return -EBUSY; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static void v3020_mmio_unmap(struct v3020 *chip) |
| 80 | { |
| 81 | iounmap(chip->ioaddress); |
| 82 | } |
| 83 | |
| 84 | static void v3020_mmio_write_bit(struct v3020 *chip, unsigned char bit) |
| 85 | { |
| 86 | writel(bit << chip->leftshift, chip->ioaddress); |
| 87 | } |
| 88 | |
| 89 | static unsigned char v3020_mmio_read_bit(struct v3020 *chip) |
| 90 | { |
Scott Valentine | bcb3a16 | 2009-11-11 14:26:49 -0800 | [diff] [blame] | 91 | return !!(readl(chip->ioaddress) & (1 << chip->leftshift)); |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Julia Lawall | 7432a85 | 2015-12-11 18:50:50 +0100 | [diff] [blame] | 94 | static const struct v3020_chip_ops v3020_mmio_ops = { |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 95 | .map_io = v3020_mmio_map, |
| 96 | .unmap_io = v3020_mmio_unmap, |
| 97 | .read_bit = v3020_mmio_read_bit, |
| 98 | .write_bit = v3020_mmio_write_bit, |
| 99 | }; |
| 100 | |
Jingoo Han | 6c95fa8 | 2013-02-22 11:19:15 +0900 | [diff] [blame] | 101 | static struct gpio v3020_gpio[] = { |
| 102 | { 0, GPIOF_OUT_INIT_HIGH, "RTC CS"}, |
| 103 | { 0, GPIOF_OUT_INIT_HIGH, "RTC WR"}, |
| 104 | { 0, GPIOF_OUT_INIT_HIGH, "RTC RD"}, |
| 105 | { 0, GPIOF_OUT_INIT_HIGH, "RTC IO"}, |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev, |
| 109 | struct v3020_platform_data *pdata) |
| 110 | { |
Jingoo Han | 6c95fa8 | 2013-02-22 11:19:15 +0900 | [diff] [blame] | 111 | int err; |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 112 | |
| 113 | v3020_gpio[V3020_CS].gpio = pdata->gpio_cs; |
| 114 | v3020_gpio[V3020_WR].gpio = pdata->gpio_wr; |
| 115 | v3020_gpio[V3020_RD].gpio = pdata->gpio_rd; |
| 116 | v3020_gpio[V3020_IO].gpio = pdata->gpio_io; |
| 117 | |
Jingoo Han | 6c95fa8 | 2013-02-22 11:19:15 +0900 | [diff] [blame] | 118 | err = gpio_request_array(v3020_gpio, ARRAY_SIZE(v3020_gpio)); |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 119 | |
Jingoo Han | 6c95fa8 | 2013-02-22 11:19:15 +0900 | [diff] [blame] | 120 | if (!err) |
| 121 | chip->gpio = v3020_gpio; |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 122 | |
| 123 | return err; |
| 124 | } |
| 125 | |
| 126 | static void v3020_gpio_unmap(struct v3020 *chip) |
| 127 | { |
Jingoo Han | 6c95fa8 | 2013-02-22 11:19:15 +0900 | [diff] [blame] | 128 | gpio_free_array(v3020_gpio, ARRAY_SIZE(v3020_gpio)); |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void v3020_gpio_write_bit(struct v3020 *chip, unsigned char bit) |
| 132 | { |
| 133 | gpio_direction_output(chip->gpio[V3020_IO].gpio, bit); |
| 134 | gpio_set_value(chip->gpio[V3020_CS].gpio, 0); |
| 135 | gpio_set_value(chip->gpio[V3020_WR].gpio, 0); |
| 136 | udelay(1); |
| 137 | gpio_set_value(chip->gpio[V3020_WR].gpio, 1); |
| 138 | gpio_set_value(chip->gpio[V3020_CS].gpio, 1); |
| 139 | } |
| 140 | |
| 141 | static unsigned char v3020_gpio_read_bit(struct v3020 *chip) |
| 142 | { |
| 143 | int bit; |
| 144 | |
| 145 | gpio_direction_input(chip->gpio[V3020_IO].gpio); |
| 146 | gpio_set_value(chip->gpio[V3020_CS].gpio, 0); |
| 147 | gpio_set_value(chip->gpio[V3020_RD].gpio, 0); |
| 148 | udelay(1); |
| 149 | bit = !!gpio_get_value(chip->gpio[V3020_IO].gpio); |
| 150 | udelay(1); |
| 151 | gpio_set_value(chip->gpio[V3020_RD].gpio, 1); |
| 152 | gpio_set_value(chip->gpio[V3020_CS].gpio, 1); |
| 153 | |
| 154 | return bit; |
| 155 | } |
| 156 | |
Julia Lawall | 7432a85 | 2015-12-11 18:50:50 +0100 | [diff] [blame] | 157 | static const struct v3020_chip_ops v3020_gpio_ops = { |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 158 | .map_io = v3020_gpio_map, |
| 159 | .unmap_io = v3020_gpio_unmap, |
| 160 | .read_bit = v3020_gpio_read_bit, |
| 161 | .write_bit = v3020_gpio_write_bit, |
| 162 | }; |
| 163 | |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 164 | static void v3020_set_reg(struct v3020 *chip, unsigned char address, |
| 165 | unsigned char data) |
| 166 | { |
| 167 | int i; |
| 168 | unsigned char tmp; |
| 169 | |
| 170 | tmp = address; |
| 171 | for (i = 0; i < 4; i++) { |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 172 | chip->ops->write_bit(chip, (tmp & 1)); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 173 | tmp >>= 1; |
Mike Rapoport | f3d79b2 | 2007-09-11 15:23:45 -0700 | [diff] [blame] | 174 | udelay(1); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /* Commands dont have data */ |
| 178 | if (!V3020_IS_COMMAND(address)) { |
| 179 | for (i = 0; i < 8; i++) { |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 180 | chip->ops->write_bit(chip, (data & 1)); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 181 | data >>= 1; |
Mike Rapoport | f3d79b2 | 2007-09-11 15:23:45 -0700 | [diff] [blame] | 182 | udelay(1); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address) |
| 188 | { |
Mike Rapoport | c08cf9d | 2009-03-31 15:24:59 -0700 | [diff] [blame] | 189 | unsigned int data = 0; |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 190 | int i; |
| 191 | |
| 192 | for (i = 0; i < 4; i++) { |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 193 | chip->ops->write_bit(chip, (address & 1)); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 194 | address >>= 1; |
Mike Rapoport | f3d79b2 | 2007-09-11 15:23:45 -0700 | [diff] [blame] | 195 | udelay(1); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | for (i = 0; i < 8; i++) { |
| 199 | data >>= 1; |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 200 | if (chip->ops->read_bit(chip)) |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 201 | data |= 0x80; |
Mike Rapoport | f3d79b2 | 2007-09-11 15:23:45 -0700 | [diff] [blame] | 202 | udelay(1); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | return data; |
| 206 | } |
| 207 | |
| 208 | static int v3020_read_time(struct device *dev, struct rtc_time *dt) |
| 209 | { |
| 210 | struct v3020 *chip = dev_get_drvdata(dev); |
| 211 | int tmp; |
| 212 | |
| 213 | /* Copy the current time to ram... */ |
| 214 | v3020_set_reg(chip, V3020_CMD_CLOCK2RAM, 0); |
| 215 | |
| 216 | /* ...and then read constant values. */ |
| 217 | tmp = v3020_get_reg(chip, V3020_SECONDS); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 218 | dt->tm_sec = bcd2bin(tmp); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 219 | tmp = v3020_get_reg(chip, V3020_MINUTES); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 220 | dt->tm_min = bcd2bin(tmp); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 221 | tmp = v3020_get_reg(chip, V3020_HOURS); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 222 | dt->tm_hour = bcd2bin(tmp); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 223 | tmp = v3020_get_reg(chip, V3020_MONTH_DAY); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 224 | dt->tm_mday = bcd2bin(tmp); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 225 | tmp = v3020_get_reg(chip, V3020_MONTH); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 226 | dt->tm_mon = bcd2bin(tmp) - 1; |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 227 | tmp = v3020_get_reg(chip, V3020_WEEK_DAY); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 228 | dt->tm_wday = bcd2bin(tmp); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 229 | tmp = v3020_get_reg(chip, V3020_YEAR); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 230 | dt->tm_year = bcd2bin(tmp)+100; |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 231 | |
Mike Rapoport | c08cf9d | 2009-03-31 15:24:59 -0700 | [diff] [blame] | 232 | dev_dbg(dev, "\n%s : Read RTC values\n", __func__); |
| 233 | dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); |
| 234 | dev_dbg(dev, "tm_min : %i\n", dt->tm_min); |
| 235 | dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); |
| 236 | dev_dbg(dev, "tm_year: %i\n", dt->tm_year); |
| 237 | dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon); |
| 238 | dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); |
| 239 | dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | static int v3020_set_time(struct device *dev, struct rtc_time *dt) |
| 246 | { |
| 247 | struct v3020 *chip = dev_get_drvdata(dev); |
| 248 | |
Mike Rapoport | c08cf9d | 2009-03-31 15:24:59 -0700 | [diff] [blame] | 249 | dev_dbg(dev, "\n%s : Setting RTC values\n", __func__); |
| 250 | dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); |
| 251 | dev_dbg(dev, "tm_min : %i\n", dt->tm_min); |
| 252 | dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); |
| 253 | dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); |
| 254 | dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); |
| 255 | dev_dbg(dev, "tm_year: %i\n", dt->tm_year); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 256 | |
| 257 | /* Write all the values to ram... */ |
Sachin Kamat | de2edf3 | 2013-07-03 15:06:05 -0700 | [diff] [blame] | 258 | v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); |
| 259 | v3020_set_reg(chip, V3020_MINUTES, bin2bcd(dt->tm_min)); |
| 260 | v3020_set_reg(chip, V3020_HOURS, bin2bcd(dt->tm_hour)); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 261 | v3020_set_reg(chip, V3020_MONTH_DAY, bin2bcd(dt->tm_mday)); |
Sachin Kamat | de2edf3 | 2013-07-03 15:06:05 -0700 | [diff] [blame] | 262 | v3020_set_reg(chip, V3020_MONTH, bin2bcd(dt->tm_mon + 1)); |
| 263 | v3020_set_reg(chip, V3020_WEEK_DAY, bin2bcd(dt->tm_wday)); |
| 264 | v3020_set_reg(chip, V3020_YEAR, bin2bcd(dt->tm_year % 100)); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 265 | |
| 266 | /* ...and set the clock. */ |
| 267 | v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0); |
| 268 | |
| 269 | /* Compulab used this delay here. I dont know why, |
| 270 | * the datasheet does not specify a delay. */ |
| 271 | /*mdelay(5);*/ |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
David Brownell | ff8371a | 2006-09-30 23:28:17 -0700 | [diff] [blame] | 276 | static const struct rtc_class_ops v3020_rtc_ops = { |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 277 | .read_time = v3020_read_time, |
| 278 | .set_time = v3020_set_time, |
| 279 | }; |
| 280 | |
| 281 | static int rtc_probe(struct platform_device *pdev) |
| 282 | { |
Jingoo Han | a65ddce | 2013-11-12 15:10:53 -0800 | [diff] [blame] | 283 | struct v3020_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 284 | struct v3020 *chip; |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 285 | int retval = -EBUSY; |
| 286 | int i; |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 287 | |
Jingoo Han | 431c6c1 | 2013-04-29 16:20:56 -0700 | [diff] [blame] | 288 | chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 289 | if (!chip) |
| 290 | return -ENOMEM; |
| 291 | |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 292 | if (pdata->use_gpio) |
| 293 | chip->ops = &v3020_gpio_ops; |
| 294 | else |
| 295 | chip->ops = &v3020_mmio_ops; |
| 296 | |
| 297 | retval = chip->ops->map_io(chip, pdev, pdata); |
| 298 | if (retval) |
Sachin Kamat | d8d5290 | 2013-07-03 15:05:41 -0700 | [diff] [blame] | 299 | return retval; |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 300 | |
| 301 | /* Make sure the v3020 expects a communication cycle |
| 302 | * by reading 8 times */ |
| 303 | for (i = 0; i < 8; i++) |
Alexandre Belloni | 4239749 | 2019-11-22 11:22:12 +0100 | [diff] [blame] | 304 | chip->ops->read_bit(chip); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 305 | |
| 306 | /* Test chip by doing a write/read sequence |
| 307 | * to the chip ram */ |
| 308 | v3020_set_reg(chip, V3020_SECONDS, 0x33); |
Mike Rapoport | c08cf9d | 2009-03-31 15:24:59 -0700 | [diff] [blame] | 309 | if (v3020_get_reg(chip, V3020_SECONDS) != 0x33) { |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 310 | retval = -ENODEV; |
| 311 | goto err_io; |
| 312 | } |
| 313 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 314 | /* Make sure frequency measurement mode, test modes, and lock |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 315 | * are all disabled */ |
| 316 | v3020_set_reg(chip, V3020_STATUS_0, 0x0); |
| 317 | |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 318 | if (pdata->use_gpio) |
| 319 | dev_info(&pdev->dev, "Chip available at GPIOs " |
| 320 | "%d, %d, %d, %d\n", |
| 321 | chip->gpio[V3020_CS].gpio, chip->gpio[V3020_WR].gpio, |
| 322 | chip->gpio[V3020_RD].gpio, chip->gpio[V3020_IO].gpio); |
| 323 | else |
| 324 | dev_info(&pdev->dev, "Chip available at " |
| 325 | "physical address 0x%llx," |
| 326 | "data connected to D%d\n", |
| 327 | (unsigned long long)pdev->resource[0].start, |
| 328 | chip->leftshift); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 329 | |
| 330 | platform_set_drvdata(pdev, chip); |
| 331 | |
Jingoo Han | 431c6c1 | 2013-04-29 16:20:56 -0700 | [diff] [blame] | 332 | chip->rtc = devm_rtc_device_register(&pdev->dev, "v3020", |
| 333 | &v3020_rtc_ops, THIS_MODULE); |
Alessandro Zummo | b74d2ca | 2009-12-15 16:45:53 -0800 | [diff] [blame] | 334 | if (IS_ERR(chip->rtc)) { |
| 335 | retval = PTR_ERR(chip->rtc); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 336 | goto err_io; |
| 337 | } |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 338 | |
| 339 | return 0; |
| 340 | |
| 341 | err_io: |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 342 | chip->ops->unmap_io(chip); |
Sachin Kamat | d8d5290 | 2013-07-03 15:05:41 -0700 | [diff] [blame] | 343 | |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 344 | return retval; |
| 345 | } |
| 346 | |
| 347 | static int rtc_remove(struct platform_device *dev) |
| 348 | { |
| 349 | struct v3020 *chip = platform_get_drvdata(dev); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 350 | |
Mike Rapoport | 9661584 | 2009-04-02 16:57:01 -0700 | [diff] [blame] | 351 | chip->ops->unmap_io(chip); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static struct platform_driver rtc_device_driver = { |
| 357 | .probe = rtc_probe, |
| 358 | .remove = rtc_remove, |
| 359 | .driver = { |
| 360 | .name = "v3020", |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 361 | }, |
| 362 | }; |
| 363 | |
Axel Lin | 0c4eae6 | 2012-01-10 15:10:48 -0800 | [diff] [blame] | 364 | module_platform_driver(rtc_device_driver); |
Raphael Assenat | 362600f | 2006-06-25 05:48:24 -0700 | [diff] [blame] | 365 | |
| 366 | MODULE_DESCRIPTION("V3020 RTC"); |
| 367 | MODULE_AUTHOR("Raphael Assenat"); |
| 368 | MODULE_LICENSE("GPL"); |
Kay Sievers | ad28a07 | 2008-04-10 21:29:25 -0700 | [diff] [blame] | 369 | MODULE_ALIAS("platform:v3020"); |