Skip to content

Commit 523923c

Browse files
Meagan Lloydalexandrebelloni
authored andcommitted
rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
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> Reviewed-by: Tyler Hicks <code@tyhicks.com> Acked-by: Rodolfo Giometti <giometti@enneenne.com> Link: https://lore.kernel.org/r/1749665656-30108-3-git-send-email-meaganlloyd@linux.microsoft.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 4845865 commit 523923c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

drivers/rtc/rtc-ds1307.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
279279
if (tmp & DS1340_BIT_OSF)
280280
return -EINVAL;
281281
break;
282+
case ds_1341:
283+
ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &tmp);
284+
if (ret)
285+
return ret;
286+
if (tmp & DS1337_BIT_OSF)
287+
return -EINVAL;
288+
break;
282289
case ds_1388:
283290
ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp);
284291
if (ret)
@@ -377,6 +384,10 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
377384
regmap_update_bits(ds1307->regmap, DS1340_REG_FLAG,
378385
DS1340_BIT_OSF, 0);
379386
break;
387+
case ds_1341:
388+
regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS,
389+
DS1337_BIT_OSF, 0);
390+
break;
380391
case ds_1388:
381392
regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG,
382393
DS1388_BIT_OSF, 0);

0 commit comments

Comments
 (0)