iio: adc: ad7192: Simplify using devm_clk_get_optional_enabled()

Message ID 7dbe973905f1fdae5d2f5ae5a3b01dd1d6a9925b.1686774340.git.christophe.jaillet@wanadoo.fr
State New
Headers
Series iio: adc: ad7192: Simplify using devm_clk_get_optional_enabled() |

Commit Message

Christophe JAILLET June 14, 2023, 8:26 p.m. UTC
  If st->mclk is not NULL, then st->clock_sel is either AD7192_CLK_EXT_MCLK2
or AD7192_CLK_EXT_MCLK1_2.

So devm_clk_get_optional_enabled() can be used instead of hand writing it.
This saves some line of code.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/iio/adc/ad7192.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
  

Comments

Nuno Sá June 15, 2023, 12:12 p.m. UTC | #1
On Wed, 2023-06-14 at 22:26 +0200, Christophe JAILLET wrote:
> If st->mclk is not NULL, then st->clock_sel is either AD7192_CLK_EXT_MCLK2
> or AD7192_CLK_EXT_MCLK1_2.
> 
> So devm_clk_get_optional_enabled() can be used instead of hand writing it.
> This saves some line of code.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/iio/adc/ad7192.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index 8685e0b58a83..5dcb257ad754 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -972,11 +972,6 @@ static void ad7192_reg_disable(void *reg)
>         regulator_disable(reg);
>  }
>  
> -static void ad7192_clk_disable(void *clk)
> -{
> -       clk_disable_unprepare(clk);
> -}
> -
>  static int ad7192_probe(struct spi_device *spi)
>  {
>         struct ad7192_state *st;
> @@ -1044,7 +1039,7 @@ static int ad7192_probe(struct spi_device *spi)
>  
>         st->fclk = AD7192_INT_FREQ_MHZ;
>  
> -       st->mclk = devm_clk_get_optional(&spi->dev, "mclk");
> +       st->mclk = devm_clk_get_optional_enabled(&spi->dev, "mclk");
>         if (IS_ERR(st->mclk))
>                 return PTR_ERR(st->mclk);
>  
> @@ -1052,15 +1047,6 @@ static int ad7192_probe(struct spi_device *spi)
>  
>         if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
>             st->clock_sel == AD7192_CLK_EXT_MCLK2) {
> -               ret = clk_prepare_enable(st->mclk);
> -               if (ret < 0)
> -                       return ret;
> -
> -               ret = devm_add_action_or_reset(&spi->dev, ad7192_clk_disable,
> -                                              st->mclk);
> -               if (ret)
> -                       return ret;
> -
>                 st->fclk = clk_get_rate(st->mclk);
>                 if (!ad7192_valid_external_frequency(st->fclk)) {
>                         dev_err(&spi->dev,
  
Jonathan Cameron June 17, 2023, 6:13 p.m. UTC | #2
On Thu, 15 Jun 2023 14:12:57 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Wed, 2023-06-14 at 22:26 +0200, Christophe JAILLET wrote:
> > If st->mclk is not NULL, then st->clock_sel is either AD7192_CLK_EXT_MCLK2
> > or AD7192_CLK_EXT_MCLK1_2.
> > 
> > So devm_clk_get_optional_enabled() can be used instead of hand writing it.
> > This saves some line of code.
> > 
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---  
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Applied to the togreg branch of iio.git but as we are approaching the merge
window I'll be rebasing that on 6.5-rc1 when available.
In meantime pushed out as testing to let 0-day poke at it.

Thanks,

Jonathan

> 
> >  drivers/iio/adc/ad7192.c | 16 +---------------
> >  1 file changed, 1 insertion(+), 15 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> > index 8685e0b58a83..5dcb257ad754 100644
> > --- a/drivers/iio/adc/ad7192.c
> > +++ b/drivers/iio/adc/ad7192.c
> > @@ -972,11 +972,6 @@ static void ad7192_reg_disable(void *reg)
> >         regulator_disable(reg);
> >  }
> >  
> > -static void ad7192_clk_disable(void *clk)
> > -{
> > -       clk_disable_unprepare(clk);
> > -}
> > -
> >  static int ad7192_probe(struct spi_device *spi)
> >  {
> >         struct ad7192_state *st;
> > @@ -1044,7 +1039,7 @@ static int ad7192_probe(struct spi_device *spi)
> >  
> >         st->fclk = AD7192_INT_FREQ_MHZ;
> >  
> > -       st->mclk = devm_clk_get_optional(&spi->dev, "mclk");
> > +       st->mclk = devm_clk_get_optional_enabled(&spi->dev, "mclk");
> >         if (IS_ERR(st->mclk))
> >                 return PTR_ERR(st->mclk);
> >  
> > @@ -1052,15 +1047,6 @@ static int ad7192_probe(struct spi_device *spi)
> >  
> >         if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
> >             st->clock_sel == AD7192_CLK_EXT_MCLK2) {
> > -               ret = clk_prepare_enable(st->mclk);
> > -               if (ret < 0)
> > -                       return ret;
> > -
> > -               ret = devm_add_action_or_reset(&spi->dev, ad7192_clk_disable,
> > -                                              st->mclk);
> > -               if (ret)
> > -                       return ret;
> > -
> >                 st->fclk = clk_get_rate(st->mclk);
> >                 if (!ad7192_valid_external_frequency(st->fclk)) {
> >                         dev_err(&spi->dev,  
>
  

Patch

diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
index 8685e0b58a83..5dcb257ad754 100644
--- a/drivers/iio/adc/ad7192.c
+++ b/drivers/iio/adc/ad7192.c
@@ -972,11 +972,6 @@  static void ad7192_reg_disable(void *reg)
 	regulator_disable(reg);
 }
 
-static void ad7192_clk_disable(void *clk)
-{
-	clk_disable_unprepare(clk);
-}
-
 static int ad7192_probe(struct spi_device *spi)
 {
 	struct ad7192_state *st;
@@ -1044,7 +1039,7 @@  static int ad7192_probe(struct spi_device *spi)
 
 	st->fclk = AD7192_INT_FREQ_MHZ;
 
-	st->mclk = devm_clk_get_optional(&spi->dev, "mclk");
+	st->mclk = devm_clk_get_optional_enabled(&spi->dev, "mclk");
 	if (IS_ERR(st->mclk))
 		return PTR_ERR(st->mclk);
 
@@ -1052,15 +1047,6 @@  static int ad7192_probe(struct spi_device *spi)
 
 	if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
 	    st->clock_sel == AD7192_CLK_EXT_MCLK2) {
-		ret = clk_prepare_enable(st->mclk);
-		if (ret < 0)
-			return ret;
-
-		ret = devm_add_action_or_reset(&spi->dev, ad7192_clk_disable,
-					       st->mclk);
-		if (ret)
-			return ret;
-
 		st->fclk = clk_get_rate(st->mclk);
 		if (!ad7192_valid_external_frequency(st->fclk)) {
 			dev_err(&spi->dev,