All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc
@ 2021-07-28 14:24 Dmitry Baryshkov
  2021-07-28 14:24 ` [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-28 14:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Bjorn Andersson
  Cc: linux-pm, linux-kernel, linux-clk, 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.

Modify Qualcomm clock controller code to use new helpers and separate
common pm code into common.c.

----------------------------------------------------------------
Dmitry Baryshkov (5):
      PM: runtime: add devm_pm_runtime_enable helper
      PM: clk: add devm_pm_clk_create helper
      clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create
      clk: qcom: use common code for qcom_cc_probe_by_index
      clk: qcom: move pm_clk functionality into common code

 drivers/base/power/clock_ops.c        | 17 +++++++++++
 drivers/base/power/runtime.c          | 17 +++++++++++
 drivers/clk/qcom/camcc-sc7180.c       | 39 +++++++++----------------
 drivers/clk/qcom/common.c             | 55 ++++++++++++++++++++++++++++-------
 drivers/clk/qcom/common.h             | 17 +++++++++++
 drivers/clk/qcom/lpass-gfm-sm8250.c   | 21 ++++++-------
 drivers/clk/qcom/lpasscorecc-sc7180.c | 55 +++++++++--------------------------
 drivers/clk/qcom/mss-sc7180.c         | 45 ++++++----------------------
 drivers/clk/qcom/q6sstop-qcs404.c     | 40 +++++++------------------
 drivers/clk/qcom/turingcc-qcs404.c    | 45 ++++++----------------------
 include/linux/pm_clock.h              |  5 ++++
 include/linux/pm_runtime.h            |  4 +++
 12 files changed, 169 insertions(+), 191 deletions(-)



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

* [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper
  2021-07-28 14:24 [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc Dmitry Baryshkov
@ 2021-07-28 14:24 ` Dmitry Baryshkov
  2021-07-28 20:04   ` Bjorn Andersson
  2021-07-28 14:24 ` [PATCH v2 2/5] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-28 14:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Bjorn Andersson
  Cc: linux-pm, linux-kernel, linux-clk, 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 related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/5] PM: clk: add devm_pm_clk_create helper
  2021-07-28 14:24 [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc Dmitry Baryshkov
  2021-07-28 14:24 ` [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
@ 2021-07-28 14:24 ` Dmitry Baryshkov
  2021-07-28 20:05   ` Bjorn Andersson
  2021-07-28 14:24 ` [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create Dmitry Baryshkov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-28 14:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Bjorn Andersson
  Cc: linux-pm, linux-kernel, linux-clk, 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 related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create
  2021-07-28 14:24 [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc Dmitry Baryshkov
  2021-07-28 14:24 ` [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
  2021-07-28 14:24 ` [PATCH v2 2/5] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
@ 2021-07-28 14:24 ` Dmitry Baryshkov
  2021-07-28 15:00   ` Bjorn Andersson
  2021-07-28 14:24 ` [PATCH v2 4/5] clk: qcom: use common code for qcom_cc_probe_by_index Dmitry Baryshkov
  2021-07-28 14:24 ` [PATCH v2 5/5] clk: qcom: move pm_clk functionality into common code Dmitry Baryshkov
  4 siblings, 1 reply; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-28 14:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Bjorn Andersson
  Cc: linux-pm, linux-kernel, linux-clk, linux-arm-msm

Use two new helpers instead of pm_runtime_enable() and pm_clk_create(),
removing the need for calling pm_runtime_disable and pm_clk_destroy().

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/clk/qcom/camcc-sc7180.c       | 25 +++++++++------------
 drivers/clk/qcom/lpass-gfm-sm8250.c   | 21 ++++++++----------
 drivers/clk/qcom/lpasscorecc-sc7180.c | 18 ++-------------
 drivers/clk/qcom/mss-sc7180.c         | 30 +++++++------------------
 drivers/clk/qcom/q6sstop-qcs404.c     | 32 ++++++++-------------------
 drivers/clk/qcom/turingcc-qcs404.c    | 30 +++++++------------------
 6 files changed, 46 insertions(+), 110 deletions(-)

diff --git a/drivers/clk/qcom/camcc-sc7180.c b/drivers/clk/qcom/camcc-sc7180.c
index 9bcf2f8ed4de..ce73ee9037cb 100644
--- a/drivers/clk/qcom/camcc-sc7180.c
+++ b/drivers/clk/qcom/camcc-sc7180.c
@@ -1652,32 +1652,35 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
 	struct regmap *regmap;
 	int ret;
 
-	pm_runtime_enable(&pdev->dev);
-	ret = pm_clk_create(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret < 0)
+		return ret;
+
+	ret = devm_pm_clk_create(&pdev->dev);
 	if (ret < 0)
 		return ret;
 
 	ret = pm_clk_add(&pdev->dev, "xo");
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to acquire XO clock\n");
-		goto disable_pm_runtime;
+		return ret;
 	}
 
 	ret = pm_clk_add(&pdev->dev, "iface");
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to acquire iface clock\n");
-		goto disable_pm_runtime;
+		return ret;
 	}
 
 	ret = pm_runtime_get(&pdev->dev);
 	if (ret)
-		goto destroy_pm_clk;
+		return ret;
 
 	regmap = qcom_cc_map(pdev, &cam_cc_sc7180_desc);
 	if (IS_ERR(regmap)) {
 		ret = PTR_ERR(regmap);
 		pm_runtime_put(&pdev->dev);
-		goto destroy_pm_clk;
+		return ret;
 	}
 
 	clk_fabia_pll_configure(&cam_cc_pll0, regmap, &cam_cc_pll0_config);
@@ -1689,18 +1692,10 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
 	pm_runtime_put(&pdev->dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to register CAM CC clocks\n");
-		goto destroy_pm_clk;
+		return ret;
 	}
 
 	return 0;
-
-destroy_pm_clk:
-	pm_clk_destroy(&pdev->dev);
-
-disable_pm_runtime:
-	pm_runtime_disable(&pdev->dev);
-
-	return ret;
 }
 
 static const struct dev_pm_ops cam_cc_pm_ops = {
diff --git a/drivers/clk/qcom/lpass-gfm-sm8250.c b/drivers/clk/qcom/lpass-gfm-sm8250.c
index f5e31e692b9b..96f476f24eb2 100644
--- a/drivers/clk/qcom/lpass-gfm-sm8250.c
+++ b/drivers/clk/qcom/lpass-gfm-sm8250.c
@@ -251,15 +251,18 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev)
 	if (IS_ERR(cc->base))
 		return PTR_ERR(cc->base);
 
-	pm_runtime_enable(dev);
-	err = pm_clk_create(dev);
+	err = devm_pm_runtime_enable(dev);
 	if (err)
-		goto pm_clk_err;
+		return err;
+
+	err = devm_pm_clk_create(dev);
+	if (err)
+		return err;
 
 	err = of_pm_clk_add_clks(dev);
 	if (err < 0) {
 		dev_dbg(dev, "Failed to get lpass core voting clocks\n");
-		goto clk_reg_err;
+		return err;
 	}
 
 	for (i = 0; i < data->onecell_data->num; i++) {
@@ -273,22 +276,16 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev)
 
 		err = devm_clk_hw_register(dev, &data->gfm_clks[i]->hw);
 		if (err)
-			goto clk_reg_err;
+			return err;
 
 	}
 
 	err = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
 					  data->onecell_data);
 	if (err)
-		goto clk_reg_err;
+		return err;
 
 	return 0;
-
-clk_reg_err:
-	pm_clk_destroy(dev);
-pm_clk_err:
-	pm_runtime_disable(dev);
-	return err;
 }
 
 static const struct of_device_id lpass_gfm_clk_match_table[] = {
diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c
index 2e0ecc38efdd..ac09b7b840ab 100644
--- a/drivers/clk/qcom/lpasscorecc-sc7180.c
+++ b/drivers/clk/qcom/lpasscorecc-sc7180.c
@@ -356,32 +356,18 @@ static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = {
 	.num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs),
 };
 
