Message ID | 497041B1.5000501@visionsystems.de |
---|---|
State | Rejected, archived |
Headers | show |
Yegor Yefremov wrote: > David Brownell wrote: >> On Thursday 15 January 2009, Yegor Yefremov wrote: >> >>> we are maintaining Linux kernel for our OpenRISC device family like >>> Alekto and Alena. Both devices are using RTC DS1337 chip from Maxim. >>> Sometimes it happens that the RTC provides invalid values such as 32 >>> days or 13th month etc. The RTC is still working properly, but due >>> to this check rtc_valid_tm() the time in the RTC cannot be changed, >>> >> >> That would be a bug in whatever version of hwclock you're using. >> I recall such a bug getting discussed, and fixed, a while back. >> >> Basically, if you're setting the clock, you don't need to read >> it first... >> >> - Dave >> > I see your point, but then the drivers/rtc/hctosys.c should be changed > not to check the correctness of returned time value but to parse the > returned err value. See the diff file to 2.6.29-rc1. > > - Yegor >> >> >>> because ds1307_get_time() comes with error. I think it is a matter >>> of application such as hwclock to check if the time value returned >>> is valid or not, but as long as I2C communication is working without >>> errors the read call should be successful. For example rtc_hctosys() >>> from /driver/rtc/hctosys.c is making this check itself. To throw a >>> kernel warning were also a solution. What do you think about this? >>> >> >> >> > My opinion is that nothing should be changed in the kernel. Instead use user space script during boot this script is tested with BusyBox v1.10.1 #!/bin/sh year=`date +"%Y"` default_year=2009 if [ "$year" -lt "$default_year" ] ; then date -D "%Y.%m.%d" $default_year.01.01 > /dev/null hwclock -w echo "setting date to default `date`" fi you can change default_year to 1970 if you like because when rtc_hctosys function fails system default time is set to 1970 To me it appears that if `hwclock` returns error (because of rtc_read_time error) the `hwclock -w` sill works (so that rtc_write_time works) JR --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. -~----------~----~----~----~------~----~------~--~---
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c index 33c0e98..446ad06 100644 --- a/drivers/rtc/hctosys.c +++ b/drivers/rtc/hctosys.c @@ -36,30 +36,29 @@ static int __init rtc_hctosys(void) err = rtc_read_time(rtc, &tm); if (err == 0) { - err = rtc_valid_tm(&tm); - if (err == 0) { - struct timespec tv; + struct timespec tv; - tv.tv_nsec = NSEC_PER_SEC >> 1; + tv.tv_nsec = NSEC_PER_SEC >> 1; - rtc_tm_to_time(&tm, &tv.tv_sec); + rtc_tm_to_time(&tm, &tv.tv_sec); - do_settimeofday(&tv); + do_settimeofday(&tv); - dev_info(rtc->dev.parent, - "setting system clock to " - "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned int) tv.tv_sec); - } - else - dev_err(rtc->dev.parent, - "hctosys: invalid date/time\n"); + dev_info(rtc->dev.parent, + "setting system clock to " + "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, + (unsigned int) tv.tv_sec); } - else + else if(err == -EIO){ dev_err(rtc->dev.parent, "hctosys: unable to read the hardware clock\n"); + } + else if(err == -EINVAL){ + dev_err(rtc->dev.parent, + "hctosys: invalid date/time\n"); + } rtc_class_close(rtc);