From 4a3ea75de4c5b3053eac326bf1c753ed65df8cb9 Mon Sep 17 00:00:00 2001 From: "Yuezhang.Mo@sony.com" Date: Wed, 17 Mar 2021 06:44:37 +0000 Subject: [PATCH 1/6] Revert "mmc: sdhci: set to INT_DATA_END when there are data" This reverts commit 17ea3c862865c0d704646f67dbf8412f9ff54f59. In eMMC specification, for the response-with-busy(R1b, R5b) command, the DAT0 will driven to LOW as BUSY status, and in sdhci specification, the transfer complete bit should be wait for BUSY status de-assert. All response-with-busy commands don't contain data, the data judgement is no need. Signed-off-by: Yuezhang.Mo Reviewed-by: Andy Wu Reviewed-by: Jaehoon Chung --- drivers/mmc/sdhci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 2f78da61beb..03bfd9d18ae 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -258,8 +258,7 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, flags = SDHCI_CMD_RESP_LONG; else if (cmd->resp_type & MMC_RSP_BUSY) { flags = SDHCI_CMD_RESP_SHORT_BUSY; - if (data) - mask |= SDHCI_INT_DATA_END; + mask |= SDHCI_INT_DATA_END; } else flags = SDHCI_CMD_RESP_SHORT; From 19f7a34a4642e25aa8b80c6d75129fe7848a158d Mon Sep 17 00:00:00 2001 From: Aswath Govindraju Date: Fri, 13 Aug 2021 23:04:41 +0530 Subject: [PATCH 2/6] mmc: Add support for enumerating MMC card in a given mode using mmc command Add support for enumerating MMC card in a given mode using mmc rescan and mmc dev commands. The speed mode is provided as the last argument in these commands and is indicated using the index from enum bus_mode in include/mmc.h. A speed mode can be set only if it has already been enabled in the device tree. Signed-off-by: Aswath Govindraju Reviewed-by: Jaehoon Chung Tested-by: Jaehoon Chung --- cmd/Kconfig | 10 ++++++++ cmd/mmc.c | 52 +++++++++++++++++++++++++++++++++------- drivers/mmc/mmc-uclass.c | 5 +++- drivers/mmc/mmc.c | 22 ++++++++++++++++- include/mmc.h | 2 ++ 5 files changed, 81 insertions(+), 10 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index ffef3cc76ca..3a857b3f6e2 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2389,4 +2389,14 @@ config CMD_UBIFS help UBIFS is a file system for flash devices which works on top of UBI. +config MMC_SPEED_MODE_SET + bool "set speed mode using mmc command" + depends on CMD_MMC + default n + help + Enable setting speed mode using mmc rescan and mmc dev commands. + The speed mode is provided as the last argument in these commands + and is indicated using the index from enum bus_mode in + include/mmc.h. A speed mode can be set only if it has already + been enabled in the device tree. endmenu diff --git a/cmd/mmc.c b/cmd/mmc.c index c67ad762422..f1e30d0cf64 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -120,7 +120,9 @@ static void print_mmcinfo(struct mmc *mmc) } } } -static struct mmc *init_mmc_device(int dev, bool force_init) + +static struct mmc *__init_mmc_device(int dev, bool force_init, + enum bus_mode speed_mode) { struct mmc *mmc; mmc = find_mmc_device(dev); @@ -134,6 +136,10 @@ static struct mmc *init_mmc_device(int dev, bool force_init) if (force_init) mmc->has_init = 0; + + if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)) + mmc->user_speed_mode = speed_mode; + if (mmc_init(mmc)) return NULL; @@ -145,6 +151,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init) return mmc; } +static struct mmc *init_mmc_device(int dev, bool force_init) +{ + return __init_mmc_device(dev, force_init, MMC_MODES_END); +} + static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -482,8 +493,17 @@ static int do_mmc_rescan(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct mmc *mmc; + enum bus_mode speed_mode = MMC_MODES_END; + + if (argc == 1) { + mmc = init_mmc_device(curr_device, true); + } else if (argc == 2) { + speed_mode = (int)dectoul(argv[1], NULL); + mmc = __init_mmc_device(curr_device, true, speed_mode); + } else { + return CMD_RET_USAGE; + } - mmc = init_mmc_device(curr_device, true); if (!mmc) return CMD_RET_FAILURE; @@ -515,11 +535,14 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, { int dev, part = 0, ret; struct mmc *mmc; + enum bus_mode speed_mode = MMC_MODES_END; if (argc == 1) { dev = curr_device; + mmc = init_mmc_device(dev, true); } else if (argc == 2) { - dev = dectoul(argv[1], NULL); + dev = (int)dectoul(argv[1], NULL); + mmc = init_mmc_device(dev, true); } else if (argc == 3) { dev = (int)dectoul(argv[1], NULL); part = (int)dectoul(argv[2], NULL); @@ -528,11 +551,21 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, PART_ACCESS_MASK); return CMD_RET_FAILURE; } + mmc = init_mmc_device(dev, true); + } else if (argc == 4) { + dev = (int)dectoul(argv[1], NULL); + part = (int)dectoul(argv[2], NULL); + if (part > PART_ACCESS_MASK) { + printf("#part_num shouldn't be larger than %d\n", + PART_ACCESS_MASK); + return CMD_RET_FAILURE; + } + speed_mode = (int)dectoul(argv[3], NULL); + mmc = __init_mmc_device(dev, true, speed_mode); } else { return CMD_RET_USAGE; } - mmc = init_mmc_device(dev, true); if (!mmc) return CMD_RET_FAILURE; @@ -983,9 +1016,9 @@ static struct cmd_tbl cmd_mmc[] = { #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""), #endif - U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), + U_BOOT_CMD_MKENT(rescan, 2, 1, do_mmc_rescan, "", ""), U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""), - U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""), + U_BOOT_CMD_MKENT(dev, 4, 0, do_mmc_dev, "", ""), U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""), #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""), @@ -1042,9 +1075,12 @@ U_BOOT_CMD( "mmc swrite addr blk#\n" #endif "mmc erase blk# cnt\n" - "mmc rescan\n" + "mmc rescan [mode]\n" "mmc part - lists available partition on current mmc device\n" - "mmc dev [dev] [part] - show or set current mmc device [partition]\n" + "mmc dev [dev] [part] [mode] - show or set current mmc device [partition] and set mode\n" + " - the required speed mode is passed as the index from the following list\n" + " [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52, UHS_SDR12, UHS_SDR25,\n" + " UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200, MMC_HS_400, MMC_HS_400_ES]\n" "mmc list - lists available devices\n" "mmc wp - power on write protect boot partitions\n" #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index 0e13238c7e7..3ee92d03ca2 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -342,6 +342,9 @@ void mmc_do_preinit(void) if (!m) continue; + + m->user_speed_mode = MMC_MODES_END; /* Initialising user set speed mode */ + if (m->preinit) mmc_start_init(m); } @@ -414,7 +417,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) /* setup initial part type */ bdesc->part_type = cfg->part_type; mmc->dev = dev; - + mmc->user_speed_mode = MMC_MODES_END; return 0; } diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 8078a89f18c..bd348974ae7 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -2862,7 +2862,25 @@ int mmc_start_init(struct mmc *mmc) * timings. */ mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) | - MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT; + MMC_MODE_1BIT; + + if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)) { + if (mmc->user_speed_mode != MMC_MODES_END) { + int i; + /* set host caps */ + if (mmc->host_caps & MMC_CAP(mmc->user_speed_mode)) { + /* Remove all existing speed capabilities */ + for (i = MMC_LEGACY; i < MMC_MODES_END; i++) + mmc->host_caps &= ~MMC_CAP(i); + mmc->host_caps |= (MMC_CAP(mmc->user_speed_mode) + | MMC_CAP(MMC_LEGACY) | + MMC_MODE_1BIT); + } else { + pr_err("bus_mode requested is not supported\n"); + return -EINVAL; + } + } + } #if CONFIG_IS_ENABLED(DM_MMC) mmc_deferred_probe(mmc); #endif @@ -3060,6 +3078,8 @@ int mmc_init_device(int num) } m = mmc_get_mmc_dev(dev); + m->user_speed_mode = MMC_MODES_END; /* Initialising user set speed mode */ + if (!m) return 0; if (m->preinit) diff --git a/include/mmc.h b/include/mmc.h index 0bf19de20e5..b92e2553402 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -726,6 +726,8 @@ struct mmc { */ u32 quirks; u8 hs400_tuning; + + enum bus_mode user_speed_mode; /* input speed mode from user */ }; #if CONFIG_IS_ENABLED(DM_MMC) From b817959bd4cc90c1f6405547a2a6c242b3a4b731 Mon Sep 17 00:00:00 2001 From: Aswath Govindraju Date: Fri, 13 Aug 2021 23:04:42 +0530 Subject: [PATCH 3/6] doc: usage: mmc: Document usage of speed mode in "mmc dev" and "mmc rescan" Add documentation on the usage of "mmc dev" and "mmc rescan" commands to set user defined speed modes. Signed-off-by: Aswath Govindraju --- doc/usage/mmc.rst | 49 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/doc/usage/mmc.rst b/doc/usage/mmc.rst index f20efe3d706..d15b151884f 100644 --- a/doc/usage/mmc.rst +++ b/doc/usage/mmc.rst @@ -12,9 +12,9 @@ Synopsis mmc read addr blk# cnt mmc write addr blk# cnt mmc erase blk# cnt - mmc rescan + mmc rescan [mode] mmc part - mmc dev [dev] [part] + mmc dev [dev] [part] [mode] mmc list mmc wp mmc bootbus @@ -49,6 +49,27 @@ The 'mmc erase' command erases *cnt* blocks on the MMC device starting at block The 'mmc rescan' command scans the available MMC device. + mode + speed mode to set. + CONFIG_MMC_SPEED_MODE_SET should be enabled. The required speed mode is + passed as the index from the following list. + + 0 - MMC_LEGACY + 1 - MMC_HS + 2 - SD_HS + 3 - MMC_HS_52 + 4 - MMC_DDR_52 + 5 - UHS_SDR12 + 6 - UHS_SDR25 + 7 - UHS_SDR50 + 8 - UHS_DDR50 + 9 - UHS_SDR104 + 10 - MMC_HS_200 + 11 - MMC_HS_400 + 12 - MMC_HS_400_ES + + A speed mode can be set only if it has already been enabled in the device tree + The 'mmc part' command displays the list available partition on current mmc device. The 'mmc dev' command shows or set current mmc device. @@ -58,6 +79,27 @@ The 'mmc dev' command shows or set current mmc device. part partition number to change + mode + speed mode to set. + CONFIG_MMC_SPEED_MODE_SET should be enabled. The required speed mode is + passed as the index from the following list. + + 0 - MMC_LEGACY + 1 - MMC_HS + 2 - SD_HS + 3 - MMC_HS_52 + 4 - MMC_DDR_52 + 5 - UHS_SDR12 + 6 - UHS_SDR25 + 7 - UHS_SDR50 + 8 - UHS_DDR50 + 9 - UHS_SDR104 + 10 - MMC_HS_200 + 11 - MMC_HS_400 + 12 - MMC_HS_400_ES + + A speed mode can be set only if it has already been enabled in the device tree + The 'mmc list' command displays the list available devices. The 'mmc wp' command enables "power on write protect" function for boot partitions. @@ -194,6 +236,9 @@ The current device can be shown or set via 'mmc dev' command: => mmc dev 2 0 switch to partitions #0, OK mmc2 is current device + => mmc dev 0 1 4 + switch to partitions #1, OK + mmc0(part 1) is current device The list of available devices can be shown via 'mmc list' command: :: From 3f4e52fc9d81e95ee90f6be7b05ca62fc8c7c1e3 Mon Sep 17 00:00:00 2001 From: Ye Li Date: Tue, 17 Aug 2021 17:20:33 +0800 Subject: [PATCH 4/6] mmc: fix switch issue with send_status disabled When send_status is false or wait_dat0 is not supported, the switch function should not send CMD13 but directly return. Signed-off-by: Ye Li Reviewed-by: Jaehoon Chung --- drivers/mmc/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index bd348974ae7..6f767cbd635 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -823,7 +823,7 @@ static int __mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value, * capable of polling by using mmc_wait_dat0, then rely on waiting the * stated timeout to be sufficient. */ - if (ret == -ENOSYS && !send_status) { + if (ret == -ENOSYS || !send_status) { mdelay(timeout_ms); return 0; } From fb8c2e8fa936f8ebe4b7cc822abe33ff620585cd Mon Sep 17 00:00:00 2001 From: Ye Li Date: Tue, 17 Aug 2021 17:20:34 +0800 Subject: [PATCH 5/6] mmc: fix device_remove when HS400_ES is enabled HS400_ES is missed when down grade to HS mode during device_remove the mmc device Signed-off-by: Ye Li Reviewed-by: Jaehoon Chung --- drivers/mmc/mmc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 6f767cbd635..d3babbfeb1c 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -2092,14 +2092,16 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps) } #if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \ - CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) + CONFIG_IS_ENABLED(MMC_HS400_SUPPORT) || \ + CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT) /* * In case the eMMC is in HS200/HS400 mode, downgrade to HS mode * before doing anything else, since a transition from either of * the HS200/HS400 mode directly to legacy mode is not supported. */ if (mmc->selected_mode == MMC_HS_200 || - mmc->selected_mode == MMC_HS_400) + mmc->selected_mode == MMC_HS_400 || + mmc->selected_mode == MMC_HS_400_ES) mmc_set_card_speed(mmc, MMC_HS, true); else #endif @@ -2970,7 +2972,7 @@ int mmc_deinit(struct mmc *mmc) return sd_select_mode_and_width(mmc, caps_filtered); } else { caps_filtered = mmc->card_caps & - ~(MMC_CAP(MMC_HS_200) | MMC_CAP(MMC_HS_400)); + ~(MMC_CAP(MMC_HS_200) | MMC_CAP(MMC_HS_400) | MMC_CAP(MMC_HS_400_ES)); return mmc_select_mode_and_width(mmc, caps_filtered); } From 285edfd7821e79de579b0bf1a7328dead2304a0b Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Fri, 10 Sep 2021 11:20:52 +0200 Subject: [PATCH 6/6] mmc: fsl_esdhc: remove 1ms sleep in esdhc_send_cmd_common() Since the beginning of this driver which was initially for the MPC8379 and MPC8536 SoCs, there is this spurious 1ms delay. According to the comment it should actually be only 8 clock cycles. Esp. during EFI block transfers, this 1ms add up to a significant delay and slows down EFI boot. I couldn't find any mention in the MPC8536 that there should be a delay of 8 clock cycles between commands. The SD card specification mentions that the clock has to be left enabled for 8 cycles after a command or response. But I don't see how this delay will help with this. Go ahead and just remove it. If there will ever be any regression we can introduce a compile time flag, but for now I'd like to keep it simple. In the split off imx driver this delay was also removed in commit 9098682200e6 ("mmc: fsl_esdhc_imx: remove the 1ms delay before sending command"). Signed-off-by: Michael Walle --- drivers/mmc/fsl_esdhc.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c index 1d98fa65c48..ebb307e9506 100644 --- a/drivers/mmc/fsl_esdhc.c +++ b/drivers/mmc/fsl_esdhc.c @@ -361,13 +361,6 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc, while (esdhc_read32(®s->prsstat) & PRSSTAT_DLA) ; - /* Wait at least 8 SD clock cycles before the next command */ - /* - * Note: This is way more than 8 cycles, but 1ms seems to - * resolve timing issues with some cards - */ - udelay(1000); - /* Set up for a data transfer if we have one */ if (data) { err = esdhc_setup_data(priv, mmc, data);