Skip to content

Commit 7e7dcab

Browse files
romandarianajic23
authored andcommitted
iio: adc: ad7192: Correct reference voltage
The avdd and the reference voltage are two different sources but the reference voltage was assigned according to the avdd supply. Add vref regulator structure and set the reference voltage according to the vref supply from the devicetree. In case vref supply is missing, reference voltage is set according to the avdd supply for compatibility with old devicetrees. Fixes: b581f74 ("staging: iio: adc: ad7192: move out of staging") Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20230924152149.41884-1-alisadariana@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 7e87ab3 commit 7e7dcab

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

drivers/iio/adc/ad7192.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct ad7192_chip_info {
177177
struct ad7192_state {
178178
const struct ad7192_chip_info *chip_info;
179179
struct regulator *avdd;
180+
struct regulator *vref;
180181
struct clk *mclk;
181182
u16 int_vref_mv;
182183
u32 fclk;
@@ -1008,10 +1009,30 @@ static int ad7192_probe(struct spi_device *spi)
10081009
if (ret)
10091010
return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n");
10101011

1011-
ret = regulator_get_voltage(st->avdd);
1012-
if (ret < 0) {
1013-
dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");
1014-
return ret;
1012+
st->vref = devm_regulator_get_optional(&spi->dev, "vref");
1013+
if (IS_ERR(st->vref)) {
1014+
if (PTR_ERR(st->vref) != -ENODEV)
1015+
return PTR_ERR(st->vref);
1016+
1017+
ret = regulator_get_voltage(st->avdd);
1018+
if (ret < 0)
1019+
return dev_err_probe(&spi->dev, ret,
1020+
"Device tree error, AVdd voltage undefined\n");
1021+
} else {
1022+
ret = regulator_enable(st->vref);
1023+
if (ret) {
1024+
dev_err(&spi->dev, "Failed to enable specified Vref supply\n");
1025+
return ret;
1026+
}
1027+
1028+
ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->vref);
1029+
if (ret)
1030+
return ret;
1031+
1032+
ret = regulator_get_voltage(st->vref);
1033+
if (ret < 0)
1034+
return dev_err_probe(&spi->dev, ret,
1035+
"Device tree error, Vref voltage undefined\n");
10151036
}
10161037
st->int_vref_mv = ret / 1000;
10171038

0 commit comments

Comments
 (0)