diff options
author | Alexandru Ardelean <alexandru.ardelean@analog.com> | 2020-10-02 11:27:23 +0300 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2020-10-10 19:38:36 +0300 |
commit | 5483b8d5015bb366c372870cfe4448742082e41f (patch) | |
tree | 047a17417b07aada3bc6c7b4b14f7e4fd64aac8d /drivers/iio/adc/ad7887.c | |
parent | ead1c9f376dbb2805796098ed6d2a70921c77ee5 (diff) | |
download | linux-5483b8d5015bb366c372870cfe4448742082e41f.tar.xz |
iio: adc: ad7887: invert/rework external ref logic
This change inverts/reworks the logic to use an external reference via a
provided regulator.
Now the driver tries to obtain a regulator. If one is found, then it is
used. The rest of the driver logic already checks if there is a non-NULL
reference to a regulator, so it should be fine.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20201002082723.184810-1-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc/ad7887.c')
-rw-r--r-- | drivers/iio/adc/ad7887.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c index 037bcb47693c..99a480ad3985 100644 --- a/drivers/iio/adc/ad7887.c +++ b/drivers/iio/adc/ad7887.c @@ -246,11 +246,15 @@ static int ad7887_probe(struct spi_device *spi) st = iio_priv(indio_dev); - if (!pdata || !pdata->use_onchip_ref) { - st->reg = devm_regulator_get(&spi->dev, "vref"); - if (IS_ERR(st->reg)) + st->reg = devm_regulator_get_optional(&spi->dev, "vref"); + if (IS_ERR(st->reg)) { + if (PTR_ERR(st->reg) != -ENODEV) return PTR_ERR(st->reg); + st->reg = NULL; + } + + if (st->reg) { ret = regulator_enable(st->reg); if (ret) return ret; @@ -269,7 +273,7 @@ static int ad7887_probe(struct spi_device *spi) /* Setup default message */ mode = AD7887_PM_MODE4; - if (!pdata || !pdata->use_onchip_ref) + if (!st->reg) mode |= AD7887_REF_DIS; if (pdata && pdata->en_dual) mode |= AD7887_DUAL; |