Skip to contentSkip to conversation

mmc: Add support for enumerating MMC card in a given mode using mmc command

PATCH Superseded Aswath Govindraju 3 participants 10 messages Jul 29, 2021 – Jul 30, 2021 MMC, SD and SDIO

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +50 -21

209 lines not on this page · raw message

drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
Signature · 1 line
2.17.1
#1 lore raw

Hi Aswath,

Quoted 5 lines · Aswath Govindraju

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.

Thanks for this patch. It seems that it's useful to develope and debug. I will test with this patch.

Could you also update doc/usage/mmc.rst file?

Best Regards,
Jaehoo Chung

Quoted 322 lines
---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +50 -21
index b942576b58ac..073e87d69634 100644
@@ -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,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+
 	if (mmc_init(mmc))
 		return NULL;
 
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -482,8 +489,19 @@ 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, MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		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;
 
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10);
@@ -528,11 +549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,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)
drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
#2 lore raw

Hi Jaehoon,

Quoted 9 lines · Jaehoon Chung

Hi Aswath,

Quoted 5 lines · Aswath Govindraju

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.

Quoted 5 lines

Thanks for this patch. It seems that it's useful to develope and debug. I will test with this patch.

Could you also update doc/usage/mmc.rst file?

Sure, I'll update it in the respin.

Thanks,
Aswath

Quoted 326 lines

Best Regards,
Jaehoo Chung

Quoted 322 lines
---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +50 -21
index b942576b58ac..073e87d69634 100644
@@ -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,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+
 	if (mmc_init(mmc))
 		return NULL;
 
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -482,8 +489,19 @@ 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, MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		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;
 
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10);
@@ -528,11 +549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,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)
drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
#3 lore raw

Hi Aswath,

Quoted 12 lines · Aswath Govindraju

Hi Jaehoon,

Quoted 9 lines · Jaehoon Chung

Hi Aswath,

Quoted 5 lines · Aswath Govindraju

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.

Quoted 7 lines
Quoted 5 lines

Thanks for this patch. It seems that it's useful to develope and debug. I will test with this patch.

Could you also update doc/usage/mmc.rst file?

Sure, I'll update it in the respin.

When I have simply tested with this patch, it's not working correct. I will test more and share them. Did you test about SD-card?

Best Regards,
Jaehoon Chung

Quoted 332 lines

Thanks,
Aswath

Quoted 326 lines

Best Regards,
Jaehoo Chung

Quoted 322 lines
---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +50 -21
index b942576b58ac..073e87d69634 100644
@@ -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,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+
 	if (mmc_init(mmc))
 		return NULL;
 
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -482,8 +489,19 @@ 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, MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		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;
 
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10);
@@ -528,11 +549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,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)
drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
#4 lore raw

Hi Jaehoon,

Quoted 18 lines · Jaehoon Chung

Hi Aswath,

Quoted 15 lines · Aswath Govindraju

Hi Jaehoon,

Quoted 12 lines · Jaehoon Chung

Hi Aswath,

Quoted 5 lines · Aswath Govindraju

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.

Thanks for this patch. It seems that it's useful to develope and debug. I will test with this patch.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Could you also update doc/usage/mmc.rst file?

Sure, I'll update it in the respin.

When I have simply tested with this patch, it's not working correct. I will test more and share them. Did you test about SD-card?

Yes, I tested with both SD-Card and eMMC.

Also, please note that MMC_SPEED_MODE_SET has to be enabled in the defconfig files.

Thanks,
Aswath

Quoted 336 lines

Best Regards,
Jaehoon Chung

Quoted 332 lines

Thanks,
Aswath

Quoted 326 lines

Best Regards,
Jaehoo Chung

Quoted 322 lines
---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +50 -21
index b942576b58ac..073e87d69634 100644
@@ -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,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+
 	if (mmc_init(mmc))
 		return NULL;
 
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -482,8 +489,19 @@ 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, MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		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;
 
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10);
@@ -528,11 +549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,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)
drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
#5 lore raw
Quoted 26 lines · Aswath Govindraju

Hi Jaehoon,

Quoted 23 lines · Jaehoon Chung

Hi Aswath,

Quoted 19 lines · Aswath Govindraju

