Linux RTC
 help / color / mirror / Atom feed
* [PATCH] rtc: omap: wait for !BUSY before reading time for the power-off alarm
@ 2026-10-04 21:59 Rosen Penev
  2026-10-04 22:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-10-04 21:59 UTC (permalink / raw)
  To: linux-rtc; +Cc: Alexandre Belloni, Johan Hovold, Andrew Morton, open list

omap_rtc_power_off_program() reads the time registers to arm ALARM2
one second ahead, but does not wait for STATUS.BUSY to clear first,
unlike omap_rtc_read_time(). The time registers must not be accessed
while BUSY is set, as the counters may be partway through an update.

A read during an update can return, for example, seconds already
wrapped to 0 with minutes still at the old value. The rollover check
after arming only compares the seconds register, which no longer
changes, so it passes and ALARM2 is armed for a time that has already
passed. Power-off or rtc-only suspend then waits for an alarm that
does not fire as intended.

Call rtc_wait_not_busy() before the read, as omap_rtc_read_time()
does. Both callers run with local interrupts disabled, as the access
window requires.

Fixes: 222a12fca604 ("rtc: omap: add support for pmic_power_en")
Assisted-by: LLM
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/rtc/rtc-omap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 540232d6f26c..4e9b4f601a9c 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -437,6 +437,7 @@ int omap_rtc_power_off_program(void)
 	rtc_writel(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM2);
 
 	/* set alarm one second from now */
+	rtc_wait_not_busy(rtc);
 	omap_rtc_read_time_raw(rtc, &tm);
 	seconds = tm.tm_sec;
 	bcd2tm(&tm);
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtc: omap: wait for !BUSY before reading time for the power-off alarm
  2026-10-04 21:59 [PATCH] rtc: omap: wait for !BUSY before reading time for the power-off alarm Rosen Penev
@ 2026-10-04 22:07 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-04 22:07 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-rtc, Alexandre Belloni

> omap_rtc_power_off_program() reads the time registers to arm ALARM2
> one second ahead, but does not wait for STATUS.BUSY to clear first,
> unlike omap_rtc_read_time(). The time registers must not be accessed
> while BUSY is set, as the counters may be partway through an update.
> 
> A read during an update can return, for example, seconds already
> wrapped to 0 with minutes still at the old value. The rollover check
> after arming only compares the seconds register, which no longer
> changes, so it passes and ALARM2 is armed for a time that has already
> passed. Power-off or rtc-only suspend then waits for an alarm that
> does not fire as intended.
> 
> Call rtc_wait_not_busy() before the read, as omap_rtc_read_time()
> does. Both callers run with local interrupts disabled, as the access
> window requires.
> 
> Fixes: 222a12fca604 ("rtc: omap: add support for pmic_power_en")
> Assisted-by: LLM
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261004215914.397512-1-rosenp@gmail.com?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-04 22:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-04 21:59 [PATCH] rtc: omap: wait for !BUSY before reading time for the power-off alarm Rosen Penev
2026-10-04 22:07 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox