diff options
Diffstat (limited to 'drivers/rtc/rtc-cmos.c')
-rw-r--r-- | drivers/rtc/rtc-cmos.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 85bf795abdcc..7c0d60910077 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
@@ -59,6 +59,19 @@ struct cmos_rtc { | |||
59 | 59 | ||
60 | static const char driver_name[] = "rtc_cmos"; | 60 | static const char driver_name[] = "rtc_cmos"; |
61 | 61 | ||
62 | /* The RTC_INTR register may have e.g. RTC_PF set even if RTC_PIE is clear; | ||
63 | * always mask it against the irq enable bits in RTC_CONTROL. Bit values | ||
64 | * are the same: PF==PIE, AF=AIE, UF=UIE; so RTC_IRQMASK works with both. | ||
65 | */ | ||
66 | #define RTC_IRQMASK (RTC_PF | RTC_AF | RTC_UF) | ||
67 | |||
68 | static inline int is_intr(u8 rtc_intr) | ||
69 | { | ||
70 | if (!(rtc_intr & RTC_IRQF)) | ||
71 | return 0; | ||
72 | return rtc_intr & RTC_IRQMASK; | ||
73 | } | ||
74 | |||
62 | /*----------------------------------------------------------------*/ | 75 | /*----------------------------------------------------------------*/ |
63 | 76 | ||
64 | static int cmos_read_time(struct device *dev, struct rtc_time *t) | 77 | static int cmos_read_time(struct device *dev, struct rtc_time *t) |
@@ -188,7 +201,8 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
188 | rtc_control &= ~RTC_AIE; | 201 | rtc_control &= ~RTC_AIE; |
189 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 202 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
190 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); | 203 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); |
191 | if (rtc_intr) | 204 | rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; |
205 | if (is_intr(rtc_intr)) | ||
192 | rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); | 206 | rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); |
193 | 207 | ||
194 | /* update alarm */ | 208 | /* update alarm */ |
@@ -207,7 +221,8 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
207 | rtc_control |= RTC_AIE; | 221 | rtc_control |= RTC_AIE; |
208 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 222 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
209 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); | 223 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); |
210 | if (rtc_intr) | 224 | rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; |
225 | if (is_intr(rtc_intr)) | ||
211 | rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); | 226 | rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); |
212 | } | 227 | } |
213 | 228 | ||
@@ -287,7 +302,8 @@ cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | |||
287 | } | 302 | } |
288 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 303 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
289 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); | 304 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); |
290 | if (rtc_intr) | 305 | rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; |
306 | if (is_intr(rtc_intr)) | ||
291 | rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); | 307 | rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); |
292 | spin_unlock_irqrestore(&rtc_lock, flags); | 308 | spin_unlock_irqrestore(&rtc_lock, flags); |
293 | return 0; | 309 | return 0; |
@@ -353,12 +369,10 @@ static irqreturn_t cmos_interrupt(int irq, void *p) | |||
353 | 369 | ||
354 | spin_lock(&rtc_lock); | 370 | spin_lock(&rtc_lock); |
355 | irqstat = CMOS_READ(RTC_INTR_FLAGS); | 371 | irqstat = CMOS_READ(RTC_INTR_FLAGS); |
372 | irqstat &= (CMOS_READ(RTC_CONTROL) & RTC_IRQMASK) | RTC_IRQF; | ||
356 | spin_unlock(&rtc_lock); | 373 | spin_unlock(&rtc_lock); |
357 | 374 | ||
358 | if (irqstat) { | 375 | if (is_intr(irqstat)) { |
359 | /* NOTE: irqstat may have e.g. RTC_PF set | ||
360 | * even when RTC_PIE is clear... | ||
361 | */ | ||
362 | rtc_update_irq(p, 1, irqstat); | 376 | rtc_update_irq(p, 1, irqstat); |
363 | return IRQ_HANDLED; | 377 | return IRQ_HANDLED; |
364 | } else | 378 | } else |
@@ -525,25 +539,26 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg) | |||
525 | { | 539 | { |
526 | struct cmos_rtc *cmos = dev_get_drvdata(dev); | 540 | struct cmos_rtc *cmos = dev_get_drvdata(dev); |
527 | int do_wake = device_may_wakeup(dev); | 541 | int do_wake = device_may_wakeup(dev); |
528 | unsigned char tmp, irqstat; | 542 | unsigned char tmp; |
529 | 543 | ||
530 | /* only the alarm might be a wakeup event source */ | 544 | /* only the alarm might be a wakeup event source */ |
531 | spin_lock_irq(&rtc_lock); | 545 | spin_lock_irq(&rtc_lock); |
532 | cmos->suspend_ctrl = tmp = CMOS_READ(RTC_CONTROL); | 546 | cmos->suspend_ctrl = tmp = CMOS_READ(RTC_CONTROL); |
533 | if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) { | 547 | if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) { |
548 | unsigned char irqstat; | ||
549 | |||
534 | if (do_wake) | 550 | if (do_wake) |
535 | tmp &= ~(RTC_PIE|RTC_UIE); | 551 | tmp &= ~(RTC_PIE|RTC_UIE); |
536 | else | 552 | else |
537 | tmp &= ~(RTC_PIE|RTC_AIE|RTC_UIE); | 553 | tmp &= ~(RTC_PIE|RTC_AIE|RTC_UIE); |
538 | CMOS_WRITE(tmp, RTC_CONTROL); | 554 | CMOS_WRITE(tmp, RTC_CONTROL); |
539 | irqstat = CMOS_READ(RTC_INTR_FLAGS); | 555 | irqstat = CMOS_READ(RTC_INTR_FLAGS); |
540 | } else | 556 | irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF; |
541 | irqstat = 0; | 557 | if (is_intr(irqstat)) |
558 | rtc_update_irq(&cmos->rtc->class_dev, 1, irqstat); | ||
559 | } | ||
542 | spin_unlock_irq(&rtc_lock); | 560 | spin_unlock_irq(&rtc_lock); |
543 | 561 | ||
544 | if (irqstat) | ||
545 | rtc_update_irq(&cmos->rtc->class_dev, 1, irqstat); | ||
546 | |||
547 | /* ACPI HOOK: enable ACPI_EVENT_RTC when (tmp & RTC_AIE) | 562 | /* ACPI HOOK: enable ACPI_EVENT_RTC when (tmp & RTC_AIE) |
548 | * ... it'd be best if we could do that under rtc_lock. | 563 | * ... it'd be best if we could do that under rtc_lock. |
549 | */ | 564 | */ |
@@ -573,9 +588,10 @@ static int cmos_resume(struct device *dev) | |||
573 | spin_lock_irq(&rtc_lock); | 588 | spin_lock_irq(&rtc_lock); |
574 | CMOS_WRITE(tmp, RTC_CONTROL); | 589 | CMOS_WRITE(tmp, RTC_CONTROL); |
575 | tmp = CMOS_READ(RTC_INTR_FLAGS); | 590 | tmp = CMOS_READ(RTC_INTR_FLAGS); |
576 | spin_unlock_irq(&rtc_lock); | 591 | tmp &= (cmos->suspend_ctrl & RTC_IRQMASK) | RTC_IRQF; |
577 | if (tmp) | 592 | if (is_intr(tmp)) |
578 | rtc_update_irq(&cmos->rtc->class_dev, 1, tmp); | 593 | rtc_update_irq(&cmos->rtc->class_dev, 1, tmp); |
594 | spin_unlock_irq(&rtc_lock); | ||
579 | } | 595 | } |
580 | 596 | ||
581 | pr_debug("%s: resume, ctrl %02x\n", | 597 | pr_debug("%s: resume, ctrl %02x\n", |
@@ -594,7 +610,7 @@ static int cmos_resume(struct device *dev) | |||
594 | /*----------------------------------------------------------------*/ | 610 | /*----------------------------------------------------------------*/ |
595 | 611 | ||
596 | /* The "CMOS" RTC normally lives on the platform_bus. On ACPI systems, | 612 | /* The "CMOS" RTC normally lives on the platform_bus. On ACPI systems, |
597 | * the device node may alternatively be created as a PNP device. | 613 | * the device node will always be created as a PNPACPI device. |
598 | */ | 614 | */ |
599 | 615 | ||
600 | #ifdef CONFIG_PNPACPI | 616 | #ifdef CONFIG_PNPACPI |
@@ -673,7 +689,7 @@ module_exit(cmos_exit); | |||
673 | /*----------------------------------------------------------------*/ | 689 | /*----------------------------------------------------------------*/ |
674 | 690 | ||
675 | /* Platform setup should have set up an RTC device, when PNPACPI is | 691 | /* Platform setup should have set up an RTC device, when PNPACPI is |
676 | * unavailable ... this is the normal case, common even on PCs. | 692 | * unavailable ... this could happen even on (older) PCs. |
677 | */ | 693 | */ |
678 | 694 | ||
679 | static int __init cmos_platform_probe(struct platform_device *pdev) | 695 | static int __init cmos_platform_probe(struct platform_device *pdev) |