Hi Jaehoon,

Quoted 9 lines · Jaehoon Chung

Hi Aswath,

Quoted 5 lines · Aswath Govindraju

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.

Quoted 5 lines

Thanks for this patch. It seems that it's useful to develope and debug. I will test with this patch.

Could you also update doc/usage/mmc.rst file?

Sure, I'll update it in the respin.

Quoted 8 lines
Quoted 3 lines

When I have simply tested with this patch, it's not working correct. I will test more and share them. Did you test about SD-card?

Yes, I tested with both SD-Card and eMMC.

Also, please note that MMC_SPEED_MODE_SET has to be enabled in the defconfig files.

I did. :) (enabled MMC_SPEED_MODE_SET).
If it's not supported mode, it seems that always set to LEGACY mode. Is it intention behavior?

I will test on eMMC and SD. Well it will take a little time. Maybe Next week?

Best Regards,
Jaehoon Chung

Quoted 342 lines

Thanks,
Aswath

Quoted 336 lines

Best Regards,
Jaehoon Chung

Quoted 332 lines

Thanks,
Aswath

Quoted 326 lines

Best Regards,
Jaehoo Chung

Quoted 322 lines
---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +50 -21
index b942576b58ac..073e87d69634 100644
@@ -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,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+
 	if (mmc_init(mmc))
 		return NULL;
 
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -482,8 +489,19 @@ 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, MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		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;
 
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10);
@@ -528,11 +549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,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)
drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
#6 lore raw

Hi Jaehoon,

Quoted 22 lines · Jaehoon Chung
Quoted 21 lines · Aswath Govindraju

Hi Jaehoon,

Quoted 18 lines · Jaehoon Chung

Hi Aswath,

Quoted 15 lines · Aswath Govindraju

Hi Jaehoon,

Quoted 12 lines · Jaehoon Chung

Hi Aswath,

Quoted 5 lines · Aswath Govindraju

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.

Thanks for this patch. It seems that it's useful to develope and debug. I will test with this patch.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Could you also update doc/usage/mmc.rst file?

Sure, I'll update it in the respin.

When I have simply tested with this patch, it's not working correct. I will test more and share them. Did you test about SD-card?

Actually I just found one error but I am not sure if it is the same error you are seeing.

In my case even if mode is supported it shows that if is not supported and this is because of [1], it should have been dev there. On correcting it I don't see this error anymore.

Quoted 9 lines
Quoted 5 lines

Yes, I tested with both SD-Card and eMMC.

Also, please note that MMC_SPEED_MODE_SET has to be enabled in the defconfig files.

I did. :) (enabled MMC_SPEED_MODE_SET).
If it's not supported mode, it seems that always set to LEGACY mode. Is it intention behavior?

No, it is not expected to always set to MMC_LEGACY mode if an unsupported mode is input.

Quoted 2 lines

I will test on eMMC and SD. Well it will take a little time. Maybe Next week?

Sure, I will post a respin before this weekend. Please do test and share your results.

Thanks,
Aswath

Quoted 174 lines

Best Regards,
Jaehoon Chung

Quoted 171 lines

Thanks,
Aswath

Quoted 167 lines

Best Regards,
Jaehoon Chung

Quoted 164 lines

Thanks,
Aswath

Quoted 160 lines

Best Regards,
Jaehoo Chung

Quoted 157 lines
---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +10 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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
cmd/mmc.c +30 -9
index b942576b58ac..073e87d69634 100644
@@ -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,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+
 	if (mmc_init(mmc))
 		return NULL;
 
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -482,8 +489,19 @@ 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, MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		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;
 
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10);
@@ -528,11 +549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

cmd/mmc.c static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, · line 557

Quoted 8 lines
cmd/mmc.c +6 -0
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);

[1]

Quoted 164 lines
Quoted 163 lines
Quoted 161 lines
Quoted 160 lines
Quoted 158 lines
Quoted 157 lines
cmd/mmc.c +14 -12
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,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)
drivers/mmc/mmc-uclass.c +3 -0
index 0e13238c7e7a..66fe8bed984b 100644
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif
 	return 0;
 }
 
