From: "Yu-Chun Lin [林祐君]" <eleanor.lin@realtek.com>
To: Brian Masney <masneyb@kernel.org>
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: Fri, 13 Nov 2026 14:12:59 +0000 [thread overview]
Message-ID: <54a7a77705674bfdac23727f5fb92cb6@realtek.com> (raw)
In-Reply-To: <179450369605.1227210.10143810675268582312.b4-review@b4>
Hi Brian,
> > +
> > +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?
> > +
> > +static int rtk_clk_regmap_pll_mmc_determine_rate(struct clk_hw *hw,
> > + struct
> clk_rate_request
> > +*req) {
> > + struct rtk_clk_regmap_pll_mmc *clkm = to_clk_pll_mmc(hw);
> > + const struct rtk_clk_pll_mmc_rate *entry;
> > +
> > + if (!clkm->rate_tbl || !clkm->num_rate_tbl ||
> > + req->min_rate > req->max_rate)
>
> clk_core_check_boundaries() already checks the min/max rate.
>
Ack. Will drop.
> > + return -EINVAL;
> > +
> > + entry = rtk_clk_pll_mmc_find_closest_rate(clkm->rate_tbl,
> > +
> clkm->num_rate_tbl, req->rate,
> > + req->min_rate,
> req->max_rate);
> > + if (!entry)
> > + return -EINVAL;
> > +
> > + req->rate = entry->rate;
> > +
> > + return 0;
> > +}
> > +
> > +static const struct rtk_clk_pll_mmc_div_cfg clk_pll_emmc_default_div_cfg[]
> = {
> > + { 31, 46, 3, 3, 2 },
> > + { 20, 30, 2, 3, 1 },
> > + { 10, 19, 1, 2, 1 },
> > + { 5, 9, 0, 2, 0 },
> > +};
> > +
> > +static const struct rtk_clk_pll_mmc_div_cfg *
> > +clk_pll_emmc_find_div_cfg(struct rtk_clk_regmap_pll_mmc *clkm, u32
> > +div) {
> > + const struct rtk_clk_pll_mmc_div_cfg *tbl = clkm->div_cfg;
> > + u8 num = clkm->num_div_cfg;
>
> This is a u32 in struct rtk_clk_regmap_pll_mmc.
Yes, will fix.
[...]
> > +static int rtk_clk_regmap_pll_mmc_set_rate(struct clk_hw *hw, unsigned
> long rate,
> > + unsigned long parent_rate)
> {
> > + struct rtk_clk_regmap_pll_mmc *clkm = to_clk_pll_mmc(hw);
> > + const struct rtk_clk_pll_mmc_rate *entry =
> rtk_clk_pll_mmc_find_rate(clkm, rate);
> > + int ret;
> > +
> > + if (!entry)
> > + return -EINVAL;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC0_OFFSET,
> > + RTK_PLL_FLAG_INITIAL_EMMC_MASK,
> > +
> FIELD_PREP(RTK_PLL_FLAG_INITIAL_EMMC_MASK, 0));
> > + if (ret)
> > + return ret;
> > +
> > + ret = clk_pll_emmc_set_ssc_div_n(clkm, entry->ssc_div_n);
> > + if (ret)
> > + return ret;
> > +
> > + ret = clk_pll_emmc_set_ssc_div_ext_f(clkm, entry->ssc_div_ext_f);
> > + if (ret)
> > + return ret;
> > +
> > + ret = clk_pll_emmc_program_div_cfg(clkm, entry->ssc_div_n);
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC3_OFFSET,
> > + RTK_PLL_NCODE_SSC_EMMC_MASK,
> > +
> FIELD_PREP(RTK_PLL_NCODE_SSC_EMMC_MASK, entry->ncode));
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC3_OFFSET,
> > + RTK_PLL_FCODE_SSC_EMMC_MASK,
> > +
> FIELD_PREP(RTK_PLL_FCODE_SSC_EMMC_MASK, entry->fcode));
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC4_OFFSET,
> > + RTK_PLL_GRAN_EST_EM_MC_MASK,
> > +
> FIELD_PREP(RTK_PLL_GRAN_EST_EM_MC_MASK, entry->gran_est));
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC0_OFFSET,
> > + RTK_PLL_SSC_DIG_EMMC0_EN_SSC,
> > +
> FIELD_PREP(RTK_PLL_SSC_DIG_EMMC0_EN_SSC, 1));
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC0_OFFSET,
> > + RTK_PLL_EN_SSC_EMMC_MASK,
> > +
> FIELD_PREP(RTK_PLL_EN_SSC_EMMC_MASK, 1));
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC0_OFFSET,
> > + RTK_PLL_EN_SSC_EMMC_MASK,
> > +
> FIELD_PREP(RTK_PLL_EN_SSC_EMMC_MASK,
> > + 0));
>
> EN_SSC_EMMC is set and then immediately cleared. If this is intentional then
> put a comment here to be sure it's intentional.
>
Sorry for the confusion, the macro name was wrong:
RTK_PLL_EN_SSC_EMMC_MASK should be RTK_PLL_SSC_DIG_EMMC0_OC_EN.
OC_EN is a trigger bit (enables over-clock or under-clock adjustment),
not the SSC enable. It needs to be set and then cleared to trigger
the adjustment.
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_update_bits(clkm->clkr.regmap,
> > + clkm->ssc_dig_ofs +
> RTK_PLL_SSC_DIG_EMMC0_OFFSET,
> > + RTK_PLL_FLAG_INITIAL_EMMC_MASK,
> > +
> FIELD_PREP(RTK_PLL_FLAG_INITIAL_EMMC_MASK, 1));
> > + if (ret)
> > + return ret;
> > +
> > + usleep_range(10, 20);
> > +
> > + return 0;
> > +}
> > +
[...]
> > +
> > +struct rtk_clk_regmap_pll_mmc {
> > + struct rtk_clk_regmap clkr;
> > + unsigned int pll_ofs;
> > + unsigned int ssc_dig_ofs;
> > +
> > + /*
> > + * Optional per-SoC tuning table. When NULL, the driver's default
> table
> > + * is used and num_div_cfg is ignored;
>
> Replace ; at end with .
Ack.
Best Regards,
Yu-Chun
next prev parent reply other threads:[~2026-11-13 14:13 UTC|newest]
Thread overview: 20+ 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 5:40 ` sashiko-bot
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 5:41 ` sashiko-bot
2026-11-12 17:14 ` Brian Masney
2026-11-13 14:12 ` Yu-Chun Lin [林祐君] [this message]
2026-11-12 5:25 ` [PATCH v16 7/9] clk: realtek: Add RTD1625-CRT clock controller driver Yu-Chun Lin
2026-11-12 5:41 ` sashiko-bot
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=54a7a77705674bfdac23727f5fb92cb6@realtek.com \
--to=eleanor.lin@realtek.com \
--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=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=masneyb@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.