mmc: Add support for enumrating MMC card in user specified mode
v4 cover mmc: Add support for enumrating MMC card in user specified mode
The following series of patches,
- add support enumerating MMC card in user specified speed mode
- add documentation for the usage of above feature
changes since v3:
- split the patch in two, seperating the documentation changes
Aswath Govindraju (2):
mmc: Add support for enumerating MMC card in a given mode using mmc
command
doc: usage: mmc: Document usage of speed mode in "mmc dev" and "mmc
rescan"
cmd/Kconfig | 10 ++++++++ cmd/mmc.c | 52 +++++++++++++++++++++++++++++++++------- doc/usage/mmc.rst | 49 +++++++++++++++++++++++++++++++++++-- drivers/mmc/mmc-uclass.c | 5 +++- drivers/mmc/mmc.c | 22 ++++++++++++++++- include/mmc.h | 2 ++ 6 files changed, 128 insertions(+), 12 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/2 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 | 52 +++++++++++++++++++++++++++++++++------- drivers/mmc/mmc-uclass.c | 5 +++- drivers/mmc/mmc.c | 22 ++++++++++++++++- include/mmc.h | 2 ++ 5 files changed, 81 insertions(+), 10 deletions(-)
cmd/Kconfig +10 -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. + 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 +44 -8
111 lines not on this page · raw message
drivers/mmc/mmc-uclass.c +4 -1
@@ -342,6 +342,9 @@ void mmc_do_preinit(void)if (!m)continue ; + + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (m->preinit)mmc_start_init (m); }
@@ -414,7 +417,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)/* setup initial part type */ bdesc->part_type = cfg->part_type; mmc->dev = dev; - + mmc->user_speed_mode =MMC_MODES_END ;return 0 ; }
drivers/mmc/mmc.c +21 -1
@@ -2862,7 +2862,25 @@ int mmc_start_init(struct mmc *mmc)* timings. */ mmc->host_caps = mmc->cfg->host_caps |MMC_CAP (MMC_LEGACY ) | -MMC_CAP (MMC_LEGACY ) |MMC_MODE_1BIT ; +MMC_MODE_1BIT ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) { +if (mmc->user_speed_mode !=MMC_MODES_END ) { +int i; +/* set host caps */ +if (mmc->host_caps &MMC_CAP (mmc->user_speed_mode)) { +/* Remove all existing speed capabilities */ +for (i =MMC_LEGACY ; i <MMC_MODES_END ; i++) + mmc->host_caps &= ~MMC_CAP (i); + mmc->host_caps |= (MMC_CAP (mmc->user_speed_mode) + |MMC_CAP (MMC_LEGACY ) | +MMC_MODE_1BIT ); + }else { +pr_err ("bus_mode requested is not supported\n" ); +return -EINVAL ; + } + } + }#if CONFIG_IS_ENABLED (DM_MMC )mmc_deferred_probe (mmc);#endif
@@ -3060,6 +3078,8 @@ int mmc_init_device(int num) } m =mmc_get_mmc_dev (dev); + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (!m)return 0 ;if (m->preinit)
include/mmc.h +2 -0
@@ -726,6 +726,8 @@ struct mmc {*/ u32 quirks;u8 hs400_tuning; + +enum bus_mode user_speed_mode;/* input speed mode from user */ };#if CONFIG_IS_ENABLED (DM_MMC )
Signature · 1 line
2.17.1
Re: [PATCH v4 1/2] mmc: Add support for enumerating MMC card in a given mode using mmc command
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_modeininclude/mmc.h. A speed mode can be set only if it has already been enabled in the device tree.
Sorry for replying too late. I have tested with your patch.
It's confused the usage.
Quoted 139 lines
Signed-off-by Aswath Govindraju <[email protected]>--- cmd/Kconfig | 10 ++++++++ cmd/mmc.c | 52 +++++++++++++++++++++++++++++++++------- drivers/mmc/mmc-uclass.c | 5 +++- drivers/mmc/mmc.c | 22 ++++++++++++++++- include/mmc.h | 2 ++ 5 files changed, 81 insertions(+), 10 deletions(-)cmd/Kconfig +10
-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. + 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. endmenucmd/mmc.c +39
-6@@ -120,7 +120,9 @@ static void print_mmcinfo(struct mmc *mmc) } } } -static struct mmc *init_mmc_device (int dev,bool force_init) + +static struct mmc *__init_mmc_device (int dev,bool force_init, +enum bus_mode speed_mode) {struct mmc *mmc; mmc =find_mmc_device (dev);@@ -134,6 +136,10 @@ static struct mmc *init_mmc_device(int dev, bool force_init)if (force_init) mmc->has_init =0 ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) + mmc->user_speed_mode = speed_mode; +if (mmc_init (mmc))return NULL ;@@ -145,6 +151,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)return mmc; } +static struct mmc *init_mmc_device (int dev,bool force_init) +{ +return __init_mmc_device (dev, force_init,MMC_MODES_END ); +} +static int do_mmcinfo (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) {@@ -482,8 +493,17 @@ static int do_mmc_rescan(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct mmc *mmc; +enum bus_mode speed_mode =MMC_MODES_END ; + +if (argc ==1 ) { + mmc =init_mmc_device (curr_device, true); + }else if (argc ==2 ) { + speed_mode = (int )dectoul (argv[1 ],NULL ); + mmc =__init_mmc_device (curr_device, true, speed_mode); + }else { +return CMD_RET_USAGE ; + } - mmc =init_mmc_device (curr_device, true);if (!mmc)return CMD_RET_FAILURE ;@@ -515,11 +535,14 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, {int dev, part =0 , ret;struct mmc *mmc; +enum bus_mode speed_mode =MMC_MODES_END ;if (argc ==1 ) { dev = curr_device; + mmc =init_mmc_device (dev, true); }else if (argc ==2 ) { - dev =dectoul (argv[1 ],NULL ); + dev = (int )dectoul (argv[1 ],NULL ); + mmc =init_mmc_device (dev, true); }else if (argc ==3 ) { dev = (int )dectoul (argv[1 ],NULL ); part = (int )dectoul (argv[2 ],NULL );@@ -528,11 +551,21 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, PART_ACCESS_MASK);return CMD_RET_FAILURE ; } + mmc =init_mmc_device (dev, true); + }else if (argc ==4 ) { + dev = (int )dectoul (argv[1 ],NULL ); + part = (int )dectoul (argv[2 ],NULL ); +if (part >PART_ACCESS_MASK ) { +printf ("#part_num shouldn't be larger than %d\n" , +PART_ACCESS_MASK ); +return CMD_RET_FAILURE ; + } + speed_mode = (int )dectoul (argv[3 ],NULL ); + mmc =__init_mmc_device (dev, true, speed_mode); }else {return CMD_RET_USAGE ; } - mmc =init_mmc_device (dev, true);if (!mmc)return CMD_RET_FAILURE ;@@ -983,9 +1016,9 @@ static struct cmd_tbl cmd_mmc[] = {#if CONFIG_IS_ENABLED (CMD_MMC_SWRITE )U_BOOT_CMD_MKENT (swrite,3 ,0 , do_mmc_sparse_write,"" ,"" ), #endif -U_BOOT_CMD_MKENT (rescan,1 ,1 , do_mmc_rescan,"" ,"" ), +U_BOOT_CMD_MKENT (rescan,2 ,1 , do_mmc_rescan,"" ,"" ),U_BOOT_CMD_MKENT (part,1 ,1 , do_mmc_part,"" ,"" ), -U_BOOT_CMD_MKENT (dev,3 ,0 , do_mmc_dev,"" ,"" ), +U_BOOT_CMD_MKENT (dev,4 ,0 , do_mmc_dev,"" ,"" ),U_BOOT_CMD_MKENT (list,1 ,1 , do_mmc_list,"" ,"" ), #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),@@ -1042,9 +1075,12 @@ U_BOOT_CMD("mmc swrite addr blk#\n"
cmd/mmc.c U_BOOT_CMD( · line 1083
Quoted 10 lines
cmd/mmc.c +5
-2#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"
If developer doesn't read a doc file, it's difficult to know the number of mode. Because this usage seems that [mode] can be passed by string.
When i have tested with your patch, I have run the below command.
# mmc rescan MMC_HS_52 - but it's always set to legacy mode. So I thought this was not working fine. But I have changed to input 3 instead of MMC_HS_52. It's working # mmc rescan 3
Is my test right?
Best Regards,
Jaehoon Chung
Quoted 80 lines
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 +4
-1@@ -342,6 +342,9 @@ void mmc_do_preinit(void)if (!m)continue ; + + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (m->preinit)mmc_start_init (m); }@@ -414,7 +417,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)/* setup initial part type */ bdesc->part_type = cfg->part_type; mmc->dev = dev; - + mmc->user_speed_mode =MMC_MODES_END ;return 0 ; }drivers/mmc/mmc.c +21
-1@@ -2862,7 +2862,25 @@ int mmc_start_init(struct mmc *mmc)* timings. */ mmc->host_caps = mmc->cfg->host_caps |MMC_CAP (MMC_LEGACY ) | -MMC_CAP (MMC_LEGACY ) |MMC_MODE_1BIT ; +MMC_MODE_1BIT ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) { +if (mmc->user_speed_mode !=MMC_MODES_END ) { +int i; +/* set host caps */ +if (mmc->host_caps &MMC_CAP (mmc->user_speed_mode)) { +/* Remove all existing speed capabilities */ +for (i =MMC_LEGACY ; i <MMC_MODES_END ; i++) + mmc->host_caps &= ~MMC_CAP (i); + mmc->host_caps |= (MMC_CAP (mmc->user_speed_mode) + |MMC_CAP (MMC_LEGACY ) | +MMC_MODE_1BIT ); + }else { +pr_err ("bus_mode requested is not supported\n" ); +return -EINVAL ; + } + } + }#if CONFIG_IS_ENABLED (DM_MMC )mmc_deferred_probe (mmc);#endif @@ -3060,6 +3078,8 @@ int mmc_init_device(int num) } m =mmc_get_mmc_dev (dev); + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (!m)return 0 ;if (m->preinit)include/mmc.h +2
-0@@ -726,6 +726,8 @@ struct mmc {*/ u32 quirks;u8 hs400_tuning; + +enum bus_mode user_speed_mode;/* input speed mode from user */ };#if CONFIG_IS_ENABLED (DM_MMC )
Re: [PATCH v4 1/2] mmc: Add support for enumerating MMC card in a given mode using mmc command
Hi Jaehoon,
Quoted 152 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_modeininclude/mmc.h. A speed mode can be set only if it has already been enabled in the device tree.Sorry for replying too late. I have tested with your patch.
It's confused the usage.
Quoted 139 lines
Signed-off-by Aswath Govindraju <[email protected]>--- cmd/Kconfig | 10 ++++++++ cmd/mmc.c | 52 +++++++++++++++++++++++++++++++++------- drivers/mmc/mmc-uclass.c | 5 +++- drivers/mmc/mmc.c | 22 ++++++++++++++++- include/mmc.h | 2 ++ 5 files changed, 81 insertions(+), 10 deletions(-)cmd/Kconfig +10
-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. + 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. endmenucmd/mmc.c +39
-6@@ -120,7 +120,9 @@ static void print_mmcinfo(struct mmc *mmc) } } } -static struct mmc *init_mmc_device (int dev,bool force_init) + +static struct mmc *__init_mmc_device (int dev,bool force_init, +enum bus_mode speed_mode) {struct mmc *mmc; mmc =find_mmc_device (dev);@@ -134,6 +136,10 @@ static struct mmc *init_mmc_device(int dev, bool force_init)if (force_init) mmc->has_init =0 ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) + mmc->user_speed_mode = speed_mode; +if (mmc_init (mmc))return NULL ;@@ -145,6 +151,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)return mmc; } +static struct mmc *init_mmc_device (int dev,bool force_init) +{ +return __init_mmc_device (dev, force_init,MMC_MODES_END ); +} +static int do_mmcinfo (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) {@@ -482,8 +493,17 @@ static int do_mmc_rescan(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct mmc *mmc; +enum bus_mode speed_mode =MMC_MODES_END ; + +if (argc ==1 ) { + mmc =init_mmc_device (curr_device, true); + }else if (argc ==2 ) { + speed_mode = (int )dectoul (argv[1 ],NULL ); + mmc =__init_mmc_device (curr_device, true, speed_mode); + }else { +return CMD_RET_USAGE ; + } - mmc =init_mmc_device (curr_device, true);if (!mmc)return CMD_RET_FAILURE ;@@ -515,11 +535,14 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, {int dev, part =0 , ret;struct mmc *mmc; +enum bus_mode speed_mode =MMC_MODES_END ;if (argc ==1 ) { dev = curr_device; + mmc =init_mmc_device (dev, true); }else if (argc ==2 ) { - dev =dectoul (argv[1 ],NULL ); + dev = (int )dectoul (argv[1 ],NULL ); + mmc =init_mmc_device (dev, true); }else if (argc ==3 ) { dev = (int )dectoul (argv[1 ],NULL ); part = (int )dectoul (argv[2 ],NULL );@@ -528,11 +551,21 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, PART_ACCESS_MASK);return CMD_RET_FAILURE ; } + mmc =init_mmc_device (dev, true); + }else if (argc ==4 ) { + dev = (int )dectoul (argv[1 ],NULL ); + part = (int )dectoul (argv[2 ],NULL ); +if (part >PART_ACCESS_MASK ) { +printf ("#part_num shouldn't be larger than %d\n" , +PART_ACCESS_MASK ); +return CMD_RET_FAILURE ; + } + speed_mode = (int )dectoul (argv[3 ],NULL ); + mmc =__init_mmc_device (dev, true, speed_mode); }else {return CMD_RET_USAGE ; } - mmc =init_mmc_device (dev, true);if (!mmc)return CMD_RET_FAILURE ;@@ -983,9 +1016,9 @@ static struct cmd_tbl cmd_mmc[] = {#if CONFIG_IS_ENABLED (CMD_MMC_SWRITE )U_BOOT_CMD_MKENT (swrite,3 ,0 , do_mmc_sparse_write,"" ,"" ), #endif -U_BOOT_CMD_MKENT (rescan,1 ,1 , do_mmc_rescan,"" ,"" ), +U_BOOT_CMD_MKENT (rescan,2 ,1 , do_mmc_rescan,"" ,"" ),U_BOOT_CMD_MKENT (part,1 ,1 , do_mmc_part,"" ,"" ), -U_BOOT_CMD_MKENT (dev,3 ,0 , do_mmc_dev,"" ,"" ), +U_BOOT_CMD_MKENT (dev,4 ,0 , do_mmc_dev,"" ,"" ),U_BOOT_CMD_MKENT (list,1 ,1 , do_mmc_list,"" ,"" ), #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),@@ -1042,9 +1075,12 @@ U_BOOT_CMD("mmc swrite addr blk#\n"
Quoted 8 lines
cmd/mmc.c U_BOOT_CMD( · line 1081
Quoted 8 lines
cmd/mmc.c +3
-2#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"
[1]
Quoted 6 lines
cmd/mmc.c U_BOOT_CMD( · line 1083
Quoted 2 lines
cmd/mmc.c +2
-0+" [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" If developer doesn't read a doc file, it's difficult to know the number of mode. Because this usage seems that [mode] can be passed by string.
Quoted 8 lines
When i have tested with your patch, I have run the below command.
# mmc rescan MMC_HS_52 - but it's always set to legacy mode. So I thought this was not working fine. But I have changed to input 3 instead of MMC_HS_52. It's working # mmc rescan 3Is my test right?
Yes, that is correct. The index of the speed mode has be provided[1].
Thanks,
Aswath
Quoted 84 lines
Best Regards,
Jaehoon ChungQuoted 80 lines
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 +4
-1@@ -342,6 +342,9 @@ void mmc_do_preinit(void)if (!m)continue ; + + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (m->preinit)mmc_start_init (m); }@@ -414,7 +417,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)/* setup initial part type */ bdesc->part_type = cfg->part_type; mmc->dev = dev; - + mmc->user_speed_mode =MMC_MODES_END ;return 0 ; }drivers/mmc/mmc.c +21
-1@@ -2862,7 +2862,25 @@ int mmc_start_init(struct mmc *mmc)* timings. */ mmc->host_caps = mmc->cfg->host_caps |MMC_CAP (MMC_LEGACY ) | -MMC_CAP (MMC_LEGACY ) |MMC_MODE_1BIT ; +MMC_MODE_1BIT ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) { +if (mmc->user_speed_mode !=MMC_MODES_END ) { +int i; +/* set host caps */ +if (mmc->host_caps &MMC_CAP (mmc->user_speed_mode)) { +/* Remove all existing speed capabilities */ +for (i =MMC_LEGACY ; i <MMC_MODES_END ; i++) + mmc->host_caps &= ~MMC_CAP (i); + mmc->host_caps |= (MMC_CAP (mmc->user_speed_mode) + |MMC_CAP (MMC_LEGACY ) | +MMC_MODE_1BIT ); + }else { +pr_err ("bus_mode requested is not supported\n" ); +return -EINVAL ; + } + } + }#if CONFIG_IS_ENABLED (DM_MMC )mmc_deferred_probe (mmc);#endif @@ -3060,6 +3078,8 @@ int mmc_init_device(int num) } m =mmc_get_mmc_dev (dev); + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (!m)return 0 ;if (m->preinit)include/mmc.h +2
-0@@ -726,6 +726,8 @@ struct mmc {*/ u32 quirks;u8 hs400_tuning; + +enum bus_mode user_speed_mode;/* input speed mode from user */ };#if CONFIG_IS_ENABLED (DM_MMC )
Re: [PATCH v4 1/2] mmc: Add support for enumerating MMC card in a given mode using mmc command
Quoted 177 lines · Aswath Govindraju
Hi Jaehoon,
Quoted 152 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_modeininclude/mmc.h. A speed mode can be set only if it has already been enabled in the device tree.Sorry for replying too late. I have tested with your patch.
It's confused the usage.
Quoted 139 lines
Signed-off-by Aswath Govindraju <[email protected]>--- cmd/Kconfig | 10 ++++++++ cmd/mmc.c | 52 +++++++++++++++++++++++++++++++++------- drivers/mmc/mmc-uclass.c | 5 +++- drivers/mmc/mmc.c | 22 ++++++++++++++++- include/mmc.h | 2 ++ 5 files changed, 81 insertions(+), 10 deletions(-)cmd/Kconfig +10
-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. + 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. endmenucmd/mmc.c +39
-6@@ -120,7 +120,9 @@ static void print_mmcinfo(struct mmc *mmc) } } } -static struct mmc *init_mmc_device (int dev,bool force_init) + +static struct mmc *__init_mmc_device (int dev,bool force_init, +enum bus_mode speed_mode) {struct mmc *mmc; mmc =find_mmc_device (dev);@@ -134,6 +136,10 @@ static struct mmc *init_mmc_device(int dev, bool force_init)if (force_init) mmc->has_init =0 ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) + mmc->user_speed_mode = speed_mode; +if (mmc_init (mmc))return NULL ;@@ -145,6 +151,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init)return mmc; } +static struct mmc *init_mmc_device (int dev,bool force_init) +{ +return __init_mmc_device (dev, force_init,MMC_MODES_END ); +} +static int do_mmcinfo (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) {@@ -482,8 +493,17 @@ static int do_mmc_rescan(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct mmc *mmc; +enum bus_mode speed_mode =MMC_MODES_END ; + +if (argc ==1 ) { + mmc =init_mmc_device (curr_device, true); + }else if (argc ==2 ) { + speed_mode = (int )dectoul (argv[1 ],NULL ); + mmc =__init_mmc_device (curr_device, true, speed_mode); + }else { +return CMD_RET_USAGE ; + } - mmc =init_mmc_device (curr_device, true);if (!mmc)return CMD_RET_FAILURE ;@@ -515,11 +535,14 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, {int dev, part =0 , ret;struct mmc *mmc; +enum bus_mode speed_mode =MMC_MODES_END ;if (argc ==1 ) { dev = curr_device; + mmc =init_mmc_device (dev, true); }else if (argc ==2 ) { - dev =dectoul (argv[1 ],NULL ); + dev = (int )dectoul (argv[1 ],NULL ); + mmc =init_mmc_device (dev, true); }else if (argc ==3 ) { dev = (int )dectoul (argv[1 ],NULL ); part = (int )dectoul (argv[2 ],NULL );@@ -528,11 +551,21 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, PART_ACCESS_MASK);return CMD_RET_FAILURE ; } + mmc =init_mmc_device (dev, true); + }else if (argc ==4 ) { + dev = (int )dectoul (argv[1 ],NULL ); + part = (int )dectoul (argv[2 ],NULL ); +if (part >PART_ACCESS_MASK ) { +printf ("#part_num shouldn't be larger than %d\n" , +PART_ACCESS_MASK ); +return CMD_RET_FAILURE ; + } + speed_mode = (int )dectoul (argv[3 ],NULL ); + mmc =__init_mmc_device (dev, true, speed_mode); }else {return CMD_RET_USAGE ; } - mmc =init_mmc_device (dev, true);if (!mmc)return CMD_RET_FAILURE ;@@ -983,9 +1016,9 @@ static struct cmd_tbl cmd_mmc[] = {#if CONFIG_IS_ENABLED (CMD_MMC_SWRITE )U_BOOT_CMD_MKENT (swrite,3 ,0 , do_mmc_sparse_write,"" ,"" ), #endif -U_BOOT_CMD_MKENT (rescan,1 ,1 , do_mmc_rescan,"" ,"" ), +U_BOOT_CMD_MKENT (rescan,2 ,1 , do_mmc_rescan,"" ,"" ),U_BOOT_CMD_MKENT (part,1 ,1 , do_mmc_part,"" ,"" ), -U_BOOT_CMD_MKENT (dev,3 ,0 , do_mmc_dev,"" ,"" ), +U_BOOT_CMD_MKENT (dev,4 ,0 , do_mmc_dev,"" ,"" ),U_BOOT_CMD_MKENT (list,1 ,1 , do_mmc_list,"" ,"" ), #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),@@ -1042,9 +1075,12 @@ U_BOOT_CMD("mmc swrite addr blk#\n" Quoted 8 lines
cmd/mmc.c U_BOOT_CMD( · line 1081
Quoted 8 lines
cmd/mmc.c +3
-2#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" [1]
Quoted 12 lines
cmd/mmc.c U_BOOT_CMD( · line 1083
Quoted 2 lines
cmd/mmc.c +2
-0+" [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" If developer doesn't read a doc file, it's difficult to know the number of mode. Because this usage seems that [mode] can be passed by string.
When i have tested with your patch, I have run the below command.
# mmc rescan MMC_HS_52 - but it's always set to legacy mode. So I thought this was not working fine. But I have changed to input 3 instead of MMC_HS_52. It's working # mmc rescan 3
Quoted 4 lines
Quoted 2 lines
Is my test right?
Yes, that is correct. The index of the speed mode has be provided[1].
Thanks! It's my mis-reading. :)
It's working fine.
Best Regards,
Jaehoon Chung
Quoted 90 lines
Thanks,
AswathQuoted 84 lines
Best Regards,
Jaehoon ChungQuoted 80 lines
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 +4
-1@@ -342,6 +342,9 @@ void mmc_do_preinit(void)if (!m)continue ; + + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (m->preinit)mmc_start_init (m); }@@ -414,7 +417,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)/* setup initial part type */ bdesc->part_type = cfg->part_type; mmc->dev = dev; - + mmc->user_speed_mode =MMC_MODES_END ;return 0 ; }drivers/mmc/mmc.c +21
-1@@ -2862,7 +2862,25 @@ int mmc_start_init(struct mmc *mmc)* timings. */ mmc->host_caps = mmc->cfg->host_caps |MMC_CAP (MMC_LEGACY ) | -MMC_CAP (MMC_LEGACY ) |MMC_MODE_1BIT ; +MMC_MODE_1BIT ; + +if (IS_ENABLED (CONFIG_MMC_SPEED_MODE_SET )) { +if (mmc->user_speed_mode !=MMC_MODES_END ) { +int i; +/* set host caps */ +if (mmc->host_caps &MMC_CAP (mmc->user_speed_mode)) { +/* Remove all existing speed capabilities */ +for (i =MMC_LEGACY ; i <MMC_MODES_END ; i++) + mmc->host_caps &= ~MMC_CAP (i); + mmc->host_caps |= (MMC_CAP (mmc->user_speed_mode) + |MMC_CAP (MMC_LEGACY ) | +MMC_MODE_1BIT ); + }else { +pr_err ("bus_mode requested is not supported\n" ); +return -EINVAL ; + } + } + }#if CONFIG_IS_ENABLED (DM_MMC )mmc_deferred_probe (mmc);#endif @@ -3060,6 +3078,8 @@ int mmc_init_device(int num) } m =mmc_get_mmc_dev (dev); + m->user_speed_mode =MMC_MODES_END ;/* Initialising user set speed mode */ +if (!m)return 0 ;if (m->preinit)include/mmc.h +2
-0@@ -726,6 +726,8 @@ struct mmc {*/ u32 quirks;u8 hs400_tuning; + +enum bus_mode user_speed_mode;/* input speed mode from user */ };#if CONFIG_IS_ENABLED (DM_MMC )
PATCH v4 2/2 doc: usage: mmc: Document usage of speed mode in "mmc dev" and "mmc rescan"
In reply to Aswath GovindrajuAdd documentation on the usage of "mmc dev" and "mmc rescan" commands to set user defined speed modes.
--- doc/usage/mmc.rst | 49 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-)
doc/usage/mmc.rst +47 -2
@@ -12,9 +12,9 @@ Synopsis mmc read addr blk# cnt mmc write addr blk# cnt mmc erase blk# cnt - mmc rescan + mmc rescan [mode] mmc part - mmc dev [dev] [part] + mmc dev [dev] [part] [mode] mmc list mmc wp mmc bootbus <dev> <boot_bus_width> <reset_boot_bus_width> <boot_mode>
@@ -49,6 +49,27 @@ The 'mmc erase' command erases *cnt* blocks on the MMC device starting at block The 'mmc rescan' command scans the available MMC device. + mode + speed mode to set. + CONFIG_MMC_SPEED_MODE_SET should be enabled. The required speed mode is + passed as the index from the following list. + + 0 - MMC_LEGACY + 1 - MMC_HS + 2 - SD_HS + 3 - MMC_HS_52 + 4 - MMC_DDR_52 + 5 - UHS_SDR12 + 6 - UHS_SDR25 + 7 - UHS_SDR50 + 8 - UHS_DDR50 + 9 - UHS_SDR104 + 10 - MMC_HS_200 + 11 - MMC_HS_400 + 12 - MMC_HS_400_ES + + A speed mode can be set only if it has already been enabled in the device tree + The 'mmc part' command displays the list available partition on current mmc device. The 'mmc dev' command shows or set current mmc device.
@@ -58,6 +79,27 @@ The 'mmc dev' command shows or set current mmc device. part partition number to change + mode + speed mode to set. + CONFIG_MMC_SPEED_MODE_SET should be enabled. The required speed mode is + passed as the index from the following list. + + 0 - MMC_LEGACY + 1 - MMC_HS + 2 - SD_HS + 3 - MMC_HS_52 + 4 - MMC_DDR_52 + 5 - UHS_SDR12 + 6 - UHS_SDR25 + 7 - UHS_SDR50 + 8 - UHS_DDR50 + 9 - UHS_SDR104 + 10 - MMC_HS_200 + 11 - MMC_HS_400 + 12 - MMC_HS_400_ES + + A speed mode can be set only if it has already been enabled in the device tree + The 'mmc list' command displays the list available devices. The 'mmc wp' command enables "power on write protect" function for boot partitions.
@@ -194,6 +236,9 @@ The current device can be shown or set via 'mmc dev' command: => mmc dev 2 0 switch to partitions #0, OK mmc2 is current device + => mmc dev 0 1 4 + switch to partitions #1, OK + mmc0(part 1) is current device The list of available devices can be shown via 'mmc list' command: ::
Signature · 1 line
2.17.1