[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VdMSr400YokZfv8SAkt-M8kuw7gt4+eCBb68xt7ipKJbQ@mail.gmail.com>
Date: Fri, 12 Sep 2025 07:45:40 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: David Lechner <dlechner@...libre.com>
Cc: Michael Hennerich <Michael.Hennerich@...log.com>, Jonathan Cameron <jic23@...nel.org>,
Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 4/6] iio: adc: ad7124: support fractional sampling_frequency
On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@...libre.com> 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
Powered by blists - more mailing lists