* [PATCH v2 0/8] spacemit mmc driver
@ 2026-06-29 15:51 Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support Eric Chung
` (7 more replies)
0 siblings, 8 replies; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
This series adds MMC support for the SpacemiT K1: an SDHCI platform
driver, the SD card device-tree overlay, defconfig options, and SPL
boot-device selection from the SoC strap/config registers. The SDHCI
driver is usable in both SPL and U-Boot proper.
A flashing guide (doc/board/spacemit/k1-flash.rst) describes how to
write images to eMMC.
This series sits on top of three series still under review, and must be
applied after them, in this order:
1. K1 clock/reset/dts migration [1] (8 patches)
2. K1 SPL bring-up v4 [2] (14 patches)
3. K1 pinctrl/GPIO and SPI NOR v2 [3] (9 patches)
Then this series (8 patches)
For each series:
b4 am <cover-msgid>
git am ./*.mbx
Link: https://lore.kernel.org/u-boot/20260526-b4-k1-clk-reset-upstream-dts-v2-0-af815e362b0c@riscstar.com/ [1]
Link: https://lore.kernel.org/u-boot/20260519-b4-k1-spl-bring-up-v4-0-3915a2a904c1@riscstar.com/ [2]
Link: https://lore.kernel.org/u-boot/20260520-b4-k1-spl-pinctrl-spinor-v2-0-8d25db98ac8e@riscstar.com/ [3]
---
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: https://patch.msgid.link/20260629-m4-v1-0-a11f8d496e62@riscstar.com
Changes in v2:
- cmd: drop patches on eminfo & tlv_eeprom.
- configs: Enable ADMA and SYSCON support.
- dts: Use vmmc-supply as vqmmc-supply on the SD card node.
- mmc: k1: Enable ADMA mode support, use CMD23 for multi-block
read/write, correct pinctrl state from "fast" to "uhs".
- mmc: sdhci: Add new quirk patch to enable CMD23 for multi-block
transfers.
- pinctrl: k1: Add new IO power domain configuration support for
dual-voltage GPIO banks.
- spacemit: k1: Use FIELD_GET() to parse boot strap mode.
- Link to v1: https://lore.kernel.org/u-boot/20260521-k1-spl-mmc-sdcard-v1-0-1bd14b8c4f9f@riscstar.com/
To: u-boot-spacemit@groups.io
To: u-boot@lists.denx.de
Cc: Huan Zhou <pericycle.cc@gmail.com>
Cc: Guodong Xu <guodong.xu@riscstar.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Raymond Mao <raymond.mao@riscstar.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Bhimeswararao Matsa <bhimeswararao.matsa@gmail.com>
Cc: Tanmay Kathpalia <tanmay.kathpalia@altera.com>
Cc: Kaustabh Chakraborty <kauschluss@disroot.org>
Cc: Han Xu <han.xu@nxp.com>
Cc: Yanir Levin <yanir.levin@tandemg.com>
Cc: Christoph Stoidner <c.stoidner@phytec.de>
Cc: Balsundar Ponnusamy <balsundar.ponnusamy@altera.com>
Cc: Daniel Palmer <daniel@thingy.jp>
Cc: Anshul Dalal <anshuld@ti.com>
Cc: Bastien Curutchet <bastien.curutchet@bootlin.com>
Cc: Angelo Dureghello <angelo@kernel-space.org>
Cc: Johan Jonker <jbx6244@gmail.com>
Cc: Rick Chen <rick@andestech.com>
Cc: Leo <ycliang@andestech.com>
Cc: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
Eric Chung (8):
pinctrl: k1: add IO power domain configuration support
mmc: sdhci: add quirk to enable CMD23 for multi-block transfers
mmc: k1: add sdhci platform driver
dts: k1: add SD card support in u-boot overlay
configs: k1: enable SD and eMMC support
doc: spacemit: flash on K1 SoC based boards
config: k1: enable ENV support for eMMC
spacemit: k1: load product name from environment variable
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 87 +++-
arch/riscv/dts/k1-musepi-pro-u-boot.dtsi | 82 +++-
board/spacemit/k1/MAINTAINERS | 3 +-
board/spacemit/k1/spl.c | 50 +--
configs/spacemit_k1_defconfig | 26 +-
doc/board/spacemit/index.rst | 1 +
doc/board/spacemit/k1-flash.rst | 157 +++++++
drivers/mmc/Kconfig | 7 +
drivers/mmc/Makefile | 1 +
drivers/mmc/mmc.c | 22 +-
drivers/mmc/sdhci.c | 3 +
drivers/mmc/spacemit_sdhci.c | 681 ++++++++++++++++++++++++++++++
drivers/pinctrl/spacemit/pinctrl-k1.c | 84 +++-
include/mmc.h | 5 +-
include/sdhci.h | 1 +
15 files changed, 1157 insertions(+), 53 deletions(-)
---
base-commit: e7a6b33b153be98fcca16729e189f90c2d91a98c
change-id: 20260629-m4-98e01659fefb
Best regards,
--
Eric Chung <eric.chung@riscstar.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-30 8:55 ` Yao Zi
2026-06-29 15:51 ` [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers Eric Chung
` (6 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Dual-voltage GPIO banks default to 3.3V, but when externally supplied
with 1.8V the internal logic must be explicitly reconfigured to match.
Add the ability to program IO power domain control registers through the
APBC block. These registers require unlocking the AIB Secure Access
Register (ASAR) before every read/write, since configuring a 1.8V domain
while 3.3V is externally supplied can cause back-powering and pin damage.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
drivers/pinctrl/spacemit/pinctrl-k1.c | 84 ++++++++++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/spacemit/pinctrl-k1.c b/drivers/pinctrl/spacemit/pinctrl-k1.c
index 3ebc397213b..5d3236aac94 100644
--- a/drivers/pinctrl/spacemit/pinctrl-k1.c
+++ b/drivers/pinctrl/spacemit/pinctrl-k1.c
@@ -12,6 +12,8 @@
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/io.h>
+#include <regmap.h>
+#include <syscon.h>
/*
* +---------+----------+-----------+--------+--------+----------+--------+
@@ -34,8 +36,24 @@
#define PAD_PULLUP BIT(14)
#define PAD_PULL_EN BIT(15)
-#define PIN_POWER_STATE_1V8 1800
-#define PIN_POWER_STATE_3V3 3300
+#define IO_PWR_DOMAIN_OFFSET 0x800
+
+#define IO_PWR_DOMAIN_GPIO2_Kx 0x0c
+#define IO_PWR_DOMAIN_MMC_Kx 0x1c
+
+#define IO_PWR_DOMAIN_GPIO3_K1 0x10
+#define IO_PWR_DOMAIN_QSPI_K1 0x20
+
+#define IO_PWR_DOMAIN_V18EN BIT(2)
+
+#define APBC_ASFAR 0x50
+#define APBC_ASSAR 0x54
+
+#define APBC_ASFAR_AKEY 0xbaba
+#define APBC_ASSAR_AKEY 0xeb10
+
+#define PIN_POWER_STATE_1V8 1800
+#define PIN_POWER_STATE_3V3 3300
enum spacemit_pin_io_type {
IO_TYPE_NONE = 0,
@@ -60,12 +78,14 @@ struct spacemit_pinctrl_data {
int (*get_pins)(struct udevice *dev);
int (*get_functions)(struct udevice *dev);
int (*get_io_type)(struct udevice *dev, unsigned int pin);
+ unsigned int (*pin_to_io_pd_offset)(unsigned int pin);
};
struct spacemit_pinctrl_priv {
void __iomem *regs;
struct spacemit_pin_io *io_pins;
int nr_io_pins;
+ struct regmap *regmap;
};
struct spacemit_pin_mux_config {
@@ -196,6 +216,28 @@ static int k1_get_io_type(struct udevice *dev, unsigned int selector)
return -EINVAL;
}
+static unsigned int spacemit_k1_pin_to_io_pd_offset(unsigned int pin)
+{
+ unsigned int offset = 0;
+
+ switch (pin) {
+ case 47 ... 52:
+ offset = IO_PWR_DOMAIN_GPIO3_K1;
+ break;
+ case 75 ... 80:
+ offset = IO_PWR_DOMAIN_GPIO2_Kx;
+ break;
+ case 98 ... 103:
+ offset = IO_PWR_DOMAIN_QSPI_K1;
+ break;
+ case 104 ... 109:
+ offset = IO_PWR_DOMAIN_MMC_Kx;
+ break;
+ }
+
+ return offset;
+}
+
/* use IO high level output current as the table */
static struct spacemit_pin_drv_strength spacemit_ds_1v8_tbl[4] = {
{ 0, 11 },
@@ -400,6 +442,35 @@ static const struct pinconf_param spacemit_pinconf_params[] = {
{ "power-source", PIN_CONFIG_POWER_SOURCE, U32_MAX },
};
+static void spacemit_set_io_power_domain(struct udevice *dev,
+ unsigned int pin,
+ unsigned int io_type)
+{
+ struct spacemit_pinctrl_priv *priv = dev_get_priv(dev);
+ struct spacemit_pinctrl_data *data;
+ unsigned int offset;
+ u32 val = 0;
+
+ if (!priv->regmap)
+ return;
+
+ data = (struct spacemit_pinctrl_data *)dev_get_driver_data(dev);
+ if (!data || !data->pin_to_io_pd_offset)
+ return;
+
+ offset = data->pin_to_io_pd_offset(pin);
+ if (!offset)
+ return;
+
+ if (io_type == IO_TYPE_1V8)
+ val = IO_PWR_DOMAIN_V18EN;
+
+ regmap_write(priv->regmap, APBC_ASFAR, APBC_ASFAR_AKEY);
+ regmap_write(priv->regmap, APBC_ASSAR, APBC_ASSAR_AKEY);
+
+ writel(val, priv->regs + IO_PWR_DOMAIN_OFFSET + offset);
+}
+
static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
unsigned int param, unsigned int argument)
{
@@ -456,6 +527,9 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
dev_err(dev, "Invalid power source (%d)\n", argument);
return -EINVAL;
}
+ if (found)
+ spacemit_set_io_power_domain(dev, pin_selector,
+ priv->io_pins[i].io_type);
break;
default:
return -EOPNOTSUPP;
@@ -485,6 +559,11 @@ static int spacemit_pinctrl_probe(struct udevice *dev)
dev_err(dev, "Fail to allocate memory\n");
return -ENOMEM;
}
+ priv->regmap = syscon_regmap_lookup_by_phandle(dev, "spacemit,apbc");
+ if (IS_ERR(priv->regmap)) {
+ dev_warn(dev, "no syscon found, disable IO power domain switching\n");
+ priv->regmap = NULL;
+ }
ret = clk_get_bulk(dev, &clks);
if (ret) {
@@ -512,6 +591,7 @@ static const struct spacemit_pinctrl_data k1_pinctrl_data = {
.get_pins = k1_get_pins,
.get_functions = k1_get_functions,
.get_io_type = k1_get_io_type,
+ .pin_to_io_pd_offset = spacemit_k1_pin_to_io_pd_offset,
};
static const struct udevice_id spacemit_pinctrl_ids[] = {
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-30 2:47 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver Eric Chung
` (5 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Introduce a controller-specific quirk to select CMD23 (SET_BLOCK_COUNT)
for read/write multi-block operations instead of the legacy CMD18/CMD25
with open-ended or pre-defined block counts.
This allows SDHCI host controllers that support CMD23 to improve I/O
efficiency by reducing the number of CMD12 (STOP_TRANSMISSION) commands
for multi-block transfers.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
drivers/mmc/mmc.c | 22 ++++++++++++++++++----
drivers/mmc/sdhci.c | 3 +++
include/mmc.h | 5 ++++-
include/sdhci.h | 1 +
4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index f0e38efb262..9f2c8cb8d14 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -461,6 +461,15 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
struct mmc_cmd cmd;
struct mmc_data data;
+ if (IS_ENABLED(CONFIG_MMC_QUIRKS) &&
+ (mmc->quirks & MMC_QUIRK_BLK_CMD23)) {
+ cmd.cmdidx = MMC_CMD_SET_BLOCK_COUNT;
+ cmd.cmdarg = blkcnt & 0x0000ffff;
+ cmd.resp_type = MMC_RSP_R1;
+ if (mmc_send_cmd(mmc, &cmd, NULL))
+ return 0;
+ }
+
if (blkcnt > 1)
cmd.cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK;
else
@@ -481,7 +490,9 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
if (mmc_send_cmd(mmc, &cmd, &data))
return 0;
- if (blkcnt > 1) {
+ if (blkcnt > 1 &&
+ IS_ENABLED(CONFIG_MMC_QUIRKS) &&
+ !(mmc->quirks & MMC_QUIRK_BLK_CMD23)) {
if (mmc_send_stop_transmission(mmc, false)) {
#if !defined(CONFIG_XPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
log_err("mmc fail to send stop cmd\n");
@@ -1436,6 +1447,9 @@ static int sd_get_capabilities(struct mmc *mmc)
if (mmc->scr[0] & SD_DATA_4BIT)
mmc->card_caps |= MMC_MODE_4BIT;
+ if (IS_ENABLED(CONFIG_MMC_QUIRKS) &&
+ !(mmc->scr[0] & SD_SCR_CMD23_SUPPORT))
+ mmc->quirks &= ~MMC_QUIRK_BLK_CMD23;
/* Version 1.0 doesn't support switching */
if (mmc->version == SD_VERSION_1_0)
@@ -2963,9 +2977,9 @@ int mmc_get_op_cond(struct mmc *mmc, bool quiet)
return err;
#ifdef CONFIG_MMC_QUIRKS
- mmc->quirks = MMC_QUIRK_RETRY_SET_BLOCKLEN |
- MMC_QUIRK_RETRY_SEND_CID |
- MMC_QUIRK_RETRY_APP_CMD;
+ mmc->quirks |= MMC_QUIRK_RETRY_SET_BLOCKLEN |
+ MMC_QUIRK_RETRY_SEND_CID |
+ MMC_QUIRK_RETRY_APP_CMD;
#endif
err = mmc_power_cycle(mmc);
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 08594e10266..f670b8edd61 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -741,6 +741,9 @@ static int sdhci_init(struct mmc *mmc)
}
}
#endif
+ if (IS_ENABLED(CONFIG_MMC_QUIRKS) &&
+ (host->quirks & SDHCI_QUIRK_BLK_CMD23))
+ host->mmc->quirks |= MMC_QUIRK_BLK_CMD23;
sdhci_set_power(host, fls(mmc->cfg->voltages) - 1);
diff --git a/include/mmc.h b/include/mmc.h
index 9509c9e9543..ba2425b96e0 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -141,6 +141,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
#define SD_HIGHSPEED_BUSY 0x00020000
#define SD_HIGHSPEED_SUPPORTED 0x00020000
+#define SD_SCR_CMD23_SUPPORT BIT(1)
+
#define UHS_SDR12_BUS_SPEED 0
#define HIGH_SPEED_BUS_SPEED 1
#define UHS_SDR25_BUS_SPEED 1
@@ -343,7 +345,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
#define MMC_QUIRK_RETRY_SEND_CID BIT(0)
#define MMC_QUIRK_RETRY_SET_BLOCKLEN BIT(1)
-#define MMC_QUIRK_RETRY_APP_CMD BIT(2)
+#define MMC_QUIRK_RETRY_APP_CMD BIT(2)
+#define MMC_QUIRK_BLK_CMD23 BIT(3)
enum mmc_voltage {
MMC_SIGNAL_VOLTAGE_000 = 0,
diff --git a/include/sdhci.h b/include/sdhci.h
index fb847821d58..64f6f6ab2bf 100644
--- a/include/sdhci.h
+++ b/include/sdhci.h
@@ -256,6 +256,7 @@
#define SDHCI_QUIRK_SUPPORT_SINGLE (1 << 10)
/* Capability register bit-63 indicates HS400 support */
#define SDHCI_QUIRK_CAPS_BIT63_FOR_HS400 BIT(11)
+#define SDHCI_QUIRK_BLK_CMD23 BIT(12)
/* to make gcc happy */
struct sdhci_host;
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-30 2:52 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay Eric Chung
` (4 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Add SDHCI platform driver support for SpacemiT K1 SoC. This driver
implements the necessary platform-specific operations for the SDHCI
controller, enabling MMC/SD card functionality on K1-based platforms.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
v2:
- Enable ADMA mode support.
- Use CMD23 for multi-block read/write.
- Move ASR/AIB register into pinctrl driver.
- Correct pinctrl state from "fast" to "uhs".
- Migrate tuning support from the spacemit linux driver.
---
drivers/mmc/Kconfig | 7 +
drivers/mmc/Makefile | 1 +
drivers/mmc/spacemit_sdhci.c | 681 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 689 insertions(+)
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 131be3106a1..f05b376ab72 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -722,6 +722,13 @@ config MMC_SDHCI_SNPS
If unsure, say N.
+config MMC_SDHCI_SPACEMIT
+ bool "Spacemit SDHCI controller"
+ depends on MMC_SDHCI
+ help
+ Support for Secure Digital Host Controller Interface (SDHCI) on
+ Spacemit K1 SoC.
+
config MMC_SDHCI_STI
bool "SDHCI support for STMicroelectronics SoC"
depends on MMC_SDHCI && OF_CONTROL && ARCH_STI
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index a23336d7d8d..aa05cec23be 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_ROCKCHIP) += rockchip_sdhci.o
obj-$(CONFIG_MMC_SDHCI_ADI) += adi_sdhci.o
obj-$(CONFIG_MMC_SDHCI_S5P) += s5p_sdhci.o
obj-$(CONFIG_MMC_SDHCI_SNPS) += snps_sdhci.o
+obj-$(CONFIG_MMC_SDHCI_SPACEMIT) += spacemit_sdhci.o
obj-$(CONFIG_MMC_SDHCI_STI) += sti_sdhci.o
obj-$(CONFIG_MMC_SDHCI_TANGIER) += tangier_sdhci.o
obj-$(CONFIG_MMC_SDHCI_TEGRA) += tegra_mmc.o
diff --git a/drivers/mmc/spacemit_sdhci.c b/drivers/mmc/spacemit_sdhci.c
new file mode 100644
index 00000000000..c905c33b2af
--- /dev/null
+++ b/drivers/mmc/spacemit_sdhci.c
@@ -0,0 +1,681 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Driver for Spacemit K1 Mobile Storage Host Controller
+ *
+ * Copyright (C) 2023-2026 Spacemit Inc.
+ * Copyright (C) 2026 RISCstar Ltd.
+ */
+
+#define LOG_CATEGORY UCLASS_MMC
+
+#include <clk.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <log.h>
+#include <malloc.h>
+#include <sdhci.h>
+#include <reset-uclass.h>
+#include <mapmem.h>
+#include <dm/pinctrl.h>
+#include <linux/libfdt.h>
+#include <linux/delay.h>
+#include <power/regulator.h>
+
+#define FIELD_PREP(mask, val) (((val) << __ffs(mask)) & (mask))
+
+/* SDH register definitions */
+#define SPACEMIT_SDHC_OP_EXT_REG 0x108
+#define SDHC_OVRRD_CLK_OEN BIT(11)
+#define SDHC_FORCE_CLK_ON BIT(12)
+
+#define SPACEMIT_SDHC_LEGACY_CTRL_REG 0x10C
+#define SDHC_GEN_PAD_CLK_ON BIT(6)
+
+#define SPACEMIT_SDHC_MMC_CTRL_REG 0x114
+#define SDHC_MISC_INT_EN BIT(1)
+#define SDHC_MISC_INT BIT(2)
+#define SDHC_ENHANCE_STROBE_EN BIT(8)
+#define SDHC_MMC_HS400 BIT(9)
+#define SDHC_MMC_HS200 BIT(10)
+#define SDHC_MMC_CARD_MODE BIT(12)
+
+#define SPACEMIT_SDHC_TX_CFG_REG 0x11C
+#define SDHC_TX_INT_CLK_SEL BIT(30)
+#define SDHC_TX_MUX_SEL BIT(31)
+
+#define SPACEMIT_SDHC_PHY_CTRL_REG 0x160
+#define SDHC_PHY_FUNC_EN BIT(0)
+#define SDHC_PHY_PLL_LOCK BIT(1)
+#define SDHC_HOST_LEGACY_MODE BIT(31)
+
+#define SPACEMIT_SDHC_PHY_FUNC_REG 0x164
+#define SDHC_PHY_TEST_EN BIT(7)
+#define SDHC_HS200_USE_RFIFO BIT(15)
+
+#define SPACEMIT_SDHC_PHY_DLLCFG 0x168
+#define SDHC_DLL_PREDLY_NUM GENMASK(3, 2)
+#define SDHC_DLL_FULLDLY_RANGE GENMASK(5, 4)
+#define SDHC_DLL_VREG_CTRL GENMASK(7, 6)
+#define SDHC_DLL_ENABLE BIT(31)
+
+#define SPACEMIT_SDHC_PHY_DLLCFG1 0x16C
+#define SDHC_DLL_REG1_CTRL GENMASK(7, 0)
+#define SDHC_DLL_REG2_CTRL GENMASK(15, 8)
+#define SDHC_DLL_REG3_CTRL GENMASK(23, 16)
+#define SDHC_DLL_REG4_CTRL GENMASK(31, 24)
+
+#define SPACEMIT_SDHC_PHY_DLLSTS 0x170
+#define SDHC_DLL_LOCK_STATE BIT(0)
+
+#define SPACEMIT_SDHC_PHY_PADCFG_REG 0x178
+#define SDHC_PHY_DRIVE_SEL GENMASK(2, 0)
+#define SDHC_RX_BIAS_CTRL BIT(5)
+
+#define SPACEMIT_SDHC_RX_CFG_REG 0x118
+#define SDHC_RX_SDCLK_SEL0_MASK GENMASK(1, 0)
+#define SDHC_RX_SDCLK_SEL1_MASK GENMASK(3, 2)
+#define SDHC_RX_SDCLK_SEL1 FIELD_PREP(SDHC_RX_SDCLK_SEL1_MASK, 1)
+
+#define SPACEMIT_SDHC_DLINE_CTRL_REG 0x130
+#define SDHC_DLINE_PU BIT(0)
+#define SDHC_RX_DLINE_CODE_MASK GENMASK(23, 16)
+#define SDHC_TX_DLINE_CODE_MASK GENMASK(31, 24)
+
+#define SPACEMIT_SDHC_DLINE_CFG_REG 0x134
+#define SDHC_RX_DLINE_REG_MASK GENMASK(7, 0)
+#define SDHC_RX_DLINE_GAIN BIT(8)
+#define SDHC_TX_DLINE_REG_MASK GENMASK(23, 16)
+
+#define SPACEMIT_RX_DLINE_REG 9
+#define SPACEMIT_RX_TUNE_DELAY_MIN 0x0
+#define SPACEMIT_RX_TUNE_DELAY_MAX 0xFF
+
+#define SPACEMIT_TX_TUNING_DLINE_REG 0x00
+#define SPACEMIT_TX_TUNING_DELAYCODE 127
+
+struct spacemit_sdhci_plat {
+ struct mmc_config cfg;
+ struct mmc mmc;
+ struct reset_ctl_bulk resets;
+ struct clk_bulk clks;
+};
+
+struct spacemit_sdhci_priv {
+ struct sdhci_host host;
+};
+
+/* All helper functions will update clr/set while preserve rest bits */
+static inline void spacemit_sdhci_setbits(struct sdhci_host *host, u32 val,
+ int reg)
+{
+ sdhci_writel(host, sdhci_readl(host, reg) | val, reg);
+}
+
+static inline void spacemit_sdhci_clrbits(struct sdhci_host *host, u32 val,
+ int reg)
+{
+ sdhci_writel(host, sdhci_readl(host, reg) & ~val, reg);
+}
+
+static inline void spacemit_sdhci_clrsetbits(struct sdhci_host *host, u32 clr,
+ u32 set, int reg)
+{
+ u32 val = sdhci_readl(host, reg);
+
+ val = (val & ~clr) | set;
+ sdhci_writel(host, val, reg);
+}
+
+#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
+static void spacemit_sdhci_set_rx_delay(struct sdhci_host *host, u8 delay)
+{
+ spacemit_sdhci_clrsetbits(host, SDHC_RX_DLINE_CODE_MASK,
+ FIELD_PREP(SDHC_RX_DLINE_CODE_MASK, delay),
+ SPACEMIT_SDHC_DLINE_CTRL_REG);
+}
+
+static void spacemit_sdhci_set_tx_delay(struct sdhci_host *host, u8 delay)
+{
+ spacemit_sdhci_clrsetbits(host, SDHC_TX_DLINE_CODE_MASK,
+ FIELD_PREP(SDHC_TX_DLINE_CODE_MASK, delay),
+ SPACEMIT_SDHC_DLINE_CTRL_REG);
+}
+
+static void spacemit_sdhci_set_tx_dline_reg(struct sdhci_host *host,
+ u8 dline_reg)
+{
+ spacemit_sdhci_clrsetbits(host, SDHC_TX_DLINE_REG_MASK,
+ FIELD_PREP(SDHC_TX_DLINE_REG_MASK, dline_reg),
+ SPACEMIT_SDHC_DLINE_CFG_REG);
+}
+
+static void spacemit_sdhci_tx_tuning_prepare(struct sdhci_host *host)
+{
+ spacemit_sdhci_setbits(host, SDHC_TX_MUX_SEL, SPACEMIT_SDHC_TX_CFG_REG);
+ spacemit_sdhci_setbits(host, SDHC_DLINE_PU,
+ SPACEMIT_SDHC_DLINE_CTRL_REG);
+ udelay(5);
+}
+
+static void spacemit_sdhci_prepare_tuning(struct sdhci_host *host)
+{
+ spacemit_sdhci_clrsetbits(host, SDHC_RX_DLINE_REG_MASK,
+ FIELD_PREP(SDHC_RX_DLINE_REG_MASK, SPACEMIT_RX_DLINE_REG),
+ SPACEMIT_SDHC_DLINE_CFG_REG);
+
+ spacemit_sdhci_setbits(host, SDHC_DLINE_PU,
+ SPACEMIT_SDHC_DLINE_CTRL_REG);
+ udelay(5);
+
+ spacemit_sdhci_clrsetbits(host, SDHC_RX_SDCLK_SEL1_MASK,
+ SDHC_RX_SDCLK_SEL1,
+ SPACEMIT_SDHC_RX_CFG_REG);
+
+ if (host->mmc->selected_mode == MMC_HS_200)
+ spacemit_sdhci_setbits(host, SDHC_HS200_USE_RFIFO,
+ SPACEMIT_SDHC_PHY_FUNC_REG);
+}
+#endif /* MMC_SUPPORTS_TUNING */
+
+/*
+ * Reference: PMU_SDH0_CLK_RES_CTRL (0x054), SDH0_CLK_SEL=0x0,
+ * SDH0_CLK_DIV=0x1. The default clock source is 204.8 MHz
+ * (pll1_d6_409p6Mhz / 2).
+ *
+ * During start-up, use a 200 kHz frequency.
+ */
+#define SDHC_MIN_CLOCK (200 * 1000)
+
+static void spacemit_sdhci_phy_init(struct udevice *dev,
+ struct sdhci_host *host)
+{
+ u32 reg = 0;
+
+ if (dev_read_bool(dev, "no-sd") && dev_read_bool(dev, "no-sdio")) {
+ /* MMC card mode */
+ reg = sdhci_readl(host, SPACEMIT_SDHC_MMC_CTRL_REG);
+ reg |= SDHC_MMC_CARD_MODE;
+ sdhci_writel(host, reg, SPACEMIT_SDHC_MMC_CTRL_REG);
+
+ /* Use PHY functional mode */
+ reg = sdhci_readl(host, SPACEMIT_SDHC_PHY_CTRL_REG);
+ reg |= (SDHC_PHY_FUNC_EN | SDHC_PHY_PLL_LOCK);
+ sdhci_writel(host, reg, SPACEMIT_SDHC_PHY_CTRL_REG);
+
+ reg = sdhci_readl(host, SPACEMIT_SDHC_PHY_PADCFG_REG);
+ reg |= SDHC_RX_BIAS_CTRL;
+ sdhci_writel(host, reg, SPACEMIT_SDHC_PHY_PADCFG_REG);
+ } else {
+ reg = sdhci_readl(host, SPACEMIT_SDHC_TX_CFG_REG);
+ reg |= SDHC_TX_INT_CLK_SEL;
+ sdhci_writel(host, reg, SPACEMIT_SDHC_TX_CFG_REG);
+ }
+
+ reg = sdhci_readl(host, SPACEMIT_SDHC_MMC_CTRL_REG);
+ reg &= ~SDHC_ENHANCE_STROBE_EN;
+ sdhci_writel(host, reg, SPACEMIT_SDHC_MMC_CTRL_REG);
+}
+
+static int spacemit_sdhci_set_vqmmc_voltage(struct mmc *mmc, int voltage)
+{
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+ int ret;
+
+ if (!mmc->vqmmc_supply)
+ return 0;
+
+ ret = regulator_set_value(mmc->vqmmc_supply, voltage);
+ if (ret) {
+ log_err("failed to set vqmmc voltage to %d.%dV\n",
+ voltage / 1000000, (voltage / 100000) % 10);
+ return ret;
+ }
+ ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true);
+ if (ret) {
+ log_err("failed to enable vqmmc supply\n");
+ return ret;
+ }
+#endif
+ return 0;
+}
+
+static void spacemit_sdhci_set_voltage(struct sdhci_host *host)
+{
+ if (IS_ENABLED(CONFIG_MMC_IO_VOLTAGE)) {
+ struct mmc *mmc = host->mmc;
+ 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);
+ break;
+ }
+ default:
+ /* No signal voltage switch required */
+ return;
+ }
+ }
+}
+
+static void spacemit_sdhci_set_clk_gate(struct sdhci_host *host, int auto_gate)
+{
+ u32 reg;
+
+ reg = sdhci_readl(host, SPACEMIT_SDHC_OP_EXT_REG);
+ if (auto_gate)
+ reg &= ~(SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON);
+ else
+ reg |= (SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON);
+ sdhci_writel(host, reg, SPACEMIT_SDHC_OP_EXT_REG);
+}
+
+static bool spacemit_sdhci_is_voltage_switch_cmd(struct sdhci_host *host)
+{
+ struct mmc *mmc = host->mmc;
+ u32 cmd;
+
+ if (!IS_SD(mmc))
+ return false;
+
+ cmd = SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND));
+ return cmd == SD_CMD_SWITCH_UHS18V &&
+ mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180;
+}
+
+static int spacemit_sdhci_wait_dat0(struct udevice *dev, int state,
+ int timeout_us)
+{
+ struct mmc *mmc = mmc_get_mmc_dev(dev);
+ struct sdhci_host *host = mmc->priv;
+ unsigned long timeout = timer_get_us() + timeout_us;
+ u32 tmp;
+
+ /*
+ * readx_poll_timeout is unsuitable because sdhci_readl accepts
+ * two arguments
+ */
+ do {
+ tmp = sdhci_readl(host, SDHCI_PRESENT_STATE);
+ if (!!(tmp & SDHCI_DATA_0_LVL_MASK) == !!state) {
+ if (spacemit_sdhci_is_voltage_switch_cmd(host))
+ spacemit_sdhci_set_clk_gate(host, 1);
+ return 0;
+ }
+ } while (!timeout_us || !time_after(timer_get_us(), timeout));
+
+ return -ETIMEDOUT;
+}
+
+static void spacemit_sdhci_set_control_reg(struct sdhci_host *host)
+{
+ struct mmc *mmc = host->mmc;
+ u32 reg;
+
+ spacemit_sdhci_set_voltage(host);
+
+ if (spacemit_sdhci_is_voltage_switch_cmd(host))
+ spacemit_sdhci_set_clk_gate(host, 0);
+
+ /*
+ * Set TX_INT_CLK_SEL to guarantee hold time at default speed,
+ * HS, SDR12/SDR25/SDR50 modes. See SDHC_TX_CFG_REG (0x11c).
+ */
+ reg = sdhci_readl(host, SPACEMIT_SDHC_TX_CFG_REG);
+ if (mmc->selected_mode == MMC_LEGACY ||
+ mmc->selected_mode == MMC_HS ||
+ mmc->selected_mode == SD_HS ||
+ mmc->selected_mode == UHS_SDR12 ||
+ mmc->selected_mode == UHS_SDR25 ||
+ mmc->selected_mode == UHS_SDR50) {
+ reg |= SDHC_TX_INT_CLK_SEL;
+ } else {
+ reg &= ~SDHC_TX_INT_CLK_SEL;
+ }
+ sdhci_writel(host, reg, SPACEMIT_SDHC_TX_CFG_REG);
+
+ /* Set pinctrl state */
+ if (IS_ENABLED(CONFIG_PINCTRL)) {
+ if (mmc->clock >= 200000000)
+ pinctrl_select_state(mmc->dev, "uhs");
+ else
+ pinctrl_select_state(mmc->dev, "default");
+ }
+
+ if (mmc->selected_mode == MMC_HS_200 ||
+ mmc->selected_mode == MMC_HS_400 ||
+ mmc->selected_mode == MMC_HS_400_ES) {
+ reg = sdhci_readw(host, SPACEMIT_SDHC_MMC_CTRL_REG);
+ if (mmc->selected_mode == MMC_HS_200)
+ reg |= SDHC_MMC_HS200;
+ else
+ reg |= SDHC_MMC_HS400;
+ sdhci_writew(host, reg, SPACEMIT_SDHC_MMC_CTRL_REG);
+ } else {
+ reg = sdhci_readw(host, SPACEMIT_SDHC_MMC_CTRL_REG);
+ reg &= ~(SDHC_MMC_HS200 | SDHC_MMC_HS400 | SDHC_ENHANCE_STROBE_EN);
+ sdhci_writew(host, reg, SPACEMIT_SDHC_MMC_CTRL_REG);
+ }
+
+ sdhci_set_uhs_timing(host);
+}
+
+#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
+static int spacemit_sdhci_execute_tuning(struct mmc *mmc, u8 opcode)
+{
+ struct sdhci_host *host = mmc->priv;
+ int current_len = 0, current_start = 0;
+ int max_pass_len = 0, max_pass_start = 0;
+ u8 final_delay;
+ int ret = 0;
+ int i;
+
+ /*
+ * Tuning is required for SDR50/SDR104, HS200/HS400 cards and
+ * if clock frequency is greater than 100MHz in these modes.
+ */
+ if (host->clock < 100 * 1000 * 1000 ||
+ !(mmc->selected_mode == MMC_HS_200 ||
+ mmc->selected_mode == UHS_SDR50 ||
+ mmc->selected_mode == UHS_SDR104))
+ return 0;
+
+ if (IS_SD(host->mmc)) {
+ spacemit_sdhci_set_tx_dline_reg(host, SPACEMIT_TX_TUNING_DLINE_REG);
+ spacemit_sdhci_set_tx_delay(host, SPACEMIT_TX_TUNING_DELAYCODE);
+ spacemit_sdhci_tx_tuning_prepare(host);
+
+ log_debug("TX tuning: dline_reg=%d, delaycode=%d\n",
+ SPACEMIT_TX_TUNING_DLINE_REG, SPACEMIT_TX_TUNING_DELAYCODE);
+ }
+
+ spacemit_sdhci_prepare_tuning(host);
+
+ for (i = SPACEMIT_RX_TUNE_DELAY_MIN; i <= SPACEMIT_RX_TUNE_DELAY_MAX; i++) {
+ spacemit_sdhci_set_rx_delay(host, i);
+ ret = mmc_send_tuning(host->mmc, opcode);
+
+ log_debug("RX delay %d: %s\n",
+ i, ret == 0 ? "pass" : "fail");
+
+ if (ret == 0) {
+ /* Test passed - extend current window */
+ if (current_len == 0)
+ current_start = i;
+ current_len++;
+ } else {
+ /* Test failed - check if current window is best so far */
+ if (current_len > max_pass_len) {
+ max_pass_len = current_len;
+ max_pass_start = current_start;
+ }
+ current_len = 0;
+ }
+ }
+
+ if (current_len > max_pass_len) {
+ max_pass_len = current_len;
+ max_pass_start = current_start;
+ }
+
+ if (max_pass_len < 3) {
+ log_err("Tuning failed: no stable window found\n");
+ return -EIO;
+ }
+
+ final_delay = max_pass_start + max_pass_len / 2;
+ spacemit_sdhci_set_rx_delay(host, final_delay);
+ ret = mmc_send_tuning(host->mmc, opcode);
+ if (ret) {
+ u8 retry_delays[] = {
+ max_pass_start + max_pass_len / 4,
+ max_pass_start + (3 * max_pass_len) / 4,
+ max_pass_start,
+ max_pass_start + max_pass_len - 1
+ };
+ int retry_count = ARRAY_SIZE(retry_delays);
+
+ log_warning("Primary delay %d failed, trying alternatives\n",
+ final_delay);
+
+ for (i = 0; i < retry_count; i++) {
+ if (retry_delays[i] >= SPACEMIT_RX_TUNE_DELAY_MIN &&
+ retry_delays[i] <= SPACEMIT_RX_TUNE_DELAY_MAX) {
+ spacemit_sdhci_set_rx_delay(host, retry_delays[i]);
+ ret = mmc_send_tuning(host->mmc, opcode);
+ if (!ret) {
+ final_delay = retry_delays[i];
+ log_info("Retry successful with delay %d\n",
+ final_delay);
+ break;
+ }
+ }
+ }
+
+ if (ret) {
+ log_err("All retry attempts failed\n");
+ return -EIO;
+ }
+ }
+
+ log_debug("Tuning successful: window %d-%d, using delay %d\n",
+ max_pass_start, max_pass_start + max_pass_len - 1, final_delay);
+
+ return 0;
+}
+#endif /* MMC_SUPPORTS_TUNING */
+
+#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
+static int spacemit_sdhci_phy_dll_init(struct sdhci_host *host)
+{
+ u32 reg;
+ int i;
+
+ /* Configure DLL predly, fulldly, and vreg */
+ spacemit_sdhci_clrsetbits(host, SDHC_DLL_PREDLY_NUM |
+ SDHC_DLL_FULLDLY_RANGE |
+ SDHC_DLL_VREG_CTRL,
+ FIELD_PREP(SDHC_DLL_PREDLY_NUM, 1) |
+ FIELD_PREP(SDHC_DLL_FULLDLY_RANGE, 1) |
+ FIELD_PREP(SDHC_DLL_VREG_CTRL, 1),
+ SPACEMIT_SDHC_PHY_DLLCFG);
+
+ reg = sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLCFG1);
+ reg |= FIELD_PREP(SDHC_DLL_REG1_CTRL, 0x92);
+ sdhci_writel(host, reg, SPACEMIT_SDHC_PHY_DLLCFG1);
+
+ /* Enable DLL */
+ reg = sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLCFG);
+ reg |= SDHC_DLL_ENABLE;
+ sdhci_writel(host, reg, SPACEMIT_SDHC_PHY_DLLCFG);
+
+ /* Wait for DLL lock */
+ i = 0;
+ while (i++ < 100) {
+ if (sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLSTS) & SDHC_DLL_LOCK_STATE)
+ break;
+ udelay(10);
+ }
+ if (i == 100) {
+ log_err("%s: phy dll lock timeout\n", host->name);
+ return -ETIMEDOUT;
+ }
+
+ return 0;
+}
+
+static int spacemit_sdhci_hs400_enhanced_strobe(struct sdhci_host *host)
+{
+ u32 reg;
+
+ reg = sdhci_readl(host, SPACEMIT_SDHC_MMC_CTRL_REG);
+ reg |= SDHC_ENHANCE_STROBE_EN;
+ sdhci_writel(host, reg, SPACEMIT_SDHC_MMC_CTRL_REG);
+
+ return spacemit_sdhci_phy_dll_init(host);
+}
+#endif
+
+const struct sdhci_ops spacemit_sdhci_ops = {
+ .set_control_reg = spacemit_sdhci_set_control_reg,
+#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
+ .platform_execute_tuning = spacemit_sdhci_execute_tuning,
+#endif
+#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
+ .set_enhanced_strobe = spacemit_sdhci_hs400_enhanced_strobe,
+#endif
+};
+
+static struct dm_mmc_ops spacemit_mmc_ops;
+
+static int spacemit_sdhci_probe(struct udevice *dev)
+{
+ struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+ struct spacemit_sdhci_priv *priv = dev_get_priv(dev);
+ struct spacemit_sdhci_plat *plat = dev_get_plat(dev);
+ struct sdhci_host *host = &priv->host;
+ struct clk clk;
+ int ret = 0;
+
+ host->mmc = &plat->mmc;
+ host->mmc->priv = host;
+ host->mmc->dev = dev;
+ upriv->mmc = host->mmc;
+
+ spacemit_mmc_ops = sdhci_ops;
+ spacemit_mmc_ops.wait_dat0 = spacemit_sdhci_wait_dat0;
+
+ ret = clk_get_bulk(dev, &plat->clks);
+ if (ret) {
+ log_err("Can't get clk: %d\n", ret);
+ return ret;
+ }
+
+ ret = clk_enable_bulk(&plat->clks);
+ if (ret) {
+ log_err("Failed to enable clk: %d\n", ret);
+ return ret;
+ }
+
+ ret = reset_get_bulk(dev, &plat->resets);
+ if (ret) {
+ log_err("Can't get reset: %d\n", ret);
+ return ret;
+ }
+
+ ret = reset_deassert_bulk(&plat->resets);
+ if (ret) {
+ log_err("Failed to reset: %d\n", ret);
+ return ret;
+ }
+
+ ret = clk_get_by_index(dev, 1, &clk);
+ if (ret) {
+ log_err("Can't get io clk: %d\n", ret);
+ return ret;
+ }
+
+ ret = clk_set_rate(&clk, plat->cfg.f_max);
+ if (ret) {
+ log_err("Failed to set io clk: %d\n", ret);
+ return ret;
+ }
+
+ /* Set quirks */
+ if (IS_ENABLED(CONFIG_SPL_BUILD))
+ host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
+ SDHCI_QUIRK_BLK_CMD23;
+ else
+ host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
+ SDHCI_QUIRK_32BIT_DMA_ADDR |
+ SDHCI_QUIRK_BLK_CMD23;
+ host->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz;
+ host->max_clk = plat->cfg.f_max;
+
+ plat->cfg.f_min = SDHC_MIN_CLOCK;
+ host->ops = &spacemit_sdhci_ops;
+
+ ret = sdhci_setup_cfg(&plat->cfg, host, plat->cfg.f_max,
+ SDHC_MIN_CLOCK);
+ if (ret)
+ return ret;
+
+ ret = sdhci_probe(dev);
+ if (ret)
+ return ret;
+
+ spacemit_sdhci_phy_init(dev, host);
+ return ret;
+}
+
+static int spacemit_sdhci_of_to_plat(struct udevice *dev)
+{
+ struct spacemit_sdhci_plat *plat = dev_get_plat(dev);
+ struct spacemit_sdhci_priv *priv = dev_get_priv(dev);
+ struct sdhci_host *host = &priv->host;
+ int ret = 0;
+
+ host->name = dev->name;
+ host->ioaddr = (void *)dev_read_addr(dev);
+
+ ret = mmc_of_parse(dev, &plat->cfg);
+
+ return ret;
+}
+
+static int spacemit_sdhci_bind(struct udevice *dev)
+{
+ struct spacemit_sdhci_plat *drv_data;
+ struct spacemit_sdhci_plat *plat = dev_get_plat(dev);
+
+ drv_data = (struct spacemit_sdhci_plat *)dev_get_driver_data(dev);
+ if (drv_data)
+ memcpy(plat, drv_data, sizeof(struct spacemit_sdhci_plat));
+ return sdhci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static const struct udevice_id spacemit_sdhci_ids[] = {
+ {
+ .compatible = "spacemit,k1-sdhci",
+ .data = 0,
+ }, {
+ }
+};
+
+U_BOOT_DRIVER(spacemit_sdhci_drv) = {
+ .name = "spacemit_sdhci",
+ .id = UCLASS_MMC,
+ .of_match = spacemit_sdhci_ids,
+ .of_to_plat = spacemit_sdhci_of_to_plat,
+ .ops = &spacemit_mmc_ops,
+ .bind = spacemit_sdhci_bind,
+ .probe = spacemit_sdhci_probe,
+ .priv_auto = sizeof(struct spacemit_sdhci_priv),
+ .plat_auto = sizeof(struct spacemit_sdhci_plat),
+};
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
` (2 preceding siblings ...)
2026-06-29 15:51 ` [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-30 2:56 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 5/8] configs: k1: enable SD and eMMC support Eric Chung
` (3 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Add the SDH0 controller node and its pinctrl groups to the u-boot
overlay. The upstream DTS only contains the eMMC node; the SD card
controller (sdhci@d4280000) and its MMC1 pinctrl configuration are
missing. Place the new node inside the storage-bus via path-based
merge so it inherits the dma-ranges from the parent bus.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
v2:
- Use vmmc-supply as vqmmc-supply on SD node.
- Add alias of mmc0 and mmc1.
---
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 87 ++++++++++++++++++++++++++++++-
arch/riscv/dts/k1-musepi-pro-u-boot.dtsi | 82 ++++++++++++++++++++++++++++-
2 files changed, 165 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi b/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
index 7f9443d6951..463952dc047 100644
--- a/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
+++ b/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
@@ -6,6 +6,11 @@
#include "binman.dtsi"
/ {
+ aliases {
+ mmc0 = &emmc;
+ mmc1 = &sdhci0;
+ };
+
memory@0 {
device_type = "memory";
reg = <0x00000000 0x00000000 0x00000000 0x80000000>;
@@ -76,12 +81,14 @@
bootph-pre-ram;
};
- buck3 {
+ buck3_1v8: buck3 {
regulator-name = "vdd_1v8";
bootph-pre-ram;
};
- aldo1 {
+ buck4_3v3: buck4 { };
+
+ aldo1: aldo1 {
regulator-name = "vdd_1v8_mmc";
bootph-pre-ram;
};
@@ -89,6 +96,82 @@
};
};
+/ {
+ soc {
+ storage-bus {
+ sdhci0: mmc@d4280000 {
+ bootph-pre-ram;
+ compatible = "spacemit,k1-sdhci";
+ reg = <0x0 0xd4280000 0x0 0x200>;
+ clocks = <&syscon_apmu CLK_SDH_AXI>,
+ <&syscon_apmu CLK_SDH0>;
+ clock-names = "core", "io";
+ interrupts = <99>;
+ resets = <&syscon_apmu RESET_SDH_AXI>,
+ <&syscon_apmu RESET_SDH0>;
+ reset-names = "sdh_axi", "sdh0";
+ bus-width = <4>;
+ max-frequency = <204800000>;
+ cd-gpios = <&gpio K1_GPIO(80) GPIO_ACTIVE_LOW>;
+ pinctrl-names = "default", "fast";
+ pinctrl-0 = <&sdhci0_0_cfg>;
+ pinctrl-1 = <&sdhci0_1_cfg>;
+ status = "okay";
+ };
+ };
+ };
+};
+
+/* SD card pinctrl groups -- not present in upstream k1-pinctrl.dtsi */
+&pinctrl {
+ sdhci0_0_cfg: sdhci0-0-cfg {
+ grp_cmd_data {
+ pinmux = <K1_PADCONF(104, 0)>, /* MMC1_DAT3 */
+ <K1_PADCONF(105, 0)>, /* MMC1_DAT2 */
+ <K1_PADCONF(106, 0)>, /* MMC1_DAT1 */
+ <K1_PADCONF(107, 0)>, /* MMC1_DAT0 */
+ <K1_PADCONF(108, 0)>; /* MMC1_CMD */
+ bias-pull-up = <1>;
+ drive-strength = <19>;
+ };
+ grp_clk {
+ pinmux = <K1_PADCONF(109, 0)>; /* MMC1_CLK */
+ bias-pull-down = <1>;
+ drive-strength = <19>;
+ };
+ };
+
+ sdhci0_1_cfg: sdhci0-1-cfg { /* fast */
+ grp_cmd_data {
+ pinmux = <K1_PADCONF(104, 0)>, /* MMC1_DAT3 */
+ <K1_PADCONF(105, 0)>, /* MMC1_DAT2 */
+ <K1_PADCONF(106, 0)>, /* MMC1_DAT1 */
+ <K1_PADCONF(107, 0)>, /* MMC1_DAT0 */
+ <K1_PADCONF(108, 0)>; /* MMC1_CMD */
+ bias-pull-up = <1>;
+ drive-strength = <42>;
+ };
+ grp_clk {
+ pinmux = <K1_PADCONF(109, 0)>; /* MMC1_CLK */
+ bias-pull-down = <1>;
+ drive-strength = <42>;
+ };
+ };
+};
+
+&emmc {
+ bootph-pre-ram;
+ resets = <&syscon_apmu RESET_SDH_AXI>, <&syscon_apmu RESET_SDH2>;
+ reset-names = "sdh_axi", "sdh2";
+ vqmmc-supply = <&buck3_1v8>;
+ vmmc-supply = <&aldo1>;
+ max-frequency = <204800000>;
+};
+
+&sdhci0 {
+ vmmc-supply = <&buck4_3v3>;
+};
+
&binman {
u-boot-spl-ddr {
type = "section";
diff --git a/arch/riscv/dts/k1-musepi-pro-u-boot.dtsi b/arch/riscv/dts/k1-musepi-pro-u-boot.dtsi
index 8a9a2a09de9..24cd8621e08 100644
--- a/arch/riscv/dts/k1-musepi-pro-u-boot.dtsi
+++ b/arch/riscv/dts/k1-musepi-pro-u-boot.dtsi
@@ -10,6 +10,8 @@
aliases {
console = &uart0;
serial0 = &uart0;
+ mmc0 = &emmc;
+ mmc1 = &sdhci0;
};
chosen {
@@ -147,7 +149,7 @@
regulator-always-on;
};
- buck4 {
+ buck4_3v3: buck4 {
regulator-min-microvolt = <500000>;
regulator-max-microvolt = <3300000>;
regulator-ramp-delay = <5000>;
@@ -168,7 +170,7 @@
regulator-always-on;
};
- aldo1 {
+ aldo1: aldo1 {
bootph-pre-ram;
regulator-name = "vdd_1v8_mmc";
regulator-min-microvolt = <500000>;
@@ -249,6 +251,82 @@
};
};
+/ {
+ soc {
+ storage-bus {
+ sdhci0: mmc@d4280000 {
+ bootph-pre-ram;
+ compatible = "spacemit,k1-sdhci";
+ reg = <0x0 0xd4280000 0x0 0x200>;
+ clocks = <&syscon_apmu CLK_SDH_AXI>,
+ <&syscon_apmu CLK_SDH0>;
+ clock-names = "core", "io";
+ interrupts = <99>;
+ resets = <&syscon_apmu RESET_SDH_AXI>,
+ <&syscon_apmu RESET_SDH0>;
+ reset-names = "sdh_axi", "sdh0";
+ bus-width = <4>;
+ max-frequency = <204800000>;
+ cd-gpios = <&gpio K1_GPIO(80) GPIO_ACTIVE_LOW>;
+ pinctrl-names = "default", "fast";
+ pinctrl-0 = <&sdhci0_0_cfg>;
+ pinctrl-1 = <&sdhci0_1_cfg>;
+ status = "okay";
+ };
+ };
+ };
+};
+
+/* SD card pinctrl groups -- not present in upstream k1-pinctrl.dtsi */
+&pinctrl {
+ sdhci0_0_cfg: sdhci0-0-cfg {
+ grp_cmd_data {
+ pinmux = <K1_PADCONF(104, 0)>, /* MMC1_DAT3 */
+ <K1_PADCONF(105, 0)>, /* MMC1_DAT2 */
+ <K1_PADCONF(106, 0)>, /* MMC1_DAT1 */
+ <K1_PADCONF(107, 0)>, /* MMC1_DAT0 */
+ <K1_PADCONF(108, 0)>; /* MMC1_CMD */
+ bias-pull-up = <1>;
+ drive-strength = <19>;
+ };
+ grp_clk {
+ pinmux = <K1_PADCONF(109, 0)>; /* MMC1_CLK */
+ bias-pull-down = <1>;
+ drive-strength = <19>;
+ };
+ };
+
+ sdhci0_1_cfg: sdhci0-1-cfg { /* fast */
+ grp_cmd_data {
+ pinmux = <K1_PADCONF(104, 0)>, /* MMC1_DAT3 */
+ <K1_PADCONF(105, 0)>, /* MMC1_DAT2 */
+ <K1_PADCONF(106, 0)>, /* MMC1_DAT1 */
+ <K1_PADCONF(107, 0)>, /* MMC1_DAT0 */
+ <K1_PADCONF(108, 0)>; /* MMC1_CMD */
+ bias-pull-up = <1>;
+ drive-strength = <42>;
+ };
+ grp_clk {
+ pinmux = <K1_PADCONF(109, 0)>; /* MMC1_CLK */
+ bias-pull-down = <1>;
+ drive-strength = <42>;
+ };
+ };
+};
+
+&emmc {
+ bootph-pre-ram;
+ resets = <&syscon_apmu RESET_SDH_AXI>, <&syscon_apmu RESET_SDH2>;
+ reset-names = "sdh_axi", "sdh2";
+ vqmmc-supply = <&buck3_1v8>;
+ vmmc-supply = <&aldo1>;
+ max-frequency = <204800000>;
+};
+
+&sdhci0 {
+ vmmc-supply = <&buck4_3v3>;
+};
+
&binman {
u-boot-spl-ddr {
type = "section";
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 5/8] configs: k1: enable SD and eMMC support
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
` (3 preceding siblings ...)
2026-06-29 15:51 ` [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 6/8] doc: spacemit: flash on K1 SoC based boards Eric Chung
` (2 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Enable high-speed MMC modes.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
v2:
- Enable ADMA support.
- Enable SYSCON support.
---
board/spacemit/k1/MAINTAINERS | 1 +
configs/spacemit_k1_defconfig | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/board/spacemit/k1/MAINTAINERS b/board/spacemit/k1/MAINTAINERS
index 32d47ecc8f1..ca994e2a1fb 100644
--- a/board/spacemit/k1/MAINTAINERS
+++ b/board/spacemit/k1/MAINTAINERS
@@ -9,6 +9,7 @@ F: configs/spacemit_k1_defconfig
F: doc/board/spacemit/bananapi-f3.rst
F: drivers/gpio/spacemit_gpio.c
F: drivers/i2c/k1_i2c.c
+F: drivers/mmc/spacemit_sdhci.c
F: drivers/pinctrl/spacemit/
F: drivers/power/pmic/pmic_spacemit_p1.c
F: drivers/power/regulator/spacemit_p1_regulator.c
diff --git a/configs/spacemit_k1_defconfig b/configs/spacemit_k1_defconfig
index 81409c844a6..886679367a9 100644
--- a/configs/spacemit_k1_defconfig
+++ b/configs/spacemit_k1_defconfig
@@ -23,6 +23,7 @@ CONFIG_DEBUG_UART_BASE=0xd4017000
CONFIG_DEBUG_UART_CLOCK=14700000
CONFIG_TARGET_SPACEMIT_K1=y
CONFIG_ARCH_RV64I=y
+CONFIG_RISCV_ISA_ZICBOM=y
CONFIG_RISCV_SMODE=y
CONFIG_SPL_RISCV_MMODE=y
# CONFIG_SPL_SMP is not set
@@ -48,6 +49,7 @@ CONFIG_SPL_CMD_TLV_EEPROM=y
CONFIG_OF_UPSTREAM=y
CONFIG_ENV_OVERWRITE=y
CONFIG_SPL_REGMAP=y
+CONFIG_SYSCON=y
CONFIG_SPL_SYSCON=y
CONFIG_CLK=y
CONFIG_CLK_CCF=y
@@ -87,6 +89,21 @@ CONFIG_SPI_FLASH_WINBOND=y
CONFIG_SPI_MEM=y
CONFIG_SYS_SPI_U_BOOT_OFFS=0x000a0000
CONFIG_CMD_SPI=y
+CONFIG_MMC=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_ADMA=y
+CONFIG_MMC_SDHCI_SPACEMIT=y
+CONFIG_MMC_IO_VOLTAGE=y
+CONFIG_MMC_HS200_SUPPORT=y
+CONFIG_MMC_HS400_SUPPORT=y
+CONFIG_MMC_HS400_ES_SUPPORT=y
+CONFIG_SUPPORT_EMMC_BOOT=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=0x4
+CONFIG_CMD_MMC=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_MEMINFO_MAP=y
+CONFIG_EFI_PARTITION=y
CONFIG_SPL_SPI=y
CONFIG_SPL_DM_SPI=y
CONFIG_SPL_DM_SPI_FLASH=y
@@ -94,3 +111,5 @@ CONFIG_SPL_SPI_LOAD=y
CONFIG_SPL_SPI_FLASH_TINY=y
CONFIG_SPL_SPI_FLASH_SUPPORT=y
CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_MMC=y
+CONFIG_SPL_SYS_MMCSD_RAW_MODE=y
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 6/8] doc: spacemit: flash on K1 SoC based boards
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
` (4 preceding siblings ...)
2026-06-29 15:51 ` [PATCH v2 v2 5/8] configs: k1: enable SD and eMMC support Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 7/8] config: k1: enable ENV support for eMMC Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable Eric Chung
7 siblings, 0 replies; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Add document on how to flash images into eMMC of K1 SoC based boards.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
board/spacemit/k1/MAINTAINERS | 2 +-
doc/board/spacemit/index.rst | 1 +
doc/board/spacemit/k1-flash.rst | 157 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 159 insertions(+), 1 deletion(-)
diff --git a/board/spacemit/k1/MAINTAINERS b/board/spacemit/k1/MAINTAINERS
index ca994e2a1fb..7a34476ea7c 100644
--- a/board/spacemit/k1/MAINTAINERS
+++ b/board/spacemit/k1/MAINTAINERS
@@ -6,7 +6,7 @@ S: Maintained
F: arch/riscv/dts/k1-*-u-boot.dtsi
F: board/spacemit/k1/
F: configs/spacemit_k1_defconfig
-F: doc/board/spacemit/bananapi-f3.rst
+F: doc/board/spacemit/
F: drivers/gpio/spacemit_gpio.c
F: drivers/i2c/k1_i2c.c
F: drivers/mmc/spacemit_sdhci.c
diff --git a/doc/board/spacemit/index.rst b/doc/board/spacemit/index.rst
index a5e35ee12ab..186c9b13602 100644
--- a/doc/board/spacemit/index.rst
+++ b/doc/board/spacemit/index.rst
@@ -6,5 +6,6 @@ SpacemiT
:maxdepth: 1
bananapi-f3
+ k1-flash
k1-spl
diff --git a/doc/board/spacemit/k1-flash.rst b/doc/board/spacemit/k1-flash.rst
new file mode 100644
index 00000000000..c33625772b6
--- /dev/null
+++ b/doc/board/spacemit/k1-flash.rst
@@ -0,0 +1,157 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+SpacemiT K1 U-Boot Flash Guide
+==============================
+
+This guide explains how to flash U-Boot on SpacemiT K1 based boards. It covers
+flashing images via USB fastboot.
+
+Tested boards: Banana Pi BPI-F3, MusePi Pro.
+
+.. note::
+
+ This procedure flashes images to eMMC over USB fastboot. The fastboot
+ function is not enabled in our SPL yet, so the download stage runs the
+ SpacemiT released SPL; our built FSBL.bin and fit.itb are the images
+ written to eMMC and used on the next normal boot.
+
+Prerequisites
+~~~~~~~~~~~~~
+
+- A SpacemiT K1 board with USB Type-C and UART access
+- USB-to-UART adapter (3.3V TTL)
+- ``minicom`` or equivalent serial terminal, configured at 115200 8N1
+- ``fastboot`` and ``flashserver`` tool on the host
+
+Hardware Setup
+~~~~~~~~~~~~~~
+
+Refer to k1-spl.rst.
+
+Flash images on eMMC
+~~~~~~~~~~~~~~~~~~~~
+
+**1. Obtain the release images**
+
+Get the release package from Spacemit website. It contains SPL image, and so on.
+
+https://archive.spacemit.com/image/k1/version/bianbu/v2.3.3/Bianbu-Minimal-K1-V2.3.3-20260128183217.zip
+
+Unzip images and store them into a directory.
+
+**2. Obtain flashserver tool**
+
+Get ``flashserver`` from Spacemit website.
+
+.. code-block:: bash
+
+ $wget https://cdn-resource.spacemit.com/file/flash/flashserver
+ $chmod +x flashserver
+ $mv flashserver {flash image path}/
+
+**3. Copy built SPL and U-Boot images**
+
+Build U-Boot as mentioned in k1-spl.rst. Create a new directory to save.
+The official u-boot.itb is used to download images. So the built U-Boot should
+not replace the official one.
+
+.. code-block:: bash
+
+ $mkdir {flash image path}/build
+ $cd {flash image path}
+ $ln -sf {path to FSBL.bin} ./build/
+ $ln -sf {path to u-boot.itb} ./build/fit.itb
+
+``{path to FSBL.bin}`` is the signed FSBL produced by ``fsbl.sh`` in
+k1-spl.rst, e.g. ``~/uboot-2022.10/spl_bin/FSBL.bin``.
+``{path to u-boot.itb}`` is the U-Boot build output, e.g.
+``~/u-boot/u-boot.itb``.
+
+**4. Update configuration files**
+
+The ``partition_2M.json`` and ``partition_universal.json`` files come from
+the release package. Patch the ``fsbl`` and ``uboot`` entries to point at
+the images staged under ``build/`` (pick the layout that matches your eMMC):
+
+.. code-block:: diff
+
+ diff -puNr bianbu-25/partition_2M.json clean/partition_2M.json
+ --- bianbu-25/partition_2M.json 2026-03-02 11:55:58.631116807 +0800
+ +++ clean/partition_2M.json 2026-05-20 11:25:21.683801401 +0800
+ @@ -13,7 +13,7 @@
+ "name": "fsbl",
+ "offset": "128K",
+ "size": "256K",
+ - "image": "factory/FSBL.bin"
+ + "image": "build/FSBL.bin"
+ },
+ {
+ "name": "env",
+ @@ -31,7 +31,7 @@
+ "name": "uboot",
+ "offset": "640K",
+ "size": "-",
+ - "image": "u-boot.itb"
+ + "image": "build/fit.itb"
+ }
+ ]
+ }
+ diff -puNr bianbu-25/partition_universal.json clean/partition_universal.json
+ --- bianbu-25/partition_universal.json 2026-03-02 11:55:58.642116862 +0800
+ +++ clean/partition_universal.json 2026-05-20 11:26:23.932581853 +0800
+ @@ -14,7 +14,7 @@
+ "name": "fsbl",
+ "offset": "128K",
+ "size": "256K",
+ - "image": "factory/FSBL.bin"
+ + "image": "build/FSBL.bin"
+ },
+ {
+ "name": "env",
+ @@ -32,7 +32,7 @@
+ "name": "uboot",
+ "offset": "2M",
+ "size": "2M",
+ - "image": "u-boot.itb"
+ + "image": "build/fit.itb"
+ },
+ {
+ "name": "bootfs",
+
+Deploying via USB Fastboot
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+To enter BootROM fastboot mode:
+
+1. Power off the board by unplugging its power supply.
+2. **Press and hold** the FDL button (called "Boot Key" on some boards;
+ see the board layout above for the BPI-F3).
+3. While holding the button, use a USB cable to connect the OTG port to
+ your host. This cable is also used by fastboot to upload the firmware.
+4. Release the button.
+
+On the host, ``fastboot devices`` should list the board::
+
+ dfu-device DFU download
+
+The serial console shows the BootROM's USB download handler trace,
+including a line like::
+
+ usb2d_initialize : enter
+
+This indicates the board is ready to accept an image via USB.
+
+.. tip::
+
+ If you are worried about insufficient USB power, you can first plug
+ in the power, then release the button, and then plug in the USB
+ cable.
+
+On the host:
+
+.. code-block:: console
+
+ $sudo ./flashserver
+
+When ``flashserver`` is running, it lists the detected fastboot devices.
+Enter the corresponding number to select one.
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 7/8] config: k1: enable ENV support for eMMC
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
` (5 preceding siblings ...)
2026-06-29 15:51 ` [PATCH v2 v2 6/8] doc: spacemit: flash on K1 SoC based boards Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable Eric Chung
7 siblings, 0 replies; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Enable environment variable support on the eMMC storage device for
both SPL and U-Boot stages.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
configs/spacemit_k1_defconfig | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/configs/spacemit_k1_defconfig b/configs/spacemit_k1_defconfig
index 886679367a9..1c92c4082a7 100644
--- a/configs/spacemit_k1_defconfig
+++ b/configs/spacemit_k1_defconfig
@@ -14,7 +14,7 @@ CONFIG_SPL_BSS_MAX_SIZE=0x400
CONFIG_SPL_STACK_R=y
CONFIG_SPL_STACK_R_ADDR=0xc00000
CONFIG_SPL_SYS_MALLOC_SIMPLE=y
-CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x100000
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x400000
CONFIG_SYS_BOOTM_LEN=0xa000000
CONFIG_SYS_LOAD_ADDR=0x200000
CONFIG_SPL_SIZE_LIMIT=0x31000
@@ -48,6 +48,10 @@ CONFIG_CMD_TLV_EEPROM=y
CONFIG_SPL_CMD_TLV_EEPROM=y
CONFIG_OF_UPSTREAM=y
CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_SIZE=0x4000
+CONFIG_ENV_OFFSET=0x60000
+CONFIG_ENV_SECT_SIZE=0x10000
+CONFIG_ENV_IS_IN_MMC=y
CONFIG_SPL_REGMAP=y
CONFIG_SYSCON=y
CONFIG_SPL_SYSCON=y
@@ -111,5 +115,6 @@ CONFIG_SPL_SPI_LOAD=y
CONFIG_SPL_SPI_FLASH_TINY=y
CONFIG_SPL_SPI_FLASH_SUPPORT=y
CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_ENV_SUPPORT=y
CONFIG_SPL_MMC=y
CONFIG_SPL_SYS_MMCSD_RAW_MODE=y
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
` (6 preceding siblings ...)
2026-06-29 15:51 ` [PATCH v2 v2 7/8] config: k1: enable ENV support for eMMC Eric Chung
@ 2026-06-29 15:51 ` Eric Chung
2026-06-30 2:55 ` Peng Fan
7 siblings, 1 reply; 14+ messages in thread
From: Eric Chung @ 2026-06-29 15:51 UTC (permalink / raw)
To: u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu,
Eric Chung
Read the product name from the environment instead of EEPROM,
as the EEPROM may not be programmed and the environment always
contains this information.
Signed-off-by: Eric Chung <eric.chung@riscstar.com>
---
board/spacemit/k1/spl.c | 50 ++++++++++---------------------------------------
1 file changed, 10 insertions(+), 40 deletions(-)
diff --git a/board/spacemit/k1/spl.c b/board/spacemit/k1/spl.c
index 0db362130e4..4f8b2f1035d 100644
--- a/board/spacemit/k1/spl.c
+++ b/board/spacemit/k1/spl.c
@@ -12,6 +12,7 @@
#include <configs/k1.h>
#include <dm/device.h>
#include <dm/uclass.h>
+#include <env.h>
#include <i2c.h>
#include <linux/delay.h>
#include <log.h>
@@ -73,39 +74,6 @@ static void i2c_early_init(void)
}
}
-int read_product_name(char *name, int size)
-{
- u8 eeprom_data[TLV_TOTAL_LEN_MAX], *p;
- struct tlvinfo_header *tlv_hdr;
- struct tlvinfo_tlv *tlv_entry;
- int ret, i = 0;
- u32 entry_size;
-
- if (!name || size <= 0)
- return -EINVAL;
- ret = read_tlvinfo_tlv_eeprom(eeprom_data, &tlv_hdr,
- &tlv_entry, i);
- if (ret)
- return ret;
- p = (u8 *)tlv_entry;
- for (i = 0; i < tlv_hdr->totallen; ) {
- if (tlv_entry->type == TLV_CODE_PRODUCT_NAME) {
- if (tlv_entry->length < size)
- size = tlv_entry->length;
- memset(name, 0, size);
- memcpy(name, &tlv_entry->value[0], size);
- return 0;
- }
- if (tlv_entry->type == TLV_CODE_CRC_32)
- return -ENOENT;
- entry_size = tlv_entry->length + sizeof(struct tlvinfo_tlv);
- i += entry_size;
- p += entry_size;
- tlv_entry = (struct tlvinfo_tlv *)p;
- }
- return -ENOENT;
-}
-
static const struct {
const char *eeprom_name;
const char *fit_name;
@@ -117,9 +85,14 @@ static const struct {
static void fixup_product_name(void)
{
- char fdt_name[I2C_BUF_SIZE];
+ char fdt_name[I2C_BUF_SIZE], *name;
int i;
+ memset(product_name, 0, I2C_BUF_SIZE);
+ env_init();
+ env_load();
+ name = env_get("product_name");
+ snprintf(product_name, I2C_BUF_SIZE, "%s", name);
memset(fdt_name, 0, I2C_BUF_SIZE);
for (i = 0; i < ARRAY_SIZE(k1_board_map); i++) {
if (!strncmp(product_name, k1_board_map[i].eeprom_name,
@@ -384,13 +357,10 @@ u32 spl_boot_device(void)
void spl_board_init(void)
{
- int ret;
+}
- ret = read_product_name(product_name, I2C_BUF_SIZE);
- if (ret)
- log_info("Fail to detect board:%d\n", ret);
- else
- log_info("Get board name:%s\n", product_name);
+void spl_perform_board_fixups(struct spl_image_info *spl_image)
+{
fixup_product_name();
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers
2026-06-29 15:51 ` [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers Eric Chung
@ 2026-06-30 2:47 ` Peng Fan
0 siblings, 0 replies; 14+ messages in thread
From: Peng Fan @ 2026-06-30 2:47 UTC (permalink / raw)
To: Eric Chung
Cc: u-boot-spacemit, u-boot, Tom Rini, Peng Fan, Huan Zhou,
Raymond Mao, Jaehoon Chung, Bhimeswararao Matsa, Tanmay Kathpalia,
Kaustabh Chakraborty, Han Xu, Yanir Levin, Christoph Stoidner,
Balsundar Ponnusamy, Daniel Palmer, Anshul Dalal,
Bastien Curutchet, Angelo Dureghello, Johan Jonker, Rick Chen,
Leo, Sam Protsenko, Guodong Xu
On Mon, Jun 29, 2026 at 11:51:16PM +0800, Eric Chung wrote:
>Introduce a controller-specific quirk to select CMD23 (SET_BLOCK_COUNT)
>for read/write multi-block operations instead of the legacy CMD18/CMD25
>with open-ended or pre-defined block counts.
>
>This allows SDHCI host controllers that support CMD23 to improve I/O
>efficiency by reducing the number of CMD12 (STOP_TRANSMISSION) commands
>for multi-block transfers.
This is a misuse of the quirk mechanism.
CMD23 (SET_BLOCK_COUNT) is part of the SD/eMMC specification -
it's the standard defined-length multi-block transfer method.
Quirks exist for hardware that deviates from spec, not for enabling
spec-compliant behavior.
Regards
Peng
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver
2026-06-29 15:51 ` [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver Eric Chung
@ 2026-06-30 2:52 ` Peng Fan
0 siblings, 0 replies; 14+ messages in thread
From: Peng Fan @ 2026-06-30 2:52 UTC (permalink / raw)
To: Eric Chung
Cc: u-boot-spacemit, u-boot, Tom Rini, Peng Fan, Huan Zhou,
Raymond Mao, Jaehoon Chung, Bhimeswararao Matsa, Tanmay Kathpalia,
Kaustabh Chakraborty, Han Xu, Yanir Levin, Christoph Stoidner,
Balsundar Ponnusamy, Daniel Palmer, Anshul Dalal,
Bastien Curutchet, Angelo Dureghello, Johan Jonker, Rick Chen,
Leo, Sam Protsenko, Guodong Xu
On Mon, Jun 29, 2026 at 11:51:17PM +0800, Eric Chung wrote:
>Add SDHCI platform driver support for SpacemiT K1 SoC. This driver
>implements the necessary platform-specific operations for the SDHCI
>controller, enabling MMC/SD card functionality on K1-based platforms.
>
>Signed-off-by: Eric Chung <eric.chung@riscstar.com>
>
>---
>v2:
>- Enable ADMA mode support.
>- Use CMD23 for multi-block read/write.
>- Move ASR/AIB register into pinctrl driver.
>- Correct pinctrl state from "fast" to "uhs".
>- Migrate tuning support from the spacemit linux driver.
>---
> drivers/mmc/Kconfig | 7 +
> drivers/mmc/Makefile | 1 +
> drivers/mmc/spacemit_sdhci.c | 681 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 689 insertions(+)
>
>diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
>index 131be3106a1..f05b376ab72 100644
>--- a/drivers/mmc/Kconfig
>+++ b/drivers/mmc/Kconfig
>@@ -722,6 +722,13 @@ config MMC_SDHCI_SNPS
>
> If unsure, say N.
>
>+config MMC_SDHCI_SPACEMIT
>+ bool "Spacemit SDHCI controller"
>+ depends on MMC_SDHCI
>+ help
>+ Support for Secure Digital Host Controller Interface (SDHCI) on
>+ Spacemit K1 SoC.
>+
> config MMC_SDHCI_STI
> bool "SDHCI support for STMicroelectronics SoC"
> depends on MMC_SDHCI && OF_CONTROL && ARCH_STI
>diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
>index a23336d7d8d..aa05cec23be 100644
>--- a/drivers/mmc/Makefile
>+++ b/drivers/mmc/Makefile
>@@ -71,6 +71,7 @@ obj-$(CONFIG_MMC_SDHCI_ROCKCHIP) += rockchip_sdhci.o
> obj-$(CONFIG_MMC_SDHCI_ADI) += adi_sdhci.o
> obj-$(CONFIG_MMC_SDHCI_S5P) += s5p_sdhci.o
> obj-$(CONFIG_MMC_SDHCI_SNPS) += snps_sdhci.o
>+obj-$(CONFIG_MMC_SDHCI_SPACEMIT) += spacemit_sdhci.o
> obj-$(CONFIG_MMC_SDHCI_STI) += sti_sdhci.o
> obj-$(CONFIG_MMC_SDHCI_TANGIER) += tangier_sdhci.o
> obj-$(CONFIG_MMC_SDHCI_TEGRA) += tegra_mmc.o
>diff --git a/drivers/mmc/spacemit_sdhci.c b/drivers/mmc/spacemit_sdhci.c
>new file mode 100644
>index 00000000000..c905c33b2af
>--- /dev/null
>+++ b/drivers/mmc/spacemit_sdhci.c
>@@ -0,0 +1,681 @@
>+// SPDX-License-Identifier: GPL-2.0+
>+/*
>+ * Driver for Spacemit K1 Mobile Storage Host Controller
>+ *
>+ * Copyright (C) 2023-2026 Spacemit Inc.
>+ * Copyright (C) 2026 RISCstar Ltd.
>+ */
>+
>+#define LOG_CATEGORY UCLASS_MMC
>+
>+#include <clk.h>
>+#include <dm.h>
>+#include <fdtdec.h>
>+#include <log.h>
>+#include <malloc.h>
>+#include <sdhci.h>
>+#include <reset-uclass.h>
>+#include <mapmem.h>
>+#include <dm/pinctrl.h>
>+#include <linux/libfdt.h>
>+#include <linux/delay.h>
>+#include <power/regulator.h>
>+
>+#define FIELD_PREP(mask, val) (((val) << __ffs(mask)) & (mask))
Please use the one in bitfield.h
>+
>+
>+struct spacemit_sdhci_plat {
>+ struct mmc_config cfg;
>+ struct mmc mmc;
>+ struct reset_ctl_bulk resets;
>+ struct clk_bulk clks;
>+};
>+
>+struct spacemit_sdhci_priv {
>+ struct sdhci_host host;
>+};
>+
...
>+
>+ /* Wait for DLL lock */
>+ i = 0;
>+ while (i++ < 100) {
>+ if (sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLSTS) & SDHC_DLL_LOCK_STATE)
>+ break;
>+ udelay(10);
Please use poll timeout.
>+ }
>+ if (i == 100) {
>+ log_err("%s: phy dll lock timeout\n", host->name);
>+ return -ETIMEDOUT;
>+ }
>+}
>+
>+static const struct udevice_id spacemit_sdhci_ids[] = {
>+ {
>+ .compatible = "spacemit,k1-sdhci",
>+ .data = 0,
No need set .data as 0.
>+ }, {
>+ }
>+};
Regards
Peng
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable
2026-06-29 15:51 ` [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable Eric Chung
@ 2026-06-30 2:55 ` Peng Fan
0 siblings, 0 replies; 14+ messages in thread
From: Peng Fan @ 2026-06-30 2:55 UTC (permalink / raw)
To: Eric Chung
Cc: u-boot-spacemit, u-boot, Tom Rini, Peng Fan, Huan Zhou,
Raymond Mao, Jaehoon Chung, Bhimeswararao Matsa, Tanmay Kathpalia,
Kaustabh Chakraborty, Han Xu, Yanir Levin, Christoph Stoidner,
Balsundar Ponnusamy, Daniel Palmer, Anshul Dalal,
Bastien Curutchet, Angelo Dureghello, Johan Jonker, Rick Chen,
Leo, Sam Protsenko, Guodong Xu
On Mon, Jun 29, 2026 at 11:51:22PM +0800, Eric Chung wrote:
>Read the product name from the environment instead of EEPROM,
>as the EEPROM may not be programmed and the environment always
>contains this information.
>
>Signed-off-by: Eric Chung <eric.chung@riscstar.com>
>---
> board/spacemit/k1/spl.c | 50 ++++++++++---------------------------------------
> 1 file changed, 10 insertions(+), 40 deletions(-)
>
>diff --git a/board/spacemit/k1/spl.c b/board/spacemit/k1/spl.c
>index 0db362130e4..4f8b2f1035d 100644
>--- a/board/spacemit/k1/spl.c
>+++ b/board/spacemit/k1/spl.c
>@@ -12,6 +12,7 @@
> #include <configs/k1.h>
> #include <dm/device.h>
> #include <dm/uclass.h>
>+#include <env.h>
> #include <i2c.h>
> #include <linux/delay.h>
> #include <log.h>
>@@ -73,39 +74,6 @@ static void i2c_early_init(void)
> }
> }
>
>-int read_product_name(char *name, int size)
>-{
>- u8 eeprom_data[TLV_TOTAL_LEN_MAX], *p;
>- struct tlvinfo_header *tlv_hdr;
>- struct tlvinfo_tlv *tlv_entry;
>- int ret, i = 0;
>- u32 entry_size;
>-
>- if (!name || size <= 0)
>- return -EINVAL;
>- ret = read_tlvinfo_tlv_eeprom(eeprom_data, &tlv_hdr,
>- &tlv_entry, i);
>- if (ret)
>- return ret;
>- p = (u8 *)tlv_entry;
>- for (i = 0; i < tlv_hdr->totallen; ) {
>- if (tlv_entry->type == TLV_CODE_PRODUCT_NAME) {
>- if (tlv_entry->length < size)
>- size = tlv_entry->length;
>- memset(name, 0, size);
>- memcpy(name, &tlv_entry->value[0], size);
>- return 0;
>- }
>- if (tlv_entry->type == TLV_CODE_CRC_32)
>- return -ENOENT;
>- entry_size = tlv_entry->length + sizeof(struct tlvinfo_tlv);
>- i += entry_size;
>- p += entry_size;
>- tlv_entry = (struct tlvinfo_tlv *)p;
>- }
>- return -ENOENT;
>-}
>-
> static const struct {
> const char *eeprom_name;
> const char *fit_name;
>@@ -117,9 +85,14 @@ static const struct {
>
> static void fixup_product_name(void)
> {
>- char fdt_name[I2C_BUF_SIZE];
>+ char fdt_name[I2C_BUF_SIZE], *name;
> int i;
>
>+ memset(product_name, 0, I2C_BUF_SIZE);
>+ env_init();
>+ env_load();
>+ name = env_get("product_name");
Need a NULL pointer check.
>+ snprintf(product_name, I2C_BUF_SIZE, "%s", name);
> memset(fdt_name, 0, I2C_BUF_SIZE);
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay
2026-06-29 15:51 ` [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay Eric Chung
@ 2026-06-30 2:56 ` Peng Fan
0 siblings, 0 replies; 14+ messages in thread
From: Peng Fan @ 2026-06-30 2:56 UTC (permalink / raw)
To: Eric Chung
Cc: u-boot-spacemit, u-boot, Tom Rini, Peng Fan, Huan Zhou,
Raymond Mao, Jaehoon Chung, Bhimeswararao Matsa, Tanmay Kathpalia,
Kaustabh Chakraborty, Han Xu, Yanir Levin, Christoph Stoidner,
Balsundar Ponnusamy, Daniel Palmer, Anshul Dalal,
Bastien Curutchet, Angelo Dureghello, Johan Jonker, Rick Chen,
Leo, Sam Protsenko, Guodong Xu
On Mon, Jun 29, 2026 at 11:51:18PM +0800, Eric Chung wrote:
>Add the SDH0 controller node and its pinctrl groups to the u-boot
>overlay. The upstream DTS only contains the eMMC node; the SD card
>controller (sdhci@d4280000) and its MMC1 pinctrl configuration are
>missing. Place the new node inside the storage-bus via path-based
>merge so it inherits the dma-ranges from the parent bus.
>
>Signed-off-by: Eric Chung <eric.chung@riscstar.com>
>
>---
>v2:
>- Use vmmc-supply as vqmmc-supply on SD node.
>- Add alias of mmc0 and mmc1.
>---
> arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 87 ++++++++++++++++++++++++++++++-
> arch/riscv/dts/k1-musepi-pro-u-boot.dtsi | 82 ++++++++++++++++++++++++++++-
> 2 files changed, 165 insertions(+), 4 deletions(-)
>
>diff --git a/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi b/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
>index 7f9443d6951..463952dc047 100644
>--- a/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
>+++ b/arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi
>@@ -6,6 +6,11 @@
> #include "binman.dtsi"
>
> / {
>+ aliases {
>+ mmc0 = &emmc;
>+ mmc1 = &sdhci0;
>+ };
>+
> memory@0 {
> device_type = "memory";
> reg = <0x00000000 0x00000000 0x00000000 0x80000000>;
>@@ -76,12 +81,14 @@
> bootph-pre-ram;
> };
>
>- buck3 {
>+ buck3_1v8: buck3 {
> regulator-name = "vdd_1v8";
> bootph-pre-ram;
> };
>
>- aldo1 {
>+ buck4_3v3: buck4 { };
>+
>+ aldo1: aldo1 {
> regulator-name = "vdd_1v8_mmc";
> bootph-pre-ram;
> };
>@@ -89,6 +96,82 @@
> };
> };
>
>+/ {
>+ soc {
>+ storage-bus {
>+ sdhci0: mmc@d4280000 {
>+ bootph-pre-ram;
>+ compatible = "spacemit,k1-sdhci";
>+ reg = <0x0 0xd4280000 0x0 0x200>;
>+ clocks = <&syscon_apmu CLK_SDH_AXI>,
>+ <&syscon_apmu CLK_SDH0>;
>+ clock-names = "core", "io";
>+ interrupts = <99>;
>+ resets = <&syscon_apmu RESET_SDH_AXI>,
>+ <&syscon_apmu RESET_SDH0>;
>+ reset-names = "sdh_axi", "sdh0";
>+ bus-width = <4>;
>+ max-frequency = <204800000>;
>+ cd-gpios = <&gpio K1_GPIO(80) GPIO_ACTIVE_LOW>;
>+ pinctrl-names = "default", "fast";
Still fast, while your driver and changelog says uhs.
>+ pinctrl-0 = <&sdhci0_0_cfg>;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support
2026-06-29 15:51 ` [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support Eric Chung
@ 2026-06-30 8:55 ` Yao Zi
0 siblings, 0 replies; 14+ messages in thread
From: Yao Zi @ 2026-06-30 8:55 UTC (permalink / raw)
To: Eric Chung, u-boot-spacemit, u-boot
Cc: Tom Rini, Peng Fan, Huan Zhou, Raymond Mao, Jaehoon Chung,
Bhimeswararao Matsa, Tanmay Kathpalia, Kaustabh Chakraborty,
Han Xu, Yanir Levin, Christoph Stoidner, Balsundar Ponnusamy,
Daniel Palmer, Anshul Dalal, Bastien Curutchet, Angelo Dureghello,
Johan Jonker, Rick Chen, Leo, Sam Protsenko, Guodong Xu, Yao Zi
On Mon, Jun 29, 2026 at 11:51:15PM +0800, Eric Chung wrote:
> Dual-voltage GPIO banks default to 3.3V, but when externally supplied
> with 1.8V the internal logic must be explicitly reconfigured to match.
>
> Add the ability to program IO power domain control registers through the
> APBC block. These registers require unlocking the AIB Secure Access
> Register (ASAR) before every read/write, since configuring a 1.8V domain
> while 3.3V is externally supplied can cause back-powering and pin damage.
>
> Signed-off-by: Eric Chung <eric.chung@riscstar.com>
> ---
> drivers/pinctrl/spacemit/pinctrl-k1.c | 84 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 82 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/spacemit/pinctrl-k1.c b/drivers/pinctrl/spacemit/pinctrl-k1.c
> index 3ebc397213b..5d3236aac94 100644
> --- a/drivers/pinctrl/spacemit/pinctrl-k1.c
> +++ b/drivers/pinctrl/spacemit/pinctrl-k1.c
...
> @@ -34,8 +36,24 @@
> #define PAD_PULLUP BIT(14)
> #define PAD_PULL_EN BIT(15)
>
> -#define PIN_POWER_STATE_1V8 1800
> -#define PIN_POWER_STATE_3V3 3300
> +#define IO_PWR_DOMAIN_OFFSET 0x800
> +
> +#define IO_PWR_DOMAIN_GPIO2_Kx 0x0c
> +#define IO_PWR_DOMAIN_MMC_Kx 0x1c
> +
> +#define IO_PWR_DOMAIN_GPIO3_K1 0x10
> +#define IO_PWR_DOMAIN_QSPI_K1 0x20
Why these four offsets aren't sorted?
> +#define IO_PWR_DOMAIN_V18EN BIT(2)
> +
> +#define APBC_ASFAR 0x50
> +#define APBC_ASSAR 0x54
> +
> +#define APBC_ASFAR_AKEY 0xbaba
> +#define APBC_ASSAR_AKEY 0xeb10
> +
> +#define PIN_POWER_STATE_1V8 1800
> +#define PIN_POWER_STATE_3V3 3300
>
> enum spacemit_pin_io_type {
> IO_TYPE_NONE = 0,
...
> @@ -485,6 +559,11 @@ static int spacemit_pinctrl_probe(struct udevice *dev)
> dev_err(dev, "Fail to allocate memory\n");
> return -ENOMEM;
> }
> + priv->regmap = syscon_regmap_lookup_by_phandle(dev, "spacemit,apbc");
So with this patch, the driver depends on syscon symbols, and you should
reflect this in Kconfig.
Regards,
Yao Zi
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-06-30 8:55 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 15:51 [PATCH v2 0/8] spacemit mmc driver Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 1/8] pinctrl: k1: add IO power domain configuration support Eric Chung
2026-06-30 8:55 ` Yao Zi
2026-06-29 15:51 ` [PATCH v2 v2 2/8] mmc: sdhci: add quirk to enable CMD23 for multi-block transfers Eric Chung
2026-06-30 2:47 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 3/8] mmc: k1: add sdhci platform driver Eric Chung
2026-06-30 2:52 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 4/8] dts: k1: add SD card support in u-boot overlay Eric Chung
2026-06-30 2:56 ` Peng Fan
2026-06-29 15:51 ` [PATCH v2 v2 5/8] configs: k1: enable SD and eMMC support Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 6/8] doc: spacemit: flash on K1 SoC based boards Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 7/8] config: k1: enable ENV support for eMMC Eric Chung
2026-06-29 15:51 ` [PATCH v2 v2 8/8] spacemit: k1: load product name from environment variable Eric Chung
2026-06-30 2:55 ` Peng Fan
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.