drivers/mmc/mmc.c +18 -0
index 8078a89f18cb..b24a45d458d4 100644
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) |
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(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_CAP(MMC_LEGACY) | MMC_MODE_1BIT);
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h +4 -0
index 0bf19de20e52..e64ef7611dd7 100644
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
#7 lore raw
In reply to Aswath Govindraju

Hi Aswath,

Quoted 68 lines

-----Original Message-----
From: Aswath Govindraju <[email protected]>
Sent: Thursday, July 29, 2021 8:25 PM
Cc: Lokesh Vutla <[email protected]>; Vignesh Raghavendra <[email protected]>; Kishon Vijay Abraham I <[email protected]>; Aswath Govindraju <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; Simon Glass <[email protected]>; Heinrich Schuchardt <[email protected]>; Bin Meng <[email protected]>; Patrick Delaunay <[email protected]>; Pragnesh Patel <[email protected]>; Frédéric Danis <[email protected]>; Reuben Dowle <[email protected]>; Yangbo Lu <[email protected]>; Stefan Bosch <[email protected]>; Ashok Reddy Soma <[email protected]>; Nicolas Saenz Julienne <[email protected]>; Pali Rohár <[email protected]>; [email protected]
Subject: [PATCH] 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.

---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +6 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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.

cmd/Kconfig +4 -0
+	  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
cmd/mmc.c +3 -1
index b942576b58ac..073e87d69634 100644
@@ -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);

cmd/mmc.c static struct mmc *init_mmc_device(int dev, bool · line 144

Quoted 9 lines
cmd/mmc.c +5 -0
@@ -134,6 +136,11 @@ static struct mmc *init_mmc_device(int dev, bool
 force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+

Can you please use if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)

Quoted 234 lines
cmd/mmc.c +18 -7
 	if (mmc_init(mmc))
 		return NULL;
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag,
 int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl
 *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -482,8 +489,19 @@ 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,
 MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		mmc = init_mmc_device(curr_device, true, speed_mode);
+	} else {
+		return CMD_RET_USAGE;
+	}
 
-	mmc = init_mmc_device(curr_device, true);
 	if (!mmc)
cmd/mmc.c +12 -3
 		return CMD_RET_FAILURE;
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10); @@ -528,11
+549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp,
 int flag,
 	enum mmc_hwpart_conf_mode mode =
 MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
cmd/mmc.c +6 -6
 		return CMD_RET_FAILURE;
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int
 flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp,
 int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int
 flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int
 flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl
 *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int
 flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
cmd/mmc.c +2 -2
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,12 @@ U_BOOT_CMD(

cmd/mmc.c +2 -2
 	"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"

cmd/mmc.c +1 -0
+	"  - the required speed mode is passed as the index from the following

list\n"

cmd/mmc.c +1 -0
+	"    [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52,

UHS_SDR12, UHS_SDR25,\n"

cmd/mmc.c +1 -0
+	"    UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200,

MMC_HS_400, MMC_HS_400_ES]\n"

cmd/mmc.c +0 -0
 	"mmc list - lists available devices\n"
 	"mmc wp - power on write protect boot partitions\n"
 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
drivers/mmc/mmc-uclass.c index renamed from drivers/mmc/mmc-uclass.c +0 -0

0e13238c7e7a..66fe8bed984b 100644

drivers/mmc/mmc-uclass.c int mmc_bind(struct udevice *dev, struct mmc *mmc, · line 421

Quoted 7 lines
drivers/mmc/mmc-uclass.c +3 -0
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc,
 const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif

same here

Quoted 11 lines
drivers/mmc/mmc-uclass.c +0 -0
 	return 0;
 }
drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0 -0

8078a89f18cb..b24a45d458d4 100644

drivers/mmc/mmc.c +0 -0
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY)

|

drivers/mmc/mmc.c int mmc_start_init(struct mmc *mmc) · line 2867

Quoted 3 lines
drivers/mmc/mmc.c +2 -0
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)

here as well

Thanks,
Ashok

Quoted 38 lines
drivers/mmc/mmc.c +8 -0
+	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-
Quoted 1 line

user_speed_mode)

drivers/mmc/mmc.c +2 -0
+					   | MMC_CAP(MMC_LEGACY) |
+					   MMC_CAP(MMC_LEGACY) |

MMC_MODE_1BIT);

drivers/mmc/mmc.c +6 -0
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h index renamed from include/mmc.h +0 -0

0bf19de20e52..e64ef7611dd7 100644

include/mmc.h +4 -1
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
--

2.17.1

#8 lore raw

Hi Ashok,

Quoted 328 lines · Ashok Reddy Soma

Hi Aswath,

Quoted 68 lines

-----Original Message-----
From: Aswath Govindraju <[email protected]>
Sent: Thursday, July 29, 2021 8:25 PM
Cc: Lokesh Vutla <[email protected]>; Vignesh Raghavendra <[email protected]>; Kishon Vijay Abraham I <[email protected]>; Aswath Govindraju <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; Simon Glass <[email protected]>; Heinrich Schuchardt <[email protected]>; Bin Meng <[email protected]>; Patrick Delaunay <[email protected]>; Pragnesh Patel <[email protected]>; Frédéric Danis <[email protected]>; Reuben Dowle <[email protected]>; Yangbo Lu <[email protected]>; Stefan Bosch <[email protected]>; Ashok Reddy Soma <[email protected]>; Nicolas Saenz Julienne <[email protected]>; Pali Rohár <[email protected]>; [email protected]
Subject: [PATCH] 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.

---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig +6 -0
index ffef3cc76ca4..3a857b3f6e2e 100644
@@ -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.

cmd/Kconfig +4 -0
+	  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
cmd/mmc.c +3 -1
index b942576b58ac..073e87d69634 100644
@@ -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);

cmd/mmc.c static struct mmc *init_mmc_device(int dev, bool · line 144

Quoted 9 lines
cmd/mmc.c +5 -0
@@ -134,6 +136,11 @@ static struct mmc *init_mmc_device(int dev, bool
 force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+

Can you please use if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)

Quoted 234 lines
cmd/mmc.c +18 -7
 	if (mmc_init(mmc))
 		return NULL;
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag,
 int argc,
 		}
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl
 *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -482,8 +489,19 @@ 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,
 MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		mmc = init_mmc_device(curr_device, true, speed_mode);
+	} else {
+		return CMD_RET_USAGE;
+	}
 
-	mmc = init_mmc_device(curr_device, true);
 	if (!mmc)
cmd/mmc.c +12 -3
 		return CMD_RET_FAILURE;
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10); @@ -528,11
+549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp,
 int flag,
 	enum mmc_hwpart_conf_mode mode =
 MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
cmd/mmc.c +6 -6
 		return CMD_RET_FAILURE;
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int
 flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp,
 int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int
 flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int
 flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl
 *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int
 flag,
 	int err;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
cmd/mmc.c +2 -2
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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 +1068,12 @@ U_BOOT_CMD(

cmd/mmc.c +2 -2
 	"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"

cmd/mmc.c +1 -0
+	"  - the required speed mode is passed as the index from the following

list\n"

cmd/mmc.c +1 -0
+	"    [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52,

UHS_SDR12, UHS_SDR25,\n"

cmd/mmc.c +1 -0
+	"    UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200,

MMC_HS_400, MMC_HS_400_ES]\n"

cmd/mmc.c +0 -0
 	"mmc list - lists available devices\n"
 	"mmc wp - power on write protect boot partitions\n"
 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
drivers/mmc/mmc-uclass.c index renamed from drivers/mmc/mmc-uclass.c +0 -0

0e13238c7e7a..66fe8bed984b 100644

drivers/mmc/mmc-uclass.c int mmc_bind(struct udevice *dev, struct mmc *mmc, · line 421

Quoted 7 lines
drivers/mmc/mmc-uclass.c +3 -0
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc,
 const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END;
+#endif

same here

Quoted 3 lines
drivers/mmc/mmc-uclass.c +0 -0
 	return 0;
 }
Quoted 14 lines

drivers/mmc/mmc.c int mmc_start_init(struct mmc *mmc) · line 2867

Quoted 11 lines
drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0 -0

8078a89f18cb..b24a45d458d4 100644

drivers/mmc/mmc.c +0 -0
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY)

|

drivers/mmc/mmc.c +2 -0
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)

here as well

