Skip to contentSkip to conversation

spacemit mmc driver

PATCH Superseded Eric Chung 5 participants 23 messages Jul 7 – Jul 23

Subsystems (4)

v4 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Eric Chung

author
#0 lore raw

v4 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.

This series sits on top of three series still under review, and must be applied after them, in this order:

1. K1 clock/reset/dts migration [1] (8 patches)
2. K1 SPL bring-up v4 [2] (14 patches)
3. K1 pinctrl/GPIO and SPI NOR v2 [3] (9 patches)
Then this series (10 patches)

For each series:

b4 am <cover-msgid>
git am ./*.mbx

---
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]

Cc Huan Zhou <[email protected]>
Cc Guodong Xu <[email protected]>
Cc Tom Rini <[email protected]>
Cc Tim Ouyang <[email protected]>
Cc Leo Liang <[email protected]>
Cc Raymond Mao <[email protected]>
Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
Cc Bhimeswararao Matsa <[email protected]>
Cc Tanmay Kathpalia <[email protected]>
Cc Kaustabh Chakraborty <[email protected]>
Cc Han Xu <[email protected]>
Cc Yanir Levin <[email protected]>
Cc Christoph Stoidner <[email protected]>
Cc Balsundar Ponnusamy <[email protected]>
Cc Daniel Palmer <[email protected]>
Cc Anshul Dalal <[email protected]>
Cc Bastien Curutchet <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Johan Jonker <[email protected]>
Cc Sam Protsenko <[email protected]>

---
Eric Chung (10):
spacemit: k1: select boot device via config registers
pinctrl: k1: add IO power domain configuration support
mmc: enable CMD23 for multi-block transfers
mmc: k1: add sdhci platform driver
dts: k1: add SD card support in u-boot overlay
configs: k1: enable SD and eMMC support
MAINTAINER: update Spacemit K1 entry
doc: spacemit: flash on K1 SoC based boards
config: k1: enable ENV support for eMMC
spacemit: k1: load product name from environment variable

 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi |  87 +++-
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  |  82 +++-
 board/spacemit/k1/MAINTAINERS             |   5 +-
 board/spacemit/k1/spl.c                   | 120 ++++--
 configs/spacemit_k1_defconfig             |  26 +-
 doc/board/spacemit/index.rst              |   1 +
 doc/board/spacemit/k1-mmc.rst             | 320 ++++++++++++++
 drivers/mmc/Kconfig                       |   7 +
 drivers/mmc/Makefile                      |   1 +
 drivers/mmc/mmc.c                         |  16 +-
 drivers/mmc/mmc_write.c                   |  19 +-
 drivers/mmc/spacemit_sdhci.c              | 685 ++++++++++++++++++++++++++++++
 drivers/pinctrl/spacemit/Kconfig          |   2 +-
 drivers/pinctrl/spacemit/pinctrl-k1.c     |  83 +++-
 include/mmc.h                             |   3 +
 15 files changed, 1401 insertions(+), 56 deletions(-)

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

Best regards,

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

PATCH v4 1/10 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.

---
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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 1 deletion(-)
board/spacemit/k1/spl.c +68 -1
index 0db362130e4..70579637b5e 100644
@@ -13,6 +13,7 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <i2c.h>
+#include <linux/bitfield.h>
 #include <linux/delay.h>
 #include <log.h>
 #include <power/regulator.h>
@@ -21,6 +22,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 +57,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 +402,51 @@ 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 = 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;
+		}
+	}
+	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
Reviewed-by on v4 1/10
#2 lore raw

Re: [PATCH v4 01/10] spacemit: k1: select boot device via config registers

Quoted 20 lines · Eric Chung

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

---
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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 1 deletion(-)
board/spacemit/k1/spl.c +0 -0
index 0db362130e4..70579637b5e 100644

...

Quoted 39 lines
board/spacemit/k1/spl.c +34 -1
@@ -379,7 +402,51 @@ 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 = 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;
+		}
+	}
+	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;

board/spacemit/k1/spl.c void board_init_f(ulong dummy) · line 448

Quoted 10 lines
board/spacemit/k1/spl.c +10 -0
+	case BOOT_MODE_USB:
+		ret = BOOT_DEVICE_USB;
+		break;
+	case BOOT_MODE_SD:
+		ret = BOOT_DEVICE_MMC2;
+		break;
+	default:
+		ret = BOOT_DEVICE_MMC1;
+		break;
+	}

Adding empty lines before and after this switch might make the code a little cleaner. Though being a little strange to me, checkpatch.pl doesn't complain about it, so I don't have a strong opinion for this.

Best regards,
Yao Zi

author
#3 lore raw

PATCH v4 2/10 pinctrl: k1: add IO power domain configuration support

In reply to Eric Chung

Dual-voltage GPIO banks default to 3.3V, but when externally supplied with 1.8V the internal logic must be explicitly reconfigured to match.

Add the ability to program IO power domain control registers through the APBC block. These registers require unlocking the AIB Secure Access Register (ASAR) before every read/write, since configuring a 1.8V domain while 3.3V is externally supplied can cause back-powering and pin damage.

---
v3:
- Add SYSCON dependency in Kconfig.
- Fix not sorted issue in the driver.

---
 drivers/pinctrl/spacemit/Kconfig      |  2 +-
 drivers/pinctrl/spacemit/pinctrl-k1.c | 83 ++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 3 deletions(-)
drivers/pinctrl/spacemit/Kconfig +1 -1
index 6aab89e160c..ff754f5839c 100644
@@ -1,6 +1,6 @@
 config PINCTRL_SPACEMIT_K1
 	bool "Spacemit K1 SoC pinctrl driver"
-	depends on PINCTRL_GENERIC && DM
+	depends on PINCTRL_GENERIC && DM && SYSCON
 	help
 	  Supports pin multiplexing control on Spacemit K1 SoCs.
 
drivers/pinctrl/spacemit/pinctrl-k1.c +81 -2

137 lines not on this page · raw message

Signature · 1 line
2.51.0
Reviewed-by on v4 2/10
#4 lore raw

Re: [PATCH v4 02/10] pinctrl: k1: add IO power domain configuration support

Quoted 18 lines · Eric Chung

Dual-voltage GPIO banks default to 3.3V, but when externally supplied with 1.8V the internal logic must be explicitly reconfigured to match.

Add the ability to program IO power domain control registers through the APBC block. These registers require unlocking the AIB Secure Access Register (ASAR) before every read/write, since configuring a 1.8V domain while 3.3V is externally supplied can cause back-powering and pin damage.

---
v3:
- Add SYSCON dependency in Kconfig.
- Fix not sorted issue in the driver.

---
 drivers/pinctrl/spacemit/Kconfig      |  2 +-
 drivers/pinctrl/spacemit/pinctrl-k1.c | 83 ++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 3 deletions(-)

...

Quoted 26 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +9 -2
index 3ebc397213b..95344f4ec72 100644
@@ -12,6 +12,8 @@
 #include <linux/bitops.h>
 #include <linux/errno.h>
 #include <linux/io.h>
+#include <regmap.h>
+#include <syscon.h>
 
 /*
  * +---------+----------+-----------+--------+--------+----------+--------+
@@ -34,8 +36,23 @@
 #define PAD_PULLUP		BIT(14)
 #define PAD_PULL_EN		BIT(15)
 
-#define PIN_POWER_STATE_1V8		1800
-#define PIN_POWER_STATE_3V3		3300
+#define IO_PWR_DOMAIN_OFFSET	0x800
+
+#define IO_PWR_DOMAIN_GPIO2_Kx  0x0c
+#define IO_PWR_DOMAIN_GPIO3_K1  0x10
+#define IO_PWR_DOMAIN_MMC_Kx    0x1c
+#define IO_PWR_DOMAIN_QSPI_K1   0x20
+

drivers/pinctrl/spacemit/pinctrl-k1.c line 55

Quoted 10 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +10 -0
+#define IO_PWR_DOMAIN_V18EN	BIT(2)
+
+#define APBC_ASFAR		0x50
+#define APBC_ASSAR		0x54
+
+#define APBC_ASFAR_AKEY		0xbaba
+#define APBC_ASSAR_AKEY		0xeb10
+
+#define PIN_POWER_STATE_1V8	1800
+#define PIN_POWER_STATE_3V3	3300

Space and TABs are both used to separate the identifiers with the values, please choose a unified style.

With this fixed,

Best regards,
Yao Zi

#5 lore raw

Re: [PATCH v4 02/10] pinctrl: k1: add IO power domain configuration support

In reply to Eric Chung

Hi Eric,

Thanks for your patch. However, I found a couple of issues while testing.

Quoted 35 lines · Eric Chung

Dual-voltage GPIO banks default to 3.3V, but when externally supplied with 1.8V the internal logic must be explicitly reconfigured to match.

Add the ability to program IO power domain control registers through the APBC block. These registers require unlocking the AIB Secure Access Register (ASAR) before every read/write, since configuring a 1.8V domain while 3.3V is externally supplied can cause back-powering and pin damage.

---
v3:
- Add SYSCON dependency in Kconfig.
- Fix not sorted issue in the driver.

---
 drivers/pinctrl/spacemit/Kconfig      |  2 +-
 drivers/pinctrl/spacemit/pinctrl-k1.c | 83 ++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 3 deletions(-)
drivers/pinctrl/spacemit/Kconfig +1 -1
index 6aab89e160c..ff754f5839c 100644
@@ -1,6 +1,6 @@
 config PINCTRL_SPACEMIT_K1
 	bool "Spacemit K1 SoC pinctrl driver"
-	depends on PINCTRL_GENERIC && DM
+	depends on PINCTRL_GENERIC && DM && SYSCON
 	help
 	  Supports pin multiplexing control on Spacemit K1 SoCs.
 
drivers/pinctrl/spacemit/pinctrl-k1.c +0 -0
index 3ebc397213b..95344f4ec72 100644

[...]

drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector, · line 530

Quoted 10 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +3 -0
+
 static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
 				unsigned int param, unsigned int argument)
 {
@@ -456,6 +526,9 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
 			dev_err(dev, "Invalid power source (%d)\n", argument);
 			return -EINVAL;
 		}
+		if (found)
+			spacemit_set_io_power_domain(dev, pin_selector,

CONFIG_PINCONF is not enabled in spacemit_k1_defconfig. Therefore, with the default configuration, the generic pinctrl code skips pin configuration properties and spacemit_pinconf_set() is never called. Consequently, the IO power domain configuration added here is not exercised when building with spacemit_k1_defconfig.

drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinctrl_probe(struct udevice *dev) · line 565

Quoted 13 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +6 -0
+						     priv->io_pins[i].io_type);
 		break;
 	default:
 		return -EOPNOTSUPP;
@@ -485,6 +558,11 @@ static int spacemit_pinctrl_probe(struct udevice *dev)
 		dev_err(dev, "Fail to allocate memory\n");
 		return -ENOMEM;
 	}
+	priv->regmap = syscon_regmap_lookup_by_phandle(dev, "spacemit,apbc");
+	if (IS_ERR(priv->regmap)) {
+		dev_warn(dev, "no syscon found, disable IO power domain switching\n");
+		priv->regmap = NULL;
+	}

The APBC node with compatible "spacemit,k1-syscon-apbc" is bound by drivers/clk/spacemit/clk-k1.c as a UCLASS_CLK device. It is not registered as a UCLASS_SYSCON device, and the node does not have the "syscon" compatible required by the fallback path in syscon_regmap_lookup_by_phandle(). Therefore, this lookup fails and priv->regmap is set to NULL.

I added a direct MMIO write to the UART registers here to confirm the failure path. The original dev_warn() is not visible because this probe happens before the normal console is initialized.

To fix this, I suggest either making the clock driver register or expose the APBC regmap through the syscon infrastructure, or avoiding syscon here and obtaining the regmap directly using dev_read_phandle_with_args() followed by regmap_init_mem().

Quoted 11 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +1 -0
 	ret = clk_get_bulk(dev, &clks);
 	if (ret) {
@@ -512,6 +590,7 @@ static const struct spacemit_pinctrl_data k1_pinctrl_data = {
 	.get_pins	= k1_get_pins,
 	.get_functions	= k1_get_functions,
 	.get_io_type	= k1_get_io_type,
+	.pin_to_io_pd_offset = spacemit_k1_pin_to_io_pd_offset,
 };
 
 static const struct udevice_id spacemit_pinctrl_ids[] = {
Signature · 2 lines
Best regards,
Junhui Liu
author
#6 lore raw

Re: [PATCH v4 02/10] pinctrl: k1: add IO power domain configuration support

Quoted 45 lines · Junhui Liu

Hi Eric,

Thanks for your patch. However, I found a couple of issues while testing.

Quoted 35 lines · Eric Chung

Dual-voltage GPIO banks default to 3.3V, but when externally supplied with 1.8V the internal logic must be explicitly reconfigured to match.

Add the ability to program IO power domain control registers through the APBC block. These registers require unlocking the AIB Secure Access Register (ASAR) before every read/write, since configuring a 1.8V domain while 3.3V is externally supplied can cause back-powering and pin damage.

---
v3:
- Add SYSCON dependency in Kconfig.
- Fix not sorted issue in the driver.

---
 drivers/pinctrl/spacemit/Kconfig      |  2 +-
 drivers/pinctrl/spacemit/pinctrl-k1.c | 83 ++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 3 deletions(-)
drivers/pinctrl/spacemit/Kconfig +1 -1
index 6aab89e160c..ff754f5839c 100644
@@ -1,6 +1,6 @@
 config PINCTRL_SPACEMIT_K1
      bool "Spacemit K1 SoC pinctrl driver"
-     depends on PINCTRL_GENERIC && DM
+     depends on PINCTRL_GENERIC && DM && SYSCON
      help
        Supports pin multiplexing control on Spacemit K1 SoCs.
 
drivers/pinctrl/spacemit/pinctrl-k1.c +0 -0
index 3ebc397213b..95344f4ec72 100644

[...]

Quoted 17 lines

drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector, · line 530

Quoted 10 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +3 -0
+
 static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
                              unsigned int param, unsigned int argument)
 {
@@ -456,6 +526,9 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,
                      dev_err(dev, "Invalid power source (%d)\n", argument);
                      return -EINVAL;
              }
+             if (found)
+                     spacemit_set_io_power_domain(dev, pin_selector,

CONFIG_PINCONF is not enabled in spacemit_k1_defconfig. Therefore, with the default configuration, the generic pinctrl code skips pin configuration properties and spacemit_pinconf_set() is never called. Consequently, the IO power domain configuration added here is not exercised when building with spacemit_k1_defconfig.

I've enabled CONFIG_PINCONF in the #5 patch of the patch set.

Quoted 21 lines

drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinctrl_probe(struct udevice *dev) · line 565

Quoted 13 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +6 -0
+                                                  priv->io_pins[i].io_type);
              break;
      default:
              return -EOPNOTSUPP;
@@ -485,6 +558,11 @@ static int spacemit_pinctrl_probe(struct udevice *dev)
              dev_err(dev, "Fail to allocate memory\n");
              return -ENOMEM;
      }
+     priv->regmap = syscon_regmap_lookup_by_phandle(dev, "spacemit,apbc");
+     if (IS_ERR(priv->regmap)) {
+             dev_warn(dev, "no syscon found, disable IO power domain switching\n");
+             priv->regmap = NULL;
+     }

The APBC node with compatible "spacemit,k1-syscon-apbc" is bound by drivers/clk/spacemit/clk-k1.c as a UCLASS_CLK device. It is not registered as a UCLASS_SYSCON device, and the node does not have the "syscon" compatible required by the fallback path in syscon_regmap_lookup_by_phandle(). Therefore, this lookup fails and priv->regmap is set to NULL.

Quoted 9 lines

I added a direct MMIO write to the UART registers here to confirm the failure path. The original dev_warn() is not visible because this probe happens before the normal console is initialized.

To fix this, I suggest either making the clock driver register or expose the APBC regmap through the syscon infrastructure, or avoiding syscon here and obtaining the regmap directly using dev_read_phandle_with_args() followed by regmap_init_mem().

Thanks. Let me check this.

Quoted 16 lines

drivers/pinctrl/spacemit/pinctrl-k1.c static const struct spacemit_pinctrl_data k1_pinctrl_data = { · line 596

Quoted 11 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +1 -0
      ret = clk_get_bulk(dev, &clks);
      if (ret) {
@@ -512,6 +590,7 @@ static const struct spacemit_pinctrl_data k1_pinctrl_data = {
      .get_pins       = k1_get_pins,
      .get_functions  = k1_get_functions,
      .get_io_type    = k1_get_io_type,
+     .pin_to_io_pd_offset = spacemit_k1_pin_to_io_pd_offset,
 };
 
 static const struct udevice_id spacemit_pinctrl_ids[] = {

--
Best regards,
Junhui Liu

author
#7 lore raw

PATCH v4 3/10 mmc: enable CMD23 for multi-block transfers

In reply to Eric Chung

Enable the support for the CMD23 (SET_BLOCK_COUNT) command to manage multi-block read/write operations. This allows the MMC core to use CMD23 in preference to the legacy CMD18/CMD25 plus CMD12 sequence, reducing command overhead and improving I/O performance on multi-block transfers.

---
v4:
- Add CMD23 on write.
- Fix on using CMD23 only for CMD18/CMD25.
v3:
- Avoid to use quirk to enable CMD23. Use capability instead.

---
 drivers/mmc/mmc.c       | 16 +++++++++++++++-
 drivers/mmc/mmc_write.c | 19 +++++++++++++++----
 include/mmc.h           |  3 +++
 3 files changed, 33 insertions(+), 5 deletions(-)
drivers/mmc/mmc.c +15 -1
index f0e38efb262..9cd9307c8cd 100644
@@ -461,6 +461,14 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
 	struct mmc_cmd cmd;
 	struct mmc_data data;
 
+	if (blkcnt > 1 && mmc->host_caps & MMC_CAP_CMD23) {
+		cmd.cmdidx = MMC_CMD_SET_BLOCK_COUNT;
+		cmd.cmdarg = blkcnt & 0x0000ffff;
+		cmd.resp_type = MMC_RSP_R1;
+		if (mmc_send_cmd(mmc, &cmd, NULL))
+			return 0;
+	}
+
 	if (blkcnt > 1)
 		cmd.cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK;
 	else
@@ -481,7 +489,7 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
 	if (mmc_send_cmd(mmc, &cmd, &data))
 		return 0;
 
-	if (blkcnt > 1) {
+	if (blkcnt > 1 && !(mmc->host_caps & MMC_CAP_CMD23)) {
 		if (mmc_send_stop_transmission(mmc, false)) {
 #if !defined(CONFIG_XPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
 			log_err("mmc fail to send stop cmd\n");
@@ -1037,6 +1045,10 @@ static int mmc_get_capabilities(struct mmc *mmc)
 
 	mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(MMC_LEGACY);
 
+	/* CMD23(SET_BLOCK_COUNT) requires eMMC spec v3.1 or above */
+	if (mmc->version < MMC_VERSION_3)
+		mmc->host_caps &= ~MMC_CAP_CMD23;
+
 	if (mmc_host_is_spi(mmc))
 		return 0;
 
