Skip to content

Commit 6fa7965

Browse files
author
Ulf Hansson
committed
mmc: core: Enable eMMC sleep commands to use HW busy polling
After the eMMC sleep command (CMD5) has been sent, the card start signals busy on the DAT0 line, which can be monitored to understand when it's allowed to proceed to power off the VCC regulator. When MMC_CAP_WAIT_WHILE_BUSY isn't supported by the host the DAT0 line isn't being monitored for busy completion, but instead we are waiting a fixed period of time. The time corresponds to the sleep timeout that is specified in the EXT_CSD register of the eMMC card. This is many cases suboptimal, as the timeout corresponds to the worst case scenario. To improve the situation add support for HW busy polling through the ->card_busy() host ops, when the host supports this. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com> Acked-by: Avri Altman <avri.altman@wdc.com> Link: https://lore.kernel.org/r/20210504161222.101536-6-ulf.hansson@linaro.org
1 parent 04f967a commit 6fa7965

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎drivers/mmc/core/mmc.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,14 @@ static int mmc_can_sleep(struct mmc_card *card)
19051905
return card->ext_csd.rev >= 3;
19061906
}
19071907

1908+
static int mmc_sleep_busy_cb(void *cb_data, bool *busy)
1909+
{
1910+
struct mmc_host *host = cb_data;
1911+
1912+
*busy = host->ops->card_busy(host);
1913+
return 0;
1914+
}
1915+
19081916
static int mmc_sleep(struct mmc_host *host)
19091917
{
19101918
struct mmc_command cmd = {};
@@ -1930,13 +1938,20 @@ static int mmc_sleep(struct mmc_host *host)
19301938
goto out_release;
19311939

19321940
/*
1933-
* If the host does not wait while the card signals busy, then we will
1934-
* will have to wait the sleep/awake timeout. Note, we cannot use the
1935-
* SEND_STATUS command to poll the status because that command (and most
1936-
* others) is invalid while the card sleeps.
1941+
* If the host does not wait while the card signals busy, then we can
1942+
* try to poll, but only if the host supports HW polling, as the
1943+
* SEND_STATUS cmd is not allowed. If we can't poll, then we simply need
1944+
* to wait the sleep/awake timeout.
19371945
*/
1938-
if (!use_r1b_resp || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY))
1946+
if (host->caps & MMC_CAP_WAIT_WHILE_BUSY && use_r1b_resp)
1947+
goto out_release;
1948+
1949+
if (!host->ops->card_busy) {
19391950
mmc_delay(timeout_ms);
1951+
goto out_release;
1952+
}
1953+
1954+
err = __mmc_poll_for_busy(card, timeout_ms, &mmc_sleep_busy_cb, host);
19401955

19411956
out_release:
19421957
mmc_retune_release(host);

0 commit comments

Comments
 (0)