Re: [PATCH v3 2/4] iio: adc: ad799x: cache regulator voltages during probe
From: David Lechner
Date: Mon Mar 02 2026 - 11:44:23 EST
On 3/2/26 7:06 AM, Archit Anant wrote:
> Reading the regulator voltage via regulator_get_voltage() can be a slow
> operation. Since the reference voltages for this ADC are not expected to
> change at runtime, it is inefficient to query the regulator API every
> time userspace reads the IIO_CHAN_INFO_SCALE attribute.
>
> Cache the VCC and VREF voltages in the state structure during probe().
> This improves the performance of ad799x_read_raw() and removes the
> dependency on the regulator pointers during fast-path reads.
>
> Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
> Signed-off-by: Archit Anant <architanant5@xxxxxxxxx>
> ---
> drivers/iio/adc/ad799x.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 7775be874081..35e0589428d0 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -135,6 +135,10 @@ struct ad799x_state {
> u16 config;
>
> unsigned int transfer_size;
> +
> + int vcc_uv;
> + int vref_uv;
> +
> IIO_DECLARE_DMA_BUFFER_WITH_TS(__be16, rx_buf, AD799X_MAX_CHANNELS);
> };
>
> @@ -303,9 +307,9 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> if (st->vref)
> - ret = regulator_get_voltage(st->vref);
> + ret = st->vref_uv;
> else
> - ret = regulator_get_voltage(st->reg);
> + ret = st->vcc_uv;
>
> if (ret < 0)
> return ret;
This can be simplified even more. See reply to v2.
We could even move the if statement to probe and only
add one state variable.