From 815c9a084e62d700ab5487974b63035e772a29a4 Mon Sep 17 00:00:00 2001 From: Elaine Zhang Date: Tue, 15 Sep 2020 17:02:40 +0800 Subject: [PATCH] rtc: hym8563: set init time remove the buf[0] & HYM8563_SEC_VL, it's unsuitable for some hym8563. set rtc init time for first power on. Change-Id: Iaa207d554d9df9ad8f138fc2f196c8a7a991b141 Signed-off-by: Elaine Zhang --- drivers/rtc/rtc-hym8563.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c index 0fb79c4afb46..dbf87d57f180 100644 --- a/drivers/rtc/rtc-hym8563.c +++ b/drivers/rtc/rtc-hym8563.c @@ -97,12 +97,6 @@ static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm) if (ret < 0) return ret; - 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); @@ -519,6 +513,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) @@ -555,6 +562,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))