drivers: sdhc: sdhc_spi: wait for card response until cmd timeout

In sdhc_spi_response_get, the logic for slow cards previously only
retried reads 16 times. Instead of using this approach, read from the
card every 10 ms until the command timeout is reached or it responds.
This way, the command timeout will be respected for cards that do not
respond.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2024-01-17 00:15:57 +00:00 committed by Alberto Escolar
parent ba7b7ffff2
commit 429188723e

View file

@ -206,7 +206,7 @@ static int sdhc_spi_response_get(const struct device *dev, struct sdhc_command *
struct sdhc_spi_data *dev_data = dev->data;
uint8_t *response = dev_data->scratch;
uint8_t *end = response + rx_len;
int ret;
int ret, timeout = cmd->timeout_ms;
uint8_t value, i;
/* First step is finding the first valid byte of the response.
@ -224,7 +224,7 @@ static int sdhc_spi_response_get(const struct device *dev, struct sdhc_command *
*/
response = dev_data->scratch;
end = response + 1;
for (i = 0; i < 16; i++) {
while (timeout > 0) {
ret = sdhc_spi_rx(config->spi_dev, dev_data->spi_cfg,
response, 1);
if (ret < 0) {
@ -233,6 +233,9 @@ static int sdhc_spi_response_get(const struct device *dev, struct sdhc_command *
if (*response != 0xff) {
break;
}
/* Delay for a bit, and poll the card again */
k_msleep(10);
timeout -= 10;
}
if (*response == 0xff) {
return -ETIMEDOUT;