Skip to content

Commit 4bc31ed

Browse files
computersforpeaceUlf Hansson
authored andcommitted
mmc: core: Set HS clock speed before sending HS CMD13
Way back in commit 4f25580 ("mmc: core: changes frequency to hs_max_dtr when selecting hs400es"), Rockchip engineers noticed that some eMMC don't respond to SEND_STATUS commands very reliably if they're still running at a low initial frequency. As mentioned in that commit, JESD84-B51 P49 suggests a sequence in which the host: 1. sets HS_TIMING 2. bumps the clock ("<= 52 MHz") 3. sends further commands It doesn't exactly require that we don't use a lower-than-52MHz frequency, but in practice, these eMMC don't like it. The aforementioned commit tried to get that right for HS400ES, although it's unclear whether this ever truly worked as committed into mainline, as other changes/refactoring adjusted the sequence in conflicting ways: 08573ea ("mmc: mmc: do not use CMD13 to get status after speed mode switch") 53e6065 ("mmc: core: Allow CMD13 polling when switching to HS mode for mmc") In any case, today we do step 3 before step 2. Let's fix that, and also apply the same logic to HS200/400, where this eMMC has problems too. Resolves errors like this seen when booting some RK3399 Gru/Scarlet systems: [ 2.058881] mmc1: CQHCI version 5.10 [ 2.097545] mmc1: SDHCI controller on fe330000.mmc [fe330000.mmc] using ADMA [ 2.209804] mmc1: mmc_select_hs400es failed, error -84 [ 2.215597] mmc1: error -84 whilst initialising MMC card [ 2.417514] mmc1: mmc_select_hs400es failed, error -110 [ 2.423373] mmc1: error -110 whilst initialising MMC card [ 2.605052] mmc1: mmc_select_hs400es failed, error -110 [ 2.617944] mmc1: error -110 whilst initialising MMC card [ 2.835884] mmc1: mmc_select_hs400es failed, error -110 [ 2.841751] mmc1: error -110 whilst initialising MMC card Ealier versions of this patch bumped to 200MHz/HS200 speeds too early, which caused issues on, e.g., qcom-msm8974-fairphone-fp2. (Thanks for the report Luca!) After a second look, it appears that aligns with JESD84 / page 45 / table 28, so we need to keep to lower (HS / 52 MHz) rates first. Fixes: 08573ea ("mmc: mmc: do not use CMD13 to get status after speed mode switch") Fixes: 53e6065 ("mmc: core: Allow CMD13 polling when switching to HS mode for mmc") Fixes: 4f25580 ("mmc: core: changes frequency to hs_max_dtr when selecting hs400es") Cc: Shawn Lin <shawn.lin@rock-chips.com> Link: https://lore.kernel.org/linux-mmc/11962455.O9o76ZdvQC@g550jk/ Reported-by: Luca Weiss <luca@z3ntu.xyz> Signed-off-by: Brian Norris <briannorris@chromium.org> Tested-by: Luca Weiss <luca@z3ntu.xyz> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220422100824.v4.1.I484f4ee35609f78b932bd50feed639c29e64997e@changeid Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent af2d861 commit 4bc31ed

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

drivers/mmc/core/mmc.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,13 +1384,17 @@ static int mmc_select_hs400es(struct mmc_card *card)
13841384
goto out_err;
13851385
}
13861386

1387+
/*
1388+
* Bump to HS timing and frequency. Some cards don't handle
1389+
* SEND_STATUS reliably at the initial frequency.
1390+
*/
13871391
mmc_set_timing(host, MMC_TIMING_MMC_HS);
1392+
mmc_set_bus_speed(card);
1393+
13881394
err = mmc_switch_status(card, true);
13891395
if (err)
13901396
goto out_err;
13911397

1392-
mmc_set_clock(host, card->ext_csd.hs_max_dtr);
1393-
13941398
/* Switch card to DDR with strobe bit */
13951399
val = EXT_CSD_DDR_BUS_WIDTH_8 | EXT_CSD_BUS_WIDTH_STROBE;
13961400
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
@@ -1448,7 +1452,7 @@ static int mmc_select_hs400es(struct mmc_card *card)
14481452
static int mmc_select_hs200(struct mmc_card *card)
14491453
{
14501454
struct mmc_host *host = card->host;
1451-
unsigned int old_timing, old_signal_voltage;
1455+
unsigned int old_timing, old_signal_voltage, old_clock;
14521456
int err = -EINVAL;
14531457
u8 val;
14541458

@@ -1479,8 +1483,17 @@ static int mmc_select_hs200(struct mmc_card *card)
14791483
false, true, MMC_CMD_RETRIES);
14801484
if (err)
14811485
goto err;
1486+
1487+
/*
1488+
* Bump to HS timing and frequency. Some cards don't handle
1489+
* SEND_STATUS reliably at the initial frequency.
1490+
* NB: We can't move to full (HS200) speeds until after we've
1491+
* successfully switched over.
1492+
*/
14821493
old_timing = host->ios.timing;
1494+
old_clock = host->ios.clock;
14831495
mmc_set_timing(host, MMC_TIMING_MMC_HS200);
1496+
mmc_set_clock(card->host, card->ext_csd.hs_max_dtr);
14841497

14851498
/*
14861499
* For HS200, CRC errors are not a reliable way to know the
@@ -1493,8 +1506,10 @@ static int mmc_select_hs200(struct mmc_card *card)
14931506
* mmc_select_timing() assumes timing has not changed if
14941507
* it is a switch error.
14951508
*/
1496-
if (err == -EBADMSG)
1509+
if (err == -EBADMSG) {
1510+
mmc_set_clock(host, old_clock);
14971511
mmc_set_timing(host, old_timing);
1512+
}
14981513
}
14991514
err:
15001515
if (err) {

0 commit comments

Comments
 (0)