Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1330088
| From | Juergen Borleis <jbe@pengutronix.de> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 2/3] RTC/PCF85063: fix time/date reading |
| Date | 2016-02-09 12:00 +0100 |
| Message-ID | <r0ebx-2Tw-43@gated-at.bofh.it> (permalink) |
| References | <r0ebw-2Tw-15@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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>
---
drivers/rtc/rtc-pcf85063.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index 7f9caee..e0343e6 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 */
--
2.7.0.rc3
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH v2] RTC/PCF85063: fix reading/setting time/date Juergen Borleis <jbe@pengutronix.de> - 2016-02-09 12:00 +0100 [PATCH v2 1/3] RTC/PCF85063: simplify code to read the current time Juergen Borleis <jbe@pengutronix.de> - 2016-02-09 12:00 +0100 [PATCH v2 3/3] RTC/PCF85063: fix time/date setting Juergen Borleis <jbe@pengutronix.de> - 2016-02-09 12:00 +0100 [PATCH v2 2/3] RTC/PCF85063: fix time/date reading Juergen Borleis <jbe@pengutronix.de> - 2016-02-09 12:00 +0100
csiph-web