mtd: dataflash: Replace C99 types with their kernel counterparts
PATCH v3 1/6 mtd: dataflash: Replace C99 types with their kernel counterparts
No functional change intended.
---
Changes since [v2]:
- Re-worded commit message
- Collected Acked-by from Marek
Not present in v1
[v2]: http://lkml.kernel.org/r/[email protected]
drivers/mtd/devices/mtd_dataflash.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +20 -20
@@ -84,7 +84,7 @@struct dataflash { -uint8_t command[4 ]; +u8 command[4 ];char name[24 ];unsigned short page_offset;/* offset in flash address */
@@ -153,8 +153,8 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)struct spi_transfer x = { };struct spi_message msg;unsigned blocksize = priv->page_size <<3 ; -uint8_t *command; -uint32_t rem; +u8 *command; +u32 rem; pr_debug("%s: erase addr=0x%llx len 0x%llx\n", dev_name(&spi->dev), (long long)instr->addr,
@@ -187,8 +187,8 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) pageaddr = pageaddr << priv->page_offset; command[0 ] = do_block ?OP_ERASE_BLOCK :OP_ERASE_PAGE ; - command[1 ] = (uint8_t )(pageaddr >>16 ); - command[2 ] = (uint8_t )(pageaddr >>8 ); + command[1 ] = (u8)(pageaddr >>16 ); + command[2 ] = (u8)(pageaddr >>8 ); command[3 ] =0 ; pr_debug("ERASE %s: (%x) %x %x %x [%i]\n",
@@ -239,7 +239,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,struct spi_transfer x[2 ] = { };struct spi_message msg;unsigned int addr; -uint8_t *command; +u8 *command;int status; pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev),
@@ -271,9 +271,9 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,* fewer "don't care" bytes. Both buffers stay unchanged. */ command[0 ] =OP_READ_CONTINUOUS ; - command[1 ] = (uint8_t )(addr >>16 ); - command[2 ] = (uint8_t )(addr >>8 ); - command[3 ] = (uint8_t )(addr >>0 ); + command[1 ] = (u8)(addr >>16 ); + command[2 ] = (u8)(addr >>8 ); + command[3 ] = (u8)(addr >>0 );/* plus 4 "don't care" bytes */ status =spi_sync (priv->spi, &msg);
@@ -308,7 +308,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,size_t remaining = len;u_char *writebuf = (u_char *) buf;int status = -EINVAL ; -uint8_t *command; +u8 *command;pr_debug ("%s: write 0x%x..0x%x\n" ,dev_name (&spi->dev), (unsigned )to, (unsigned )(to + len));
@@ -455,11 +455,11 @@ static int dataflash_get_otp_info(struct mtd_info *mtd, size_t len, }static ssize_t otp_read (struct spi_device *spi,unsigned base, -uint8_t *buf,loff_t off,size_t len) +u8 *buf,loff_t off,size_t len) {struct spi_message m;size_t l; -uint8_t *scratch; +u8 *scratch;struct spi_transfer t;int status;
@@ -538,7 +538,7 @@ static int dataflash_write_user_otp(struct mtd_info *mtd, {struct spi_message m;const size_t l =4 +64 ; -uint8_t *scratch; +u8 *scratch;struct spi_transfer t;struct dataflash *priv = mtd->priv;int status;
@@ -689,14 +689,14 @@ struct flash_info {/* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ -uint32_t jedec_id; +u32 jedec_id;/* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages; -uint16_t pagesize; -uint16_t pageoffset; +u16 pagesize; +u16 pageoffset; -uint16_t flags; +u16 flags;#define SUP_POW2PS 0x0002/* supports 2^N byte pages */ #define IS_POW2PS 0x0001/* uses 2^N byte pages */ };
@@ -739,9 +739,9 @@ static struct flash_info dataflash_data[] = {static struct flash_info *jedec_probe (struct spi_device *spi) {int tmp; -uint8_t code =OP_READ_ID ; -uint8_t id[3 ]; -uint32_t jedec; +u8 code =OP_READ_ID ; +u8 id[3 ]; +u32 jedec;struct flash_info *info;int status;
Signature · 1 line
2.9.3
PATCH v3 2/6 mtd: dataflash: Improve coding style in jedec_probe()
Change the following:
- Replace indentation between type and name of local variable from tabs to spaces
- Replace magic number 0x1F with CFI_MFR_ATMEL macro
- Replace variable 'tmp' with 'ret' and 'i' where appropriate
- Reformat multi-line comments and add newlines where appropriate
No functional change intended.
---
Changes since [v2]:
- Re-worded commit message
- Collected Acked-by from Marek
Not present in v1
[v2] http://lkml.kernel.org/r/[email protected]
drivers/mtd/devices/mtd_dataflash.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +17 -14
@@ -82,6 +82,7 @@#define OP_WRITE_SECURITY_REVC 0x9A#define OP_WRITE_SECURITY 0x9B/* revision D */ +#define CFI_MFR_ATMEL 0x1Fstruct dataflash {u8 command[4 ];
@@ -738,14 +739,15 @@ static struct flash_info dataflash_data[] = {static struct flash_info *jedec_probe (struct spi_device *spi) { -int tmp; -u8 code =OP_READ_ID ; -u8 id[3 ]; -u32 jedec; -struct flash_info *info; +int ret, i; +u8 code =OP_READ_ID ; +u8 id[3 ]; +u32 jedec; +struct flash_info *info;int status; -/* JEDEC also defines an optional "extended device information" +/* +* JEDEC also defines an optional "extended device information" * string for after vendor-specific data, after the three bytes * we use here. Supporting some chips might require using it. *
@@ -753,13 +755,14 @@ static struct flash_info *jedec_probe(struct spi_device *spi)* That's not an error; only rev C and newer chips handle it, and * only Atmel sells these chips. */ - tmp =spi_write_then_read (spi, &code,1 , id,3 ); -if (tmp <0 ) { + ret =spi_write_then_read (spi, &code,1 , id,3 ); +if (ret <0 ) {pr_debug ("%s: error %d reading JEDEC ID\n" , -dev_name (&spi->dev), tmp); -return ERR_PTR (tmp); +dev_name (&spi->dev), ret); +return ERR_PTR (ret); } -if (id[0 ] !=0x1f ) + +if (id[0 ] !=CFI_MFR_ATMEL )return NULL ; jedec = id[0 ];
@@ -768,9 +771,9 @@ static struct flash_info *jedec_probe(struct spi_device *spi) jedec = jedec <<8 ; jedec |= id[2 ]; -for (tmp =0 , info = dataflash_data; - tmp <ARRAY_SIZE (dataflash_data); - tmp++, info++) { +for (i =0 , info = dataflash_data; + i <ARRAY_SIZE (dataflash_data); + i++, info++) {if (info->jedec_id == jedec) { pr_debug("%s: OTP, sector protect%s\n", dev_name(&spi->dev),
Signature · 1 line
2.9.3
PATCH v3 3/6 mtd: dataflash: Replace pr_debug, printk with dev_* functions
In reply to Andrey SmirnovLion's share of calls to pr_debug in this driver follow the pattern of pr_debug("%s <message>", dev_name(<dev>), <arguments>), which should be semantically identical to dev_dbg(<dev>, "<message>", <arguments>), so replace such occurencies to simplify the code.
Convert the small minority of pr_debug that do not follow pattern from above to use dev_dbg as well, for the sake of consistency.
Convert similar patter of printk(KERN_ERR, "%s: ...", dev_name(...), ...) to use dev_err instead.
No functional change intended.
---
Not present in v2, v1
drivers/mtd/devices/mtd_dataflash.c | 74 +++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 41 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +33 -41
@@ -130,8 +130,7 @@ static int dataflash_waitready(struct spi_device *spi)for (;;) { status =dataflash_status (spi);if (status <0 ) { -pr_debug ("%s: status %d?\n" , -dev_name (&spi->dev), status); +dev_dbg (&spi->dev,"status %d?\n" , status); status =0 ; }
@@ -157,9 +156,8 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)u8 *command;u32 rem; -pr_debug ("%s: erase addr=0x%llx len 0x%llx\n" , -dev_name (&spi->dev), (long long )instr->addr, - (long long )instr->len); +dev_dbg (&spi->dev,"erase addr=0x%llx len 0x%llx\n" , + (long long )instr->addr, (long long )instr->len);div_u64_rem (instr->len, priv->page_size, &rem);if (rem)
@@ -192,7 +190,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) command[2 ] = (u8)(pageaddr >>8 ); command[3 ] =0 ; -pr_debug ("ERASE %s: (%x) %x %x %x [%i]\n" , +dev_dbg (&spi->dev,"ERASE %s: (%x) %x %x %x [%i]\n" , do_block ?"block" :"page" , command[0 ], command[1 ], command[2 ], command[3 ], pageaddr);
@@ -201,8 +199,8 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) (void )dataflash_waitready (spi);if (status <0 ) { -printk (KERN_ERR "%s: erase %x, err %d\n" , -dev_name (&spi->dev), pageaddr, status); +dev_err (&spi->dev,"erase %x, err %d\n" , + pageaddr, status);/* REVISIT: can retry instr->retries times; or * giveup and instr->fail_addr = instr->addr; */
@@ -243,8 +241,8 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,u8 *command;int status; -pr_debug ("%s: read 0x%x..0x%x\n" ,dev_name (&priv->spi->dev), - (unsigned )from, (unsigned )(from + len)); +dev_dbg (&priv->spi->dev,"read 0x%x..0x%x\n" , + (unsigned int )from, (unsigned int )(from + len));/* Calculate flash page/byte address */ addr = (((unsigned )from / priv->page_size) << priv->page_offset)
@@ -252,7 +250,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, command = priv->command; -pr_debug ("READ: (%x) %x %x %x\n" , +dev_dbg (&priv->spi->dev,"READ: (%x) %x %x %x\n" , command[0 ], command[1 ], command[2 ], command[3 ]);spi_message_init (&msg);
@@ -284,8 +282,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, *retlen = msg.actual_length -8 ; status =0 ; }else -pr_debug ("%s: read %x..%x --> %d\n" , -dev_name (&priv->spi->dev), +dev_dbg (&priv->spi->dev,"read %x..%x --> %d\n" , (unsigned )from, (unsigned )(from + len), status);return status;
@@ -311,8 +308,8 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,int status = -EINVAL ;u8 *command; -pr_debug ("%s: write 0x%x..0x%x\n" , -dev_name (&spi->dev), (unsigned )to, (unsigned )(to + len)); +dev_dbg (&spi->dev,"write 0x%x..0x%x\n" , + (unsigned int )to, (unsigned int )(to + len));spi_message_init (&msg);
@@ -329,7 +326,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,mutex_lock (&priv->lock);while (remaining >0 ) { -pr_debug ("write @ %i:%i len=%i\n" , +dev_dbg (&spi->dev,"write @ %i:%i len=%i\n" , pageaddr, offset, writelen);/* REVISIT:
@@ -357,13 +354,13 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, command[2 ] = (addr &0x0000FF00 ) >>8 ; command[3 ] =0 ; -pr_debug ("TRANSFER: (%x) %x %x %x\n" , +dev_dbg (&spi->dev,"TRANSFER: (%x) %x %x %x\n" , command[0 ], command[1 ], command[2 ], command[3 ]); status =spi_sync (spi, &msg);if (status <0 ) -pr_debug ("%s: xfer %u -> %d\n" , -dev_name (&spi->dev), addr, status); +dev_dbg (&spi->dev,"xfer %u -> %d\n" , + addr, status); (void )dataflash_waitready (priv->spi); }
@@ -375,7 +372,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, command[2 ] = (addr &0x0000FF00 ) >>8 ; command[3 ] = (addr &0x000000FF ); -pr_debug ("PROGRAM: (%x) %x %x %x\n" , +dev_dbg (&spi->dev,"PROGRAM: (%x) %x %x %x\n" , command[0 ], command[1 ], command[2 ], command[3 ]); x[1 ].tx_buf = writebuf;
@@ -384,8 +381,8 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, status =spi_sync (spi, &msg);spi_transfer_del (x +1 );if (status <0 ) -pr_debug ("%s: pgm %u/%u -> %d\n" , -dev_name (&spi->dev), addr, writelen, status); +dev_dbg (&spi->dev,"pgm %u/%u -> %d\n" , + addr, writelen, status); (void )dataflash_waitready (priv->spi);
@@ -399,20 +396,20 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, command[2 ] = (addr &0x0000FF00 ) >>8 ; command[3 ] =0 ; -pr_debug ("COMPARE: (%x) %x %x %x\n" , +dev_dbg (&spi->dev,"COMPARE: (%x) %x %x %x\n" , command[0 ], command[1 ], command[2 ], command[3 ]); status =spi_sync (spi, &msg);if (status <0 ) -pr_debug ("%s: compare %u -> %d\n" , -dev_name (&spi->dev), addr, status); +dev_dbg (&spi->dev,"compare %u -> %d\n" , + addr, status); status =dataflash_waitready (priv->spi);/* Check result of the compare operation */ if (status & (1 <<6 )) { -printk (KERN_ERR "%s: compare page %u, err %d\n" , -dev_name (&spi->dev), pageaddr, status); +dev_err (&spi->dev,"compare page %u, err %d\n" , + pageaddr, status); remaining =0 ; status = -EIO ;break ;
@@ -757,8 +754,7 @@ static struct flash_info *jedec_probe(struct spi_device *spi)*/ ret =spi_write_then_read (spi, &code,1 , id,3 );if (ret <0 ) { -pr_debug ("%s: error %d reading JEDEC ID\n" , -dev_name (&spi->dev), ret); +dev_dbg (&spi->dev,"error %d reading JEDEC ID\n" , ret);return ERR_PTR (ret); }
@@ -775,16 +771,14 @@ static struct flash_info *jedec_probe(struct spi_device *spi) i <ARRAY_SIZE (dataflash_data); i++, info++) {if (info->jedec_id == jedec) { -pr_debug ("%s: OTP, sector protect%s\n" , -dev_name (&spi->dev), - (info->flags &SUP_POW2PS ) - ?", binary pagesize" :"" - ); +dev_dbg (&spi->dev,"OTP, sector protect%s\n" , + (info->flags &SUP_POW2PS ) ? +", binary pagesize" :"" );if (info->flags &SUP_POW2PS ) { status =dataflash_status (spi);if (status <0 ) { -pr_debug ("%s: status error %d\n" , -dev_name (&spi->dev), status); +dev_dbg (&spi->dev,"status error %d\n" , + status);return ERR_PTR (status); }if (status &0x1 ) {
@@ -848,8 +842,7 @@ static int dataflash_probe(struct spi_device *spi)*/ status =dataflash_status (spi);if (status <=0 || status ==0xff ) { -pr_debug ("%s: status error %d\n" , -dev_name (&spi->dev), status); +dev_dbg (&spi->dev,"status error %d\n" , status);if (status ==0 || status ==0xff ) status = -ENODEV ;return status;
@@ -890,8 +883,7 @@ static int dataflash_probe(struct spi_device *spi) }if (status <0 ) -pr_debug ("%s: add_dataflash --> %d\n" ,dev_name (&spi->dev), - status); +dev_dbg (&spi->dev,"add_dataflash --> %d\n" , status);return status; }
@@ -901,7 +893,7 @@ static int dataflash_remove(struct spi_device *spi)struct dataflash *flash =spi_get_drvdata (spi);int status; -pr_debug ("%s: remove\n" ,dev_name (&spi->dev)); +dev_dbg (&spi->dev,"remove\n" ); status =mtd_device_unregister (&flash->mtd);if (status ==0 )
Signature · 1 line
2.9.3
Re: [PATCH v3 3/6] mtd: dataflash: Replace pr_debug, printk with dev_* functions
Quoted 22 lines · Andrey Smirnov
Lion's share of calls to
pr_debugin this driver follow the pattern ofpr_debug("%s <message>", dev_name(<dev>), <arguments>), which should be semantically identical todev_dbg(<dev>, "<message>", <arguments>), so replace such occurencies to simplify the code.Convert the small minority of
pr_debugthat do not follow pattern from above to usedev_dbgas well, for the sake of consistency.Convert similar patter of
printk(KERN_ERR, "%s: ...", dev_name(...), ...)to usedev_errinstead.No functional change intended.
Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 1 line
---
btw where is 1/6 and 2/6 ?
Signature · 2 lines
Best regards, Marek Vasut
Re: [PATCH v3 3/6] mtd: dataflash: Replace pr_debug, printk with dev_* functions
Quoted 25 lines · Marek Vasut
Quoted 22 lines · Andrey Smirnov
Lion's share of calls to
pr_debugin this driver follow the pattern ofpr_debug("%s <message>", dev_name(<dev>), <arguments>), which should be semantically identical todev_dbg(<dev>, "<message>", <arguments>), so replace such occurencies to simplify the code.Convert the small minority of
pr_debugthat do not follow pattern from above to usedev_dbgas well, for the sake of consistency.Convert similar patter of
printk(KERN_ERR, "%s: ...", dev_name(...), ...)to usedev_errinstead.No functional change intended.
Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>Quoted 1 line
---
Quoted 3 lines
Reviewed-by Marek Vasut <[email protected]>btw where is 1/6 and 2/6 ?
Sorry, looks like git send-mail didn't pick up Acked-by tag to be added to CC list. They are here:
https://marc.info/?l=linux-kernel&m=149261547916625
https://marc.info/?l=linux-kernel&m=149261543416614
Quoted 4 lines
--
Best regards,
Marek Vasut
Re: [PATCH v3 3/6] mtd: dataflash: Replace pr_debug, printk with dev_* functions
Quoted 26 lines · Andrey Smirnov
Quoted 25 lines · Marek Vasut
Quoted 23 lines · Andrey Smirnov
Lion's share of calls to
pr_debugin this driver follow the pattern ofpr_debug("%s <message>", dev_name(<dev>), <arguments>), which should be semantically identical todev_dbg(<dev>, "<message>", <arguments>), so replace such occurencies to simplify the code.Convert the small minority of
pr_debugthat do not follow pattern from above to usedev_dbgas well, for the sake of consistency.Convert similar patter of
printk(KERN_ERR, "%s: ...", dev_name(...), ...)to usedev_errinstead.No functional change intended.
Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
Quoted 6 lines
Quoted 3 lines
Reviewed-by Marek Vasut <[email protected]>btw where is 1/6 and 2/6 ?
Sorry, looks like git send-mail didn't pick up Acked-by tag to be added to CC list. They are here:
Yeah, git send-email doesn't CC people in the Ack list. Keep the CC: tag please.
Quoted 7 lines
https://marc.info/?l=linux-kernel&m=149261547916625
https://marc.info/?l=linux-kernel&m=149261543416614Quoted 4 lines
--
Best regards,
Marek Vasut
Signature · 2 lines
Best regards, Marek Vasut
PATCH v3 4/6 mtd: dataflash: Get rid of loop counter in jedec_probe()
In reply to Andrey Smirnov"For" loop in jedec_probe can be simplified to not need counter 'i'. Convert the code and get rid of the variable.
---
Not present in v2, v1.
drivers/mtd/devices/mtd_dataflash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +4 -4
@@ -736,7 +736,7 @@ static struct flash_info dataflash_data[] = {static struct flash_info *jedec_probe (struct spi_device *spi) { -int ret, i; +int ret;u8 code =OP_READ_ID ;u8 id[3 ];u32 jedec;
@@ -767,9 +767,9 @@ static struct flash_info *jedec_probe(struct spi_device *spi) jedec = jedec <<8 ; jedec |= id[2 ]; -for (i =0 , info = dataflash_data; - i <ARRAY_SIZE (dataflash_data); - i++, info++) { +for (info = dataflash_data; + info < dataflash_data +ARRAY_SIZE (dataflash_data); + info++) {if (info->jedec_id == jedec) { dev_dbg(&spi->dev, "OTP, sector protect%s\n", (info->flags & SUP_POW2PS) ?
Signature · 1 line
2.9.3
Re: [PATCH v3 4/6] mtd: dataflash: Get rid of loop counter in jedec_probe()
Quoted 12 lines · Andrey Smirnov
"For" loop in
jedec_probecan be simplified to not need counter 'i'. Convert the code and get rid of the variable.Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 1 line
---
Signature · 2 lines
Best regards, Marek Vasut
PATCH v3 5/6 mtd: dataflash: Make use of "extened device information"
In reply to Andrey SmirnovIn anticipation of supporting chips that need it, extend the size of struct flash_info's 'jedec_id' field to make room 2 byte of extended device information as well as add code to fetch this data during jedec_probe().
---
Changes since [v2]:
- Make 'id' have same size as 'jedec'
- Get rid of eid_mask variable in favour of using GENMASK in-place
Changes since [v1]:
- Formatting
[v1] http://lkml.kernel.org/r/[email protected]
[v2] http://lkml.kernel.org/r/[email protected]
drivers/mtd/devices/mtd_dataflash.c | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-)
drivers/mtd/devices/mtd_dataflash.c +68 -47
@@ -687,7 +687,7 @@ struct flash_info {/* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ -u32 jedec_id; +u64 jedec_id;/* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages;
@@ -710,62 +710,34 @@ static struct flash_info dataflash_data[] = {* These newer chips also support 128-byte security registers (with * 64 bytes one-time-programmable) and software write-protection. */ - { "AT45DB011B", 0x1f2200, 512, 264, 9, SUP_POW2PS}, - { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB011B", 0x1f22000000, 512, 264, 9, SUP_POW2PS}, + { "at45db011d", 0x1f22000000, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB021B", 0x1f2300, 1024, 264, 9, SUP_POW2PS}, - { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB021B", 0x1f23000000, 1024, 264, 9, SUP_POW2PS}, + { "at45db021d", 0x1f23000000, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB041x", 0x1f2400, 2048, 264, 9, SUP_POW2PS}, - { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB041x", 0x1f24000000, 2048, 264, 9, SUP_POW2PS}, + { "at45db041d", 0x1f24000000, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB081B", 0x1f2500, 4096, 264, 9, SUP_POW2PS}, - { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB081B", 0x1f25000000, 4096, 264, 9, SUP_POW2PS}, + { "at45db081d", 0x1f25000000, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB161x", 0x1f2600, 4096, 528, 10, SUP_POW2PS}, - { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB161x", 0x1f26000000, 4096, 528, 10, SUP_POW2PS}, + { "at45db161d", 0x1f26000000, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB321x", 0x1f2700, 8192, 528, 10, 0}, /* rev C */ + { "AT45DB321x", 0x1f27000000, 8192, 528, 10, 0}, /* rev C */ - { "AT45DB321x", 0x1f2701, 8192, 528, 10, SUP_POW2PS}, - { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB321x", 0x1f27010000, 8192, 528, 10, SUP_POW2PS}, + { "at45db321d", 0x1f27010000, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB642x", 0x1f2800, 8192, 1056, 11, SUP_POW2PS}, - { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, + { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe (struct spi_device *spi) +static struct flash_info *jedec_lookup (struct spi_device *spi,u64 jedec) { -int ret; -u8 code =OP_READ_ID ; -u8 id[3 ]; -u32 jedec; -struct flash_info *info;int status; - -/* -* JEDEC also defines an optional "extended device information" -* string for after vendor-specific data, after the three bytes -* we use here. Supporting some chips might require using it. -* -* If the vendor ID isn't Atmel's (0x1f), assume this call failed. -* That's not an error; only rev C and newer chips handle it, and -* only Atmel sells these chips. -*/ - ret =spi_write_then_read (spi, &code,1 , id,3 ); -if (ret <0 ) { -dev_dbg (&spi->dev,"error %d reading JEDEC ID\n" , ret); -return ERR_PTR (ret); - } - -if (id[0 ] !=CFI_MFR_ATMEL ) -return NULL ; - - jedec = id[0 ]; - jedec = jedec <<8 ; - jedec |= id[1 ]; - jedec = jedec <<8 ; - jedec |= id[2 ]; +struct flash_info *info; for (info = dataflash_data; info < dataflash_data + ARRAY_SIZE(dataflash_data);
@@ -793,12 +765,61 @@ static struct flash_info *jedec_probe(struct spi_device *spi) } } +return NULL ; +} + +static struct flash_info *jedec_probe (struct spi_device *spi) +{ +int ret; +u8 code =OP_READ_ID ; +u64 jedec; +u8 id[sizeof (jedec)] = {0 }; +const unsigned int id_size =5 ; +const unsigned int first_byte =sizeof (id) - id_size; +struct flash_info *info; + +/* +* JEDEC also defines an optional "extended device information" +* string for after vendor-specific data, after the three bytes +* we use here. Supporting some chips might require using it. +* +* If the vendor ID isn't Atmel's (0x1f), assume this call failed. +* That's not an error; only rev C and newer chips handle it, and +* only Atmel sells these chips. +*/ + ret =spi_write_then_read (spi, &code,1 , &id[first_byte], id_size); +if (ret <0 ) { +pr_debug ("%s: error %d reading JEDEC ID\n" , +dev_name (&spi->dev), ret); +return ERR_PTR (ret); + } + +if (id[first_byte] !=CFI_MFR_ATMEL ) +return NULL ; + + jedec =be64_to_cpup ((__be64 *)id); + + info =jedec_lookup (spi, jedec); +if (info) +return info; + +/* +* Clear extended id bits (bits 0 through 15) and try to find +* a match again in case our chip does not support returning +* extended ID information and we got invalid bits instead +*/ + jedec &=GENMASK_ULL (63 ,16 ); + + info =jedec_lookup (spi, jedec); +if (info) +return info; +/* * Treat other chips as errors ... we won't know the right page * size (it might be binary) even when we can tell which density * class is involved (legacy chip id scheme). */ -dev_warn (&spi->dev,"JEDEC id %06x not handled\n" , jedec); +dev_warn (&spi->dev,"JEDEC id %010llx not handled\n" , jedec);return ERR_PTR (-ENODEV ); }
Signature · 1 line
2.9.3
Re: [PATCH v3 5/6] mtd: dataflash: Make use of "extened device information"
Quoted 143 lines · Andrey Smirnov
In anticipation of supporting chips that need it, extend the size of struct flash_info's '
jedec_id' field to make room 2 byte of extended device information as well as add code to fetch this data duringjedec_probe().Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
Changes since [v2]:
- Make 'id' have same size as 'jedec'
- Get rid of
eid_maskvariable in favour of using GENMASK in-placeChanges since [v1]:
- Formatting
[v1] http://lkml.kernel.org/r/[email protected]
[v2] http://lkml.kernel.org/r/[email protected]drivers/mtd/devices/mtd_dataflash.c | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-)drivers/mtd/devices/mtd_dataflash.c +31
-46@@ -687,7 +687,7 @@ struct flash_info {/* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ -u32 jedec_id; +u64 jedec_id;/* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages;@@ -710,62 +710,34 @@ static struct flash_info dataflash_data[] = {* These newer chips also support 128-byte security registers (with * 64 bytes one-time-programmable) and software write-protection. */ - { "AT45DB011B", 0x1f2200, 512, 264, 9, SUP_POW2PS}, - { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB011B", 0x1f22000000, 512, 264, 9, SUP_POW2PS}, + { "at45db011d", 0x1f22000000, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB021B", 0x1f2300, 1024, 264, 9, SUP_POW2PS}, - { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB021B", 0x1f23000000, 1024, 264, 9, SUP_POW2PS}, + { "at45db021d", 0x1f23000000, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB041x", 0x1f2400, 2048, 264, 9, SUP_POW2PS}, - { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB041x", 0x1f24000000, 2048, 264, 9, SUP_POW2PS}, + { "at45db041d", 0x1f24000000, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB081B", 0x1f2500, 4096, 264, 9, SUP_POW2PS}, - { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB081B", 0x1f25000000, 4096, 264, 9, SUP_POW2PS}, + { "at45db081d", 0x1f25000000, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB161x", 0x1f2600, 4096, 528, 10, SUP_POW2PS}, - { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB161x", 0x1f26000000, 4096, 528, 10, SUP_POW2PS}, + { "at45db161d", 0x1f26000000, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB321x", 0x1f2700, 8192, 528, 10, 0}, /* rev C */ + { "AT45DB321x", 0x1f27000000, 8192, 528, 10, 0}, /* rev C */ - { "AT45DB321x", 0x1f2701, 8192, 528, 10, SUP_POW2PS}, - { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB321x", 0x1f27010000, 8192, 528, 10, SUP_POW2PS}, + { "at45db321d", 0x1f27010000, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB642x", 0x1f2800, 8192, 1056, 11, SUP_POW2PS}, - { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, + { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe (struct spi_device *spi) +static struct flash_info *jedec_lookup (struct spi_device *spi,u64 jedec) { -int ret; -u8 code =OP_READ_ID ; -u8 id[3 ]; -u32 jedec; -struct flash_info *info;int status; - -/* -* JEDEC also defines an optional "extended device information" -* string for after vendor-specific data, after the three bytes -* we use here. Supporting some chips might require using it. -* -* If the vendor ID isn't Atmel's (0x1f), assume this call failed. -* That's not an error; only rev C and newer chips handle it, and -* only Atmel sells these chips. -*/ - ret =spi_write_then_read (spi, &code,1 , id,3 ); -if (ret <0 ) { -dev_dbg (&spi->dev,"error %d reading JEDEC ID\n" , ret); -return ERR_PTR (ret); - } - -if (id[0 ] !=CFI_MFR_ATMEL ) -return NULL ; - - jedec = id[0 ]; - jedec = jedec <<8 ; - jedec |= id[1 ]; - jedec = jedec <<8 ; - jedec |= id[2 ]; +struct flash_info *info; for (info = dataflash_data; info < dataflash_data + ARRAY_SIZE(dataflash_data);@@ -793,12 +765,61 @@ static struct flash_info *jedec_probe(struct spi_device *spi) } } +return NULL ; +} + +static struct flash_info *jedec_probe (struct spi_device *spi) +{ +int ret; +u8 code =OP_READ_ID ; +u64 jedec; +u8 id[sizeof (jedec)] = {0 }; +const unsigned int id_size =5 ; +const unsigned int first_byte =sizeof (id) - id_size; +struct flash_info *info; +
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 790
Quoted 10 lines
drivers/mtd/devices/mtd_dataflash.c +10
-0+/* +* JEDEC also defines an optional "extended device information" +* string for after vendor-specific data, after the three bytes +* we use here. Supporting some chips might require using it. +* +* If the vendor ID isn't Atmel's (0x1f), assume this call failed. +* That's not an error; only rev C and newer chips handle it, and +* only Atmel sells these chips. +*/ + ret =spi_write_then_read (spi, &code,1 , &id[first_byte], id_size);
Hm, looking at this again, what prevents you from reading these bytes into &id[0] ? Might be easier, ie.
ret = spi_write_then_read(spi, &code, 1, id, id_size);
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 797
Quoted 7 lines
drivers/mtd/devices/mtd_dataflash.c +7
-0+if (ret <0 ) { +pr_debug ("%s: error %d reading JEDEC ID\n" , +dev_name (&spi->dev), ret); +return ERR_PTR (ret); + } + +if (id[first_byte] !=CFI_MFR_ATMEL )
if (id[0] != CFI_MFR_ATMEL)
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 802
Quoted 5 lines
drivers/mtd/devices/mtd_dataflash.c +5
-0+return NULL ; + + jedec =be64_to_cpup ((__be64 *)id); + + info =jedec_lookup (spi, jedec);
... define these somewhere at the beginning of the dataflash code ...
#define DATAFLASH_MASK_STD GENMASK(63, 40)
#define DATAFLASH_MASK_EXT GENMASK(63, 16)
... then ...
info = jedec_lookup(spi, jedec & DATAFLASH_MASK_EXT);
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 811
Quoted 9 lines
drivers/mtd/devices/mtd_dataflash.c +9
-0+if (info) +return info; + +/* +* Clear extended id bits (bits 0 through 15) and try to find +* a match again in case our chip does not support returning +* extended ID information and we got invalid bits instead +*/ + jedec &=GENMASK_ULL (63 ,16 );
info = jedec_lookup(spi, jedec & DATAFLASH_MASK_STD);
Quoted 15 lines
drivers/mtd/devices/mtd_dataflash.c +5
-1+ info =jedec_lookup (spi, jedec); +if (info) +return info; +/* * Treat other chips as errors ... we won't know the right page * size (it might be binary) even when we can tell which density * class is involved (legacy chip id scheme). */ -dev_warn (&spi->dev,"JEDEC id %06x not handled\n" , jedec); +dev_warn (&spi->dev,"JEDEC id %010llx not handled\n" , jedec);return ERR_PTR (-ENODEV ); }
Signature · 2 lines
Best regards, Marek Vasut
Re: [PATCH v3 5/6] mtd: dataflash: Make use of "extened device information"
Quoted 158 lines · Marek Vasut
Quoted 143 lines · Andrey Smirnov
In anticipation of supporting chips that need it, extend the size of struct flash_info's '
jedec_id' field to make room 2 byte of extended device information as well as add code to fetch this data duringjedec_probe().Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
Changes since [v2]:
- Make 'id' have same size as 'jedec'
- Get rid of
eid_maskvariable in favour of using GENMASK in-placeChanges since [v1]:
- Formatting
[v1] http://lkml.kernel.org/r/[email protected]
[v2] http://lkml.kernel.org/r/[email protected]drivers/mtd/devices/mtd_dataflash.c | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-)drivers/mtd/devices/mtd_dataflash.c +31
-46@@ -687,7 +687,7 @@ struct flash_info {/* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ -u32 jedec_id; +u64 jedec_id;/* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages;@@ -710,62 +710,34 @@ static struct flash_info dataflash_data[] = {* These newer chips also support 128-byte security registers (with * 64 bytes one-time-programmable) and software write-protection. */ - { "AT45DB011B", 0x1f2200, 512, 264, 9, SUP_POW2PS}, - { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB011B", 0x1f22000000, 512, 264, 9, SUP_POW2PS}, + { "at45db011d", 0x1f22000000, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB021B", 0x1f2300, 1024, 264, 9, SUP_POW2PS}, - { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB021B", 0x1f23000000, 1024, 264, 9, SUP_POW2PS}, + { "at45db021d", 0x1f23000000, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB041x", 0x1f2400, 2048, 264, 9, SUP_POW2PS}, - { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB041x", 0x1f24000000, 2048, 264, 9, SUP_POW2PS}, + { "at45db041d", 0x1f24000000, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB081B", 0x1f2500, 4096, 264, 9, SUP_POW2PS}, - { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB081B", 0x1f25000000, 4096, 264, 9, SUP_POW2PS}, + { "at45db081d", 0x1f25000000, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB161x", 0x1f2600, 4096, 528, 10, SUP_POW2PS}, - { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB161x", 0x1f26000000, 4096, 528, 10, SUP_POW2PS}, + { "at45db161d", 0x1f26000000, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB321x", 0x1f2700, 8192, 528, 10, 0}, /* rev C */ + { "AT45DB321x", 0x1f27000000, 8192, 528, 10, 0}, /* rev C */ - { "AT45DB321x", 0x1f2701, 8192, 528, 10, SUP_POW2PS}, - { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB321x", 0x1f27010000, 8192, 528, 10, SUP_POW2PS}, + { "at45db321d", 0x1f27010000, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB642x", 0x1f2800, 8192, 1056, 11, SUP_POW2PS}, - { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, + { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe (struct spi_device *spi) +static struct flash_info *jedec_lookup (struct spi_device *spi,u64 jedec) { -int ret; -u8 code =OP_READ_ID ; -u8 id[3 ]; -u32 jedec; -struct flash_info *info;int status; - -/* -* JEDEC also defines an optional "extended device information" -* string for after vendor-specific data, after the three bytes -* we use here. Supporting some chips might require using it. -* -* If the vendor ID isn't Atmel's (0x1f), assume this call failed. -* That's not an error; only rev C and newer chips handle it, and -* only Atmel sells these chips. -*/ - ret =spi_write_then_read (spi, &code,1 , id,3 ); -if (ret <0 ) { -dev_dbg (&spi->dev,"error %d reading JEDEC ID\n" , ret); -return ERR_PTR (ret); - } - -if (id[0 ] !=CFI_MFR_ATMEL ) -return NULL ; - - jedec = id[0 ]; - jedec = jedec <<8 ; - jedec |= id[1 ]; - jedec = jedec <<8 ; - jedec |= id[2 ]; +struct flash_info *info; for (info = dataflash_data; info < dataflash_data + ARRAY_SIZE(dataflash_data);@@ -793,12 +765,61 @@ static struct flash_info *jedec_probe(struct spi_device *spi) } } +return NULL ; +} + +static struct flash_info *jedec_probe (struct spi_device *spi) +{ +int ret; +u8 code =OP_READ_ID ; +u64 jedec; +u8 id[sizeof (jedec)] = {0 }; +const unsigned int id_size =5 ; +const unsigned int first_byte =sizeof (id) - id_size; +struct flash_info *info; +drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 790
Quoted 10 lines
drivers/mtd/devices/mtd_dataflash.c +10
-0+/* +* JEDEC also defines an optional "extended device information" +* string for after vendor-specific data, after the three bytes +* we use here. Supporting some chips might require using it. +* +* If the vendor ID isn't Atmel's (0x1f), assume this call failed. +* That's not an error; only rev C and newer chips handle it, and +* only Atmel sells these chips. +*/ + ret =spi_write_then_read (spi, &code,1 , &id[first_byte], id_size);Hm, looking at this again, what prevents you from reading these bytes into &id[0] ? Might be easier, ie.
Quoted 2 lines
ret =
spi_write_then_read(spi, &code, 1, id, id_size);
Then I'd have to add 6 more '0's to each of the IDs in dataflash_data, which would make that code even less readable.
Quoted 33 lines
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 797
Quoted 7 lines
drivers/mtd/devices/mtd_dataflash.c +7
-0+if (ret <0 ) { +pr_debug ("%s: error %d reading JEDEC ID\n" , +dev_name (&spi->dev), ret); +return ERR_PTR (ret); + } + +if (id[first_byte] !=CFI_MFR_ATMEL )if (id[0] !=
CFI_MFR_ATMEL)drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 802
Quoted 5 lines
drivers/mtd/devices/mtd_dataflash.c +5
-0+return NULL ; + + jedec =be64_to_cpup ((__be64 *)id); + + info =jedec_lookup (spi, jedec);... define these somewhere at the beginning of the dataflash code ...
#defineDATAFLASH_MASK_STDGENMASK(63, 40)
#defineDATAFLASH_MASK_EXTGENMASK(63, 16)... then ...
info =jedec_lookup(spi, jedec & DATAFLASH_MASK_EXT);drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 811
Quoted 9 lines
drivers/mtd/devices/mtd_dataflash.c +9
-0+if (info) +return info; + +/* +* Clear extended id bits (bits 0 through 15) and try to find +* a match again in case our chip does not support returning +* extended ID information and we got invalid bits instead +*/ + jedec &=GENMASK_ULL (63 ,16 );
Quoted 2 lines
info =
jedec_lookup(spi, jedec & DATAFLASH_MASK_STD);
Sure, OK.
Thanks,
Andrey Smirnov
Re: [PATCH v3 5/6] mtd: dataflash: Make use of "extened device information"
Quoted 159 lines · Andrey Smirnov
Quoted 158 lines · Marek Vasut
Quoted 143 lines · Andrey Smirnov
In anticipation of supporting chips that need it, extend the size of struct flash_info's '
jedec_id' field to make room 2 byte of extended device information as well as add code to fetch this data duringjedec_probe().Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
Changes since [v2]:
- Make 'id' have same size as 'jedec'
- Get rid of
eid_maskvariable in favour of using GENMASK in-placeChanges since [v1]:
- Formatting
[v1] http://lkml.kernel.org/r/[email protected]
[v2] http://lkml.kernel.org/r/[email protected]drivers/mtd/devices/mtd_dataflash.c | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-)drivers/mtd/devices/mtd_dataflash.c +31
-46@@ -687,7 +687,7 @@ struct flash_info {/* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ -u32 jedec_id; +u64 jedec_id;/* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages;@@ -710,62 +710,34 @@ static struct flash_info dataflash_data[] = {* These newer chips also support 128-byte security registers (with * 64 bytes one-time-programmable) and software write-protection. */ - { "AT45DB011B", 0x1f2200, 512, 264, 9, SUP_POW2PS}, - { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB011B", 0x1f22000000, 512, 264, 9, SUP_POW2PS}, + { "at45db011d", 0x1f22000000, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB021B", 0x1f2300, 1024, 264, 9, SUP_POW2PS}, - { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB021B", 0x1f23000000, 1024, 264, 9, SUP_POW2PS}, + { "at45db021d", 0x1f23000000, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB041x", 0x1f2400, 2048, 264, 9, SUP_POW2PS}, - { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB041x", 0x1f24000000, 2048, 264, 9, SUP_POW2PS}, + { "at45db041d", 0x1f24000000, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB081B", 0x1f2500, 4096, 264, 9, SUP_POW2PS}, - { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB081B", 0x1f25000000, 4096, 264, 9, SUP_POW2PS}, + { "at45db081d", 0x1f25000000, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB161x", 0x1f2600, 4096, 528, 10, SUP_POW2PS}, - { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB161x", 0x1f26000000, 4096, 528, 10, SUP_POW2PS}, + { "at45db161d", 0x1f26000000, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB321x", 0x1f2700, 8192, 528, 10, 0}, /* rev C */ + { "AT45DB321x", 0x1f27000000, 8192, 528, 10, 0}, /* rev C */ - { "AT45DB321x", 0x1f2701, 8192, 528, 10, SUP_POW2PS}, - { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB321x", 0x1f27010000, 8192, 528, 10, SUP_POW2PS}, + { "at45db321d", 0x1f27010000, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB642x", 0x1f2800, 8192, 1056, 11, SUP_POW2PS}, - { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, + { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe (struct spi_device *spi) +static struct flash_info *jedec_lookup (struct spi_device *spi,u64 jedec) { -int ret; -u8 code =OP_READ_ID ; -u8 id[3 ]; -u32 jedec; -struct flash_info *info;int status; - -/* -* JEDEC also defines an optional "extended device information" -* string for after vendor-specific data, after the three bytes -* we use here. Supporting some chips might require using it. -* -* If the vendor ID isn't Atmel's (0x1f), assume this call failed. -* That's not an error; only rev C and newer chips handle it, and -* only Atmel sells these chips. -*/ - ret =spi_write_then_read (spi, &code,1 , id,3 ); -if (ret <0 ) { -dev_dbg (&spi->dev,"error %d reading JEDEC ID\n" , ret); -return ERR_PTR (ret); - } - -if (id[0 ] !=CFI_MFR_ATMEL ) -return NULL ; - - jedec = id[0 ]; - jedec = jedec <<8 ; - jedec |= id[1 ]; - jedec = jedec <<8 ; - jedec |= id[2 ]; +struct flash_info *info; for (info = dataflash_data; info < dataflash_data + ARRAY_SIZE(dataflash_data);@@ -793,12 +765,61 @@ static struct flash_info *jedec_probe(struct spi_device *spi) } } +return NULL ; +} + +static struct flash_info *jedec_probe (struct spi_device *spi) +{ +int ret; +u8 code =OP_READ_ID ; +u64 jedec; +u8 id[sizeof (jedec)] = {0 }; +const unsigned int id_size =5 ; +const unsigned int first_byte =sizeof (id) - id_size; +struct flash_info *info; +drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 790
Quoted 10 lines
drivers/mtd/devices/mtd_dataflash.c +10
-0+/* +* JEDEC also defines an optional "extended device information" +* string for after vendor-specific data, after the three bytes +* we use here. Supporting some chips might require using it. +* +* If the vendor ID isn't Atmel's (0x1f), assume this call failed. +* That's not an error; only rev C and newer chips handle it, and +* only Atmel sells these chips. +*/ + ret =spi_write_then_read (spi, &code,1 , &id[first_byte], id_size);Hm, looking at this again, what prevents you from reading these bytes into &id[0] ? Might be easier, ie.
Quoted 5 lines
Quoted 2 lines
ret =
spi_write_then_read(spi, &code, 1, id, id_size);Then I'd have to add 6 more '0's to each of the IDs in
dataflash_data, which would make that code even less readable.
Or do >>= 24 on the jedec ID :)
Quoted 41 lines
Quoted 33 lines
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 797
Quoted 7 lines
drivers/mtd/devices/mtd_dataflash.c +7
-0+if (ret <0 ) { +pr_debug ("%s: error %d reading JEDEC ID\n" , +dev_name (&spi->dev), ret); +return ERR_PTR (ret); + } + +if (id[first_byte] !=CFI_MFR_ATMEL )if (id[0] !=
CFI_MFR_ATMEL)drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 802
Quoted 5 lines
drivers/mtd/devices/mtd_dataflash.c +5
-0+return NULL ; + + jedec =be64_to_cpup ((__be64 *)id); + + info =jedec_lookup (spi, jedec);... define these somewhere at the beginning of the dataflash code ...
#defineDATAFLASH_MASK_STDGENMASK(63, 40)
#defineDATAFLASH_MASK_EXTGENMASK(63, 16)... then ...
info =jedec_lookup(spi, jedec & DATAFLASH_MASK_EXT);drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 811
Quoted 9 lines
drivers/mtd/devices/mtd_dataflash.c +9
-0+if (info) +return info; + +/* +* Clear extended id bits (bits 0 through 15) and try to find +* a match again in case our chip does not support returning +* extended ID information and we got invalid bits instead +*/ + jedec &=GENMASK_ULL (63 ,16 );Quoted 2 lines
info =
jedec_lookup(spi, jedec & DATAFLASH_MASK_STD);Sure, OK.
Thanks,
Andrey Smirnov
Signature · 2 lines
Best regards, Marek Vasut
Re: [PATCH v3 5/6] mtd: dataflash: Make use of "extened device information"
Quoted 160 lines · Marek Vasut
Quoted 159 lines · Andrey Smirnov
Quoted 158 lines · Marek Vasut
Quoted 143 lines · Andrey Smirnov
In anticipation of supporting chips that need it, extend the size of struct flash_info's '
jedec_id' field to make room 2 byte of extended device information as well as add code to fetch this data duringjedec_probe().Cc David Woodhouse <[email protected]>Cc Brian Norris <[email protected]>Cc Boris Brezillon <[email protected]>Cc Marek Vasut <[email protected]>Cc Richard Weinberger <[email protected]>Cc Cyrille Pitchen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>---
Changes since [v2]:
- Make 'id' have same size as 'jedec'
- Get rid of
eid_maskvariable in favour of using GENMASK in-placeChanges since [v1]:
- Formatting
[v1] http://lkml.kernel.org/r/[email protected]
[v2] http://lkml.kernel.org/r/[email protected]drivers/mtd/devices/mtd_dataflash.c | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-)drivers/mtd/devices/mtd_dataflash.c +31
-46@@ -687,7 +687,7 @@ struct flash_info {/* JEDEC id has a high byte of zero plus three data bytes: * the manufacturer id, then a two byte device id. */ -u32 jedec_id; +u64 jedec_id;/* The size listed here is what works with OP_ERASE_PAGE. */ unsigned nr_pages;@@ -710,62 +710,34 @@ static struct flash_info dataflash_data[] = {* These newer chips also support 128-byte security registers (with * 64 bytes one-time-programmable) and software write-protection. */ - { "AT45DB011B", 0x1f2200, 512, 264, 9, SUP_POW2PS}, - { "at45db011d", 0x1f2200, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB011B", 0x1f22000000, 512, 264, 9, SUP_POW2PS}, + { "at45db011d", 0x1f22000000, 512, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB021B", 0x1f2300, 1024, 264, 9, SUP_POW2PS}, - { "at45db021d", 0x1f2300, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB021B", 0x1f23000000, 1024, 264, 9, SUP_POW2PS}, + { "at45db021d", 0x1f23000000, 1024, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB041x", 0x1f2400, 2048, 264, 9, SUP_POW2PS}, - { "at45db041d", 0x1f2400, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB041x", 0x1f24000000, 2048, 264, 9, SUP_POW2PS}, + { "at45db041d", 0x1f24000000, 2048, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB081B", 0x1f2500, 4096, 264, 9, SUP_POW2PS}, - { "at45db081d", 0x1f2500, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, + { "AT45DB081B", 0x1f25000000, 4096, 264, 9, SUP_POW2PS}, + { "at45db081d", 0x1f25000000, 4096, 256, 8, SUP_POW2PS | IS_POW2PS}, - { "AT45DB161x", 0x1f2600, 4096, 528, 10, SUP_POW2PS}, - { "at45db161d", 0x1f2600, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB161x", 0x1f26000000, 4096, 528, 10, SUP_POW2PS}, + { "at45db161d", 0x1f26000000, 4096, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB321x", 0x1f2700, 8192, 528, 10, 0}, /* rev C */ + { "AT45DB321x", 0x1f27000000, 8192, 528, 10, 0}, /* rev C */ - { "AT45DB321x", 0x1f2701, 8192, 528, 10, SUP_POW2PS}, - { "at45db321d", 0x1f2701, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, + { "AT45DB321x", 0x1f27010000, 8192, 528, 10, SUP_POW2PS}, + { "at45db321d", 0x1f27010000, 8192, 512, 9, SUP_POW2PS | IS_POW2PS}, - { "AT45DB642x", 0x1f2800, 8192, 1056, 11, SUP_POW2PS}, - { "at45db642d", 0x1f2800, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, + { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, }; -static struct flash_info *jedec_probe (struct spi_device *spi) +static struct flash_info *jedec_lookup (struct spi_device *spi,u64 jedec) { -int ret; -u8 code =OP_READ_ID ; -u8 id[3 ]; -u32 jedec; -struct flash_info *info;int status; - -/* -* JEDEC also defines an optional "extended device information" -* string for after vendor-specific data, after the three bytes -* we use here. Supporting some chips might require using it. -* -* If the vendor ID isn't Atmel's (0x1f), assume this call failed. -* That's not an error; only rev C and newer chips handle it, and -* only Atmel sells these chips. -*/ - ret =spi_write_then_read (spi, &code,1 , id,3 ); -if (ret <0 ) { -dev_dbg (&spi->dev,"error %d reading JEDEC ID\n" , ret); -return ERR_PTR (ret); - } - -if (id[0 ] !=CFI_MFR_ATMEL ) -return NULL ; - - jedec = id[0 ]; - jedec = jedec <<8 ; - jedec |= id[1 ]; - jedec = jedec <<8 ; - jedec |= id[2 ]; +struct flash_info *info; for (info = dataflash_data; info < dataflash_data + ARRAY_SIZE(dataflash_data);@@ -793,12 +765,61 @@ static struct flash_info *jedec_probe(struct spi_device *spi) } } +return NULL ; +} + +static struct flash_info *jedec_probe (struct spi_device *spi) +{ +int ret; +u8 code =OP_READ_ID ; +u64 jedec; +u8 id[sizeof (jedec)] = {0 }; +const unsigned int id_size =5 ; +const unsigned int first_byte =sizeof (id) - id_size; +struct flash_info *info; +drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 790
Quoted 10 lines
drivers/mtd/devices/mtd_dataflash.c +10
-0+/* +* JEDEC also defines an optional "extended device information" +* string for after vendor-specific data, after the three bytes +* we use here. Supporting some chips might require using it. +* +* If the vendor ID isn't Atmel's (0x1f), assume this call failed. +* That's not an error; only rev C and newer chips handle it, and +* only Atmel sells these chips. +*/ + ret =spi_write_then_read (spi, &code,1 , &id[first_byte], id_size);Hm, looking at this again, what prevents you from reading these bytes into &id[0] ? Might be easier, ie.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
ret =
spi_write_then_read(spi, &code, 1, id, id_size);Then I'd have to add 6 more '0's to each of the IDs in
dataflash_data, which would make that code even less readable.Or do >>= 24 on the jedec ID :)
In fact, you can use the flags field to introduce a flag to indicate that the flash uses ext ID . Then the lookup function can do first try the ext IDs (with correct shift) and then standard IDs (with correct bitshift again).
Upside is, you don't need to patch the table above at all, you just add your new flash with another flag , ie. SUP_EXTID .
Quoted 43 lines
Quoted 41 lines
Quoted 33 lines
drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 797
Quoted 7 lines
drivers/mtd/devices/mtd_dataflash.c +7
-0+if (ret <0 ) { +pr_debug ("%s: error %d reading JEDEC ID\n" , +dev_name (&spi->dev), ret); +return ERR_PTR (ret); + } + +if (id[first_byte] !=CFI_MFR_ATMEL )if (id[0] !=
CFI_MFR_ATMEL)drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 802
Quoted 5 lines
drivers/mtd/devices/mtd_dataflash.c +5
-0+return NULL ; + + jedec =be64_to_cpup ((__be64 *)id); + + info =jedec_lookup (spi, jedec);... define these somewhere at the beginning of the dataflash code ...
#defineDATAFLASH_MASK_STDGENMASK(63, 40)
#defineDATAFLASH_MASK_EXTGENMASK(63, 16)... then ...
info =jedec_lookup(spi, jedec & DATAFLASH_MASK_EXT);drivers/mtd/devices/mtd_dataflash.c static struct flash_info *jedec_probe(struct spi_device *spi) · line 811
Quoted 9 lines
drivers/mtd/devices/mtd_dataflash.c +9
-0+if (info) +return info; + +/* +* Clear extended id bits (bits 0 through 15) and try to find +* a match again in case our chip does not support returning +* extended ID information and we got invalid bits instead +*/ + jedec &=GENMASK_ULL (63 ,16 );Quoted 2 lines
info =
jedec_lookup(spi, jedec & DATAFLASH_MASK_STD);Sure, OK.
Thanks,
Andrey Smirnov
Signature · 2 lines
Best regards, Marek Vasut
PATCH v3 6/6 mtd: dataflash: Add flash_info for AT45DB641E
In reply to Andrey Smirnov---
No changes between v3 through v1.
drivers/mtd/devices/mtd_dataflash.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/devices/mtd_dataflash.c +3 -0
@@ -732,6 +732,9 @@ static struct flash_info dataflash_data[] = { { "AT45DB642x", 0x1f28000000, 8192, 1056, 11, SUP_POW2PS}, { "at45db642d", 0x1f28000000, 8192, 1024, 10, SUP_POW2PS | IS_POW2PS}, + + { "AT45DB641E", 0x1f28000100, 32768, 264, 9, SUP_POW2PS}, + { "at45db641e", 0x1f28000100, 32768, 256, 8, SUP_POW2PS | IS_POW2PS}, };static struct flash_info *jedec_lookup (struct spi_device *spi,u64 jedec)
Signature · 1 line
2.9.3
Quoted 1 line · Andrey Smirnov
No functional change intended.
FWIW I *deliberately* used the proper C datatypes throughout all of the MTD code instead of the silly kernel-speshul datatypes. To the extent of *fixing* submissions to be written in C when they were using the silly kernel types instead.
There is a reason for the __u32 type in userspace APIs. There is basically no reason for 'u32' et al, just to save a trivial few characters in the type name. We might as well be using the proper language types.
I appreciate that not everyone agrees with that, but at least it used to be consistent throughout the code I was maintaining. I'll defer to the currently active maintainers though...
[ +cc: Marek, since I accidentally dropped him off CC list ]
Quoted 8 lines · David Woodhouse
Quoted 1 line · Andrey Smirnov
No functional change intended.
FWIW I *deliberately* used the proper C datatypes throughout all of the MTD code instead of the silly kernel-speshul datatypes. To the extent of *fixing* submissions to be written in C when they were using the silly kernel types instead.
Quoted 8 lines
There is a reason for the
__u32type in userspace APIs. There is basically no reason for 'u32' et al, just to save a trivial few characters in the type name. We might as well be using the proper language types.I appreciate that not everyone agrees with that, but at least it used to be consistent throughout the code I was maintaining. I'll defer to the currently active maintainers though...
This conversion was an explicit request from Marek, see
https://marc.info/?l=linux-kernel&m=149192751625941
Thanks,
Andrey Smirnov