LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* PM: add two device managed helpers
@ 2021-07-27 21:02 Dmitry Baryshkov
  2021-07-27 21:02 ` [PATCH 1/2] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dmitry Baryshkov @ 2021-07-27 21:02 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman
  Cc: linux-pm, linux-kernel, Andy Gross, Bjorn Andersson, linux-arm-msm

Qualcomm clock controller code (and most probably other drivers) would
benefit from having devres helpers for pm_runtime_enable() and
pm_clk_create(). Add those two helpers.

----------------------------------------------------------------
Dmitry Baryshkov (2):
      PM: runtime: add devm_pm_runtime_enable helper
      PM: clk: add devm_pm_clk_create helper

 drivers/base/power/clock_ops.c | 17 +++++++++++++++++
 drivers/base/power/runtime.c   | 17 +++++++++++++++++
 include/linux/pm_clock.h       |  5 +++++
 include/linux/pm_runtime.h     |  4 ++++
 4 files changed, 43 insertions(+)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] PM: runtime: add devm_pm_runtime_enable helper
  2021-07-27 21:02 PM: add two device managed helpers Dmitry Baryshkov
@ 2021-07-27 21:02 ` Dmitry Baryshkov
  2021-07-27 21:02 ` [PATCH 2/2] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Baryshkov @ 2021-07-27 21:02 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman
  Cc: linux-pm, linux-kernel, Andy Gross, Bjorn Andersson, linux-arm-msm

Add helper function handling typical driver action: call
pm_runtime_enable at the probe() time and disable it during remove().

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/base/power/runtime.c | 17 +++++++++++++++++
 include/linux/pm_runtime.h   |  4 ++++
 2 files changed, 21 insertions(+)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 8a66eaf731e4..ec94049442b9 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1447,6 +1447,23 @@ void pm_runtime_enable(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(pm_runtime_enable);
 
+static void pm_runtime_disable_action(void *data)
+{
+	pm_runtime_disable(data);
+}
+
+/**
+ * devm_pm_runtime_enable - devres-enabled version of pm_runtime_enable.
+ * @dev: Device to handle.
+ */
+int devm_pm_runtime_enable(struct device *dev)
+{
+	pm_runtime_enable(dev);
+
+	return devm_add_action_or_reset(dev, pm_runtime_disable_action, dev);
+}
+EXPORT_SYMBOL_GPL(devm_pm_runtime_enable);
+
 /**
  * pm_runtime_forbid - Block runtime PM of a device.
  * @dev: Device to handle.
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index aab8b35e9f8a..222da43b7096 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -59,6 +59,8 @@ extern void pm_runtime_put_suppliers(struct device *dev);
 extern void pm_runtime_new_link(struct device *dev);
 extern void pm_runtime_drop_link(struct device_link *link);
 
+extern int devm_pm_runtime_enable(struct device *dev);
+
 /**
  * pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter.
  * @dev: Target device.
@@ -253,6 +255,8 @@ static inline void __pm_runtime_disable(struct device *dev, bool c) {}
 static inline void pm_runtime_allow(struct device *dev) {}
 static inline void pm_runtime_forbid(struct device *dev) {}
 
+static inline int devm_pm_runtime_enable(struct device *dev) { return 0; }
+
 static inline void pm_suspend_ignore_children(struct device *dev, bool enable) {}
 static inline void pm_runtime_get_noresume(struct device *dev) {}
 static inline void pm_runtime_put_noidle(struct device *dev) {}
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] PM: clk: add devm_pm_clk_create helper
  2021-07-27 21:02 PM: add two device managed helpers Dmitry Baryshkov
  2021-07-27 21:02 ` [PATCH 1/2] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
