summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Dumberger <andreas.dumberger@tqs.de>2012-04-12 12:49:12 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-04-12 13:12:12 -0700
commitbb58da08f01ee12561867fcd4385b82679ae7f6c (patch)
tree892e60c551aa5be4046fe20402c0cb9d2950a978
parent44e4360fa3384850d65dd36fb4e6e5f2f112709b (diff)
downloadlinux-bb58da08f01ee12561867fcd4385b82679ae7f6c.tar.gz
linux-bb58da08f01ee12561867fcd4385b82679ae7f6c.tar.bz2
linux-bb58da08f01ee12561867fcd4385b82679ae7f6c.zip
drivers/rtc/rtc-r9701.c: reset registers if invalid values are detected
hwclock refuses to set date/time if RTC registers contain invalid values. Check the date/time register values at probe time and initialize them to make hwclock happy. Signed-off-by: Andreas Dumberger <andreas.dumberger@tqs.de> Signed-off-by: Anatolij Gustschin <agust@denx.de> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/rtc/rtc-r9701.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 7f8e6c247935..33b6ba0afa0d 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -122,6 +122,7 @@ static const struct rtc_class_ops r9701_rtc_ops = {
static int __devinit r9701_probe(struct spi_device *spi)
{
struct rtc_device *rtc;
+ struct rtc_time dt;
unsigned char tmp;
int res;
@@ -132,6 +133,27 @@ static int __devinit r9701_probe(struct spi_device *spi)
return -ENODEV;
}
+ /*
+ * The device seems to be present. Now check if the registers
+ * contain invalid values. If so, try to write a default date:
+ * 2000/1/1 00:00:00
+ */
+ r9701_get_datetime(&spi->dev, &dt);
+ if (rtc_valid_tm(&dt)) {
+ dev_info(&spi->dev, "trying to repair invalid date/time\n");
+ dt.tm_sec = 0;
+ dt.tm_min = 0;
+ dt.tm_hour = 0;
+ dt.tm_mday = 1;
+ dt.tm_mon = 0;
+ dt.tm_year = 100;
+
+ if (r9701_set_datetime(&spi->dev, &dt)) {
+ dev_err(&spi->dev, "cannot repair RTC register\n");
+ return -ENODEV;
+ }
+ }
+
rtc = rtc_device_register("r9701",
&spi->dev, &r9701_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc))