[PATCH v2 2/7] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support
Iker Pedrosa
ikerpedrosam at gmail.com
Thu Mar 12 02:38:48 PDT 2026
El lun, 9 mar 2026 a las 14:22, Yixun Lan (<dlan at kernel.org>) escribió:
>
> 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 at 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;
>
Makes sense. I'll get it ready for the next version.
>
> > + 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.
Yes, I'll do that. Thank you for the feedback.
>
> > ret = spacemit_sdhci_get_clocks(dev, pltfm_host);
> > if (ret)
> > goto err_pltfm;
> >
> > --
> > 2.53.0
> >
>
> --
> Yixun Lan (dlan)
More information about the linux-riscv
mailing list