Re: [PATCH v5 3/4] iio: adc: ad799x: cache regulator voltages during probe

From: Andy Shevchenko

Date: Wed Mar 18 2026 - 10:45:47 EST


On Wed, Mar 18, 2026 at 02:57:14PM +0530, 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.
>
> Determine the active reference voltage (either VREF or VCC) during
> probe() and cache it in the state structure. This improves the
> performance of ad799x_read_raw() and removes the dependency on the
> regulator pointers during fast-path reads.

...

> case IIO_CHAN_INFO_SCALE:
> - if (st->vref)
> - ret = regulator_get_voltage(st->vref);
> - else
> - ret = regulator_get_voltage(st->reg);
> -
> - if (ret < 0)
> - return ret;
> - *val = ret / 1000;
> + *val = st->vref_uV / MILLI;

Not sure I understand properly this MILLI in conjunction with FRACTIONAL_LOG2
below. Is this simply millivolts? Then we have "(MICRO / MILLI)" pattern as
of today to show that in a better way.

> *val2 = chan->scan_type.realbits;
> return IIO_VAL_FRACTIONAL_LOG2;

--
With Best Regards,
Andy Shevchenko