spi: sf: Support byte program for sst spi flash
Subsystems (2)
PATCH 3/5 spi: sf: Support byte program for sst spi flash
Currently if SST flash advertises SST_WP flag in the params table the word program command (ADh) with auto address increment will be used for the flash write op. However some SPI controllers do not support the word program command (like the Intel ICH 7), the byte programm command (02h) has to be used.
A new TX operation mode SPI_OPM_TX_BP is introduced for such SPI controller to use byte program op for SST flash.
--- drivers/mtd/spi/sf_internal.h | 2 ++ drivers/mtd/spi/sf_ops.c | 31 +++++++++++++++++++++++++++++++ drivers/mtd/spi/sf_probe.c | 8 ++++++-- drivers/spi/ich.c | 9 +++++++-- include/spi.h | 1 + 5 files changed, 47 insertions(+), 4 deletions(-)
drivers/mtd/spi/sf_internal.h +2 -0
@@ -77,6 +77,8 @@int sst_write_wp (struct spi_flash *flash,u32 offset,size_t len,const void *buf); +int sst_write_bp (struct spi_flash *flash,u32 offset,size_t len, +const void *buf);#endif /* Send a single-byte command to the device and read the response */
drivers/mtd/spi/sf_ops.c +31 -0
@@ -516,4 +516,35 @@ int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,spi_release_bus (flash->spi);return ret; } + +int sst_write_bp (struct spi_flash *flash,u32 offset,size_t len, +const void *buf) +{ +size_t actual; +int ret; + + ret =spi_claim_bus (flash->spi); +if (ret) { +debug ("SF: Unable to claim SPI bus\n" ); +return ret; + } + +for (actual =0 ; actual < len; actual++) { + ret =sst_byte_write (flash, offset, buf + actual); +if (ret) { +debug ("SF: sst byte program failed\n" ); +break ; + } + offset++; + } + +if (!ret) + ret =spi_flash_cmd_write_disable (flash); + +debug ("SF: sst: program %s %zu bytes @ 0x%zx\n" , + ret ?"failure" :"success" , len, offset - actual); + +spi_release_bus (flash->spi); +return ret; +}#endif
drivers/mtd/spi/sf_probe.c +6 -2
@@ -138,8 +138,12 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,/* Assign spi_flash ops */ flash->write = spi_flash_cmd_write_ops;#ifdef CONFIG_SPI_FLASH_SST -if (params->flags &SST_WP ) - flash->write = sst_write_wp; +if (params->flags &SST_WP ) { +if (flash->spi->op_mode_tx &SPI_OPM_TX_BP ) + flash->write = sst_write_bp; +else + flash->write = sst_write_wp; + }#endif flash->erase = spi_flash_cmd_erase_ops; flash->read = spi_flash_cmd_read_ops;
drivers/spi/ich.c +7 -2
@@ -141,9 +141,14 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, ich->slave.max_write_size = ctlr.databytes; ich->speed = max_hz; -/* ICH 7 SPI controller only supports array read command */ -if (ctlr.ich_version ==7 ) +/* +* ICH 7 SPI controller only supports array read command +* and byte program command for SST flash +*/ +if (ctlr.ich_version ==7 ) { ich->slave.op_mode_rx =SPI_OPM_RX_AS ; + ich->slave.op_mode_tx =SPI_OPM_TX_BP ; + }return &ich->slave; }
include/spi.h +1 -0
@@ -34,6 +34,7 @@/* SPI TX operation modes */ #define SPI_OPM_TX_QPP 1 << 0 +#define SPI_OPM_TX_BP 1 << 1/* SPI RX operation modes */ #define SPI_OPM_RX_AS 1 << 0
Signature · 1 line
1.8.2.1
PATCH 3/5 spi: sf: Support byte program for sst spi flash
Quoted 9 lines · Bin Meng
Currently if SST flash advertises
SST_WPflag in the params table the word program command (ADh) with auto address increment will be used for the flash write op. However some SPI controllers do not support the word program command (like the Intel ICH 7), the byte programm command (02h) has to be used.A new TX operation mode
SPI_OPM_TX_BPis introduced for such SPI controller to use byte program op for SST flash.
Quoted 8 lines
Signed-off-by Bin Meng <[email protected]>--- drivers/mtd/spi/sf_internal.h | 2 ++ drivers/mtd/spi/sf_ops.c | 31 +++++++++++++++++++++++++++++++ drivers/mtd/spi/sf_probe.c | 8 ++++++-- drivers/spi/ich.c | 9 +++++++-- include/spi.h | 1 + 5 files changed, 47 insertions(+), 4 deletions(-)
Tested on link (which is however ich9)
There are a few conflicts with the driver model SPI series that just landed. I'll push this to u-boot-x86/testing for now so that Jagan can take a look. But probably this should come through the x86 tree.
Regards,
Simon
PATCH 3/5 spi: sf: Support byte program for sst spi flash
In reply to Bin MengQuoted 23 lines · Bin Meng
Currently if SST flash advertises
SST_WPflag in the params table the word program command (ADh) with auto address increment will be used for the flash write op. However some SPI controllers do not support the word program command (like the Intel ICH 7), the byte programm command (02h) has to be used.A new TX operation mode
SPI_OPM_TX_BPis introduced for such SPI controller to use byte program op for SST flash.Signed-off-by Bin Meng <[email protected]>--- drivers/mtd/spi/sf_internal.h | 2 ++ drivers/mtd/spi/sf_ops.c | 31 +++++++++++++++++++++++++++++++ drivers/mtd/spi/sf_probe.c | 8 ++++++-- drivers/spi/ich.c | 9 +++++++-- include/spi.h | 1 + 5 files changed, 47 insertions(+), 4 deletions(-)drivers/mtd/spi/sf_internal.h +0
-0
drivers/mtd/spi/sf_internal.h line 82
Quoted 6 lines
drivers/mtd/spi/sf_internal.h +2
-0@@ -77,6 +77,8 @@int sst_write_wp (struct spi_flash *flash,u32 offset,size_t len,const void *buf); +int sst_write_bp (struct spi_flash *flash,u32 offset,size_t len, +const void *buf);#endif
I believe byte write is already been used within the sst_write_wp - please check.
drivers/mtd/spi/sf_ops.c int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, · line 521
Quoted 13 lines
drivers/mtd/spi/sf_internal.h +0
-0/* Send a single-byte command to the device and read the response */ drivers/mtd/spi/sf_ops.c +3
-0@@ -516,4 +516,35 @@ int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,spi_release_bus (flash->spi);return ret; } + +int sst_write_bp (struct spi_flash *flash,u32 offset,size_t len, +const void *buf)
This function is simply calling existing sst_byte_write().
Quoted 56 lines
drivers/mtd/spi/sf_ops.c +28
-0+{ +size_t actual; +int ret; + + ret =spi_claim_bus (flash->spi); +if (ret) { +debug ("SF: Unable to claim SPI bus\n" ); +return ret; + } + +for (actual =0 ; actual < len; actual++) { + ret =sst_byte_write (flash, offset, buf + actual); +if (ret) { +debug ("SF: sst byte program failed\n" ); +break ; + } + offset++; + } + +if (!ret) + ret =spi_flash_cmd_write_disable (flash); + +debug ("SF: sst: program %s %zu bytes @ 0x%zx\n" , + ret ?"failure" :"success" , len, offset - actual); + +spi_release_bus (flash->spi); +return ret; +}#endif drivers/mtd/spi/sf_probe.c +6
-2@@ -138,8 +138,12 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,/* Assign spi_flash ops */ flash->write = spi_flash_cmd_write_ops;#ifdef CONFIG_SPI_FLASH_SST -if (params->flags &SST_WP ) - flash->write = sst_write_wp; +if (params->flags &SST_WP ) { +if (flash->spi->op_mode_tx &SPI_OPM_TX_BP ) + flash->write = sst_write_bp; +else + flash->write = sst_write_wp; + }#endif flash->erase = spi_flash_cmd_erase_ops; flash->read = spi_flash_cmd_read_ops;drivers/spi/ich.c +0
-0@@ -141,9 +141,14 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, ich->slave.max_write_size = ctlr.databytes; ich->speed = max_hz;
drivers/spi/ich.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 151
Quoted 10 lines
drivers/spi/ich.c +7
-2-/* ICH 7 SPI controller only supports array read command */ -if (ctlr.ich_version ==7 ) +/* +* ICH 7 SPI controller only supports array read command +* and byte program command for SST flash +*/ +if (ctlr.ich_version ==7 ) { ich->slave.op_mode_rx =SPI_OPM_RX_AS ; + ich->slave.op_mode_tx =SPI_OPM_TX_BP ; + }
SST commands(write) is different than normal flash commands, I don't like to change the controller driver to know the flash command usage.
May be this part can think later, try to see above comments.
Quoted 16 lines
drivers/spi/ich.c +0
-0return &ich->slave; }include/spi.h +1
-1@@ -34,6 +34,7 @@/* SPI TX operation modes */ #define SPI_OPM_TX_QPP 1 << 0 +#define SPI_OPM_TX_BP 1 << 1/* SPI RX operation modes */ #define SPI_OPM_RX_AS 1 << 0 --
Quoted 2 lines
1.8.2.1
thanks!
Signature · 1 line
Jagan.
PATCH 3/5 spi: sf: Support byte program for sst spi flash
Hi Jegan,
Quoted 3 lines · Jagan Teki
I believe byte write is already been used within the
sst_write_wp- please check.
Yes, byte write is used within sst_write_wp, however that does not mean sst_write_wp is doing the correct thing for byte program (02h). The sst_write_wp() is using the AAI command (ADh) which might not be supported by every spi host controller.
Quoted 6 lines
Quoted 6 lines
/* Send a single-byte command to the device and read the response */
drivers/mtd/spi/sf_ops.c +0
-0@@ -516,4 +516,35 @@ int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
Quoted 8 lines
drivers/mtd/spi/sf_ops.c int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, · line 521
Quoted 6 lines
drivers/mtd/spi/sf_ops.c +3
-0spi_release_bus (flash->spi);return ret; } + +int sst_write_bp (struct spi_flash *flash,u32 offset,size_t len, +const void *buf)This function is simply calling existing
sst_byte_write().
Yes, but with a loop counter of buffer length.
Quoted 4 lines
SST commands(write) is different than normal flash commands, I don't like to change the controller driver to know the flash command usage.
May be this part can think later, try to see above comments.
Yes, SST is different. But since there is already a spi->op_mode_tx field we can make use of it to do similar thing like spi->op_mode_rx (determining which read command to use). Again this might be revisited in the future if this is not that clean.
Regards,
Bin