-static void lpass_pm_runtime_disable(void *data)
-{
-	pm_runtime_disable(data);
-}
-
-static void lpass_pm_clk_destroy(void *data)
-{
-	pm_clk_destroy(data);
-}
-
 static int lpass_create_pm_clks(struct platform_device *pdev)
 {
 	int ret;
 
 	pm_runtime_use_autosuspend(&pdev->dev);
 	pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
-	pm_runtime_enable(&pdev->dev);
 
-	ret = devm_add_action_or_reset(&pdev->dev, lpass_pm_runtime_disable, &pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
 	if (ret)
 		return ret;
 
-	ret = pm_clk_create(&pdev->dev);
-	if (ret)
-		return ret;
-	ret = devm_add_action_or_reset(&pdev->dev, lpass_pm_clk_destroy, &pdev->dev);
+	ret = devm_pm_clk_create(&pdev->dev);
 	if (ret)
 		return ret;
 
diff --git a/drivers/clk/qcom/mss-sc7180.c b/drivers/clk/qcom/mss-sc7180.c
index 673fa1a4f734..5a1407440662 100644
--- a/drivers/clk/qcom/mss-sc7180.c
+++ b/drivers/clk/qcom/mss-sc7180.c
@@ -73,36 +73,23 @@ static int mss_sc7180_probe(struct platform_device *pdev)
 {
 	int ret;
 
-	pm_runtime_enable(&pdev->dev);
-	ret = pm_clk_create(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
 	if (ret)
-		goto disable_pm_runtime;
+		return ret;
+
+	ret = devm_pm_clk_create(&pdev->dev);
+	if (ret)
+		return ret;
 
 	ret = pm_clk_add(&pdev->dev, "cfg_ahb");
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-		goto destroy_pm_clk;
+		return ret;
 	}
 
 	ret = qcom_cc_probe(pdev, &mss_sc7180_desc);
 	if (ret < 0)
-		goto destroy_pm_clk;
-
-	return 0;
-
-destroy_pm_clk:
-	pm_clk_destroy(&pdev->dev);
-
-disable_pm_runtime:
-	pm_runtime_disable(&pdev->dev);
-
-	return ret;
-}
-
-static int mss_sc7180_remove(struct platform_device *pdev)
-{
-	pm_clk_destroy(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
+		return ret;
 
 	return 0;
 }
@@ -119,7 +106,6 @@ MODULE_DEVICE_TABLE(of, mss_sc7180_match_table);
 
 static struct platform_driver mss_sc7180_driver = {
 	.probe		= mss_sc7180_probe,
-	.remove		= mss_sc7180_remove,
 	.driver		= {
 		.name		= "sc7180-mss",
 		.of_match_table = mss_sc7180_match_table,
diff --git a/drivers/clk/qcom/q6sstop-qcs404.c b/drivers/clk/qcom/q6sstop-qcs404.c
index 723f932fbf7d..507386bee07d 100644
--- a/drivers/clk/qcom/q6sstop-qcs404.c
+++ b/drivers/clk/qcom/q6sstop-qcs404.c
@@ -159,15 +159,18 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
 	const struct qcom_cc_desc *desc;
 	int ret;
 
-	pm_runtime_enable(&pdev->dev);
-	ret = pm_clk_create(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
 	if (ret)
-		goto disable_pm_runtime;
+		return ret;
+
+	ret = devm_pm_clk_create(&pdev->dev);
+	if (ret)
+		return ret;
 
 	ret = pm_clk_add(&pdev->dev, NULL);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-		goto destroy_pm_clk;
+		return ret;
 	}
 
 	q6sstop_regmap_config.name = "q6sstop_tcsr";
@@ -175,30 +178,14 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
 
 	ret = qcom_cc_probe_by_index(pdev, 1, desc);
 	if (ret)
-		goto destroy_pm_clk;
+		return ret;
 
 	q6sstop_regmap_config.name = "q6sstop_cc";
 	desc = &q6sstop_qcs404_desc;
 
 	ret = qcom_cc_probe_by_index(pdev, 0, desc);
 	if (ret)
-		goto destroy_pm_clk;
-
-	return 0;
-
-destroy_pm_clk:
-	pm_clk_destroy(&pdev->dev);
-
-disable_pm_runtime:
-	pm_runtime_disable(&pdev->dev);
-
-	return ret;
-}
-
-static int q6sstopcc_qcs404_remove(struct platform_device *pdev)
-{
-	pm_clk_destroy(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
+		return ret;
 
 	return 0;
 }
@@ -209,7 +196,6 @@ static const struct dev_pm_ops q6sstopcc_pm_ops = {
 
 static struct platform_driver q6sstopcc_qcs404_driver = {
 	.probe		= q6sstopcc_qcs404_probe,
-	.remove		= q6sstopcc_qcs404_remove,
 	.driver		= {
 		.name	= "qcs404-q6sstopcc",
 		.of_match_table = q6sstopcc_qcs404_match_table,
diff --git a/drivers/clk/qcom/turingcc-qcs404.c b/drivers/clk/qcom/turingcc-qcs404.c
index 4cfbbf5bf4d9..4543bda793f4 100644
--- a/drivers/clk/qcom/turingcc-qcs404.c
+++ b/drivers/clk/qcom/turingcc-qcs404.c
@@ -110,36 +110,23 @@ static int turingcc_probe(struct platform_device *pdev)
 {
 	int ret;
 
-	pm_runtime_enable(&pdev->dev);
-	ret = pm_clk_create(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
 	if (ret)
-		goto disable_pm_runtime;
+		return ret;
+
+	ret = devm_pm_clk_create(&pdev->dev);
+	if (ret)
+		return ret;
 
 	ret = pm_clk_add(&pdev->dev, NULL);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-		goto destroy_pm_clk;
+		return ret;
 	}
 
 	ret = qcom_cc_probe(pdev, &turingcc_desc);
 	if (ret < 0)
-		goto destroy_pm_clk;
-
-	return 0;
-
-destroy_pm_clk:
-	pm_clk_destroy(&pdev->dev);
-
-disable_pm_runtime:
-	pm_runtime_disable(&pdev->dev);
-
-	return ret;
-}
-
-static int turingcc_remove(struct platform_device *pdev)
-{
-	pm_clk_destroy(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
+		return ret;
 
 	return 0;
 }
@@ -156,7 +143,6 @@ MODULE_DEVICE_TABLE(of, turingcc_match_table);
 
 static struct platform_driver turingcc_driver = {
 	.probe		= turingcc_probe,
-	.remove		= turingcc_remove,
 	.driver		= {
 		.name	= "qcs404-turingcc",
 		.of_match_table = turingcc_match_table,
-- 
2.30.2


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

* [PATCH v2 4/5] clk: qcom: use common code for qcom_cc_probe_by_index
  2021-07-28 14:24 [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc Dmitry Baryshkov
                   ` (2 preceding siblings ...)
  2021-07-28 14:24 ` [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create Dmitry Baryshkov
@ 2021-07-28 14:24 ` Dmitry Baryshkov
  2021-07-28 14:24 ` [PATCH v2 5/5] clk: qcom: move pm_clk functionality into common code Dmitry Baryshkov
  4 siblings, 0 replies; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-28 14:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Bjorn Andersson
  Cc: linux-pm, linux-kernel, linux-clk, linux-arm-msm

Rewrite qcom_cc_map and qcom_cc_probe_by_index to use (new)
qcom_cc_map_by_index, removing code duplication and opening a way to
have more common code in qcom_cc_map*.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/clk/qcom/common.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c
index 60d2a78d1395..ed7c516a597a 100644
--- a/drivers/clk/qcom/common.c
+++ b/drivers/clk/qcom/common.c
@@ -69,20 +69,26 @@ int qcom_find_src_index(struct clk_hw *hw, const struct parent_map *map, u8 src)
 }
 EXPORT_SYMBOL_GPL(qcom_find_src_index);
 
-struct regmap *
-qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc)
+static struct regmap *
+qcom_cc_map_by_index(struct platform_device *pdev, const struct qcom_cc_desc *desc, int index)
 {
 	void __iomem *base;
 	struct resource *res;
 	struct device *dev = &pdev->dev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	res = platform_get_resource(pdev, IORESOURCE_MEM, index);
 	base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(base))
 		return ERR_CAST(base);
 
 	return devm_regmap_init_mmio(dev, base, desc->config);
 }
+
+struct regmap *
+qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc)
+{
+	return qcom_cc_map_by_index(pdev, desc, 0);
+}
 EXPORT_SYMBOL_GPL(qcom_cc_map);
 
 void
@@ -313,15 +319,8 @@ int qcom_cc_probe_by_index(struct platform_device *pdev, int index,
 			   const struct qcom_cc_desc *desc)
 {
 	struct regmap *regmap;
-	struct resource *res;
-	void __iomem *base;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, index);
-	base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(base))
-		return -ENOMEM;
 
-	regmap = devm_regmap_init_mmio(&pdev->dev, base, desc->config);
+	regmap = qcom_cc_map_by_index(pdev, desc, index);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
 
-- 
2.30.2


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

* [PATCH v2 5/5] clk: qcom: move pm_clk functionality into common code
  2021-07-28 14:24 [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc Dmitry Baryshkov
                   ` (3 preceding siblings ...)
  2021-07-28 14:24 ` [PATCH v2 4/5] clk: qcom: use common code for qcom_cc_probe_by_index Dmitry Baryshkov
@ 2021-07-28 14:24 ` Dmitry Baryshkov
  4 siblings, 0 replies; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-28 14:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Bjorn Andersson
  Cc: linux-pm, linux-kernel, linux-clk, linux-arm-msm

Several Qualcomm clock controller drivers use pm_clk functionality.
Instead of having common code in all the drivers, move the pm_clk
handling to the qcom_cc_map/qcom_cc_probe.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/clk/qcom/camcc-sc7180.c       | 28 +++++++-----------
 drivers/clk/qcom/common.c             | 36 +++++++++++++++++++++++
 drivers/clk/qcom/common.h             | 17 +++++++++++
 drivers/clk/qcom/lpasscorecc-sc7180.c | 41 +++++++++------------------
 drivers/clk/qcom/mss-sc7180.c         | 31 ++++++--------------
 drivers/clk/qcom/q6sstop-qcs404.c     | 22 ++++++--------
 drivers/clk/qcom/turingcc-qcs404.c    | 31 ++++++--------------
 7 files changed, 103 insertions(+), 103 deletions(-)

diff --git a/drivers/clk/qcom/camcc-sc7180.c b/drivers/clk/qcom/camcc-sc7180.c
index ce73ee9037cb..cb213b8473a5 100644
--- a/drivers/clk/qcom/camcc-sc7180.c
+++ b/drivers/clk/qcom/camcc-sc7180.c
@@ -1631,8 +1631,16 @@ static const struct regmap_config cam_cc_sc7180_regmap_config = {
 	.fast_io = true,
 };
 
+static const char * const cam_cc_sc7180_pm_clks[] = { "xo", "iface" };
+
+static const struct qcom_cc_pm cam_cc_sc7180_pm = {
+	.pm_clks = cam_cc_sc7180_pm_clks,
+	.num_pm_clks = ARRAY_SIZE(cam_cc_sc7180_pm_clks),
+};
+
 static const struct qcom_cc_desc cam_cc_sc7180_desc = {
 	.config = &cam_cc_sc7180_regmap_config,
+	.pm = &cam_cc_sc7180_pm,
 	.clk_hws = cam_cc_sc7180_hws,
 	.num_clk_hws = ARRAY_SIZE(cam_cc_sc7180_hws),
 	.clks = cam_cc_sc7180_clocks,
@@ -1652,25 +1660,9 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
 	struct regmap *regmap;
 	int ret;
 
-	ret = devm_pm_runtime_enable(&pdev->dev);
-	if (ret < 0)
-		return ret;
-
-	ret = devm_pm_clk_create(&pdev->dev);
-	if (ret < 0)
-		return ret;
-
-	ret = pm_clk_add(&pdev->dev, "xo");
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to acquire XO clock\n");
-		return ret;
-	}
-
-	ret = pm_clk_add(&pdev->dev, "iface");
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to acquire iface clock\n");
+	ret = qcom_cc_setup_pm(pdev, &cam_cc_sc7180_desc);
+	if (ret)
 		return ret;
-	}
 
 	ret = pm_runtime_get(&pdev->dev);
 	if (ret)
diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c
index ed7c516a597a..def01be085ba 100644
--- a/drivers/clk/qcom/common.c
+++ b/drivers/clk/qcom/common.c
@@ -7,6 +7,8 @@
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/platform_device.h>
+#include <linux/pm_clock.h>
+#include <linux/pm_runtime.h>
 #include <linux/clk-provider.h>
 #include <linux/reset-controller.h>
 #include <linux/of.h>
@@ -307,6 +309,8 @@ int qcom_cc_probe(struct platform_device *pdev, const struct qcom_cc_desc *desc)
 {
 	struct regmap *regmap;
 
+	qcom_cc_setup_pm(pdev, desc);
+
 	regmap = qcom_cc_map(pdev, desc);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
@@ -320,6 +324,8 @@ int qcom_cc_probe_by_index(struct platform_device *pdev, int index,
 {
 	struct regmap *regmap;
 
+	qcom_cc_setup_pm(pdev, desc);
+
 	regmap = qcom_cc_map_by_index(pdev, desc, index);
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
@@ -328,4 +334,34 @@ int qcom_cc_probe_by_index(struct platform_device *pdev, int index,
 }
 EXPORT_SYMBOL_GPL(qcom_cc_probe_by_index);
 
+int qcom_cc_really_setup_pm(struct platform_device *pdev, const struct qcom_cc_pm *pm)
+{
+	int ret;
+	int i;
+
+	if (!pm)
+		return -EINVAL;
+
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		return ret;
+
+	if (pm->num_pm_clks) {
+		ret = devm_pm_clk_create(&pdev->dev);
+		if (ret)
+			return ret;
+	}
+
+	for (i = 0; i < pm->num_pm_clks; i++) {
+		ret = pm_clk_add(&pdev->dev, pm->pm_clks[i]);
+		if (ret < 0) {
+			dev_err(&pdev->dev, "Failed to acquire %s pm clk\n", pm->pm_clks[i]);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_cc_really_setup_pm);
+
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/clk/qcom/common.h b/drivers/clk/qcom/common.h
index bb39a7e106d8..ea4394439712 100644
--- a/drivers/clk/qcom/common.h
+++ b/drivers/clk/qcom/common.h
@@ -19,8 +19,15 @@ struct clk_hw;
 #define PLL_VOTE_FSM_ENA	BIT(20)
 #define PLL_VOTE_FSM_RESET	BIT(21)
 
+/* This can be used from within the qcom_cc_desc or separately */
+struct qcom_cc_pm {
+	const char *const *pm_clks;
+	size_t num_pm_clks;
+};
+
 struct qcom_cc_desc {
 	const struct regmap_config *config;
+	const struct qcom_cc_pm *pm;
 	struct clk_regmap **clks;
 	size_t num_clks;
 	const struct qcom_reset_map *resets;
@@ -54,6 +61,16 @@ extern int qcom_cc_register_board_clk(struct device *dev, const char *path,
 				      const char *name, unsigned long rate);
 extern int qcom_cc_register_sleep_clk(struct device *dev);
 
+extern int qcom_cc_really_setup_pm(struct platform_device *pdev, const struct qcom_cc_pm *pm);
+
+static inline int qcom_cc_setup_pm(struct platform_device *pdev, const struct qcom_cc_desc *desc)
+{
+	if (!desc->pm)
+		return 0;
+
+	return qcom_cc_really_setup_pm(pdev, desc->pm);
+}
+
 extern struct regmap *qcom_cc_map(struct platform_device *pdev,
 				  const struct qcom_cc_desc *desc);
 extern int qcom_cc_really_probe(struct platform_device *pdev,
diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c
index ac09b7b840ab..af1b04615d1d 100644
--- a/drivers/clk/qcom/lpasscorecc-sc7180.c
+++ b/drivers/clk/qcom/lpasscorecc-sc7180.c
@@ -338,8 +338,16 @@ static struct regmap_config lpass_core_cc_sc7180_regmap_config = {
 	.fast_io = true,
 };
 
+static const char * const lpass_core_sc7180_pm_clks[] = { "iface" };
+
+static const struct qcom_cc_pm lpass_core_sc7180_pm = {
+	.pm_clks = lpass_core_sc7180_pm_clks,
+	.num_pm_clks = ARRAY_SIZE(lpass_core_sc7180_pm_clks),
+};
+
 static const struct qcom_cc_desc lpass_core_hm_sc7180_desc = {
 	.config = &lpass_core_cc_sc7180_regmap_config,
+	.pm = &lpass_core_sc7180_pm,
 	.gdscs = lpass_core_hm_sc7180_gdscs,
 	.num_gdscs = ARRAY_SIZE(lpass_core_hm_sc7180_gdscs),
 };
@@ -356,35 +364,16 @@ static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = {
 	.num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs),
 };
 
-static int lpass_create_pm_clks(struct platform_device *pdev)
-{
-	int ret;
-
-	pm_runtime_use_autosuspend(&pdev->dev);
-	pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
-
-	ret = devm_pm_runtime_enable(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = devm_pm_clk_create(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = pm_clk_add(&pdev->dev, "iface");
-	if (ret < 0)
-		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-
-	return ret;
-}
-
 static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
 {
 	const struct qcom_cc_desc *desc;
 	struct regmap *regmap;
 	int ret;
 
-	ret = lpass_create_pm_clks(pdev);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
+
+	ret = qcom_cc_really_setup_pm(pdev, &lpass_core_sc7180_pm);
 	if (ret)
 		return ret;
 
@@ -423,11 +412,9 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
 static int lpass_hm_core_probe(struct platform_device *pdev)
 {
 	const struct qcom_cc_desc *desc;
-	int ret;
 
-	ret = lpass_create_pm_clks(pdev);
-	if (ret)
-		return ret;
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
 
 	lpass_core_cc_sc7180_regmap_config.name = "lpass_hm_core";
 	desc = &lpass_core_hm_sc7180_desc;
diff --git a/drivers/clk/qcom/mss-sc7180.c b/drivers/clk/qcom/mss-sc7180.c
index 5a1407440662..47feca261985 100644
--- a/drivers/clk/qcom/mss-sc7180.c
+++ b/drivers/clk/qcom/mss-sc7180.c
@@ -7,7 +7,6 @@
 #include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/pm_clock.h>
-#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 
 #include <dt-bindings/clock/qcom,mss-sc7180.h>
@@ -63,35 +62,23 @@ static struct clk_regmap *mss_sc7180_clocks[] = {
 	[MSS_AXI_NAV_CLK] = &mss_axi_nav_clk.clkr,
 };
 
+static const char * const mss_sc7180_pm_clks[] = { "cfg_ahb" };
+
+static const struct qcom_cc_pm mss_sc7180_pm = {
+	.pm_clks = mss_sc7180_pm_clks,
+	.num_pm_clks = ARRAY_SIZE(mss_sc7180_pm_clks),
+};
+
 static const struct qcom_cc_desc mss_sc7180_desc = {
 	.config = &mss_regmap_config,
+	.pm = &mss_sc7180_pm,
 	.clks = mss_sc7180_clocks,
 	.num_clks = ARRAY_SIZE(mss_sc7180_clocks),
 };
 
 static int mss_sc7180_probe(struct platform_device *pdev)
 {
-	int ret;
-
-	ret = devm_pm_runtime_enable(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = devm_pm_clk_create(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = pm_clk_add(&pdev->dev, "cfg_ahb");
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-		return ret;
-	}
-
-	ret = qcom_cc_probe(pdev, &mss_sc7180_desc);
-	if (ret < 0)
-		return ret;
-
-	return 0;
+	return qcom_cc_probe(pdev, &mss_sc7180_desc);
 }
 
 static const struct dev_pm_ops mss_sc7180_pm_ops = {
diff --git a/drivers/clk/qcom/q6sstop-qcs404.c b/drivers/clk/qcom/q6sstop-qcs404.c
index 507386bee07d..e19ee2b047ac 100644
--- a/drivers/clk/qcom/q6sstop-qcs404.c
+++ b/drivers/clk/qcom/q6sstop-qcs404.c
@@ -8,7 +8,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm_clock.h>
-#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 
 #include <dt-bindings/clock/qcom,q6sstopcc-qcs404.h>
@@ -117,6 +116,13 @@ static struct regmap_config q6sstop_regmap_config = {
 	.fast_io	= true,
 };
 
+static const char * const q6sstop_qcs404_pm_clks[] = { NULL };
+
+static const struct qcom_cc_pm q6sstop_qcs404_pm = {
+	.pm_clks = q6sstop_qcs404_pm_clks,
+	.num_pm_clks = ARRAY_SIZE(q6sstop_qcs404_pm_clks),
+};
+
 static struct clk_regmap *q6sstop_qcs404_clocks[] = {
 	[LCC_AHBFABRIC_CBC_CLK] = &lcc_ahbfabric_cbc_clk.clkr,
 	[LCC_Q6SS_AHBS_CBC_CLK] = &lcc_q6ss_ahbs_cbc_clk.clkr,
@@ -159,19 +165,7 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
 	const struct qcom_cc_desc *desc;
 	int ret;
 
-	ret = devm_pm_runtime_enable(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = devm_pm_clk_create(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = pm_clk_add(&pdev->dev, NULL);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-		return ret;
-	}
+	ret = qcom_cc_really_setup_pm(pdev, &q6sstop_qcs404_pm);
 
 	q6sstop_regmap_config.name = "q6sstop_tcsr";
 	desc = &tcsr_qcs404_desc;
diff --git a/drivers/clk/qcom/turingcc-qcs404.c b/drivers/clk/qcom/turingcc-qcs404.c
index 4543bda793f4..a2ac9e6da13c 100644
--- a/drivers/clk/qcom/turingcc-qcs404.c
+++ b/drivers/clk/qcom/turingcc-qcs404.c
@@ -9,7 +9,6 @@
 #include <linux/module.h>
 #include <linux/of_address.h>
 #include <linux/pm_clock.h>
-#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 
 #include <dt-bindings/clock/qcom,turingcc-qcs404.h>
@@ -100,35 +99,23 @@ static const struct regmap_config turingcc_regmap_config = {
 	.fast_io	= true,
 };
 
+static const char * const turingcc_pm_clks[] = { NULL };
+
+static const struct qcom_cc_pm turingcc_pm = {
+	.pm_clks = turingcc_pm_clks,
+	.num_pm_clks = ARRAY_SIZE(turingcc_pm_clks),
+};
+
 static const struct qcom_cc_desc turingcc_desc = {
 	.config = &turingcc_regmap_config,
+	.pm = &turingcc_pm,
 	.clks = turingcc_clocks,
 	.num_clks = ARRAY_SIZE(turingcc_clocks),
 };
 
 static int turingcc_probe(struct platform_device *pdev)
 {
-	int ret;
-
-	ret = devm_pm_runtime_enable(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = devm_pm_clk_create(&pdev->dev);
-	if (ret)
-		return ret;
-
-	ret = pm_clk_add(&pdev->dev, NULL);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to acquire iface clock\n");
-		return ret;
-	}
-
-	ret = qcom_cc_probe(pdev, &turingcc_desc);
-	if (ret < 0)
-		return ret;
-
-	return 0;
+	return qcom_cc_probe(pdev, &turingcc_desc);
 }
 
 static const struct dev_pm_ops turingcc_pm_ops = {
-- 
2.30.2


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

* Re: [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create
  2021-07-28 14:24 ` [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create Dmitry Baryshkov
@ 2021-07-28 15:00   ` Bjorn Andersson
  2021-07-29 14:28     ` Dmitry Baryshkov
  0 siblings, 1 reply; 10+ messages in thread
From: Bjorn Andersson @ 2021-07-28 15:00 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, linux-pm, linux-kernel,
	linux-clk, linux-arm-msm

On Wed 28 Jul 09:24 CDT 2021, Dmitry Baryshkov wrote:

> Use two new helpers instead of pm_runtime_enable() and pm_clk_create(),
> removing the need for calling pm_runtime_disable and pm_clk_destroy().
> 
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

It's quite reasonable to expect that Rafael wants to take the two first
patches through his tree, but I expect that these clock patches will
conflict with your other changes resulting in a less smooth path into
mainline.

Grepping the tree for candidates I find many better examples, that
we don't foresee any conflicting changes..

So may I suggest that you fix drivers/hwspinlock/omap_hwspinlock.c and
drivers/hwspinlock/stm32_hwspinlock.c, then I (as maintainer) can Ack
those changes and Rafael can take the series in his tree for v5.15.


Then as v5.15-rc1 lands, we have the API and we can follow up changing
these more complex drivers - and those patches can go through the
individual maintainer trees.

Regards,
Bjorn

> ---
>  drivers/clk/qcom/camcc-sc7180.c       | 25 +++++++++------------
>  drivers/clk/qcom/lpass-gfm-sm8250.c   | 21 ++++++++----------
>  drivers/clk/qcom/lpasscorecc-sc7180.c | 18 ++-------------
>  drivers/clk/qcom/mss-sc7180.c         | 30 +++++++------------------
>  drivers/clk/qcom/q6sstop-qcs404.c     | 32 ++++++++-------------------
>  drivers/clk/qcom/turingcc-qcs404.c    | 30 +++++++------------------
>  6 files changed, 46 insertions(+), 110 deletions(-)
> 
> diff --git a/drivers/clk/qcom/camcc-sc7180.c b/drivers/clk/qcom/camcc-sc7180.c
> index 9bcf2f8ed4de..ce73ee9037cb 100644
> --- a/drivers/clk/qcom/camcc-sc7180.c
> +++ b/drivers/clk/qcom/camcc-sc7180.c
> @@ -1652,32 +1652,35 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
>  	struct regmap *regmap;
>  	int ret;
>  
> -	pm_runtime_enable(&pdev->dev);
> -	ret = pm_clk_create(&pdev->dev);
> +	ret = devm_pm_runtime_enable(&pdev->dev);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = devm_pm_clk_create(&pdev->dev);
>  	if (ret < 0)
>  		return ret;
>  
>  	ret = pm_clk_add(&pdev->dev, "xo");
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "Failed to acquire XO clock\n");
> -		goto disable_pm_runtime;
> +		return ret;
>  	}
>  
>  	ret = pm_clk_add(&pdev->dev, "iface");
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "Failed to acquire iface clock\n");
> -		goto disable_pm_runtime;
> +		return ret;
>  	}
>  
>  	ret = pm_runtime_get(&pdev->dev);
>  	if (ret)
> -		goto destroy_pm_clk;
> +		return ret;
>  
>  	regmap = qcom_cc_map(pdev, &cam_cc_sc7180_desc);
>  	if (IS_ERR(regmap)) {
>  		ret = PTR_ERR(regmap);
>  		pm_runtime_put(&pdev->dev);
> -		goto destroy_pm_clk;
> +		return ret;
>  	}
>  
>  	clk_fabia_pll_configure(&cam_cc_pll0, regmap, &cam_cc_pll0_config);
> @@ -1689,18 +1692,10 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
>  	pm_runtime_put(&pdev->dev);
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "Failed to register CAM CC clocks\n");
> -		goto destroy_pm_clk;
> +		return ret;
>  	}
>  
>  	return 0;
> -
> -destroy_pm_clk:
> -	pm_clk_destroy(&pdev->dev);
> -
> -disable_pm_runtime:
> -	pm_runtime_disable(&pdev->dev);
> -
> -	return ret;
>  }
>  
>  static const struct dev_pm_ops cam_cc_pm_ops = {
> diff --git a/drivers/clk/qcom/lpass-gfm-sm8250.c b/drivers/clk/qcom/lpass-gfm-sm8250.c
> index f5e31e692b9b..96f476f24eb2 100644
> --- a/drivers/clk/qcom/lpass-gfm-sm8250.c
> +++ b/drivers/clk/qcom/lpass-gfm-sm8250.c
> @@ -251,15 +251,18 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev)
>  	if (IS_ERR(cc->base))
>  		return PTR_ERR(cc->base);
>  
> -	pm_runtime_enable(dev);
> -	err = pm_clk_create(dev);
> +	err = devm_pm_runtime_enable(dev);
>  	if (err)
> -		goto pm_clk_err;
> +		return err;
> +
> +	err = devm_pm_clk_create(dev);
> +	if (err)
> +		return err;
>  
>  	err = of_pm_clk_add_clks(dev);
>  	if (err < 0) {
>  		dev_dbg(dev, "Failed to get lpass core voting clocks\n");
> -		goto clk_reg_err;
> +		return err;
>  	}
>  
>  	for (i = 0; i < data->onecell_data->num; i++) {
> @@ -273,22 +276,16 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev)
>  
>  		err = devm_clk_hw_register(dev, &data->gfm_clks[i]->hw);
>  		if (err)
> -			goto clk_reg_err;
> +			return err;
>  
>  	}
>  
>  	err = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
>  					  data->onecell_data);
>  	if (err)
> -		goto clk_reg_err;
> +		return err;
>  
>  	return 0;
> -
> -clk_reg_err:
> -	pm_clk_destroy(dev);
> -pm_clk_err:
> -	pm_runtime_disable(dev);
> -	return err;
>  }
>  
>  static const struct of_device_id lpass_gfm_clk_match_table[] = {
> diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c
> index 2e0ecc38efdd..ac09b7b840ab 100644
> --- a/drivers/clk/qcom/lpasscorecc-sc7180.c
> +++ b/drivers/clk/qcom/lpasscorecc-sc7180.c
> @@ -356,32 +356,18 @@ static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = {
>  	.num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs),
>  };
>  
> -static void lpass_pm_runtime_disable(void *data)
> -{
> -	pm_runtime_disable(data);
> -}
> -
> -static void lpass_pm_clk_destroy(void *data)
> -{
> -	pm_clk_destroy(data);
> -}
> -
>  static int lpass_create_pm_clks(struct platform_device *pdev)
>  {
>  	int ret;
>  
>  	pm_runtime_use_autosuspend(&pdev->dev);
>  	pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
> -	pm_runtime_enable(&pdev->dev);
>  
> -	ret = devm_add_action_or_reset(&pdev->dev, lpass_pm_runtime_disable, &pdev->dev);
> +	ret = devm_pm_runtime_enable(&pdev->dev);
>  	if (ret)
>  		return ret;
>  
> -	ret = pm_clk_create(&pdev->dev);
> -	if (ret)
> -		return ret;
> -	ret = devm_add_action_or_reset(&pdev->dev, lpass_pm_clk_destroy, &pdev->dev);
> +	ret = devm_pm_clk_create(&pdev->dev);
>  	if (ret)
>  		return ret;
>  
> diff --git a/drivers/clk/qcom/mss-sc7180.c b/drivers/clk/qcom/mss-sc7180.c
> index 673fa1a4f734..5a1407440662 100644
> --- a/drivers/clk/qcom/mss-sc7180.c
> +++ b/drivers/clk/qcom/mss-sc7180.c
> @@ -73,36 +73,23 @@ static int mss_sc7180_probe(struct platform_device *pdev)
>  {
>  	int ret;
>  
> -	pm_runtime_enable(&pdev->dev);
> -	ret = pm_clk_create(&pdev->dev);
> +	ret = devm_pm_runtime_enable(&pdev->dev);
>  	if (ret)
> -		goto disable_pm_runtime;
> +		return ret;
> +
> +	ret = devm_pm_clk_create(&pdev->dev);
> +	if (ret)
> +		return ret;
>  
>  	ret = pm_clk_add(&pdev->dev, "cfg_ahb");
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "failed to acquire iface clock\n");
> -		goto destroy_pm_clk;
> +		return ret;
>  	}
>  
>  	ret = qcom_cc_probe(pdev, &mss_sc7180_desc);
>  	if (ret < 0)
> -		goto destroy_pm_clk;
> -
> -	return 0;
> -
> -destroy_pm_clk:
> -	pm_clk_destroy(&pdev->dev);
> -
> -disable_pm_runtime:
> -	pm_runtime_disable(&pdev->dev);
> -
> -	return ret;
> -}
> -
> -static int mss_sc7180_remove(struct platform_device *pdev)
> -{
> -	pm_clk_destroy(&pdev->dev);
> -	pm_runtime_disable(&pdev->dev);
> +		return ret;
>  
>  	return 0;
>  }
> @@ -119,7 +106,6 @@ MODULE_DEVICE_TABLE(of, mss_sc7180_match_table);
>  
>  static struct platform_driver mss_sc7180_driver = {
>  	.probe		= mss_sc7180_probe,
> -	.remove		= mss_sc7180_remove,
>  	.driver		= {
>  		.name		= "sc7180-mss",
>  		.of_match_table = mss_sc7180_match_table,
> diff --git a/drivers/clk/qcom/q6sstop-qcs404.c b/drivers/clk/qcom/q6sstop-qcs404.c
> index 723f932fbf7d..507386bee07d 100644
> --- a/drivers/clk/qcom/q6sstop-qcs404.c
> +++ b/drivers/clk/qcom/q6sstop-qcs404.c
> @@ -159,15 +159,18 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
>  	const struct qcom_cc_desc *desc;
>  	int ret;
>  
> -	pm_runtime_enable(&pdev->dev);
> -	ret = pm_clk_create(&pdev->dev);
> +	ret = devm_pm_runtime_enable(&pdev->dev);
>  	if (ret)
> -		goto disable_pm_runtime;
> +		return ret;
> +
> +	ret = devm_pm_clk_create(&pdev->dev);
> +	if (ret)
> +		return ret;
>  
>  	ret = pm_clk_add(&pdev->dev, NULL);
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "failed to acquire iface clock\n");
> -		goto destroy_pm_clk;
> +		return ret;
>  	}
>  
>  	q6sstop_regmap_config.name = "q6sstop_tcsr";
> @@ -175,30 +178,14 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
>  
>  	ret = qcom_cc_probe_by_index(pdev, 1, desc);
>  	if (ret)
> -		goto destroy_pm_clk;
> +		return ret;
>  
>  	q6sstop_regmap_config.name = "q6sstop_cc";
>  	desc = &q6sstop_qcs404_desc;
>  
>  	ret = qcom_cc_probe_by_index(pdev, 0, desc);
>  	if (ret)
> -		goto destroy_pm_clk;
> -
> -	return 0;
> -
> -destroy_pm_clk:
> -	pm_clk_destroy(&pdev->dev);
> -
> -disable_pm_runtime:
> -	pm_runtime_disable(&pdev->dev);
> -
> -	return ret;
> -}
> -
> -static int q6sstopcc_qcs404_remove(struct platform_device *pdev)
> -{
> -	pm_clk_destroy(&pdev->dev);
> -	pm_runtime_disable(&pdev->dev);
> +		return ret;
>  
>  	return 0;
>  }
> @@ -209,7 +196,6 @@ static const struct dev_pm_ops q6sstopcc_pm_ops = {
>  
>  static struct platform_driver q6sstopcc_qcs404_driver = {
>  	.probe		= q6sstopcc_qcs404_probe,
> -	.remove		= q6sstopcc_qcs404_remove,
>  	.driver		= {
>  		.name	= "qcs404-q6sstopcc",
>  		.of_match_table = q6sstopcc_qcs404_match_table,
> diff --git a/drivers/clk/qcom/turingcc-qcs404.c b/drivers/clk/qcom/turingcc-qcs404.c
> index 4cfbbf5bf4d9..4543bda793f4 100644
> --- a/drivers/clk/qcom/turingcc-qcs404.c
> +++ b/drivers/clk/qcom/turingcc-qcs404.c
> @@ -110,36 +110,23 @@ static int turingcc_probe(struct platform_device *pdev)
>  {
>  	int ret;
>  
> -	pm_runtime_enable(&pdev->dev);
> -	ret = pm_clk_create(&pdev->dev);
> +	ret = devm_pm_runtime_enable(&pdev->dev);
>  	if (ret)
> -		goto disable_pm_runtime;
> +		return ret;
> +
> +	ret = devm_pm_clk_create(&pdev->dev);
> +	if (ret)
> +		return ret;
>  
>  	ret = pm_clk_add(&pdev->dev, NULL);
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "failed to acquire iface clock\n");
> -		goto destroy_pm_clk;
> +		return ret;
>  	}
>  
>  	ret = qcom_cc_probe(pdev, &turingcc_desc);
>  	if (ret < 0)
> -		goto destroy_pm_clk;
> -
> -	return 0;
> -
> -destroy_pm_clk:
> -	pm_clk_destroy(&pdev->dev);
> -
> -disable_pm_runtime:
> -	pm_runtime_disable(&pdev->dev);
> -
> -	return ret;
> -}
> -
> -static int turingcc_remove(struct platform_device *pdev)
> -{
> -	pm_clk_destroy(&pdev->dev);
> -	pm_runtime_disable(&pdev->dev);
> +		return ret;
>  
>  	return 0;
>  }
> @@ -156,7 +143,6 @@ MODULE_DEVICE_TABLE(of, turingcc_match_table);
>  
>  static struct platform_driver turingcc_driver = {
>  	.probe		= turingcc_probe,
> -	.remove		= turingcc_remove,
>  	.driver		= {
>  		.name	= "qcs404-turingcc",
>  		.of_match_table = turingcc_match_table,
> -- 
> 2.30.2
> 

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

* Re: [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper
  2021-07-28 14:24 ` [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
@ 2021-07-28 20:04   ` Bjorn Andersson
  0 siblings, 0 replies; 10+ messages in thread
From: Bjorn Andersson @ 2021-07-28 20:04 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, linux-pm, linux-kernel,
	linux-clk, linux-arm-msm

On Wed 28 Jul 07:24 PDT 2021, Dmitry Baryshkov wrote:

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

This says what the patch does, but it doesn't say why we would like
these helpers - i.e. the fact that it's quite common across the kernel
to have error handlers and remove functions that simply has to do
pm_runtime_disable().

> 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.

() on the function name.

> + * @dev: Device to handle.

Returns: 0 on success, negative errno on failure

Regards,
Bjorn

> + */
> +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] 10+ messages in thread

* Re: [PATCH v2 2/5] PM: clk: add devm_pm_clk_create helper
  2021-07-28 14:24 ` [PATCH v2 2/5] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
@ 2021-07-28 20:05   ` Bjorn Andersson
  0 siblings, 0 replies; 10+ messages in thread
From: Bjorn Andersson @ 2021-07-28 20:05 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, linux-pm, linux-kernel,
	linux-clk, linux-arm-msm

On Wed 28 Jul 07:24 PDT 2021, Dmitry Baryshkov wrote:

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

As with path 1, please describe why this is a good thing. (I definitely
think it is, but I've been part of the discussion leading up to this
patch)

> 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);
> +}
> +

As this is an addition to the API, it deserves some kerneldoc.

Regards,
Bjorn

> +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] 10+ messages in thread

