mtd: spi-nor: Add support for Infineon SEMPER s25hl02gt and s25hs02gt
Subsystems (2)
v2 cover mtd: spi-nor: Add support for Infineon SEMPER s25hl02gt and s25hs02gt
From: Takahiro Kuwano <[email protected]>
Infineon SEMPER s25hl02gt and s25hs02gt are multi-chip (dual-die) package parts and the datasheet can be found at:
https://www.infineon.com/dgdl/Infineon-S25HS02GT_S25HS04GT_S25HL02GT_S25HL04GT_2-Gb_DDP_4-Gb_QDP_HS-T_1.8-V_HL-T_3_0-V_Semper_Flash_with_Quad_SPI-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c7e7124d1017f01b9a5055b7b
The key characteristics of multi-chip devices are:
- Each die has dedicataed registers so we need to configure and check registers in all the dice
- Read ops can cross the die boundary
- 4-byte address mode by default
- Legacy chip-erase command is not supported
To support multi-chip devices, core and sfdp need to determine the number of dice and volatile register offset for each die. The SCCR map and newly added SCCR map for multi-chip params in SFDP helps to do it.
In manufacturer specific code (spansion.c), configuration and status check are updated to support multi-chip.
The s25hl02gt and s25hs02gt support chip-erase-addressed command followed by die address instead of legacy chip-erase command. This series does not add support for chip-erase-addressed. Another patch set may be created to introduced how we can utilise that command.
Tested with Xilinx Zynq-7000 platform. Existing devices that share the same manufacturer code (S25Hx-T and S28HS512T) are also tested.
Changes in v2:
- s/return 0/continue in cypress_nor_quad_enable_volatile()
- Stop introducing DEF_4BAM flag. Handle it in post_bfpt_fixup() instead
ID, SFDP, and test log:
--------------------------------------------------------------------------
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/partname s25hl02gt
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id 342a1c0f0090
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer spansion
zynq> xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp 53464450080104ff00080114000100ff84000102500100ff81000118e001 00ff8700011c580100ff88000106c80100ffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffe720faffffffff7f48eb086b00ff 88bbfeffffffffff00ffffff48eb0c2000ff00ff12d823faff8b82e7ffec ec031c608a857a75f766805c8cd6ddfff938c0a1000000000000bc000000 0000f7f5ffff7b920ffe21ffffdc0000800000000000c0ffc3fbc8ffe3fb 00650090066500b10065009600650095716503d0716503d000000000b02e 000088a489aa716503967165039600000000000000000000000000000000 000000000000000000000000000000000000000000000000716505d57165 05d50000a015000080080000000800008010000000100000801800000018 fc65ff0804008000fc65ff0402008000fc65ff0804008008fd65ff040200 8008fe0202fff1ff0100f8ff0100f8fffb0ffe0902fff8fffb0ff8ff0100 f1ff0100fe0104fff1ff0100f8ff0100f8fff70ff8ff0100f1ff0100ff0a 00fff8ffff0f
zynq> md5sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp 86aef254bcfdf763bdb92e4c31667242 /sys/bus/spi/devices/spi0.0/spi-nor/sfdp zynq> test_qspi.sh
6+0 records in
6+0 records out
6291456 bytes (6.0MB) copied, 0.231488 seconds, 25.9MB/s Copied 6291456 bytes from qspi_test to address 0x00000000 in flash Erased 6291456 bytes from address 0x00000000 in flash
Copied 6291456 bytes from address 0x00000000 in flash to qspi_read 0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0600000
Copied 6291456 bytes from qspi_test to address 0x00000000 in flash Copied 6291456 bytes from address 0x00000000 in flash to qspi_read 9f433bd1566013c98b94f5ff441859314c1fc7d6 qspi_test 9f433bd1566013c98b94f5ff441859314c1fc7d6 qspi_read
--------------------------------------------------------------------------
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/partname s25hs02gt
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id 342b1c0f0090
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer spansion
zynq> xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp 53464450080104ff00080114000100ff84000102500100ff81000118e001 00ff8700011c580100ff88000106c80100ffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ffffffffffffffffffffffffffffffffe720faffffffff7f48eb086b00ff 88bbfeffffffffff00ffffff48eb0c2000ff00ff12d823faff8b82e7ffec ec031c608a857a75f766805c8cd6ddfff938c0a1000000000000bc000000 0000f7f5ffff7b920ffe21ffffdc0000800000000000c0ffc3fbc8ffe3fb 00650090066500b10065009600650095716503d0716503d000000000b02e 000088a489aa716503967165039600000000000000000000000000000000 000000000000000000000000000000000000000000000000716505d57165 05d50000a015000080080000000800008010000000100000801800000018 fc65ff0804008000fc65ff0402008000fc65ff0804008008fd65ff040200 8008fe0202fff1ff0100f8ff0100f8fffb0ffe0902fff8fffb0ff8ff0100 f1ff0100fe0104fff1ff0100f8ff0100f8fff70ff8ff0100f1ff0100ff0a 00fff8ffff0f
zynq> md5sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp 86aef254bcfdf763bdb92e4c31667242 /sys/bus/spi/devices/spi0.0/spi-nor/sfdp zynq> test_qspi.sh
6+0 records in
6+0 records out
6291456 bytes (6.0MB) copied, 0.231691 seconds, 25.9MB/s Copied 6291456 bytes from qspi_test to address 0x00000000 in flash Erased 6291456 bytes from address 0x00000000 in flash
Copied 6291456 bytes from address 0x00000000 in flash to qspi_read 0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0600000
Copied 6291456 bytes from qspi_test to address 0x00000000 in flash Copied 6291456 bytes from address 0x00000000 in flash to qspi_read 58b52b293f93574507b6ffb06f0e79b57b0f1f28 qspi_test 58b52b293f93574507b6ffb06f0e79b57b0f1f28 qspi_read
--------------------------------------------------------------------------
Takahiro Kuwano (8):
mtd: spi-nor: core: Introduce number of dice and volatile register
offset params
mtd: spi-nor: sfdp: Extract volatile register offset from SCCR map
mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
mtd: spi-nor: spansion: Rework cypress_nor_set_page_size() for
multi-chip device support
mtd: spi-nor: spansion: Rework cypress_nor_quad_enable_volatile() for
multi-chip device support
mtd: spi-nor: spansion: Add a new ->ready() hook for multi-chip device
mtd: spi-nor: spansion: Set params->addr_mode_nbytes = 4 for multi-die
parts
mtd: spi-nor: spansion: Add support for Infineon
drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/sfdp.c | 76 +++++++++++ drivers/mtd/spi-nor/spansion.c | 232 ++++++++++++++++++++++----------- 4 files changed, 236 insertions(+), 77 deletions(-)
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 1/8 mtd: spi-nor: core: Introduce number of dice and volatile register offset params
From: Takahiro Kuwano <[email protected]>
In use of mult-chip devices, we need to access registers in each die for configuration and status check. The number of dice in the device and volatile register offset for each die are essential to iterate register access ops.
The number of dice must be initialized as 1 and may be updated through SFDP parse.
The volatile register offset table is dinamically allocated based on the number of dice then filled with offset values collected from SFDP.
--- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 4 ++++ 2 files changed, 5 insertions(+)
drivers/mtd/spi-nor/core.c +1 -0
@@ -2576,6 +2576,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor) params->writesize =1 ; params->size = (u64 )info->sector_size * info->n_sectors; params->page_size = info->page_size; + params->num_of_dice =1 ;if (!(info->flags &SPI_NOR_NO_FR )) {/* Default to Fast Read for DT and non-DT platform devices. */
drivers/mtd/spi-nor/core.h +4 -0
@@ -349,6 +349,8 @@ struct spi_nor_otp {* in octal DTR mode. * @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register * command in octal DTR mode. +* @num_of_dice: number of dice in the flash memory. +* @vreg_offset: volatile register offset for each die. * @hwcaps: describes the read and page program hardware * capabilities. * @reads: read capabilities ordered by priority: the higher index
@@ -381,6 +383,8 @@ struct spi_nor_flash_parameter {u8 addr_mode_nbytes;u8 rdsr_dummy;u8 rdsr_addr_nbytes; +u8 num_of_dice; +u32 *vreg_offset;struct spi_nor_hwcaps hwcaps;struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ];
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 1/8] mtd: spi-nor: core: Introduce number of dice and volatile register offset params
Quoted 3 lines · On 08/02/23 11:23, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
In use of mult-chip devices, we need to access registers in each die for
s/mult-/multi-
Quoted 2 lines
configuration and status check. The number of dice in the device and volatile register offset for each die are essential to iterate register
s/offset/offsets for each die
Quoted 6 lines
access ops.
The number of dice must be initialized as 1 and may be updated through SFDP parse.
The volatile register offset table is dinamically allocated based on
s/dinamically/dynamically
Quoted 42 lines
the number of dice then filled with offset values collected from SFDP.
Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 4 ++++ 2 files changed, 5 insertions(+)drivers/mtd/spi-nor/core.c +1
-0@@ -2576,6 +2576,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor) params->writesize =1 ; params->size = (u64 )info->sector_size * info->n_sectors; params->page_size = info->page_size; + params->num_of_dice =1 ;if (!(info->flags &SPI_NOR_NO_FR )) {/* Default to Fast Read for DT and non-DT platform devices. */ drivers/mtd/spi-nor/core.h +4
-0@@ -349,6 +349,8 @@ struct spi_nor_otp {* in octal DTR mode. * @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register * command in octal DTR mode. +* @num_of_dice: number of dice in the flash memory. +* @vreg_offset: volatile register offset for each die. * @hwcaps: describes the read and page program hardware * capabilities. * @reads: read capabilities ordered by priority: the higher index @@ -381,6 +383,8 @@ struct spi_nor_flash_parameter {u8 addr_mode_nbytes;u8 rdsr_dummy;u8 rdsr_addr_nbytes; +u8 num_of_dice; +u32 *vreg_offset;struct spi_nor_hwcaps hwcaps;struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ];
Signature · 6 lines
Thanks and Regards, Dhruva Gole ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 1/8] mtd: spi-nor: core: Introduce number of dice and volatile register offset params
In reply to [email protected]Quoted 45 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
In use of mult-chip devices, we need to access registers in each die for configuration and status check. The number of dice in the device and volatile register offset for each die are essential to iterate register access ops.
The number of dice must be initialized as 1 and may be updated through SFDP parse.
The volatile register offset table is dinamically allocated based on the number of dice then filled with offset values collected from SFDP.
Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 4 ++++ 2 files changed, 5 insertions(+)drivers/mtd/spi-nor/core.c +1
-0@@ -2576,6 +2576,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor) params->writesize =1 ; params->size = (u64 )info->sector_size * info->n_sectors; params->page_size = info->page_size; + params->num_of_dice =1 ;if (!(info->flags &SPI_NOR_NO_FR )) {/* Default to Fast Read for DT and non-DT platform devices. */ drivers/mtd/spi-nor/core.h +2
-0@@ -349,6 +349,8 @@ struct spi_nor_otp {* in octal DTR mode. * @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register * command in octal DTR mode. +* @num_of_dice: number of dice in the flash memory. +* @vreg_offset: volatile register offset for each die. * @hwcaps: describes the read and page program hardware * capabilities. * @reads: read capabilities ordered by priority: the higher index
drivers/mtd/spi-nor/core.h struct spi_nor_flash_parameter { · line 386
Quoted 4 lines
drivers/mtd/spi-nor/core.h +1
-0@@ -381,6 +383,8 @@ struct spi_nor_flash_parameter {u8 addr_mode_nbytes;u8 rdsr_dummy;u8 rdsr_addr_nbytes; +u8 num_of_dice;
ndice maybe?
drivers/mtd/spi-nor/core.h struct spi_nor_flash_parameter { · line 390
Quoted 4 lines
drivers/mtd/spi-nor/core.h +1
-0+u32 *vreg_offset;struct spi_nor_hwcaps hwcaps;struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ];
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 2/8 mtd: spi-nor: sfdp: Extract volatile register offset from SCCR map
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
The volatile register offset resides in the 1st DWORD of SCCR map. Allocate the table and copy the offset value.
The table may be allocated when the SCCR map for multi-chip is parsed. Since we cannot assume SCCR parse is always in ahead of SCCR multi-chip, we need to check if the table is already allocated or not.
--- drivers/mtd/spi-nor/sfdp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/mtd/spi-nor/sfdp.c +12 -0
@@ -1215,6 +1215,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,static int spi_nor_parse_sccr (struct spi_nor *nor,const struct sfdp_parameter_header *sccr_header) { +struct spi_nor_flash_parameter *params = nor->params;u32 *dwords, addr;size_t len;int ret;
@@ -1231,6 +1232,17 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,le32_to_cpu_array (dwords, sccr_header->length); +/* Address offset for volatile registers (die 0) */ +if (!params->vreg_offset) { + params->vreg_offset =devm_kmalloc (nor->dev,sizeof (*dwords), +GFP_KERNEL ); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out; + } + } + params->vreg_offset[0 ] = dwords[0 ]; +if (FIELD_GET (SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE , dwords[SFDP_DWORD (22 )])) nor->flags |=SNOR_F_IO_MODE_EN_VOLATILE ;
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 2/8] mtd: spi-nor: sfdp: Extract volatile register offset from SCCR map
Quoted 30 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
The volatile register offset resides in the 1st DWORD of SCCR map. Allocate the table and copy the offset value.
The table may be allocated when the SCCR map for multi-chip is parsed. Since we cannot assume SCCR parse is always in ahead of SCCR multi-chip, we need to check if the table is already allocated or not.
Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/sfdp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/mtd/spi-nor/sfdp.c +1
-0@@ -1215,6 +1215,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,static int spi_nor_parse_sccr (struct spi_nor *nor,const struct sfdp_parameter_header *sccr_header) { +struct spi_nor_flash_parameter *params = nor->params;u32 *dwords, addr;size_t len;int ret;@@ -1231,6 +1232,17 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,le32_to_cpu_array (dwords, sccr_header->length);
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1244
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +10
-0+/* Address offset for volatile registers (die 0) */ +if (!params->vreg_offset) { + params->vreg_offset =devm_kmalloc (nor->dev,sizeof (*dwords), +GFP_KERNEL ); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out; + } + } + params->vreg_offset[0 ] = dwords[0 ];
params->vreg_offset[0] = dwords[SFDP_DWORD(1)];
it helps readers match the code with the standard
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1248
Quoted 4 lines
drivers/mtd/spi-nor/sfdp.c +1
-0+if (FIELD_GET (SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE , dwords[SFDP_DWORD (22 )])) nor->flags |=SNOR_F_IO_MODE_EN_VOLATILE ;
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 3/8 mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
SCCR map for multi-chip devices contains the number of additional dice in the device and register offset values for each additional dice.
spi_nor_parse_sccr_mc() is added to determine the number of dice and volatile register offset for each die. The volatile register offset table may already be allocated and contains offset value for die-0 via SCCR map parse. So, we should use devm_krealloc() to expand the table with preserving die-0 offset.
--- drivers/mtd/spi-nor/sfdp.c | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/mtd/spi-nor/sfdp.c +64 -0
@@ -26,6 +26,11 @@* Status, Control and Configuration * Register Map. */ +#define SFDP_SCCR_MAP_MC_ID 0xff88/* +* Status, Control and Configuration +* Register Map Offsets for Multi-Chip +* SPI Memory Devices. +*/ #define SFDP_SIGNATURE 0x50444653U
@@ -1252,6 +1257,61 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,return ret; } +/** +* spi_nor_parse_sccr_mc() - Parse the Status, Control and Configuration +* Register Map Offsets for Multi-Chip SPI Memory +* Devices. +* @nor: pointer to a 'struct spi_nor' +* @sccr_mc_header: pointer to the 'struct sfdp_parameter_header' describing +* the SCCR Map offsets table length and version. +* +* Return: 0 on success, -errno otherwise. +*/ +static int spi_nor_parse_sccr_mc (struct spi_nor *nor, +const struct sfdp_parameter_header *sccr_mc_header) +{ +struct spi_nor_flash_parameter *params = nor->params; +u32 *dwords, addr; +size_t len; +int ret; +u8 i; + + len = sccr_mc_header->length *sizeof (*dwords); + dwords =kmalloc (len,GFP_KERNEL ); +if (!dwords) +return -ENOMEM ; + + addr =SFDP_PARAM_HEADER_PTP (sccr_mc_header); + ret =spi_nor_read_sfdp (nor, addr, len, dwords); +if (ret) + goto out; + +le32_to_cpu_array (dwords, sccr_mc_header->length); + +/* +* Pair of DOWRDs (volatile and non-volatile register offsets) per +* additional die. Hence, length = 2 * (number of additional dice). +*/ + params->num_of_dice += sccr_mc_header->length /2 ; + +/* Address offset for volatile registers of additional dice */ + params->vreg_offset = +devm_krealloc (nor->dev, params->vreg_offset, + params->num_of_dice *sizeof (*dwords), +GFP_KERNEL ); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out; + } + +for (i =1 ; i < params->num_of_dice; i++) + params->vreg_offset[i] = dwords[(i -1 ) *2 ]; + +out: +kfree (dwords); +return ret; +} +/** * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings * after SFDP has been parsed. Called only for flashes that define JESD216 SFDP
@@ -1461,6 +1521,10 @@ int spi_nor_parse_sfdp(struct spi_nor *nor) err =spi_nor_parse_sccr (nor, param_header);break ; +case SFDP_SCCR_MAP_MC_ID : + err =spi_nor_parse_sccr_mc (nor, param_header); +break ; +default :break ; }
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 3/8] mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
Quoted 74 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
SCCR map for multi-chip devices contains the number of additional dice in the device and register offset values for each additional dice.
spi_nor_parse_sccr_mc()is added to determine the number of dice and volatile register offset for each die. The volatile register offset table may already be allocated and contains offset value for die-0 via SCCR map parse. So, we should usedevm_krealloc()to expand the table with preserving die-0 offset.Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/sfdp.c | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)drivers/mtd/spi-nor/sfdp.c +43
-0@@ -26,6 +26,11 @@* Status, Control and Configuration * Register Map. */ +#define SFDP_SCCR_MAP_MC_ID 0xff88/* +* Status, Control and Configuration +* Register Map Offsets for Multi-Chip +* SPI Memory Devices. +*/ #define SFDP_SIGNATURE 0x50444653U@@ -1252,6 +1257,61 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,return ret; } +/** +* spi_nor_parse_sccr_mc() - Parse the Status, Control and Configuration +* Register Map Offsets for Multi-Chip SPI Memory +* Devices. +* @nor: pointer to a 'struct spi_nor' +* @sccr_mc_header: pointer to the 'struct sfdp_parameter_header' describing +* the SCCR Map offsets table length and version. +* +* Return: 0 on success, -errno otherwise. +*/ +static int spi_nor_parse_sccr_mc (struct spi_nor *nor, +const struct sfdp_parameter_header *sccr_mc_header) +{ +struct spi_nor_flash_parameter *params = nor->params; +u32 *dwords, addr; +size_t len; +int ret; +u8 i; + + len = sccr_mc_header->length *sizeof (*dwords); + dwords =kmalloc (len,GFP_KERNEL ); +if (!dwords) +return -ENOMEM ; + + addr =SFDP_PARAM_HEADER_PTP (sccr_mc_header); + ret =spi_nor_read_sfdp (nor, addr, len, dwords); +if (ret) + goto out; + +le32_to_cpu_array (dwords, sccr_mc_header->length); + +/* +* Pair of DOWRDs (volatile and non-volatile register offsets) per +* additional die. Hence, length = 2 * (number of additional dice). +*/ + params->num_of_dice += sccr_mc_header->length /2 ; + +/* Address offset for volatile registers of additional dice */
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1307
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +10
-0+ params->vreg_offset = +devm_krealloc (nor->dev, params->vreg_offset, + params->num_of_dice *sizeof (*dwords), +GFP_KERNEL ); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out; + } + +for (i =1 ; i < params->num_of_dice; i++)
here you limit the number of dices to 256, while the jesd216 says "any number from 2 and up may be used". While I agree that having 256 dices is improbable we'll have to decide whether:
1/ keep using u8 for the number of dices, thus limiting them to 256, assuming that the table length is wrong. In this case you'll have to check sccr_mc_header->length and return an error for no-of-dices > 256 2/ use unsigned int for the number of dices and hope you'll get an ENOMEM sooner or later
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1308
Quoted 1 line
drivers/mtd/spi-nor/sfdp.c +1
-0+ params->vreg_offset[i] = dwords[(i -1 ) *2 ];
use SFDP_DWORD() please
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +6
-0+ +out: +kfree (dwords); +return ret; +} +/** * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings * after SFDP has been parsed. Called only for flashes that define JESD216 SFDP
drivers/mtd/spi-nor/sfdp.c int spi_nor_parse_sfdp(struct spi_nor *nor) · line 1530
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +4
-0@@ -1461,6 +1521,10 @@ int spi_nor_parse_sfdp(struct spi_nor *nor) err =spi_nor_parse_sccr (nor, param_header);break ; +case SFDP_SCCR_MAP_MC_ID : + err =spi_nor_parse_sccr_mc (nor, param_header); +break ; +default :break ; }
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 3/8] mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
Quoted 99 lines · Tudor Ambarus
Quoted 73 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
SCCR map for multi-chip devices contains the number of additional dice in the device and register offset values for each additional dice.
spi_nor_parse_sccr_mc()is added to determine the number of dice and volatile register offset for each die. The volatile register offset table may already be allocated and contains offset value for die-0 via SCCR map parse. So, we should usedevm_krealloc()to expand the table with preserving die-0 offset.Signed-off-by Takahiro Kuwano <[email protected]>---
drivers/mtd/spi-nor/sfdp.c| 64 ++++++++++++++++++++++++++++++++++++++1 file changed, 64 insertions(+)drivers/mtd/spi-nor/sfdp.c +8
-0@@ -26,6 +26,11 @@* Status, Control and Configuration * Register Map. */ +#define SFDP_SCCR_MAP_MC_ID 0xff88/* +* Status, Control and Configuration +* Register Map Offsets for Multi-Chip +* SPI Memory Devices. +*/ #define SFDP_SIGNATURE 0x50444653U@@ -1252,6 +1257,61 @@ static int spi_nor_parse_sccr(struct spi_nor *nor, return ret; } +/** +* spi_nor_parse_sccr_mc() - Parse the Status, Control and Configuration +* Register Map Offsets for Multi-Chip SPI Memory
+ * Devices.
+ * @nor: pointer to a 'structspi_nor'
+ * @sccr_mc_header: pointer to the 'structsfdp_parameter_header' describing
+ * the SCCR Map offsets table length and version.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */drivers/mtd/spi-nor/sfdp.c +28
-0+static int spi_nor_parse_sccr_mc (struct spi_nor *nor, + const struct sfdp_parameter_header *sccr_mc_header) +{ + struct spi_nor_flash_parameter *params = nor->params; + u32 *dwords, addr; + size_t len; + int ret; + u8 i; + + len = sccr_mc_header->length * sizeof(*dwords); + dwords = kmalloc(len, GFP_KERNEL); + if (!dwords) + return -ENOMEM; + + addr = SFDP_PARAM_HEADER_PTP(sccr_mc_header); + ret = spi_nor_read_sfdp(nor, addr, len, dwords); + if (ret) + goto out; + + le32_to_cpu_array(dwords, sccr_mc_header->length); + + /* + * Pair of DOWRDs (volatile and non-volatile register offsets) per + * additional die. Hence, length = 2 * (number of additional dice). + */ + params->num_of_dice += sccr_mc_header->length / 2; + + /* Address offset for volatile registers of additional dice */drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1307
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +10
-0+ params->vreg_offset = + devm_krealloc(nor->dev, params->vreg_offset, + params->num_of_dice * sizeof(*dwords), + GFP_KERNEL); + if (!params->vreg_offset) { + ret = -ENOMEM; + goto out; + } + + for (i = 1; i < params->num_of_dice; i++)here you limit the number of dices to 256, while the jesd216 says "any number from 2 and up may be used". While I agree that having 256 dices is improbable we'll have to decide whether:
1/ keep using u8 for the number of dices, thus limiting them to 256, assuming that the table length is wrong. In this case you'll have to checksccr_mc_header->lengthand return an error for no-of-dices > 256 2/ use unsigned int for the number of dices and hope you'll get an ENOMEM sooner or laterQuoted 1 line
+ params->vreg_offset[i] = dwords[(i - 1) * 2];
use
SFDP_DWORD()please
Quoted 14 lines
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +6
-0+ +out: + kfree(dwords); + return ret; +} +/**
*spi_nor_post_sfdp_fixups()- Updates the flash's parameters and settings
* after SFDP has been parsed. Called only for flashes that define JESD216 SFDPdrivers/mtd/spi-nor/sfdp.c int spi_nor_parse_sfdp(struct spi_nor *nor) · line 1524
Quoted 4 lines
drivers/mtd/spi-nor/sfdp.c +2
-0@@ -1461,6 +1521,10 @@ int spi_nor_parse_sfdp(struct spi_nor *nor) err = spi_nor_parse_sccr(nor, param_header); break; + case SFDP_SCCR_MAP_MC_ID: + err = spi_nor_parse_sccr_mc(nor, param_header);
what happens if you get an error here? Will the flash work fine just for the first dice or it will not work at all?
Quoted 5 lines
Quoted 5 lines
drivers/mtd/spi-nor/sfdp.c +2
-0+ break; +default:
break;
}
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 4/8 mtd: spi-nor: spansion: Rework cypress_nor_set_page_size() for multi-chip device support
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we can use 512B page only when the all dice are configured as 512B page size. Simple for-loop with params->num_of_dice can check the CFR3V in each die. The volatile register address is calculated inside the loop by using die number and volatile register offset.
The location of cypress_nor_set_page_size() call is moved from post_bfpt_fixup() to post_sfdp_fixup(), because the number of dice and volatile register offset are parsed after BFPT. The post_sfdp_fixup() does not return error code so cypress_nor_set_page_size() prints error message instead of returning error code.
--- drivers/mtd/spi-nor/spansion.c | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-)
drivers/mtd/spi-nor/spansion.c +25 -22
@@ -18,7 +18,7 @@#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ #define SPINOR_REG_CYPRESS_CFR2V 0x00800003#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb -#define SPINOR_REG_CYPRESS_CFR3V 0x00800004 +#define SPINOR_REG_CYPRESS_CFR3 0x4#define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4)/* Page size. */ #define SPINOR_REG_CYPRESS_CFR5V 0x00800006#define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6)
@@ -195,27 +195,34 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor)* The BFPT table advertises a 512B or 256B page size depending on part but the * page size is actually configurable (with the default being 256B). Read from * CFR3V[4] and set the correct size. -* -* Return: 0 on success, -errno otherwise. */ -static int cypress_nor_set_page_size (struct spi_nor *nor) +static void cypress_nor_set_page_size (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params = nor->params;struct spi_mem_op op = -CYPRESS_NOR_RD_ANY_REG_OP (nor->params->addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR3V , +CYPRESS_NOR_RD_ANY_REG_OP (params->addr_mode_nbytes,0 , nor->bouncebuf);int ret; +u8 i; - ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); -if (ret) -return ret; +/* Set to default page size */ + params->page_size =256 ; -if (nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR3_PGSZ ) - nor->params->page_size =512 ; -else - nor->params->page_size =256 ; +for (i =0 ; i < params->num_of_dice; i++) { + op.addr.val = params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR3 ; -return 0 ; + ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); +if (ret) { +dev_err (nor->dev,"Failed to read page size configuration. Use default 256B.\n" ); +return ; + } + +if (!(nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR3_PGSZ )) +return ; + } + +/* We reach here only when all dice are configured to 512B */ + params->page_size =512 ; } static int
@@ -226,7 +233,7 @@ s25hx_t_post_bfpt_fixup(struct spi_nor *nor,/* Replace Quad Enable with volatile version */ nor->params->quad_enable = cypress_nor_quad_enable_volatile; -return cypress_nor_set_page_size (nor); +return 0 ; }static void s25hx_t_post_sfdp_fixup (struct spi_nor *nor)
@@ -251,6 +258,8 @@ static void s25hx_t_post_sfdp_fixup(struct spi_nor *nor)break ; } } + +cypress_nor_set_page_size (nor); }static void s25hx_t_late_init (struct spi_nor *nor)
@@ -312,13 +321,8 @@ static void s28hx_t_post_sfdp_fixup(struct spi_nor *nor)* actual value for that is 4. */ nor->params->rdsr_addr_nbytes =4 ; -} -static int s28hx_t_post_bfpt_fixup (struct spi_nor *nor, -const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt) -{ -return cypress_nor_set_page_size (nor); +cypress_nor_set_page_size (nor); }static void s28hx_t_late_init (struct spi_nor *nor)
@@ -329,7 +333,6 @@ static void s28hx_t_late_init(struct spi_nor *nor)static const struct spi_nor_fixups s28hx_t_fixups = { .post_sfdp = s28hx_t_post_sfdp_fixup, - .post_bfpt = s28hx_t_post_bfpt_fixup, .late_init = s28hx_t_late_init, };
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/8] mtd: spi-nor: spansion: Rework cypress_nor_set_page_size() for multi-chip device support
Quoted 10 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we can use 512B page only when the all dice are configured as 512B page size. Simple for-loop with
params->num_of_dicecan check the CFR3V in each die. The volatile register address is calculated inside the loop by using die number and volatile register offset.The location of
cypress_nor_set_page_size()call is moved frompost_bfpt_fixup()topost_sfdp_fixup(), because the number of dice and volatile register offset are parsed after BFPT. Thepost_sfdp_fixup()
No, this looks wrong.
BFPT is the only mandatory table and should be sufficient to make any flash work (in the multi die case, just for the first die). All the other tables are considered optional. If we get an error when parsing BFPT we return an error, if we get an error in any optional table, we just print a warning and continue. So you should make sure that the flash works fine even if sccr_map_mc fails.
Quoted 42 lines
does not return error code so
cypress_nor_set_page_size()prints error message instead of returning error code.Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/spansion.c | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-)drivers/mtd/spi-nor/spansion.c +5
-8@@ -18,7 +18,7 @@#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ #define SPINOR_REG_CYPRESS_CFR2V 0x00800003#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb -#define SPINOR_REG_CYPRESS_CFR3V 0x00800004 +#define SPINOR_REG_CYPRESS_CFR3 0x4#define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4)/* Page size. */ #define SPINOR_REG_CYPRESS_CFR5V 0x00800006#define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6)@@ -195,27 +195,34 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor)* The BFPT table advertises a 512B or 256B page size depending on part but the * page size is actually configurable (with the default being 256B). Read from * CFR3V[4] and set the correct size. -* -* Return: 0 on success, -errno otherwise. */ -static int cypress_nor_set_page_size (struct spi_nor *nor) +static void cypress_nor_set_page_size (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params = nor->params;struct spi_mem_op op = -CYPRESS_NOR_RD_ANY_REG_OP (nor->params->addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR3V , +CYPRESS_NOR_RD_ANY_REG_OP (params->addr_mode_nbytes,0 , nor->bouncebuf);int ret; +u8 i; - ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); -if (ret)
drivers/mtd/spi-nor/spansion.c static int cypress_nor_quad_enable_volatile(struct spi_nor *nor) · line 212
Quoted 10 lines
drivers/mtd/spi-nor/spansion.c +4
-5-return ret; +/* Set to default page size */ + params->page_size =256 ; -if (nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR3_PGSZ ) - nor->params->page_size =512 ; -else - nor->params->page_size =256 ; +for (i =0 ; i < params->num_of_dice; i++) { + op.addr.val = params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR3 ;
in case sccr_map fails vreg_offset is zero here, you'll read garbage
drivers/mtd/spi-nor/spansion.c static int cypress_nor_quad_enable_volatile(struct spi_nor *nor) · line 217
Quoted 6 lines
drivers/mtd/spi-nor/spansion.c +4
-1-return 0 ; + ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); +if (ret) { +dev_err (nor->dev,"Failed to read page size configuration. Use default 256B.\n" ); +return ;
why did we consider a no-go error and exited in the past and now we just use a default config?
Quoted 45 lines
drivers/mtd/spi-nor/spansion.c +12
-7+ } + +if (!(nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR3_PGSZ )) +return ; + } + +/* We reach here only when all dice are configured to 512B */ + params->page_size =512 ; } static int@@ -226,7 +233,7 @@ s25hx_t_post_bfpt_fixup(struct spi_nor *nor,/* Replace Quad Enable with volatile version */ nor->params->quad_enable = cypress_nor_quad_enable_volatile; -return cypress_nor_set_page_size (nor); +return 0 ; }static void s25hx_t_post_sfdp_fixup (struct spi_nor *nor)@@ -251,6 +258,8 @@ static void s25hx_t_post_sfdp_fixup(struct spi_nor *nor)break ; } } + +cypress_nor_set_page_size (nor); }static void s25hx_t_late_init (struct spi_nor *nor)@@ -312,13 +321,8 @@ static void s28hx_t_post_sfdp_fixup(struct spi_nor *nor)* actual value for that is 4. */ nor->params->rdsr_addr_nbytes =4 ; -} -static int s28hx_t_post_bfpt_fixup (struct spi_nor *nor, -const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt) -{ -return cypress_nor_set_page_size (nor); +cypress_nor_set_page_size (nor); }static void s28hx_t_late_init (struct spi_nor *nor)
drivers/mtd/spi-nor/spansion.c static void s28hx_t_late_init(struct spi_nor *nor) · line 338
Quoted 7 lines
drivers/mtd/spi-nor/spansion.c +0
-1@@ -329,7 +333,6 @@ static void s28hx_t_late_init(struct spi_nor *nor)static const struct spi_nor_fixups s28hx_t_fixups = { .post_sfdp = s28hx_t_post_sfdp_fixup, - .post_bfpt = s28hx_t_post_bfpt_fixup, .late_init = s28hx_t_late_init, };
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/8] mtd: spi-nor: spansion: Rework cypress_nor_set_page_size() for multi-chip device support
Quoted 88 lines · Tudor Ambarus
Quoted 11 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we can use 512B page only when the all dice are configured as 512B page size. Simple for-loop with
params->num_of_dicecan
check the CFR3V in each die. The volatile register address is calculated inside the loop by using die number and volatile register offset.The location of
cypress_nor_set_page_size()call is moved frompost_bfpt_fixup()topost_sfdp_fixup(), because the number of dice and volatile register offset are parsed after BFPT. Thepost_sfdp_fixup()No, this looks wrong.
BFPT is the only mandatory table and should be sufficient to make any flash work (in the multi die case, just for the first die). All the other tables are considered optional. If we get an error when parsing BFPT we return an error, if we get an error in any optional table, we just print a warning and continue. So you should make sure that the flash works fine even if
sccr_map_mcfails.Quoted 47 lines
does not return error code so
cypress_nor_set_page_size()prints error message instead of returning error code.Signed-off-by Takahiro Kuwano <[email protected]>---
drivers/mtd/spi-nor/spansion.c| 47 ++++++++++++++++++----------------1 file changed, 25 insertions(+), 22 deletions(-)drivers/mtd/spi-nor/spansion.c +0
-0@@ -18,7 +18,7 @@ #define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1) /* QuadEnable */
#define SPINOR_REG_CYPRESS_CFR2V0x00800003#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_240xbdrivers/mtd/spi-nor/spansion.c +1
-1-#define SPINOR_REG_CYPRESS_CFR3V 0x00800004 +#define SPINOR_REG_CYPRESS_CFR3 0x4#define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4) /* Page size. */ #define SPINOR_REG_CYPRESS_CFR5V
0x00800006#define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6)drivers/mtd/spi-nor/spansion.c +0
-0@@ -195,27 +195,34 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor) * The BFPT table advertises a 512B or 256B page size depending onpart but the
* page size is actually configurable (with the default being 256B). Read from
* CFR3V[4] and set the correct size.
- *
- * Return: 0 on success, -errno otherwise.
*/drivers/mtd/spi-nor/spansion.c +1
-1-static int cypress_nor_set_page_size (struct spi_nor *nor) +static void cypress_nor_set_page_size (struct spi_nor *nor){
+ structspi_nor_flash_parameter*params =nor->params; structspi_mem_opop =
- CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR3V,
+CYPRESS_NOR_RD_ANY_REG_OP(params->addr_mode_nbytes, 0, nor->bouncebuf);
int ret;
+ u8 i;
- ret =spi_nor_read_any_reg(nor, &op, nor->reg_proto); - if (ret)
- return ret;Quoted 8 lines
+ /* Set to default page size */
+params->page_size= 256;
- if (nor->bouncebuf[0] &SPINOR_REG_CYPRESS_CFR3_PGSZ) -nor->params->page_size= 512;
- else
-nor->params->page_size= 256;
+ for (i = 0; i <params->num_of_dice; i++) {
+ op.addr.val = params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR3;in case
sccr_mapfailsvreg_offsetis zero here, you'll read garbageQuoted 6 lines
- return 0;
+ ret =spi_nor_read_any_reg(nor, &op, nor->reg_proto); + if (ret) {
+ dev_err(nor->dev, "Failed to read page size configuration. Use default 256B.\n");
+ return;
Quoted 3 lines
why did we consider a no-go error and exited in the past and now we just use a default config?
we should instead allow parse_sfdp to return errors. I'm sending a patch shortly.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 5/8 mtd: spi-nor: spansion: Rework cypress_nor_quad_enable_volatile() for multi-chip device support
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we need to enable QUAD by updating CFR1V in all dice in the device. That is done by for-loop with params->num_of_dice. The volatile register address is calculated inside the loop by using die number and volatile register offset.
--- drivers/mtd/spi-nor/spansion.c | 65 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 32 deletions(-)
drivers/mtd/spi-nor/spansion.c +33 -32
@@ -14,7 +14,7 @@#define SPINOR_OP_CLSR 0x30/* Clear status register 1 */ #define SPINOR_OP_RD_ANY_REG 0x65/* Read any register */ #define SPINOR_OP_WR_ANY_REG 0x71/* Write any register */ -#define SPINOR_REG_CYPRESS_CFR1V 0x00800002 +#define SPINOR_REG_CYPRESS_CFR1 0x2#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ #define SPINOR_REG_CYPRESS_CFR2V 0x00800003#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb
@@ -142,46 +142,47 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)static int cypress_nor_quad_enable_volatile (struct spi_nor *nor) {struct spi_mem_op op; +u32 addr; +u8 i;u8 addr_mode_nbytes = nor->params->addr_mode_nbytes;u8 cfr1v_written;int ret; - op = (struct spi_mem_op ) -CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR1V , - nor->bouncebuf); - - ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); -if (ret) -return ret; +for (i =0 ; i < nor->params->num_of_dice; i++) { + addr = nor->params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR1 ; + op = (struct spi_mem_op ) +CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, addr, + nor->bouncebuf); + ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); +if (ret) +return ret; -if (nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR1_QUAD_EN ) -return 0 ; +if (nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR1_QUAD_EN ) +continue ; -/* Update the Quad Enable bit. */ - nor->bouncebuf[0 ] |=SPINOR_REG_CYPRESS_CFR1_QUAD_EN ; - op = (struct spi_mem_op ) -CYPRESS_NOR_WR_ANY_REG_OP (addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR1V ,1 , - nor->bouncebuf); - ret =spi_nor_write_any_volatile_reg (nor, &op, nor->reg_proto); -if (ret) -return ret; +/* Update the Quad Enable bit. */ + nor->bouncebuf[0 ] |=SPINOR_REG_CYPRESS_CFR1_QUAD_EN ; + op = (struct spi_mem_op ) +CYPRESS_NOR_WR_ANY_REG_OP (addr_mode_nbytes, addr,1 , + nor->bouncebuf); + ret =spi_nor_write_any_volatile_reg (nor, &op, nor->reg_proto); +if (ret) +return ret; - cfr1v_written = nor->bouncebuf[0 ]; + cfr1v_written = nor->bouncebuf[0 ]; -/* Read back and check it. */ - op = (struct spi_mem_op ) -CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR1V , - nor->bouncebuf); - ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); -if (ret) -return ret; +/* Read back and check it. */ + op = (struct spi_mem_op ) +CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, addr, + nor->bouncebuf); + ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); +if (ret) +return ret; -if (nor->bouncebuf[0 ] != cfr1v_written) { -dev_err (nor->dev,"CFR1: Read back test failed\n" ); -return -EIO ; +if (nor->bouncebuf[0 ] != cfr1v_written) { +dev_err (nor->dev,"CFR1: Read back test failed\n" ); +return -EIO ; + } }return 0 ;
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 5/8] mtd: spi-nor: spansion: Rework cypress_nor_quad_enable_volatile() for multi-chip device support
Quoted 35 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we need to enable QUAD by updating CFR1V in all dice in the device. That is done by for-loop with
params->num_of_dice. The volatile register address is calculated inside the loop by using die number and volatile register offset.Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/spansion.c | 65 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 32 deletions(-)drivers/mtd/spi-nor/spansion.c +3
-1@@ -14,7 +14,7 @@#define SPINOR_OP_CLSR 0x30/* Clear status register 1 */ #define SPINOR_OP_RD_ANY_REG 0x65/* Read any register */ #define SPINOR_OP_WR_ANY_REG 0x71/* Write any register */ -#define SPINOR_REG_CYPRESS_CFR1V 0x00800002 +#define SPINOR_REG_CYPRESS_CFR1 0x2#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ #define SPINOR_REG_CYPRESS_CFR2V 0x00800003#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb@@ -142,46 +142,47 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)static int cypress_nor_quad_enable_volatile (struct spi_nor *nor) {struct spi_mem_op op; +u32 addr; +u8 i;u8 addr_mode_nbytes = nor->params->addr_mode_nbytes;u8 cfr1v_written;int ret;
drivers/mtd/spi-nor/spansion.c static int cypress_nor_octal_dtr_dis(struct spi_nor *nor) · line 152
Quoted 10 lines
drivers/mtd/spi-nor/spansion.c +2
-8- op = (struct spi_mem_op ) -CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR1V , - nor->bouncebuf); - - ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); -if (ret) -return ret; +for (i =0 ; i < nor->params->num_of_dice; i++) { + addr = nor->params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR1 ;
the same note, you should consider what happens when all the optional tables fail.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 6/8 mtd: spi-nor: spansion: Add a new ->ready() hook for multi-chip device
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we need to make sure the all dice in the device are ready. The cypress_nor_sr_ready_and_clear() reads SR in each die and returns true only when all dice are ready. This function also takes care for program or erase error handling by reusing spansion_nor_clear_sr(). To do that, spansion_nor_clear_sr() is moved to top.
--- drivers/mtd/spi-nor/spansion.c | 96 ++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 23 deletions(-)
drivers/mtd/spi-nor/spansion.c +73 -23
@@ -14,6 +14,7 @@#define SPINOR_OP_CLSR 0x30/* Clear status register 1 */ #define SPINOR_OP_RD_ANY_REG 0x65/* Read any register */ #define SPINOR_OP_WR_ANY_REG 0x71/* Write any register */ +#define SPINOR_REG_CYPRESS_STR1 0x0#define SPINOR_REG_CYPRESS_CFR1 0x2#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ #define SPINOR_REG_CYPRESS_CFR2V 0x00800003
@@ -49,6 +50,74 @@ SPI_MEM_OP_NO_DUMMY, \ SPI_MEM_OP_NO_DATA) +/** +* spansion_nor_clear_sr() - Clear the Status Register. +* @nor: pointer to 'struct spi_nor'. +*/ +static void spansion_nor_clear_sr (struct spi_nor *nor) +{ +int ret; + +if (nor->spimem) { +struct spi_mem_op op =SPANSION_CLSR_OP ; + +spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); + + ret =spi_mem_exec_op (nor->spimem, &op); + }else { + ret =spi_nor_controller_ops_write_reg (nor,SPINOR_OP_CLSR , +NULL ,0 ); + } + +if (ret) +dev_dbg (nor->dev,"error %d clearing SR\n" , ret); +} + +/** +* cypress_nor_sr_ready_and_clear() - Query the Status Register of each die by +* using Read Any Register command to see if the whole flash is ready for new +* commands and clear it if there are any errors. +* @nor: pointer to 'struct spi_nor'. +* +* Return: 1 if ready, 0 if not ready, -errno on errors. +*/ +static int cypress_nor_sr_ready_and_clear (struct spi_nor *nor) +{ +struct spi_mem_op op = +CYPRESS_NOR_RD_ANY_REG_OP (nor->params->addr_mode_nbytes,0 , + nor->bouncebuf); +int ret; +u8 i; + +for (i =0 ; i < nor->params->num_of_dice; i++) { + op.addr.val = + nor->params->vreg_offset[i] +SPINOR_REG_CYPRESS_STR1 ; + ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); +if (ret) +return ret; + +if (nor->bouncebuf[0 ] & (SR_E_ERR |SR_P_ERR )) { +if (nor->bouncebuf[0 ] &SR_E_ERR ) +dev_err (nor->dev,"Erase Error occurred\n" ); +else +dev_err (nor->dev,"Programming Error occurred\n" ); + +spansion_nor_clear_sr (nor); + + ret =spi_nor_write_disable (nor); +if (ret) +return ret; + +return -EIO ; + } + +if (nor->bouncebuf[0 ] &SR_WIP ) +return 0 ; + } + +return 1 ; +} +static int cypress_nor_octal_dtr_en (struct spi_nor *nor) {struct spi_mem_op op;
@@ -272,6 +341,10 @@ static void s25hx_t_late_init(struct spi_nor *nor)/* The writesize should be ECC data unit size */ params->writesize =16 ; + +/* Replace ready() with multi die version */ +if (nor->params->num_of_dice >1 ) + nor->params->ready = cypress_nor_sr_ready_and_clear; }static struct spi_nor_fixups s25hx_t_fixups = {
@@ -486,29 +559,6 @@ static const struct flash_info spansion_nor_parts[] = { }, }; -/** -* spansion_nor_clear_sr() - Clear the Status Register. -* @nor: pointer to 'struct spi_nor'. -*/ -static void spansion_nor_clear_sr (struct spi_nor *nor) -{ -int ret; - -if (nor->spimem) { -struct spi_mem_op op =SPANSION_CLSR_OP ; - -spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); - - ret =spi_mem_exec_op (nor->spimem, &op); - }else { - ret =spi_nor_controller_ops_write_reg (nor,SPINOR_OP_CLSR , -NULL ,0 ); - } - -if (ret) -dev_dbg (nor->dev,"error %d clearing SR\n" , ret); -} -/** * spansion_nor_sr_ready_and_clear() - Query the Status Register to see if the * flash is ready for new commands and clear it if there are any errors.
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 6/8] mtd: spi-nor: spansion: Add a new ->ready() hook for multi-chip device
Quoted 51 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
For multi-chip devices, we need to make sure the all dice in the device are ready. The
cypress_nor_sr_ready_and_clear()reads SR in each die and returns true only when all dice are ready. This function also takes care for program or erase error handling by reusingspansion_nor_clear_sr(). To do that,spansion_nor_clear_sr()is moved to top.Signed-off-by Takahiro Kuwano <[email protected]>--- drivers/mtd/spi-nor/spansion.c | 96 ++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 23 deletions(-)drivers/mtd/spi-nor/spansion.c +23
-0@@ -14,6 +14,7 @@#define SPINOR_OP_CLSR 0x30/* Clear status register 1 */ #define SPINOR_OP_RD_ANY_REG 0x65/* Read any register */ #define SPINOR_OP_WR_ANY_REG 0x71/* Write any register */ +#define SPINOR_REG_CYPRESS_STR1 0x0#define SPINOR_REG_CYPRESS_CFR1 0x2#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ #define SPINOR_REG_CYPRESS_CFR2V 0x00800003@@ -49,6 +50,74 @@ SPI_MEM_OP_NO_DUMMY, \ SPI_MEM_OP_NO_DATA) +/** +* spansion_nor_clear_sr() - Clear the Status Register. +* @nor: pointer to 'struct spi_nor'. +*/ +static void spansion_nor_clear_sr (struct spi_nor *nor) +{ +int ret; + +if (nor->spimem) { +struct spi_mem_op op =SPANSION_CLSR_OP ; + +spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); + + ret =spi_mem_exec_op (nor->spimem, &op); + }else { + ret =spi_nor_controller_ops_write_reg (nor,SPINOR_OP_CLSR , +NULL ,0 ); + } + +if (ret) +dev_dbg (nor->dev,"error %d clearing SR\n" , ret); +}
drivers/mtd/spi-nor/spansion.c line 84
Quoted 10 lines
drivers/mtd/spi-nor/spansion.c +10
-0+ +/** +* cypress_nor_sr_ready_and_clear() - Query the Status Register of each die by +* using Read Any Register command to see if the whole flash is ready for new +* commands and clear it if there are any errors. +* @nor: pointer to 'struct spi_nor'. +* +* Return: 1 if ready, 0 if not ready, -errno on errors. +*/ +static int cypress_nor_sr_ready_and_clear (struct spi_nor *nor)
we could rename this to cypress_nor_md_sr_ready_and_clear to indicate it's solely used for multi die devices.
drivers/mtd/spi-nor/spansion.c line 92
Quoted 8 lines
drivers/mtd/spi-nor/spansion.c +8
-0+{ +struct spi_mem_op op = +CYPRESS_NOR_RD_ANY_REG_OP (nor->params->addr_mode_nbytes,0 , + nor->bouncebuf); +int ret; +u8 i; + +for (i =0 ; i < nor->params->num_of_dice; i++) {
as long as you rollback the num of dice to 1 in case of errors in the sccr tables, this should be fine.
Looks fine.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 7/8 mtd: spi-nor: spansion: Set params->addr_mode_nbytes = 4 for multi-die parts
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
The params->addr_mode_nbytes is set to 3 during BFPT parse in case of BFPT_DWORD1_ADDRESS_BYTES_3_OR_4. Infineon SEMPER multi-chip devices are in 3- or 4-byte address mode by factory default, depending on model number. 3-byte address mode is for backward compatibility for some SoCs. Since we cannot access to registers in 2nd die by 3-byte addressing. We assume post BootRom programs change the address mode to 4 before hand-off.
--- drivers/mtd/spi-nor/spansion.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/mtd/spi-nor/spansion.c +12 -0
@@ -303,6 +303,18 @@ s25hx_t_post_bfpt_fixup(struct spi_nor *nor,/* Replace Quad Enable with volatile version */ nor->params->quad_enable = cypress_nor_quad_enable_volatile; +/* +* The factory default of address mode in multi-die parts (>128MB) may +* be 3- or 4-byte, depending on model number. Since register address of +* 2nd die is mappeted to 32-bit address space, we cannot access to +* registers in 2nd die in 3-byte mode. 3-byte mode is for backward +* compatibility as some SoCs use 3-byte address in their BootROM. So +* far we assume post BootROM programs change the address mode to 4 +* before handing off, rather than calling set_4byte_addr_mode() here. +*/ +if (nor->params->size >SZ_128M ) + nor->params->addr_mode_nbytes =4 ; +return 0 ; }
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 7/8] mtd: spi-nor: spansion: Set params->addr_mode_nbytes = 4 for multi-die parts
Quoted 5 lines · On 08.02.2023 07:53, [email protected] wrote:
From: Takahiro Kuwano <[email protected]>
The
params->addr_mode_nbytesis set to 3 during BFPT parse in case ofBFPT_DWORD1_ADDRESS_BYTES_3_OR_4. Infineon SEMPER multi-chip devices are in 3- or 4-byte address mode by factory default, depending on model number.
are the models differentiated by unique IDs?
Quoted 3 lines
3-byte address mode is for backward compatibility for some SoCs. Since we cannot access to registers in 2nd die by 3-byte addressing. We assume post BootRom programs change the address mode to 4 before hand-off.
no, we can't make this assumption. The only assumption that we may accept is that the flash is at the factory default settings. But this is fragile too, because one can configure the flash in a non volatile way and change the factory default settings. You can't add support for flashes that come with 3 byte address mode by default without discovering the address mode at run-time.
Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 8/8 mtd: spi-nor: spansion: Add support for Infineon
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
s25hl02gt and s25hs02gt
Add ID, flags, and fixup for s25hl02gt and s25hs02gt. These parts are
- Dual-die package parts
- Not support chip erase
- 4-byte addressing mode by default
- Wrong param in SCCR map that needs to be fixed
--- drivers/mtd/spi-nor/spansion.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/mtd/spi-nor/spansion.c +12 -0
@@ -341,6 +341,10 @@ static void s25hx_t_post_sfdp_fixup(struct spi_nor *nor) } } +/* Fix the number of dice that is wrongly advertised in 2Gb parts. */ +if (nor->params->size ==SZ_256M ) + nor->params->num_of_dice =2 ; +cypress_nor_set_page_size (nor); }
@@ -543,6 +547,10 @@ static const struct flash_info spansion_nor_parts[] = { PARSE_SFDP MFR_FLAGS(USE_CLSR) .fixups = &s25hx_t_fixups }, + { "s25hl02gt", INFO6(0x342a1c, 0x0f0090, 0, 0) + PARSE_SFDP + FLAGS(NO_CHIP_ERASE) + .fixups = &s25hx_t_fixups }, { "s25hs512t", INFO6(0x342b1a, 0x0f0390, 256 * 1024, 256)PARSE_SFDP MFR_FLAGS (USE_CLSR )
@@ -551,6 +559,10 @@ static const struct flash_info spansion_nor_parts[] = { PARSE_SFDP MFR_FLAGS(USE_CLSR) .fixups = &s25hx_t_fixups }, + { "s25hs02gt", INFO6(0x342b1c, 0x0f0090, 0, 0) + PARSE_SFDP + FLAGS(NO_CHIP_ERASE) + .fixups = &s25hx_t_fixups }, { "cy15x104q", INFO6(0x042cc2, 0x7f7f7f, 512 * 1024, 1) FLAGS(SPI_NOR_NO_ERASE) }, {"s28hl512t" ,INFO (0x345a1a ,0 ,256 *1024 ,256 )
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/