]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
rtc: pcf85063: adjust date format to adhere to the rtc_time spec
authorAlexander Feilke <alexander.feilke@ew.tq-group.com>
Fri, 22 May 2026 15:39:23 +0000 (17:39 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 5 Jun 2026 16:14:24 +0000 (10:14 -0600)
The rtc_time documentation in rtc_def.h notes a differences
to the common "struct time" that specifies tm_mon as 1 ... 12
and tm_year as year since 0. Also trim register values to valid bits.

Fixes: 1c2a2253f798 ("drivers: rtc: add PCF85063 support")
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Signed-off-by: Alexander Feilke <alexander.feilke@ew.tq-group.com>
drivers/rtc/pcf85063.c

index 737d4547aca0a224319da616b2e88faf582cb2ab..21640b039c1e60c09e37c6c1051422dcec2edc2b 100644 (file)
@@ -35,7 +35,9 @@ static int pcf85063_get_time(struct udevice *dev, struct rtc_time *tm)
        tm->tm_hour = bcd2bin(regs[2] & 0x3f);
        tm->tm_mday = bcd2bin(regs[3] & 0x3f);
        tm->tm_wday = regs[4] & 0x07;
-       tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1;
+       /* rtc register and rtc_time spec uses 1 - 12 */
+       tm->tm_mon = bcd2bin(regs[5] & 0x1f);
+       /* adjust rtc_time (years since 0) to match register spec */
        tm->tm_year = bcd2bin(regs[6]) + 2000;
 
        return 0;
@@ -50,12 +52,21 @@ static int pcf85063_set_time(struct udevice *dev, const struct rtc_time *tm)
                return -EINVAL;
        }
 
-       regs[0] = bin2bcd(tm->tm_sec);
+       /* hours, minutes and seconds */
+       regs[0] = bin2bcd(tm->tm_sec) & (~PCF85063_REG_SC_OS);
+
        regs[1] = bin2bcd(tm->tm_min);
        regs[2] = bin2bcd(tm->tm_hour);
+
+       /* Day of month, 1 - 31 */
        regs[3] = bin2bcd(tm->tm_mday);
-       regs[4] = tm->tm_wday;
-       regs[5] = bin2bcd(tm->tm_mon + 1);
+
+       /* Day of week 0 - 6 */
+       regs[4] = tm->tm_wday & 0x07;
+
+       /* rtc register and rtc_time spec uses 1 - 12 */
+       regs[5] = bin2bcd(tm->tm_mon);
+       /* adjust register to match rtc_time spec */
        regs[6] = bin2bcd(tm->tm_year % 100);
 
        return dm_i2c_write(dev, PCF85063_REG_SC, regs, sizeof(regs));