Skip to contentSkip to conversation

thermal: sprd: Use devm_clk_get_enabled() helpers

PATCH Applied Huan Yang 3 participants 3 messages Aug 20, 2024 – Sep 2, 2024

Subsystems (2)
lore
Share & tools
lore

Huan Yang

author
#0 lore raw

PATCH 1/1 thermal: sprd: Use devm_clk_get_enabled() helpers

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

---
 drivers/thermal/sprd_thermal.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/thermal/sprd_thermal.c +3 -11
index 874192546548..dfd1d529c410 100644
@@ -359,21 +359,17 @@ static int sprd_thm_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	thm->clk = devm_clk_get(&pdev->dev, "enable");
+	thm->clk = devm_clk_get_enabled(&pdev->dev, "enable");
 	if (IS_ERR(thm->clk)) {
 		dev_err(&pdev->dev, "failed to get enable clock\n");
 		return PTR_ERR(thm->clk);
 	}
 
-	ret = clk_prepare_enable(thm->clk);
-	if (ret)
-		return ret;
-
 	sprd_thm_para_config(thm);
 
 	ret = sprd_thm_cal_read(np, "thm_sign_cal", &val);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	if (val > 0)
 		thm->ratio_sign = -1;
@@ -382,7 +378,7 @@ static int sprd_thm_probe(struct platform_device *pdev)
 
 	ret = sprd_thm_cal_read(np, "thm_ratio_cal", &thm->ratio_off);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	for_each_child_of_node(np, sen_child) {
 		sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL);
@@ -439,8 +435,6 @@ static int sprd_thm_probe(struct platform_device *pdev)
 
 of_put:
 	of_node_put(sen_child);
-disable_clk:
-	clk_disable_unprepare(thm->clk);
 	return ret;
 }
 
@@ -526,8 +520,6 @@ static void sprd_thm_remove(struct platform_device *pdev)
 		devm_thermal_of_zone_unregister(&pdev->dev,
 						thm->sensor[i]->tzd);
 	}
-
-	clk_disable_unprepare(thm->clk);
 }
 
 static const struct of_device_id sprd_thermal_of_match[] = {
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Huan Yang

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

Thanks. LGTM.

Quoted 59 lines
---
  drivers/thermal/sprd_thermal.c | 14 +++-----------
  1 file changed, 3 insertions(+), 11 deletions(-)
drivers/thermal/sprd_thermal.c +3 -11
index 874192546548..dfd1d529c410 100644
@@ -359,21 +359,17 @@ static int sprd_thm_probe(struct platform_device *pdev)
  		return -EINVAL;
  	}
 
-	thm->clk = devm_clk_get(&pdev->dev, "enable");
+	thm->clk = devm_clk_get_enabled(&pdev->dev, "enable");
  	if (IS_ERR(thm->clk)) {
  		dev_err(&pdev->dev, "failed to get enable clock\n");
  		return PTR_ERR(thm->clk);
  	}
 
-	ret = clk_prepare_enable(thm->clk);
-	if (ret)
-		return ret;
-
  	sprd_thm_para_config(thm);
 
  	ret = sprd_thm_cal_read(np, "thm_sign_cal", &val);
  	if (ret)
-		goto disable_clk;
+		return ret;
 
  	if (val > 0)
  		thm->ratio_sign = -1;
@@ -382,7 +378,7 @@ static int sprd_thm_probe(struct platform_device *pdev)
 
  	ret = sprd_thm_cal_read(np, "thm_ratio_cal", &thm->ratio_off);
  	if (ret)
-		goto disable_clk;
+		return ret;
 
  	for_each_child_of_node(np, sen_child) {
  		sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL);
@@ -439,8 +435,6 @@ static int sprd_thm_probe(struct platform_device *pdev)
 
  of_put:
  	of_node_put(sen_child);
-disable_clk:
-	clk_disable_unprepare(thm->clk);
  	return ret;
  }
 
@@ -526,8 +520,6 @@ static void sprd_thm_remove(struct platform_device *pdev)
  		devm_thermal_of_zone_unregister(&pdev->dev,
  						thm->sensor[i]->tzd);
  	}
-
-	clk_disable_unprepare(thm->clk);
  }
 
  static const struct of_device_id sprd_thermal_of_match[] = {
#2 lore raw
In reply to Huan Yang
Quoted 9 lines · Huan Yang

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

---

Applied, thanks

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog