* [PATCH RESEND 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
2025-07-14 21:39 [PATCH RESEND 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
@ 2025-07-14 21:39 ` Meagan Lloyd
2025-07-14 21:39 ` [PATCH RESEND 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Meagan Lloyd
1 sibling, 0 replies; 3+ messages in thread
From: Meagan Lloyd @ 2025-07-14 21:39 UTC (permalink / raw)
To: alexandre.belloni; +Cc: linux-rtc, linux-kernel, code, giometti, Meagan Lloyd
In using CONFIG_RTC_HCTOSYS, rtc_hctosys() will sync the RTC time to the
kernel time as long as rtc_read_time() succeeds. In some power loss
situations, our supercapacitor-backed DS1342 RTC comes up with either an
unpredictable future time or the default 01/01/00 from the datasheet.
The oscillator stop flag (OSF) is set in these scenarios due to the
power loss and can be used to determine the validity of the RTC data.
Some chip types in the ds1307 driver already have OSF handling to
determine whether .read_time provides valid RTC data or returns -EINVAL.
This change removes the clear of the OSF in .probe as the OSF needs to
be preserved to expand the OSF handling to the ds1341 chip type (note
that DS1341 and DS1342 share a datasheet).
Signed-off-by: Meagan Lloyd <meaganlloyd@linux.microsoft.com>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Reviewed-by: Tyler Hicks <code@tyhicks.com>
---
Compile tested on rtc-next. Tested on an older kernel with ds1342 which
has the same datasheet as ds1341.
---
drivers/rtc/rtc-ds1307.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 5efbe69bf5ca8..65beb7067e3f5 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1813,10 +1813,8 @@ static int ds1307_probe(struct i2c_client *client)
regmap_write(ds1307->regmap, DS1337_REG_CONTROL,
regs[0]);
- /* oscillator fault? clear flag, and warn */
+ /* oscillator fault? warn */
if (regs[1] & DS1337_BIT_OSF) {
- regmap_write(ds1307->regmap, DS1337_REG_STATUS,
- regs[1] & ~DS1337_BIT_OSF);
dev_warn(ds1307->dev, "SET TIME!\n");
}
break;
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH RESEND 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
2025-07-14 21:39 [PATCH RESEND 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
2025-07-14 21:39 ` [PATCH RESEND 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe Meagan Lloyd
@ 2025-07-14 21:39 ` Meagan Lloyd
1 sibling, 0 replies; 3+ messages in thread
From: Meagan Lloyd @ 2025-07-14 21:39 UTC (permalink / raw)
To: alexandre.belloni; +Cc: linux-rtc, linux-kernel, code, giometti, Meagan Lloyd
In using CONFIG_RTC_HCTOSYS, rtc_hctosys() will sync the RTC time to the
kernel time as long as rtc_read_time() succeeds. In some power loss
situations, our supercapacitor-backed DS1342 RTC comes up with either an
unpredictable future time or the default 01/01/00 from the datasheet.
The oscillator stop flag (OSF) is set in these scenarios due to the
power loss and can be used to determine the validity of the RTC data.
This change expands the oscillator stop flag (OSF) handling that has
already been implemented for some chips to the ds1341 chip (DS1341 and
DS1342 share a datasheet). This handling manages the validity of the RTC
data in .read_time and .set_time based on the OSF.
Signed-off-by: Meagan Lloyd <meaganlloyd@linux.microsoft.com>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Reviewed-by: Tyler Hicks <code@tyhicks.com>
---
Compile tested on rtc-next. Tested on an older kernel with ds1342 which
has the same datasheet as ds1341.
---
drivers/rtc/rtc-ds1307.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 65beb7067e3f5..ce0994d9219a2 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -279,6 +279,13 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
if (tmp & DS1340_BIT_OSF)
return -EINVAL;
break;
+ case ds_1341:
+ ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &tmp);
+ if (ret)
+ return ret;
+ if (tmp & DS1337_BIT_OSF)
+ return -EINVAL;
+ break;
case ds_1388:
ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp);
if (ret)
@@ -377,6 +384,10 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
regmap_update_bits(ds1307->regmap, DS1340_REG_FLAG,
DS1340_BIT_OSF, 0);
break;
+ case ds_1341:
+ regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS,
+ DS1337_BIT_OSF, 0);
+ break;
case ds_1388:
regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG,
DS1388_BIT_OSF, 0);
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread