From 2f1852aeb0d855be0aed5abde612cd6f79608561 Mon Sep 17 00:00:00 2001 From: Choi Jaehyoung Date: Mon, 7 Aug 2017 14:27:10 +0900 Subject: [PATCH] [COMMON] rtc: rtc-s3c: Initialize BCD register 1) Reset values of BCD registers are undefined. Therefore, there is no guarantee that these registers are initialized to BCD values. Initialize BCD register in RTC probe function 2) BCD year register uses 12bit. Change-Id: I7ce7fb59db96b5347ff008d5806036b10a8b844f Signed-off-by: Choi Jaehyoung --- drivers/rtc/rtc-s3c.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index aae8fee95fc4..a26d03637d16 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c @@ -209,7 +209,7 @@ retry_get_time: rtc_tm->tm_hour = readb(info->base + S3C2410_RTCHOUR); rtc_tm->tm_mday = readb(info->base + S3C2410_RTCDATE); rtc_tm->tm_mon = readb(info->base + S3C2410_RTCMON); - rtc_tm->tm_year = readb(info->base + S3C2410_RTCYEAR); + rtc_tm->tm_year = readw(info->base + S3C2410_RTCYEAR); rtc_tm->tm_sec = readb(info->base + S3C2410_RTCSEC); /* the only way to work out whether the system was mid-update @@ -268,7 +268,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_RTCHOUR); writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_RTCDATE); writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); - writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); + writew(bin2bcd(year), info->base + S3C2410_RTCYEAR); s3c_rtc_disable_clk(info); @@ -291,7 +291,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) alm_tm->tm_hour = readb(info->base + S3C2410_ALMHOUR); alm_tm->tm_mon = readb(info->base + S3C2410_ALMMON); alm_tm->tm_mday = readb(info->base + S3C2410_ALMDATE); - alm_tm->tm_year = readb(info->base + S3C2410_ALMYEAR); + alm_tm->tm_year = readw(info->base + S3C2410_ALMYEAR); alm_en = readb(info->base + S3C2410_RTCALM); @@ -365,7 +365,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) if (year < 100 && year >= 0) { alrm_en |= S3C2410_RTCALM_YEAREN; - writeb(bin2bcd(year), info->base + S3C2410_ALMYEAR); + writew(bin2bcd(year), info->base + S3C2410_ALMYEAR); } if (tm->tm_mon < 12 && tm->tm_mon >= 0) { @@ -566,19 +566,14 @@ static int s3c_rtc_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); - /* Check RTC Time */ - if (s3c_rtc_gettime(&pdev->dev, &rtc_tm)) { - rtc_tm.tm_year = 100; - rtc_tm.tm_mon = 0; - rtc_tm.tm_mday = 1; - rtc_tm.tm_hour = 0; - rtc_tm.tm_min = 0; - rtc_tm.tm_sec = 0; - - s3c_rtc_settime(&pdev->dev, &rtc_tm); - - dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n"); - } + /* Initialize BCD register */ + rtc_tm.tm_year = 100; + rtc_tm.tm_mon = 0; + rtc_tm.tm_mday = 1; + rtc_tm.tm_hour = 0; + rtc_tm.tm_min = 0; + rtc_tm.tm_sec = 0; + s3c_rtc_settime(&pdev->dev, &rtc_tm); /* register RTC and exit */ info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, -- 2.20.1