Skip to contentSkip to conversation

spacemit mmc driver

PATCH Applied Eric Chung 4 participants 18 messages Sep 12 – Oct 6

Subsystems (3)
lore
Share & tools
lore

Eric Chung

author
#0 lore raw

v13 cover spacemit mmc driver

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.

---
Changes in v13:
- mmc: Sync the definition values from upstream mmc driver.
- doc: Only flash the minimised partitions for SD boot.
- Link to v12: https://patch.msgid.link/[email protected]

Changes in v12:
- dts: Drop all upstreamed DTS patches since they're merged now.
- Link to v11: https://patch.msgid.link/[email protected]

Changes in v11:
- spl: Fix the read_boot_mode() that returns both boot mode and boot device.
- Link to v10: https://patch.msgid.link/[email protected]

Changes in v10:
- pinctrl: Move all pinctrl patches into a new patch set.
- Link to v9: https://patch.msgid.link/[email protected]

Changes in v9:
- spl: Enhance detection on booting from SD.
- dts: Synched upstream DTS files for K1.
- doc: Create SD card image from scratch.
- mmc: Avoid to use CMD18 on SD card in SPL.
- pinctrl: Drop "fix drive strength configuration".
- Link to v8: https://patch.msgid.link/[email protected]

Changes in v8:
- doc: Remove SD card.
- Link to v7: https://patch.msgid.link/[email protected]

Changes in v7:
- env: Drop env support on the mmc series.
- dts: Sync upstream DTS files for spacemit.
- pinctrl: Simply clrsetbits_le32() on pull-up/pull-down configuration.
- spl: Fix DTB matching.
- Link to v6: https://patch.msgid.link/[email protected]

Changes in v6:
- pinctrl: Fix drive strength configuration.
- pinctrl: Fix pull-up/pull-down configuration.
- pinctrl: Use dev_read_phandle_with_args() to fetch "spacemit,syscon" instead.
- spacemit: rebase on latest upstream branch.
- Link to v5: https://patch.msgid.link/[email protected]

Changes in v5:
- mmc: Split CMD23 support out.
- mmc: Use read_poll_timeout().
- mmc: Set pinctrl state based on selected timing mode.
- mmc: Remove the condition based on quirks.
- pinctrl: Fix power source argument.
- dts: Add missing power source on mmc pins.
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- mmc: Add CMD23 for write.
- mmc: Fix CMD23 only for CMD18.
- mmc: Update bulk release operations on reset and clocks for spacemit platform driver.
- MAINTAINER: update the maintainer of Spacemit K1.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- pinctrl: Fix "fast" by "uhs".
- pinctrl: Add syscon dependency.
- mmc: Fix quick by capability.
- doc: Add SD boot support.
- Link to v2: https://lore.kernel.org/u-boot/[email protected]/T/#m2aba875a2696a7bb9b704618d22ae2fd7f7f5acc

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/[email protected]/

To: [email protected]
To: [email protected]
To: Yao Zi <[email protected]>
Cc: Huan Zhou <[email protected]>
Cc: Eric Chung <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Jaehoon Chung <[email protected]>
Cc: Bastien Curutchet <[email protected]>
Cc: Anshul Dalal <[email protected]>
Cc: Siu Ming Tong <[email protected]>
Cc: Johan Jonker <[email protected]>
Cc: Tim Ouyang <[email protected]>
Cc: Leo Liang <[email protected]>

---
Eric Chung (7):
spacemit: k1: select boot device via config registers
mmc: k1: add sdhci platform driver
dts: k1: enable mmc devices in SPL
configs: k1: enable SD and eMMC support
MAINTAINER: update Spacemit K1 entry
doc: spacemit: flash on K1 SoC based boards
spacemit: k1: fix product name detection and DTB matching in SPL

 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi |  12 +-
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  | 136 +-----
 board/spacemit/k1/MAINTAINERS             |   5 +-
 board/spacemit/k1/spl.c                   | 148 ++++++-
 configs/spacemit_k1_defconfig             |  22 +
 doc/board/spacemit/index.rst              |   1 +
 doc/board/spacemit/k1-mmc.rst             | 268 ++++++++++++
 drivers/mmc/Kconfig                       |   7 +
 drivers/mmc/Makefile                      |   1 +
 drivers/mmc/spacemit_sdhci.c              | 684 ++++++++++++++++++++++++++++++
 10 files changed, 1136 insertions(+), 148 deletions(-)

---
base-commit: ff22b8227d2531e3698ef1e2623805d0bfb20bbb
change-id: 20260629-m4-98e01659fefb

Best regards,

Signature · 1 line
Eric Chung <[email protected]>
author
#1 lore raw

PATCH v13 1/7 spacemit: k1: select boot device via config registers

Add logic to determine the current boot device by reading the SoC's configuration registers, rather than using a hardcoded default.

---
v11:
- Fix read_boot_mode() on returning both boot mode and boot device. v9:
- Enhance detection on booting from SD card.
v5:
- Add blank lines around the switch statement.
v2:
- Use FIELD_GET() to parse boot strap mode.
- Remove comments on hacking. Since the sequence between eMMC and SD device is exchanged in the upstream DTS. So it isn't a hacking any more.

---
 board/spacemit/k1/spl.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 97 insertions(+), 1 deletion(-)
board/spacemit/k1/spl.c +97 -1
index d749e21a2d57..374922573c98 100644
@@ -13,6 +13,7 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <i2c.h>
+#include <linux/bitfield.h>
 #include <linux/ctype.h>
 #include <linux/delay.h>
 #include <log.h>
@@ -22,6 +23,20 @@
 #include <tlv_eeprom.h>
 #include "tlv_codes.h"
 
+/* boot mode configs */
+#define BOOT_DEV_FLAG_REG	0xd4282d10
+#define BOOT_PIN_SEL_REG	0xd4282c20
+
+#define BOOT_STRAP_MODE_OFFSET	9
+#define BOOT_STRAP_MODE_MASK	3
+#define BOOT_STRAP_MODE_EMMC	0
+#define BOOT_STRAP_MODE_SPI	1
+#define BOOT_STRAP_MODE_NAND	2
+#define BOOT_STRAP_MODE_SD	3
+
+#define STORAGE_API_P_ADDR	0xc0838498
+#define SDCARD_API_ENTRY	0xffe0a548
+
 #define MUX_MODE4		4
 #define EDGE_NONE		BIT(6)
 #define PULL_UP			(6 << 13)       /* bit[15:13] 110 */
@@ -46,6 +61,17 @@ typedef void (*puts_func_t)(const char *s);
 typedef int (*ddr_init_func_t)(u64 ddr_base, u32 cs_num, u32 data_rate,
 			       puts_func_t puts);
 
