drivers: sdhc: sdhc_spi: rework CMD12 failure logic

Rework CMD12 failure logic for SDHC SPI driver. Previously, the error
code of CMD12 was not checked, so even if CMD12 failed to send the
initial command would be retried. Change this behavior to retry CMD12
until it succeeds. If CMD12 fails, its error code will be propagated to
the caller. Otherwise, the return code from the command being sent by
the caller will be propagated.

Fixes #72365

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2024-05-14 11:34:03 -05:00 committed by Carles Cufí
parent cb9d8bac54
commit a2087bed16

View file

@ -604,7 +604,7 @@ static int sdhc_spi_request(const struct device *dev,
{
const struct sdhc_spi_config *config = dev->config;
struct sdhc_spi_data *dev_data = dev->data;
int ret, retries = cmd->retries;
int ret, stop_ret, retries = cmd->retries;
const struct sdhc_command stop_cmd = {
.opcode = SD_STOP_TRANSMISSION,
.arg = 0,
@ -618,6 +618,7 @@ static int sdhc_spi_request(const struct device *dev,
} while ((ret != 0) && (retries-- > 0));
} else {
do {
retries--;
ret = sdhc_spi_send_cmd(dev, cmd, true);
if (ret) {
continue;
@ -629,14 +630,23 @@ static int sdhc_spi_request(const struct device *dev,
ret = sdhc_spi_read_data(dev, data);
}
if (ret || (cmd->opcode == SD_READ_MULTIPLE_BLOCK)) {
int stop_retries = cmd->retries;
/* CMD12 is required after multiple read, or
* to retry failed transfer
*/
sdhc_spi_send_cmd(dev,
stop_ret = sdhc_spi_send_cmd(dev,
(struct sdhc_command *)&stop_cmd,
false);
while ((stop_ret != 0) && (stop_retries > 0)) {
/* Retry stop command */
ret = stop_ret = sdhc_spi_send_cmd(dev,
(struct sdhc_command *)&stop_cmd,
false);
stop_retries--;
}
}
} while ((ret != 0) && (retries-- > 0));
} while ((ret != 0) && (retries > 0));
}
if (ret) {
/* Release SPI bus */