Skip to content

Commit 87a18a6

Browse files
ChaotianJingstorulf
authored andcommitted
mmc: mmc: Use ->card_busy() to detect busy cards in __mmc_switch()
Some MMC hosts do not support MMC_CAP_WAIT_WHILE_BUSY, but implements the ->card_busy() callback. In such cases, extend __mmc_switch() to use this method to check card status after switch command. Signed-off-by: Chaotian Jing <[email protected]> Signed-off-by: Ulf Hansson <[email protected]>
1 parent e613cc4 commit 87a18a6

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

drivers/mmc/core/mmc_ops.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
480480
u32 status = 0;
481481
bool use_r1b_resp = use_busy_signal;
482482
bool expired = false;
483+
bool busy = false;
483484

484485
mmc_retune_hold(host);
485486

@@ -535,19 +536,24 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
535536
/* Must check status to be sure of no errors. */
536537
timeout = jiffies + msecs_to_jiffies(timeout_ms);
537538
do {
539+
/*
540+
* Due to the possibility of being preempted after
541+
* sending the status command, check the expiration
542+
* time first.
543+
*/
544+
expired = time_after(jiffies, timeout);
538545
if (send_status) {
539-
/*
540-
* Due to the possibility of being preempted after
541-
* sending the status command, check the expiration
542-
* time first.
543-
*/
544-
expired = time_after(jiffies, timeout);
545546
err = __mmc_send_status(card, &status, ignore_crc);
546547
if (err)
547548
goto out;
548549
}
549550
if ((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp)
550551
break;
552+
if (host->ops->card_busy) {
553+
if (!host->ops->card_busy(host))
554+
break;
555+
busy = true;
556+
}
551557
if (mmc_host_is_spi(host))
552558
break;
553559

@@ -556,19 +562,20 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
556562
* does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only
557563
* rely on waiting for the stated timeout to be sufficient.
558564
*/
559-
if (!send_status) {
565+
if (!send_status && !host->ops->card_busy) {
560566
mmc_delay(timeout_ms);
561567
goto out;
562568
}
563569

564570
/* Timeout if the device never leaves the program state. */
565-
if (expired && R1_CURRENT_STATE(status) == R1_STATE_PRG) {
571+
if (expired &&
572+
(R1_CURRENT_STATE(status) == R1_STATE_PRG || busy)) {
566573
pr_err("%s: Card stuck in programming state! %s\n",
567574
mmc_hostname(host), __func__);
568575
err = -ETIMEDOUT;
569576
goto out;
570577
}
571-
} while (R1_CURRENT_STATE(status) == R1_STATE_PRG);
578+
} while (R1_CURRENT_STATE(status) == R1_STATE_PRG || busy);
572579

573580
err = mmc_switch_status_error(host, status);
574581
out:

0 commit comments

Comments
 (0)