Add SD card and eMMC support for SpacemiT K1
Subsystems (3)
cover Add SD card and eMMC support for SpacemiT K1
From: Raymond Mao <[email protected]>
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.
It also carries two generic cmd/meminfo fixes needed on K1, whose DRAM is larger than 4 GB and split across two banks with an address hole:
widen the printed addresses to phys_addr_t, and account LMB regions per bank.
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 v2 [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)
[1] https://lore.kernel.org/u-boot/20260526-b4-k1-clk-reset-upstream-dts-v2-0-af815e362b0c@riscstar.com/
[2] https://lore.kernel.org/u-boot/[email protected]/
[3] https://lore.kernel.org/u-boot/[email protected]/
Guodong Xu (8):
spacemit: k1: select boot device via config registers
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
cmd: meminfo: widen memory map addresses to phys_addr_t
cmd: meminfo: fix the lmb info for large DRAM
cmd: tlv_eeprom: fix accessing invalid parameter
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 | 77 +- cmd/meminfo.c | 53 +- cmd/tlv_eeprom.c | 2 +- configs/spacemit_k1_defconfig | 17 + doc/board/spacemit/index.rst | 1 + doc/board/spacemit/k1-flash.rst | 157 ++++ drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 934 ++++++++++++++++++++++ 12 files changed, 1401 insertions(+), 20 deletions(-) create mode 100644 doc/board/spacemit/k1-flash.rst create mode 100644 drivers/mmc/spacemit_sdhci.c
Signature · 1 line
2.25.1
PATCH 1/8 spacemit: k1: select boot device via config registers
From: Guodong Xu <[email protected]>
Add logic to determine the current boot device by reading the SoC's configuration registers, rather than using a hardcoded default.
--- board/spacemit/k1/spl.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)
board/spacemit/k1/spl.c +76 -1
@@ -21,6 +21,17 @@#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 MUX_MODE4 4#define EDGE_NONE BIT(6)#define PULL_UP (6 << 13)/* bit[15:13] 110 */
@@ -45,6 +56,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;
@@ -379,7 +401,60 @@ void board_init_f(ulong dummy)u32 spl_boot_device (void ) { -return BOOT_DEVICE_SPI ; +void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG ; +void __iomem *boot_strap = (void __iomem *)BOOT_PIN_SEL_REG ; +u32 mode, sel, ret =0 ; + + mode =readl (boot_dev); +if (mode ==BOOT_MODE_NONE || mode >BOOT_MODE_SD ) { + sel =readl (boot_strap); + sel >>=BOOT_STRAP_MODE_OFFSET ; + sel &=BOOT_STRAP_MODE_MASK ; +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 ; + } + } +/* TODO: +* The current upstream DTS file only contains the eMMC node. When +* the SD node is added via an overlay, the eMMC device ends up as +* MMC1 in SPL. +* However, the SD device should be the first device (MMC1). +* This sequence needs to be corrected once the SD node is merged +* into the upstream U-Boot DTS file. +*/ +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.25.1
PATCH 2/8 mmc: k1: add sdhci platform driver
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
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.
--- drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 934 +++++++++++++++++++++++++++++++++++ 3 files changed, 942 insertions(+) create mode 100644 drivers/mmc/spacemit_sdhci.c
drivers/mmc/Kconfig +7 -0
@@ -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
drivers/mmc/Makefile +1 -0
@@ -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
drivers/mmc/spacemit_sdhci.c new file +934 -0
934 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 3/8 dts: k1: add SD card support in u-boot overlay
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
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.
--- 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(-)
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi +85 -2
@@ -6,6 +6,11 @@ #include "binman.dtsi" / { + aliases { + mmc0 = &sd; + mmc1 = &emmc; + }; + 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 { + sd: 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>; +}; + +&sd { + vqmmc-supply = <&buck4_3v3>; +}; + &binman { u-boot-spl-ddr { type = "section";
arch/riscv/dts/k1-musepi-pro-u-boot.dtsi +80 -2
106 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 4/8 configs: k1: enable SD and eMMC support
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
Enable high-speed MMC modes for PIO.
--- board/spacemit/k1/MAINTAINERS | 1 + configs/spacemit_k1_defconfig | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
board/spacemit/k1/MAINTAINERS +1 -0
@@ -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
configs/spacemit_k1_defconfig +17 -0
@@ -87,6 +87,20 @@ 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_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 +108,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_MMC=y +CONFIG_SPL_MMC_TINY=y +CONFIG_SPL_SYS_MMCSD_RAW_MODE=y
Signature · 1 line
2.25.1
PATCH 5/8 doc: spacemit: flash on K1 SoC based boards
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
Add document on how to flash images into eMMC of K1 SoC based boards.
--- 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(-) create mode 100644 doc/board/spacemit/k1-flash.rst
board/spacemit/k1/MAINTAINERS +1 -1
@@ -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
@@ -6,5 +6,6 @@ SpacemiT :maxdepth: 1 bananapi-f3 + k1-flash k1-spl
doc/board/spacemit/k1-flash.rst new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 6/8 cmd: meminfo: widen memory map addresses to phys_addr_t
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
On 32-bit builds 'ulong' is only 32 bits wide, so the memory map truncates any address or size at or above 4 GiB even though the columns already allow 13 hex digits. Boards with large DRAM therefore print wrong bases, sizes and gaps.
Use phys_addr_t for every region address and print it as a 64-bit value so the map is correct regardless of the build's long width.
--- cmd/meminfo.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
cmd/meminfo.c +11 -6
@@ -21,18 +21,23 @@ void __weak arch_dump_mem_attrs(void) { } -static void print_region (const char *name,ulong base,ulong size,ulong *uptop) +static void print_region (const char *name,phys_addr_t base,phys_addr_t size, +phys_addr_t *uptop) { -ulong end = base + size; +phys_addr_t end = base + size; -printf ("%-12s %13lx %13lx %13lx" , name, base, size, end); +printf ("%-12s %13llx %13llx %13llx" , + name, + (unsigned long long )base, + (unsigned long long )size, + (unsigned long long )end);if (*uptop) -printf (" %13lx" , *uptop - end); +printf (" %13llx" , (unsigned long long )(*uptop - end));putc ('\n' ); *uptop = base; } -static void show_lmb (const struct lmb *lmb,ulong *uptop) +static void show_lmb (const struct lmb *lmb,phys_addr_t *uptop) {int i;
@@ -56,7 +61,7 @@ static void show_lmb(const struct lmb *lmb, ulong *uptop)static int do_meminfo (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) { -ulong upto, stk_bot; +phys_addr_t upto, stk_bot;puts ("DRAM: " );print_size (gd->ram_size,"\n" );
Signature · 1 line
2.25.1
PATCH 7/8 cmd: meminfo: fix the lmb info for large DRAM
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
When DRAM size exceeds 4GB, it may be split into two separate banks, leaving an address hole between them.
To properly handle this configuration, LMB regions must be calculated individually for each memory bank. Additionally, all address calculations should support 64-bit to accommodate large memory ranges.
--- cmd/meminfo.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
cmd/meminfo.c +28 -6
@@ -31,31 +31,53 @@ static void print_region(const char *name, phys_addr_t base, phys_addr_t size, (unsigned long long )base, (unsigned long long )size, (unsigned long long)end); -if (*uptop) +if (*uptop > end)printf (" %13llx" , (unsigned long long )(*uptop - end)); +else +printf (" %13llx" , (unsigned long long )(end - end));putc ('\n' ); *uptop = base; }static void show_lmb (const struct lmb *lmb,phys_addr_t *uptop) { -int i; +int i, j; +phys_addr_t bank_top[CONFIG_NR_DRAM_BANKS ]; +struct bd_info *bd = gd->bd; +bool get_bank; + +for (j =0 ; j <CONFIG_NR_DRAM_BANKS ; j++) + bank_top[j] = bd->bi_dram[j].start + bd->bi_dram[j].size;for (i = lmb->used_mem.count -1 ; i >=0 ; i--) {const struct lmb_region *rgn =alist_get (&lmb->used_mem, i, struct lmb_region); +for (j =0 , get_bank = false; j <CONFIG_NR_DRAM_BANKS ; j++) { +if (rgn->base >= bd->bi_dram[j].start && + rgn->base < bank_top[j]) { + get_bank = true; +break ; + } + } +if (!get_bank) { +log_err ("The region (base:0x%llx, size:0x%llx) does not exists in any DRAM bank.\n" , + (unsigned long long )rgn->base, (unsigned long long )rgn->size); +return ; + }/* * Assume that the top lmb region is the U-Boot region, so just * take account of the memory not already reported */ if (lmb->used_mem.count -1 ) -print_region ("lmb" , rgn->base, *uptop - rgn->base, - uptop); +print_region ("lmb" , rgn->base, bank_top[j] - rgn->base, + &bank_top[j]);else -print_region ("lmb" , rgn->base, rgn->size, uptop); - *uptop = rgn->base; +print_region ("lmb" , rgn->base, rgn->size, &bank_top[j]); + bank_top[j] = rgn->base; } + + *uptop = bank_top[0 ]; } static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,
Signature · 1 line
2.25.1
PATCH 8/8 cmd: tlv_eeprom: fix accessing invalid parameter
In reply to Raymond MaoFrom: Guodong Xu <[email protected]>
=> tlv_eeprom dev
Unhandled exception: Load access fault
EPC: 000000007ffb351a RA: 000000007ff7c302 TVAL: 0000000000000000
EPC: 000000000024b51a RA: 0000000000214302 reloc adjusted
SP: 000000007ef3ec90 GP: 000000007ef48e40 TP: 0000000000000000 T0: 000000007ef3eda0 T1: 0000000000000000 T2: 0000000000000000 S0: 0000000000000002 S1: 000000007f05c0a0 A0: 0000000000000000 A1: 0000000000000000 A2: 0000000000000000 A3: 00000000d4017000 A4: 0000000000000002 A5: 00000000d4017000 A6: 0000000000000001 A7: 0000000000000000 S2: 0000000000000001 S3: 000000007f05c0a0 S4: 0000000000000002 S5: 000000007fffbbec S6: 0000000000000000 S7: 000000007f05c080 S8: 000000007f05c0a0 S9: 0000000000000000 S10: 0000000000000000 S11: 000000007f05afa0 T3: 0000000000000005 T4: 0000000000000009 T5: 0000000000000006 T6: 000000007ef3ed80
Code: 0007 3513 0015 70a2 7402 64e2 6145 8082 (4683 0005)
Command "tlv_eeprom dev" should not access argv[2]. argv[2] should be only accessed by command "tlv_eeprom dev [dev]" command.
So add a guard to prevent this invalid access.
--- cmd/tlv_eeprom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/tlv_eeprom.c +1 -1
@@ -450,7 +450,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) cmd = argv[1 ][0 ];// select device -if (cmd =='d' ) { +if (cmd =='d' && argc >2 ) {/* 'dev' command */ unsigned int devnum;
Signature · 1 line
2.25.1
Re: [PATCH 1/8] spacemit: k1: select boot device via config registers
In reply to Raymond MaoQuoted 16 lines · Raymond Mao
From: Guodong Xu <[email protected]>
Add logic to determine the current boot device by reading the SoC's configuration registers, rather than using a hardcoded default.
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- board/spacemit/k1/spl.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)board/spacemit/k1/spl.c +0
-0
...
Quoted 4 lines
board/spacemit/k1/spl.c +0
-0@@ -379,7 +401,60 @@ void board_init_f(ulong dummy)u32 spl_boot_device (void ) {
board/spacemit/k1/spl.c void board_init_f(ulong dummy) · line 412
Quoted 10 lines
board/spacemit/k1/spl.c +9
-1-return BOOT_DEVICE_SPI ; +void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG ; +void __iomem *boot_strap = (void __iomem *)BOOT_PIN_SEL_REG ; +u32 mode, sel, ret =0 ; + + mode =readl (boot_dev); +if (mode ==BOOT_MODE_NONE || mode >BOOT_MODE_SD ) { + sel =readl (boot_strap); + sel >>=BOOT_STRAP_MODE_OFFSET ; + sel &=BOOT_STRAP_MODE_MASK ;
Is FIELD_GET() helpful here?
Quoted 10 lines
board/spacemit/k1/spl.c +10
-0+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 ;
board/spacemit/k1/spl.c void board_init_f(ulong dummy) · line 432
Quoted 10 lines
board/spacemit/k1/spl.c +10
-0+case BOOT_STRAP_MODE_SD : +default : + mode =BOOT_MODE_SD ; +break ; + } + } +/* TODO: +* The current upstream DTS file only contains the eMMC node. When +* the SD node is added via an overlay, the eMMC device ends up as +* MMC1 in SPL.
Why not fix this with an extra alias in the overlay dt?
Quoted 31 lines
board/spacemit/k1/spl.c +25
-0+* However, the SD device should be the first device (MMC1). +* This sequence needs to be corrected once the SD node is merged +* into the upstream U-Boot DTS file. +*/ +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.25.1
Regards,
Yao Zi
Re: [PATCH 2/8] mmc: k1: add sdhci platform driver
In reply to Raymond MaoQuoted 5 lines · Raymond Mao
From: Guodong Xu <[email protected]>
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.
Is there any reason not to re-use Linux-side K1 MMC driver, sdhci-of-k1.c, and its companion ABI? Since Linux commit e9cb83c10071 (mmc: sdhci-of-k1: add comprehensive SDR tuning support, 2026-05-11) it is now capable of operating on SD cards, too.
Quoted 8 lines
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 934 +++++++++++++++++++++++++++++++++++ 3 files changed, 942 insertions(+) create mode 100644 drivers/mmc/spacemit_sdhci.c
...
Quoted 5 lines
drivers/mmc/spacemit_sdhci.c new file +0
-0
...
Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7
-0+static void spacemit_sdhci_set_aib_mmc1_io (struct sdhci_host *host,int voltage) +{ +struct mmc *mmc = host->mmc; +struct spacemit_sdhci_plat *plat =dev_get_plat (mmc->dev); +void __iomem *aib_mmc1_io, *apbc_asfar, *apbc_assar; +u32 reg; +
drivers/mmc/spacemit_sdhci.c line 310
Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10
-0+if (!plat->aib_mmc1_io_reg || !plat->apbc_asfar_reg || + !plat->apbc_assar_reg) +return ; + + aib_mmc1_io =map_sysmem ((uintptr_t )plat->aib_mmc1_io_reg, +sizeof (u32)); + apbc_asfar =map_sysmem ((uintptr_t )plat->apbc_asfar_reg, +sizeof (u32)); + apbc_assar =map_sysmem ((uintptr_t )plat->apbc_assar_reg, +sizeof (u32));
AFAIK aib_mmc1_io region is related to pinctrl settings, and shouldn't be handled by the MMC driver directly. Quoting my own reply[1] to the series adding SD support to sdhci-of-k1.c in Linux side,
Quoted 8 lines
Also, the pin controller on K1 SoC seems to have some undocumented registers to select the IO voltage of SD pins, which should be adjusted when switching IO voltage.
I think these pins should be implemented in the pinctrl driver, then you could create two pinctrl states, one for 1.8v operation, one for 3.3v, and switch between them through
pinctrl_lookup_state()when changing IO voltage.
This idea is later confirmed by SpacemiT guy's series[2],
Quoted 8 lines
On K1, IO domain power control registers determine whether a GPIO bank operates at 1.8V or 3.3V. These registers default to 3.3V operation, which may lead to functional failures when GPIO banks are externally supplied with 1.8V but internally remain configured for 3.3V.
The IO power domain registers are implemented as secure registers and require an explicit unlock sequence via the AIB Secure Access Register (ASAR), located in the APBC register space.
Thus I think you should move the logic to pinctrl driver instead, like what has been done in the Linux upstream driver.
Quoted 16 lines
drivers/mmc/spacemit_sdhci.c new file +16
-0+writel (AKEY_ASFAR , apbc_asfar); +writel (AKEY_ASSAR , apbc_assar); + reg =readl (aib_mmc1_io); + +switch (voltage) { +case MMC_SIGNAL_VOLTAGE_180 : + reg |=MMC1_IO_V18EN ; +break ; +default : + reg &= ~MMC1_IO_V18EN ; +break ; + } +writel (AKEY_ASFAR , apbc_asfar); +writel (AKEY_ASSAR , apbc_assar); +writel (reg, aib_mmc1_io); +}
...
Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2
-0+static void spacemit_sdhci_set_control_reg (struct sdhci_host *host) +{
...
drivers/mmc/spacemit_sdhci.c line 412
Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7
-0+/* Set pinctrl state */ +if (IS_ENABLED (CONFIG_PINCTRL )) { +if (mmc->clock >=200000000 ) +pinctrl_select_state (mmc->dev,"fast" ); +else +pinctrl_select_state (mmc->dev,"default" ); + }
This doesn't match Linux side ABI, where when card operates in UHS mode, pinctrl state "uhs" is selected.
Regards,
Yao Zi
[1]: https://lore.kernel.org/linux-riscv/aUDwDkd8k_4gD1yc@pie/
[2]: https://lore.kernel.org/linux-riscv/20260108-kx-pinctrl-aib-io-pwr-domain-v2-0-6bcb46146e53@linux.spacemit.com
Re: [PATCH 1/8] spacemit: k1: select boot device via config registers
In reply to Eric ChungQuoted 42 lines · Eric Chung
Quoted 41 lines · Yao Zi' via uboot
Quoted 16 lines · Raymond Mao
From: Guodong Xu <[email protected]>
Add logic to determine the current boot device by reading the SoC's configuration registers, rather than using a hardcoded default.
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- board/spacemit/k1/spl.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)board/spacemit/k1/spl.c +0
-0...
Quoted 20 lines
board/spacemit/k1/spl.c +20
-0+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 ; + } + } +/* TODO: +* The current upstream DTS file only contains the eMMC node. When +* the SD node is added via an overlay, the eMMC device ends up as +* MMC1 in SPL.
Quoted 5 lines
Quoted 2 lines
Why not fix this with an extra alias in the overlay dt?
That approach doesn't really help — with the alias, mmc0 and mmc1 get swapped, which ultimately breaks ABI consistency.
Sorry I didn't read you correctly, I'm not sure which you are trying to keep consistency with.
I did a check in Linux next-20260623, and the aliases for bananapi-f3 look like,
aliases {
ethernet0 = ð0;
ethernet1 = ð1;
serial0 = &uart0;
spi3 = &spi3;
i2c2 = &i2c2;
i2c8 = &i2c8;
mmc0 = &emmc;
mmc1 = &sdhci0;
};and for musepi-pro,
aliases {
ethernet0 = ð0;
serial0 = &uart0;
i2c2 = &i2c2;
i2c8 = &i2c8;
mmc0 = &emmc;
mmc1 = &sdhci0;
};So both of them assign emmc to mmc0 and sdhci0 (SD) to mmc1.
As a summary of the situation,
- Linux before SD card support is merged: emmc becomes mmc0 (without other hotpluggable devices present), no SD card
- Linux after SD card support is merged: emmc becomes mmc0, SD becomes mmc1
But PATCH 3 in the series assigns SD to mmc0 and emmc to MMC1, this instead looks like an ABI breakage, and would go away as long as you change the aliases? At the same time the comment here could be dropped.
Quoted 40 lines
The hack on MMC1 only affects its role in SPL and doesn't impact the ABI in the devicetree. It's just a workaround. Eventually, both the overlay and the hack will be removed once the upstream DTS is robust enough.
Quoted 34 lines
Quoted 29 lines
board/spacemit/k1/spl.c +25
-1+* However, the SD device should be the first device (MMC1). +* This sequence needs to be corrected once the SD node is merged +* into the upstream U-Boot DTS file. +*/ +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 ) --Quoted 2 lines
2.25.1
Regards,
Yao Zi
Regards,
Yao Zi
Re: [PATCH 2/8] mmc: k1: add sdhci platform driver
In reply to Eric ChungQuoted 9 lines · Eric Chung
Quoted 8 lines · Yao Zi' via uboot
Quoted 5 lines · Raymond Mao
From: Guodong Xu <[email protected]>
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.
Quoted 6 lines
Quoted 5 lines
Is there any reason not to re-use Linux-side K1 MMC driver,
sdhci-of-k1.c, and its companion ABI? Since Linux commite9cb83c10071(mmc: sdhci-of-k1: add comprehensive SDR tuning support, 2026-05-11) it is now capable of operating on SD cards, too.Excuse me. Is there any ABI breakage in this SD/eMMC device?
Yes, I only take a brief look, and at least the names for pinctrl states differ from Linux upstream, as mentioned below.
So are there any reasons not to re-use it? This driver has been carefully reviewed in Linux side, has the expected ABI, which would reduce your work of upstreaming.
Quoted 16 lines
Quoted 16 lines
Quoted 8 lines
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 934 +++++++++++++++++++++++++++++++++++ 3 files changed, 942 insertions(+) create mode 100644 drivers/mmc/spacemit_sdhci.c...
Quoted 5 lines
drivers/mmc/spacemit_sdhci.c new file +0
-0
...
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2
-0+static void spacemit_sdhci_set_control_reg (struct sdhci_host *host) +{...
Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7
-0+/* Set pinctrl state */ +if (IS_ENABLED (CONFIG_PINCTRL )) { +if (mmc->clock >=200000000 ) +pinctrl_select_state (mmc->dev,"fast" ); +else +pinctrl_select_state (mmc->dev,"default" ); + }
Quoted 5 lines
Quoted 3 lines
This doesn't match Linux side ABI, where when card operates in UHS mode, pinctrl state "uhs" is selected.
OK. Switch to "uhs". By the way, the upstream DTS file hasn't been synced into uboot yet. This is not easy to find.
I'm not sure what do you mean by "not easy to find". You could always refer to the dt-bindings maintained by Linux side for ABI description, and we want to keep aligned with it in U-Boot side as long as possible to reduce maintenance burden and improve interoperability.
Quoted 5 lines
Regards,
Yao Zi
Re: [PATCH 1/8] spacemit: k1: select boot device via config registers
In reply to Yao ZiQuoted 23 lines · Yao Zi' via uboot
Quoted 16 lines · Raymond Mao
From: Guodong Xu <[email protected]>
Add logic to determine the current boot device by reading the SoC's configuration registers, rather than using a hardcoded default.
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- board/spacemit/k1/spl.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)board/spacemit/k1/spl.c +0
-0...
Quoted 2 lines
board/spacemit/k1/spl.c +0
-0@@ -379,7 +401,60 @@ void board_init_f(ulong dummy)
Quoted 15 lines
board/spacemit/k1/spl.c void board_init_f(ulong dummy) · line 412
Quoted 12 lines
board/spacemit/k1/spl.c +9
-1u32 spl_boot_device (void ) { -return BOOT_DEVICE_SPI ; +void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG ; +void __iomem *boot_strap = (void __iomem *)BOOT_PIN_SEL_REG ; +u32 mode, sel, ret =0 ; + + mode =readl (boot_dev); +if (mode ==BOOT_MODE_NONE || mode >BOOT_MODE_SD ) { + sel =readl (boot_strap); + sel >>=BOOT_STRAP_MODE_OFFSET ; + sel &=BOOT_STRAP_MODE_MASK ;Is
FIELD_GET()helpful here?
Yes, we can use FIELD_GET().
Quoted 21 lines
Quoted 10 lines
board/spacemit/k1/spl.c +10
-0+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 ;board/spacemit/k1/spl.c void board_init_f(ulong dummy) · line 432
Quoted 10 lines
board/spacemit/k1/spl.c +10
-0+case BOOT_STRAP_MODE_SD : +default : + mode =BOOT_MODE_SD ; +break ; + } + } +/* TODO: +* The current upstream DTS file only contains the eMMC node. When +* the SD node is added via an overlay, the eMMC device ends up as +* MMC1 in SPL.
Quoted 2 lines
Why not fix this with an extra alias in the overlay dt?
That approach doesn't really help — with the alias, mmc0 and mmc1 get swapped, which ultimately breaks ABI consistency.
The hack on MMC1 only affects its role in SPL and doesn't impact the ABI in the devicetree. It's just a workaround. Eventually, both the overlay and the hack will be removed once the upstream DTS is robust enough.
Quoted 34 lines
Quoted 29 lines
board/spacemit/k1/spl.c +25
-1+* However, the SD device should be the first device (MMC1). +* This sequence needs to be corrected once the SD node is merged +* into the upstream U-Boot DTS file. +*/ +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 ) --Quoted 2 lines
2.25.1
Regards,
Yao Zi
Re: [PATCH 2/8] mmc: k1: add sdhci platform driver
In reply to Yao ZiQuoted 4 lines · Yao Zi' via uboot
Quoted 2 lines · Raymond Mao
From: Guodong Xu <[email protected]>
Quoted 9 lines
Quoted 3 lines
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.
Is there any reason not to re-use Linux-side K1 MMC driver,
sdhci-of-k1.c, and its companion ABI? Since Linux commite9cb83c10071(mmc: sdhci-of-k1: add comprehensive SDR tuning support, 2026-05-11) it is now capable of operating on SD cards, too.
Excuse me. Is there any ABI breakage in this SD/eMMC device?
Quoted 32 lines
Quoted 8 lines
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 934 +++++++++++++++++++++++++++++++++++ 3 files changed, 942 insertions(+) create mode 100644 drivers/mmc/spacemit_sdhci.c...
Quoted 5 lines
drivers/mmc/spacemit_sdhci.c new file +0
-0...
Quoted 13 lines
drivers/mmc/spacemit_sdhci.c new file +13
-0+static void spacemit_sdhci_set_aib_mmc1_io (struct sdhci_host *host,int voltage) +{ +struct mmc *mmc = host->mmc; +struct spacemit_sdhci_plat *plat =dev_get_plat (mmc->dev); +void __iomem *aib_mmc1_io, *apbc_asfar, *apbc_assar; +u32 reg; + +if (!plat->aib_mmc1_io_reg || !plat->apbc_asfar_reg || + !plat->apbc_assar_reg) +return ; + + aib_mmc1_io =map_sysmem ((uintptr_t )plat->aib_mmc1_io_reg, +sizeof (u32));
Quoted 9 lines
drivers/mmc/spacemit_sdhci.c line 310
Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4
-0+ apbc_asfar =map_sysmem ((uintptr_t )plat->apbc_asfar_reg, +sizeof (u32)); + apbc_assar =map_sysmem ((uintptr_t )plat->apbc_assar_reg, +sizeof (u32));AFAIK
aib_mmc1_ioregion is related to pinctrl settings, and shouldn't be handled by the MMC driver directly. Quoting my own reply[1] to the series adding SD support tosdhci-of-k1.cin Linux side,
OK. I'll move it to pinctrl.
Quoted 16 lines
Quoted 8 lines
Also, the pin controller on K1 SoC seems to have some undocumented registers to select the IO voltage of SD pins, which should be adjusted when switching IO voltage.
I think these pins should be implemented in the pinctrl driver, then you could create two pinctrl states, one for 1.8v operation, one for 3.3v, and switch between them through
pinctrl_lookup_state()when changing IO voltage.This idea is later confirmed by SpacemiT guy's series[2],
Quoted 5 lines
On K1, IO domain power control registers determine whether a GPIO bank operates at 1.8V or 3.3V. These registers default to 3.3V operation, which may lead to functional failures when GPIO banks are externally supplied with 1.8V but internally remain configured for 3.3V.
Quoted 7 lines
Quoted 3 lines
The IO power domain registers are implemented as secure registers and require an explicit unlock sequence via the AIB Secure Access Register (ASAR), located in the APBC register space.
Thus I think you should move the logic to pinctrl driver instead, like what has been done in the Linux upstream driver.
OK
Quoted 32 lines
Quoted 16 lines
drivers/mmc/spacemit_sdhci.c new file +16
-0+writel (AKEY_ASFAR , apbc_asfar); +writel (AKEY_ASSAR , apbc_assar); + reg =readl (aib_mmc1_io); + +switch (voltage) { +case MMC_SIGNAL_VOLTAGE_180 : + reg |=MMC1_IO_V18EN ; +break ; +default : + reg &= ~MMC1_IO_V18EN ; +break ; + } +writel (AKEY_ASFAR , apbc_asfar); +writel (AKEY_ASSAR , apbc_assar); +writel (reg, aib_mmc1_io); +}...
Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2
-0+static void spacemit_sdhci_set_control_reg (struct sdhci_host *host) +{...
drivers/mmc/spacemit_sdhci.c line 412
Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7
-0+/* Set pinctrl state */ +if (IS_ENABLED (CONFIG_PINCTRL )) { +if (mmc->clock >=200000000 ) +pinctrl_select_state (mmc->dev,"fast" ); +else +pinctrl_select_state (mmc->dev,"default" ); + }
Quoted 3 lines
This doesn't match Linux side ABI, where when card operates in UHS mode, pinctrl state "uhs" is selected.
OK. Switch to "uhs". By the way, the upstream DTS file hasn't been synced into uboot yet. This is not easy to find.
Re: [PATCH 1/8] spacemit: k1: select boot device via config registers
In reply to Yao ZiQuoted 78 lines · Yao Zi
Quoted 42 lines · Eric Chung
Quoted 41 lines · Yao Zi' via uboot
Quoted 16 lines · Raymond Mao
From: Guodong Xu <[email protected]>
Add logic to determine the current boot device by reading the SoC's configuration registers, rather than using a hardcoded default.
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- board/spacemit/k1/spl.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)board/spacemit/k1/spl.c +0
-0...
Quoted 20 lines
board/spacemit/k1/spl.c +20
-0+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 ; + } + } +/* TODO: +* The current upstream DTS file only contains the eMMC node. When +* the SD node is added via an overlay, the eMMC device ends up as +* MMC1 in SPL. Quoted 5 lines
Quoted 2 lines
Why not fix this with an extra alias in the overlay dt?
That approach doesn't really help — with the alias, mmc0 and mmc1 get swapped, which ultimately breaks ABI consistency.
Sorry I didn't read you correctly, I'm not sure which you are trying to keep consistency with.
I did a check in Linux next-20260623, and the aliases for bananapi-f3 look like,
aliases { ethernet0 = ð0; ethernet1 = ð1; serial0 = &uart0; spi3 = &spi3; i2c2 = &i2c2; i2c8 = &i2c8; mmc0 = &emmc; mmc1 = &sdhci0; };and for musepi-pro,
aliases { ethernet0 = ð0; serial0 = &uart0; i2c2 = &i2c2; i2c8 = &i2c8; mmc0 = &emmc; mmc1 = &sdhci0; };
Quoted 9 lines
So both of them assign emmc to mmc0 and sdhci0 (SD) to mmc1.
As a summary of the situation,
- Linux before SD card support is merged: emmc becomes mmc0 (without other hotpluggable devices present), no SD card
- Linux after SD card support is merged: emmc becomes mmc0, SD becomes mmc1
Because I don't know there's a new alias in upstream DTS. OK. I can use the alias in uboot.
Quoted 47 lines
But PATCH 3 in the series assigns SD to mmc0 and emmc to MMC1, this instead looks like an ABI breakage, and would go away as long as you change the aliases? At the same time the comment here could be dropped.
Quoted 40 lines
The hack on MMC1 only affects its role in SPL and doesn't impact the ABI in the devicetree. It's just a workaround. Eventually, both the overlay and the hack will be removed once the upstream DTS is robust enough.
Quoted 34 lines
Quoted 29 lines
board/spacemit/k1/spl.c +25
-1+* However, the SD device should be the first device (MMC1). +* This sequence needs to be corrected once the SD node is merged +* into the upstream U-Boot DTS file. +*/ +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 ) --Quoted 2 lines
2.25.1
Regards,
Yao ZiRegards,
Yao Zi
Re: [PATCH 2/8] mmc: k1: add sdhci platform driver
In reply to Yao ZiQuoted 16 lines · Yao Zi
Quoted 14 lines · Eric Chung
Quoted 13 lines · Yao Zi' via uboot
Quoted 5 lines · Raymond Mao
From: Guodong Xu <[email protected]>
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.
Is there any reason not to re-use Linux-side K1 MMC driver,
sdhci-of-k1.c, and its companion ABI? Since Linux commite9cb83c10071(mmc: sdhci-of-k1: add comprehensive SDR tuning support, 2026-05-11) it is now capable of operating on SD cards, too.
Quoted 5 lines
Quoted 1 line
Excuse me. Is there any ABI breakage in this SD/eMMC device?
Yes, I only take a brief look, and at least the names for pinctrl states differ from Linux upstream, as mentioned below.
I can change the pinctrl state.
Quoted 4 lines
So are there any reasons not to re-use it? This driver has been carefully reviewed in Linux side, has the expected ABI, which would reduce your work of upstreaming.
There is no tuning support in linux driver when I write the mmc driver in uboot.
Quoted 51 lines
Quoted 16 lines
Quoted 16 lines
Quoted 8 lines
Signed-off-by Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>--- drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 934 +++++++++++++++++++++++++++++++++++ 3 files changed, 942 insertions(+) create mode 100644 drivers/mmc/spacemit_sdhci.c...
Quoted 5 lines
drivers/mmc/spacemit_sdhci.c new file +0
-0...
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2
-0+static void spacemit_sdhci_set_control_reg (struct sdhci_host *host) +{...
Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7
-0+/* Set pinctrl state */ +if (IS_ENABLED (CONFIG_PINCTRL )) { +if (mmc->clock >=200000000 ) +pinctrl_select_state (mmc->dev,"fast" ); +else +pinctrl_select_state (mmc->dev,"default" ); + }Quoted 5 lines
Quoted 3 lines
This doesn't match Linux side ABI, where when card operates in UHS mode, pinctrl state "uhs" is selected.
OK. Switch to "uhs". By the way, the upstream DTS file hasn't been synced into uboot yet. This is not easy to find.
I'm not sure what do you mean by "not easy to find". You could always refer to the dt-bindings maintained by Linux side for ABI description, and we want to keep aligned with it in U-Boot side as long as possible to reduce maintenance burden and improve interoperability.
Quoted 5 lines
Regards,
Yao Zi
Re: [PATCH 2/8] mmc: k1: add sdhci platform driver
In reply to Raymond MaoQuoted 14 lines · Raymond Mao
From: Guodong Xu <[email protected]>
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 Guodong Xu <[email protected]>Signed-off-by Raymond Mao <[email protected]>---
drivers/mmc/spacemit_sdhci.c new file +5
-0+ +#define LOG_CATEGORY UCLASS_MMC + +#include <clk.h> +#include <dm.h>
drivers/mmc/spacemit_sdhci.c line 22
Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10
-0+#include <dm/pinctrl.h> +#include <fdtdec.h> +#include <linux/libfdt.h> +#include <linux/delay.h> +#include <log.h> +#include <malloc.h> +#include <sdhci.h> +#include <reset-uclass.h> +#include <power/regulator.h> +#include <mapmem.h>
See doc/develop/codingstyle.rst regarding "Include files"
drivers/mmc/spacemit_sdhci.c line 29
Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7
-0+ +/* SDH register definitions */ +#define SDHC_OP_EXT_REG 0x108 +#define OVRRD_CLK_OEN 0x0800 +#define FORCE_CLK_ON 0x1000 + +#define SDHC_LEGACY_CTRL_REG 0x10C
Not used.
drivers/mmc/spacemit_sdhci.c line 38
Quoted 9 lines
drivers/mmc/spacemit_sdhci.c new file +9
-0+#define GEN_PAD_CLK_ON 0x0040 + +#define SDHC_MMC_CTRL_REG 0x114 +#define MISC_INT_EN 0x0002 +#define MISC_INT 0x0004 +#define ENHANCE_STROBE_EN 0x0100 +#define MMC_HS400 0x0200 +#define MMC_HS200 0x0400 +#define MMC_CARD_MODE 0x1000
Use BIT(x) and GENMASK for register bits, and other places.
Quoted 87 lines
drivers/mmc/spacemit_sdhci.c new file +87
-0+ +#define SDHC_RX_CFG_REG 0x118 +#define RX_SDCLK_SEL0_MASK 0x03 +#define RX_SDCLK_SEL0_SHIFT 0x00 +#define RX_SDCLK_SEL0 0x02 +#define RX_SDCLK_SEL1_MASK 0x03 +#define RX_SDCLK_SEL1_SHIFT 0x02 +#define RX_SDCLK_SEL1 0x01 + +#define SDHC_TX_CFG_REG 0x11C +#define TX_INT_CLK_SEL 0x40000000 +#define TX_MUX_SEL 0x80000000 + +#define SDHC_DLINE_CTRL_REG 0x130 +#define DLINE_PU 0x01 +#define RX_DLINE_CODE_MASK 0xFF +#define RX_DLINE_CODE_SHIFT 0x10 +#define TX_DLINE_CODE_MASK 0xFF +#define TX_DLINE_CODE_SHIFT 0x18 + +#define SDHC_DLINE_CFG_REG 0x134 +#define RX_DLINE_REG_MASK 0xFF +#define RX_DLINE_REG_SHIFT 0x00 +#define RX_DLINE_GAIN_MASK 0x1 +#define RX_DLINE_GAIN_SHIFT 0x8 +#define RX_DLINE_GAIN 0x1 +#define TX_DLINE_REG_MASK 0xFF +#define TX_DLINE_REG_SHIFT 0x10 + +#define SDHC_PHY_CTRL_REG 0x160 +#define PHY_FUNC_EN 0x0001 +#define PHY_PLL_LOCK 0x0002 +#define HOST_LEGACY_MODE 0x80000000 + +#define SDHC_PHY_FUNC_REG 0x164 +#define PHY_TEST_EN 0x0080 +#define HS200_USE_RFIFO 0x8000 + +#define SDHC_PHY_DLLCFG 0x168 +#define DLL_PREDLY_NUM 0x04 +#define DLL_FULLDLY_RANGE 0x10 +#define DLL_VREG_CTRL 0x40 +#define DLL_ENABLE 0x80000000 +#define DLL_REFRESH_SWEN_SHIFT 0x1C +#define DLL_REFRESH_SW_SHIFT 0x1D + +#define SDHC_PHY_DLLCFG1 0x16C +#define DLL_REG2_CTRL 0x0C +#define DLL_REG3_CTRL_MASK 0xFF +#define DLL_REG3_CTRL_SHIFT 0x10 +#define DLL_REG2_CTRL_MASK 0xFF +#define DLL_REG2_CTRL_SHIFT 0x08 +#define DLL_REG1_CTRL 0x92 +#define DLL_REG1_CTRL_MASK 0xFF +#define DLL_REG1_CTRL_SHIFT 0x00 + +#define SDHC_PHY_DLLSTS 0x170 +#define DLL_LOCK_STATE 0x01 + +#define SDHC_PHY_DLLSTS1 0x174 +#define DLL_MASTER_DELAY_MASK 0xFF +#define DLL_MASTER_DELAY_SHIFT 0x10 + +#define SDHC_PHY_PADCFG_REG 0x178 +#define RX_BIAS_CTRL_SHIFT 0x5 +#define PHY_DRIVE_SEL_SHIFT 0x0 +#define PHY_DRIVE_SEL_MASK 0x7 +#define PHY_DRIVE_SEL_DEFAULT 0x4 + +#define MMC1_IO_V18EN 0x04 +#define AKEY_ASFAR 0xBABA +#define AKEY_ASSAR 0xEB10 + +#define SDHC_RX_TUNE_DELAY_MIN 0x0 +#define SDHC_RX_TUNE_DELAY_MAX 0xFF +#define SDHC_RX_TUNE_DELAY_STEP 0x1 + +#define CANDIDATE_WIN_NUM 3 +#define SELECT_DELAY_NUM 9 +#define WINDOW_1ST 0 +#define WINDOW_2ND 1 +#define WINDOW_3RD 2 + +#define RX_TUNING_WINDOW_THRESHOLD 80 +#define RX_TUNING_DLINE_REG 0x09 +#define TX_TUNING_DLINE_REG 0x00 +#define TX_TUNING_DELAYCODE 127
...
drivers/mmc/spacemit_sdhci.c line 584
Quoted 13 lines
drivers/mmc/spacemit_sdhci.c new file +13
-0+ +static int spacemit_sdhci_send_tuning_cmd (struct sdhci_host *host,u32 opcode) +{ +int err =0 ; + + err =spacemit_sdhci_send_tuning (host, opcode,NULL ); +if (err) { +log_warning ("%s: send tuning err:%d\n" , host->name, err); +return err; + } + + err =spacemit_sdhci_tuning_pattern_check (host); +return err;
return spacemit_sdhci_tuning_pattern_check(host);
Quoted 11 lines
drivers/mmc/spacemit_sdhci.c new file +11
-0+} + +static void spacemit_sdhci_clear_tuned_clk (struct sdhci_host *host) +{ +u16 ctrl; + + ctrl =sdhci_readw (host,SDHCI_HOST_CONTROL2 ); + ctrl &= ~(SDHCI_CTRL_TUNED_CLK |SDHCI_CTRL_EXEC_TUNING ); +sdhci_writew (host, ctrl,SDHCI_HOST_CONTROL2 ); +} +
...
Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4
-0+ + +/* Enable DLL */ + reg =sdhci_readl (host,SDHC_PHY_DLLCFG );
drivers/mmc/spacemit_sdhci.c line 770
Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10
-0+ reg |=DLL_ENABLE ; +sdhci_writel (host, reg,SDHC_PHY_DLLCFG ); + +/* Wait for DLL lock */ + i =0 ; +while (i++ <100 ) { +if (sdhci_readl (host,SDHC_PHY_DLLSTS ) &DLL_LOCK_STATE ) +break ; +udelay (10 ); + }
Use readx_poll_sleep_timeout?
Quoted 75 lines
drivers/mmc/spacemit_sdhci.c new file +75
-0+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,SDHC_MMC_CTRL_REG ); + reg |=ENHANCE_STROBE_EN ; +sdhci_writel (host, reg,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, + .platform_execute_tuning = spacemit_sdhci_execute_tuning, +#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;
drivers/mmc/spacemit_sdhci.c line 855
Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10
-0+ } + + 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 ))
CONFIG_XPL_BUILD
drivers/mmc/spacemit_sdhci.c line 859
Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4
-0+ host->quirks =SDHCI_QUIRK_WAIT_SEND_CMD ; + else + host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | +SDHCI_QUIRK_32BIT_DMA_ADDR ;
Regards
Peng