From 1c0795536a66187602ab55b203d28cbdf7d903a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=BB=84=E6=B6=9B?= Date: Thu, 31 Mar 2011 18:03:30 +0800 Subject: [PATCH] rtc: wm831x: init rtc when first run --- drivers/rtc/rtc-wm831x.c | 45 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c index b6c830b7a2f9..4a55af6f8265 100755 --- a/drivers/rtc/rtc-wm831x.c +++ b/drivers/rtc/rtc-wm831x.c @@ -424,6 +424,8 @@ static int wm831x_rtc_probe(struct platform_device *pdev) int per_irq = platform_get_irq_byname(pdev, "PER"); int alm_irq = platform_get_irq_byname(pdev, "ALM"); int ret = 0; + struct rtc_time tm; + //printk("wm831x_rtc_probe\n"); wm831x_rtc = kzalloc(sizeof(*wm831x_rtc), GFP_KERNEL); if (wm831x_rtc == NULL) @@ -432,38 +434,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, wm831x_rtc); wm831x_rtc->wm831x = wm831x; - #if 0 - /*set time when power on for debug*/ - ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1, - (0x1000000 >> 16) & 0xffff); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to write TIME_1: %d\n", ret); - return ret; - } - - ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_2, 0x100000 & 0xffff); - - if (ret < 0) { - dev_err(&pdev->dev, "Failed to write TIME_2: %d\n", ret); - return ret; - } - - ret = wm831x_reg_read(wm831x, WM831X_RTC_TIME_1); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to read TIME_2: %d\n", ret); - goto err; - } - printk("%s:WM831X_RTC_TIME_1=0x%x\n",__FUNCTION__,ret); - ret = wm831x_reg_read(wm831x, WM831X_RTC_TIME_2); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to read TIME_2: %d\n", ret); - goto err; - } - printk("%s:WM831X_RTC_TIME_2=0x%x\n",__FUNCTION__,ret); - -#endif - - ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL); if (ret < 0) { dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret); @@ -472,6 +442,17 @@ static int wm831x_rtc_probe(struct platform_device *pdev) if (ret & WM831X_RTC_ALM_ENA) wm831x_rtc->alarm_enabled = 1; + ret = wm831x_rtc_readtime(&pdev->dev, &tm); + if (ret < 0 || tm.tm_year < 111) { + if (ret) + dev_err(&pdev->dev, "Failed to read RTC time\n"); + else + dev_err(&pdev->dev, "Invalid RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", + 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_wday, + tm.tm_hour, tm.tm_min, tm.tm_sec); + wm831x_rtc_set_mmss(&pdev->dev, 1293883200); // 2011-01-01 12:00:00 + } + device_init_wakeup(&pdev->dev, 1); wm831x_rtc->rtc = rtc_device_register("wm831x", &pdev->dev, -- 2.34.1