+enum board_boot_mode {
+	BOOT_MODE_NONE = 0,
+	BOOT_MODE_USB = 0x55a,
+	BOOT_MODE_EMMC,
+	BOOT_MODE_NAND,
+	BOOT_MODE_SPI,
+	BOOT_MODE_SD,
+	BOOT_MODE_SHELL = 0x55f,
+	BOOT_MODE_BOOTSTRAP,
+};
+
 struct ddr_cfg {
 	u32     data_rate;
 	u32     cs_num;
@@ -58,6 +84,47 @@ binman_sym_declare(ulong, ddr_fw, size);
 
 char product_name[I2C_BUF_SIZE] = "k1";
 
+static u32 read_boot_mode(void)
+{
+	void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG;
+	void __iomem *boot_strap = (void __iomem *)BOOT_PIN_SEL_REG;
+	void __iomem *storage_api = (void __iomem *)STORAGE_API_P_ADDR;
+	u32 mode, sel;
+
+	mode = readl(storage_api);
+	if (mode == SDCARD_API_ENTRY)
+		return BOOT_MODE_SD;
+
+	mode = readl(boot_dev);
+	if (mode == BOOT_MODE_NONE || mode > BOOT_MODE_SD) {
+		sel = FIELD_GET(BOOT_STRAP_MODE_MASK << BOOT_STRAP_MODE_OFFSET,
+				readl(boot_strap));
+		switch (sel) {
+		case BOOT_STRAP_MODE_EMMC:
+			mode = BOOT_MODE_EMMC;
+			break;
+		case BOOT_STRAP_MODE_NAND:
+			mode = BOOT_MODE_NAND;
+			break;
+		case BOOT_STRAP_MODE_SPI:
+			mode = BOOT_MODE_SPI;
+			break;
+		case BOOT_STRAP_MODE_SD:
+		default:
+			mode = BOOT_MODE_SD;
+			break;
+		}
+	}
+	return mode;
+}
+
+static void write_boot_mode(u32 mode)
+{
+	void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG;
+
+	writel(mode, boot_dev);
+}
+
 static void i2c_early_init(void)
 {
 	struct udevice *bus;
@@ -327,8 +394,12 @@ void nor_early_init(void)
 
 void board_init_f(ulong dummy)
 {
+	u32 mode;
 	int ret;
 
+	mode = read_boot_mode();
+	write_boot_mode(mode);
+
 	ret = spl_early_init();
 	if (ret)
 		panic("spl_early_init() failed:%d\n", ret);
@@ -354,7 +425,32 @@ void board_init_f(ulong dummy)
 
 u32 spl_boot_device(void)
 {
-	return BOOT_DEVICE_SPI;
+	u32 mode;
+	int ret;
+
+	mode = read_boot_mode();
+	switch (mode) {
+	case BOOT_MODE_EMMC:
+		ret = BOOT_DEVICE_MMC1;
+		break;
+	case BOOT_MODE_NAND:
+		ret = BOOT_DEVICE_NAND;
+		break;
+	case BOOT_MODE_SPI:
+		ret = BOOT_DEVICE_SPI;
+		break;
+	case BOOT_MODE_USB:
+		ret = BOOT_DEVICE_USB;
+		break;
+	case BOOT_MODE_SD:
+		ret = BOOT_DEVICE_MMC2;
+		break;
+	default:
+		ret = BOOT_DEVICE_MMC1;
+		break;
+	}
+
+	return ret;
 }
 
 void spl_board_init(void)
Signature · 1 line
2.51.0
author
#2 lore raw

PATCH v13 2/7 mmc: k1: add sdhci platform driver

In reply to 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.

---
v13:
- Sync definition values from upstream mmc driver.
v9:
- Disable CMD18 (multiple-block read) for SD cards in SPL. v6:
- Remove ".data = 0" in spacemit_sdhci_ids[].
v5:
- Remove MMC_CAP_CMD23 as the CMD23 support is now a separate series.
- Use tabs for macro definition alignment.
- Use read_poll_timeout().
- Set pinctrl state based on selected timing mode.
- Add the definition of SDHC_DLL_REG1_HS400_VAL.
- Remove the condition based on quirks.
v4:
- Add bulk release operations on reset and clock.
v3:
- Enable CMD23 in capability.
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 | 684 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 692 insertions(+)
drivers/mmc/Kconfig +7 -0
index 4ee56465c0fe..f3443cc9bed8 100644
@@ -729,6 +729,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
drivers/mmc/Makefile +1 -0
index f4a40ee10d5b..5130b46f29c0 100644
@@ -72,6 +72,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
drivers/mmc/spacemit_sdhci.c new file +684 -0

684 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer
#3 lore raw

Re: [PATCH v13 2/7] mmc: k1: add sdhci platform driver

Hi Peng Fan, Jaehoon Chung,

Quoted 30 lines · 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.

---
v13:
- Sync definition values from upstream mmc driver.
v9:
- Disable CMD18 (multiple-block read) for SD cards in SPL. v6:
- Remove ".data = 0" in spacemit_sdhci_ids[].
v5:
- Remove MMC_CAP_CMD23 as the CMD23 support is now a separate series.
- Use tabs for macro definition alignment.
- Use read_poll_timeout().
- Set pinctrl state based on selected timing mode.
- Add the definition of SDHC_DLL_REG1_HS400_VAL.
- Remove the condition based on quirks.
v4:
- Add bulk release operations on reset and clock.
v3:
- Enable CMD23 in capability.
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.

Quoted 6 lines
---
 drivers/mmc/Kconfig          |   7 +
 drivers/mmc/Makefile         |   1 +
 drivers/mmc/spacemit_sdhci.c | 684 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 692 insertions(+)

Ping mmc maintainer for this patch, would it be Ok if I take this patch via spacemit's custodian tree [1], if yes, then I'd like to grant an Acked-by

Or, if you guys prefer to take it with mmc tree, then I could handle the rest..

Btw, FYI, I've already pushed for CI testing which looks good [2]

Thank you

Signature · 1 line
Yixun Lan (dlan)
maintainer
#4 lore raw

Re: [PATCH v13 2/7] mmc: k1: add sdhci platform driver

Hi Peng Fan, Jaehoon Chung,

Quoted 40 lines · Yixun Lan

Hi Peng Fan, Jaehoon Chung,

Quoted 30 lines · 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.

---
v13:
- Sync definition values from upstream mmc driver.
v9:
- Disable CMD18 (multiple-block read) for SD cards in SPL. v6:
- Remove ".data = 0" in spacemit_sdhci_ids[].
v5:
- Remove MMC_CAP_CMD23 as the CMD23 support is now a separate series.
- Use tabs for macro definition alignment.
- Use read_poll_timeout().
- Set pinctrl state based on selected timing mode.
- Add the definition of SDHC_DLL_REG1_HS400_VAL.
- Remove the condition based on quirks.
v4:
- Add bulk release operations on reset and clock.
v3:
- Enable CMD23 in capability.
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.

Quoted 6 lines
---
 drivers/mmc/Kconfig          |   7 +
 drivers/mmc/Makefile         |   1 +
 drivers/mmc/spacemit_sdhci.c | 684 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 692 insertions(+)
Quoted 7 lines

Ping mmc maintainer for this patch, would it be Ok if I take this patch via spacemit's custodian tree [1], if yes, then I'd like to grant an Acked-by

Or, if you guys prefer to take it with mmc tree, then I could handle the rest..

Btw, FYI, I've already pushed for CI testing which looks good [2]

Ping again, otherwise I'd go ahead and proceed via spacemit custodian tree

Quoted 5 lines

Thank you

Signature · 1 line
Yixun Lan (dlan)
author
#5 lore raw

PATCH v13 3/7 dts: k1: enable mmc devices in SPL

In reply to Eric Chung

Enable eMMC and SD device nodes in SPL stage. And set the bus frequency for mmc device nodes.

Remove the redundant device nodes that are delcared in upstream DTS files.

---
 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi |  12 ++-
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  | 136 +++---------------------------
 2 files changed, 21 insertions(+), 127 deletions(-)
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi +10 -2
index 7f9443d69510..3077cdee55d7 100644
@@ -50,7 +50,6 @@
 
 &i2c2 {
 	bootph-pre-ram;
-	resets = <&syscon_apbc RESET_TWSI2>;
 
 	eeprom@50 {
 		bootph-pre-ram;
@@ -65,7 +64,6 @@
  */
 &i2c8 {
 	bootph-pre-ram;
-	resets = <&syscon_apbc RESET_TWSI8>;
 
 	pmic@41 {
 		bootph-pre-ram;
@@ -89,6 +87,16 @@
 	};
 };
 
+&emmc {
+	bootph-pre-ram;
+	max-frequency = <204800000>;
+};
+
+&sdhci0 {
+	bootph-pre-ram;
+	max-frequency = <204800000>;
+};
+
 &binman {
 	u-boot-spl-ddr {
 		type = "section";
arch/riscv/dts/k1-musepi-pro-u-boot.dtsi +11 -125

183 lines not on this page · raw message

Signature · 1 line
2.51.0
author
#6 lore raw

PATCH v13 4/7 configs: k1: enable SD and eMMC support

In reply to Eric Chung

Enable high-speed MMC modes.

---
v7:
- Remove the change on MAINTAINERS.
- Force DM to use alias by CONFIG_DM_SEQ_ALIAS. Since the sequence of mmc devices in DTS are inverted by alias.
v5:
- Remove ADMA support since it depends on CMD23 support.
- Enable PINCONF support for related power source setting. v2:
- Enable ADMA support.
- Enable SYSCON support.

---
 configs/spacemit_k1_defconfig | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
configs/spacemit_k1_defconfig +22 -0
index 0604c2feefc1..5f9923c7f470 100644
@@ -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
@@ -61,6 +63,7 @@ CONFIG_MISC=y
 CONFIG_I2C_EEPROM=y
 CONFIG_SPL_I2C_EEPROM=y
 CONFIG_PINCTRL=y
+CONFIG_PINCONF=y
 CONFIG_PINCTRL_SPACEMIT_K1=y
 CONFIG_GPIO=y
 CONFIG_DM_GPIO=y
@@ -87,9 +90,28 @@ CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_MEM=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x000a0000
 CONFIG_CMD_SPI=y
+CONFIG_DM_SEQ_ALIAS=y
+CONFIG_MMC=y
+CONFIG_MMC_SDHCI=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
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_SPI_FLASH_TINY=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
+CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_SPL_MMC=y
+CONFIG_SPL_SYS_MMCSD_RAW_MODE=y
Signature · 1 line
2.51.0
author
#7 lore raw

PATCH v13 5/7 MAINTAINER: update Spacemit K1 entry

In reply to Eric Chung

Update the maintainer for Spacemit K1 from Guodong to Eric.

Add mmc driver to maintained files.

---
v7:
- Add mmc driver to maintained files.
v4:
- Update the maintainer.

---
 board/spacemit/k1/MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
board/spacemit/k1/MAINTAINERS +2 -1
index 32d47ecc8f1e..4b2bc4ecfc10 100644
@@ -1,6 +1,6 @@
 BananaPi F3
 M:	Huan Zhou <[email protected]>
-M:	Guodong Xu <[email protected]>
+M:	Eric Chung <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	arch/riscv/dts/k1-*-u-boot.dtsi
@@ -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
Signature · 1 line
2.51.0
author
#8 lore raw

PATCH v13 6/7 doc: spacemit: flash on K1 SoC based boards

In reply to Eric Chung

Add document on how to flash images into eMMC of K1 SoC based boards.

---
v13:
- Only flash the minimized partitions for SD boot. v9:
- Add to generate the partition table of SD card. v3:
- Add document on how to flash images into SD card.

---
 board/spacemit/k1/MAINTAINERS |   2 +-
 doc/board/spacemit/index.rst  |   1 +
 doc/board/spacemit/k1-mmc.rst | 268 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 270 insertions(+), 1 deletion(-)
board/spacemit/k1/MAINTAINERS +1 -1
index 4b2bc4ecfc10..e12288a206e0 100644
@@ -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
doc/board/spacemit/index.rst +1 -0
index a5e35ee12ab6..71854e5735bd 100644
@@ -6,5 +6,6 @@ SpacemiT
    :maxdepth: 1
 
    bananapi-f3
+   k1-mmc
    k1-spl
 
doc/board/spacemit/k1-mmc.rst new file +268 -0

268 lines not on this page · raw message

Signature · 1 line
2.51.0
author
#9 lore raw

PATCH v13 7/7 spacemit: k1: fix product name detection and DTB matching in SPL

In reply to Eric Chung

Use a table to handle DTB matching.

---
v7:
- Abandon to load product name from ENV.
v6:
- Rebased onto latest upstream. Cleaned up board_fit_config_name_match() to maintain consistentcy with v5.

---
 board/spacemit/k1/spl.c | 50 +++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)
board/spacemit/k1/spl.c +32 -18
index 374922573c98..ef23db62d6cc 100644
@@ -141,6 +141,15 @@ static void i2c_early_init(void)
 	}
 }
 
+static const struct {
+	const char *eeprom_name;
+	const char *fit_name;
+} k1_board_map[] = {
+	{ "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+	{ "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+	{ "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};
+
 int read_product_name(char *name, int size)
 {
 	u8 eeprom_data[TLV_TOTAL_LEN_MAX], *p;
@@ -174,6 +183,27 @@ int read_product_name(char *name, int size)
 	return -ENOENT;
 }
 
+static void fixup_product_name(void)
+{
+	char fdt_name[I2C_BUF_SIZE];
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(k1_board_map); i++) {
+		memset(fdt_name, 0, I2C_BUF_SIZE);
+		if (!strncmp(product_name, k1_board_map[i].eeprom_name,
+			     strlen(k1_board_map[i].eeprom_name))) {
+			snprintf(fdt_name, I2C_BUF_SIZE, "%s",
+				 k1_board_map[i].fit_name);
+			break;
+		}
+	}
+	if (fdt_name[0] == '\0') {
+		/* set default board name */
+		sprintf(fdt_name, CONFIG_DEFAULT_DEVICE_TREE);
+	}
+	memcpy(product_name, fdt_name, I2C_BUF_SIZE);
+}
+
 static void clk_early_init(void)
 {
 	struct udevice *dev;
@@ -417,6 +447,7 @@ void board_init_f(ulong dummy)
 		log_info("Fail to detect board:%d\n", ret);
 	else
 		log_info("Get board name:%s\n", product_name);
+	fixup_product_name();
 	pmic_init();
 
 	ddr_early_init();
@@ -459,24 +490,7 @@ void spl_board_init(void)
 
 int board_fit_config_name_match(const char *name)
 {
-	char fdt_name[I2C_BUF_SIZE];
-	int i;
-
-	memset(fdt_name, 0, I2C_BUF_SIZE);
-	if (!strncmp(product_name, "k1-x_", 5)) {
-		snprintf(fdt_name, I2C_BUF_SIZE, "%s-%s", "k1",
-			 &product_name[5]);
-	}
-	if (fdt_name[0] == '\0') {
-		/* set default board name */
-		sprintf(fdt_name, "k1-musepi-pro");
-	}
-	for (i = 0; i < I2C_BUF_SIZE; i++) {
-		if (fdt_name[i] == '\0')
-			break;
-		fdt_name[i] = tolower(fdt_name[i]);
-	}
-	if (!strcmp(name, fdt_name))
+	if (!strcmp(name, product_name))
 		return 0;
 	return -ENOENT;
 }
Signature · 1 line
2.51.0
#10 lore raw

Re: [PATCH v13 7/7] spacemit: k1: fix product name detection and DTB matching in SPL

Hi,

just a general question related to this patch, not about the patch itself, see below:

board/spacemit/k1/spl.c static void i2c_early_init(void) · line 151

Quoted 8 lines · Eric Chung
board/spacemit/k1/spl.c +8 -0
+static const struct {
+	const char *eeprom_name;
+	const char *fit_name;
+} k1_board_map[] = {
+	{ "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+	{ "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+	{ "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};

This maps the EEPROMs product_name to the dtb, just like the vendor fork, nice.

But does the BPI F3 really have "k1-x_deb1" in there?
I know that's the fallback dtb of the vendor's fork [0][1], in case there's nothing there, and I thought that was the case for the F3?

Because it seems it's not set for BPI-CM6 IO board either [2], which then makes it impossible to distinguish, at least based on the EEPROM value :\

Are there any ideas how to handle that, yet?

Can we distinguish between those boards in the SPL based on something different?

Or can we make up our own strings and let users write that to EEPROM? Mainline and vendor technically allows it via e.g.:
tlv_eeprom set 0x21 "k1-x_BPI-CM6-IO"
tlv_eeprom write
But that's assuming the EEPROM is writable, which I haven't checked.
(And I neither have a F3 nor a CM6).

Cheers,
Andre

[0] https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/include/configs/k1-x.h#L28
[1] https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/board/spacemit/k1-x/spl.c#L558
[2] https://github.com/openwrt/openwrt/pull/23231#issuecomment-5943699070

author
#11 lore raw

Re: [PATCH v13 7/7] spacemit: k1: fix product name detection and DTB matching in SPL

Quoted 16 lines · Andre Heider

Hi,

just a general question related to this patch, not about the patch itself, see below:

board/spacemit/k1/spl.c static void i2c_early_init(void) · line 151

Quoted 8 lines · Eric Chung
board/spacemit/k1/spl.c +8 -0
+static const struct {
+     const char *eeprom_name;
+     const char *fit_name;
+} k1_board_map[] = {
+     { "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+     { "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+     { "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};

This maps the EEPROMs product_name to the dtb, just like the vendor fork, nice.

Quoted 3 lines

But does the BPI F3 really have "k1-x_deb1" in there?
I know that's the fallback dtb of the vendor's fork [0][1], in case there's nothing there, and I thought that was the case for the F3?

k1-x_deb1 means the internal development board. And it could work smoothly on the Banana Pi F3.

Quoted 2 lines

Because it seems it's not set for BPI-CM6 IO board either [2], which then makes it impossible to distinguish, at least based on the EEPROM value :\

What's BPI-CM6 IO board? Is the BPI-CM6 IO board similar to the Banana Pi F3? Is it supported by linux kernel now?

Quoted 10 lines

Are there any ideas how to handle that, yet?

Can we distinguish between those boards in the SPL based on something different?

Or can we make up our own strings and let users write that to EEPROM? Mainline and vendor technically allows it via e.g.:

   tlv_eeprom set 0x21 "k1-x_BPI-CM6-IO"
   tlv_eeprom write

But that's assuming the EEPROM is writable, which I haven't checked. (And I neither have a F3 nor a CM6).

tlv_eeprom should support to write EEPROM. If it fails, we could enable ENV in SPL. I have a patch in the mailing list to enable ENV. But that patch was abandoned. You could review the mailing list to reuse it.

Quoted 6 lines

Cheers,
Andre

[0] https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/include/configs/k1-x.h#L28
[1] https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/board/spacemit/k1-x/spl.c#L558
[2] https://github.com/openwrt/openwrt/pull/23231#issuecomment-5943699070

#12 lore raw

Re: [PATCH v13 7/7] spacemit: k1: fix product name detection and DTB matching in SPL

Quoted 17 lines · Eric Chung
Quoted 16 lines · Andre Heider

Hi,

just a general question related to this patch, not about the patch itself, see below:

board/spacemit/k1/spl.c static void i2c_early_init(void) · line 151

Quoted 8 lines · Eric Chung
board/spacemit/k1/spl.c +8 -0
+static const struct {
+     const char *eeprom_name;
+     const char *fit_name;
+} k1_board_map[] = {
+     { "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+     { "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+     { "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};

This maps the EEPROMs product_name to the dtb, just like the vendor fork, nice.

Quoted 6 lines
Quoted 3 lines

But does the BPI F3 really have "k1-x_deb1" in there?
I know that's the fallback dtb of the vendor's fork [0][1], in case there's nothing there, and I thought that was the case for the F3?

k1-x_deb1 means the internal development board. And it could work smoothly on the Banana Pi F3.

Yes, but maybe someone with a F3 board can verify via tlv_eeprom if that string is actually in there?

Quoted 7 lines
Quoted 4 lines

Because it seems it's not set for BPI-CM6 IO board either [2], which then makes it impossible to distinguish, at least based on the EEPROM value :\

What's BPI-CM6 IO board? Is the BPI-CM6 IO board similar to the Banana Pi F3? Is it supported by linux kernel now?

This one:
https://docs.banana-pi.org/en/BPI-CM6/BananaPi_BPI-CM6

Supported by mainline via:
arch/riscv/boot/dts/spacemit/k1-bananapi-cm6-io.dts

Apparently sinovoip *edited* k1-x_deb1.dts for CM6 and even ship that hack in their OS images (visible in the logs on that OpenWrt PR):
https://github.com/BPI-SINOVOIP/pi-linux/commit/333b99e8cd9b18e98bf71821518548df345dbb61
/o\

Quoted 12 lines
Quoted 11 lines

Are there any ideas how to handle that, yet?

Can we distinguish between those boards in the SPL based on something different?

Or can we make up our own strings and let users write that to EEPROM? Mainline and vendor technically allows it via e.g.:

    tlv_eeprom set 0x21 "k1-x_BPI-CM6-IO"
    tlv_eeprom write

But that's assuming the EEPROM is writable, which I haven't checked. (And I neither have a F3 nor a CM6).

Quoted 4 lines

tlv_eeprom should support to write EEPROM. If it fails, we could enable ENV in SPL. I have a patch in the mailing list to enable ENV. But that patch was abandoned. You could review the mailing list to reuse it.

In the meantime a board owner verified the EEPROM write as working:
https://github.com/openwrt/openwrt/pull/23231#issuecomment-5972395785

For the record, I made up "k1-x_BPI-CM6-IO" as product name with a matching vendor fork device-tree file name, which makes u-boot as well as the kernel pick up their matching device-trees via CONFIG_FIT_BEST_MATCH.

In case mainline u-boot goes the same way (let CM6 owners add a value to EEPROM) to properly make multi-dtb fit images boot, can we agree on a value? Or maybe someone here has connections to sinovoip and ask them to put that/anything in there?

Quoted 7 lines
Quoted 7 lines

Cheers,
Andre

[0] https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/include/configs/k1-x.h#L28
[1] https://gitee.com/spacemit-buildroot/uboot-2022.10/blob/k1-bl-v2.2.y/board/spacemit/k1-x/spl.c#L558
[2] https://github.com/openwrt/openwrt/pull/23231#issuecomment-5943699070

author
#13 lore raw

Re: [PATCH v13 7/7] spacemit: k1: fix product name detection and DTB matching in SPL

Quoted 63 lines · Andre Heider
Quoted 17 lines · Eric Chung
Quoted 16 lines · Andre Heider

Hi,

just a general question related to this patch, not about the patch itself, see below:

board/spacemit/k1/spl.c static void i2c_early_init(void) · line 151

Quoted 8 lines · Eric Chung
board/spacemit/k1/spl.c +8 -0
+static const struct {
+     const char *eeprom_name;
+     const char *fit_name;
+} k1_board_map[] = {
+     { "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+     { "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+     { "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};

This maps the EEPROMs product_name to the dtb, just like the vendor fork, nice.

Quoted 6 lines
Quoted 3 lines

But does the BPI F3 really have "k1-x_deb1" in there?
I know that's the fallback dtb of the vendor's fork [0][1], in case there's nothing there, and I thought that was the case for the F3?

k1-x_deb1 means the internal development board. And it could work smoothly on the Banana Pi F3.

Yes, but maybe someone with a F3 board can verify via tlv_eeprom if that string is actually in there?

Quoted 7 lines
Quoted 4 lines

Because it seems it's not set for BPI-CM6 IO board either [2], which then makes it impossible to distinguish, at least based on the EEPROM value :\

What's BPI-CM6 IO board? Is the BPI-CM6 IO board similar to the Banana Pi F3? Is it supported by linux kernel now?

This one:
https://docs.banana-pi.org/en/BPI-CM6/BananaPi_BPI-CM6

Supported by mainline via:
arch/riscv/boot/dts/spacemit/k1-bananapi-cm6-io.dts

Apparently sinovoip *edited* k1-x_deb1.dts for CM6 and even ship that hack in their OS images (visible in the logs on that OpenWrt PR):
https://github.com/BPI-SINOVOIP/pi-linux/commit/333b99e8cd9b18e98bf71821518548df345dbb61
/o\

Quoted 12 lines
Quoted 11 lines

Are there any ideas how to handle that, yet?

Can we distinguish between those boards in the SPL based on something different?

Or can we make up our own strings and let users write that to EEPROM? Mainline and vendor technically allows it via e.g.:

    tlv_eeprom set 0x21 "k1-x_BPI-CM6-IO"
    tlv_eeprom write

But that's assuming the EEPROM is writable, which I haven't checked. (And I neither have a F3 nor a CM6).

Quoted 4 lines

tlv_eeprom should support to write EEPROM. If it fails, we could enable ENV in SPL. I have a patch in the mailing list to enable ENV. But that patch was abandoned. You could review the mailing list to reuse it.

Quoted 7 lines

In the meantime a board owner verified the EEPROM write as working:
https://github.com/openwrt/openwrt/pull/23231#issuecomment-5972395785

For the record, I made up "k1-x_BPI-CM6-IO" as product name with a matching vendor fork device-tree file name, which makes u-boot as well as the kernel pick up their matching device-trees via CONFIG_FIT_BEST_MATCH.

In case mainline u-boot goes the same way (let CM6 owners add a value to EEPROM) to properly make multi-dtb fit images boot, can we agree on a value? Or maybe someone here has connections to sinovoip and ask them to put that/anything in there?

Yes, adding "k1-x_BPI-CM6-IO" to the EEPROM sounds good to me. Feel free to format a patch and send it to the mailing list.

#14 lore raw

Re: [PATCH v13 7/7] spacemit: k1: fix product name detection and DTB matching in SPL

Quoted 67 lines · Eric Chung
Quoted 66 lines · Andre Heider
Quoted 17 lines · Eric Chung
Quoted 16 lines · Andre Heider

Hi,

just a general question related to this patch, not about the patch itself, see below:

board/spacemit/k1/spl.c static void i2c_early_init(void) · line 151

Quoted 8 lines · Eric Chung
board/spacemit/k1/spl.c +8 -0
+static const struct {
+     const char *eeprom_name;
+     const char *fit_name;
+} k1_board_map[] = {
+     { "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+     { "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+     { "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};

This maps the EEPROMs product_name to the dtb, just like the vendor fork, nice.

Quoted 6 lines
Quoted 3 lines

But does the BPI F3 really have "k1-x_deb1" in there?
I know that's the fallback dtb of the vendor's fork [0][1], in case there's nothing there, and I thought that was the case for the F3?

k1-x_deb1 means the internal development board. And it could work smoothly on the Banana Pi F3.

Yes, but maybe someone with a F3 board can verify via tlv_eeprom if that string is actually in there?

Quoted 7 lines
Quoted 4 lines

Because it seems it's not set for BPI-CM6 IO board either [2], which then makes it impossible to distinguish, at least based on the EEPROM value :\

What's BPI-CM6 IO board? Is the BPI-CM6 IO board similar to the Banana Pi F3? Is it supported by linux kernel now?

This one:
https://docs.banana-pi.org/en/BPI-CM6/BananaPi_BPI-CM6

Supported by mainline via:
arch/riscv/boot/dts/spacemit/k1-bananapi-cm6-io.dts

Apparently sinovoip *edited* k1-x_deb1.dts for CM6 and even ship that hack in their OS images (visible in the logs on that OpenWrt PR):
https://github.com/BPI-SINOVOIP/pi-linux/commit/333b99e8cd9b18e98bf71821518548df345dbb61
/o\

Quoted 12 lines
Quoted 11 lines

Are there any ideas how to handle that, yet?

Can we distinguish between those boards in the SPL based on something different?

Or can we make up our own strings and let users write that to EEPROM? Mainline and vendor technically allows it via e.g.:

    tlv_eeprom set 0x21 "k1-x_BPI-CM6-IO"
    tlv_eeprom write

But that's assuming the EEPROM is writable, which I haven't checked. (And I neither have a F3 nor a CM6).

Quoted 4 lines

tlv_eeprom should support to write EEPROM. If it fails, we could enable ENV in SPL. I have a patch in the mailing list to enable ENV. But that patch was abandoned. You could review the mailing list to reuse it.

In the meantime a board owner verified the EEPROM write as working:
https://github.com/openwrt/openwrt/pull/23231#issuecomment-5972395785

Quoted 7 lines
Quoted 4 lines

For the record, I made up "k1-x_BPI-CM6-IO" as product name with a matching vendor fork device-tree file name, which makes u-boot as well as the kernel pick up their matching device-trees via CONFIG_FIT_BEST_MATCH.

In case mainline u-boot goes the same way (let CM6 owners add a value to EEPROM) to properly make multi-dtb fit images boot, can we agree on a value? Or maybe someone here has connections to sinovoip and ask them to put that/anything in there?

Yes, adding "k1-x_BPI-CM6-IO" to the EEPROM sounds good to me. Feel free to format a patch and send it to the mailing list.

If we are inventing EEPROM data based on vibes then I think it is appropriate to give at least one or two characters in the EEPROM data to the company names respectively; "BananaPi" and "OrangePi" are brands astroturfing the Raspbery Pi Foundation trademark.

"Orange Pi is an open source product brand of Shenzhen Xunlong Software Co., Ltd" from www.orangepi.org website.

FYI for the StarFive JH-7110 SoC Xunlong OrangePi RV board I made up this EEPROM value in board/starfive/visionfive2/spl.c:

        } else if (!strcmp(name, "starfive/jh7110-orangepi-rv") &&
                    !strncmp(get_product_id_from_eeprom(), "XOPIRV", 6)) {

and in board/starfive/visionfive2/starfive_visionfive2.c:

        } else if (!strncmp(get_product_id_from_eeprom(), "XOPIRV", 6)) {
                fdtfile = "starfive/jh7110-orangepi-rv.dtb";

It is the situation that a few products on the market with JH-7110 SoC have shipped having an EEPROM product name data identical to the reference StarFive VisionFive2 1.3b board and where the vendor edits this corresponding dts file in their own u-boot fork. Eventually I would like this to be a bare-minimum default for boards in mainline u-boot that get it wrong to boot with just enough peripheral support to write a new EEPROM value. As it is now we fail the boot with a message for the user when no match is found.

While we're inventing new values for boards with SpacemiT SoC we should also add such for the Banana Pi F3 and not leave it with the generic reference board product name (unless that is in fact what its purpose is historically). I suggest a logical-or to the existing comparison for compatibility until a decision is formed about what should be the default when no match is found.

The EEPROM data examples are derived from vendor u-boot filenames so not necessary to arbitrarily upcase; Add for example "k1-x_svbpi-cm6" for the System-on module or "k1-x_svbpi-cm6-io" for the baseboard, whichever has the EEPROM device. In fact we might also derive this as "k1-bananapi-cm6" or "k1-bananapi-cm6-io" from upstream Linux. The pattern with "k1-x_" prefix appears to be representing vendor dts filenames for boards with the taped-out K1 SoC; and "k1-pro_" is pre-production dts filename related. That is very arbitrary and I don't see any reason why we should invent something on vibes about a filename that does not exist... but anyways it would be lowercase and not upcase.

Suggested thus any of:
k1-x_bpi-cm6(-io)
k1-x_svbpi-cm6(-io)
k1-x_svbp-bpi-cm6(-io)
k1-x_bpbpi-cm6(-io)
k1-x_bpi-cm6(-io)
k1-bananapi-cm6
k1-bananapi-cm6-io
k1-bananapi-f3

My strong preference is for referring to mainline Linux dts filenames if we are just making it up when the overwhelming trend is to refer to actual filenames, somewhere.

-E

#15 lore raw

Re: [PATCH v13 7/7] spacemit: k1: fix product name detection and DTB matching in SPL

Hi,

just noticed that Yixuan wasn't part of cc:, adding.

Quoted 95 lines · E Shattow
Quoted 67 lines · Eric Chung
Quoted 66 lines · Andre Heider
Quoted 17 lines · Eric Chung
Quoted 16 lines · Andre Heider

Hi,

just a general question related to this patch, not about the patch itself, see below:

board/spacemit/k1/spl.c static void i2c_early_init(void) · line 151

Quoted 8 lines · Eric Chung
board/spacemit/k1/spl.c +8 -0
+static const struct {
+     const char *eeprom_name;
+     const char *fit_name;
+} k1_board_map[] = {
+     { "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+     { "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+     { "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};

This maps the EEPROMs product_name to the dtb, just like the vendor fork, nice.

Quoted 6 lines
Quoted 3 lines

But does the BPI F3 really have "k1-x_deb1" in there?
I know that's the fallback dtb of the vendor's fork [0][1], in case there's nothing there, and I thought that was the case for the F3?

k1-x_deb1 means the internal development board. And it could work smoothly on the Banana Pi F3.

Yes, but maybe someone with a F3 board can verify via tlv_eeprom if that string is actually in there?

Quoted 7 lines
Quoted 4 lines

Because it seems it's not set for BPI-CM6 IO board either [2], which then makes it impossible to distinguish, at least based on the EEPROM value :\

What's BPI-CM6 IO board? Is the BPI-CM6 IO board similar to the Banana Pi F3? Is it supported by linux kernel now?

This one:
https://docs.banana-pi.org/en/BPI-CM6/BananaPi_BPI-CM6

Supported by mainline via:
arch/riscv/boot/dts/spacemit/k1-bananapi-cm6-io.dts

Apparently sinovoip *edited* k1-x_deb1.dts for CM6 and even ship that hack in their OS images (visible in the logs on that OpenWrt PR):
https://github.com/BPI-SINOVOIP/pi-linux/commit/333b99e8cd9b18e98bf71821518548df345dbb61
/o\

Quoted 12 lines
Quoted 11 lines

Are there any ideas how to handle that, yet?

Can we distinguish between those boards in the SPL based on something different?

Or can we make up our own strings and let users write that to EEPROM? Mainline and vendor technically allows it via e.g.:

     tlv_eeprom set 0x21 "k1-x_BPI-CM6-IO"
     tlv_eeprom write

But that's assuming the EEPROM is writable, which I haven't checked. (And I neither have a F3 nor a CM6).

Quoted 4 lines

tlv_eeprom should support to write EEPROM. If it fails, we could enable ENV in SPL. I have a patch in the mailing list to enable ENV. But that patch was abandoned. You could review the mailing list to reuse it.

In the meantime a board owner verified the EEPROM write as working:
https://github.com/openwrt/openwrt/pull/23231#issuecomment-5972395785

Quoted 7 lines
Quoted 4 lines

For the record, I made up "k1-x_BPI-CM6-IO" as product name with a matching vendor fork device-tree file name, which makes u-boot as well as the kernel pick up their matching device-trees via CONFIG_FIT_BEST_MATCH.

In case mainline u-boot goes the same way (let CM6 owners add a value to EEPROM) to properly make multi-dtb fit images boot, can we agree on a value? Or maybe someone here has connections to sinovoip and ask them to put that/anything in there?

Yes, adding "k1-x_BPI-CM6-IO" to the EEPROM sounds good to me. Feel free to format a patch and send it to the mailing list.

If we are inventing EEPROM data based on vibes then I think it is appropriate to give at least one or two characters in the EEPROM data to the company names respectively; "BananaPi" and "OrangePi" are brands astroturfing the Raspbery Pi Foundation trademark.

"Orange Pi is an open source product brand of Shenzhen Xunlong Software Co., Ltd" from www.orangepi.org website.

FYI for the StarFive JH-7110 SoC Xunlong OrangePi RV board I made up this EEPROM value in board/starfive/visionfive2/spl.c:

         } else if (!strcmp(name, "starfive/jh7110-orangepi-rv") &&
                     !strncmp(get_product_id_from_eeprom(), "XOPIRV", 6)) {

and in board/starfive/visionfive2/starfive_visionfive2.c:

         } else if (!strncmp(get_product_id_from_eeprom(), "XOPIRV", 6)) {
                 fdtfile = "starfive/jh7110-orangepi-rv.dtb";
Quoted 8 lines

It is the situation that a few products on the market with JH-7110 SoC have shipped having an EEPROM product name data identical to the reference StarFive VisionFive2 1.3b board and where the vendor edits this corresponding dts file in their own u-boot fork. Eventually I would like this to be a bare-minimum default for boards in mainline u-boot that get it wrong to boot with just enough peripheral support to write a new EEPROM value. As it is now we fail the boot with a message for the user when no match is found.

Ack, that sounds like a good idea.

Quoted 7 lines

While we're inventing new values for boards with SpacemiT SoC we should also add such for the Banana Pi F3 and not leave it with the generic reference board product name (unless that is in fact what its purpose is historically). I suggest a logical-or to the existing comparison for compatibility until a decision is formed about what should be the default when no match is found.

Quoted 10 lines

The EEPROM data examples are derived from vendor u-boot filenames so not necessary to arbitrarily upcase; Add for example "k1-x_svbpi-cm6" for the System-on module or "k1-x_svbpi-cm6-io" for the baseboard, whichever has the EEPROM device. In fact we might also derive this as "k1-bananapi-cm6" or "k1-bananapi-cm6-io" from upstream Linux. The pattern with "k1-x_" prefix appears to be representing vendor dts filenames for boards with the taped-out K1 SoC; and "k1-pro_" is pre-production dts filename related. That is very arbitrary and I don't see any reason why we should invent something on vibes about a filename that does not exist... but anyways it would be lowercase and not upcase.

While mainline u-boot for K1 progresses nicely, it's not ready yet (think bootstrapping spl/proper/kernel on all boards from bootrom via fastboot). Which is why the OpenWrt PR has the vendor u-boot for now (with some patches and compatibles added to boot mainline opensbi/linux). So I actually created a k1-x_BPI-CM6-IO.dts file in there. I just derived the name based on what else is in there:

k1-x_baton-camera.dts
k1-x_BPI-CM6-IO.dts
k1-x_deb1.dts
k1-x_deb2.dts
k1-x_evb.dts
k1-x_FusionOne.dts
k1-x_InnoBoard-Pi.dts
k1-x_lpi3a.dts
k1-x_LX-V10.dts
k1-x_milkv-jupiter.dts
k1-x_MINI-PC.dts
k1-x_MUSE-Book.dts
k1-x_MUSE-Card.dts
k1-x_MUSE-N1.dts
k1-x_MUSE-Paper2.dts
k1-x_MUSE-Paper-mini-4g.dts
k1-x_MUSE-Pi.dts
k1-x_MUSE-Pi-Pro.dts
k1-x_som.dts
k1-x_spl.dts
k1-x_uav.dts
k1-x_ZT001H.dts
k1-x_ZT_RVOH007.dts
x1_orangepi-r2s.dts
x1_orangepi-rv2.dts

- the k1-x_ prefix is to keep it in line
- there's a mix of upper and lower case
- the mainline dts has no "sv" or "sinovoip" either, it even uses the "bananapi" vendor for the compatible
- both orangepi boards are already covered. The patches are from armbian IIRC, but didn't require adding a product name to EEPROM

Quoted 10 lines

Suggested thus any of:
k1-x_bpi-cm6(-io)
k1-x_svbpi-cm6(-io)
k1-x_svbp-bpi-cm6(-io)
k1-x_bpbpi-cm6(-io)
k1-x_bpi-cm6(-io)
k1-bananapi-cm6
k1-bananapi-cm6-io
k1-bananapi-f3

Quoted 3 lines

My strong preference is for referring to mainline Linux dts filenames if we are just making it up when the overwhelming trend is to refer to actual filenames, somewhere.

I don't really have a preference, the name I made up was the first thing that made sense to me. Whatever can be agreed upon ;)

Cheers,
Andre

maintainer Tested-by Reviewed-by on the v13 series
#16 lore raw
In reply to Eric Chung
Quoted 126 lines · 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.

---
Changes in v13:
- mmc: Sync the definition values from upstream mmc driver.
- doc: Only flash the minimised partitions for SD boot.
- Link to v12: https://patch.msgid.link/[email protected]

Changes in v12:
- dts: Drop all upstreamed DTS patches since they're merged now.
- Link to v11: https://patch.msgid.link/[email protected]

Changes in v11:
- spl: Fix the read_boot_mode() that returns both boot mode and boot device.
- Link to v10: https://patch.msgid.link/[email protected]

Changes in v10:
- pinctrl: Move all pinctrl patches into a new patch set.
- Link to v9: https://patch.msgid.link/[email protected]

Changes in v9:
- spl: Enhance detection on booting from SD.
- dts: Synched upstream DTS files for K1.
- doc: Create SD card image from scratch.
- mmc: Avoid to use CMD18 on SD card in SPL.
- pinctrl: Drop "fix drive strength configuration".
- Link to v8: https://patch.msgid.link/[email protected]

Changes in v8:
- doc: Remove SD card.
- Link to v7: https://patch.msgid.link/[email protected]

Changes in v7:
- env: Drop env support on the mmc series.
- dts: Sync upstream DTS files for spacemit.
- pinctrl: Simply clrsetbits_le32() on pull-up/pull-down configuration.
- spl: Fix DTB matching.
- Link to v6: https://patch.msgid.link/[email protected]

Changes in v6:
- pinctrl: Fix drive strength configuration.
- pinctrl: Fix pull-up/pull-down configuration.
- pinctrl: Use dev_read_phandle_with_args() to fetch "spacemit,syscon" instead.
- spacemit: rebase on latest upstream branch.
- Link to v5: https://patch.msgid.link/[email protected]

Changes in v5:
- mmc: Split CMD23 support out.
- mmc: Use read_poll_timeout().
- mmc: Set pinctrl state based on selected timing mode.
- mmc: Remove the condition based on quirks.
- pinctrl: Fix power source argument.
- dts: Add missing power source on mmc pins.
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- mmc: Add CMD23 for write.
- mmc: Fix CMD23 only for CMD18.
- mmc: Update bulk release operations on reset and clocks for spacemit platform driver.
- MAINTAINER: update the maintainer of Spacemit K1.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- pinctrl: Fix "fast" by "uhs".
- pinctrl: Add syscon dependency.
- mmc: Fix quick by capability.
- doc: Add SD boot support.
- Link to v2: https://lore.kernel.org/u-boot/[email protected]/T/#m2aba875a2696a7bb9b704618d22ae2fd7f7f5acc

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/[email protected]/

To: [email protected]
To: [email protected]
To: Yao Zi <[email protected]>
Cc: Huan Zhou <[email protected]>
Cc: Eric Chung <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Raymond Mao <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Jaehoon Chung <[email protected]>
Cc: Bastien Curutchet <[email protected]>
Cc: Anshul Dalal <[email protected]>
Cc: Siu Ming Tong <[email protected]>
Cc: Johan Jonker <[email protected]>
Cc: Tim Ouyang <[email protected]>
Cc: Leo Liang <[email protected]>

---
Eric Chung (7):
spacemit: k1: select boot device via config registers
mmc: k1: add sdhci platform driver
dts: k1: enable mmc devices in SPL
configs: k1: enable SD and eMMC support
MAINTAINER: update Spacemit K1 entry
doc: spacemit: flash on K1 SoC based boards
spacemit: k1: fix product name detection and DTB matching in SPL

 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi |  12 +-
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  | 136 +-----
 board/spacemit/k1/MAINTAINERS             |   5 +-
 board/spacemit/k1/spl.c                   | 148 ++++++-
 configs/spacemit_k1_defconfig             |  22 +
 doc/board/spacemit/index.rst              |   1 +
 doc/board/spacemit/k1-mmc.rst             | 268 ++++++++++++
 drivers/mmc/Kconfig                       |   7 +
 drivers/mmc/Makefile                      |   1 +
 drivers/mmc/spacemit_sdhci.c              | 684 ++++++++++++++++++++++++++++++
 10 files changed, 1136 insertions(+), 148 deletions(-)
Quoted 1 line

---

For this series, I've tested on Bananapi-F3 board, which works on both eMMC and SD card, and so with

Signature · 1 line
Yixun Lan (dlan)
maintainer Applied
#17 lore raw
In reply to Eric Chung
Quoted 9 lines · 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.

[...]

Applied, thanks!

[1/7] spacemit: k1: select boot device via config registers

      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/aa3091dcd7012ca77fae5854da62e360a9d4ddeb
[2/7] mmc: k1: add sdhci platform driver
      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/18e9745c932718335d0a8cf0223a00d216f71272
[3/7] dts: k1: enable mmc devices in SPL
      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/c8d4129cb9a4ef84fb167324a4fee1b2807e9219
[4/7] configs: k1: enable SD and eMMC support
      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/f570dfb74e7ddcd4063bec68e3e81a7063179700
[5/7] MAINTAINER: update Spacemit K1 entry
      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/a75e1ed839a31f8ae9e534fa76167290f1180d94
[6/7] doc: spacemit: flash on K1 SoC based boards
      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/69d82789fe6fdaea697fa124a934aa5e4a92b3d1
[7/7] spacemit: k1: fix product name detection and DTB matching in SPL
      https://git.u-boot-project.org/u-boot/custodians/u-boot-spacemit/-/commit/6f8c134610b9d139ff3e104e4cdba3512c4ee7e1

Best regards,

Signature · 1 line
Yixun Lan <[email protected]>