@@ -949,46 +949,9 @@ static inline bool mmc_blk_in_tran_state(u32 status)
(R1_CURRENT_STATE(status) == R1_STATE_TRAN);
}
-static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
- struct request *req, u32 *resp_errs)
+static inline bool mmc_blk_in_busy_state(u32 status)
{
- unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
- int err = 0;
- u32 status;
-
- do {
- bool done = time_after(jiffies, timeout);
-
- err = __mmc_send_status(card, &status, 5);
- if (err) {
- pr_err("%s: error %d requesting status\n",
- req->rq_disk->disk_name, err);
- return err;
- }
-
- /* Accumulate any response error bits seen */
- if (resp_errs)
- *resp_errs |= status;
-
- /*
- * Timeout if the device never becomes ready for data and never
- * leaves the program state.
- */
- if (done) {
- pr_err("%s: Card stuck in wrong state! %s %s status: %#x\n",
- mmc_hostname(card->host),
- req->rq_disk->disk_name, __func__, status);
- return -ETIMEDOUT;
- }
-
- /*
- * Some cards mishandle the status bits,
- * so make sure to check both the busy
- * indication and the card state.
- */
- } while (!mmc_blk_in_tran_state(status));
-
- return err;
+ return !(mmc_blk_in_tran_state(status));
}
static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
@@ -1636,7 +1599,9 @@ static int mmc_blk_fix_state(struct mmc_card *card, struct request *req)
mmc_blk_send_stop(card, timeout);
- err = card_busy_detect(card, timeout, req, NULL);
+ err = mmc_poll_for_busy(card, timeout, true, false, false, NULL,
+ &mmc_blk_in_busy_state, false);
+
mmc_retune_release(card->host);
@@ -1857,10 +1822,11 @@ static int mmc_blk_card_busy(struct mmc_card *card, struct request *req)
u32 status = 0;
int err;
- if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ)
+ if (rq_data_dir(req) == READ)
return 0;
- err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, req, &status);
+ err = mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, true, false, false,
+ &status, &mmc_blk_in_busy_state, false);
/*
* Do not assume data transferred correctly if there are any error bits
This patch removes card_busy_detect() and use mmc_poll_for_busy() instead. Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com> --- Changes in v3: - remove mmc_host_is_spi() from mmc_blk_card_busy() as mmc_poll_for_busy() has considered it. Changes in v2: None drivers/mmc/core/block.c | 50 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 42 deletions(-)