diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-26 00:00:19 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-26 00:00:19 -0400 |
commit | 45b583b10a8b438b970e95a7d1d4db22c9e35004 (patch) | |
tree | 14fa481598289df0459580c582b48a9d95db51f6 /drivers/rtc | |
parent | 154dd78d30b56ffb8b447f629bfcceb14150e5c4 (diff) | |
parent | f19da2ce8ef5e49b8b8ea199c3601dd45d71b262 (diff) |
Merge 'akpm' patch series
* Merge akpm patch series: (122 commits)
drivers/connector/cn_proc.c: remove unused local
Documentation/SubmitChecklist: add RCU debug config options
reiserfs: use hweight_long()
reiserfs: use proper little-endian bitops
pnpacpi: register disabled resources
drivers/rtc/rtc-tegra.c: properly initialize spinlock
drivers/rtc/rtc-twl.c: check return value of twl_rtc_write_u8() in twl_rtc_set_time()
drivers/rtc: add support for Qualcomm PMIC8xxx RTC
drivers/rtc/rtc-s3c.c: support clock gating
drivers/rtc/rtc-mpc5121.c: add support for RTC on MPC5200
init: skip calibration delay if previously done
misc/eeprom: add eeprom access driver for digsy_mtc board
misc/eeprom: add driver for microwire 93xx46 EEPROMs
checkpatch.pl: update $logFunctions
checkpatch: make utf-8 test --strict
checkpatch.pl: add ability to ignore various messages
checkpatch: add a "prefer __aligned" check
checkpatch: validate signature styles and To: and Cc: lines
checkpatch: add __rcu as a sparse modifier
checkpatch: suggest using min_t or max_t
...
Did this as a merge because of (trivial) conflicts in
- Documentation/feature-removal-schedule.txt
- arch/xtensa/include/asm/uaccess.h
that were just easier to fix up in the merge than in the patch series.
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 14 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-mpc5121.c | 81 | ||||
-rw-r--r-- | drivers/rtc/rtc-pm8xxx.c | 550 | ||||
-rw-r--r-- | drivers/rtc/rtc-s3c.c | 27 | ||||
-rw-r--r-- | drivers/rtc/rtc-tegra.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-twl.c | 2 |
7 files changed, 664 insertions, 13 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 | ||
1007 | config RTC_DRV_MPC5121 | 1007 | config 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 | ||
1037 | config 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 | |||
1037 | config RTC_DRV_TEGRA | 1047 | config 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 | |||
77 | obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o | 77 | obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o |
78 | obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o | 78 | obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o |
79 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o | 79 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o |
80 | obj-$(CONFIG_RTC_DRV_PM8XXX) += rtc-pm8xxx.o | ||
80 | obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o | 81 | obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o |
81 | obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o | 82 | obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o |
82 | obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o | 83 | obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o |
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 | ||
149 | static 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(®s->second); | ||
156 | tm->tm_min = in_8(®s->minute); | ||
157 | |||
158 | /* 12 hour format? */ | ||
159 | if (in_8(®s->hour) & 0x20) | ||
160 | tm->tm_hour = (in_8(®s->hour) >> 1) + | ||
161 | (in_8(®s->hour) & 1 ? 12 : 0); | ||
162 | else | ||
163 | tm->tm_hour = in_8(®s->hour); | ||
164 | |||
165 | tmp = in_8(®s->wday_mday); | ||
166 | tm->tm_mday = tmp & 0x1f; | ||
167 | tm->tm_mon = in_8(®s->month) - 1; | ||
168 | tm->tm_year = in_be16(®s->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 | |||
176 | static 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(®s->month_set, tm->tm_mon + 1); | ||
185 | out_8(®s->weekday_set, tm->tm_wday ? tm->tm_wday : 7); | ||
186 | out_8(®s->date_set, tm->tm_mday); | ||
187 | out_be16(®s->year_set, tm->tm_year + 1900); | ||
188 | |||
189 | /* set date sequence */ | ||
190 | out_8(®s->set_date, 0x1); | ||
191 | out_8(®s->set_date, 0x3); | ||
192 | out_8(®s->set_date, 0x1); | ||
193 | out_8(®s->set_date, 0x0); | ||
194 | |||
195 | return 0; | ||
196 | } | ||
197 | |||
148 | static int mpc5121_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | 198 | static 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 | ||
301 | static 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 | |||
251 | static int __devinit mpc5121_rtc_probe(struct platform_device *op) | 309 | static 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 | ||
341 | static struct of_device_id mpc5121_rtc_match[] __devinitdata = { | 405 | static 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-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 | */ | ||
49 | struct 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 | */ | ||
65 | static 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 | |||
82 | static 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 | */ | ||
106 | static 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, ®, 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 | |||
174 | rtc_rw_fail: | ||
175 | if (alarm_enabled) | ||
176 | spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); | ||
177 | |||
178 | return rc; | ||
179 | } | ||
180 | |||
181 | static 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, ®, 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 | |||
231 | static 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); | ||
270 | rtc_rw_fail: | ||
271 | spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); | ||
272 | return rc; | ||
273 | } | ||
274 | |||
275 | static 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 | |||
307 | static 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 | |||
327 | rtc_rw_fail: | ||
328 | spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); | ||
329 | return rc; | ||
330 | } | ||
331 | |||
332 | static 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 | |||
339 | static 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 | |||
381 | rtc_alarm_handled: | ||
382 | return IRQ_HANDLED; | ||
383 | } | ||
384 | |||
385 | static 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 | |||
480 | fail_req_irq: | ||
481 | rtc_device_unregister(rtc_dd->rtc); | ||
482 | fail_rtc_enable: | ||
483 | platform_set_drvdata(pdev, NULL); | ||
484 | kfree(rtc_dd); | ||
485 | return rc; | ||
486 | } | ||
487 | |||
488 | static 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 | ||
502 | static 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 | |||
512 | static 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 | |||
523 | SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, pm8xxx_rtc_suspend, pm8xxx_rtc_resume); | ||
524 | |||
525 | static 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 | |||
535 | static int __init pm8xxx_rtc_init(void) | ||
536 | { | ||
537 | return platform_driver_register(&pm8xxx_rtc_driver); | ||
538 | } | ||
539 | module_init(pm8xxx_rtc_init); | ||
540 | |||
541 | static void __exit pm8xxx_rtc_exit(void) | ||
542 | { | ||
543 | platform_driver_unregister(&pm8xxx_rtc_driver); | ||
544 | } | ||
545 | module_exit(pm8xxx_rtc_exit); | ||
546 | |||
547 | MODULE_ALIAS("platform:rtc-pm8xxx"); | ||
548 | MODULE_DESCRIPTION("PMIC8xxx RTC driver"); | ||
549 | MODULE_LICENSE("GPL v2"); | ||
550 | MODULE_AUTHOR("Anirudh Ghayal <aghayal@codeaurora.org>"); | ||
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index 2a65e85e0f56..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 | ||
404 | static int __devexit s3c_rtc_remove(struct platform_device *dev) | 424 | static 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 | ||
@@ -529,6 +548,8 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev) | |||
529 | 548 | ||
530 | s3c_rtc_setfreq(&pdev->dev, 1); | 549 | s3c_rtc_setfreq(&pdev->dev, 1); |
531 | 550 | ||
551 | clk_disable(rtc_clk); | ||
552 | |||
532 | return 0; | 553 | return 0; |
533 | 554 | ||
534 | err_nortc: | 555 | err_nortc: |
@@ -554,6 +575,7 @@ static int ticnt_save, ticnt_en_save; | |||
554 | 575 | ||
555 | static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) | 576 | static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) |
556 | { | 577 | { |
578 | clk_enable(rtc_clk); | ||
557 | /* save TICNT for anyone using periodic interrupts */ | 579 | /* save TICNT for anyone using periodic interrupts */ |
558 | ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); | 580 | ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); |
559 | if (s3c_rtc_cpu_type == TYPE_S3C64XX) { | 581 | if (s3c_rtc_cpu_type == TYPE_S3C64XX) { |
@@ -568,6 +590,7 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) | |||
568 | else | 590 | else |
569 | dev_err(&pdev->dev, "enable_irq_wake failed\n"); | 591 | dev_err(&pdev->dev, "enable_irq_wake failed\n"); |
570 | } | 592 | } |
593 | clk_disable(rtc_clk); | ||
571 | 594 | ||
572 | return 0; | 595 | return 0; |
573 | } | 596 | } |
@@ -576,6 +599,7 @@ static int s3c_rtc_resume(struct platform_device *pdev) | |||
576 | { | 599 | { |
577 | unsigned int tmp; | 600 | unsigned int tmp; |
578 | 601 | ||
602 | clk_enable(rtc_clk); | ||
579 | s3c_rtc_enable(pdev, 1); | 603 | s3c_rtc_enable(pdev, 1); |
580 | writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); | 604 | writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); |
581 | if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) { | 605 | if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) { |
@@ -587,6 +611,7 @@ static int s3c_rtc_resume(struct platform_device *pdev) | |||
587 | disable_irq_wake(s3c_rtc_alarmno); | 611 | disable_irq_wake(s3c_rtc_alarmno); |
588 | wake_en = false; | 612 | wake_en = false; |
589 | } | 613 | } |
614 | clk_disable(rtc_clk); | ||
590 | 615 | ||
591 | return 0; | 616 | return 0; |
592 | } | 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 | ||