mtd: use the full-id as the keyword for some nand chips
Subsystems (2)
v6 cover mtd: use the full-id as the keyword for some nand chips
As time goes on, we begin to meet the situation that we can not get enough information from some nand chips's id data. Take some Toshiba's nand chips for example.
I have 4 Toshiba's nand chips in my hand:
TC58NVG2S0F, TC58NVG3S0F, TC58NVG5D2, TC58NVG6D2
When we read these chips' datasheets, we will get the geometry of these chips:
TC58NVG2S0F : 4096 + 224 TC58NVG3S0F : 4096 + 232 TC58NVG5D2 : 8192 + 640 TC58NVG6D2 : 8192 + 640
But we can not parse out the correct oob size for these chips from the id data. So it is time to add some new fields to the nand_flash_dev{},
and update the detection mechanisms.
v5 --> v6:
[1] add back the id_len as Brian's suggest.
[2] use id_len to check the full id nand or not.
[3] change the new fields oob_size/id_len to "uint16_t" type.
[4] misc
v4 --> v5:
[1] remove the id_len field.
[2] based on Artem "mtd: nand: use more reasonable integer types"
[3] add more comments.
v3 --> v4:
[1] rewrite the code based on the latest l2-mtd.
[2] add the full-id nand in the nand_flash_lds.
v2 --> v3:
[1] remove the duplicated header.
[2] remove the field "ecc_len" in nand_flash_dev{}.
[3] fix some coding style warnings.
[4] add more comments
Huang Shijie (3):
mtd: add new fields to nand_flash_dev{}
mtd: add the support to parse out the full-id nand type
mtd: add 4 Toshiba nand chips for the full-id case
drivers/mtd/nand/nand_base.c | 35 ++++++++++++++++++++++++++++++++--- drivers/mtd/nand/nand_ids.c | 19 +++++++++++++++++++ include/linux/mtd/nand.h | 4 ++++ 3 files changed, 55 insertions(+), 3 deletions(-)
PATCH v6 1/3 mtd: add new fields to nand_flash_dev{}
As time goes on, we begin to meet the situation that we can not get enough information from some nand chips's id data. Take some Toshiba's nand chips for example. I have 4 Toshiba's nand chips in my hand:
TC58NVG2S0F, TC58NVG3S0F, TC58NVG5D2, TC58NVG6D2
When we read these chips' datasheets, we will get the geometry of these chips:
TC58NVG2S0F : 4096 + 224 TC58NVG3S0F : 4096 + 232 TC58NVG5D2 : 8192 + 640 TC58NVG6D2 : 8192 + 640
But we can not parse out the correct oob size for these chips from the id data.
This patch adds some new fields to the nand_flash_dev{}:
@id_len: the valid length of the id data. See the comments in
nand_id_has_period()
@oobsize: the oob size.
--- include/linux/mtd/nand.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/linux/mtd/nand.h +4 -0
@@ -584,6 +584,8 @@ struct nand_chip {* @chipsize: total chip size in MiB * @erasesize: eraseblock size in bytes (determined from the extended ID if 0) * @options: stores various chip bit options +* @id_len: The valid length of the @id. +* @oobsize: OOB size */ struct nand_flash_dev {char *name;
@@ -598,6 +600,8 @@ struct nand_flash_dev {unsigned int chipsize;unsigned int erasesize;unsigned int options; +uint16_t id_len; +uint16_t oobsize; };/**
Signature · 1 line
1.7.1
PATCH v6 2/3 mtd: add the support to parse out the full-id nand type
In reply to Huang ShijieWhen we meet a full-id nand type whose @id_len is not zero, we can use the find_full_id_nand() to parse out the necessary information for a nand chip.
If we meet a non full-id nand type, we can handle it in the legacy way.
--- drivers/mtd/nand/nand_base.c | 35 ++++++++++++++++++++++++++++++++--- 1 files changed, 32 insertions(+), 3 deletions(-)
drivers/mtd/nand/nand_base.c +32 -3
@@ -3123,6 +3123,30 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, chip->bbt_options |=NAND_BBT_SCAN2NDPAGE ; } +static inline bool is_full_id_nand (struct nand_flash_dev *type) +{ +return type->id_len; +} + +static bool find_full_id_nand (struct mtd_info *mtd,struct nand_chip *chip, +struct nand_flash_dev *type,u8 *id_data,int *busw) +{ +if (!strncmp (type->id, id_data, type->id_len)) { + mtd->writesize = type->pagesize; + mtd->erasesize = type->erasesize; + mtd->oobsize = type->oobsize; + + chip->cellinfo = id_data[2 ]; + chip->chipsize = (uint64_t )type->chipsize <<20 ; + chip->options |= type->options; + + *busw = type->options &NAND_BUSWIDTH_16 ; + +return true; + } +return false; +} +/* * Get the flash and manufacturer id and lookup if the type is supported. */
@@ -3174,9 +3198,14 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,if (!type) type = nand_flash_ids; -for (; type->name !=NULL ; type++) -if (*dev_id == type->dev_id) -break ; +for (; type->name !=NULL ; type++) { +if (is_full_id_nand (type)) { +if (find_full_id_nand (mtd, chip, type, id_data, &busw)) + goto ident_done; + }else if (*dev_id == type->dev_id) { +break ; + } + } chip->onfi_version =0 ;if (!type->name || !type->pagesize) {
Signature · 1 line
1.7.1
PATCH v6 3/3 mtd: add 4 Toshiba nand chips for the full-id case
In reply to Huang ShijieI have 4 Toshiba nand chips which can not be parsed out by the id data. We can not get the oob size from the id data. So add them as the full-id nand chips in the first of nand_flash_ids.
The comment for the full-id items is from Brian.
--- drivers/mtd/nand/nand_ids.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/mtd/nand/nand_ids.c +19 -0
@@ -10,6 +10,7 @@*/ #include <linux/module.h> #include <linux/mtd/nand.h> +#include <linux/sizes.h> #define LP_OPTIONS NAND_SAMSUNG_LP_OPTIONS#define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16)
@@ -22,6 +23,24 @@* extended chip ID. */ struct nand_flash_dev nand_flash_ids[] = { +/* +* Some incompatible NAND chips share device ID's and so must be +* listed by full ID. We list them first so that we can easily identify +* the most specific match. +*/ + {"TC58NVG2S0F 4G 3.3V 8-bit" , + { .id = {0x98 ,0xdc ,0x90 ,0x26 ,0x76 ,0x15 ,0x01 ,0x08 } }, +SZ_4K ,SZ_512 ,SZ_256K ,0 ,8 ,224 }, + {"TC58NVG3S0F 8G 3.3V 8-bit" , + { .id = {0x98 ,0xd3 ,0x90 ,0x26 ,0x76 ,0x15 ,0x02 ,0x08 } }, +SZ_4K ,SZ_1K ,SZ_256K ,0 ,8 ,232 }, + {"TC58NVG5D2 32G 3.3V 8-bit" , + { .id = {0x98 ,0xd7 ,0x94 ,0x32 ,0x76 ,0x56 ,0x09 ,0x00 } }, +SZ_8K ,SZ_4K ,SZ_1M ,0 ,8 ,640 }, + {"TC58NVG6D2 64G 3.3V 8-bit" , + { .id = {0x98 ,0xde ,0x94 ,0x82 ,0x76 ,0x56 ,0x04 ,0x20 } }, +SZ_8K ,SZ_8K ,SZ_2M ,0 ,8 ,640 }, +LEGACY_ID_NAND ("NAND 4MiB 5V 8-bit" ,0x6B ,512 ,4 ,0x2000 ,0 ),LEGACY_ID_NAND ("NAND 4MiB 3,3V 8-bit" ,0xE3 ,512 ,4 ,0x2000 ,0 ),LEGACY_ID_NAND ("NAND 4MiB 3,3V 8-bit" ,0xE5 ,512 ,4 ,0x2000 ,0 ),
Signature · 1 line
1.7.1
Quoted 42 lines · Huang Shijie
As time goes on, we begin to meet the situation that we can not get enough information from some nand chips's id data. Take some Toshiba's nand chips for example.
I have 4 Toshiba's nand chips in my hand:TC58NVG2S0F, TC58NVG3S0F, TC58NVG5D2, TC58NVG6D2When we read these chips' datasheets, we will get the geometry of these chips:
TC58NVG2S0F : 4096 + 224 TC58NVG3S0F : 4096 + 232 TC58NVG5D2 : 8192 + 640 TC58NVG6D2 : 8192 + 640But we can not parse out the correct oob size for these chips from the id data. So it is time to add some new fields to the nand_flash_dev{},
and update the detection mechanisms.v5 --> v6:
[1] add back theid_lenas Brian's suggest.
[2] useid_lento check the full id nand or not.
[3] change the new fields oob_size/id_len to "uint16_t" type.
[4] miscv4 --> v5:
[1] remove theid_lenfield.
[2] based on Artem "mtd: nand: use more reasonable integer types"
[3] add more comments.v3 --> v4:
[1] rewrite the code based on the latest l2-mtd.
[2] add the full-id nand in thenand_flash_lds.v2 --> v3:
[1] remove the duplicated header.
[2] remove the field "ecc_len" in nand_flash_dev{}.
[3] fix some coding style warnings.
[4] add more commentsHuang Shijie (3):
mtd: add new fields to nand_flash_dev{}
mtd: add the support to parse out the full-id nand type
mtd: add 4 Toshiba nand chips for the full-id case
Quoted 4 lines
drivers/mtd/nand/nand_base.c | 35 ++++++++++++++++++++++++++++++++--- drivers/mtd/nand/nand_ids.c | 19 +++++++++++++++++++ include/linux/mtd/nand.h | 4 ++++ 3 files changed, 55 insertions(+), 3 deletions(-)
Series looks good to me. Thanks Huang!
Artem Bityutskiy
AppliedQuoted 5 lines · Huang Shijie
As time goes on, we begin to meet the situation that we can not get enough information from some nand chips's id data. Take some Toshiba's nand chips for example.
I have 4 Toshiba's nand chips in my hand:TC58NVG2S0F, TC58NVG3S0F, TC58NVG5D2, TC58NVG6D2
Pushed to l2-mtd.git, thanks!
Signature · 2 lines
Best Regards, Artem Bityutskiy