rtc: omap: prevent disabling of clock/module during suspend
authorTero Kristo <t-kristo@ti.com>
Thu, 27 Oct 2016 05:57:26 +0000 (11:27 +0530)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Fri, 4 Nov 2016 22:11:39 +0000 (23:11 +0100)
If RTC is running from an internal clock source, the RTC module can't
be disabled; otherwise it stops ticking completely. Current suspend
handler implementation disables the clock/module unconditionally,
instead fix this by disabling the clock only if we are running on
external clock source, which is not affected by suspend.

The prevention of disabling the clock must be done via implementing
the runtime_pm handlers for the device, and returning an error code
from the runtime suspend handler; otherwise OMAP core PM will disable
the clocks for the driver.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
drivers/rtc/rtc-omap.c

index dddaa60871b98cac8c950dc9a97a4f97529725fd..51e52446eacb8f4d1e32821fd9c2d6da019825f3 100644 (file)
@@ -147,6 +147,7 @@ struct omap_rtc {
        u8 interrupts_reg;
        bool is_pmic_controller;
        bool has_ext_clk;
+       bool is_suspending;
        const struct omap_rtc_device_type *type;
        struct pinctrl_dev *pctldev;
 };
@@ -900,8 +901,7 @@ static int omap_rtc_suspend(struct device *dev)
                rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
        rtc->type->lock(rtc);
 
-       /* Disable the clock/module */
-       pm_runtime_put_sync(dev);
+       rtc->is_suspending = true;
 
        return 0;
 }
@@ -910,9 +910,6 @@ static int omap_rtc_resume(struct device *dev)
 {
        struct omap_rtc *rtc = dev_get_drvdata(dev);
 
-       /* Enable the clock/module so that we can access the registers */
-       pm_runtime_get_sync(dev);
-
        rtc->type->unlock(rtc);
        if (device_may_wakeup(dev))
                disable_irq_wake(rtc->irq_alarm);
@@ -920,11 +917,34 @@ static int omap_rtc_resume(struct device *dev)
                rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg);
        rtc->type->lock(rtc);
 
+       rtc->is_suspending = false;
+
        return 0;
 }
 #endif
 
-static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume);
+#ifdef CONFIG_PM
+static int omap_rtc_runtime_suspend(struct device *dev)
+{
+       struct omap_rtc *rtc = dev_get_drvdata(dev);
+
+       if (rtc->is_suspending && !rtc->has_ext_clk)
+               return -EBUSY;
+
+       return 0;
+}
+
+static int omap_rtc_runtime_resume(struct device *dev)
+{
+       return 0;
+}
+#endif
+
+static const struct dev_pm_ops omap_rtc_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(omap_rtc_suspend, omap_rtc_resume)
+       SET_RUNTIME_PM_OPS(omap_rtc_runtime_suspend,
+                          omap_rtc_runtime_resume, NULL)
+};
 
 static void omap_rtc_shutdown(struct platform_device *pdev)
 {