I can't use if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET) because of [1], as it would lead to build errors.

If it is ok, to remove #ifdef around [1] and add user_speed_mode field irrespective of config, then I will be able to use it.

Thanks,
Aswath

Quoted 28 lines

Thanks,
Ashok

Quoted 25 lines
drivers/mmc/mmc.c +8 -0
+	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-
Quoted 1 line

user_speed_mode)

drivers/mmc/mmc.c +2 -0
+					   | MMC_CAP(MMC_LEGACY) |
+					   MMC_CAP(MMC_LEGACY) |

MMC_MODE_1BIT);

drivers/mmc/mmc.c +6 -0
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h index renamed from include/mmc.h +0 -0

0bf19de20e52..e64ef7611dd7 100644

include/mmc.h +0 -0
Quoted 8 lines

include/mmc.h struct mmc { · line 732

Quoted 8 lines
include/mmc.h +4 -0
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif

[1]

Quoted 6 lines
Quoted 5 lines
include/mmc.h +0 -1
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
--

2.17.1

#9 lore raw

HI Aswath,

Quoted 369 lines

-----Original Message-----
From: Aswath Govindraju <[email protected]>
Sent: Friday, July 30, 2021 10:41 AM
To: Ashok Reddy Soma <[email protected]>
Cc: Lokesh Vutla <[email protected]>; Vignesh Raghavendra <[email protected]>; Kishon Vijay Abraham I <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; Simon Glass <[email protected]>; Heinrich Schuchardt <[email protected]>; Bin Meng <[email protected]>; Patrick Delaunay <[email protected]>; Pragnesh Patel <[email protected]>; Frédéric Danis <[email protected]>; Reuben Dowle <[email protected]>; Yangbo Lu <[email protected]>; Stefan Bosch <[email protected]>; Nicolas Saenz Julienne <[email protected]>; Pali Rohár <[email protected]>; [email protected]
Subject: Re: [PATCH] mmc: Add support for enumerating MMC card in a given mode using mmc command

Hi Ashok,

Quoted 15 lines · Ashok Reddy Soma

Hi Aswath,

Quoted 13 lines

-----Original Message-----
From: Aswath Govindraju <[email protected]>
Sent: Thursday, July 29, 2021 8:25 PM
Cc: Lokesh Vutla <[email protected]>; Vignesh Raghavendra <[email protected]>; Kishon Vijay Abraham I <[email protected]>; Aswath Govindraju <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; Simon Glass <[email protected]>; Heinrich Schuchardt <[email protected]>; Bin Meng <[email protected]>; Patrick Delaunay <[email protected]>; Pragnesh Patel <[email protected]>; Frédéric Danis <[email protected]>; Reuben Dowle <[email protected]>; Yangbo Lu <[email protected]>; Stefan

Bosch

Quoted 76 lines
Quoted 57 lines

<[email protected]>; Ashok Reddy Soma <[email protected]>; Nicolas Saenz Julienne <[email protected]>; Pali Rohár <[email protected]>; [email protected]
Subject: [PATCH] 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.

---
 cmd/Kconfig              | 10 ++++++
 cmd/mmc.c                | 71 ++++++++++++++++++++++++++++------------
 drivers/mmc/mmc-uclass.c |  3 ++
 drivers/mmc/mmc.c        | 18 ++++++++++
 include/mmc.h            |  4 +++
 5 files changed, 85 insertions(+), 21 deletions(-)
cmd/Kconfig index renamed from cmd/Kconfig +0 -0

ffef3cc76ca4..3a857b3f6e2e 100644

cmd/Kconfig +6 -0
@@ -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.

cmd/Kconfig +4 -0
+	  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
cmd/mmc.c +3 -1
index b942576b58ac..073e87d69634 100644
@@ -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);

cmd/mmc.c static struct mmc *init_mmc_device(int dev, bool · line 144

Quoted 9 lines
cmd/mmc.c +5 -0
@@ -134,6 +136,11 @@ static struct mmc *init_mmc_device(int dev, bool
 force_init)
 
 	if (force_init)
 		mmc->has_init = 0;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = speed_mode;
+#endif
+

Can you please use if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)

Quoted 8 lines
cmd/mmc.c +0 -0
 	if (mmc_init(mmc))
 		return NULL;
