Skip to content

Commit

Permalink
iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jonathanns committed Nov 6, 2024
1 parent 6ff8415 commit c686d8d
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions drivers/iio/adc/ad7768-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ struct ad7768_chip_info {
struct ad7768_state {
const struct ad7768_chip_info *chip;
struct spi_device *spi;
struct regulator *vref;
int vref;
struct mutex lock;
struct clk *mclk;
struct gpio_chip gpiochip;
Expand Down Expand Up @@ -977,7 +977,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;
if (scale_uv < 0)
return scale_uv;

Expand Down Expand Up @@ -1217,13 +1217,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_triggered_buffer_alloc(struct iio_dev *indio_dev)
{
struct ad7768_state *st = iio_priv(indio_dev);
Expand Down Expand Up @@ -1326,19 +1319,11 @@ static int ad7768_probe(struct spi_device *spi)
return ret;
st->spi = spi;

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 = ret;

st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
if (IS_ERR(st->mclk))
Expand Down

0 comments on commit c686d8d

Please sign in to comment.