Skip to content

Commit c53ccb4

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7292: use devm_regulator_get_enable_read_voltage
This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sa <nuno.sa@analog.com> Link: https://patch.msgid.link/20240612-iio-adc-ref-supply-refactor-v2-3-fa622e7354e9@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 634c6b5 commit c53ccb4

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

drivers/iio/adc/ad7292.c

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#define ADI_VENDOR_ID 0x0018
1919

20+
#define AD7292_INTERNAL_REF_MV 1250
21+
2022
/* AD7292 registers definition */
2123
#define AD7292_REG_VENDOR_ID 0x00
2224
#define AD7292_REG_CONF_BANK 0x05
@@ -79,7 +81,6 @@ static const struct iio_chan_spec ad7292_channels_diff[] = {
7981

8082
struct ad7292_state {
8183
struct spi_device *spi;
82-
struct regulator *reg;
8384
unsigned short vref_mv;
8485

8586
__be16 d16 __aligned(IIO_DMA_MINALIGN);
@@ -250,13 +251,6 @@ static const struct iio_info ad7292_info = {
250251
.read_raw = ad7292_read_raw,
251252
};
252253

253-
static void ad7292_regulator_disable(void *data)
254-
{
255-
struct ad7292_state *st = data;
256-
257-
regulator_disable(st->reg);
258-
}
259-
260254
static int ad7292_probe(struct spi_device *spi)
261255
{
262256
struct ad7292_state *st;
@@ -277,29 +271,11 @@ static int ad7292_probe(struct spi_device *spi)
277271
return -EINVAL;
278272
}
279273

280-
st->reg = devm_regulator_get_optional(&spi->dev, "vref");
281-
if (!IS_ERR(st->reg)) {
282-
ret = regulator_enable(st->reg);
283-
if (ret) {
284-
dev_err(&spi->dev,
285-
"Failed to enable external vref supply\n");
286-
return ret;
287-
}
288-
289-
ret = devm_add_action_or_reset(&spi->dev,
290-
ad7292_regulator_disable, st);
291-
if (ret)
292-
return ret;
293-
294-
ret = regulator_get_voltage(st->reg);
295-
if (ret < 0)
296-
return ret;
274+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
275+
if (ret < 0 && ret != -ENODEV)
276+
return ret;
297277

298-
st->vref_mv = ret / 1000;
299-
} else {
300-
/* Use the internal voltage reference. */
301-
st->vref_mv = 1250;
302-
}
278+
st->vref_mv = ret == -ENODEV ? AD7292_INTERNAL_REF_MV : ret / 1000;
303279

304280
indio_dev->name = spi_get_device_id(spi)->name;
305281
indio_dev->modes = INDIO_DIRECT_MODE;

0 commit comments

Comments
 (0)