Commit 634c6b5a authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron

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: default avatarDavid Lechner <dlechner@baylibre.com>
Reviewed-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240612-iio-adc-ref-supply-refactor-v2-2-fa622e7354e9@baylibre.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7347d295
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
#include <linux/platform_data/ad7266.h> #include <linux/platform_data/ad7266.h>
#define AD7266_INTERNAL_REF_MV 2500
struct ad7266_state { struct ad7266_state {
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg;
unsigned long vref_mv; unsigned long vref_mv;
struct spi_transfer single_xfer[3]; struct spi_transfer single_xfer[3];
...@@ -377,11 +378,6 @@ static const char * const ad7266_gpio_labels[] = { ...@@ -377,11 +378,6 @@ static const char * const ad7266_gpio_labels[] = {
"ad0", "ad1", "ad2", "ad0", "ad1", "ad2",
}; };
static void ad7266_reg_disable(void *reg)
{
regulator_disable(reg);
}
static int ad7266_probe(struct spi_device *spi) static int ad7266_probe(struct spi_device *spi)
{ {
struct ad7266_platform_data *pdata = spi->dev.platform_data; struct ad7266_platform_data *pdata = spi->dev.platform_data;
...@@ -396,28 +392,11 @@ static int ad7266_probe(struct spi_device *spi) ...@@ -396,28 +392,11 @@ static int ad7266_probe(struct spi_device *spi)
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
st->reg = devm_regulator_get_optional(&spi->dev, "vref"); ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
if (!IS_ERR(st->reg)) { if (ret < 0 && ret != -ENODEV)
ret = regulator_enable(st->reg); return ret;
if (ret)
return ret;
ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
if (ret)
return ret;
ret = regulator_get_voltage(st->reg);
if (ret < 0)
return ret;
st->vref_mv = ret / 1000; st->vref_mv = ret == -ENODEV ? AD7266_INTERNAL_REF_MV : ret / 1000;
} else {
/* Any other error indicates that the regulator does exist */
if (PTR_ERR(st->reg) != -ENODEV)
return PTR_ERR(st->reg);
/* Use internal reference */
st->vref_mv = 2500;
}
if (pdata) { if (pdata) {
st->fixed_addr = pdata->fixed_addr; st->fixed_addr = pdata->fixed_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment