From: Brian Masney <masneyb@kernel.org>
To: "Yu-Chun Lin [林祐君]" <eleanor.lin@realtek.com>
Cc: "sboyd@kernel.org" <sboyd@kernel.org>,
"bmasney+clk@redhat.com" <bmasney+clk@redhat.com>,
"jbrunet+clk@baylibre.com" <jbrunet+clk@baylibre.com>,
"robh@kernel.org" <robh@kernel.org>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"Edgar Lee [李承諭]" <cylee12@realtek.com>,
"afaerber@suse.com" <afaerber@suse.com>,
"Jyan Chou [周芷安]" <jyanchou@realtek.com>,
"linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-realtek-soc@lists.infradead.org"
<linux-realtek-soc@lists.infradead.org>,
"James Tai [戴志峰]" <james.tai@realtek.com>,
"CY_Huang[黃鉦晏]" <cy.huang@realtek.com>,
"Stanley Chang[昌育德]" <stanley_chang@realtek.com>
Subject: Re: [PATCH v16 6/9] clk: realtek: Add support for MMC-tuned PLL clocks
Date: Wed, 18 Nov 2026 21:23:54 -0500 [thread overview]
Message-ID: <av5dut67EajT0zn3@x1g10> (raw)
In-Reply-To: <54a7a77705674bfdac23727f5fb92cb6@realtek.com>
Hi Yu-Chun,
On Fri, Nov 13, 2026 at 02:12:59PM +0000, Yu-Chun Lin [林祐君] wrote:
> > > +static const struct rtk_clk_pll_mmc_rate *
> > > +rtk_clk_pll_mmc_find_closest_rate(const struct rtk_clk_pll_mmc_rate *tbl,
> > u32 num,
> > > + unsigned long rate, unsigned long
> > min_rate,
> > > + unsigned long max_rate) {
> > > + const struct rtk_clk_pll_mmc_rate *best = NULL;
> > > + unsigned long best_delta = ~0UL;
> > > +
> > > + for (unsigned int i = 0; i < num; i++) {
> > > + const struct rtk_clk_pll_mmc_rate *entry = &tbl[i];
> > > + unsigned long delta;
> > > +
> > > + if (entry->rate < min_rate || entry->rate > max_rate)
> > > + continue;
> > > +
> > > + delta = entry->rate >= rate ? entry->rate - rate : rate -
> > entry->rate;
> > > + if (delta < best_delta) {
> > > + best = entry;
> > > + best_delta = delta;
> > > + }
> > > + }
> > > +
> > > + return best;
> > > +}
> >
> > This duplicates the functionality in ftbl_find_closest_by_rate() from patch 3.
> >
>
> I considered sharing the logic, but the two tables have different entry
> layouts.
>
> Unifying them would need a macro or (void *) (both lose type checking), or
> embedding rtk_freq_table with container_of() (a larger rework for little
> gain). I prefer keeping the two type-safe functions. Is that acceptable?
What about this? This is completely untested.
#define ftbl_find_closest_by_rate(_tbl, _rate, _min, _max) ({ \
typeof(&(_tbl)[0]) __best = NULL, __e; \
unsigned long __r = (_rate), __lo = (_min), __hi = (_max); \
unsigned long __best_delta = ULONG_MAX; \
\
for (__e = (_tbl); __e->rate; __e++) { \
unsigned long __d; \
\
if (__e->rate < __lo || __e->rate > __hi) \
continue; \
\
__d = abs_diff(__e->rate, __r); \
if (__d < __best_delta) { \
__best_delta = __d; \
__best = __e; \
} \
} \
__best; \
})
Brian
next prev parent reply other threads:[~2026-11-19 2:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 5:25 [PATCH v16 0/9] clk: realtek: Add RTD1625 clock support Yu-Chun Lin
2026-11-12 5:25 ` [PATCH v16 1/9] dt-bindings: clock: Add Realtek RTD1625 Clock & Reset Controller Yu-Chun Lin
2026-11-12 9:23 ` Krzysztof Kozlowski
2026-11-12 5:25 ` [PATCH v16 2/9] clk: realtek: Introduce common probe() Yu-Chun Lin
2026-11-12 17:14 ` Brian Masney
2026-11-12 5:25 ` [PATCH v16 3/9] clk: realtek: Add support for phase locked loops (PLLs) Yu-Chun Lin
2026-11-12 17:14 ` Brian Masney
2026-11-12 5:25 ` [PATCH v16 4/9] clk: realtek: Add support for gate clock Yu-Chun Lin
2026-11-12 17:14 ` Brian Masney
2026-11-12 5:25 ` [PATCH v16 5/9] clk: realtek: Add support for mux clock Yu-Chun Lin
2026-11-12 5:25 ` [PATCH v16 6/9] clk: realtek: Add support for MMC-tuned PLL clocks Yu-Chun Lin
2026-11-12 17:14 ` Brian Masney
2026-11-13 14:12 ` Yu-Chun Lin [林祐君]
2026-11-19 2:23 ` Brian Masney [this message]
2026-11-19 5:52 ` Yu-Chun Lin [林祐君]
2026-11-12 5:25 ` [PATCH v16 7/9] clk: realtek: Add RTD1625-CRT clock controller driver Yu-Chun Lin
2026-11-12 17:14 ` Brian Masney
2026-11-12 5:25 ` [PATCH v16 8/9] clk: realtek: Add RTD1625-ISO " Yu-Chun Lin
2026-11-12 5:25 ` [PATCH v16 9/9] arm64: dts: realtek: Add clock support for RTD1625 Yu-Chun Lin
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=av5dut67EajT0zn3@x1g10 \
--to=masneyb@kernel.org \
--cc=afaerber@suse.com \
--cc=bmasney+clk@redhat.com \
--cc=conor+dt@kernel.org \
--cc=cy.huang@realtek.com \
--cc=cylee12@realtek.com \
--cc=devicetree@vger.kernel.org \
--cc=eleanor.lin@realtek.com \
--cc=james.tai@realtek.com \
--cc=jbrunet+clk@baylibre.com \
--cc=jyanchou@realtek.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-realtek-soc@lists.infradead.org \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=stanley_chang@realtek.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