Re: [PATCH v5 10/20] iio: adc: ad7768: Add sampling frequency controls
From: Andy Shevchenko
Date: Mon Aug 31 2026 - 05:06:01 EST
On Fri, Aug 28, 2026 at 05:30:33PM +0200, Janani Sunil wrote:
> Expose the requested sampling frequency and available rates for each
> channel. Validate requests against the rates supported by the power mode
> tables and apply them when buffered capture starts.
...
> struct ad7768_state {
> unsigned int power_mode_idx;
> const struct ad7768_chip_info *chip_info;
> struct ad7768_avail_freq avail_freq[ARRAY_SIZE(ad7768_power_modes)];
> + unsigned int n_freqs;
> + int freqs[AD7768_MAX_FREQS];
> unsigned int ch_freq[AD7768_MAX_CHANNEL];
> struct iio_backend *back;
> unsigned int vref_uV[2];
Just double check with `pahole` that this is optimal layout.
> };
...
> {
> struct ad7768_state *st = iio_priv(indio_dev);
> - unsigned int vref_idx;
>
> - if (info != IIO_CHAN_INFO_SCALE)
> + switch (info) {
> + case IIO_CHAN_INFO_SCALE: {
> + unsigned int vref_idx;
> +
> + vref_idx = chan->channel >= st->chip_info->num_channels / 2;
> + *val = 2 * st->vref_uV[vref_idx] / 1000;
1000 --> (MICRO / MILLI)
> + *val2 = chan->scan_type.realbits;
> +
> + return IIO_VAL_FRACTIONAL_LOG2;
> + }
> + case IIO_CHAN_INFO_SAMP_FREQ: {
> + guard(mutex)(&st->lock);
> + *val = st->ch_freq[chan->channel];
> +
> + return IIO_VAL_INT;
> + }
> + default:
> + return -EINVAL;
> + }
> +}
--
With Best Regards,
Andy Shevchenko