mtd: nand: spi: rework detect procedure for different read id op
Subsystems (2)
PATCH v2 1/1 mtd: nand: spi: rework detect procedure for different read id op
Currently there are 3 different variants of read_id implementation:
1. opcode only. Found in GD5FxGQ4xF.
2. opcode + 1 addr byte. Found in GD5GxGQ4xA/E
3. opcode + 1 dummy byte. Found in other currently supported chips.
Original implementation was for variant 1 and let detect function of chips with variant 2 and 3 to ignore the first byte. This isn't robust:
1. For chips of variant 2, if SPI master doesn't keep MOSI low during read, chip will get a random id offset, and the entire id buffer will shift by that offset, causing detect failure.
2. For chips of variant 1, if it happens to get a devid that equals to manufacture id of variant 2 or 3 chips, it'll get incorrectly detected.
This patch reworks detect procedure to address problems above. New logic do detection for all variants separatedly, in 1-2-3 order. Since all current detect methods do exactly the same id matching procedure, unify them into core.c and remove detect method from manufacture_ops.
Tested on GD5F1GQ4UAYIG and W25N01GVZEIG.
---
Changes since v1:
1. rename spinand_table to chips
2. introduce per-chip spinand_devid structure containing id value, length and read id method.
drivers/mtd/nand/spi/core.c | 90 +++++++++++++++++++++++-------- drivers/mtd/nand/spi/gigadevice.c | 45 +++++----------- drivers/mtd/nand/spi/macronix.c | 30 +++-------- drivers/mtd/nand/spi/micron.c | 26 ++------- drivers/mtd/nand/spi/paragon.c | 28 +++------- drivers/mtd/nand/spi/toshiba.c | 42 +++++---------- drivers/mtd/nand/spi/winbond.c | 34 +++--------- include/linux/mtd/spinand.h | 66 +++++++++++++++-------- 8 files changed, 159 insertions(+), 202 deletions(-)
drivers/mtd/nand/spi/core.c +67 -23
@@ -370,10 +370,11 @@ static int spinand_wait(struct spinand_device *spinand, u8 *s)return status &STATUS_BUSY ? -ETIMEDOUT :0 ; } -static int spinand_read_id_op (struct spinand_device *spinand,u8 *buf) +static int spinand_read_id_op (struct spinand_device *spinand,u8 naddr, +u8 ndummy,u8 *buf) { -struct spi_mem_op op =SPINAND_READID_OP (0 , spinand->scratchbuf, -SPINAND_MAX_ID_LEN ); +struct spi_mem_op op =SPINAND_READID_OP ( + naddr, ndummy, spinand->scratchbuf,SPINAND_MAX_ID_LEN );int ret; ret =spi_mem_exec_op (spinand->spimem, &op);
@@ -762,24 +763,62 @@ static const struct spinand_manufacturer *spinand_manufacturers[] = { &winbond_spinand_manufacturer, }; -static int spinand_manufacturer_detect (struct spinand_device *spinand) +static int spinand_manufacturer_match (struct spinand_device *spinand, +enum spinand_readid_method rdid_method) { +u8 *id = spinand->id.data;unsigned int i;int ret;for (i =0 ; i <ARRAY_SIZE (spinand_manufacturers); i++) { - ret = spinand_manufacturers[i]->ops->detect (spinand); -if (ret >0 ) { - spinand->manufacturer = spinand_manufacturers[i]; -return 0 ; - }else if (ret <0 ) { -return ret; - } - } +const struct spinand_manufacturer *manufacturer = + spinand_manufacturers[i]; + +if (id[0 ] != manufacturer->id) +continue ; + ret =spinand_match_and_init (spinand, + manufacturer->chips, + manufacturer->nchips, + rdid_method); +if (ret <0 ) +continue ; + + spinand->manufacturer = manufacturer; +return 0 ; + }return -ENOTSUPP ; } +static int spinand_manufacturer_detect (struct spinand_device *spinand) +{ +u8 *id = spinand->id.data; +int ret; + + ret =spinand_read_id_op (spinand,0 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand,SPINAND_READID_METHOD_OPCODE ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,1 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_ADDR ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,0 ,1 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_DUMMY ); + +return ret; +} +static int spinand_manufacturer_init (struct spinand_device *spinand) {if (spinand->manufacturer->ops->init)
@@ -835,9 +874,9 @@ spinand_select_op_variant(struct spinand_device *spinand,* @spinand: SPI NAND object * @table: SPI NAND device description table * @table_size: size of the device description table +* @rdid_method: read id method to match * -* Should be used by SPI NAND manufacturer drivers when they want to find a -* match between a device ID retrieved through the READ_ID command and an +* Match between a device ID retrieved through the READ_ID command and an * entry in the SPI NAND description table. If a match is found, the spinand * object will be initialized with information provided by the matching * spinand_info entry.
@@ -846,22 +885,33 @@ spinand_select_op_variant(struct spinand_device *spinand,*/ int spinand_match_and_init (struct spinand_device *spinand,const struct spinand_info *table, -unsigned int table_size,u16 devid) +unsigned int table_size, +enum spinand_readid_method rdid_method) { +u8 *id = spinand->id.data;struct nand_device *nand =spinand_to_nand (spinand); -unsigned int i; +u16 devid; +unsigned int i, j;for (i =0 ; i < table_size; i++) {const struct spinand_info *info = &table[i];const struct spi_mem_op *op; -if (devid != info->devid) +if (rdid_method != info->devid.method) +continue ; + + devid = id[1 ]; +for (j =1 ; j < info->devid.len ; j++) + devid = devid <<8 | id[j +1 ]; + +if (devid != info->devid.id)continue ; nand->memorg = table[i].memorg; nand->eccreq = table[i].eccreq; spinand->eccinfo = table[i].eccinfo; spinand->flags = table[i].flags; + spinand->id.len =1 + table[i].devid.len; spinand->select_target = table[i].select_target; op = spinand_select_op_variant(spinand,
@@ -898,12 +948,6 @@ static int spinand_detect(struct spinand_device *spinand)if (ret)return ret; - ret =spinand_read_id_op (spinand, spinand->id.data); -if (ret) -return ret; - - spinand->id.len =SPINAND_MAX_ID_LEN ; - ret =spinand_manufacturer_detect (spinand);if (ret) { dev_err(dev, "unknown raw ID %*phN\n", SPINAND_MAX_ID_LEN,
drivers/mtd/nand/spi/gigadevice.c +12 -33
86 lines not on this page · raw message
drivers/mtd/nand/spi/macronix.c +6 -24
@@ -99,7 +99,8 @@ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand, }static const struct spinand_info macronix_spinand_table[] = { - SPINAND_INFO("MX35LF1GE4AB", 0x12, + SPINAND_INFO("MX35LF1GE4AB", + SPINAND_ID(0x12, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1), NAND_ECCREQ(4, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -108,7 +109,8 @@ static const struct spinand_info macronix_spinand_table[] = { SPINAND_HAS_QE_BIT, SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), - SPINAND_INFO("MX35LF2GE4AB", 0x22, + SPINAND_INFO("MX35LF2GE4AB", + SPINAND_ID(0x22, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1), NAND_ECCREQ(4, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -118,33 +120,13 @@ static const struct spinand_info macronix_spinand_table[] = { SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)), }; -static int macronix_spinand_detect (struct spinand_device *spinand) -{ -u8 *id = spinand->id.data; -int ret; - -/* -* Macronix SPI NAND read ID needs a dummy byte, so the first byte in -* raw_id is garbage. -*/ -if (id[1 ] !=SPINAND_MFR_MACRONIX ) -return 0 ; - - ret =spinand_match_and_init (spinand, macronix_spinand_table, -ARRAY_SIZE (macronix_spinand_table), - id[2 ]); -if (ret) -return ret; - -return 1 ; -} -static const struct spinand_manufacturer_ops macronix_spinand_manuf_ops = { - .detect = macronix_spinand_detect, };const struct spinand_manufacturer macronix_spinand_manufacturer = { .id =SPINAND_MFR_MACRONIX , .name ="Macronix" , + .chips = macronix_spinand_table, + .nchips =ARRAY_SIZE (macronix_spinand_table), .ops = ¯onix_spinand_manuf_ops, };
drivers/mtd/nand/spi/micron.c +4 -22
@@ -91,7 +91,8 @@ static int mt29f2g01abagd_ecc_get_status(struct spinand_device *spinand, }static const struct spinand_info micron_spinand_table[] = { - SPINAND_INFO("MT29F2G01ABAGD", 0x24, + SPINAND_INFO("MT29F2G01ABAGD", + SPINAND_ID(0x24, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1), NAND_ECCREQ(8, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -102,32 +103,13 @@ static const struct spinand_info micron_spinand_table[] = { mt29f2g01abagd_ecc_get_status)), }; -static int micron_spinand_detect (struct spinand_device *spinand) -{ -u8 *id = spinand->id.data; -int ret; - -/* -* Micron SPI NAND read ID need a dummy byte, -* so the first byte in raw_id is dummy. -*/ -if (id[1 ] !=SPINAND_MFR_MICRON ) -return 0 ; - - ret =spinand_match_and_init (spinand, micron_spinand_table, -ARRAY_SIZE (micron_spinand_table), id[2 ]); -if (ret) -return ret; - -return 1 ; -} -static const struct spinand_manufacturer_ops micron_spinand_manuf_ops = { - .detect = micron_spinand_detect, };const struct spinand_manufacturer micron_spinand_manufacturer = { .id =SPINAND_MFR_MICRON , .name ="Micron" , + .chips = micron_spinand_table, + .nchips =ARRAY_SIZE (micron_spinand_table), .ops = µn_spinand_manuf_ops, };
drivers/mtd/nand/spi/paragon.c +6 -22
@@ -97,7 +97,8 @@ static const struct mtd_ooblayout_ops pn26g0xa_ooblayout = {static const struct spinand_info paragon_spinand_table[] = { - SPINAND_INFO("PN26G01A", 0xe1, + SPINAND_INFO("PN26G01A", + SPINAND_ID(0xe1, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 128, 64, 1024, 21, 1, 1, 1), NAND_ECCREQ(8, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -106,7 +107,8 @@ static const struct spinand_info paragon_spinand_table[] = { 0, SPINAND_ECCINFO(&pn26g0xa_ooblayout, pn26g0xa_ecc_get_status)), - SPINAND_INFO("PN26G02A", 0xe2, + SPINAND_INFO("PN26G02A", + SPINAND_ID(0xe2, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 128, 64, 2048, 41, 1, 1, 1), NAND_ECCREQ(8, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -117,31 +119,13 @@ static const struct spinand_info paragon_spinand_table[] = { pn26g0xa_ecc_get_status)), }; -static int paragon_spinand_detect (struct spinand_device *spinand) -{ -u8 *id = spinand->id.data; -int ret; - -/* Read ID returns [0][MID][DID] */ - -if (id[1 ] !=SPINAND_MFR_PARAGON ) -return 0 ; - - ret =spinand_match_and_init (spinand, paragon_spinand_table, -ARRAY_SIZE (paragon_spinand_table), - id[2 ]); -if (ret) -return ret; - -return 1 ; -} -static const struct spinand_manufacturer_ops paragon_spinand_manuf_ops = { - .detect = paragon_spinand_detect, };const struct spinand_manufacturer paragon_spinand_manufacturer = { .id =SPINAND_MFR_PARAGON , .name ="Paragon" , + .chips = paragon_spinand_table, + .nchips =ARRAY_SIZE (paragon_spinand_table), .ops = ¶gon_spinand_manuf_ops, };
drivers/mtd/nand/spi/toshiba.c +14 -28
89 lines not on this page · raw message
drivers/mtd/nand/spi/winbond.c +6 -28
@@ -75,7 +75,8 @@ static int w25m02gv_select_target(struct spinand_device *spinand, }static const struct spinand_info winbond_spinand_table[] = { - SPINAND_INFO("W25M02GV", 0xAB, + SPINAND_INFO("W25M02GV", + SPINAND_ID(0xAB, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2), NAND_ECCREQ(1, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -84,7 +85,8 @@ static const struct spinand_info winbond_spinand_table[] = { 0, SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL), SPINAND_SELECT_TARGET(w25m02gv_select_target)), - SPINAND_INFO("W25N01GV", 0xAA, + SPINAND_INFO("W25N01GV", + SPINAND_ID(0xAA, 1, SPINAND_READID_METHOD_OPCODE_DUMMY), NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1), NAND_ECCREQ(1, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
@@ -94,31 +96,6 @@ static const struct spinand_info winbond_spinand_table[] = { SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)), }; -/** -* winbond_spinand_detect - initialize device related part in spinand_device -* struct if it is a Winbond device. -* @spinand: SPI NAND device structure -*/ -static int winbond_spinand_detect (struct spinand_device *spinand) -{ -u8 *id = spinand->id.data; -int ret; - -/* -* Winbond SPI NAND read ID need a dummy byte, -* so the first byte in raw_id is dummy. -*/ -if (id[1 ] !=SPINAND_MFR_WINBOND ) -return 0 ; - - ret =spinand_match_and_init (spinand, winbond_spinand_table, -ARRAY_SIZE (winbond_spinand_table), id[2 ]); -if (ret) -return ret; - -return 1 ; -} -static int winbond_spinand_init (struct spinand_device *spinand) {struct nand_device *nand =spinand_to_nand (spinand);
@@ -138,12 +115,13 @@ static int winbond_spinand_init(struct spinand_device *spinand) }static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = { - .detect = winbond_spinand_detect, .init = winbond_spinand_init, };const struct spinand_manufacturer winbond_spinand_manufacturer = { .id =SPINAND_MFR_WINBOND , .name ="Winbond" , + .chips = winbond_spinand_table, + .nchips =ARRAY_SIZE (winbond_spinand_table), .ops = &winbond_spinand_manuf_ops, };
include/linux/mtd/spinand.h +44 -22
123 lines not on this page · raw message
Signature · 6 lines
2.24.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 11 lines · On Fri, 10 Jan 2020 10:51:14 +0800 Chuanhong Guo <[email protected]> wrote:
drivers/mtd/nand/spi/core.c +11
-0+static int spinand_manufacturer_detect (struct spinand_device *spinand) +{ +u8 *id = spinand->id.data; +int ret; + + ret =spinand_read_id_op (spinand,0 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand,SPINAND_READID_METHOD_OPCODE ); +if (!ret) +return 0 ;
drivers/mtd/nand/spi/core.c static const struct spinand_manufacturer *spinand_manufacturers[] = { · line 813
Quoted 10 lines
drivers/mtd/nand/spi/core.c +10
-0+ + ret =spinand_read_id_op (spinand,1 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_ADDR ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,0 ,1 , id);
Hm, we should probably do only one of each read_id and iterate over all manufacturers/chips each time instead of doing 3 read_ids per manufacturer.
Quoted 8 lines
drivers/mtd/nand/spi/core.c +8
-0+if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_DUMMY ); + +return ret; +} +
[...]
Quoted 5 lines
include/linux/mtd/spinand.h +5
-0+/** +* struct spinand_devid - SPI NAND device id structure +* @id: device id of current chip +* @len: number of bytes in device id +* @method: method to read chip id
include/linux/mtd/spinand.h struct spinand_device; · line 205
Quoted 10 lines
include/linux/mtd/spinand.h +10
-0+* There are 3 possible variants: +* SPINAND_READID_METHOD_OPCODE: chip id is returned immediately +* after read_id opcode. +* SPINAND_READID_METHOD_OPCODE_ADDR: chip id is returned after +* read_id opcode + 1-byte address. +* SPINAND_READID_METHOD_OPCODE_DUMMY: chip id is returned after +* read_id opcode + 1 dummy byte. +*/ +struct spinand_devid { +u16 id;
Can we make that field an array of u8?
const u8 *id;
Quoted 55 lines
include/linux/mtd/spinand.h +11
-13+u8 len; +enum spinand_readid_method method; +}; +/** * struct manufacurer_ops - SPI NAND manufacturer specific operations -* @detect: detect a SPI NAND device. Every time a SPI NAND device is probed -* the core calls the struct_manufacurer_ops->detect() hook of each -* registered manufacturer until one of them return 1. Note that -* the first thing to check in this hook is that the manufacturer ID -* in struct_spinand_device->id matches the manufacturer whose -* ->detect() hook has been called. Should return 1 if there's a -* match, 0 if the manufacturer ID does not match and a negative -* error code otherwise. When true is returned, the core assumes -* that properties of the NAND chip (spinand->base.memorg and -* spinand->base.eccreq) have been filled * @init: initialize a SPI NAND device * @cleanup: cleanup a SPI NAND device * * Each SPI NAND manufacturer driver should implement this interface so that -* NAND chips coming from this vendor can be detected and initialized properly. +* NAND chips coming from this vendor can be initialized properly. */ struct spinand_manufacturer_ops { -int (*detect)(struct spinand_device *spinand);int (*init)(struct spinand_device *spinand);void (*cleanup)(struct spinand_device *spinand); };@@ -215,11 +224,16 @@ struct spinand_manufacturer_ops {* struct spinand_manufacturer - SPI NAND manufacturer instance * @id: manufacturer ID * @name: manufacturer name +* @devid_len: number of bytes in device ID +* @chips: supported SPI NANDs under current manufacturer +* @nchips: number of SPI NANDs available in chips array * @ops: manufacturer operations */ struct spinand_manufacturer {u8 id;char *name; +const struct spinand_info *chips; +const size_t nchips;const struct spinand_manufacturer_ops *ops; };@@ -291,7 +305,7 @@ struct spinand_ecc_info {*/ struct spinand_info {const char *model; -u16 devid; +struct spinand_devid devid;u32 flags;struct nand_memory_organization memorg;struct nand_ecc_req eccreq;
include/linux/mtd/spinand.h struct spinand_info { · line 327
Quoted 9 lines
include/linux/mtd/spinand.h +6
-0@@ -305,6 +319,13 @@ struct spinand_info { unsigned int target); }; +#define SPINAND_ID (__id, __len, __method) \ + { \ + .id = __id, \ + .len = __len, \ + .method = __method, \ + }
That one can be turned into
#define SPINAND_ID(__method, ...) \
{ \
.id = (const u8[]){ __VA_ARGS }, \
.len = sizeof((u8[]){ __VA_ARGS }), \
.method = __method, \
}Quoted 17 lines
include/linux/mtd/spinand.h +4
-2+#define SPINAND_INFO_OP_VARIANTS (__read, __write, __update) \ { \ .read_cache = __read, \@@ -451,9 +472,10 @@ static inline void spinand_set_of_node(struct spinand_device *spinand,nanddev_set_of_node (&spinand->base, np); } -int spinand_match_and_init (struct spinand_device *dev, +int spinand_match_and_init (struct spinand_device *spinand,const struct spinand_info *table, -unsigned int table_size,u16 devid); +unsigned int table_size, +enum spinand_readid_method rdid_method);int spinand_upd_cfg (struct spinand_device *spinand,u8 mask,u8 val);int spinand_select_target (struct spinand_device *spinand,unsigned int target);
Hi!
Quoted 11 lines · Boris Brezillon
[...]
drivers/mtd/nand/spi/core.c static const struct spinand_manufacturer *spinand_manufacturers[] = { · line 813
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+ ret =spinand_read_id_op (spinand,1 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_ADDR ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,0 ,1 , id);
Quoted 3 lines
Hm, we should probably do only one of each
read_idand iterate over all manufacturers/chips each time instead of doing 3read_idsper manufacturer.
This actually do the former instead of the latter. Maybe the function names are a bit
misleading. spinand_manufacturer_match iterates over all manufacturers in one call,
and spinand_manufacturer_detect is called once in spinand_detect. Do you have suggestions on function naming?
Quoted 23 lines
[...]
include/linux/mtd/spinand.h struct spinand_device; · line 205
Quoted 5 lines
+ *
SPINAND_READID_METHOD_OPCODE_DUMMY: chip id is returned after
+ *read_idopcode + 1 dummy byte.
+ */include/linux/mtd/spinand.h +2
-0+struct spinand_devid { +u16 id;Can we make that field an array of u8?
const u8 *id;Quoted 3 lines
include/linux/mtd/spinand.h +3
-0+u8 len; +enum spinand_readid_method method; +};[...]
include/linux/mtd/spinand.h struct spinand_info { · line 327
Quoted 7 lines
include/linux/mtd/spinand.h +6
-0+#define SPINAND_ID (__id, __len, __method) \ + { \ + .id = __id, \ + .len = __len, \ + .method = __method, \ + }
Quoted 8 lines
That one can be turned into
#define SPINAND_ID(__method, ...) \ { \ .id = (const u8[]){ __VA_ARGS }, \ .len = sizeof((u8[]){ __VA_ARGS }), \ .method = __method, \ }
Wow. I never thought of this cool trick. I'll give it a try.
Regards,
Chuanhong Guo
Quoted 19 lines · On Fri, 10 Jan 2020 15:34:28 +0800 Chuanhong Guo <[email protected]> wrote:
Hi!
Quoted 11 lines · Boris Brezillon
[...]
drivers/mtd/nand/spi/core.c static const struct spinand_manufacturer *spinand_manufacturers[] = { · line 813
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+ ret =spinand_read_id_op (spinand,1 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_ADDR ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,0 ,1 , id);Quoted 3 lines
Hm, we should probably do only one of each
read_idand iterate over all manufacturers/chips each time instead of doing 3read_idsper manufacturer.
Quoted 6 lines
This actually do the former instead of the latter. Maybe the function names are a bit
misleading.spinand_manufacturer_matchiterates over all manufacturers in one call,
andspinand_manufacturer_detectis called once inspinand_detect. Do you have suggestions on function naming?
Maybe you can just inline the content of this function in spinand_detect().
Miquel Raynal
maintainerHi Boris,
Boris Brezillon <[email protected]> wrote on Fri, 10 Jan 2020 09:04:22 +0100:
Quoted 29 lines
Quoted 19 lines · On Fri, 10 Jan 2020 15:34:28 +0800 Chuanhong Guo <[email protected]> wrote:
Hi!
Quoted 11 lines · Boris Brezillon
[...]
drivers/mtd/nand/spi/core.c static const struct spinand_manufacturer *spinand_manufacturers[] = { · line 813
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+ ret =spinand_read_id_op (spinand,1 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_ADDR ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,0 ,1 , id);Quoted 3 lines
Hm, we should probably do only one of each
read_idand iterate over all manufacturers/chips each time instead of doing 3read_idsper manufacturer.Quoted 6 lines
This actually do the former instead of the latter. Maybe the function names are a bit
misleading.spinand_manufacturer_matchiterates over all manufacturers in one call,
andspinand_manufacturer_detectis called once inspinand_detect. Do you have suggestions on function naming?
Quoted 2 lines
Maybe you can just inline the content of this function in
spinand_detect().
Actually I found that part clear enough, I would keep it as is, out of the spinand_detect() function as long as there is no actual reason to merge them?
Quoted 34 lines · On Fri, 10 Jan 2020 09:10:24 +0100 Miquel Raynal <[email protected]>…
Hi Boris,
Boris Brezillon <[email protected]> wrote on Fri, 10 Jan 2020 09:04:22 +0100:
Quoted 29 lines
Quoted 25 lines · On Fri, 10 Jan 2020 15:34:28 +0800 Chuanhong Guo <[email protected]> wrote:
Hi!
Quoted 11 lines · Boris Brezillon
[...]
drivers/mtd/nand/spi/core.c static const struct spinand_manufacturer *spinand_manufacturers[] = { · line 813
Quoted 9 lines
drivers/mtd/nand/spi/core.c +9
-0+ ret =spinand_read_id_op (spinand,1 ,0 , id); +if (ret) +return ret; + ret =spinand_manufacturer_match (spinand, +SPINAND_READID_METHOD_OPCODE_ADDR ); +if (!ret) +return 0 ; + + ret =spinand_read_id_op (spinand,0 ,1 , id);Quoted 3 lines
Hm, we should probably do only one of each
read_idand iterate over all manufacturers/chips each time instead of doing 3read_idsper manufacturer.This actually do the former instead of the latter. Maybe the function names are a bit
misleading.spinand_manufacturer_matchiterates over all manufacturers in one call,
andspinand_manufacturer_detectis called once inspinand_detect. Do you have suggestions on function naming?
Quoted 6 lines
Quoted 2 lines
Maybe you can just inline the content of this function in
spinand_detect().Actually I found that part clear enough, I would keep it as is, out of the
spinand_detect()function as long as there is no actual reason to merge them?
Hm, I kind of disagree. The current name makes it sound like the function detects the manufacturer or does a per-manufacturer id detection, which is not the case. How about spinand_id_based_detect() or spinand_readid_detect()?