Linux RTC
 help / color / mirror / Atom feed
* [PATCH] rtc: ds1307: fix RX8130 wakeup alarm WADA bit for day-of-month mode
@ 2026-07-21  8:19 Robert Leussler
  2026-07-21  8:30 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Robert Leussler @ 2026-07-21  8:19 UTC (permalink / raw)
  To: alexandre.belloni; +Cc: linux-rtc, linux-kernel, Robert Leussler

The RX8130 wakeup alarm never fired when set via
/sys/class/rtc/rtc0/wakealarm. The root cause is that the WADA bit
(bit 3) in the Extension register (0x1c) was never set before
programming the alarm registers.

Per the RX8130 datasheet:
WADA=0 - Week alarm: register 0x19 is compared against day-of-week
WADA=1 - Day alarm:  register 0x19 is compared against day-of-month

rx8130_set_alarm() always writes a BCD day-of-month value to alarm
register 0x19, so WADA must be 1. With WADA=0 the hardware matched the
day-of-month value (e.g. 15) as a day-of-week index, which is always
out of range (valid weekdays are 0-6), so the alarm interrupt was never
asserted.

Fix by setting the WADA bit in rx8130_set_alarm() before writing the
Extension register back to the device.

This is consistent with rx8130_read_alarm(), which decodes the same
register under the same assumption (24-hour and day-of-month mode).


Signed-off-by: Robert Leussler <robert.leussler@leica-geosystems.com>
---
 drivers/rtc/rtc-ds1307.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 1960d1bd851c..3631f0894d55 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -656,7 +656,7 @@ static int rx8130_set_alarm(struct device *dev, struct rtc_wkalrm *t)
 	if (ret < 0)
 		return ret;
 
-	ctl[0] &= RX8130_REG_EXTENSION_WADA;
+	ctl[0] |= RX8130_REG_EXTENSION_WADA;
 	ctl[1] &= ~RX8130_REG_FLAG_AF;
 	ctl[2] &= ~RX8130_REG_CONTROL0_AIE;
 
-- 
2.43.0


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

* Re: [PATCH] rtc: ds1307: fix RX8130 wakeup alarm WADA bit for day-of-month mode
  2026-07-21  8:19 [PATCH] rtc: ds1307: fix RX8130 wakeup alarm WADA bit for day-of-month mode Robert Leussler
@ 2026-07-21  8:30 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-07-21  8:30 UTC (permalink / raw)
  To: Robert Leussler; +Cc: linux-rtc, Alexandre Belloni

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Read-modify-write on the write-0-to-clear FLAG register can silently clear asynchronous hardware flags.
--

--- Patch [1]: [PATCH] rtc: ds1307: fix RX8130 wakeup alarm WADA bit for day-of-month mode ---
commit 8a134031395cee2cc4d889ef300ebcec83e18b1b
Author: Robert Leussler <robert.leussler@leica-geosystems.com>
Subject: rtc: ds1307: fix RX8130 wakeup alarm WADA bit for day-of-month mode

This commit fixes the RX8130 wakeup alarm by setting the WADA bit in the
Extension register so the day-of-month alarm works correctly, rather than
failing as an out-of-range day-of-week alarm.

> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -656,13 +656,13 @@ static int rx8130_set_alarm(struct device *dev, struct rtc_wkalrm *t)
>  
>  	/* Read control registers. */
>  	ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl,
>  			       sizeof(ctl));
>  	if (ret < 0)
>  		return ret;
>  
> -	ctl[0] &= RX8130_REG_EXTENSION_WADA;
> +	ctl[0] |= RX8130_REG_EXTENSION_WADA;
>  	ctl[1] &= ~RX8130_REG_FLAG_AF;

[Severity: High]
This is a pre-existing issue, but could this read-modify-write sequence on 
the FLAG register (ctl[1]) silently clear asynchronous hardware flags like 
the Voltage Low Flag (VLF)?

Because the FLAG register uses write-0-to-clear semantics, any bits that
are read as 0 will be written back as 0. If a hardware flag like VLF is
asserted in the slow I2C window between regmap_bulk_read() and
regmap_bulk_write(), wouldn't writing back a 0 accidentally clear it and
potentially hide an oscillator failure from userspace?

This same read-modify-write pattern also appears to be present during
interrupt handling in rx8130_irq().

>  	ctl[2] &= ~RX8130_REG_CONTROL0_AIE;
>  
>  	ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl,
>  				sizeof(ctl));

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721081907.3518648-1-robert.leussler@leica-geosystems.com?part=1

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

end of thread, other threads:[~2026-07-21  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-21  8:19 [PATCH] rtc: ds1307: fix RX8130 wakeup alarm WADA bit for day-of-month mode Robert Leussler
2026-07-21  8:30 ` sashiko-bot

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