Skip to content

Commit a386cf9

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 593b88a commit a386cf9

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
@@ -297,7 +297,7 @@ struct ad7768_chip_info {
297297
struct ad7768_state {
298298
const struct ad7768_chip_info *chip;
299299
struct spi_device *spi;
300-
struct regulator *vref;
300+
int vref_uv;
301301
struct mutex lock;
302302
struct clk *mclk;
303303
struct gpio_chip gpiochip;
@@ -985,7 +985,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
985985
return IIO_VAL_INT;
986986

987987
case IIO_CHAN_INFO_SCALE:
988-
scale_uv = regulator_get_voltage(st->vref);
988+
scale_uv = st->vref_uv;
989989
if (scale_uv < 0)
990990
return scale_uv;
991991

@@ -1225,13 +1225,6 @@ static const struct iio_trigger_ops ad7768_trigger_ops = {
12251225
.validate_device = iio_trigger_validate_own_device,
12261226
};
12271227

1228-
static void ad7768_regulator_disable(void *data)
1229-
{
1230-
struct ad7768_state *st = data;
1231-
1232-
regulator_disable(st->vref);
1233-
}
1234-
12351228
static int ad7768_triggered_buffer_alloc(struct iio_dev *indio_dev)
12361229
{
12371230
struct ad7768_state *st = iio_priv(indio_dev);
@@ -1334,19 +1327,11 @@ static int ad7768_probe(struct spi_device *spi)
13341327
return ret;
13351328
st->spi = spi;
13361329

1337-
st->vref = devm_regulator_get(&spi->dev, "vref");
1338-
if (IS_ERR(st->vref))
1339-
return PTR_ERR(st->vref);
1340-
1341-
ret = regulator_enable(st->vref);
1342-
if (ret) {
1343-
dev_err(&spi->dev, "Failed to enable specified vref supply\n");
1344-
return ret;
1345-
}
1346-
1347-
ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st);
1348-
if (ret)
1349-
return ret;
1330+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
1331+
if (ret < 0)
1332+
return dev_err_probe(&spi->dev, ret,
1333+
"Failed to get VREF voltage\n");
1334+
st->vref_uv = ret;
13501335

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

0 commit comments

Comments
 (0)