From: Eric Chung Date: Wed, 22 Jul 2026 15:21:16 +0000 (+0800) Subject: mmc: enable CMD23 for multi-block transfers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e613de952e7e407a14d7110d6697457a53a68bc;p=thirdparty%2Fu-boot.git mmc: enable CMD23 for multi-block transfers 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. Signed-off-by: Eric Chung Signed-off-by: Tanmay Kathpalia [ Drop MMC_CAP_CMD32 from mvebu_mmc.h ] Signed-off-by: Peng Fan --- diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 135fd835609..670e92ee12b 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -457,6 +457,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 @@ -477,7 +485,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"); @@ -1033,6 +1041,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; @@ -1432,6 +1444,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) diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c index 9cf07b4ad1f..e739720b77c 100644 --- a/drivers/mmc/mmc_write.c +++ b/drivers/mmc/mmc_write.c @@ -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; diff --git a/include/mmc.h b/include/mmc.h index 9509c9e9543..4bda44ea220 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -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 diff --git a/include/mvebu_mmc.h b/include/mvebu_mmc.h index 0f6f5c23dee..258623d5c67 100644 --- a/include/mvebu_mmc.h +++ b/include/mvebu_mmc.h @@ -253,8 +253,6 @@ #define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type D */ #define MMC_CAP_DRIVER_TYPE_D (1 << 25) -/* CMD23 supported. */ -#define MMC_CAP_CMD23 (1 << 30) /* Hardware reset */ #define MMC_CAP_HW_RESET (1 << 31)