* [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341
@ 2025-06-11 18:14 Meagan Lloyd
2025-06-11 18:14 ` [PATCH 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe Meagan Lloyd
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Meagan Lloyd @ 2025-06-11 18:14 UTC (permalink / raw)
To: alexandre.belloni; +Cc: linux-rtc, linux-kernel, code, Meagan Lloyd
We would like to use CONFIG_RTC_HCTOSYS to sync a supercapacitor-backed
DS1342 RTC to the kernel time early in boot. An obstacle is that the
sync in rtc_hctosys() is unconditional as long as rtc_read_time()
succeeds and in some power loss situations, our RTC comes up with either
an unpredictable future time or the default 01/01/00 from the datasheet.
Syncing a future time, followed by an NTP sync would not be desired as
it would result in a backwards time jump. The sync feature is useful in
boot scenarios where power is maintained so syncing only when the RTC
data is valid would allow us to make use of the feature.
The DS1342 has the oscillator stop flag (OSF) which is a status flag
indicating that the oscillator stopped for a period of time. It can be
set due to power loss. Some chip types in the ds1307 driver already use
the OSF to determine whether .read_time should provide valid data or
return -EINVAL. This patch series expands that handling to the ds1341
chip type (DS1341 and DS1342 share a datasheet).
These changes enable us to make use of CONFIG_RTC_HCTOSYS as they
prevent the invalid time from getting synced to the kernel time. It will
also prevent userspace programs from getting the invalid time as the fix
cuts it off at the source - the .read_time function.
Meagan Lloyd (2):
rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
drivers/rtc/rtc-ds1307.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
--
2.49.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
2025-06-11 18:14 [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
@ 2025-06-11 18:14 ` Meagan Lloyd
2025-06-11 18:14 ` [PATCH 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Meagan Lloyd
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Meagan Lloyd @ 2025-06-11 18:14 UTC (permalink / raw)
To: alexandre.belloni; +Cc: linux-rtc, linux-kernel, code, 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>
---
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] 7+ messages in thread
* [PATCH 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
2025-06-11 18:14 [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
2025-06-11 18:14 ` [PATCH 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe Meagan Lloyd
@ 2025-06-11 18:14 ` Meagan Lloyd
2025-06-30 22:54 ` [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Tyler Hicks
2025-07-23 21:25 ` Alexandre Belloni
3 siblings, 0 replies; 7+ messages in thread
From: Meagan Lloyd @ 2025-06-11 18:14 UTC (permalink / raw)
To: alexandre.belloni; +Cc: linux-rtc, linux-kernel, code, 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>
---
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] 7+ messages in thread
* Re: [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341
2025-06-11 18:14 [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
2025-06-11 18:14 ` [PATCH 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe Meagan Lloyd
2025-06-11 18:14 ` [PATCH 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Meagan Lloyd
@ 2025-06-30 22:54 ` Tyler Hicks
2025-07-02 14:37 ` Rodolfo Giometti
2025-07-23 21:25 ` Alexandre Belloni
3 siblings, 1 reply; 7+ messages in thread
From: Tyler Hicks @ 2025-06-30 22:54 UTC (permalink / raw)
To: Meagan Lloyd, alexandre.belloni, Rodolfo Giometti; +Cc: linux-rtc, linux-kernel
[Adding Rodolfo Giometti]
On 2025-06-11 11:14:14, Meagan Lloyd wrote:
> We would like to use CONFIG_RTC_HCTOSYS to sync a supercapacitor-backed
> DS1342 RTC to the kernel time early in boot. An obstacle is that the
> sync in rtc_hctosys() is unconditional as long as rtc_read_time()
> succeeds and in some power loss situations, our RTC comes up with either
> an unpredictable future time or the default 01/01/00 from the datasheet.
> Syncing a future time, followed by an NTP sync would not be desired as
> it would result in a backwards time jump. The sync feature is useful in
> boot scenarios where power is maintained so syncing only when the RTC
> data is valid would allow us to make use of the feature.
>
> The DS1342 has the oscillator stop flag (OSF) which is a status flag
> indicating that the oscillator stopped for a period of time. It can be
> set due to power loss. Some chip types in the ds1307 driver already use
> the OSF to determine whether .read_time should provide valid data or
> return -EINVAL. This patch series expands that handling to the ds1341
> chip type (DS1341 and DS1342 share a datasheet).
>
> These changes enable us to make use of CONFIG_RTC_HCTOSYS as they
> prevent the invalid time from getting synced to the kernel time. It will
> also prevent userspace programs from getting the invalid time as the fix
> cuts it off at the source - the .read_time function.
These two patches look good to me, although I'm not an expert in RTC drivers.
I've reviewed the DS1341/DS1342 datasheet and the approach that Meagan has
taken makes sense to me given our (Meagan and I work together) desire to use
CONFIG_RTC_HCTOSYS and the need to avoid syncing from an invalid RTC state.
I've added Rodolfo because he first added the logic to clear the Oscillator
Stop Flag, during driver initialization, way back in 2007 with v2.6.23 commit
be5f59f4b67f ("rtc-ds1307: oscillator restart for ds13{37,38,39,40}") and may
have additional context to provide.
Alexandre and Rodolfo, does this approach make sense to you? If not, do you
have any other suggestions on how to make CONFIG_RTC_HCTOSYS work with this
driver? Thanks!
Tyler
>
> Meagan Lloyd (2):
> rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
> rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
>
> drivers/rtc/rtc-ds1307.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
>
> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341
2025-06-30 22:54 ` [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Tyler Hicks
@ 2025-07-02 14:37 ` Rodolfo Giometti
2025-07-02 14:52 ` Tyler Hicks
0 siblings, 1 reply; 7+ messages in thread
From: Rodolfo Giometti @ 2025-07-02 14:37 UTC (permalink / raw)
To: Tyler Hicks, Meagan Lloyd, alexandre.belloni; +Cc: linux-rtc, linux-kernel
On 01/07/25 00:54, Tyler Hicks wrote:
> [Adding Rodolfo Giometti]
>
> On 2025-06-11 11:14:14, Meagan Lloyd wrote:
>> We would like to use CONFIG_RTC_HCTOSYS to sync a supercapacitor-backed
>> DS1342 RTC to the kernel time early in boot. An obstacle is that the
>> sync in rtc_hctosys() is unconditional as long as rtc_read_time()
>> succeeds and in some power loss situations, our RTC comes up with either
>> an unpredictable future time or the default 01/01/00 from the datasheet.
>> Syncing a future time, followed by an NTP sync would not be desired as
>> it would result in a backwards time jump. The sync feature is useful in
>> boot scenarios where power is maintained so syncing only when the RTC
>> data is valid would allow us to make use of the feature.
>>
>> The DS1342 has the oscillator stop flag (OSF) which is a status flag
>> indicating that the oscillator stopped for a period of time. It can be
>> set due to power loss. Some chip types in the ds1307 driver already use
>> the OSF to determine whether .read_time should provide valid data or
>> return -EINVAL. This patch series expands that handling to the ds1341
>> chip type (DS1341 and DS1342 share a datasheet).
>>
>> These changes enable us to make use of CONFIG_RTC_HCTOSYS as they
>> prevent the invalid time from getting synced to the kernel time. It will
>> also prevent userspace programs from getting the invalid time as the fix
>> cuts it off at the source - the .read_time function.
>
> These two patches look good to me, although I'm not an expert in RTC drivers.
> I've reviewed the DS1341/DS1342 datasheet and the approach that Meagan has
> taken makes sense to me given our (Meagan and I work together) desire to use
> CONFIG_RTC_HCTOSYS and the need to avoid syncing from an invalid RTC state.
>
> I've added Rodolfo because he first added the logic to clear the Oscillator
> Stop Flag, during driver initialization, way back in 2007 with v2.6.23 commit
> be5f59f4b67f ("rtc-ds1307: oscillator restart for ds13{37,38,39,40}") and may
> have additional context to provide.
>
> Alexandre and Rodolfo, does this approach make sense to you? If not, do you
> have any other suggestions on how to make CONFIG_RTC_HCTOSYS work with this
> driver? Thanks!
They look good to me. You can add my Acked-by line to all of them:
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Rodolfo
> Tyler
>
>>
>> Meagan Lloyd (2):
>> rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
>> rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
>>
>> drivers/rtc/rtc-ds1307.c | 15 ++++++++++++---
>> 1 file changed, 12 insertions(+), 3 deletions(-)
>>
>>
>> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
>> --
>> 2.49.0
>>
--
GNU/Linux Solutions e-mail: giometti@enneenne.com
Linux Device Driver giometti@linux.it
Embedded Systems phone: +39 349 2432127
UNIX programming
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341
2025-07-02 14:37 ` Rodolfo Giometti
@ 2025-07-02 14:52 ` Tyler Hicks
0 siblings, 0 replies; 7+ messages in thread
From: Tyler Hicks @ 2025-07-02 14:52 UTC (permalink / raw)
To: Rodolfo Giometti, alexandre.belloni; +Cc: Meagan Lloyd, linux-rtc, linux-kernel
On 2025-07-02 16:37:41, Rodolfo Giometti wrote:
> On 01/07/25 00:54, Tyler Hicks wrote:
> > [Adding Rodolfo Giometti]
> >
> > On 2025-06-11 11:14:14, Meagan Lloyd wrote:
> > > We would like to use CONFIG_RTC_HCTOSYS to sync a supercapacitor-backed
> > > DS1342 RTC to the kernel time early in boot. An obstacle is that the
> > > sync in rtc_hctosys() is unconditional as long as rtc_read_time()
> > > succeeds and in some power loss situations, our RTC comes up with either
> > > an unpredictable future time or the default 01/01/00 from the datasheet.
> > > Syncing a future time, followed by an NTP sync would not be desired as
> > > it would result in a backwards time jump. The sync feature is useful in
> > > boot scenarios where power is maintained so syncing only when the RTC
> > > data is valid would allow us to make use of the feature.
> > >
> > > The DS1342 has the oscillator stop flag (OSF) which is a status flag
> > > indicating that the oscillator stopped for a period of time. It can be
> > > set due to power loss. Some chip types in the ds1307 driver already use
> > > the OSF to determine whether .read_time should provide valid data or
> > > return -EINVAL. This patch series expands that handling to the ds1341
> > > chip type (DS1341 and DS1342 share a datasheet).
> > >
> > > These changes enable us to make use of CONFIG_RTC_HCTOSYS as they
> > > prevent the invalid time from getting synced to the kernel time. It will
> > > also prevent userspace programs from getting the invalid time as the fix
> > > cuts it off at the source - the .read_time function.
> >
> > These two patches look good to me, although I'm not an expert in RTC drivers.
> > I've reviewed the DS1341/DS1342 datasheet and the approach that Meagan has
> > taken makes sense to me given our (Meagan and I work together) desire to use
> > CONFIG_RTC_HCTOSYS and the need to avoid syncing from an invalid RTC state.
> >
> > I've added Rodolfo because he first added the logic to clear the Oscillator
> > Stop Flag, during driver initialization, way back in 2007 with v2.6.23 commit
> > be5f59f4b67f ("rtc-ds1307: oscillator restart for ds13{37,38,39,40}") and may
> > have additional context to provide.
> >
> > Alexandre and Rodolfo, does this approach make sense to you? If not, do you
> > have any other suggestions on how to make CONFIG_RTC_HCTOSYS work with this
> > driver? Thanks!
>
> They look good to me. You can add my Acked-by line to all of them:
>
> Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Thanks for taking a look!
I should have formally given my Reviewed-by tag for both patches earlier in the thread:
Reviewed-by: Tyler Hicks <code@tyhicks.com>
Tyler
>
> Rodolfo
>
> > Tyler
> >
> > >
> > > Meagan Lloyd (2):
> > > rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
> > > rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
> > >
> > > drivers/rtc/rtc-ds1307.c | 15 ++++++++++++---
> > > 1 file changed, 12 insertions(+), 3 deletions(-)
> > >
> > >
> > > base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
> > > --
> > > 2.49.0
> > >
>
> --
> GNU/Linux Solutions e-mail: giometti@enneenne.com
> Linux Device Driver giometti@linux.it
> Embedded Systems phone: +39 349 2432127
> UNIX programming
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341
2025-06-11 18:14 [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
` (2 preceding siblings ...)
2025-06-30 22:54 ` [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Tyler Hicks
@ 2025-07-23 21:25 ` Alexandre Belloni
3 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2025-07-23 21:25 UTC (permalink / raw)
To: Meagan Lloyd; +Cc: linux-rtc, linux-kernel, code
On Wed, 11 Jun 2025 11:14:14 -0700, Meagan Lloyd wrote:
> We would like to use CONFIG_RTC_HCTOSYS to sync a supercapacitor-backed
> DS1342 RTC to the kernel time early in boot. An obstacle is that the
> sync in rtc_hctosys() is unconditional as long as rtc_read_time()
> succeeds and in some power loss situations, our RTC comes up with either
> an unpredictable future time or the default 01/01/00 from the datasheet.
> Syncing a future time, followed by an NTP sync would not be desired as
> it would result in a backwards time jump. The sync feature is useful in
> boot scenarios where power is maintained so syncing only when the RTC
> data is valid would allow us to make use of the feature.
>
> [...]
Applied, thanks!
[1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe
https://git.kernel.org/abelloni/c/48458654659c
[2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
https://git.kernel.org/abelloni/c/523923cfd5d6
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-23 21:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11 18:14 [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Meagan Lloyd
2025-06-11 18:14 ` [PATCH 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe Meagan Lloyd
2025-06-11 18:14 ` [PATCH 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Meagan Lloyd
2025-06-30 22:54 ` [PATCH 0/2] Expand oscillator stop flag (OSF) validity check to ds1341 Tyler Hicks
2025-07-02 14:37 ` Rodolfo Giometti
2025-07-02 14:52 ` Tyler Hicks
2025-07-23 21:25 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox