Skip to content

Commit a2087be

Browse files
danieldegrassecarlescufi
authored andcommitted
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 <[email protected]>
1 parent cb9d8ba commit a2087be

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/sdhc/sdhc_spi.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ static int sdhc_spi_request(const struct device *dev,
604604
{
605605
const struct sdhc_spi_config *config = dev->config;
606606
struct sdhc_spi_data *dev_data = dev->data;
607-
int ret, retries = cmd->retries;
607+
int ret, stop_ret, retries = cmd->retries;
608608
const struct sdhc_command stop_cmd = {
609609
.opcode = SD_STOP_TRANSMISSION,
610610
.arg = 0,
@@ -618,6 +618,7 @@ static int sdhc_spi_request(const struct device *dev,
618618
} while ((ret != 0) && (retries-- > 0));
619619
} else {
620620
do {
621+
retries--;
621622
ret = sdhc_spi_send_cmd(dev, cmd, true);
622623
if (ret) {
623624
continue;
@@ -629,14 +630,23 @@ static int sdhc_spi_request(const struct device *dev,
629630
ret = sdhc_spi_read_data(dev, data);
630631
}
631632
if (ret || (cmd->opcode == SD_READ_MULTIPLE_BLOCK)) {
633+
int stop_retries = cmd->retries;
634+
632635
/* CMD12 is required after multiple read, or
633636
* to retry failed transfer
634637
*/
635-
sdhc_spi_send_cmd(dev,
638+
stop_ret = sdhc_spi_send_cmd(dev,
636639
(struct sdhc_command *)&stop_cmd,
637640
false);
641+
while ((stop_ret != 0) && (stop_retries > 0)) {
642+
/* Retry stop command */
643+
ret = stop_ret = sdhc_spi_send_cmd(dev,
644+
(struct sdhc_command *)&stop_cmd,
645+
false);
646+
stop_retries--;
647+
}
638648
}
639-
} while ((ret != 0) && (retries-- > 0));
649+
} while ((ret != 0) && (retries > 0));
640650
}
641651
if (ret) {
642652
/* Release SPI bus */

0 commit comments

Comments
 (0)