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

From: Archit Anant

Date: Wed Mar 18 2026 - 22:37:21 EST


On Wed, Mar 18, 2026 at 8:11 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> wrote:
>
> 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.

My bad, I thought you wanted me to use either MICRO or MILLI i.e the
fitting one
instead of 1000. I see this is the preferred way to show unit conversions.
I'll redo in accordance with this pattern.

>
> > *val2 = chan->scan_type.realbits;
> > return IIO_VAL_FRACTIONAL_LOG2;
>
> --
> With Best Regards,
> Andy Shevchenko
>
>


--
Sincerely,
Archit Anant