* Re: [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create
  2021-07-28 15:00   ` Bjorn Andersson
@ 2021-07-29 14:28     ` Dmitry Baryshkov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Baryshkov @ 2021-07-29 14:28 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Rafael J. Wysocki, Pavel Machek, Greg Kroah-Hartman, Stephen Boyd,
	Taniya Das, Michael Turquette, Andy Gross, Linux PM, open list,
	open list:COMMON CLK FRAMEWORK,
	open list:DRM DRIVER FOR MSM ADRENO GPU

On Wed, 28 Jul 2021 at 18:00, Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
>
> On Wed 28 Jul 09:24 CDT 2021, Dmitry Baryshkov wrote:
>
> > Use two new helpers instead of pm_runtime_enable() and pm_clk_create(),
> > removing the need for calling pm_runtime_disable and pm_clk_destroy().
> >
> > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>
> It's quite reasonable to expect that Rafael wants to take the two first
> patches through his tree, but I expect that these clock patches will
> conflict with your other changes resulting in a less smooth path into
> mainline.

I do not expect any conflicts in the clock code. The gdsc fixes do not
touch these parts.

> Grepping the tree for candidates I find many better examples, that
> we don't foresee any conflicting changes..
>
> So may I suggest that you fix drivers/hwspinlock/omap_hwspinlock.c and
> drivers/hwspinlock/stm32_hwspinlock.c, then I (as maintainer) can Ack
> those changes and Rafael can take the series in his tree for v5.15.

These two would use devm_pm_runtime_enable, but not the
devm_pm_clk_create. Thus I'd still prefer to modify these few drivers
(note, the generification is a separate patch and I can safely drop it
for now).

> Then as v5.15-rc1 lands, we have the API and we can follow up changing
> these more complex drivers - and those patches can go through the
> individual maintainer trees.
>
> Regards,
> Bjorn
>
> > ---
> >  drivers/clk/qcom/camcc-sc7180.c       | 25 +++++++++------------
> >  drivers/clk/qcom/lpass-gfm-sm8250.c   | 21 ++++++++----------
> >  drivers/clk/qcom/lpasscorecc-sc7180.c | 18 ++-------------
> >  drivers/clk/qcom/mss-sc7180.c         | 30 +++++++------------------
> >  drivers/clk/qcom/q6sstop-qcs404.c     | 32 ++++++++-------------------
> >  drivers/clk/qcom/turingcc-qcs404.c    | 30 +++++++------------------
> >  6 files changed, 46 insertions(+), 110 deletions(-)
> >
> > diff --git a/drivers/clk/qcom/camcc-sc7180.c b/drivers/clk/qcom/camcc-sc7180.c
> > index 9bcf2f8ed4de..ce73ee9037cb 100644
> > --- a/drivers/clk/qcom/camcc-sc7180.c
> > +++ b/drivers/clk/qcom/camcc-sc7180.c
> > @@ -1652,32 +1652,35 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
> >       struct regmap *regmap;
> >       int ret;
> >
> > -     pm_runtime_enable(&pdev->dev);
> > -     ret = pm_clk_create(&pdev->dev);
> > +     ret = devm_pm_runtime_enable(&pdev->dev);
> > +     if (ret < 0)
> > +             return ret;
> > +
> > +     ret = devm_pm_clk_create(&pdev->dev);
> >       if (ret < 0)
> >               return ret;
> >
> >       ret = pm_clk_add(&pdev->dev, "xo");
> >       if (ret < 0) {
> >               dev_err(&pdev->dev, "Failed to acquire XO clock\n");
> > -             goto disable_pm_runtime;
> > +             return ret;
> >       }
> >
> >       ret = pm_clk_add(&pdev->dev, "iface");
> >       if (ret < 0) {
> >               dev_err(&pdev->dev, "Failed to acquire iface clock\n");
> > -             goto disable_pm_runtime;
> > +             return ret;
> >       }
> >
> >       ret = pm_runtime_get(&pdev->dev);
> >       if (ret)
> > -             goto destroy_pm_clk;
> > +             return ret;
> >
> >       regmap = qcom_cc_map(pdev, &cam_cc_sc7180_desc);
> >       if (IS_ERR(regmap)) {
> >               ret = PTR_ERR(regmap);
> >               pm_runtime_put(&pdev->dev);
> > -             goto destroy_pm_clk;
> > +             return ret;
> >       }
> >
> >       clk_fabia_pll_configure(&cam_cc_pll0, regmap, &cam_cc_pll0_config);
> > @@ -1689,18 +1692,10 @@ static int cam_cc_sc7180_probe(struct platform_device *pdev)
> >       pm_runtime_put(&pdev->dev);
> >       if (ret < 0) {
> >               dev_err(&pdev->dev, "Failed to register CAM CC clocks\n");
> > -             goto destroy_pm_clk;
> > +             return ret;
> >       }
> >
> >       return 0;
> > -
> > -destroy_pm_clk:
> > -     pm_clk_destroy(&pdev->dev);
> > -
> > -disable_pm_runtime:
> > -     pm_runtime_disable(&pdev->dev);
> > -
> > -     return ret;
> >  }
> >
> >  static const struct dev_pm_ops cam_cc_pm_ops = {
> > diff --git a/drivers/clk/qcom/lpass-gfm-sm8250.c b/drivers/clk/qcom/lpass-gfm-sm8250.c
> > index f5e31e692b9b..96f476f24eb2 100644
> > --- a/drivers/clk/qcom/lpass-gfm-sm8250.c
> > +++ b/drivers/clk/qcom/lpass-gfm-sm8250.c
> > @@ -251,15 +251,18 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev)
> >       if (IS_ERR(cc->base))
> >               return PTR_ERR(cc->base);
> >
> > -     pm_runtime_enable(dev);
> > -     err = pm_clk_create(dev);
> > +     err = devm_pm_runtime_enable(dev);
> >       if (err)
> > -             goto pm_clk_err;
> > +             return err;
> > +
> > +     err = devm_pm_clk_create(dev);
> > +     if (err)
> > +             return err;
> >
> >       err = of_pm_clk_add_clks(dev);
> >       if (err < 0) {
> >               dev_dbg(dev, "Failed to get lpass core voting clocks\n");
> > -             goto clk_reg_err;
> > +             return err;
> >       }
> >
> >       for (i = 0; i < data->onecell_data->num; i++) {
> > @@ -273,22 +276,16 @@ static int lpass_gfm_clk_driver_probe(struct platform_device *pdev)
> >
> >               err = devm_clk_hw_register(dev, &data->gfm_clks[i]->hw);
> >               if (err)
> > -                     goto clk_reg_err;
> > +                     return err;
> >
> >       }
> >
> >       err = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
> >                                         data->onecell_data);
> >       if (err)
> > -             goto clk_reg_err;
> > +             return err;
> >
> >       return 0;
> > -
> > -clk_reg_err:
> > -     pm_clk_destroy(dev);
> > -pm_clk_err:
> > -     pm_runtime_disable(dev);
> > -     return err;
> >  }
> >
> >  static const struct of_device_id lpass_gfm_clk_match_table[] = {
> > diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c
> > index 2e0ecc38efdd..ac09b7b840ab 100644
> > --- a/drivers/clk/qcom/lpasscorecc-sc7180.c
> > +++ b/drivers/clk/qcom/lpasscorecc-sc7180.c
> > @@ -356,32 +356,18 @@ static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = {
> >       .num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs),
> >  };
> >
> > -static void lpass_pm_runtime_disable(void *data)
> > -{
> > -     pm_runtime_disable(data);
> > -}
> > -
> > -static void lpass_pm_clk_destroy(void *data)
> > -{
> > -     pm_clk_destroy(data);
> > -}
> > -
> >  static int lpass_create_pm_clks(struct platform_device *pdev)
> >  {
> >       int ret;
> >
> >       pm_runtime_use_autosuspend(&pdev->dev);
> >       pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
> > -     pm_runtime_enable(&pdev->dev);
> >
> > -     ret = devm_add_action_or_reset(&pdev->dev, lpass_pm_runtime_disable, &pdev->dev);
> > +     ret = devm_pm_runtime_enable(&pdev->dev);
> >       if (ret)
> >               return ret;
> >
> > -     ret = pm_clk_create(&pdev->dev);
> > -     if (ret)
> > -             return ret;
> > -     ret = devm_add_action_or_reset(&pdev->dev, lpass_pm_clk_destroy, &pdev->dev);
> > +     ret = devm_pm_clk_create(&pdev->dev);
> >       if (ret)
> >               return ret;
> >
> > diff --git a/drivers/clk/qcom/mss-sc7180.c b/drivers/clk/qcom/mss-sc7180.c
> > index 673fa1a4f734..5a1407440662 100644
> > --- a/drivers/clk/qcom/mss-sc7180.c
> > +++ b/drivers/clk/qcom/mss-sc7180.c
> > @@ -73,36 +73,23 @@ static int mss_sc7180_probe(struct platform_device *pdev)
> >  {
> >       int ret;
> >
> > -     pm_runtime_enable(&pdev->dev);
> > -     ret = pm_clk_create(&pdev->dev);
> > +     ret = devm_pm_runtime_enable(&pdev->dev);
> >       if (ret)
> > -             goto disable_pm_runtime;
> > +             return ret;
> > +
> > +     ret = devm_pm_clk_create(&pdev->dev);
> > +     if (ret)
> > +             return ret;
> >
> >       ret = pm_clk_add(&pdev->dev, "cfg_ahb");
> >       if (ret < 0) {
> >               dev_err(&pdev->dev, "failed to acquire iface clock\n");
> > -             goto destroy_pm_clk;
> > +             return ret;
> >       }
> >
> >       ret = qcom_cc_probe(pdev, &mss_sc7180_desc);
> >       if (ret < 0)
> > -             goto destroy_pm_clk;
> > -
> > -     return 0;
> > -
> > -destroy_pm_clk:
> > -     pm_clk_destroy(&pdev->dev);
> > -
> > -disable_pm_runtime:
> > -     pm_runtime_disable(&pdev->dev);
> > -
> > -     return ret;
> > -}
> > -
> > -static int mss_sc7180_remove(struct platform_device *pdev)
> > -{
> > -     pm_clk_destroy(&pdev->dev);
> > -     pm_runtime_disable(&pdev->dev);
> > +             return ret;
> >
> >       return 0;
> >  }
> > @@ -119,7 +106,6 @@ MODULE_DEVICE_TABLE(of, mss_sc7180_match_table);
> >
> >  static struct platform_driver mss_sc7180_driver = {
> >       .probe          = mss_sc7180_probe,
> > -     .remove         = mss_sc7180_remove,
> >       .driver         = {
> >               .name           = "sc7180-mss",
> >               .of_match_table = mss_sc7180_match_table,
> > diff --git a/drivers/clk/qcom/q6sstop-qcs404.c b/drivers/clk/qcom/q6sstop-qcs404.c
> > index 723f932fbf7d..507386bee07d 100644
> > --- a/drivers/clk/qcom/q6sstop-qcs404.c
> > +++ b/drivers/clk/qcom/q6sstop-qcs404.c
> > @@ -159,15 +159,18 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
> >       const struct qcom_cc_desc *desc;
> >       int ret;
> >
> > -     pm_runtime_enable(&pdev->dev);
> > -     ret = pm_clk_create(&pdev->dev);
> > +     ret = devm_pm_runtime_enable(&pdev->dev);
> >       if (ret)
> > -             goto disable_pm_runtime;
> > +             return ret;
> > +
> > +     ret = devm_pm_clk_create(&pdev->dev);
> > +     if (ret)
> > +             return ret;
> >
> >       ret = pm_clk_add(&pdev->dev, NULL);
> >       if (ret < 0) {
> >               dev_err(&pdev->dev, "failed to acquire iface clock\n");
> > -             goto destroy_pm_clk;
> > +             return ret;
> >       }
> >
> >       q6sstop_regmap_config.name = "q6sstop_tcsr";
> > @@ -175,30 +178,14 @@ static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
> >
> >       ret = qcom_cc_probe_by_index(pdev, 1, desc);
> >       if (ret)
> > -             goto destroy_pm_clk;
> > +             return ret;
> >
> >       q6sstop_regmap_config.name = "q6sstop_cc";
> >       desc = &q6sstop_qcs404_desc;
> >
> >       ret = qcom_cc_probe_by_index(pdev, 0, desc);
> >       if (ret)
> > -             goto destroy_pm_clk;
> > -
> > -     return 0;
> > -
> > -destroy_pm_clk:
> > -     pm_clk_destroy(&pdev->dev);
> > -
> > -disable_pm_runtime:
> > -     pm_runtime_disable(&pdev->dev);
> > -
> > -     return ret;
> > -}
> > -
> > -static int q6sstopcc_qcs404_remove(struct platform_device *pdev)
> > -{
> > -     pm_clk_destroy(&pdev->dev);
> > -     pm_runtime_disable(&pdev->dev);
> > +             return ret;
> >
> >       return 0;
> >  }
> > @@ -209,7 +196,6 @@ static const struct dev_pm_ops q6sstopcc_pm_ops = {
> >
> >  static struct platform_driver q6sstopcc_qcs404_driver = {
> >       .probe          = q6sstopcc_qcs404_probe,
> > -     .remove         = q6sstopcc_qcs404_remove,
> >       .driver         = {
> >               .name   = "qcs404-q6sstopcc",
> >               .of_match_table = q6sstopcc_qcs404_match_table,
> > diff --git a/drivers/clk/qcom/turingcc-qcs404.c b/drivers/clk/qcom/turingcc-qcs404.c
> > index 4cfbbf5bf4d9..4543bda793f4 100644
> > --- a/drivers/clk/qcom/turingcc-qcs404.c
> > +++ b/drivers/clk/qcom/turingcc-qcs404.c
> > @@ -110,36 +110,23 @@ static int turingcc_probe(struct platform_device *pdev)
> >  {
> >       int ret;
> >
> > -     pm_runtime_enable(&pdev->dev);
> > -     ret = pm_clk_create(&pdev->dev);
> > +     ret = devm_pm_runtime_enable(&pdev->dev);
> >       if (ret)
> > -             goto disable_pm_runtime;
> > +             return ret;
> > +
> > +     ret = devm_pm_clk_create(&pdev->dev);
> > +     if (ret)
> > +             return ret;
> >
> >       ret = pm_clk_add(&pdev->dev, NULL);
> >       if (ret < 0) {
> >               dev_err(&pdev->dev, "failed to acquire iface clock\n");
> > -             goto destroy_pm_clk;
> > +             return ret;
> >       }
> >
> >       ret = qcom_cc_probe(pdev, &turingcc_desc);
> >       if (ret < 0)
> > -             goto destroy_pm_clk;
> > -
> > -     return 0;
> > -
> > -destroy_pm_clk:
> > -     pm_clk_destroy(&pdev->dev);
> > -
> > -disable_pm_runtime:
> > -     pm_runtime_disable(&pdev->dev);
> > -
> > -     return ret;
> > -}
> > -
> > -static int turingcc_remove(struct platform_device *pdev)
> > -{
> > -     pm_clk_destroy(&pdev->dev);
> > -     pm_runtime_disable(&pdev->dev);
> > +             return ret;
> >
> >       return 0;
> >  }
> > @@ -156,7 +143,6 @@ MODULE_DEVICE_TABLE(of, turingcc_match_table);
> >
> >  static struct platform_driver turingcc_driver = {
> >       .probe          = turingcc_probe,
> > -     .remove         = turingcc_remove,
> >       .driver         = {
> >               .name   = "qcs404-turingcc",
> >               .of_match_table = turingcc_match_table,
> > --
> > 2.30.2
> >



-- 
With best wishes
Dmitry

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 14:24 [PATCH v2 0/5] PM: add two devres helpers and use them in qcom cc Dmitry Baryshkov
2021-07-28 14:24 ` [PATCH v2 1/5] PM: runtime: add devm_pm_runtime_enable helper Dmitry Baryshkov
2021-07-28 20:04   ` Bjorn Andersson
2021-07-28 14:24 ` [PATCH v2 2/5] PM: clk: add devm_pm_clk_create helper Dmitry Baryshkov
2021-07-28 20:05   ` Bjorn Andersson
2021-07-28 14:24 ` [PATCH v2 3/5] clk: qcom: use devm_pm_runtime_enable and devm_pm_clk_create Dmitry Baryshkov
2021-07-28 15:00   ` Bjorn Andersson
2021-07-29 14:28     ` Dmitry Baryshkov
2021-07-28 14:24 ` [PATCH v2 4/5] clk: qcom: use common code for qcom_cc_probe_by_index Dmitry Baryshkov
2021-07-28 14:24 ` [PATCH v2 5/5] clk: qcom: move pm_clk functionality into common code Dmitry Baryshkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.