From: Anand Moon <linux.amoon@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Anand Moon <linux.amoon@gmail.com>,
Dave Klotz <DaveWK225@protonmail.com>,
Eric Chung <eric.chung@riscstar.com>,
Hung-Chun Tseng <alan.tseng.cs@gmail.com>,
E Shattow <e@freeshell.de>, Yixun Lan <dlan@kernel.org>,
Huan Zhou <pericycle.cc@gmail.com>, Peng Fan <peng.fan@nxp.com>,
Jaehoon Chung <jh80.chung@samsung.com>,
Tanmay Kathpalia <tanmay.kathpalia@altera.com>,
Tom Rini <trini@konsulko.com>,
u-boot-spacemit@groups.io
Subject: [PATCH v1 2/6] mmc: spacemit_sdhci: Improve voltage switching diagnostics
Date: Thu, 29 Oct 2026 19:16:51 +0530 [thread overview]
Message-ID: <20261029134705.3767-3-linux.amoon@gmail.com> (raw)
In-Reply-To: <20261029134705.3767-1-linux.amoon@gmail.com>
Improve error reporting when setting or enabling the VQMMC
regulator fails.
Refactor voltage handling to determine the target signal voltage
before updating the regulator, and report failures when the
SDHCI voltage-switch bit does not reflect the requested state.
Keep the SDHCI host-control voltage-bit handling specific to SD
devices, while allowing the VQMMC regulator to be configured
for other MMC device types.
Cc: Dave Klotz <DaveWK225@protonmail.com>
Cc: Eric Chung <eric.chung@riscstar.com>
Cc: Hung-Chun Tseng <alan.tseng.cs@gmail.com>
Cc: E Shattow <e@freeshell.de>
Cc: Yixun Lan <dlan@kernel.org>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
drivers/mmc/spacemit_sdhci.c | 85 ++++++++++++++++++++++--------------
1 file changed, 53 insertions(+), 32 deletions(-)
diff --git a/drivers/mmc/spacemit_sdhci.c b/drivers/mmc/spacemit_sdhci.c
index f5578f38bdd..836201ce83c 100644
--- a/drivers/mmc/spacemit_sdhci.c
+++ b/drivers/mmc/spacemit_sdhci.c
@@ -222,15 +222,26 @@ static int spacemit_sdhci_set_vqmmc_voltage(struct mmc *mmc, int voltage)
#if CONFIG_IS_ENABLED(DM_REGULATOR)
int ret;
- if (!mmc->vqmmc_supply)
+ /*
+ * eMMC VCCQ is fixed at 1.8V on the BPI-F3.
+ * Do not attempt to switch its VQMMC regulator.
+ */
+ if (!IS_SD(mmc) || !mmc->vqmmc_supply)
return 0;
ret = regulator_set_value(mmc->vqmmc_supply, voltage);
- if (ret)
+ if (ret) {
+ log_err("%s: failed to set VQMMC to %d uV: %d\n",
+ mmc->dev->name, voltage, ret);
return ret;
+ }
+
ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true);
- if (ret)
+ if (ret) {
+ log_err("%s: failed to enable VQMMC: %d\n",
+ mmc->dev->name, ret);
return ret;
+ }
#endif
return 0;
}
@@ -239,44 +250,54 @@ static void spacemit_sdhci_set_voltage(struct sdhci_host *host)
{
if (IS_ENABLED(CONFIG_MMC_IO_VOLTAGE)) {
struct mmc *mmc = host->mmc;
+ bool to_180, ok;
+ int voltage_uv, ret;
u32 ctrl;
- ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
-
switch (mmc->signal_voltage) {
case MMC_SIGNAL_VOLTAGE_330:
- case MMC_SIGNAL_VOLTAGE_180: {
- bool to_180 = mmc->signal_voltage ==
- MMC_SIGNAL_VOLTAGE_180;
- bool ok;
- int voltage_mv = to_180 ? 1800000 : 3300000;
-
- if (spacemit_sdhci_set_vqmmc_voltage(mmc, voltage_mv))
- return;
- if (!IS_SD(mmc))
- return;
- if (to_180)
- ctrl |= SDHCI_CTRL_VDD_180;
- else
- ctrl &= ~SDHCI_CTRL_VDD_180;
- sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
-
- mdelay(5);
-
- ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
- ok = !!(ctrl & SDHCI_CTRL_VDD_180) == to_180;
- if (ok)
- return;
-
- log_err("%d.%dV regulator output not stable\n",
- voltage_mv / 1000000,
- (voltage_mv / 100000) % 10);
+ to_180 = false;
+ voltage_uv = 3300000;
+ break;
+ case MMC_SIGNAL_VOLTAGE_180:
+ to_180 = true;
+ voltage_uv = 1800000;
break;
- }
default:
/* No signal voltage switch required */
return;
}
+
+ ret = spacemit_sdhci_set_vqmmc_voltage(mmc, voltage_uv);
+ if (ret) {
+ log_err("%s: VQMMC switch to %d uV failed: %d\n",
+ mmc->dev->name, voltage_uv, ret);
+ return;
+ }
+
+ /*
+ * Non-SD devices may not use the SD Host Control 2
+ * voltage-switch bit. Keep their handling separate.
+ */
+ if (!IS_SD(mmc))
+ return;
+
+ ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+
+ if (to_180)
+ ctrl |= SDHCI_CTRL_VDD_180;
+ else
+ ctrl &= ~SDHCI_CTRL_VDD_180;
+
+ sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+ mdelay(5);
+
+ ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+ ok = !!(ctrl & SDHCI_CTRL_VDD_180) == to_180;
+ if (!ok) {
+ log_err("%s: SDHCI voltage bit did not switch to %d uV\n",
+ mmc->dev->name, voltage_uv);
+ }
}
}
--
2.56.0
next prev parent reply other threads:[~2026-10-29 13:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 13:46 [PATCH v1 0/6] riscv: dts: spacemit: Improve K1 SPL support Anand Moon
2026-10-29 13:46 ` [PATCH v1 1/6] riscv: dts: spacemit: Clean Up K1 U-Boot Device Tree for SPL Initialization Anand Moon
2026-10-29 13:46 ` Anand Moon [this message]
2026-10-29 13:46 ` [PATCH v1 3/6] mmc: spacemit_sdhci: Handle missing pinctrl states Anand Moon
2026-10-29 13:46 ` [PATCH v1 4/6] gpio: spacemit: Add SPL support for K1 GPIO driver Anand Moon
2026-10-29 13:46 ` [PATCH v1 5/6] pinctrl: spacemit: Add SPL support for K1 pinctrl driver Anand Moon
2026-10-29 13:46 ` [PATCH v1 6/6] configs: spacemit_k1: Enable SPL GPIO and pinctrl support 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=20261029134705.3767-3-linux.amoon@gmail.com \
--to=linux.amoon@gmail.com \
--cc=DaveWK225@protonmail.com \
--cc=alan.tseng.cs@gmail.com \
--cc=dlan@kernel.org \
--cc=e@freeshell.de \
--cc=eric.chung@riscstar.com \
--cc=jh80.chung@samsung.com \
--cc=peng.fan@nxp.com \
--cc=pericycle.cc@gmail.com \
--cc=tanmay.kathpalia@altera.com \
--cc=trini@konsulko.com \
--cc=u-boot-spacemit@groups.io \
--cc=u-boot@lists.u-boot-project.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.