[PATCH 1/2] mmc: detect illegal command response in SPI mode

Martí Alonso martialonso11 at gmail.com
Sun Jun 14 02:04:37 CEST 2026


At idle state, prior initialization, MMC cards (not SD) will respond
with illegal command to anything other than CMD1 (MMC_SEND_OP_COND) and
CMD58 (MMC_READ_OCR). The MMC driver initially sends CMD8
(SD_SEND_IF_COND) to check for an SD card, but this needs to return an
error, if not an SD card, so it can later check for an MMC card with
CMD1 (MMC_SEND_OP_COND).

Additionally, CMD55 + ACMD41 (SD_APP_SEND_OP_COND) can be skipped if
CMD8 (SD_SEND_IF_COND) already failed.

Signed-off-by: Martí Alonso <martialonso11 at gmail.com>
---

 drivers/mmc/mmc.c     | 18 ++++++++++--------
 drivers/mmc/mmc_spi.c |  3 +++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index f0e38efb262b..27eed9a76ba2 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -3014,16 +3014,18 @@ retry:
 	/* Test for SD version 2 */
 	err = mmc_send_if_cond(mmc);
 
-	/* Now try to get the SD card's operating condition */
-	err = sd_send_op_cond(mmc, uhs_en);
-	if (err && uhs_en) {
-		uhs_en = false;
-		mmc_power_cycle(mmc);
-		goto retry;
+	if (!err) {
+		/* Now try to get the SD card's operating condition */
+		err = sd_send_op_cond(mmc, uhs_en);
+		if (err && uhs_en) {
+			uhs_en = false;
+			mmc_power_cycle(mmc);
+			goto retry;
+		}
 	}
 
-	/* If the command timed out, we check for an MMC card */
-	if (err == -ETIMEDOUT) {
+	/* If the command timed out or returned illegal, we check for an MMC card */
+	if (err == -ETIMEDOUT || err == -EOPNOTSUPP) {
 		err = mmc_send_op_cond(mmc);
 
 		if (err) {
diff --git a/drivers/mmc/mmc_spi.c b/drivers/mmc/mmc_spi.c
index 675e642efd08..53bf4f583243 100644
--- a/drivers/mmc/mmc_spi.c
+++ b/drivers/mmc/mmc_spi.c
@@ -168,6 +168,9 @@ static int mmc_spi_sendcmd(struct udevice *dev,
 			return -ETIMEDOUT;
 	}
 
+	if (resp[0] & R1_SPI_ILLEGAL_COMMAND)
+		return -EOPNOTSUPP;
+
 	debug("\n");
 
 	return 0;
-- 
2.43.0

base-commit: 5ca1a73c7d3064582498a8aa96c29e714402a6d3
branch: fix-mmc-no-sd


More information about the U-Boot mailing list