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