spacemit mmc driver
Subsystems (4)
v8 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-mmc.rst) describes how to write images to eMMC.
---
Changes in v8:
- doc: Remove SD part.
- Link to v7: https://patch.msgid.link/[email protected]
Changes in v7:
- spl: Avoid to load product name from ENV.
- spl: Fix DTB matching.
- pinctrl: Simply clrsetbits_le32() on pull-up/pull-down configuration.
- pinctrl: Remove the dependency on SYSCON.
- Link to v6: https://patch.msgid.link/[email protected]
Changes in v6:
- pinctrl: Fix drive strength configuration.
- pinctrl: Fix pull-up/pull-down configuration.
- pinctrl: Use dev_read_phandle_with_args() to fetch "spacemit,syscon" instead.
- spacemit: rebase on latest upstream branch.
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- mmc: Split CMD23 support out.
- mmc: Use read_poll_timeout().
- mmc: Set pinctrl state based on selected timing mode.
- mmc: Remove the condition based on quirks.
- pinctrl: Fix power source argument.
- dts: Add missing power source on mmc pins.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- mmc: Add CMD23 for write.
- mmc: Fix CMD23 only for CMD18.
- mmc: Update bulk release operations on reset and clocks for spacemit platform driver.
- MAINTAINER: update the maintainer of Spacemit K1.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- pinctrl: Fix "fast" by "uhs".
- pinctrl: Add syscon dependency.
- mmc: Fix quick by capability.
- doc: Add SD boot support.
- Link to v2: https://lore.kernel.org/u-boot/[email protected]/T/#m2aba875a2696a7bb9b704618d22ae2fd7f7f5acc
Changes in v2:
- cmd: drop patches on eminfo & tlv_eeprom.
- configs: Enable ADMA and SYSCON support.
- dts: Use vmmc-supply as vqmmc-supply on the SD card node.
- mmc: k1: Enable ADMA mode support, use CMD23 for multi-block
read/write, correct pinctrl state from "fast" to "uhs".
- mmc: sdhci: Add new quirk patch to enable CMD23 for multi-block
transfers.
- pinctrl: k1: Add new IO power domain configuration support for
dual-voltage GPIO banks.
- spacemit: k1: Use FIELD_GET() to parse boot strap mode.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/
To: [email protected]
To: [email protected]
To: [email protected]
---
Eric Chung (11):
spacemit: k1: select boot device via config registers
pinctrl: k1: fix drive strength configuration
pinctrl: k1: fix pull-up/pull-down configuration
pinctrl: k1: add IO power domain configuration support
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: fix product name detection and DTB matching in SPL
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi | 91 +++- arch/riscv/dts/k1-musepi-pro-u-boot.dtsi | 86 +++- board/spacemit/k1/MAINTAINERS | 5 +- board/spacemit/k1/spl.c | 121 +++++- configs/spacemit_k1_defconfig | 27 +- doc/board/spacemit/index.rst | 1 + doc/board/spacemit/k1-mmc.rst | 167 ++++++++ drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 673 ++++++++++++++++++++++++++++++ drivers/pinctrl/spacemit/pinctrl-k1.c | 114 ++++- 11 files changed, 1256 insertions(+), 37 deletions(-)
---
base-commit: 616c3d79f01cf9204e38738857c4647a730dcb3b
change-id: 20260629-m4-98e01659fefb
Best regards,
Signature · 1 line
Eric Chung <[email protected]>
PATCH v8 1/11 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.
---
v5:
- Add blank lines around the switch statement.
v2:
- Use FIELD_GET() to parse boot strap mode.
- Remove comments on hacking. Since the sequence between eMMC and SD device is exchanged in the upstream DTS. So it isn't a hacking any more.
--- board/spacemit/k1/spl.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-)
board/spacemit/k1/spl.c +70 -1
@@ -13,6 +13,7 @@#include <dm/device.h> #include <dm/uclass.h> #include <i2c.h> +#include <linux/bitfield.h> #include <linux/ctype.h> #include <linux/delay.h> #include <log.h>
@@ -22,6 +23,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 */
@@ -46,6 +58,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;
@@ -354,7 +377,53 @@ 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
PATCH v8 2/11 pinctrl: k1: fix drive strength configuration
In reply to Eric ChungFix drive strength configuration by:
- Using FIELD_PREP() to properly set the PAD_DRIVE mask bits
- Not overriding io_type with IO_TYPE_EXTERNAL for external pins
- Returning the pin number instead of 0 from pinmux_property_set
- Removing redundant zero-initialization of the mask variable
---
v6:
- Fix drive strength configuration.
--- drivers/pinctrl/spacemit/pinctrl-k1.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pinctrl/spacemit/pinctrl-k1.c +8 -4
@@ -9,6 +9,7 @@#include <dm/device_compat.h> #include <dm/pinctrl.h> #include <dm/read.h> +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/errno.h> #include <linux/io.h>
@@ -386,10 +387,12 @@ static int spacemit_pinmux_set(struct udevice *dev, unsigned int pin,static int spacemit_pinmux_property_set (struct udevice *dev,u32 pinmux_group) {u32 pin, mux; +int ret; pin =spacemit_dt_get_pin (pinmux_group); mux =spacemit_dt_get_pin_mux (pinmux_group); -return spacemit_pinmux_set (dev, pin, mux); + ret =spacemit_pinmux_set (dev, pin, mux); +return ret ? ret : pin; }static const struct pinconf_param spacemit_pinconf_params[] = {
@@ -406,7 +409,7 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,struct spacemit_pinctrl_data *data;struct spacemit_pinctrl_priv *priv =dev_get_priv (dev);void __iomem *addr; -u32 mask =0 ; +u32 mask;unsigned int io_type;u8 ds;bool found;
@@ -433,7 +436,8 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,for (i =0 ; i < priv->nr_io_pins; i++) {if (priv->io_pins[i].pin != pin_selector)continue ; - io_type = priv->io_pins[i].io_type; +if (priv->io_pins[i].io_type !=IO_TYPE_EXTERNAL ) + io_type = priv->io_pins[i].io_type;break ; }if (io_type !=IO_TYPE_3V3 && io_type !=IO_TYPE_1V8 ) {
@@ -441,7 +445,7 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,return -EINVAL ; } ds =spacemit_get_drive_strength (io_type, argument); -clrsetbits_le32 (addr,PAD_DRIVE , ds); +clrsetbits_le32 (addr,PAD_DRIVE ,FIELD_PREP (PAD_DRIVE , ds));break ;case PIN_CONFIG_POWER_SOURCE :for (i =0 , found = false; i < priv->nr_io_pins; i++) {
Signature · 1 line
2.51.0
Re: [PATCH v8 02/11] pinctrl: k1: fix drive strength configuration
Quoted 8 lines · Eric Chung
Fix drive strength configuration by:
- UsingFIELD_PREP()to properly set thePAD_DRIVEmask bits
- Not overridingio_typewithIO_TYPE_EXTERNALfor external pins
- Returning the pin number instead of 0 frompinmux_property_set
- Removing redundant zero-initialization of the mask variableSigned-off-by Eric Chung <[email protected]>
Checked this patch, the logic looks ok to me (only few minor comments), And you can still add my R-B, thanks
Quoted 29 lines
---
v6:
- Fix drive strength configuration.--- drivers/pinctrl/spacemit/pinctrl-k1.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/pinctrl/spacemit/pinctrl-k1.c +3
-1@@ -9,6 +9,7 @@#include <dm/device_compat.h> #include <dm/pinctrl.h> #include <dm/read.h> +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/errno.h> #include <linux/io.h> @@ -386,10 +387,12 @@ static int spacemit_pinmux_set(struct udevice *dev, unsigned int pin,static int spacemit_pinmux_property_set (struct udevice *dev,u32 pinmux_group) {u32 pin, mux; +int ret; pin =spacemit_dt_get_pin (pinmux_group); mux =spacemit_dt_get_pin_mux (pinmux_group); -return spacemit_pinmux_set (dev, pin, mux); + ret =spacemit_pinmux_set (dev, pin, mux);
..
drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinmux_set(struct udevice *dev, unsigned int pin, · line 395
Quoted 1 line
drivers/pinctrl/spacemit/pinctrl-k1.c +1
-0+return ret ? ret : pin;
I'd prefer doing as below, which would more explicitly tell that's an error handler
if (ret < 0) return ret; return pin;
drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector, · line 412
Quoted 9 lines
}
static const struct
pinconf_paramspacemit_pinconf_params[] = {drivers/pinctrl/spacemit/pinctrl-k1.c +1
-1@@ -406,7 +409,7 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,struct spacemit_pinctrl_data *data;struct spacemit_pinctrl_priv *priv =dev_get_priv (dev);void __iomem *addr; -u32 mask =0 ; +u32 mask;
This isn't a necessary change, which doesn't alter any logic or fix anything, and more worse, the follow-up patch drop line of this variable
I mean bringing in unrelated change only increase the review burden..
Quoted 26 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +3
-2unsigned int io_type;u8 ds;bool found;@@ -433,7 +436,8 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,for (i =0 ; i < priv->nr_io_pins; i++) {if (priv->io_pins[i].pin != pin_selector)continue ; - io_type = priv->io_pins[i].io_type; +if (priv->io_pins[i].io_type !=IO_TYPE_EXTERNAL ) + io_type = priv->io_pins[i].io_type;break ; }if (io_type !=IO_TYPE_3V3 && io_type !=IO_TYPE_1V8 ) {@@ -441,7 +445,7 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,return -EINVAL ; } ds =spacemit_get_drive_strength (io_type, argument); -clrsetbits_le32 (addr,PAD_DRIVE , ds); +clrsetbits_le32 (addr,PAD_DRIVE ,FIELD_PREP (PAD_DRIVE , ds));break ;case PIN_CONFIG_POWER_SOURCE :for (i =0 , found = false; i < priv->nr_io_pins; i++) {Signature · 2 lines
-- 2.51.0
Signature · 1 line
Yixun Lan (dlan)
PATCH v8 3/11 pinctrl: k1: fix pull-up/pull-down configuration
In reply to Eric ChungFix pull-up/pull-down configuration to honor the argument parameter:
when argument is non-zero, enable the requested pull direction; when argument is zero, clear all pull bits to disable.
---
v7:
- Simplify pull-up/pull-down configuration by using a single clrsetbits_le32() call.
v6:
- Fix pull-up/pull-down configuration.
--- drivers/pinctrl/spacemit/pinctrl-k1.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pinctrl/spacemit/pinctrl-k1.c +4 -5
@@ -409,7 +409,6 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,struct spacemit_pinctrl_data *data;struct spacemit_pinctrl_priv *priv =dev_get_priv (dev);void __iomem *addr; -u32 mask;unsigned int io_type;u8 ds;bool found;
@@ -424,12 +423,12 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,clrbits_le32 (addr,PAD_PULLUP |PAD_PULLDOWN |PAD_PULL_EN );break ;case PIN_CONFIG_BIAS_PULL_DOWN : - mask =PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN ; -clrsetbits_le32 (addr, mask,PAD_PULLDOWN |PAD_PULL_EN ); +clrsetbits_le32 (addr,PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN , + argument ?PAD_PULLDOWN |PAD_PULL_EN :0 );break ;case PIN_CONFIG_BIAS_PULL_UP : - mask =PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN ; -clrsetbits_le32 (addr, mask,PAD_PULLUP |PAD_PULL_EN ); +clrsetbits_le32 (addr,PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN , + argument ?PAD_PULLUP |PAD_PULL_EN :0 );break ;case PIN_CONFIG_DRIVE_STRENGTH : io_type =IO_TYPE_1V8 ;
Signature · 1 line
2.51.0
Yixun Lan
maintainerRe: [PATCH v8 03/11] pinctrl: k1: fix pull-up/pull-down configuration
Hi Eric,
Quoted 3 lines · Eric Chung
Fix pull-up/pull-down configuration to honor the argument parameter:
when argument is non-zero, enable the requested pull direction; when argument is zero, clear all pull bits to disable.
No, This will be problem .. see my comment below
Quoted 34 lines
Signed-off-by Eric Chung <[email protected]>---
v7:
- Simplify pull-up/pull-down configuration by using a singleclrsetbits_le32()call.
v6:
- Fix pull-up/pull-down configuration.--- drivers/pinctrl/spacemit/pinctrl-k1.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/pinctrl/spacemit/pinctrl-k1.c +2
-3@@ -409,7 +409,6 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,struct spacemit_pinctrl_data *data;struct spacemit_pinctrl_priv *priv =dev_get_priv (dev);void __iomem *addr; -u32 mask;unsigned int io_type;u8 ds;bool found;@@ -424,12 +423,12 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector,clrbits_le32 (addr,PAD_PULLUP |PAD_PULLDOWN |PAD_PULL_EN );break ;case PIN_CONFIG_BIAS_PULL_DOWN : - mask =PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN ; -clrsetbits_le32 (addr, mask,PAD_PULLDOWN |PAD_PULL_EN ); +clrsetbits_le32 (addr,PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN , + argument ?PAD_PULLDOWN |PAD_PULL_EN :0 );break ;
..
drivers/pinctrl/spacemit/pinctrl-k1.c static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector, · line 431
Quoted 5 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +2
-2case PIN_CONFIG_BIAS_PULL_UP : - mask =PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN ; -clrsetbits_le32 (addr, mask,PAD_PULLUP |PAD_PULL_EN ); +clrsetbits_le32 (addr,PAD_PULLDOWN |PAD_PULLUP |PAD_PULL_EN , + argument ?PAD_PULLUP |PAD_PULL_EN :0 );
In kernel side, the argument for pull up settings has documentated as
0 - normal pull up
1 - strong pull up
well, you can still use bias-disable property to disable bias settings if needed
I'd suggest to have this aligned with kernel DT files, which would more easily for us to reuse upstream dts files
Quoted 7 lines
drivers/pinctrl/spacemit/pinctrl-k1.c +0
-0break ;case PIN_CONFIG_DRIVE_STRENGTH : io_type =IO_TYPE_1V8 ;Signature · 2 lines
-- 2.51.0
Signature · 1 line
Yixun Lan (dlan)
PATCH v8 4/11 pinctrl: k1: add IO power domain configuration support
In reply to Eric ChungDual-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.
---
v7:
- Remove the dependency on SYSCON.
v6:
- Use dev_read_phandle_with_args() to fetch "spacemit,apbc" instead. v5:
- Use tabs for macro definition alignment.
- Fix the missing power source argument.
v3:
- Add SYSCON dependency in Kconfig.
- Fix not sorted issue in the driver.
--- drivers/pinctrl/spacemit/pinctrl-k1.c | 95 +++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-)
drivers/pinctrl/spacemit/pinctrl-k1.c +92 -3
@@ -13,6 +13,7 @@#include <linux/bitops.h> #include <linux/errno.h> #include <linux/io.h> +#include <regmap.h> /* * +---------+----------+-----------+--------+--------+----------+--------+
@@ -35,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 + +#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 3300enum spacemit_pin_io_type {IO_TYPE_NONE =0 ,
@@ -61,12 +77,14 @@ struct spacemit_pinctrl_data {int (*get_pins)(struct udevice *dev);int (*get_functions)(struct udevice *dev);int (*get_io_type)(struct udevice *dev,unsigned int pin); +unsigned int (*pin_to_io_pd_offset)(unsigned int pin); };struct spacemit_pinctrl_priv {void __iomem *regs;struct spacemit_pin_io *io_pins;int nr_io_pins; +struct regmap *regmap; };struct spacemit_pin_mux_config {
@@ -197,6 +215,28 @@ static int k1_get_io_type(struct udevice *dev, unsigned int selector)return -EINVAL ; } +static unsigned int spacemit_k1_pin_to_io_pd_offset (unsigned int pin) +{ +unsigned int offset =0 ; + +switch (pin) { + case 47 ... 52: + offset =IO_PWR_DOMAIN_GPIO3_K1 ; +break ; + case 75 ... 80: + offset = IO_PWR_DOMAIN_GPIO2_Kx; +break ; + case 98 ... 103: + offset =IO_PWR_DOMAIN_QSPI_K1 ; +break ; + case 104 ... 109: + offset = IO_PWR_DOMAIN_MMC_Kx; +break ; + } + +return offset; +} +/* use IO high level output current as the table */ static struct spacemit_pin_drv_strength spacemit_ds_1v8_tbl[4 ] = { {0 ,11 },
@@ -403,6 +443,35 @@ static const struct pinconf_param spacemit_pinconf_params[] = { { "power-source", PIN_CONFIG_POWER_SOURCE, U32_MAX }, }; +static void spacemit_set_io_power_domain (struct udevice *dev, +unsigned int pin, +unsigned int io_type) +{ +struct spacemit_pinctrl_priv *priv =dev_get_priv (dev); +struct spacemit_pinctrl_data *data; +unsigned int offset; +u32 val =0 ; + +if (!priv->regmap) +return ; + + data = (struct spacemit_pinctrl_data *)dev_get_driver_data (dev); +if (!data || !data->pin_to_io_pd_offset) +return ; + + offset = data->pin_to_io_pd_offset (pin); +if (!offset) +return ; + +if (io_type ==IO_TYPE_1V8 ) + val =IO_PWR_DOMAIN_V18EN ; + +regmap_write (priv->regmap,APBC_ASFAR ,APBC_ASFAR_AKEY ); +regmap_write (priv->regmap,APBC_ASSAR ,APBC_ASSAR_AKEY ); + +writel (val, priv->regs +IO_PWR_DOMAIN_OFFSET + offset); +} +static int spacemit_pinconf_set (struct udevice *dev,unsigned int pin_selector,unsigned int param,unsigned int argument) {
@@ -417,6 +486,7 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector, data = (struct spacemit_pinctrl_data *)dev_get_driver_data (dev);if (!data || !data->pin_to_reg)return -EINVAL ; + addr = data->pin_to_reg (dev, pin_selector);switch (param) {case PIN_CONFIG_BIAS_DISABLE :
@@ -459,10 +529,14 @@ static int spacemit_pinconf_set(struct udevice *dev, unsigned int pin_selector, }break ; } -if (!found && argument !=PIN_POWER_STATE_1V8 ) { +if (!found && argument !=PIN_POWER_STATE_1V8 && + argument !=PIN_POWER_STATE_3V3 ) {dev_err (dev,"Invalid power source (%d)\n" , argument);return -EINVAL ; } +if (found) +spacemit_set_io_power_domain (dev, pin_selector, + priv->io_pins[i].io_type);break ;default :return -EOPNOTSUPP ;
@@ -475,6 +549,7 @@ static int spacemit_pinctrl_probe(struct udevice *dev)struct spacemit_pinctrl_data *data;struct spacemit_pinctrl_priv *priv;struct clk_bulk clks; +struct ofnode_phandle_args args;size_t size;int ret;
@@ -492,6 +567,19 @@ static int spacemit_pinctrl_probe(struct udevice *dev)dev_err (dev,"Fail to allocate memory\n" );return -ENOMEM ; } + ret =dev_read_phandle_with_args (dev,"spacemit,apbc" , +NULL ,0 ,0 , &args); +if (ret) { +dev_warn (dev,"no APBC phandle found, disable IO power domain switching\n" ); + priv->regmap =NULL ; + }else { + ret =regmap_init_mem (args.node, &priv->regmap); +if (ret) { +dev_warn (dev,"failed to get APBC regmap," +" disable IO power domain switching\n" ); + priv->regmap =NULL ; + } + } ret =clk_get_bulk (dev, &clks);if (ret) {
@@ -519,6 +607,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 · 1 line
2.51.0
Re: [PATCH v8 04/11] pinctrl: k1: add IO power domain configuration support
Hi Eric,
Quoted 11 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.
Signed-off-by Eric Chung <[email protected]>Reviewed-by Yao Zi <[email protected]>
Looks good, please
Quoted 11 lines
---
v7:
- Remove the dependency on SYSCON.
v6:
- Usedev_read_phandle_with_args()to fetch "spacemit,apbc" instead. v5:
- Use tabs for macro definition alignment.
- Fix the missing power source argument.
v3:
- Add SYSCON dependency inKconfig.
- Fix not sorted issue in the driver.
Signature · 1 line
Yixun Lan (dlan)
PATCH v8 5/11 mmc: k1: add sdhci platform driver
In reply to Eric ChungAdd 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.
---
v6:
- Remove ".data = 0" in spacemit_sdhci_ids[].
v5:
- Remove MMC_CAP_CMD23 as the CMD23 support is now a separate series.
- Use tabs for macro definition alignment.
- Use read_poll_timeout().
- Set pinctrl state based on selected timing mode.
- Add the definition of SDHC_DLL_REG1_HS400_VAL.
- Remove the condition based on quirks.
v4:
- Add bulk release operations on reset and clock.
v3:
- Enable CMD23 in capability.
v2:
- Enable ADMA mode support.
- Use CMD23 for multi-block read/write.
- Move ASR/AIB register into pinctrl driver.
- Correct pinctrl state from "fast" to "uhs".
- Migrate tuning support from the spacemit linux driver.
--- drivers/mmc/Kconfig | 7 + drivers/mmc/Makefile | 1 + drivers/mmc/spacemit_sdhci.c | 673 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 681 insertions(+)
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 +673 -0
673 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v8 6/11 dts: k1: add SD card support in u-boot overlay
In reply to Eric ChungAdd 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.
---
v5:
- Append power source field on eMMC/SD pinctrl.
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 | 91 ++++++++++++++++++++++++++++++- arch/riscv/dts/k1-musepi-pro-u-boot.dtsi | 86 ++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 4 deletions(-)
arch/riscv/dts/k1-bananapi-f3-u-boot.dtsi +89 -2
@@ -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,86 @@ }; }; +/ { + 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>; + power-source = <3300>; + }; + grp_clk { + pinmux = <K1_PADCONF(109, 0)>; /* MMC1_CLK */ + bias-pull-down = <1>; + drive-strength = <19>; + power-source = <3300>; + }; + }; + + 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>; + power-source = <1800>; + }; + grp_clk { + pinmux = <K1_PADCONF(109, 0)>; /* MMC1_CLK */ + bias-pull-down = <1>; + drive-strength = <42>; + power-source = <1800>; + }; + }; +}; + +&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 +84 -2
110 lines not on this page · raw message
Signature · 1 line
2.51.0
Yixun Lan
maintainerRe: [PATCH v8 06/11] dts: k1: add SD card support in u-boot overlay
Hi Eric,
Quoted 3 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
The kernel side has added SD card support, can you sync first before adding more into the overlay?
Quoted 6 lines
missing. Place the new node inside the storage-bus via path-based merge so it inherits the dma-ranges from the parent bus.
Signed-off-by Eric Chung <[email protected]>---
Signature · 1 line
Yixun Lan (dlan)
PATCH v8 7/11 configs: k1: enable SD and eMMC support
In reply to Eric ChungEnable high-speed MMC modes.
---
v7:
- Remove mmc driver from MAINTAINERS file.
v5:
- Remove ADMA support since it depends on CMD23 support.
- Enable PINCONF support for related power source setting. v2:
- Enable ADMA support.
- Enable SYSCON support.
--- configs/spacemit_k1_defconfig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
configs/spacemit_k1_defconfig +20 -0
@@ -23,6 +23,7 @@ CONFIG_DEBUG_UART_BASE=0xd4017000 CONFIG_DEBUG_UART_CLOCK=14700000 CONFIG_TARGET_SPACEMIT_K1=y CONFIG_ARCH_RV64I=y +CONFIG_RISCV_ISA_ZICBOM=y CONFIG_RISCV_SMODE=y CONFIG_SPL_RISCV_MMODE=y # CONFIG_SPL_SMP is not set
@@ -48,6 +49,7 @@ CONFIG_SPL_CMD_TLV_EEPROM=y CONFIG_OF_UPSTREAM=y CONFIG_ENV_OVERWRITE=y CONFIG_SPL_REGMAP=y +CONFIG_SYSCON=y CONFIG_SPL_SYSCON=y CONFIG_CLK=y CONFIG_CLK_CCF=y
@@ -61,6 +63,7 @@ CONFIG_MISC=y CONFIG_I2C_EEPROM=y CONFIG_SPL_I2C_EEPROM=y CONFIG_PINCTRL=y +CONFIG_PINCONF=y CONFIG_PINCTRL_SPACEMIT_K1=y CONFIG_GPIO=y CONFIG_DM_GPIO=y
@@ -87,9 +90,26 @@ 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 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
PATCH v8 8/11 MAINTAINER: update Spacemit K1 entry
In reply to Eric ChungUpdate the maintainer for Spacemit K1 from Guodong to Eric.
---
v7:
- Add mmc driver.
v4:
- Update the maintainer.
--- board/spacemit/k1/MAINTAINERS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
board/spacemit/k1/MAINTAINERS +2 -1
@@ -1,6 +1,6 @@ BananaPi F3 M: Huan Zhou <[email protected]> -M: Guodong Xu <[email protected]> +M: Eric Chung <[email protected]> L: [email protected] S: Maintained F: arch/riscv/dts/k1-*-u-boot.dtsi
@@ -9,6 +9,7 @@ F: configs/spacemit_k1_defconfig F: doc/board/spacemit/bananapi-f3.rst F: drivers/gpio/spacemit_gpio.c F: drivers/i2c/k1_i2c.c +F: drivers/mmc/spacemit_sdhci.c F: drivers/pinctrl/spacemit/ F: drivers/power/pmic/pmic_spacemit_p1.c F: drivers/power/regulator/spacemit_p1_regulator.c
Signature · 1 line
2.51.0
PATCH v8 9/11 doc: spacemit: flash on K1 SoC based boards
In reply to Eric ChungAdd document on how to flash images into eMMC of K1 SoC based boards.
---
v8:
- Remove SD Card part.
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 | 167 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-)
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-mmc k1-spl
doc/board/spacemit/k1-mmc.rst new file +167 -0
167 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v8 10/11 config: k1: enable ENV support for eMMC
In reply to Eric ChungEnable 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
@@ -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
PATCH v8 11/11 spacemit: k1: fix product name detection and DTB matching in SPL
In reply to Eric ChungUse a table to handle DTB matching.
---
v7:
- Abandon to load product name from ENV.
v6:
- Rebased onto latest upstream. Cleaned up board_fit_config_name_match() to maintain consistentcy with v5.
--- board/spacemit/k1/spl.c | 50 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-)
board/spacemit/k1/spl.c +32 -18
@@ -97,6 +97,15 @@ static void i2c_early_init(void) } } +static const struct { +const char *eeprom_name; +const char *fit_name; +} k1_board_map[] = { + {"k1-x_MUSE-Pi-Pro" ,"spacemit/k1-musepi-pro" }, + {"k1-x_deb1" ,"spacemit/k1-bananapi-f3" }, + {"k1-x_milkv-jupiter" ,"spacemit/k1-milkv-jupiter" }, +}; +int read_product_name (char *name,int size) {u8 eeprom_data[TLV_TOTAL_LEN_MAX ], *p;
@@ -130,6 +139,27 @@ int read_product_name(char *name, int size)return -ENOENT ; } +static void fixup_product_name (void ) +{ +char fdt_name[I2C_BUF_SIZE ]; +int i; + +for (i =0 ; i <ARRAY_SIZE (k1_board_map); i++) { +memset (fdt_name,0 ,I2C_BUF_SIZE ); +if (!strncmp (product_name, k1_board_map[i].eeprom_name, +strlen (k1_board_map[i].eeprom_name))) { +snprintf (fdt_name,I2C_BUF_SIZE ,"%s" , + k1_board_map[i].fit_name); +break ; + } + } +if (fdt_name[0 ] =='\0' ) { +/* set default board name */ +sprintf (fdt_name,CONFIG_DEFAULT_DEVICE_TREE ); + } +memcpy (product_name, fdt_name,I2C_BUF_SIZE ); +} +static void clk_early_init (void ) {struct udevice *dev;
@@ -369,6 +399,7 @@ void board_init_f(ulong dummy)log_info ("Fail to detect board:%d\n" , ret); else log_info("Get board name:%s\n", product_name); +fixup_product_name ();pmic_init ();ddr_early_init ();
@@ -432,24 +463,7 @@ void spl_board_init(void)int board_fit_config_name_match (const char *name) { -char fdt_name[I2C_BUF_SIZE ]; -int i; - -memset (fdt_name,0 ,I2C_BUF_SIZE ); -if (!strncmp (product_name,"k1-x_" ,5 )) { -snprintf (fdt_name,I2C_BUF_SIZE ,"%s-%s" ,"k1" , - &product_name[5 ]); - } -if (fdt_name[0 ] =='\0' ) { -/* set default board name */ -sprintf (fdt_name,"k1-musepi-pro" ); - } -for (i =0 ; i <I2C_BUF_SIZE ; i++) { -if (fdt_name[i] =='\0' ) -break ; - fdt_name[i] =tolower (fdt_name[i]); - } -if (!strcmp (name, fdt_name)) +if (!strcmp (name, product_name))return 0 ;return -ENOENT ; }
Signature · 1 line
2.51.0