]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mmc: enable CMD23 for multi-block transfers
authorEric Chung <eric.chung@riscstar.com>
Wed, 22 Jul 2026 15:21:16 +0000 (23:21 +0800)
committerPeng Fan <peng.fan@nxp.com>
Wed, 29 Jul 2026 03:15:56 +0000 (11:15 +0800)
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 <eric.chung@riscstar.com>
Signed-off-by: Tanmay Kathpalia <tanmay.kathpalia@altera.com>
[ Drop MMC_CAP_CMD32 from mvebu_mmc.h ]
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/mmc/mmc.c
drivers/mmc/mmc_write.c
include/mmc.h
include/mvebu_mmc.h

index 135fd835609aa54c5c5bb9a4787e2b5fb153320b..670e92ee12b03074387bed2046c36069aa567d67 100644 (file)
@@ -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)
index 9cf07b4ad1fb3c0cc5eba7f007d7db78bdb5595d..e739720b77c717f0de4663c4c1ed792839432ce5 100644 (file)
@@ -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;
index 9509c9e9543d2d43f9fabd3c6fe61d207f13b88e..4bda44ea22048887bb21e968b9233780628e8487 100644 (file)
@@ -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
index 0f6f5c23dee672fd83ab55d40fdfc5c3a847afc4..258623d5c67643f4cedd8593bf1e9ab56fbb52ab 100644 (file)
 #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)