linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/5] pinctrl: k210: Use devm_clk_get_enabled() helpers
@ 2024-08-29  6:49 Wang Jianzheng
  2024-08-30  4:54 ` Damien Le Moal
  2024-09-02  8:26 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Wang Jianzheng @ 2024-08-29  6:49 UTC (permalink / raw)
  To: Damien Le Moal, Linus Walleij,
	open list:CANAAN/KENDRYTE K210 SOC FPIOA DRIVER,
	open list:CANAAN/KENDRYTE K210 SOC FPIOA DRIVER, open list
  Cc: opensource.kernel, wangjianzheng

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

Signed-off-by: Wang Jianzheng <wangjianzheng@vivo.com>
---
 drivers/pinctrl/pinctrl-k210.c | 35 ++++++++--------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-k210.c b/drivers/pinctrl/pinctrl-k210.c
index a898e40451fe..0f6b55fec31d 100644
--- a/drivers/pinctrl/pinctrl-k210.c
+++ b/drivers/pinctrl/pinctrl-k210.c
@@ -925,7 +925,6 @@ static int k210_fpioa_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
 	struct k210_fpioa_data *pdata;
-	int ret;
 
 	dev_info(dev, "K210 FPIOA pin controller\n");
 
@@ -940,46 +939,28 @@ static int k210_fpioa_probe(struct platform_device *pdev)
 	if (IS_ERR(pdata->fpioa))
 		return PTR_ERR(pdata->fpioa);
 
-	pdata->clk = devm_clk_get(dev, "ref");
+	pdata->clk = devm_clk_get_enabled(dev, "ref");
 	if (IS_ERR(pdata->clk))
 		return PTR_ERR(pdata->clk);
 
-	ret = clk_prepare_enable(pdata->clk);
-	if (ret)
-		return ret;
-
-	pdata->pclk = devm_clk_get_optional(dev, "pclk");
-	if (!IS_ERR(pdata->pclk)) {
-		ret = clk_prepare_enable(pdata->pclk);
-		if (ret)
-			goto disable_clk;
-	}
+	pdata->pclk = devm_clk_get_optional_enabled(dev, "pclk");
+	if (IS_ERR(pdata->pclk))
+		return PTR_ERR(pdata->pclk);
 
 	pdata->sysctl_map =
 		syscon_regmap_lookup_by_phandle_args(np,
 						"canaan,k210-sysctl-power",
 						1, &pdata->power_offset);
-	if (IS_ERR(pdata->sysctl_map)) {
-		ret = PTR_ERR(pdata->sysctl_map);
-		goto disable_pclk;
-	}
+	if (IS_ERR(pdata->sysctl_map))
+		return PTR_ERR(pdata->sysctl_map);
 
 	k210_fpioa_init_ties(pdata);
 
 	pdata->pctl = pinctrl_register(&k210_pinctrl_desc, dev, (void *)pdata);
-	if (IS_ERR(pdata->pctl)) {
-		ret = PTR_ERR(pdata->pctl);
-		goto disable_pclk;
-	}
+	if (IS_ERR(pdata->pctl))
+		return PTR_ERR(pdata->pctl);
 
 	return 0;
-
-disable_pclk:
-	clk_disable_unprepare(pdata->pclk);
-disable_clk:
-	clk_disable_unprepare(pdata->clk);
-
-	return ret;
 }
 
 static const struct of_device_id k210_fpioa_dt_ids[] = {
-- 
2.34.1


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

* Re: [PATCH 4/5] pinctrl: k210: Use devm_clk_get_enabled() helpers
  2024-08-29  6:49 [PATCH 4/5] pinctrl: k210: Use devm_clk_get_enabled() helpers Wang Jianzheng
@ 2024-08-30  4:54 ` Damien Le Moal
  2024-09-02  8:26 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2024-08-30  4:54 UTC (permalink / raw)
  To: Wang Jianzheng, Linus Walleij,
	open list:CANAAN/KENDRYTE K210 SOC FPIOA DRIVER,
	open list:CANAAN/KENDRYTE K210 SOC FPIOA DRIVER, open list
  Cc: opensource.kernel

On 8/29/24 3:49 PM, Wang Jianzheng wrote:
> 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().
> 
> Signed-off-by: Wang Jianzheng <wangjianzheng@vivo.com>

Looks OK to me.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH 4/5] pinctrl: k210: Use devm_clk_get_enabled() helpers
  2024-08-29  6:49 [PATCH 4/5] pinctrl: k210: Use devm_clk_get_enabled() helpers Wang Jianzheng
  2024-08-30  4:54 ` Damien Le Moal
@ 2024-09-02  8:26 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2024-09-02  8:26 UTC (permalink / raw)
  To: Wang Jianzheng
  Cc: Damien Le Moal, open list:CANAAN/KENDRYTE K210 SOC FPIOA DRIVER,
	open list:CANAAN/KENDRYTE K210 SOC FPIOA DRIVER, open list,
	opensource.kernel

On Thu, Aug 29, 2024 at 8:49 AM Wang Jianzheng <wangjianzheng@vivo.com> wrote:

> 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().
>
> Signed-off-by: Wang Jianzheng <wangjianzheng@vivo.com>

Patch applied!

Yours,
Linus Walleij

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

end of thread, other threads:[~2024-09-02  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29  6:49 [PATCH 4/5] pinctrl: k210: Use devm_clk_get_enabled() helpers Wang Jianzheng
2024-08-30  4:54 ` Damien Le Moal
2024-09-02  8:26 ` Linus Walleij

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