From 9feaa4d8416f4e30e34af91df55f46eaaf1cfb38 Mon Sep 17 00:00:00 2001 From: buxiasen Date: Fri, 6 Mar 2026 15:48:48 +0800 Subject: [PATCH] mmcsd: fix MMC bus width switch using wrong condition and add 8-bit support The MMC CMD6 bus width switch was gated on priv->buswidth which is derived from the SD SCR register. For MMC cards this field is never set (unless SDIO_CAPS_4BIT_ONLY), so the CMD6 was skipped while the host PROCTL DTW was still changed - causing a bus width mismatch and data transfer timeouts. Fix by checking priv->caps instead of priv->buswidth for MMC cards. Also select EXT_CSD_BUS_WIDTH_8 when host reports SDIO_CAPS_8BIT. Signed-off-by: buxiasen --- drivers/mmcsd/mmcsd_sdio.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index 567cdd870da..3643ad62390 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -2822,15 +2822,23 @@ static int mmcsd_widebus(FAR struct mmcsd_state_s *priv) } #ifdef CONFIG_MMCSD_MMCSUPPORT else if (IS_MMC(priv->type) && - ((priv->buswidth & MMCSD_SCR_BUSWIDTH_4BIT) != 0 && - (priv->caps & SDIO_CAPS_1BIT_ONLY) == 0)) + (priv->caps & SDIO_CAPS_1BIT_ONLY) == 0) { - /* SD card supports 4-bit BUS and host settings is not 1-bit only. - * Configuring MMC - Use MMC_SWITCH access modes. + /* Configuring MMC - Use MMC_SWITCH access modes. + * Select 8-bit if host supports it, otherwise 4-bit. */ - mmcsd_sendcmdpoll(priv, MMCSD_CMD6, - MMC_CMD6_BUSWIDTH(EXT_CSD_BUS_WIDTH_4)); + if (priv->caps & SDIO_CAPS_8BIT) + { + mmcsd_sendcmdpoll(priv, MMCSD_CMD6, + MMC_CMD6_BUSWIDTH(EXT_CSD_BUS_WIDTH_8)); + } + else + { + mmcsd_sendcmdpoll(priv, MMCSD_CMD6, + MMC_CMD6_BUSWIDTH(EXT_CSD_BUS_WIDTH_4)); + } + ret = mmcsd_recv_r1(priv, MMCSD_CMD6); if (ret != OK)