devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 3/4] iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage()
@ 2025-08-24  4:10 Jonathan Santos
  2025-08-25 14:35 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Santos @ 2025-08-24  4:10 UTC (permalink / raw)
  To: linux-kernel, linux-iio, devicetree
  Cc: Jonathan Santos, Michael.Hennerich, lars, jic23, dlechner,
	nuno.sa, andy, robh, krzk+dt, conor+dt, marcelo.schmitt1,
	Marcelo Schmitt

Use devm_regulator_get_enable_read_voltage() function as a standard and
concise way of reading the voltage from the regulator and keep the
regulator enabled. Replace the regulator descriptor with the direct
voltage value in the device struct.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
v2 Changes:
* Removed regulator value check (already done in probe).
* Fixed commit message and description as requested.
---
 drivers/iio/adc/ad7768-1.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index 83b0907b068d..51562367a9d4 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -224,7 +224,7 @@ struct ad7768_state {
 	struct spi_device *spi;
 	struct regmap *regmap;
 	struct regmap *regmap24;
-	struct regulator *vref;
+	int vref_uv;
 	struct regulator_dev *vcm_rdev;
 	unsigned int vcm_output_sel;
 	struct clk *mclk;
@@ -787,7 +787,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
 {
 	struct ad7768_state *st = iio_priv(indio_dev);
 	const struct iio_scan_type *scan_type;
-	int scale_uv, ret, temp;
+	int ret, temp;
 
 	scan_type = iio_get_current_scan_type(indio_dev, chan);
 	if (IS_ERR(scan_type))
@@ -808,11 +808,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
 		return IIO_VAL_INT;
 
 	case IIO_CHAN_INFO_SCALE:
-		scale_uv = regulator_get_voltage(st->vref);
-		if (scale_uv < 0)
-			return scale_uv;
-
-		*val = (scale_uv * 2) / 1000;
+		*val = (st->vref_uv * 2) / 1000;
 		*val2 = scan_type->realbits;
 
 		return IIO_VAL_FRACTIONAL_LOG2;
@@ -1145,13 +1141,6 @@ static const struct iio_trigger_ops ad7768_trigger_ops = {
 	.validate_device = iio_trigger_validate_own_device,
 };
 
-static void ad7768_regulator_disable(void *data)
-{
-	struct ad7768_state *st = data;
-
-	regulator_disable(st->vref);
-}
-
 static int ad7768_set_channel_label(struct iio_dev *indio_dev,
 						int num_channels)
 {
@@ -1395,19 +1384,11 @@ static int ad7768_probe(struct spi_device *spi)
 		return dev_err_probe(&spi->dev, PTR_ERR(st->regmap24),
 				     "Failed to initialize regmap24");
 
-	st->vref = devm_regulator_get(&spi->dev, "vref");
-	if (IS_ERR(st->vref))
-		return PTR_ERR(st->vref);
-
-	ret = regulator_enable(st->vref);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to enable specified vref supply\n");
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st);
-	if (ret)
-		return ret;
+	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
+	if (ret < 0)
+		return dev_err_probe(&spi->dev, ret,
+				     "Failed to get VREF voltage\n");
+	st->vref_uv = ret;
 
 	st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
 	if (IS_ERR(st->mclk))
-- 
2.34.1


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

* Re: [PATCH v2 3/4] iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage()
  2025-08-24  4:10 [PATCH v2 3/4] iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage() Jonathan Santos
@ 2025-08-25 14:35 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2025-08-25 14:35 UTC (permalink / raw)
  To: Jonathan Santos
  Cc: linux-kernel, linux-iio, devicetree, Michael.Hennerich, lars,
	dlechner, nuno.sa, andy, robh, krzk+dt, conor+dt,
	marcelo.schmitt1, Marcelo Schmitt

On Sun, 24 Aug 2025 01:10:03 -0300
Jonathan Santos <Jonathan.Santos@analog.com> wrote:

> Use devm_regulator_get_enable_read_voltage() function as a standard and
> concise way of reading the voltage from the regulator and keep the
> regulator enabled. Replace the regulator descriptor with the direct
> voltage value in the device struct.
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>

This makes sense even without the rest of the series, so to reduce
what you have to deal with in v3, applied to the togreg branch of iio.git

thanks,

Jonathan

> ---
> v2 Changes:
> * Removed regulator value check (already done in probe).
> * Fixed commit message and description as requested.
> ---
>  drivers/iio/adc/ad7768-1.c | 35 ++++++++---------------------------
>  1 file changed, 8 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> index 83b0907b068d..51562367a9d4 100644
> --- a/drivers/iio/adc/ad7768-1.c
> +++ b/drivers/iio/adc/ad7768-1.c
> @@ -224,7 +224,7 @@ struct ad7768_state {
>  	struct spi_device *spi;
>  	struct regmap *regmap;
>  	struct regmap *regmap24;
> -	struct regulator *vref;
> +	int vref_uv;
>  	struct regulator_dev *vcm_rdev;
>  	unsigned int vcm_output_sel;
>  	struct clk *mclk;
> @@ -787,7 +787,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
>  {
>  	struct ad7768_state *st = iio_priv(indio_dev);
>  	const struct iio_scan_type *scan_type;
> -	int scale_uv, ret, temp;
> +	int ret, temp;
>  
>  	scan_type = iio_get_current_scan_type(indio_dev, chan);
>  	if (IS_ERR(scan_type))
> @@ -808,11 +808,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT;
>  
>  	case IIO_CHAN_INFO_SCALE:
> -		scale_uv = regulator_get_voltage(st->vref);
> -		if (scale_uv < 0)
> -			return scale_uv;
> -
> -		*val = (scale_uv * 2) / 1000;
> +		*val = (st->vref_uv * 2) / 1000;
>  		*val2 = scan_type->realbits;
>  
>  		return IIO_VAL_FRACTIONAL_LOG2;
> @@ -1145,13 +1141,6 @@ static const struct iio_trigger_ops ad7768_trigger_ops = {
>  	.validate_device = iio_trigger_validate_own_device,
>  };
>  
> -static void ad7768_regulator_disable(void *data)
> -{
> -	struct ad7768_state *st = data;
> -
> -	regulator_disable(st->vref);
> -}
> -
>  static int ad7768_set_channel_label(struct iio_dev *indio_dev,
>  						int num_channels)
>  {
> @@ -1395,19 +1384,11 @@ static int ad7768_probe(struct spi_device *spi)
>  		return dev_err_probe(&spi->dev, PTR_ERR(st->regmap24),
>  				     "Failed to initialize regmap24");
>  
> -	st->vref = devm_regulator_get(&spi->dev, "vref");
> -	if (IS_ERR(st->vref))
> -		return PTR_ERR(st->vref);
> -
> -	ret = regulator_enable(st->vref);
> -	if (ret) {
> -		dev_err(&spi->dev, "Failed to enable specified vref supply\n");
> -		return ret;
> -	}
> -
> -	ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st);
> -	if (ret)
> -		return ret;
> +	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
> +	if (ret < 0)
> +		return dev_err_probe(&spi->dev, ret,
> +				     "Failed to get VREF voltage\n");
> +	st->vref_uv = ret;
>  
>  	st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
>  	if (IS_ERR(st->mclk))


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

end of thread, other threads:[~2025-08-25 14:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-24  4:10 [PATCH v2 3/4] iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage() Jonathan Santos
2025-08-25 14:35 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).