Skip to content

Commit b34763f

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 <Jonathan.Santos@analog.com>
1 parent 5c26081 commit b34763f

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_uv;
307307
struct mutex lock;
308308
struct clk *mclk;
309309
struct gpio_chip gpiochip;
@@ -995,7 +995,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
995995
return IIO_VAL_INT;
996996

997997
case IIO_CHAN_INFO_SCALE:
998-
scale_uv = regulator_get_voltage(st->vref);
998+
scale_uv = st->vref_uv;
999999
if (scale_uv < 0)
10001000
return scale_uv;
10011001

@@ -1235,13 +1235,6 @@ static const struct iio_trigger_ops ad7768_trigger_ops = {
12351235
.validate_device = iio_trigger_validate_own_device,
12361236
};
12371237

1238-
static void ad7768_regulator_disable(void *data)
1239-
{
1240-
struct ad7768_state *st = data;
1241-
1242-
regulator_disable(st->vref);
1243-
}
1244-
12451238
static int ad7768_triggered_buffer_alloc(struct iio_dev *indio_dev)
12461239
{
12471240
struct ad7768_state *st = iio_priv(indio_dev);
@@ -1344,19 +1337,11 @@ static int ad7768_probe(struct spi_device *spi)
13441337
return ret;
13451338
st->spi = spi;
13461339

1347-
st->vref = devm_regulator_get(&spi->dev, "vref");
1348-
if (IS_ERR(st->vref))
1349-
return PTR_ERR(st->vref);
1350-
1351-
ret = regulator_enable(st->vref);
1352-
if (ret) {
1353-
dev_err(&spi->dev, "Failed to enable specified vref supply\n");
1354-
return ret;
1355-
}
1356-
1357-
ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st);
1358-
if (ret)
1359-
return ret;
1340+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
1341+
if (ret < 0)
1342+
return dev_err_probe(&spi->dev, ret,
1343+
"Failed to get VREF voltage\n");
1344+
st->vref_uv = ret;
13601345

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

0 commit comments

Comments
 (0)