Skip to content

Commit fe0157b

Browse files
paulmnalexandrebelloni
authored andcommitted
rtc: pcf8523: fix for stop bit
Bugfix for an issue detected when a goldcap capacitor gets fully discharged due to a long absence of the power supply, and then recharges again. The RTC failed to continue to keep the real-time clock. This was caused by the incorrect handling of the STOP bit in the RTC internal register. This fix solves the problem. Signed-off-by: paulmn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent eec7950 commit fe0157b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/rtc/rtc-pcf8523.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,24 @@ static irqreturn_t pcf8523_irq(int irq, void *dev_id)
9999
static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
100100
{
101101
struct pcf8523 *pcf8523 = dev_get_drvdata(dev);
102-
u8 regs[7];
102+
u8 regs[10];
103103
int err;
104104

105-
err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_SECONDS, regs,
105+
err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_CONTROL1, regs,
106106
sizeof(regs));
107107
if (err < 0)
108108
return err;
109109

110-
if (regs[0] & PCF8523_SECONDS_OS)
110+
if ((regs[0] & PCF8523_CONTROL1_STOP) || (regs[3] & PCF8523_SECONDS_OS))
111111
return -EINVAL;
112112

113-
tm->tm_sec = bcd2bin(regs[0] & 0x7f);
114-
tm->tm_min = bcd2bin(regs[1] & 0x7f);
115-
tm->tm_hour = bcd2bin(regs[2] & 0x3f);
116-
tm->tm_mday = bcd2bin(regs[3] & 0x3f);
117-
tm->tm_wday = regs[4] & 0x7;
118-
tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1;
119-
tm->tm_year = bcd2bin(regs[6]) + 100;
113+
tm->tm_sec = bcd2bin(regs[3] & 0x7f);
114+
tm->tm_min = bcd2bin(regs[4] & 0x7f);
115+
tm->tm_hour = bcd2bin(regs[5] & 0x3f);
116+
tm->tm_mday = bcd2bin(regs[6] & 0x3f);
117+
tm->tm_wday = regs[7] & 0x7;
118+
tm->tm_mon = bcd2bin(regs[8] & 0x1f) - 1;
119+
tm->tm_year = bcd2bin(regs[9]) + 100;
120120

121121
return 0;
122122
}

0 commit comments

Comments
 (0)