[PATCH] rtc-pcf50633: Fix month off-by-one error

Rask Ingemann Lambertsen rask at sygehus.dk
Mon Mar 2 00:14:44 CET 2009


   The PCF50633 stores a month value of 1-12, but the kernel wants 0-11.

Signed-off-by: Rask Ingemann Lambertsen <rask at sygehus.dk>

---

   Tested on a GTA02. Someone with a GTA01 should check if the same bug
exists in rtc-pcf50606.c too. It'll be in the logs if you booted today
2009-03-01 because the PCF thinks it's 2009-01-29. Then comes the effect of
the off-by-one error. From the logs:

pcf50633-rtc: PCF_TIME: 29.01.09 15:09:28	means 2009-01-29, but
pcf50633-rtc: RTC_TIME: 29.1.109 15:9:28	means 2009-02-29. :-(
pcf50633-rtc: hctosys: unable to read the hardware clock

 drivers/rtc/rtc-pcf50633.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index 1013634..8669815 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -71,7 +71,7 @@ static void pcf2rtc_time(struct rtc_time *rtc, struct pcf50633_time *pcf)
 	rtc->tm_hour = bcd2bin(pcf->time[PCF50633_TI_HOUR]);
 	rtc->tm_wday = bcd2bin(pcf->time[PCF50633_TI_WKDAY]);
 	rtc->tm_mday = bcd2bin(pcf->time[PCF50633_TI_DAY]);
-	rtc->tm_mon = bcd2bin(pcf->time[PCF50633_TI_MONTH]);
+	rtc->tm_mon = bcd2bin(pcf->time[PCF50633_TI_MONTH]) - 1;
 	rtc->tm_year = bcd2bin(pcf->time[PCF50633_TI_YEAR]) + 100;
 }
 
@@ -82,7 +82,7 @@ static void rtc2pcf_time(struct pcf50633_time *pcf, struct rtc_time *rtc)
 	pcf->time[PCF50633_TI_HOUR] = bin2bcd(rtc->tm_hour);
 	pcf->time[PCF50633_TI_WKDAY] = bin2bcd(rtc->tm_wday);
 	pcf->time[PCF50633_TI_DAY] = bin2bcd(rtc->tm_mday);
-	pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon);
+	pcf->time[PCF50633_TI_MONTH] = bin2bcd(rtc->tm_mon + 1);
 	pcf->time[PCF50633_TI_YEAR] = bin2bcd(rtc->tm_year % 100);
 }
 


-- 
Rask Ingemann Lambertsen
Danish law requires addresses in e-mail to be logged and stored for a year



More information about the openmoko-kernel mailing list