@ 2021-07-27 21:02 ` Dmitry Baryshkov
  2021-07-28  6:23 ` PM: add two device managed helpers Greg Kroah-Hartman
  2021-07-28 10:40 ` Pavel Machek
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Baryshkov @ 2021-07-27 21:02 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman
  Cc: linux-pm, linux-kernel, Andy Gross, Bjorn Andersson, linux-arm-msm

Add devm_pm_clk_create helper, devres-enabled version of the
pm_clk_create(), which will call pm_clk_destroy at the correct time.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/base/power/clock_ops.c | 17 +++++++++++++++++
 include/linux/pm_clock.h       |  5 +++++
 2 files changed, 22 insertions(+)

diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 0251f3e6e61d..4110c19c08dc 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -519,6 +519,23 @@ void pm_clk_destroy(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(pm_clk_destroy);
 
+static void pm_clk_destroy_action(void *data)
+{
+	pm_clk_destroy(data);
+}
+
+int devm_pm_clk_create(struct device *dev)
+{
+	int ret;
+
+	ret = pm_clk_create(dev);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, pm_clk_destroy_action, dev);
+}
+EXPORT_SYMBOL_GPL(devm_pm_clk_create);
+
 /**
  * pm_clk_suspend - Disable clocks in a device's PM clock list.
  * @dev: Device to disable the clocks for.
diff --git a/include/linux/pm_clock.h b/include/linux/pm_clock.h
index 8ddc7860e131..ada3a0ab10bf 100644
--- a/include/linux/pm_clock.h
+++ b/include/linux/pm_clock.h
@@ -47,6 +47,7 @@ extern void pm_clk_remove(struct device *dev, const char *con_id);
 extern void pm_clk_remove_clk(struct device *dev, struct clk *clk);
 extern int pm_clk_suspend(struct device *dev);
 extern int pm_clk_resume(struct device *dev);
+extern int devm_pm_clk_create(struct device *dev);
 #else
 static inline bool pm_clk_no_clocks(struct device *dev)
 {
@@ -83,6 +84,10 @@ static inline void pm_clk_remove(struct device *dev, const char *con_id)
 static inline void pm_clk_remove_clk(struct device *dev, struct clk *clk)
 {
 }
+static inline int devm_pm_clk_create(struct device *dev)
+{
+	return -EINVAL;
+}
 #endif
 
 #ifdef CONFIG_HAVE_CLK
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PM: add two device managed helpers
  2021-07-27 21:02 PM: add two device managed helpers Dmitry Baryshkov
  2021-07-27 21:02 ` [PATCH 1/2] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
  2021-07-27 21:02 ` [PATCH 2/2] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
@ 2021-07-28  6:23 ` Greg Kroah-Hartman
  2021-07-28 10:40 ` Pavel Machek
  3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-28  6:23 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Rafael J. Wysocki, Pavel Machek, linux-pm, linux-kernel,
	Andy Gross, Bjorn Andersson, linux-arm-msm

On Wed, Jul 28, 2021 at 12:02:00AM +0300, Dmitry Baryshkov wrote:
> Qualcomm clock controller code (and most probably other drivers) would
> benefit from having devres helpers for pm_runtime_enable() and
> pm_clk_create(). Add those two helpers.
> 

I do not want to add new "helpers" without seeing them actually used in
the kernel at the same time, so that we can verify they work and make
code easier to understand.

So please feel free to resubmit this as a patch series that uses them,
adding apis that no one uses is not a good idea.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PM: add two device managed helpers
  2021-07-27 21:02 PM: add two device managed helpers Dmitry Baryshkov
                   ` (2 preceding siblings ...)
  2021-07-28  6:23 ` PM: add two device managed helpers Greg Kroah-Hartman
@ 2021-07-28 10:40 ` Pavel Machek
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2021-07-28 10:40 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Rafael J. Wysocki, Greg Kroah-Hartman, linux-pm, linux-kernel,
	Andy Gross, Bjorn Andersson, linux-arm-msm

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]

On Wed 2021-07-28 00:02:00, Dmitry Baryshkov wrote:
> Qualcomm clock controller code (and most probably other drivers) would
> benefit from having devres helpers for pm_runtime_enable() and
> pm_clk_create(). Add those two helpers.

Yes, please. We have quite a lot of drivers getting this wrong.

Best regards,
								Pavel
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-28 10:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 21:02 PM: add two device managed helpers Dmitry Baryshkov
2021-07-27 21:02 ` [PATCH 1/2] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
2021-07-27 21:02 ` [PATCH 2/2] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
2021-07-28  6:23 ` PM: add two device managed helpers Greg Kroah-Hartman
2021-07-28 10:40 ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).