rtc: hym8563: check power down tag
authorhxy <hxy@rock-chips.com>
Wed, 5 Jan 2011 12:05:23 +0000 (20:05 +0800)
committerhxy <hxy@rock-chips.com>
Wed, 5 Jan 2011 12:05:23 +0000 (20:05 +0800)
drivers/rtc/rtc-HYM8563.c

index 1604836aff4b06f806604619243afee5852b99ae..64df8521594f5307d7040d407d2f38a9178b033c 100644 (file)
@@ -323,6 +323,7 @@ static const struct rtc_class_ops hym8563_rtc_ops = {
 static int __devinit  hym8563_probe(struct i2c_client *client,const struct i2c_device_id *id)
 {
        int rc = 0;
+       u8 reg = 0;
        struct hym8563 *hym8563;
        struct rtc_device *rtc = NULL;
        struct rtc_time tm_read, tm = {
@@ -352,6 +353,14 @@ static int __devinit  hym8563_probe(struct i2c_client *client,const struct i2c_d
        }
        hym8563->client = client;
        hym8563_init_device(client);
+
+       // check power down 
+       hym8563_i2c_read_regs(client,RTC_SEC,&reg,1);
+       if (reg&0x80) {
+               dev_info(&client->dev, "clock/calendar information is no longer guaranteed\n");
+               hym8563_set_time(client, &tm);
+       }
+
        hym8563_read_datetime(client, &tm_read);        //read time from hym8563
        
        if(((tm_read.tm_year < 70) | (tm_read.tm_year > 137 )) | (tm_read.tm_mon == -1) | (rtc_valid_tm(&tm_read) != 0)) //if the hym8563 haven't initialized