diff mbox series

[v4,4/6] rtc: at91sma9: Simplify using devm_clk_get_enabled()

Message ID 20210330181755.204339-5-u.kleine-koenig@pengutronix.de (mailing list archive)
State Under Review
Headers show
Series clk: provide new devm helpers for prepared and enabled clocks | expand

Commit Message

Uwe Kleine-König March 30, 2021, 6:17 p.m. UTC
devm_clk_get_enabled() returns the clk already (prepared and) enabled
and the automatically called cleanup cares for disabling (and
unpreparing). So simplify .probe() and .remove() accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/rtc/rtc-at91sam9.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

Comments

Nicolas Ferre April 6, 2021, 12:55 p.m. UTC | #1
On 30/03/2021 at 20:17, Uwe Kleine-König wrote:
> devm_clk_get_enabled() returns the clk already (prepared and) enabled
> and the automatically called cleanup cares for disabling (and
> unpreparing). So simplify .probe() and .remove() accordingly.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

I do see the benefit:
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>

Thanks Uwe for taking these drivers as examples! Best regards,
   Nicolas

> ---
>   drivers/rtc/rtc-at91sam9.c | 22 ++++------------------
>   1 file changed, 4 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
> index 2216be429ab7..b52e7bd26303 100644
> --- a/drivers/rtc/rtc-at91sam9.c
> +++ b/drivers/rtc/rtc-at91sam9.c
> @@ -374,21 +374,14 @@ static int at91_rtc_probe(struct platform_device *pdev)
>                  return -ENOMEM;
>          }
> 
> -       rtc->sclk = devm_clk_get(&pdev->dev, NULL);
> +       rtc->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
>          if (IS_ERR(rtc->sclk))
>                  return PTR_ERR(rtc->sclk);
> 
> -       ret = clk_prepare_enable(rtc->sclk);
> -       if (ret) {
> -               dev_err(&pdev->dev, "Could not enable slow clock\n");
> -               return ret;
> -       }
> -
>          sclk_rate = clk_get_rate(rtc->sclk);
>          if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) {
>                  dev_err(&pdev->dev, "Invalid slow clock rate\n");
> -               ret = -EINVAL;
> -               goto err_clk;
> +               return -EINVAL;
>          }
> 
>          mr = rtt_readl(rtc, MR);
> @@ -406,7 +399,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
>          rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
>          if (IS_ERR(rtc->rtcdev)) {
>                  ret = PTR_ERR(rtc->rtcdev);
> -               goto err_clk;
> +               return ret;
>          }
> 
>          rtc->rtcdev->ops = &at91_rtc_ops;
> @@ -418,7 +411,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
>                                 dev_name(&rtc->rtcdev->dev), rtc);
>          if (ret) {
>                  dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
> -               goto err_clk;
> +               return ret;
>          }
> 
>          /* NOTE:  sam9260 rev A silicon has a ROM bug which resets the
> @@ -432,11 +425,6 @@ static int at91_rtc_probe(struct platform_device *pdev)
>                           dev_name(&rtc->rtcdev->dev));
> 
>          return devm_rtc_register_device(rtc->rtcdev);
> -
> -err_clk:
> -       clk_disable_unprepare(rtc->sclk);
> -
> -       return ret;
>   }
> 
>   /*
> @@ -450,8 +438,6 @@ static int at91_rtc_remove(struct platform_device *pdev)
>          /* disable all interrupts */
>          rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
> 
> -       clk_disable_unprepare(rtc->sclk);
> -
>          return 0;
>   }
> 
> --
> 2.30.2
>
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 2216be429ab7..b52e7bd26303 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -374,21 +374,14 @@  static int at91_rtc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	rtc->sclk = devm_clk_get(&pdev->dev, NULL);
+	rtc->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(rtc->sclk))
 		return PTR_ERR(rtc->sclk);
 
-	ret = clk_prepare_enable(rtc->sclk);
-	if (ret) {
-		dev_err(&pdev->dev, "Could not enable slow clock\n");
-		return ret;
-	}
-
 	sclk_rate = clk_get_rate(rtc->sclk);
 	if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) {
 		dev_err(&pdev->dev, "Invalid slow clock rate\n");
-		ret = -EINVAL;
-		goto err_clk;
+		return -EINVAL;
 	}
 
 	mr = rtt_readl(rtc, MR);
@@ -406,7 +399,7 @@  static int at91_rtc_probe(struct platform_device *pdev)
 	rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(rtc->rtcdev)) {
 		ret = PTR_ERR(rtc->rtcdev);
-		goto err_clk;
+		return ret;
 	}
 
 	rtc->rtcdev->ops = &at91_rtc_ops;
@@ -418,7 +411,7 @@  static int at91_rtc_probe(struct platform_device *pdev)
 			       dev_name(&rtc->rtcdev->dev), rtc);
 	if (ret) {
 		dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
-		goto err_clk;
+		return ret;
 	}
 
 	/* NOTE:  sam9260 rev A silicon has a ROM bug which resets the
@@ -432,11 +425,6 @@  static int at91_rtc_probe(struct platform_device *pdev)
 			 dev_name(&rtc->rtcdev->dev));
 
 	return devm_rtc_register_device(rtc->rtcdev);
-
-err_clk:
-	clk_disable_unprepare(rtc->sclk);
-
-	return ret;
 }
 
 /*
@@ -450,8 +438,6 @@  static int at91_rtc_remove(struct platform_device *pdev)
 	/* disable all interrupts */
 	rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
 
-	clk_disable_unprepare(rtc->sclk);
-
 	return 0;
 }