public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] staging: iio: ad9832: Use devm_regulator_get_enable_read_voltage()
@ 2025-03-03 20:03 Saalim Quadri
  2025-03-03 22:07 ` Marcelo Schmitt
  0 siblings, 1 reply; 3+ messages in thread
From: Saalim Quadri @ 2025-03-03 20:03 UTC (permalink / raw)
  To: jic23
  Cc: lars, Michael.Hennerich, gregkh, linux-iio, linux-kernel,
	linux-staging, Saalim Quadri

Use devm_regulator_get_enable_read_voltage() to reduce boiler plate
code.

* Here I am particularly confused about regulator_enable(), part where I should
  use devm_regulator_get_enable() to enable avdd supply?
* I can resend this as a patch if everything is alright, specifically with
  devm_regulator_get_enable() for dvdd

Signed-off-by: Saalim Quadri <danascape@gmail.com>
---
 drivers/staging/iio/frequency/ad9832.c | 37 +++-----------------------
 1 file changed, 4 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 140ee4f9c137..9e7975265454 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -74,8 +74,6 @@
 /**
  * struct ad9832_state - driver instance specific data
  * @spi:		spi_device
- * @avdd:		supply regulator for the analog section
- * @dvdd:		supply regulator for the digital section
  * @mclk:		external master clock
  * @ctrl_fp:		cached frequency/phase control word
  * @ctrl_ss:		cached sync/selsrc control word
@@ -94,8 +92,6 @@
 
 struct ad9832_state {
 	struct spi_device		*spi;
-	struct regulator		*avdd;
-	struct regulator		*dvdd;
 	struct clk			*mclk;
 	unsigned short			ctrl_fp;
 	unsigned short			ctrl_ss;
@@ -297,11 +293,6 @@ static const struct iio_info ad9832_info = {
 	.attrs = &ad9832_attribute_group,
 };
 
-static void ad9832_reg_disable(void *reg)
-{
-	regulator_disable(reg);
-}
-
 static int ad9832_probe(struct spi_device *spi)
 {
 	struct ad9832_platform_data *pdata = dev_get_platdata(&spi->dev);
@@ -320,33 +311,13 @@ static int ad9832_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 
-	st->avdd = devm_regulator_get(&spi->dev, "avdd");
-	if (IS_ERR(st->avdd))
-		return PTR_ERR(st->avdd);
-
-	ret = regulator_enable(st->avdd);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to enable specified AVDD supply\n");
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->avdd);
+	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "avdd");
 	if (ret)
-		return ret;
-
-	st->dvdd = devm_regulator_get(&spi->dev, "dvdd");
-	if (IS_ERR(st->dvdd))
-		return PTR_ERR(st->dvdd);
+			return dev_err_probe(&spi->dev, ret, "failed to get AVDD voltage\n");
 
-	ret = regulator_enable(st->dvdd);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to enable specified DVDD supply\n");
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->dvdd);
+	ret = devm_regulator_get_enable(&spi->dev, "dvdd");
 	if (ret)
-		return ret;
+			return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVDD supply\n");
 
 	st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
 	if (IS_ERR(st->mclk))
-- 
2.34.1


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

* Re: [RFC] staging: iio: ad9832: Use devm_regulator_get_enable_read_voltage()
  2025-03-03 20:03 [RFC] staging: iio: ad9832: Use devm_regulator_get_enable_read_voltage() Saalim Quadri
@ 2025-03-03 22:07 ` Marcelo Schmitt
  2025-03-03 22:15   ` Saalim Quadri
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Schmitt @ 2025-03-03 22:07 UTC (permalink / raw)
  To: Saalim Quadri
  Cc: jic23, lars, Michael.Hennerich, gregkh, linux-iio, linux-kernel,
	linux-staging

Hello Saalim,

On 03/04, Saalim Quadri wrote:
> Use devm_regulator_get_enable_read_voltage() to reduce boiler plate
> code.
> 
> * Here I am particularly confused about regulator_enable(), part where I should
>   use devm_regulator_get_enable() to enable avdd supply?

I misread the driver yesterday and thought avdd and dvdd regulator voltages were
being read, but that is not true. devm_regulator_get_enable() is enough for the
cases where the voltage is not read.

> * I can resend this as a patch if everything is alright, specifically with
>   devm_regulator_get_enable() for dvdd
> 
If I'm not missing anything else, you'll probably be using
devm_regulator_get_enable() for both avdd and dvdd. And probably ok to update
both in a single patch.

Regards,
Marcelo

> Signed-off-by: Saalim Quadri <danascape@gmail.com>
> ---
>  drivers/staging/iio/frequency/ad9832.c | 37 +++-----------------------
>  1 file changed, 4 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index 140ee4f9c137..9e7975265454 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -74,8 +74,6 @@
>  /**
>   * struct ad9832_state - driver instance specific data
>   * @spi:		spi_device
> - * @avdd:		supply regulator for the analog section
> - * @dvdd:		supply regulator for the digital section
>   * @mclk:		external master clock
>   * @ctrl_fp:		cached frequency/phase control word
>   * @ctrl_ss:		cached sync/selsrc control word
> @@ -94,8 +92,6 @@
>  
>  struct ad9832_state {
>  	struct spi_device		*spi;
> -	struct regulator		*avdd;
> -	struct regulator		*dvdd;
>  	struct clk			*mclk;
>  	unsigned short			ctrl_fp;
>  	unsigned short			ctrl_ss;
> @@ -297,11 +293,6 @@ static const struct iio_info ad9832_info = {
>  	.attrs = &ad9832_attribute_group,
>  };
>  
> -static void ad9832_reg_disable(void *reg)
> -{
> -	regulator_disable(reg);
> -}
> -
>  static int ad9832_probe(struct spi_device *spi)
>  {
>  	struct ad9832_platform_data *pdata = dev_get_platdata(&spi->dev);
> @@ -320,33 +311,13 @@ static int ad9832_probe(struct spi_device *spi)
>  
>  	st = iio_priv(indio_dev);
>  
> -	st->avdd = devm_regulator_get(&spi->dev, "avdd");
> -	if (IS_ERR(st->avdd))
> -		return PTR_ERR(st->avdd);
> -
> -	ret = regulator_enable(st->avdd);
> -	if (ret) {
> -		dev_err(&spi->dev, "Failed to enable specified AVDD supply\n");
> -		return ret;
> -	}
> -
> -	ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->avdd);
> +	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "avdd");
>  	if (ret)
> -		return ret;
> -
> -	st->dvdd = devm_regulator_get(&spi->dev, "dvdd");
> -	if (IS_ERR(st->dvdd))
> -		return PTR_ERR(st->dvdd);
> +			return dev_err_probe(&spi->dev, ret, "failed to get AVDD voltage\n");
>  
> -	ret = regulator_enable(st->dvdd);
> -	if (ret) {
> -		dev_err(&spi->dev, "Failed to enable specified DVDD supply\n");
> -		return ret;
> -	}
> -
> -	ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->dvdd);
> +	ret = devm_regulator_get_enable(&spi->dev, "dvdd");
>  	if (ret)
> -		return ret;
> +			return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVDD supply\n");
>  
>  	st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
>  	if (IS_ERR(st->mclk))
> -- 
> 2.34.1
> 
> 

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

* Re: [RFC] staging: iio: ad9832: Use devm_regulator_get_enable_read_voltage()
  2025-03-03 22:07 ` Marcelo Schmitt
@ 2025-03-03 22:15   ` Saalim Quadri
  0 siblings, 0 replies; 3+ messages in thread
From: Saalim Quadri @ 2025-03-03 22:15 UTC (permalink / raw)
  To: marcelo.schmitt1
  Cc: Michael.Hennerich, danascape, gregkh, jic23, lars, linux-iio,
	linux-kernel, linux-staging

I sent the patch in a separate thread, if that is alright.

Sincerely,
Saalim Quadri

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

end of thread, other threads:[~2025-03-03 22:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 20:03 [RFC] staging: iio: ad9832: Use devm_regulator_get_enable_read_voltage() Saalim Quadri
2025-03-03 22:07 ` Marcelo Schmitt
2025-03-03 22:15   ` Saalim Quadri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox