Re: [PATCH v2 4/6] iio: adc: ad7124: support fractional sampling_frequency
From: Andy Shevchenko
Date: Fri Sep 12 2025 - 00:46:18 EST
On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@xxxxxxxxxxxx> wrote:
>
> Modify the attribute read/write functions for sampling_frequency and
> filter_low_pass_3db_frequency to return fractional values.
>
> These ADCs support output data rates in the single digits, so being
> able to specify fractional values is necessary to use all possible
> sampling frequencies.
...
> factor = 32 * 4; /* N = 4 for default sinc4 filter. */
> - odr_sel_bits = clamp(DIV_ROUND_CLOSEST(fclk, odr * factor), 1, 2047);
> + odr_sel_bits = DIV_ROUND_CLOSEST(fclk, odr * factor +
> + odr_micro * factor / MICRO);
> + odr_sel_bits = clamp(odr_sel_bits, 1, 2047);
I would rather see this clamp() call to be the part of
cfg.odr_sel_bits() assignment, otherwise the above line and this
operate on the semantically (slightly) different data. So, the first
line should use different variable name, or the second, like
odr_sel_bits_clamped.
> if (odr_sel_bits != st->channels[channel].cfg.odr_sel_bits)
> st->channels[channel].cfg.live = false;
>
> - /* fADC = fCLK / (FS[10:0] x 32) */
> - st->channels[channel].cfg.odr = DIV_ROUND_CLOSEST(fclk, odr_sel_bits *
> - factor);
> st->channels[channel].cfg.odr_sel_bits = odr_sel_bits;
--
With Best Regards,
Andy Shevchenko