Commit 04f967ad authored by Ulf Hansson's avatar Ulf Hansson

mmc: core: Extend re-use of __mmc_poll_for_busy()

Via __mmc_poll_for_busy() we end up polling with the ->card_busy() host ops
or by sending the CMD13. To allow polling of different types, which is
needed to support a few new SD card features, let's rework the code around
__mmc_poll_for_busy() to make it more generic.

More precisely, let __mmc_poll_for_busy() take a pointer to a callback
function as in-parameter, which it calls to poll for busy state completion.
Additionally, let's share __mmc_poll_for_busy() to allow it to be re-used
outside of mmc_ops.c. Subsequent changes will make use of it.
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Reviewed-by: default avatarShawn Lin <shawn.lin@rock-chips.com>
Acked-by: default avatarAvri Altman <avri.altman@wdc.com>
Link: https://lore.kernel.org/r/20210504161222.101536-5-ulf.hansson@linaro.org
parent 1e0b069b
...@@ -1671,7 +1671,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, ...@@ -1671,7 +1671,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
goto out; goto out;
/* Let's poll to find out when the erase operation completes. */ /* Let's poll to find out when the erase operation completes. */
err = mmc_poll_for_busy(card, busy_timeout, MMC_BUSY_ERASE); err = mmc_poll_for_busy(card, busy_timeout, false, MMC_BUSY_ERASE);
out: out:
mmc_retune_release(card->host); mmc_retune_release(card->host);
......
...@@ -53,6 +53,12 @@ static const u8 tuning_blk_pattern_8bit[] = { ...@@ -53,6 +53,12 @@ static const u8 tuning_blk_pattern_8bit[] = {
0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
}; };
struct mmc_busy_data {
struct mmc_card *card;
bool retry_crc_err;
enum mmc_busy_cmd busy_cmd;
};
int __mmc_send_status(struct mmc_card *card, u32 *status, unsigned int retries) int __mmc_send_status(struct mmc_card *card, u32 *status, unsigned int retries)
{ {
int err; int err;
...@@ -424,10 +430,10 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) ...@@ -424,10 +430,10 @@ 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, static int mmc_busy_cb(void *cb_data, bool *busy)
enum mmc_busy_cmd busy_cmd, bool *busy)
{ {
struct mmc_host *host = card->host; struct mmc_busy_data *data = cb_data;
struct mmc_host *host = data->card->host;
u32 status = 0; u32 status = 0;
int err; int err;
...@@ -436,17 +442,17 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, ...@@ -436,17 +442,17 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err,
return 0; return 0;
} }
err = mmc_send_status(card, &status); err = mmc_send_status(data->card, &status);
if (retry_crc_err && err == -EILSEQ) { if (data->retry_crc_err && err == -EILSEQ) {
*busy = true; *busy = true;
return 0; return 0;
} }
if (err) if (err)
return err; return err;
switch (busy_cmd) { switch (data->busy_cmd) {
case MMC_BUSY_CMD6: case MMC_BUSY_CMD6:
err = mmc_switch_status_error(card->host, status); err = mmc_switch_status_error(host, status);
break; break;
case MMC_BUSY_ERASE: case MMC_BUSY_ERASE:
err = R1_STATUS(status) ? -EIO : 0; err = R1_STATUS(status) ? -EIO : 0;
...@@ -464,8 +470,9 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, ...@@ -464,8 +470,9 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err,
return 0; return 0;
} }
static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
bool retry_crc_err, enum mmc_busy_cmd busy_cmd) int (*busy_cb)(void *cb_data, bool *busy),
void *cb_data)
{ {
struct mmc_host *host = card->host; struct mmc_host *host = card->host;
int err; int err;
...@@ -482,7 +489,7 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, ...@@ -482,7 +489,7 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
*/ */
expired = time_after(jiffies, timeout); expired = time_after(jiffies, timeout);
err = mmc_busy_status(card, retry_crc_err, busy_cmd, &busy); err = (*busy_cb)(cb_data, &busy);
if (err) if (err)
return err; return err;
...@@ -505,9 +512,15 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, ...@@ -505,9 +512,15 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
} }
int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
enum mmc_busy_cmd busy_cmd) bool retry_crc_err, enum mmc_busy_cmd busy_cmd)
{ {
return __mmc_poll_for_busy(card, timeout_ms, false, busy_cmd); struct mmc_busy_data cb_data;
cb_data.card = card;
cb_data.retry_crc_err = retry_crc_err;
cb_data.busy_cmd = busy_cmd;
return __mmc_poll_for_busy(card, timeout_ms, &mmc_busy_cb, &cb_data);
} }
bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd,
...@@ -591,8 +604,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, ...@@ -591,8 +604,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
} }
/* Let's try to poll to find out when the command is completed. */ /* Let's try to poll to find out when the command is completed. */
err = __mmc_poll_for_busy(card, timeout_ms, retry_crc_err, err = mmc_poll_for_busy(card, timeout_ms, retry_crc_err, MMC_BUSY_CMD6);
MMC_BUSY_CMD6);
if (err) if (err)
goto out; goto out;
...@@ -840,7 +852,7 @@ static int mmc_send_hpi_cmd(struct mmc_card *card) ...@@ -840,7 +852,7 @@ static int mmc_send_hpi_cmd(struct mmc_card *card)
return 0; return 0;
/* Let's poll to find out when the HPI request completes. */ /* Let's poll to find out when the HPI request completes. */
return mmc_poll_for_busy(card, busy_timeout_ms, MMC_BUSY_HPI); return mmc_poll_for_busy(card, busy_timeout_ms, false, MMC_BUSY_HPI);
} }
/** /**
......
...@@ -38,8 +38,11 @@ int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); ...@@ -38,8 +38,11 @@ int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal);
bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd,
unsigned int timeout_ms); unsigned int timeout_ms);
int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
int (*busy_cb)(void *cb_data, bool *busy),
void *cb_data);
int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms,
enum mmc_busy_cmd busy_cmd); bool retry_crc_err, enum mmc_busy_cmd busy_cmd);
int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
unsigned int timeout_ms, unsigned char timing, unsigned int timeout_ms, unsigned char timing,
bool send_status, bool retry_crc_err, unsigned int retries); bool send_status, bool retry_crc_err, unsigned int retries);
......
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