mtd: spi-nor: Add support for Infineon SEMPER s25hl02gt and s25hs02gt
Subsystems (2)
v3 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 v3
- include Tudor's prerequisite patches: "mtd: spi-nor: spansion: Rename method to cypress_nor_get_page_size" "mtd: spi-nor: Allow post_sfdp hook to return errors"
- s/num_of_dice/n_dice
- fix typos in "mtd: spi-nor: core: Introduce number of dice and volatile register offset params"
- use SFDP_DWORD() for SFDP indexes
- limit the number of dices to 256 as a higher number of dices is improbable, thus we assume the table value is wrong
- reworked common methods for multi-chip devices and single chip devices. When SCCR or SCCR_MC are fined use the value of the Volatile Register offsets defined in the tables, otherwise use the statically defined ones from the driver.
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 (6):
mtd: spi-nor: 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: Add support for Infineon
Tudor Ambarus (2):
mtd: spi-nor: spansion: Rename method to cypress_nor_get_page_size
mtd: spi-nor: Allow post_sfdp hook to return errors
drivers/mtd/spi-nor/core.h | 6 +- drivers/mtd/spi-nor/micron-st.c | 4 +- drivers/mtd/spi-nor/sfdp.c | 103 +++++++++++- drivers/mtd/spi-nor/spansion.c | 281 ++++++++++++++++++++++++-------- 4 files changed, 319 insertions(+), 75 deletions(-)
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 1/8 mtd: spi-nor: spansion: Rename method to cypress_nor_get_page_size
From: Tudor Ambarus <[email protected]>
The method queries SPINOR_REG_CYPRESS_CFR3V to determine the page size. Rename the method accordingly, s/set/get.
--- drivers/mtd/spi-nor/spansion.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/mtd/spi-nor/spansion.c +5 -6
@@ -302,8 +302,7 @@ static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor) }/** -* cypress_nor_set_page_size() - Set page size which corresponds to the flash -* configuration. +* cypress_nor_get_page_size() - Get flash page size configuration. * @nor: pointer to a 'struct spi_nor' * * The BFPT table advertises a 512B or 256B page size depending on part but the
@@ -312,7 +311,7 @@ static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor)* * Return: 0 on success, -errno otherwise. */ -static int cypress_nor_set_page_size (struct spi_nor *nor) +static int cypress_nor_get_page_size (struct spi_nor *nor) {struct spi_mem_op op = CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes,
@@ -368,7 +367,7 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor,if (nor->bouncebuf[0 ])return -ENODEV ; -return cypress_nor_set_page_size (nor); +return cypress_nor_get_page_size (nor); }static void s25fs256t_post_sfdp_fixup (struct spi_nor *nor)
@@ -407,7 +406,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 cypress_nor_get_page_size (nor); }static void s25hx_t_post_sfdp_fixup (struct spi_nor *nor)
@@ -502,7 +501,7 @@ static int s28hx_t_post_bfpt_fixup(struct spi_nor *nor,if (ret)return ret; -return cypress_nor_set_page_size (nor); +return cypress_nor_get_page_size (nor); }static void s28hx_t_late_init (struct spi_nor *nor)
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 2/8 mtd: spi-nor: Allow post_sfdp hook to return errors
In reply to [email protected]From: Tudor Ambarus <[email protected]>
Multi die flashes like s25hl02gt need to determine the page_size at run-time by querying a configuration register for each die. Since the number of dice is determined in an optional SFDP table, SCCR MC, the page size configuration must be done in the post_sfdp hook. Allow post_sfdp to return errors, as reading the configuration register might return errors.
--- drivers/mtd/spi-nor/core.h | 2 +- drivers/mtd/spi-nor/micron-st.c | 4 +++- drivers/mtd/spi-nor/sfdp.c | 17 ++++++++++++----- drivers/mtd/spi-nor/spansion.c | 12 +++++++++--- 4 files changed, 25 insertions(+), 10 deletions(-)
drivers/mtd/spi-nor/core.h +1 -1
@@ -426,7 +426,7 @@ struct spi_nor_fixups {int (*post_bfpt)(struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header,const struct sfdp_bfpt *bfpt); -void (*post_sfdp)(struct spi_nor *nor); +int (*post_sfdp)(struct spi_nor *nor);void (*late_init)(struct spi_nor *nor); };
drivers/mtd/spi-nor/micron-st.c +3 -1
@@ -131,7 +131,7 @@ static void mt35xu512aba_default_init(struct spi_nor *nor) nor->params->octal_dtr_enable = micron_st_nor_octal_dtr_enable; } -static void mt35xu512aba_post_sfdp_fixup (struct spi_nor *nor) +static int mt35xu512aba_post_sfdp_fixup (struct spi_nor *nor) {/* Set the Fast Read settings. */ nor->params->hwcaps.mask |=SNOR_HWCAPS_READ_8_8_8_DTR ;
@@ -149,6 +149,8 @@ static void mt35xu512aba_post_sfdp_fixup(struct spi_nor *nor)* disable it. */ nor->params->quad_enable =NULL ; + +return 0 ; }static const struct spi_nor_fixups mt35xu512aba_fixups = {
drivers/mtd/spi-nor/sfdp.c +12 -5
@@ -1260,14 +1260,21 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,* Used to tweak various flash parameters when information provided by the SFDP * tables are wrong. */ -static void spi_nor_post_sfdp_fixups (struct spi_nor *nor) +static int spi_nor_post_sfdp_fixups (struct spi_nor *nor) { +int ret; +if (nor->manufacturer && nor->manufacturer->fixups && - nor->manufacturer->fixups->post_sfdp) - nor->manufacturer->fixups->post_sfdp (nor); + nor->manufacturer->fixups->post_sfdp) { + ret = nor->manufacturer->fixups->post_sfdp (nor); +if (ret) +return ret; + }if (nor->info->fixups && nor->info->fixups->post_sfdp) - nor->info->fixups->post_sfdp (nor); +return nor->info->fixups->post_sfdp (nor); + +return 0 ; }/**
@@ -1477,7 +1484,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor) } } -spi_nor_post_sfdp_fixups (nor); + err =spi_nor_post_sfdp_fixups (nor); exit:kfree (param_headers);return err;
drivers/mtd/spi-nor/spansion.c +9 -3
@@ -370,7 +370,7 @@ s25fs256t_post_bfpt_fixup(struct spi_nor *nor,return cypress_nor_get_page_size (nor); } -static void s25fs256t_post_sfdp_fixup (struct spi_nor *nor) +static int s25fs256t_post_sfdp_fixup (struct spi_nor *nor) {struct spi_nor_flash_parameter *params = nor->params;
@@ -379,6 +379,8 @@ static void s25fs256t_post_sfdp_fixup(struct spi_nor *nor)spi_nor_set_pp_settings (¶ms->page_programs[SNOR_CMD_PP_1_1_4 ],SPINOR_OP_PP_1_1_4_4B ,SNOR_PROTO_1_1_4 ); + +return 0 ; }static void s25fs256t_late_init (struct spi_nor *nor)
@@ -409,7 +411,7 @@ s25hx_t_post_bfpt_fixup(struct spi_nor *nor,return cypress_nor_get_page_size (nor); } -static void s25hx_t_post_sfdp_fixup (struct spi_nor *nor) +static int s25hx_t_post_sfdp_fixup (struct spi_nor *nor) {struct spi_nor_erase_type *erase_type = nor->params->erase_map.erase_type;
@@ -431,6 +433,8 @@ static void s25hx_t_post_sfdp_fixup(struct spi_nor *nor)break ; } } + +return 0 ; }static void s25hx_t_late_init (struct spi_nor *nor)
@@ -463,7 +467,7 @@ static int cypress_nor_octal_dtr_enable(struct spi_nor *nor, bool enable)cypress_nor_octal_dtr_dis (nor); } -static void s28hx_t_post_sfdp_fixup (struct spi_nor *nor) +static int s28hx_t_post_sfdp_fixup (struct spi_nor *nor) {/* * On older versions of the flash the xSPI Profile 1.0 table has the
@@ -489,6 +493,8 @@ static void s28hx_t_post_sfdp_fixup(struct spi_nor *nor)* actual value for that is 4. */ nor->params->rdsr_addr_nbytes =4 ; + +return 0 ; } static int s28hx_t_post_bfpt_fixup(struct spi_nor *nor,
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 3/8 mtd: spi-nor: Extract volatile register offset from SCCR map
In reply to [email protected]From: Takahiro Kuwano <[email protected]>
In use of multi-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 offsets for each die are essential to iterate register access ops.
The volatile register offset for the first die 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/core.h | 4 ++++ drivers/mtd/spi-nor/sfdp.c | 13 +++++++++++++ 2 files changed, 17 insertions(+)
drivers/mtd/spi-nor/core.h +4 -0
@@ -352,6 +352,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. +* @n_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
@@ -385,6 +387,8 @@ struct spi_nor_flash_parameter {u8 addr_mode_nbytes;u8 rdsr_dummy;u8 rdsr_addr_nbytes; +u8 n_dice; +u32 *vreg_offset;struct spi_nor_hwcaps hwcaps;struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ];
drivers/mtd/spi-nor/sfdp.c +13 -0
@@ -1226,6 +1226,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;
@@ -1242,6 +1243,18 @@ 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[SFDP_DWORD (1 )]; + params->n_dice =1 ; +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.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 4/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 | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
drivers/mtd/spi-nor/sfdp.c +73 -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
@@ -1264,6 +1269,70 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,return ret; } +#define SCCR_MC_MAX_DICE 255 + +/** +* 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; +u8 i, n_dice; +size_t len; +int ret; + + 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). +*/ + n_dice =1 + sccr_mc_header->length /2 ; +if (params->n_dice >SCCR_MC_MAX_DICE ) { +dev_dbg (nor->dev,"Improbable number of dice defined in SCCR MC table, use one die.\n" ); + ret = -EINVAL ; + goto out; + } + +/* Address offset for volatile registers of additional dice */ + params->vreg_offset = +devm_krealloc (nor->dev, params->vreg_offset, + n_dice *sizeof (*dwords), +GFP_KERNEL ); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out; + } + +for (i =1 ; i < n_dice; i++) + params->vreg_offset[i] = dwords[SFDP_DWORD (i) *2 ]; + + params->n_dice = n_dice; + +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
@@ -1480,6 +1549,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.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 4/8] mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
Quoted 65 lines · On 4/6/23 07:18, [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 | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)drivers/mtd/spi-nor/sfdp.c +34
-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@@ -1264,6 +1269,70 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,return ret; } +#define SCCR_MC_MAX_DICE 255 + +/** +* 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; +u8 i, n_dice; +size_t len; +int ret; + + 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)
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1310
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +10
-0+ 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). +*/ + n_dice =1 + sccr_mc_header->length /2 ; +if (params->n_dice >SCCR_MC_MAX_DICE ) {
smatch warnings:drivers/mtd/spi-nor/sfdp.c:1310 spi_nor_parse_sccr_mc() warn: impossible condition '(params->n_dice > 255) => (0-255 > 255)'
declaring the local variable n_dice as unsigned int should solve the problem.
Quoted 9 lines
drivers/mtd/spi-nor/sfdp.c +9
-0+dev_dbg (nor->dev,"Improbable number of dice defined in SCCR MC table, use one die.\n" ); + ret = -EINVAL ; + goto out; + } + +/* Address offset for volatile registers of additional dice */ + params->vreg_offset = + devm_krealloc(nor->dev, params->vreg_offset, + n_dice * sizeof(*dwords),
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1329
Quoted 10 lines
drivers/mtd/spi-nor/sfdp.c +10
-0+ GFP_KERNEL); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out; + } + +for (i =1 ; i < n_dice; i++) + params->vreg_offset[i] = dwords[SFDP_DWORD (i) *2 ]; + + params->n_dice = n_dice;
we then truncate it to u8, which is fine.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 4/8] mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
Hi Tudor,
Quoted 70 lines · Tudor Ambarus
Quoted 67 lines · On 4/6/23 07:18, [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 | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)drivers/mtd/spi-nor/sfdp.c +36
-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@@ -1264,6 +1269,70 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,return ret; } +#define SCCR_MC_MAX_DICE 255 + +/** +* 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; +u8 i, n_dice; +size_t len; +int ret; + + 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; +
Quoted 8 lines
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1310
Quoted 8 lines
drivers/mtd/spi-nor/sfdp.c +8
-0+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). +*/ + n_dice =1 + sccr_mc_header->length /2 ; +if (params->n_dice >SCCR_MC_MAX_DICE ) {
s/params->n_dice/n_dice
Quoted 8 lines
smatch warnings:
drivers/mtd/spi-nor/sfdp.c:1310spi_nor_parse_sccr_mc()warn: impossible condition '(params->n_dice> 255) => (0-255 > 255)'declaring the local variable
n_diceas unsigned int should solve the problem.
'sccr_mc_header->length' is u8 so n_dice can be 1-128. We can keep n_dice as u8.
(n_dice > SCCR_MC_MAX_DICE) is impossible condition anyway... We don't need n_dice check. Otherwise define SCCR_MC_MAX_DICE as smaller value something like 16. What do you think?
Quoted 13 lines
Quoted 13 lines
drivers/mtd/spi-nor/sfdp.c +13
-0+dev_dbg (nor->dev,"Improbable number of dice defined in SCCR MC table, use one die.\n" ); + ret = -EINVAL ; + goto out; + } + +/* Address offset for volatile registers of additional dice */ + params->vreg_offset = +devm_krealloc (nor->dev, params->vreg_offset, + n_dice *sizeof (*dwords), +GFP_KERNEL ); +if (!params->vreg_offset) { + ret = -ENOMEM ; + goto out;
Quoted 8 lines
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1329
Quoted 6 lines
drivers/mtd/spi-nor/sfdp.c +6
-0+ } + +for (i =1 ; i < n_dice; i++) + params->vreg_offset[i] = dwords[SFDP_DWORD (i) *2 ]; + + params->n_dice = n_dice;we then truncate it to u8, which is fine.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v3 4/8] mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device
Quoted 2 lines · Takahiro Kuwano
Hi Tudor,
Hi!
Quoted 89 lines · Tudor Ambarus
Quoted 70 lines · On 4/6/23 07:18, [email protected] wrote:
Quoted 67 lines
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 | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)drivers/mtd/spi-nor/sfdp.c +36
-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@@ -1264,6 +1269,70 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,return ret; } +#define SCCR_MC_MAX_DICE 255 + +/** +* 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; +u8 i, n_dice; +size_t len; +int ret; + + 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; +Quoted 8 lines
drivers/mtd/spi-nor/sfdp.c static int spi_nor_parse_sccr(struct spi_nor *nor, · line 1310
Quoted 8 lines
drivers/mtd/spi-nor/sfdp.c +8
-0+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). +*/ + n_dice =1 + sccr_mc_header->length /2 ; +if (params->n_dice >SCCR_MC_MAX_DICE ) {s/params->n_dice/n_dice
Quoted 8 lines
smatch warnings:
drivers/mtd/spi-nor/sfdp.c:1310spi_nor_parse_sccr_mc()warn: impossible condition '(params->n_dice> 255) => (0-255 > 255)'declaring the local variable
n_diceas unsigned int should solve the problem.
Quoted 7 lines
'
sccr_mc_header->length' is u8 son_dicecan be 1-128. We can keepn_diceas u8.(
n_dice>SCCR_MC_MAX_DICE) is impossible condition anyway... We don't needn_dicecheck. Otherwise defineSCCR_MC_MAX_DICEas smaller value something like 16. What do you think?
Indeed. Let's get rid of the check entirely. Keep n_dice as u8, remove SCCR_MC_MAX_DICE and the check.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 5/8 mtd: spi-nor: spansion: Rework cypress_nor_get_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. The volatile register address is calculated by using the volatile register addresses retrieved from the SCCR tables and the (configuration) 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 in the optional SCCR tables.
--- drivers/mtd/spi-nor/spansion.c | 89 ++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 20 deletions(-)
drivers/mtd/spi-nor/spansion.c +69 -20
@@ -14,15 +14,26 @@#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_STR1V 0x00800000 -#define SPINOR_REG_CYPRESS_CFR1V 0x00800002 +#define SPINOR_REG_CYPRESS_VREG 0x00800000 +#define SPINOR_REG_CYPRESS_STR1 0x0 +#define SPINOR_REG_CYPRESS_STR1V \ + (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_STR1) +#define SPINOR_REG_CYPRESS_CFR1 0x2 +#define SPINOR_REG_CYPRESS_CFR1V \ + (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_CFR1)#define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1)/* Quad Enable */ -#define SPINOR_REG_CYPRESS_CFR2V 0x00800003 +#define SPINOR_REG_CYPRESS_CFR2 0x3 +#define SPINOR_REG_CYPRESS_CFR2V \ + (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_CFR2)#define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb#define SPINOR_REG_CYPRESS_CFR2_ADRBYT BIT(7) -#define SPINOR_REG_CYPRESS_CFR3V 0x00800004 +#define SPINOR_REG_CYPRESS_CFR3 0x4 +#define SPINOR_REG_CYPRESS_CFR3V \ + (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_CFR3)#define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4)/* Page size. */ -#define SPINOR_REG_CYPRESS_CFR5V 0x00800006 +#define SPINOR_REG_CYPRESS_CFR5 0x6 +#define SPINOR_REG_CYPRESS_CFR5V \ + (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_CFR5)#define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6)#define SPINOR_REG_CYPRESS_CFR5_DDR BIT(1)#define SPINOR_REG_CYPRESS_CFR5_OPI BIT(0)
@@ -301,17 +312,7 @@ static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor)return 0 ; } -/** -* cypress_nor_get_page_size() - Get flash page size configuration. -* @nor: pointer to a 'struct spi_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_get_page_size (struct spi_nor *nor) +static int cypress_nor_get_page_size_single_chip (struct spi_nor *nor) {struct spi_mem_op op = CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes,
@@ -331,6 +332,54 @@ static int cypress_nor_get_page_size(struct spi_nor *nor)return 0 ; } + +static int cypress_nor_get_page_size_mcp (struct spi_nor *nor) +{ +struct spi_mem_op op = +CYPRESS_NOR_RD_ANY_REG_OP (nor->params->addr_mode_nbytes, +0 ,0 , nor->bouncebuf); +struct spi_nor_flash_parameter *params = nor->params; +int ret; +u8 i; + +/* +* Use the minimum common page size configuration. Programming 256-byte +* under 512-byte page size configuration is safe. +*/ + params->page_size =256 ; +for (i =0 ; i < params->n_dice; i++) { + op.addr.val = params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR3 ; + + ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto); +if (ret) +return ret; + +if (!(nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR3_PGSZ )) +return 0 ; + } + + params->page_size =512 ; + +return 0 ; +} + +/** +* cypress_nor_get_page_size() - Get flash page size configuration. +* @nor: pointer to a 'struct spi_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_get_page_size (struct spi_nor *nor) +{ +if (nor->params->n_dice) +return cypress_nor_get_page_size_mcp (nor); +return cypress_nor_get_page_size_single_chip (nor); +} +static void cypress_nor_ecc_init (struct spi_nor *nor) {/*
@@ -408,7 +457,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_get_page_size (nor); +return 0 ; }static int s25hx_t_post_sfdp_fixup (struct spi_nor *nor)
@@ -434,7 +483,7 @@ static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor) } } -return 0 ; +return cypress_nor_get_page_size (nor); }static void s25hx_t_late_init (struct spi_nor *nor)
@@ -494,7 +543,7 @@ static int s28hx_t_post_sfdp_fixup(struct spi_nor *nor)*/ nor->params->rdsr_addr_nbytes =4 ; -return 0 ; +return cypress_nor_get_page_size (nor); } static int s28hx_t_post_bfpt_fixup(struct spi_nor *nor,
@@ -507,7 +556,7 @@ static int s28hx_t_post_bfpt_fixup(struct spi_nor *nor,if (ret)return ret; -return cypress_nor_get_page_size (nor); +return 0 ; }static void s28hx_t_late_init (struct spi_nor *nor)
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 6/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]>
Rework quad method for multi-chip devices by updating CFR1V in all dice in the device.
--- drivers/mtd/spi-nor/spansion.c | 60 ++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 21 deletions(-)
drivers/mtd/spi-nor/spansion.c +39 -21
@@ -139,21 +139,7 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)return 0 ; } -/** -* cypress_nor_quad_enable_volatile() - enable Quad I/O mode in volatile -* register. -* @nor: pointer to a 'struct spi_nor' -* -* 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. -* -* Return: 0 on success, -errno otherwise. -*/ -static int cypress_nor_quad_enable_volatile (struct spi_nor *nor) +static int cypress_nor_quad_enable_volatile_reg (struct spi_nor *nor,u64 addr) {struct spi_mem_op op;u8 addr_mode_nbytes = nor->params->addr_mode_nbytes;
@@ -161,8 +147,7 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor)int ret; op = (struct spi_mem_op ) -CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR1V ,0 , +CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, addr,0 , nor->bouncebuf); ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto);
@@ -175,8 +160,7 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor)/* 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 , +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)
@@ -186,8 +170,7 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor)/* Read back and check it. */ op = (struct spi_mem_op ) -CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, -SPINOR_REG_CYPRESS_CFR1V ,0 , +CYPRESS_NOR_RD_ANY_REG_OP (addr_mode_nbytes, addr,0 , nor->bouncebuf); ret =spi_nor_read_any_reg (nor, &op, nor->reg_proto);if (ret)
@@ -201,6 +184,41 @@ static int cypress_nor_quad_enable_volatile(struct spi_nor *nor)return 0 ; } +/** +* cypress_nor_quad_enable_volatile() - enable Quad I/O mode in volatile +* register. +* @nor: pointer to a 'struct spi_nor' +* +* 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. +* +* Return: 0 on success, -errno otherwise. +*/ +static int cypress_nor_quad_enable_volatile (struct spi_nor *nor) +{ +struct spi_nor_flash_parameter *params = nor->params; +u64 addr; +u8 i; +int ret; + +if (!params->n_dice) +return cypress_nor_quad_enable_volatile_reg (nor, +SPINOR_REG_CYPRESS_CFR1V ); + +for (i =0 ; i < params->n_dice; i++) { + addr = params->vreg_offset[i] +SPINOR_REG_CYPRESS_CFR1 ; + ret =cypress_nor_quad_enable_volatile_reg (nor, addr); +if (ret) +return ret; + } + +return 0 ; +} +/** * cypress_nor_determine_addr_mode_by_sr1() - Determine current address mode * (3 or 4-byte) by querying status
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 7/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 | 109 +++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 24 deletions(-)
drivers/mtd/spi-nor/spansion.c +85 -24
@@ -63,6 +63,84 @@ 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); +} + +static int cypress_nor_sr_ready_and_clear_reg (struct spi_nor *nor,u64 addr) +{ +struct spi_mem_op op = +CYPRESS_NOR_RD_ANY_REG_OP (nor->params->addr_mode_nbytes, addr, +0 , nor->bouncebuf); +int ret; + + 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 ; + } + +return !(nor->bouncebuf[0 ] &SR_WIP ); +} +/** +* 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_nor_flash_parameter *params = nor->params; +u64 addr; +int ret; +u8 i; + +for (i =0 ; i < params->n_dice; i++) { + addr = params->vreg_offset[i] +SPINOR_REG_CYPRESS_STR1 ; + ret =cypress_nor_sr_ready_and_clear_reg (nor, addr); +if (ret <0 ) +return ret; +else if (ret ==0 ) +return 0 ; + } + +return 1 ; +} +static int cypress_nor_octal_dtr_en (struct spi_nor *nor) {struct spi_mem_op op;
@@ -506,10 +584,16 @@ static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor)static void s25hx_t_late_init (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params = nor->params; +/* Fast Read 4B requires mode cycles */ - nor->params->reads[SNOR_CMD_READ_FAST ].num_mode_clocks =8 ; + params->reads[SNOR_CMD_READ_FAST ].num_mode_clocks =8 ;cypress_nor_ecc_init (nor); + +/* Replace ready() with multi die version */ +if (params->n_dice) + params->ready = cypress_nor_sr_ready_and_clear; }static struct spi_nor_fixups s25hx_t_fixups = {
@@ -741,29 +825,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.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v3 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
@@ -579,6 +579,10 @@ static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor) } } +/* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */ +if (nor->params->size ==SZ_256M ) + nor->params->n_dice =2 ; +return cypress_nor_get_page_size (nor); }
@@ -797,6 +801,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 )
@@ -805,6 +813,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.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/