sd: resend CMD0 before each CMD8

Resend CMD0 before each CMD8 query while initialising the card, as the
first CMD0 is not always sufficient to recover the card.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2024-08-25 10:57:52 +10:00 committed by Anas Nashif
parent 3e9197a58a
commit 6bfd7a4302

View file

@ -32,13 +32,26 @@ static inline int sd_idle(struct sd_card *card)
return sdhc_request(card->sdhc, &cmd, NULL);
}
/* Sends CMD8 during SD initialization */
/*
* Perform init required for both SD and SDIO cards.
* This function performs the following portions of SD initialization
* - CMD0 (SD reset)
* - CMD8 (SD voltage check)
*/
static int sd_send_interface_condition(struct sd_card *card)
{
struct sdhc_command cmd;
int ret;
uint32_t resp;
/* Reset card with CMD0 */
ret = sd_idle(card);
if (ret) {
LOG_ERR("Card error on CMD0");
return ret;
}
/* Query voltage with CMD 8 */
cmd.opcode = SD_SEND_IF_COND;
cmd.arg = SD_IF_COND_VHS_3V3 | SD_IF_COND_CHECK;
cmd.response_type = (SD_RSP_TYPE_R7 | SD_SPI_RSP_TYPE_R7);
@ -84,22 +97,11 @@ static int sd_enable_crc(struct sd_card *card)
return sdhc_request(card->sdhc, &cmd, NULL);
}
/*
* Perform init required for both SD and SDIO cards.
* This function performs the following portions of SD initialization
* - CMD0 (SD reset)
* - CMD8 (SD voltage check)
*/
/* Retries SD and SDIO initialisation until card has valid response to SD CMD8 */
static int sd_common_init(struct sd_card *card)
{
int ret;
/* Reset card with CMD0 */
ret = sd_idle(card);
if (ret) {
LOG_ERR("Card error on CMD0");
return ret;
}
/* Perform voltage check using SD CMD8 */
ret = sd_retry(sd_send_interface_condition, card, CONFIG_SD_RETRY_COUNT);
if (ret == -ETIMEDOUT) {