Re: [PATCH v5 12/20] iio: adc: ad7768: Wait for digital filters to settle

From: Andy Shevchenko

Date: Mon Aug 31 2026 - 03:46:52 EST


On Fri, Aug 28, 2026 at 05:30:35PM +0200, Janani Sunil wrote:
> After synchronizing the channel mode configuration, wait for the longest
> settling period required by the active profiles. Derive the delay from
> the selected output data rate and the datasheet filter-settling limits.

...

> +static void ad7768_filter_wait(const unsigned int *mode_freq,
> + const enum ad7768_filter_type *mode_filter,
> + const bool *mode_used)
> +{
> + unsigned int t_settle_us = 0;
> +
> + for (unsigned int mode = 0; mode < AD7768_NUM_CHANNEL_MODES; mode++) {

> + unsigned int settling_samples;

Taking into account the values and multiplication below I would make this
to be u8. This will make it clear that the values are not high and there
is no multiplication overflow. Another approach is to have it as unsigned int,
but rename and change semantics, id est use with multiplier.

> + unsigned int t_mode_us;
> +
> + if (!mode_used[mode] || !mode_freq[mode])
> + continue;
> +
> + if (mode_filter[mode] == AD7768_FILTER_TYPE_SINC5)
> + settling_samples = AD7768_SINC5_SETTLING_SAMPLES;
> + else
> + settling_samples = AD7768_WIDEBAND_SETTLING_SAMPLES;
> +
> + t_mode_us = DIV_ROUND_UP(settling_samples * USEC_PER_SEC,
> + mode_freq[mode]);

if (mode_filter[mode] == AD7768_FILTER_TYPE_SINC5)
t_settle_samples_us = USEC_PER_SEC * AD7768_SINC5_SETTLING_SAMPLES;
else
t_settle_samples_us = USEC_PER_SEC * AD7768_WIDEBAND_SETTLING_SAMPLES;
// or even define the respective constants in units of _US

t_mode_us = DIV_ROUND_UP(t_settle_samples_us, mode_freq[mode]);

> + t_settle_us = max(t_settle_us, t_mode_us);
> + }
> +
> + if (t_settle_us)
> + fsleep(t_settle_us);
> +}

--
With Best Regards,
Andy Shevchenko