iio: adc: ad7192: Correct reference voltage
[ Upstream commit7e7dcab620
] 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:b581f748cc
("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
ee1d783be5
commit
82a93c65a4
|
@ -177,6 +177,7 @@ struct ad7192_chip_info {
|
||||||
struct ad7192_state {
|
struct ad7192_state {
|
||||||
const struct ad7192_chip_info *chip_info;
|
const struct ad7192_chip_info *chip_info;
|
||||||
struct regulator *avdd;
|
struct regulator *avdd;
|
||||||
|
struct regulator *vref;
|
||||||
struct clk *mclk;
|
struct clk *mclk;
|
||||||
u16 int_vref_mv;
|
u16 int_vref_mv;
|
||||||
u32 fclk;
|
u32 fclk;
|
||||||
|
@ -1014,10 +1015,30 @@ static int ad7192_probe(struct spi_device *spi)
|
||||||
if (ret)
|
if (ret)
|
||||||
return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n");
|
return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n");
|
||||||
|
|
||||||
ret = regulator_get_voltage(st->avdd);
|
st->vref = devm_regulator_get_optional(&spi->dev, "vref");
|
||||||
if (ret < 0) {
|
if (IS_ERR(st->vref)) {
|
||||||
dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");
|
if (PTR_ERR(st->vref) != -ENODEV)
|
||||||
return ret;
|
return PTR_ERR(st->vref);
|
||||||
|
|
||||||
|
ret = regulator_get_voltage(st->avdd);
|
||||||
|
if (ret < 0)
|
||||||
|
return dev_err_probe(&spi->dev, ret,
|
||||||
|
"Device tree error, AVdd voltage undefined\n");
|
||||||
|
} else {
|
||||||
|
ret = regulator_enable(st->vref);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(&spi->dev, "Failed to enable specified Vref supply\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->vref);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = regulator_get_voltage(st->vref);
|
||||||
|
if (ret < 0)
|
||||||
|
return dev_err_probe(&spi->dev, ret,
|
||||||
|
"Device tree error, Vref voltage undefined\n");
|
||||||
}
|
}
|
||||||
st->int_vref_mv = ret / 1000;
|
st->int_vref_mv = ret / 1000;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue