Skip to content

Commit 2b7cbd9

Browse files
LukasStockmannalexandrebelloni
authored andcommitted
rtc: pcf85063: do a SW reset if POR failed
Power-on Reset has a documented issue in PCF85063, refer to its datasheet, section "Software reset": "There is a low probability that some devices will have corruption of the registers after the automatic power-on reset if the device is powered up with a residual VDD level. It is required that the VDD starts at zero volts at power up or upon power cycling to ensure that there is no corruption of the registers. If this is not possible, a reset must be initiated after power-up (i.e. when power is stable) with the software reset command" Trigger SW reset if there is an indication that POR has failed. Link: https://www.nxp.com/docs/en/data-sheet/PCF85063A.pdf Signed-off-by: Lukas Stockmann <lukas.stockmann@siemens.com> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com> Link: https://lore.kernel.org/r/20250120093451.30778-1-alexander.sverdlin@siemens.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent a419357 commit 2b7cbd9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

drivers/rtc/rtc-pcf85063.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define PCF85063_REG_CTRL1_CAP_SEL BIT(0)
3636
#define PCF85063_REG_CTRL1_STOP BIT(5)
3737
#define PCF85063_REG_CTRL1_EXT_TEST BIT(7)
38+
#define PCF85063_REG_CTRL1_SWR 0x58
3839

3940
#define PCF85063_REG_CTRL2 0x01
4041
#define PCF85063_CTRL2_AF BIT(6)
@@ -589,7 +590,7 @@ static int pcf85063_probe(struct i2c_client *client)
589590

590591
i2c_set_clientdata(client, pcf85063);
591592

592-
err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp);
593+
err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp);
593594
if (err) {
594595
dev_err(&client->dev, "RTC chip is not present\n");
595596
return err;
@@ -599,6 +600,22 @@ static int pcf85063_probe(struct i2c_client *client)
599600
if (IS_ERR(pcf85063->rtc))
600601
return PTR_ERR(pcf85063->rtc);
601602

603+
/*
604+
* If a Power loss is detected, SW reset the device.
605+
* From PCF85063A datasheet:
606+
* There is a low probability that some devices will have corruption
607+
* of the registers after the automatic power-on reset...
608+
*/
609+
if (tmp & PCF85063_REG_SC_OS) {
610+
dev_warn(&client->dev,
611+
"POR issue detected, sending a SW reset\n");
612+
err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1,
613+
PCF85063_REG_CTRL1_SWR);
614+
if (err < 0)
615+
dev_warn(&client->dev,
616+
"SW reset failed, trying to continue\n");
617+
}
618+
602619
err = pcf85063_load_capacitance(pcf85063, client->dev.of_node,
603620
config->force_cap_7000 ? 7000 : 0);
604621
if (err < 0)

0 commit comments

Comments
 (0)