aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig5
-rw-r--r--drivers/rtc/rtc-at91rm9200.c12
-rw-r--r--drivers/rtc/rtc-at91sam9.c2
-rw-r--r--drivers/rtc/rtc-bfin.c2
-rw-r--r--drivers/rtc/rtc-cmos.c7
-rw-r--r--drivers/rtc/rtc-ds1302.c2
-rw-r--r--drivers/rtc/rtc-ds1307.c66
-rw-r--r--drivers/rtc/rtc-ds1374.c10
-rw-r--r--drivers/rtc/rtc-ds1511.c6
-rw-r--r--drivers/rtc/rtc-ds1672.c14
-rw-r--r--drivers/rtc/rtc-isl1208.c364
-rw-r--r--drivers/rtc/rtc-m41t80.c81
-rw-r--r--drivers/rtc/rtc-max6900.c6
-rw-r--r--drivers/rtc/rtc-max6902.c4
-rw-r--r--drivers/rtc/rtc-pcf8563.c134
-rw-r--r--drivers/rtc/rtc-pcf8583.c2
-rw-r--r--drivers/rtc/rtc-proc.c8
-rw-r--r--drivers/rtc/rtc-rs5c313.c4
-rw-r--r--drivers/rtc/rtc-rs5c372.c45
-rw-r--r--drivers/rtc/rtc-s35390a.c10
-rw-r--r--drivers/rtc/rtc-s3c.c6
-rw-r--r--drivers/rtc/rtc-sh.c298
-rw-r--r--drivers/rtc/rtc-sysfs.c12
-rw-r--r--drivers/rtc/rtc-test.c8
-rw-r--r--drivers/rtc/rtc-v3020.c4
-rw-r--r--drivers/rtc/rtc-x1205.c178
26 files changed, 627 insertions, 663 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 02a4c8cf2b2d..6cc2c0330230 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -20,10 +20,6 @@ menuconfig RTC_CLASS
20 20
21if RTC_CLASS 21if RTC_CLASS
22 22
23if GEN_RTC || RTC
24comment "Conflicting RTC option has been selected, check GEN_RTC and RTC"
25endif
26
27config RTC_HCTOSYS 23config RTC_HCTOSYS
28 bool "Set system time from RTC on startup and resume" 24 bool "Set system time from RTC on startup and resume"
29 depends on RTC_CLASS = y 25 depends on RTC_CLASS = y
@@ -304,6 +300,7 @@ comment "Platform RTC drivers"
304config RTC_DRV_CMOS 300config RTC_DRV_CMOS
305 tristate "PC-style 'CMOS'" 301 tristate "PC-style 'CMOS'"
306 depends on X86 || ALPHA || ARM || M32R || ATARI || PPC || MIPS 302 depends on X86 || ALPHA || ARM || M32R || ATARI || PPC || MIPS
303 default y if X86
307 help 304 help
308 Say "yes" here to get direct support for the real time clock 305 Say "yes" here to get direct support for the real time clock
309 found in every PC or ACPI-based system, and some other boards. 306 found in every PC or ACPI-based system, and some other boards.
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 52abffc86bcd..39e64ab1ecb7 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -83,7 +83,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
83 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 83 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
84 tm->tm_year = tm->tm_year - 1900; 84 tm->tm_year = tm->tm_year - 1900;
85 85
86 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 86 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
87 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 87 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
88 tm->tm_hour, tm->tm_min, tm->tm_sec); 88 tm->tm_hour, tm->tm_min, tm->tm_sec);
89 89
@@ -97,7 +97,7 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
97{ 97{
98 unsigned long cr; 98 unsigned long cr;
99 99
100 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 100 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
101 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 101 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
102 tm->tm_hour, tm->tm_min, tm->tm_sec); 102 tm->tm_hour, tm->tm_min, tm->tm_sec);
103 103
@@ -142,7 +142,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
142 alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM) 142 alrm->enabled = (at91_sys_read(AT91_RTC_IMR) & AT91_RTC_ALARM)
143 ? 1 : 0; 143 ? 1 : 0;
144 144
145 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 145 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
146 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 146 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
147 tm->tm_hour, tm->tm_min, tm->tm_sec); 147 tm->tm_hour, tm->tm_min, tm->tm_sec);
148 148
@@ -178,7 +178,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
178 if (alrm->enabled) 178 if (alrm->enabled)
179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM); 179 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
180 180
181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__, 181 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 182 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
183 tm.tm_min, tm.tm_sec); 183 tm.tm_min, tm.tm_sec);
184 184
@@ -193,7 +193,7 @@ static int at91_rtc_ioctl(struct device *dev, unsigned int cmd,
193{ 193{
194 int ret = 0; 194 int ret = 0;
195 195
196 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __FUNCTION__, cmd, arg); 196 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __func__, cmd, arg);
197 197
198 switch (cmd) { 198 switch (cmd) {
199 case RTC_AIE_OFF: /* alarm off */ 199 case RTC_AIE_OFF: /* alarm off */
@@ -265,7 +265,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
265 265
266 rtc_update_irq(rtc, 1, events); 266 rtc_update_irq(rtc, 1, events);
267 267
268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__, 268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __func__,
269 events >> 8, events & 0x000000FF); 269 events >> 8, events & 0x000000FF);
270 270
271 return IRQ_HANDLED; 271 return IRQ_HANDLED;
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 56728a2a3385..38d8742a4bdf 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -288,7 +288,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *_rtc)
288 288
289 rtc_update_irq(rtc->rtcdev, 1, events); 289 rtc_update_irq(rtc->rtcdev, 1, events);
290 290
291 pr_debug("%s: num=%ld, events=0x%02lx\n", __FUNCTION__, 291 pr_debug("%s: num=%ld, events=0x%02lx\n", __func__,
292 events >> 8, events & 0x000000FF); 292 events >> 8, events & 0x000000FF);
293 293
294 return IRQ_HANDLED; 294 return IRQ_HANDLED;
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index 4f28045d9ef2..8624f55d0560 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -419,7 +419,7 @@ static int __devinit bfin_rtc_probe(struct platform_device *pdev)
419 return -ENOMEM; 419 return -ENOMEM;
420 420
421 rtc->rtc_dev = rtc_device_register(pdev->name, &pdev->dev, &bfin_rtc_ops, THIS_MODULE); 421 rtc->rtc_dev = rtc_device_register(pdev->name, &pdev->dev, &bfin_rtc_ops, THIS_MODULE);
422 if (unlikely(IS_ERR(rtc))) { 422 if (IS_ERR(rtc)) {
423 ret = PTR_ERR(rtc->rtc_dev); 423 ret = PTR_ERR(rtc->rtc_dev);
424 goto err; 424 goto err;
425 } 425 }
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index dcdc142a3441..d060a06ce05b 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -854,11 +854,12 @@ cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
854 * don't define the IRQ. It should always be safe to 854 * don't define the IRQ. It should always be safe to
855 * hardcode it in these cases 855 * hardcode it in these cases
856 */ 856 */
857 return cmos_do_probe(&pnp->dev, &pnp->res.port_resource[0], 8); 857 return cmos_do_probe(&pnp->dev,
858 pnp_get_resource(pnp, IORESOURCE_IO, 0), 8);
858 else 859 else
859 return cmos_do_probe(&pnp->dev, 860 return cmos_do_probe(&pnp->dev,
860 &pnp->res.port_resource[0], 861 pnp_get_resource(pnp, IORESOURCE_IO, 0),
861 pnp->res.irq_resource[0].start); 862 pnp_irq(pnp, 0));
862} 863}
863 864
864static void __exit cmos_pnp_remove(struct pnp_dev *pnp) 865static void __exit cmos_pnp_remove(struct pnp_dev *pnp)
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index 7b002ceeaa7d..b9397818f73a 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -122,7 +122,7 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
122 122
123 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 123 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
124 "mday=%d, mon=%d, year=%d, wday=%d\n", 124 "mday=%d, mon=%d, year=%d, wday=%d\n",
125 __FUNCTION__, 125 __func__,
126 tm->tm_sec, tm->tm_min, tm->tm_hour, 126 tm->tm_sec, tm->tm_min, tm->tm_hour,
127 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); 127 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
128 128
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index f389a28720d2..bbf97e65202a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -99,45 +99,38 @@ struct ds1307 {
99}; 99};
100 100
101struct chip_desc { 101struct chip_desc {
102 char name[9];
103 unsigned nvram56:1; 102 unsigned nvram56:1;
104 unsigned alarm:1; 103 unsigned alarm:1;
105 enum ds_type type;
106}; 104};
107 105
108static const struct chip_desc chips[] = { { 106static const struct chip_desc chips[] = {
109 .name = "ds1307", 107[ds_1307] = {
110 .type = ds_1307,
111 .nvram56 = 1, 108 .nvram56 = 1,
112}, { 109},
113 .name = "ds1337", 110[ds_1337] = {
114 .type = ds_1337,
115 .alarm = 1, 111 .alarm = 1,
116}, { 112},
117 .name = "ds1338", 113[ds_1338] = {
118 .type = ds_1338,
119 .nvram56 = 1, 114 .nvram56 = 1,
120}, { 115},
121 .name = "ds1339", 116[ds_1339] = {
122 .type = ds_1339,
123 .alarm = 1, 117 .alarm = 1,
124}, { 118},
125 .name = "ds1340", 119[ds_1340] = {
126 .type = ds_1340, 120},
127}, { 121[m41t00] = {
128 .name = "m41t00",
129 .type = m41t00,
130}, }; 122}, };
131 123
132static inline const struct chip_desc *find_chip(const char *s) 124static const struct i2c_device_id ds1307_id[] = {
133{ 125 { "ds1307", ds_1307 },
134 unsigned i; 126 { "ds1337", ds_1337 },
135 127 { "ds1338", ds_1338 },
136 for (i = 0; i < ARRAY_SIZE(chips); i++) 128 { "ds1339", ds_1339 },
137 if (strnicmp(s, chips[i].name, sizeof chips[i].name) == 0) 129 { "ds1340", ds_1340 },
138 return &chips[i]; 130 { "m41t00", m41t00 },
139 return NULL; 131 { }
140} 132};
133MODULE_DEVICE_TABLE(i2c, ds1307_id);
141 134
142static int ds1307_get_time(struct device *dev, struct rtc_time *t) 135static int ds1307_get_time(struct device *dev, struct rtc_time *t)
143{ 136{
@@ -326,21 +319,15 @@ static struct bin_attribute nvram = {
326 319
327static struct i2c_driver ds1307_driver; 320static struct i2c_driver ds1307_driver;
328 321
329static int __devinit ds1307_probe(struct i2c_client *client) 322static int __devinit ds1307_probe(struct i2c_client *client,
323 const struct i2c_device_id *id)
330{ 324{
331 struct ds1307 *ds1307; 325 struct ds1307 *ds1307;
332 int err = -ENODEV; 326 int err = -ENODEV;
333 int tmp; 327 int tmp;
334 const struct chip_desc *chip; 328 const struct chip_desc *chip = &chips[id->driver_data];
335 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 329 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
336 330
337 chip = find_chip(client->name);
338 if (!chip) {
339 dev_err(&client->dev, "unknown chip type '%s'\n",
340 client->name);
341 return -ENODEV;
342 }
343
344 if (!i2c_check_functionality(adapter, 331 if (!i2c_check_functionality(adapter,
345 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 332 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
346 return -EIO; 333 return -EIO;
@@ -361,7 +348,7 @@ static int __devinit ds1307_probe(struct i2c_client *client)
361 ds1307->msg[1].len = sizeof(ds1307->regs); 348 ds1307->msg[1].len = sizeof(ds1307->regs);
362 ds1307->msg[1].buf = ds1307->regs; 349 ds1307->msg[1].buf = ds1307->regs;
363 350
364 ds1307->type = chip->type; 351 ds1307->type = id->driver_data;
365 352
366 switch (ds1307->type) { 353 switch (ds1307->type) {
367 case ds_1337: 354 case ds_1337:
@@ -550,6 +537,7 @@ static struct i2c_driver ds1307_driver = {
550 }, 537 },
551 .probe = ds1307_probe, 538 .probe = ds1307_probe,
552 .remove = __devexit_p(ds1307_remove), 539 .remove = __devexit_p(ds1307_remove),
540 .id_table = ds1307_id,
553}; 541};
554 542
555static int __init ds1307_init(void) 543static int __init ds1307_init(void)
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 45bda186befc..fa2d2f8b3f4d 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -41,6 +41,12 @@
41#define DS1374_REG_SR_AF 0x01 /* Alarm Flag */ 41#define DS1374_REG_SR_AF 0x01 /* Alarm Flag */
42#define DS1374_REG_TCR 0x09 /* Trickle Charge */ 42#define DS1374_REG_TCR 0x09 /* Trickle Charge */
43 43
44static const struct i2c_device_id ds1374_id[] = {
45 { "rtc-ds1374", 0 },
46 { }
47};
48MODULE_DEVICE_TABLE(i2c, ds1374_id);
49
44struct ds1374 { 50struct ds1374 {
45 struct i2c_client *client; 51 struct i2c_client *client;
46 struct rtc_device *rtc; 52 struct rtc_device *rtc;
@@ -355,7 +361,8 @@ static const struct rtc_class_ops ds1374_rtc_ops = {
355 .ioctl = ds1374_ioctl, 361 .ioctl = ds1374_ioctl,
356}; 362};
357 363
358static int ds1374_probe(struct i2c_client *client) 364static int ds1374_probe(struct i2c_client *client,
365 const struct i2c_device_id *id)
359{ 366{
360 struct ds1374 *ds1374; 367 struct ds1374 *ds1374;
361 int ret; 368 int ret;
@@ -429,6 +436,7 @@ static struct i2c_driver ds1374_driver = {
429 }, 436 },
430 .probe = ds1374_probe, 437 .probe = ds1374_probe,
431 .remove = __devexit_p(ds1374_remove), 438 .remove = __devexit_p(ds1374_remove),
439 .id_table = ds1374_id,
432}; 440};
433 441
434static int __init ds1374_init(void) 442static int __init ds1374_init(void)
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index d08912f18ddd..a83a40b3ebaa 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -181,8 +181,7 @@ ds1511_wdog_disable(void)
181 * stupidly, some callers call with year unmolested; 181 * stupidly, some callers call with year unmolested;
182 * and some call with year = year - 1900. thanks. 182 * and some call with year = year - 1900. thanks.
183 */ 183 */
184 int 184static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
185ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
186{ 185{
187 u8 mon, day, dow, hrs, min, sec, yrs, cen; 186 u8 mon, day, dow, hrs, min, sec, yrs, cen;
188 unsigned int flags; 187 unsigned int flags;
@@ -245,8 +244,7 @@ ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
245 return 0; 244 return 0;
246} 245}
247 246
248 int 247static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
249ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
250{ 248{
251 unsigned int century; 249 unsigned int century;
252 unsigned int flags; 250 unsigned int flags;
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index e0900ca678ec..6fa4556f5f5c 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -50,13 +50,13 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
50 50
51 /* read date registers */ 51 /* read date registers */
52 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 52 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
53 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 53 dev_err(&client->dev, "%s: read error\n", __func__);
54 return -EIO; 54 return -EIO;
55 } 55 }
56 56
57 dev_dbg(&client->dev, 57 dev_dbg(&client->dev,
58 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n", 58 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n",
59 __FUNCTION__, buf[0], buf[1], buf[2], buf[3]); 59 __func__, buf[0], buf[1], buf[2], buf[3]);
60 60
61 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; 61 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
62 62
@@ -64,7 +64,7 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
64 64
65 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 65 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
66 "mday=%d, mon=%d, year=%d, wday=%d\n", 66 "mday=%d, mon=%d, year=%d, wday=%d\n",
67 __FUNCTION__, tm->tm_sec, tm->tm_min, tm->tm_hour, 67 __func__, tm->tm_sec, tm->tm_min, tm->tm_hour,
68 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 68 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
69 69
70 return 0; 70 return 0;
@@ -84,7 +84,7 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
84 84
85 xfer = i2c_master_send(client, buf, 6); 85 xfer = i2c_master_send(client, buf, 6);
86 if (xfer != 6) { 86 if (xfer != 6) {
87 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer); 87 dev_err(&client->dev, "%s: send: %d\n", __func__, xfer);
88 return -EIO; 88 return -EIO;
89 } 89 }
90 90
@@ -98,7 +98,7 @@ static int ds1672_set_datetime(struct i2c_client *client, struct rtc_time *tm)
98 dev_dbg(&client->dev, 98 dev_dbg(&client->dev,
99 "%s: secs=%d, mins=%d, hours=%d, " 99 "%s: secs=%d, mins=%d, hours=%d, "
100 "mday=%d, mon=%d, year=%d, wday=%d\n", 100 "mday=%d, mon=%d, year=%d, wday=%d\n",
101 __FUNCTION__, 101 __func__,
102 tm->tm_sec, tm->tm_min, tm->tm_hour, 102 tm->tm_sec, tm->tm_min, tm->tm_hour,
103 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 103 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
104 104
@@ -133,7 +133,7 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
133 133
134 /* read control register */ 134 /* read control register */
135 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 135 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
136 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 136 dev_err(&client->dev, "%s: read error\n", __func__);
137 return -EIO; 137 return -EIO;
138 } 138 }
139 139
@@ -199,7 +199,7 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
199 struct i2c_client *client; 199 struct i2c_client *client;
200 struct rtc_device *rtc; 200 struct rtc_device *rtc;
201 201
202 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 202 dev_dbg(&adapter->dev, "%s\n", __func__);
203 203
204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
205 err = -ENODEV; 205 err = -ENODEV;
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index 725b0c73c333..fbb90b1e4098 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -15,16 +15,15 @@
15#include <linux/bcd.h> 15#include <linux/bcd.h>
16#include <linux/rtc.h> 16#include <linux/rtc.h>
17 17
18#define DRV_NAME "isl1208" 18#define DRV_VERSION "0.3"
19#define DRV_VERSION "0.2"
20 19
21/* Register map */ 20/* Register map */
22/* rtc section */ 21/* rtc section */
23#define ISL1208_REG_SC 0x00 22#define ISL1208_REG_SC 0x00
24#define ISL1208_REG_MN 0x01 23#define ISL1208_REG_MN 0x01
25#define ISL1208_REG_HR 0x02 24#define ISL1208_REG_HR 0x02
26#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */ 25#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */
27#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */ 26#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
28#define ISL1208_REG_DT 0x03 27#define ISL1208_REG_DT 0x03
29#define ISL1208_REG_MO 0x04 28#define ISL1208_REG_MO 0x04
30#define ISL1208_REG_YR 0x05 29#define ISL1208_REG_YR 0x05
@@ -33,14 +32,14 @@
33 32
34/* control/status section */ 33/* control/status section */
35#define ISL1208_REG_SR 0x07 34#define ISL1208_REG_SR 0x07
36#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */ 35#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */
37#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */ 36#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */
38#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */ 37#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */
39#define ISL1208_REG_SR_ALM (1<<2) /* alarm */ 38#define ISL1208_REG_SR_ALM (1<<2) /* alarm */
40#define ISL1208_REG_SR_BAT (1<<1) /* battery */ 39#define ISL1208_REG_SR_BAT (1<<1) /* battery */
41#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */ 40#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */
42#define ISL1208_REG_INT 0x08 41#define ISL1208_REG_INT 0x08
43#define ISL1208_REG_09 0x09 /* reserved */ 42#define ISL1208_REG_09 0x09 /* reserved */
44#define ISL1208_REG_ATR 0x0a 43#define ISL1208_REG_ATR 0x0a
45#define ISL1208_REG_DTR 0x0b 44#define ISL1208_REG_DTR 0x0b
46 45
@@ -58,39 +57,21 @@
58#define ISL1208_REG_USR2 0x13 57#define ISL1208_REG_USR2 0x13
59#define ISL1208_USR_SECTION_LEN 2 58#define ISL1208_USR_SECTION_LEN 2
60 59
61/* i2c configuration */ 60static struct i2c_driver isl1208_driver;
62#define ISL1208_I2C_ADDR 0xde
63
64static const unsigned short normal_i2c[] = {
65 ISL1208_I2C_ADDR>>1, I2C_CLIENT_END
66};
67I2C_CLIENT_INSMOD; /* defines addr_data */
68
69static int isl1208_attach_adapter(struct i2c_adapter *adapter);
70static int isl1208_detach_client(struct i2c_client *client);
71
72static struct i2c_driver isl1208_driver = {
73 .driver = {
74 .name = DRV_NAME,
75 },
76 .id = I2C_DRIVERID_ISL1208,
77 .attach_adapter = &isl1208_attach_adapter,
78 .detach_client = &isl1208_detach_client,
79};
80 61
81/* block read */ 62/* block read */
82static int 63static int
83isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], 64isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
84 unsigned len) 65 unsigned len)
85{ 66{
86 u8 reg_addr[1] = { reg }; 67 u8 reg_addr[1] = { reg };
87 struct i2c_msg msgs[2] = { 68 struct i2c_msg msgs[2] = {
88 { client->addr, client->flags, sizeof(reg_addr), reg_addr }, 69 {client->addr, 0, sizeof(reg_addr), reg_addr}
89 { client->addr, client->flags | I2C_M_RD, len, buf } 70 ,
71 {client->addr, I2C_M_RD, len, buf}
90 }; 72 };
91 int ret; 73 int ret;
92 74
93 BUG_ON(len == 0);
94 BUG_ON(reg > ISL1208_REG_USR2); 75 BUG_ON(reg > ISL1208_REG_USR2);
95 BUG_ON(reg + len > ISL1208_REG_USR2 + 1); 76 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
96 77
@@ -103,15 +84,14 @@ isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
103/* block write */ 84/* block write */
104static int 85static int
105isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], 86isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
106 unsigned len) 87 unsigned len)
107{ 88{
108 u8 i2c_buf[ISL1208_REG_USR2 + 2]; 89 u8 i2c_buf[ISL1208_REG_USR2 + 2];
109 struct i2c_msg msgs[1] = { 90 struct i2c_msg msgs[1] = {
110 { client->addr, client->flags, len + 1, i2c_buf } 91 {client->addr, 0, len + 1, i2c_buf}
111 }; 92 };
112 int ret; 93 int ret;
113 94
114 BUG_ON(len == 0);
115 BUG_ON(reg > ISL1208_REG_USR2); 95 BUG_ON(reg > ISL1208_REG_USR2);
116 BUG_ON(reg + len > ISL1208_REG_USR2 + 1); 96 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
117 97
@@ -125,7 +105,8 @@ isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
125} 105}
126 106
127/* simple check to see wether we have a isl1208 */ 107/* simple check to see wether we have a isl1208 */
128static int isl1208_i2c_validate_client(struct i2c_client *client) 108static int
109isl1208_i2c_validate_client(struct i2c_client *client)
129{ 110{
130 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 111 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
131 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = { 112 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
@@ -139,24 +120,29 @@ static int isl1208_i2c_validate_client(struct i2c_client *client)
139 return ret; 120 return ret;
140 121
141 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) { 122 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
142 if (regs[i] & zero_mask[i]) /* check if bits are cleared */ 123 if (regs[i] & zero_mask[i]) /* check if bits are cleared */
143 return -ENODEV; 124 return -ENODEV;
144 } 125 }
145 126
146 return 0; 127 return 0;
147} 128}
148 129
149static int isl1208_i2c_get_sr(struct i2c_client *client) 130static int
131isl1208_i2c_get_sr(struct i2c_client *client)
150{ 132{
151 return i2c_smbus_read_byte_data(client, ISL1208_REG_SR) == -1 ? -EIO:0; 133 int sr = i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
134 if (sr < 0)
135 return -EIO;
136
137 return sr;
152} 138}
153 139
154static int isl1208_i2c_get_atr(struct i2c_client *client) 140static int
141isl1208_i2c_get_atr(struct i2c_client *client)
155{ 142{
156 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR); 143 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
157
158 if (atr < 0) 144 if (atr < 0)
159 return -EIO; 145 return atr;
160 146
161 /* The 6bit value in the ATR register controls the load 147 /* The 6bit value in the ATR register controls the load
162 * capacitance C_load * in steps of 0.25pF 148 * capacitance C_load * in steps of 0.25pF
@@ -169,51 +155,54 @@ static int isl1208_i2c_get_atr(struct i2c_client *client)
169 * 155 *
170 */ 156 */
171 157
172 atr &= 0x3f; /* mask out lsb */ 158 atr &= 0x3f; /* mask out lsb */
173 atr ^= 1<<5; /* invert 6th bit */ 159 atr ^= 1 << 5; /* invert 6th bit */
174 atr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */ 160 atr += 2 * 9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
175 161
176 return atr; 162 return atr;
177} 163}
178 164
179static int isl1208_i2c_get_dtr(struct i2c_client *client) 165static int
166isl1208_i2c_get_dtr(struct i2c_client *client)
180{ 167{
181 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR); 168 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
182
183 if (dtr < 0) 169 if (dtr < 0)
184 return -EIO; 170 return -EIO;
185 171
186 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */ 172 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
187 dtr = ((dtr & 0x3) * 20) * (dtr & (1<<2) ? -1 : 1); 173 dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
188 174
189 return dtr; 175 return dtr;
190} 176}
191 177
192static int isl1208_i2c_get_usr(struct i2c_client *client) 178static int
179isl1208_i2c_get_usr(struct i2c_client *client)
193{ 180{
194 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, }; 181 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
195 int ret; 182 int ret;
196 183
197 ret = isl1208_i2c_read_regs (client, ISL1208_REG_USR1, buf, 184 ret = isl1208_i2c_read_regs(client, ISL1208_REG_USR1, buf,
198 ISL1208_USR_SECTION_LEN); 185 ISL1208_USR_SECTION_LEN);
199 if (ret < 0) 186 if (ret < 0)
200 return ret; 187 return ret;
201 188
202 return (buf[1] << 8) | buf[0]; 189 return (buf[1] << 8) | buf[0];
203} 190}
204 191
205static int isl1208_i2c_set_usr(struct i2c_client *client, u16 usr) 192static int
193isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
206{ 194{
207 u8 buf[ISL1208_USR_SECTION_LEN]; 195 u8 buf[ISL1208_USR_SECTION_LEN];
208 196
209 buf[0] = usr & 0xff; 197 buf[0] = usr & 0xff;
210 buf[1] = (usr >> 8) & 0xff; 198 buf[1] = (usr >> 8) & 0xff;
211 199
212 return isl1208_i2c_set_regs (client, ISL1208_REG_USR1, buf, 200 return isl1208_i2c_set_regs(client, ISL1208_REG_USR1, buf,
213 ISL1208_USR_SECTION_LEN); 201 ISL1208_USR_SECTION_LEN);
214} 202}
215 203
216static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq) 204static int
205isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
217{ 206{
218 struct i2c_client *const client = to_i2c_client(dev); 207 struct i2c_client *const client = to_i2c_client(dev);
219 int sr, dtr, atr, usr; 208 int sr, dtr, atr, usr;
@@ -230,20 +219,19 @@ static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
230 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "", 219 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
231 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "", 220 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
232 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "", 221 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
233 (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", 222 (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", sr);
234 sr);
235 223
236 seq_printf(seq, "batt_status\t: %s\n", 224 seq_printf(seq, "batt_status\t: %s\n",
237 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay"); 225 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
238 226
239 dtr = isl1208_i2c_get_dtr(client); 227 dtr = isl1208_i2c_get_dtr(client);
240 if (dtr >= 0 -1) 228 if (dtr >= 0 - 1)
241 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr); 229 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr);
242 230
243 atr = isl1208_i2c_get_atr(client); 231 atr = isl1208_i2c_get_atr(client);
244 if (atr >= 0) 232 if (atr >= 0)
245 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n", 233 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
246 atr>>2, (atr&0x3)*25); 234 atr >> 2, (atr & 0x3) * 25);
247 235
248 usr = isl1208_i2c_get_usr(client); 236 usr = isl1208_i2c_get_usr(client);
249 if (usr >= 0) 237 if (usr >= 0)
@@ -252,9 +240,8 @@ static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
252 return 0; 240 return 0;
253} 241}
254 242
255 243static int
256static int isl1208_i2c_read_time(struct i2c_client *client, 244isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
257 struct rtc_time *tm)
258{ 245{
259 int sr; 246 int sr;
260 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 247 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
@@ -274,27 +261,30 @@ static int isl1208_i2c_read_time(struct i2c_client *client,
274 261
275 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]); 262 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]);
276 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]); 263 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]);
277 { /* HR field has a more complex interpretation */ 264
265 /* HR field has a more complex interpretation */
266 {
278 const u8 _hr = regs[ISL1208_REG_HR]; 267 const u8 _hr = regs[ISL1208_REG_HR];
279 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */ 268 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
280 tm->tm_hour = BCD2BIN(_hr & 0x3f); 269 tm->tm_hour = BCD2BIN(_hr & 0x3f);
281 else { // 12h format 270 else {
271 /* 12h format */
282 tm->tm_hour = BCD2BIN(_hr & 0x1f); 272 tm->tm_hour = BCD2BIN(_hr & 0x1f);
283 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */ 273 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
284 tm->tm_hour += 12; 274 tm->tm_hour += 12;
285 } 275 }
286 } 276 }
287 277
288 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]); 278 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]);
289 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */ 279 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
290 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100; 280 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100;
291 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]); 281 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]);
292 282
293 return 0; 283 return 0;
294} 284}
295 285
296static int isl1208_i2c_read_alarm(struct i2c_client *client, 286static int
297 struct rtc_wkalrm *alarm) 287isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
298{ 288{
299 struct rtc_time *const tm = &alarm->time; 289 struct rtc_time *const tm = &alarm->time;
300 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, }; 290 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
@@ -307,7 +297,7 @@ static int isl1208_i2c_read_alarm(struct i2c_client *client,
307 } 297 }
308 298
309 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs, 299 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
310 ISL1208_ALARM_SECTION_LEN); 300 ISL1208_ALARM_SECTION_LEN);
311 if (sr < 0) { 301 if (sr < 0) {
312 dev_err(&client->dev, "%s: reading alarm section failed\n", 302 dev_err(&client->dev, "%s: reading alarm section failed\n",
313 __func__); 303 __func__);
@@ -315,23 +305,25 @@ static int isl1208_i2c_read_alarm(struct i2c_client *client,
315 } 305 }
316 306
317 /* MSB of each alarm register is an enable bit */ 307 /* MSB of each alarm register is an enable bit */
318 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA-ISL1208_REG_SCA] & 0x7f); 308 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
319 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA-ISL1208_REG_SCA] & 0x7f); 309 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
320 tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA-ISL1208_REG_SCA] & 0x3f); 310 tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
321 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA-ISL1208_REG_SCA] & 0x3f); 311 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
322 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MOA-ISL1208_REG_SCA] & 0x1f)-1; 312 tm->tm_mon =
323 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA-ISL1208_REG_SCA] & 0x03); 313 BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
314 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
324 315
325 return 0; 316 return 0;
326} 317}
327 318
328static int isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm) 319static int
320isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
329{ 321{
330 return isl1208_i2c_read_time(to_i2c_client(dev), tm); 322 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
331} 323}
332 324
333static int isl1208_i2c_set_time(struct i2c_client *client, 325static int
334 struct rtc_time const *tm) 326isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
335{ 327{
336 int sr; 328 int sr;
337 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 329 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
@@ -353,7 +345,7 @@ static int isl1208_i2c_set_time(struct i2c_client *client,
353 } 345 }
354 346
355 /* set WRTC */ 347 /* set WRTC */
356 sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR, 348 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
357 sr | ISL1208_REG_SR_WRTC); 349 sr | ISL1208_REG_SR_WRTC);
358 if (sr < 0) { 350 if (sr < 0) {
359 dev_err(&client->dev, "%s: writing SR failed\n", __func__); 351 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
@@ -369,7 +361,7 @@ static int isl1208_i2c_set_time(struct i2c_client *client,
369 } 361 }
370 362
371 /* clear WRTC again */ 363 /* clear WRTC again */
372 sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR, 364 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
373 sr & ~ISL1208_REG_SR_WRTC); 365 sr & ~ISL1208_REG_SR_WRTC);
374 if (sr < 0) { 366 if (sr < 0) {
375 dev_err(&client->dev, "%s: writing SR failed\n", __func__); 367 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
@@ -380,70 +372,69 @@ static int isl1208_i2c_set_time(struct i2c_client *client,
380} 372}
381 373
382 374
383static int isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm) 375static int
376isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
384{ 377{
385 return isl1208_i2c_set_time(to_i2c_client(dev), tm); 378 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
386} 379}
387 380
388static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 381static int
382isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
389{ 383{
390 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm); 384 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
391} 385}
392 386
393static const struct rtc_class_ops isl1208_rtc_ops = { 387static const struct rtc_class_ops isl1208_rtc_ops = {
394 .proc = isl1208_rtc_proc, 388 .proc = isl1208_rtc_proc,
395 .read_time = isl1208_rtc_read_time, 389 .read_time = isl1208_rtc_read_time,
396 .set_time = isl1208_rtc_set_time, 390 .set_time = isl1208_rtc_set_time,
397 .read_alarm = isl1208_rtc_read_alarm, 391 .read_alarm = isl1208_rtc_read_alarm,
398 //.set_alarm = isl1208_rtc_set_alarm, 392 /*.set_alarm = isl1208_rtc_set_alarm, */
399}; 393};
400 394
401/* sysfs interface */ 395/* sysfs interface */
402 396
403static ssize_t isl1208_sysfs_show_atrim(struct device *dev, 397static ssize_t
404 struct device_attribute *attr, 398isl1208_sysfs_show_atrim(struct device *dev,
405 char *buf) 399 struct device_attribute *attr, char *buf)
406{ 400{
407 int atr; 401 int atr = isl1208_i2c_get_atr(to_i2c_client(dev));
408
409 atr = isl1208_i2c_get_atr(to_i2c_client(dev));
410 if (atr < 0) 402 if (atr < 0)
411 return atr; 403 return atr;
412 404
413 return sprintf(buf, "%d.%.2d pF\n", atr>>2, (atr&0x3)*25); 405 return sprintf(buf, "%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
414} 406}
407
415static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL); 408static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
416 409
417static ssize_t isl1208_sysfs_show_dtrim(struct device *dev, 410static ssize_t
418 struct device_attribute *attr, 411isl1208_sysfs_show_dtrim(struct device *dev,
419 char *buf) 412 struct device_attribute *attr, char *buf)
420{ 413{
421 int dtr; 414 int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
422
423 dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
424 if (dtr < 0) 415 if (dtr < 0)
425 return dtr; 416 return dtr;
426 417
427 return sprintf(buf, "%d ppm\n", dtr); 418 return sprintf(buf, "%d ppm\n", dtr);
428} 419}
420
429static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL); 421static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
430 422
431static ssize_t isl1208_sysfs_show_usr(struct device *dev, 423static ssize_t
432 struct device_attribute *attr, 424isl1208_sysfs_show_usr(struct device *dev,
433 char *buf) 425 struct device_attribute *attr, char *buf)
434{ 426{
435 int usr; 427 int usr = isl1208_i2c_get_usr(to_i2c_client(dev));
436
437 usr = isl1208_i2c_get_usr(to_i2c_client(dev));
438 if (usr < 0) 428 if (usr < 0)
439 return usr; 429 return usr;
440 430
441 return sprintf(buf, "0x%.4x\n", usr); 431 return sprintf(buf, "0x%.4x\n", usr);
442} 432}
443 433
444static ssize_t isl1208_sysfs_store_usr(struct device *dev, 434static ssize_t
445 struct device_attribute *attr, 435isl1208_sysfs_store_usr(struct device *dev,
446 const char *buf, size_t count) 436 struct device_attribute *attr,
437 const char *buf, size_t count)
447{ 438{
448 int usr = -1; 439 int usr = -1;
449 440
@@ -460,124 +451,123 @@ static ssize_t isl1208_sysfs_store_usr(struct device *dev,
460 451
461 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count; 452 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
462} 453}
454
463static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr, 455static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
464 isl1208_sysfs_store_usr); 456 isl1208_sysfs_store_usr);
465 457
466static int 458static int
467isl1208_probe(struct i2c_adapter *adapter, int addr, int kind) 459isl1208_sysfs_register(struct device *dev)
468{ 460{
469 int rc = 0; 461 int err;
470 struct i2c_client *new_client = NULL;
471 struct rtc_device *rtc = NULL;
472 462
473 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 463 err = device_create_file(dev, &dev_attr_atrim);
474 rc = -ENODEV; 464 if (err)
475 goto failout; 465 return err;
466
467 err = device_create_file(dev, &dev_attr_dtrim);
468 if (err) {
469 device_remove_file(dev, &dev_attr_atrim);
470 return err;
476 } 471 }
477 472
478 new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 473 err = device_create_file(dev, &dev_attr_usr);
479 if (new_client == NULL) { 474 if (err) {
480 rc = -ENOMEM; 475 device_remove_file(dev, &dev_attr_atrim);
481 goto failout; 476 device_remove_file(dev, &dev_attr_dtrim);
482 } 477 }
483 478
484 new_client->addr = addr; 479 return 0;
485 new_client->adapter = adapter; 480}
486 new_client->driver = &isl1208_driver;
487 new_client->flags = 0;
488 strcpy(new_client->name, DRV_NAME);
489 481
490 if (kind < 0) { 482static int
491 rc = isl1208_i2c_validate_client(new_client); 483isl1208_sysfs_unregister(struct device *dev)
492 if (rc < 0) 484{
493 goto failout; 485 device_remove_file(dev, &dev_attr_atrim);
494 } 486 device_remove_file(dev, &dev_attr_atrim);
487 device_remove_file(dev, &dev_attr_usr);
488
489 return 0;
490}
491
492static int
493isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
494{
495 int rc = 0;
496 struct rtc_device *rtc;
497
498 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
499 return -ENODEV;
495 500
496 rc = i2c_attach_client(new_client); 501 if (isl1208_i2c_validate_client(client) < 0)
497 if (rc < 0) 502 return -ENODEV;
498 goto failout;
499 503
500 dev_info(&new_client->dev, 504 dev_info(&client->dev,
501 "chip found, driver version " DRV_VERSION "\n"); 505 "chip found, driver version " DRV_VERSION "\n");
502 506
503 rtc = rtc_device_register(isl1208_driver.driver.name, 507 rtc = rtc_device_register(isl1208_driver.driver.name,
504 &new_client->dev, 508 &client->dev, &isl1208_rtc_ops,
505 &isl1208_rtc_ops, THIS_MODULE); 509 THIS_MODULE);
510 if (IS_ERR(rtc))
511 return PTR_ERR(rtc);
506 512
507 if (IS_ERR(rtc)) { 513 i2c_set_clientdata(client, rtc);
508 rc = PTR_ERR(rtc);
509 goto failout_detach;
510 }
511
512 i2c_set_clientdata(new_client, rtc);
513 514
514 rc = isl1208_i2c_get_sr(new_client); 515 rc = isl1208_i2c_get_sr(client);
515 if (rc < 0) { 516 if (rc < 0) {
516 dev_err(&new_client->dev, "reading status failed\n"); 517 dev_err(&client->dev, "reading status failed\n");
517 goto failout_unregister; 518 goto exit_unregister;
518 } 519 }
519 520
520 if (rc & ISL1208_REG_SR_RTCF) 521 if (rc & ISL1208_REG_SR_RTCF)
521 dev_warn(&new_client->dev, "rtc power failure detected, " 522 dev_warn(&client->dev, "rtc power failure detected, "
522 "please set clock.\n"); 523 "please set clock.\n");
523 524
524 rc = device_create_file(&new_client->dev, &dev_attr_atrim); 525 rc = isl1208_sysfs_register(&client->dev);
525 if (rc < 0) 526 if (rc)
526 goto failout_unregister; 527 goto exit_unregister;
527 rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
528 if (rc < 0)
529 goto failout_atrim;
530 rc = device_create_file(&new_client->dev, &dev_attr_usr);
531 if (rc < 0)
532 goto failout_dtrim;
533 528
534 return 0; 529 return 0;
535 530
536 failout_dtrim: 531exit_unregister:
537 device_remove_file(&new_client->dev, &dev_attr_dtrim);
538 failout_atrim:
539 device_remove_file(&new_client->dev, &dev_attr_atrim);
540 failout_unregister:
541 rtc_device_unregister(rtc); 532 rtc_device_unregister(rtc);
542 failout_detach:
543 i2c_detach_client(new_client);
544 failout:
545 kfree(new_client);
546 return rc;
547}
548 533
549static int 534 return rc;
550isl1208_attach_adapter (struct i2c_adapter *adapter)
551{
552 return i2c_probe(adapter, &addr_data, isl1208_probe);
553} 535}
554 536
555static int 537static int
556isl1208_detach_client(struct i2c_client *client) 538isl1208_remove(struct i2c_client *client)
557{ 539{
558 int rc; 540 struct rtc_device *rtc = i2c_get_clientdata(client);
559 struct rtc_device *const rtc = i2c_get_clientdata(client);
560 541
561 if (rtc) 542 isl1208_sysfs_unregister(&client->dev);
562 rtc_device_unregister(rtc); /* do we need to kfree? */ 543 rtc_device_unregister(rtc);
563
564 rc = i2c_detach_client(client);
565 if (rc)
566 return rc;
567
568 kfree(client);
569 544
570 return 0; 545 return 0;
571} 546}
572 547
573/* module management */ 548static const struct i2c_device_id isl1208_id[] = {
549 { "isl1208", 0 },
550 { }
551};
552MODULE_DEVICE_TABLE(i2c, isl1208_id);
553
554static struct i2c_driver isl1208_driver = {
555 .driver = {
556 .name = "rtc-isl1208",
557 },
558 .probe = isl1208_probe,
559 .remove = isl1208_remove,
560 .id_table = isl1208_id,
561};
574 562
575static int __init isl1208_init(void) 563static int __init
564isl1208_init(void)
576{ 565{
577 return i2c_add_driver(&isl1208_driver); 566 return i2c_add_driver(&isl1208_driver);
578} 567}
579 568
580static void __exit isl1208_exit(void) 569static void __exit
570isl1208_exit(void)
581{ 571{
582 i2c_del_driver(&isl1208_driver); 572 i2c_del_driver(&isl1208_driver);
583} 573}
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 1cb33cac1237..316bfaa80872 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -60,48 +60,21 @@
60 60
61#define DRV_VERSION "0.05" 61#define DRV_VERSION "0.05"
62 62
63struct m41t80_chip_info { 63static const struct i2c_device_id m41t80_id[] = {
64 const char *name; 64 { "m41t80", 0 },
65 u8 features; 65 { "m41t81", M41T80_FEATURE_HT },
66}; 66 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
67 67 { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
68static const struct m41t80_chip_info m41t80_chip_info_tbl[] = { 68 { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
69 { 69 { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
70 .name = "m41t80", 70 { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
71 .features = 0, 71 { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL },
72 }, 72 { }
73 {
74 .name = "m41t81",
75 .features = M41T80_FEATURE_HT,
76 },
77 {
78 .name = "m41t81s",
79 .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
80 },
81 {
82 .name = "m41t82",
83 .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
84 },
85 {
86 .name = "m41t83",
87 .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
88 },
89 {
90 .name = "m41st84",
91 .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
92 },
93 {
94 .name = "m41st85",
95 .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
96 },
97 {
98 .name = "m41st87",
99 .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
100 },
101}; 73};
74MODULE_DEVICE_TABLE(i2c, m41t80_id);
102 75
103struct m41t80_data { 76struct m41t80_data {
104 const struct m41t80_chip_info *chip; 77 u8 features;
105 struct rtc_device *rtc; 78 struct rtc_device *rtc;
106}; 79};
107 80
@@ -208,7 +181,7 @@ static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq)
208 struct m41t80_data *clientdata = i2c_get_clientdata(client); 181 struct m41t80_data *clientdata = i2c_get_clientdata(client);
209 u8 reg; 182 u8 reg;
210 183
211 if (clientdata->chip->features & M41T80_FEATURE_BL) { 184 if (clientdata->features & M41T80_FEATURE_BL) {
212 reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); 185 reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
213 seq_printf(seq, "battery\t\t: %s\n", 186 seq_printf(seq, "battery\t\t: %s\n",
214 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok"); 187 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok");
@@ -756,12 +729,12 @@ static struct notifier_block wdt_notifier = {
756 * 729 *
757 ***************************************************************************** 730 *****************************************************************************
758 */ 731 */
759static int m41t80_probe(struct i2c_client *client) 732static int m41t80_probe(struct i2c_client *client,
733 const struct i2c_device_id *id)
760{ 734{
761 int i, rc = 0; 735 int rc = 0;
762 struct rtc_device *rtc = NULL; 736 struct rtc_device *rtc = NULL;
763 struct rtc_time tm; 737 struct rtc_time tm;
764 const struct m41t80_chip_info *chip;
765 struct m41t80_data *clientdata = NULL; 738 struct m41t80_data *clientdata = NULL;
766 739
767 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C 740 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C
@@ -773,19 +746,6 @@ static int m41t80_probe(struct i2c_client *client)
773 dev_info(&client->dev, 746 dev_info(&client->dev,
774 "chip found, driver version " DRV_VERSION "\n"); 747 "chip found, driver version " DRV_VERSION "\n");
775 748
776 chip = NULL;
777 for (i = 0; i < ARRAY_SIZE(m41t80_chip_info_tbl); i++) {
778 if (!strcmp(m41t80_chip_info_tbl[i].name, client->name)) {
779 chip = &m41t80_chip_info_tbl[i];
780 break;
781 }
782 }
783 if (!chip) {
784 dev_err(&client->dev, "%s is not supported\n", client->name);
785 rc = -ENODEV;
786 goto exit;
787 }
788
789 clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL); 749 clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL);
790 if (!clientdata) { 750 if (!clientdata) {
791 rc = -ENOMEM; 751 rc = -ENOMEM;
@@ -801,7 +761,7 @@ static int m41t80_probe(struct i2c_client *client)
801 } 761 }
802 762
803 clientdata->rtc = rtc; 763 clientdata->rtc = rtc;
804 clientdata->chip = chip; 764 clientdata->features = id->driver_data;
805 i2c_set_clientdata(client, clientdata); 765 i2c_set_clientdata(client, clientdata);
806 766
807 /* Make sure HT (Halt Update) bit is cleared */ 767 /* Make sure HT (Halt Update) bit is cleared */
@@ -810,7 +770,7 @@ static int m41t80_probe(struct i2c_client *client)
810 goto ht_err; 770 goto ht_err;
811 771
812 if (rc & M41T80_ALHOUR_HT) { 772 if (rc & M41T80_ALHOUR_HT) {
813 if (chip->features & M41T80_FEATURE_HT) { 773 if (clientdata->features & M41T80_FEATURE_HT) {
814 m41t80_get_datetime(client, &tm); 774 m41t80_get_datetime(client, &tm);
815 dev_info(&client->dev, "HT bit was set!\n"); 775 dev_info(&client->dev, "HT bit was set!\n");
816 dev_info(&client->dev, 776 dev_info(&client->dev,
@@ -842,7 +802,7 @@ static int m41t80_probe(struct i2c_client *client)
842 goto exit; 802 goto exit;
843 803
844#ifdef CONFIG_RTC_DRV_M41T80_WDT 804#ifdef CONFIG_RTC_DRV_M41T80_WDT
845 if (chip->features & M41T80_FEATURE_HT) { 805 if (clientdata->features & M41T80_FEATURE_HT) {
846 rc = misc_register(&wdt_dev); 806 rc = misc_register(&wdt_dev);
847 if (rc) 807 if (rc)
848 goto exit; 808 goto exit;
@@ -878,7 +838,7 @@ static int m41t80_remove(struct i2c_client *client)
878 struct rtc_device *rtc = clientdata->rtc; 838 struct rtc_device *rtc = clientdata->rtc;
879 839
880#ifdef CONFIG_RTC_DRV_M41T80_WDT 840#ifdef CONFIG_RTC_DRV_M41T80_WDT
881 if (clientdata->chip->features & M41T80_FEATURE_HT) { 841 if (clientdata->features & M41T80_FEATURE_HT) {
882 misc_deregister(&wdt_dev); 842 misc_deregister(&wdt_dev);
883 unregister_reboot_notifier(&wdt_notifier); 843 unregister_reboot_notifier(&wdt_notifier);
884 } 844 }
@@ -896,6 +856,7 @@ static struct i2c_driver m41t80_driver = {
896 }, 856 },
897 .probe = m41t80_probe, 857 .probe = m41t80_probe,
898 .remove = m41t80_remove, 858 .remove = m41t80_remove,
859 .id_table = m41t80_id,
899}; 860};
900 861
901static int __init m41t80_rtc_init(void) 862static int __init m41t80_rtc_init(void)
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index 7683412970c4..ded3c0abad83 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -98,7 +98,7 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
98 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 98 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
99 if (rc != ARRAY_SIZE(msgs)) { 99 if (rc != ARRAY_SIZE(msgs)) {
100 dev_err(&client->dev, "%s: register read failed\n", 100 dev_err(&client->dev, "%s: register read failed\n",
101 __FUNCTION__); 101 __func__);
102 return -EIO; 102 return -EIO;
103 } 103 }
104 return 0; 104 return 0;
@@ -150,7 +150,7 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
150 150
151write_failed: 151write_failed:
152 dev_err(&client->dev, "%s: register write failed\n", 152 dev_err(&client->dev, "%s: register write failed\n",
153 __FUNCTION__); 153 __func__);
154 return -EIO; 154 return -EIO;
155} 155}
156 156
@@ -214,7 +214,7 @@ static int max6900_i2c_clear_write_protect(struct i2c_client *client)
214 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0); 214 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0);
215 if (rc < 0) { 215 if (rc < 0) {
216 dev_err(&client->dev, "%s: control register write failed\n", 216 dev_err(&client->dev, "%s: control register write failed\n",
217 __FUNCTION__); 217 __func__);
218 return -EIO; 218 return -EIO;
219 } 219 }
220 return 0; 220 return 0;
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 1f956dc5d56e..12f0310ae89c 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -140,7 +140,7 @@ static int max6902_get_datetime(struct device *dev, struct rtc_time *dt)
140 dt->tm_year -= 1900; 140 dt->tm_year -= 1900;
141 141
142#ifdef MAX6902_DEBUG 142#ifdef MAX6902_DEBUG
143 printk("\n%s : Read RTC values\n",__FUNCTION__); 143 printk("\n%s : Read RTC values\n",__func__);
144 printk("tm_hour: %i\n",dt->tm_hour); 144 printk("tm_hour: %i\n",dt->tm_hour);
145 printk("tm_min : %i\n",dt->tm_min); 145 printk("tm_min : %i\n",dt->tm_min);
146 printk("tm_sec : %i\n",dt->tm_sec); 146 printk("tm_sec : %i\n",dt->tm_sec);
@@ -158,7 +158,7 @@ static int max6902_set_datetime(struct device *dev, struct rtc_time *dt)
158 dt->tm_year = dt->tm_year+1900; 158 dt->tm_year = dt->tm_year+1900;
159 159
160#ifdef MAX6902_DEBUG 160#ifdef MAX6902_DEBUG
161 printk("\n%s : Setting RTC values\n",__FUNCTION__); 161 printk("\n%s : Setting RTC values\n",__func__);
162 printk("tm_sec : %i\n",dt->tm_sec); 162 printk("tm_sec : %i\n",dt->tm_sec);
163 printk("tm_min : %i\n",dt->tm_min); 163 printk("tm_min : %i\n",dt->tm_min);
164 printk("tm_hour: %i\n",dt->tm_hour); 164 printk("tm_hour: %i\n",dt->tm_hour);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index b3317fcc16c3..0fc4c3630780 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -18,17 +18,7 @@
18#include <linux/bcd.h> 18#include <linux/bcd.h>
19#include <linux/rtc.h> 19#include <linux/rtc.h>
20 20
21#define DRV_VERSION "0.4.2" 21#define DRV_VERSION "0.4.3"
22
23/* Addresses to scan: none
24 * This chip cannot be reliably autodetected. An empty eeprom
25 * located at 0x51 will pass the validation routine due to
26 * the way the registers are implemented.
27 */
28static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
29
30/* Module parameters */
31I2C_CLIENT_INSMOD;
32 22
33#define PCF8563_REG_ST1 0x00 /* status */ 23#define PCF8563_REG_ST1 0x00 /* status */
34#define PCF8563_REG_ST2 0x01 24#define PCF8563_REG_ST2 0x01
@@ -53,8 +43,10 @@ I2C_CLIENT_INSMOD;
53#define PCF8563_SC_LV 0x80 /* low voltage */ 43#define PCF8563_SC_LV 0x80 /* low voltage */
54#define PCF8563_MO_C 0x80 /* century */ 44#define PCF8563_MO_C 0x80 /* century */
55 45
46static struct i2c_driver pcf8563_driver;
47
56struct pcf8563 { 48struct pcf8563 {
57 struct i2c_client client; 49 struct rtc_device *rtc;
58 /* 50 /*
59 * The meaning of MO_C bit varies by the chip type. 51 * The meaning of MO_C bit varies by the chip type.
60 * From PCF8563 datasheet: this bit is toggled when the years 52 * From PCF8563 datasheet: this bit is toggled when the years
@@ -72,16 +64,13 @@ struct pcf8563 {
72 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */ 64 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
73}; 65};
74 66
75static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
76static int pcf8563_detach(struct i2c_client *client);
77
78/* 67/*
79 * In the routines that deal directly with the pcf8563 hardware, we use 68 * In the routines that deal directly with the pcf8563 hardware, we use
80 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 69 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
81 */ 70 */
82static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm) 71static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
83{ 72{
84 struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); 73 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
85 unsigned char buf[13] = { PCF8563_REG_ST1 }; 74 unsigned char buf[13] = { PCF8563_REG_ST1 };
86 75
87 struct i2c_msg msgs[] = { 76 struct i2c_msg msgs[] = {
@@ -91,7 +80,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
91 80
92 /* read registers */ 81 /* read registers */
93 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) { 82 if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
94 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 83 dev_err(&client->dev, "%s: read error\n", __func__);
95 return -EIO; 84 return -EIO;
96 } 85 }
97 86
@@ -102,7 +91,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
102 dev_dbg(&client->dev, 91 dev_dbg(&client->dev,
103 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, " 92 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
104 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n", 93 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
105 __FUNCTION__, 94 __func__,
106 buf[0], buf[1], buf[2], buf[3], 95 buf[0], buf[1], buf[2], buf[3],
107 buf[4], buf[5], buf[6], buf[7], 96 buf[4], buf[5], buf[6], buf[7],
108 buf[8]); 97 buf[8]);
@@ -123,7 +112,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
123 112
124 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 113 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
125 "mday=%d, mon=%d, year=%d, wday=%d\n", 114 "mday=%d, mon=%d, year=%d, wday=%d\n",
126 __FUNCTION__, 115 __func__,
127 tm->tm_sec, tm->tm_min, tm->tm_hour, 116 tm->tm_sec, tm->tm_min, tm->tm_hour,
128 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 117 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
129 118
@@ -138,13 +127,13 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
138 127
139static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) 128static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
140{ 129{
141 struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); 130 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
142 int i, err; 131 int i, err;
143 unsigned char buf[9]; 132 unsigned char buf[9];
144 133
145 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " 134 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
146 "mday=%d, mon=%d, year=%d, wday=%d\n", 135 "mday=%d, mon=%d, year=%d, wday=%d\n",
147 __FUNCTION__, 136 __func__,
148 tm->tm_sec, tm->tm_min, tm->tm_hour, 137 tm->tm_sec, tm->tm_min, tm->tm_hour,
149 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 138 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
150 139
@@ -174,7 +163,7 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
174 if (err != sizeof(data)) { 163 if (err != sizeof(data)) {
175 dev_err(&client->dev, 164 dev_err(&client->dev,
176 "%s: err=%d addr=%02x, data=%02x\n", 165 "%s: err=%d addr=%02x, data=%02x\n",
177 __FUNCTION__, err, data[0], data[1]); 166 __func__, err, data[0], data[1]);
178 return -EIO; 167 return -EIO;
179 } 168 }
180 }; 169 };
@@ -219,7 +208,7 @@ static int pcf8563_validate_client(struct i2c_client *client)
219 if (xfer != ARRAY_SIZE(msgs)) { 208 if (xfer != ARRAY_SIZE(msgs)) {
220 dev_err(&client->dev, 209 dev_err(&client->dev,
221 "%s: could not read register 0x%02X\n", 210 "%s: could not read register 0x%02X\n",
222 __FUNCTION__, pattern[i].reg); 211 __func__, pattern[i].reg);
223 212
224 return -EIO; 213 return -EIO;
225 } 214 }
@@ -231,7 +220,7 @@ static int pcf8563_validate_client(struct i2c_client *client)
231 dev_dbg(&client->dev, 220 dev_dbg(&client->dev,
232 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, " 221 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
233 "max=%d, value=%d, raw=0x%02X\n", 222 "max=%d, value=%d, raw=0x%02X\n",
234 __FUNCTION__, i, pattern[i].reg, pattern[i].mask, 223 __func__, i, pattern[i].reg, pattern[i].mask,
235 pattern[i].min, pattern[i].max, 224 pattern[i].min, pattern[i].max,
236 value, buf); 225 value, buf);
237 226
@@ -257,100 +246,75 @@ static const struct rtc_class_ops pcf8563_rtc_ops = {
257 .set_time = pcf8563_rtc_set_time, 246 .set_time = pcf8563_rtc_set_time,
258}; 247};
259 248
260static int pcf8563_attach(struct i2c_adapter *adapter) 249static int pcf8563_probe(struct i2c_client *client,
261{ 250 const struct i2c_device_id *id)
262 return i2c_probe(adapter, &addr_data, pcf8563_probe);
263}
264
265static struct i2c_driver pcf8563_driver = {
266 .driver = {
267 .name = "pcf8563",
268 },
269 .id = I2C_DRIVERID_PCF8563,
270 .attach_adapter = &pcf8563_attach,
271 .detach_client = &pcf8563_detach,
272};
273
274static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
275{ 251{
276 struct pcf8563 *pcf8563; 252 struct pcf8563 *pcf8563;
277 struct i2c_client *client;
278 struct rtc_device *rtc;
279 253
280 int err = 0; 254 int err = 0;
281 255
282 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 256 dev_dbg(&client->dev, "%s\n", __func__);
283 257
284 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 258 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
285 err = -ENODEV; 259 return -ENODEV;
286 goto exit;
287 }
288 260
289 if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) { 261 pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL);
290 err = -ENOMEM; 262 if (!pcf8563)
291 goto exit; 263 return -ENOMEM;
292 }
293
294 client = &pcf8563->client;
295 client->addr = address;
296 client->driver = &pcf8563_driver;
297 client->adapter = adapter;
298
299 strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
300 264
301 /* Verify the chip is really an PCF8563 */ 265 /* Verify the chip is really an PCF8563 */
302 if (kind < 0) { 266 if (pcf8563_validate_client(client) < 0) {
303 if (pcf8563_validate_client(client) < 0) { 267 err = -ENODEV;
304 err = -ENODEV;
305 goto exit_kfree;
306 }
307 }
308
309 /* Inform the i2c layer */
310 if ((err = i2c_attach_client(client)))
311 goto exit_kfree; 268 goto exit_kfree;
269 }
312 270
313 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 271 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
314 272
315 rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev, 273 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name,
316 &pcf8563_rtc_ops, THIS_MODULE); 274 &client->dev, &pcf8563_rtc_ops, THIS_MODULE);
317 275
318 if (IS_ERR(rtc)) { 276 if (IS_ERR(pcf8563->rtc)) {
319 err = PTR_ERR(rtc); 277 err = PTR_ERR(pcf8563->rtc);
320 goto exit_detach; 278 goto exit_kfree;
321 } 279 }
322 280
323 i2c_set_clientdata(client, rtc); 281 i2c_set_clientdata(client, pcf8563);
324 282
325 return 0; 283 return 0;
326 284
327exit_detach:
328 i2c_detach_client(client);
329
330exit_kfree: 285exit_kfree:
331 kfree(pcf8563); 286 kfree(pcf8563);
332 287
333exit:
334 return err; 288 return err;
335} 289}
336 290
337static int pcf8563_detach(struct i2c_client *client) 291static int pcf8563_remove(struct i2c_client *client)
338{ 292{
339 struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); 293 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
340 int err;
341 struct rtc_device *rtc = i2c_get_clientdata(client);
342 294
343 if (rtc) 295 if (pcf8563->rtc)
344 rtc_device_unregister(rtc); 296 rtc_device_unregister(pcf8563->rtc);
345
346 if ((err = i2c_detach_client(client)))
347 return err;
348 297
349 kfree(pcf8563); 298 kfree(pcf8563);
350 299
351 return 0; 300 return 0;
352} 301}
353 302
303static const struct i2c_device_id pcf8563_id[] = {
304 { "pcf8563", 0 },
305 { }
306};
307MODULE_DEVICE_TABLE(i2c, pcf8563_id);
308
309static struct i2c_driver pcf8563_driver = {
310 .driver = {
311 .name = "rtc-pcf8563",
312 },
313 .probe = pcf8563_probe,
314 .remove = pcf8563_remove,
315 .id_table = pcf8563_id,
316};
317
354static int __init pcf8563_init(void) 318static int __init pcf8563_init(void)
355{ 319{
356 return i2c_add_driver(&pcf8563_driver); 320 return i2c_add_driver(&pcf8563_driver);
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 8b3997007506..3d09d8f0b1f0 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -15,7 +15,7 @@
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/mc146818rtc.h> 18#include <linux/rtc.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/bcd.h> 21#include <linux/bcd.h>
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index 8d300e6d0d9e..0c6257a034ff 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -108,12 +108,10 @@ void rtc_proc_add_device(struct rtc_device *rtc)
108 if (rtc->id == 0) { 108 if (rtc->id == 0) {
109 struct proc_dir_entry *ent; 109 struct proc_dir_entry *ent;
110 110
111 ent = create_proc_entry("driver/rtc", 0, NULL); 111 ent = proc_create_data("driver/rtc", 0, NULL,
112 if (ent) { 112 &rtc_proc_fops, rtc);
113 ent->proc_fops = &rtc_proc_fops; 113 if (ent)
114 ent->owner = rtc->owner; 114 ent->owner = rtc->owner;
115 ent->data = rtc;
116 }
117 } 115 }
118} 116}
119 117
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index 664e89a817ed..1c14d4497c4d 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -228,7 +228,7 @@ static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
228 ndelay(700); /* CE:L */ 228 ndelay(700); /* CE:L */
229 229
230 if (cnt++ > 100) { 230 if (cnt++ > 100) {
231 dev_err(dev, "%s: timeout error\n", __FUNCTION__); 231 dev_err(dev, "%s: timeout error\n", __func__);
232 return -EIO; 232 return -EIO;
233 } 233 }
234 } 234 }
@@ -289,7 +289,7 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
289 ndelay(700); /* CE:L */ 289 ndelay(700); /* CE:L */
290 290
291 if (cnt++ > 100) { 291 if (cnt++ > 100) {
292 dev_err(dev, "%s: timeout error\n", __FUNCTION__); 292 dev_err(dev, "%s: timeout error\n", __func__);
293 return -EIO; 293 return -EIO;
294 } 294 }
295 } 295 }
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 6b67b5097927..56caf6b2c3e5 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -69,6 +69,15 @@ enum rtc_type {
69 rtc_rv5c387a, 69 rtc_rv5c387a,
70}; 70};
71 71
72static const struct i2c_device_id rs5c372_id[] = {
73 { "rs5c372a", rtc_rs5c372a },
74 { "rs5c372b", rtc_rs5c372b },
75 { "rv5c386", rtc_rv5c386 },
76 { "rv5c387a", rtc_rv5c387a },
77 { }
78};
79MODULE_DEVICE_TABLE(i2c, rs5c372_id);
80
72/* REVISIT: this assumes that: 81/* REVISIT: this assumes that:
73 * - we're in the 21st century, so it's safe to ignore the century 82 * - we're in the 21st century, so it's safe to ignore the century
74 * bit for rv5c38[67] (REG_MONTH bit 7); 83 * bit for rv5c38[67] (REG_MONTH bit 7);
@@ -99,7 +108,7 @@ static int rs5c_get_regs(struct rs5c372 *rs5c)
99 * least 80219 chips; this works around that bug. 108 * least 80219 chips; this works around that bug.
100 */ 109 */
101 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) { 110 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
102 pr_debug("%s: can't read registers\n", rs5c->rtc->name); 111 dev_warn(&client->dev, "can't read registers\n");
103 return -EIO; 112 return -EIO;
104 } 113 }
105 114
@@ -166,7 +175,7 @@ static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
166 175
167 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 176 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
168 "mday=%d, mon=%d, year=%d, wday=%d\n", 177 "mday=%d, mon=%d, year=%d, wday=%d\n",
169 __FUNCTION__, 178 __func__,
170 tm->tm_sec, tm->tm_min, tm->tm_hour, 179 tm->tm_sec, tm->tm_min, tm->tm_hour,
171 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 180 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
172 181
@@ -181,7 +190,7 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
181 190
182 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " 191 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d "
183 "mday=%d, mon=%d, year=%d, wday=%d\n", 192 "mday=%d, mon=%d, year=%d, wday=%d\n",
184 __FUNCTION__, 193 __func__,
185 tm->tm_sec, tm->tm_min, tm->tm_hour, 194 tm->tm_sec, tm->tm_min, tm->tm_hour,
186 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 195 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
187 196
@@ -195,7 +204,7 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
195 buf[7] = BIN2BCD(tm->tm_year - 100); 204 buf[7] = BIN2BCD(tm->tm_year - 100);
196 205
197 if ((i2c_master_send(client, buf, 8)) != 8) { 206 if ((i2c_master_send(client, buf, 8)) != 8) {
198 dev_err(&client->dev, "%s: write error\n", __FUNCTION__); 207 dev_err(&client->dev, "%s: write error\n", __func__);
199 return -EIO; 208 return -EIO;
200 } 209 }
201 210
@@ -220,7 +229,7 @@ static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim)
220 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768; 229 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768;
221 230
222 if (trim) { 231 if (trim) {
223 dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, tmp); 232 dev_dbg(&client->dev, "%s: raw trim=%x\n", __func__, tmp);
224 tmp &= RS5C372_TRIM_MASK; 233 tmp &= RS5C372_TRIM_MASK;
225 if (tmp & 0x3e) { 234 if (tmp & 0x3e) {
226 int t = tmp & 0x3f; 235 int t = tmp & 0x3f;
@@ -494,13 +503,14 @@ static void rs5c_sysfs_unregister(struct device *dev)
494 503
495static struct i2c_driver rs5c372_driver; 504static struct i2c_driver rs5c372_driver;
496 505
497static int rs5c372_probe(struct i2c_client *client) 506static int rs5c372_probe(struct i2c_client *client,
507 const struct i2c_device_id *id)
498{ 508{
499 int err = 0; 509 int err = 0;
500 struct rs5c372 *rs5c372; 510 struct rs5c372 *rs5c372;
501 struct rtc_time tm; 511 struct rtc_time tm;
502 512
503 dev_dbg(&client->dev, "%s\n", __FUNCTION__); 513 dev_dbg(&client->dev, "%s\n", __func__);
504 514
505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 515 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
506 err = -ENODEV; 516 err = -ENODEV;
@@ -512,29 +522,17 @@ static int rs5c372_probe(struct i2c_client *client)
512 goto exit; 522 goto exit;
513 } 523 }
514 524
515 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
516 rs5c372->regs=&rs5c372->buf[1];
517
518 rs5c372->client = client; 525 rs5c372->client = client;
519 i2c_set_clientdata(client, rs5c372); 526 i2c_set_clientdata(client, rs5c372);
527 rs5c372->type = id->driver_data;
528
529 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
530 rs5c372->regs = &rs5c372->buf[1];
520 531
521 err = rs5c_get_regs(rs5c372); 532 err = rs5c_get_regs(rs5c372);
522 if (err < 0) 533 if (err < 0)
523 goto exit_kfree; 534 goto exit_kfree;
524 535
525 if (strcmp(client->name, "rs5c372a") == 0)
526 rs5c372->type = rtc_rs5c372a;
527 else if (strcmp(client->name, "rs5c372b") == 0)
528 rs5c372->type = rtc_rs5c372b;
529 else if (strcmp(client->name, "rv5c386") == 0)
530 rs5c372->type = rtc_rv5c386;
531 else if (strcmp(client->name, "rv5c387a") == 0)
532 rs5c372->type = rtc_rv5c387a;
533 else {
534 rs5c372->type = rtc_rs5c372b;
535 dev_warn(&client->dev, "assuming rs5c372b\n");
536 }
537
538 /* clock may be set for am/pm or 24 hr time */ 536 /* clock may be set for am/pm or 24 hr time */
539 switch (rs5c372->type) { 537 switch (rs5c372->type) {
540 case rtc_rs5c372a: 538 case rtc_rs5c372a:
@@ -651,6 +649,7 @@ static struct i2c_driver rs5c372_driver = {
651 }, 649 },
652 .probe = rs5c372_probe, 650 .probe = rs5c372_probe,
653 .remove = rs5c372_remove, 651 .remove = rs5c372_remove,
652 .id_table = rs5c372_id,
654}; 653};
655 654
656static __init int rs5c372_init(void) 655static __init int rs5c372_init(void)
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index e8abc90c32c5..29f47bacfc77 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -34,6 +34,12 @@
34#define S35390A_FLAG_RESET 0x80 34#define S35390A_FLAG_RESET 0x80
35#define S35390A_FLAG_TEST 0x01 35#define S35390A_FLAG_TEST 0x01
36 36
37static const struct i2c_device_id s35390a_id[] = {
38 { "s35390a", 0 },
39 { }
40};
41MODULE_DEVICE_TABLE(i2c, s35390a_id);
42
37struct s35390a { 43struct s35390a {
38 struct i2c_client *client[8]; 44 struct i2c_client *client[8];
39 struct rtc_device *rtc; 45 struct rtc_device *rtc;
@@ -195,7 +201,8 @@ static const struct rtc_class_ops s35390a_rtc_ops = {
195 201
196static struct i2c_driver s35390a_driver; 202static struct i2c_driver s35390a_driver;
197 203
198static int s35390a_probe(struct i2c_client *client) 204static int s35390a_probe(struct i2c_client *client,
205 const struct i2c_device_id *id)
199{ 206{
200 int err; 207 int err;
201 unsigned int i; 208 unsigned int i;
@@ -296,6 +303,7 @@ static struct i2c_driver s35390a_driver = {
296 }, 303 },
297 .probe = s35390a_probe, 304 .probe = s35390a_probe,
298 .remove = s35390a_remove, 305 .remove = s35390a_remove,
306 .id_table = s35390a_id,
299}; 307};
300 308
301static int __init s35390a_rtc_init(void) 309static int __init s35390a_rtc_init(void)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 9f4d5129a496..f26e0cad8f16 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -68,7 +68,7 @@ static void s3c_rtc_setaie(int to)
68{ 68{
69 unsigned int tmp; 69 unsigned int tmp;
70 70
71 pr_debug("%s: aie=%d\n", __FUNCTION__, to); 71 pr_debug("%s: aie=%d\n", __func__, to);
72 72
73 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 73 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
74 74
@@ -82,7 +82,7 @@ static void s3c_rtc_setpie(int to)
82{ 82{
83 unsigned int tmp; 83 unsigned int tmp;
84 84
85 pr_debug("%s: pie=%d\n", __FUNCTION__, to); 85 pr_debug("%s: pie=%d\n", __func__, to);
86 86
87 spin_lock_irq(&s3c_rtc_pie_lock); 87 spin_lock_irq(&s3c_rtc_pie_lock);
88 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE; 88 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
@@ -457,7 +457,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
457 struct resource *res; 457 struct resource *res;
458 int ret; 458 int ret;
459 459
460 pr_debug("%s: probe=%p\n", __FUNCTION__, pdev); 460 pr_debug("%s: probe=%p\n", __func__, pdev);
461 461
462 /* find the IRQs */ 462 /* find the IRQs */
463 463
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 9e9caa5d7f5f..110699bb4787 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * SuperH On-Chip RTC Support 2 * SuperH On-Chip RTC Support
3 * 3 *
4 * Copyright (C) 2006, 2007 Paul Mundt 4 * Copyright (C) 2006, 2007, 2008 Paul Mundt
5 * Copyright (C) 2006 Jamie Lenehan 5 * Copyright (C) 2006 Jamie Lenehan
6 * Copyright (C) 2008 Angelo Castello
6 * 7 *
7 * Based on the old arch/sh/kernel/cpu/rtc.c by: 8 * Based on the old arch/sh/kernel/cpu/rtc.c by:
8 * 9 *
@@ -26,7 +27,7 @@
26#include <asm/rtc.h> 27#include <asm/rtc.h>
27 28
28#define DRV_NAME "sh-rtc" 29#define DRV_NAME "sh-rtc"
29#define DRV_VERSION "0.1.6" 30#define DRV_VERSION "0.2.0"
30 31
31#define RTC_REG(r) ((r) * rtc_reg_size) 32#define RTC_REG(r) ((r) * rtc_reg_size)
32 33
@@ -63,6 +64,13 @@
63/* ALARM Bits - or with BCD encoded value */ 64/* ALARM Bits - or with BCD encoded value */
64#define AR_ENB 0x80 /* Enable for alarm cmp */ 65#define AR_ENB 0x80 /* Enable for alarm cmp */
65 66
67/* Period Bits */
68#define PF_HP 0x100 /* Enable Half Period to support 8,32,128Hz */
69#define PF_COUNT 0x200 /* Half periodic counter */
70#define PF_OXS 0x400 /* Periodic One x Second */
71#define PF_KOU 0x800 /* Kernel or User periodic request 1=kernel */
72#define PF_MASK 0xf00
73
66/* RCR1 Bits */ 74/* RCR1 Bits */
67#define RCR1_CF 0x80 /* Carry Flag */ 75#define RCR1_CF 0x80 /* Carry Flag */
68#define RCR1_CIE 0x10 /* Carry Interrupt Enable */ 76#define RCR1_CIE 0x10 /* Carry Interrupt Enable */
@@ -84,33 +92,24 @@ struct sh_rtc {
84 unsigned int alarm_irq, periodic_irq, carry_irq; 92 unsigned int alarm_irq, periodic_irq, carry_irq;
85 struct rtc_device *rtc_dev; 93 struct rtc_device *rtc_dev;
86 spinlock_t lock; 94 spinlock_t lock;
87 int rearm_aie;
88 unsigned long capabilities; /* See asm-sh/rtc.h for cap bits */ 95 unsigned long capabilities; /* See asm-sh/rtc.h for cap bits */
96 unsigned short periodic_freq;
89}; 97};
90 98
91static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id) 99static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id)
92{ 100{
93 struct platform_device *pdev = to_platform_device(dev_id); 101 struct sh_rtc *rtc = dev_id;
94 struct sh_rtc *rtc = platform_get_drvdata(pdev); 102 unsigned int tmp;
95 unsigned int tmp, events = 0;
96 103
97 spin_lock(&rtc->lock); 104 spin_lock(&rtc->lock);
98 105
99 tmp = readb(rtc->regbase + RCR1); 106 tmp = readb(rtc->regbase + RCR1);
100 tmp &= ~RCR1_CF; 107 tmp &= ~RCR1_CF;
101
102 if (rtc->rearm_aie) {
103 if (tmp & RCR1_AF)
104 tmp &= ~RCR1_AF; /* try to clear AF again */
105 else {
106 tmp |= RCR1_AIE; /* AF has cleared, rearm IRQ */
107 rtc->rearm_aie = 0;
108 }
109 }
110
111 writeb(tmp, rtc->regbase + RCR1); 108 writeb(tmp, rtc->regbase + RCR1);
112 109
113 rtc_update_irq(rtc->rtc_dev, 1, events); 110 /* Users have requested One x Second IRQ */
111 if (rtc->periodic_freq & PF_OXS)
112 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
114 113
115 spin_unlock(&rtc->lock); 114 spin_unlock(&rtc->lock);
116 115
@@ -119,47 +118,48 @@ static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id)
119 118
120static irqreturn_t sh_rtc_alarm(int irq, void *dev_id) 119static irqreturn_t sh_rtc_alarm(int irq, void *dev_id)
121{ 120{
122 struct platform_device *pdev = to_platform_device(dev_id); 121 struct sh_rtc *rtc = dev_id;
123 struct sh_rtc *rtc = platform_get_drvdata(pdev); 122 unsigned int tmp;
124 unsigned int tmp, events = 0;
125 123
126 spin_lock(&rtc->lock); 124 spin_lock(&rtc->lock);
127 125
128 tmp = readb(rtc->regbase + RCR1); 126 tmp = readb(rtc->regbase + RCR1);
129 127 tmp &= ~(RCR1_AF | RCR1_AIE);
130 /*
131 * If AF is set then the alarm has triggered. If we clear AF while
132 * the alarm time still matches the RTC time then AF will
133 * immediately be set again, and if AIE is enabled then the alarm
134 * interrupt will immediately be retrigger. So we clear AIE here
135 * and use rtc->rearm_aie so that the carry interrupt will keep
136 * trying to clear AF and once it stays cleared it'll re-enable
137 * AIE.
138 */
139 if (tmp & RCR1_AF) {
140 events |= RTC_AF | RTC_IRQF;
141
142 tmp &= ~(RCR1_AF|RCR1_AIE);
143
144 writeb(tmp, rtc->regbase + RCR1); 128 writeb(tmp, rtc->regbase + RCR1);
145 129
146 rtc->rearm_aie = 1; 130 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
147
148 rtc_update_irq(rtc->rtc_dev, 1, events);
149 }
150 131
151 spin_unlock(&rtc->lock); 132 spin_unlock(&rtc->lock);
133
152 return IRQ_HANDLED; 134 return IRQ_HANDLED;
153} 135}
154 136
155static irqreturn_t sh_rtc_periodic(int irq, void *dev_id) 137static irqreturn_t sh_rtc_periodic(int irq, void *dev_id)
156{ 138{
157 struct platform_device *pdev = to_platform_device(dev_id); 139 struct sh_rtc *rtc = dev_id;
158 struct sh_rtc *rtc = platform_get_drvdata(pdev); 140 struct rtc_device *rtc_dev = rtc->rtc_dev;
141 unsigned int tmp;
159 142
160 spin_lock(&rtc->lock); 143 spin_lock(&rtc->lock);
161 144
162 rtc_update_irq(rtc->rtc_dev, 1, RTC_PF | RTC_IRQF); 145 tmp = readb(rtc->regbase + RCR2);
146 tmp &= ~RCR2_PEF;
147 writeb(tmp, rtc->regbase + RCR2);
148
149 /* Half period enabled than one skipped and the next notified */
150 if ((rtc->periodic_freq & PF_HP) && (rtc->periodic_freq & PF_COUNT))
151 rtc->periodic_freq &= ~PF_COUNT;
152 else {
153 if (rtc->periodic_freq & PF_HP)
154 rtc->periodic_freq |= PF_COUNT;
155 if (rtc->periodic_freq & PF_KOU) {
156 spin_lock(&rtc_dev->irq_task_lock);
157 if (rtc_dev->irq_task)
158 rtc_dev->irq_task->func(rtc_dev->irq_task->private_data);
159 spin_unlock(&rtc_dev->irq_task_lock);
160 } else
161 rtc_update_irq(rtc->rtc_dev, 1, RTC_PF | RTC_IRQF);
162 }
163 163
164 spin_unlock(&rtc->lock); 164 spin_unlock(&rtc->lock);
165 165
@@ -176,8 +176,8 @@ static inline void sh_rtc_setpie(struct device *dev, unsigned int enable)
176 tmp = readb(rtc->regbase + RCR2); 176 tmp = readb(rtc->regbase + RCR2);
177 177
178 if (enable) { 178 if (enable) {
179 tmp &= ~RCR2_PESMASK; 179 tmp &= ~RCR2_PEF; /* Clear PES bit */
180 tmp |= RCR2_PEF | (2 << 4); 180 tmp |= (rtc->periodic_freq & ~PF_HP); /* Set PES2-0 */
181 } else 181 } else
182 tmp &= ~(RCR2_PESMASK | RCR2_PEF); 182 tmp &= ~(RCR2_PESMASK | RCR2_PEF);
183 183
@@ -186,82 +186,81 @@ static inline void sh_rtc_setpie(struct device *dev, unsigned int enable)
186 spin_unlock_irq(&rtc->lock); 186 spin_unlock_irq(&rtc->lock);
187} 187}
188 188
189static inline void sh_rtc_setaie(struct device *dev, unsigned int enable) 189static inline int sh_rtc_setfreq(struct device *dev, unsigned int freq)
190{ 190{
191 struct sh_rtc *rtc = dev_get_drvdata(dev); 191 struct sh_rtc *rtc = dev_get_drvdata(dev);
192 unsigned int tmp; 192 int tmp, ret = 0;
193 193
194 spin_lock_irq(&rtc->lock); 194 spin_lock_irq(&rtc->lock);
195 tmp = rtc->periodic_freq & PF_MASK;
195 196
196 tmp = readb(rtc->regbase + RCR1); 197 switch (freq) {
197 198 case 0:
198 if (!enable) { 199 rtc->periodic_freq = 0x00;
199 tmp &= ~RCR1_AIE; 200 break;
200 rtc->rearm_aie = 0; 201 case 1:
201 } else if (rtc->rearm_aie == 0) 202 rtc->periodic_freq = 0x60;
202 tmp |= RCR1_AIE; 203 break;
204 case 2:
205 rtc->periodic_freq = 0x50;
206 break;
207 case 4:
208 rtc->periodic_freq = 0x40;
209 break;
210 case 8:
211 rtc->periodic_freq = 0x30 | PF_HP;
212 break;
213 case 16:
214 rtc->periodic_freq = 0x30;
215 break;
216 case 32:
217 rtc->periodic_freq = 0x20 | PF_HP;
218 break;
219 case 64:
220 rtc->periodic_freq = 0x20;
221 break;
222 case 128:
223 rtc->periodic_freq = 0x10 | PF_HP;
224 break;
225 case 256:
226 rtc->periodic_freq = 0x10;
227 break;
228 default:
229 ret = -ENOTSUPP;
230 }
203 231
204 writeb(tmp, rtc->regbase + RCR1); 232 if (ret == 0) {
233 rtc->periodic_freq |= tmp;
234 rtc->rtc_dev->irq_freq = freq;
235 }
205 236
206 spin_unlock_irq(&rtc->lock); 237 spin_unlock_irq(&rtc->lock);
238 return ret;
207} 239}
208 240
209static int sh_rtc_open(struct device *dev) 241static inline void sh_rtc_setaie(struct device *dev, unsigned int enable)
210{ 242{
211 struct sh_rtc *rtc = dev_get_drvdata(dev); 243 struct sh_rtc *rtc = dev_get_drvdata(dev);
212 unsigned int tmp; 244 unsigned int tmp;
213 int ret;
214
215 tmp = readb(rtc->regbase + RCR1);
216 tmp &= ~RCR1_CF;
217 tmp |= RCR1_CIE;
218 writeb(tmp, rtc->regbase + RCR1);
219 245
220 ret = request_irq(rtc->periodic_irq, sh_rtc_periodic, IRQF_DISABLED, 246 spin_lock_irq(&rtc->lock);
221 "sh-rtc period", dev);
222 if (unlikely(ret)) {
223 dev_err(dev, "request period IRQ failed with %d, IRQ %d\n",
224 ret, rtc->periodic_irq);
225 return ret;
226 }
227
228 ret = request_irq(rtc->carry_irq, sh_rtc_interrupt, IRQF_DISABLED,
229 "sh-rtc carry", dev);
230 if (unlikely(ret)) {
231 dev_err(dev, "request carry IRQ failed with %d, IRQ %d\n",
232 ret, rtc->carry_irq);
233 free_irq(rtc->periodic_irq, dev);
234 goto err_bad_carry;
235 }
236 247
237 ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, IRQF_DISABLED, 248 tmp = readb(rtc->regbase + RCR1);
238 "sh-rtc alarm", dev);
239 if (unlikely(ret)) {
240 dev_err(dev, "request alarm IRQ failed with %d, IRQ %d\n",
241 ret, rtc->alarm_irq);
242 goto err_bad_alarm;
243 }
244 249
245 return 0; 250 if (!enable)
251 tmp &= ~RCR1_AIE;
252 else
253 tmp |= RCR1_AIE;
246 254
247err_bad_alarm: 255 writeb(tmp, rtc->regbase + RCR1);
248 free_irq(rtc->carry_irq, dev);
249err_bad_carry:
250 free_irq(rtc->periodic_irq, dev);
251 256
252 return ret; 257 spin_unlock_irq(&rtc->lock);
253} 258}
254 259
255static void sh_rtc_release(struct device *dev) 260static void sh_rtc_release(struct device *dev)
256{ 261{
257 struct sh_rtc *rtc = dev_get_drvdata(dev);
258
259 sh_rtc_setpie(dev, 0); 262 sh_rtc_setpie(dev, 0);
260 sh_rtc_setaie(dev, 0); 263 sh_rtc_setaie(dev, 0);
261
262 free_irq(rtc->periodic_irq, dev);
263 free_irq(rtc->carry_irq, dev);
264 free_irq(rtc->alarm_irq, dev);
265} 264}
266 265
267static int sh_rtc_proc(struct device *dev, struct seq_file *seq) 266static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
@@ -270,31 +269,44 @@ static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
270 unsigned int tmp; 269 unsigned int tmp;
271 270
272 tmp = readb(rtc->regbase + RCR1); 271 tmp = readb(rtc->regbase + RCR1);
273 seq_printf(seq, "carry_IRQ\t: %s\n", 272 seq_printf(seq, "carry_IRQ\t: %s\n", (tmp & RCR1_CIE) ? "yes" : "no");
274 (tmp & RCR1_CIE) ? "yes" : "no");
275 273
276 tmp = readb(rtc->regbase + RCR2); 274 tmp = readb(rtc->regbase + RCR2);
277 seq_printf(seq, "periodic_IRQ\t: %s\n", 275 seq_printf(seq, "periodic_IRQ\t: %s\n",
278 (tmp & RCR2_PEF) ? "yes" : "no"); 276 (tmp & RCR2_PESMASK) ? "yes" : "no");
279 277
280 return 0; 278 return 0;
281} 279}
282 280
283static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 281static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
284{ 282{
285 unsigned int ret = -ENOIOCTLCMD; 283 struct sh_rtc *rtc = dev_get_drvdata(dev);
284 unsigned int ret = 0;
286 285
287 switch (cmd) { 286 switch (cmd) {
288 case RTC_PIE_OFF: 287 case RTC_PIE_OFF:
289 case RTC_PIE_ON: 288 case RTC_PIE_ON:
290 sh_rtc_setpie(dev, cmd == RTC_PIE_ON); 289 sh_rtc_setpie(dev, cmd == RTC_PIE_ON);
291 ret = 0;
292 break; 290 break;
293 case RTC_AIE_OFF: 291 case RTC_AIE_OFF:
294 case RTC_AIE_ON: 292 case RTC_AIE_ON:
295 sh_rtc_setaie(dev, cmd == RTC_AIE_ON); 293 sh_rtc_setaie(dev, cmd == RTC_AIE_ON);
296 ret = 0;
297 break; 294 break;
295 case RTC_UIE_OFF:
296 rtc->periodic_freq &= ~PF_OXS;
297 break;
298 case RTC_UIE_ON:
299 rtc->periodic_freq |= PF_OXS;
300 break;
301 case RTC_IRQP_READ:
302 ret = put_user(rtc->rtc_dev->irq_freq,
303 (unsigned long __user *)arg);
304 break;
305 case RTC_IRQP_SET:
306 ret = sh_rtc_setfreq(dev, arg);
307 break;
308 default:
309 ret = -ENOIOCTLCMD;
298 } 310 }
299 311
300 return ret; 312 return ret;
@@ -349,7 +361,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
349 361
350 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 362 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
351 "mday=%d, mon=%d, year=%d, wday=%d\n", 363 "mday=%d, mon=%d, year=%d, wday=%d\n",
352 __FUNCTION__, 364 __func__,
353 tm->tm_sec, tm->tm_min, tm->tm_hour, 365 tm->tm_sec, tm->tm_min, tm->tm_hour,
354 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); 366 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
355 367
@@ -421,7 +433,7 @@ static int sh_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
421{ 433{
422 struct platform_device *pdev = to_platform_device(dev); 434 struct platform_device *pdev = to_platform_device(dev);
423 struct sh_rtc *rtc = platform_get_drvdata(pdev); 435 struct sh_rtc *rtc = platform_get_drvdata(pdev);
424 struct rtc_time* tm = &wkalrm->time; 436 struct rtc_time *tm = &wkalrm->time;
425 437
426 spin_lock_irq(&rtc->lock); 438 spin_lock_irq(&rtc->lock);
427 439
@@ -452,7 +464,7 @@ static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc,
452 writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off); 464 writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off);
453} 465}
454 466
455static int sh_rtc_check_alarm(struct rtc_time* tm) 467static int sh_rtc_check_alarm(struct rtc_time *tm)
456{ 468{
457 /* 469 /*
458 * The original rtc says anything > 0xc0 is "don't care" or "match 470 * The original rtc says anything > 0xc0 is "don't care" or "match
@@ -503,11 +515,9 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
503 515
504 /* disable alarm interrupt and clear the alarm flag */ 516 /* disable alarm interrupt and clear the alarm flag */
505 rcr1 = readb(rtc->regbase + RCR1); 517 rcr1 = readb(rtc->regbase + RCR1);
506 rcr1 &= ~(RCR1_AF|RCR1_AIE); 518 rcr1 &= ~(RCR1_AF | RCR1_AIE);
507 writeb(rcr1, rtc->regbase + RCR1); 519 writeb(rcr1, rtc->regbase + RCR1);
508 520
509 rtc->rearm_aie = 0;
510
511 /* set alarm time */ 521 /* set alarm time */
512 sh_rtc_write_alarm_value(rtc, tm->tm_sec, RSECAR); 522 sh_rtc_write_alarm_value(rtc, tm->tm_sec, RSECAR);
513 sh_rtc_write_alarm_value(rtc, tm->tm_min, RMINAR); 523 sh_rtc_write_alarm_value(rtc, tm->tm_min, RMINAR);
@@ -529,14 +539,34 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
529 return 0; 539 return 0;
530} 540}
531 541
542static int sh_rtc_irq_set_state(struct device *dev, int enabled)
543{
544 struct platform_device *pdev = to_platform_device(dev);
545 struct sh_rtc *rtc = platform_get_drvdata(pdev);
546
547 if (enabled) {
548 rtc->periodic_freq |= PF_KOU;
549 return sh_rtc_ioctl(dev, RTC_PIE_ON, 0);
550 } else {
551 rtc->periodic_freq &= ~PF_KOU;
552 return sh_rtc_ioctl(dev, RTC_PIE_OFF, 0);
553 }
554}
555
556static int sh_rtc_irq_set_freq(struct device *dev, int freq)
557{
558 return sh_rtc_ioctl(dev, RTC_IRQP_SET, freq);
559}
560
532static struct rtc_class_ops sh_rtc_ops = { 561static struct rtc_class_ops sh_rtc_ops = {
533 .open = sh_rtc_open,
534 .release = sh_rtc_release, 562 .release = sh_rtc_release,
535 .ioctl = sh_rtc_ioctl, 563 .ioctl = sh_rtc_ioctl,
536 .read_time = sh_rtc_read_time, 564 .read_time = sh_rtc_read_time,
537 .set_time = sh_rtc_set_time, 565 .set_time = sh_rtc_set_time,
538 .read_alarm = sh_rtc_read_alarm, 566 .read_alarm = sh_rtc_read_alarm,
539 .set_alarm = sh_rtc_set_alarm, 567 .set_alarm = sh_rtc_set_alarm,
568 .irq_set_state = sh_rtc_irq_set_state,
569 .irq_set_freq = sh_rtc_irq_set_freq,
540 .proc = sh_rtc_proc, 570 .proc = sh_rtc_proc,
541}; 571};
542 572
@@ -544,6 +574,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
544{ 574{
545 struct sh_rtc *rtc; 575 struct sh_rtc *rtc;
546 struct resource *res; 576 struct resource *res;
577 unsigned int tmp;
547 int ret = -ENOENT; 578 int ret = -ENOENT;
548 579
549 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); 580 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL);
@@ -552,6 +583,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
552 583
553 spin_lock_init(&rtc->lock); 584 spin_lock_init(&rtc->lock);
554 585
586 /* get periodic/carry/alarm irqs */
555 rtc->periodic_irq = platform_get_irq(pdev, 0); 587 rtc->periodic_irq = platform_get_irq(pdev, 0);
556 if (unlikely(rtc->periodic_irq < 0)) { 588 if (unlikely(rtc->periodic_irq < 0)) {
557 dev_err(&pdev->dev, "No IRQ for period\n"); 589 dev_err(&pdev->dev, "No IRQ for period\n");
@@ -608,8 +640,48 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
608 rtc->capabilities |= pinfo->capabilities; 640 rtc->capabilities |= pinfo->capabilities;
609 } 641 }
610 642
643 rtc->rtc_dev->max_user_freq = 256;
644 rtc->rtc_dev->irq_freq = 1;
645 rtc->periodic_freq = 0x60;
646
611 platform_set_drvdata(pdev, rtc); 647 platform_set_drvdata(pdev, rtc);
612 648
649 /* register periodic/carry/alarm irqs */
650 ret = request_irq(rtc->periodic_irq, sh_rtc_periodic, IRQF_DISABLED,
651 "sh-rtc period", rtc);
652 if (unlikely(ret)) {
653 dev_err(&pdev->dev,
654 "request period IRQ failed with %d, IRQ %d\n", ret,
655 rtc->periodic_irq);
656 goto err_badmap;
657 }
658
659 ret = request_irq(rtc->carry_irq, sh_rtc_interrupt, IRQF_DISABLED,
660 "sh-rtc carry", rtc);
661 if (unlikely(ret)) {
662 dev_err(&pdev->dev,
663 "request carry IRQ failed with %d, IRQ %d\n", ret,
664 rtc->carry_irq);
665 free_irq(rtc->periodic_irq, rtc);
666 goto err_badmap;
667 }
668
669 ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, IRQF_DISABLED,
670 "sh-rtc alarm", rtc);
671 if (unlikely(ret)) {
672 dev_err(&pdev->dev,
673 "request alarm IRQ failed with %d, IRQ %d\n", ret,
674 rtc->alarm_irq);
675 free_irq(rtc->carry_irq, rtc);
676 free_irq(rtc->periodic_irq, rtc);
677 goto err_badmap;
678 }
679
680 tmp = readb(rtc->regbase + RCR1);
681 tmp &= ~RCR1_CF;
682 tmp |= RCR1_CIE;
683 writeb(tmp, rtc->regbase + RCR1);
684
613 return 0; 685 return 0;
614 686
615err_badmap: 687err_badmap:
@@ -630,6 +702,10 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev)
630 sh_rtc_setpie(&pdev->dev, 0); 702 sh_rtc_setpie(&pdev->dev, 0);
631 sh_rtc_setaie(&pdev->dev, 0); 703 sh_rtc_setaie(&pdev->dev, 0);
632 704
705 free_irq(rtc->carry_irq, rtc);
706 free_irq(rtc->periodic_irq, rtc);
707 free_irq(rtc->alarm_irq, rtc);
708
633 release_resource(rtc->res); 709 release_resource(rtc->res);
634 710
635 platform_set_drvdata(pdev, NULL); 711 platform_set_drvdata(pdev, NULL);
@@ -662,6 +738,8 @@ module_exit(sh_rtc_exit);
662 738
663MODULE_DESCRIPTION("SuperH on-chip RTC driver"); 739MODULE_DESCRIPTION("SuperH on-chip RTC driver");
664MODULE_VERSION(DRV_VERSION); 740MODULE_VERSION(DRV_VERSION);
665MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, Jamie Lenehan <lenehan@twibble.org>"); 741MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, "
742 "Jamie Lenehan <lenehan@twibble.org>, "
743 "Angelo Castello <angelo.castello@st.com>");
666MODULE_LICENSE("GPL"); 744MODULE_LICENSE("GPL");
667MODULE_ALIAS("platform:" DRV_NAME); 745MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 4d27ccc4fc06..2531ce4c9db0 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -145,6 +145,8 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
145 unsigned long now, alarm; 145 unsigned long now, alarm;
146 struct rtc_wkalrm alm; 146 struct rtc_wkalrm alm;
147 struct rtc_device *rtc = to_rtc_device(dev); 147 struct rtc_device *rtc = to_rtc_device(dev);
148 char *buf_ptr;
149 int adjust = 0;
148 150
149 /* Only request alarms that trigger in the future. Disable them 151 /* Only request alarms that trigger in the future. Disable them
150 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC. 152 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
@@ -154,7 +156,15 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
154 return retval; 156 return retval;
155 rtc_tm_to_time(&alm.time, &now); 157 rtc_tm_to_time(&alm.time, &now);
156 158
157 alarm = simple_strtoul(buf, NULL, 0); 159 buf_ptr = (char *)buf;
160 if (*buf_ptr == '+') {
161 buf_ptr++;
162 adjust = 1;
163 }
164 alarm = simple_strtoul(buf_ptr, NULL, 0);
165 if (adjust) {
166 alarm += now;
167 }
158 if (alarm > now) { 168 if (alarm > now) {
159 /* Avoid accidentally clobbering active alarms; we can't 169 /* Avoid accidentally clobbering active alarms; we can't
160 * entirely prevent that here, without even the minimal 170 * entirely prevent that here, without even the minimal
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 254c9fce27da..bc930022004a 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -147,7 +147,7 @@ static int __devexit test_remove(struct platform_device *plat_dev)
147 return 0; 147 return 0;
148} 148}
149 149
150static struct platform_driver test_drv = { 150static struct platform_driver test_driver = {
151 .probe = test_probe, 151 .probe = test_probe,
152 .remove = __devexit_p(test_remove), 152 .remove = __devexit_p(test_remove),
153 .driver = { 153 .driver = {
@@ -160,7 +160,7 @@ static int __init test_init(void)
160{ 160{
161 int err; 161 int err;
162 162
163 if ((err = platform_driver_register(&test_drv))) 163 if ((err = platform_driver_register(&test_driver)))
164 return err; 164 return err;
165 165
166 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) { 166 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
@@ -191,7 +191,7 @@ exit_free_test0:
191 platform_device_put(test0); 191 platform_device_put(test0);
192 192
193exit_driver_unregister: 193exit_driver_unregister:
194 platform_driver_unregister(&test_drv); 194 platform_driver_unregister(&test_driver);
195 return err; 195 return err;
196} 196}
197 197
@@ -199,7 +199,7 @@ static void __exit test_exit(void)
199{ 199{
200 platform_device_unregister(test0); 200 platform_device_unregister(test0);
201 platform_device_unregister(test1); 201 platform_device_unregister(test1);
202 platform_driver_unregister(&test_drv); 202 platform_driver_unregister(&test_driver);
203} 203}
204 204
205MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 205MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index 24203a06051a..10025d840268 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -107,7 +107,7 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt)
107 dt->tm_year = BCD2BIN(tmp)+100; 107 dt->tm_year = BCD2BIN(tmp)+100;
108 108
109#ifdef DEBUG 109#ifdef DEBUG
110 printk("\n%s : Read RTC values\n",__FUNCTION__); 110 printk("\n%s : Read RTC values\n",__func__);
111 printk("tm_hour: %i\n",dt->tm_hour); 111 printk("tm_hour: %i\n",dt->tm_hour);
112 printk("tm_min : %i\n",dt->tm_min); 112 printk("tm_min : %i\n",dt->tm_min);
113 printk("tm_sec : %i\n",dt->tm_sec); 113 printk("tm_sec : %i\n",dt->tm_sec);
@@ -126,7 +126,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)
126 struct v3020 *chip = dev_get_drvdata(dev); 126 struct v3020 *chip = dev_get_drvdata(dev);
127 127
128#ifdef DEBUG 128#ifdef DEBUG
129 printk("\n%s : Setting RTC values\n",__FUNCTION__); 129 printk("\n%s : Setting RTC values\n",__func__);
130 printk("tm_sec : %i\n",dt->tm_sec); 130 printk("tm_sec : %i\n",dt->tm_sec);
131 printk("tm_min : %i\n",dt->tm_min); 131 printk("tm_min : %i\n",dt->tm_min);
132 printk("tm_hour: %i\n",dt->tm_hour); 132 printk("tm_hour: %i\n",dt->tm_hour);
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index b90fb1866ce9..eaf55945f21b 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -22,20 +22,7 @@
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24 24
25#define DRV_VERSION "1.0.7" 25#define DRV_VERSION "1.0.8"
26
27/* Addresses to scan: none. This chip is located at
28 * 0x6f and uses a two bytes register addressing.
29 * Two bytes need to be written to read a single register,
30 * while most other chips just require one and take the second
31 * one as the data to be written. To prevent corrupting
32 * unknown chips, the user must explicitly set the probe parameter.
33 */
34
35static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
36
37/* Insmod parameters */
38I2C_CLIENT_INSMOD;
39 26
40/* offsets into CCR area */ 27/* offsets into CCR area */
41 28
@@ -91,19 +78,7 @@ I2C_CLIENT_INSMOD;
91 78
92#define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ 79#define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
93 80
94/* Prototypes */ 81static struct i2c_driver x1205_driver;
95static int x1205_attach(struct i2c_adapter *adapter);
96static int x1205_detach(struct i2c_client *client);
97static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
98
99static struct i2c_driver x1205_driver = {
100 .driver = {
101 .name = "x1205",
102 },
103 .id = I2C_DRIVERID_X1205,
104 .attach_adapter = &x1205_attach,
105 .detach_client = &x1205_detach,
106};
107 82
108/* 83/*
109 * In the routines that deal directly with the x1205 hardware, we use 84 * In the routines that deal directly with the x1205 hardware, we use
@@ -124,14 +99,14 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
124 99
125 /* read date registers */ 100 /* read date registers */
126 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 101 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
127 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 102 dev_err(&client->dev, "%s: read error\n", __func__);
128 return -EIO; 103 return -EIO;
129 } 104 }
130 105
131 dev_dbg(&client->dev, 106 dev_dbg(&client->dev,
132 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, " 107 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
133 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n", 108 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
134 __FUNCTION__, 109 __func__,
135 buf[0], buf[1], buf[2], buf[3], 110 buf[0], buf[1], buf[2], buf[3],
136 buf[4], buf[5], buf[6], buf[7]); 111 buf[4], buf[5], buf[6], buf[7]);
137 112
@@ -146,7 +121,7 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
146 121
147 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 122 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
148 "mday=%d, mon=%d, year=%d, wday=%d\n", 123 "mday=%d, mon=%d, year=%d, wday=%d\n",
149 __FUNCTION__, 124 __func__,
150 tm->tm_sec, tm->tm_min, tm->tm_hour, 125 tm->tm_sec, tm->tm_min, tm->tm_hour,
151 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 126 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
152 127
@@ -164,7 +139,7 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
164 139
165 /* read status register */ 140 /* read status register */
166 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 141 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
167 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 142 dev_err(&client->dev, "%s: read error\n", __func__);
168 return -EIO; 143 return -EIO;
169 } 144 }
170 145
@@ -187,7 +162,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
187 162
188 dev_dbg(&client->dev, 163 dev_dbg(&client->dev,
189 "%s: secs=%d, mins=%d, hours=%d\n", 164 "%s: secs=%d, mins=%d, hours=%d\n",
190 __FUNCTION__, 165 __func__,
191 tm->tm_sec, tm->tm_min, tm->tm_hour); 166 tm->tm_sec, tm->tm_min, tm->tm_hour);
192 167
193 buf[CCR_SEC] = BIN2BCD(tm->tm_sec); 168 buf[CCR_SEC] = BIN2BCD(tm->tm_sec);
@@ -200,7 +175,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
200 if (datetoo) { 175 if (datetoo) {
201 dev_dbg(&client->dev, 176 dev_dbg(&client->dev,
202 "%s: mday=%d, mon=%d, year=%d, wday=%d\n", 177 "%s: mday=%d, mon=%d, year=%d, wday=%d\n",
203 __FUNCTION__, 178 __func__,
204 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 179 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
205 180
206 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); 181 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday);
@@ -216,12 +191,12 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
216 191
217 /* this sequence is required to unlock the chip */ 192 /* this sequence is required to unlock the chip */
218 if ((xfer = i2c_master_send(client, wel, 3)) != 3) { 193 if ((xfer = i2c_master_send(client, wel, 3)) != 3) {
219 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer); 194 dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer);
220 return -EIO; 195 return -EIO;
221 } 196 }
222 197
223 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) { 198 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) {
224 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer); 199 dev_err(&client->dev, "%s: rwel - %d\n", __func__, xfer);
225 return -EIO; 200 return -EIO;
226 } 201 }
227 202
@@ -233,7 +208,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
233 if (xfer != 3) { 208 if (xfer != 3) {
234 dev_err(&client->dev, 209 dev_err(&client->dev,
235 "%s: xfer=%d addr=%02x, data=%02x\n", 210 "%s: xfer=%d addr=%02x, data=%02x\n",
236 __FUNCTION__, 211 __func__,
237 xfer, rdata[1], rdata[2]); 212 xfer, rdata[1], rdata[2]);
238 return -EIO; 213 return -EIO;
239 } 214 }
@@ -241,7 +216,7 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
241 216
242 /* disable further writes */ 217 /* disable further writes */
243 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { 218 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) {
244 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer); 219 dev_err(&client->dev, "%s: diswe - %d\n", __func__, xfer);
245 return -EIO; 220 return -EIO;
246 } 221 }
247 222
@@ -274,11 +249,11 @@ static int x1205_get_dtrim(struct i2c_client *client, int *trim)
274 249
275 /* read dtr register */ 250 /* read dtr register */
276 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 251 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
277 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 252 dev_err(&client->dev, "%s: read error\n", __func__);
278 return -EIO; 253 return -EIO;
279 } 254 }
280 255
281 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __FUNCTION__, dtr); 256 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __func__, dtr);
282 257
283 *trim = 0; 258 *trim = 0;
284 259
@@ -306,11 +281,11 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
306 281
307 /* read atr register */ 282 /* read atr register */
308 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 283 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
309 dev_err(&client->dev, "%s: read error\n", __FUNCTION__); 284 dev_err(&client->dev, "%s: read error\n", __func__);
310 return -EIO; 285 return -EIO;
311 } 286 }
312 287
313 dev_dbg(&client->dev, "%s: raw atr=%x\n", __FUNCTION__, atr); 288 dev_dbg(&client->dev, "%s: raw atr=%x\n", __func__, atr);
314 289
315 /* atr is a two's complement value on 6 bits, 290 /* atr is a two's complement value on 6 bits,
316 * perform sign extension. The formula is 291 * perform sign extension. The formula is
@@ -319,11 +294,11 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
319 if (atr & 0x20) 294 if (atr & 0x20)
320 atr |= 0xC0; 295 atr |= 0xC0;
321 296
322 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __FUNCTION__, atr, atr); 297 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr);
323 298
324 *trim = (atr * 250) + 11000; 299 *trim = (atr * 250) + 11000;
325 300
326 dev_dbg(&client->dev, "%s: real=%d\n", __FUNCTION__, *trim); 301 dev_dbg(&client->dev, "%s: real=%d\n", __func__, *trim);
327 302
328 return 0; 303 return 0;
329} 304}
@@ -377,7 +352,7 @@ static int x1205_validate_client(struct i2c_client *client)
377 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 352 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
378 dev_err(&client->dev, 353 dev_err(&client->dev,
379 "%s: could not read register %x\n", 354 "%s: could not read register %x\n",
380 __FUNCTION__, probe_zero_pattern[i]); 355 __func__, probe_zero_pattern[i]);
381 356
382 return -EIO; 357 return -EIO;
383 } 358 }
@@ -385,7 +360,7 @@ static int x1205_validate_client(struct i2c_client *client)
385 if ((buf & probe_zero_pattern[i+1]) != 0) { 360 if ((buf & probe_zero_pattern[i+1]) != 0) {
386 dev_err(&client->dev, 361 dev_err(&client->dev,
387 "%s: register=%02x, zero pattern=%d, value=%x\n", 362 "%s: register=%02x, zero pattern=%d, value=%x\n",
388 __FUNCTION__, probe_zero_pattern[i], i, buf); 363 __func__, probe_zero_pattern[i], i, buf);
389 364
390 return -ENODEV; 365 return -ENODEV;
391 } 366 }
@@ -405,7 +380,7 @@ static int x1205_validate_client(struct i2c_client *client)
405 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 380 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
406 dev_err(&client->dev, 381 dev_err(&client->dev,
407 "%s: could not read register %x\n", 382 "%s: could not read register %x\n",
408 __FUNCTION__, probe_limits_pattern[i].reg); 383 __func__, probe_limits_pattern[i].reg);
409 384
410 return -EIO; 385 return -EIO;
411 } 386 }
@@ -416,7 +391,7 @@ static int x1205_validate_client(struct i2c_client *client)
416 value < probe_limits_pattern[i].min) { 391 value < probe_limits_pattern[i].min) {
417 dev_dbg(&client->dev, 392 dev_dbg(&client->dev,
418 "%s: register=%x, lim pattern=%d, value=%d\n", 393 "%s: register=%x, lim pattern=%d, value=%d\n",
419 __FUNCTION__, probe_limits_pattern[i].reg, 394 __func__, probe_limits_pattern[i].reg,
420 i, value); 395 i, value);
421 396
422 return -ENODEV; 397 return -ENODEV;
@@ -497,58 +472,50 @@ static ssize_t x1205_sysfs_show_dtrim(struct device *dev,
497} 472}
498static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL); 473static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
499 474
500static int x1205_attach(struct i2c_adapter *adapter) 475static int x1205_sysfs_register(struct device *dev)
501{ 476{
502 return i2c_probe(adapter, &addr_data, x1205_probe); 477 int err;
478
479 err = device_create_file(dev, &dev_attr_atrim);
480 if (err)
481 return err;
482
483 err = device_create_file(dev, &dev_attr_dtrim);
484 if (err)
485 device_remove_file(dev, &dev_attr_atrim);
486
487 return err;
503} 488}
504 489
505static int x1205_probe(struct i2c_adapter *adapter, int address, int kind) 490static void x1205_sysfs_unregister(struct device *dev)
491{
492 device_remove_file(dev, &dev_attr_atrim);
493 device_remove_file(dev, &dev_attr_dtrim);
494}
495
496
497static int x1205_probe(struct i2c_client *client,
498 const struct i2c_device_id *id)
506{ 499{
507 int err = 0; 500 int err = 0;
508 unsigned char sr; 501 unsigned char sr;
509 struct i2c_client *client;
510 struct rtc_device *rtc; 502 struct rtc_device *rtc;
511 503
512 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 504 dev_dbg(&client->dev, "%s\n", __func__);
513
514 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
515 err = -ENODEV;
516 goto exit;
517 }
518
519 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
520 err = -ENOMEM;
521 goto exit;
522 }
523
524 /* I2C client */
525 client->addr = address;
526 client->driver = &x1205_driver;
527 client->adapter = adapter;
528
529 strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE);
530 505
531 /* Verify the chip is really an X1205 */ 506 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
532 if (kind < 0) { 507 return -ENODEV;
533 if (x1205_validate_client(client) < 0) {
534 err = -ENODEV;
535 goto exit_kfree;
536 }
537 }
538 508
539 /* Inform the i2c layer */ 509 if (x1205_validate_client(client) < 0)
540 if ((err = i2c_attach_client(client))) 510 return -ENODEV;
541 goto exit_kfree;
542 511
543 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 512 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
544 513
545 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev, 514 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
546 &x1205_rtc_ops, THIS_MODULE); 515 &x1205_rtc_ops, THIS_MODULE);
547 516
548 if (IS_ERR(rtc)) { 517 if (IS_ERR(rtc))
549 err = PTR_ERR(rtc); 518 return PTR_ERR(rtc);
550 goto exit_detach;
551 }
552 519
553 i2c_set_clientdata(client, rtc); 520 i2c_set_clientdata(client, rtc);
554 521
@@ -565,45 +532,42 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
565 else 532 else
566 dev_err(&client->dev, "couldn't read status\n"); 533 dev_err(&client->dev, "couldn't read status\n");
567 534
568 err = device_create_file(&client->dev, &dev_attr_atrim); 535 err = x1205_sysfs_register(&client->dev);
569 if (err) goto exit_devreg; 536 if (err)
570 err = device_create_file(&client->dev, &dev_attr_dtrim); 537 goto exit_devreg;
571 if (err) goto exit_atrim;
572 538
573 return 0; 539 return 0;
574 540
575exit_atrim:
576 device_remove_file(&client->dev, &dev_attr_atrim);
577
578exit_devreg: 541exit_devreg:
579 rtc_device_unregister(rtc); 542 rtc_device_unregister(rtc);
580 543
581exit_detach:
582 i2c_detach_client(client);
583
584exit_kfree:
585 kfree(client);
586
587exit:
588 return err; 544 return err;
589} 545}
590 546
591static int x1205_detach(struct i2c_client *client) 547static int x1205_remove(struct i2c_client *client)
592{ 548{
593 int err;
594 struct rtc_device *rtc = i2c_get_clientdata(client); 549 struct rtc_device *rtc = i2c_get_clientdata(client);
595 550
596 if (rtc) 551 rtc_device_unregister(rtc);
597 rtc_device_unregister(rtc); 552 x1205_sysfs_unregister(&client->dev);
598
599 if ((err = i2c_detach_client(client)))
600 return err;
601
602 kfree(client);
603
604 return 0; 553 return 0;
605} 554}
606 555
556static const struct i2c_device_id x1205_id[] = {
557 { "x1205", 0 },
558 { }
559};
560MODULE_DEVICE_TABLE(i2c, x1205_id);
561
562static struct i2c_driver x1205_driver = {
563 .driver = {
564 .name = "rtc-x1205",
565 },
566 .probe = x1205_probe,
567 .remove = x1205_remove,
568 .id_table = x1205_id,
569};
570
607static int __init x1205_init(void) 571static int __init x1205_init(void)
608{ 572{
609 return i2c_add_driver(&x1205_driver); 573 return i2c_add_driver(&x1205_driver);