bcm27xx: 6.1: add kernel patches
[openwrt/staging/stintel.git] / target / linux / bcm27xx / patches-6.1 / 950-0356-rtc-pcf8523-Fix-oscillator-stop-bit-handling.patch
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
5
6 See: https://github.com/raspberrypi/firmware/issues/1065
7
8 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
9 ---
10 drivers/rtc/rtc-pcf8523.c | 29 +++++++++++++++++++++++++++--
11 1 file changed, 27 insertions(+), 2 deletions(-)
12
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
16 {
17 struct pcf8523 *pcf8523 = dev_get_drvdata(dev);
18 u8 regs[7];
19 + u32 value;
20 int err;
21
22 err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_SECONDS, regs,
23 @@ -107,8 +108,32 @@ static int pcf8523_rtc_read_time(struct
24 if (err < 0)
25 return err;
26
27 - if (regs[0] & PCF8523_SECONDS_OS)
28 - return -EINVAL;
29 + if (regs[0] & PCF8523_SECONDS_OS) {
30 + /*
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.
36 + */
37 +
38 + regs[0] &= ~PCF8523_SECONDS_OS;
39 +
40 + err = regmap_write(pcf8523->regmap, PCF8523_REG_SECONDS,
41 + regs[0]);
42 + if (err < 0)
43 + return err;
44 +
45 + err = regmap_read(pcf8523->regmap, PCF8523_REG_SECONDS,
46 + &value);
47 + if (err < 0)
48 + return err;
49 +
50 + if (value & PCF8523_SECONDS_OS)
51 + return -EAGAIN;
52 +
53 + regs[0] = value;
54 + }
55
56 tm->tm_sec = bcd2bin(regs[0] & 0x7f);
57 tm->tm_min = bcd2bin(regs[1] & 0x7f);