From 664aaf0bdc13b78ca52724ecb03e67b6306a28e8 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Wed, 31 Mar 2021 21:55:24 +0800 Subject: [PATCH] driver: usdhc: fix spec 1.0 sdcard can't work The SD Card below Physical Layer 1.10 does not support CMD6. When usdhc_sd_init is executed, it will fail to exit due to execution of CMD6, causing the SD Card to not work normally. For different SD Card Physical Layer specifications, the following modifications have been made: Version 1.10 and above support CMD6. Version 3.0 and above support CMD6 Group 3 (driver strength and current limit) . Signed-off-by: Frank Li --- drivers/disk/usdhc.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/disk/usdhc.c b/drivers/disk/usdhc.c index 8ccc77ca4b2..6702ca06879 100644 --- a/drivers/disk/usdhc.c +++ b/drivers/disk/usdhc.c @@ -2534,20 +2534,22 @@ APP_SEND_OP_COND_AGAIN: usdhc_set_bus_width(base, USDHC_DATA_BUS_WIDTH_4BIT); } - /* set sd card driver strength */ - ret = usdhc_select_fun(priv, SD_GRP_DRIVER_STRENGTH_MODE, - priv->card_info.driver_strength); - if (ret) { - LOG_ERR("Set SD driver strehgth failed: %d\r\n", ret); - return ret; - } + if (priv->card_info.version >= SD_SPEC_VER3_0) { + /* set sd card driver strength */ + ret = usdhc_select_fun(priv, SD_GRP_DRIVER_STRENGTH_MODE, + priv->card_info.driver_strength); + if (ret) { + LOG_ERR("Set SD driver strehgth failed: %d\r\n", ret); + return ret; + } - /* set sd card current limit */ - ret = usdhc_select_fun(priv, SD_GRP_CURRENT_LIMIT_MODE, - priv->card_info.max_current); - if (ret) { - LOG_ERR("Set SD current limit failed: %d\r\n", ret); - return ret; + /* set sd card current limit */ + ret = usdhc_select_fun(priv, SD_GRP_CURRENT_LIMIT_MODE, + priv->card_info.max_current); + if (ret) { + LOG_ERR("Set SD current limit failed: %d\r\n", ret); + return ret; + } } /* set block size */ @@ -2560,11 +2562,13 @@ APP_SEND_OP_COND_AGAIN: return -EIO; } - /* select bus timing */ - ret = usdhc_select_bus_timing(priv); - if (ret) { - LOG_ERR("Select bus timing failed: %d\r\n", ret); - return ret; + if (priv->card_info.version > SD_SPEC_VER1_0) { + /* select bus timing */ + ret = usdhc_select_bus_timing(priv); + if (ret) { + LOG_ERR("Select bus timing failed: %d\r\n", ret); + return ret; + } } retry = 10;