Thread (12 messages) 12 messages, 3 authors, 2016-08-15

[rtc-linux] RE: [PATCH v2 2/2] rtc: bq32k: Fix handling of oscillator failure flag

From: Jan Östlund <hidden>
Date: 2016-08-15 08:46:04
Also in: lkml
Subsystem: real time clock (rtc) subsystem, the rest · Maintainers: Alexandre Belloni, Linus Torvalds

Signed-off-by: Jan =C3=96stlund <redacted>

-----Original Message-----
From: Daniel Romell [mailto:danielromell@gmail.com]=20
Sent: den 11 augusti 2016 13:32
To: a.zummo@towertech.it
Cc: alexandre.belloni@free-electrons.com; rtc-linux@googlegroups.com; linux=
-kernel@vger.kernel.org; Daniel Romell [off-list ref]; Jan =C3=96stlund <jao=
@hms.se>; Magnus Olsson [off-list ref]
Subject: [PATCH v2 2/2] rtc: bq32k: Fix handling of oscillator failure flag

From: Jan =C3=96stlund <redacted>

While the oscillator failure flag is set, the RTC registers
should be considered invalid. bq32k_rtc_read_time() now
returns an error instead of an invalid time.

The failure flag is cleared the next time the clock is set.

Signed-off-by: Daniel Romell <redacted>
---
 drivers/rtc/rtc-bq32k.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 5a0c137..3977424 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struc=
t rtc_time *tm)
 	if (error)
 		return error;
=20
+	/*
+	 * In case of oscillator failure, the register contents should be
+	 * considered invalid. The flag is cleared the next time the RTC is set.
+	 */
+	if (regs.minutes & BQ32K_OF)
+		return -EINVAL;
+
 	tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
 	tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
 	tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
@@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client,
=20
 	/* Check Oscillator Failure flag */
 	error =3D bq32k_read(dev, &reg, BQ32K_MINUTES, 1);
-	if (!error && (reg & BQ32K_OF)) {
-		dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
-		reg &=3D ~BQ32K_OF;
-		error =3D bq32k_write(dev, &reg, BQ32K_MINUTES, 1);
-	}
 	if (error)
 		return error;
+	if (reg & BQ32K_OF)
+		dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
=20
 	if (client->dev.of_node)
 		trickle_charger_of_init(dev, client->dev.of_node);
--=20
2.7.4

--=20
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "=
rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help