From 1003d539930177b552e48881c1805fd2bc20066a Mon Sep 17 00:00:00 2001 From: Matti Vaittinen Date: Mon, 11 Aug 2025 11:50:55 +0300 Subject: [PATCH] iio: adc: ad7476: Use mV for internal reference MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The ad7476 supports some ICs with an internal reference voltage. For those ICs the reference voltage has been hard-coded as micro volts, but the value which is later used in code needs to be milli volts. This results the need to divide hard coded voltage by 1000 before using it. Simplify code by changing the hard-coded voltage to millivolts and by dropping the division. Signed-off-by: Matti Vaittinen Reviewed-by: Nuno Sá Reviewed-by: Andy Shevchenko Link: https://patch.msgid.link/1c26529fcc039a3ce8b5a336948229ec727ee281.1754901948.git.mazziesaccount@gmail.com Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ad7476.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c index f117aafd8fad1..7b6d36999afcb 100644 --- a/drivers/iio/adc/ad7476.c +++ b/drivers/iio/adc/ad7476.c @@ -27,7 +27,7 @@ struct ad7476_state; struct ad7476_chip_info { - unsigned int int_vref_uv; + unsigned int int_vref_mv; struct iio_chan_spec channel[2]; /* channels used when convst gpio is defined */ struct iio_chan_spec convst_channel[2]; @@ -172,7 +172,7 @@ static const struct ad7476_chip_info ad7091r_chip_info = { .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), .convst_channel[0] = AD7091R_CONVST_CHAN(12), .convst_channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), - .int_vref_uv = 2500000, + .int_vref_mv = 2500, .has_vref = true, .reset = ad7091_reset, }; @@ -229,7 +229,7 @@ static const struct ad7476_chip_info ad7475_chip_info = { static const struct ad7476_chip_info ad7495_chip_info = { .channel[0] = AD7476_CHAN(12), .channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1), - .int_vref_uv = 2500000, + .int_vref_mv = 2500, .has_vdrive = true, }; @@ -295,7 +295,7 @@ static int ad7476_probe(struct spi_device *spi) return -ENODEV; /* Use VCC for reference voltage if vref / internal vref aren't used */ - if (!st->chip_info->int_vref_uv && !st->chip_info->has_vref) { + if (!st->chip_info->int_vref_mv && !st->chip_info->has_vref) { ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); if (ret < 0) return ret; @@ -310,7 +310,7 @@ static int ad7476_probe(struct spi_device *spi) ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); if (ret < 0) { /* Vref is optional if a device has an internal reference */ - if (!st->chip_info->int_vref_uv || ret != -ENODEV) + if (!st->chip_info->int_vref_mv || ret != -ENODEV) return ret; } else { st->scale_mv = ret / 1000; @@ -318,7 +318,7 @@ static int ad7476_probe(struct spi_device *spi) } if (!st->scale_mv) - st->scale_mv = st->chip_info->int_vref_uv / 1000; + st->scale_mv = st->chip_info->int_vref_mv; if (st->chip_info->has_vdrive) { ret = devm_regulator_get_enable(&spi->dev, "vdrive"); -- 2.47.3