aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig14
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/class.c65
-rw-r--r--drivers/rtc/rtc-at32ap700x.c2
-rw-r--r--drivers/rtc/rtc-cmos.c6
-rw-r--r--drivers/rtc/rtc-ds1286.c2
-rw-r--r--drivers/rtc/rtc-ds1511.c2
-rw-r--r--drivers/rtc/rtc-ds1742.c2
-rw-r--r--drivers/rtc/rtc-m48t35.c2
-rw-r--r--drivers/rtc/rtc-m48t59.c2
-rw-r--r--drivers/rtc/rtc-mpc5121.c81
-rw-r--r--drivers/rtc/rtc-mrst.c5
-rw-r--r--drivers/rtc/rtc-omap.c2
-rw-r--r--drivers/rtc/rtc-pm8xxx.c550
-rw-r--r--drivers/rtc/rtc-puv3.c5
-rw-r--r--drivers/rtc/rtc-s3c.c32
-rw-r--r--drivers/rtc/rtc-tegra.c2
-rw-r--r--drivers/rtc/rtc-twl.c2
18 files changed, 728 insertions, 49 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index dcb61e23b985..5a538fc1cc85 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1006,10 +1006,10 @@ config RTC_DRV_MC13XXX
1006 1006
1007config RTC_DRV_MPC5121 1007config RTC_DRV_MPC5121
1008 tristate "Freescale MPC5121 built-in RTC" 1008 tristate "Freescale MPC5121 built-in RTC"
1009 depends on PPC_MPC512x && RTC_CLASS 1009 depends on PPC_MPC512x || PPC_MPC52xx
1010 help 1010 help
1011 If you say yes here you will get support for the 1011 If you say yes here you will get support for the
1012 built-in RTC MPC5121. 1012 built-in RTC on MPC5121 or on MPC5200.
1013 1013
1014 This driver can also be built as a module. If so, the module 1014 This driver can also be built as a module. If so, the module
1015 will be called rtc-mpc5121. 1015 will be called rtc-mpc5121.
@@ -1034,6 +1034,16 @@ config RTC_DRV_LPC32XX
1034 This driver can also be buillt as a module. If so, the module 1034 This driver can also be buillt as a module. If so, the module
1035 will be called rtc-lpc32xx. 1035 will be called rtc-lpc32xx.
1036 1036
1037config RTC_DRV_PM8XXX
1038 tristate "Qualcomm PMIC8XXX RTC"
1039 depends on MFD_PM8XXX
1040 help
1041 If you say yes here you get support for the
1042 Qualcomm PMIC8XXX RTC.
1043
1044 To compile this driver as a module, choose M here: the
1045 module will be called rtc-pm8xxx.
1046
1037config RTC_DRV_TEGRA 1047config RTC_DRV_TEGRA
1038 tristate "NVIDIA Tegra Internal RTC driver" 1048 tristate "NVIDIA Tegra Internal RTC driver"
1039 depends on RTC_CLASS && ARCH_TEGRA 1049 depends on RTC_CLASS && ARCH_TEGRA
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0ffefe877bfa..6e6982335c10 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o
77obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o 77obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o
78obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o 78obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o
79obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o 79obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
80obj-$(CONFIG_RTC_DRV_PM8XXX) += rtc-pm8xxx.o
80obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o 81obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o
81obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o 82obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o
82obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o 83obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 4194e59e14cd..01a7df5317c1 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -41,20 +41,41 @@ static void rtc_device_release(struct device *dev)
41 * system's wall clock; restore it on resume(). 41 * system's wall clock; restore it on resume().
42 */ 42 */
43 43
44static time_t oldtime; 44static struct timespec old_rtc, old_system, old_delta;
45static struct timespec oldts; 45
46 46
47static int rtc_suspend(struct device *dev, pm_message_t mesg) 47static int rtc_suspend(struct device *dev, pm_message_t mesg)
48{ 48{
49 struct rtc_device *rtc = to_rtc_device(dev); 49 struct rtc_device *rtc = to_rtc_device(dev);
50 struct rtc_time tm; 50 struct rtc_time tm;
51 51 struct timespec delta, delta_delta;
52 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 52 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
53 return 0; 53 return 0;
54 54
55 /* snapshot the current RTC and system time at suspend*/
55 rtc_read_time(rtc, &tm); 56 rtc_read_time(rtc, &tm);
56 ktime_get_ts(&oldts); 57 getnstimeofday(&old_system);
57 rtc_tm_to_time(&tm, &oldtime); 58 rtc_tm_to_time(&tm, &old_rtc.tv_sec);
59
60
61 /*
62 * To avoid drift caused by repeated suspend/resumes,
63 * which each can add ~1 second drift error,
64 * try to compensate so the difference in system time
65 * and rtc time stays close to constant.
66 */
67 delta = timespec_sub(old_system, old_rtc);
68 delta_delta = timespec_sub(delta, old_delta);
69 if (abs(delta_delta.tv_sec) >= 2) {
70 /*
71 * if delta_delta is too large, assume time correction
72 * has occured and set old_delta to the current delta.
73 */
74 old_delta = delta;
75 } else {
76 /* Otherwise try to adjust old_system to compensate */
77 old_system = timespec_sub(old_system, delta_delta);
78 }
58 79
59 return 0; 80 return 0;
60} 81}
@@ -63,32 +84,42 @@ static int rtc_resume(struct device *dev)
63{ 84{
64 struct rtc_device *rtc = to_rtc_device(dev); 85 struct rtc_device *rtc = to_rtc_device(dev);
65 struct rtc_time tm; 86 struct rtc_time tm;
66 time_t newtime; 87 struct timespec new_system, new_rtc;
67 struct timespec time; 88 struct timespec sleep_time;
68 struct timespec newts;
69 89
70 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 90 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
71 return 0; 91 return 0;
72 92
73 ktime_get_ts(&newts); 93 /* snapshot the current rtc and system time at resume */
94 getnstimeofday(&new_system);
74 rtc_read_time(rtc, &tm); 95 rtc_read_time(rtc, &tm);
75 if (rtc_valid_tm(&tm) != 0) { 96 if (rtc_valid_tm(&tm) != 0) {
76 pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev)); 97 pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev));
77 return 0; 98 return 0;
78 } 99 }
79 rtc_tm_to_time(&tm, &newtime); 100 rtc_tm_to_time(&tm, &new_rtc.tv_sec);
80 if (newtime <= oldtime) { 101 new_rtc.tv_nsec = 0;
81 if (newtime < oldtime) 102
103 if (new_rtc.tv_sec <= old_rtc.tv_sec) {
104 if (new_rtc.tv_sec < old_rtc.tv_sec)
82 pr_debug("%s: time travel!\n", dev_name(&rtc->dev)); 105 pr_debug("%s: time travel!\n", dev_name(&rtc->dev));
83 return 0; 106 return 0;
84 } 107 }
85 /* calculate the RTC time delta */
86 set_normalized_timespec(&time, newtime - oldtime, 0);
87 108
88 /* subtract kernel time between rtc_suspend to rtc_resume */ 109 /* calculate the RTC time delta (sleep time)*/
89 time = timespec_sub(time, timespec_sub(newts, oldts)); 110 sleep_time = timespec_sub(new_rtc, old_rtc);
111
112 /*
113 * Since these RTC suspend/resume handlers are not called
114 * at the very end of suspend or the start of resume,
115 * some run-time may pass on either sides of the sleep time
116 * so subtract kernel run-time between rtc_suspend to rtc_resume
117 * to keep things accurate.
118 */
119 sleep_time = timespec_sub(sleep_time,
120 timespec_sub(new_system, old_system));
90 121
91 timekeeping_inject_sleeptime(&time); 122 timekeeping_inject_sleeptime(&sleep_time);
92 return 0; 123 return 0;
93} 124}
94 125
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
index e725d51e773d..8dd08305aae1 100644
--- a/drivers/rtc/rtc-at32ap700x.c
+++ b/drivers/rtc/rtc-at32ap700x.c
@@ -223,7 +223,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
223 } 223 }
224 224
225 rtc->irq = irq; 225 rtc->irq = irq;
226 rtc->regs = ioremap(regs->start, regs->end - regs->start + 1); 226 rtc->regs = ioremap(regs->start, resource_size(regs));
227 if (!rtc->regs) { 227 if (!rtc->regs) {
228 ret = -ENOMEM; 228 ret = -ENOMEM;
229 dev_dbg(&pdev->dev, "could not map I/O memory\n"); 229 dev_dbg(&pdev->dev, "could not map I/O memory\n");
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 911e75cdc125..05beb6c1ca79 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -606,7 +606,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
606 * (needing ioremap etc), not i/o space resources like this ... 606 * (needing ioremap etc), not i/o space resources like this ...
607 */ 607 */
608 ports = request_region(ports->start, 608 ports = request_region(ports->start,
609 ports->end + 1 - ports->start, 609 resource_size(ports),
610 driver_name); 610 driver_name);
611 if (!ports) { 611 if (!ports) {
612 dev_dbg(dev, "i/o registers already in use\n"); 612 dev_dbg(dev, "i/o registers already in use\n");
@@ -750,7 +750,7 @@ cleanup1:
750 cmos_rtc.dev = NULL; 750 cmos_rtc.dev = NULL;
751 rtc_device_unregister(cmos_rtc.rtc); 751 rtc_device_unregister(cmos_rtc.rtc);
752cleanup0: 752cleanup0:
753 release_region(ports->start, ports->end + 1 - ports->start); 753 release_region(ports->start, resource_size(ports));
754 return retval; 754 return retval;
755} 755}
756 756
@@ -779,7 +779,7 @@ static void __exit cmos_do_remove(struct device *dev)
779 cmos->rtc = NULL; 779 cmos->rtc = NULL;
780 780
781 ports = cmos->iomem; 781 ports = cmos->iomem;
782 release_region(ports->start, ports->end + 1 - ports->start); 782 release_region(ports->start, resource_size(ports));
783 cmos->iomem = NULL; 783 cmos->iomem = NULL;
784 784
785 cmos->dev = NULL; 785 cmos->dev = NULL;
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
index 47e681df31e2..68e6caf25496 100644
--- a/drivers/rtc/rtc-ds1286.c
+++ b/drivers/rtc/rtc-ds1286.c
@@ -343,7 +343,7 @@ static int __devinit ds1286_probe(struct platform_device *pdev)
343 if (!priv) 343 if (!priv)
344 return -ENOMEM; 344 return -ENOMEM;
345 345
346 priv->size = res->end - res->start + 1; 346 priv->size = resource_size(res);
347 if (!request_mem_region(res->start, priv->size, pdev->name)) { 347 if (!request_mem_region(res->start, priv->size, pdev->name)) {
348 ret = -EBUSY; 348 ret = -EBUSY;
349 goto out; 349 goto out;
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index fbabc773dded..568ad30617e7 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -490,7 +490,7 @@ ds1511_rtc_probe(struct platform_device *pdev)
490 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 490 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
491 if (!pdata) 491 if (!pdata)
492 return -ENOMEM; 492 return -ENOMEM;
493 pdata->size = res->end - res->start + 1; 493 pdata->size = resource_size(res);
494 if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size, 494 if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size,
495 pdev->name)) 495 pdev->name))
496 return -EBUSY; 496 return -EBUSY;
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 042630c90dd3..d84a448dd754 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -173,7 +173,7 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
173 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 173 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
174 if (!pdata) 174 if (!pdata)
175 return -ENOMEM; 175 return -ENOMEM;
176 pdata->size = res->end - res->start + 1; 176 pdata->size = resource_size(res);
177 if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size, 177 if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size,
178 pdev->name)) 178 pdev->name))
179 return -EBUSY; 179 return -EBUSY;
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index 7410875e5838..8e2a24e33ed6 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -154,7 +154,7 @@ static int __devinit m48t35_probe(struct platform_device *pdev)
154 if (!priv) 154 if (!priv)
155 return -ENOMEM; 155 return -ENOMEM;
156 156
157 priv->size = res->end - res->start + 1; 157 priv->size = resource_size(res);
158 /* 158 /*
159 * kludge: remove the #ifndef after ioc3 resource 159 * kludge: remove the #ifndef after ioc3 resource
160 * conflicts are resolved 160 * conflicts are resolved
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index 3978f4caf724..28365388fb6c 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -433,7 +433,7 @@ static int __devinit m48t59_rtc_probe(struct platform_device *pdev)
433 433
434 if (!m48t59->ioaddr) { 434 if (!m48t59->ioaddr) {
435 /* ioaddr not mapped externally */ 435 /* ioaddr not mapped externally */
436 m48t59->ioaddr = ioremap(res->start, res->end - res->start + 1); 436 m48t59->ioaddr = ioremap(res->start, resource_size(res));
437 if (!m48t59->ioaddr) 437 if (!m48t59->ioaddr)
438 goto out; 438 goto out;
439 } 439 }
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index 09ccd8d3ba2a..da60915818b6 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright 2007, Domen Puncer <domen.puncer@telargo.com> 4 * Copyright 2007, Domen Puncer <domen.puncer@telargo.com>
5 * Copyright 2008, Freescale Semiconductor, Inc. All rights reserved. 5 * Copyright 2008, Freescale Semiconductor, Inc. All rights reserved.
6 * Copyright 2011, Dmitry Eremin-Solenikov
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * 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 * it under the terms of the GNU General Public License version 2 as
@@ -145,6 +146,55 @@ static int mpc5121_rtc_set_time(struct device *dev, struct rtc_time *tm)
145 return 0; 146 return 0;
146} 147}
147 148
149static int mpc5200_rtc_read_time(struct device *dev, struct rtc_time *tm)
150{
151 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
152 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
153 int tmp;
154
155 tm->tm_sec = in_8(&regs->second);
156 tm->tm_min = in_8(&regs->minute);
157
158 /* 12 hour format? */
159 if (in_8(&regs->hour) & 0x20)
160 tm->tm_hour = (in_8(&regs->hour) >> 1) +
161 (in_8(&regs->hour) & 1 ? 12 : 0);
162 else
163 tm->tm_hour = in_8(&regs->hour);
164
165 tmp = in_8(&regs->wday_mday);
166 tm->tm_mday = tmp & 0x1f;
167 tm->tm_mon = in_8(&regs->month) - 1;
168 tm->tm_year = in_be16(&regs->year) - 1900;
169 tm->tm_wday = (tmp >> 5) % 7;
170 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
171 tm->tm_isdst = 0;
172
173 return 0;
174}
175
176static int mpc5200_rtc_set_time(struct device *dev, struct rtc_time *tm)
177{
178 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
179 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
180
181 mpc5121_rtc_update_smh(regs, tm);
182
183 /* date */
184 out_8(&regs->month_set, tm->tm_mon + 1);
185 out_8(&regs->weekday_set, tm->tm_wday ? tm->tm_wday : 7);
186 out_8(&regs->date_set, tm->tm_mday);
187 out_be16(&regs->year_set, tm->tm_year + 1900);
188
189 /* set date sequence */
190 out_8(&regs->set_date, 0x1);
191 out_8(&regs->set_date, 0x3);
192 out_8(&regs->set_date, 0x1);
193 out_8(&regs->set_date, 0x0);
194
195 return 0;
196}
197
148static int mpc5121_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 198static int mpc5121_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
149{ 199{
150 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); 200 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
@@ -248,11 +298,18 @@ static const struct rtc_class_ops mpc5121_rtc_ops = {
248 .alarm_irq_enable = mpc5121_rtc_alarm_irq_enable, 298 .alarm_irq_enable = mpc5121_rtc_alarm_irq_enable,
249}; 299};
250 300
301static const struct rtc_class_ops mpc5200_rtc_ops = {
302 .read_time = mpc5200_rtc_read_time,
303 .set_time = mpc5200_rtc_set_time,
304 .read_alarm = mpc5121_rtc_read_alarm,
305 .set_alarm = mpc5121_rtc_set_alarm,
306 .alarm_irq_enable = mpc5121_rtc_alarm_irq_enable,
307};
308
251static int __devinit mpc5121_rtc_probe(struct platform_device *op) 309static int __devinit mpc5121_rtc_probe(struct platform_device *op)
252{ 310{
253 struct mpc5121_rtc_data *rtc; 311 struct mpc5121_rtc_data *rtc;
254 int err = 0; 312 int err = 0;
255 u32 ka;
256 313
257 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 314 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
258 if (!rtc) 315 if (!rtc)
@@ -287,15 +344,22 @@ static int __devinit mpc5121_rtc_probe(struct platform_device *op)
287 goto out_dispose2; 344 goto out_dispose2;
288 } 345 }
289 346
290 ka = in_be32(&rtc->regs->keep_alive); 347 if (of_device_is_compatible(op->dev.of_node, "fsl,mpc5121-rtc")) {
291 if (ka & 0x02) { 348 u32 ka;
292 dev_warn(&op->dev, 349 ka = in_be32(&rtc->regs->keep_alive);
293 "mpc5121-rtc: Battery or oscillator failure!\n"); 350 if (ka & 0x02) {
294 out_be32(&rtc->regs->keep_alive, ka); 351 dev_warn(&op->dev,
352 "mpc5121-rtc: Battery or oscillator failure!\n");
353 out_be32(&rtc->regs->keep_alive, ka);
354 }
355
356 rtc->rtc = rtc_device_register("mpc5121-rtc", &op->dev,
357 &mpc5121_rtc_ops, THIS_MODULE);
358 } else {
359 rtc->rtc = rtc_device_register("mpc5200-rtc", &op->dev,
360 &mpc5200_rtc_ops, THIS_MODULE);
295 } 361 }
296 362
297 rtc->rtc = rtc_device_register("mpc5121-rtc", &op->dev,
298 &mpc5121_rtc_ops, THIS_MODULE);
299 if (IS_ERR(rtc->rtc)) { 363 if (IS_ERR(rtc->rtc)) {
300 err = PTR_ERR(rtc->rtc); 364 err = PTR_ERR(rtc->rtc);
301 goto out_free_irq; 365 goto out_free_irq;
@@ -340,6 +404,7 @@ static int __devexit mpc5121_rtc_remove(struct platform_device *op)
340 404
341static struct of_device_id mpc5121_rtc_match[] __devinitdata = { 405static struct of_device_id mpc5121_rtc_match[] __devinitdata = {
342 { .compatible = "fsl,mpc5121-rtc", }, 406 { .compatible = "fsl,mpc5121-rtc", },
407 { .compatible = "fsl,mpc5200-rtc", },
343 {}, 408 {},
344}; 409};
345 410
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c
index 0cec5650d56a..d33544802a2e 100644
--- a/drivers/rtc/rtc-mrst.c
+++ b/drivers/rtc/rtc-mrst.c
@@ -332,9 +332,8 @@ vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, int rtc_irq)
332 if (!iomem) 332 if (!iomem)
333 return -ENODEV; 333 return -ENODEV;
334 334
335 iomem = request_mem_region(iomem->start, 335 iomem = request_mem_region(iomem->start, resource_size(iomem),
336 iomem->end + 1 - iomem->start, 336 driver_name);
337 driver_name);
338 if (!iomem) { 337 if (!iomem) {
339 dev_dbg(dev, "i/o mem already in use.\n"); 338 dev_dbg(dev, "i/o mem already in use.\n");
340 return -EBUSY; 339 return -EBUSY;
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index bcae8dd41496..7789002bdd5c 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -368,7 +368,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
368 pr_info("%s: already running\n", pdev->name); 368 pr_info("%s: already running\n", pdev->name);
369 369
370 /* force to 24 hour mode */ 370 /* force to 24 hour mode */
371 new_ctrl = reg & ~(OMAP_RTC_CTRL_SPLIT|OMAP_RTC_CTRL_AUTO_COMP); 371 new_ctrl = reg & (OMAP_RTC_CTRL_SPLIT|OMAP_RTC_CTRL_AUTO_COMP);
372 new_ctrl |= OMAP_RTC_CTRL_STOP; 372 new_ctrl |= OMAP_RTC_CTRL_STOP;
373 373
374 /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE: 374 /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE:
diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
new file mode 100644
index 000000000000..d420e9d877e8
--- /dev/null
+++ b/drivers/rtc/rtc-pm8xxx.c
@@ -0,0 +1,550 @@
1/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/rtc.h>
16#include <linux/pm.h>
17#include <linux/slab.h>
18#include <linux/spinlock.h>
19
20#include <linux/mfd/pm8xxx/core.h>
21#include <linux/mfd/pm8xxx/rtc.h>
22
23
24/* RTC Register offsets from RTC CTRL REG */
25#define PM8XXX_ALARM_CTRL_OFFSET 0x01
26#define PM8XXX_RTC_WRITE_OFFSET 0x02
27#define PM8XXX_RTC_READ_OFFSET 0x06
28#define PM8XXX_ALARM_RW_OFFSET 0x0A
29
30/* RTC_CTRL register bit fields */
31#define PM8xxx_RTC_ENABLE BIT(7)
32#define PM8xxx_RTC_ALARM_ENABLE BIT(1)
33#define PM8xxx_RTC_ALARM_CLEAR BIT(0)
34
35#define NUM_8_BIT_RTC_REGS 0x4
36
37/**
38 * struct pm8xxx_rtc - rtc driver internal structure
39 * @rtc: rtc device for this driver.
40 * @rtc_alarm_irq: rtc alarm irq number.
41 * @rtc_base: address of rtc control register.
42 * @rtc_read_base: base address of read registers.
43 * @rtc_write_base: base address of write registers.
44 * @alarm_rw_base: base address of alarm registers.
45 * @ctrl_reg: rtc control register.
46 * @rtc_dev: device structure.
47 * @ctrl_reg_lock: spinlock protecting access to ctrl_reg.
48 */
49struct pm8xxx_rtc {
50 struct rtc_device *rtc;
51 int rtc_alarm_irq;
52 int rtc_base;
53 int rtc_read_base;
54 int rtc_write_base;
55 int alarm_rw_base;
56 u8 ctrl_reg;
57 struct device *rtc_dev;
58 spinlock_t ctrl_reg_lock;
59};
60
61/*
62 * The RTC registers need to be read/written one byte at a time. This is a
63 * hardware limitation.
64 */
65static int pm8xxx_read_wrapper(struct pm8xxx_rtc *rtc_dd, u8 *rtc_val,
66 int base, int count)
67{
68 int i, rc;
69 struct device *parent = rtc_dd->rtc_dev->parent;
70
71 for (i = 0; i < count; i++) {
72 rc = pm8xxx_readb(parent, base + i, &rtc_val[i]);
73 if (rc < 0) {
74 dev_err(rtc_dd->rtc_dev, "PMIC read failed\n");
75 return rc;
76 }
77 }
78
79 return 0;
80}
81
82static int pm8xxx_write_wrapper(struct pm8xxx_rtc *rtc_dd, u8 *rtc_val,
83 int base, int count)
84{
85 int i, rc;
86 struct device *parent = rtc_dd->rtc_dev->parent;
87
88 for (i = 0; i < count; i++) {
89 rc = pm8xxx_writeb(parent, base + i, rtc_val[i]);
90 if (rc < 0) {
91 dev_err(rtc_dd->rtc_dev, "PMIC write failed\n");
92 return rc;
93 }
94 }
95
96 return 0;
97}
98
99/*
100 * Steps to write the RTC registers.
101 * 1. Disable alarm if enabled.
102 * 2. Write 0x00 to LSB.
103 * 3. Write Byte[1], Byte[2], Byte[3] then Byte[0].
104 * 4. Enable alarm if disabled in step 1.
105 */
106static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
107{
108 int rc, i;
109 unsigned long secs, irq_flags;
110 u8 value[NUM_8_BIT_RTC_REGS], reg = 0, alarm_enabled = 0, ctrl_reg;
111 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
112
113 rtc_tm_to_time(tm, &secs);
114
115 for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) {
116 value[i] = secs & 0xFF;
117 secs >>= 8;
118 }
119
120 dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs);
121
122 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
123 ctrl_reg = rtc_dd->ctrl_reg;
124
125 if (ctrl_reg & PM8xxx_RTC_ALARM_ENABLE) {
126 alarm_enabled = 1;
127 ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
128 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
129 1);
130 if (rc < 0) {
131 dev_err(dev, "Write to RTC control register "
132 "failed\n");
133 goto rtc_rw_fail;
134 }
135 rtc_dd->ctrl_reg = ctrl_reg;
136 } else
137 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
138
139 /* Write 0 to Byte[0] */
140 reg = 0;
141 rc = pm8xxx_write_wrapper(rtc_dd, &reg, rtc_dd->rtc_write_base, 1);
142 if (rc < 0) {
143 dev_err(dev, "Write to RTC write data register failed\n");
144 goto rtc_rw_fail;
145 }
146
147 /* Write Byte[1], Byte[2], Byte[3] */
148 rc = pm8xxx_write_wrapper(rtc_dd, value + 1,
149 rtc_dd->rtc_write_base + 1, 3);
150 if (rc < 0) {
151 dev_err(dev, "Write to RTC write data register failed\n");
152 goto rtc_rw_fail;
153 }
154
155 /* Write Byte[0] */
156 rc = pm8xxx_write_wrapper(rtc_dd, value, rtc_dd->rtc_write_base, 1);
157 if (rc < 0) {
158 dev_err(dev, "Write to RTC write data register failed\n");
159 goto rtc_rw_fail;
160 }
161
162 if (alarm_enabled) {
163 ctrl_reg |= PM8xxx_RTC_ALARM_ENABLE;
164 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
165 1);
166 if (rc < 0) {
167 dev_err(dev, "Write to RTC control register "
168 "failed\n");
169 goto rtc_rw_fail;
170 }
171 rtc_dd->ctrl_reg = ctrl_reg;
172 }
173
174rtc_rw_fail:
175 if (alarm_enabled)
176 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
177
178 return rc;
179}
180
181static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
182{
183 int rc;
184 u8 value[NUM_8_BIT_RTC_REGS], reg;
185 unsigned long secs;
186 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
187
188 rc = pm8xxx_read_wrapper(rtc_dd, value, rtc_dd->rtc_read_base,
189 NUM_8_BIT_RTC_REGS);
190 if (rc < 0) {
191 dev_err(dev, "RTC read data register failed\n");
192 return rc;
193 }
194
195 /*
196 * Read the LSB again and check if there has been a carry over.
197 * If there is, redo the read operation.
198 */
199 rc = pm8xxx_read_wrapper(rtc_dd, &reg, rtc_dd->rtc_read_base, 1);
200 if (rc < 0) {
201 dev_err(dev, "RTC read data register failed\n");
202 return rc;
203 }
204
205 if (unlikely(reg < value[0])) {
206 rc = pm8xxx_read_wrapper(rtc_dd, value,
207 rtc_dd->rtc_read_base, NUM_8_BIT_RTC_REGS);
208 if (rc < 0) {
209 dev_err(dev, "RTC read data register failed\n");
210 return rc;
211 }
212 }
213
214 secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24);
215
216 rtc_time_to_tm(secs, tm);
217
218 rc = rtc_valid_tm(tm);
219 if (rc < 0) {
220 dev_err(dev, "Invalid time read from RTC\n");
221 return rc;
222 }
223
224 dev_dbg(dev, "secs = %lu, h:m:s == %d:%d:%d, d/m/y = %d/%d/%d\n",
225 secs, tm->tm_hour, tm->tm_min, tm->tm_sec,
226 tm->tm_mday, tm->tm_mon, tm->tm_year);
227
228 return 0;
229}
230
231static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
232{
233 int rc, i;
234 u8 value[NUM_8_BIT_RTC_REGS], ctrl_reg;
235 unsigned long secs, irq_flags;
236 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
237
238 rtc_tm_to_time(&alarm->time, &secs);
239
240 for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) {
241 value[i] = secs & 0xFF;
242 secs >>= 8;
243 }
244
245 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
246
247 rc = pm8xxx_write_wrapper(rtc_dd, value, rtc_dd->alarm_rw_base,
248 NUM_8_BIT_RTC_REGS);
249 if (rc < 0) {
250 dev_err(dev, "Write to RTC ALARM register failed\n");
251 goto rtc_rw_fail;
252 }
253
254 ctrl_reg = rtc_dd->ctrl_reg;
255 ctrl_reg = alarm->enabled ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
256 (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
257
258 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
259 if (rc < 0) {
260 dev_err(dev, "Write to RTC control register failed\n");
261 goto rtc_rw_fail;
262 }
263
264 rtc_dd->ctrl_reg = ctrl_reg;
265
266 dev_dbg(dev, "Alarm Set for h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
267 alarm->time.tm_hour, alarm->time.tm_min,
268 alarm->time.tm_sec, alarm->time.tm_mday,
269 alarm->time.tm_mon, alarm->time.tm_year);
270rtc_rw_fail:
271 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
272 return rc;
273}
274
275static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
276{
277 int rc;
278 u8 value[NUM_8_BIT_RTC_REGS];
279 unsigned long secs;
280 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
281
282 rc = pm8xxx_read_wrapper(rtc_dd, value, rtc_dd->alarm_rw_base,
283 NUM_8_BIT_RTC_REGS);
284 if (rc < 0) {
285 dev_err(dev, "RTC alarm time read failed\n");
286 return rc;
287 }
288
289 secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24);
290
291 rtc_time_to_tm(secs, &alarm->time);
292
293 rc = rtc_valid_tm(&alarm->time);
294 if (rc < 0) {
295 dev_err(dev, "Invalid alarm time read from RTC\n");
296 return rc;
297 }
298
299 dev_dbg(dev, "Alarm set for - h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
300 alarm->time.tm_hour, alarm->time.tm_min,
301 alarm->time.tm_sec, alarm->time.tm_mday,
302 alarm->time.tm_mon, alarm->time.tm_year);
303
304 return 0;
305}
306
307static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
308{
309 int rc;
310 unsigned long irq_flags;
311 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
312 u8 ctrl_reg;
313
314 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
315 ctrl_reg = rtc_dd->ctrl_reg;
316 ctrl_reg = (enable) ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
317 (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
318
319 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
320 if (rc < 0) {
321 dev_err(dev, "Write to RTC control register failed\n");
322 goto rtc_rw_fail;
323 }
324
325 rtc_dd->ctrl_reg = ctrl_reg;
326
327rtc_rw_fail:
328 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
329 return rc;
330}
331
332static struct rtc_class_ops pm8xxx_rtc_ops = {
333 .read_time = pm8xxx_rtc_read_time,
334 .set_alarm = pm8xxx_rtc_set_alarm,
335 .read_alarm = pm8xxx_rtc_read_alarm,
336 .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable,
337};
338
339static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
340{
341 struct pm8xxx_rtc *rtc_dd = dev_id;
342 u8 ctrl_reg;
343 int rc;
344 unsigned long irq_flags;
345
346 rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF);
347
348 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
349
350 /* Clear the alarm enable bit */
351 ctrl_reg = rtc_dd->ctrl_reg;
352 ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
353
354 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
355 if (rc < 0) {
356 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
357 dev_err(rtc_dd->rtc_dev, "Write to RTC control register "
358 "failed\n");
359 goto rtc_alarm_handled;
360 }
361
362 rtc_dd->ctrl_reg = ctrl_reg;
363 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
364
365 /* Clear RTC alarm register */
366 rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
367 PM8XXX_ALARM_CTRL_OFFSET, 1);
368 if (rc < 0) {
369 dev_err(rtc_dd->rtc_dev, "RTC Alarm control register read "
370 "failed\n");
371 goto rtc_alarm_handled;
372 }
373
374 ctrl_reg &= ~PM8xxx_RTC_ALARM_CLEAR;
375 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
376 PM8XXX_ALARM_CTRL_OFFSET, 1);
377 if (rc < 0)
378 dev_err(rtc_dd->rtc_dev, "Write to RTC Alarm control register"
379 " failed\n");
380
381rtc_alarm_handled:
382 return IRQ_HANDLED;
383}
384
385static int __devinit pm8xxx_rtc_probe(struct platform_device *pdev)
386{
387 int rc;
388 u8 ctrl_reg;
389 bool rtc_write_enable = false;
390 struct pm8xxx_rtc *rtc_dd;
391 struct resource *rtc_resource;
392 const struct pm8xxx_rtc_platform_data *pdata =
393 dev_get_platdata(&pdev->dev);
394
395 if (pdata != NULL)
396 rtc_write_enable = pdata->rtc_write_enable;
397
398 rtc_dd = kzalloc(sizeof(*rtc_dd), GFP_KERNEL);
399 if (rtc_dd == NULL) {
400 dev_err(&pdev->dev, "Unable to allocate memory!\n");
401 return -ENOMEM;
402 }
403
404 /* Initialise spinlock to protect RTC control register */
405 spin_lock_init(&rtc_dd->ctrl_reg_lock);
406
407 rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0);
408 if (rtc_dd->rtc_alarm_irq < 0) {
409 dev_err(&pdev->dev, "Alarm IRQ resource absent!\n");
410 rc = -ENXIO;
411 goto fail_rtc_enable;
412 }
413
414 rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO,
415 "pmic_rtc_base");
416 if (!(rtc_resource && rtc_resource->start)) {
417 dev_err(&pdev->dev, "RTC IO resource absent!\n");
418 rc = -ENXIO;
419 goto fail_rtc_enable;
420 }
421
422 rtc_dd->rtc_base = rtc_resource->start;
423
424 /* Setup RTC register addresses */
425 rtc_dd->rtc_write_base = rtc_dd->rtc_base + PM8XXX_RTC_WRITE_OFFSET;
426 rtc_dd->rtc_read_base = rtc_dd->rtc_base + PM8XXX_RTC_READ_OFFSET;
427 rtc_dd->alarm_rw_base = rtc_dd->rtc_base + PM8XXX_ALARM_RW_OFFSET;
428
429 rtc_dd->rtc_dev = &pdev->dev;
430
431 /* Check if the RTC is on, else turn it on */
432 rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
433 if (rc < 0) {
434 dev_err(&pdev->dev, "RTC control register read failed!\n");
435 goto fail_rtc_enable;
436 }
437
438 if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) {
439 ctrl_reg |= PM8xxx_RTC_ENABLE;
440 rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
441 1);
442 if (rc < 0) {
443 dev_err(&pdev->dev, "Write to RTC control register "
444 "failed\n");
445 goto fail_rtc_enable;
446 }
447 }
448
449 rtc_dd->ctrl_reg = ctrl_reg;
450 if (rtc_write_enable == true)
451 pm8xxx_rtc_ops.set_time = pm8xxx_rtc_set_time;
452
453 platform_set_drvdata(pdev, rtc_dd);
454
455 /* Register the RTC device */
456 rtc_dd->rtc = rtc_device_register("pm8xxx_rtc", &pdev->dev,
457 &pm8xxx_rtc_ops, THIS_MODULE);
458 if (IS_ERR(rtc_dd->rtc)) {
459 dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n",
460 __func__, PTR_ERR(rtc_dd->rtc));
461 rc = PTR_ERR(rtc_dd->rtc);
462 goto fail_rtc_enable;
463 }
464
465 /* Request the alarm IRQ */
466 rc = request_any_context_irq(rtc_dd->rtc_alarm_irq,
467 pm8xxx_alarm_trigger, IRQF_TRIGGER_RISING,
468 "pm8xxx_rtc_alarm", rtc_dd);
469 if (rc < 0) {
470 dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc);
471 goto fail_req_irq;
472 }
473
474 device_init_wakeup(&pdev->dev, 1);
475
476 dev_dbg(&pdev->dev, "Probe success !!\n");
477
478 return 0;
479
480fail_req_irq:
481 rtc_device_unregister(rtc_dd->rtc);
482fail_rtc_enable:
483 platform_set_drvdata(pdev, NULL);
484 kfree(rtc_dd);
485 return rc;
486}
487
488static int __devexit pm8xxx_rtc_remove(struct platform_device *pdev)
489{
490 struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
491
492 device_init_wakeup(&pdev->dev, 0);
493 free_irq(rtc_dd->rtc_alarm_irq, rtc_dd);
494 rtc_device_unregister(rtc_dd->rtc);
495 platform_set_drvdata(pdev, NULL);
496 kfree(rtc_dd);
497
498 return 0;
499}
500
501#ifdef CONFIG_PM_SLEEP
502static int pm8xxx_rtc_resume(struct device *dev)
503{
504 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
505
506 if (device_may_wakeup(dev))
507 disable_irq_wake(rtc_dd->rtc_alarm_irq);
508
509 return 0;
510}
511
512static int pm8xxx_rtc_suspend(struct device *dev)
513{
514 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
515
516 if (device_may_wakeup(dev))
517 enable_irq_wake(rtc_dd->rtc_alarm_irq);
518
519 return 0;
520}
521#endif
522
523SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, pm8xxx_rtc_suspend, pm8xxx_rtc_resume);
524
525static struct platform_driver pm8xxx_rtc_driver = {
526 .probe = pm8xxx_rtc_probe,
527 .remove = __devexit_p(pm8xxx_rtc_remove),
528 .driver = {
529 .name = PM8XXX_RTC_DEV_NAME,
530 .owner = THIS_MODULE,
531 .pm = &pm8xxx_rtc_pm_ops,
532 },
533};
534
535static int __init pm8xxx_rtc_init(void)
536{
537 return platform_driver_register(&pm8xxx_rtc_driver);
538}
539module_init(pm8xxx_rtc_init);
540
541static void __exit pm8xxx_rtc_exit(void)
542{
543 platform_driver_unregister(&pm8xxx_rtc_driver);
544}
545module_exit(pm8xxx_rtc_exit);
546
547MODULE_ALIAS("platform:rtc-pm8xxx");
548MODULE_DESCRIPTION("PMIC8xxx RTC driver");
549MODULE_LICENSE("GPL v2");
550MODULE_AUTHOR("Anirudh Ghayal <aghayal@codeaurora.org>");
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index 46f14b82f3ab..b3eba3cddd42 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -267,9 +267,8 @@ static int puv3_rtc_probe(struct platform_device *pdev)
267 return -ENOENT; 267 return -ENOENT;
268 } 268 }
269 269
270 puv3_rtc_mem = request_mem_region(res->start, 270 puv3_rtc_mem = request_mem_region(res->start, resource_size(res),
271 res->end-res->start+1, 271 pdev->name);
272 pdev->name);
273 272
274 if (puv3_rtc_mem == NULL) { 273 if (puv3_rtc_mem == NULL) {
275 dev_err(&pdev->dev, "failed to reserve memory region\n"); 274 dev_err(&pdev->dev, "failed to reserve memory region\n");
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 16512ecae31a..9329dbb9ebab 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -57,11 +57,13 @@ static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
57{ 57{
58 struct rtc_device *rdev = id; 58 struct rtc_device *rdev = id;
59 59
60 clk_enable(rtc_clk);
60 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF); 61 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF);
61 62
62 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 63 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
63 writeb(S3C2410_INTP_ALM, s3c_rtc_base + S3C2410_INTP); 64 writeb(S3C2410_INTP_ALM, s3c_rtc_base + S3C2410_INTP);
64 65
66 clk_disable(rtc_clk);
65 return IRQ_HANDLED; 67 return IRQ_HANDLED;
66} 68}
67 69
@@ -69,11 +71,13 @@ static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
69{ 71{
70 struct rtc_device *rdev = id; 72 struct rtc_device *rdev = id;
71 73
74 clk_enable(rtc_clk);
72 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF); 75 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF);
73 76
74 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 77 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
75 writeb(S3C2410_INTP_TIC, s3c_rtc_base + S3C2410_INTP); 78 writeb(S3C2410_INTP_TIC, s3c_rtc_base + S3C2410_INTP);
76 79
80 clk_disable(rtc_clk);
77 return IRQ_HANDLED; 81 return IRQ_HANDLED;
78} 82}
79 83
@@ -84,12 +88,14 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
84 88
85 pr_debug("%s: aie=%d\n", __func__, enabled); 89 pr_debug("%s: aie=%d\n", __func__, enabled);
86 90
91 clk_enable(rtc_clk);
87 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 92 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
88 93
89 if (enabled) 94 if (enabled)
90 tmp |= S3C2410_RTCALM_ALMEN; 95 tmp |= S3C2410_RTCALM_ALMEN;
91 96
92 writeb(tmp, s3c_rtc_base + S3C2410_RTCALM); 97 writeb(tmp, s3c_rtc_base + S3C2410_RTCALM);
98 clk_disable(rtc_clk);
93 99
94 return 0; 100 return 0;
95} 101}
@@ -103,6 +109,7 @@ static int s3c_rtc_setfreq(struct device *dev, int freq)
103 if (!is_power_of_2(freq)) 109 if (!is_power_of_2(freq))
104 return -EINVAL; 110 return -EINVAL;
105 111
112 clk_enable(rtc_clk);
106 spin_lock_irq(&s3c_rtc_pie_lock); 113 spin_lock_irq(&s3c_rtc_pie_lock);
107 114
108 if (s3c_rtc_cpu_type == TYPE_S3C2410) { 115 if (s3c_rtc_cpu_type == TYPE_S3C2410) {
@@ -114,6 +121,7 @@ static int s3c_rtc_setfreq(struct device *dev, int freq)
114 121
115 writel(tmp, s3c_rtc_base + S3C2410_TICNT); 122 writel(tmp, s3c_rtc_base + S3C2410_TICNT);
116 spin_unlock_irq(&s3c_rtc_pie_lock); 123 spin_unlock_irq(&s3c_rtc_pie_lock);
124 clk_disable(rtc_clk);
117 125
118 return 0; 126 return 0;
119} 127}
@@ -125,6 +133,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
125 unsigned int have_retried = 0; 133 unsigned int have_retried = 0;
126 void __iomem *base = s3c_rtc_base; 134 void __iomem *base = s3c_rtc_base;
127 135
136 clk_enable(rtc_clk);
128 retry_get_time: 137 retry_get_time:
129 rtc_tm->tm_min = readb(base + S3C2410_RTCMIN); 138 rtc_tm->tm_min = readb(base + S3C2410_RTCMIN);
130 rtc_tm->tm_hour = readb(base + S3C2410_RTCHOUR); 139 rtc_tm->tm_hour = readb(base + S3C2410_RTCHOUR);
@@ -157,6 +166,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
157 rtc_tm->tm_year += 100; 166 rtc_tm->tm_year += 100;
158 rtc_tm->tm_mon -= 1; 167 rtc_tm->tm_mon -= 1;
159 168
169 clk_disable(rtc_clk);
160 return rtc_valid_tm(rtc_tm); 170 return rtc_valid_tm(rtc_tm);
161} 171}
162 172
@@ -165,6 +175,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
165 void __iomem *base = s3c_rtc_base; 175 void __iomem *base = s3c_rtc_base;
166 int year = tm->tm_year - 100; 176 int year = tm->tm_year - 100;
167 177
178 clk_enable(rtc_clk);
168 pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n", 179 pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n",
169 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 180 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
170 tm->tm_hour, tm->tm_min, tm->tm_sec); 181 tm->tm_hour, tm->tm_min, tm->tm_sec);
@@ -182,6 +193,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
182 writeb(bin2bcd(tm->tm_mday), base + S3C2410_RTCDATE); 193 writeb(bin2bcd(tm->tm_mday), base + S3C2410_RTCDATE);
183 writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_RTCMON); 194 writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_RTCMON);
184 writeb(bin2bcd(year), base + S3C2410_RTCYEAR); 195 writeb(bin2bcd(year), base + S3C2410_RTCYEAR);
196 clk_disable(rtc_clk);
185 197
186 return 0; 198 return 0;
187} 199}
@@ -192,6 +204,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
192 void __iomem *base = s3c_rtc_base; 204 void __iomem *base = s3c_rtc_base;
193 unsigned int alm_en; 205 unsigned int alm_en;
194 206
207 clk_enable(rtc_clk);
195 alm_tm->tm_sec = readb(base + S3C2410_ALMSEC); 208 alm_tm->tm_sec = readb(base + S3C2410_ALMSEC);
196 alm_tm->tm_min = readb(base + S3C2410_ALMMIN); 209 alm_tm->tm_min = readb(base + S3C2410_ALMMIN);
197 alm_tm->tm_hour = readb(base + S3C2410_ALMHOUR); 210 alm_tm->tm_hour = readb(base + S3C2410_ALMHOUR);
@@ -243,6 +256,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
243 else 256 else
244 alm_tm->tm_year = -1; 257 alm_tm->tm_year = -1;
245 258
259 clk_disable(rtc_clk);
246 return 0; 260 return 0;
247} 261}
248 262
@@ -252,6 +266,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
252 void __iomem *base = s3c_rtc_base; 266 void __iomem *base = s3c_rtc_base;
253 unsigned int alrm_en; 267 unsigned int alrm_en;
254 268
269 clk_enable(rtc_clk);
255 pr_debug("s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 270 pr_debug("s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
256 alrm->enabled, 271 alrm->enabled,
257 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 272 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
@@ -282,6 +297,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
282 297
283 s3c_rtc_setaie(dev, alrm->enabled); 298 s3c_rtc_setaie(dev, alrm->enabled);
284 299
300 clk_disable(rtc_clk);
285 return 0; 301 return 0;
286} 302}
287 303
@@ -289,6 +305,7 @@ static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
289{ 305{
290 unsigned int ticnt; 306 unsigned int ticnt;
291 307
308 clk_enable(rtc_clk);
292 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 309 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
293 ticnt = readw(s3c_rtc_base + S3C2410_RTCCON); 310 ticnt = readw(s3c_rtc_base + S3C2410_RTCCON);
294 ticnt &= S3C64XX_RTCCON_TICEN; 311 ticnt &= S3C64XX_RTCCON_TICEN;
@@ -298,6 +315,7 @@ static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
298 } 315 }
299 316
300 seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no"); 317 seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no");
318 clk_disable(rtc_clk);
301 return 0; 319 return 0;
302} 320}
303 321
@@ -360,6 +378,7 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
360 if (s3c_rtc_base == NULL) 378 if (s3c_rtc_base == NULL)
361 return; 379 return;
362 380
381 clk_enable(rtc_clk);
363 if (!en) { 382 if (!en) {
364 tmp = readw(base + S3C2410_RTCCON); 383 tmp = readw(base + S3C2410_RTCCON);
365 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 384 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
@@ -399,6 +418,7 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
399 base + S3C2410_RTCCON); 418 base + S3C2410_RTCCON);
400 } 419 }
401 } 420 }
421 clk_disable(rtc_clk);
402} 422}
403 423
404static int __devexit s3c_rtc_remove(struct platform_device *dev) 424static int __devexit s3c_rtc_remove(struct platform_device *dev)
@@ -410,7 +430,6 @@ static int __devexit s3c_rtc_remove(struct platform_device *dev)
410 430
411 s3c_rtc_setaie(&dev->dev, 0); 431 s3c_rtc_setaie(&dev->dev, 0);
412 432
413 clk_disable(rtc_clk);
414 clk_put(rtc_clk); 433 clk_put(rtc_clk);
415 rtc_clk = NULL; 434 rtc_clk = NULL;
416 435
@@ -455,8 +474,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
455 return -ENOENT; 474 return -ENOENT;
456 } 475 }
457 476
458 s3c_rtc_mem = request_mem_region(res->start, 477 s3c_rtc_mem = request_mem_region(res->start, resource_size(res),
459 res->end-res->start+1,
460 pdev->name); 478 pdev->name);
461 479
462 if (s3c_rtc_mem == NULL) { 480 if (s3c_rtc_mem == NULL) {
@@ -465,7 +483,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
465 goto err_nores; 483 goto err_nores;
466 } 484 }
467 485
468 s3c_rtc_base = ioremap(res->start, res->end - res->start + 1); 486 s3c_rtc_base = ioremap(res->start, resource_size(res));
469 if (s3c_rtc_base == NULL) { 487 if (s3c_rtc_base == NULL) {
470 dev_err(&pdev->dev, "failed ioremap()\n"); 488 dev_err(&pdev->dev, "failed ioremap()\n");
471 ret = -EINVAL; 489 ret = -EINVAL;
@@ -530,6 +548,8 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
530 548
531 s3c_rtc_setfreq(&pdev->dev, 1); 549 s3c_rtc_setfreq(&pdev->dev, 1);
532 550
551 clk_disable(rtc_clk);
552
533 return 0; 553 return 0;
534 554
535 err_nortc: 555 err_nortc:
@@ -555,6 +575,7 @@ static int ticnt_save, ticnt_en_save;
555 575
556static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) 576static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
557{ 577{
578 clk_enable(rtc_clk);
558 /* save TICNT for anyone using periodic interrupts */ 579 /* save TICNT for anyone using periodic interrupts */
559 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); 580 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
560 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 581 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
@@ -569,6 +590,7 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
569 else 590 else
570 dev_err(&pdev->dev, "enable_irq_wake failed\n"); 591 dev_err(&pdev->dev, "enable_irq_wake failed\n");
571 } 592 }
593 clk_disable(rtc_clk);
572 594
573 return 0; 595 return 0;
574} 596}
@@ -577,6 +599,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
577{ 599{
578 unsigned int tmp; 600 unsigned int tmp;
579 601
602 clk_enable(rtc_clk);
580 s3c_rtc_enable(pdev, 1); 603 s3c_rtc_enable(pdev, 1);
581 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); 604 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
582 if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) { 605 if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) {
@@ -588,6 +611,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
588 disable_irq_wake(s3c_rtc_alarmno); 611 disable_irq_wake(s3c_rtc_alarmno);
589 wake_en = false; 612 wake_en = false;
590 } 613 }
614 clk_disable(rtc_clk);
591 615
592 return 0; 616 return 0;
593} 617}
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index 2fc31aac3f4e..75259fe38602 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -343,7 +343,7 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev)
343 343
344 /* set context info. */ 344 /* set context info. */
345 info->pdev = pdev; 345 info->pdev = pdev;
346 info->tegra_rtc_lock = __SPIN_LOCK_UNLOCKED(info->tegra_rtc_lock); 346 spin_lock_init(&info->tegra_rtc_lock);
347 347
348 platform_set_drvdata(pdev, info); 348 platform_set_drvdata(pdev, info);
349 349
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index f9a2799c44d6..9a81f778d6b2 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -275,7 +275,7 @@ static int twl_rtc_set_time(struct device *dev, struct rtc_time *tm)
275 goto out; 275 goto out;
276 276
277 save_control &= ~BIT_RTC_CTRL_REG_STOP_RTC_M; 277 save_control &= ~BIT_RTC_CTRL_REG_STOP_RTC_M;
278 twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG); 278 ret = twl_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
279 if (ret < 0) 279 if (ret < 0)
280 goto out; 280 goto out;
281 281