From: Yixun Lan <dlan@kernel.org>
To: Iker Pedrosa <ikerpedrosam@gmail.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Michael Opdenacker <michael.opdenacker@rootcommit.com>,
Javier Martinez Canillas <javierm@redhat.com>,
linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/7] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support
Date: Mon, 9 Mar 2026 21:22:19 +0800 [thread overview]
Message-ID: <20260309132219-GKE302167@kernel.org> (raw)
In-Reply-To: <20260309-orangepi-sd-card-uhs-v2-2-5bb2b574df5d@gmail.com>
Hi Iker,
On 12:40 Mon 09 Mar , Iker Pedrosa wrote:
> Add voltage switching infrastructure for UHS-I modes by integrating both
> regulator framework (for supply voltage control) and pinctrl state
> switching (for pin drive strength optimization).
>
> - Add regulator supply parsing and voltage switching callback
> - Add optional pinctrl state switching between "default" (3.3V) and
> "state_uhs" (1.8V) configurations
> - Enable coordinated voltage and pin configuration changes for UHS modes
>
> This provides complete voltage switching support while maintaining
> backward compatibility when pinctrl states are not defined.
>
> Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
> ---
> drivers/mmc/host/sdhci-of-k1.c | 59 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 59 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
> index 585c7eca6ebf253aac466dd37cef029deb63f692..8af117a8e271c04a80d8dc7bb5ce12075652dd7a 100644
> --- a/drivers/mmc/host/sdhci-of-k1.c
> +++ b/drivers/mmc/host/sdhci-of-k1.c
> @@ -15,6 +15,7 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_device.h>
> +#include <linux/pinctrl/consumer.h>
> #include <linux/platform_device.h>
>
> #include "sdhci.h"
> @@ -70,6 +71,9 @@
> struct spacemit_sdhci_host {
> struct clk *clk_core;
> struct clk *clk_io;
> + struct pinctrl *pinctrl;
> + struct pinctrl_state *pinctrl_default;
> + struct pinctrl_state *pinctrl_uhs;
> };
>
> /* All helper functions will update clr/set while preserve rest bits */
> @@ -218,6 +222,42 @@ static void spacemit_sdhci_pre_hs400_to_hs200(struct mmc_host *mmc)
> SPACEMIT_SDHC_PHY_CTRL_REG);
> }
>
> +static void spacemit_sdhci_voltage_switch(struct sdhci_host *host)
> +{
> + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> + struct spacemit_sdhci_host *sdhst = sdhci_pltfm_priv(pltfm_host);
> + struct mmc_ios *ios = &host->mmc->ios;
> + struct pinctrl_state *state;
> + int ret;
> +
> + /* Select appropriate pinctrl state based on signal voltage */
> + if (sdhst->pinctrl) {
do a sanity check, then abort it early, the advantage is that you can get rid of
one indetation for next code..
if (!sdhst->pinctrl)
return;
> + switch (ios->signal_voltage) {
> + case MMC_SIGNAL_VOLTAGE_330:
> + state = sdhst->pinctrl_default;
> + break;
> + case MMC_SIGNAL_VOLTAGE_180:
> + state = sdhst->pinctrl_uhs;
> + break;
> + default:
> + dev_warn(mmc_dev(host->mmc), "unsupported voltage %d\n",
> + ios->signal_voltage);
> + return;
> + }
> +
> + if (state) {
> + ret = pinctrl_select_state(sdhst->pinctrl, state);
> + if (ret) {
> + dev_warn(mmc_dev(host->mmc),
> + "failed to select pinctrl state: %d\n", ret);
> + return;
> + }
> + dev_dbg(mmc_dev(host->mmc), "switched to %s pinctrl state\n",
> + ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180 ? "UHS" : "default");
> + }
> + }
> +}
> +
> static inline int spacemit_sdhci_get_clocks(struct device *dev,
> struct sdhci_pltfm_host *pltfm_host)
> {
> @@ -242,6 +282,7 @@ static const struct sdhci_ops spacemit_sdhci_ops = {
> .set_bus_width = sdhci_set_bus_width,
> .set_clock = spacemit_sdhci_set_clock,
> .set_uhs_signaling = spacemit_sdhci_set_uhs_signaling,
> + .voltage_switch = spacemit_sdhci_voltage_switch,
> };
>
> static const struct sdhci_pltfm_data spacemit_sdhci_k1_pdata = {
> @@ -293,6 +334,24 @@ static int spacemit_sdhci_probe(struct platform_device *pdev)
>
> host->mmc->caps |= MMC_CAP_NEED_RSP_BUSY;
>
> + sdhst = sdhci_pltfm_priv(pltfm_host);
..
> + sdhst->pinctrl = devm_pinctrl_get(dev);
> + if (!IS_ERR(sdhst->pinctrl)) {
> + sdhst->pinctrl_default = pinctrl_lookup_state(sdhst->pinctrl, "default");
> + if (IS_ERR(sdhst->pinctrl_default))
> + sdhst->pinctrl_default = NULL;
> +
> + sdhst->pinctrl_uhs = pinctrl_lookup_state(sdhst->pinctrl, "state_uhs");
> + if (IS_ERR(sdhst->pinctrl_uhs))
> + sdhst->pinctrl_uhs = NULL;
> +
> + dev_dbg(dev, "pinctrl setup: default=%p, uhs=%p\n",
> + sdhst->pinctrl_default, sdhst->pinctrl_uhs);
> + } else {
> + sdhst->pinctrl = NULL;
> + dev_dbg(dev, "pinctrl not available, voltage switching will work without it\n");
> + }
> +
how about creating a function spacemit_sdhci_get_pins()? similar as get
resource for clock, will more readable.
> ret = spacemit_sdhci_get_clocks(dev, pltfm_host);
> if (ret)
> goto err_pltfm;
>
> --
> 2.53.0
>
--
Yixun Lan (dlan)
next prev parent reply other threads:[~2026-03-09 13:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 11:40 [PATCH v2 0/7] riscv: spacemit: enable SD card support with UHS modes for OrangePi RV2 Iker Pedrosa
2026-03-09 11:40 ` [PATCH v2 1/7] mmc: sdhci-of-k1: enable essential clock infrastructure for SD operation Iker Pedrosa
2026-03-13 13:04 ` Adrian Hunter
2026-03-16 9:04 ` Iker Pedrosa
2026-03-16 9:34 ` Adrian Hunter
2026-03-09 11:40 ` [PATCH v2 2/7] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support Iker Pedrosa
2026-03-09 13:22 ` Yixun Lan [this message]
2026-03-12 9:38 ` Iker Pedrosa
2026-03-13 13:04 ` Adrian Hunter
2026-03-09 11:40 ` [PATCH v2 3/7] mmc: sdhci-of-k1: add SDR tuning infrastructure Iker Pedrosa
2026-03-13 13:04 ` Adrian Hunter
2026-03-09 11:40 ` [PATCH v2 4/7] mmc: sdhci-of-k1: add comprehensive SDR tuning support Iker Pedrosa
2026-03-13 13:04 ` Adrian Hunter
2026-03-13 14:15 ` Yao Zi
2026-03-09 11:40 ` [PATCH v2 5/7] riscv: dts: spacemit: k1: add SD card controller and pinctrl support Iker Pedrosa
2026-03-09 11:40 ` [PATCH v2 6/7] riscv: dts: spacemit: k1-orangepi-rv2: add PMIC and power infrastructure Iker Pedrosa
2026-03-11 18:27 ` Trevor Gamblin
2026-03-13 0:19 ` Yixun Lan
2026-03-13 9:42 ` Iker Pedrosa
2026-03-13 11:11 ` Yixun Lan
2026-03-13 15:06 ` Iker Pedrosa
2026-03-09 11:40 ` [PATCH v2 7/7] riscv: dts: spacemit: k1-orangepi-rv2: add SD card support with UHS modes Iker Pedrosa
2026-03-13 11:20 ` Anand Moon
2026-03-13 13:54 ` Trevor Gamblin
2026-03-13 14:42 ` Anand Moon
2026-03-13 17:08 ` Trevor Gamblin
2026-03-09 18:49 ` [PATCH v2 0/7] riscv: spacemit: enable SD card support with UHS modes for OrangePi RV2 Anand Moon
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=20260309132219-GKE302167@kernel.org \
--to=dlan@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ikerpedrosam@gmail.com \
--cc=javierm@redhat.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=michael.opdenacker@rootcommit.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=robh@kernel.org \
--cc=spacemit@lists.linux.dev \
--cc=ulf.hansson@linaro.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