Skip to content

Commit c686d8d

Browse files
committed
iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage
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]>
1 parent 6ff8415 commit c686d8d

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ struct ad7768_chip_info {
303303
struct ad7768_state {
304304
const struct ad7768_chip_info *chip;
305305
struct spi_device *spi;
306-
struct regulator *vref;
306+
int vref;
307307
struct mutex lock;
308308
struct clk *mclk;
309309
struct gpio_chip gpiochip;
@@ -977,7 +977,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
977977
return IIO_VAL_INT;
978978

979979
case IIO_CHAN_INFO_SCALE:
980-
scale_uv = regulator_get_voltage(st->vref);
980+
scale_uv = st->vref;
981981
if (scale_uv < 0)
982982
return scale_uv;
983983

@@ -1217,13 +1217,6 @@ static const struct iio_trigger_ops ad7768_trigger_ops = {
12171217
.validate_device = iio_trigger_validate_own_device,
12181218
};
12191219

1220-
static void ad7768_regulator_disable(void *data)
1221-
{
1222-
struct ad7768_state *st = data;
1223-
1224-
regulator_disable(st->vref);
1225-
}
1226-
12271220
static int ad7768_triggered_buffer_alloc(struct iio_dev *indio_dev)
12281221
{
12291222
struct ad7768_state *st = iio_priv(indio_dev);
@@ -1326,19 +1319,11 @@ static int ad7768_probe(struct spi_device *spi)
13261319
return ret;
13271320
st->spi = spi;
13281321

1329-
st->vref = devm_regulator_get(&spi->dev, "vref");
1330-
if (IS_ERR(st->vref))
1331-
return PTR_ERR(st->vref);
1332-
1333-
ret = regulator_enable(st->vref);
1334-
if (ret) {
1335-
dev_err(&spi->dev, "Failed to enable specified vref supply\n");
1336-
return ret;
1337-
}
1338-
1339-
ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st);
1340-
if (ret)
1341-
return ret;
1322+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
1323+
if (ret < 0)
1324+
return dev_err_probe(&spi->dev, ret,
1325+
"Failed to get VREF voltage\n");
1326+
st->vref = ret;
13421327

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

0 commit comments

Comments
 (0)