aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig34
-rw-r--r--drivers/rtc/Makefile5
-rw-r--r--drivers/rtc/rtc-at32ap700x.c4
-rw-r--r--drivers/rtc/rtc-bq32k.c204
-rw-r--r--drivers/rtc/rtc-bq4802.c3
-rw-r--r--drivers/rtc/rtc-cmos.c90
-rw-r--r--drivers/rtc/rtc-ds1302.c1
-rw-r--r--drivers/rtc/rtc-ds1305.c16
-rw-r--r--drivers/rtc/rtc-ds1307.c4
-rw-r--r--drivers/rtc/rtc-ds1374.c2
-rw-r--r--drivers/rtc/rtc-ds1511.c148
-rw-r--r--drivers/rtc/rtc-ds1553.c149
-rw-r--r--drivers/rtc/rtc-ds1742.c59
-rw-r--r--drivers/rtc/rtc-m48t35.c16
-rw-r--r--drivers/rtc/rtc-m48t59.c11
-rw-r--r--drivers/rtc/rtc-mc13783.c262
-rw-r--r--drivers/rtc/rtc-mv.c157
-rw-r--r--drivers/rtc/rtc-nuc900.c342
-rw-r--r--drivers/rtc/rtc-omap.c47
-rw-r--r--drivers/rtc/rtc-pcf50633.c10
-rw-r--r--drivers/rtc/rtc-pcf8563.c4
-rw-r--r--drivers/rtc/rtc-pcf8583.c3
-rw-r--r--drivers/rtc/rtc-pl031.c374
-rw-r--r--drivers/rtc/rtc-pxa.c2
-rw-r--r--drivers/rtc/rtc-sa1100.c2
-rw-r--r--drivers/rtc/rtc-sh.c2
-rw-r--r--drivers/rtc/rtc-stk17ta8.c124
-rw-r--r--drivers/rtc/rtc-twl.c (renamed from drivers/rtc/rtc-twl4030.c)284
-rw-r--r--drivers/rtc/rtc-tx4939.c51
-rw-r--r--drivers/rtc/rtc-v3020.c8
-rw-r--r--drivers/rtc/rtc-vr41xx.c4
-rw-r--r--drivers/rtc/rtc-wm831x.c2
-rw-r--r--drivers/rtc/rtc-wm8350.c39
-rw-r--r--drivers/rtc/rtc-x1205.c53
34 files changed, 1887 insertions, 629 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index f2e1004d12c7..8167e9e6827a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -242,6 +242,15 @@ config RTC_DRV_M41T80_WDT
242 If you say Y here you will get support for the 242 If you say Y here you will get support for the
243 watchdog timer in the ST M41T60 and M41T80 RTC chips series. 243 watchdog timer in the ST M41T60 and M41T80 RTC chips series.
244 244
245config RTC_DRV_BQ32K
246 tristate "TI BQ32000"
247 help
248 If you say Y here you will get support for the TI
249 BQ32000 I2C RTC chip.
250
251 This driver can also be built as a module. If so, the module
252 will be called rtc-bq32k.
253
245config RTC_DRV_DM355EVM 254config RTC_DRV_DM355EVM
246 tristate "TI DaVinci DM355 EVM RTC" 255 tristate "TI DaVinci DM355 EVM RTC"
247 depends on MFD_DM355EVM_MSP 256 depends on MFD_DM355EVM_MSP
@@ -258,14 +267,14 @@ config RTC_DRV_TWL92330
258 the Menelaus driver; it's not separate module. 267 the Menelaus driver; it's not separate module.
259 268
260config RTC_DRV_TWL4030 269config RTC_DRV_TWL4030
261 tristate "TI TWL4030/TWL5030/TPS659x0" 270 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0"
262 depends on RTC_CLASS && TWL4030_CORE 271 depends on RTC_CLASS && TWL4030_CORE
263 help 272 help
264 If you say yes here you get support for the RTC on the 273 If you say yes here you get support for the RTC on the
265 TWL4030 family chips, used mostly with OMAP3 platforms. 274 TWL4030/TWL5030/TWL6030 family chips, used mostly with OMAP3 platforms.
266 275
267 This driver can also be built as a module. If so, the module 276 This driver can also be built as a module. If so, the module
268 will be called rtc-twl4030. 277 will be called rtc-twl.
269 278
270config RTC_DRV_S35390A 279config RTC_DRV_S35390A
271 tristate "Seiko Instruments S-35390A" 280 tristate "Seiko Instruments S-35390A"
@@ -592,15 +601,22 @@ config RTC_DRV_AB3100
592 Select this to enable the ST-Ericsson AB3100 Mixed Signal IC RTC 601 Select this to enable the ST-Ericsson AB3100 Mixed Signal IC RTC
593 support. This chip contains a battery- and capacitor-backed RTC. 602 support. This chip contains a battery- and capacitor-backed RTC.
594 603
604config RTC_DRV_NUC900
605 tristate "NUC910/NUC920 RTC driver"
606 depends on RTC_CLASS && ARCH_W90X900
607 help
608 If you say yes here you get support for the RTC subsystem of the
609 NUC910/NUC920 used in embedded systems.
595 610
596comment "on-CPU RTC drivers" 611comment "on-CPU RTC drivers"
597 612
598config RTC_DRV_OMAP 613config RTC_DRV_OMAP
599 tristate "TI OMAP1" 614 tristate "TI OMAP1"
600 depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 615 depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX
601 help 616 help
602 Say "yes" here to support the real time clock on TI OMAP1 chips. 617 Say "yes" here to support the real time clock on TI OMAP1 and
603 This driver can also be built as a module called rtc-omap. 618 DA8xx/OMAP-L13x chips. This driver can also be built as a
619 module called rtc-omap.
604 620
605config RTC_DRV_S3C 621config RTC_DRV_S3C
606 tristate "Samsung S3C series SoC RTC" 622 tristate "Samsung S3C series SoC RTC"
@@ -846,4 +862,10 @@ config RTC_DRV_PCAP
846 If you say Y here you will get support for the RTC found on 862 If you say Y here you will get support for the RTC found on
847 the PCAP2 ASIC used on some Motorola phones. 863 the PCAP2 ASIC used on some Motorola phones.
848 864
865config RTC_DRV_MC13783
866 depends on MFD_MC13783
867 tristate "Freescale MC13783 RTC"
868 help
869 This enables support for the Freescale MC13783 PMIC RTC
870
849endif # RTC_CLASS 871endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index af1ba7ae2857..e5160fddc446 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
23obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o 23obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
24obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o 24obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o
25obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o 25obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o
26obj-$(CONFIG_RTC_DRV_BQ32K) += rtc-bq32k.o
26obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o 27obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o
27obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 28obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
28obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o 29obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o
@@ -52,8 +53,10 @@ obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
52obj-$(CONFIG_RTC_MXC) += rtc-mxc.o 53obj-$(CONFIG_RTC_MXC) += rtc-mxc.o
53obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o 54obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
54obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 55obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
56obj-$(CONFIG_RTC_DRV_MC13783) += rtc-mc13783.o
55obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o 57obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o
56obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o 58obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o
59obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o
57obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o 60obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o
58obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o 61obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o
59obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 62obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
@@ -80,7 +83,7 @@ obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
80obj-$(CONFIG_RTC_DRV_STMP) += rtc-stmp3xxx.o 83obj-$(CONFIG_RTC_DRV_STMP) += rtc-stmp3xxx.o
81obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o 84obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o
82obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 85obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
83obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl4030.o 86obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o
84obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o 87obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o
85obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 88obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
86obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 89obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
index e1ec33e40e38..8825695777df 100644
--- a/drivers/rtc/rtc-at32ap700x.c
+++ b/drivers/rtc/rtc-at32ap700x.c
@@ -256,6 +256,8 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
256 goto out_iounmap; 256 goto out_iounmap;
257 } 257 }
258 258
259 platform_set_drvdata(pdev, rtc);
260
259 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 261 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
260 &at32_rtc_ops, THIS_MODULE); 262 &at32_rtc_ops, THIS_MODULE);
261 if (IS_ERR(rtc->rtc)) { 263 if (IS_ERR(rtc->rtc)) {
@@ -264,7 +266,6 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
264 goto out_free_irq; 266 goto out_free_irq;
265 } 267 }
266 268
267 platform_set_drvdata(pdev, rtc);
268 device_init_wakeup(&pdev->dev, 1); 269 device_init_wakeup(&pdev->dev, 1);
269 270
270 dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n", 271 dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n",
@@ -273,6 +274,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
273 return 0; 274 return 0;
274 275
275out_free_irq: 276out_free_irq:
277 platform_set_drvdata(pdev, NULL);
276 free_irq(irq, rtc); 278 free_irq(irq, rtc);
277out_iounmap: 279out_iounmap:
278 iounmap(rtc->regs); 280 iounmap(rtc->regs);
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
new file mode 100644
index 000000000000..408cc8f735be
--- /dev/null
+++ b/drivers/rtc/rtc-bq32k.c
@@ -0,0 +1,204 @@
1/*
2 * Driver for TI BQ32000 RTC.
3 *
4 * Copyright (C) 2009 Semihalf.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/i2c.h>
13#include <linux/rtc.h>
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/bcd.h>
17
18#define BQ32K_SECONDS 0x00 /* Seconds register address */
19#define BQ32K_SECONDS_MASK 0x7F /* Mask over seconds value */
20#define BQ32K_STOP 0x80 /* Oscillator Stop flat */
21
22#define BQ32K_MINUTES 0x01 /* Minutes register address */
23#define BQ32K_MINUTES_MASK 0x7F /* Mask over minutes value */
24#define BQ32K_OF 0x80 /* Oscillator Failure flag */
25
26#define BQ32K_HOURS_MASK 0x3F /* Mask over hours value */
27#define BQ32K_CENT 0x40 /* Century flag */
28#define BQ32K_CENT_EN 0x80 /* Century flag enable bit */
29
30struct bq32k_regs {
31 uint8_t seconds;
32 uint8_t minutes;
33 uint8_t cent_hours;
34 uint8_t day;
35 uint8_t date;
36 uint8_t month;
37 uint8_t years;
38};
39
40static struct i2c_driver bq32k_driver;
41
42static int bq32k_read(struct device *dev, void *data, uint8_t off, uint8_t len)
43{
44 struct i2c_client *client = to_i2c_client(dev);
45 struct i2c_msg msgs[] = {
46 {
47 .addr = client->addr,
48 .flags = 0,
49 .len = 1,
50 .buf = &off,
51 }, {
52 .addr = client->addr,
53 .flags = I2C_M_RD,
54 .len = len,
55 .buf = data,
56 }
57 };
58
59 if (i2c_transfer(client->adapter, msgs, 2) == 2)
60 return 0;
61
62 return -EIO;
63}
64
65static int bq32k_write(struct device *dev, void *data, uint8_t off, uint8_t len)
66{
67 struct i2c_client *client = to_i2c_client(dev);
68 uint8_t buffer[len + 1];
69
70 buffer[0] = off;
71 memcpy(&buffer[1], data, len);
72
73 if (i2c_master_send(client, buffer, len + 1) == len + 1)
74 return 0;
75
76 return -EIO;
77}
78
79static int bq32k_rtc_read_time(struct device *dev, struct rtc_time *tm)
80{
81 struct bq32k_regs regs;
82 int error;
83
84 error = bq32k_read(dev, &regs, 0, sizeof(regs));
85 if (error)
86 return error;
87
88 tm->tm_sec = bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
89 tm->tm_min = bcd2bin(regs.minutes & BQ32K_SECONDS_MASK);
90 tm->tm_hour = bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
91 tm->tm_mday = bcd2bin(regs.date);
92 tm->tm_wday = bcd2bin(regs.day) - 1;
93 tm->tm_mon = bcd2bin(regs.month) - 1;
94 tm->tm_year = bcd2bin(regs.years) +
95 ((regs.cent_hours & BQ32K_CENT) ? 100 : 0);
96
97 return rtc_valid_tm(tm);
98}
99
100static int bq32k_rtc_set_time(struct device *dev, struct rtc_time *tm)
101{
102 struct bq32k_regs regs;
103
104 regs.seconds = bin2bcd(tm->tm_sec);
105 regs.minutes = bin2bcd(tm->tm_min);
106 regs.cent_hours = bin2bcd(tm->tm_hour) | BQ32K_CENT_EN;
107 regs.day = bin2bcd(tm->tm_wday + 1);
108 regs.date = bin2bcd(tm->tm_mday);
109 regs.month = bin2bcd(tm->tm_mon + 1);
110
111 if (tm->tm_year >= 100) {
112 regs.cent_hours |= BQ32K_CENT;
113 regs.years = bin2bcd(tm->tm_year - 100);
114 } else
115 regs.years = bin2bcd(tm->tm_year);
116
117 return bq32k_write(dev, &regs, 0, sizeof(regs));
118}
119
120static const struct rtc_class_ops bq32k_rtc_ops = {
121 .read_time = bq32k_rtc_read_time,
122 .set_time = bq32k_rtc_set_time,
123};
124
125static int bq32k_probe(struct i2c_client *client,
126 const struct i2c_device_id *id)
127{
128 struct device *dev = &client->dev;
129 struct rtc_device *rtc;
130 uint8_t reg;
131 int error;
132
133 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
134 return -ENODEV;
135
136 /* Check Oscillator Stop flag */
137 error = bq32k_read(dev, &reg, BQ32K_SECONDS, 1);
138 if (!error && (reg & BQ32K_STOP)) {
139 dev_warn(dev, "Oscillator was halted. Restarting...\n");
140 reg &= ~BQ32K_STOP;
141 error = bq32k_write(dev, &reg, BQ32K_SECONDS, 1);
142 }
143 if (error)
144 return error;
145
146 /* Check Oscillator Failure flag */
147 error = bq32k_read(dev, &reg, BQ32K_MINUTES, 1);
148 if (!error && (reg & BQ32K_OF)) {
149 dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
150 reg &= ~BQ32K_OF;
151 error = bq32k_write(dev, &reg, BQ32K_MINUTES, 1);
152 }
153 if (error)
154 return error;
155
156 rtc = rtc_device_register(bq32k_driver.driver.name, &client->dev,
157 &bq32k_rtc_ops, THIS_MODULE);
158 if (IS_ERR(rtc))
159 return PTR_ERR(rtc);
160
161 i2c_set_clientdata(client, rtc);
162
163 return 0;
164}
165
166static int __devexit bq32k_remove(struct i2c_client *client)
167{
168 struct rtc_device *rtc = i2c_get_clientdata(client);
169
170 rtc_device_unregister(rtc);
171 return 0;
172}
173
174static const struct i2c_device_id bq32k_id[] = {
175 { "bq32000", 0 },
176 { }
177};
178MODULE_DEVICE_TABLE(i2c, bq32k_id);
179
180static struct i2c_driver bq32k_driver = {
181 .driver = {
182 .name = "bq32k",
183 .owner = THIS_MODULE,
184 },
185 .probe = bq32k_probe,
186 .remove = __devexit_p(bq32k_remove),
187 .id_table = bq32k_id,
188};
189
190static __init int bq32k_init(void)
191{
192 return i2c_add_driver(&bq32k_driver);
193}
194module_init(bq32k_init);
195
196static __exit void bq32k_exit(void)
197{
198 i2c_del_driver(&bq32k_driver);
199}
200module_exit(bq32k_exit);
201
202MODULE_AUTHOR("Semihalf, Piotr Ziecik <kosmo@semihalf.com>");
203MODULE_DESCRIPTION("TI BQ32000 I2C RTC driver");
204MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index d00a274df8fc..280fe48ada0b 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -169,6 +169,8 @@ static int __devinit bq4802_probe(struct platform_device *pdev)
169 goto out_free; 169 goto out_free;
170 } 170 }
171 171
172 platform_set_drvdata(pdev, p);
173
172 p->rtc = rtc_device_register("bq4802", &pdev->dev, 174 p->rtc = rtc_device_register("bq4802", &pdev->dev,
173 &bq4802_ops, THIS_MODULE); 175 &bq4802_ops, THIS_MODULE);
174 if (IS_ERR(p->rtc)) { 176 if (IS_ERR(p->rtc)) {
@@ -176,7 +178,6 @@ static int __devinit bq4802_probe(struct platform_device *pdev)
176 goto out_iounmap; 178 goto out_iounmap;
177 } 179 }
178 180
179 platform_set_drvdata(pdev, p);
180 err = 0; 181 err = 0;
181out: 182out:
182 return err; 183 return err;
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index f7a4701bf863..e9aa814ddd23 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -420,49 +420,43 @@ static int cmos_irq_set_state(struct device *dev, int enabled)
420 return 0; 420 return 0;
421} 421}
422 422
423#if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE) 423static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled)
424
425static int
426cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
427{ 424{
428 struct cmos_rtc *cmos = dev_get_drvdata(dev); 425 struct cmos_rtc *cmos = dev_get_drvdata(dev);
429 unsigned long flags; 426 unsigned long flags;
430 427
431 switch (cmd) { 428 if (!is_valid_irq(cmos->irq))
432 case RTC_AIE_OFF: 429 return -EINVAL;
433 case RTC_AIE_ON:
434 case RTC_UIE_OFF:
435 case RTC_UIE_ON:
436 if (!is_valid_irq(cmos->irq))
437 return -EINVAL;
438 break;
439 /* PIE ON/OFF is handled by cmos_irq_set_state() */
440 default:
441 return -ENOIOCTLCMD;
442 }
443 430
444 spin_lock_irqsave(&rtc_lock, flags); 431 spin_lock_irqsave(&rtc_lock, flags);
445 switch (cmd) { 432
446 case RTC_AIE_OFF: /* alarm off */ 433 if (enabled)
447 cmos_irq_disable(cmos, RTC_AIE);
448 break;
449 case RTC_AIE_ON: /* alarm on */
450 cmos_irq_enable(cmos, RTC_AIE); 434 cmos_irq_enable(cmos, RTC_AIE);
451 break; 435 else
452 case RTC_UIE_OFF: /* update off */ 436 cmos_irq_disable(cmos, RTC_AIE);
453 cmos_irq_disable(cmos, RTC_UIE); 437
454 break;
455 case RTC_UIE_ON: /* update on */
456 cmos_irq_enable(cmos, RTC_UIE);
457 break;
458 }
459 spin_unlock_irqrestore(&rtc_lock, flags); 438 spin_unlock_irqrestore(&rtc_lock, flags);
460 return 0; 439 return 0;
461} 440}
462 441
463#else 442static int cmos_update_irq_enable(struct device *dev, unsigned int enabled)
464#define cmos_rtc_ioctl NULL 443{
465#endif 444 struct cmos_rtc *cmos = dev_get_drvdata(dev);
445 unsigned long flags;
446
447 if (!is_valid_irq(cmos->irq))
448 return -EINVAL;
449
450 spin_lock_irqsave(&rtc_lock, flags);
451
452 if (enabled)
453 cmos_irq_enable(cmos, RTC_UIE);
454 else
455 cmos_irq_disable(cmos, RTC_UIE);
456
457 spin_unlock_irqrestore(&rtc_lock, flags);
458 return 0;
459}
466 460
467#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 461#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
468 462
@@ -503,14 +497,15 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq)
503#endif 497#endif
504 498
505static const struct rtc_class_ops cmos_rtc_ops = { 499static const struct rtc_class_ops cmos_rtc_ops = {
506 .ioctl = cmos_rtc_ioctl, 500 .read_time = cmos_read_time,
507 .read_time = cmos_read_time, 501 .set_time = cmos_set_time,
508 .set_time = cmos_set_time, 502 .read_alarm = cmos_read_alarm,
509 .read_alarm = cmos_read_alarm, 503 .set_alarm = cmos_set_alarm,
510 .set_alarm = cmos_set_alarm, 504 .proc = cmos_procfs,
511 .proc = cmos_procfs, 505 .irq_set_freq = cmos_irq_set_freq,
512 .irq_set_freq = cmos_irq_set_freq, 506 .irq_set_state = cmos_irq_set_state,
513 .irq_set_state = cmos_irq_set_state, 507 .alarm_irq_enable = cmos_alarm_irq_enable,
508 .update_irq_enable = cmos_update_irq_enable,
514}; 509};
515 510
516/*----------------------------------------------------------------*/ 511/*----------------------------------------------------------------*/
@@ -691,7 +686,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
691 */ 686 */
692#if defined(CONFIG_ATARI) 687#if defined(CONFIG_ATARI)
693 address_space = 64; 688 address_space = 64;
694#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__sparc__) 689#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) \
690 || defined(__sparc__) || defined(__mips__)
695 address_space = 128; 691 address_space = 128;
696#else 692#else
697#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. 693#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes.
@@ -871,8 +867,9 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
871 mask = RTC_IRQMASK; 867 mask = RTC_IRQMASK;
872 tmp &= ~mask; 868 tmp &= ~mask;
873 CMOS_WRITE(tmp, RTC_CONTROL); 869 CMOS_WRITE(tmp, RTC_CONTROL);
874 hpet_mask_rtc_irq_bit(mask);
875 870
871 /* shut down hpet emulation - we don't need it for alarm */
872 hpet_mask_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE);
876 cmos_checkintr(cmos, tmp); 873 cmos_checkintr(cmos, tmp);
877 } 874 }
878 spin_unlock_irq(&rtc_lock); 875 spin_unlock_irq(&rtc_lock);
@@ -1099,9 +1096,9 @@ static int cmos_pnp_resume(struct pnp_dev *pnp)
1099#define cmos_pnp_resume NULL 1096#define cmos_pnp_resume NULL
1100#endif 1097#endif
1101 1098
1102static void cmos_pnp_shutdown(struct device *pdev) 1099static void cmos_pnp_shutdown(struct pnp_dev *pnp)
1103{ 1100{
1104 if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(pdev)) 1101 if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(&pnp->dev))
1105 return; 1102 return;
1106 1103
1107 cmos_do_shutdown(); 1104 cmos_do_shutdown();
@@ -1120,15 +1117,12 @@ static struct pnp_driver cmos_pnp_driver = {
1120 .id_table = rtc_ids, 1117 .id_table = rtc_ids,
1121 .probe = cmos_pnp_probe, 1118 .probe = cmos_pnp_probe,
1122 .remove = __exit_p(cmos_pnp_remove), 1119 .remove = __exit_p(cmos_pnp_remove),
1120 .shutdown = cmos_pnp_shutdown,
1123 1121
1124 /* flag ensures resume() gets called, and stops syslog spam */ 1122 /* flag ensures resume() gets called, and stops syslog spam */
1125 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, 1123 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
1126 .suspend = cmos_pnp_suspend, 1124 .suspend = cmos_pnp_suspend,
1127 .resume = cmos_pnp_resume, 1125 .resume = cmos_pnp_resume,
1128 .driver = {
1129 .name = (char *)driver_name,
1130 .shutdown = cmos_pnp_shutdown,
1131 }
1132}; 1126};
1133 1127
1134#endif /* CONFIG_PNP */ 1128#endif /* CONFIG_PNP */
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index 1e73c8f42e38..532acf9b05d8 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -143,7 +143,6 @@ static int ds1302_rtc_ioctl(struct device *dev, unsigned int cmd,
143#ifdef RTC_SET_CHARGE 143#ifdef RTC_SET_CHARGE
144 case RTC_SET_CHARGE: 144 case RTC_SET_CHARGE:
145 { 145 {
146 struct ds1302_rtc *rtc = dev_get_drvdata(dev);
147 int tcs_val; 146 int tcs_val;
148 147
149 if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int))) 148 if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index 2736b11a1b1e..9630e7d3314e 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -617,7 +617,6 @@ static struct bin_attribute nvram = {
617static int __devinit ds1305_probe(struct spi_device *spi) 617static int __devinit ds1305_probe(struct spi_device *spi)
618{ 618{
619 struct ds1305 *ds1305; 619 struct ds1305 *ds1305;
620 struct rtc_device *rtc;
621 int status; 620 int status;
622 u8 addr, value; 621 u8 addr, value;
623 struct ds1305_platform_data *pdata = spi->dev.platform_data; 622 struct ds1305_platform_data *pdata = spi->dev.platform_data;
@@ -756,14 +755,13 @@ static int __devinit ds1305_probe(struct spi_device *spi)
756 dev_dbg(&spi->dev, "AM/PM\n"); 755 dev_dbg(&spi->dev, "AM/PM\n");
757 756
758 /* register RTC ... from here on, ds1305->ctrl needs locking */ 757 /* register RTC ... from here on, ds1305->ctrl needs locking */
759 rtc = rtc_device_register("ds1305", &spi->dev, 758 ds1305->rtc = rtc_device_register("ds1305", &spi->dev,
760 &ds1305_ops, THIS_MODULE); 759 &ds1305_ops, THIS_MODULE);
761 if (IS_ERR(rtc)) { 760 if (IS_ERR(ds1305->rtc)) {
762 status = PTR_ERR(rtc); 761 status = PTR_ERR(ds1305->rtc);
763 dev_dbg(&spi->dev, "register rtc --> %d\n", status); 762 dev_dbg(&spi->dev, "register rtc --> %d\n", status);
764 goto fail0; 763 goto fail0;
765 } 764 }
766 ds1305->rtc = rtc;
767 765
768 /* Maybe set up alarm IRQ; be ready to handle it triggering right 766 /* Maybe set up alarm IRQ; be ready to handle it triggering right
769 * away. NOTE that we don't share this. The signal is active low, 767 * away. NOTE that we don't share this. The signal is active low,
@@ -774,12 +772,14 @@ static int __devinit ds1305_probe(struct spi_device *spi)
774 if (spi->irq) { 772 if (spi->irq) {
775 INIT_WORK(&ds1305->work, ds1305_work); 773 INIT_WORK(&ds1305->work, ds1305_work);
776 status = request_irq(spi->irq, ds1305_irq, 774 status = request_irq(spi->irq, ds1305_irq,
777 0, dev_name(&rtc->dev), ds1305); 775 0, dev_name(&ds1305->rtc->dev), ds1305);
778 if (status < 0) { 776 if (status < 0) {
779 dev_dbg(&spi->dev, "request_irq %d --> %d\n", 777 dev_dbg(&spi->dev, "request_irq %d --> %d\n",
780 spi->irq, status); 778 spi->irq, status);
781 goto fail1; 779 goto fail1;
782 } 780 }
781
782 device_set_wakeup_capable(&spi->dev, 1);
783 } 783 }
784 784
785 /* export NVRAM */ 785 /* export NVRAM */
@@ -794,7 +794,7 @@ static int __devinit ds1305_probe(struct spi_device *spi)
794fail2: 794fail2:
795 free_irq(spi->irq, ds1305); 795 free_irq(spi->irq, ds1305);
796fail1: 796fail1:
797 rtc_device_unregister(rtc); 797 rtc_device_unregister(ds1305->rtc);
798fail0: 798fail0:
799 kfree(ds1305); 799 kfree(ds1305);
800 return status; 800 return status;
@@ -802,7 +802,7 @@ fail0:
802 802
803static int __devexit ds1305_remove(struct spi_device *spi) 803static int __devexit ds1305_remove(struct spi_device *spi)
804{ 804{
805 struct ds1305 *ds1305 = spi_get_drvdata(spi); 805 struct ds1305 *ds1305 = spi_get_drvdata(spi);
806 806
807 sysfs_remove_bin_file(&spi->dev.kobj, &nvram); 807 sysfs_remove_bin_file(&spi->dev.kobj, &nvram);
808 808
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index eb99ee4fa0f5..c4ec5c158aa1 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -874,13 +874,15 @@ read_rtc:
874 } 874 }
875 875
876 if (want_irq) { 876 if (want_irq) {
877 err = request_irq(client->irq, ds1307_irq, 0, 877 err = request_irq(client->irq, ds1307_irq, IRQF_SHARED,
878 ds1307->rtc->name, client); 878 ds1307->rtc->name, client);
879 if (err) { 879 if (err) {
880 dev_err(&client->dev, 880 dev_err(&client->dev,
881 "unable to request IRQ!\n"); 881 "unable to request IRQ!\n");
882 goto exit_irq; 882 goto exit_irq;
883 } 883 }
884
885 device_set_wakeup_capable(&client->dev, 1);
884 set_bit(HAS_ALARM, &ds1307->flags); 886 set_bit(HAS_ALARM, &ds1307->flags);
885 dev_dbg(&client->dev, "got IRQ %d\n", client->irq); 887 dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
886 } 888 }
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 713f7bf5afb3..5317bbcbc7a0 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -383,6 +383,8 @@ static int ds1374_probe(struct i2c_client *client,
383 dev_err(&client->dev, "unable to request IRQ\n"); 383 dev_err(&client->dev, "unable to request IRQ\n");
384 goto out_free; 384 goto out_free;
385 } 385 }
386
387 device_set_wakeup_capable(&client->dev, 1);
386 } 388 }
387 389
388 ds1374->rtc = rtc_device_register(client->name, &client->dev, 390 ds1374->rtc = rtc_device_register(client->name, &client->dev,
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 539676e25fd8..4166b84cb514 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -87,7 +87,6 @@ enum ds1511reg {
87struct rtc_plat_data { 87struct rtc_plat_data {
88 struct rtc_device *rtc; 88 struct rtc_device *rtc;
89 void __iomem *ioaddr; /* virtual base address */ 89 void __iomem *ioaddr; /* virtual base address */
90 unsigned long baseaddr; /* physical base address */
91 int size; /* amount of memory mapped */ 90 int size; /* amount of memory mapped */
92 int irq; 91 int irq;
93 unsigned int irqen; 92 unsigned int irqen;
@@ -95,6 +94,7 @@ struct rtc_plat_data {
95 int alrm_min; 94 int alrm_min;
96 int alrm_hour; 95 int alrm_hour;
97 int alrm_mday; 96 int alrm_mday;
97 spinlock_t lock;
98}; 98};
99 99
100static DEFINE_SPINLOCK(ds1511_lock); 100static DEFINE_SPINLOCK(ds1511_lock);
@@ -302,7 +302,7 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
302{ 302{
303 unsigned long flags; 303 unsigned long flags;
304 304
305 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); 305 spin_lock_irqsave(&pdata->lock, flags);
306 rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 306 rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
307 0x80 : bin2bcd(pdata->alrm_mday) & 0x3f, 307 0x80 : bin2bcd(pdata->alrm_mday) & 0x3f,
308 RTC_ALARM_DATE); 308 RTC_ALARM_DATE);
@@ -317,7 +317,7 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
317 RTC_ALARM_SEC); 317 RTC_ALARM_SEC);
318 rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD); 318 rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD);
319 rtc_read(RTC_CMD1); /* clear interrupts */ 319 rtc_read(RTC_CMD1); /* clear interrupts */
320 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); 320 spin_unlock_irqrestore(&pdata->lock, flags);
321} 321}
322 322
323 static int 323 static int
@@ -362,61 +362,63 @@ ds1511_interrupt(int irq, void *dev_id)
362{ 362{
363 struct platform_device *pdev = dev_id; 363 struct platform_device *pdev = dev_id;
364 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 364 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
365 unsigned long events = RTC_IRQF; 365 unsigned long events = 0;
366 366
367 spin_lock(&pdata->lock);
367 /* 368 /*
368 * read and clear interrupt 369 * read and clear interrupt
369 */ 370 */
370 if (!(rtc_read(RTC_CMD1) & DS1511_IRQF)) { 371 if (rtc_read(RTC_CMD1) & DS1511_IRQF) {
371 return IRQ_NONE; 372 events = RTC_IRQF;
372 } 373 if (rtc_read(RTC_ALARM_SEC) & 0x80)
373 if (rtc_read(RTC_ALARM_SEC) & 0x80) { 374 events |= RTC_UF;
374 events |= RTC_UF; 375 else
375 } else { 376 events |= RTC_AF;
376 events |= RTC_AF; 377 if (likely(pdata->rtc))
377 } 378 rtc_update_irq(pdata->rtc, 1, events);
378 rtc_update_irq(pdata->rtc, 1, events); 379 }
379 return IRQ_HANDLED; 380 spin_unlock(&pdata->lock);
381 return events ? IRQ_HANDLED : IRQ_NONE;
380} 382}
381 383
382 static int 384static int ds1511_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
383ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
384{ 385{
385 struct platform_device *pdev = to_platform_device(dev); 386 struct platform_device *pdev = to_platform_device(dev);
386 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 387 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
387 388
388 if (pdata->irq <= 0) { 389 if (pdata->irq <= 0)
389 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */ 390 return -EINVAL;
390 } 391 if (enabled)
391 switch (cmd) {
392 case RTC_AIE_OFF:
393 pdata->irqen &= ~RTC_AF;
394 ds1511_rtc_update_alarm(pdata);
395 break;
396 case RTC_AIE_ON:
397 pdata->irqen |= RTC_AF; 392 pdata->irqen |= RTC_AF;
398 ds1511_rtc_update_alarm(pdata); 393 else
399 break; 394 pdata->irqen &= ~RTC_AF;
400 case RTC_UIE_OFF: 395 ds1511_rtc_update_alarm(pdata);
401 pdata->irqen &= ~RTC_UF; 396 return 0;
402 ds1511_rtc_update_alarm(pdata); 397}
403 break; 398
404 case RTC_UIE_ON: 399static int ds1511_rtc_update_irq_enable(struct device *dev,
400 unsigned int enabled)
401{
402 struct platform_device *pdev = to_platform_device(dev);
403 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
404
405 if (pdata->irq <= 0)
406 return -EINVAL;
407 if (enabled)
405 pdata->irqen |= RTC_UF; 408 pdata->irqen |= RTC_UF;
406 ds1511_rtc_update_alarm(pdata); 409 else
407 break; 410 pdata->irqen &= ~RTC_UF;
408 default: 411 ds1511_rtc_update_alarm(pdata);
409 return -ENOIOCTLCMD;
410 }
411 return 0; 412 return 0;
412} 413}
413 414
414static const struct rtc_class_ops ds1511_rtc_ops = { 415static const struct rtc_class_ops ds1511_rtc_ops = {
415 .read_time = ds1511_rtc_read_time, 416 .read_time = ds1511_rtc_read_time,
416 .set_time = ds1511_rtc_set_time, 417 .set_time = ds1511_rtc_set_time,
417 .read_alarm = ds1511_rtc_read_alarm, 418 .read_alarm = ds1511_rtc_read_alarm,
418 .set_alarm = ds1511_rtc_set_alarm, 419 .set_alarm = ds1511_rtc_set_alarm,
419 .ioctl = ds1511_rtc_ioctl, 420 .alarm_irq_enable = ds1511_rtc_alarm_irq_enable,
421 .update_irq_enable = ds1511_rtc_update_irq_enable,
420}; 422};
421 423
422 static ssize_t 424 static ssize_t
@@ -492,29 +494,23 @@ ds1511_rtc_probe(struct platform_device *pdev)
492{ 494{
493 struct rtc_device *rtc; 495 struct rtc_device *rtc;
494 struct resource *res; 496 struct resource *res;
495 struct rtc_plat_data *pdata = NULL; 497 struct rtc_plat_data *pdata;
496 int ret = 0; 498 int ret = 0;
497 499
498 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 500 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
499 if (!res) { 501 if (!res) {
500 return -ENODEV; 502 return -ENODEV;
501 } 503 }
502 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 504 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
503 if (!pdata) { 505 if (!pdata)
504 return -ENOMEM; 506 return -ENOMEM;
505 }
506 pdata->size = res->end - res->start + 1; 507 pdata->size = res->end - res->start + 1;
507 if (!request_mem_region(res->start, pdata->size, pdev->name)) { 508 if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size,
508 ret = -EBUSY; 509 pdev->name))
509 goto out; 510 return -EBUSY;
510 } 511 ds1511_base = devm_ioremap(&pdev->dev, res->start, pdata->size);
511 pdata->baseaddr = res->start; 512 if (!ds1511_base)
512 pdata->size = pdata->size; 513 return -ENOMEM;
513 ds1511_base = ioremap(pdata->baseaddr, pdata->size);
514 if (!ds1511_base) {
515 ret = -ENOMEM;
516 goto out;
517 }
518 pdata->ioaddr = ds1511_base; 514 pdata->ioaddr = ds1511_base;
519 pdata->irq = platform_get_irq(pdev, 0); 515 pdata->irq = platform_get_irq(pdev, 0);
520 516
@@ -540,13 +536,15 @@ ds1511_rtc_probe(struct platform_device *pdev)
540 dev_warn(&pdev->dev, "voltage-low detected.\n"); 536 dev_warn(&pdev->dev, "voltage-low detected.\n");
541 } 537 }
542 538
539 spin_lock_init(&pdata->lock);
540 platform_set_drvdata(pdev, pdata);
543 /* 541 /*
544 * if the platform has an interrupt in mind for this device, 542 * if the platform has an interrupt in mind for this device,
545 * then by all means, set it 543 * then by all means, set it
546 */ 544 */
547 if (pdata->irq > 0) { 545 if (pdata->irq > 0) {
548 rtc_read(RTC_CMD1); 546 rtc_read(RTC_CMD1);
549 if (request_irq(pdata->irq, ds1511_interrupt, 547 if (devm_request_irq(&pdev->dev, pdata->irq, ds1511_interrupt,
550 IRQF_DISABLED | IRQF_SHARED, pdev->name, pdev) < 0) { 548 IRQF_DISABLED | IRQF_SHARED, pdev->name, pdev) < 0) {
551 549
552 dev_warn(&pdev->dev, "interrupt not available.\n"); 550 dev_warn(&pdev->dev, "interrupt not available.\n");
@@ -556,33 +554,13 @@ ds1511_rtc_probe(struct platform_device *pdev)
556 554
557 rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops, 555 rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops,
558 THIS_MODULE); 556 THIS_MODULE);
559 if (IS_ERR(rtc)) { 557 if (IS_ERR(rtc))
560 ret = PTR_ERR(rtc); 558 return PTR_ERR(rtc);
561 goto out;
562 }
563 pdata->rtc = rtc; 559 pdata->rtc = rtc;
564 platform_set_drvdata(pdev, pdata); 560
565 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 561 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
566 if (ret) { 562 if (ret)
567 goto out;
568 }
569 return 0;
570 out:
571 if (pdata->rtc) {
572 rtc_device_unregister(pdata->rtc); 563 rtc_device_unregister(pdata->rtc);
573 }
574 if (pdata->irq > 0) {
575 free_irq(pdata->irq, pdev);
576 }
577 if (ds1511_base) {
578 iounmap(ds1511_base);
579 ds1511_base = NULL;
580 }
581 if (pdata->baseaddr) {
582 release_mem_region(pdata->baseaddr, pdata->size);
583 }
584
585 kfree(pdata);
586 return ret; 564 return ret;
587} 565}
588 566
@@ -593,19 +571,13 @@ ds1511_rtc_remove(struct platform_device *pdev)
593 571
594 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 572 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
595 rtc_device_unregister(pdata->rtc); 573 rtc_device_unregister(pdata->rtc);
596 pdata->rtc = NULL;
597 if (pdata->irq > 0) { 574 if (pdata->irq > 0) {
598 /* 575 /*
599 * disable the alarm interrupt 576 * disable the alarm interrupt
600 */ 577 */
601 rtc_write(rtc_read(RTC_CMD) & ~RTC_TIE, RTC_CMD); 578 rtc_write(rtc_read(RTC_CMD) & ~RTC_TIE, RTC_CMD);
602 rtc_read(RTC_CMD1); 579 rtc_read(RTC_CMD1);
603 free_irq(pdata->irq, pdev);
604 } 580 }
605 iounmap(pdata->ioaddr);
606 ds1511_base = NULL;
607 release_mem_region(pdata->baseaddr, pdata->size);
608 kfree(pdata);
609 return 0; 581 return 0;
610} 582}
611 583
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 717288527c6b..ed1ef7c9cc06 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -18,7 +18,7 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/io.h> 19#include <linux/io.h>
20 20
21#define DRV_VERSION "0.2" 21#define DRV_VERSION "0.3"
22 22
23#define RTC_REG_SIZE 0x2000 23#define RTC_REG_SIZE 0x2000
24#define RTC_OFFSET 0x1ff0 24#define RTC_OFFSET 0x1ff0
@@ -61,7 +61,6 @@
61struct rtc_plat_data { 61struct rtc_plat_data {
62 struct rtc_device *rtc; 62 struct rtc_device *rtc;
63 void __iomem *ioaddr; 63 void __iomem *ioaddr;
64 resource_size_t baseaddr;
65 unsigned long last_jiffies; 64 unsigned long last_jiffies;
66 int irq; 65 int irq;
67 unsigned int irqen; 66 unsigned int irqen;
@@ -69,6 +68,7 @@ struct rtc_plat_data {
69 int alrm_min; 68 int alrm_min;
70 int alrm_hour; 69 int alrm_hour;
71 int alrm_mday; 70 int alrm_mday;
71 spinlock_t lock;
72}; 72};
73 73
74static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm) 74static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -139,7 +139,7 @@ static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata)
139 void __iomem *ioaddr = pdata->ioaddr; 139 void __iomem *ioaddr = pdata->ioaddr;
140 unsigned long flags; 140 unsigned long flags;
141 141
142 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); 142 spin_lock_irqsave(&pdata->lock, flags);
143 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 143 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
144 0x80 : bin2bcd(pdata->alrm_mday), 144 0x80 : bin2bcd(pdata->alrm_mday),
145 ioaddr + RTC_DATE_ALARM); 145 ioaddr + RTC_DATE_ALARM);
@@ -154,7 +154,7 @@ static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata)
154 ioaddr + RTC_SECONDS_ALARM); 154 ioaddr + RTC_SECONDS_ALARM);
155 writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS); 155 writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS);
156 readb(ioaddr + RTC_FLAGS); /* clear interrupts */ 156 readb(ioaddr + RTC_FLAGS); /* clear interrupts */
157 spin_unlock_irqrestore(&pdata->rtc->irq_lock, flags); 157 spin_unlock_irqrestore(&pdata->lock, flags);
158} 158}
159 159
160static int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 160static int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
@@ -194,64 +194,69 @@ static irqreturn_t ds1553_rtc_interrupt(int irq, void *dev_id)
194 struct platform_device *pdev = dev_id; 194 struct platform_device *pdev = dev_id;
195 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 195 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
196 void __iomem *ioaddr = pdata->ioaddr; 196 void __iomem *ioaddr = pdata->ioaddr;
197 unsigned long events = RTC_IRQF; 197 unsigned long events = 0;
198 198
199 spin_lock(&pdata->lock);
199 /* read and clear interrupt */ 200 /* read and clear interrupt */
200 if (!(readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF)) 201 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF) {
201 return IRQ_NONE; 202 events = RTC_IRQF;
202 if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80) 203 if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80)
203 events |= RTC_UF; 204 events |= RTC_UF;
204 else 205 else
205 events |= RTC_AF; 206 events |= RTC_AF;
206 rtc_update_irq(pdata->rtc, 1, events); 207 if (likely(pdata->rtc))
207 return IRQ_HANDLED; 208 rtc_update_irq(pdata->rtc, 1, events);
209 }
210 spin_unlock(&pdata->lock);
211 return events ? IRQ_HANDLED : IRQ_NONE;
208} 212}
209 213
210static int ds1553_rtc_ioctl(struct device *dev, unsigned int cmd, 214static int ds1553_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
211 unsigned long arg)
212{ 215{
213 struct platform_device *pdev = to_platform_device(dev); 216 struct platform_device *pdev = to_platform_device(dev);
214 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 217 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
215 218
216 if (pdata->irq <= 0) 219 if (pdata->irq <= 0)
217 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */ 220 return -EINVAL;
218 switch (cmd) { 221 if (enabled)
219 case RTC_AIE_OFF:
220 pdata->irqen &= ~RTC_AF;
221 ds1553_rtc_update_alarm(pdata);
222 break;
223 case RTC_AIE_ON:
224 pdata->irqen |= RTC_AF; 222 pdata->irqen |= RTC_AF;
225 ds1553_rtc_update_alarm(pdata); 223 else
226 break; 224 pdata->irqen &= ~RTC_AF;
227 case RTC_UIE_OFF: 225 ds1553_rtc_update_alarm(pdata);
228 pdata->irqen &= ~RTC_UF; 226 return 0;
229 ds1553_rtc_update_alarm(pdata); 227}
230 break; 228
231 case RTC_UIE_ON: 229static int ds1553_rtc_update_irq_enable(struct device *dev,
230 unsigned int enabled)
231{
232 struct platform_device *pdev = to_platform_device(dev);
233 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
234
235 if (pdata->irq <= 0)
236 return -EINVAL;
237 if (enabled)
232 pdata->irqen |= RTC_UF; 238 pdata->irqen |= RTC_UF;
233 ds1553_rtc_update_alarm(pdata); 239 else
234 break; 240 pdata->irqen &= ~RTC_UF;
235 default: 241 ds1553_rtc_update_alarm(pdata);
236 return -ENOIOCTLCMD;
237 }
238 return 0; 242 return 0;
239} 243}
240 244
241static const struct rtc_class_ops ds1553_rtc_ops = { 245static const struct rtc_class_ops ds1553_rtc_ops = {
242 .read_time = ds1553_rtc_read_time, 246 .read_time = ds1553_rtc_read_time,
243 .set_time = ds1553_rtc_set_time, 247 .set_time = ds1553_rtc_set_time,
244 .read_alarm = ds1553_rtc_read_alarm, 248 .read_alarm = ds1553_rtc_read_alarm,
245 .set_alarm = ds1553_rtc_set_alarm, 249 .set_alarm = ds1553_rtc_set_alarm,
246 .ioctl = ds1553_rtc_ioctl, 250 .alarm_irq_enable = ds1553_rtc_alarm_irq_enable,
251 .update_irq_enable = ds1553_rtc_update_irq_enable,
247}; 252};
248 253
249static ssize_t ds1553_nvram_read(struct kobject *kobj, 254static ssize_t ds1553_nvram_read(struct kobject *kobj,
250 struct bin_attribute *bin_attr, 255 struct bin_attribute *bin_attr,
251 char *buf, loff_t pos, size_t size) 256 char *buf, loff_t pos, size_t size)
252{ 257{
253 struct platform_device *pdev = 258 struct device *dev = container_of(kobj, struct device, kobj);
254 to_platform_device(container_of(kobj, struct device, kobj)); 259 struct platform_device *pdev = to_platform_device(dev);
255 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 260 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
256 void __iomem *ioaddr = pdata->ioaddr; 261 void __iomem *ioaddr = pdata->ioaddr;
257 ssize_t count; 262 ssize_t count;
@@ -265,8 +270,8 @@ static ssize_t ds1553_nvram_write(struct kobject *kobj,
265 struct bin_attribute *bin_attr, 270 struct bin_attribute *bin_attr,
266 char *buf, loff_t pos, size_t size) 271 char *buf, loff_t pos, size_t size)
267{ 272{
268 struct platform_device *pdev = 273 struct device *dev = container_of(kobj, struct device, kobj);
269 to_platform_device(container_of(kobj, struct device, kobj)); 274 struct platform_device *pdev = to_platform_device(dev);
270 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 275 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
271 void __iomem *ioaddr = pdata->ioaddr; 276 void __iomem *ioaddr = pdata->ioaddr;
272 ssize_t count; 277 ssize_t count;
@@ -291,26 +296,23 @@ static int __devinit ds1553_rtc_probe(struct platform_device *pdev)
291 struct rtc_device *rtc; 296 struct rtc_device *rtc;
292 struct resource *res; 297 struct resource *res;
293 unsigned int cen, sec; 298 unsigned int cen, sec;
294 struct rtc_plat_data *pdata = NULL; 299 struct rtc_plat_data *pdata;
295 void __iomem *ioaddr = NULL; 300 void __iomem *ioaddr;
296 int ret = 0; 301 int ret = 0;
297 302
298 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 303 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
299 if (!res) 304 if (!res)
300 return -ENODEV; 305 return -ENODEV;
301 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 306 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
302 if (!pdata) 307 if (!pdata)
303 return -ENOMEM; 308 return -ENOMEM;
304 if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) { 309 if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE,
305 ret = -EBUSY; 310 pdev->name))
306 goto out; 311 return -EBUSY;
307 } 312
308 pdata->baseaddr = res->start; 313 ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE);
309 ioaddr = ioremap(pdata->baseaddr, RTC_REG_SIZE); 314 if (!ioaddr)
310 if (!ioaddr) { 315 return -ENOMEM;
311 ret = -ENOMEM;
312 goto out;
313 }
314 pdata->ioaddr = ioaddr; 316 pdata->ioaddr = ioaddr;
315 pdata->irq = platform_get_irq(pdev, 0); 317 pdata->irq = platform_get_irq(pdev, 0);
316 318
@@ -326,9 +328,13 @@ static int __devinit ds1553_rtc_probe(struct platform_device *pdev)
326 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_BLF) 328 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_BLF)
327 dev_warn(&pdev->dev, "voltage-low detected.\n"); 329 dev_warn(&pdev->dev, "voltage-low detected.\n");
328 330
331 spin_lock_init(&pdata->lock);
332 pdata->last_jiffies = jiffies;
333 platform_set_drvdata(pdev, pdata);
329 if (pdata->irq > 0) { 334 if (pdata->irq > 0) {
330 writeb(0, ioaddr + RTC_INTERRUPTS); 335 writeb(0, ioaddr + RTC_INTERRUPTS);
331 if (request_irq(pdata->irq, ds1553_rtc_interrupt, 336 if (devm_request_irq(&pdev->dev, pdata->irq,
337 ds1553_rtc_interrupt,
332 IRQF_DISABLED, pdev->name, pdev) < 0) { 338 IRQF_DISABLED, pdev->name, pdev) < 0) {
333 dev_warn(&pdev->dev, "interrupt not available.\n"); 339 dev_warn(&pdev->dev, "interrupt not available.\n");
334 pdata->irq = 0; 340 pdata->irq = 0;
@@ -337,27 +343,13 @@ static int __devinit ds1553_rtc_probe(struct platform_device *pdev)
337 343
338 rtc = rtc_device_register(pdev->name, &pdev->dev, 344 rtc = rtc_device_register(pdev->name, &pdev->dev,
339 &ds1553_rtc_ops, THIS_MODULE); 345 &ds1553_rtc_ops, THIS_MODULE);
340 if (IS_ERR(rtc)) { 346 if (IS_ERR(rtc))
341 ret = PTR_ERR(rtc); 347 return PTR_ERR(rtc);
342 goto out;
343 }
344 pdata->rtc = rtc; 348 pdata->rtc = rtc;
345 pdata->last_jiffies = jiffies; 349
346 platform_set_drvdata(pdev, pdata);
347 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 350 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
348 if (ret) 351 if (ret)
349 goto out; 352 rtc_device_unregister(rtc);
350 return 0;
351 out:
352 if (pdata->rtc)
353 rtc_device_unregister(pdata->rtc);
354 if (pdata->irq > 0)
355 free_irq(pdata->irq, pdev);
356 if (ioaddr)
357 iounmap(ioaddr);
358 if (pdata->baseaddr)
359 release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
360 kfree(pdata);
361 return ret; 353 return ret;
362} 354}
363 355
@@ -367,13 +359,8 @@ static int __devexit ds1553_rtc_remove(struct platform_device *pdev)
367 359
368 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 360 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
369 rtc_device_unregister(pdata->rtc); 361 rtc_device_unregister(pdata->rtc);
370 if (pdata->irq > 0) { 362 if (pdata->irq > 0)
371 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 363 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
372 free_irq(pdata->irq, pdev);
373 }
374 iounmap(pdata->ioaddr);
375 release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
376 kfree(pdata);
377 return 0; 364 return 0;
378} 365}
379 366
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 09249459e9a4..a1273360a44e 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -21,7 +21,7 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/io.h> 22#include <linux/io.h>
23 23
24#define DRV_VERSION "0.3" 24#define DRV_VERSION "0.4"
25 25
26#define RTC_SIZE 8 26#define RTC_SIZE 8
27 27
@@ -55,7 +55,6 @@ struct rtc_plat_data {
55 void __iomem *ioaddr_rtc; 55 void __iomem *ioaddr_rtc;
56 size_t size_nvram; 56 size_t size_nvram;
57 size_t size; 57 size_t size;
58 resource_size_t baseaddr;
59 unsigned long last_jiffies; 58 unsigned long last_jiffies;
60 struct bin_attribute nvram_attr; 59 struct bin_attribute nvram_attr;
61}; 60};
@@ -132,8 +131,8 @@ static ssize_t ds1742_nvram_read(struct kobject *kobj,
132 struct bin_attribute *bin_attr, 131 struct bin_attribute *bin_attr,
133 char *buf, loff_t pos, size_t size) 132 char *buf, loff_t pos, size_t size)
134{ 133{
135 struct platform_device *pdev = 134 struct device *dev = container_of(kobj, struct device, kobj);
136 to_platform_device(container_of(kobj, struct device, kobj)); 135 struct platform_device *pdev = to_platform_device(dev);
137 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 136 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
138 void __iomem *ioaddr = pdata->ioaddr_nvram; 137 void __iomem *ioaddr = pdata->ioaddr_nvram;
139 ssize_t count; 138 ssize_t count;
@@ -147,8 +146,8 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj,
147 struct bin_attribute *bin_attr, 146 struct bin_attribute *bin_attr,
148 char *buf, loff_t pos, size_t size) 147 char *buf, loff_t pos, size_t size)
149{ 148{
150 struct platform_device *pdev = 149 struct device *dev = container_of(kobj, struct device, kobj);
151 to_platform_device(container_of(kobj, struct device, kobj)); 150 struct platform_device *pdev = to_platform_device(dev);
152 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 151 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
153 void __iomem *ioaddr = pdata->ioaddr_nvram; 152 void __iomem *ioaddr = pdata->ioaddr_nvram;
154 ssize_t count; 153 ssize_t count;
@@ -163,27 +162,24 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
163 struct rtc_device *rtc; 162 struct rtc_device *rtc;
164 struct resource *res; 163 struct resource *res;
165 unsigned int cen, sec; 164 unsigned int cen, sec;
166 struct rtc_plat_data *pdata = NULL; 165 struct rtc_plat_data *pdata;
167 void __iomem *ioaddr = NULL; 166 void __iomem *ioaddr;
168 int ret = 0; 167 int ret = 0;
169 168
170 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 169 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
171 if (!res) 170 if (!res)
172 return -ENODEV; 171 return -ENODEV;
173 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 172 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
174 if (!pdata) 173 if (!pdata)
175 return -ENOMEM; 174 return -ENOMEM;
176 pdata->size = res->end - res->start + 1; 175 pdata->size = res->end - res->start + 1;
177 if (!request_mem_region(res->start, pdata->size, pdev->name)) { 176 if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size,
178 ret = -EBUSY; 177 pdev->name))
179 goto out; 178 return -EBUSY;
180 } 179 ioaddr = devm_ioremap(&pdev->dev, res->start, pdata->size);
181 pdata->baseaddr = res->start; 180 if (!ioaddr)
182 ioaddr = ioremap(pdata->baseaddr, pdata->size); 181 return -ENOMEM;
183 if (!ioaddr) { 182
184 ret = -ENOMEM;
185 goto out;
186 }
187 pdata->ioaddr_nvram = ioaddr; 183 pdata->ioaddr_nvram = ioaddr;
188 pdata->size_nvram = pdata->size - RTC_SIZE; 184 pdata->size_nvram = pdata->size - RTC_SIZE;
189 pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; 185 pdata->ioaddr_rtc = ioaddr + pdata->size_nvram;
@@ -207,31 +203,19 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
207 if (!(readb(ioaddr + RTC_DAY) & RTC_BATT_FLAG)) 203 if (!(readb(ioaddr + RTC_DAY) & RTC_BATT_FLAG))
208 dev_warn(&pdev->dev, "voltage-low detected.\n"); 204 dev_warn(&pdev->dev, "voltage-low detected.\n");
209 205
206 pdata->last_jiffies = jiffies;
207 platform_set_drvdata(pdev, pdata);
210 rtc = rtc_device_register(pdev->name, &pdev->dev, 208 rtc = rtc_device_register(pdev->name, &pdev->dev,
211 &ds1742_rtc_ops, THIS_MODULE); 209 &ds1742_rtc_ops, THIS_MODULE);
212 if (IS_ERR(rtc)) { 210 if (IS_ERR(rtc))
213 ret = PTR_ERR(rtc); 211 return PTR_ERR(rtc);
214 goto out;
215 }
216 pdata->rtc = rtc; 212 pdata->rtc = rtc;
217 pdata->last_jiffies = jiffies;
218 platform_set_drvdata(pdev, pdata);
219 213
220 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 214 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
221 if (ret) { 215 if (ret) {
222 dev_err(&pdev->dev, "creating nvram file in sysfs failed\n"); 216 dev_err(&pdev->dev, "creating nvram file in sysfs failed\n");
223 goto out; 217 rtc_device_unregister(rtc);
224 } 218 }
225
226 return 0;
227 out:
228 if (pdata->rtc)
229 rtc_device_unregister(pdata->rtc);
230 if (pdata->ioaddr_nvram)
231 iounmap(pdata->ioaddr_nvram);
232 if (pdata->baseaddr)
233 release_mem_region(pdata->baseaddr, pdata->size);
234 kfree(pdata);
235 return ret; 219 return ret;
236} 220}
237 221
@@ -241,9 +225,6 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev)
241 225
242 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 226 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
243 rtc_device_unregister(pdata->rtc); 227 rtc_device_unregister(pdata->rtc);
244 iounmap(pdata->ioaddr_nvram);
245 release_mem_region(pdata->baseaddr, pdata->size);
246 kfree(pdata);
247 return 0; 228 return 0;
248} 229}
249 230
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index 0b2197559940..8cb5b8959e5b 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -142,7 +142,6 @@ static const struct rtc_class_ops m48t35_ops = {
142 142
143static int __devinit m48t35_probe(struct platform_device *pdev) 143static int __devinit m48t35_probe(struct platform_device *pdev)
144{ 144{
145 struct rtc_device *rtc;
146 struct resource *res; 145 struct resource *res;
147 struct m48t35_priv *priv; 146 struct m48t35_priv *priv;
148 int ret = 0; 147 int ret = 0;
@@ -171,20 +170,21 @@ static int __devinit m48t35_probe(struct platform_device *pdev)
171 ret = -ENOMEM; 170 ret = -ENOMEM;
172 goto out; 171 goto out;
173 } 172 }
173
174 spin_lock_init(&priv->lock); 174 spin_lock_init(&priv->lock);
175 rtc = rtc_device_register("m48t35", &pdev->dev, 175
176 platform_set_drvdata(pdev, priv);
177
178 priv->rtc = rtc_device_register("m48t35", &pdev->dev,
176 &m48t35_ops, THIS_MODULE); 179 &m48t35_ops, THIS_MODULE);
177 if (IS_ERR(rtc)) { 180 if (IS_ERR(priv->rtc)) {
178 ret = PTR_ERR(rtc); 181 ret = PTR_ERR(priv->rtc);
179 goto out; 182 goto out;
180 } 183 }
181 priv->rtc = rtc; 184
182 platform_set_drvdata(pdev, priv);
183 return 0; 185 return 0;
184 186
185out: 187out:
186 if (priv->rtc)
187 rtc_device_unregister(priv->rtc);
188 if (priv->reg) 188 if (priv->reg)
189 iounmap(priv->reg); 189 iounmap(priv->reg);
190 if (priv->baseaddr) 190 if (priv->baseaddr)
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index 33921a6b1707..ede43b846859 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -481,6 +481,9 @@ static int __devinit m48t59_rtc_probe(struct platform_device *pdev)
481 goto out; 481 goto out;
482 } 482 }
483 483
484 spin_lock_init(&m48t59->lock);
485 platform_set_drvdata(pdev, m48t59);
486
484 m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE); 487 m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE);
485 if (IS_ERR(m48t59->rtc)) { 488 if (IS_ERR(m48t59->rtc)) {
486 ret = PTR_ERR(m48t59->rtc); 489 ret = PTR_ERR(m48t59->rtc);
@@ -490,16 +493,14 @@ static int __devinit m48t59_rtc_probe(struct platform_device *pdev)
490 m48t59_nvram_attr.size = pdata->offset; 493 m48t59_nvram_attr.size = pdata->offset;
491 494
492 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 495 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
493 if (ret) 496 if (ret) {
497 rtc_device_unregister(m48t59->rtc);
494 goto out; 498 goto out;
499 }
495 500
496 spin_lock_init(&m48t59->lock);
497 platform_set_drvdata(pdev, m48t59);
498 return 0; 501 return 0;
499 502
500out: 503out:
501 if (!IS_ERR(m48t59->rtc))
502 rtc_device_unregister(m48t59->rtc);
503 if (m48t59->irq != NO_IRQ) 504 if (m48t59->irq != NO_IRQ)
504 free_irq(m48t59->irq, &pdev->dev); 505 free_irq(m48t59->irq, &pdev->dev);
505 if (m48t59->ioaddr) 506 if (m48t59->ioaddr)
diff --git a/drivers/rtc/rtc-mc13783.c b/drivers/rtc/rtc-mc13783.c
new file mode 100644
index 000000000000..850f983c039c
--- /dev/null
+++ b/drivers/rtc/rtc-mc13783.c
@@ -0,0 +1,262 @@
1/*
2 * Real Time Clock driver for Freescale MC13783 PMIC
3 *
4 * (C) 2009 Sascha Hauer, Pengutronix
5 * (C) 2009 Uwe Kleine-Koenig, Pengutronix
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/mfd/mc13783.h>
13#include <linux/platform_device.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/rtc.h>
17
18#define DRIVER_NAME "mc13783-rtc"
19
20#define MC13783_RTCTOD 20
21#define MC13783_RTCTODA 21
22#define MC13783_RTCDAY 22
23#define MC13783_RTCDAYA 23
24
25struct mc13783_rtc {
26 struct rtc_device *rtc;
27 struct mc13783 *mc13783;
28 int valid;
29};
30
31static int mc13783_rtc_read_time(struct device *dev, struct rtc_time *tm)
32{
33 struct mc13783_rtc *priv = dev_get_drvdata(dev);
34 unsigned int seconds, days1, days2;
35 unsigned long s1970;
36 int ret;
37
38 mc13783_lock(priv->mc13783);
39
40 if (!priv->valid) {
41 ret = -ENODATA;
42 goto out;
43 }
44
45 ret = mc13783_reg_read(priv->mc13783, MC13783_RTCDAY, &days1);
46 if (unlikely(ret))
47 goto out;
48
49 ret = mc13783_reg_read(priv->mc13783, MC13783_RTCTOD, &seconds);
50 if (unlikely(ret))
51 goto out;
52
53 ret = mc13783_reg_read(priv->mc13783, MC13783_RTCDAY, &days2);
54out:
55 mc13783_unlock(priv->mc13783);
56
57 if (ret)
58 return ret;
59
60 if (days2 == days1 + 1) {
61 if (seconds >= 86400 / 2)
62 days2 = days1;
63 else
64 days1 = days2;
65 }
66
67 if (days1 != days2)
68 return -EIO;
69
70 s1970 = days1 * 86400 + seconds;
71
72 rtc_time_to_tm(s1970, tm);
73
74 return rtc_valid_tm(tm);
75}
76
77static int mc13783_rtc_set_mmss(struct device *dev, unsigned long secs)
78{
79 struct mc13783_rtc *priv = dev_get_drvdata(dev);
80 unsigned int seconds, days;
81 int ret;
82
83 seconds = secs % 86400;
84 days = secs / 86400;
85
86 mc13783_lock(priv->mc13783);
87
88 /*
89 * first write seconds=0 to prevent a day switch between writing days
90 * and seconds below
91 */
92 ret = mc13783_reg_write(priv->mc13783, MC13783_RTCTOD, 0);
93 if (unlikely(ret))
94 goto out;
95
96 ret = mc13783_reg_write(priv->mc13783, MC13783_RTCDAY, days);
97 if (unlikely(ret))
98 goto out;
99
100 ret = mc13783_reg_write(priv->mc13783, MC13783_RTCTOD, seconds);
101 if (unlikely(ret))
102 goto out;
103
104 ret = mc13783_ackirq(priv->mc13783, MC13783_IRQ_RTCRST);
105 if (unlikely(ret))
106 goto out;
107
108 ret = mc13783_unmask(priv->mc13783, MC13783_IRQ_RTCRST);
109out:
110 priv->valid = !ret;
111
112 mc13783_unlock(priv->mc13783);
113
114 return ret;
115}
116
117static irqreturn_t mc13783_rtc_update_handler(int irq, void *dev)
118{
119 struct mc13783_rtc *priv = dev;
120 struct mc13783 *mc13783 = priv->mc13783;
121
122 dev_dbg(&priv->rtc->dev, "1HZ\n");
123
124 rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_UF);
125
126 mc13783_ackirq(mc13783, irq);
127
128 return IRQ_HANDLED;
129}
130
131static int mc13783_rtc_update_irq_enable(struct device *dev,
132 unsigned int enabled)
133{
134 struct mc13783_rtc *priv = dev_get_drvdata(dev);
135 int ret = -ENODATA;
136
137 mc13783_lock(priv->mc13783);
138 if (!priv->valid)
139 goto out;
140
141 ret = (enabled ? mc13783_unmask : mc13783_mask)(priv->mc13783,
142 MC13783_IRQ_1HZ);
143out:
144 mc13783_unlock(priv->mc13783);
145
146 return ret;
147}
148
149static const struct rtc_class_ops mc13783_rtc_ops = {
150 .read_time = mc13783_rtc_read_time,
151 .set_mmss = mc13783_rtc_set_mmss,
152 .update_irq_enable = mc13783_rtc_update_irq_enable,
153};
154
155static irqreturn_t mc13783_rtc_reset_handler(int irq, void *dev)
156{
157 struct mc13783_rtc *priv = dev;
158 struct mc13783 *mc13783 = priv->mc13783;
159
160 dev_dbg(&priv->rtc->dev, "RTCRST\n");
161 priv->valid = 0;
162
163 mc13783_mask(mc13783, irq);
164
165 return IRQ_HANDLED;
166}
167
168static int __devinit mc13783_rtc_probe(struct platform_device *pdev)
169{
170 int ret;
171 struct mc13783_rtc *priv;
172
173 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
174 if (!priv)
175 return -ENOMEM;
176
177 priv->mc13783 = dev_get_drvdata(pdev->dev.parent);
178 platform_set_drvdata(pdev, priv);
179
180 priv->valid = 1;
181
182 mc13783_lock(priv->mc13783);
183
184 ret = mc13783_irq_request(priv->mc13783, MC13783_IRQ_RTCRST,
185 mc13783_rtc_reset_handler, DRIVER_NAME, priv);
186 if (ret)
187 goto err_reset_irq_request;
188
189 ret = mc13783_irq_request_nounmask(priv->mc13783, MC13783_IRQ_1HZ,
190 mc13783_rtc_update_handler, DRIVER_NAME, priv);
191 if (ret)
192 goto err_update_irq_request;
193
194 mc13783_unlock(priv->mc13783);
195
196 priv->rtc = rtc_device_register(pdev->name,
197 &pdev->dev, &mc13783_rtc_ops, THIS_MODULE);
198
199 if (IS_ERR(priv->rtc)) {
200 ret = PTR_ERR(priv->rtc);
201
202 mc13783_lock(priv->mc13783);
203
204 mc13783_irq_free(priv->mc13783, MC13783_IRQ_1HZ, priv);
205err_update_irq_request:
206
207 mc13783_irq_free(priv->mc13783, MC13783_IRQ_RTCRST, priv);
208err_reset_irq_request:
209
210 mc13783_unlock(priv->mc13783);
211
212 platform_set_drvdata(pdev, NULL);
213 kfree(priv);
214 }
215
216 return ret;
217}
218
219static int __devexit mc13783_rtc_remove(struct platform_device *pdev)
220{
221 struct mc13783_rtc *priv = platform_get_drvdata(pdev);
222
223 rtc_device_unregister(priv->rtc);
224
225 mc13783_lock(priv->mc13783);
226
227 mc13783_irq_free(priv->mc13783, MC13783_IRQ_1HZ, priv);
228 mc13783_irq_free(priv->mc13783, MC13783_IRQ_RTCRST, priv);
229
230 mc13783_unlock(priv->mc13783);
231
232 platform_set_drvdata(pdev, NULL);
233
234 kfree(priv);
235
236 return 0;
237}
238
239static struct platform_driver mc13783_rtc_driver = {
240 .remove = __devexit_p(mc13783_rtc_remove),
241 .driver = {
242 .name = DRIVER_NAME,
243 .owner = THIS_MODULE,
244 },
245};
246
247static int __init mc13783_rtc_init(void)
248{
249 return platform_driver_probe(&mc13783_rtc_driver, &mc13783_rtc_probe);
250}
251module_init(mc13783_rtc_init);
252
253static void __exit mc13783_rtc_exit(void)
254{
255 platform_driver_unregister(&mc13783_rtc_driver);
256}
257module_exit(mc13783_rtc_exit);
258
259MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
260MODULE_DESCRIPTION("RTC driver for Freescale MC13783 PMIC");
261MODULE_LICENSE("GPL v2");
262MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index e0263d2005ee..dc052ce6e63a 100644
--- a/drivers/rtc/rtc-mv.c
+++ b/drivers/rtc/rtc-mv.c
@@ -27,10 +27,17 @@
27#define RTC_MONTH_OFFS 8 27#define RTC_MONTH_OFFS 8
28#define RTC_YEAR_OFFS 16 28#define RTC_YEAR_OFFS 16
29 29
30#define RTC_ALARM_TIME_REG_OFFS 8
31#define RTC_ALARM_DATE_REG_OFFS 0xc
32#define RTC_ALARM_VALID (1 << 7)
33
34#define RTC_ALARM_INTERRUPT_MASK_REG_OFFS 0x10
35#define RTC_ALARM_INTERRUPT_CASUE_REG_OFFS 0x14
30 36
31struct rtc_plat_data { 37struct rtc_plat_data {
32 struct rtc_device *rtc; 38 struct rtc_device *rtc;
33 void __iomem *ioaddr; 39 void __iomem *ioaddr;
40 int irq;
34}; 41};
35 42
36static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm) 43static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -84,12 +91,134 @@ static int mv_rtc_read_time(struct device *dev, struct rtc_time *tm)
84 return rtc_valid_tm(tm); 91 return rtc_valid_tm(tm);
85} 92}
86 93
94static int mv_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
95{
96 struct rtc_plat_data *pdata = dev_get_drvdata(dev);
97 void __iomem *ioaddr = pdata->ioaddr;
98 u32 rtc_time, rtc_date;
99 unsigned int year, month, day, hour, minute, second, wday;
100
101 rtc_time = readl(ioaddr + RTC_ALARM_TIME_REG_OFFS);
102 rtc_date = readl(ioaddr + RTC_ALARM_DATE_REG_OFFS);
103
104 second = rtc_time & 0x7f;
105 minute = (rtc_time >> RTC_MINUTES_OFFS) & 0x7f;
106 hour = (rtc_time >> RTC_HOURS_OFFS) & 0x3f; /* assume 24 hours mode */
107 wday = (rtc_time >> RTC_WDAY_OFFS) & 0x7;
108
109 day = rtc_date & 0x3f;
110 month = (rtc_date >> RTC_MONTH_OFFS) & 0x3f;
111 year = (rtc_date >> RTC_YEAR_OFFS) & 0xff;
112
113 alm->time.tm_sec = bcd2bin(second);
114 alm->time.tm_min = bcd2bin(minute);
115 alm->time.tm_hour = bcd2bin(hour);
116 alm->time.tm_mday = bcd2bin(day);
117 alm->time.tm_wday = bcd2bin(wday);
118 alm->time.tm_mon = bcd2bin(month) - 1;
119 /* hw counts from year 2000, but tm_year is relative to 1900 */
120 alm->time.tm_year = bcd2bin(year) + 100;
121
122 if (rtc_valid_tm(&alm->time) < 0) {
123 dev_err(dev, "retrieved alarm date/time is not valid.\n");
124 rtc_time_to_tm(0, &alm->time);
125 }
126
127 alm->enabled = !!readl(ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS);
128 return 0;
129}
130
131static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
132{
133 struct rtc_plat_data *pdata = dev_get_drvdata(dev);
134 void __iomem *ioaddr = pdata->ioaddr;
135 u32 rtc_reg = 0;
136
137 if (alm->time.tm_sec >= 0)
138 rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_sec))
139 << RTC_SECONDS_OFFS;
140 if (alm->time.tm_min >= 0)
141 rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_min))
142 << RTC_MINUTES_OFFS;
143 if (alm->time.tm_hour >= 0)
144 rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_hour))
145 << RTC_HOURS_OFFS;
146
147 writel(rtc_reg, ioaddr + RTC_ALARM_TIME_REG_OFFS);
148
149 if (alm->time.tm_mday >= 0)
150 rtc_reg = (RTC_ALARM_VALID | bin2bcd(alm->time.tm_mday))
151 << RTC_MDAY_OFFS;
152 else
153 rtc_reg = 0;
154
155 if (alm->time.tm_mon >= 0)
156 rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_mon + 1))
157 << RTC_MONTH_OFFS;
158
159 if (alm->time.tm_year >= 0)
160 rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year % 100))
161 << RTC_YEAR_OFFS;
162
163 writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS);
164 writel(0, ioaddr + RTC_ALARM_INTERRUPT_CASUE_REG_OFFS);
165 writel(alm->enabled ? 1 : 0,
166 ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS);
167
168 return 0;
169}
170
171static int mv_rtc_ioctl(struct device *dev, unsigned int cmd,
172 unsigned long arg)
173{
174 struct platform_device *pdev = to_platform_device(dev);
175 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
176 void __iomem *ioaddr = pdata->ioaddr;
177
178 if (pdata->irq < 0)
179 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */
180 switch (cmd) {
181 case RTC_AIE_OFF:
182 writel(0, ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS);
183 break;
184 case RTC_AIE_ON:
185 writel(1, ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS);
186 break;
187 default:
188 return -ENOIOCTLCMD;
189 }
190 return 0;
191}
192
193static irqreturn_t mv_rtc_interrupt(int irq, void *data)
194{
195 struct rtc_plat_data *pdata = data;
196 void __iomem *ioaddr = pdata->ioaddr;
197
198 /* alarm irq? */
199 if (!readl(ioaddr + RTC_ALARM_INTERRUPT_CASUE_REG_OFFS))
200 return IRQ_NONE;
201
202 /* clear interrupt */
203 writel(0, ioaddr + RTC_ALARM_INTERRUPT_CASUE_REG_OFFS);
204 rtc_update_irq(pdata->rtc, 1, RTC_IRQF | RTC_AF);
205 return IRQ_HANDLED;
206}
207
87static const struct rtc_class_ops mv_rtc_ops = { 208static const struct rtc_class_ops mv_rtc_ops = {
88 .read_time = mv_rtc_read_time, 209 .read_time = mv_rtc_read_time,
89 .set_time = mv_rtc_set_time, 210 .set_time = mv_rtc_set_time,
90}; 211};
91 212
92static int __init mv_rtc_probe(struct platform_device *pdev) 213static const struct rtc_class_ops mv_rtc_alarm_ops = {
214 .read_time = mv_rtc_read_time,
215 .set_time = mv_rtc_set_time,
216 .read_alarm = mv_rtc_read_alarm,
217 .set_alarm = mv_rtc_set_alarm,
218 .ioctl = mv_rtc_ioctl,
219};
220
221static int __devinit mv_rtc_probe(struct platform_device *pdev)
93{ 222{
94 struct resource *res; 223 struct resource *res;
95 struct rtc_plat_data *pdata; 224 struct rtc_plat_data *pdata;
@@ -130,12 +259,31 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
130 } 259 }
131 } 260 }
132 261
262 pdata->irq = platform_get_irq(pdev, 0);
263
133 platform_set_drvdata(pdev, pdata); 264 platform_set_drvdata(pdev, pdata);
134 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 265
135 &mv_rtc_ops, THIS_MODULE); 266 if (pdata->irq >= 0) {
267 device_init_wakeup(&pdev->dev, 1);
268 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev,
269 &mv_rtc_alarm_ops,
270 THIS_MODULE);
271 } else
272 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev,
273 &mv_rtc_ops, THIS_MODULE);
136 if (IS_ERR(pdata->rtc)) 274 if (IS_ERR(pdata->rtc))
137 return PTR_ERR(pdata->rtc); 275 return PTR_ERR(pdata->rtc);
138 276
277 if (pdata->irq >= 0) {
278 writel(0, pdata->ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS);
279 if (devm_request_irq(&pdev->dev, pdata->irq, mv_rtc_interrupt,
280 IRQF_DISABLED | IRQF_SHARED,
281 pdev->name, pdata) < 0) {
282 dev_warn(&pdev->dev, "interrupt not available.\n");
283 pdata->irq = -1;
284 }
285 }
286
139 return 0; 287 return 0;
140} 288}
141 289
@@ -143,6 +291,9 @@ static int __exit mv_rtc_remove(struct platform_device *pdev)
143{ 291{
144 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 292 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
145 293
294 if (pdata->irq >= 0)
295 device_init_wakeup(&pdev->dev, 0);
296
146 rtc_device_unregister(pdata->rtc); 297 rtc_device_unregister(pdata->rtc);
147 return 0; 298 return 0;
148} 299}
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
new file mode 100644
index 000000000000..bf59c9c586b2
--- /dev/null
+++ b/drivers/rtc/rtc-nuc900.c
@@ -0,0 +1,342 @@
1/*
2 * Copyright (c) 2008-2009 Nuvoton technology corporation.
3 *
4 * Wan ZongShun <mcuos.com@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation;version 2 of the License.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/rtc.h>
16#include <linux/delay.h>
17#include <linux/io.h>
18#include <linux/bcd.h>
19
20/* RTC Control Registers */
21#define REG_RTC_INIR 0x00
22#define REG_RTC_AER 0x04
23#define REG_RTC_FCR 0x08
24#define REG_RTC_TLR 0x0C
25#define REG_RTC_CLR 0x10
26#define REG_RTC_TSSR 0x14
27#define REG_RTC_DWR 0x18
28#define REG_RTC_TAR 0x1C
29#define REG_RTC_CAR 0x20
30#define REG_RTC_LIR 0x24
31#define REG_RTC_RIER 0x28
32#define REG_RTC_RIIR 0x2C
33#define REG_RTC_TTR 0x30
34
35#define RTCSET 0x01
36#define AERRWENB 0x10000
37#define INIRRESET 0xa5eb1357
38#define AERPOWERON 0xA965
39#define AERPOWEROFF 0x0000
40#define LEAPYEAR 0x0001
41#define TICKENB 0x80
42#define TICKINTENB 0x0002
43#define ALARMINTENB 0x0001
44#define MODE24 0x0001
45
46struct nuc900_rtc {
47 int irq_num;
48 void __iomem *rtc_reg;
49 struct rtc_device *rtcdev;
50};
51
52struct nuc900_bcd_time {
53 int bcd_sec;
54 int bcd_min;
55 int bcd_hour;
56 int bcd_mday;
57 int bcd_mon;
58 int bcd_year;
59};
60
61static irqreturn_t nuc900_rtc_interrupt(int irq, void *_rtc)
62{
63 struct nuc900_rtc *rtc = _rtc;
64 unsigned long events = 0, rtc_irq;
65
66 rtc_irq = __raw_readl(rtc->rtc_reg + REG_RTC_RIIR);
67
68 if (rtc_irq & ALARMINTENB) {
69 rtc_irq &= ~ALARMINTENB;
70 __raw_writel(rtc_irq, rtc->rtc_reg + REG_RTC_RIIR);
71 events |= RTC_AF | RTC_IRQF;
72 }
73
74 if (rtc_irq & TICKINTENB) {
75 rtc_irq &= ~TICKINTENB;
76 __raw_writel(rtc_irq, rtc->rtc_reg + REG_RTC_RIIR);
77 events |= RTC_UF | RTC_IRQF;
78 }
79
80 rtc_update_irq(rtc->rtcdev, 1, events);
81
82 return IRQ_HANDLED;
83}
84
85static int *check_rtc_access_enable(struct nuc900_rtc *nuc900_rtc)
86{
87 unsigned int i;
88 __raw_writel(INIRRESET, nuc900_rtc->rtc_reg + REG_RTC_INIR);
89
90 mdelay(10);
91
92 __raw_writel(AERPOWERON, nuc900_rtc->rtc_reg + REG_RTC_AER);
93
94 for (i = 0; i < 1000; i++) {
95 if (__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB)
96 return 0;
97 }
98
99 if ((__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB) == 0x0)
100 return ERR_PTR(-ENODEV);
101
102 return ERR_PTR(-EPERM);
103}
104
105static void nuc900_rtc_bcd2bin(unsigned int timereg,
106 unsigned int calreg, struct rtc_time *tm)
107{
108 tm->tm_mday = bcd2bin(calreg >> 0);
109 tm->tm_mon = bcd2bin(calreg >> 8);
110 tm->tm_year = bcd2bin(calreg >> 16) + 100;
111
112 tm->tm_sec = bcd2bin(timereg >> 0);
113 tm->tm_min = bcd2bin(timereg >> 8);
114 tm->tm_hour = bcd2bin(timereg >> 16);
115
116 rtc_valid_tm(tm);
117}
118
119static void nuc900_rtc_bin2bcd(struct rtc_time *settm,
120 struct nuc900_bcd_time *gettm)
121{
122 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0;
123 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8;
124 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16;
125
126 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0;
127 gettm->bcd_min = bin2bcd(settm->tm_min) << 8;
128 gettm->bcd_hour = bin2bcd(settm->tm_hour) << 16;
129}
130
131static int nuc900_update_irq_enable(struct device *dev, unsigned int enabled)
132{
133 struct nuc900_rtc *rtc = dev_get_drvdata(dev);
134
135 if (enabled)
136 __raw_writel(__raw_readl(rtc->rtc_reg + REG_RTC_RIER)|
137 (TICKINTENB), rtc->rtc_reg + REG_RTC_RIER);
138 else
139 __raw_writel(__raw_readl(rtc->rtc_reg + REG_RTC_RIER)&
140 (~TICKINTENB), rtc->rtc_reg + REG_RTC_RIER);
141
142 return 0;
143}
144
145static int nuc900_alarm_irq_enable(struct device *dev, unsigned int enabled)
146{
147 struct nuc900_rtc *rtc = dev_get_drvdata(dev);
148
149 if (enabled)
150 __raw_writel(__raw_readl(rtc->rtc_reg + REG_RTC_RIER)|
151 (ALARMINTENB), rtc->rtc_reg + REG_RTC_RIER);
152 else
153 __raw_writel(__raw_readl(rtc->rtc_reg + REG_RTC_RIER)&
154 (~ALARMINTENB), rtc->rtc_reg + REG_RTC_RIER);
155
156 return 0;
157}
158
159static int nuc900_rtc_read_time(struct device *dev, struct rtc_time *tm)
160{
161 struct nuc900_rtc *rtc = dev_get_drvdata(dev);
162 unsigned int timeval, clrval;
163
164 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TLR);
165 clrval = __raw_readl(rtc->rtc_reg + REG_RTC_CLR);
166
167 nuc900_rtc_bcd2bin(timeval, clrval, tm);
168
169 return 0;
170}
171
172static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm)
173{
174 struct nuc900_rtc *rtc = dev_get_drvdata(dev);
175 struct nuc900_bcd_time gettm;
176 unsigned long val;
177 int *err;
178
179 nuc900_rtc_bin2bcd(tm, &gettm);
180
181 err = check_rtc_access_enable(rtc);
182 if (IS_ERR(err))
183 return PTR_ERR(err);
184
185 val = gettm.bcd_mday | gettm.bcd_mon | gettm.bcd_year;
186 __raw_writel(val, rtc->rtc_reg + REG_RTC_CLR);
187
188 val = gettm.bcd_sec | gettm.bcd_min | gettm.bcd_hour;
189 __raw_writel(val, rtc->rtc_reg + REG_RTC_TLR);
190
191 return 0;
192}
193
194static int nuc900_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
195{
196 struct nuc900_rtc *rtc = dev_get_drvdata(dev);
197 unsigned int timeval, carval;
198
199 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TAR);
200 carval = __raw_readl(rtc->rtc_reg + REG_RTC_CAR);
201
202 nuc900_rtc_bcd2bin(timeval, carval, &alrm->time);
203
204 return 0;
205}
206
207static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
208{
209 struct nuc900_rtc *rtc = dev_get_drvdata(dev);
210 struct nuc900_bcd_time tm;
211 unsigned long val;
212 int *err;
213
214 nuc900_rtc_bin2bcd(&alrm->time, &tm);
215
216 err = check_rtc_access_enable(rtc);
217 if (IS_ERR(err))
218 return PTR_ERR(err);
219
220 val = tm.bcd_mday | tm.bcd_mon | tm.bcd_year;
221 __raw_writel(val, rtc->rtc_reg + REG_RTC_CAR);
222
223 val = tm.bcd_sec | tm.bcd_min | tm.bcd_hour;
224 __raw_writel(val, rtc->rtc_reg + REG_RTC_TAR);
225
226 return 0;
227}
228
229static struct rtc_class_ops nuc900_rtc_ops = {
230 .read_time = nuc900_rtc_read_time,
231 .set_time = nuc900_rtc_set_time,
232 .read_alarm = nuc900_rtc_read_alarm,
233 .set_alarm = nuc900_rtc_set_alarm,
234 .alarm_irq_enable = nuc900_alarm_irq_enable,
235 .update_irq_enable = nuc900_update_irq_enable,
236};
237
238static int __devinit nuc900_rtc_probe(struct platform_device *pdev)
239{
240 struct resource *res;
241 struct nuc900_rtc *nuc900_rtc;
242 int err = 0;
243
244 nuc900_rtc = kzalloc(sizeof(struct nuc900_rtc), GFP_KERNEL);
245 if (!nuc900_rtc) {
246 dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n");
247 return -ENOMEM;
248 }
249 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250 if (!res) {
251 dev_err(&pdev->dev, "platform_get_resource failed\n");
252 err = -ENXIO;
253 goto fail1;
254 }
255
256 if (!request_mem_region(res->start, resource_size(res),
257 pdev->name)) {
258 dev_err(&pdev->dev, "request_mem_region failed\n");
259 err = -EBUSY;
260 goto fail1;
261 }
262
263 nuc900_rtc->rtc_reg = ioremap(res->start, resource_size(res));
264 if (!nuc900_rtc->rtc_reg) {
265 dev_err(&pdev->dev, "ioremap rtc_reg failed\n");
266 err = -ENOMEM;
267 goto fail2;
268 }
269
270 nuc900_rtc->irq_num = platform_get_irq(pdev, 0);
271 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt,
272 IRQF_DISABLED, "nuc900rtc", nuc900_rtc)) {
273 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
274 err = -EBUSY;
275 goto fail3;
276 }
277
278 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev,
279 &nuc900_rtc_ops, THIS_MODULE);
280 if (IS_ERR(nuc900_rtc->rtcdev)) {
281 dev_err(&pdev->dev, "rtc device register faild\n");
282 err = PTR_ERR(nuc900_rtc->rtcdev);
283 goto fail4;
284 }
285
286 platform_set_drvdata(pdev, nuc900_rtc);
287 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24,
288 nuc900_rtc->rtc_reg + REG_RTC_TSSR);
289
290 return 0;
291
292fail4: free_irq(nuc900_rtc->irq_num, nuc900_rtc);
293fail3: iounmap(nuc900_rtc->rtc_reg);
294fail2: release_mem_region(res->start, resource_size(res));
295fail1: kfree(nuc900_rtc);
296 return err;
297}
298
299static int __devexit nuc900_rtc_remove(struct platform_device *pdev)
300{
301 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
302 struct resource *res;
303
304 rtc_device_unregister(nuc900_rtc->rtcdev);
305 free_irq(nuc900_rtc->irq_num, nuc900_rtc);
306 iounmap(nuc900_rtc->rtc_reg);
307
308 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
309 release_mem_region(res->start, resource_size(res));
310
311 kfree(nuc900_rtc);
312
313 platform_set_drvdata(pdev, NULL);
314
315 return 0;
316}
317
318static struct platform_driver nuc900_rtc_driver = {
319 .remove = __devexit_p(nuc900_rtc_remove),
320 .driver = {
321 .name = "nuc900-rtc",
322 .owner = THIS_MODULE,
323 },
324};
325
326static int __init nuc900_rtc_init(void)
327{
328 return platform_driver_probe(&nuc900_rtc_driver, nuc900_rtc_probe);
329}
330
331static void __exit nuc900_rtc_exit(void)
332{
333 platform_driver_unregister(&nuc900_rtc_driver);
334}
335
336module_init(nuc900_rtc_init);
337module_exit(nuc900_rtc_exit);
338
339MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
340MODULE_DESCRIPTION("nuc910/nuc920 RTC driver");
341MODULE_LICENSE("GPL");
342MODULE_ALIAS("platform:nuc900-rtc");
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 0587d53987fe..64d9727b7229 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -87,9 +87,10 @@
87#define OMAP_RTC_INTERRUPTS_IT_ALARM (1<<3) 87#define OMAP_RTC_INTERRUPTS_IT_ALARM (1<<3)
88#define OMAP_RTC_INTERRUPTS_IT_TIMER (1<<2) 88#define OMAP_RTC_INTERRUPTS_IT_TIMER (1<<2)
89 89
90static void __iomem *rtc_base;
90 91
91#define rtc_read(addr) omap_readb(OMAP_RTC_BASE + (addr)) 92#define rtc_read(addr) __raw_readb(rtc_base + (addr))
92#define rtc_write(val, addr) omap_writeb(val, OMAP_RTC_BASE + (addr)) 93#define rtc_write(val, addr) __raw_writeb(val, rtc_base + (addr))
93 94
94 95
95/* we rely on the rtc framework to handle locking (rtc->ops_lock), 96/* we rely on the rtc framework to handle locking (rtc->ops_lock),
@@ -330,32 +331,31 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
330 return -ENOENT; 331 return -ENOENT;
331 } 332 }
332 333
333 /* NOTE: using static mapping for RTC registers */
334 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 334 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
335 if (res && res->start != OMAP_RTC_BASE) { 335 if (!res) {
336 pr_debug("%s: RTC registers at %08x, expected %08x\n", 336 pr_debug("%s: RTC resource data missing\n", pdev->name);
337 pdev->name, (unsigned) res->start, OMAP_RTC_BASE);
338 return -ENOENT; 337 return -ENOENT;
339 } 338 }
340 339
341 if (res) 340 mem = request_mem_region(res->start, resource_size(res), pdev->name);
342 mem = request_mem_region(res->start,
343 res->end - res->start + 1,
344 pdev->name);
345 else
346 mem = NULL;
347 if (!mem) { 341 if (!mem) {
348 pr_debug("%s: RTC registers at %08x are not free\n", 342 pr_debug("%s: RTC registers at %08x are not free\n",
349 pdev->name, OMAP_RTC_BASE); 343 pdev->name, res->start);
350 return -EBUSY; 344 return -EBUSY;
351 } 345 }
352 346
347 rtc_base = ioremap(res->start, resource_size(res));
348 if (!rtc_base) {
349 pr_debug("%s: RTC registers can't be mapped\n", pdev->name);
350 goto fail;
351 }
352
353 rtc = rtc_device_register(pdev->name, &pdev->dev, 353 rtc = rtc_device_register(pdev->name, &pdev->dev,
354 &omap_rtc_ops, THIS_MODULE); 354 &omap_rtc_ops, THIS_MODULE);
355 if (IS_ERR(rtc)) { 355 if (IS_ERR(rtc)) {
356 pr_debug("%s: can't register RTC device, err %ld\n", 356 pr_debug("%s: can't register RTC device, err %ld\n",
357 pdev->name, PTR_ERR(rtc)); 357 pdev->name, PTR_ERR(rtc));
358 goto fail; 358 goto fail0;
359 } 359 }
360 platform_set_drvdata(pdev, rtc); 360 platform_set_drvdata(pdev, rtc);
361 dev_set_drvdata(&rtc->dev, mem); 361 dev_set_drvdata(&rtc->dev, mem);
@@ -380,13 +380,14 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
380 dev_name(&rtc->dev), rtc)) { 380 dev_name(&rtc->dev), rtc)) {
381 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", 381 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n",
382 pdev->name, omap_rtc_timer); 382 pdev->name, omap_rtc_timer);
383 goto fail0; 383 goto fail1;
384 } 384 }
385 if (request_irq(omap_rtc_alarm, rtc_irq, IRQF_DISABLED, 385 if ((omap_rtc_timer != omap_rtc_alarm) &&
386 dev_name(&rtc->dev), rtc)) { 386 (request_irq(omap_rtc_alarm, rtc_irq, IRQF_DISABLED,
387 dev_name(&rtc->dev), rtc))) {
387 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", 388 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n",
388 pdev->name, omap_rtc_alarm); 389 pdev->name, omap_rtc_alarm);
389 goto fail1; 390 goto fail2;
390 } 391 }
391 392
392 /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ 393 /* On boards with split power, RTC_ON_NOFF won't reset the RTC */
@@ -419,10 +420,12 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
419 420
420 return 0; 421 return 0;
421 422
422fail1: 423fail2:
423 free_irq(omap_rtc_timer, NULL); 424 free_irq(omap_rtc_timer, NULL);
424fail0: 425fail1:
425 rtc_device_unregister(rtc); 426 rtc_device_unregister(rtc);
427fail0:
428 iounmap(rtc_base);
426fail: 429fail:
427 release_resource(mem); 430 release_resource(mem);
428 return -EIO; 431 return -EIO;
@@ -438,7 +441,9 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
438 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 441 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
439 442
440 free_irq(omap_rtc_timer, rtc); 443 free_irq(omap_rtc_timer, rtc);
441 free_irq(omap_rtc_alarm, rtc); 444
445 if (omap_rtc_timer != omap_rtc_alarm)
446 free_irq(omap_rtc_alarm, rtc);
442 447
443 release_resource(dev_get_drvdata(&rtc->dev)); 448 release_resource(dev_get_drvdata(&rtc->dev));
444 rtc_device_unregister(rtc); 449 rtc_device_unregister(rtc);
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index 4c5d5d0c4cfc..854c3cb365a1 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -58,6 +58,7 @@ struct pcf50633_time {
58struct pcf50633_rtc { 58struct pcf50633_rtc {
59 int alarm_enabled; 59 int alarm_enabled;
60 int second_enabled; 60 int second_enabled;
61 int alarm_pending;
61 62
62 struct pcf50633 *pcf; 63 struct pcf50633 *pcf;
63 struct rtc_device *rtc_dev; 64 struct rtc_device *rtc_dev;
@@ -209,6 +210,7 @@ static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
209 rtc = dev_get_drvdata(dev); 210 rtc = dev_get_drvdata(dev);
210 211
211 alrm->enabled = rtc->alarm_enabled; 212 alrm->enabled = rtc->alarm_enabled;
213 alrm->pending = rtc->alarm_pending;
212 214
213 ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA, 215 ret = pcf50633_read_block(rtc->pcf, PCF50633_REG_RTCSCA,
214 PCF50633_TI_EXTENT, &pcf_tm.time[0]); 216 PCF50633_TI_EXTENT, &pcf_tm.time[0]);
@@ -244,6 +246,8 @@ static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
244 /* Returns 0 on success */ 246 /* Returns 0 on success */
245 ret = pcf50633_write_block(rtc->pcf, PCF50633_REG_RTCSCA, 247 ret = pcf50633_write_block(rtc->pcf, PCF50633_REG_RTCSCA,
246 PCF50633_TI_EXTENT, &pcf_tm.time[0]); 248 PCF50633_TI_EXTENT, &pcf_tm.time[0]);
249 if (!alrm->enabled)
250 rtc->alarm_pending = 0;
247 251
248 if (!alarm_masked || alrm->enabled) 252 if (!alarm_masked || alrm->enabled)
249 pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM); 253 pcf50633_irq_unmask(rtc->pcf, PCF50633_IRQ_ALARM);
@@ -268,6 +272,7 @@ static void pcf50633_rtc_irq(int irq, void *data)
268 switch (irq) { 272 switch (irq) {
269 case PCF50633_IRQ_ALARM: 273 case PCF50633_IRQ_ALARM:
270 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF); 274 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
275 rtc->alarm_pending = 1;
271 break; 276 break;
272 case PCF50633_IRQ_SECOND: 277 case PCF50633_IRQ_SECOND:
273 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF); 278 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
@@ -277,16 +282,13 @@ static void pcf50633_rtc_irq(int irq, void *data)
277 282
278static int __devinit pcf50633_rtc_probe(struct platform_device *pdev) 283static int __devinit pcf50633_rtc_probe(struct platform_device *pdev)
279{ 284{
280 struct pcf50633_subdev_pdata *pdata;
281 struct pcf50633_rtc *rtc; 285 struct pcf50633_rtc *rtc;
282 286
283
284 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 287 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
285 if (!rtc) 288 if (!rtc)
286 return -ENOMEM; 289 return -ENOMEM;
287 290
288 pdata = pdev->dev.platform_data; 291 rtc->pcf = dev_to_pcf50633(pdev->dev.parent);
289 rtc->pcf = pdata->pcf;
290 platform_set_drvdata(pdev, rtc); 292 platform_set_drvdata(pdev, rtc);
291 rtc->rtc_dev = rtc_device_register("pcf50633-rtc", &pdev->dev, 293 rtc->rtc_dev = rtc_device_register("pcf50633-rtc", &pdev->dev,
292 &pcf50633_rtc_ops, THIS_MODULE); 294 &pcf50633_rtc_ops, THIS_MODULE);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index b725913ccbe8..65f346b2fbae 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -212,6 +212,8 @@ static int pcf8563_probe(struct i2c_client *client,
212 212
213 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 213 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
214 214
215 i2c_set_clientdata(client, pcf8563);
216
215 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, 217 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name,
216 &client->dev, &pcf8563_rtc_ops, THIS_MODULE); 218 &client->dev, &pcf8563_rtc_ops, THIS_MODULE);
217 219
@@ -220,8 +222,6 @@ static int pcf8563_probe(struct i2c_client *client,
220 goto exit_kfree; 222 goto exit_kfree;
221 } 223 }
222 224
223 i2c_set_clientdata(client, pcf8563);
224
225 return 0; 225 return 0;
226 226
227exit_kfree: 227exit_kfree:
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 7d33cda3f8f6..2d201afead3b 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -277,6 +277,8 @@ static int pcf8583_probe(struct i2c_client *client,
277 if (!pcf8583) 277 if (!pcf8583)
278 return -ENOMEM; 278 return -ENOMEM;
279 279
280 i2c_set_clientdata(client, pcf8583);
281
280 pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name, 282 pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
281 &client->dev, &pcf8583_rtc_ops, THIS_MODULE); 283 &client->dev, &pcf8583_rtc_ops, THIS_MODULE);
282 284
@@ -285,7 +287,6 @@ static int pcf8583_probe(struct i2c_client *client,
285 goto exit_kfree; 287 goto exit_kfree;
286 } 288 }
287 289
288 i2c_set_clientdata(client, pcf8583);
289 return 0; 290 return 0;
290 291
291exit_kfree: 292exit_kfree:
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index f41873f98f66..c256aacfa954 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -7,6 +7,9 @@
7 * 7 *
8 * Copyright 2006 (c) MontaVista Software, Inc. 8 * Copyright 2006 (c) MontaVista Software, Inc.
9 * 9 *
10 * Author: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
11 * Copyright 2010 (c) ST-Ericsson AB
12 *
10 * This program is free software; you can redistribute it and/or 13 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License 14 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 15 * as published by the Free Software Foundation; either version
@@ -18,6 +21,9 @@
18#include <linux/interrupt.h> 21#include <linux/interrupt.h>
19#include <linux/amba/bus.h> 22#include <linux/amba/bus.h>
20#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/bcd.h>
25#include <linux/delay.h>
26#include <linux/version.h>
21 27
22/* 28/*
23 * Register definitions 29 * Register definitions
@@ -30,42 +36,214 @@
30#define RTC_RIS 0x14 /* Raw interrupt status register */ 36#define RTC_RIS 0x14 /* Raw interrupt status register */
31#define RTC_MIS 0x18 /* Masked interrupt status register */ 37#define RTC_MIS 0x18 /* Masked interrupt status register */
32#define RTC_ICR 0x1c /* Interrupt clear register */ 38#define RTC_ICR 0x1c /* Interrupt clear register */
39/* ST variants have additional timer functionality */
40#define RTC_TDR 0x20 /* Timer data read register */
41#define RTC_TLR 0x24 /* Timer data load register */
42#define RTC_TCR 0x28 /* Timer control register */
43#define RTC_YDR 0x30 /* Year data read register */
44#define RTC_YMR 0x34 /* Year match register */
45#define RTC_YLR 0x38 /* Year data load register */
46
47#define RTC_CR_CWEN (1 << 26) /* Clockwatch enable bit */
48
49#define RTC_TCR_EN (1 << 1) /* Periodic timer enable bit */
50
51/* Common bit definitions for Interrupt status and control registers */
52#define RTC_BIT_AI (1 << 0) /* Alarm interrupt bit */
53#define RTC_BIT_PI (1 << 1) /* Periodic interrupt bit. ST variants only. */
54
55/* Common bit definations for ST v2 for reading/writing time */
56#define RTC_SEC_SHIFT 0
57#define RTC_SEC_MASK (0x3F << RTC_SEC_SHIFT) /* Second [0-59] */
58#define RTC_MIN_SHIFT 6
59#define RTC_MIN_MASK (0x3F << RTC_MIN_SHIFT) /* Minute [0-59] */
60#define RTC_HOUR_SHIFT 12
61#define RTC_HOUR_MASK (0x1F << RTC_HOUR_SHIFT) /* Hour [0-23] */
62#define RTC_WDAY_SHIFT 17
63#define RTC_WDAY_MASK (0x7 << RTC_WDAY_SHIFT) /* Day of Week [1-7] 1=Sunday */
64#define RTC_MDAY_SHIFT 20
65#define RTC_MDAY_MASK (0x1F << RTC_MDAY_SHIFT) /* Day of Month [1-31] */
66#define RTC_MON_SHIFT 25
67#define RTC_MON_MASK (0xF << RTC_MON_SHIFT) /* Month [1-12] 1=January */
68
69#define RTC_TIMER_FREQ 32768
33 70
34struct pl031_local { 71struct pl031_local {
35 struct rtc_device *rtc; 72 struct rtc_device *rtc;
36 void __iomem *base; 73 void __iomem *base;
74 u8 hw_designer;
75 u8 hw_revision:4;
37}; 76};
38 77
39static irqreturn_t pl031_interrupt(int irq, void *dev_id) 78static int pl031_alarm_irq_enable(struct device *dev,
79 unsigned int enabled)
40{ 80{
41 struct rtc_device *rtc = dev_id; 81 struct pl031_local *ldata = dev_get_drvdata(dev);
82 unsigned long imsc;
83
84 /* Clear any pending alarm interrupts. */
85 writel(RTC_BIT_AI, ldata->base + RTC_ICR);
86
87 imsc = readl(ldata->base + RTC_IMSC);
42 88
43 rtc_update_irq(rtc, 1, RTC_AF); 89 if (enabled == 1)
90 writel(imsc | RTC_BIT_AI, ldata->base + RTC_IMSC);
91 else
92 writel(imsc & ~RTC_BIT_AI, ldata->base + RTC_IMSC);
44 93
45 return IRQ_HANDLED; 94 return 0;
46} 95}
47 96
48static int pl031_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 97/*
98 * Convert Gregorian date to ST v2 RTC format.
99 */
100static int pl031_stv2_tm_to_time(struct device *dev,
101 struct rtc_time *tm, unsigned long *st_time,
102 unsigned long *bcd_year)
49{ 103{
104 int year = tm->tm_year + 1900;
105 int wday = tm->tm_wday;
106
107 /* wday masking is not working in hardware so wday must be valid */
108 if (wday < -1 || wday > 6) {
109 dev_err(dev, "invalid wday value %d\n", tm->tm_wday);
110 return -EINVAL;
111 } else if (wday == -1) {
112 /* wday is not provided, calculate it here */
113 unsigned long time;
114 struct rtc_time calc_tm;
115
116 rtc_tm_to_time(tm, &time);
117 rtc_time_to_tm(time, &calc_tm);
118 wday = calc_tm.tm_wday;
119 }
120
121 *bcd_year = (bin2bcd(year % 100) | bin2bcd(year / 100) << 8);
122
123 *st_time = ((tm->tm_mon + 1) << RTC_MON_SHIFT)
124 | (tm->tm_mday << RTC_MDAY_SHIFT)
125 | ((wday + 1) << RTC_WDAY_SHIFT)
126 | (tm->tm_hour << RTC_HOUR_SHIFT)
127 | (tm->tm_min << RTC_MIN_SHIFT)
128 | (tm->tm_sec << RTC_SEC_SHIFT);
129
130 return 0;
131}
132
133/*
134 * Convert ST v2 RTC format to Gregorian date.
135 */
136static int pl031_stv2_time_to_tm(unsigned long st_time, unsigned long bcd_year,
137 struct rtc_time *tm)
138{
139 tm->tm_year = bcd2bin(bcd_year) + (bcd2bin(bcd_year >> 8) * 100);
140 tm->tm_mon = ((st_time & RTC_MON_MASK) >> RTC_MON_SHIFT) - 1;
141 tm->tm_mday = ((st_time & RTC_MDAY_MASK) >> RTC_MDAY_SHIFT);
142 tm->tm_wday = ((st_time & RTC_WDAY_MASK) >> RTC_WDAY_SHIFT) - 1;
143 tm->tm_hour = ((st_time & RTC_HOUR_MASK) >> RTC_HOUR_SHIFT);
144 tm->tm_min = ((st_time & RTC_MIN_MASK) >> RTC_MIN_SHIFT);
145 tm->tm_sec = ((st_time & RTC_SEC_MASK) >> RTC_SEC_SHIFT);
146
147 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
148 tm->tm_year -= 1900;
149
150 return 0;
151}
152
153static int pl031_stv2_read_time(struct device *dev, struct rtc_time *tm)
154{
155 struct pl031_local *ldata = dev_get_drvdata(dev);
156
157 pl031_stv2_time_to_tm(readl(ldata->base + RTC_DR),
158 readl(ldata->base + RTC_YDR), tm);
159
160 return 0;
161}
162
163static int pl031_stv2_set_time(struct device *dev, struct rtc_time *tm)
164{
165 unsigned long time;
166 unsigned long bcd_year;
50 struct pl031_local *ldata = dev_get_drvdata(dev); 167 struct pl031_local *ldata = dev_get_drvdata(dev);
168 int ret;
51 169
52 switch (cmd) { 170 ret = pl031_stv2_tm_to_time(dev, tm, &time, &bcd_year);
53 case RTC_AIE_OFF: 171 if (ret == 0) {
54 __raw_writel(1, ldata->base + RTC_MIS); 172 writel(bcd_year, ldata->base + RTC_YLR);
55 return 0; 173 writel(time, ldata->base + RTC_LR);
56 case RTC_AIE_ON:
57 __raw_writel(0, ldata->base + RTC_MIS);
58 return 0;
59 } 174 }
60 175
61 return -ENOIOCTLCMD; 176 return ret;
177}
178
179static int pl031_stv2_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
180{
181 struct pl031_local *ldata = dev_get_drvdata(dev);
182 int ret;
183
184 ret = pl031_stv2_time_to_tm(readl(ldata->base + RTC_MR),
185 readl(ldata->base + RTC_YMR), &alarm->time);
186
187 alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI;
188 alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI;
189
190 return ret;
191}
192
193static int pl031_stv2_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
194{
195 struct pl031_local *ldata = dev_get_drvdata(dev);
196 unsigned long time;
197 unsigned long bcd_year;
198 int ret;
199
200 /* At the moment, we can only deal with non-wildcarded alarm times. */
201 ret = rtc_valid_tm(&alarm->time);
202 if (ret == 0) {
203 ret = pl031_stv2_tm_to_time(dev, &alarm->time,
204 &time, &bcd_year);
205 if (ret == 0) {
206 writel(bcd_year, ldata->base + RTC_YMR);
207 writel(time, ldata->base + RTC_MR);
208
209 pl031_alarm_irq_enable(dev, alarm->enabled);
210 }
211 }
212
213 return ret;
214}
215
216static irqreturn_t pl031_interrupt(int irq, void *dev_id)
217{
218 struct pl031_local *ldata = dev_id;
219 unsigned long rtcmis;
220 unsigned long events = 0;
221
222 rtcmis = readl(ldata->base + RTC_MIS);
223 if (rtcmis) {
224 writel(rtcmis, ldata->base + RTC_ICR);
225
226 if (rtcmis & RTC_BIT_AI)
227 events |= (RTC_AF | RTC_IRQF);
228
229 /* Timer interrupt is only available in ST variants */
230 if ((rtcmis & RTC_BIT_PI) &&
231 (ldata->hw_designer == AMBA_VENDOR_ST))
232 events |= (RTC_PF | RTC_IRQF);
233
234 rtc_update_irq(ldata->rtc, 1, events);
235
236 return IRQ_HANDLED;
237 }
238
239 return IRQ_NONE;
62} 240}
63 241
64static int pl031_read_time(struct device *dev, struct rtc_time *tm) 242static int pl031_read_time(struct device *dev, struct rtc_time *tm)
65{ 243{
66 struct pl031_local *ldata = dev_get_drvdata(dev); 244 struct pl031_local *ldata = dev_get_drvdata(dev);
67 245
68 rtc_time_to_tm(__raw_readl(ldata->base + RTC_DR), tm); 246 rtc_time_to_tm(readl(ldata->base + RTC_DR), tm);
69 247
70 return 0; 248 return 0;
71} 249}
@@ -74,20 +252,24 @@ static int pl031_set_time(struct device *dev, struct rtc_time *tm)
74{ 252{
75 unsigned long time; 253 unsigned long time;
76 struct pl031_local *ldata = dev_get_drvdata(dev); 254 struct pl031_local *ldata = dev_get_drvdata(dev);
255 int ret;
77 256
78 rtc_tm_to_time(tm, &time); 257 ret = rtc_tm_to_time(tm, &time);
79 __raw_writel(time, ldata->base + RTC_LR);
80 258
81 return 0; 259 if (ret == 0)
260 writel(time, ldata->base + RTC_LR);
261
262 return ret;
82} 263}
83 264
84static int pl031_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 265static int pl031_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
85{ 266{
86 struct pl031_local *ldata = dev_get_drvdata(dev); 267 struct pl031_local *ldata = dev_get_drvdata(dev);
87 268
88 rtc_time_to_tm(__raw_readl(ldata->base + RTC_MR), &alarm->time); 269 rtc_time_to_tm(readl(ldata->base + RTC_MR), &alarm->time);
89 alarm->pending = __raw_readl(ldata->base + RTC_RIS); 270
90 alarm->enabled = __raw_readl(ldata->base + RTC_IMSC); 271 alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI;
272 alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI;
91 273
92 return 0; 274 return 0;
93} 275}
@@ -96,22 +278,71 @@ static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
96{ 278{
97 struct pl031_local *ldata = dev_get_drvdata(dev); 279 struct pl031_local *ldata = dev_get_drvdata(dev);
98 unsigned long time; 280 unsigned long time;
281 int ret;
282
283 /* At the moment, we can only deal with non-wildcarded alarm times. */
284 ret = rtc_valid_tm(&alarm->time);
285 if (ret == 0) {
286 ret = rtc_tm_to_time(&alarm->time, &time);
287 if (ret == 0) {
288 writel(time, ldata->base + RTC_MR);
289 pl031_alarm_irq_enable(dev, alarm->enabled);
290 }
291 }
292
293 return ret;
294}
295
296/* Periodic interrupt is only available in ST variants. */
297static int pl031_irq_set_state(struct device *dev, int enabled)
298{
299 struct pl031_local *ldata = dev_get_drvdata(dev);
300
301 if (enabled == 1) {
302 /* Clear any pending timer interrupt. */
303 writel(RTC_BIT_PI, ldata->base + RTC_ICR);
304
305 writel(readl(ldata->base + RTC_IMSC) | RTC_BIT_PI,
306 ldata->base + RTC_IMSC);
307
308 /* Now start the timer */
309 writel(readl(ldata->base + RTC_TCR) | RTC_TCR_EN,
310 ldata->base + RTC_TCR);
99 311
100 rtc_tm_to_time(&alarm->time, &time); 312 } else {
313 writel(readl(ldata->base + RTC_IMSC) & (~RTC_BIT_PI),
314 ldata->base + RTC_IMSC);
101 315
102 __raw_writel(time, ldata->base + RTC_MR); 316 /* Also stop the timer */
103 __raw_writel(!alarm->enabled, ldata->base + RTC_MIS); 317 writel(readl(ldata->base + RTC_TCR) & (~RTC_TCR_EN),
318 ldata->base + RTC_TCR);
319 }
320 /* Wait at least 1 RTC32 clock cycle to ensure next access
321 * to RTC_TCR will succeed.
322 */
323 udelay(40);
104 324
105 return 0; 325 return 0;
106} 326}
107 327
108static const struct rtc_class_ops pl031_ops = { 328static int pl031_irq_set_freq(struct device *dev, int freq)
109 .ioctl = pl031_ioctl, 329{
110 .read_time = pl031_read_time, 330 struct pl031_local *ldata = dev_get_drvdata(dev);
111 .set_time = pl031_set_time, 331
112 .read_alarm = pl031_read_alarm, 332 /* Cant set timer if it is already enabled */
113 .set_alarm = pl031_set_alarm, 333 if (readl(ldata->base + RTC_TCR) & RTC_TCR_EN) {
114}; 334 dev_err(dev, "can't change frequency while timer enabled\n");
335 return -EINVAL;
336 }
337
338 /* If self start bit in RTC_TCR is set timer will start here,
339 * but we never set that bit. Instead we start the timer when
340 * set_state is called with enabled == 1.
341 */
342 writel(RTC_TIMER_FREQ / freq, ldata->base + RTC_TLR);
343
344 return 0;
345}
115 346
116static int pl031_remove(struct amba_device *adev) 347static int pl031_remove(struct amba_device *adev)
117{ 348{
@@ -131,18 +362,20 @@ static int pl031_probe(struct amba_device *adev, struct amba_id *id)
131{ 362{
132 int ret; 363 int ret;
133 struct pl031_local *ldata; 364 struct pl031_local *ldata;
365 struct rtc_class_ops *ops = id->data;
134 366
135 ret = amba_request_regions(adev, NULL); 367 ret = amba_request_regions(adev, NULL);
136 if (ret) 368 if (ret)
137 goto err_req; 369 goto err_req;
138 370
139 ldata = kmalloc(sizeof(struct pl031_local), GFP_KERNEL); 371 ldata = kzalloc(sizeof(struct pl031_local), GFP_KERNEL);
140 if (!ldata) { 372 if (!ldata) {
141 ret = -ENOMEM; 373 ret = -ENOMEM;
142 goto out; 374 goto out;
143 } 375 }
144 376
145 ldata->base = ioremap(adev->res.start, resource_size(&adev->res)); 377 ldata->base = ioremap(adev->res.start, resource_size(&adev->res));
378
146 if (!ldata->base) { 379 if (!ldata->base) {
147 ret = -ENOMEM; 380 ret = -ENOMEM;
148 goto out_no_remap; 381 goto out_no_remap;
@@ -150,24 +383,36 @@ static int pl031_probe(struct amba_device *adev, struct amba_id *id)
150 383
151 amba_set_drvdata(adev, ldata); 384 amba_set_drvdata(adev, ldata);
152 385
153 if (request_irq(adev->irq[0], pl031_interrupt, IRQF_DISABLED, 386 ldata->hw_designer = amba_manf(adev);
154 "rtc-pl031", ldata->rtc)) { 387 ldata->hw_revision = amba_rev(adev);
155 ret = -EIO; 388
156 goto out_no_irq; 389 dev_dbg(&adev->dev, "designer ID = 0x%02x\n", ldata->hw_designer);
157 } 390 dev_dbg(&adev->dev, "revision = 0x%01x\n", ldata->hw_revision);
391
392 /* Enable the clockwatch on ST Variants */
393 if ((ldata->hw_designer == AMBA_VENDOR_ST) &&
394 (ldata->hw_revision > 1))
395 writel(readl(ldata->base + RTC_CR) | RTC_CR_CWEN,
396 ldata->base + RTC_CR);
158 397
159 ldata->rtc = rtc_device_register("pl031", &adev->dev, &pl031_ops, 398 ldata->rtc = rtc_device_register("pl031", &adev->dev, ops,
160 THIS_MODULE); 399 THIS_MODULE);
161 if (IS_ERR(ldata->rtc)) { 400 if (IS_ERR(ldata->rtc)) {
162 ret = PTR_ERR(ldata->rtc); 401 ret = PTR_ERR(ldata->rtc);
163 goto out_no_rtc; 402 goto out_no_rtc;
164 } 403 }
165 404
405 if (request_irq(adev->irq[0], pl031_interrupt,
406 IRQF_DISABLED | IRQF_SHARED, "rtc-pl031", ldata)) {
407 ret = -EIO;
408 goto out_no_irq;
409 }
410
166 return 0; 411 return 0;
167 412
168out_no_rtc:
169 free_irq(adev->irq[0], ldata->rtc);
170out_no_irq: 413out_no_irq:
414 rtc_device_unregister(ldata->rtc);
415out_no_rtc:
171 iounmap(ldata->base); 416 iounmap(ldata->base);
172 amba_set_drvdata(adev, NULL); 417 amba_set_drvdata(adev, NULL);
173out_no_remap: 418out_no_remap:
@@ -175,13 +420,58 @@ out_no_remap:
175out: 420out:
176 amba_release_regions(adev); 421 amba_release_regions(adev);
177err_req: 422err_req:
423
178 return ret; 424 return ret;
179} 425}
180 426
427/* Operations for the original ARM version */
428static struct rtc_class_ops arm_pl031_ops = {
429 .read_time = pl031_read_time,
430 .set_time = pl031_set_time,
431 .read_alarm = pl031_read_alarm,
432 .set_alarm = pl031_set_alarm,
433 .alarm_irq_enable = pl031_alarm_irq_enable,
434};
435
436/* The First ST derivative */
437static struct rtc_class_ops stv1_pl031_ops = {
438 .read_time = pl031_read_time,
439 .set_time = pl031_set_time,
440 .read_alarm = pl031_read_alarm,
441 .set_alarm = pl031_set_alarm,
442 .alarm_irq_enable = pl031_alarm_irq_enable,
443 .irq_set_state = pl031_irq_set_state,
444 .irq_set_freq = pl031_irq_set_freq,
445};
446
447/* And the second ST derivative */
448static struct rtc_class_ops stv2_pl031_ops = {
449 .read_time = pl031_stv2_read_time,
450 .set_time = pl031_stv2_set_time,
451 .read_alarm = pl031_stv2_read_alarm,
452 .set_alarm = pl031_stv2_set_alarm,
453 .alarm_irq_enable = pl031_alarm_irq_enable,
454 .irq_set_state = pl031_irq_set_state,
455 .irq_set_freq = pl031_irq_set_freq,
456};
457
181static struct amba_id pl031_ids[] __initdata = { 458static struct amba_id pl031_ids[] __initdata = {
182 { 459 {
183 .id = 0x00041031, 460 .id = 0x00041031,
184 .mask = 0x000fffff, }, 461 .mask = 0x000fffff,
462 .data = &arm_pl031_ops,
463 },
464 /* ST Micro variants */
465 {
466 .id = 0x00180031,
467 .mask = 0x00ffffff,
468 .data = &stv1_pl031_ops,
469 },
470 {
471 .id = 0x00280031,
472 .mask = 0x00ffffff,
473 .data = &stv2_pl031_ops,
474 },
185 {0, 0}, 475 {0, 0},
186}; 476};
187 477
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index 747ca194fad4..e6351b743da6 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -456,7 +456,7 @@ static int pxa_rtc_resume(struct device *dev)
456 return 0; 456 return 0;
457} 457}
458 458
459static struct dev_pm_ops pxa_rtc_pm_ops = { 459static const struct dev_pm_ops pxa_rtc_pm_ops = {
460 .suspend = pxa_rtc_suspend, 460 .suspend = pxa_rtc_suspend,
461 .resume = pxa_rtc_resume, 461 .resume = pxa_rtc_resume,
462}; 462};
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 29f98a70586e..e4a44b641702 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -407,7 +407,7 @@ static int sa1100_rtc_resume(struct device *dev)
407 return 0; 407 return 0;
408} 408}
409 409
410static struct dev_pm_ops sa1100_rtc_pm_ops = { 410static const struct dev_pm_ops sa1100_rtc_pm_ops = {
411 .suspend = sa1100_rtc_suspend, 411 .suspend = sa1100_rtc_suspend,
412 .resume = sa1100_rtc_resume, 412 .resume = sa1100_rtc_resume,
413}; 413};
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index e6ed5404bca0..e95cc6f8d61e 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -826,7 +826,7 @@ static int sh_rtc_resume(struct device *dev)
826 return 0; 826 return 0;
827} 827}
828 828
829static struct dev_pm_ops sh_rtc_dev_pm_ops = { 829static const struct dev_pm_ops sh_rtc_dev_pm_ops = {
830 .suspend = sh_rtc_suspend, 830 .suspend = sh_rtc_suspend,
831 .resume = sh_rtc_resume, 831 .resume = sh_rtc_resume,
832}; 832};
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index d491eb265c38..67700831b5c9 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -62,7 +62,6 @@
62struct rtc_plat_data { 62struct rtc_plat_data {
63 struct rtc_device *rtc; 63 struct rtc_device *rtc;
64 void __iomem *ioaddr; 64 void __iomem *ioaddr;
65 unsigned long baseaddr;
66 unsigned long last_jiffies; 65 unsigned long last_jiffies;
67 int irq; 66 int irq;
68 unsigned int irqen; 67 unsigned int irqen;
@@ -70,6 +69,7 @@ struct rtc_plat_data {
70 int alrm_min; 69 int alrm_min;
71 int alrm_hour; 70 int alrm_hour;
72 int alrm_mday; 71 int alrm_mday;
72 spinlock_t lock;
73}; 73};
74 74
75static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm) 75static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -142,7 +142,7 @@ static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata)
142 unsigned long irqflags; 142 unsigned long irqflags;
143 u8 flags; 143 u8 flags;
144 144
145 spin_lock_irqsave(&pdata->rtc->irq_lock, irqflags); 145 spin_lock_irqsave(&pdata->lock, irqflags);
146 146
147 flags = readb(ioaddr + RTC_FLAGS); 147 flags = readb(ioaddr + RTC_FLAGS);
148 writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS); 148 writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
@@ -162,7 +162,7 @@ static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata)
162 writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS); 162 writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS);
163 readb(ioaddr + RTC_FLAGS); /* clear interrupts */ 163 readb(ioaddr + RTC_FLAGS); /* clear interrupts */
164 writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS); 164 writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS);
165 spin_unlock_irqrestore(&pdata->rtc->irq_lock, irqflags); 165 spin_unlock_irqrestore(&pdata->lock, irqflags);
166} 166}
167 167
168static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 168static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
@@ -202,56 +202,53 @@ static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id)
202 struct platform_device *pdev = dev_id; 202 struct platform_device *pdev = dev_id;
203 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 203 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
204 void __iomem *ioaddr = pdata->ioaddr; 204 void __iomem *ioaddr = pdata->ioaddr;
205 unsigned long events = RTC_IRQF; 205 unsigned long events = 0;
206 206
207 spin_lock(&pdata->lock);
207 /* read and clear interrupt */ 208 /* read and clear interrupt */
208 if (!(readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF)) 209 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF) {
209 return IRQ_NONE; 210 events = RTC_IRQF;
210 if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80) 211 if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80)
211 events |= RTC_UF; 212 events |= RTC_UF;
212 else 213 else
213 events |= RTC_AF; 214 events |= RTC_AF;
214 rtc_update_irq(pdata->rtc, 1, events); 215 if (likely(pdata->rtc))
215 return IRQ_HANDLED; 216 rtc_update_irq(pdata->rtc, 1, events);
217 }
218 spin_unlock(&pdata->lock);
219 return events ? IRQ_HANDLED : IRQ_NONE;
216} 220}
217 221
218static int stk17ta8_rtc_ioctl(struct device *dev, unsigned int cmd, 222static int stk17ta8_rtc_alarm_irq_enable(struct device *dev,
219 unsigned long arg) 223 unsigned int enabled)
220{ 224{
221 struct platform_device *pdev = to_platform_device(dev); 225 struct platform_device *pdev = to_platform_device(dev);
222 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 226 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
223 227
224 if (pdata->irq <= 0) 228 if (pdata->irq <= 0)
225 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */ 229 return -EINVAL;
226 switch (cmd) { 230 if (enabled)
227 case RTC_AIE_OFF:
228 pdata->irqen &= ~RTC_AF;
229 stk17ta8_rtc_update_alarm(pdata);
230 break;
231 case RTC_AIE_ON:
232 pdata->irqen |= RTC_AF; 231 pdata->irqen |= RTC_AF;
233 stk17ta8_rtc_update_alarm(pdata); 232 else
234 break; 233 pdata->irqen &= ~RTC_AF;
235 default: 234 stk17ta8_rtc_update_alarm(pdata);
236 return -ENOIOCTLCMD;
237 }
238 return 0; 235 return 0;
239} 236}
240 237
241static const struct rtc_class_ops stk17ta8_rtc_ops = { 238static const struct rtc_class_ops stk17ta8_rtc_ops = {
242 .read_time = stk17ta8_rtc_read_time, 239 .read_time = stk17ta8_rtc_read_time,
243 .set_time = stk17ta8_rtc_set_time, 240 .set_time = stk17ta8_rtc_set_time,
244 .read_alarm = stk17ta8_rtc_read_alarm, 241 .read_alarm = stk17ta8_rtc_read_alarm,
245 .set_alarm = stk17ta8_rtc_set_alarm, 242 .set_alarm = stk17ta8_rtc_set_alarm,
246 .ioctl = stk17ta8_rtc_ioctl, 243 .alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable,
247}; 244};
248 245
249static ssize_t stk17ta8_nvram_read(struct kobject *kobj, 246static ssize_t stk17ta8_nvram_read(struct kobject *kobj,
250 struct bin_attribute *attr, char *buf, 247 struct bin_attribute *attr, char *buf,
251 loff_t pos, size_t size) 248 loff_t pos, size_t size)
252{ 249{
253 struct platform_device *pdev = 250 struct device *dev = container_of(kobj, struct device, kobj);
254 to_platform_device(container_of(kobj, struct device, kobj)); 251 struct platform_device *pdev = to_platform_device(dev);
255 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 252 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
256 void __iomem *ioaddr = pdata->ioaddr; 253 void __iomem *ioaddr = pdata->ioaddr;
257 ssize_t count; 254 ssize_t count;
@@ -265,8 +262,8 @@ static ssize_t stk17ta8_nvram_write(struct kobject *kobj,
265 struct bin_attribute *attr, char *buf, 262 struct bin_attribute *attr, char *buf,
266 loff_t pos, size_t size) 263 loff_t pos, size_t size)
267{ 264{
268 struct platform_device *pdev = 265 struct device *dev = container_of(kobj, struct device, kobj);
269 to_platform_device(container_of(kobj, struct device, kobj)); 266 struct platform_device *pdev = to_platform_device(dev);
270 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 267 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
271 void __iomem *ioaddr = pdata->ioaddr; 268 void __iomem *ioaddr = pdata->ioaddr;
272 ssize_t count; 269 ssize_t count;
@@ -288,31 +285,26 @@ static struct bin_attribute stk17ta8_nvram_attr = {
288 285
289static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev) 286static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev)
290{ 287{
291 struct rtc_device *rtc;
292 struct resource *res; 288 struct resource *res;
293 unsigned int cal; 289 unsigned int cal;
294 unsigned int flags; 290 unsigned int flags;
295 struct rtc_plat_data *pdata; 291 struct rtc_plat_data *pdata;
296 void __iomem *ioaddr = NULL; 292 void __iomem *ioaddr;
297 int ret = 0; 293 int ret = 0;
298 294
299 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 295 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
300 if (!res) 296 if (!res)
301 return -ENODEV; 297 return -ENODEV;
302 298
303 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 299 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
304 if (!pdata) 300 if (!pdata)
305 return -ENOMEM; 301 return -ENOMEM;
306 if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) { 302 if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE,
307 ret = -EBUSY; 303 pdev->name))
308 goto out; 304 return -EBUSY;
309 } 305 ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE);
310 pdata->baseaddr = res->start; 306 if (!ioaddr)
311 ioaddr = ioremap(pdata->baseaddr, RTC_REG_SIZE); 307 return -ENOMEM;
312 if (!ioaddr) {
313 ret = -ENOMEM;
314 goto out;
315 }
316 pdata->ioaddr = ioaddr; 308 pdata->ioaddr = ioaddr;
317 pdata->irq = platform_get_irq(pdev, 0); 309 pdata->irq = platform_get_irq(pdev, 0);
318 310
@@ -328,9 +320,13 @@ static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev)
328 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF) 320 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF)
329 dev_warn(&pdev->dev, "voltage-low detected.\n"); 321 dev_warn(&pdev->dev, "voltage-low detected.\n");
330 322
323 spin_lock_init(&pdata->lock);
324 pdata->last_jiffies = jiffies;
325 platform_set_drvdata(pdev, pdata);
331 if (pdata->irq > 0) { 326 if (pdata->irq > 0) {
332 writeb(0, ioaddr + RTC_INTERRUPTS); 327 writeb(0, ioaddr + RTC_INTERRUPTS);
333 if (request_irq(pdata->irq, stk17ta8_rtc_interrupt, 328 if (devm_request_irq(&pdev->dev, pdata->irq,
329 stk17ta8_rtc_interrupt,
334 IRQF_DISABLED | IRQF_SHARED, 330 IRQF_DISABLED | IRQF_SHARED,
335 pdev->name, pdev) < 0) { 331 pdev->name, pdev) < 0) {
336 dev_warn(&pdev->dev, "interrupt not available.\n"); 332 dev_warn(&pdev->dev, "interrupt not available.\n");
@@ -338,29 +334,14 @@ static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev)
338 } 334 }
339 } 335 }
340 336
341 rtc = rtc_device_register(pdev->name, &pdev->dev, 337 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev,
342 &stk17ta8_rtc_ops, THIS_MODULE); 338 &stk17ta8_rtc_ops, THIS_MODULE);
343 if (IS_ERR(rtc)) { 339 if (IS_ERR(pdata->rtc))
344 ret = PTR_ERR(rtc); 340 return PTR_ERR(pdata->rtc);
345 goto out; 341
346 }
347 pdata->rtc = rtc;
348 pdata->last_jiffies = jiffies;
349 platform_set_drvdata(pdev, pdata);
350 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 342 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
351 if (ret) 343 if (ret)
352 goto out;
353 return 0;
354 out:
355 if (pdata->rtc)
356 rtc_device_unregister(pdata->rtc); 344 rtc_device_unregister(pdata->rtc);
357 if (pdata->irq > 0)
358 free_irq(pdata->irq, pdev);
359 if (ioaddr)
360 iounmap(ioaddr);
361 if (pdata->baseaddr)
362 release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
363 kfree(pdata);
364 return ret; 345 return ret;
365} 346}
366 347
@@ -370,13 +351,8 @@ static int __devexit stk17ta8_rtc_remove(struct platform_device *pdev)
370 351
371 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 352 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
372 rtc_device_unregister(pdata->rtc); 353 rtc_device_unregister(pdata->rtc);
373 if (pdata->irq > 0) { 354 if (pdata->irq > 0)
374 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 355 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
375 free_irq(pdata->irq, pdev);
376 }
377 iounmap(pdata->ioaddr);
378 release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
379 kfree(pdata);
380 return 0; 356 return 0;
381} 357}
382 358
diff --git a/drivers/rtc/rtc-twl4030.c b/drivers/rtc/rtc-twl.c
index 9c8c70c497dc..c6a83a2a722c 100644
--- a/drivers/rtc/rtc-twl4030.c
+++ b/drivers/rtc/rtc-twl.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * rtc-twl4030.c -- TWL4030 Real Time Clock interface 2 * rtc-twl.c -- TWL Real Time Clock interface
3 * 3 *
4 * Copyright (C) 2007 MontaVista Software, Inc 4 * Copyright (C) 2007 MontaVista Software, Inc
5 * Author: Alexandre Rusev <source@mvista.com> 5 * Author: Alexandre Rusev <source@mvista.com>
@@ -28,33 +28,81 @@
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30 30
31#include <linux/i2c/twl4030.h> 31#include <linux/i2c/twl.h>
32 32
33 33
34/* 34/*
35 * RTC block register offsets (use TWL_MODULE_RTC) 35 * RTC block register offsets (use TWL_MODULE_RTC)
36 */ 36 */
37#define REG_SECONDS_REG 0x00 37enum {
38#define REG_MINUTES_REG 0x01 38 REG_SECONDS_REG = 0,
39#define REG_HOURS_REG 0x02 39 REG_MINUTES_REG,
40#define REG_DAYS_REG 0x03 40 REG_HOURS_REG,
41#define REG_MONTHS_REG 0x04 41 REG_DAYS_REG,
42#define REG_YEARS_REG 0x05 42 REG_MONTHS_REG,
43#define REG_WEEKS_REG 0x06 43 REG_YEARS_REG,
44 44 REG_WEEKS_REG,
45#define REG_ALARM_SECONDS_REG 0x07 45
46#define REG_ALARM_MINUTES_REG 0x08 46 REG_ALARM_SECONDS_REG,
47#define REG_ALARM_HOURS_REG 0x09 47 REG_ALARM_MINUTES_REG,
48#define REG_ALARM_DAYS_REG 0x0A 48 REG_ALARM_HOURS_REG,
49#define REG_ALARM_MONTHS_REG 0x0B 49 REG_ALARM_DAYS_REG,
50#define REG_ALARM_YEARS_REG 0x0C 50 REG_ALARM_MONTHS_REG,
51 51 REG_ALARM_YEARS_REG,
52#define REG_RTC_CTRL_REG 0x0D 52
53#define REG_RTC_STATUS_REG 0x0E 53 REG_RTC_CTRL_REG,
54#define REG_RTC_INTERRUPTS_REG 0x0F 54 REG_RTC_STATUS_REG,
55 55 REG_RTC_INTERRUPTS_REG,
56#define REG_RTC_COMP_LSB_REG 0x10 56
57#define REG_RTC_COMP_MSB_REG 0x11 57 REG_RTC_COMP_LSB_REG,
58 REG_RTC_COMP_MSB_REG,
59};
60const static u8 twl4030_rtc_reg_map[] = {
61 [REG_SECONDS_REG] = 0x00,
62 [REG_MINUTES_REG] = 0x01,
63 [REG_HOURS_REG] = 0x02,
64 [REG_DAYS_REG] = 0x03,
65 [REG_MONTHS_REG] = 0x04,
66 [REG_YEARS_REG] = 0x05,
67 [REG_WEEKS_REG] = 0x06,
68
69 [REG_ALARM_SECONDS_REG] = 0x07,
70 [REG_ALARM_MINUTES_REG] = 0x08,
71 [REG_ALARM_HOURS_REG] = 0x09,
72 [REG_ALARM_DAYS_REG] = 0x0A,
73 [REG_ALARM_MONTHS_REG] = 0x0B,
74 [REG_ALARM_YEARS_REG] = 0x0C,
75
76 [REG_RTC_CTRL_REG] = 0x0D,
77 [REG_RTC_STATUS_REG] = 0x0E,
78 [REG_RTC_INTERRUPTS_REG] = 0x0F,
79
80 [REG_RTC_COMP_LSB_REG] = 0x10,
81 [REG_RTC_COMP_MSB_REG] = 0x11,
82};
83const static u8 twl6030_rtc_reg_map[] = {
84 [REG_SECONDS_REG] = 0x00,
85 [REG_MINUTES_REG] = 0x01,
86 [REG_HOURS_REG] = 0x02,
87 [REG_DAYS_REG] = 0x03,
88 [REG_MONTHS_REG] = 0x04,
89 [REG_YEARS_REG] = 0x05,
90 [REG_WEEKS_REG] = 0x06,
91
92 [REG_ALARM_SECONDS_REG] = 0x08,
93 [REG_ALARM_MINUTES_REG] = 0x09,
94 [REG_ALARM_HOURS_REG] = 0x0A,
95 [REG_ALARM_DAYS_REG] = 0x0B,
96 [REG_ALARM_MONTHS_REG] = 0x0C,
97 [REG_ALARM_YEARS_REG] = 0x0D,
98
99 [REG_RTC_CTRL_REG] = 0x10,
100 [REG_RTC_STATUS_REG] = 0x11,
101 [REG_RTC_INTERRUPTS_REG] = 0x12,
102
103 [REG_RTC_COMP_LSB_REG] = 0x13,
104 [REG_RTC_COMP_MSB_REG] = 0x14,
105};
58 106
59/* RTC_CTRL_REG bitfields */ 107/* RTC_CTRL_REG bitfields */
60#define BIT_RTC_CTRL_REG_STOP_RTC_M 0x01 108#define BIT_RTC_CTRL_REG_STOP_RTC_M 0x01
@@ -84,31 +132,32 @@
84#define ALL_TIME_REGS 6 132#define ALL_TIME_REGS 6
85 133
86/*----------------------------------------------------------------------*/ 134/*----------------------------------------------------------------------*/
135static u8 *rtc_reg_map;
87 136
88/* 137/*
89 * Supports 1 byte read from TWL4030 RTC register. 138 * Supports 1 byte read from TWL RTC register.
90 */ 139 */
91static int twl4030_rtc_read_u8(u8 *data, u8 reg) 140static int twl_rtc_read_u8(u8 *data, u8 reg)
92{ 141{
93 int ret; 142 int ret;
94 143
95 ret = twl4030_i2c_read_u8(TWL4030_MODULE_RTC, data, reg); 144 ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg]));
96 if (ret < 0) 145 if (ret < 0)
97 pr_err("twl4030_rtc: Could not read TWL4030" 146 pr_err("twl_rtc: Could not read TWL"
98 "register %X - error %d\n", reg, ret); 147 "register %X - error %d\n", reg, ret);
99 return ret; 148 return ret;
100} 149}
101 150
102/* 151/*
103 * Supports 1 byte write to TWL4030 RTC registers. 152 * Supports 1 byte write to TWL RTC registers.
104 */ 153 */
105static int twl4030_rtc_write_u8(u8 data, u8 reg) 154static int twl_rtc_write_u8(u8 data, u8 reg)
106{ 155{
107 int ret; 156 int ret;
108 157
109 ret = twl4030_i2c_write_u8(TWL4030_MODULE_RTC, data, reg); 158 ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg]));
110 if (ret < 0) 159 if (ret < 0)
111 pr_err("twl4030_rtc: Could not write TWL4030" 160 pr_err("twl_rtc: Could not write TWL"
112 "register %X - error %d\n", reg, ret); 161 "register %X - error %d\n", reg, ret);
113 return ret; 162 return ret;
114} 163}
@@ -129,7 +178,7 @@ static int set_rtc_irq_bit(unsigned char bit)
129 178
130 val = rtc_irq_bits | bit; 179 val = rtc_irq_bits | bit;
131 val &= ~BIT_RTC_INTERRUPTS_REG_EVERY_M; 180 val &= ~BIT_RTC_INTERRUPTS_REG_EVERY_M;
132 ret = twl4030_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG); 181 ret = twl_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
133 if (ret == 0) 182 if (ret == 0)
134 rtc_irq_bits = val; 183 rtc_irq_bits = val;
135 184
@@ -145,14 +194,14 @@ static int mask_rtc_irq_bit(unsigned char bit)
145 int ret; 194 int ret;
146 195
147 val = rtc_irq_bits & ~bit; 196 val = rtc_irq_bits & ~bit;
148 ret = twl4030_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG); 197 ret = twl_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
149 if (ret == 0) 198 if (ret == 0)
150 rtc_irq_bits = val; 199 rtc_irq_bits = val;
151 200
152 return ret; 201 return ret;
153} 202}
154 203
155static int twl4030_rtc_alarm_irq_enable(struct device *dev, unsigned enabled) 204static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
156{ 205{
157 int ret; 206 int ret;
158 207
@@ -164,7 +213,7 @@ static int twl4030_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
164 return ret; 213 return ret;
165} 214}
166 215
167static int twl4030_rtc_update_irq_enable(struct device *dev, unsigned enabled) 216static int twl_rtc_update_irq_enable(struct device *dev, unsigned enabled)
168{ 217{
169 int ret; 218 int ret;
170 219
@@ -177,7 +226,7 @@ static int twl4030_rtc_update_irq_enable(struct device *dev, unsigned enabled)
177} 226}
178 227
179/* 228/*
180 * Gets current TWL4030 RTC time and date parameters. 229 * Gets current TWL RTC time and date parameters.
181 * 230 *
182 * The RTC's time/alarm representation is not what gmtime(3) requires 231 * The RTC's time/alarm representation is not what gmtime(3) requires
183 * Linux to use: 232 * Linux to use:
@@ -185,24 +234,24 @@ static int twl4030_rtc_update_irq_enable(struct device *dev, unsigned enabled)
185 * - Months are 1..12 vs Linux 0-11 234 * - Months are 1..12 vs Linux 0-11
186 * - Years are 0..99 vs Linux 1900..N (we assume 21st century) 235 * - Years are 0..99 vs Linux 1900..N (we assume 21st century)
187 */ 236 */
188static int twl4030_rtc_read_time(struct device *dev, struct rtc_time *tm) 237static int twl_rtc_read_time(struct device *dev, struct rtc_time *tm)
189{ 238{
190 unsigned char rtc_data[ALL_TIME_REGS + 1]; 239 unsigned char rtc_data[ALL_TIME_REGS + 1];
191 int ret; 240 int ret;
192 u8 save_control; 241 u8 save_control;
193 242
194 ret = twl4030_rtc_read_u8(&save_control, REG_RTC_CTRL_REG); 243 ret = twl_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
195 if (ret < 0) 244 if (ret < 0)
196 return ret; 245 return ret;
197 246
198 save_control |= BIT_RTC_CTRL_REG_GET_TIME_M; 247 save_control |= BIT_RTC_CTRL_REG_GET_TIME_M;
199 248
200 ret = twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG); 249 ret = twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
201 if (ret < 0) 250 if (ret < 0)
202 return ret; 251 return ret;
203 252
204 ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data, 253 ret = twl_i2c_read(TWL_MODULE_RTC, rtc_data,
205 REG_SECONDS_REG, ALL_TIME_REGS); 254 (rtc_reg_map[REG_SECONDS_REG]), ALL_TIME_REGS);
206 255
207 if (ret < 0) { 256 if (ret < 0) {
208 dev_err(dev, "rtc_read_time error %d\n", ret); 257 dev_err(dev, "rtc_read_time error %d\n", ret);
@@ -219,7 +268,7 @@ static int twl4030_rtc_read_time(struct device *dev, struct rtc_time *tm)
219 return ret; 268 return ret;
220} 269}
221 270
222static int twl4030_rtc_set_time(struct device *dev, struct rtc_time *tm) 271static int twl_rtc_set_time(struct device *dev, struct rtc_time *tm)
223{ 272{
224 unsigned char save_control; 273 unsigned char save_control;
225 unsigned char rtc_data[ALL_TIME_REGS + 1]; 274 unsigned char rtc_data[ALL_TIME_REGS + 1];
@@ -233,18 +282,18 @@ static int twl4030_rtc_set_time(struct device *dev, struct rtc_time *tm)
233 rtc_data[6] = bin2bcd(tm->tm_year - 100); 282 rtc_data[6] = bin2bcd(tm->tm_year - 100);
234 283
235 /* Stop RTC while updating the TC registers */ 284 /* Stop RTC while updating the TC registers */
236 ret = twl4030_rtc_read_u8(&save_control, REG_RTC_CTRL_REG); 285 ret = twl_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
237 if (ret < 0) 286 if (ret < 0)
238 goto out; 287 goto out;
239 288
240 save_control &= ~BIT_RTC_CTRL_REG_STOP_RTC_M; 289 save_control &= ~BIT_RTC_CTRL_REG_STOP_RTC_M;
241 twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG); 290 twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
242 if (ret < 0) 291 if (ret < 0)
243 goto out; 292 goto out;
244 293
245 /* update all the time registers in one shot */ 294 /* update all the time registers in one shot */
246 ret = twl4030_i2c_write(TWL4030_MODULE_RTC, rtc_data, 295 ret = twl_i2c_write(TWL_MODULE_RTC, rtc_data,
247 REG_SECONDS_REG, ALL_TIME_REGS); 296 (rtc_reg_map[REG_SECONDS_REG]), ALL_TIME_REGS);
248 if (ret < 0) { 297 if (ret < 0) {
249 dev_err(dev, "rtc_set_time error %d\n", ret); 298 dev_err(dev, "rtc_set_time error %d\n", ret);
250 goto out; 299 goto out;
@@ -252,22 +301,22 @@ static int twl4030_rtc_set_time(struct device *dev, struct rtc_time *tm)
252 301
253 /* Start back RTC */ 302 /* Start back RTC */
254 save_control |= BIT_RTC_CTRL_REG_STOP_RTC_M; 303 save_control |= BIT_RTC_CTRL_REG_STOP_RTC_M;
255 ret = twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG); 304 ret = twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
256 305
257out: 306out:
258 return ret; 307 return ret;
259} 308}
260 309
261/* 310/*
262 * Gets current TWL4030 RTC alarm time. 311 * Gets current TWL RTC alarm time.
263 */ 312 */
264static int twl4030_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 313static int twl_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
265{ 314{
266 unsigned char rtc_data[ALL_TIME_REGS + 1]; 315 unsigned char rtc_data[ALL_TIME_REGS + 1];
267 int ret; 316 int ret;
268 317
269 ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data, 318 ret = twl_i2c_read(TWL_MODULE_RTC, rtc_data,
270 REG_ALARM_SECONDS_REG, ALL_TIME_REGS); 319 (rtc_reg_map[REG_ALARM_SECONDS_REG]), ALL_TIME_REGS);
271 if (ret < 0) { 320 if (ret < 0) {
272 dev_err(dev, "rtc_read_alarm error %d\n", ret); 321 dev_err(dev, "rtc_read_alarm error %d\n", ret);
273 return ret; 322 return ret;
@@ -288,12 +337,12 @@ static int twl4030_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
288 return ret; 337 return ret;
289} 338}
290 339
291static int twl4030_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 340static int twl_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
292{ 341{
293 unsigned char alarm_data[ALL_TIME_REGS + 1]; 342 unsigned char alarm_data[ALL_TIME_REGS + 1];
294 int ret; 343 int ret;
295 344
296 ret = twl4030_rtc_alarm_irq_enable(dev, 0); 345 ret = twl_rtc_alarm_irq_enable(dev, 0);
297 if (ret) 346 if (ret)
298 goto out; 347 goto out;
299 348
@@ -305,20 +354,20 @@ static int twl4030_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
305 alarm_data[6] = bin2bcd(alm->time.tm_year - 100); 354 alarm_data[6] = bin2bcd(alm->time.tm_year - 100);
306 355
307 /* update all the alarm registers in one shot */ 356 /* update all the alarm registers in one shot */
308 ret = twl4030_i2c_write(TWL4030_MODULE_RTC, alarm_data, 357 ret = twl_i2c_write(TWL_MODULE_RTC, alarm_data,
309 REG_ALARM_SECONDS_REG, ALL_TIME_REGS); 358 (rtc_reg_map[REG_ALARM_SECONDS_REG]), ALL_TIME_REGS);
310 if (ret) { 359 if (ret) {
311 dev_err(dev, "rtc_set_alarm error %d\n", ret); 360 dev_err(dev, "rtc_set_alarm error %d\n", ret);
312 goto out; 361 goto out;
313 } 362 }
314 363
315 if (alm->enabled) 364 if (alm->enabled)
316 ret = twl4030_rtc_alarm_irq_enable(dev, 1); 365 ret = twl_rtc_alarm_irq_enable(dev, 1);
317out: 366out:
318 return ret; 367 return ret;
319} 368}
320 369
321static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc) 370static irqreturn_t twl_rtc_interrupt(int irq, void *rtc)
322{ 371{
323 unsigned long events = 0; 372 unsigned long events = 0;
324 int ret = IRQ_NONE; 373 int ret = IRQ_NONE;
@@ -333,7 +382,7 @@ static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc)
333 local_irq_enable(); 382 local_irq_enable();
334#endif 383#endif
335 384
336 res = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG); 385 res = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
337 if (res) 386 if (res)
338 goto out; 387 goto out;
339 /* 388 /*
@@ -347,26 +396,28 @@ static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc)
347 else 396 else
348 events |= RTC_IRQF | RTC_UF; 397 events |= RTC_IRQF | RTC_UF;
349 398
350 res = twl4030_rtc_write_u8(rd_reg | BIT_RTC_STATUS_REG_ALARM_M, 399 res = twl_rtc_write_u8(rd_reg | BIT_RTC_STATUS_REG_ALARM_M,
351 REG_RTC_STATUS_REG); 400 REG_RTC_STATUS_REG);
352 if (res) 401 if (res)
353 goto out; 402 goto out;
354 403
355 /* Clear on Read enabled. RTC_IT bit of TWL4030_INT_PWR_ISR1 404 if (twl_class_is_4030()) {
356 * needs 2 reads to clear the interrupt. One read is done in 405 /* Clear on Read enabled. RTC_IT bit of TWL4030_INT_PWR_ISR1
357 * do_twl4030_pwrirq(). Doing the second read, to clear 406 * needs 2 reads to clear the interrupt. One read is done in
358 * the bit. 407 * do_twl_pwrirq(). Doing the second read, to clear
359 * 408 * the bit.
360 * FIXME the reason PWR_ISR1 needs an extra read is that 409 *
361 * RTC_IF retriggered until we cleared REG_ALARM_M above. 410 * FIXME the reason PWR_ISR1 needs an extra read is that
362 * But re-reading like this is a bad hack; by doing so we 411 * RTC_IF retriggered until we cleared REG_ALARM_M above.
363 * risk wrongly clearing status for some other IRQ (losing 412 * But re-reading like this is a bad hack; by doing so we
364 * the interrupt). Be smarter about handling RTC_UF ... 413 * risk wrongly clearing status for some other IRQ (losing
365 */ 414 * the interrupt). Be smarter about handling RTC_UF ...
366 res = twl4030_i2c_read_u8(TWL4030_MODULE_INT, 415 */
416 res = twl_i2c_read_u8(TWL4030_MODULE_INT,
367 &rd_reg, TWL4030_INT_PWR_ISR1); 417 &rd_reg, TWL4030_INT_PWR_ISR1);
368 if (res) 418 if (res)
369 goto out; 419 goto out;
420 }
370 421
371 /* Notify RTC core on event */ 422 /* Notify RTC core on event */
372 rtc_update_irq(rtc, 1, events); 423 rtc_update_irq(rtc, 1, events);
@@ -376,18 +427,18 @@ out:
376 return ret; 427 return ret;
377} 428}
378 429
379static struct rtc_class_ops twl4030_rtc_ops = { 430static struct rtc_class_ops twl_rtc_ops = {
380 .read_time = twl4030_rtc_read_time, 431 .read_time = twl_rtc_read_time,
381 .set_time = twl4030_rtc_set_time, 432 .set_time = twl_rtc_set_time,
382 .read_alarm = twl4030_rtc_read_alarm, 433 .read_alarm = twl_rtc_read_alarm,
383 .set_alarm = twl4030_rtc_set_alarm, 434 .set_alarm = twl_rtc_set_alarm,
384 .alarm_irq_enable = twl4030_rtc_alarm_irq_enable, 435 .alarm_irq_enable = twl_rtc_alarm_irq_enable,
385 .update_irq_enable = twl4030_rtc_update_irq_enable, 436 .update_irq_enable = twl_rtc_update_irq_enable,
386}; 437};
387 438
388/*----------------------------------------------------------------------*/ 439/*----------------------------------------------------------------------*/
389 440
390static int __devinit twl4030_rtc_probe(struct platform_device *pdev) 441static int __devinit twl_rtc_probe(struct platform_device *pdev)
391{ 442{
392 struct rtc_device *rtc; 443 struct rtc_device *rtc;
393 int ret = 0; 444 int ret = 0;
@@ -398,7 +449,7 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
398 return -EINVAL; 449 return -EINVAL;
399 450
400 rtc = rtc_device_register(pdev->name, 451 rtc = rtc_device_register(pdev->name,
401 &pdev->dev, &twl4030_rtc_ops, THIS_MODULE); 452 &pdev->dev, &twl_rtc_ops, THIS_MODULE);
402 if (IS_ERR(rtc)) { 453 if (IS_ERR(rtc)) {
403 ret = PTR_ERR(rtc); 454 ret = PTR_ERR(rtc);
404 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 455 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
@@ -409,7 +460,7 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
409 460
410 platform_set_drvdata(pdev, rtc); 461 platform_set_drvdata(pdev, rtc);
411 462
412 ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG); 463 ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
413 if (ret < 0) 464 if (ret < 0)
414 goto out1; 465 goto out1;
415 466
@@ -420,11 +471,11 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
420 dev_warn(&pdev->dev, "Pending Alarm interrupt detected.\n"); 471 dev_warn(&pdev->dev, "Pending Alarm interrupt detected.\n");
421 472
422 /* Clear RTC Power up reset and pending alarm interrupts */ 473 /* Clear RTC Power up reset and pending alarm interrupts */
423 ret = twl4030_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG); 474 ret = twl_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
424 if (ret < 0) 475 if (ret < 0)
425 goto out1; 476 goto out1;
426 477
427 ret = request_irq(irq, twl4030_rtc_interrupt, 478 ret = request_irq(irq, twl_rtc_interrupt,
428 IRQF_TRIGGER_RISING, 479 IRQF_TRIGGER_RISING,
429 dev_name(&rtc->dev), rtc); 480 dev_name(&rtc->dev), rtc);
430 if (ret < 0) { 481 if (ret < 0) {
@@ -432,21 +483,28 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
432 goto out1; 483 goto out1;
433 } 484 }
434 485
486 if (twl_class_is_6030()) {
487 twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
488 REG_INT_MSK_LINE_A);
489 twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
490 REG_INT_MSK_STS_A);
491 }
492
435 /* Check RTC module status, Enable if it is off */ 493 /* Check RTC module status, Enable if it is off */
436 ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG); 494 ret = twl_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG);
437 if (ret < 0) 495 if (ret < 0)
438 goto out2; 496 goto out2;
439 497
440 if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) { 498 if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) {
441 dev_info(&pdev->dev, "Enabling TWL4030-RTC.\n"); 499 dev_info(&pdev->dev, "Enabling TWL-RTC.\n");
442 rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M; 500 rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M;
443 ret = twl4030_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG); 501 ret = twl_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG);
444 if (ret < 0) 502 if (ret < 0)
445 goto out2; 503 goto out2;
446 } 504 }
447 505
448 /* init cached IRQ enable bits */ 506 /* init cached IRQ enable bits */
449 ret = twl4030_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG); 507 ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
450 if (ret < 0) 508 if (ret < 0)
451 goto out2; 509 goto out2;
452 510
@@ -461,10 +519,10 @@ out0:
461} 519}
462 520
463/* 521/*
464 * Disable all TWL4030 RTC module interrupts. 522 * Disable all TWL RTC module interrupts.
465 * Sets status flag to free. 523 * Sets status flag to free.
466 */ 524 */
467static int __devexit twl4030_rtc_remove(struct platform_device *pdev) 525static int __devexit twl_rtc_remove(struct platform_device *pdev)
468{ 526{
469 /* leave rtc running, but disable irqs */ 527 /* leave rtc running, but disable irqs */
470 struct rtc_device *rtc = platform_get_drvdata(pdev); 528 struct rtc_device *rtc = platform_get_drvdata(pdev);
@@ -472,6 +530,13 @@ static int __devexit twl4030_rtc_remove(struct platform_device *pdev)
472 530
473 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M); 531 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
474 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M); 532 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
533 if (twl_class_is_6030()) {
534 twl6030_interrupt_mask(TWL6030_RTC_INT_MASK,
535 REG_INT_MSK_LINE_A);
536 twl6030_interrupt_mask(TWL6030_RTC_INT_MASK,
537 REG_INT_MSK_STS_A);
538 }
539
475 540
476 free_irq(irq, rtc); 541 free_irq(irq, rtc);
477 542
@@ -480,7 +545,7 @@ static int __devexit twl4030_rtc_remove(struct platform_device *pdev)
480 return 0; 545 return 0;
481} 546}
482 547
483static void twl4030_rtc_shutdown(struct platform_device *pdev) 548static void twl_rtc_shutdown(struct platform_device *pdev)
484{ 549{
485 /* mask timer interrupts, but leave alarm interrupts on to enable 550 /* mask timer interrupts, but leave alarm interrupts on to enable
486 power-on when alarm is triggered */ 551 power-on when alarm is triggered */
@@ -491,7 +556,7 @@ static void twl4030_rtc_shutdown(struct platform_device *pdev)
491 556
492static unsigned char irqstat; 557static unsigned char irqstat;
493 558
494static int twl4030_rtc_suspend(struct platform_device *pdev, pm_message_t state) 559static int twl_rtc_suspend(struct platform_device *pdev, pm_message_t state)
495{ 560{
496 irqstat = rtc_irq_bits; 561 irqstat = rtc_irq_bits;
497 562
@@ -499,42 +564,47 @@ static int twl4030_rtc_suspend(struct platform_device *pdev, pm_message_t state)
499 return 0; 564 return 0;
500} 565}
501 566
502static int twl4030_rtc_resume(struct platform_device *pdev) 567static int twl_rtc_resume(struct platform_device *pdev)
503{ 568{
504 set_rtc_irq_bit(irqstat); 569 set_rtc_irq_bit(irqstat);
505 return 0; 570 return 0;
506} 571}
507 572
508#else 573#else
509#define twl4030_rtc_suspend NULL 574#define twl_rtc_suspend NULL
510#define twl4030_rtc_resume NULL 575#define twl_rtc_resume NULL
511#endif 576#endif
512 577
513MODULE_ALIAS("platform:twl4030_rtc"); 578MODULE_ALIAS("platform:twl_rtc");
514 579
515static struct platform_driver twl4030rtc_driver = { 580static struct platform_driver twl4030rtc_driver = {
516 .probe = twl4030_rtc_probe, 581 .probe = twl_rtc_probe,
517 .remove = __devexit_p(twl4030_rtc_remove), 582 .remove = __devexit_p(twl_rtc_remove),
518 .shutdown = twl4030_rtc_shutdown, 583 .shutdown = twl_rtc_shutdown,
519 .suspend = twl4030_rtc_suspend, 584 .suspend = twl_rtc_suspend,
520 .resume = twl4030_rtc_resume, 585 .resume = twl_rtc_resume,
521 .driver = { 586 .driver = {
522 .owner = THIS_MODULE, 587 .owner = THIS_MODULE,
523 .name = "twl4030_rtc", 588 .name = "twl_rtc",
524 }, 589 },
525}; 590};
526 591
527static int __init twl4030_rtc_init(void) 592static int __init twl_rtc_init(void)
528{ 593{
594 if (twl_class_is_4030())
595 rtc_reg_map = (u8 *) twl4030_rtc_reg_map;
596 else
597 rtc_reg_map = (u8 *) twl6030_rtc_reg_map;
598
529 return platform_driver_register(&twl4030rtc_driver); 599 return platform_driver_register(&twl4030rtc_driver);
530} 600}
531module_init(twl4030_rtc_init); 601module_init(twl_rtc_init);
532 602
533static void __exit twl4030_rtc_exit(void) 603static void __exit twl_rtc_exit(void)
534{ 604{
535 platform_driver_unregister(&twl4030rtc_driver); 605 platform_driver_unregister(&twl4030rtc_driver);
536} 606}
537module_exit(twl4030_rtc_exit); 607module_exit(twl_rtc_exit);
538 608
539MODULE_AUTHOR("Texas Instruments, MontaVista Software"); 609MODULE_AUTHOR("Texas Instruments, MontaVista Software");
540MODULE_LICENSE("GPL"); 610MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 4a6ed1104fbb..9ee81d8aa7c0 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -17,6 +17,7 @@
17struct tx4939rtc_plat_data { 17struct tx4939rtc_plat_data {
18 struct rtc_device *rtc; 18 struct rtc_device *rtc;
19 struct tx4939_rtc_reg __iomem *rtcreg; 19 struct tx4939_rtc_reg __iomem *rtcreg;
20 spinlock_t lock;
20}; 21};
21 22
22static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev) 23static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev)
@@ -52,14 +53,14 @@ static int tx4939_rtc_set_mmss(struct device *dev, unsigned long secs)
52 buf[3] = secs >> 8; 53 buf[3] = secs >> 8;
53 buf[4] = secs >> 16; 54 buf[4] = secs >> 16;
54 buf[5] = secs >> 24; 55 buf[5] = secs >> 24;
55 spin_lock_irq(&pdata->rtc->irq_lock); 56 spin_lock_irq(&pdata->lock);
56 __raw_writel(0, &rtcreg->adr); 57 __raw_writel(0, &rtcreg->adr);
57 for (i = 0; i < 6; i++) 58 for (i = 0; i < 6; i++)
58 __raw_writel(buf[i], &rtcreg->dat); 59 __raw_writel(buf[i], &rtcreg->dat);
59 ret = tx4939_rtc_cmd(rtcreg, 60 ret = tx4939_rtc_cmd(rtcreg,
60 TX4939_RTCCTL_COMMAND_SETTIME | 61 TX4939_RTCCTL_COMMAND_SETTIME |
61 (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); 62 (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME));
62 spin_unlock_irq(&pdata->rtc->irq_lock); 63 spin_unlock_irq(&pdata->lock);
63 return ret; 64 return ret;
64} 65}
65 66
@@ -71,18 +72,18 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
71 unsigned long sec; 72 unsigned long sec;
72 unsigned char buf[6]; 73 unsigned char buf[6];
73 74
74 spin_lock_irq(&pdata->rtc->irq_lock); 75 spin_lock_irq(&pdata->lock);
75 ret = tx4939_rtc_cmd(rtcreg, 76 ret = tx4939_rtc_cmd(rtcreg,
76 TX4939_RTCCTL_COMMAND_GETTIME | 77 TX4939_RTCCTL_COMMAND_GETTIME |
77 (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); 78 (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME));
78 if (ret) { 79 if (ret) {
79 spin_unlock_irq(&pdata->rtc->irq_lock); 80 spin_unlock_irq(&pdata->lock);
80 return ret; 81 return ret;
81 } 82 }
82 __raw_writel(2, &rtcreg->adr); 83 __raw_writel(2, &rtcreg->adr);
83 for (i = 2; i < 6; i++) 84 for (i = 2; i < 6; i++)
84 buf[i] = __raw_readl(&rtcreg->dat); 85 buf[i] = __raw_readl(&rtcreg->dat);
85 spin_unlock_irq(&pdata->rtc->irq_lock); 86 spin_unlock_irq(&pdata->lock);
86 sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; 87 sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2];
87 rtc_time_to_tm(sec, tm); 88 rtc_time_to_tm(sec, tm);
88 return rtc_valid_tm(tm); 89 return rtc_valid_tm(tm);
@@ -110,13 +111,13 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
110 buf[3] = sec >> 8; 111 buf[3] = sec >> 8;
111 buf[4] = sec >> 16; 112 buf[4] = sec >> 16;
112 buf[5] = sec >> 24; 113 buf[5] = sec >> 24;
113 spin_lock_irq(&pdata->rtc->irq_lock); 114 spin_lock_irq(&pdata->lock);
114 __raw_writel(0, &rtcreg->adr); 115 __raw_writel(0, &rtcreg->adr);
115 for (i = 0; i < 6; i++) 116 for (i = 0; i < 6; i++)
116 __raw_writel(buf[i], &rtcreg->dat); 117 __raw_writel(buf[i], &rtcreg->dat);
117 ret = tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_SETALARM | 118 ret = tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_SETALARM |
118 (alrm->enabled ? TX4939_RTCCTL_ALME : 0)); 119 (alrm->enabled ? TX4939_RTCCTL_ALME : 0));
119 spin_unlock_irq(&pdata->rtc->irq_lock); 120 spin_unlock_irq(&pdata->lock);
120 return ret; 121 return ret;
121} 122}
122 123
@@ -129,12 +130,12 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
129 unsigned char buf[6]; 130 unsigned char buf[6];
130 u32 ctl; 131 u32 ctl;
131 132
132 spin_lock_irq(&pdata->rtc->irq_lock); 133 spin_lock_irq(&pdata->lock);
133 ret = tx4939_rtc_cmd(rtcreg, 134 ret = tx4939_rtc_cmd(rtcreg,
134 TX4939_RTCCTL_COMMAND_GETALARM | 135 TX4939_RTCCTL_COMMAND_GETALARM |
135 (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); 136 (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME));
136 if (ret) { 137 if (ret) {
137 spin_unlock_irq(&pdata->rtc->irq_lock); 138 spin_unlock_irq(&pdata->lock);
138 return ret; 139 return ret;
139 } 140 }
140 __raw_writel(2, &rtcreg->adr); 141 __raw_writel(2, &rtcreg->adr);
@@ -143,7 +144,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
143 ctl = __raw_readl(&rtcreg->ctl); 144 ctl = __raw_readl(&rtcreg->ctl);
144 alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0; 145 alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0;
145 alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0; 146 alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0;
146 spin_unlock_irq(&pdata->rtc->irq_lock); 147 spin_unlock_irq(&pdata->lock);
147 sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; 148 sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2];
148 rtc_time_to_tm(sec, &alrm->time); 149 rtc_time_to_tm(sec, &alrm->time);
149 return rtc_valid_tm(&alrm->time); 150 return rtc_valid_tm(&alrm->time);
@@ -153,11 +154,11 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
153{ 154{
154 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 155 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
155 156
156 spin_lock_irq(&pdata->rtc->irq_lock); 157 spin_lock_irq(&pdata->lock);
157 tx4939_rtc_cmd(pdata->rtcreg, 158 tx4939_rtc_cmd(pdata->rtcreg,
158 TX4939_RTCCTL_COMMAND_NOP | 159 TX4939_RTCCTL_COMMAND_NOP |
159 (enabled ? TX4939_RTCCTL_ALME : 0)); 160 (enabled ? TX4939_RTCCTL_ALME : 0));
160 spin_unlock_irq(&pdata->rtc->irq_lock); 161 spin_unlock_irq(&pdata->lock);
161 return 0; 162 return 0;
162} 163}
163 164
@@ -167,13 +168,14 @@ static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id)
167 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 168 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
168 unsigned long events = RTC_IRQF; 169 unsigned long events = RTC_IRQF;
169 170
170 spin_lock(&pdata->rtc->irq_lock); 171 spin_lock(&pdata->lock);
171 if (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALMD) { 172 if (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALMD) {
172 events |= RTC_AF; 173 events |= RTC_AF;
173 tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_NOP); 174 tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_NOP);
174 } 175 }
175 spin_unlock(&pdata->rtc->irq_lock); 176 spin_unlock(&pdata->lock);
176 rtc_update_irq(pdata->rtc, 1, events); 177 if (likely(pdata->rtc))
178 rtc_update_irq(pdata->rtc, 1, events);
177 return IRQ_HANDLED; 179 return IRQ_HANDLED;
178} 180}
179 181
@@ -194,13 +196,13 @@ static ssize_t tx4939_rtc_nvram_read(struct kobject *kobj,
194 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 196 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
195 ssize_t count; 197 ssize_t count;
196 198
197 spin_lock_irq(&pdata->rtc->irq_lock); 199 spin_lock_irq(&pdata->lock);
198 for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE; 200 for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE;
199 count++, size--) { 201 count++, size--) {
200 __raw_writel(pos++, &rtcreg->adr); 202 __raw_writel(pos++, &rtcreg->adr);
201 *buf++ = __raw_readl(&rtcreg->dat); 203 *buf++ = __raw_readl(&rtcreg->dat);
202 } 204 }
203 spin_unlock_irq(&pdata->rtc->irq_lock); 205 spin_unlock_irq(&pdata->lock);
204 return count; 206 return count;
205} 207}
206 208
@@ -213,13 +215,13 @@ static ssize_t tx4939_rtc_nvram_write(struct kobject *kobj,
213 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 215 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
214 ssize_t count; 216 ssize_t count;
215 217
216 spin_lock_irq(&pdata->rtc->irq_lock); 218 spin_lock_irq(&pdata->lock);
217 for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE; 219 for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE;
218 count++, size--) { 220 count++, size--) {
219 __raw_writel(pos++, &rtcreg->adr); 221 __raw_writel(pos++, &rtcreg->adr);
220 __raw_writel(*buf++, &rtcreg->dat); 222 __raw_writel(*buf++, &rtcreg->dat);
221 } 223 }
222 spin_unlock_irq(&pdata->rtc->irq_lock); 224 spin_unlock_irq(&pdata->lock);
223 return count; 225 return count;
224} 226}
225 227
@@ -259,6 +261,7 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
259 if (!pdata->rtcreg) 261 if (!pdata->rtcreg)
260 return -EBUSY; 262 return -EBUSY;
261 263
264 spin_lock_init(&pdata->lock);
262 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); 265 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
263 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, 266 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt,
264 IRQF_DISABLED, pdev->name, &pdev->dev) < 0) 267 IRQF_DISABLED, pdev->name, &pdev->dev) < 0)
@@ -277,14 +280,12 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
277static int __exit tx4939_rtc_remove(struct platform_device *pdev) 280static int __exit tx4939_rtc_remove(struct platform_device *pdev)
278{ 281{
279 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev); 282 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev);
280 struct rtc_device *rtc = pdata->rtc;
281 283
282 spin_lock_irq(&rtc->irq_lock);
283 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
284 spin_unlock_irq(&rtc->irq_lock);
285 sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 284 sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
286 rtc_device_unregister(rtc); 285 rtc_device_unregister(pdata->rtc);
287 platform_set_drvdata(pdev, NULL); 286 spin_lock_irq(&pdata->lock);
287 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
288 spin_unlock_irq(&pdata->lock);
288 return 0; 289 return 0;
289} 290}
290 291
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index ad741afd47d8..bed4cab07043 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -304,7 +304,6 @@ static int rtc_probe(struct platform_device *pdev)
304{ 304{
305 struct v3020_platform_data *pdata = pdev->dev.platform_data; 305 struct v3020_platform_data *pdata = pdev->dev.platform_data;
306 struct v3020 *chip; 306 struct v3020 *chip;
307 struct rtc_device *rtc;
308 int retval = -EBUSY; 307 int retval = -EBUSY;
309 int i; 308 int i;
310 int temp; 309 int temp;
@@ -353,13 +352,12 @@ static int rtc_probe(struct platform_device *pdev)
353 352
354 platform_set_drvdata(pdev, chip); 353 platform_set_drvdata(pdev, chip);
355 354
356 rtc = rtc_device_register("v3020", 355 chip->rtc = rtc_device_register("v3020",
357 &pdev->dev, &v3020_rtc_ops, THIS_MODULE); 356 &pdev->dev, &v3020_rtc_ops, THIS_MODULE);
358 if (IS_ERR(rtc)) { 357 if (IS_ERR(chip->rtc)) {
359 retval = PTR_ERR(rtc); 358 retval = PTR_ERR(chip->rtc);
360 goto err_io; 359 goto err_io;
361 } 360 }
362 chip->rtc = rtc;
363 361
364 return 0; 362 return 0;
365 363
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index fadddac1e5a4..c3244244e8cf 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -327,7 +327,7 @@ static int __devinit rtc_probe(struct platform_device *pdev)
327 if (!res) 327 if (!res)
328 return -EBUSY; 328 return -EBUSY;
329 329
330 rtc1_base = ioremap(res->start, res->end - res->start + 1); 330 rtc1_base = ioremap(res->start, resource_size(res));
331 if (!rtc1_base) 331 if (!rtc1_base)
332 return -EBUSY; 332 return -EBUSY;
333 333
@@ -337,7 +337,7 @@ static int __devinit rtc_probe(struct platform_device *pdev)
337 goto err_rtc1_iounmap; 337 goto err_rtc1_iounmap;
338 } 338 }
339 339
340 rtc2_base = ioremap(res->start, res->end - res->start + 1); 340 rtc2_base = ioremap(res->start, resource_size(res));
341 if (!rtc2_base) { 341 if (!rtc2_base) {
342 retval = -EBUSY; 342 retval = -EBUSY;
343 goto err_rtc1_iounmap; 343 goto err_rtc1_iounmap;
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index 79795cdf6ed8..000c7e481e59 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -485,7 +485,7 @@ static int __devexit wm831x_rtc_remove(struct platform_device *pdev)
485 return 0; 485 return 0;
486} 486}
487 487
488static struct dev_pm_ops wm831x_rtc_pm_ops = { 488static const struct dev_pm_ops wm831x_rtc_pm_ops = {
489 .suspend = wm831x_rtc_suspend, 489 .suspend = wm831x_rtc_suspend,
490 .resume = wm831x_rtc_resume, 490 .resume = wm831x_rtc_resume,
491 491
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c
index c91edc572eb6..f1e440521c54 100644
--- a/drivers/rtc/rtc-wm8350.c
+++ b/drivers/rtc/rtc-wm8350.c
@@ -315,9 +315,9 @@ static int wm8350_rtc_update_irq_enable(struct device *dev,
315 return 0; 315 return 0;
316} 316}
317 317
318static void wm8350_rtc_alarm_handler(struct wm8350 *wm8350, int irq, 318static irqreturn_t wm8350_rtc_alarm_handler(int irq, void *data)
319 void *data)
320{ 319{
320 struct wm8350 *wm8350 = data;
321 struct rtc_device *rtc = wm8350->rtc.rtc; 321 struct rtc_device *rtc = wm8350->rtc.rtc;
322 int ret; 322 int ret;
323 323
@@ -330,14 +330,18 @@ static void wm8350_rtc_alarm_handler(struct wm8350 *wm8350, int irq,
330 dev_err(&(wm8350->rtc.pdev->dev), 330 dev_err(&(wm8350->rtc.pdev->dev),
331 "Failed to disable alarm: %d\n", ret); 331 "Failed to disable alarm: %d\n", ret);
332 } 332 }
333
334 return IRQ_HANDLED;
333} 335}
334 336
335static void wm8350_rtc_update_handler(struct wm8350 *wm8350, int irq, 337static irqreturn_t wm8350_rtc_update_handler(int irq, void *data)
336 void *data)
337{ 338{
339 struct wm8350 *wm8350 = data;
338 struct rtc_device *rtc = wm8350->rtc.rtc; 340 struct rtc_device *rtc = wm8350->rtc.rtc;
339 341
340 rtc_update_irq(rtc, 1, RTC_IRQF | RTC_UF); 342 rtc_update_irq(rtc, 1, RTC_IRQF | RTC_UF);
343
344 return IRQ_HANDLED;
341} 345}
342 346
343static const struct rtc_class_ops wm8350_rtc_ops = { 347static const struct rtc_class_ops wm8350_rtc_ops = {
@@ -350,8 +354,9 @@ static const struct rtc_class_ops wm8350_rtc_ops = {
350}; 354};
351 355
352#ifdef CONFIG_PM 356#ifdef CONFIG_PM
353static int wm8350_rtc_suspend(struct platform_device *pdev, pm_message_t state) 357static int wm8350_rtc_suspend(struct device *dev)
354{ 358{
359 struct platform_device *pdev = to_platform_device(dev);
355 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev); 360 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
356 int ret = 0; 361 int ret = 0;
357 u16 reg; 362 u16 reg;
@@ -369,8 +374,9 @@ static int wm8350_rtc_suspend(struct platform_device *pdev, pm_message_t state)
369 return ret; 374 return ret;
370} 375}
371 376
372static int wm8350_rtc_resume(struct platform_device *pdev) 377static int wm8350_rtc_resume(struct device *dev)
373{ 378{
379 struct platform_device *pdev = to_platform_device(dev);
374 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev); 380 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
375 int ret; 381 int ret;
376 382
@@ -455,15 +461,14 @@ static int wm8350_rtc_probe(struct platform_device *pdev)
455 return ret; 461 return ret;
456 } 462 }
457 463
458 wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
459 wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_PER);
460
461 wm8350_register_irq(wm8350, WM8350_IRQ_RTC_SEC, 464 wm8350_register_irq(wm8350, WM8350_IRQ_RTC_SEC,
462 wm8350_rtc_update_handler, NULL); 465 wm8350_rtc_update_handler, 0,
466 "RTC Seconds", wm8350);
467 wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
463 468
464 wm8350_register_irq(wm8350, WM8350_IRQ_RTC_ALM, 469 wm8350_register_irq(wm8350, WM8350_IRQ_RTC_ALM,
465 wm8350_rtc_alarm_handler, NULL); 470 wm8350_rtc_alarm_handler, 0,
466 wm8350_unmask_irq(wm8350, WM8350_IRQ_RTC_ALM); 471 "RTC Alarm", wm8350);
467 472
468 return 0; 473 return 0;
469} 474}
@@ -473,8 +478,6 @@ static int __devexit wm8350_rtc_remove(struct platform_device *pdev)
473 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 478 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
474 struct wm8350_rtc *wm_rtc = &wm8350->rtc; 479 struct wm8350_rtc *wm_rtc = &wm8350->rtc;
475 480
476 wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC);
477
478 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC); 481 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC);
479 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM); 482 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM);
480 483
@@ -483,13 +486,17 @@ static int __devexit wm8350_rtc_remove(struct platform_device *pdev)
483 return 0; 486 return 0;
484} 487}
485 488
489static struct dev_pm_ops wm8350_rtc_pm_ops = {
490 .suspend = wm8350_rtc_suspend,
491 .resume = wm8350_rtc_resume,
492};
493
486static struct platform_driver wm8350_rtc_driver = { 494static struct platform_driver wm8350_rtc_driver = {
487 .probe = wm8350_rtc_probe, 495 .probe = wm8350_rtc_probe,
488 .remove = __devexit_p(wm8350_rtc_remove), 496 .remove = __devexit_p(wm8350_rtc_remove),
489 .suspend = wm8350_rtc_suspend,
490 .resume = wm8350_rtc_resume,
491 .driver = { 497 .driver = {
492 .name = "wm8350-rtc", 498 .name = "wm8350-rtc",
499 .pm = &wm8350_rtc_pm_ops,
493 }, 500 },
494}; 501};
495 502
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 6583c1a8b070..9aae49139a0a 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -155,11 +155,11 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
155} 155}
156 156
157static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, 157static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
158 int datetoo, u8 reg_base, unsigned char alm_enable) 158 u8 reg_base, unsigned char alm_enable)
159{ 159{
160 int i, xfer, nbytes; 160 int i, xfer;
161 unsigned char buf[8];
162 unsigned char rdata[10] = { 0, reg_base }; 161 unsigned char rdata[10] = { 0, reg_base };
162 unsigned char *buf = rdata + 2;
163 163
164 static const unsigned char wel[3] = { 0, X1205_REG_SR, 164 static const unsigned char wel[3] = { 0, X1205_REG_SR,
165 X1205_SR_WEL }; 165 X1205_SR_WEL };
@@ -170,9 +170,9 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
170 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 }; 170 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 };
171 171
172 dev_dbg(&client->dev, 172 dev_dbg(&client->dev,
173 "%s: secs=%d, mins=%d, hours=%d\n", 173 "%s: sec=%d min=%d hour=%d mday=%d mon=%d year=%d wday=%d\n",
174 __func__, 174 __func__, tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday,
175 tm->tm_sec, tm->tm_min, tm->tm_hour); 175 tm->tm_mon, tm->tm_year, tm->tm_wday);
176 176
177 buf[CCR_SEC] = bin2bcd(tm->tm_sec); 177 buf[CCR_SEC] = bin2bcd(tm->tm_sec);
178 buf[CCR_MIN] = bin2bcd(tm->tm_min); 178 buf[CCR_MIN] = bin2bcd(tm->tm_min);
@@ -180,23 +180,15 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
180 /* set hour and 24hr bit */ 180 /* set hour and 24hr bit */
181 buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL; 181 buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL;
182 182
183 /* should we also set the date? */ 183 buf[CCR_MDAY] = bin2bcd(tm->tm_mday);
184 if (datetoo) {
185 dev_dbg(&client->dev,
186 "%s: mday=%d, mon=%d, year=%d, wday=%d\n",
187 __func__,
188 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
189 184
190 buf[CCR_MDAY] = bin2bcd(tm->tm_mday); 185 /* month, 1 - 12 */
186 buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1);
191 187
192 /* month, 1 - 12 */ 188 /* year, since the rtc epoch*/
193 buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1); 189 buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100);
194 190 buf[CCR_WDAY] = tm->tm_wday & 0x07;
195 /* year, since the rtc epoch*/ 191 buf[CCR_Y2K] = bin2bcd((tm->tm_year + 1900) / 100);
196 buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100);
197 buf[CCR_WDAY] = tm->tm_wday & 0x07;
198 buf[CCR_Y2K] = bin2bcd((tm->tm_year + 1900) / 100);
199 }
200 192
201 /* If writing alarm registers, set compare bits on registers 0-4 */ 193 /* If writing alarm registers, set compare bits on registers 0-4 */
202 if (reg_base < X1205_CCR_BASE) 194 if (reg_base < X1205_CCR_BASE)
@@ -214,17 +206,8 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
214 return -EIO; 206 return -EIO;
215 } 207 }
216 208
217 209 xfer = i2c_master_send(client, rdata, sizeof(rdata));
218 /* write register's data */ 210 if (xfer != sizeof(rdata)) {
219 if (datetoo)
220 nbytes = 8;
221 else
222 nbytes = 3;
223 for (i = 0; i < nbytes; i++)
224 rdata[2+i] = buf[i];
225
226 xfer = i2c_master_send(client, rdata, nbytes+2);
227 if (xfer != nbytes+2) {
228 dev_err(&client->dev, 211 dev_err(&client->dev,
229 "%s: result=%d addr=%02x, data=%02x\n", 212 "%s: result=%d addr=%02x, data=%02x\n",
230 __func__, 213 __func__,
@@ -282,7 +265,7 @@ static int x1205_fix_osc(struct i2c_client *client)
282 265
283 memset(&tm, 0, sizeof(tm)); 266 memset(&tm, 0, sizeof(tm));
284 267
285 err = x1205_set_datetime(client, &tm, 1, X1205_CCR_BASE, 0); 268 err = x1205_set_datetime(client, &tm, X1205_CCR_BASE, 0);
286 if (err < 0) 269 if (err < 0)
287 dev_err(&client->dev, "unable to restart the oscillator\n"); 270 dev_err(&client->dev, "unable to restart the oscillator\n");
288 271
@@ -481,7 +464,7 @@ static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
481static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 464static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
482{ 465{
483 return x1205_set_datetime(to_i2c_client(dev), 466 return x1205_set_datetime(to_i2c_client(dev),
484 &alrm->time, 1, X1205_ALM0_BASE, alrm->enabled); 467 &alrm->time, X1205_ALM0_BASE, alrm->enabled);
485} 468}
486 469
487static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) 470static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm)
@@ -493,7 +476,7 @@ static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm)
493static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) 476static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm)
494{ 477{
495 return x1205_set_datetime(to_i2c_client(dev), 478 return x1205_set_datetime(to_i2c_client(dev),
496 tm, 1, X1205_CCR_BASE, 0); 479 tm, X1205_CCR_BASE, 0);
497} 480}
498 481
499static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) 482static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)