git: 3e5fe3d5bf88 - main - pcf85063: Set RTC device to work in 24h mode

From: Wojciech Macek <wma_at_FreeBSD.org>
Date: Fri, 17 Dec 2021 10:09:56 UTC
The branch main has been updated by wma:

URL: https://cgit.FreeBSD.org/src/commit/?id=3e5fe3d5bf8812795e0b9f29f01c5e5cf5449871

commit 3e5fe3d5bf8812795e0b9f29f01c5e5cf5449871
Author:     Hubert Mazur <hum@semihalf.com>
AuthorDate: 2021-12-16 08:16:22 +0000
Commit:     Wojciech Macek <wma@FreeBSD.org>
CommitDate: 2021-12-17 10:07:07 +0000

    pcf85063: Set RTC device to work in 24h mode
    
    Sometimes the device did not set default hour mode setting correctly,
    which lead to conversion errors. Explicitly set device to work in 24h
    mode by clearing flag in register, instead of allowing defaults.
    
    Reviewed by:            imp
    Obtained from:          Semihalf
    Sponsored by:           Alstom Group
    Differential revision:  https://reviews.freebsd.org/D33497
---
 sys/dev/iicbus/rtc/pcf85063.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sys/dev/iicbus/rtc/pcf85063.c b/sys/dev/iicbus/rtc/pcf85063.c
index dad52239f061..af2417a497db 100644
--- a/sys/dev/iicbus/rtc/pcf85063.c
+++ b/sys/dev/iicbus/rtc/pcf85063.c
@@ -183,7 +183,7 @@ pcf85063_set_time(device_t dev, struct timespec *ts)
 	    sizeof(uint8_t), IIC_WAIT);
 
 	ts->tv_sec -= utc_offset();
-	clock_ts_to_bcd(ts, &bcd, ctrl_reg & PCF85063_CTRL1_TIME_FORMAT);
+	clock_ts_to_bcd(ts, &bcd, false);
 	clock_dbgprint_bcd(dev, CLOCK_DBG_WRITE, &bcd);
 
 	data.sec = bcd.sec;
@@ -194,11 +194,6 @@ pcf85063_set_time(device_t dev, struct timespec *ts)
 	data.mon = bcd.mon;
 	data.year = bcd.year;
 
-	/* Set this bit in case of 12-hour mode and pm hour. */
-	if (!(ctrl_reg & PCF85063_CTRL1_TIME_FORMAT))
-		if (bcd.ispm)
-			data.hour |= 0x20;
-
 	if (ts->tv_nsec > PCF85063_HALF_OF_SEC_NS)
 		data.sec++;
 
@@ -209,6 +204,8 @@ pcf85063_set_time(device_t dev, struct timespec *ts)
 		return (error);
 
 	ctrl_reg |= PCF85063_CTRL1_RTC_CLK_STOP;
+	/* Explicitly set 24-hour mode. */
+	ctrl_reg &= ~PCF85063_CTRL1_TIME_FORMAT;
 
 	error = iicdev_writeto(dev, PCF85063_CTRL1_REG, &ctrl_reg,
 	    sizeof(uint8_t), IIC_WAIT);