Re: [PATCH v5 09/20] iio: adc: ad7768: Configure channel sampling profiles
From: Andy Shevchenko
Date: Mon Aug 31 2026 - 04:28:22 EST
On Fri, Aug 28, 2026 at 05:30:32PM +0200, Janani Sunil wrote:
> At buffered capture setup, select the fastest compatible power mode for
> the enabled channel rates. Group channels into the two hardware mode
> profiles and program their decimation, mode selection, and data clock.
...
> +static int ad7768_set_lowest_noise_mode(struct ad7768_state *st,
> + const unsigned long *scan_mask)
> +{
> + /*
> + * The output data rate ranges overlap between the power modes. At a
> + * common ODR, the faster mode has lower noise, so prefer the fastest
> + * mode that supports every enabled channel.
> + */
> + for (unsigned int mode_idx = ARRAY_SIZE(ad7768_power_modes);
> + mode_idx-- > 0;) {
This is rather unusual pattern, better to have this as simple as
unsigned int mode_idx = ARRAY_SIZE(ad7768_power_modes);
while (mode_idx --) {
> + bool supported = true;
> + unsigned int channel;
> +
> + for_each_set_bit(channel, scan_mask,
> + st->chip_info->num_channels) {
> + if (!ad7768_find_freq_config(st, mode_idx,
> + st->ch_freq[channel])) {
> + supported = false;
> + break;
> + }
> + }
> +
> + if (supported)
> + return ad7768_set_power_mode(st, mode_idx);
> + }
> +
> + return -EINVAL;
> +}
...
> +static int ad7768_apply_channel_modes(struct iio_dev *indio_dev,
> + const unsigned long *scan_mask)
> {
> + unsigned int mode_freq[AD7768_NUM_CHANNEL_MODES] = { };
> + bool mode_used[AD7768_NUM_CHANNEL_MODES] = { };
> struct ad7768_state *st = iio_priv(indio_dev);
> + struct device *dev = indio_dev->dev.parent;
> unsigned long channel_mask;
> unsigned long standby_mask;
> + unsigned int max_freq = 0;
Split assignment, also see below.
> + unsigned int c;
> int ret;
...
max_freq = 0;
> + for (unsigned int mode = 0; mode < AD7768_NUM_CHANNEL_MODES; mode++) {
> + if (!mode_used[mode])
> + continue;
> +
> + ret = ad7768_set_mode_decimation(st, mode_freq[mode], mode);
> + if (ret)
> + return ret;
> +
> + ret = regmap_clear_bits(st->regmap, AD7768_REG_CH_MODE(mode),
> + AD7768_CH_MODE_FILTER_TYPE_MSK);
> + if (ret)
> + return ret;
> +
> + max_freq = max(max_freq, mode_freq[mode]);
> + }
> +
> + ret = ad7768_set_clk_divs(st, max_freq);
> + if (ret)
> + return ret;
> +
> + return ad7768_sync(st);
> +}
--
With Best Regards,
Andy Shevchenko