]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mmc: Fix retry logic in sd_get_capabilities
authorYanir Levin <yanir.levin@tandemg.com>
Thu, 22 Jan 2026 02:32:06 +0000 (10:32 +0800)
committerPeng Fan <peng.fan@nxp.com>
Thu, 22 Jan 2026 02:38:50 +0000 (10:38 +0800)
In sd_get_capabilities an ACMD is sent (SD_CMD_APP_SEND_SCR),
which requires sending APP_CMD (MMC_CMD_APP_CMD) before.

Currently, the ACMD is retried on error, however APP_CMD isn't.
In this case, when the ACMD fails and it is tried again,
the retry attempts will not be handled as ACMD, which is wrong.

The fix performs the retry attempts on the sequence of
APP_CMD and the ACMD together.

Signed-off-by: Yanir Levin <yanir.levin@tandemg.com>
Reviewed-by: Eran Moshe <emoshe@gsitechnology.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/mmc/mmc.c

index 71664173016516c909a48bc909c1cab509e40dcf..7dadff27abe2f23d47b58d7a33b915a325231269 100644 (file)
@@ -1382,6 +1382,7 @@ static int sd_get_capabilities(struct mmc *mmc)
        ALLOC_CACHE_ALIGN_BUFFER(__be32, switch_status, 16);
        struct mmc_data data;
        int timeout;
+       uint retries = 3;
 
        mmc->card_caps = MMC_MODE_1BIT | MMC_CAP(MMC_LEGACY);
 
@@ -1389,25 +1390,26 @@ static int sd_get_capabilities(struct mmc *mmc)
                return 0;
 
        /* Read the SCR to find out if this card supports higher speeds */
-       cmd.cmdidx = MMC_CMD_APP_CMD;
-       cmd.resp_type = MMC_RSP_R1;
-       cmd.cmdarg = mmc->rca << 16;
-
-       err = mmc_send_cmd(mmc, &cmd, NULL);
+       do {
+               cmd.cmdidx = MMC_CMD_APP_CMD;
+               cmd.resp_type = MMC_RSP_R1;
+               cmd.cmdarg = mmc->rca << 16;
 
-       if (err)
-               return err;
+               err = mmc_send_cmd(mmc, &cmd, NULL);
+               if (err)
+                       continue;
 
-       cmd.cmdidx = SD_CMD_APP_SEND_SCR;
-       cmd.resp_type = MMC_RSP_R1;
-       cmd.cmdarg = 0;
+               cmd.cmdidx = SD_CMD_APP_SEND_SCR;
+               cmd.resp_type = MMC_RSP_R1;
+               cmd.cmdarg = 0;
 
-       data.dest = (char *)scr;
-       data.blocksize = 8;
-       data.blocks = 1;
-       data.flags = MMC_DATA_READ;
+               data.dest = (char *)scr;
+               data.blocksize = 8;
+               data.blocks = 1;
+               data.flags = MMC_DATA_READ;
 
-       err = mmc_send_cmd_retry(mmc, &cmd, &data, 3);
+               err = mmc_send_cmd(mmc, &cmd, &data);
+       } while (err && retries--);
 
        if (err)
                return err;