mtd: spi-nor: Add support for Cypress s25hl-t/s25hs-t
Subsystems (2)
v6 cover mtd: spi-nor: Add support for Cypress s25hl-t/s25hs-t
From: Takahiro Kuwano <[email protected]>
The S25HL-T/S25HS-T family is the Cypress Semper Flash with Quad SPI.
The summary datasheets can be found in the following links.
https://www.cypress.com/file/424146/download (256Mb/512Mb/1Gb, single die)
The full version can be found in the following links (registration required).
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-Semper-Flash-with-Quad-SPI/ta-p/260789?attachment-id=19522
Tested on Xilinx Zynq-7000 FPGA board.
Changes in v6:
- Remove 2Gb dual die package parts and related changes to split mulit die package support into another series of patches
Changes in v5:
- Fix 'if (ret == 1)' to 'if (ret < 0)' in spansion_read_any_reg()
- Add NO_CHIP_ERASE flag to S25HL02GT and S25HS02GT
Changes in v4:
- Reword 'legacy' to 'default'
- Rename spi_nor_read() to spi_nor_default_ready()
- Fix dummy cycle calculation in spansion_read_any_reg()
- Modify comment for spansion_write_any_reg()
- Merge block comments about SMPT in s25hx_t_post_sfdp_fixups()
- Remove USE_CLSR flags from S25HL02GT and S25HS02GT
Changes in v3:
- Split into multiple patches
- Remove S25HL256T and S25HS256T
- Add S25HL02GT and S25HS02GT
- Add support for multi-die package parts support
- Cleanup Read/Write Any Register implementation
- Remove erase_map fix for top/split sector layout
- Set ECC data unit size (16B) to writesize
Changes in v2:
- Remove SPI_NOR_SKIP_SFDP flag and clean up related fixups
- Check CFR3V[4] to determine page_size instead of force 512B
- Depend on the patchset below to support non-uniform sector layout
https://lore.kernel.org/linux-mtd/[email protected]/
Takahiro Kuwano (3):
mtd: spi-nor: spansion: Add support for Read/Write Any Register
mtd: spi-nor: spansion: Add support for volatile QE bit
mtd: spi-nor: spansion: Add s25hl-t/s25hs-t IDs and fixups
drivers/mtd/spi-nor/spansion.c | 278 +++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+)
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v6 1/3 mtd: spi-nor: spansion: Add support for Read/Write Any Register
From: Takahiro Kuwano <[email protected]>
Some of Spansion/Cypress chips support Read/Write Any Register commands. These commands are mainly used to write volatile registers.
The Read Any Register instruction (65h) is followed by register address and dummy cycles, then the selected register byte is returned.
The Write Any Register instruction (71h) is followed by register address and register byte to write.
---
Changes in v6:
- Add helper functions for controller_ops
- Add 'reg_addr_width' parameter to spansion_read/write_any_reg()
- Remove spi_nor_write_enable() from spansion_write_any_reg() and modified function header comment
Changes in v5:
- Fix 'if (ret == 1)' to 'if (ret < 0)' in spansion_read_any_reg()
Changes in v4:
- Fix dummy cycle calculation in spansion_read_any_reg()
- Modify comment for spansion_write_any_reg()
Changes in v3:
- Cleanup implementation
drivers/mtd/spi-nor/spansion.c | 142 +++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+)
drivers/mtd/spi-nor/spansion.c +142 -0
@@ -19,6 +19,148 @@#define SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_DS 0#define SPINOR_OP_CYPRESS_RD_FAST 0xee +/** +* controller_ops_read_any_reg() - Read Any Register using controller_ops. +* @nor: pointer to a 'struct spi_nor' +* @reg_addr: register address +* @reg_addr_width: number of address bytes +* @reg_dummy: number of dummy cycles for register read +* @reg_val: pointer to a buffer where the register value is copied +* +* Return: 0 on success, -errno otherwise. +*/ +static int controller_ops_read_any_reg (struct spi_nor *nor,u32 reg_addr, +u8 reg_addr_width,u8 reg_dummy, +u8 *reg_val) +{ +ssize_t ret; +enum spi_nor_protocol proto = nor->read_proto; +u8 opcode = nor->read_opcode; +u8 dummy = nor->read_dummy; +u8 addr_width = nor->addr_width; + + nor->read_opcode =SPINOR_OP_RD_ANY_REG ; + nor->read_dummy = reg_dummy; + nor->read_proto = nor->reg_proto; + nor->addr_width = reg_addr_width; + + ret = nor->controller_ops->read (nor, reg_addr,1 , reg_val); + + nor->read_opcode = opcode; + nor->read_dummy = dummy; + nor->read_proto = proto; + nor->addr_width = addr_width; + +if (ret <0 ) +return ret; +if (ret !=1 ) +return -EIO ; + +return 0 ; +} + +/** +* controller_ops_write_any_reg() - Write Any Register using controller_ops. +* @nor: pointer to a 'struct spi_nor' +* @reg_addr: register address +* @reg_addr_width: number of address bytes +* @reg_val: register value to be written +* * +* Return: 0 on success, -errno otherwise. +*/ +static int controller_ops_write_any_reg (struct spi_nor *nor,u32 reg_addr, +u8 reg_addr_width,u8 reg_val) +{ +ssize_t ret; +enum spi_nor_protocol proto = nor->write_proto; +u8 opcode = nor->program_opcode; +u8 addr_width = nor->addr_width; + + nor->program_opcode =SPINOR_OP_WR_ANY_REG ; + nor->write_proto = nor->reg_proto; + nor->addr_width = reg_addr_width; + + ret = nor->controller_ops->write (nor, reg_addr,1 , ®_val); + + nor->program_opcode = opcode; + nor->write_proto = proto; + nor->addr_width = addr_width; + +if (ret <0 ) +return ret; +if (ret !=1 ) +return -EIO ; + +return 0 ; +} + +/** +* spansion_read_any_reg() - Read Any Register. +* @nor: pointer to a 'struct spi_nor' +* @reg_addr: register address +* @reg_addr_width: number of address bytes +* @reg_dummy: number of dummy cycles for register read +* @reg_val: pointer to a buffer where the register value is copied +* +* Return: 0 on success, -errno otherwise. +*/ +static int spansion_read_any_reg (struct spi_nor *nor,u32 reg_addr, +u8 reg_addr_width,u8 reg_dummy,u8 *reg_val) +{ +if (nor->spimem) { +struct spi_mem_op op = +SPI_MEM_OP (SPI_MEM_OP_CMD (SPINOR_OP_RD_ANY_REG ,0 ), +SPI_MEM_OP_ADDR (reg_addr_width, reg_addr,0 ), +SPI_MEM_OP_DUMMY (reg_dummy,0 ), +SPI_MEM_OP_DATA_IN (1 , reg_val,0 )); + +spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); + +/* convert the dummy cycles to the number of bytes */ + op.dummy.nbytes = (reg_dummy * op.dummy.buswidth) /8 ; +if (spi_nor_protocol_is_dtr (nor->reg_proto)) + op.dummy.nbytes *=2 ; + +return spi_mem_exec_op (nor->spimem, &op); + } + +return controller_ops_read_any_reg (nor, reg_addr, reg_addr_width, + reg_dummy, reg_val); +} + +/** +* spansion_write_any_reg() - Write Any Register. +* @nor: pointer to a 'struct spi_nor' +* @reg_addr: register address +* @reg_addr_width: number of address bytes +* @reg_val: register value to be written +* +* spi_nor_write_enable() and spi_nor_write_disable() need to be called before +* and after this function. Caller also need to poll status for non-volatile +* register. No need to poll status for volatile registers since volatile +* register write will be effective immediately after the operation. +* +* Return: 0 on success, -errno otherwise. +*/ +static int spansion_write_any_reg (struct spi_nor *nor,u32 reg_addr, +u8 reg_addr_width,u8 reg_val) +{ +if (nor->spimem) { +struct spi_mem_op op = +SPI_MEM_OP (SPI_MEM_OP_CMD (SPINOR_OP_WR_ANY_REG ,0 ), +SPI_MEM_OP_ADDR (reg_addr_width, reg_addr,0 ), +SPI_MEM_OP_NO_DUMMY , +SPI_MEM_OP_DATA_OUT (1 , ®_val,0 )); + +spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); + +return spi_mem_exec_op (nor->spimem, &op); + } + +return controller_ops_write_any_reg (nor, reg_addr, reg_addr_width, + reg_val); +} +/** * spi_nor_cypress_octal_dtr_enable() - Enable octal DTR on Cypress flashes. * @nor: pointer to a 'struct spi_nor'
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v6 2/3 mtd: spi-nor: spansion: Add support for volatile QE bit
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
Some of Spansion/Cypress chips support volatile version of configuration registers and it is recommended to update volatile registers in the field application due to a risk of the non-volatile registers corruption by power interrupt.
---
Changes in v6:
- Remove multi die package support
Changes in v5:
- No change
Changes in v4:
- No change
Changes in v3:
- Add multi-die package parts support
drivers/mtd/spi-nor/spansion.c | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
drivers/mtd/spi-nor/spansion.c +57 -0
@@ -161,6 +161,63 @@ static int spansion_write_any_reg(struct spi_nor *nor, u32 reg_addr, reg_val); } +/** +* spansion_quad_enable_volatile() - enable Quad I/O mode in volatile register. +* @nor: pointer to a 'struct spi_nor' +* @reg_dummy: number of dummy cycles for register read +* +* It is recommended to update volatile registers in the field application due +* to a risk of the non-volatile registers corruption by power interrupt. This +* function sets Quad Enable bit in CFR1 volatile. If users set the Quad Enable +* bit in the CFR1 non-volatile in advance (typically by a Flash programmer +* before mounting Flash on PCB), the Quad Enable bit in the CFR1 volatile is +* also set during Flash power-up. This function supports multi-die package +* parts that require to set the Quad Enable bit in each die. +* +* Return: 0 on success, -errno otherwise. +*/ +static int spansion_quad_enable_volatile (struct spi_nor *nor,u8 reg_dummy) +{ +u32 reg_addr =SPINOR_REG_CYPRESS_CFR1V ; +u8 cfr1v, cfr1v_written; +int ret; + + ret =spansion_read_any_reg (nor, reg_addr, nor->addr_width, reg_dummy, + &cfr1v); +if (ret) +return ret; + +if (cfr1v &SPINOR_REG_CYPRESS_CFR1V_QUAD_EN ) +return 0 ; + + ret =spi_nor_write_enable (nor); +if (ret) +return ret; + +/* Update the Quad Enable bit. */ + cfr1v |=SPINOR_REG_CYPRESS_CFR1V_QUAD_EN ; + + ret =spansion_write_any_reg (nor, reg_addr, nor->addr_width, cfr1v); + +if (ret) +return ret; + + cfr1v_written = cfr1v; + +/* Read back and check it. */ + ret =spansion_read_any_reg (nor, reg_addr, nor->addr_width, reg_dummy, + &cfr1v); +if (ret) +return ret; + +if (cfr1v != cfr1v_written) { +dev_err (nor->dev,"CFR1: Read back test failed\n" ); +return -EIO ; + } + +return 0 ; +} +/** * spi_nor_cypress_octal_dtr_enable() - Enable octal DTR on Cypress flashes. * @nor: pointer to a 'struct spi_nor'
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v6 3/3 mtd: spi-nor: spansion: Add s25hl-t/s25hs-t IDs and fixups
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
The S25HL-T/S25HS-T family is the Cypress Semper Flash with Quad SPI.
For the single-die package parts (512Mb and 1Gb), only bottom 4KB and uniform sector sizes are supported. This is due to missing or incorrect entries in SMPT. Fixup for other sector sizes configurations will be followed up as needed.
Tested on Xilinx Zynq-7000 FPGA board.
---
Changes in v6:
- Remove 2Gb multi die pacakge support
Changes in v5:
- Add NO_CHIP_ERASE flag to S25HL02GT and S25HS02GT
Changes in v4:
- Merge block comments about SMPT in s25hx_t_post_sfdp_fixups()
- Remove USE_CLSR flags from S25HL02GT and S25HS02GT
Changes in v3:
- Remove S25HL256T and S25HS256T
- Add S25HL02GT and S25HS02GT
- Add support for multi-die package parts support
- Remove erase_map fix for top/split sector layout
- Set ECC data unit size (16B) to writesize
drivers/mtd/spi-nor/spansion.c | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
drivers/mtd/spi-nor/spansion.c +79 -0
@@ -218,6 +218,85 @@ static int spansion_quad_enable_volatile(struct spi_nor *nor, u8 reg_dummy)return 0 ; } +static int s25hx_t_quad_enable (struct spi_nor *nor) +{ +int ret =spansion_quad_enable_volatile (nor,0 ); + +/* Reset WEL bit in any error cases */ +spi_nor_write_disable (nor); + +return ret; +} + +static int +s25hx_t_post_bfpt_fixups (struct spi_nor *nor, +const struct sfdp_parameter_header *bfpt_header, +const struct sfdp_bfpt *bfpt, +struct spi_nor_flash_parameter *params) +{ +int ret; +u32 addr; +u8 cfr3v; + + ret =spi_nor_set_4byte_addr_mode (nor, true); +if (ret) +return ret; + nor->addr_width =4 ; + +/* Replace Quad Enable with volatile version */ + params->quad_enable = s25hx_t_quad_enable; + +/* +* The page_size is set to 512B from BFPT, but it actually depends on +* the configuration register. Look up the CFR3V and determine the +* page_size. +*/ + ret =spansion_read_any_reg (nor, addr +SPINOR_REG_CYPRESS_CFR3V , + nor->addr_width,0 , &cfr3v); +if (ret) +return ret; + +if (!(cfr3v &SPINOR_REG_CYPRESS_CFR3V_PGSZ )) + params->page_size =256 ; +else + params->page_size =512 ; + +return 0 ; +} + +void s25hx_t_post_sfdp_fixups (struct spi_nor *nor) +{ +/* Fast Read 4B requires mode cycles */ + nor->params->reads[SNOR_CMD_READ_FAST ].num_mode_clocks =8 ; + +/* The writesize should be ECC data unit size */ + nor->params->writesize =16 ; + +/* +* For the single-die package parts (512Mb and 1Gb), bottom 4KB and +* uniform sector maps are correctly populated in the erase_map +* structure. The table below shows all possible combinations of related +* register bits and its availability in SMPT. +* +* CFR3[3] | CFR1[6] | CFR1[2] | Sector Map | Available in SMPT? +* ------------------------------------------------------------------- +* 0 | 0 | 0 | Bottom | YES +* 0 | 0 | 1 | Top | NO (decoded as Split) +* 0 | 1 | 0 | Split | NO +* 0 | 1 | 1 | Split | NO (decoded as Top) +* 1 | 0 | 0 | Uniform | YES +* 1 | 0 | 1 | Uniform | NO +* 1 | 1 | 0 | Uniform | NO +* 1 | 1 | 1 | Uniform | NO +* ------------------------------------------------------------------- +*/ +} + +static struct spi_nor_fixups s25hx_t_fixups = { + .post_bfpt = s25hx_t_post_bfpt_fixups, + .post_sfdp = s25hx_t_post_sfdp_fixups +}; +/** * spi_nor_cypress_octal_dtr_enable() - Enable octal DTR on Cypress flashes. * @nor: pointer to a 'struct spi_nor'
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi,
I found some critical changes are missing from this series. I will submit new version.
Quoted 44 lines · On 6/16/2021 5:44 PM, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
The S25HL-T/S25HS-T family is the Cypress Semper Flash with Quad SPI.
The summary datasheets can be found in the following links.
https://www.cypress.com/file/424146/download (256Mb/512Mb/1Gb, single die)The full version can be found in the following links (registration required).
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-Semper-Flash-with-Quad-SPI/ta-p/260789?attachment-id=19522Tested on Xilinx Zynq-7000 FPGA board.
Changes in v6:
- Remove 2Gb dual die package parts and related changes to split mulit die package support into another series of patchesChanges in v5:
- Fix 'if (ret == 1)' to 'if (ret < 0)' inspansion_read_any_reg()
- AddNO_CHIP_ERASEflag to S25HL02GT and S25HS02GTChanges in v4:
- Reword 'legacy' to 'default'
- Renamespi_nor_read()tospi_nor_default_ready()
- Fix dummy cycle calculation inspansion_read_any_reg()
- Modify comment forspansion_write_any_reg()
- Merge block comments about SMPT ins25hx_t_post_sfdp_fixups()
- RemoveUSE_CLSRflags from S25HL02GT and S25HS02GTChanges in v3:
- Split into multiple patches
- Remove S25HL256T and S25HS256T
- Add S25HL02GT and S25HS02GT
- Add support for multi-die package parts support
- Cleanup Read/Write Any Register implementation
- Removeerase_mapfix for top/split sector layout
- Set ECC data unit size (16B) to writesizeChanges in v2:
- RemoveSPI_NOR_SKIP_SFDPflag and clean up related fixups
- Check CFR3V[4] to determinepage_sizeinstead of force 512B
- Depend on the patchset below to support non-uniform sector layouthttps://lore.kernel.org/linux-mtd/[email protected]/
Quoted 8 lines
Takahiro Kuwano (3):
mtd: spi-nor: spansion: Add support for Read/Write Any Register
mtd: spi-nor: spansion: Add support for volatile QE bit
mtd: spi-nor: spansion: Add s25hl-t/s25hs-t IDs and fixupsdrivers/mtd/spi-nor/spansion.c | 278 +++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+)
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Vignesh Raghavendra
maintainerQuoted 5 lines · Takahiro Kuwano
Hi,
I found some critical changes are missing from this series. I will submit new version.
While reposting, could you provide dumps of SFDP and device ID data in cover letter for future reference. See [1] on how to dump these tables.
[1] https://lore.kernel.org/linux-mtd/[email protected]/
Regards
Vignesh
Quoted 45 lines · On 6/16/2021 5:44 PM, [email protected] wrote:
Quoted 44 lines
From: Takahiro Kuwano <[email protected]>
The S25HL-T/S25HS-T family is the Cypress Semper Flash with Quad SPI.
The summary datasheets can be found in the following links.
https://www.cypress.com/file/424146/download (256Mb/512Mb/1Gb, single die)The full version can be found in the following links (registration required).
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-Semper-Flash-with-Quad-SPI/ta-p/260789?attachment-id=19522Tested on Xilinx Zynq-7000 FPGA board.
Changes in v6:
- Remove 2Gb dual die package parts and related changes to split mulit die package support into another series of patchesChanges in v5:
- Fix 'if (ret == 1)' to 'if (ret < 0)' inspansion_read_any_reg()
- AddNO_CHIP_ERASEflag to S25HL02GT and S25HS02GTChanges in v4:
- Reword 'legacy' to 'default'
- Renamespi_nor_read()tospi_nor_default_ready()
- Fix dummy cycle calculation inspansion_read_any_reg()
- Modify comment forspansion_write_any_reg()
- Merge block comments about SMPT ins25hx_t_post_sfdp_fixups()
- RemoveUSE_CLSRflags from S25HL02GT and S25HS02GTChanges in v3:
- Split into multiple patches
- Remove S25HL256T and S25HS256T
- Add S25HL02GT and S25HS02GT
- Add support for multi-die package parts support
- Cleanup Read/Write Any Register implementation
- Removeerase_mapfix for top/split sector layout
- Set ECC data unit size (16B) to writesizeChanges in v2:
- RemoveSPI_NOR_SKIP_SFDPflag and clean up related fixups
- Check CFR3V[4] to determinepage_sizeinstead of force 512B
- Depend on the patchset below to support non-uniform sector layouthttps://lore.kernel.org/linux-mtd/[email protected]/
Quoted 8 lines
Quoted 8 lines
Takahiro Kuwano (3):
mtd: spi-nor: spansion: Add support for Read/Write Any Register
mtd: spi-nor: spansion: Add support for volatile QE bit
mtd: spi-nor: spansion: Add s25hl-t/s25hs-t IDs and fixupsdrivers/mtd/spi-nor/spansion.c | 278 +++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+)
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/