If an RTC alarm fires just as suspend is happening, it is possible for
suspend to complete and the alarm to be missed.
To avoid the race, we must register the event with the PM core.
As the event is made visible to userspace through a thread which is
only scheduled by the interrupt, we need a pm_stay_awake/pm_relax
pair preventing suspend from the interrupt until the thread completes
its work.
This makes the pm_wakeup_event() call in cmos_interrupt unnecessary as
it provides suspend protection for all RTCs that use rtc_update_irq.
BUG=chromium-os:36570
TEST=Fire wakealarm, check wakeup_count for increase:
cat /sys/power/wakeup_count
echo +1 >| /sys/class/rtc/rtc0/wakealarm
sleep 1
cat /sys/power/wakeup_count
Change-Id: I7dfc88bf6f95d0c5916b7e6ba751a56c62b5b82d
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Michael Spang <spang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/38480
Reviewed-by: Grant Grundler <grundler@chromium.org>
Reviewed-by: Jon Kliegman <kliegs@chromium.org>
void rtc_update_irq(struct rtc_device *rtc,
unsigned long num, unsigned long events)
{
+ pm_stay_awake(rtc->dev.parent);
schedule_work(&rtc->irqwork);
}
EXPORT_SYMBOL_GPL(rtc_update_irq);
mutex_lock(&rtc->ops_lock);
again:
+ pm_relax(rtc->dev.parent);
__rtc_read_time(rtc, &tm);
now = rtc_tm_to_ktime(tm);
while ((next = timerqueue_getnext(&rtc->timerqueue))) {