[U-Boot-Users] [PATCH] m41t62.c wday fix

Paul VanGraafeiland pvg at pt.com
Sat Jul 19 18:36:43 CEST 2008


The range for the "Day of Week" field of the m41t62 RTC is 1 thru 7 while 
the range for tm_wday is 0 thru 6.  The code didn't accommodate this 
difference in ranges.  The patch takes it into account.

Signed-off-by: Paul VanGraafeiland <pvg at pt.com>
---

diff -up a/drivers/rtc/m41t62.c b/drivers/rtc/m41t62.c 
--- a/drivers/rtc/m41t62.c      2008-07-19 12:19:45.000000000 -0400
+++ b/drivers/rtc/m41t62.c      2008-07-19 12:07:08.000000000 -0400
@@ -80,7 +80,7 @@ int rtc_get(struct rtc_time *tm)
        tm->tm_min = BCD2BIN(buf[M41T62_REG_MIN] & 0x7f);
        tm->tm_hour = BCD2BIN(buf[M41T62_REG_HOUR] & 0x3f);
        tm->tm_mday = BCD2BIN(buf[M41T62_REG_DAY] & 0x3f);
-       tm->tm_wday = buf[M41T62_REG_WDAY] & 0x07;
+       tm->tm_wday = (buf[M41T62_REG_WDAY] - 1) & 0x07;
        tm->tm_mon = BCD2BIN(buf[M41T62_REG_MON] & 0x1f);
 
        /* assume 20YY not 19YY, and ignore the Century Bit */
@@ -115,7 +115,7 @@ void rtc_set(struct rtc_time *tm)
        buf[M41T62_REG_HOUR] =
                BIN2BCD(tm->tm_hour) | (buf[M41T62_REG_HOUR] & ~0x3f) ;
        buf[M41T62_REG_WDAY] =
-               (tm->tm_wday & 0x07) | (buf[M41T62_REG_WDAY] & ~0x07);
+               ((tm->tm_wday + 1) & 0x07) | (buf[M41T62_REG_WDAY] & 
~0x07);
        buf[M41T62_REG_DAY] =
                BIN2BCD(tm->tm_mday) | (buf[M41T62_REG_DAY] & ~0x3f);
        buf[M41T62_REG_MON] =




More information about the U-Boot mailing list