Skip to content

Commit 98bbab0

Browse files
Phil Elwellpelwell
Phil Elwell
authored andcommitted
Revert "rtc: pcf8523: properly handle oscillator stop bit"
This reverts commit ede44c9. See: raspberrypi/firmware#1065 Signed-off-by: Phil Elwell <[email protected]>
1 parent 9dd1078 commit 98bbab0

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

drivers/rtc/rtc-pcf8523.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,28 @@ static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
181181
if (err < 0)
182182
return err;
183183

184-
if (regs[0] & REG_SECONDS_OS)
185-
return -EINVAL;
184+
if (regs[0] & REG_SECONDS_OS) {
185+
/*
186+
* If the oscillator was stopped, try to clear the flag. Upon
187+
* power-up the flag is always set, but if we cannot clear it
188+
* the oscillator isn't running properly for some reason. The
189+
* sensible thing therefore is to return an error, signalling
190+
* that the clock cannot be assumed to be correct.
191+
*/
192+
193+
regs[0] &= ~REG_SECONDS_OS;
194+
195+
err = pcf8523_write(client, REG_SECONDS, regs[0]);
196+
if (err < 0)
197+
return err;
198+
199+
err = pcf8523_read(client, REG_SECONDS, &regs[0]);
200+
if (err < 0)
201+
return err;
202+
203+
if (regs[0] & REG_SECONDS_OS)
204+
return -EAGAIN;
205+
}
186206

187207
tm->tm_sec = bcd2bin(regs[0] & 0x7f);
188208
tm->tm_min = bcd2bin(regs[1] & 0x7f);
@@ -218,7 +238,6 @@ static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
218238
return err;
219239

220240
regs[0] = REG_SECONDS;
221-
/* This will purposely overwrite REG_SECONDS_OS */
222241
regs[1] = bin2bcd(tm->tm_sec);
223242
regs[2] = bin2bcd(tm->tm_min);
224243
regs[3] = bin2bcd(tm->tm_hour);

0 commit comments

Comments
 (0)