From 41a1285c1c31080661fce8de782d8ee4a57014a9 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 20 Jun 2023 00:38:23 +0200 Subject: [PATCH 1/4] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment For MMC/eMMC, the MMC_CMD_STOP_TRANSMISSION response is R1 for read transfers and R1b for write transfers per JEDEC Standard No. 84-B51 Page 126 . The response is R1b unconditionally per Physical Layer Simplified Specification Version 9.00. Correct the response type and add a comment about it. Signed-off-by: Marek Vasut Reviewed-by: Peng Fan --- drivers/mmc/mmc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 72c1076c56d..541781328a0 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -427,7 +427,16 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start, if (blkcnt > 1) { cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION; cmd.cmdarg = 0; - cmd.resp_type = MMC_RSP_R1b; + /* + * JEDEC Standard No. 84-B51 Page 126 + * CMD12 STOP_TRANSMISSION R1/R1b[3] + * NOTE 3 R1 for read cases and R1b for write cases. + * + * Physical Layer Simplified Specification Version 9.00 + * 7.3.1.3 Detailed Command Description + * CMD12 R1b + */ + cmd.resp_type = IS_SD(mmc) ? MMC_RSP_R1b : MMC_RSP_R1; if (mmc_send_cmd(mmc, &cmd, NULL)) { #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT) pr_err("mmc fail to send stop cmd\n"); From 0ac2cca3a447cbc59d714b1b35425b54283d153a Mon Sep 17 00:00:00 2001 From: Hai Pham Date: Tue, 20 Jun 2023 00:38:24 +0200 Subject: [PATCH 2/4] mmc: Introduce mmc_send_stop_transmission() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a tuning command times out, the card could still be processing it, which will cause problems for recovery. The eMMC specification section 6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop CMD21: " The relationship between the various data transfer modes is summarized (see Figure 27): - All data read commands can be aborted any time by the stop command (CMD12). The data transfer will terminate and the Device will return to the Transfer State. The read commands are: ... send tuning block (CMD21) .... " Add a function that does that. Based on Linux commit [1] and [2]. [1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()") [2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning cmd") Reviewed-by: Takeshi Kihara Reviewed-by: Marek Vasut Signed-off-by: Hai Pham Signed-off-by: Marek Vasut [Marek: Update commit message, quote relevant part of the specification. Rename to mmc_send_stop_transmission(). Remove tuning opcode check, this is controller driver specific. Deduplicate part of mmc_read_blocks() using this function.] Reviewed-by: Peng Fan --- drivers/mmc/mmc.c | 34 +++++++++++++++++++++------------- include/mmc.h | 2 ++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 541781328a0..de3f569da12 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -398,6 +398,26 @@ int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error) } #endif +int mmc_send_stop_transmission(struct mmc *mmc, bool write) +{ + struct mmc_cmd cmd; + + cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION; + cmd.cmdarg = 0; + /* + * JEDEC Standard No. 84-B51 Page 126 + * CMD12 STOP_TRANSMISSION R1/R1b[3] + * NOTE 3 R1 for read cases and R1b for write cases. + * + * Physical Layer Simplified Specification Version 9.00 + * 7.3.1.3 Detailed Command Description + * CMD12 R1b + */ + cmd.resp_type = (IS_SD(mmc) || write) ? MMC_RSP_R1b : MMC_RSP_R1; + + return mmc_send_cmd(mmc, &cmd, NULL); +} + static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start, lbaint_t blkcnt) { @@ -425,19 +445,7 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start, return 0; if (blkcnt > 1) { - cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION; - cmd.cmdarg = 0; - /* - * JEDEC Standard No. 84-B51 Page 126 - * CMD12 STOP_TRANSMISSION R1/R1b[3] - * NOTE 3 R1 for read cases and R1b for write cases. - * - * Physical Layer Simplified Specification Version 9.00 - * 7.3.1.3 Detailed Command Description - * CMD12 R1b - */ - cmd.resp_type = IS_SD(mmc) ? MMC_RSP_R1b : MMC_RSP_R1; - if (mmc_send_cmd(mmc, &cmd, NULL)) { + if (mmc_send_stop_transmission(mmc, false)) { #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT) pr_err("mmc fail to send stop cmd\n"); #endif diff --git a/include/mmc.h b/include/mmc.h index b8fbff150de..1022db3ffa7 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -558,6 +558,8 @@ int mmc_deferred_probe(struct mmc *mmc); int mmc_reinit(struct mmc *mmc); int mmc_get_b_max(struct mmc *mmc, void *dst, lbaint_t blkcnt); int mmc_hs400_prepare_ddr(struct mmc *mmc); +int mmc_send_stop_transmission(struct mmc *mmc, bool write); + #else struct mmc_ops { int (*send_cmd)(struct mmc *mmc, From 99ab3d8dc45c184dcec692fd7130f8732e8c25e4 Mon Sep 17 00:00:00 2001 From: Hai Pham Date: Tue, 20 Jun 2023 00:38:25 +0200 Subject: [PATCH 3/4] mmc: renesas-sdhi: Send stop when MMC tuning command fails When tuning command (CMD21) fails with command error, call mmc_send_stop_transmission() to send stop command (CMD12). Reviewed-by: Takeshi Kihara Reviewed-by: Marek Vasut Signed-off-by: Hai Pham Signed-off-by: Marek Vasut [Marek: Add dev_dbg() message in case tuning abort fails Move tuning opcode check from mmc_abort_tuning()] Reviewed-by: Peng Fan --- drivers/mmc/renesas-sdhi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c index 280d96dbc2d..8e716f74491 100644 --- a/drivers/mmc/renesas-sdhi.c +++ b/drivers/mmc/renesas-sdhi.c @@ -611,6 +611,17 @@ int renesas_sdhi_execute_tuning(struct udevice *dev, uint opcode) priv->smpcmp |= BIT(i); mdelay(1); + + /* + * eMMC specification specifies that CMD12 can be used to stop a tuning + * command, but SD specification does not, so do nothing unless it is + * eMMC. + */ + if (ret && (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200)) { + ret = mmc_send_stop_transmission(mmc, false); + if (ret < 0) + dev_dbg(dev, "Tuning abort fail (%d)\n", ret); + } } ret = renesas_sdhi_select_tuning(priv, taps); From 50dee4f3610331cc31f1f02f9d4116b716907011 Mon Sep 17 00:00:00 2001 From: Valentine Barshak Date: Sat, 10 Jun 2023 13:22:33 +0200 Subject: [PATCH 4/4] mmc: Set clock when reverting to safe bus mode Set MMC clock when reverting to safe bus mode and speed in case current MMC mode fails. Otherwise, trying out the other modes may fail as well. Reviewed-by: Marek Vasut Signed-off-by: Valentine Barshak [hp: fallback to legacy_speed] Signed-off-by: Hai Pham Reviewed-by: Peng Fan --- drivers/mmc/mmc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index de3f569da12..31cfda28858 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -2240,6 +2240,7 @@ error: mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_1); mmc_select_mode(mmc, MMC_LEGACY); + mmc_set_clock(mmc, mmc->legacy_speed, MMC_CLK_ENABLE); mmc_set_bus_width(mmc, 1); } }