From: Adrian Hunter <adrian.hunter@intel.com>
To: Iker Pedrosa <ikerpedrosam@gmail.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Yixun Lan <dlan@kernel.org>
Cc: 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>,
Anand Moon <linux.amoon@gmail.com>
Subject: Re: [PATCH v3 2/7] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support
Date: Tue, 17 Mar 2026 13:28:06 +0200 [thread overview]
Message-ID: <182321ef-f01e-4bc8-8f23-aa85b4c70860@intel.com> (raw)
In-Reply-To: <20260316-orangepi-sd-card-uhs-v3-2-aefd3b7832df@gmail.com>
On 16/03/2026 16:03, 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.
>
> Tested-by: Anand Moon <linux.amoon@gmail.com>
> Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
> ---
> drivers/mmc/host/sdhci-of-k1.c | 58 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 58 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
> index 0dd06fc19b8574ae1b00f7e5d09b7d4c87d06770..01afdadcf70796704b272ee5a31543afd5e01188 100644
> --- a/drivers/mmc/host/sdhci-of-k1.c
> +++ b/drivers/mmc/host/sdhci-of-k1.c
> @@ -16,6 +16,7 @@
> #include <linux/of.h>
> #include <linux/of_device.h>
> #include <linux/reset.h>
> +#include <linux/pinctrl/consumer.h>
> #include <linux/platform_device.h>
>
> #include "sdhci.h"
> @@ -71,6 +72,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 */
> @@ -219,6 +223,33 @@ 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;
> + int ret;
> +
> + if (!sdhst->pinctrl)
> + return;
> +
> + if (ios->signal_voltage != MMC_SIGNAL_VOLTAGE_180) {
> + dev_warn(mmc_dev(host->mmc), "unsupported voltage %d\n",
> + ios->signal_voltage);
> + return;
> + }
In V2, I put "->voltage_switch() is called only for
ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180" by
which I meant that it does not allow the driver to
switch pin state back for 3.3V.
So you probably need an approach similar to the original
spacemit_sdhci_start_signal_voltage_switch() in:
https://lore.kernel.org/linux-mmc/20260302-orangepi-sd-card-uhs-v1-4-89c219973c0c@gmail.com/
> +
> + if (sdhst->pinctrl_uhs) {
> + ret = pinctrl_select_state(sdhst->pinctrl, sdhst->pinctrl_uhs);
> + if (ret) {
> + dev_warn(mmc_dev(host->mmc),
> + "failed to select UHS pinctrl state: %d\n", ret);
> + return;
> + }
> + dev_dbg(mmc_dev(host->mmc), "switched to UHS pinctrl state\n");
> + }
> +}
> +
> static inline int spacemit_sdhci_get_clocks(struct device *dev,
> struct sdhci_pltfm_host *pltfm_host)
> {
> @@ -252,12 +283,37 @@ static inline int spacemit_sdhci_get_resets(struct device *dev)
> return 0;
> }
>
> +static inline void spacemit_sdhci_get_pins(struct device *dev,
> + struct sdhci_pltfm_host *pltfm_host)
> +{
> + struct spacemit_sdhci_host *sdhst = sdhci_pltfm_priv(pltfm_host);
> +
> + sdhst->pinctrl = devm_pinctrl_get(dev);
> + if (IS_ERR(sdhst->pinctrl)) {
> + sdhst->pinctrl = NULL;
> + dev_dbg(dev, "pinctrl not available, voltage switching will work without it\n");
> + return;
> + }
> +
> + 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);
> +}
> +
> static const struct sdhci_ops spacemit_sdhci_ops = {
> .get_max_clock = spacemit_sdhci_clk_get_max_clock,
> .reset = spacemit_sdhci_reset,
> .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 = {
> @@ -324,6 +380,8 @@ static int spacemit_sdhci_probe(struct platform_device *pdev)
>
> host->mmc->caps |= MMC_CAP_NEED_RSP_BUSY;
>
> + spacemit_sdhci_get_pins(dev, pltfm_host);
> +
> ret = spacemit_sdhci_get_clocks(dev, pltfm_host);
> if (ret)
> goto err_pltfm;
>
next prev parent reply other threads:[~2026-03-17 11:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 14:03 [PATCH v3 0/7] riscv: spacemit: enable SD card support with UHS modes for OrangePi RV2 Iker Pedrosa
2026-03-16 14:03 ` [PATCH v3 1/7] mmc: sdhci-of-k1: enable essential clock infrastructure for SD operation Iker Pedrosa
2026-03-17 11:32 ` Adrian Hunter
2026-03-16 14:03 ` [PATCH v3 2/7] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support Iker Pedrosa
2026-03-17 11:28 ` Adrian Hunter [this message]
2026-03-20 9:17 ` Iker Pedrosa
2026-03-20 11:31 ` Adrian Hunter
2026-03-16 14:03 ` [PATCH v3 3/7] mmc: sdhci-of-k1: add comprehensive SDR tuning support Iker Pedrosa
2026-03-17 11:33 ` Adrian Hunter
2026-03-16 14:03 ` [PATCH v3 4/7] riscv: dts: spacemit: k1: add SD card controller and pinctrl support Iker Pedrosa
2026-03-16 14:03 ` [PATCH v3 5/7] riscv: dts: spacemit: k1-orangepi-rv2: add PMIC and power infrastructure Iker Pedrosa
2026-03-17 20:24 ` Trevor Gamblin
2026-03-16 14:03 ` [PATCH v3 6/7] riscv: dts: spacemit: k1-orangepi-rv2: add SD card support with UHS modes Iker Pedrosa
2026-03-17 15:54 ` Michael Opdenacker
2026-03-16 14:03 ` [PATCH v3 7/7] riscv: dts: spacemit: k1-bananapi-f3: " Iker Pedrosa
2026-03-18 20:24 ` Aurelien Jarno
2026-03-19 1:53 ` Yixun Lan
2026-03-17 20:23 ` [PATCH v3 0/7] riscv: spacemit: enable SD card support with UHS modes for OrangePi RV2 Trevor Gamblin
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=182321ef-f01e-4bc8-8f23-aa85b4c70860@intel.com \
--to=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlan@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=linux.amoon@gmail.com \
--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