sf: Add bank address register writing support
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v5 1/14 sf: Add bank address register writing support
This patch provides support to program a flash bank address register.
extended/bank address register contains an information to access the 4th byte addressing in 3-byte address mode.
reff' the spec for more details about bank addr register in Page-63, Table 8.16
http://www.spansion.com/Support/Datasheets/S25FL128S_256S_00.pdf
---
Changes for v5:
- none
Changes for v4:
- remove bank cmds
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 26 ++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 3 +++ 2 files changed, 29 insertions(+)
drivers/mtd/spi/spi_flash.c +26 -0
@@ -278,6 +278,32 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)return 0 ; } +int spi_flash_cmd_bankaddr_write (struct spi_flash *flash,u8 bank_sel) +{ +u8 cmd; +int ret; + + ret =spi_flash_cmd_write_enable (flash); +if (ret <0 ) { +debug ("SF: enabling write failed\n" ); +return ret; + } + + ret =spi_flash_cmd_write (flash->spi, &cmd,1 , &bank_sel,1 ); +if (ret) { +debug ("SF: fail to write bank addr register\n" ); +return ret; + } + + ret =spi_flash_cmd_wait_ready (flash,SPI_FLASH_PROG_TIMEOUT ); +if (ret <0 ) { +debug ("SF: write bank addr register timed out\n" ); +return ret; + } + +return 0 ; +} +#ifdef CONFIG_OF_CONTROL int spi_flash_decode_fdt (const void *blob,struct spi_flash *flash) {
drivers/mtd/spi/spi_flash_internal.h +3 -0
@@ -77,6 +77,9 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)/* Program the status register. */ int spi_flash_cmd_write_status (struct spi_flash *flash,u8 sr); +/* Program the bank address register */ +int spi_flash_cmd_bankaddr_write (struct spi_flash *flash,u8 bank_sel); +/* * Same as spi_flash_cmd_read() except it also claims/releases the SPI * bus. Used as common part of the ->read() operation.
Signature · 1 line
1.8.3
PATCH v5 2/14 sf: Discover the bank addr commands
In reply to a message not in the archiveBank/Extended addr commands are specific to particular flash vendor so discover them based on the idocode0.
Assign the discovered bank commands to spi_flash members so-that the bank read/write will use their specific operations.
---
Changes for v5:
- bank_read_cmd <= bank_cmd[0]
- bank_write_cmd <= bank_cmd[1]
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 21 +++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 14 ++++++++++++++ include/spi_flash.h | 4 ++++ 3 files changed, 39 insertions(+)
drivers/mtd/spi/spi_flash.c +21 -0
@@ -304,6 +304,27 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)return 0 ; } +int spi_flash_bank_config (struct spi_flash *flash,u8 idcode0) +{ +/* discover bank cmds */ +switch (idcode0) { +case SPI_FLASH_SPANSION_IDCODE0 : + flash->bank_read_cmd =CMD_BANKADDR_BRRD ; + flash->bank_write_cmd =CMD_BANKADDR_BRWR ; +break ; +case SPI_FLASH_STMICRO_IDCODE0 : +case SPI_FLASH_WINBOND_IDCODE0 : + flash->bank_read_cmd =CMD_EXTNADDR_RDEAR ; + flash->bank_write_cmd =CMD_EXTNADDR_WREAR ; +break ; +default : +printf ("SF: Unsupported bank commands %02x\n" , idcode0); +return -1 ; + } + +return 0 ; +} +#ifdef CONFIG_OF_CONTROL int spi_flash_decode_fdt (const void *blob,struct spi_flash *flash) {
drivers/mtd/spi/spi_flash_internal.h +14 -0
@@ -28,6 +28,17 @@#define CMD_ERASE_64K 0xd8#define CMD_ERASE_CHIP 0xc7 +/* Manufacture ID's */ +#define SPI_FLASH_SPANSION_IDCODE0 0x01 +#define SPI_FLASH_STMICRO_IDCODE0 0x20 +#define SPI_FLASH_WINBOND_IDCODE0 0xef + +/* Bank addr access commands */ +#define CMD_BANKADDR_BRWR 0x17 +#define CMD_BANKADDR_BRRD 0x16 +#define CMD_EXTNADDR_WREAR 0xC5 +#define CMD_EXTNADDR_RDEAR 0xC8 +/* Common status */ #define STATUS_WIP 0x01
@@ -80,6 +91,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);/* Program the bank address register */ int spi_flash_cmd_bankaddr_write (struct spi_flash *flash,u8 bank_sel); +/* Configure the BAR - discover the bank cmds */ +int spi_flash_bank_config (struct spi_flash *flash,u8 idcode0); +/* * Same as spi_flash_cmd_read() except it also claims/releases the SPI * bus. Used as common part of the ->read() operation.
include/spi_flash.h +4 -0
@@ -38,6 +38,10 @@ struct spi_flash {u32 page_size;/* Erase (sector) size */ u32 sector_size; +/* Bank read cmd */ +u8 bank_read_cmd; +/* Bank write cmd */ +u8 bank_write_cmd;void *memory_map;/* Address of read-only SPI flash access */ int (*read)(struct spi_flash *flash, u32 offset,
Signature · 1 line
1.8.3
PATCH v5 3/14 sf: Read flash bank addr register at probe time
In reply to a message not in the archiveRead the flash bank addr register to get the state of bank in a perticular flash. and also bank write happens only when there is a change in bank selection from user.
bank read only valid for flashes which has > 16Mbytes those are opearted in 3-byte addr mode, each bank occupies 16Mytes.
Suppose if the flash has 64Mbytes size consists of 4 banks like bank0, bank1, bank2 and bank3.
---
Changes for v5:
- bank_read_cmd <= bank_cmd[0]
- bank_write_cmd <= bank_cmd[1]
Changes for v4:
- Added spi_flash_bank_config
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 27 +++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 2 ++ include/spi_flash.h | 2 ++ 3 files changed, 31 insertions(+)
drivers/mtd/spi/spi_flash.c +27 -0
@@ -283,6 +283,12 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)u8 cmd;int ret; +if (flash->bank_curr == bank_sel) { +debug ("SF: not require to enable bank%d\n" , bank_sel); +return 0 ; + } + + cmd = flash->bank_write_cmd; ret =spi_flash_cmd_write_enable (flash);if (ret <0 ) {debug ("SF: enabling write failed\n" );
@@ -294,6 +300,7 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)debug ("SF: fail to write bank addr register\n" );return ret; } + flash->bank_curr = bank_sel; ret =spi_flash_cmd_wait_ready (flash,SPI_FLASH_PROG_TIMEOUT );if (ret <0 ) {
@@ -306,6 +313,9 @@ int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel)int spi_flash_bank_config (struct spi_flash *flash,u8 idcode0) { +u8 cmd; +u8 curr_bank =0 ; +/* discover bank cmds */ switch (idcode0) {case SPI_FLASH_SPANSION_IDCODE0 :
@@ -322,6 +332,18 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0)return -1 ; } +/* read the bank reg - on which bank the flash is in currently */ + cmd = flash->bank_read_cmd; +if (flash->size >SPI_FLASH_16MB_BOUN ) { +if (spi_flash_read_common (flash, &cmd,1 , &curr_bank,1 )) { +debug ("SF: fail to read bank addr register\n" ); +return -1 ; + } + flash->bank_curr = curr_bank; + }else { + flash->bank_curr = curr_bank; + } +return 0 ; }
@@ -469,6 +491,11 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, goto err_manufacturer_probe; } +/* Configure the BAR - disover bank cmds and read current bank */ + ret =spi_flash_bank_config (flash, *idp); +if (ret <0 ) + goto err_manufacturer_probe; +#ifdef CONFIG_OF_CONTROL if (spi_flash_decode_fdt (gd->fdt_blob, flash)) {debug ("SF: FDT decode error\n" );
drivers/mtd/spi/spi_flash_internal.h +2 -0
@@ -28,6 +28,8 @@#define CMD_ERASE_64K 0xd8#define CMD_ERASE_CHIP 0xc7 +#define SPI_FLASH_16MB_BOUN 0x1000000 +/* Manufacture ID's */ #define SPI_FLASH_SPANSION_IDCODE0 0x01#define SPI_FLASH_STMICRO_IDCODE0 0x20
include/spi_flash.h +2 -0
@@ -42,6 +42,8 @@ struct spi_flash {u8 bank_read_cmd;/* Bank write cmd */ u8 bank_write_cmd; +/* Current flash bank */ +u8 bank_curr;void *memory_map;/* Address of read-only SPI flash access */ int (*read)(struct spi_flash *flash, u32 offset,
Signature · 1 line
1.8.3
PATCH v5 4/14 sf: Update sf to support all sizes of flashes
In reply to a message not in the archiveUpdated the spi_flash framework to handle all sizes of flashes using bank/extd addr reg facility
The current implementation in spi_flash supports 3-byte address mode due to this up to 16Mbytes amount of flash is able to access for those flashes which has an actual size of > 16MB.
As most of the flashes introduces a bank/extd address registers for accessing the flashes in 16Mbytes of banks if the flash size is > 16Mbytes, this new scheme will add the bank selection feature for performing write/erase operations on all flashes.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
drivers/mtd/spi/spi_flash.c +26 -13
@@ -74,11 +74,9 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,unsigned long page_addr, byte_addr, page_size;size_t chunk_len, actual;int ret; -u8 cmd[4 ]; +u8 cmd[4 ], bank_sel; page_size = flash->page_size; - page_addr = offset / page_size; - byte_addr = offset % page_size; ret =spi_claim_bus (flash->spi);if (ret) {
@@ -88,6 +86,16 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, cmd[0 ] =CMD_PAGE_PROGRAM ;for (actual =0 ; actual < len; actual += chunk_len) { + bank_sel = offset /SPI_FLASH_16MB_BOUN ; + + ret =spi_flash_cmd_bankaddr_write (flash, bank_sel); +if (ret) { +debug ("SF: fail to set bank%d\n" , bank_sel); +return ret; + } + + page_addr = offset / page_size; + byte_addr = offset % page_size; chunk_len =min (len - actual, page_size - byte_addr);if (flash->spi->max_write_size)
@@ -117,11 +125,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,if (ret)break ; - byte_addr += chunk_len; -if (byte_addr == page_size) { - page_addr++; - byte_addr =0 ; - } + offset += chunk_len; }spi_release_bus (flash->spi);
@@ -204,9 +208,9 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)int spi_flash_cmd_erase (struct spi_flash *flash,u32 offset,size_t len) { -u32 end, erase_size; +u32 erase_size;int ret; -u8 cmd[4 ]; +u8 cmd[4 ], bank_sel; erase_size = flash->sector_size;if (offset % erase_size || len % erase_size) {
@@ -224,11 +228,17 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len) cmd[0 ] =CMD_ERASE_4K ; else cmd[0 ] =CMD_ERASE_64K ; - end = offset + len; -while (offset < end) { +while (len) { + bank_sel = offset /SPI_FLASH_16MB_BOUN ; + + ret =spi_flash_cmd_bankaddr_write (flash, bank_sel); +if (ret) { +debug ("SF: fail to set bank%d\n" , bank_sel); +return ret; + } +spi_flash_addr (offset, cmd); - offset += erase_size;debug ("SF: erase %2x %2x %2x %2x (%x)\n" , cmd[0 ], cmd[1 ], cmd[2 ], cmd[3 ], offset);
@@ -244,6 +254,9 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len) ret =spi_flash_cmd_wait_ready (flash,SPI_FLASH_PAGE_ERASE_TIMEOUT );if (ret) goto out; + + offset += erase_size; + len -= erase_size; } out:
Signature · 1 line
1.8.3
PATCH v5 5/14 sf: Update sf read to support all sizes of flashes
In reply to a message not in the archiveThis patch updated the spi_flash read func to support all sizes of flashes using bank reg addr facility.
The same support has been added in below patch for erase/write spi_flash functions:
"sf: Support all sizes of flashes using bank addr reg facility" (sha1: c956f600cbb0943d0afe1004cdb503f4fcd8f415)
With these new updates on sf framework, the flashes which has < 16MB are not effected as per as performance is concern and but the u-boot.bin size incrased ~460 bytes.
sf update(for first 16MBytes), Changes before:
U-Boot> sf update 0x1000000 0x0 0x1000000
- N25Q256
16777216 bytes written, 0 bytes skipped in 199.72s, speed 86480 B/s
- W25Q128BV
16777216 bytes written, 0 bytes skipped in 351.739s, speed 48913 B/s
- S25FL256S_64K
16777216 bytes written, 0 bytes skipped in 65.659s, speed 262144 B/s
sf update(for first 16MBytes), Changes before:
U-Boot> sf update 0x1000000 0x0 0x1000000
- N25Q256
16777216 bytes written, 0 bytes skipped in 198.953s, speed 86480 B/s
- W25Q128BV
16777216 bytes written, 0 bytes skipped in 350.90s, speed 49200 B/s
- S25FL256S_64K
16777216 bytes written, 0 bytes skipped in 66.521s, speed 262144 B/s
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi_flash.c +33 -3
@@ -148,7 +148,9 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,int spi_flash_cmd_read_fast (struct spi_flash *flash,u32 offset,size_t len,void *data) { -u8 cmd[5 ]; +u8 cmd[5 ], bank_sel; +u32 remain_len, read_len; +int ret =-1 ;/* Handle memory-mapped SPI */ if (flash->memory_map) {
@@ -157,10 +159,38 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, } cmd[0 ] =CMD_READ_ARRAY_FAST ; -spi_flash_addr (offset, cmd); cmd[4 ] =0x00 ; -return spi_flash_read_common (flash, cmd,sizeof (cmd), data, len); +while (len) { + bank_sel = offset /SPI_FLASH_16MB_BOUN ; + + ret =spi_flash_cmd_bankaddr_write (flash, bank_sel); +if (ret) { +debug ("SF: fail to set bank%d\n" , bank_sel); +return ret; + } + + remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel +1 ) - offset); +if (len < remain_len) + read_len = len; +else + read_len = remain_len; + +spi_flash_addr (offset, cmd); + + ret =spi_flash_read_common (flash, cmd,sizeof (cmd), + data, read_len); +if (ret <0 ) { +debug ("SF: read failed\n" ); +break ; + } + + offset += read_len; + len -= read_len; + data += read_len; + } + +return ret; } int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
Signature · 1 line
1.8.3
PATCH v5 6/14 sf: Add bank addr code in CONFIG_SPI_FLASH_BAR
In reply to a message not in the archiveDefined bank addr code on CONFIG_SPI_FLASH_BAR macro, to reduce the size for existing boards which has < 16Mbytes SPI flashes.
It's upto user which has provision to use the bank addr code for flashes which has > 16Mbytes.
---
Changes for v5:
- none
Changes for v4:
- rebase of 02/14
Changes for v3:
- none
Changes for v2:
- none
README | 5 +++++ drivers/mtd/spi/spi_flash.c | 23 +++++++++++++++++------ drivers/mtd/spi/spi_flash_internal.h | 12 ++++++++---- include/spi_flash.h | 3 ++- 4 files changed, 32 insertions(+), 11 deletions(-)
README +5 -0
@@ -2509,6 +2509,11 @@ CBFS (Coreboot Filesystem) support Define this option to include a destructive SPI flash test ('sf test'). + CONFIG_SPI_FLASH_BAR Ban/Extended Addr Reg + + Define this option to use the Bank addr/Extended addr + support on SPI flashes which has size > 16Mbytes. + - SystemACE Support: CONFIG_SYSTEMACE
drivers/mtd/spi/spi_flash.c +17 -6
@@ -74,7 +74,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,unsigned long page_addr, byte_addr, page_size;size_t chunk_len, actual;int ret; -u8 cmd[4 ], bank_sel; +u8 cmd[4 ]; page_size = flash->page_size;
@@ -86,6 +86,9 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, cmd[0 ] =CMD_PAGE_PROGRAM ;for (actual =0 ; actual < len; actual += chunk_len) { +#ifdef CONFIG_SPI_FLASH_BAR +u8 bank_sel; + bank_sel = offset /SPI_FLASH_16MB_BOUN ; ret =spi_flash_cmd_bankaddr_write (flash, bank_sel);
@@ -93,7 +96,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,debug ("SF: fail to set bank%d\n" , bank_sel); return ret; } - +#endif page_addr = offset / page_size; byte_addr = offset % page_size; chunk_len =min (len - actual, page_size - byte_addr);
@@ -148,7 +151,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,int spi_flash_cmd_read_fast (struct spi_flash *flash,u32 offset,size_t len,void *data) { -u8 cmd[5 ], bank_sel; +u8 cmd[5 ], bank_sel =0 ;u32 remain_len, read_len;int ret =-1 ;
@@ -162,6 +165,7 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, cmd[4 ] =0x00 ;while (len) { +#ifdef CONFIG_SPI_FLASH_BAR bank_sel = offset /SPI_FLASH_16MB_BOUN ; ret =spi_flash_cmd_bankaddr_write (flash, bank_sel);
@@ -169,7 +173,7 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,debug ("SF: fail to set bank%d\n" , bank_sel); return ret; } - +#endif remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel +1 ) - offset);if (len < remain_len) read_len = len;
@@ -240,7 +244,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len) {u32 erase_size;int ret; -u8 cmd[4 ], bank_sel; +u8 cmd[4 ]; erase_size = flash->sector_size;if (offset % erase_size || len % erase_size) {
@@ -260,6 +264,9 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len) cmd[0 ] =CMD_ERASE_64K ;while (len) { +#ifdef CONFIG_SPI_FLASH_BAR +u8 bank_sel; + bank_sel = offset /SPI_FLASH_16MB_BOUN ; ret =spi_flash_cmd_bankaddr_write (flash, bank_sel);
@@ -267,7 +274,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)debug ("SF: fail to set bank%d\n" , bank_sel);return ret; } - +#endif spi_flash_addr (offset, cmd); debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
@@ -321,6 +328,7 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)return 0 ; } +#ifdef CONFIG_SPI_FLASH_BAR int spi_flash_cmd_bankaddr_write (struct spi_flash *flash,u8 bank_sel) {u8 cmd;
@@ -389,6 +397,7 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0) return 0; } +#endif #ifdef CONFIG_OF_CONTROL int spi_flash_decode_fdt (const void *blob,struct spi_flash *flash)
@@ -534,10 +543,12 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, goto err_manufacturer_probe; } +#ifdef CONFIG_SPI_FLASH_BAR /* Configure the BAR - disover bank cmds and read current bank */ ret =spi_flash_bank_config (flash, *idp);if (ret <0 ) goto err_manufacturer_probe; +#endif #ifdef CONFIG_OF_CONTROL if (spi_flash_decode_fdt (gd->fdt_blob, flash)) {
drivers/mtd/spi/spi_flash_internal.h +8 -4
@@ -35,11 +35,13 @@#define SPI_FLASH_STMICRO_IDCODE0 0x20#define SPI_FLASH_WINBOND_IDCODE0 0xef +#ifdef CONFIG_SPI_FLASH_BAR /* Bank addr access commands */ -#define CMD_BANKADDR_BRWR 0x17 -#define CMD_BANKADDR_BRRD 0x16 -#define CMD_EXTNADDR_WREAR 0xC5 -#define CMD_EXTNADDR_RDEAR 0xC8 +# define CMD_BANKADDR_BRWR 0x17 +# define CMD_BANKADDR_BRRD 0x16 +# define CMD_EXTNADDR_WREAR 0xC5 +# define CMD_EXTNADDR_RDEAR 0xC8 +#endif /* Common status */ #define STATUS_WIP 0x01
@@ -90,11 +92,13 @@ static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)/* Program the status register. */ int spi_flash_cmd_write_status (struct spi_flash *flash,u8 sr); +#ifdef CONFIG_SPI_FLASH_BAR /* Program the bank address register */ int spi_flash_cmd_bankaddr_write (struct spi_flash *flash,u8 bank_sel);/* Configure the BAR - discover the bank cmds */ int spi_flash_bank_config (struct spi_flash *flash,u8 idcode0); +#endif /* * Same as spi_flash_cmd_read() except it also claims/releases the SPI
include/spi_flash.h +2 -1
@@ -38,13 +38,14 @@ struct spi_flash {u32 page_size;/* Erase (sector) size */ u32 sector_size; +#ifdef CONFIG_SPI_FLASH_BAR /* Bank read cmd */ u8 bank_read_cmd;/* Bank write cmd */ u8 bank_write_cmd;/* Current flash bank */ u8 bank_curr; - +#endif void *memory_map;/* Address of read-only SPI flash access */ int (*read)(struct spi_flash *flash,u32 offset,size_t len,void *buf);
Signature · 1 line
1.8.3
PATCH v5 7/14 sf: Use spi_flash_addr() in write call
In reply to a message not in the archiveUse the existing spi_flash_addr() for 3-byte addressing cmd filling in write call.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/mtd/spi/spi_flash.c +2 -5
@@ -71,7 +71,7 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,int spi_flash_cmd_write_multi (struct spi_flash *flash,u32 offset,size_t len,const void *buf) { -unsigned long page_addr, byte_addr, page_size; +unsigned long byte_addr, page_size;size_t chunk_len, actual;int ret;u8 cmd[4 ];
@@ -97,16 +97,13 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, return ret; }#endif - page_addr = offset / page_size; byte_addr = offset % page_size; chunk_len =min (len - actual, page_size - byte_addr);if (flash->spi->max_write_size) chunk_len =min (chunk_len, flash->spi->max_write_size); - cmd[1 ] = page_addr >>8 ; - cmd[2 ] = page_addr; - cmd[3 ] = byte_addr; +spi_flash_addr (offset, cmd);debug ("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n" , buf + actual, cmd[0 ], cmd[1 ], cmd[2 ], cmd[3 ], chunk_len);
Signature · 1 line
1.8.3
PATCH v5 8/14 sf: stmicro: Add support for N25Q512
In reply to a message not in the archiveAdd support for Numonyx N25Q512 SPI flash.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/stmicro.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
@@ -140,6 +140,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { .nr_sectors = 512, .name = "N25Q256A", }, + { + .id = 0xba20, + .pages_per_sector = 256, + .nr_sectors = 1024, + .name = "N25Q512", + }, };struct spi_flash *spi_flash_probe_stmicro (struct spi_slave *spi,u8 * idcode)
Signature · 1 line
1.8.3
PATCH v5 9/14 sf: stmicro: Add support for N25Q512A
In reply to a message not in the archiveAdd support for Numonyx N25Q512A SPI flash.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/stmicro.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
@@ -146,6 +146,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { .nr_sectors = 1024, .name = "N25Q512", }, + { + .id = 0xbb20, + .pages_per_sector = 256, + .nr_sectors = 1024, + .name = "N25Q512A", + }, };struct spi_flash *spi_flash_probe_stmicro (struct spi_slave *spi,u8 * idcode)
Signature · 1 line
1.8.3
PATCH v5 10/14 sf: stmicro: Add support for N25Q1024
In reply to a message not in the archiveAdd support for Numonyx N25Q1024 SPI flash.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/stmicro.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
@@ -152,6 +152,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { .nr_sectors = 1024, .name = "N25Q512A", }, + { + .id = 0xba21, + .pages_per_sector = 256, + .nr_sectors = 2048, + .name = "N25Q1024", + }, };struct spi_flash *spi_flash_probe_stmicro (struct spi_slave *spi,u8 * idcode)
Signature · 1 line
1.8.3
PATCH v5 11/14 sf: stmicro: Add support for N25Q1024A
In reply to a message not in the archiveAdd support for Numonyx N25Q1024A SPI flash.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/stmicro.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mtd/spi/stmicro.c +6 -0
@@ -158,6 +158,12 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { .nr_sectors = 2048, .name = "N25Q1024", }, + { + .id = 0xbb21, + .pages_per_sector = 256, + .nr_sectors = 2048, + .name = "N25Q1024A", + }, };struct spi_flash *spi_flash_probe_stmicro (struct spi_slave *spi,u8 * idcode)
Signature · 1 line
1.8.3
PATCH v5 12/14 sf: spansion: Add support for S25FL512S_64K
In reply to a message not in the archiveAdd support for Spansion S25FL512S_64K SPI flash.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spansion.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mtd/spi/spansion.c +7 -0
@@ -110,6 +110,13 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = { .nr_sectors = 512, .name = "S25FL256S_64K", }, + { + .idcode1 = 0x0220, + .idcode2 = 0x4d01, + .pages_per_sector = 256, + .nr_sectors = 1024, + .name = "S25FL512S_64K", + }, };struct spi_flash *spi_flash_probe_spansion (struct spi_slave *spi,u8 *idcode)
Signature · 1 line
1.8.3
PATCH v5 13/14 sf: Remove spi_flash_cmd_poll_bit()
In reply to a message not in the archiveThere is no other call other than spi_flash_cmd_wait_ready(), hence removed spi_flash_cmd_poll_bit and use the poll status code spi_flash_cmd_wait_ready() itself.
---
Changes for v5:
- none
Changes for v4:
- none
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 11 +++-------- drivers/mtd/spi/spi_flash_internal.h | 4 ---- 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/mtd/spi/spi_flash.c +3 -8
@@ -194,13 +194,14 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,return ret; } -int spi_flash_cmd_poll_bit (struct spi_flash *flash,unsigned long timeout, -u8 cmd,u8 poll_bit) +int spi_flash_cmd_wait_ready (struct spi_flash *flash,unsigned long timeout) {struct spi_slave *spi = flash->spi;unsigned long timebase;int ret;u8 status; +u8 poll_bit =STATUS_WIP ; +u8 cmd =CMD_READ_STATUS ; ret =spi_xfer (spi,8 , &cmd,NULL ,SPI_XFER_BEGIN );if (ret) {
@@ -231,12 +232,6 @@ int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,return -1 ; } -int spi_flash_cmd_wait_ready (struct spi_flash *flash,unsigned long timeout) -{ -return spi_flash_cmd_poll_bit (flash, timeout, -CMD_READ_STATUS ,STATUS_WIP ); -} -int spi_flash_cmd_erase (struct spi_flash *flash,u32 offset,size_t len) {u32 erase_size;
drivers/mtd/spi/spi_flash_internal.h +0 -4
@@ -107,10 +107,6 @@ int spi_flash_bank_config(struct spi_flash *flash, u8 idcode0);int spi_flash_read_common (struct spi_flash *flash,const u8 *cmd,size_t cmd_len,void *data,size_t data_len); -/* Send a command to the device and wait for some bit to clear itself. */ -int spi_flash_cmd_poll_bit (struct spi_flash *flash,unsigned long timeout, -u8 cmd,u8 poll_bit); -/* * Send the read status command to the device and wait for the wip * (write-in-progress) bit to clear itself.
Signature · 1 line
1.8.3
PATCH v5 14/14 sf: Add flag status register polling support
In reply to a message not in the archiveFlag status register polling is required for micron 512Mb flash devices onwards, for performing erase/program operations.
Like polling for WIP(Write-In-Progress) bit in read status register, spi_flash_cmd_wait_ready will poll for PEC(Program-Erase-Control) bit in flag status register.
---
Changes for v5:
- move flag_status assignment to stmicro driver
Changes for v4:
- Remove STMICRO config, discover poll_cmd at probe
Changes for v3:
- none
Changes for v2:
- none
drivers/mtd/spi/spi_flash.c | 16 ++++++++++++---- drivers/mtd/spi/spi_flash_internal.h | 2 ++ drivers/mtd/spi/stmicro.c | 4 ++++ include/spi_flash.h | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -4
@@ -200,12 +200,19 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)unsigned long timebase;int ret;u8 status; +u8 check_status =0x0 ;u8 poll_bit =STATUS_WIP ; -u8 cmd =CMD_READ_STATUS ; +u8 cmd = flash->poll_cmd; + +if (cmd ==CMD_FLAG_STATUS ) { + poll_bit =STATUS_PEC ; + check_status = poll_bit; + } ret =spi_xfer (spi,8 , &cmd,NULL ,SPI_XFER_BEGIN );if (ret) { -debug ("SF: Failed to send command %02x: %d\n" , cmd, ret); +debug ("SF: fail to read %s status register\n" , + cmd ==CMD_READ_STATUS ?"read" :"flag" );return ret; }
@@ -217,14 +224,14 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)if (ret)return -1 ; -if ((status & poll_bit) ==0 ) +if ((status & poll_bit) == check_status)break ; }while (get_timer (timebase) < timeout);spi_xfer (spi,0 ,NULL ,NULL ,SPI_XFER_END ); -if ((status & poll_bit) ==0 ) +if ((status & poll_bit) == check_status)return 0 ;/* Timed out */
@@ -584,6 +591,7 @@ void *spi_flash_do_alloc(int offset, int size, struct spi_slave *spi,/* Set up some basic fields - caller will sort out sizes */ flash->spi = spi; flash->name = name; + flash->poll_cmd =CMD_READ_STATUS ; flash->read = spi_flash_cmd_read_fast; flash->write = spi_flash_cmd_write_multi;
drivers/mtd/spi/spi_flash_internal.h +2 -0
@@ -22,6 +22,7 @@#define CMD_PAGE_PROGRAM 0x02#define CMD_WRITE_DISABLE 0x04#define CMD_READ_STATUS 0x05 +#define CMD_FLAG_STATUS 0x70#define CMD_WRITE_ENABLE 0x06#define CMD_ERASE_4K 0x20#define CMD_ERASE_32K 0x52
@@ -45,6 +46,7 @@/* Common status */ #define STATUS_WIP 0x01 +#define STATUS_PEC 0x80/* Send a single-byte command to the device and read the response */ int spi_flash_cmd (struct spi_slave *spi,u8 cmd,void *response,size_t len);
drivers/mtd/spi/stmicro.c +4 -0
@@ -210,5 +210,9 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) flash->sector_size =256 * params->pages_per_sector; flash->size = flash->sector_size * params->nr_sectors; +/* for >= 512MiB flashes, use flag status instead of read_status */ +if (flash->size >=0x4000000 ) + flash->poll_cmd =CMD_FLAG_STATUS ; +return flash; }
include/spi_flash.h +3 -0
@@ -46,6 +46,9 @@ struct spi_flash {/* Current flash bank */ u8 bank_curr;#endif +/* Poll cmd - for flash erase/program */ +u8 poll_cmd; +void *memory_map;/* Address of read-only SPI flash access */ int (*read)(struct spi_flash *flash,u32 offset,size_t len,void *buf);
Signature · 1 line
1.8.3