1 From d4caec563cc89319516a29a9b3c40ec302925d7a Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Mon, 29 Oct 2018 14:45:45 +0000
4 Subject: [PATCH] rtc: pcf8523: Fix oscillator stop bit handling
6 See: https://github.com/raspberrypi/firmware/issues/1065
8 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
10 drivers/rtc/rtc-pcf8523.c | 29 +++++++++++++++++++++++++++--
11 1 file changed, 27 insertions(+), 2 deletions(-)
13 --- a/drivers/rtc/rtc-pcf8523.c
14 +++ b/drivers/rtc/rtc-pcf8523.c
15 @@ -100,6 +100,7 @@ static int pcf8523_rtc_read_time(struct
17 struct pcf8523 *pcf8523 = dev_get_drvdata(dev);
22 err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_SECONDS, regs,
23 @@ -107,8 +108,32 @@ static int pcf8523_rtc_read_time(struct
27 - if (regs[0] & PCF8523_SECONDS_OS)
29 + if (regs[0] & PCF8523_SECONDS_OS) {
31 + * If the oscillator was stopped, try to clear the flag. Upon
32 + * power-up the flag is always set, but if we cannot clear it
33 + * the oscillator isn't running properly for some reason. The
34 + * sensible thing therefore is to return an error, signalling
35 + * that the clock cannot be assumed to be correct.
38 + regs[0] &= ~PCF8523_SECONDS_OS;
40 + err = regmap_write(pcf8523->regmap, PCF8523_REG_SECONDS,
45 + err = regmap_read(pcf8523->regmap, PCF8523_REG_SECONDS,
50 + if (value & PCF8523_SECONDS_OS)
56 tm->tm_sec = bcd2bin(regs[0] & 0x7f);
57 tm->tm_min = bcd2bin(regs[1] & 0x7f);