From: Yixun Lan <dlan@kernel.org>
To: Dave Klotz <DaveWK225@protonmail.com>
Cc: Eric Chung <eric.chung@riscstar.com>, Peng Fan <peng.fan@nxp.com>,
u-boot@lists.u-boot-project.org,
Jaehoon Chung <jh80.chung@samsung.com>,
Tanmay Kathpalia <tanmay.kathpalia@altera.com>,
Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v2 1/3] mmc: k1: handle a missing max-frequency and clk_set_rate()'s return value
Date: Sat, 10 Oct 2026 08:45:45 +0000 [thread overview]
Message-ID: <20261010084545-GKD26088@kernel.org> (raw)
In-Reply-To: <20261005T135220-0400.mmc-v2-0001.DaveWK225@protonmail.com>
Hi Dave,
On 17:55 Mon 05 Oct , Dave Klotz wrote:
> The driver sets the io clock to the max-frequency the device tree gives
> and fails the probe on any non-zero return from clk_set_rate(). Two
> problems follow:
>
I can understand your problem and what to solve.. but wouldn't it be
a more simpler way to just setting max-frequency?
currently, only two boards are supported in mainline uboot:
k1-bananapi-f3 k1-musepi-pro
so, you likely also need to add a customized u-boot dtsi file for
supporting OrangePi R2S, something as file below, where setting the
max-frequency property
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
> - clk_set_rate() returns the new rate on success and a negative error
> code on failure. The SpacemiT clock driver happens to return 0, but
> any clock driver that reports the rate makes the probe fail.
Could you elaborate a bit "happens to return 0, ..probe fail" ?
> - A node without max-frequency asks for 0 Hz. On the K1 clock driver
A node with DT property get 0 Hz - that's expected behavior
> that picks no divider at all and writes whatever the calculation left
> behind into the io clock's divider field; host->max_clk is then 0,
> the capabilities register gives no base clock either, and the probe
> fails in sdhci_setup_cfg().
I occur to me, we should further check these logic, like a rate = 0 input
for clk subsystem - clk_set_rate(, 0) is actually a valid case? also if
need to set host->max_clk ..
>
> Treat only a negative return as an error. Without max-frequency, leave
> the io clock as an earlier stage set it and run from its current rate.
>
> Signed-off-by: Dave Klotz <DaveWK225@protonmail.com>
>
> Changes in v2:
> - Use ulong and IS_ERR_VALUE() for the clock API return values.
> - Validate clk_get_rate() before narrowing to cfg.f_max and retain the error.
>
> ---
> drivers/mmc/spacemit_sdhci.c | 28 ++++++++++++++++++++++++----
> 1 file changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/spacemit_sdhci.c b/drivers/mmc/spacemit_sdhci.c
> index f5578f38bd..6488ae0fdb 100644
> --- a/drivers/mmc/spacemit_sdhci.c
> +++ b/drivers/mmc/spacemit_sdhci.c
> @@ -606,10 +606,30 @@
> goto err_reset;
> }
>
> - ret = clk_set_rate(&clk, plat->cfg.f_max);
> - if (ret) {
> - log_err("Failed to set io clk: %d\n", ret);
> - goto err_reset;
> + /*
> + * Without max-frequency there is no rate to ask for: leave the io
> + * clock as an earlier stage set it and run from its current rate. The
I'm wondering if we could set a sane default max-frequency if no DT property
provided? as we can't always trust previous earlier stage which may in
an undetermined state, it will be fragile and easy to fail..
> + * capabilities register gives no base clock on the K1, so it cannot
> + * stand in. clk_set_rate() returns the new rate on success, so only a
> + * negative value is an error.
> + */
> + if (plat->cfg.f_max) {
> + ulong rate = clk_set_rate(&clk, plat->cfg.f_max);
> +
> + if (IS_ERR_VALUE(rate)) {
> + ret = (int)rate;
> + log_err("Failed to set io clk: %d\n", ret);
> + goto err_reset;
> + }
> + } else {
> + ulong rate = clk_get_rate(&clk);
> +
> + if (IS_ERR_VALUE(rate) || !rate) {
> + ret = rate ? (int)rate : -EINVAL;
> + log_err("No max-frequency and no io clk rate\n");
> + goto err_reset;
> + }
> + plat->cfg.f_max = rate;
> }
>
> /* Set quirks */
> --
> 2.55.0
>
--
Yixun Lan (dlan)
next prev parent reply other threads:[~2026-10-10 8:45 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 21:29 [PATCH 0/3] mmc: k1: fixes for the SpacemiT K1 SDHCI driver Dave Klotz
2026-10-02 21:29 ` [PATCH 1/3] mmc: k1: handle a missing max-frequency and clk_set_rate()'s return value Dave Klotz
2026-10-04 9:14 ` Kathpalia, Tanmay
2026-10-04 9:30 ` Kathpalia, Tanmay
2026-10-05 17:46 ` Dave Klotz
2026-10-02 21:29 ` [PATCH 2/3] mmc: k1: let the SPL read SD cards more than one block at a time Dave Klotz
2026-10-04 9:28 ` Kathpalia, Tanmay
2026-10-02 21:29 ` [PATCH 3/3] mmc: k1: do not release the shared AXI clock and reset on probe failure Dave Klotz
2026-10-04 9:28 ` Kathpalia, Tanmay
2026-10-02 22:06 ` [PATCH 0/3] mmc: k1: fixes for the SpacemiT K1 SDHCI driver Dave Klotz
2026-10-05 17:50 ` [PATCH v2 " Dave Klotz
2026-10-05 17:55 ` [PATCH v2 1/3] mmc: k1: handle a missing max-frequency and clk_set_rate()'s return value Dave Klotz
2026-10-06 5:40 ` Kathpalia, Tanmay
2026-10-10 8:45 ` Yixun Lan [this message]
2026-10-05 18:01 ` [PATCH v2 2/3] mmc: k1: let the SPL read SD cards more than one block at a time Dave Klotz
2026-10-10 6:17 ` Zixian Zeng
2026-10-10 19:02 ` Kathpalia, Tanmay
2026-10-10 19:16 ` Kathpalia, Tanmay
2026-10-11 3:38 ` Zixian Zeng
2026-10-11 14:31 ` Kathpalia, Tanmay
2026-10-11 15:33 ` Anand Moon
2026-10-11 19:41 ` Kathpalia, Tanmay
2026-10-12 13:15 ` Zixian Zeng
2026-10-12 14:00 ` Kathpalia, Tanmay
2026-10-12 14:30 ` Yixun Lan
2026-10-12 14:50 ` Kathpalia, Tanmay
2026-10-12 15:22 ` Yixun Lan
2026-10-12 16:07 ` Anand Moon
2026-10-13 0:15 ` Yixun Lan
2026-10-13 3:44 ` Anand Moon
2026-10-05 18:11 ` [PATCH v2 3/3] mmc: k1: do not release the shared AXI clock and reset on probe failure Dave Klotz
2026-10-10 7:14 ` Yixun Lan
2026-10-10 19:27 ` Kathpalia, Tanmay
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=20261010084545-GKD26088@kernel.org \
--to=dlan@kernel.org \
--cc=DaveWK225@protonmail.com \
--cc=eric.chung@riscstar.com \
--cc=jh80.chung@samsung.com \
--cc=peng.fan@nxp.com \
--cc=tanmay.kathpalia@altera.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/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