mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-24 22:05:40 +00:00
mmc: add required delays when retrying commands
A new function mmc_reset_to_idle is also created. Signed-off-by: Yann Gautier <yann.gautier@st.com>
This commit is contained in:
parent
f214a80698
commit
15e913d4ab
1 changed files with 42 additions and 35 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <arch_helpers.h>
|
#include <arch_helpers.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <delay_timer.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <mmc.h>
|
#include <mmc.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -319,18 +320,12 @@ static int mmc_fill_device_info(void)
|
||||||
|
|
||||||
static int sd_send_op_cond(void)
|
static int sd_send_op_cond(void)
|
||||||
{
|
{
|
||||||
int retries = SEND_OP_COND_MAX_RETRIES;
|
int n;
|
||||||
unsigned int resp_data[4];
|
unsigned int resp_data[4];
|
||||||
|
|
||||||
do {
|
for (n = 0; n < SEND_OP_COND_MAX_RETRIES; n++) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (retries == 0) {
|
|
||||||
ERROR("ACMD41 failed after %d retries\n",
|
|
||||||
SEND_OP_COND_MAX_RETRIES);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* CMD55: Application Specific Command */
|
/* CMD55: Application Specific Command */
|
||||||
ret = mmc_send_cmd(MMC_CMD(55), 0, MMC_RESPONSE_R(1), NULL);
|
ret = mmc_send_cmd(MMC_CMD(55), 0, MMC_RESPONSE_R(1), NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -344,25 +339,31 @@ static int sd_send_op_cond(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
retries--;
|
if ((resp_data[0] & OCR_POWERUP) != 0U) {
|
||||||
} while ((resp_data[0] & OCR_POWERUP) == 0U);
|
mmc_ocr_value = resp_data[0];
|
||||||
|
|
||||||
mmc_ocr_value = resp_data[0];
|
if ((mmc_ocr_value & OCR_HCS) != 0U) {
|
||||||
|
mmc_dev_info->mmc_dev_type = MMC_IS_SD_HC;
|
||||||
|
} else {
|
||||||
|
mmc_dev_info->mmc_dev_type = MMC_IS_SD;
|
||||||
|
}
|
||||||
|
|
||||||
if ((mmc_ocr_value & OCR_HCS) != 0U) {
|
return 0;
|
||||||
mmc_dev_info->mmc_dev_type = MMC_IS_SD_HC;
|
}
|
||||||
} else {
|
|
||||||
mmc_dev_info->mmc_dev_type = MMC_IS_SD;
|
mdelay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
ERROR("ACMD41 failed after %d retries\n", SEND_OP_COND_MAX_RETRIES);
|
||||||
|
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmc_send_op_cond(void)
|
static int mmc_reset_to_idle(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int retries = SEND_OP_COND_MAX_RETRIES;
|
|
||||||
unsigned int resp_data[4];
|
mdelay(1);
|
||||||
|
|
||||||
/* CMD0: reset to IDLE */
|
/* CMD0: reset to IDLE */
|
||||||
ret = mmc_send_cmd(MMC_CMD(0), 0, 0, NULL);
|
ret = mmc_send_cmd(MMC_CMD(0), 0, 0, NULL);
|
||||||
|
@ -370,14 +371,19 @@ static int mmc_send_op_cond(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
mdelay(2);
|
||||||
if (retries == 0) {
|
|
||||||
ERROR("CMD1 failed after %d retries\n",
|
|
||||||
SEND_OP_COND_MAX_RETRIES);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* CMD1: get OCR register (SEND_OP_COND) */
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mmc_send_op_cond(void)
|
||||||
|
{
|
||||||
|
int ret, n;
|
||||||
|
unsigned int resp_data[4];
|
||||||
|
|
||||||
|
mmc_reset_to_idle();
|
||||||
|
|
||||||
|
for (n = 0; n < SEND_OP_COND_MAX_RETRIES; n++) {
|
||||||
ret = mmc_send_cmd(MMC_CMD(1), OCR_SECTOR_MODE |
|
ret = mmc_send_cmd(MMC_CMD(1), OCR_SECTOR_MODE |
|
||||||
OCR_VDD_MIN_2V7 | OCR_VDD_MIN_1V7,
|
OCR_VDD_MIN_2V7 | OCR_VDD_MIN_1V7,
|
||||||
MMC_RESPONSE_R(3), &resp_data[0]);
|
MMC_RESPONSE_R(3), &resp_data[0]);
|
||||||
|
@ -385,12 +391,17 @@ static int mmc_send_op_cond(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
retries--;
|
if ((resp_data[0] & OCR_POWERUP) != 0U) {
|
||||||
} while ((resp_data[0] & OCR_POWERUP) == 0U);
|
mmc_ocr_value = resp_data[0];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
mmc_ocr_value = resp_data[0];
|
mdelay(1);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
ERROR("CMD1 failed after %d retries\n", SEND_OP_COND_MAX_RETRIES);
|
||||||
|
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmc_enumerate(unsigned int clk, unsigned int bus_width)
|
static int mmc_enumerate(unsigned int clk, unsigned int bus_width)
|
||||||
|
@ -400,11 +411,7 @@ static int mmc_enumerate(unsigned int clk, unsigned int bus_width)
|
||||||
|
|
||||||
ops->init();
|
ops->init();
|
||||||
|
|
||||||
/* CMD0: reset to IDLE */
|
mmc_reset_to_idle();
|
||||||
ret = mmc_send_cmd(MMC_CMD(0), 0, 0, NULL);
|
|
||||||
if (ret != 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* CMD8: Send Interface Condition Command */
|
/* CMD8: Send Interface Condition Command */
|
||||||
ret = mmc_send_cmd(MMC_CMD(8), VHS_2_7_3_6_V | CMD8_CHECK_PATTERN,
|
ret = mmc_send_cmd(MMC_CMD(8), VHS_2_7_3_6_V | CMD8_CHECK_PATTERN,
|
||||||
|
|
Loading…
Add table
Reference in a new issue