Commit 529a4f4e authored by Haavard Skinnemoen's avatar Haavard Skinnemoen Committed by Linus Torvalds

rtc-at32ap700x: fix bug in at32_rtc_readalarm()

alarm->pending indicates whether there's an alarm that has actually been
triggered, not whether we're waiting for it.  alarm->enabled indicates
that.

Also add missing locking around reading the RTC registers.
Signed-off-by: default avatarHaavard Skinnemoen <haavard.skinnemoen@atmel.com>
Signed-off-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Cc: Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6c38d857
...@@ -94,8 +94,11 @@ static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -94,8 +94,11 @@ static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct rtc_at32ap700x *rtc = dev_get_drvdata(dev); struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
spin_lock_irq(&rtc->lock);
rtc_time_to_tm(rtc->alarm_time, &alrm->time); rtc_time_to_tm(rtc->alarm_time, &alrm->time);
alrm->pending = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0; alrm->enabled = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0;
alrm->pending = rtc_readl(rtc, ISR) & RTC_BIT(ISR_TOPI) ? 1 : 0;
spin_unlock_irq(&rtc->lock);
return 0; return 0;
} }
...@@ -119,7 +122,7 @@ static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -119,7 +122,7 @@ static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
spin_lock_irq(&rtc->lock); spin_lock_irq(&rtc->lock);
rtc->alarm_time = alarm_unix_time; rtc->alarm_time = alarm_unix_time;
rtc_writel(rtc, TOP, rtc->alarm_time); rtc_writel(rtc, TOP, rtc->alarm_time);
if (alrm->pending) if (alrm->enabled)
rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL) rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
| RTC_BIT(CTRL_TOPEN)); | RTC_BIT(CTRL_TOPEN));
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment