diff mbox series

watchdog: pic32-wdt: Use devm_clk_get_enabled() helper

Message ID 4335b4201b535ebc749a98bad0b99e3cb5317c39.1672496563.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series watchdog: pic32-wdt: Use devm_clk_get_enabled() helper | expand

Commit Message

Christophe JAILLET Dec. 31, 2022, 2:22 p.m. UTC
The devm_clk_get_enabled() helper:
   - calls devm_clk_get()
   - calls clk_prepare_enable() and registers what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the need of a dedicated function used
with devm_add_action_or_reset().

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/watchdog/pic32-wdt.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

Comments

Guenter Roeck Jan. 3, 2023, 9:15 p.m. UTC | #1
On Sat, Dec 31, 2022 at 03:22:57PM +0100, Christophe JAILLET wrote:
> The devm_clk_get_enabled() helper:
>    - calls devm_clk_get()
>    - calls clk_prepare_enable() and registers what is needed in order to
>      call clk_disable_unprepare() when needed, as a managed resource.
> 
> This simplifies the code and avoids the need of a dedicated function used
> with devm_add_action_or_reset().
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/watchdog/pic32-wdt.c | 17 +----------------
>  1 file changed, 1 insertion(+), 16 deletions(-)
> 
> diff --git a/drivers/watchdog/pic32-wdt.c b/drivers/watchdog/pic32-wdt.c
> index 41715d68d9e9..6d1a00222991 100644
> --- a/drivers/watchdog/pic32-wdt.c
> +++ b/drivers/watchdog/pic32-wdt.c
> @@ -162,11 +162,6 @@ static const struct of_device_id pic32_wdt_dt_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, pic32_wdt_dt_ids);
>  
> -static void pic32_clk_disable_unprepare(void *data)
> -{
> -	clk_disable_unprepare(data);
> -}
> -
>  static int pic32_wdt_drv_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -186,22 +181,12 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev)
>  	if (!wdt->rst_base)
>  		return -ENOMEM;
>  
> -	wdt->clk = devm_clk_get(dev, NULL);
> +	wdt->clk = devm_clk_get_enabled(dev, NULL);
>  	if (IS_ERR(wdt->clk)) {
>  		dev_err(dev, "clk not found\n");
>  		return PTR_ERR(wdt->clk);
>  	}
>  
> -	ret = clk_prepare_enable(wdt->clk);
> -	if (ret) {
> -		dev_err(dev, "clk enable failed\n");
> -		return ret;
> -	}
> -	ret = devm_add_action_or_reset(dev, pic32_clk_disable_unprepare,
> -				       wdt->clk);
> -	if (ret)
> -		return ret;
> -
>  	if (pic32_wdt_is_win_enabled(wdt)) {
>  		dev_err(dev, "windowed-clear mode is not supported.\n");
>  		return -ENODEV;
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/watchdog/pic32-wdt.c b/drivers/watchdog/pic32-wdt.c
index 41715d68d9e9..6d1a00222991 100644
--- a/drivers/watchdog/pic32-wdt.c
+++ b/drivers/watchdog/pic32-wdt.c
@@ -162,11 +162,6 @@  static const struct of_device_id pic32_wdt_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, pic32_wdt_dt_ids);
 
-static void pic32_clk_disable_unprepare(void *data)
-{
-	clk_disable_unprepare(data);
-}
-
 static int pic32_wdt_drv_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -186,22 +181,12 @@  static int pic32_wdt_drv_probe(struct platform_device *pdev)
 	if (!wdt->rst_base)
 		return -ENOMEM;
 
-	wdt->clk = devm_clk_get(dev, NULL);
+	wdt->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(wdt->clk)) {
 		dev_err(dev, "clk not found\n");
 		return PTR_ERR(wdt->clk);
 	}
 
-	ret = clk_prepare_enable(wdt->clk);
-	if (ret) {
-		dev_err(dev, "clk enable failed\n");
-		return ret;
-	}
-	ret = devm_add_action_or_reset(dev, pic32_clk_disable_unprepare,
-				       wdt->clk);
-	if (ret)
-		return ret;
-
 	if (pic32_wdt_is_win_enabled(wdt)) {
 		dev_err(dev, "windowed-clear mode is not supported.\n");
 		return -ENODEV;