@@ -159,7 +166,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int
 flag, int argc,
 		}
 	}
 
Quoted 6 lines

cmd/mmc.c static int do_mmcrpmb(struct cmd_tbl *cmdtp, int

Quoted 6 lines
cmd/mmc.c +1 -1
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -293,7 +300,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int

flag,

Quoted 67 lines
Quoted 67 lines
cmd/mmc.c +17 -5
 	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
 		return CMD_RET_SUCCESS;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -338,7 +345,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int
 flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -387,7 +394,7 @@ static int do_mmc_sparse_write(struct cmd_tbl
 *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -431,7 +438,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp,
 int flag,
 	blk = simple_strtoul(argv[2], NULL, 16);
 	cnt = simple_strtoul(argv[3], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -460,7 +467,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp,
 int flag,
 	blk = simple_strtoul(argv[1], NULL, 16);
 	cnt = simple_strtoul(argv[2], NULL, 16);
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -482,8 +489,19 @@ 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,
 MMC_MODES_END);
+	} else if (argc == 2) {
+		/* parse the mode */
+		speed_mode = simple_strtoul(argv[1], NULL, 10);
+		/* Need to pass the the speed mode required too */
+		mmc = init_mmc_device(curr_device, true, speed_mode);
+	} else {
+		return CMD_RET_USAGE;
+	}
 
Quoted 5 lines

cmd/mmc.c static int do_mmc_part(struct cmd_tbl *cmdtp, int

Quoted 5 lines
cmd/mmc.c +0 -1
-	mmc = init_mmc_device(curr_device, true);
 	if (!mmc)
cmd/mmc.c +0 -0
 		return CMD_RET_FAILURE;
@@ -496,7 +514,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int

flag,

Quoted 107 lines
Quoted 107 lines
cmd/mmc.c +12 -3
 	struct blk_desc *mmc_dev;
 	struct mmc *mmc;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
 
@@ -515,11 +533,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, MMC_MODES_END);
 	} else if (argc == 2) {
 		dev = simple_strtoul(argv[1], NULL, 10);
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
 	} else if (argc == 3) {
 		dev = (int)simple_strtoul(argv[1], NULL, 10);
 		part = (int)simple_strtoul(argv[2], NULL, 10); @@ -528,11
+549,16 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
 			       PART_ACCESS_MASK);
 			return CMD_RET_FAILURE;
 		}
