rtc: mxc: use a second rtc clock
authorPhilippe Reynes <tremyfr@gmail.com>
Sun, 26 Jul 2015 21:37:50 +0000 (23:37 +0200)
committerShawn Guo <shawnguo@kernel.org>
Wed, 5 Aug 2015 12:03:46 +0000 (20:03 +0800)
The mxc RTC needs two clocks, one for the input
reference, and one for the IP. But this driver
was only using one clock (for the reference).
This patch add the second clock (for the IP).

Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Philippe Reynes <tremyfr@gmail.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
drivers/rtc/rtc-mxc.c

index 5fc292c2dfdf1b39548165cdbd03eb0dffdc5150..880d485d5cc13778aa377568e0fa95d9c0de2355 100644 (file)
@@ -79,7 +79,8 @@ struct rtc_plat_data {
        struct rtc_device *rtc;
        void __iomem *ioaddr;
        int irq;
-       struct clk *clk;
+       struct clk *clk_ref;
+       struct clk *clk_ipg;
        struct rtc_time g_rtc_alarm;
        enum imx_rtc_type devtype;
 };
@@ -373,17 +374,28 @@ static int mxc_rtc_probe(struct platform_device *pdev)
        if (IS_ERR(pdata->ioaddr))
                return PTR_ERR(pdata->ioaddr);
 
-       pdata->clk = devm_clk_get(&pdev->dev, NULL);
-       if (IS_ERR(pdata->clk)) {
-               dev_err(&pdev->dev, "unable to get clock!\n");
-               return PTR_ERR(pdata->clk);
+       pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
+       if (IS_ERR(pdata->clk_ipg)) {
+               dev_err(&pdev->dev, "unable to get ipg clock!\n");
+               return PTR_ERR(pdata->clk_ipg);
        }
 
-       ret = clk_prepare_enable(pdata->clk);
+       ret = clk_prepare_enable(pdata->clk_ipg);
        if (ret)
                return ret;
 
-       rate = clk_get_rate(pdata->clk);
+       pdata->clk_ref = devm_clk_get(&pdev->dev, "ref");
+       if (IS_ERR(pdata->clk_ref)) {
+               dev_err(&pdev->dev, "unable to get ref clock!\n");
+               ret = PTR_ERR(pdata->clk_ref);
+               goto exit_put_clk_ipg;
+       }
+
+       ret = clk_prepare_enable(pdata->clk_ref);
+       if (ret)
+               goto exit_put_clk_ipg;
+
+       rate = clk_get_rate(pdata->clk_ref);
 
        if (rate == 32768)
                reg = RTC_INPUT_CLK_32768HZ;
@@ -394,7 +406,7 @@ static int mxc_rtc_probe(struct platform_device *pdev)
        else {
                dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate);
                ret = -EINVAL;
-               goto exit_put_clk;
+               goto exit_put_clk_ref;
        }
 
        reg |= RTC_ENABLE_BIT;
@@ -402,7 +414,7 @@ static int mxc_rtc_probe(struct platform_device *pdev)
        if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) {
                dev_err(&pdev->dev, "hardware module can't be enabled!\n");
                ret = -EIO;
-               goto exit_put_clk;
+               goto exit_put_clk_ref;
        }
 
        platform_set_drvdata(pdev, pdata);
@@ -424,15 +436,17 @@ static int mxc_rtc_probe(struct platform_device *pdev)
                                  THIS_MODULE);
        if (IS_ERR(rtc)) {
                ret = PTR_ERR(rtc);
-               goto exit_put_clk;
+               goto exit_put_clk_ref;
        }
 
        pdata->rtc = rtc;
 
        return 0;
 
-exit_put_clk:
-       clk_disable_unprepare(pdata->clk);
+exit_put_clk_ref:
+       clk_disable_unprepare(pdata->clk_ref);
+exit_put_clk_ipg:
+       clk_disable_unprepare(pdata->clk_ipg);
 
        return ret;
 }
@@ -441,7 +455,8 @@ static int mxc_rtc_remove(struct platform_device *pdev)
 {
        struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 
-       clk_disable_unprepare(pdata->clk);
+       clk_disable_unprepare(pdata->clk_ref);
+       clk_disable_unprepare(pdata->clk_ipg);
 
        return 0;
 }