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.
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
drivers/iio/adc/ad7768-1.c | 29 +++++++----------------------
1 file changed, 7 insertions(+), 22 deletions(-)
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index 36ba208fc119..d0b9764a8f92 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -225,7 +225,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;
@@ -809,7 +809,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);
+ scale_uv = st->vref_uv;
if (scale_uv < 0)
return scale_uv;
@@ -1146,13 +1146,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)
{
@@ -1396,19 +1389,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
On 08/12, Jonathan Santos 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. > > Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com> > --- With David's and Andy's comments addressed: Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
On Tue, 2025-08-12 at 23:49 -0300, Jonathan Santos 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. > > Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com> > --- With David's comment fixed: Reviewed-by: Nuno Sá <nuno.sa@analog.com> > drivers/iio/adc/ad7768-1.c | 29 +++++++---------------------- > 1 file changed, 7 insertions(+), 22 deletions(-) > > diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c > index 36ba208fc119..d0b9764a8f92 100644 > --- a/drivers/iio/adc/ad7768-1.c > +++ b/drivers/iio/adc/ad7768-1.c > @@ -225,7 +225,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; > @@ -809,7 +809,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); > + scale_uv = st->vref_uv; > if (scale_uv < 0) > return scale_uv; > > @@ -1146,13 +1146,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) > { > @@ -1396,19 +1389,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))
On 8/12/25 9:49 PM, Jonathan Santos 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. > > Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com> > --- > drivers/iio/adc/ad7768-1.c | 29 +++++++---------------------- > 1 file changed, 7 insertions(+), 22 deletions(-) > > diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c > index 36ba208fc119..d0b9764a8f92 100644 > --- a/drivers/iio/adc/ad7768-1.c > +++ b/drivers/iio/adc/ad7768-1.c > @@ -225,7 +225,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; > @@ -809,7 +809,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); > + scale_uv = st->vref_uv; > if (scale_uv < 0) > return scale_uv; Can also drop the error check since we've already done that in probe.
On Wed, Aug 13, 2025 at 4:49 AM Jonathan Santos <Jonathan.Santos@analog.com> wrote: > > Use devm_regulator_get_enable_read_voltage function as a standard and ..._voltage() (Note the parentheses) > 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. ... > 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; > }; Does `pahole` agree with your arrangement? -- With Best Regards, Andy Shevchenko
© 2016 - 2025 Red Hat, Inc.