diff options
author | Juergen Borleis <jbe@pengutronix.de> | 2016-02-09 13:57:26 +0300 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2016-03-14 19:08:17 +0300 |
commit | 6cc4c8b1e3790c63b2e1b6d9b25d2bda6e406572 (patch) | |
tree | acabf4ff6d12954bb5c4d741cef57d1fd3e83d7a /drivers/rtc/rtc-pcf85063.c | |
parent | 7b5768486a910532885f01b9d2dad4818c8b3be1 (diff) | |
download | linux-6cc4c8b1e3790c63b2e1b6d9b25d2bda6e406572.tar.xz |
rtc: pcf85063: fix time/date reading
Check if the RTC signals an invalid time/date (due to a battery power loss
for example). In this case ignore the time/date until it is really set again.
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc/rtc-pcf85063.c')
-rw-r--r-- | drivers/rtc/rtc-pcf85063.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c index 7f9caee5f4ab..e0343e6aeb31 100644 --- a/drivers/rtc/rtc-pcf85063.c +++ b/drivers/rtc/rtc-pcf85063.c @@ -22,6 +22,7 @@ #define PCF85063_REG_CTRL2 0x01 #define PCF85063_REG_SC 0x04 /* datetime */ +#define PCF85063_REG_SC_OS 0x80 #define PCF85063_REG_MN 0x05 #define PCF85063_REG_HR 0x06 #define PCF85063_REG_DM 0x07 @@ -62,6 +63,12 @@ static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm) return -EIO; } + /* if the clock has lost its power it makes no sense to use its time */ + if (regs[0] & PCF85063_REG_SC_OS) { + dev_warn(&client->dev, "Power loss detected, invalid time\n"); + return -EINVAL; + } + tm->tm_sec = bcd2bin(regs[0] & 0x7F); tm->tm_min = bcd2bin(regs[1] & 0x7F); tm->tm_hour = bcd2bin(regs[2] & 0x3F); /* rtc hr 0-23 */ |