From 792caa4a4baaa9bc3fb59052b30cee08e8bc801d Mon Sep 17 00:00:00 2001 From: Marcus Folkesson Date: Sat, 16 Nov 2024 11:55:55 +0100 Subject: [PATCH 01/10] mtd: spi-nor: atmel: add at25sf321 entry Add entry for the at25sf321 32Mbit SPI flash. This flash is populated on a custom board and was tested at 10MHz frequency using the "ti,da830-spi" SPI controller. Link: https://www.renesas.com/en/document/dst/at25sf321-datasheet?r=1608801 Reviewed-by: Michael Walle Signed-off-by: Marcus Folkesson Reviewed-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241116-spi-nor-v4-1-3de8ac6fd0be@gmail.com --- drivers/mtd/spi-nor/atmel.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/mtd/spi-nor/atmel.c b/drivers/mtd/spi-nor/atmel.c index 45d1153a04a07..82c592f0a1e15 100644 --- a/drivers/mtd/spi-nor/atmel.c +++ b/drivers/mtd/spi-nor/atmel.c @@ -238,6 +238,10 @@ static const struct flash_info atmel_nor_parts[] = { .flags = SPI_NOR_HAS_LOCK, .no_sfdp_flags = SECT_4K, .fixups = &at25fs_nor_fixups + }, { + .id = SNOR_ID(0x1f, 0x87, 0x01), + .size = SZ_4M, + .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ, }, }; From 5be9a36c44cd7e6990631957df523a5059b26bcd Mon Sep 17 00:00:00 2001 From: Tudor Ambarus Date: Mon, 11 Nov 2024 13:36:09 +0200 Subject: [PATCH 02/10] mtd: spi-nor: macronix: use nor->addr_nbytes Use the nor->addr_nbytes set by the core, we shouldn't use magic numbers or states that are not tracked by the core. Signed-off-by: Tudor Ambarus Acked-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241111113609.12093-1-tudor.ambarus@linaro.org --- drivers/mtd/spi-nor/macronix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c index 830da21eea08f..57a40fa70c6a1 100644 --- a/drivers/mtd/spi-nor/macronix.c +++ b/drivers/mtd/spi-nor/macronix.c @@ -230,7 +230,8 @@ static int macronix_nor_octal_dtr_en(struct spi_nor *nor) return ret; /* Read flash ID to make sure the switch was successful. */ - ret = spi_nor_read_id(nor, 4, 4, buf, SNOR_PROTO_8_8_8_DTR); + ret = spi_nor_read_id(nor, nor->addr_nbytes, 4, buf, + SNOR_PROTO_8_8_8_DTR); if (ret) { dev_dbg(nor->dev, "error %d reading JEDEC ID after enabling 8D-8D-8D mode\n", ret); return ret; From e7f4e924f46d41952271b3f97e51596a54e48775 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Mon, 11 Nov 2024 13:19:44 +0200 Subject: [PATCH 03/10] dt-bindings: mtd: jedec,spi-nor: add optional vcc-supply Introduce optional vcc-supply property, SPI NOR flashes needs power supply to work properly. The power supply maybe software controlable per board design. Acked-by: Rob Herring (Arm) Signed-off-by: Peng Fan Signed-off-by: Tudor Ambarus Reviewed-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241111111946.9048-1-tudor.ambarus@linaro.org --- Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml index 6e3afb42926ea..335f8204aa1eb 100644 --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml @@ -96,6 +96,10 @@ properties: If "broken-flash-reset" is present then having this property does not make any difference. + vcc-supply: + description: + Supply for the SPI NOR power. + spi-cpol: true spi-cpha: true From 07c888838ea34662b9fd4a2698ef24ff59f0a630 Mon Sep 17 00:00:00 2001 From: Tudor Ambarus Date: Mon, 11 Nov 2024 13:19:45 +0200 Subject: [PATCH 04/10] mtd: spi-nor: use local variable for struct device Use a local variable for the struct device pointers to avoid dereferencing. Signed-off-by: Tudor Ambarus Reviewed-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241111111946.9048-2-tudor.ambarus@linaro.org --- drivers/mtd/spi-nor/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 66949d9f0cc5a..0b50293fc3734 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3576,7 +3576,8 @@ static int spi_nor_create_write_dirmap(struct spi_nor *nor) static int spi_nor_probe(struct spi_mem *spimem) { struct spi_device *spi = spimem->spi; - struct flash_platform_data *data = dev_get_platdata(&spi->dev); + struct device *dev = &spi->dev; + struct flash_platform_data *data = dev_get_platdata(dev); struct spi_nor *nor; /* * Enable all caps by default. The core will mask them after @@ -3586,13 +3587,13 @@ static int spi_nor_probe(struct spi_mem *spimem) char *flash_name; int ret; - nor = devm_kzalloc(&spi->dev, sizeof(*nor), GFP_KERNEL); + nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL); if (!nor) return -ENOMEM; nor->spimem = spimem; - nor->dev = &spi->dev; - spi_nor_set_flash_node(nor, spi->dev.of_node); + nor->dev = dev; + spi_nor_set_flash_node(nor, dev->of_node); spi_mem_set_drvdata(spimem, nor); @@ -3628,9 +3629,8 @@ static int spi_nor_probe(struct spi_mem *spimem) */ if (nor->params->page_size > PAGE_SIZE) { nor->bouncebuf_size = nor->params->page_size; - devm_kfree(nor->dev, nor->bouncebuf); - nor->bouncebuf = devm_kmalloc(nor->dev, - nor->bouncebuf_size, + devm_kfree(dev, nor->bouncebuf); + nor->bouncebuf = devm_kmalloc(dev, nor->bouncebuf_size, GFP_KERNEL); if (!nor->bouncebuf) return -ENOMEM; From d8bde4fd663667822956ad76dc33f0bbfa57bee8 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Mon, 11 Nov 2024 13:19:46 +0200 Subject: [PATCH 05/10] mtd: spi-nor: support vcc-supply regulator SPI NOR flashes needs power supply to work properly. The power supply maybe software controllable per board design. So add the support for an vcc-supply regulator. Signed-off-by: Peng Fan Reviewed-by: Marco Felsch [ta: move devm_regulator_get_enable() to spi_nor_probe().] Signed-off-by: Tudor Ambarus Reviewed-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241111111946.9048-3-tudor.ambarus@linaro.org --- drivers/mtd/spi-nor/core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 0b50293fc3734..7ba89ffeaf2d0 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -3587,6 +3588,10 @@ static int spi_nor_probe(struct spi_mem *spimem) char *flash_name; int ret; + ret = devm_regulator_get_enable(dev, "vcc"); + if (ret) + return ret; + nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL); if (!nor) return -ENOMEM; From 93e00ccab5f7da0c479bbdc6fc08c7e42f07eb5e Mon Sep 17 00:00:00 2001 From: Parth Pancholi Date: Tue, 5 Nov 2024 11:58:44 +0100 Subject: [PATCH 06/10] mtd: spi-nor: macronix: remove mx25u25635f from parts list to enable SFDP The Macronix mx25u25635f flash device supports SFDP initialization. This commit removes the specific mx25u25635f entry (NOR ID 0xc22539), along with its size and flags, from the NOR parts list. By removing this entry, both mx25u25635f and mx25u25645g (which share the same NOR ID) will utilize the generic flash driver configuration. This change allows both devices (mx25u25635f and mx25u25645g) to leverage SFDP-defined parameters, enabling dual and quad read operations without the need for manual adjustment of no_sfdp_flags. Link: https://www.macronix.com/Lists/Datasheet/Attachments/8663/MX25U25635F,%201.8V,%20256Mb,%20v1.5.pdf Signed-off-by: Parth Pancholi Reviewed-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241105105844.257676-1-parth105105@gmail.com --- drivers/mtd/spi-nor/macronix.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c index 57a40fa70c6a1..99936fd25d43c 100644 --- a/drivers/mtd/spi-nor/macronix.c +++ b/drivers/mtd/spi-nor/macronix.c @@ -142,12 +142,6 @@ static const struct flash_info macronix_nor_parts[] = { .name = "mx25u12835f", .size = SZ_16M, .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ, - }, { - .id = SNOR_ID(0xc2, 0x25, 0x39), - .name = "mx25u25635f", - .size = SZ_32M, - .no_sfdp_flags = SECT_4K, - .fixup_flags = SPI_NOR_4B_OPCODES, }, { .id = SNOR_ID(0xc2, 0x25, 0x3a), .name = "mx25u51245g", From ef262847122b7589d0a1056ab79c688645e2da21 Mon Sep 17 00:00:00 2001 From: Tudor Ambarus Date: Thu, 19 Dec 2024 09:20:04 +0000 Subject: [PATCH 07/10] mtd: spi-nor: extend description of size member of struct flash_info We use the size as an indicator whether to parse SFDP or not. We don't introduce a dedicated member for SFDP parsing because we'd like to keep the struct size at a minimum, as it's used for every flash declaration. Ideally we won't have flash entries at all, but there are still flash parameters that aren't defined by SFDP, thus we need to statically specify them. Signed-off-by: Tudor Ambarus Reviewed-by: Miquel Raynal Reviewed-by: Michael Walle Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241219-spi-nor-flash-info-size-desc-v1-1-6b53cf011027@linaro.org --- drivers/mtd/spi-nor/core.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 5c33740ed7f5f..ceff412f7d65a 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -448,7 +448,11 @@ struct spi_nor_id { * @id: pointer to struct spi_nor_id or NULL, which means "no ID" (mostly * older chips). * @name: (obsolete) the name of the flash. Do not set it for new additions. - * @size: the size of the flash in bytes. + * @size: the size of the flash in bytes. The flash size is one + * property parsed by the SFDP. We use it as an indicator + * whether we need SFDP parsing for a particular flash. + * I.e. non-legacy flash entries in flash_info will have + * a size of zero iff SFDP should be used. * @sector_size: (optional) the size listed here is what works with * SPINOR_OP_SE, which isn't necessarily called a "sector" by * the vendor. Defaults to 64k. From 78bc75e16e03822218bcbae0578fdf988af39ffd Mon Sep 17 00:00:00 2001 From: Takahiro Kuwano Date: Thu, 19 Dec 2024 16:06:15 +0900 Subject: [PATCH 08/10] mtd: spi-nor: spansion: Add support for S28HL256T Infineon S28HL256T is 3.0V, 256Mb Flash device with Octal interface. It has the same functionalities with S28HS256T(1.8V). Link: https://www.infineon.com/dgdl/Infineon-S28HS256T_S28HL256T_256Mb_SEMPER_Flash_Octal_interface_1_8V_3-DataSheet-v02_00-EN.pdf?fileId=8ac78c8c8fc2dd9c018fc66787aa0657 Signed-off-by: Takahiro Kuwano Reviewed-by: Tudor Ambarus [pratyush@kernel.org: add comment with flash name] Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/f052b04693f1100e725e076fd8a0ae339f8002c4.1734588106.git.Takahiro.Kuwano@infineon.com --- drivers/mtd/spi-nor/spansion.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c index 5a88a6096ca8c..e354fe3a48eeb 100644 --- a/drivers/mtd/spi-nor/spansion.c +++ b/drivers/mtd/spi-nor/spansion.c @@ -957,6 +957,11 @@ static const struct flash_info spansion_nor_parts[] = { .name = "s25hs02gt", .mfr_flags = USE_CLPEF, .fixups = &s25hx_t_fixups + }, { + /* S28HL256T */ + .id = SNOR_ID(0x34, 0x5a, 0x19), + .mfr_flags = USE_CLPEF, + .fixups = &s28hx_t_fixups, }, { .id = SNOR_ID(0x34, 0x5a, 0x1a), .name = "s28hl512t", From b239cbc7b078ff9c8b218c6191550ae28763fdaa Mon Sep 17 00:00:00 2001 From: Takahiro Kuwano Date: Thu, 19 Dec 2024 16:06:16 +0900 Subject: [PATCH 09/10] mtd: spi-nor: spansion: Add support for S28HL02GT Infineon S28HL02GT is 3.0V, 2Gb Flash device with Octal interface. It has the same functionalities with S28HS02GT. Link: https://www.infineon.com/dgdl/Infineon-S28HS02GT_S28HS04GT_S28HL02GT_S28HL04GT_2Gb_4Gb_SEMPER_Flash_Octal_interface_1.8V_3.0V-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c7e7124d1017f0631e33714d9 Signed-off-by: Takahiro Kuwano Reviewed-by: Tudor Ambarus [pratyush@kernel.org: add comment with flash name] Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/dc6aa706253a5200ff0c0d4523c2540312575c01.1734588106.git.Takahiro.Kuwano@infineon.com --- drivers/mtd/spi-nor/spansion.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c index e354fe3a48eeb..bf08dbf5e7421 100644 --- a/drivers/mtd/spi-nor/spansion.c +++ b/drivers/mtd/spi-nor/spansion.c @@ -972,6 +972,11 @@ static const struct flash_info spansion_nor_parts[] = { .name = "s28hl01gt", .mfr_flags = USE_CLPEF, .fixups = &s28hx_t_fixups, + }, { + /* S28HL02GT */ + .id = SNOR_ID(0x34, 0x5a, 0x1c), + .mfr_flags = USE_CLPEF, + .fixups = &s28hx_t_fixups, }, { .id = SNOR_ID(0x34, 0x5b, 0x19), .mfr_flags = USE_CLPEF, From 943e5f85600708c348f7b23d3c1cff1cf9763032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 22 Dec 2024 21:15:55 +0100 Subject: [PATCH 10/10] mtd: spi-nor: sysfs: constify 'struct bin_attribute' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh Acked-by: Pratyush Yadav Signed-off-by: Pratyush Yadav Link: https://lore.kernel.org/r/20241222-sysfs-const-bin_attr-mtd-v1-1-ee13140a4e9b@weissschuh.net --- drivers/mtd/spi-nor/sysfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c index 5e9eb268073d1..4f12ff755df06 100644 --- a/drivers/mtd/spi-nor/sysfs.c +++ b/drivers/mtd/spi-nor/sysfs.c @@ -50,7 +50,7 @@ static struct attribute *spi_nor_sysfs_entries[] = { }; static ssize_t sfdp_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct spi_device *spi = to_spi_device(kobj_to_dev(kobj)); @@ -62,9 +62,9 @@ static ssize_t sfdp_read(struct file *filp, struct kobject *kobj, return memory_read_from_buffer(buf, count, &off, nor->sfdp->dwords, sfdp_size); } -static BIN_ATTR_RO(sfdp, 0); +static const BIN_ATTR_RO(sfdp, 0); -static struct bin_attribute *spi_nor_sysfs_bin_entries[] = { +static const struct bin_attribute *const spi_nor_sysfs_bin_entries[] = { &bin_attr_sfdp, NULL }; @@ -104,7 +104,7 @@ static const struct attribute_group spi_nor_sysfs_group = { .is_visible = spi_nor_sysfs_is_visible, .is_bin_visible = spi_nor_sysfs_is_bin_visible, .attrs = spi_nor_sysfs_entries, - .bin_attrs = spi_nor_sysfs_bin_entries, + .bin_attrs_new = spi_nor_sysfs_bin_entries, }; const struct attribute_group *spi_nor_sysfs_groups[] = {