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: 1c2a2253f7 ("drivers: rtc: add PCF85063 support")
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Signed-off-by: Alexander Feilke <alexander.feilke@ew.tq-group.com>
This commit is contained in:
committed by
Tom Rini
parent
3bf0e5d90c
commit
8763c0169d
+15
-4
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user