Commit 6972096a authored by Ulf Hansson's avatar Ulf Hansson

mmc: core: Split up mmc_poll_for_busy()

To make the code more readable, move the part that gets the busy status of
the card out into a separate function, mmc_busy_status(). Then call it from
mmc_poll_for_busy().
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Tested-by: default avatarBaolin Wang <baolin.wang7@gmail.com>
Tested-by: default avatarLudovic Barre <ludovic.barre@st.com>
Reviewed-by: default avatarLudovic Barre <ludovic.barre@st.com>
Link: https://lore.kernel.org/r/20200204085449.32585-6-ulf.hansson@linaro.org
parent 02098ccd
...@@ -444,6 +444,34 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) ...@@ -444,6 +444,34 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal)
return mmc_switch_status_error(card->host, status); return mmc_switch_status_error(card->host, status);
} }
static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err,
bool *busy)
{
struct mmc_host *host = card->host;
u32 status = 0;
int err;
if (host->ops->card_busy) {
*busy = host->ops->card_busy(host);
return 0;
}
err = mmc_send_status(card, &status);
if (retry_crc_err && err == -EILSEQ) {
*busy = true;
return 0;
}
if (err)
return err;
err = mmc_switch_status_error(card->host, status);
if (err)
return err;
*busy = R1_CURRENT_STATE(status) == R1_STATE_PRG;
return 0;
}
static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
bool send_status, bool retry_crc_err) bool send_status, bool retry_crc_err)
{ {
...@@ -451,7 +479,6 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, ...@@ -451,7 +479,6 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
int err; int err;
unsigned long timeout; unsigned long timeout;
unsigned int udelay = 32, udelay_max = 32768; unsigned int udelay = 32, udelay_max = 32768;
u32 status = 0;
bool expired = false; bool expired = false;
bool busy = false; bool busy = false;
...@@ -473,21 +500,9 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, ...@@ -473,21 +500,9 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
*/ */
expired = time_after(jiffies, timeout); expired = time_after(jiffies, timeout);
if (host->ops->card_busy) { err = mmc_busy_status(card, retry_crc_err, &busy);
busy = host->ops->card_busy(host);
} else {
err = mmc_send_status(card, &status);
if (retry_crc_err && err == -EILSEQ) {
busy = true;
} else if (err) {
return err;
} else {
err = mmc_switch_status_error(host, status);
if (err) if (err)
return err; return err;
busy = R1_CURRENT_STATE(status) == R1_STATE_PRG;
}
}
/* Timeout if the device still remains busy. */ /* Timeout if the device still remains busy. */
if (expired && busy) { if (expired && busy) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment