From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Andy Shevchenko" <andy.shevchenko@gmail.com>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/6] iio: adc: ad7124: add filter support
Date: Sat, 13 Sep 2025 14:42:00 +0100 [thread overview]
Message-ID: <20250913144200.17337dd8@jic23-huawei> (raw)
In-Reply-To: <87245221-c3d0-4026-980d-36562f0b4669@baylibre.com>
On Fri, 12 Sep 2025 09:27:47 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 9/11/25 11:49 PM, Andy Shevchenko wrote:
> > On Fri, Sep 12, 2025 at 12:43 AM David Lechner <dlechner@baylibre.com> wrote:
> >>
> >> Add support to the ad7124 driver for selecting the filter type.
> >>
> >> The filter type has an influence on the effective sampling frequency of
> >> each channel. For sinc3+pf{1,2,3,4}, the sampling frequency is fixed.
> >> For sinc{3,4} (without post filter), there is a factor of 3 or 4
> >> depending on the filter type. For the extra +sinc1, there is an extra
> >> averaging factor that depends on the power mode.
> >>
> >> In order to select the closest sampling frequency for each filter type,
> >> we keep a copy of the requested sampling frequency. This way, if the
> >> user sets the sampling frequency first and then selects the filter type,
> >> the sampling frequency will still be as close as possible to the
> >> requested value.
> >>
> >> Since we always either have the SINGLE_CYCLE bit set or have more than
> >> one channel enabled, the sampling frequency is always using the
> >> "zero-latency" calculation from the data sheet. This is only documented
> >> for the basic sinc{3,4} filters, so the other filter types had to be
> >> inferred and confirmed through testing.
> >>
> >> Since the flat filter type list consists of multiple register fields,
> >> the struct ad7124_channel_config::filter_type field is changed to the
> >> enum ad7124_filter_type type to avoid nested switch statements in a
> >> lot of places.
> >
> > ...
> >
> >> - factor = 32 * 4; /* N = 4 for default sinc4 filter. */
> >> - odr_sel_bits = DIV_ROUND_CLOSEST(fclk, odr * factor +
> >> - odr_micro * factor / MICRO);
> >> - odr_sel_bits = clamp(odr_sel_bits, 1, 2047);
> >> + divisor = cfg->requested_odr * factor +
> >> + cfg->requested_odr_micro * factor / MICRO;
> >> + odr_sel_bits = clamp(DIV_ROUND_CLOSEST(fclk, divisor), 1, 2047);
> >
> > I have a déjà vu feeling here. Is this similar code to elsewhere? Can
> > it be factored out to a helper?
> >
> >
>
> It is changing the same code from a previous commit, not duplicating
> it. I guess I could have introduced the divisor variable in the
> earlier commit and saved some churn.
For this and the previous patch, to me it feels like we are letting
aiming for perfect patch break up be the enemy of a good result.
So I've applied them both but as I don't know if Andy will agree
not his RB.
Jonathan
next prev parent reply other threads:[~2025-09-13 13:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 21:41 [PATCH v2 0/6] iio: adc: ad7124: add filter support David Lechner
2025-09-11 21:42 ` [PATCH v2 1/6] iio: adc: ad7124: use clamp() David Lechner
2025-09-11 21:42 ` [PATCH v2 2/6] iio: adc: ad7124: use read_avail() for scale_available David Lechner
2025-09-11 21:42 ` [PATCH v2 3/6] iio: adc: ad7124: use guard(mutex) to simplify return paths David Lechner
2025-09-12 4:39 ` Andy Shevchenko
2025-09-12 14:19 ` David Lechner
2025-09-12 17:15 ` Andy Shevchenko
2025-09-12 17:41 ` David Lechner
2025-09-12 18:07 ` Andy Shevchenko
2025-09-13 13:40 ` Jonathan Cameron
2025-09-11 21:42 ` [PATCH v2 4/6] iio: adc: ad7124: support fractional sampling_frequency David Lechner
2025-09-12 4:45 ` Andy Shevchenko
2025-09-12 14:25 ` David Lechner
2025-09-11 21:42 ` [PATCH v2 5/6] iio: adc: ad7124: add filter support David Lechner
2025-09-12 4:49 ` Andy Shevchenko
2025-09-12 14:27 ` David Lechner
2025-09-13 13:42 ` Jonathan Cameron [this message]
2025-09-15 6:46 ` Andy Shevchenko
2025-09-11 21:42 ` [PATCH v2 6/6] iio: ABI: document "sinc4+rej60" filter_type David Lechner
2025-09-12 4:50 ` [PATCH v2 0/6] iio: adc: ad7124: add filter support Andy Shevchenko
2025-09-13 13:43 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250913144200.17337dd8@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox