sf: Add extended address register writing support
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/4 sf: Add extended address register writing support
This patch provides support to program a flash extended address register.
extended/bank address register contains an information to access the 4th byte addressing in 3-byte address mode.
Currently added an extended/bank address register writing support for spansion flashes.
--- drivers/mtd/spi/spi_flash.c | 41 ++++++++++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 6 +++++ 2 files changed, 47 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +41 -0
@@ -269,6 +269,47 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)return 0 ; } +int spi_flash_cmd_extaddr_write (struct spi_flash *flash,u8 ear) +{ +u8 cmd; +u8 idcode0; +int ret; + + ret =spi_flash_cmd (flash->spi,CMD_READ_ID , &idcode0,1 ); +if (ret) { +debug ("SF: fail to read read id\n" ); +return ret; + } + +if (idcode0 ==0x01 ) + cmd =CMD_EXT_BRWR ; +else { +printf ("SF: unable to support extaddr reg write" +" for %s flash\n" , flash->name); +return -1 ; + } + + 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 , &ear,1 ); +if (ret) { +debug ("SF: fail to write ext addr register\n" ); +return ret; + } + + ret =spi_flash_cmd_wait_ready (flash,SPI_FLASH_PROG_TIMEOUT ); +if (ret <0 ) { +debug ("SF: write config register timed out\n" ); +return ret; + } + +return 0 ; +} +/* * The following table holds all device probe functions *
drivers/mtd/spi/spi_flash_internal.h +6 -0
@@ -28,6 +28,9 @@#define CMD_ERASE_64K 0xd8#define CMD_ERASE_CHIP 0xc7 +/* Extended addr acess commands */ +#define CMD_EXT_BRWR 0x17 +/* Common status */ #define STATUS_WIP 0x01
@@ -77,6 +80,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 extended address register */ +int spi_flash_cmd_extaddr_write (struct spi_flash *flash,u8 ear); +/* * 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.7.4
PATCH 2/4 sf: Add extended address register reading support
In reply to a message not in the archiveThis patch provides support to read a flash extended address register.
reading extended/bank address register will give whether the flash is operated on extended addressing or normal addressing in 3-byte address mode.
Currently added an extended/bank address register reading support for spansion flashes.
--- drivers/mtd/spi/spi_flash.c | 23 +++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 4 ++++ 2 files changed, 27 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +23 -0
@@ -310,6 +310,29 @@ int spi_flash_cmd_extaddr_write(struct spi_flash *flash, u8 ear)return 0 ; } +int spi_flash_cmd_extaddr_read (struct spi_flash *flash,void *data) +{ +u8 cmd; +u8 idcode0; +int ret; + + ret =spi_flash_cmd (flash->spi,CMD_READ_ID , &idcode0,1 ); +if (ret) { +debug ("SF: fail to read read id\n" ); +return ret; + } + +if (idcode0 ==0x01 ) + cmd =CMD_EXT_BRRD ; +else { +printf ("SF: unable to support extended addr reg read" +" for %s flash\n" , flash->name); +return -1 ; + } + +return spi_flash_read_common (flash, &cmd,1 , data,1 ); +} +/* * The following table holds all device probe functions *
drivers/mtd/spi/spi_flash_internal.h +4 -0
@@ -30,6 +30,7 @@/* Extended addr acess commands */ #define CMD_EXT_BRWR 0x17 +#define CMD_EXT_BRRD 0x16/* Common status */ #define STATUS_WIP 0x01
@@ -83,6 +84,9 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);/* Program the extended address register */ int spi_flash_cmd_extaddr_write (struct spi_flash *flash,u8 ear); +/* Read the extended address register */ +int spi_flash_cmd_extaddr_read (struct spi_flash *flash,void *data); +/* * 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.7.4
PATCH 2/4 sf: Add extended address register reading support
Hello Jagan,
Am 23.02.2013 12:38, schrieb Jagannadha Sutradharudu Teki:
Quoted 7 lines
This patch provides support to read a flash extended address register.
reading extended/bank address register will give whether the flash is operated on extended addressing or normal addressing in 3-byte address mode.
Currently added an extended/bank address register reading support for spansion flashes.
The same comments as for patch 1/4 apply here.
[...]
Best Regards,
Thomas
PATCH 3/4 sf: Add extended address access support
In reply to a message not in the archiveThis patch provides support to access an extended addressing in 3-byte address mode.
The current implementation in spi_flash supports 3-byte address mode due to this up to 16MB amount of flash is able to access for those flashes which has an actual size of > 16MB.
extended/bank address register contains an information to access the 4th byte addressing hence the flashes which has > 16MB can be accessible.
--- drivers/mtd/spi/spi_flash.c | 81 ++++++++++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 8 +++ 2 files changed, 89 insertions(+), 0 deletions(-)
drivers/mtd/spi/spi_flash.c +81 -0
@@ -23,6 +23,30 @@ static void spi_flash_addr(u32 addr, u8 *cmd) cmd[3 ] = addr >>0 ; } +static int spi_flash_check_extaddr_access (struct spi_flash *flash,u32 *offset) +{ +int ret; + +if (*offset >=0x1000000 ) { + ret =spi_flash_extaddr_access (flash,STATUS_EXTADDR_ENABLE ); +if (ret) { +debug ("SF: fail to %s ext addr bit\n" , +STATUS_EXTADDR_ENABLE ?"set" :"reset" ); +return ret; + } + *offset -=0x1000000 ; + }else { + ret =spi_flash_extaddr_access (flash,STATUS_EXTADDR_DISABLE ); +if (ret) { +debug ("SF: fail to %s ext addr bit\n" , +STATUS_EXTADDR_DISABLE ?"set" :"reset" ); +return ret; + } + } + +return ret; +} + static int spi_flash_read_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, const u8 *data_out, u8 *data_in,
@@ -73,6 +97,14 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,int ret;u8 cmd[4 ]; +if (flash->size >0x1000000 ) { + ret =spi_flash_check_extaddr_access (flash, &offset); +if (ret) { +debug ("SF: fail to acess ext_addr\n" ); +return ret; + } + } + page_size = flash->page_size; page_addr = offset / page_size; byte_addr = offset % page_size;
@@ -139,6 +171,15 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, size_t len, void *data) { u8 cmd[5]; +int ret; + +if (flash->size >0x1000000 ) { + ret =spi_flash_check_extaddr_access (flash, &offset); +if (ret) { +debug ("SF: fail to acess ext_addr\n" ); +return ret; + } + } cmd[0 ] =CMD_READ_ARRAY_FAST ;spi_flash_addr (offset, cmd);
@@ -196,6 +237,14 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)int ret;u8 cmd[4 ]; +if (flash->size >0x1000000 ) { + ret =spi_flash_check_extaddr_access (flash, &offset); +if (ret) { +debug ("SF: fail to acess ext_addr\n" ); +return ret; + } + } + erase_size = flash->sector_size;if (offset % erase_size || len % erase_size) {debug ("SF: Erase offset/length not multiple of erase size\n" );
@@ -333,6 +382,38 @@ int spi_flash_cmd_extaddr_read(struct spi_flash *flash, void *data)return spi_flash_read_common (flash, &cmd,1 , data,1 ); } +int spi_flash_extaddr_access (struct spi_flash *flash,u8 status) +{ +int ret, pass; +u8 data =0 , write_done =0 ; + +for (pass =0 ; pass <2 ; pass++) { + ret =spi_flash_cmd_extaddr_read (flash, (void *)&data); +if (ret <0 ) { +debug ("SF: fail to read ext addr register\n" ); +return ret; + } + +if ((data != status) & !write_done) { +debug ("SF: need to %s ext addr bit\n" , + status ?"set" :"reset" ); + + write_done =1 ; + ret =spi_flash_cmd_extaddr_write (flash, status); +if (ret <0 ) { +debug ("SF: fail to write ext addr bit\n" ); +return ret; + } + }else { +debug ("SF: ext addr bit is %s.\n" , + status ?"set" :"reset" ); +return ret; + } + } + +return -1 ; +} +/* * The following table holds all device probe functions *
drivers/mtd/spi/spi_flash_internal.h +8 -0
@@ -34,6 +34,8 @@/* Common status */ #define STATUS_WIP 0x01 +#define STATUS_EXTADDR_ENABLE 0x01 +#define STATUS_EXTADDR_DISABLE 0x00/* 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);
@@ -86,6 +88,12 @@ int spi_flash_cmd_extaddr_write(struct spi_flash *flash, u8 ear);/* Read the extended address register */ int spi_flash_cmd_extaddr_read (struct spi_flash *flash,void *data); +/* +* Extended address access +* access 4th byte address in 3-byte addessing mode for flashes +* which has an actual size of > 16MB. +*/ +int spi_flash_extaddr_access (struct spi_flash *flash,u8 status);/* * Same as spi_flash_cmd_read() except it also claims/releases the SPI
Signature · 1 line
1.7.4
PATCH 3/4 sf: Add extended address access support
Hello Jagan,
Am 23.02.2013 12:39, schrieb Jagannadha Sutradharudu Teki:
Quoted 21 lines
This patch provides support to access an extended addressing in 3-byte address mode.
The current implementation in
spi_flashsupports 3-byte address mode due to this up to 16MB amount of flash is able to access for those flashes which has an actual size of > 16MB.extended/bank address register contains an information to access the 4th byte addressing hence the flashes which has > 16MB can be accessible.
Signed-off-by Jagannadha Sutradharudu Teki <[email protected]>--- drivers/mtd/spi/spi_flash.c | 81 ++++++++++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 8 +++ 2 files changed, 89 insertions(+), 0 deletions(-)drivers/mtd/spi/spi_flash.c +0
-0
drivers/mtd/spi/spi_flash.c static void spi_flash_addr(u32 addr, u8 *cmd) · line 31
Quoted 9 lines
drivers/mtd/spi/spi_flash.c +6
-0@@ -23,6 +23,30 @@ static void spi_flash_addr(u32 addr, u8 *cmd) cmd[3 ] = addr >>0 ; } +static int spi_flash_check_extaddr_access (struct spi_flash *flash,u32 *offset) +{ +int ret; + +if (*offset >=0x1000000 ) { + ret =spi_flash_extaddr_access (flash,STATUS_EXTADDR_ENABLE );
Restricting this to a single bit here would give the next size limit at 32M.
Please make it future-prov as much as possible: Why not directly use the upper byte of the offset as parameter?
drivers/mtd/spi/spi_flash.c static void spi_flash_addr(u32 addr, u8 *cmd) · line 37
Quoted 6 lines
drivers/mtd/spi/spi_flash.c +6
-0+if (ret) { +debug ("SF: fail to %s ext addr bit\n" , +STATUS_EXTADDR_ENABLE ?"set" :"reset" ); +return ret; + } + *offset -=0x1000000 ;
Are you sure that manipulating the value of the caller has no side-effect?
Is it even necessary, if the callers only do 3-byte-addressing and probably ignore the upper byte?
Quoted 16 lines
drivers/mtd/spi/spi_flash.c +12
-0+ }else { + ret =spi_flash_extaddr_access (flash,STATUS_EXTADDR_DISABLE ); +if (ret) { +debug ("SF: fail to %s ext addr bit\n" , +STATUS_EXTADDR_DISABLE ?"set" :"reset" ); +return ret; + } + } + +return ret; +} + static int spi_flash_read_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, const u8 *data_out, u8 *data_in,
drivers/mtd/spi/spi_flash.c int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset, · line 100
Quoted 4 lines
drivers/mtd/spi/spi_flash.c +1
-0@@ -73,6 +97,14 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,int ret;u8 cmd[4 ]; +if (flash->size >0x1000000 ) {
As already said in my comments to patch 1/4, this check (and the check for manufacturer ID) should be done only once once during probing of the flash.
Then, if necessary, adapted functions for read, write and erase should be assigned to the function-pointers. Or use an additional function-pointer, which can be set to this or a similar function. Then the call of this function should be included in the loops, which all these functions have. Otherwise, as with your current code, you have a problem if the current accessed block crosses the boundary at 16M. Have you ever tried this?
Quoted 42 lines
drivers/mtd/spi/spi_flash.c +24
-0+ ret =spi_flash_check_extaddr_access (flash, &offset); +if (ret) { +debug ("SF: fail to acess ext_addr\n" ); +return ret; + } + } + page_size = flash->page_size; page_addr = offset / page_size; byte_addr = offset % page_size;@@ -139,6 +171,15 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, size_t len, void *data) { u8 cmd[5]; +int ret; + +if (flash->size >0x1000000 ) { + ret =spi_flash_check_extaddr_access (flash, &offset); +if (ret) { +debug ("SF: fail to acess ext_addr\n" ); +return ret; + } + } cmd[0 ] =CMD_READ_ARRAY_FAST ;spi_flash_addr (offset, cmd);@@ -196,6 +237,14 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)int ret;u8 cmd[4 ]; +if (flash->size >0x1000000 ) { + ret =spi_flash_check_extaddr_access (flash, &offset); +if (ret) { +debug ("SF: fail to acess ext_addr\n" ); +return ret; + } + } + erase_size = flash->sector_size;if (offset % erase_size || len % erase_size) {debug ("SF: Erase offset/length not multiple of erase size\n" );
drivers/mtd/spi/spi_flash.c int spi_flash_cmd_extaddr_read(struct spi_flash *flash, void *data) · line 390
Quoted 9 lines
drivers/mtd/spi/spi_flash.c +6
-0@@ -333,6 +382,38 @@ int spi_flash_cmd_extaddr_read(struct spi_flash *flash, void *data)return spi_flash_read_common (flash, &cmd,1 , data,1 ); } +int spi_flash_extaddr_access (struct spi_flash *flash,u8 status) +{ +int ret, pass; +u8 data =0 , write_done =0 ; + +for (pass =0 ; pass <2 ; pass++) {
Why this is required??
Quoted 9 lines
drivers/mtd/spi/spi_flash.c +9
-0+ ret =spi_flash_cmd_extaddr_read (flash, (void *)&data); +if (ret <0 ) { +debug ("SF: fail to read ext addr register\n" ); +return ret; + } + +if ((data != status) & !write_done) { +debug ("SF: need to %s ext addr bit\n" , + status ?"set" :"reset" );
drivers/mtd/spi/spi_flash.c int spi_flash_cmd_extaddr_read(struct spi_flash *flash, void *data) · line 409
Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10
-0+ + write_done =1 ; + ret =spi_flash_cmd_extaddr_write (flash, status); +if (ret <0 ) { +debug ("SF: fail to write ext addr bit\n" ); +return ret; + } + }else { +debug ("SF: ext addr bit is %s.\n" , + status ?"set" :"reset" );
Instead of reading and writing this register each time (which will happen often, if this function is called in the loops as suggested above), please cache the actual value inside struct spi_flash.
Initial read should be done during probing and then writing only if the value needs to change.
This is something depending on this design rule:
http://www.denx.de/wiki/U-Boot/DesignPrinciples#2_Keep_it_Fast
Quoted 15 lines
drivers/mtd/spi/spi_flash.c +7
-0+return ret; + } + } + +return -1 ; +} +/* * The following table holds all device probe functions * drivers/mtd/spi/spi_flash_internal.h +0
-0
drivers/mtd/spi/spi_flash_internal.h line 38
Quoted 5 lines
drivers/mtd/spi/spi_flash_internal.h +2
-0@@ -34,6 +34,8 @@/* Common status */ #define STATUS_WIP 0x01 +#define STATUS_EXTADDR_ENABLE 0x01 +#define STATUS_EXTADDR_DISABLE 0x00
As said above, don't restrict to a single bit!
Quoted 7 lines
drivers/mtd/spi/spi_flash_internal.h +0
-0/* 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);@@ -86,6 +88,12 @@ int spi_flash_cmd_extaddr_write(struct spi_flash *flash, u8 ear);/* Read the extended address register */
drivers/mtd/spi/spi_flash_internal.h int spi_flash_cmd_extaddr_write(struct spi_flash *flash, u8 ear); · line 99
Quoted 10 lines
drivers/mtd/spi/spi_flash_internal.h +6
-0int spi_flash_cmd_extaddr_read (struct spi_flash *flash,void *data); +/* +* Extended address access +* access 4th byte address in 3-byte addessing mode for flashes +* which has an actual size of > 16MB. +*/ +int spi_flash_extaddr_access (struct spi_flash *flash,u8 status);/* * Same as spi_flash_cmd_read() except it also claims/releases the SPI
Best Regards,
Thomas
PATCH 3/4 sf: Add extended address access support
Quoted 38 lines
-----Original Message-----
From: Langer Thomas (LQDE RD ST PON SW)
[mailto:thomas.langer at lantiq.com]
Sent: 24 February 2013 21:21
To: Jagannadha Sutradharudu Teki; u-boot at lists.denx.de
Cc: Michal at theia.denx.de; Jagannadha Sutradharudu Teki
Subject: AW: [U-Boot] [PATCH 3/4] sf: Add extended address access supportHello Jagan,
Am 23.02.2013 12:39, schrieb Jagannadha Sutradharudu Teki:
Quoted 7 lines
This patch provides support to access an extended addressing in 3-byte address mode.
The current implementation in
spi_flashsupports 3-byte address mode due to this up to 16MB amount of flash is able to access for those flashes which has an actual size of > 16MB.Quoted 6 lines
extended/bank address register contains an information to access the 4th byte addressing hence the flashes which has > 16MB can be accessible.
Signed-off-by Jagannadha Sutradharudu Teki <[email protected]>--- drivers/mtd/spi/spi_flash.c | 81++++++++++++++++++++++++++++++++++
Quoted 11 lines
drivers/mtd/spi/spi_flash_internal.h | 8 +++ 2 files changed, 89 insertions(+), 0 deletions(-)drivers/mtd/spi/spi_flash.c +0
-0@@ -23,6 +23,30 @@ static void spi_flash_addr(u32 addr, u8 *cmd) cmd[3 ] = addr >>0 ; }
Quoted 10 lines
drivers/mtd/spi/spi_flash.c static void spi_flash_addr(u32 addr, u8 *cmd)
Quoted 6 lines
drivers/mtd/spi/spi_flash.c +6
-0+static int spi_flash_check_extaddr_access (struct spi_flash *flash, +u32 *offset) { +int ret; + +if (*offset >=0x1000000 ) { + ret = spi_flash_extaddr_access(flash,
STATUS_EXTADDR_ENABLE);
Restricting this to a single bit here would give the next size limit at 32M. Please make it future-prov as much as possible: Why not directly use the upper byte of the offset as parameter?
I didn't get you clearly, can you please elaborate.
Quoted 10 lines
drivers/mtd/spi/spi_flash.c static void spi_flash_addr(u32 addr, u8 *cmd) · line 37
Quoted 7 lines
drivers/mtd/spi/spi_flash.c +6
-0+if (ret) { +debug ("SF: fail to %s ext addr bit\n" , +STATUS_EXTADDR_ENABLE ?"set" :"reset" ); +return ret; + } + *offset -=0x1000000 ;Are you sure that manipulating the value of the caller has no side-effect? Is it even necessary, if the callers only do 3-byte-addressing and probably ignore the upper byte?
May be you are not getting my exact code context.
PATCH 4/4 sf: winbond: Add support for W25Q256
In reply to a message not in the archiveAdd support for Winbond W25Q256 SPI flash.
--- drivers/mtd/spi/winbond.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/mtd/spi/winbond.c +5 -0
@@ -63,6 +63,11 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { .name = "W25Q128", }, { + .id = 0x4019, + .nr_blocks = 512, + .name = "W25Q256", + }, + { .id = 0x5014, .nr_blocks = 128, .name = "W25Q80",
Signature · 1 line
1.7.4
PATCH 4/4 sf: winbond: Add support for W25Q256
Hi Jagan,
Am 23.02.2013 12:39, schrieb Jagannadha Sutradharudu Teki:
Quoted 2 lines
Add support for Winbond W25Q256 SPI flash.
As the other patches are only supporting spansion flashes, this is unrelated and should be resend independent of them.
Even if not the full capacity of this flash is usable until the extended address support for winbond is added, it might be useful for others to detect this chip and use the first 16 MB of it.
Best Regards,
Thomas
PATCH 4/4 sf: winbond: Add support for W25Q256
In reply to Jagannadha Sutradharudu TekiQuoted 24 lines · Jagannadha Sutradharudu Teki
Add support for Winbond W25Q256 SPI flash.
Signed-off-by Jagannadha Sutradharudu Teki <[email protected]>--- drivers/mtd/spi/winbond.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)drivers/mtd/spi/winbond.c +5
-1@@ -63,6 +63,11 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { .name = "W25Q128", }, { + .id = 0x4019, + .nr_blocks = 512, + .name = "W25Q256", + }, + { .id = 0x5014, .nr_blocks = 128, .name = "W25Q80", --
Quoted 1 line
1.7.4
--
Thanks,
Jagan.
PATCH 4/4 sf: winbond: Add support for W25Q256
In reply to Jagannadha Sutradharudu TekiQuoted 14 lines · Jagannadha Sutradharudu Teki
Add support for Winbond W25Q256 SPI flash.
Signed-off-by Jagannadha Sutradharudu Teki <[email protected]>---
drivers/mtd/spi/winbond.c| 5 +++++1 files changed, 5 insertions(+), 0 deletions(-)drivers/mtd/spi/winbond.c +0
-0@@ -63,6 +63,11 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { .name = "W25Q128",
drivers/mtd/spi/winbond.c static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { · line 73
Quoted 10 lines
drivers/mtd/spi/winbond.c +5
-0}, { + .id = 0x4019, + .nr_blocks = 512, + .name = "W25Q256", + }, + { .id = 0x5014, .nr_blocks = 128, .name = "W25Q80",
Applied to u-boot-spi/master
--
Thanks,
Jagan.