drivers: mci: Make two functions public
PATCH v3 1/4 drivers: mci: Make two functions public
There is no possibility to read/write to the extended CSD register of MMC devices from a command. To avoid duplicated driver code, two driver functions have to be public.
---
Changes:
v2: Changed patch order v3: No changes
drivers/mci/mci-core.c | 4 ++-- include/mci.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/mci/mci-core.c +2 -2
@@ -370,7 +370,7 @@ static int mmc_send_op_cond(struct mci *mci)* Note: Only cards newer than Version 1.1 (Physical Layer Spec) support * this command */ -static int mci_send_ext_csd (struct mci *mci,char *ext_csd) +int mci_send_ext_csd (struct mci *mci,char *ext_csd) {struct mci_cmd cmd;struct mci_data data;
@@ -394,7 +394,7 @@ static int mci_send_ext_csd(struct mci *mci, char *ext_csd)* @param value FIXME * @return Transaction status (0 on success) */ -static int mci_switch (struct mci *mci,unsigned set,unsigned index, +int mci_switch (struct mci *mci,unsigned set,unsigned index,unsigned value) {struct mci_cmd cmd;
include/mci.h +3 -0
@@ -372,6 +372,9 @@ struct mci {int mci_register (struct mci_host *);void mci_of_parse (struct mci_host *host);int mci_detect_card (struct mci_host *); +int mci_send_ext_csd (struct mci *mci,char *ext_csd); +int mci_switch (struct mci *mci,unsigned set,unsigned index, +unsigned value);static inline int mmc_host_is_spi (struct mci_host *host) {
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 2/4 include: mci: Add new ext. CSD field defines
Added missing defines for the extended CSD register until standard 5.1.
---
Changes:
v2: Changed patch order Removed whitespaces from old defines v3: No changes
include/mci.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+)
include/mci.h +99 -0
@@ -183,6 +183,105 @@#define EXT_CSD_CACHE_SIZE 249/* RO, 4 bytes */ #define EXT_CSD_HPI_FEATURES 503/* RO */ +/* Added with the 5.1 standard */ +#define EXT_CSD_CMDQ_MODE_EN 15/* RO */ +#define EXT_CSD_SECURE_REMOVAL_TYPE 16/* R/W */ +#define EXT_CSD_PRODUCT_ST8_AWARENSS_ENABLEMENT 17/* R/W */ +#define EXT_CSD_MAX_PRE_LOADING_DATA_SIZE 18/* RO, 4 bytes */ +#define EXT_CSD_PRE_LOADING_DATA_SIZE 22/* R/W, 4 bytes */ +#define EXT_CSD_FFU_STATUS 26/* RO */ +#define EXT_CSD_MODE_OPERATION_CODES 29/* W */ +#define EXT_CSD_MODE_CONFIG 30/* R/W */ +#define EXT_CSD_BARRIER_CTRL 31/* R/W */ +#define EXT_CSD_PACKED_FAILURE_INDEX 35/* RO */ +#define EXT_CSD_PACKED_COMMAND_STATUS 36/* RO */ +#define EXT_CSD_CONTEXT_CONF 37/* R/W, 15 bytes */ +#define EXT_CSD_EXT_PARTITIONS_ATTRIBUTE 52/* R/W, 2 bytes */ +#define EXT_CSD_EXCEPTION_EVENTS_STATUS 54/* RO, 2 bytes */ +#define EXT_CSD_EXCEPTION_EVENTS_CTRL 56/* R/W, 2 bytes */ +#define EXT_CSD_CLASS_6_CTRL 59/* R/W */ +#define EXT_CSD_INI_TIMEOUT_EMU 60/* RO */ +#define EXT_CSD_DATA_SECTOR_SIZE 61/* RO */ +#define EXT_CSD_USE_NATIVE_SECTOR 62/* RO */ +#define EXT_CSD_NATIVE_SECTOR_SIZE 63/* RO */ +#define EXT_CSD_PROGRAM_CID_CSD_DDR_SUPPORT 130/* R/W */ +#define EXT_CSD_PERIODIC_WAKEUP 131/* R/W/ */ +#define EXT_CSD_TCASE_SUPPORT 132/* R/W */ +#define EXT_CSD_PRODUCTION_STATE_AWARENESS 133/* R/W */ +#define EXT_CSD_SEC_BAD_BLK_MGMNT 134/* R/W */ +#define EXT_CSD_ENH_START_ADDR 136/* R/W, 4 bytes */ +#define EXT_CSD_ENH_SIZE_MULT 140/* R/W, 3 bytes */ +#define EXT_CSD_PARTITION_SETTING_COMPLETED 155/* R/W */ +#define EXT_CSD_PARTITIONS_ATTRIBUTE 156/* R/W */ +#define EXT_CSD_MAX_ENH_SIZE_MULT 157/* RO, 3 bytes */ +#define EXT_CSD_PARTITIONING_SUPPORT 160/* RO */ +#define EXT_CSD_BKOPS_EN 163/* R/W */ +#define EXT_CSD_BKOPS_START 164/* WO */ +#define EXT_CSD_WR_REL_SET 167/* R/W */ +#define EXT_CSD_RPMB_SIZE_MULT 168/* RO */ +#define EXT_CSD_FW_CONFIG 169/* R/W */ +#define EXT_CSD_USER_WP 171/* R/W */ +#define EXT_CSD_BOOT_WP_STATUS 174/* RO */ +#define EXT_CSD_BOOT_BUS_CONDITIONS 177/* R/W */ +#define EXT_CSD_BOOT_CONFIG_PROT 178/* R/W */ +#define EXT_CSD_PARTITION_CONFIG 179/* R/W */ +#define EXT_CSD_STROBE_SUPPORT 184/* RO */ +#define EXT_CSD_CMD_SET_REV 189/* R/W */ +#define EXT_CSD_CMD_SET 191/* R/W */ +#define EXT_CSD_CSD_STRUCTURE 194/* RO */ +#define EXT_CSD_DEVICE_TYPE 196/* RO */ +#define EXT_CSD_DRIVER_STRENGTH 197/* RO */ +#define EXT_CSD_PART_SWITCH_TIME 199/* RO */ +#define EXT_CSD_PARTITION_SWITCH_TIME 199/* RO */ +#define EXT_CSD_MIN_PERF_R_4_26 205/* RO */ +#define EXT_CSD_MIN_PERF_W_4_26 206/* RO */ +#define EXT_CSD_MIN_PERF_R_8_26_4_52 207/* RO */ +#define EXT_CSD_MIN_PERF_W_8_26_4_52 208/* RO */ +#define EXT_CSD_MIN_PERF_R_8_52 209/* RO */ +#define EXT_CSD_MIN_PERF_W_8_52 210/* RO */ +#define EXT_CSD_SECURE_WP_INFO 211/* RO */ +#define EXT_CSD_SEC_COUNT 212/* RO, 4 bytes */ +#define EXT_CSD_SLEEP_NOTIFICATION_TIME 216/* RO */ +#define EXT_CSD_PRODUCTION_ST8_AWARENSS_TIMEOUT 218/* RO */ +#define EXT_CSD_S_C_VCCQ 219/* RO */ +#define EXT_CSD_S_C_VCC 220/* RO */ +#define EXT_CSD_ACC_SIZE 225/* RO */ +#define EXT_CSD_BOOT_SIZE_MULT 226/* RO */ +#define EXT_CSD_BOOT_INFO 228/* RO */ +#define EXT_CSD_MIN_PERF_DDR_R_8_52 234/* RO */ +#define EXT_CSD_MIN_PERF_DDR_W_8_52 235/* RO */ +#define EXT_CSD_CACHE_FLUSH_POLICY 240/* RO */ +#define EXT_CSD_INI_TIMEOUT_AP 241/* RO */ +#define EXT_CSD_CORRECTLY_PRG_SECTORS_NUM 242/* RO, 4 bytes */ +#define EXT_CSD_BKOPS_STATUS 246/* RO */ +#define EXT_CSD_FIRMWARE_VERSION 254/* RO, 8 bytes */ +#define EXT_CSD_DEVICE_VERSION 262/* RO, 2 bytes */ +#define EXT_CSD_OPTIMAL_TRIM_UNIT_SIZE 264/* RO */ +#define EXT_CSD_OPTIMAL_WRITE_SIZE 265/* RO */ +#define EXT_CSD_OPTIMAL_READ_SIZE 266/* RO */ +#define EXT_CSD_PRE_EOL_INFO 267/* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268/* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269/* RO */ +#define EXT_CSD_NMBR_OF_FW_SCTRS_CRRCTLY_PRGRMD 302/* RO, 4 bytes */ +#define EXT_CSD_CMDQ_DEPTH 307/* RO */ +#define EXT_CSD_CMDQ_SUPPORT 308/* RO */ +#define EXT_CSD_BARRIER_SUPPORT 486/* RO */ +#define EXT_CSD_FFU_ARG 487/* RO, 4 bytes */ +#define EXT_CSD_OPERATION_CODES_TIMEOUT 491/* RO */ +#define EXT_CSD_FFU_FEATURES 492/* RO */ +#define EXT_CSD_SUPPORTED_MODES 493/* RO */ +#define EXT_CSD_EXT_SUPPORT 494/* RO */ +#define EXT_CSD_LARGE_UNIT_SIZE_M1 495/* RO */ +#define EXT_CSD_CONTEXT_CAPABILITIES 496/* RO */ +#define EXT_CSD_TAG_RES_SIZE 497/* RO */ +#define EXT_CSD_TAG_UNIT_SIZE 498/* RO */ +#define EXT_CSD_DATA_TAG_SUPPORT 499/* RO */ +#define EXT_CSD_MAX_PACKED_WRITES 500/* RO */ +#define EXT_CSD_MAX_PACKED_READS 501/* RO */ +#define EXT_CSD_BKOPS_SUPPORT 502/* RO */ +#define EXT_CSD_S_CMD_SET 504/* RO */ +#define EXT_CSD_EXT_SECURITY_ERR 505/* RO */ +/* * EXT_CSD field definitions */
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 3/4 drivers: mci: Add mci_get_device_by_name function
In reply to Daniel SchultzGet a 'struct mci' by search after the device name.
---
Changes:
v3: New with patch v3
drivers/mci/mci-core.c | 16 ++++++++++++++++ include/mci.h | 8 ++++++++ 2 files changed, 24 insertions(+)
drivers/mci/mci-core.c +16 -0
@@ -53,6 +53,8 @@ __res & __mask; \ }) +LIST_HEAD (mci_list); +/** * @file * @brief Memory Card framework
@@ -1753,6 +1755,8 @@ int mci_register(struct mci_host *host) mci->dev.id =DEVICE_ID_DYNAMIC ; } +list_add_tail (&mci->list, &mci_list); + mci->dev.platform_data = host; mci->dev.parent = host->hw_dev; mci->host = host;
@@ -1844,3 +1848,15 @@ void mci_of_parse(struct mci_host *host) host->non_removable =of_property_read_bool (np,"non-removable" ); } + +struct mci *mci_get_device_by_name (const char *name) +{ +struct mci *dev; + +for_each_mci_device (dev) { +if (!strcmp (dev->cdevname, name)) +return dev; + } + +return NULL ; +}
include/mci.h +8 -0
@@ -466,6 +466,8 @@ struct mci {struct mci_part *part_curr;u8 ext_csd_part_config; + +struct list_head list;/* The list of all mci devices */ };int mci_register (struct mci_host *);
@@ -483,4 +485,10 @@ static inline int mmc_host_is_spi(struct mci_host *host) return 0; } +/* Iterate over all mci devices +*/ +#define for_each_mci_device (dev) list_for_each_entry(dev, &mci_list, list) + +struct mci *mci_get_device_by_name (const char *name); +#endif /* _MCI_H_ */
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedRe: [PATCH v3 3/4] drivers: mci: Add mci_get_device_by_name function
Quoted 27 lines · Daniel Schultz
Get a 'struct mci' by search after the device name.
Signed-off-by Daniel Schultz <[email protected]>---
Changes:
v3: New with patch v3drivers/mci/mci-core.c | 16 ++++++++++++++++ include/mci.h | 8 ++++++++ 2 files changed, 24 insertions(+)drivers/mci/mci-core.c +2
-0@@ -53,6 +53,8 @@ __res & __mask; \ }) +LIST_HEAD (mci_list); +/** * @file * @brief Memory Card framework
drivers/mci/mci-core.c int mci_register(struct mci_host *host) · line 1759
Quoted 5 lines
drivers/mci/mci-core.c +2
-0@@ -1753,6 +1755,8 @@ int mci_register(struct mci_host *host) mci->dev.id =DEVICE_ID_DYNAMIC ; } +list_add_tail (&mci->list, &mci_list); +
mci_register() may fail later in which case you end up with an undefined entry in the mci_list. This should be done near the end of mci_register() when it can't fail anymore.
Quoted 6 lines
drivers/mci/mci-core.c +0
-0mci->dev.platform_data = host; mci->dev.parent = host->hw_dev; mci->host = host;@@ -1844,3 +1848,15 @@ void mci_of_parse(struct mci_host *host) host->non_removable =of_property_read_bool (np,"non-removable" );
drivers/mci/mci-core.c void mci_of_parse(struct mci_host *host) · line 1859
Quoted 10 lines
drivers/mci/mci-core.c +9
-0} + +struct mci *mci_get_device_by_name (const char *name) +{ +struct mci *dev; + +for_each_mci_device (dev) { +if (!strcmp (dev->cdevname, name)) +return dev; + }
dev->cdevname is initialized only in mci_card_probe() and only when actually a card is detected. This causes a NULL pointer exception for example when a there's no card in a slot. This has to be checked here.
It's a bit confusing when a variable named 'dev' not of type struct device_d. Please rather use more specific names, like 'mci' in this case.
I applied a fixed version to the -next branch.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 4/4 commands: Add MMC ext. CSD register tool
In reply to Daniel SchultzThis tools can read/write to the extended CSD register of MMC devices.
---
Changes:
v2:
Changed patch order
v3:
Splitted output in different functions to reduce the indentation. Minimized strings and optimized printfs.
Refactored main function
commands/Kconfig | 16 + commands/Makefile | 1 + commands/mmc_extcsd.c | 2041 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2058 insertions(+) create mode 100644 commands/mmc_extcsd.c
commands/Kconfig +16 -0
@@ -242,6 +242,22 @@ config CMD_VERSION barebox 2014.05.0-00142-gb289373 #177 Mon May 12 20:35:55 CEST 2014 +config CMD_MMC_EXTCSD + tristate + prompt "read/write eMMC ext. CSD register" + depends on MCI + help + Read or write the extended CSD register of a MMC device. + + Usage: mmc_extcsd dev [-r | -i index [-r | -v value -y]] + + Options: + -i field index of the register + -r print the register as raw data + -v value which will be written + -y don't request when writing to one time programmable fields + __CAUTION__: this could damage the device! + # end Information commands endmenu
commands/Makefile +1 -0
@@ -114,3 +114,4 @@ obj-$(CONFIG_CMD_STATE) += state.o obj-$(CONFIG_CMD_DHCP) += dhcp.o obj-$(CONFIG_CMD_DHRYSTONE) += dhrystone.o obj-$(CONFIG_CMD_SPD_DECODE) += spd_decode.o +obj-$(CONFIG_CMD_MMC_EXTCSD) += mmc_extcsd.o
commands/mmc_extcsd.c new file +2041 -0
2,041 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v3 4/4] commands: Add MMC ext. CSD register tool
Quoted 37 lines · Daniel Schultz
commands/mmc_extcsd.c new file +37
-0+#define EXT_CSD_BLOCKSIZE 512 + +/* Access types */ +#define R "R" +#define RW "R/W" +#define RWaR "R/W & R" +#define RWaRWE "R/W & R/W/E" +#define RWaRWC_P "R/W & R/W/C_P" +#define RWaRWC_PaRWE_P "R/W, R/W/C_P & R/W/E_P" +#define WE "W/E" +#define RWE "R/W/E" +#define RWEaR "R/W/E & R" +#define RWEaRWE_P "R/W/E & R/W/E_P" +#define RWC_P "R/W/C_P" +#define RWE_P "R/W/E_P" +#define WE_P "W/E_P" + +#define print_field_caption (reg_name, access_mode) \ + do { \ + printf(#reg_name"[%u]:\n", EXT_CSD_##reg_name); \ + printf("\tValue: %#02x\n", reg[index]); \ + printf("\tAccess: "access_mode"\n"); \ + } while (false); + +#define print_field_caption_with_offset (reg_name, offset, access_mode) \ + do { \ + printf(#reg_name"[%u]:\n", EXT_CSD_##reg_name + offset); \ + printf("\tValue: %#02x\n", reg[index]); \ + printf("\tAccess: "access_mode"\n"); \ + } while (false); + +#define get_field_val (reg_name, offset, mask) \ + ((reg[EXT_CSD_##reg_name] >> offset) & mask) + +#define get_field_val_with_index (index, offset, mask) \ + ((reg[index] >> offset) & mask) +
commands/mmc_extcsd.c line 72
Quoted 10 lines
commands/mmc_extcsd.c new file +10
-0+static void print_access_type_key (void ) +{ +printf ("\nR: Read only.\n" ); +printf ("W: One time programmable and not readable.\n" ); +printf ("R/W: One time programmable and readable.\n" ); +printf ("W/E: Multiple writable with value kept after power failure, H/W reset assertion and any CMD0 reset and not readable.\n" ); +printf ("R/W/E: Multiple writable with value kept after power failure, H/W reset assertion and any CMD0 reset and readable.\n" ); +printf ("R/W/C_P: Writable after value cleared by power failure and HW/rest assertion (the value not cleared by CMD0 reset) and readable.\n" ); +printf ("R/W/E_P: Multiple writable with value reset after power failure, H/W reset assertion and any CMD0 reset and readable.\n" ); +printf ("W/E_P: Multiple writable with value reset after power failure, H/W reset assertion and any CMD0 reset and not readable.\n\n" );
Wouldn't it make sense to explain the meaning of the individual flags rather than all possible combinations? i.e.:
R: readable
W: One time writable
E: Multiple writableC_P: Value cleared by power failureE_P: Value cleared by power failure and CMD0
Also please add some linebreaks in the printfs. You can do multiline printf like this:
printf("permanently disable the use of permanent write protection\n"
"for write protection groups within all the partitions in the\n" "user area from the point this bit is set forward. Setting this\n" "bit does not impact areas that are already protected\n"
Even better, shorten the descriptions. "permanently disable the use of permanent write protection\n" should be enough in this case.
s/optimzed/optimized/
s/disbale/disable/
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox