Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1365917

[PATCH 8/8] rtc: m41t80: handle oscillator failure bit

From Mylène Josserand <mylene.josserand@free-electrons.com>
Newsgroups linux.kernel
Subject [PATCH 8/8] rtc: m41t80: handle oscillator failure bit
Date 2016-03-29 09:00 +0200
Message-ID <rhVN8-2iO-23@gated-at.bofh.it> (permalink)
References <rhVN7-2iO-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Handle the Oscillator Failure (OF) bit on each read of date-time.
If the OF is set, an error is returned (-EINVAL) instead of the date-time.
The OF bit is cleared each time the date is set.

Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com>
---
 drivers/rtc/rtc-m41t80.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 660a734..64d66a9 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -56,6 +56,7 @@
 #define M41T80_ALMON_AFE	BIT(7)	/* AFE: AF Enable Bit */
 #define M41T80_ALMON_SQWE	BIT(6)	/* SQWE: SQW Enable Bit */
 #define M41T80_ALHOUR_HT	BIT(6)	/* HT: Halt Update Bit */
+#define M41T80_FLAGS_OF		BIT(2)	/* OF: Oscillator Failure Bit */
 #define M41T80_FLAGS_AF		BIT(6)	/* AF: Alarm Flag Bit */
 #define M41T80_FLAGS_BATT_LOW	BIT(4)	/* BL: Battery Low Bit */
 #define M41T80_WATCHDOG_RB2	BIT(7)	/* RB: Watchdog resolution */
@@ -130,7 +131,16 @@ static int m41t80_get_datetime(struct i2c_client *client,
 			       struct rtc_time *tm)
 {
 	unsigned char buf[8];
-	int err;
+	int err, flags;
+
+	flags = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
+	if (flags < 0)
+		return flags;
+
+	if (flags & M41T80_FLAGS_OF) {
+		dev_err(&client->dev, "Oscillator failure, data is invalid.\n");
+		return -EINVAL;
+	}
 
 	err = i2c_smbus_read_i2c_block_data(client, M41T80_REG_SSEC,
 					    sizeof(buf), buf);
@@ -155,7 +165,7 @@ static int m41t80_get_datetime(struct i2c_client *client,
 static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 {
 	unsigned char buf[8];
-	int err;
+	int err, flags;
 
 	if (tm->tm_year < 100 || tm->tm_year > 199)
 		return -EINVAL;
@@ -176,6 +186,17 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 		return err;
 	}
 
+	/* Clear the OF bit of Flags Register */
+	flags = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
+	if (flags < 0)
+		return flags;
+
+	if (i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS,
+				      flags & ~M41T80_FLAGS_OF)) {
+		dev_err(&client->dev, "Unable to write flags register\n");
+		return -EIO;
+	}
+
 	return err;
 }
 
-- 
2.8.0.rc3

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/8] rtc: m41t80: update and add functionalities Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200
  [PATCH 1/8] rtc: m41t80: update sysfs entries export Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200
  [PATCH 8/8] rtc: m41t80: handle oscillator failure bit Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200
  [PATCH 6/8] rtc: m41t80: add alarm functionality Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200
  [PATCH 4/8] rtc: m41t80: add the use of 'BIT' macro Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200
  [PATCH 2/8] rtc: m41t80: remove proc macro Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200
  [PATCH 3/8] rtc: m41t80: replace i2c functions to smbus ones Mylène Josserand   <mylene.josserand@free-electrons.com> - 2016-03-29 09:00 +0200

csiph-web