linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: pcf8523: fix for stop bit
@ 2022-08-29 12:46 paulmn
  2022-11-16 22:21 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: paulmn @ 2022-08-29 12:46 UTC (permalink / raw)
  To: alexandre.belloni; +Cc: paulmn, Alessandro Zummo, linux-rtc, linux-kernel

Bugfix for an issue detected when a goldcap capacitor gets
fully discharged due to a long absence of the power supply,
and then recharges again. The RTC failed to continue to keep
the real-time clock.

This was caused by the incorrect handling of the STOP bit in
the RTC internal register.  This fix solves the problem.

Signed-off-by: paulmn <paulmn@axis.com>
---
 drivers/rtc/rtc-pcf8523.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index 6174b3fd4b98..92de99f11a7a 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -99,24 +99,24 @@ static irqreturn_t pcf8523_irq(int irq, void *dev_id)
 static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
 	struct pcf8523 *pcf8523 = dev_get_drvdata(dev);
-	u8 regs[7];
+	u8 regs[10];
 	int err;
 
-	err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_SECONDS, regs,
+	err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_CONTROL1, regs,
 			       sizeof(regs));
 	if (err < 0)
 		return err;
 
-	if (regs[0] & PCF8523_SECONDS_OS)
+	if ((regs[0] & PCF8523_CONTROL1_STOP) || (regs[3] & PCF8523_SECONDS_OS))
 		return -EINVAL;
 
-	tm->tm_sec = bcd2bin(regs[0] & 0x7f);
-	tm->tm_min = bcd2bin(regs[1] & 0x7f);
-	tm->tm_hour = bcd2bin(regs[2] & 0x3f);
-	tm->tm_mday = bcd2bin(regs[3] & 0x3f);
-	tm->tm_wday = regs[4] & 0x7;
-	tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1;
-	tm->tm_year = bcd2bin(regs[6]) + 100;
+	tm->tm_sec = bcd2bin(regs[3] & 0x7f);
+	tm->tm_min = bcd2bin(regs[4] & 0x7f);
+	tm->tm_hour = bcd2bin(regs[5] & 0x3f);
+	tm->tm_mday = bcd2bin(regs[6] & 0x3f);
+	tm->tm_wday = regs[7] & 0x7;
+	tm->tm_mon = bcd2bin(regs[8] & 0x1f) - 1;
+	tm->tm_year = bcd2bin(regs[9]) + 100;
 
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtc: pcf8523: fix for stop bit
  2022-08-29 12:46 [PATCH] rtc: pcf8523: fix for stop bit paulmn
@ 2022-11-16 22:21 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2022-11-16 22:21 UTC (permalink / raw)
  To: paulmn; +Cc: linux-kernel, Alessandro Zummo, linux-rtc

On Mon, 29 Aug 2022 14:46:39 +0200, paulmn wrote:
> Bugfix for an issue detected when a goldcap capacitor gets
> fully discharged due to a long absence of the power supply,
> and then recharges again. The RTC failed to continue to keep
> the real-time clock.
> 
> This was caused by the incorrect handling of the STOP bit in
> the RTC internal register.  This fix solves the problem.
> 
> [...]

Applied, thanks!

[1/1] rtc: pcf8523: fix for stop bit
      commit: fe0157ba679dc95407dd5eae6550a4ceaea75040

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-16 22:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-29 12:46 [PATCH] rtc: pcf8523: fix for stop bit paulmn
2022-11-16 22:21 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).