diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c index c68fec70607e..c3dcb8a0a1bf 100644 --- a/drivers/rtc/rtc-hym8563.c +++ b/drivers/rtc/rtc-hym8563.c @@ -103,12 +103,6 @@ static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm) ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf); - if (buf[0] & HYM8563_SEC_VL) { - dev_warn(&client->dev, - "no valid clock/calendar values available\n"); - return -EINVAL; - } - tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK); tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK); tm->tm_hour = bcd2bin(buf[2] & HYM8563_HOUR_MASK); @@ -525,6 +519,19 @@ static int hym8563_probe(struct i2c_client *client, { struct hym8563 *hym8563; int ret; + /* + * hym8563 initial time(2020_1_1_12:00:00), + * avoid hym8563 read time error + */ + struct rtc_time tm_read, tm = { + .tm_wday = 0, + .tm_year = 120, + .tm_mon = 0, + .tm_mday = 1, + .tm_hour = 12, + .tm_min = 0, + .tm_sec = 0, + }; hym8563 = devm_kzalloc(&client->dev, sizeof(*hym8563), GFP_KERNEL); if (!hym8563) @@ -561,6 +568,11 @@ static int hym8563_probe(struct i2c_client *client, dev_dbg(&client->dev, "rtc information is %s\n", (ret & HYM8563_SEC_VL) ? "invalid" : "valid"); + hym8563_rtc_read_time(&client->dev, &tm_read); + if (((tm_read.tm_year < 70) | (tm_read.tm_year > 200)) | + (tm_read.tm_mon == -1) | (rtc_valid_tm(&tm_read) != 0)) + hym8563_rtc_set_time(&client->dev, &tm); + hym8563->rtc = devm_rtc_device_register(&client->dev, client->name, &hym8563_rtc_ops, THIS_MODULE); if (IS_ERR(hym8563->rtc))