diff options
author | Boris BREZILLON <boris.brezillon@free-electrons.com> | 2015-03-02 04:18:15 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2015-03-04 16:11:07 -0500 |
commit | dd1f1f391dd7f3a39a3983df2ca076871111cec9 (patch) | |
tree | 2ab56a2848ff355a800d746f8c4eb50d3cd14080 | |
parent | 603b1a232604dcd19a28eaddf70eee9fbe3edc88 (diff) |
rtc: at91rm9200: rework wakeup and interrupt handling
The IRQ line used by the RTC device is usually shared with the system
timer (PIT) on at91 platforms.
Since timers are registering their handlers with IRQF_NO_SUSPEND, we
should expect being called in suspended state, and properly wake the
system up when this is the case.
Set IRQF_COND_SUSPEND flag when registering the IRQ handler to inform
irq core that it can safely be called while the system is suspended.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/rtc/rtc-at91rm9200.c | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c index 70a5d94cc766..b4f7744f6751 100644 --- a/drivers/rtc/rtc-at91rm9200.c +++ b/drivers/rtc/rtc-at91rm9200.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/io.h> | 31 | #include <linux/io.h> |
32 | #include <linux/of.h> | 32 | #include <linux/of.h> |
33 | #include <linux/of_device.h> | 33 | #include <linux/of_device.h> |
34 | #include <linux/suspend.h> | ||
34 | #include <linux/uaccess.h> | 35 | #include <linux/uaccess.h> |
35 | 36 | ||
36 | #include "rtc-at91rm9200.h" | 37 | #include "rtc-at91rm9200.h" |
@@ -54,6 +55,10 @@ static void __iomem *at91_rtc_regs; | |||
54 | static int irq; | 55 | static int irq; |
55 | static DEFINE_SPINLOCK(at91_rtc_lock); | 56 | static DEFINE_SPINLOCK(at91_rtc_lock); |
56 | static u32 at91_rtc_shadow_imr; | 57 | static u32 at91_rtc_shadow_imr; |
58 | static bool suspended; | ||
59 | static DEFINE_SPINLOCK(suspended_lock); | ||
60 | static unsigned long cached_events; | ||
61 | static u32 at91_rtc_imr; | ||
57 | 62 | ||
58 | static void at91_rtc_write_ier(u32 mask) | 63 | static void at91_rtc_write_ier(u32 mask) |
59 | { | 64 | { |
@@ -290,7 +295,9 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id) | |||
290 | struct rtc_device *rtc = platform_get_drvdata(pdev); | 295 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
291 | unsigned int rtsr; | 296 | unsigned int rtsr; |
292 | unsigned long events = 0; | 297 | unsigned long events = 0; |
298 | int ret = IRQ_NONE; | ||
293 | 299 | ||
300 | spin_lock(&suspended_lock); | ||
294 | rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read_imr(); | 301 | rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read_imr(); |
295 | if (rtsr) { /* this interrupt is shared! Is it ours? */ | 302 | if (rtsr) { /* this interrupt is shared! Is it ours? */ |
296 | if (rtsr & AT91_RTC_ALARM) | 303 | if (rtsr & AT91_RTC_ALARM) |
@@ -304,14 +311,22 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id) | |||
304 | 311 | ||
305 | at91_rtc_write(AT91_RTC_SCCR, rtsr); /* clear status reg */ | 312 | at91_rtc_write(AT91_RTC_SCCR, rtsr); /* clear status reg */ |
306 | 313 | ||
307 | rtc_update_irq(rtc, 1, events); | 314 | if (!suspended) { |
315 | rtc_update_irq(rtc, 1, events); | ||
308 | 316 | ||
309 | dev_dbg(&pdev->dev, "%s(): num=%ld, events=0x%02lx\n", __func__, | 317 | dev_dbg(&pdev->dev, "%s(): num=%ld, events=0x%02lx\n", |
310 | events >> 8, events & 0x000000FF); | 318 | __func__, events >> 8, events & 0x000000FF); |
319 | } else { | ||
320 | cached_events |= events; | ||
321 | at91_rtc_write_idr(at91_rtc_imr); | ||
322 | pm_system_wakeup(); | ||
323 | } | ||
311 | 324 | ||
312 | return IRQ_HANDLED; | 325 | ret = IRQ_HANDLED; |
313 | } | 326 | } |
314 | return IRQ_NONE; /* not handled */ | 327 | spin_lock(&suspended_lock); |
328 | |||
329 | return ret; | ||
315 | } | 330 | } |
316 | 331 | ||
317 | static const struct at91_rtc_config at91rm9200_config = { | 332 | static const struct at91_rtc_config at91rm9200_config = { |
@@ -401,8 +416,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev) | |||
401 | AT91_RTC_CALEV); | 416 | AT91_RTC_CALEV); |
402 | 417 | ||
403 | ret = devm_request_irq(&pdev->dev, irq, at91_rtc_interrupt, | 418 | ret = devm_request_irq(&pdev->dev, irq, at91_rtc_interrupt, |
404 | IRQF_SHARED, | 419 | IRQF_SHARED | IRQF_COND_SUSPEND, |
405 | "at91_rtc", pdev); | 420 | "at91_rtc", pdev); |
406 | if (ret) { | 421 | if (ret) { |
407 | dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); | 422 | dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); |
408 | return ret; | 423 | return ret; |
@@ -454,8 +469,6 @@ static void at91_rtc_shutdown(struct platform_device *pdev) | |||
454 | 469 | ||
455 | /* AT91RM9200 RTC Power management control */ | 470 | /* AT91RM9200 RTC Power management control */ |
456 | 471 | ||
457 | static u32 at91_rtc_imr; | ||
458 | |||
459 | static int at91_rtc_suspend(struct device *dev) | 472 | static int at91_rtc_suspend(struct device *dev) |
460 | { | 473 | { |
461 | /* this IRQ is shared with DBGU and other hardware which isn't | 474 | /* this IRQ is shared with DBGU and other hardware which isn't |
@@ -464,21 +477,42 @@ static int at91_rtc_suspend(struct device *dev) | |||
464 | at91_rtc_imr = at91_rtc_read_imr() | 477 | at91_rtc_imr = at91_rtc_read_imr() |
465 | & (AT91_RTC_ALARM|AT91_RTC_SECEV); | 478 | & (AT91_RTC_ALARM|AT91_RTC_SECEV); |
466 | if (at91_rtc_imr) { | 479 | if (at91_rtc_imr) { |
467 | if (device_may_wakeup(dev)) | 480 | if (device_may_wakeup(dev)) { |
481 | unsigned long flags; | ||
482 | |||
468 | enable_irq_wake(irq); | 483 | enable_irq_wake(irq); |
469 | else | 484 | |
485 | spin_lock_irqsave(&suspended_lock, flags); | ||
486 | suspended = true; | ||
487 | spin_unlock_irqrestore(&suspended_lock, flags); | ||
488 | } else { | ||
470 | at91_rtc_write_idr(at91_rtc_imr); | 489 | at91_rtc_write_idr(at91_rtc_imr); |
490 | } | ||
471 | } | 491 | } |
472 | return 0; | 492 | return 0; |
473 | } | 493 | } |
474 | 494 | ||
475 | static int at91_rtc_resume(struct device *dev) | 495 | static int at91_rtc_resume(struct device *dev) |
476 | { | 496 | { |
497 | struct rtc_device *rtc = dev_get_drvdata(dev); | ||
498 | |||
477 | if (at91_rtc_imr) { | 499 | if (at91_rtc_imr) { |
478 | if (device_may_wakeup(dev)) | 500 | if (device_may_wakeup(dev)) { |
501 | unsigned long flags; | ||
502 | |||
503 | spin_lock_irqsave(&suspended_lock, flags); | ||
504 | |||
505 | if (cached_events) { | ||
506 | rtc_update_irq(rtc, 1, cached_events); | ||
507 | cached_events = 0; | ||
508 | } | ||
509 | |||
510 | suspended = false; | ||
511 | spin_unlock_irqrestore(&suspended_lock, flags); | ||
512 | |||
479 | disable_irq_wake(irq); | 513 | disable_irq_wake(irq); |
480 | else | 514 | } |
481 | at91_rtc_write_ier(at91_rtc_imr); | 515 | at91_rtc_write_ier(at91_rtc_imr); |
482 | } | 516 | } |
483 | return 0; | 517 | return 0; |
484 | } | 518 | } |