From: Alexander Feilke Date: Fri, 22 May 2026 15:39:23 +0000 (+0200) Subject: rtc: pcf85063: adjust date format to adhere to the rtc_time spec X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8763c0169d8d8f16ee8c88fb9672f18638f0bba8;p=thirdparty%2Fu-boot.git rtc: pcf85063: adjust date format to adhere to the rtc_time spec 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 Signed-off-by: Alexander Feilke --- diff --git a/drivers/rtc/pcf85063.c b/drivers/rtc/pcf85063.c index 737d4547aca..21640b039c1 100644 --- a/drivers/rtc/pcf85063.c +++ b/drivers/rtc/pcf85063.c @@ -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));