diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 12 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-dev.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1305.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1374.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds3232.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-mrst.c | 582 | ||||
-rw-r--r-- | drivers/rtc/rtc-rx8025.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-sa1100.c | 161 |
9 files changed, 727 insertions, 39 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 2883428d5ac8..4941cade319f 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -463,6 +463,18 @@ config RTC_DRV_CMOS | |||
463 | This driver can also be built as a module. If so, the module | 463 | This driver can also be built as a module. If so, the module |
464 | will be called rtc-cmos. | 464 | will be called rtc-cmos. |
465 | 465 | ||
466 | config RTC_DRV_VRTC | ||
467 | tristate "Virtual RTC for Moorestown platforms" | ||
468 | depends on X86_MRST | ||
469 | default y if X86_MRST | ||
470 | |||
471 | help | ||
472 | Say "yes" here to get direct support for the real time clock | ||
473 | found on Moorestown platforms. The VRTC is a emulated RTC that | ||
474 | derives its clock source from a real RTC in the PMIC. The MC146818 | ||
475 | style programming interface is mostly conserved, but any | ||
476 | updates are done via IPC calls to the system controller FW. | ||
477 | |||
466 | config RTC_DRV_DS1216 | 478 | config RTC_DRV_DS1216 |
467 | tristate "Dallas DS1216" | 479 | tristate "Dallas DS1216" |
468 | depends on SNI_RM | 480 | depends on SNI_RM |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 4c2832df4697..2afdaf3ff986 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -30,6 +30,7 @@ obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o | |||
30 | obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o | 30 | obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o |
31 | obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o | 31 | obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o |
32 | obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o | 32 | obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o |
33 | obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o | ||
33 | obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o | 34 | obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o |
34 | obj-$(CONFIG_RTC_DRV_DS1286) += rtc-ds1286.o | 35 | obj-$(CONFIG_RTC_DRV_DS1286) += rtc-ds1286.o |
35 | obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o | 36 | obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o |
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 62227cd52410..0cc0984d155b 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c | |||
@@ -104,7 +104,7 @@ static int clear_uie(struct rtc_device *rtc) | |||
104 | } | 104 | } |
105 | if (rtc->uie_task_active) { | 105 | if (rtc->uie_task_active) { |
106 | spin_unlock_irq(&rtc->irq_lock); | 106 | spin_unlock_irq(&rtc->irq_lock); |
107 | flush_scheduled_work(); | 107 | flush_work_sync(&rtc->uie_task); |
108 | spin_lock_irq(&rtc->irq_lock); | 108 | spin_lock_irq(&rtc->irq_lock); |
109 | } | 109 | } |
110 | rtc->uie_irq_active = 0; | 110 | rtc->uie_irq_active = 0; |
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c index 48da85e97ca4..077af1d7b9e4 100644 --- a/drivers/rtc/rtc-ds1305.c +++ b/drivers/rtc/rtc-ds1305.c | |||
@@ -813,7 +813,7 @@ static int __devexit ds1305_remove(struct spi_device *spi) | |||
813 | if (spi->irq) { | 813 | if (spi->irq) { |
814 | set_bit(FLAG_EXITING, &ds1305->flags); | 814 | set_bit(FLAG_EXITING, &ds1305->flags); |
815 | free_irq(spi->irq, ds1305); | 815 | free_irq(spi->irq, ds1305); |
816 | flush_scheduled_work(); | 816 | cancel_work_sync(&ds1305->work); |
817 | } | 817 | } |
818 | 818 | ||
819 | rtc_device_unregister(ds1305->rtc); | 819 | rtc_device_unregister(ds1305->rtc); |
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c index 1f0007fd4431..47fb6357c346 100644 --- a/drivers/rtc/rtc-ds1374.c +++ b/drivers/rtc/rtc-ds1374.c | |||
@@ -417,7 +417,7 @@ static int __devexit ds1374_remove(struct i2c_client *client) | |||
417 | mutex_unlock(&ds1374->mutex); | 417 | mutex_unlock(&ds1374->mutex); |
418 | 418 | ||
419 | free_irq(client->irq, client); | 419 | free_irq(client->irq, client); |
420 | flush_scheduled_work(); | 420 | cancel_work_sync(&ds1374->work); |
421 | } | 421 | } |
422 | 422 | ||
423 | rtc_device_unregister(ds1374->rtc); | 423 | rtc_device_unregister(ds1374->rtc); |
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c index 57063552d3b7..23a9ee19764c 100644 --- a/drivers/rtc/rtc-ds3232.c +++ b/drivers/rtc/rtc-ds3232.c | |||
@@ -463,7 +463,7 @@ static int __devexit ds3232_remove(struct i2c_client *client) | |||
463 | mutex_unlock(&ds3232->mutex); | 463 | mutex_unlock(&ds3232->mutex); |
464 | 464 | ||
465 | free_irq(client->irq, client); | 465 | free_irq(client->irq, client); |
466 | flush_scheduled_work(); | 466 | cancel_work_sync(&ds3232->work); |
467 | } | 467 | } |
468 | 468 | ||
469 | rtc_device_unregister(ds3232->rtc); | 469 | rtc_device_unregister(ds3232->rtc); |
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c new file mode 100644 index 000000000000..bcd0cf63eb16 --- /dev/null +++ b/drivers/rtc/rtc-mrst.c | |||
@@ -0,0 +1,582 @@ | |||
1 | /* | ||
2 | * rtc-mrst.c: Driver for Moorestown virtual RTC | ||
3 | * | ||
4 | * (C) Copyright 2009 Intel Corporation | ||
5 | * Author: Jacob Pan (jacob.jun.pan@intel.com) | ||
6 | * Feng Tang (feng.tang@intel.com) | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * as published by the Free Software Foundation; version 2 | ||
11 | * of the License. | ||
12 | * | ||
13 | * Note: | ||
14 | * VRTC is emulated by system controller firmware, the real HW | ||
15 | * RTC is located in the PMIC device. SCU FW shadows PMIC RTC | ||
16 | * in a memory mapped IO space that is visible to the host IA | ||
17 | * processor. | ||
18 | * | ||
19 | * This driver is based upon drivers/rtc/rtc-cmos.c | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Note: | ||
24 | * * vRTC only supports binary mode and 24H mode | ||
25 | * * vRTC only support PIE and AIE, no UIE, and its PIE only happens | ||
26 | * at 23:59:59pm everyday, no support for adjustable frequency | ||
27 | * * Alarm function is also limited to hr/min/sec. | ||
28 | */ | ||
29 | |||
30 | #include <linux/mod_devicetable.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/spinlock.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/module.h> | ||
36 | #include <linux/init.h> | ||
37 | #include <linux/sfi.h> | ||
38 | |||
39 | #include <asm-generic/rtc.h> | ||
40 | #include <asm/intel_scu_ipc.h> | ||
41 | #include <asm/mrst.h> | ||
42 | #include <asm/mrst-vrtc.h> | ||
43 | |||
44 | struct mrst_rtc { | ||
45 | struct rtc_device *rtc; | ||
46 | struct device *dev; | ||
47 | int irq; | ||
48 | struct resource *iomem; | ||
49 | |||
50 | u8 enabled_wake; | ||
51 | u8 suspend_ctrl; | ||
52 | }; | ||
53 | |||
54 | static const char driver_name[] = "rtc_mrst"; | ||
55 | |||
56 | #define RTC_IRQMASK (RTC_PF | RTC_AF) | ||
57 | |||
58 | static inline int is_intr(u8 rtc_intr) | ||
59 | { | ||
60 | if (!(rtc_intr & RTC_IRQF)) | ||
61 | return 0; | ||
62 | return rtc_intr & RTC_IRQMASK; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * rtc_time's year contains the increment over 1900, but vRTC's YEAR | ||
67 | * register can't be programmed to value larger than 0x64, so vRTC | ||
68 | * driver chose to use 1960 (1970 is UNIX time start point) as the base, | ||
69 | * and does the translation at read/write time. | ||
70 | * | ||
71 | * Why not just use 1970 as the offset? it's because using 1960 will | ||
72 | * make it consistent in leap year setting for both vrtc and low-level | ||
73 | * physical rtc devices. | ||
74 | */ | ||
75 | static int mrst_read_time(struct device *dev, struct rtc_time *time) | ||
76 | { | ||
77 | unsigned long flags; | ||
78 | |||
79 | if (rtc_is_updating()) | ||
80 | mdelay(20); | ||
81 | |||
82 | spin_lock_irqsave(&rtc_lock, flags); | ||
83 | time->tm_sec = vrtc_cmos_read(RTC_SECONDS); | ||
84 | time->tm_min = vrtc_cmos_read(RTC_MINUTES); | ||
85 | time->tm_hour = vrtc_cmos_read(RTC_HOURS); | ||
86 | time->tm_mday = vrtc_cmos_read(RTC_DAY_OF_MONTH); | ||
87 | time->tm_mon = vrtc_cmos_read(RTC_MONTH); | ||
88 | time->tm_year = vrtc_cmos_read(RTC_YEAR); | ||
89 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
90 | |||
91 | /* Adjust for the 1960/1900 */ | ||
92 | time->tm_year += 60; | ||
93 | time->tm_mon--; | ||
94 | return RTC_24H; | ||
95 | } | ||
96 | |||
97 | static int mrst_set_time(struct device *dev, struct rtc_time *time) | ||
98 | { | ||
99 | int ret; | ||
100 | unsigned long flags; | ||
101 | unsigned char mon, day, hrs, min, sec; | ||
102 | unsigned int yrs; | ||
103 | |||
104 | yrs = time->tm_year; | ||
105 | mon = time->tm_mon + 1; /* tm_mon starts at zero */ | ||
106 | day = time->tm_mday; | ||
107 | hrs = time->tm_hour; | ||
108 | min = time->tm_min; | ||
109 | sec = time->tm_sec; | ||
110 | |||
111 | if (yrs < 70 || yrs > 138) | ||
112 | return -EINVAL; | ||
113 | yrs -= 60; | ||
114 | |||
115 | spin_lock_irqsave(&rtc_lock, flags); | ||
116 | |||
117 | vrtc_cmos_write(yrs, RTC_YEAR); | ||
118 | vrtc_cmos_write(mon, RTC_MONTH); | ||
119 | vrtc_cmos_write(day, RTC_DAY_OF_MONTH); | ||
120 | vrtc_cmos_write(hrs, RTC_HOURS); | ||
121 | vrtc_cmos_write(min, RTC_MINUTES); | ||
122 | vrtc_cmos_write(sec, RTC_SECONDS); | ||
123 | |||
124 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
125 | |||
126 | ret = intel_scu_ipc_simple_command(IPCMSG_VRTC, IPC_CMD_VRTC_SETTIME); | ||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | static int mrst_read_alarm(struct device *dev, struct rtc_wkalrm *t) | ||
131 | { | ||
132 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
133 | unsigned char rtc_control; | ||
134 | |||
135 | if (mrst->irq <= 0) | ||
136 | return -EIO; | ||
137 | |||
138 | /* Basic alarms only support hour, minute, and seconds fields. | ||
139 | * Some also support day and month, for alarms up to a year in | ||
140 | * the future. | ||
141 | */ | ||
142 | t->time.tm_mday = -1; | ||
143 | t->time.tm_mon = -1; | ||
144 | t->time.tm_year = -1; | ||
145 | |||
146 | /* vRTC only supports binary mode */ | ||
147 | spin_lock_irq(&rtc_lock); | ||
148 | t->time.tm_sec = vrtc_cmos_read(RTC_SECONDS_ALARM); | ||
149 | t->time.tm_min = vrtc_cmos_read(RTC_MINUTES_ALARM); | ||
150 | t->time.tm_hour = vrtc_cmos_read(RTC_HOURS_ALARM); | ||
151 | |||
152 | rtc_control = vrtc_cmos_read(RTC_CONTROL); | ||
153 | spin_unlock_irq(&rtc_lock); | ||
154 | |||
155 | t->enabled = !!(rtc_control & RTC_AIE); | ||
156 | t->pending = 0; | ||
157 | |||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | static void mrst_checkintr(struct mrst_rtc *mrst, unsigned char rtc_control) | ||
162 | { | ||
163 | unsigned char rtc_intr; | ||
164 | |||
165 | /* | ||
166 | * NOTE after changing RTC_xIE bits we always read INTR_FLAGS; | ||
167 | * allegedly some older rtcs need that to handle irqs properly | ||
168 | */ | ||
169 | rtc_intr = vrtc_cmos_read(RTC_INTR_FLAGS); | ||
170 | rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; | ||
171 | if (is_intr(rtc_intr)) | ||
172 | rtc_update_irq(mrst->rtc, 1, rtc_intr); | ||
173 | } | ||
174 | |||
175 | static void mrst_irq_enable(struct mrst_rtc *mrst, unsigned char mask) | ||
176 | { | ||
177 | unsigned char rtc_control; | ||
178 | |||
179 | /* | ||
180 | * Flush any pending IRQ status, notably for update irqs, | ||
181 | * before we enable new IRQs | ||
182 | */ | ||
183 | rtc_control = vrtc_cmos_read(RTC_CONTROL); | ||
184 | mrst_checkintr(mrst, rtc_control); | ||
185 | |||
186 | rtc_control |= mask; | ||
187 | vrtc_cmos_write(rtc_control, RTC_CONTROL); | ||
188 | |||
189 | mrst_checkintr(mrst, rtc_control); | ||
190 | } | ||
191 | |||
192 | static void mrst_irq_disable(struct mrst_rtc *mrst, unsigned char mask) | ||
193 | { | ||
194 | unsigned char rtc_control; | ||
195 | |||
196 | rtc_control = vrtc_cmos_read(RTC_CONTROL); | ||
197 | rtc_control &= ~mask; | ||
198 | vrtc_cmos_write(rtc_control, RTC_CONTROL); | ||
199 | mrst_checkintr(mrst, rtc_control); | ||
200 | } | ||
201 | |||
202 | static int mrst_set_alarm(struct device *dev, struct rtc_wkalrm *t) | ||
203 | { | ||
204 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
205 | unsigned char hrs, min, sec; | ||
206 | int ret = 0; | ||
207 | |||
208 | if (!mrst->irq) | ||
209 | return -EIO; | ||
210 | |||
211 | hrs = t->time.tm_hour; | ||
212 | min = t->time.tm_min; | ||
213 | sec = t->time.tm_sec; | ||
214 | |||
215 | spin_lock_irq(&rtc_lock); | ||
216 | /* Next rtc irq must not be from previous alarm setting */ | ||
217 | mrst_irq_disable(mrst, RTC_AIE); | ||
218 | |||
219 | /* Update alarm */ | ||
220 | vrtc_cmos_write(hrs, RTC_HOURS_ALARM); | ||
221 | vrtc_cmos_write(min, RTC_MINUTES_ALARM); | ||
222 | vrtc_cmos_write(sec, RTC_SECONDS_ALARM); | ||
223 | |||
224 | spin_unlock_irq(&rtc_lock); | ||
225 | |||
226 | ret = intel_scu_ipc_simple_command(IPCMSG_VRTC, IPC_CMD_VRTC_SETALARM); | ||
227 | if (ret) | ||
228 | return ret; | ||
229 | |||
230 | spin_lock_irq(&rtc_lock); | ||
231 | if (t->enabled) | ||
232 | mrst_irq_enable(mrst, RTC_AIE); | ||
233 | |||
234 | spin_unlock_irq(&rtc_lock); | ||
235 | |||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static int mrst_irq_set_state(struct device *dev, int enabled) | ||
240 | { | ||
241 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
242 | unsigned long flags; | ||
243 | |||
244 | if (!mrst->irq) | ||
245 | return -ENXIO; | ||
246 | |||
247 | spin_lock_irqsave(&rtc_lock, flags); | ||
248 | |||
249 | if (enabled) | ||
250 | mrst_irq_enable(mrst, RTC_PIE); | ||
251 | else | ||
252 | mrst_irq_disable(mrst, RTC_PIE); | ||
253 | |||
254 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | #if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE) | ||
259 | |||
260 | /* Currently, the vRTC doesn't support UIE ON/OFF */ | ||
261 | static int | ||
262 | mrst_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | ||
263 | { | ||
264 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
265 | unsigned long flags; | ||
266 | |||
267 | switch (cmd) { | ||
268 | case RTC_AIE_OFF: | ||
269 | case RTC_AIE_ON: | ||
270 | if (!mrst->irq) | ||
271 | return -EINVAL; | ||
272 | break; | ||
273 | default: | ||
274 | /* PIE ON/OFF is handled by mrst_irq_set_state() */ | ||
275 | return -ENOIOCTLCMD; | ||
276 | } | ||
277 | |||
278 | spin_lock_irqsave(&rtc_lock, flags); | ||
279 | switch (cmd) { | ||
280 | case RTC_AIE_OFF: /* alarm off */ | ||
281 | mrst_irq_disable(mrst, RTC_AIE); | ||
282 | break; | ||
283 | case RTC_AIE_ON: /* alarm on */ | ||
284 | mrst_irq_enable(mrst, RTC_AIE); | ||
285 | break; | ||
286 | } | ||
287 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | #else | ||
292 | #define mrst_rtc_ioctl NULL | ||
293 | #endif | ||
294 | |||
295 | #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) | ||
296 | |||
297 | static int mrst_procfs(struct device *dev, struct seq_file *seq) | ||
298 | { | ||
299 | unsigned char rtc_control, valid; | ||
300 | |||
301 | spin_lock_irq(&rtc_lock); | ||
302 | rtc_control = vrtc_cmos_read(RTC_CONTROL); | ||
303 | valid = vrtc_cmos_read(RTC_VALID); | ||
304 | spin_unlock_irq(&rtc_lock); | ||
305 | |||
306 | return seq_printf(seq, | ||
307 | "periodic_IRQ\t: %s\n" | ||
308 | "alarm\t\t: %s\n" | ||
309 | "BCD\t\t: no\n" | ||
310 | "periodic_freq\t: daily (not adjustable)\n", | ||
311 | (rtc_control & RTC_PIE) ? "on" : "off", | ||
312 | (rtc_control & RTC_AIE) ? "on" : "off"); | ||
313 | } | ||
314 | |||
315 | #else | ||
316 | #define mrst_procfs NULL | ||
317 | #endif | ||
318 | |||
319 | static const struct rtc_class_ops mrst_rtc_ops = { | ||
320 | .ioctl = mrst_rtc_ioctl, | ||
321 | .read_time = mrst_read_time, | ||
322 | .set_time = mrst_set_time, | ||
323 | .read_alarm = mrst_read_alarm, | ||
324 | .set_alarm = mrst_set_alarm, | ||
325 | .proc = mrst_procfs, | ||
326 | .irq_set_state = mrst_irq_set_state, | ||
327 | }; | ||
328 | |||
329 | static struct mrst_rtc mrst_rtc; | ||
330 | |||
331 | /* | ||
332 | * When vRTC IRQ is captured by SCU FW, FW will clear the AIE bit in | ||
333 | * Reg B, so no need for this driver to clear it | ||
334 | */ | ||
335 | static irqreturn_t mrst_rtc_irq(int irq, void *p) | ||
336 | { | ||
337 | u8 irqstat; | ||
338 | |||
339 | spin_lock(&rtc_lock); | ||
340 | /* This read will clear all IRQ flags inside Reg C */ | ||
341 | irqstat = vrtc_cmos_read(RTC_INTR_FLAGS); | ||
342 | spin_unlock(&rtc_lock); | ||
343 | |||
344 | irqstat &= RTC_IRQMASK | RTC_IRQF; | ||
345 | if (is_intr(irqstat)) { | ||
346 | rtc_update_irq(p, 1, irqstat); | ||
347 | return IRQ_HANDLED; | ||
348 | } | ||
349 | return IRQ_NONE; | ||
350 | } | ||
351 | |||
352 | static int __init | ||
353 | vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, int rtc_irq) | ||
354 | { | ||
355 | int retval = 0; | ||
356 | unsigned char rtc_control; | ||
357 | |||
358 | /* There can be only one ... */ | ||
359 | if (mrst_rtc.dev) | ||
360 | return -EBUSY; | ||
361 | |||
362 | if (!iomem) | ||
363 | return -ENODEV; | ||
364 | |||
365 | iomem = request_mem_region(iomem->start, | ||
366 | iomem->end + 1 - iomem->start, | ||
367 | driver_name); | ||
368 | if (!iomem) { | ||
369 | dev_dbg(dev, "i/o mem already in use.\n"); | ||
370 | return -EBUSY; | ||
371 | } | ||
372 | |||
373 | mrst_rtc.irq = rtc_irq; | ||
374 | mrst_rtc.iomem = iomem; | ||
375 | |||
376 | mrst_rtc.rtc = rtc_device_register(driver_name, dev, | ||
377 | &mrst_rtc_ops, THIS_MODULE); | ||
378 | if (IS_ERR(mrst_rtc.rtc)) { | ||
379 | retval = PTR_ERR(mrst_rtc.rtc); | ||
380 | goto cleanup0; | ||
381 | } | ||
382 | |||
383 | mrst_rtc.dev = dev; | ||
384 | dev_set_drvdata(dev, &mrst_rtc); | ||
385 | rename_region(iomem, dev_name(&mrst_rtc.rtc->dev)); | ||
386 | |||
387 | spin_lock_irq(&rtc_lock); | ||
388 | mrst_irq_disable(&mrst_rtc, RTC_PIE | RTC_AIE); | ||
389 | rtc_control = vrtc_cmos_read(RTC_CONTROL); | ||
390 | spin_unlock_irq(&rtc_lock); | ||
391 | |||
392 | if (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY))) | ||
393 | dev_dbg(dev, "TODO: support more than 24-hr BCD mode\n"); | ||
394 | |||
395 | if (rtc_irq) { | ||
396 | retval = request_irq(rtc_irq, mrst_rtc_irq, | ||
397 | IRQF_DISABLED, dev_name(&mrst_rtc.rtc->dev), | ||
398 | mrst_rtc.rtc); | ||
399 | if (retval < 0) { | ||
400 | dev_dbg(dev, "IRQ %d is already in use, err %d\n", | ||
401 | rtc_irq, retval); | ||
402 | goto cleanup1; | ||
403 | } | ||
404 | } | ||
405 | dev_dbg(dev, "initialised\n"); | ||
406 | return 0; | ||
407 | |||
408 | cleanup1: | ||
409 | mrst_rtc.dev = NULL; | ||
410 | rtc_device_unregister(mrst_rtc.rtc); | ||
411 | cleanup0: | ||
412 | release_region(iomem->start, iomem->end + 1 - iomem->start); | ||
413 | dev_err(dev, "rtc-mrst: unable to initialise\n"); | ||
414 | return retval; | ||
415 | } | ||
416 | |||
417 | static void rtc_mrst_do_shutdown(void) | ||
418 | { | ||
419 | spin_lock_irq(&rtc_lock); | ||
420 | mrst_irq_disable(&mrst_rtc, RTC_IRQMASK); | ||
421 | spin_unlock_irq(&rtc_lock); | ||
422 | } | ||
423 | |||
424 | static void __exit rtc_mrst_do_remove(struct device *dev) | ||
425 | { | ||
426 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
427 | struct resource *iomem; | ||
428 | |||
429 | rtc_mrst_do_shutdown(); | ||
430 | |||
431 | if (mrst->irq) | ||
432 | free_irq(mrst->irq, mrst->rtc); | ||
433 | |||
434 | rtc_device_unregister(mrst->rtc); | ||
435 | mrst->rtc = NULL; | ||
436 | |||
437 | iomem = mrst->iomem; | ||
438 | release_region(iomem->start, iomem->end + 1 - iomem->start); | ||
439 | mrst->iomem = NULL; | ||
440 | |||
441 | mrst->dev = NULL; | ||
442 | dev_set_drvdata(dev, NULL); | ||
443 | } | ||
444 | |||
445 | #ifdef CONFIG_PM | ||
446 | static int mrst_suspend(struct device *dev, pm_message_t mesg) | ||
447 | { | ||
448 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
449 | unsigned char tmp; | ||
450 | |||
451 | /* Only the alarm might be a wakeup event source */ | ||
452 | spin_lock_irq(&rtc_lock); | ||
453 | mrst->suspend_ctrl = tmp = vrtc_cmos_read(RTC_CONTROL); | ||
454 | if (tmp & (RTC_PIE | RTC_AIE)) { | ||
455 | unsigned char mask; | ||
456 | |||
457 | if (device_may_wakeup(dev)) | ||
458 | mask = RTC_IRQMASK & ~RTC_AIE; | ||
459 | else | ||
460 | mask = RTC_IRQMASK; | ||
461 | tmp &= ~mask; | ||
462 | vrtc_cmos_write(tmp, RTC_CONTROL); | ||
463 | |||
464 | mrst_checkintr(mrst, tmp); | ||
465 | } | ||
466 | spin_unlock_irq(&rtc_lock); | ||
467 | |||
468 | if (tmp & RTC_AIE) { | ||
469 | mrst->enabled_wake = 1; | ||
470 | enable_irq_wake(mrst->irq); | ||
471 | } | ||
472 | |||
473 | dev_dbg(&mrst_rtc.rtc->dev, "suspend%s, ctrl %02x\n", | ||
474 | (tmp & RTC_AIE) ? ", alarm may wake" : "", | ||
475 | tmp); | ||
476 | |||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | /* | ||
481 | * We want RTC alarms to wake us from the deep power saving state | ||
482 | */ | ||
483 | static inline int mrst_poweroff(struct device *dev) | ||
484 | { | ||
485 | return mrst_suspend(dev, PMSG_HIBERNATE); | ||
486 | } | ||
487 | |||
488 | static int mrst_resume(struct device *dev) | ||
489 | { | ||
490 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | ||
491 | unsigned char tmp = mrst->suspend_ctrl; | ||
492 | |||
493 | /* Re-enable any irqs previously active */ | ||
494 | if (tmp & RTC_IRQMASK) { | ||
495 | unsigned char mask; | ||
496 | |||
497 | if (mrst->enabled_wake) { | ||
498 | disable_irq_wake(mrst->irq); | ||
499 | mrst->enabled_wake = 0; | ||
500 | } | ||
501 | |||
502 | spin_lock_irq(&rtc_lock); | ||
503 | do { | ||
504 | vrtc_cmos_write(tmp, RTC_CONTROL); | ||
505 | |||
506 | mask = vrtc_cmos_read(RTC_INTR_FLAGS); | ||
507 | mask &= (tmp & RTC_IRQMASK) | RTC_IRQF; | ||
508 | if (!is_intr(mask)) | ||
509 | break; | ||
510 | |||
511 | rtc_update_irq(mrst->rtc, 1, mask); | ||
512 | tmp &= ~RTC_AIE; | ||
513 | } while (mask & RTC_AIE); | ||
514 | spin_unlock_irq(&rtc_lock); | ||
515 | } | ||
516 | |||
517 | dev_dbg(&mrst_rtc.rtc->dev, "resume, ctrl %02x\n", tmp); | ||
518 | |||
519 | return 0; | ||
520 | } | ||
521 | |||
522 | #else | ||
523 | #define mrst_suspend NULL | ||
524 | #define mrst_resume NULL | ||
525 | |||
526 | static inline int mrst_poweroff(struct device *dev) | ||
527 | { | ||
528 | return -ENOSYS; | ||
529 | } | ||
530 | |||
531 | #endif | ||
532 | |||
533 | static int __init vrtc_mrst_platform_probe(struct platform_device *pdev) | ||
534 | { | ||
535 | return vrtc_mrst_do_probe(&pdev->dev, | ||
536 | platform_get_resource(pdev, IORESOURCE_MEM, 0), | ||
537 | platform_get_irq(pdev, 0)); | ||
538 | } | ||
539 | |||
540 | static int __exit vrtc_mrst_platform_remove(struct platform_device *pdev) | ||
541 | { | ||
542 | rtc_mrst_do_remove(&pdev->dev); | ||
543 | return 0; | ||
544 | } | ||
545 | |||
546 | static void vrtc_mrst_platform_shutdown(struct platform_device *pdev) | ||
547 | { | ||
548 | if (system_state == SYSTEM_POWER_OFF && !mrst_poweroff(&pdev->dev)) | ||
549 | return; | ||
550 | |||
551 | rtc_mrst_do_shutdown(); | ||
552 | } | ||
553 | |||
554 | MODULE_ALIAS("platform:vrtc_mrst"); | ||
555 | |||
556 | static struct platform_driver vrtc_mrst_platform_driver = { | ||
557 | .probe = vrtc_mrst_platform_probe, | ||
558 | .remove = __exit_p(vrtc_mrst_platform_remove), | ||
559 | .shutdown = vrtc_mrst_platform_shutdown, | ||
560 | .driver = { | ||
561 | .name = (char *) driver_name, | ||
562 | .suspend = mrst_suspend, | ||
563 | .resume = mrst_resume, | ||
564 | } | ||
565 | }; | ||
566 | |||
567 | static int __init vrtc_mrst_init(void) | ||
568 | { | ||
569 | return platform_driver_register(&vrtc_mrst_platform_driver); | ||
570 | } | ||
571 | |||
572 | static void __exit vrtc_mrst_exit(void) | ||
573 | { | ||
574 | platform_driver_unregister(&vrtc_mrst_platform_driver); | ||
575 | } | ||
576 | |||
577 | module_init(vrtc_mrst_init); | ||
578 | module_exit(vrtc_mrst_exit); | ||
579 | |||
580 | MODULE_AUTHOR("Jacob Pan; Feng Tang"); | ||
581 | MODULE_DESCRIPTION("Driver for Moorestown virtual RTC"); | ||
582 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c index 1146e3522d3c..af32a62e12a8 100644 --- a/drivers/rtc/rtc-rx8025.c +++ b/drivers/rtc/rtc-rx8025.c | |||
@@ -650,7 +650,7 @@ static int __devexit rx8025_remove(struct i2c_client *client) | |||
650 | mutex_unlock(lock); | 650 | mutex_unlock(lock); |
651 | 651 | ||
652 | free_irq(client->irq, client); | 652 | free_irq(client->irq, client); |
653 | flush_scheduled_work(); | 653 | cancel_work_sync(&rx8025->work); |
654 | } | 654 | } |
655 | 655 | ||
656 | rx8025_sysfs_unregister(&client->dev); | 656 | rx8025_sysfs_unregister(&client->dev); |
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index e4a44b641702..88ea52b8647a 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c | |||
@@ -39,10 +39,10 @@ | |||
39 | #include <mach/regs-ost.h> | 39 | #include <mach/regs-ost.h> |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #define RTC_DEF_DIVIDER 32768 - 1 | 42 | #define RTC_DEF_DIVIDER (32768 - 1) |
43 | #define RTC_DEF_TRIM 0 | 43 | #define RTC_DEF_TRIM 0 |
44 | 44 | ||
45 | static unsigned long rtc_freq = 1024; | 45 | static const unsigned long RTC_FREQ = 1024; |
46 | static unsigned long timer_freq; | 46 | static unsigned long timer_freq; |
47 | static struct rtc_time rtc_alarm; | 47 | static struct rtc_time rtc_alarm; |
48 | static DEFINE_SPINLOCK(sa1100_rtc_lock); | 48 | static DEFINE_SPINLOCK(sa1100_rtc_lock); |
@@ -61,7 +61,8 @@ static inline int rtc_periodic_alarm(struct rtc_time *tm) | |||
61 | * Calculate the next alarm time given the requested alarm time mask | 61 | * Calculate the next alarm time given the requested alarm time mask |
62 | * and the current time. | 62 | * and the current time. |
63 | */ | 63 | */ |
64 | static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc_time *alrm) | 64 | static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, |
65 | struct rtc_time *alrm) | ||
65 | { | 66 | { |
66 | unsigned long next_time; | 67 | unsigned long next_time; |
67 | unsigned long now_time; | 68 | unsigned long now_time; |
@@ -116,7 +117,23 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) | |||
116 | rtsr = RTSR; | 117 | rtsr = RTSR; |
117 | /* clear interrupt sources */ | 118 | /* clear interrupt sources */ |
118 | RTSR = 0; | 119 | RTSR = 0; |
119 | RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2); | 120 | /* Fix for a nasty initialization problem the in SA11xx RTSR register. |
121 | * See also the comments in sa1100_rtc_probe(). */ | ||
122 | if (rtsr & (RTSR_ALE | RTSR_HZE)) { | ||
123 | /* This is the original code, before there was the if test | ||
124 | * above. This code does not clear interrupts that were not | ||
125 | * enabled. */ | ||
126 | RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2); | ||
127 | } else { | ||
128 | /* For some reason, it is possible to enter this routine | ||
129 | * without interruptions enabled, it has been tested with | ||
130 | * several units (Bug in SA11xx chip?). | ||
131 | * | ||
132 | * This situation leads to an infinite "loop" of interrupt | ||
133 | * routine calling and as a result the processor seems to | ||
134 | * lock on its first call to open(). */ | ||
135 | RTSR = RTSR_AL | RTSR_HZ; | ||
136 | } | ||
120 | 137 | ||
121 | /* clear alarm interrupt if it has occurred */ | 138 | /* clear alarm interrupt if it has occurred */ |
122 | if (rtsr & RTSR_AL) | 139 | if (rtsr & RTSR_AL) |
@@ -139,8 +156,58 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) | |||
139 | return IRQ_HANDLED; | 156 | return IRQ_HANDLED; |
140 | } | 157 | } |
141 | 158 | ||
159 | static int sa1100_irq_set_freq(struct device *dev, int freq) | ||
160 | { | ||
161 | if (freq < 1 || freq > timer_freq) { | ||
162 | return -EINVAL; | ||
163 | } else { | ||
164 | struct rtc_device *rtc = (struct rtc_device *)dev; | ||
165 | |||
166 | rtc->irq_freq = freq; | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | } | ||
171 | |||
142 | static int rtc_timer1_count; | 172 | static int rtc_timer1_count; |
143 | 173 | ||
174 | static int sa1100_irq_set_state(struct device *dev, int enabled) | ||
175 | { | ||
176 | spin_lock_irq(&sa1100_rtc_lock); | ||
177 | if (enabled) { | ||
178 | struct rtc_device *rtc = (struct rtc_device *)dev; | ||
179 | |||
180 | OSMR1 = timer_freq / rtc->irq_freq + OSCR; | ||
181 | OIER |= OIER_E1; | ||
182 | rtc_timer1_count = 1; | ||
183 | } else { | ||
184 | OIER &= ~OIER_E1; | ||
185 | } | ||
186 | spin_unlock_irq(&sa1100_rtc_lock); | ||
187 | |||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static inline int sa1100_timer1_retrigger(struct rtc_device *rtc) | ||
192 | { | ||
193 | unsigned long diff; | ||
194 | unsigned long period = timer_freq / rtc->irq_freq; | ||
195 | |||
196 | spin_lock_irq(&sa1100_rtc_lock); | ||
197 | |||
198 | do { | ||
199 | OSMR1 += period; | ||
200 | diff = OSMR1 - OSCR; | ||
201 | /* If OSCR > OSMR1, diff is a very large number (unsigned | ||
202 | * math). This means we have a lost interrupt. */ | ||
203 | } while (diff > period); | ||
204 | OIER |= OIER_E1; | ||
205 | |||
206 | spin_unlock_irq(&sa1100_rtc_lock); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
144 | static irqreturn_t timer1_interrupt(int irq, void *dev_id) | 211 | static irqreturn_t timer1_interrupt(int irq, void *dev_id) |
145 | { | 212 | { |
146 | struct platform_device *pdev = to_platform_device(dev_id); | 213 | struct platform_device *pdev = to_platform_device(dev_id); |
@@ -158,7 +225,11 @@ static irqreturn_t timer1_interrupt(int irq, void *dev_id) | |||
158 | rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); | 225 | rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); |
159 | 226 | ||
160 | if (rtc_timer1_count == 1) | 227 | if (rtc_timer1_count == 1) |
161 | rtc_timer1_count = (rtc_freq * ((1 << 30) / (timer_freq >> 2))); | 228 | rtc_timer1_count = |
229 | (rtc->irq_freq * ((1 << 30) / (timer_freq >> 2))); | ||
230 | |||
231 | /* retrigger. */ | ||
232 | sa1100_timer1_retrigger(rtc); | ||
162 | 233 | ||
163 | return IRQ_HANDLED; | 234 | return IRQ_HANDLED; |
164 | } | 235 | } |
@@ -166,8 +237,10 @@ static irqreturn_t timer1_interrupt(int irq, void *dev_id) | |||
166 | static int sa1100_rtc_read_callback(struct device *dev, int data) | 237 | static int sa1100_rtc_read_callback(struct device *dev, int data) |
167 | { | 238 | { |
168 | if (data & RTC_PF) { | 239 | if (data & RTC_PF) { |
240 | struct rtc_device *rtc = (struct rtc_device *)dev; | ||
241 | |||
169 | /* interpolate missed periods and set match for the next */ | 242 | /* interpolate missed periods and set match for the next */ |
170 | unsigned long period = timer_freq / rtc_freq; | 243 | unsigned long period = timer_freq / rtc->irq_freq; |
171 | unsigned long oscr = OSCR; | 244 | unsigned long oscr = OSCR; |
172 | unsigned long osmr1 = OSMR1; | 245 | unsigned long osmr1 = OSMR1; |
173 | unsigned long missed = (oscr - osmr1)/period; | 246 | unsigned long missed = (oscr - osmr1)/period; |
@@ -178,7 +251,7 @@ static int sa1100_rtc_read_callback(struct device *dev, int data) | |||
178 | * Here we compare (match - OSCR) 8 instead of 0 -- | 251 | * Here we compare (match - OSCR) 8 instead of 0 -- |
179 | * see comment in pxa_timer_interrupt() for explanation. | 252 | * see comment in pxa_timer_interrupt() for explanation. |
180 | */ | 253 | */ |
181 | while( (signed long)((osmr1 = OSMR1) - OSCR) <= 8 ) { | 254 | while ((signed long)((osmr1 = OSMR1) - OSCR) <= 8) { |
182 | data += 0x100; | 255 | data += 0x100; |
183 | OSSR = OSSR_M1; /* clear match on timer 1 */ | 256 | OSSR = OSSR_M1; /* clear match on timer 1 */ |
184 | OSMR1 = osmr1 + period; | 257 | OSMR1 = osmr1 + period; |
@@ -190,25 +263,29 @@ static int sa1100_rtc_read_callback(struct device *dev, int data) | |||
190 | static int sa1100_rtc_open(struct device *dev) | 263 | static int sa1100_rtc_open(struct device *dev) |
191 | { | 264 | { |
192 | int ret; | 265 | int ret; |
266 | struct rtc_device *rtc = (struct rtc_device *)dev; | ||
193 | 267 | ||
194 | ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED, | 268 | ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED, |
195 | "rtc 1Hz", dev); | 269 | "rtc 1Hz", dev); |
196 | if (ret) { | 270 | if (ret) { |
197 | dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz); | 271 | dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz); |
198 | goto fail_ui; | 272 | goto fail_ui; |
199 | } | 273 | } |
200 | ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, IRQF_DISABLED, | 274 | ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, IRQF_DISABLED, |
201 | "rtc Alrm", dev); | 275 | "rtc Alrm", dev); |
202 | if (ret) { | 276 | if (ret) { |
203 | dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm); | 277 | dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm); |
204 | goto fail_ai; | 278 | goto fail_ai; |
205 | } | 279 | } |
206 | ret = request_irq(IRQ_OST1, timer1_interrupt, IRQF_DISABLED, | 280 | ret = request_irq(IRQ_OST1, timer1_interrupt, IRQF_DISABLED, |
207 | "rtc timer", dev); | 281 | "rtc timer", dev); |
208 | if (ret) { | 282 | if (ret) { |
209 | dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1); | 283 | dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1); |
210 | goto fail_pi; | 284 | goto fail_pi; |
211 | } | 285 | } |
286 | rtc->max_user_freq = RTC_FREQ; | ||
287 | sa1100_irq_set_freq(dev, RTC_FREQ); | ||
288 | |||
212 | return 0; | 289 | return 0; |
213 | 290 | ||
214 | fail_pi: | 291 | fail_pi: |
@@ -236,7 +313,7 @@ static void sa1100_rtc_release(struct device *dev) | |||
236 | static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, | 313 | static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, |
237 | unsigned long arg) | 314 | unsigned long arg) |
238 | { | 315 | { |
239 | switch(cmd) { | 316 | switch (cmd) { |
240 | case RTC_AIE_OFF: | 317 | case RTC_AIE_OFF: |
241 | spin_lock_irq(&sa1100_rtc_lock); | 318 | spin_lock_irq(&sa1100_rtc_lock); |
242 | RTSR &= ~RTSR_ALE; | 319 | RTSR &= ~RTSR_ALE; |
@@ -257,25 +334,6 @@ static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, | |||
257 | RTSR |= RTSR_HZE; | 334 | RTSR |= RTSR_HZE; |
258 | spin_unlock_irq(&sa1100_rtc_lock); | 335 | spin_unlock_irq(&sa1100_rtc_lock); |
259 | return 0; | 336 | return 0; |
260 | case RTC_PIE_OFF: | ||
261 | spin_lock_irq(&sa1100_rtc_lock); | ||
262 | OIER &= ~OIER_E1; | ||
263 | spin_unlock_irq(&sa1100_rtc_lock); | ||
264 | return 0; | ||
265 | case RTC_PIE_ON: | ||
266 | spin_lock_irq(&sa1100_rtc_lock); | ||
267 | OSMR1 = timer_freq / rtc_freq + OSCR; | ||
268 | OIER |= OIER_E1; | ||
269 | rtc_timer1_count = 1; | ||
270 | spin_unlock_irq(&sa1100_rtc_lock); | ||
271 | return 0; | ||
272 | case RTC_IRQP_READ: | ||
273 | return put_user(rtc_freq, (unsigned long *)arg); | ||
274 | case RTC_IRQP_SET: | ||
275 | if (arg < 1 || arg > timer_freq) | ||
276 | return -EINVAL; | ||
277 | rtc_freq = arg; | ||
278 | return 0; | ||
279 | } | 337 | } |
280 | return -ENOIOCTLCMD; | 338 | return -ENOIOCTLCMD; |
281 | } | 339 | } |
@@ -327,12 +385,15 @@ static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
327 | 385 | ||
328 | static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) | 386 | static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) |
329 | { | 387 | { |
388 | struct rtc_device *rtc = (struct rtc_device *)dev; | ||
389 | |||
330 | seq_printf(seq, "trim/divider\t: 0x%08x\n", (u32) RTTR); | 390 | seq_printf(seq, "trim/divider\t: 0x%08x\n", (u32) RTTR); |
331 | seq_printf(seq, "update_IRQ\t: %s\n", | 391 | seq_printf(seq, "update_IRQ\t: %s\n", |
332 | (RTSR & RTSR_HZE) ? "yes" : "no"); | 392 | (RTSR & RTSR_HZE) ? "yes" : "no"); |
333 | seq_printf(seq, "periodic_IRQ\t: %s\n", | 393 | seq_printf(seq, "periodic_IRQ\t: %s\n", |
334 | (OIER & OIER_E1) ? "yes" : "no"); | 394 | (OIER & OIER_E1) ? "yes" : "no"); |
335 | seq_printf(seq, "periodic_freq\t: %ld\n", rtc_freq); | 395 | seq_printf(seq, "periodic_freq\t: %d\n", rtc->irq_freq); |
396 | seq_printf(seq, "RTSR\t\t: 0x%08x\n", (u32)RTSR); | ||
336 | 397 | ||
337 | return 0; | 398 | return 0; |
338 | } | 399 | } |
@@ -347,6 +408,8 @@ static const struct rtc_class_ops sa1100_rtc_ops = { | |||
347 | .read_alarm = sa1100_rtc_read_alarm, | 408 | .read_alarm = sa1100_rtc_read_alarm, |
348 | .set_alarm = sa1100_rtc_set_alarm, | 409 | .set_alarm = sa1100_rtc_set_alarm, |
349 | .proc = sa1100_rtc_proc, | 410 | .proc = sa1100_rtc_proc, |
411 | .irq_set_freq = sa1100_irq_set_freq, | ||
412 | .irq_set_state = sa1100_irq_set_state, | ||
350 | }; | 413 | }; |
351 | 414 | ||
352 | static int sa1100_rtc_probe(struct platform_device *pdev) | 415 | static int sa1100_rtc_probe(struct platform_device *pdev) |
@@ -364,7 +427,8 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
364 | */ | 427 | */ |
365 | if (RTTR == 0) { | 428 | if (RTTR == 0) { |
366 | RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); | 429 | RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); |
367 | dev_warn(&pdev->dev, "warning: initializing default clock divider/trim value\n"); | 430 | dev_warn(&pdev->dev, "warning: " |
431 | "initializing default clock divider/trim value\n"); | ||
368 | /* The current RTC value probably doesn't make sense either */ | 432 | /* The current RTC value probably doesn't make sense either */ |
369 | RCNR = 0; | 433 | RCNR = 0; |
370 | } | 434 | } |
@@ -372,13 +436,42 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
372 | device_init_wakeup(&pdev->dev, 1); | 436 | device_init_wakeup(&pdev->dev, 1); |
373 | 437 | ||
374 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, | 438 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, |
375 | THIS_MODULE); | 439 | THIS_MODULE); |
376 | 440 | ||
377 | if (IS_ERR(rtc)) | 441 | if (IS_ERR(rtc)) |
378 | return PTR_ERR(rtc); | 442 | return PTR_ERR(rtc); |
379 | 443 | ||
380 | platform_set_drvdata(pdev, rtc); | 444 | platform_set_drvdata(pdev, rtc); |
381 | 445 | ||
446 | /* Set the irq_freq */ | ||
447 | /*TODO: Find out who is messing with this value after we initialize | ||
448 | * it here.*/ | ||
449 | rtc->irq_freq = RTC_FREQ; | ||
450 | |||
451 | /* Fix for a nasty initialization problem the in SA11xx RTSR register. | ||
452 | * See also the comments in sa1100_rtc_interrupt(). | ||
453 | * | ||
454 | * Sometimes bit 1 of the RTSR (RTSR_HZ) will wake up 1, which means an | ||
455 | * interrupt pending, even though interrupts were never enabled. | ||
456 | * In this case, this bit it must be reset before enabling | ||
457 | * interruptions to avoid a nonexistent interrupt to occur. | ||
458 | * | ||
459 | * In principle, the same problem would apply to bit 0, although it has | ||
460 | * never been observed to happen. | ||
461 | * | ||
462 | * This issue is addressed both here and in sa1100_rtc_interrupt(). | ||
463 | * If the issue is not addressed here, in the times when the processor | ||
464 | * wakes up with the bit set there will be one spurious interrupt. | ||
465 | * | ||
466 | * The issue is also dealt with in sa1100_rtc_interrupt() to be on the | ||
467 | * safe side, once the condition that lead to this strange | ||
468 | * initialization is unknown and could in principle happen during | ||
469 | * normal processing. | ||
470 | * | ||
471 | * Notice that clearing bit 1 and 0 is accomplished by writting ONES to | ||
472 | * the corresponding bits in RTSR. */ | ||
473 | RTSR = RTSR_AL | RTSR_HZ; | ||
474 | |||
382 | return 0; | 475 | return 0; |
383 | } | 476 | } |
384 | 477 | ||
@@ -386,7 +479,7 @@ static int sa1100_rtc_remove(struct platform_device *pdev) | |||
386 | { | 479 | { |
387 | struct rtc_device *rtc = platform_get_drvdata(pdev); | 480 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
388 | 481 | ||
389 | if (rtc) | 482 | if (rtc) |
390 | rtc_device_unregister(rtc); | 483 | rtc_device_unregister(rtc); |
391 | 484 | ||
392 | return 0; | 485 | return 0; |