diff options
| author | Alexander Feilke <[email protected]> | 2026-05-22 17:39:23 +0200 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-06-05 10:14:24 -0600 |
| commit | 8763c0169d8d8f16ee8c88fb9672f18638f0bba8 (patch) | |
| tree | f45de990a8fb57fc7b582ce7e759a72dd633dec5 /drivers | |
| parent | 3bf0e5d90c0c74e7dacc185558516cdf1e3b045c (diff) | |
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 <[email protected]>
Signed-off-by: Alexander Feilke <[email protected]>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/rtc/pcf85063.c | 19 |
1 files changed, 15 insertions, 4 deletions
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)); |