+		mmc = init_mmc_device(dev, true, MMC_MODES_END);
+	} else if (argc == 4) {
+		dev = (int)simple_strtoul(argv[1], NULL, 10);
+		part = (int)simple_strtoul(argv[2], NULL, 10);
+		speed_mode = simple_strtoul(argv[3], NULL, 10);
+		mmc = init_mmc_device(curr_device, true, speed_mode);
 	} else {
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, true);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -636,7 +662,7 @@ static int do_mmc_hwpartition(struct cmd_tbl
 *cmdtp, int flag,
 	enum mmc_hwpart_conf_mode mode =
 MMC_HWPART_CONF_CHECK;
 	int i, r, pidx;
 
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
cmd/mmc.c +5 -5
 		return CMD_RET_FAILURE;
@@ -726,7 +752,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp,
 int flag,
 	reset = simple_strtoul(argv[3], NULL, 10);
 	mode = simple_strtoul(argv[4], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -789,7 +815,7 @@ static int do_mmc_boot_resize(struct cmd_tbl
 *cmdtp, int flag,
 	bootsize = simple_strtoul(argv[2], NULL, 10);
 	rpmbsize = simple_strtoul(argv[3], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -844,7 +870,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp,
 int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -887,7 +913,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp,
 int flag,
 		return CMD_RET_USAGE;
 	}
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -939,7 +965,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl
 *cmdtp, int flag,
 
 	dev = simple_strtoul(argv[1], NULL, 10);
 
-	mmc = init_mmc_device(dev, false);
+	mmc = init_mmc_device(dev, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
@@ -958,7 +984,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp,
 int flag,
 	int err;
 	struct mmc *mmc;
 
Quoted 8 lines

cmd/mmc.c static struct cmd_tbl cmd_mmc[] = { #if · line 1010

Quoted 8 lines
cmd/mmc.c +1 -1
-	mmc = init_mmc_device(curr_device, false);
+	mmc = init_mmc_device(curr_device, false, MMC_MODES_END);
 	if (!mmc)
 		return CMD_RET_FAILURE;
cmd/mmc.c +0 -0
 	if (IS_SD(mmc)) {
@@ -983,9 +1009,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

Quoted 8 lines

cmd/mmc.c static struct cmd_tbl cmd_mmc[] = {

Quoted 8 lines
cmd/mmc.c +2 -2
-	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, "",

""),

Quoted 37 lines
Quoted 25 lines
cmd/mmc.c +2 -2
@@ -1042,9 +1068,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"

cmd/mmc.c +2 -0
+	"  - the required speed mode is passed as the index from the
+following

list\n"

cmd/mmc.c +1 -0
+	"    [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52,

UHS_SDR12, UHS_SDR25,\n"

cmd/mmc.c +1 -0
+	"    UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200,

MMC_HS_400, MMC_HS_400_ES]\n"

cmd/mmc.c +0 -0
 	"mmc list - lists available devices\n"
 	"mmc wp - power on write protect boot partitions\n"
 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
drivers/mmc/mmc-uclass.c +0 -0
index 0e13238c7e7a..66fe8bed984b 100644

drivers/mmc/mmc-uclass.c int mmc_bind(struct udevice *dev, struct mmc · line 420

Quoted 6 lines
drivers/mmc/mmc-uclass.c +2 -0
@@ -415,6 +415,9 @@ int mmc_bind(struct udevice *dev, struct mmc
 *mmc, const struct mmc_config *cfg)
 	bdesc->part_type = cfg->part_type;
 	mmc->dev = dev;
 
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	mmc->user_speed_mode = MMC_MODES_END; #endif

same here

Quoted 3 lines
drivers/mmc/mmc-uclass.c +0 -0
 	return 0;
 }
Quoted 14 lines

drivers/mmc/mmc.c int mmc_start_init(struct mmc *mmc) · line 2867

Quoted 11 lines
drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0 -0

8078a89f18cb..b24a45d458d4 100644

drivers/mmc/mmc.c +0 -0
@@ -2863,6 +2863,24 @@ int mmc_start_init(struct mmc *mmc)
 	 */
 	mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY)

|

drivers/mmc/mmc.c +2 -0
 			 MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)

here as well

Quoted 5 lines

I can't use if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET) because of [1], as it would lead to build errors.

If it is ok, to remove #ifdef around [1] and add user_speed_mode field irrespective of config, then I will be able to use it.

I see no problem in removing [1]. Please go ahead.

Thanks,
Ashok

Quoted 49 lines

Thanks,
Aswath

Quoted 28 lines

Thanks,
Ashok

Quoted 25 lines
drivers/mmc/mmc.c +8 -0
+	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-
Quoted 1 line

user_speed_mode)

drivers/mmc/mmc.c +2 -0
+					   | MMC_CAP(MMC_LEGACY) |
+					   MMC_CAP(MMC_LEGACY) |

MMC_MODE_1BIT);

drivers/mmc/mmc.c +6 -0
+		} else {
+			pr_err("bus_mode requested is not supported\n");
+			return -EINVAL;
+		}
+	}
+#endif
 #if CONFIG_IS_ENABLED(DM_MMC)
 	mmc_deferred_probe(mmc);
 #endif
include/mmc.h index renamed from include/mmc.h +0 -0

0bf19de20e52..e64ef7611dd7 100644

include/mmc.h +0 -0
Quoted 8 lines

include/mmc.h struct mmc { · line 732

Quoted 8 lines
include/mmc.h +4 -0
@@ -726,6 +726,10 @@ struct mmc {
 				  */
 	u32 quirks;
 	u8 hs400_tuning;
+
+#if CONFIG_IS_ENABLED(MMC_SPEED_MODE_SET)
+	enum bus_mode user_speed_mode;
+#endif

[1]

Quoted 6 lines
Quoted 5 lines
include/mmc.h +0 -1
 };
 
 #if CONFIG_IS_ENABLED(DM_MMC)
--

2.17.1