diff mbox series

leds: lp55xx: Use devm_clk_get_enabled() helpers

Message ID 20240820102006.128840-1-link@vivo.com
State New
Headers show
Series leds: lp55xx: Use devm_clk_get_enabled() helpers | expand

Commit Message

Huan Yang Aug. 20, 2024, 10:20 a.m. UTC
lp55xx lp55xx_is_extclk_used get, enable clk and
deinit_device disable and unprepare it.

This can use a simplifies helper to cover.

Signed-off-by: Huan Yang <link@vivo.com>
---
 drivers/leds/leds-lp55xx-common.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

Comments

Christophe JAILLET Aug. 20, 2024, 1:13 p.m. UTC | #1
Le 20/08/2024 à 12:20, Huan Yang a écrit :
> lp55xx lp55xx_is_extclk_used get, enable clk and
> deinit_device disable and unprepare it.
> 
> This can use a simplifies helper to cover.
> 
> Signed-off-by: Huan Yang <link@vivo.com>
> ---

Hi,

if you want to go 1 step further, I think that 'vlk' can now also be 
removed from struct lp55xx_chip.

Just my 2c.

CJ


>   drivers/leds/leds-lp55xx-common.c | 14 ++------------
>   1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
> index 29e7142dca72..76dc62a3bd45 100644
> --- a/drivers/leds/leds-lp55xx-common.c
> +++ b/drivers/leds/leds-lp55xx-common.c
> @@ -965,21 +965,14 @@ EXPORT_SYMBOL_GPL(lp55xx_update_bits);
>   bool lp55xx_is_extclk_used(struct lp55xx_chip *chip)
>   {
>   	struct clk *clk;
> -	int err;
>   
> -	clk = devm_clk_get(&chip->cl->dev, "32k_clk");
> +	clk = devm_clk_get_enabled(&chip->cl->dev, "32k_clk");
>   	if (IS_ERR(clk))
>   		goto use_internal_clk;
>   
> -	err = clk_prepare_enable(clk);
> -	if (err)
> +	if (clk_get_rate(clk) != LP55XX_CLK_32K)
>   		goto use_internal_clk;
>   
> -	if (clk_get_rate(clk) != LP55XX_CLK_32K) {
> -		clk_disable_unprepare(clk);
> -		goto use_internal_clk;
> -	}
> -
>   	dev_info(&chip->cl->dev, "%dHz external clock used\n",	LP55XX_CLK_32K);
>   
>   	chip->clk = clk;
> @@ -995,9 +988,6 @@ static void lp55xx_deinit_device(struct lp55xx_chip *chip)
>   {
>   	struct lp55xx_platform_data *pdata = chip->pdata;
>   
> -	if (chip->clk)
> -		clk_disable_unprepare(chip->clk);
> -
>   	if (pdata->enable_gpiod)
>   		gpiod_set_value(pdata->enable_gpiod, 0);
>   }
Lee Jones Aug. 22, 2024, 1:27 p.m. UTC | #2
On Tue, 20 Aug 2024 18:20:06 +0800, Huan Yang wrote:
> lp55xx lp55xx_is_extclk_used get, enable clk and
> deinit_device disable and unprepare it.
> 
> This can use a simplifies helper to cover.
> 
> 

Applied, thanks!

[1/1] leds: lp55xx: Use devm_clk_get_enabled() helpers
      commit: d4f5c2c6b36b12fe627dd4372bb4d47a1811b9f4

--
Lee Jones [李琼斯]
Lee Jones Aug. 22, 2024, 1:28 p.m. UTC | #3
On Tue, 20 Aug 2024, Huan Yang wrote:

> lp55xx lp55xx_is_extclk_used get, enable clk and
> deinit_device disable and unprepare it.
> 
> This can use a simplifies helper to cover.
> 
> Signed-off-by: Huan Yang <link@vivo.com>
> ---
>  drivers/leds/leds-lp55xx-common.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)

The commit message makes little sense, so I rewrote it for you.
diff mbox series

Patch

diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 29e7142dca72..76dc62a3bd45 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -965,21 +965,14 @@  EXPORT_SYMBOL_GPL(lp55xx_update_bits);
 bool lp55xx_is_extclk_used(struct lp55xx_chip *chip)
 {
 	struct clk *clk;
-	int err;
 
-	clk = devm_clk_get(&chip->cl->dev, "32k_clk");
+	clk = devm_clk_get_enabled(&chip->cl->dev, "32k_clk");
 	if (IS_ERR(clk))
 		goto use_internal_clk;
 
-	err = clk_prepare_enable(clk);
-	if (err)
+	if (clk_get_rate(clk) != LP55XX_CLK_32K)
 		goto use_internal_clk;
 
-	if (clk_get_rate(clk) != LP55XX_CLK_32K) {
-		clk_disable_unprepare(clk);
-		goto use_internal_clk;
-	}
-
 	dev_info(&chip->cl->dev, "%dHz external clock used\n",	LP55XX_CLK_32K);
 
 	chip->clk = clk;
@@ -995,9 +988,6 @@  static void lp55xx_deinit_device(struct lp55xx_chip *chip)
 {
 	struct lp55xx_platform_data *pdata = chip->pdata;
 
-	if (chip->clk)
-		clk_disable_unprepare(chip->clk);
-
 	if (pdata->enable_gpiod)
 		gpiod_set_value(pdata->enable_gpiod, 0);
 }