PM / clock_ops: Provide default runtime ops to users
authorRajendra Nayak <rnayak@codeaurora.org>
Thu, 23 Apr 2015 08:33:09 +0000 (14:03 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 May 2015 21:55:37 +0000 (23:55 +0200)
Most users of PM clocks do the extact same things in the runtime
suspend/resume callbacks. Provide them USE_PM_CLK_RUNTIME_OPS so
as to avoid/remove boilerplate code.

Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
Acked-by: Santosh Shilimkar <ssantosh@kernel.org>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/clock_ops.c
include/linux/pm_clock.h

index 7fdd0172605afe1be1f74fa90593932a97153787..8abea669c82c2192e3b3f9d715faf0c02c7edf98 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/clkdev.h>
 #include <linux/slab.h>
 #include <linux/err.h>
+#include <linux/pm_runtime.h>
 
 #ifdef CONFIG_PM
 
@@ -367,6 +368,43 @@ static int pm_clk_notify(struct notifier_block *nb,
        return 0;
 }
 
+int pm_clk_runtime_suspend(struct device *dev)
+{
+       int ret;
+
+       dev_dbg(dev, "%s\n", __func__);
+
+       ret = pm_generic_runtime_suspend(dev);
+       if (ret) {
+               dev_err(dev, "failed to suspend device\n");
+               return ret;
+       }
+
+       ret = pm_clk_suspend(dev);
+       if (ret) {
+               dev_err(dev, "failed to suspend clock\n");
+               pm_generic_runtime_resume(dev);
+               return ret;
+       }
+
+       return 0;
+}
+
+int pm_clk_runtime_resume(struct device *dev)
+{
+       int ret;
+
+       dev_dbg(dev, "%s\n", __func__);
+
+       ret = pm_clk_resume(dev);
+       if (ret) {
+               dev_err(dev, "failed to resume clock\n");
+               return ret;
+       }
+
+       return pm_generic_runtime_resume(dev);
+}
+
 #else /* !CONFIG_PM */
 
 /**
index 0b0039634410c158a22c3667b142856dfa4a66a1..25266c600021462c8f809a22451231820caf1b6e 100644 (file)
@@ -20,6 +20,16 @@ struct pm_clk_notifier_block {
 
 struct clk;
 
+#ifdef CONFIG_PM
+extern int pm_clk_runtime_suspend(struct device *dev);
+extern int pm_clk_runtime_resume(struct device *dev);
+#define USE_PM_CLK_RUNTIME_OPS \
+       .runtime_suspend = pm_clk_runtime_suspend, \
+       .runtime_resume = pm_clk_runtime_resume,
+#else
+#define USE_PM_CLK_RUNTIME_OPS
+#endif
+
 #ifdef CONFIG_PM_CLK
 static inline bool pm_clk_no_clocks(struct device *dev)
 {