@@ -1436,6 +1448,8 @@ static int sd_get_capabilities(struct mmc *mmc)
 
 	if (mmc->scr[0] & SD_DATA_4BIT)
 		mmc->card_caps |= MMC_MODE_4BIT;
+	if (!(mmc->scr[0] & SD_SCR_CMD23_SUPPORT))
+		mmc->host_caps &= ~MMC_CAP_CMD23;
 
 	/* Version 1.0 doesn't support switching */
 	if (mmc->version == SD_VERSION_1_0)
drivers/mmc/mmc_write.c +15 -4
index 928c05872ca..971e61295a1 100644
@@ -165,7 +165,15 @@ static ulong mmc_write_blocks(struct mmc *mmc, lbaint_t start,
 
 	if (blkcnt == 0)
 		return 0;
-	else if (blkcnt == 1)
+	if (blkcnt > 1 && mmc->host_caps & MMC_CAP_CMD23) {
+		cmd.cmdidx = MMC_CMD_SET_BLOCK_COUNT;
+		cmd.cmdarg = blkcnt & 0x0000ffff;
+		cmd.resp_type = MMC_RSP_R1;
+		if (mmc_send_cmd(mmc, &cmd, NULL))
+			return 0;
+	}
+
+	if (blkcnt == 1)
 		cmd.cmdidx = MMC_CMD_WRITE_SINGLE_BLOCK;
 	else
 		cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
@@ -191,10 +199,13 @@ static ulong mmc_write_blocks(struct mmc *mmc, lbaint_t start,
 		 */
 	}
 
-	/* SPI multiblock writes terminate using a special
-	 * token, not a STOP_TRANSMISSION request.
+	/*
+	 * SPI multiblock writes terminate using a special token, not CMD12.
+	 * When CMD23 was issued the card auto-terminates, so CMD12 is also
+	 * skipped in that case.
 	 */
-	if (!mmc_host_is_spi(mmc) && blkcnt > 1) {
+	if (!mmc_host_is_spi(mmc) && blkcnt > 1 &&
+	    !(mmc->host_caps & MMC_CAP_CMD23)) {
 		cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
 		cmd.cmdarg = 0;
 		cmd.resp_type = MMC_RSP_R1b;
include/mmc.h +3 -0
index 9509c9e9543..4bda44ea220 100644
@@ -67,6 +67,7 @@ struct bd_info;
 #define MMC_CAP_NONREMOVABLE	BIT(14)
 #define MMC_CAP_NEEDS_POLL	BIT(15)
 #define MMC_CAP_CD_ACTIVE_HIGH  BIT(16)
+#define MMC_CAP_CMD23		BIT(17)
 
 #define MMC_MODE_8BIT		BIT(30)
 #define MMC_MODE_4BIT		BIT(29)
@@ -141,6 +142,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
 #define SD_HIGHSPEED_BUSY	0x00020000
 #define SD_HIGHSPEED_SUPPORTED	0x00020000
 
+#define SD_SCR_CMD23_SUPPORT	BIT(1)
+
 #define UHS_SDR12_BUS_SPEED	0
 #define HIGH_SPEED_BUS_SPEED	1
 #define UHS_SDR25_BUS_SPEED	1
Signature · 1 line
2.51.0
#8 lore raw

Re: [PATCH v4 03/10] mmc: enable CMD23 for multi-block transfers

Quoted 5 lines · Eric Chung

Enable the support for the CMD23 (SET_BLOCK_COUNT) command to manage multi-block read/write operations. This allows the MMC core to use CMD23 in preference to the legacy CMD18/CMD25 plus CMD12 sequence, reducing command overhead and improving I/O performance on multi-block transfers.

From the description, it seems CMD23 support isn't essential for MMC support on SpacemiT K1? If so, it might be helpful to separate MMC core changes into another series, and focus on basic support only. A smaller series is easier to track and review.

Quoted 2 lines

Regards,
Yao Zi

author
#9 lore raw

Re: [PATCH v4 03/10] mmc: enable CMD23 for multi-block transfers

Quoted 8 lines · Yao Zi
Quoted 5 lines · Eric Chung

Enable the support for the CMD23 (SET_BLOCK_COUNT) command to manage multi-block read/write operations. This allows the MMC core to use CMD23 in preference to the legacy CMD18/CMD25 plus CMD12 sequence, reducing command overhead and improving I/O performance on multi-block transfers.

Quoted 5 lines

From the description, it seems CMD23 support isn't essential for MMC support on SpacemiT K1? If so, it might be helpful to separate MMC core changes into another series, and focus on basic support only. A smaller series is easier to track and review.

Actually CMD23 is necessary for Spacemit K1. So I can't split it from this series.

Best Regards
Haojian

author
#10 lore raw

Re: [PATCH v4 03/10] mmc: enable CMD23 for multi-block transfers

Quoted 10 lines · Eric Chung
Quoted 8 lines · Yao Zi
Quoted 5 lines · Eric Chung

Enable the support for the CMD23 (SET_BLOCK_COUNT) command to manage multi-block read/write operations. This allows the MMC core to use CMD23 in preference to the legacy CMD18/CMD25 plus CMD12 sequence, reducing command overhead and improving I/O performance on multi-block transfers.

Quoted 8 lines
Quoted 5 lines

From the description, it seems CMD23 support isn't essential for MMC support on SpacemiT K1? If so, it might be helpful to separate MMC core changes into another series, and focus on basic support only. A smaller series is easier to track and review.

Actually CMD23 is necessary for Spacemit K1. So I can't split it from this series.

If I use ADMA mode, CMD23 is required. If I'm using PIO mode, CMD23 isn't required. So I prefer it go through this series.

If the reason isn't solid, I can split it into another patch set.

Best Regards
Eric

#11 lore raw

Re: [PATCH v4 03/10] mmc: enable CMD23 for multi-block transfers

Hi Eric,

Quoted 13 lines · Eric Chung
Quoted 12 lines · Eric Chung
Quoted 11 lines · Yao Zi
Quoted 5 lines · Eric Chung

Enable the support for the CMD23 (SET_BLOCK_COUNT) command to manage multi-block read/write operations. This allows the MMC core to use CMD23 in preference to the legacy CMD18/CMD25 plus CMD12 sequence, reducing command overhead and improving I/O performance on multi-block transfers.

From the description, it seems CMD23 support isn't essential for MMC
support on SpacemiT K1? If so, it might be helpful to separate MMC core changes into another series, and focus on basic support only. A smaller series is easier to track and review.

Quoted 8 lines
Quoted 3 lines

Actually CMD23 is necessary for Spacemit K1. So I can't split it from this series.

If I use ADMA mode, CMD23 is required. If I'm using PIO mode, CMD23 isn't required. So I prefer it go through this series.

If the reason isn't solid, I can split it into another patch set.

Both CMD23 and CMD12 are valid mechanisms to terminate a multi-block transfer: CMD23 (SET_BLOCK_COUNT) is issued before the transfer so the card auto-terminates, while CMD12 (STOP_TRANSMISSION) is issued after the last block. The u-boot MMC core already has CMD12 support in place, so multi-block transfers work today without CMD23.

Given that, I agree with Yao Zi's suggestion - splitting the CMD23 changes into a separate series would make both series easier to review and merge.

That said, Is there a specific hardware issue on the K1 board where CMD12 does not work correctly?

#12 lore raw

Re: [PATCH v4 03/10] mmc: enable CMD23 for multi-block transfers

Quoted 32 lines · Tanmay

Hi Eric,

Quoted 13 lines · Eric Chung
Quoted 12 lines · Eric Chung
Quoted 11 lines · Yao Zi
Quoted 5 lines · Eric Chung

Enable the support for the CMD23 (SET_BLOCK_COUNT) command to manage multi-block read/write operations. This allows the MMC core to use CMD23 in preference to the legacy CMD18/CMD25 plus CMD12 sequence, reducing command overhead and improving I/O performance on multi-block transfers.

From the description, it seems CMD23 support isn't essential for MMC
support on SpacemiT K1? If so, it might be helpful to separate MMC core changes into another series, and focus on basic support only. A smaller series is easier to track and review.

Quoted 8 lines
Quoted 3 lines

Actually CMD23 is necessary for Spacemit K1. So I can't split it from this series.

If I use ADMA mode, CMD23 is required. If I'm using PIO mode, CMD23 isn't required. So I prefer it go through this series.

If the reason isn't solid, I can split it into another patch set.

Both CMD23 and CMD12 are valid mechanisms to terminate a multi-block transfer: CMD23 (SET_BLOCK_COUNT) is issued before the transfer so the card auto-terminates, while CMD12 (STOP_TRANSMISSION) is issued after the last block. The u-boot MMC core already has CMD12 support in place, so multi-block transfers work today without CMD23.

Quoted 6 lines

Given that, I agree with Yao Zi's suggestion - splitting the CMD23 changes into a separate series would make both series easier to review and merge.

That said, Is there a specific hardware issue on the K1 board where CMD12 does not work correctly?

I don't think it's a hardware issue. The ADMA just depends on CMD23.

author
#13 lore raw

PATCH v4 4/10 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.

---
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 | 685 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 693 insertions(+)
drivers/mmc/Kconfig +7 -0
index 131be3106a1..f05b376ab72 100644
@@ -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
index a23336d7d8d..aa05cec23be 100644
@@ -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 +685 -0

685 lines not on this page · raw message

Signature · 1 line
2.51.0
#14 lore raw

Re: [PATCH v4 04/10] mmc: k1: add sdhci platform driver

Quoted 22 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.

---
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 | 685 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 693 insertions(+)

...

Quoted 6 lines
drivers/mmc/spacemit_sdhci.c new file +0 -0
new file mode 100644
index 00000000000..1c7dd3a5870
@@ -0,0 +1,685 @@

...

drivers/mmc/spacemit_sdhci.c line 76

Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4 -0
+#define SPACEMIT_SDHC_RX_CFG_REG        0x118
+#define  SDHC_RX_SDCLK_SEL0_MASK        GENMASK(1, 0)
+#define  SDHC_RX_SDCLK_SEL1_MASK        GENMASK(3, 2)
+#define  SDHC_RX_SDCLK_SEL1             FIELD_PREP(SDHC_RX_SDCLK_SEL1_MASK, 1)

Space and TABs are both used in definitions of macros in this file, please choose a consistent style.

...

Quoted 56 lines
drivers/mmc/spacemit_sdhci.c new file +56 -0
+static int spacemit_sdhci_set_vqmmc_voltage(struct mmc *mmc, int voltage)
+{
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+	int ret;
+
+	if (!mmc->vqmmc_supply)
+		return 0;
+
+	ret = regulator_set_value(mmc->vqmmc_supply, voltage);
+	if (ret) {
+		log_err("failed to set vqmmc voltage to %d.%dV\n",
+			voltage / 1000000, (voltage / 100000) % 10);
+		return ret;
+	}
+	ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true);
+	if (ret) {
+		log_err("failed to enable vqmmc supply\n");
+		return ret;
+	}
+#endif
+	return 0;
+}
+
+static void spacemit_sdhci_set_voltage(struct sdhci_host *host)
+{
+	if (IS_ENABLED(CONFIG_MMC_IO_VOLTAGE)) {
+		struct mmc *mmc = host->mmc;
+		u32 ctrl;
+
+		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+
+		switch (mmc->signal_voltage) {
+		case MMC_SIGNAL_VOLTAGE_330:
+		case MMC_SIGNAL_VOLTAGE_180: {
+			bool to_180 = mmc->signal_voltage ==
+				      MMC_SIGNAL_VOLTAGE_180;
+			bool ok;
+			int voltage_mv = to_180 ? 1800000 : 3300000;
+
+			if (spacemit_sdhci_set_vqmmc_voltage(mmc, voltage_mv))
+				return;
+			if (!IS_SD(mmc))
+				return;
+			if (to_180)
+				ctrl |= SDHCI_CTRL_VDD_180;
+			else
+				ctrl &= ~SDHCI_CTRL_VDD_180;
+			sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+			mdelay(5);
+
+			ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+			ok = !!(ctrl & SDHCI_CTRL_VDD_180) == to_180;
+			if (ok)
+				return;
+

drivers/mmc/spacemit_sdhci.c line 283

Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10 -0
+			log_err("%d.%dV regulator output not stable\n",
+				voltage_mv / 1000000,
+				(voltage_mv / 100000) % 10);
+			break;
+		}
+		default:
+			/* No signal voltage switch required */
+			return;
+		}
+	}

It seems the only difference between spacemit_sdhci_set_voltage() and sdhci_set_voltage() is that the earlier doesn't disable vqmmc before changing its voltage, is this really necessary, since I don't see similar behavior in the kernel MMC driver? And if it is, please point the difference out in comment, and explain why if possible.

Quoted 1 line

+}

...

drivers/mmc/spacemit_sdhci.c line 322

Quoted 12 lines
drivers/mmc/spacemit_sdhci.c new file +12 -0
+static int spacemit_sdhci_wait_dat0(struct udevice *dev, int state,
+				    int timeout_us)
+{
+	struct mmc *mmc = mmc_get_mmc_dev(dev);
+	struct sdhci_host *host = mmc->priv;
+	unsigned long timeout = timer_get_us() + timeout_us;
+	u32 tmp;
+
+	/*
+	 * readx_poll_timeout is unsuitable because sdhci_readl accepts
+	 * two arguments
+	 */

But read_poll_timeout() accepts op with arbitrary number of arguments, could it be used?

Quoted 14 lines
drivers/mmc/spacemit_sdhci.c new file +14 -0
+	do {
+		tmp = sdhci_readl(host, SDHCI_PRESENT_STATE);
+		if (!!(tmp & SDHCI_DATA_0_LVL_MASK) == !!state) {
+			if (spacemit_sdhci_is_voltage_switch_cmd(host))
+				spacemit_sdhci_set_clk_gate(host, 1);
+			return 0;
+		}
+	} while (!timeout_us || !time_after(timer_get_us(), timeout));
+
+	return -ETIMEDOUT;
+}
+
+static void spacemit_sdhci_set_control_reg(struct sdhci_host *host)
+{

...

drivers/mmc/spacemit_sdhci.c line 367

Quoted 6 lines
drivers/mmc/spacemit_sdhci.c new file +6 -0
+	/* Set pinctrl state */
+	if (IS_ENABLED(CONFIG_PINCTRL)) {
+		if (mmc->clock >= 200000000)
+			pinctrl_select_state(mmc->dev, "uhs");
+		else
+			pinctrl_select_state(mmc->dev, "default");

Shouldn't pinctrl setting be switched based on mode (whether it's UHS or not) instead of clock frequency, as what has been done in the kernel side?

In v1 of this series, the spacemit_sdhci_set_aib_mmc1_io() is also called with the selected signal voltage, so I think voltage switching logic is incorrect here.

...

Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7 -0
+#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
+static int spacemit_sdhci_phy_dll_init(struct sdhci_host *host)
+{
+	u32 reg;
+	int i;
+
+	/* Configure DLL predly, fulldly, and vreg */

drivers/mmc/spacemit_sdhci.c line 509

Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10 -0
+	spacemit_sdhci_clrsetbits(host, SDHC_DLL_PREDLY_NUM |
+				  SDHC_DLL_FULLDLY_RANGE |
+				  SDHC_DLL_VREG_CTRL,
+				  FIELD_PREP(SDHC_DLL_PREDLY_NUM, 1) |
+				  FIELD_PREP(SDHC_DLL_FULLDLY_RANGE, 1) |
+				  FIELD_PREP(SDHC_DLL_VREG_CTRL, 1),
+				  SPACEMIT_SDHC_PHY_DLLCFG);
+
+	reg = sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLCFG1);
+	reg |= FIELD_PREP(SDHC_DLL_REG1_CTRL, 0x92);

What does 0x92 mean here? Please define it as a macro with meaningful name if possible, like SPACEMIT_SDHC_PHY_DLLCFG's case.

Quoted 1 line
drivers/mmc/spacemit_sdhci.c new file +1 -0
+	sdhci_writel(host, reg, SPACEMIT_SDHC_PHY_DLLCFG1);

...

drivers/mmc/spacemit_sdhci.c line 527

Quoted 11 lines
drivers/mmc/spacemit_sdhci.c new file +11 -0
+	/* Wait for DLL lock */
+	i = 0;
+	while (i++ < 100) {
+		if (sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLSTS) & SDHC_DLL_LOCK_STATE)
+			break;
+		udelay(10);
+	}
+	if (i == 100) {
+		log_err("%s: phy dll lock timeout\n", host->name);
+		return -ETIMEDOUT;
+	}

Please use read*_poll_timeout() family to replace the loop and the following check.

Quoted 3 lines
drivers/mmc/spacemit_sdhci.c new file +3 -0
+
+	return 0;
+}

...

Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2 -0
+static int spacemit_sdhci_probe(struct udevice *dev)
+{

...

drivers/mmc/spacemit_sdhci.c line 609

Quoted 1 line
drivers/mmc/spacemit_sdhci.c new file +1 -0
+	/* Set quirks */

I think it's obvious, and there's no need to comment it, but

drivers/mmc/spacemit_sdhci.c line 614

Quoted 5 lines
drivers/mmc/spacemit_sdhci.c new file +5 -0
+	if (IS_ENABLED(CONFIG_SPL_BUILD))
+		host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
+	else
+		host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
+				SDHCI_QUIRK_32BIT_DMA_ADDR;

Why SDHCI_QUIRK_32BIT_DMA_ADDR is only enabled in SPL build? Even it isn't used by any code, it shouldn't hurt to set the flag, which is less confusing.

...

drivers/mmc/spacemit_sdhci.c line 670

Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4 -0
+static const struct udevice_id spacemit_sdhci_ids[] = {
+	{
+		.compatible = "spacemit,k1-sdhci",
+		.data = 0,

Uninitialized fields of static variables are automatically zeroed in C, so please remove this assignment.

drivers/mmc/spacemit_sdhci.c line 673

Quoted 3 lines
drivers/mmc/spacemit_sdhci.c new file +3 -0
+	}, {
+	}
+};

Regards,
Yao Zi

#15 lore raw

Re: [PATCH v4 04/10] mmc: k1: add sdhci platform driver

Quoted 110 lines · Yao Zi
Quoted 22 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.

---
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 | 685 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 693 insertions(+)

...

Quoted 6 lines
drivers/mmc/spacemit_sdhci.c new file +0 -0
new file mode 100644
index 00000000000..1c7dd3a5870
@@ -0,0 +1,685 @@

...

drivers/mmc/spacemit_sdhci.c line 76

Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4 -0
+#define SPACEMIT_SDHC_RX_CFG_REG        0x118
+#define  SDHC_RX_SDCLK_SEL0_MASK        GENMASK(1, 0)
+#define  SDHC_RX_SDCLK_SEL1_MASK        GENMASK(3, 2)
+#define  SDHC_RX_SDCLK_SEL1             FIELD_PREP(SDHC_RX_SDCLK_SEL1_MASK, 1)

Space and TABs are both used in definitions of macros in this file, please choose a consistent style.

...

Quoted 64 lines
drivers/mmc/spacemit_sdhci.c new file +64 -0
+static int spacemit_sdhci_set_vqmmc_voltage(struct mmc *mmc, int voltage)
+{
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+     int ret;
+
+     if (!mmc->vqmmc_supply)
+             return 0;
+
+     ret = regulator_set_value(mmc->vqmmc_supply, voltage);
+     if (ret) {
+             log_err("failed to set vqmmc voltage to %d.%dV\n",
+                     voltage / 1000000, (voltage / 100000) % 10);
+             return ret;
+     }
+     ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true);
+     if (ret) {
+             log_err("failed to enable vqmmc supply\n");
+             return ret;
+     }
+#endif
+     return 0;
+}
+
+static void spacemit_sdhci_set_voltage(struct sdhci_host *host)
+{
+     if (IS_ENABLED(CONFIG_MMC_IO_VOLTAGE)) {
+             struct mmc *mmc = host->mmc;
+             u32 ctrl;
+
+             ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+
+             switch (mmc->signal_voltage) {
+             case MMC_SIGNAL_VOLTAGE_330:
+             case MMC_SIGNAL_VOLTAGE_180: {
+                     bool to_180 = mmc->signal_voltage ==
+                                   MMC_SIGNAL_VOLTAGE_180;
+                     bool ok;
+                     int voltage_mv = to_180 ? 1800000 : 3300000;
+
+                     if (spacemit_sdhci_set_vqmmc_voltage(mmc, voltage_mv))
+                             return;
+                     if (!IS_SD(mmc))
+                             return;
+                     if (to_180)
+                             ctrl |= SDHCI_CTRL_VDD_180;
+                     else
+                             ctrl &= ~SDHCI_CTRL_VDD_180;
+                     sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+
+                     mdelay(5);
+
+                     ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+                     ok = !!(ctrl & SDHCI_CTRL_VDD_180) == to_180;
+                     if (ok)
+                             return;
+
+                     log_err("%d.%dV regulator output not stable\n",
+                             voltage_mv / 1000000,
+                             (voltage_mv / 100000) % 10);
+                     break;
+             }
+             default:
+                     /* No signal voltage switch required */
+                     return;
Quoted 9 lines

drivers/mmc/spacemit_sdhci.c

Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2 -0
+             }
+     }

It seems the only difference between spacemit_sdhci_set_voltage() and sdhci_set_voltage() is that the earlier doesn't disable vqmmc before changing its voltage, is this really necessary, since I don't see similar behavior in the kernel MMC driver? And if it is, please point the difference out in comment, and explain why if possible.

I can't find the code of disabling vqmmc before changing its voltage in kernel. mmc_regulator_set_vqmmc() only sets the voltage directly.

Quoted 44 lines
Quoted 1 line

+}

...

drivers/mmc/spacemit_sdhci.c line 322

Quoted 12 lines
drivers/mmc/spacemit_sdhci.c new file +12 -0
+static int spacemit_sdhci_wait_dat0(struct udevice *dev, int state,
+                                 int timeout_us)
+{
+     struct mmc *mmc = mmc_get_mmc_dev(dev);
+     struct sdhci_host *host = mmc->priv;
+     unsigned long timeout = timer_get_us() + timeout_us;
+     u32 tmp;
+
+     /*
+      * readx_poll_timeout is unsuitable because sdhci_readl accepts
+      * two arguments
+      */

But read_poll_timeout() accepts op with arbitrary number of arguments, could it be used?

Quoted 14 lines
drivers/mmc/spacemit_sdhci.c new file +14 -0
+     do {
+             tmp = sdhci_readl(host, SDHCI_PRESENT_STATE);
+             if (!!(tmp & SDHCI_DATA_0_LVL_MASK) == !!state) {
+                     if (spacemit_sdhci_is_voltage_switch_cmd(host))
+                             spacemit_sdhci_set_clk_gate(host, 1);
+                     return 0;
+             }
+     } while (!timeout_us || !time_after(timer_get_us(), timeout));
+
+     return -ETIMEDOUT;
+}
+
+static void spacemit_sdhci_set_control_reg(struct sdhci_host *host)
+{

...

drivers/mmc/spacemit_sdhci.c line 367

Quoted 6 lines
drivers/mmc/spacemit_sdhci.c new file +6 -0
+     /* Set pinctrl state */
+     if (IS_ENABLED(CONFIG_PINCTRL)) {
+             if (mmc->clock >= 200000000)
+                     pinctrl_select_state(mmc->dev, "uhs");
+             else
+                     pinctrl_select_state(mmc->dev, "default");
Quoted 4 lines

Shouldn't pinctrl setting be switched based on mode (whether it's UHS or not) instead of clock frequency, as what has been done in the kernel side?

OK. I'll switch it based on mode.

Quoted 4 lines

In v1 of this series, the spacemit_sdhci_set_aib_mmc1_io() is also called with the selected signal voltage, so I think voltage switching logic is incorrect here.

I moved the content of spacemit_sdhci_set_aib_mmc1_io() into pinctrl driver.

Quoted 83 lines

...

Quoted 7 lines
drivers/mmc/spacemit_sdhci.c new file +7 -0
+#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
+static int spacemit_sdhci_phy_dll_init(struct sdhci_host *host)
+{
+     u32 reg;
+     int i;
+
+     /* Configure DLL predly, fulldly, and vreg */

drivers/mmc/spacemit_sdhci.c line 509

Quoted 10 lines
drivers/mmc/spacemit_sdhci.c new file +10 -0
+     spacemit_sdhci_clrsetbits(host, SDHC_DLL_PREDLY_NUM |
+                               SDHC_DLL_FULLDLY_RANGE |
+                               SDHC_DLL_VREG_CTRL,
+                               FIELD_PREP(SDHC_DLL_PREDLY_NUM, 1) |
+                               FIELD_PREP(SDHC_DLL_FULLDLY_RANGE, 1) |
+                               FIELD_PREP(SDHC_DLL_VREG_CTRL, 1),
+                               SPACEMIT_SDHC_PHY_DLLCFG);
+
+     reg = sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLCFG1);
+     reg |= FIELD_PREP(SDHC_DLL_REG1_CTRL, 0x92);

What does 0x92 mean here? Please define it as a macro with meaningful name if possible, like SPACEMIT_SDHC_PHY_DLLCFG's case.

Quoted 1 line

+ sdhci_writel(host, reg, SPACEMIT_SDHC_PHY_DLLCFG1);

...

drivers/mmc/spacemit_sdhci.c line 527

Quoted 11 lines
drivers/mmc/spacemit_sdhci.c new file +11 -0
+     /* Wait for DLL lock */
+     i = 0;
+     while (i++ < 100) {
+             if (sdhci_readl(host, SPACEMIT_SDHC_PHY_DLLSTS) & SDHC_DLL_LOCK_STATE)
+                     break;
+             udelay(10);
+     }
+     if (i == 100) {
+             log_err("%s: phy dll lock timeout\n", host->name);
+             return -ETIMEDOUT;
+     }

Please use read*_poll_timeout() family to replace the loop and the following check.

Quoted 3 lines
drivers/mmc/spacemit_sdhci.c new file +3 -0
+
+     return 0;
+}

...

Quoted 2 lines
drivers/mmc/spacemit_sdhci.c new file +2 -0
+static int spacemit_sdhci_probe(struct udevice *dev)
+{

...

Quoted 1 line

+ /* Set quirks */

I think it's obvious, and there's no need to comment it, but

drivers/mmc/spacemit_sdhci.c line 614

Quoted 5 lines
drivers/mmc/spacemit_sdhci.c new file +5 -0
+     if (IS_ENABLED(CONFIG_SPL_BUILD))
+             host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
+     else
+             host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
+                             SDHCI_QUIRK_32BIT_DMA_ADDR;

Why SDHCI_QUIRK_32BIT_DMA_ADDR is only enabled in SPL build? Even it isn't used by any code, it shouldn't hurt to set the flag, which is less confusing.

...

drivers/mmc/spacemit_sdhci.c line 670

Quoted 4 lines
drivers/mmc/spacemit_sdhci.c new file +4 -0
+static const struct udevice_id spacemit_sdhci_ids[] = {
+     {
+             .compatible = "spacemit,k1-sdhci",
+             .data = 0,

Uninitialized fields of static variables are automatically zeroed in C, so please remove this assignment.

drivers/mmc/spacemit_sdhci.c line 673

Quoted 3 lines
drivers/mmc/spacemit_sdhci.c new file +3 -0
+     }, {
+     }
+};

Regards,
Yao Zi

author
#16 lore raw

PATCH v4 5/10 dts: k1: add SD card support in u-boot overlay

In reply to Eric Chung

Add the SDH0 controller node and its pinctrl groups to the u-boot overlay. The upstream DTS only contains the eMMC node; the SD card controller (sdhci@d4280000) and its MMC1 pinctrl configuration are missing. Place the new node inside the storage-bus via path-based merge so it inherits the dma-ranges from the parent bus.

---
v3:
- Fix SD pinctrl as uhs.
v2:
- Use vmmc-supply as vqmmc-supply on SD node.
- Add alias of mmc0 and mmc1.

---
 arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 87 ++++++++++++++++++++++++++++++-
 arch/riscv/dts/k1-musepi-pro-u-boot.dtsi  | 82 ++++++++++++++++++++++++++++-
 2 files changed, 165 insertions(+), 4 deletions(-)
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi +85 -2
index 7f9443d6951..582bd61d27c 100644
@@ -6,6 +6,11 @@
 #include "binman.dtsi"
 
 / {
+	aliases {
+		mmc0 = &emmc;
+		mmc1 = &sdhci0;
+	};
+
 	memory@0 {
 		device_type = "memory";
 		reg = <0x00000000 0x00000000 0x00000000 0x80000000>;
@@ -76,12 +81,14 @@
 				bootph-pre-ram;
 			};
 
-			buck3 {
+			buck3_1v8: buck3 {
 				regulator-name = "vdd_1v8";
 				bootph-pre-ram;
 			};
 
-			aldo1 {
+			buck4_3v3: buck4 { };
+
+			aldo1: aldo1 {
 				regulator-name = "vdd_1v8_mmc";
 				bootph-pre-ram;
 			};
@@ -89,6 +96,82 @@
 	};
 };
 
+/ {
+	soc {
+		storage-bus {
+			sdhci0: mmc@d4280000 {
+				bootph-pre-ram;
+				compatible = "spacemit,k1-sdhci";
+				reg = <0x0 0xd4280000 0x0 0x200>;
+				clocks = <&syscon_apmu CLK_SDH_AXI>,
+					 <&syscon_apmu CLK_SDH0>;
+				clock-names = "core", "io";
+				interrupts = <99>;
+				resets = <&syscon_apmu RESET_SDH_AXI>,
+					 <&syscon_apmu RESET_SDH0>;
+				reset-names = "sdh_axi", "sdh0";
+				bus-width = <4>;
+				max-frequency = <204800000>;
+				cd-gpios = <&gpio K1_GPIO(80) GPIO_ACTIVE_LOW>;
+				pinctrl-names = "default", "uhs";
+				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 {			/* uhs */
+		grp_cmd_data {
+			pinmux = <K1_PADCONF(104, 0)>,  /* MMC1_DAT3 */
+				 <K1_PADCONF(105, 0)>,  /* MMC1_DAT2 */
+				 <K1_PADCONF(106, 0)>,  /* MMC1_DAT1 */
+				 <K1_PADCONF(107, 0)>,  /* MMC1_DAT0 */
+				 <K1_PADCONF(108, 0)>;  /* MMC1_CMD */
+			bias-pull-up = <1>;
+			drive-strength = <42>;
+		};
+		grp_clk {
+			pinmux = <K1_PADCONF(109, 0)>;  /* MMC1_CLK */
+			bias-pull-down = <1>;
+			drive-strength = <42>;
+		};
+	};
+};
+
+&emmc {
+	bootph-pre-ram;
+	resets = <&syscon_apmu RESET_SDH_AXI>, <&syscon_apmu RESET_SDH2>;
+	reset-names = "sdh_axi", "sdh2";
+	vqmmc-supply = <&buck3_1v8>;
+	vmmc-supply = <&aldo1>;
+	max-frequency = <204800000>;
+};
+
+&sdhci0 {
+	vmmc-supply = <&buck4_3v3>;
+};
+
 &binman {
 	u-boot-spl-ddr {
 		type = "section";
arch/riscv/dts/k1-musepi-pro-u-boot.dtsi +80 -2

106 lines not on this page · raw message

Signature · 1 line
2.51.0
#17 lore raw

Re: [PATCH v4 05/10] dts: k1: add SD card support in u-boot overlay

Quoted 14 lines · Eric Chung

Add the SDH0 controller node and its pinctrl groups to the u-boot overlay. The upstream DTS only contains the eMMC node; the SD card controller (sdhci@d4280000) and its MMC1 pinctrl configuration are missing. Place the new node inside the storage-bus via path-based merge so it inherits the dma-ranges from the parent bus.

---
v3:
- Fix SD pinctrl as uhs.
v2:
- Use vmmc-supply as vqmmc-supply on SD node.
- Add alias of mmc0 and mmc1.

Quoted 4 lines
---
 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(-)

Please note SD-card-related devicetree changes for BPI-F3 and MusePi Pro have been landed in devicetree upstream, and you should be able to pick them with tools/update-subtree.sh.

Regards,
Yao Zi

author
#18 lore raw

PATCH v4 6/10 configs: k1: enable SD and eMMC support

In reply to Eric Chung

Enable high-speed MMC modes.

---
v2:
- Enable ADMA support.
- Enable SYSCON support.

---
 board/spacemit/k1/MAINTAINERS |  1 +
 configs/spacemit_k1_defconfig | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
board/spacemit/k1/MAINTAINERS +1 -0
index 32d47ecc8f1..ca994e2a1fb 100644
@@ -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 +19 -0
index 81409c844a6..886679367a9 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
@@ -87,6 +89,21 @@ CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_MEM=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x000a0000
 CONFIG_CMD_SPI=y
+CONFIG_MMC=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_ADMA=y
+CONFIG_MMC_SDHCI_SPACEMIT=y
+CONFIG_MMC_IO_VOLTAGE=y
+CONFIG_MMC_HS200_SUPPORT=y
+CONFIG_MMC_HS400_SUPPORT=y
+CONFIG_MMC_HS400_ES_SUPPORT=y
+CONFIG_SUPPORT_EMMC_BOOT=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=0x4
+CONFIG_CMD_MMC=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_MEMINFO_MAP=y
+CONFIG_EFI_PARTITION=y
 CONFIG_SPL_SPI=y
 CONFIG_SPL_DM_SPI=y
 CONFIG_SPL_DM_SPI_FLASH=y
@@ -94,3 +111,5 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_SPI_FLASH_TINY=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_MMC=y
+CONFIG_SPL_SYS_MMCSD_RAW_MODE=y
Signature · 1 line
2.51.0
author
#19 lore raw

PATCH v4 7/10 MAINTAINER: update Spacemit K1 entry

In reply to Eric Chung

Update the maintainer for Spacemit K1 from Guodong to Eric.

---
v4:
- Update the maintainer.

---
 board/spacemit/k1/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/spacemit/k1/MAINTAINERS +1 -1
index ca994e2a1fb..4b2bc4ecfc1 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
Signature · 1 line
2.51.0
author
#20 lore raw

PATCH v4 8/10 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.

---
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 | 320 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 322 insertions(+), 1 deletion(-)
board/spacemit/k1/MAINTAINERS +1 -1
index 4b2bc4ecfc1..e12288a206e 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 a5e35ee12ab..71854e5735b 100644
@@ -6,5 +6,6 @@ SpacemiT
    :maxdepth: 1
 
    bananapi-f3
+   k1-mmc
    k1-spl
 
doc/board/spacemit/k1-mmc.rst new file +320 -0

320 lines not on this page · raw message

Signature · 1 line
2.51.0
author
#21 lore raw

PATCH v4 9/10 config: k1: enable ENV support for eMMC

In reply to Eric Chung

Enable environment variable support on the eMMC storage device for both SPL and U-Boot stages.

---
 configs/spacemit_k1_defconfig | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
configs/spacemit_k1_defconfig +6 -1
index 886679367a9..1c92c4082a7 100644
@@ -14,7 +14,7 @@ CONFIG_SPL_BSS_MAX_SIZE=0x400
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_ADDR=0xc00000
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
-CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x100000
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x400000
 CONFIG_SYS_BOOTM_LEN=0xa000000
 CONFIG_SYS_LOAD_ADDR=0x200000
 CONFIG_SPL_SIZE_LIMIT=0x31000
@@ -48,6 +48,10 @@ CONFIG_CMD_TLV_EEPROM=y
 CONFIG_SPL_CMD_TLV_EEPROM=y
 CONFIG_OF_UPSTREAM=y
 CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_SIZE=0x4000
+CONFIG_ENV_OFFSET=0x60000
+CONFIG_ENV_SECT_SIZE=0x10000
+CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SPL_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_SPL_SYSCON=y
@@ -111,5 +115,6 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_SPI_FLASH_TINY=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_MMC=y
 CONFIG_SPL_SYS_MMCSD_RAW_MODE=y
Signature · 1 line
2.51.0
author
#22 lore raw

PATCH v4 10/10 spacemit: k1: load product name from environment variable

In reply to Eric Chung

Read the product name from the environment instead of EEPROM, as the EEPROM may not be programmed and the environment always contains this information.

---
 board/spacemit/k1/spl.c | 51 +++++++++++--------------------------------------
 1 file changed, 11 insertions(+), 40 deletions(-)
board/spacemit/k1/spl.c +11 -40
index 70579637b5e..1387c2ef9b3 100644
@@ -12,6 +12,7 @@
 #include <configs/k1.h>
 #include <dm/device.h>
 #include <dm/uclass.h>
+#include <env.h>
 #include <i2c.h>
 #include <linux/bitfield.h>
 #include <linux/delay.h>
@@ -96,39 +97,6 @@ static void i2c_early_init(void)
 	}
 }
 
-int read_product_name(char *name, int size)
-{
-	u8 eeprom_data[TLV_TOTAL_LEN_MAX], *p;
-	struct tlvinfo_header *tlv_hdr;
-	struct tlvinfo_tlv *tlv_entry;
-	int ret, i = 0;
-	u32 entry_size;
-
-	if (!name || size <= 0)
-		return -EINVAL;
-	ret = read_tlvinfo_tlv_eeprom(eeprom_data, &tlv_hdr,
-				      &tlv_entry, i);
-	if (ret)
-		return ret;
-	p = (u8 *)tlv_entry;
-	for (i = 0; i < tlv_hdr->totallen; ) {
-		if (tlv_entry->type == TLV_CODE_PRODUCT_NAME) {
-			if (tlv_entry->length < size)
-				size = tlv_entry->length;
-			memset(name, 0, size);
-			memcpy(name, &tlv_entry->value[0], size);
-			return 0;
-		}
-		if (tlv_entry->type == TLV_CODE_CRC_32)
-			return -ENOENT;
-		entry_size = tlv_entry->length + sizeof(struct tlvinfo_tlv);
-		i += entry_size;
-		p += entry_size;
-		tlv_entry = (struct tlvinfo_tlv *)p;
-	}
-	return -ENOENT;
-}
-
 static const struct {
 	const char *eeprom_name;
 	const char *fit_name;
@@ -140,9 +108,15 @@ static const struct {
 
 static void fixup_product_name(void)
 {
-	char fdt_name[I2C_BUF_SIZE];
+	char fdt_name[I2C_BUF_SIZE], *name;
 	int i;
 
+	memset(product_name, 0, I2C_BUF_SIZE);
+	env_init();
+	env_load();
+	name = env_get("product_name");
+	if (name)
+		snprintf(product_name, I2C_BUF_SIZE, "%s", name);
 	memset(fdt_name, 0, I2C_BUF_SIZE);
 	for (i = 0; i < ARRAY_SIZE(k1_board_map); i++) {
 		if (!strncmp(product_name, k1_board_map[i].eeprom_name,
@@ -451,13 +425,10 @@ u32 spl_boot_device(void)
 
 void spl_board_init(void)
 {
-	int ret;
+}
 
-	ret = read_product_name(product_name, I2C_BUF_SIZE);
-	if (ret)
-		log_info("Fail to detect board:%d\n", ret);
-	else
-		log_info("Get board name:%s\n", product_name);
+void spl_perform_board_fixups(struct spl_image_info *spl_image)
+{
 	fixup_product_name();
 }
 
Signature · 1 line
2.51.0