mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support

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>
Tested-by: Trevor Gamblin <tgamblin@baylibre.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Troy Mitchell <troy.mitchell@linux.dev>
Tested-by: Vincent Legoll <legoll@online.fr>
Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
This commit is contained in:
Iker Pedrosa
2026-05-11 10:53:58 +02:00
committed by Ulf Hansson
parent f87b273e4b
commit 00a97fc57c

View File

@@ -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,46 @@ static void spacemit_sdhci_pre_hs400_to_hs200(struct mmc_host *mmc)
SPACEMIT_SDHC_PHY_CTRL_REG);
}
static int spacemit_sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
struct mmc_ios *ios)
{
struct sdhci_host *host = mmc_priv(mmc);
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct spacemit_sdhci_host *sdhst = sdhci_pltfm_priv(pltfm_host);
struct pinctrl_state *state;
int ret;
ret = sdhci_start_signal_voltage_switch(mmc, ios);
if (ret)
return ret;
if (!sdhst->pinctrl)
return 0;
/* Select appropriate pinctrl state based on signal voltage */
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(mmc), "unsupported voltage %d\n", ios->signal_voltage);
return 0;
}
ret = pinctrl_select_state(sdhst->pinctrl, state);
if (ret) {
dev_warn(mmc_dev(mmc), "failed to select pinctrl state: %d\n", ret);
return 0;
}
dev_dbg(mmc_dev(mmc), "switched to %s pinctrl state\n",
ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180 ? "UHS" : "default");
return 0;
}
static inline int spacemit_sdhci_get_clocks(struct device *dev,
struct sdhci_pltfm_host *pltfm_host)
{
@@ -252,6 +296,30 @@ 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, "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,
@@ -324,6 +392,10 @@ static int spacemit_sdhci_probe(struct platform_device *pdev)
host->mmc->caps |= MMC_CAP_NEED_RSP_BUSY;
spacemit_sdhci_get_pins(dev, pltfm_host);
host->mmc_host_ops.start_signal_voltage_switch = spacemit_sdhci_start_signal_voltage_switch;
ret = spacemit_sdhci_get_clocks(dev, pltfm_host);
if (ret)
goto err_pltfm;