Skip to content

Commit 634c6b5

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7266: 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-2-fa622e7354e9@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 7347d29 commit 634c6b5

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

drivers/iio/adc/ad7266.c

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323

2424
#include <linux/platform_data/ad7266.h>
2525

26+
#define AD7266_INTERNAL_REF_MV 2500
27+
2628
struct ad7266_state {
2729
struct spi_device *spi;
28-
struct regulator *reg;
2930
unsigned long vref_mv;
3031

3132
struct spi_transfer single_xfer[3];
@@ -377,11 +378,6 @@ static const char * const ad7266_gpio_labels[] = {
377378
"ad0", "ad1", "ad2",
378379
};
379380

380-
static void ad7266_reg_disable(void *reg)
381-
{
382-
regulator_disable(reg);
383-
}
384-
385381
static int ad7266_probe(struct spi_device *spi)
386382
{
387383
struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -396,28 +392,11 @@ static int ad7266_probe(struct spi_device *spi)
396392

397393
st = iio_priv(indio_dev);
398394

399-
st->reg = devm_regulator_get_optional(&spi->dev, "vref");
400-
if (!IS_ERR(st->reg)) {
401-
ret = regulator_enable(st->reg);
402-
if (ret)
403-
return ret;
404-
405-
ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
406-
if (ret)
407-
return ret;
408-
409-
ret = regulator_get_voltage(st->reg);
410-
if (ret < 0)
411-
return ret;
395+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
396+
if (ret < 0 && ret != -ENODEV)
397+
return ret;
412398

413-
st->vref_mv = ret / 1000;
414-
} else {
415-
/* Any other error indicates that the regulator does exist */
416-
if (PTR_ERR(st->reg) != -ENODEV)
417-
return PTR_ERR(st->reg);
418-
/* Use internal reference */
419-
st->vref_mv = 2500;
420-
}
399+
st->vref_mv = ret == -ENODEV ? AD7266_INTERNAL_REF_MV : ret / 1000;
421400

422401
if (pdata) {
423402
st->fixed_addr = pdata->fixed_addr;

0 commit comments

Comments
 (0)