All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Trevor Gamblin <tgamblin@baylibre.com>
Subject: Re: [PATCH v4 2/8] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support
Date: Tue, 24 Mar 2026 09:46:05 +0200	[thread overview]
Message-ID: <00bf0bb1-f769-4102-aa1b-e2804e62ccb3@intel.com> (raw)
In-Reply-To: <20260323-orangepi-sd-card-uhs-v4-2-567c9775fd0e@gmail.com>

On 23/03/2026 12:19, 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>
> Tested-by: Trevor Gamblin <tgamblin@baylibre.com>
> Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/host/sdhci-of-k1.c | 72 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 72 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
> index 0dd06fc19b8574ae1b00f7e5d09b7d4c87d06770..234e258af25996e7bbcd0b70366c7480bf62bee7 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,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, "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,
> @@ -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;
> 


WARNING: multiple messages have this Message-ID (diff)
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>,
	Trevor Gamblin <tgamblin@baylibre.com>
Subject: Re: [PATCH v4 2/8] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support
Date: Tue, 24 Mar 2026 09:46:05 +0200	[thread overview]
Message-ID: <00bf0bb1-f769-4102-aa1b-e2804e62ccb3@intel.com> (raw)
In-Reply-To: <20260323-orangepi-sd-card-uhs-v4-2-567c9775fd0e@gmail.com>

On 23/03/2026 12:19, 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>
> Tested-by: Trevor Gamblin <tgamblin@baylibre.com>
> Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/host/sdhci-of-k1.c | 72 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 72 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c
> index 0dd06fc19b8574ae1b00f7e5d09b7d4c87d06770..234e258af25996e7bbcd0b70366c7480bf62bee7 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,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, "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,
> @@ -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;
> 


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2026-03-24  7:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 10:19 [PATCH v4 0/8] riscv: spacemit: enable SD card support with UHS modes for OrangePi RV2 Iker Pedrosa
2026-03-23 10:19 ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 1/8] mmc: sdhci-of-k1: enable essential clock infrastructure for SD operation Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 2/8] mmc: sdhci-of-k1: add regulator and pinctrl voltage switching support Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-24  7:46   ` Adrian Hunter [this message]
2026-03-24  7:46     ` Adrian Hunter
2026-03-24 14:43   ` Ulf Hansson
2026-03-24 14:43     ` Ulf Hansson
2026-03-23 10:19 ` [PATCH v4 3/8] mmc: sdhci-of-k1: add comprehensive SDR tuning support Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 4/8] riscv: dts: spacemit: k1: add SD card controller and pinctrl support Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 5/8] riscv: dts: spacemit: k1-orangepi-rv2: add PMIC and power infrastructure Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 6/8] riscv: dts: spacemit: k1-orangepi-rv2: add SD card support with UHS modes Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 7/8] riscv: dts: spacemit: k1-bananapi-f3: " Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-23 10:19 ` [PATCH v4 8/8] riscv: dts: spacemit: k1-musepi-pro: " Iker Pedrosa
2026-03-23 10:19   ` Iker Pedrosa
2026-03-29  9:20 ` [PATCH v4 1/8] mmc: sdhci-of-k1: enable essential clock, infrastructure for SD operation Vincent Legoll
2026-03-29  9:20   ` Vincent Legoll
2026-03-29 11:53   ` Vincent Legoll
2026-03-29 11:53     ` Vincent Legoll

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=00bf0bb1-f769-4102-aa1b-e2804e62ccb3@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=tgamblin@baylibre.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.