drivers: rtc: correct week day for mc146818
PATCH v2 1/1 drivers: rtc: correct week day for mc146818
For qemu-x86 the date command produces wrong days of the week:
Date: 2018-07-06 (Saturday) Time: 18:02:03
Date: 2018-07-07 (unknown day) Time: 21:02:06
According to a comment in the Linux driver the mc146818 only updates the day of the week if the register value is non-zero.
Sunday is 1, saturday is 7 unlike in U-Boot (see data sheet
https://www.nxp.com/docs/en/data-sheet/MC146818.pdf).
So let's use our library function to determine the day of the week.
---
v2
the day of the week must be calculated after filling the rtc_tm
--- drivers/rtc/mc146818.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/rtc/mc146818.c +6 -2
@@ -81,7 +81,7 @@ static void mc146818_write8(int reg, uchar val)static int mc146818_get (struct rtc_time *tmp) { -uchar sec, min, hour, mday, wday, mon, year; + uchar sec, min, hour, mday, wday __attribute__((unused)),mon, year;/* here check if rtc can be accessed */ while ((mc146818_read8 (RTC_CONFIG_A ) &0x80 ) ==0x80 )
@@ -109,7 +109,6 @@ static int mc146818_get(struct rtc_time *tmp) tmp->tm_mday =bcd2bin (mday &0x3f ); tmp->tm_mon =bcd2bin (mon &0x1f ); tmp->tm_year =bcd2bin (year); - tmp->tm_wday =bcd2bin (wday &0x07 );if (tmp->tm_year <70 ) tmp->tm_year +=2000 ;
@@ -118,6 +117,11 @@ static int mc146818_get(struct rtc_time *tmp) tmp->tm_yday =0 ; tmp->tm_isdst =0 ; +/* +* The mc146818 only updates wday if it is non-zero, sunday is 1 +* saturday is 7. So let's use our library routine. +*/ +rtc_calc_weekday (tmp);#ifdef RTC_DEBUG printf("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
Signature · 1 line
2.18.0
PATCH v2 1/1 drivers: rtc: correct week day for mc146818
Quoted 7 lines · Heinrich Schuchardt
For qemu-x86 the date command produces wrong days of the week:
Date: 2018-07-06 (Saturday) Time: 18:02:03
Date: 2018-07-07 (unknown day) Time: 21:02:06According to a comment in the Linux driver the mc146818 only updates the day of the week if the register value is non-zero.
Quoted 6 lines
Sunday is 1, saturday is 7 unlike in U-Boot (see data sheet
https://www.nxp.com/docs/en/data-sheet/MC146818.pdf).So let's use our library function to determine the day of the week.
Signed-off-by Heinrich Schuchardt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/2603dafb/attachment.sig>