mmc: Fix retry logic in sd_get_capabilities

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>
This commit is contained in:
Yanir Levin
2026-01-22 10:32:06 +08:00
committed by Peng Fan
parent 0e6ed61175
commit 124aeeff83

View 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,14 +1390,14 @@ static int sd_get_capabilities(struct mmc *mmc)
return 0;
/* Read the SCR to find out if this card supports higher speeds */
do {
cmd.cmdidx = MMC_CMD_APP_CMD;
cmd.resp_type = MMC_RSP_R1;
cmd.cmdarg = mmc->rca << 16;
err = mmc_send_cmd(mmc, &cmd, NULL);
if (err)
return err;
continue;
cmd.cmdidx = SD_CMD_APP_SEND_SCR;
cmd.resp_type = MMC_RSP_R1;
@@ -1407,7 +1408,8 @@ static int sd_get_capabilities(struct mmc *mmc)
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;