diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 6 | ||||
-rw-r--r-- | drivers/rtc/interface.c | 54 | ||||
-rw-r--r-- | drivers/rtc/rtc-at91sam9.c | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-dev.c | 51 | ||||
-rw-r--r-- | drivers/rtc/rtc-isl1208.c | 7 | ||||
-rw-r--r-- | drivers/rtc/rtc-s3c.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-sa1100.c | 12 |
7 files changed, 110 insertions, 23 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 123092d8a984..165a81843357 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -102,9 +102,13 @@ config RTC_INTF_DEV_UIE_EMUL | |||
102 | depends on RTC_INTF_DEV | 102 | depends on RTC_INTF_DEV |
103 | help | 103 | help |
104 | Provides an emulation for RTC_UIE if the underlying rtc chip | 104 | Provides an emulation for RTC_UIE if the underlying rtc chip |
105 | driver does not expose RTC_UIE ioctls. Those requests generate | 105 | driver does not expose RTC_UIE ioctls. Those requests generate |
106 | once-per-second update interrupts, used for synchronization. | 106 | once-per-second update interrupts, used for synchronization. |
107 | 107 | ||
108 | The emulation code will read the time from the hardware | ||
109 | clock several times per second, please enable this option | ||
110 | only if you know that you really need it. | ||
111 | |||
108 | config RTC_DRV_TEST | 112 | config RTC_DRV_TEST |
109 | tristate "Test driver/device" | 113 | tristate "Test driver/device" |
110 | help | 114 | help |
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index a04c1b6b1575..fd2c652504ff 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
@@ -307,6 +307,60 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
307 | } | 307 | } |
308 | EXPORT_SYMBOL_GPL(rtc_set_alarm); | 308 | EXPORT_SYMBOL_GPL(rtc_set_alarm); |
309 | 309 | ||
310 | int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) | ||
311 | { | ||
312 | int err = mutex_lock_interruptible(&rtc->ops_lock); | ||
313 | if (err) | ||
314 | return err; | ||
315 | |||
316 | if (!rtc->ops) | ||
317 | err = -ENODEV; | ||
318 | else if (!rtc->ops->alarm_irq_enable) | ||
319 | err = -EINVAL; | ||
320 | else | ||
321 | err = rtc->ops->alarm_irq_enable(rtc->dev.parent, enabled); | ||
322 | |||
323 | mutex_unlock(&rtc->ops_lock); | ||
324 | return err; | ||
325 | } | ||
326 | EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); | ||
327 | |||
328 | int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) | ||
329 | { | ||
330 | int err = mutex_lock_interruptible(&rtc->ops_lock); | ||
331 | if (err) | ||
332 | return err; | ||
333 | |||
334 | #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL | ||
335 | if (enabled == 0 && rtc->uie_irq_active) { | ||
336 | mutex_unlock(&rtc->ops_lock); | ||
337 | return rtc_dev_update_irq_enable_emul(rtc, enabled); | ||
338 | } | ||
339 | #endif | ||
340 | |||
341 | if (!rtc->ops) | ||
342 | err = -ENODEV; | ||
343 | else if (!rtc->ops->update_irq_enable) | ||
344 | err = -EINVAL; | ||
345 | else | ||
346 | err = rtc->ops->update_irq_enable(rtc->dev.parent, enabled); | ||
347 | |||
348 | mutex_unlock(&rtc->ops_lock); | ||
349 | |||
350 | #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL | ||
351 | /* | ||
352 | * Enable emulation if the driver did not provide | ||
353 | * the update_irq_enable function pointer or if returned | ||
354 | * -EINVAL to signal that it has been configured without | ||
355 | * interrupts or that are not available at the moment. | ||
356 | */ | ||
357 | if (err == -EINVAL) | ||
358 | err = rtc_dev_update_irq_enable_emul(rtc, enabled); | ||
359 | #endif | ||
360 | return err; | ||
361 | } | ||
362 | EXPORT_SYMBOL_GPL(rtc_update_irq_enable); | ||
363 | |||
310 | /** | 364 | /** |
311 | * rtc_update_irq - report RTC periodic, alarm, and/or update irqs | 365 | * rtc_update_irq - report RTC periodic, alarm, and/or update irqs |
312 | * @rtc: the rtc device | 366 | * @rtc: the rtc device |
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 2133f37906f2..d5e4e637ddec 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <mach/board.h> | 22 | #include <mach/board.h> |
23 | #include <mach/at91_rtt.h> | 23 | #include <mach/at91_rtt.h> |
24 | #include <mach/cpu.h> | ||
24 | 25 | ||
25 | 26 | ||
26 | /* | 27 | /* |
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index ecdea44ae4e5..45152f4952d6 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c | |||
@@ -92,10 +92,10 @@ static void rtc_uie_timer(unsigned long data) | |||
92 | spin_unlock_irqrestore(&rtc->irq_lock, flags); | 92 | spin_unlock_irqrestore(&rtc->irq_lock, flags); |
93 | } | 93 | } |
94 | 94 | ||
95 | static void clear_uie(struct rtc_device *rtc) | 95 | static int clear_uie(struct rtc_device *rtc) |
96 | { | 96 | { |
97 | spin_lock_irq(&rtc->irq_lock); | 97 | spin_lock_irq(&rtc->irq_lock); |
98 | if (rtc->irq_active) { | 98 | if (rtc->uie_irq_active) { |
99 | rtc->stop_uie_polling = 1; | 99 | rtc->stop_uie_polling = 1; |
100 | if (rtc->uie_timer_active) { | 100 | if (rtc->uie_timer_active) { |
101 | spin_unlock_irq(&rtc->irq_lock); | 101 | spin_unlock_irq(&rtc->irq_lock); |
@@ -108,9 +108,10 @@ static void clear_uie(struct rtc_device *rtc) | |||
108 | flush_scheduled_work(); | 108 | flush_scheduled_work(); |
109 | spin_lock_irq(&rtc->irq_lock); | 109 | spin_lock_irq(&rtc->irq_lock); |
110 | } | 110 | } |
111 | rtc->irq_active = 0; | 111 | rtc->uie_irq_active = 0; |
112 | } | 112 | } |
113 | spin_unlock_irq(&rtc->irq_lock); | 113 | spin_unlock_irq(&rtc->irq_lock); |
114 | return 0; | ||
114 | } | 115 | } |
115 | 116 | ||
116 | static int set_uie(struct rtc_device *rtc) | 117 | static int set_uie(struct rtc_device *rtc) |
@@ -122,8 +123,8 @@ static int set_uie(struct rtc_device *rtc) | |||
122 | if (err) | 123 | if (err) |
123 | return err; | 124 | return err; |
124 | spin_lock_irq(&rtc->irq_lock); | 125 | spin_lock_irq(&rtc->irq_lock); |
125 | if (!rtc->irq_active) { | 126 | if (!rtc->uie_irq_active) { |
126 | rtc->irq_active = 1; | 127 | rtc->uie_irq_active = 1; |
127 | rtc->stop_uie_polling = 0; | 128 | rtc->stop_uie_polling = 0; |
128 | rtc->oldsecs = tm.tm_sec; | 129 | rtc->oldsecs = tm.tm_sec; |
129 | rtc->uie_task_active = 1; | 130 | rtc->uie_task_active = 1; |
@@ -134,6 +135,16 @@ static int set_uie(struct rtc_device *rtc) | |||
134 | spin_unlock_irq(&rtc->irq_lock); | 135 | spin_unlock_irq(&rtc->irq_lock); |
135 | return 0; | 136 | return 0; |
136 | } | 137 | } |
138 | |||
139 | int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc, unsigned int enabled) | ||
140 | { | ||
141 | if (enabled) | ||
142 | return set_uie(rtc); | ||
143 | else | ||
144 | return clear_uie(rtc); | ||
145 | } | ||
146 | EXPORT_SYMBOL(rtc_dev_update_irq_enable_emul); | ||
147 | |||
137 | #endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */ | 148 | #endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */ |
138 | 149 | ||
139 | static ssize_t | 150 | static ssize_t |
@@ -357,6 +368,22 @@ static long rtc_dev_ioctl(struct file *file, | |||
357 | err = rtc_irq_set_state(rtc, NULL, 0); | 368 | err = rtc_irq_set_state(rtc, NULL, 0); |
358 | break; | 369 | break; |
359 | 370 | ||
371 | case RTC_AIE_ON: | ||
372 | mutex_unlock(&rtc->ops_lock); | ||
373 | return rtc_alarm_irq_enable(rtc, 1); | ||
374 | |||
375 | case RTC_AIE_OFF: | ||
376 | mutex_unlock(&rtc->ops_lock); | ||
377 | return rtc_alarm_irq_enable(rtc, 0); | ||
378 | |||
379 | case RTC_UIE_ON: | ||
380 | mutex_unlock(&rtc->ops_lock); | ||
381 | return rtc_update_irq_enable(rtc, 1); | ||
382 | |||
383 | case RTC_UIE_OFF: | ||
384 | mutex_unlock(&rtc->ops_lock); | ||
385 | return rtc_update_irq_enable(rtc, 0); | ||
386 | |||
360 | case RTC_IRQP_SET: | 387 | case RTC_IRQP_SET: |
361 | err = rtc_irq_set_freq(rtc, NULL, arg); | 388 | err = rtc_irq_set_freq(rtc, NULL, arg); |
362 | break; | 389 | break; |
@@ -401,17 +428,6 @@ static long rtc_dev_ioctl(struct file *file, | |||
401 | err = -EFAULT; | 428 | err = -EFAULT; |
402 | return err; | 429 | return err; |
403 | 430 | ||
404 | #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL | ||
405 | case RTC_UIE_OFF: | ||
406 | mutex_unlock(&rtc->ops_lock); | ||
407 | clear_uie(rtc); | ||
408 | return 0; | ||
409 | |||
410 | case RTC_UIE_ON: | ||
411 | mutex_unlock(&rtc->ops_lock); | ||
412 | err = set_uie(rtc); | ||
413 | return err; | ||
414 | #endif | ||
415 | default: | 431 | default: |
416 | err = -ENOTTY; | 432 | err = -ENOTTY; |
417 | break; | 433 | break; |
@@ -440,7 +456,10 @@ static int rtc_dev_release(struct inode *inode, struct file *file) | |||
440 | * Leave the alarm alone; it may be set to trigger a system wakeup | 456 | * Leave the alarm alone; it may be set to trigger a system wakeup |
441 | * later, or be used by kernel code, and is a one-shot event anyway. | 457 | * later, or be used by kernel code, and is a one-shot event anyway. |
442 | */ | 458 | */ |
459 | |||
460 | /* Keep ioctl until all drivers are converted */ | ||
443 | rtc_dev_ioctl(file, RTC_UIE_OFF, 0); | 461 | rtc_dev_ioctl(file, RTC_UIE_OFF, 0); |
462 | rtc_update_irq_enable(rtc, 0); | ||
444 | rtc_irq_set_state(rtc, NULL, 0); | 463 | rtc_irq_set_state(rtc, NULL, 0); |
445 | 464 | ||
446 | if (rtc->ops->release) | 465 | if (rtc->ops->release) |
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c index 2cd77ab8fc66..054e05294af8 100644 --- a/drivers/rtc/rtc-isl1208.c +++ b/drivers/rtc/rtc-isl1208.c | |||
@@ -328,6 +328,13 @@ isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) | |||
328 | int sr; | 328 | int sr; |
329 | u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; | 329 | u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; |
330 | 330 | ||
331 | /* The clock has an 8 bit wide bcd-coded register (they never learn) | ||
332 | * for the year. tm_year is an offset from 1900 and we are interested | ||
333 | * in the 2000-2099 range, so any value less than 100 is invalid. | ||
334 | */ | ||
335 | if (tm->tm_year < 100) | ||
336 | return -EINVAL; | ||
337 | |||
331 | regs[ISL1208_REG_SC] = bin2bcd(tm->tm_sec); | 338 | regs[ISL1208_REG_SC] = bin2bcd(tm->tm_sec); |
332 | regs[ISL1208_REG_MN] = bin2bcd(tm->tm_min); | 339 | regs[ISL1208_REG_MN] = bin2bcd(tm->tm_min); |
333 | regs[ISL1208_REG_HR] = bin2bcd(tm->tm_hour) | ISL1208_REG_HR_MIL; | 340 | regs[ISL1208_REG_HR] = bin2bcd(tm->tm_hour) | ISL1208_REG_HR_MIL; |
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index f59277bbedaa..7a568beba3f0 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
27 | #include <asm/io.h> | 27 | #include <asm/io.h> |
28 | #include <asm/irq.h> | 28 | #include <asm/irq.h> |
29 | #include <asm/plat-s3c/regs-rtc.h> | 29 | #include <plat/regs-rtc.h> |
30 | 30 | ||
31 | /* I have yet to find an S3C implementation with more than one | 31 | /* I have yet to find an S3C implementation with more than one |
32 | * of these rtc blocks in */ | 32 | * of these rtc blocks in */ |
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index 66a9bb85bbe8..d26a5f82aaba 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c | |||
@@ -38,11 +38,11 @@ | |||
38 | #include <mach/pxa-regs.h> | 38 | #include <mach/pxa-regs.h> |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | #define TIMER_FREQ CLOCK_TICK_RATE | ||
42 | #define RTC_DEF_DIVIDER 32768 - 1 | 41 | #define RTC_DEF_DIVIDER 32768 - 1 |
43 | #define RTC_DEF_TRIM 0 | 42 | #define RTC_DEF_TRIM 0 |
44 | 43 | ||
45 | static unsigned long rtc_freq = 1024; | 44 | static unsigned long rtc_freq = 1024; |
45 | static unsigned long timer_freq; | ||
46 | static struct rtc_time rtc_alarm; | 46 | static struct rtc_time rtc_alarm; |
47 | static DEFINE_SPINLOCK(sa1100_rtc_lock); | 47 | static DEFINE_SPINLOCK(sa1100_rtc_lock); |
48 | 48 | ||
@@ -157,7 +157,7 @@ static irqreturn_t timer1_interrupt(int irq, void *dev_id) | |||
157 | rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); | 157 | rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); |
158 | 158 | ||
159 | if (rtc_timer1_count == 1) | 159 | if (rtc_timer1_count == 1) |
160 | rtc_timer1_count = (rtc_freq * ((1<<30)/(TIMER_FREQ>>2))); | 160 | rtc_timer1_count = (rtc_freq * ((1 << 30) / (timer_freq >> 2))); |
161 | 161 | ||
162 | return IRQ_HANDLED; | 162 | return IRQ_HANDLED; |
163 | } | 163 | } |
@@ -166,7 +166,7 @@ static int sa1100_rtc_read_callback(struct device *dev, int data) | |||
166 | { | 166 | { |
167 | if (data & RTC_PF) { | 167 | if (data & RTC_PF) { |
168 | /* interpolate missed periods and set match for the next */ | 168 | /* interpolate missed periods and set match for the next */ |
169 | unsigned long period = TIMER_FREQ/rtc_freq; | 169 | unsigned long period = timer_freq / rtc_freq; |
170 | unsigned long oscr = OSCR; | 170 | unsigned long oscr = OSCR; |
171 | unsigned long osmr1 = OSMR1; | 171 | unsigned long osmr1 = OSMR1; |
172 | unsigned long missed = (oscr - osmr1)/period; | 172 | unsigned long missed = (oscr - osmr1)/period; |
@@ -263,7 +263,7 @@ static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, | |||
263 | return 0; | 263 | return 0; |
264 | case RTC_PIE_ON: | 264 | case RTC_PIE_ON: |
265 | spin_lock_irq(&sa1100_rtc_lock); | 265 | spin_lock_irq(&sa1100_rtc_lock); |
266 | OSMR1 = TIMER_FREQ/rtc_freq + OSCR; | 266 | OSMR1 = timer_freq / rtc_freq + OSCR; |
267 | OIER |= OIER_E1; | 267 | OIER |= OIER_E1; |
268 | rtc_timer1_count = 1; | 268 | rtc_timer1_count = 1; |
269 | spin_unlock_irq(&sa1100_rtc_lock); | 269 | spin_unlock_irq(&sa1100_rtc_lock); |
@@ -271,7 +271,7 @@ static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, | |||
271 | case RTC_IRQP_READ: | 271 | case RTC_IRQP_READ: |
272 | return put_user(rtc_freq, (unsigned long *)arg); | 272 | return put_user(rtc_freq, (unsigned long *)arg); |
273 | case RTC_IRQP_SET: | 273 | case RTC_IRQP_SET: |
274 | if (arg < 1 || arg > TIMER_FREQ) | 274 | if (arg < 1 || arg > timer_freq) |
275 | return -EINVAL; | 275 | return -EINVAL; |
276 | rtc_freq = arg; | 276 | rtc_freq = arg; |
277 | return 0; | 277 | return 0; |
@@ -352,6 +352,8 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
352 | { | 352 | { |
353 | struct rtc_device *rtc; | 353 | struct rtc_device *rtc; |
354 | 354 | ||
355 | timer_freq = get_clock_tick_rate(); | ||
356 | |||
355 | /* | 357 | /* |
356 | * According to the manual we should be able to let RTTR be zero | 358 | * According to the manual we should be able to let RTTR be zero |
357 | * and then a default diviser for a 32.768KHz clock is used. | 359 | * and then a default diviser for a 32.768KHz clock is used. |