* [PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode
2026-11-25 18:01 [PATCH 0/4] mtd: spi-nor: macronix: Improve general support Miquel Raynal
@ 2026-11-25 18:01 ` Miquel Raynal
2026-11-25 18:17 ` sashiko-bot
2026-11-25 18:01 ` [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E Miquel Raynal
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Miquel Raynal @ 2026-11-25 18:01 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd,
linux-kernel, Miquel Raynal
The core defaults opcodes.read_sr2 to the JEDEC RDCR opcode (0x35).
Macronix flashes do not use 0x35 to access their configuration
register; they read it with 0x15, and some parts have no configuration
register at all.
Clear the opcode in the manufacturer default_init, which runs after the
core default and before the SFDP parsing. Parts that do support the
vendor opcode can then opt in from their own fixup.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/spi-nor/macronix.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index b3fdb4b2fa1c..2c6f507a2dde 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -333,6 +333,13 @@ static void macronix_nor_default_init(struct spi_nor *nor)
{
nor->params->qe_mask[0] = BIT(6);
nor->params->qe_mask[1] = 0;
+
+ /*
+ * The JEDEC RDCR opcode (0x35) is not valid for Macronix: some parts
+ * have no CR at all, others use 0x15. Clear the core default. Parts
+ * that do support the vendor opcode can opt-in from their own fixup.
+ */
+ nor->params->opcodes.read_sr2 = 0;
}
static int macronix_nor_late_init(struct spi_nor *nor)
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode
2026-11-25 18:01 ` [PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode Miquel Raynal
@ 2026-11-25 18:17 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-25 18:17 UTC (permalink / raw)
To: Miquel Raynal, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mtd: spi-nor: macronix: missing write_sr1 setup in
macronix_nor_default_init()
- [Medium] mtd: spi-nor: macronix: read_sr2 cleared before
spi_nor_parse_bfpt() reset
- [Low] mtd: spi-nor: macronix: missing Fixes trailer for commit
63489002d397
--
commit 5d3e4568e97ca20a41fbc446cff7e7e89070cad1
Author: Miquel Raynal <miquel.raynal@bootlin.com>
> mtd: spi-nor: macronix: Clear the default RDCR opcode
>
> The core defaults opcodes.read_sr2 to the JEDEC RDCR opcode (0x35).
> Macronix flashes do not use 0x35 to access their configuration
> register; they read it with 0x15, and some parts have no configuration
> register at all.
>
> Clear the opcode in the manufacturer default_init, which runs after the
> core default and before the SFDP parsing. Parts that do support the
> vendor opcode can then opt in from their own fixup.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
[Severity: Low]
Since this fixes the default SPINOR_OP_RDCR assignment for Macronix flashes,
should it include a Fixes: tag?
Fixes: 63489002d397 ("mtd: spi-nor: Refactor Read Status/Write Status support")
> diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
> index b3fdb4b2fa1ca..2c6f507a2dde7 100644
> --- a/drivers/mtd/spi-nor/macronix.c
> +++ b/drivers/mtd/spi-nor/macronix.c
> @@ -333,6 +333,13 @@ static void macronix_nor_default_init(struct spi_nor *nor)
> {
> nor->params->qe_mask[0] = BIT(6);
> nor->params->qe_mask[1] = 0;
> +
> + /*
> + * The JEDEC RDCR opcode (0x35) is not valid for Macronix: some parts
> + * have no CR at all, others use 0x15. Clear the core default. Parts
> + * that do support the vendor opcode can opt-in from their own fixup.
> + */
> + nor->params->opcodes.read_sr2 = 0;
> }
>
> static int macronix_nor_late_init(struct spi_nor *nor)
[Severity: High]
Should macronix_nor_default_init() also set opcodes.write_sr1 = SPINOR_OP_WRSR
and clear opcodes.write_sr1_and_sr2 = 0, matching BFPT_DWORD15_QER_SR1_BIT6 in
spi_nor_parse_bfpt()?
spi_nor_init_default_params() initializes opcodes.write_sr1_and_sr2 to
SPINOR_OP_WRSR and leaves opcodes.write_sr1 as 0. On Macronix flashes without
SFDP (such as mx25l12805d) or with a 9-DWORD JESD216 v1.0 BFPT (such as
mx25l25635e), spi_nor_parse_bfpt() does not run the QER switch. When
spi_nor_generic_quad_enable() or software lock/unlock runs with read_sr2
cleared to 0, spi_nor_read_sr1_and_sr2() leaves sr[1] = 0 and
spi_nor_write_sr1_and_sr2() issues a 2-byte WRSR (0x01) command instead of a
1-byte SR1 write, either sending an invalid second byte to flashes without a
Configuration Register or overwriting the Configuration Register with 0x00.
[Severity: Medium]
Does clearing opcodes.read_sr2 in macronix_nor_default_init() get overwritten
by spi_nor_parse_bfpt() on flashes with a >9-DWORD BFPT table and
BFPT_DWORD15_QER_NONE?
macronix_nor_default_init() runs before SFDP parsing, and spi_nor_parse_bfpt()
unconditionally resets params->opcodes.read_sr2 = SPINOR_OP_RDCR before
switching on the QER field:
drivers/mtd/spi-nor/sfdp.c:spi_nor_parse_bfpt() {
...
params->opcodes.read_sr1 = SPINOR_OP_RDSR;
params->opcodes.read_sr2 = SPINOR_OP_RDCR;
params->opcodes.write_sr1 = SPINOR_OP_WRSR;
params->opcodes.write_sr1_and_sr2 = SPINOR_OP_WRSR;
params->qe_mask[0] = 0;
params->qe_mask[1] = 0;
/* Quad Enable Requirements. */
switch (bfpt.dwords[SFDP_DWORD(15)] & BFPT_DWORD15_QER_MASK) {
case BFPT_DWORD15_QER_NONE:
break;
...
}
Because BFPT_DWORD15_QER_NONE leaves opcodes.read_sr2 untouched, any Macronix
flash with >9 BFPT DWORDs and QER_NONE gets 0x35 restored and will still issue
RDCR during spi_nor_init(). A later patch in the series, commit "mtd:
spi-nor: macronix: Clear the RDCR opcode on MX25L3255E", works around this in
late_init for MX25L3255E, but other QER_NONE Macronix parts with >9 BFPT
DWORDs (such as octal-only flashes like MX25UW51245G) remain with read_sr2 set
to 0x35.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-nor-cleanup-v1-0-0d1ab783fd8b@bootlin.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E
2026-11-25 18:01 [PATCH 0/4] mtd: spi-nor: macronix: Improve general support Miquel Raynal
2026-11-25 18:01 ` [PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode Miquel Raynal
@ 2026-11-25 18:01 ` Miquel Raynal
2026-11-25 18:22 ` sashiko-bot
2026-11-25 18:01 ` [PATCH 3/4] mtd: spi-nor: macronix: Enable RDCR for the parts that support it Miquel Raynal
2026-11-25 18:01 ` [PATCH 4/4] mtd: spi-nor: macronix: Describe locking support for MX25L51245G Miquel Raynal
3 siblings, 1 reply; 8+ messages in thread
From: Miquel Raynal @ 2026-11-25 18:01 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd,
linux-kernel, Miquel Raynal
The MX25L3255E BFPT table is incorrect which leads to the RDCR opcode to
be reset. Make sure the configuration for this chip remains correct.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/spi-nor/macronix.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 2c6f507a2dde..0331f9f3f853 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -64,13 +64,14 @@ mx25l3255e_late_init_fixups(struct spi_nor *nor)
struct spi_nor_flash_parameter *params = nor->params;
/*
- * SFDP of MX25L3255E is JESD216, which does not include the Quad
- * Enable bit Requirement in BFPT. As a result, during BFPT parsing
- * the quad_enable mask is reset. Therefore, it is necessary to
- * correct this setting by late_init.
+ * SFDP of MX25L3255E does not include the Quad Enable bit
+ * Requirement in BFPT. As a result, during BFPT parsing the
+ * quad_enable mask and RDCR opcode are reset. Ensure these
+ * values remain valid.
*/
params->qe_mask[0] = BIT(6);
params->qe_mask[1] = 0;
+ params->opcodes.read_sr2 = 0;
/*
* In addition, MX25L3255E also supports 1-4-4 page program in 3-byte
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E
2026-11-25 18:01 ` [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E Miquel Raynal
@ 2026-11-25 18:22 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-25 18:22 UTC (permalink / raw)
To: Miquel Raynal, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mtd: spi-nor: macronix: mx25l3255e_late_init_fixups() leaves
2-byte WRSR set
- [Low] mtd: spi-nor: macronix: missing Fixes trailer for commit
63489002d397
--
commit 48e33caf0f5945c8c50d282ae7f083714bc2908f
Author: Miquel Raynal <miquel.raynal@bootlin.com>
> mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E
>
> The MX25L3255E BFPT table is incorrect which leads to the RDCR opcode to
> be reset. Make sure the configuration for this chip remains correct.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
[Severity: Low]
This fixes a regression on MX25L3255E where RDCR remained set after BFPT
parsing. Should the commit message include:
Fixes: 63489002d397 ("mtd: spi-nor: Refactor Read Status/Write Status support")
> diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
> index 2c6f507a2dde7..0331f9f3f853c 100644
> --- a/drivers/mtd/spi-nor/macronix.c
> +++ b/drivers/mtd/spi-nor/macronix.c
> @@ -64,13 +64,14 @@ mx25l3255e_late_init_fixups(struct spi_nor *nor)
> struct spi_nor_flash_parameter *params = nor->params;
>
> /*
> - * SFDP of MX25L3255E is JESD216, which does not include the Quad
> - * Enable bit Requirement in BFPT. As a result, during BFPT parsing
> - * the quad_enable mask is reset. Therefore, it is necessary to
> - * correct this setting by late_init.
> + * SFDP of MX25L3255E does not include the Quad Enable bit
> + * Requirement in BFPT. As a result, during BFPT parsing the
> + * quad_enable mask and RDCR opcode are reset. Ensure these
> + * values remain valid.
> */
> params->qe_mask[0] = BIT(6);
> params->qe_mask[1] = 0;
> + params->opcodes.read_sr2 = 0;
[Severity: Medium]
Should this also clear params->opcodes.write_sr1_and_sr2?
spi_nor_parse_bfpt() initializes write_sr1_and_sr2 to SPINOR_OP_WRSR before
checking the QER field and only clears it in the BFPT_DWORD15_QER_SR1_BIT6
case:
drivers/mtd/spi-nor/sfdp.c:spi_nor_parse_bfpt() {
...
case BFPT_DWORD15_QER_SR1_BIT6:
params->opcodes.read_sr2 = 0;
params->opcodes.write_sr1_and_sr2 = 0;
params->qe_mask[0] = BIT(6);
break;
...
}
Because MX25L3255E has no QER entry in its BFPT, write_sr1_and_sr2 remains
SPINOR_OP_WRSR, causing spi_nor_generic_quad_enable() ->
spi_nor_write_sr1_and_sr2() to issue a 2-byte WRSR command instead of a
1-byte SR1 write when enabling Quad mode.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-nor-cleanup-v1-0-0d1ab783fd8b@bootlin.com?part=2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/4] mtd: spi-nor: macronix: Enable RDCR for the parts that support it
2026-11-25 18:01 [PATCH 0/4] mtd: spi-nor: macronix: Improve general support Miquel Raynal
2026-11-25 18:01 ` [PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode Miquel Raynal
2026-11-25 18:01 ` [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E Miquel Raynal
@ 2026-11-25 18:01 ` Miquel Raynal
2026-11-25 18:01 ` [PATCH 4/4] mtd: spi-nor: macronix: Describe locking support for MX25L51245G Miquel Raynal
3 siblings, 0 replies; 8+ messages in thread
From: Miquel Raynal @ 2026-11-25 18:01 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd,
linux-kernel, Miquel Raynal
Some Macronix parts have support for reading SR2, in which case the
opcode 0x15 will be used. Since the opcode is now cleared by default,
opt-in for the parts whose datasheet documents RDCR.
Sometimes the JEDEC ID is not useful since Macronix has re-used IDs
across incompatible parts. In this case, another discriminant is used on
top (eg. SFDP support or 4B addressing capability):
- 128 Mbit variants (typically MX25L12805D) have no RDCR, but the
MX25L12833F and MX25L12845G are SFDP-capable and have RDCR support.
Use the SFDP presence to discriminate the RDCR capability.
- 256 Mbit variants have no RDCR support, except the MX25L25635F and
MX25L25645G parts which happen to also be 4-byte-capable. Use that
capability to discriminate RDCR support.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/spi-nor/macronix.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 0331f9f3f853..bbc41af14882 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -14,6 +14,7 @@
#define MXIC_NOR_ADDR_CR2_DC 0x00000300 /* CR2 address for setting dummy cycles */
#define MXIC_NOR_REG_DOPI_EN 0x2 /* Enable Octal DTR */
#define MXIC_NOR_REG_SPI_EN 0x0 /* Enable SPI */
+#define MXIC_NOR_OP_RDCR 0x15 /* Read Configuration Register opcode */
/* Convert dummy cycles to bit pattern */
#define MXIC_NOR_REG_DC(p) \
@@ -25,6 +26,27 @@
SPI_MEM_OP_NO_DUMMY, \
SPI_MEM_OP_DATA_OUT(ndata, buf, 0))
+/*
+ * RDCR support is not tied to the presence of SFDP, but the SFDP
+ * presence is sometimes enough to discriminate parts with the same
+ * JEDEC ID wrt their RDCR support.
+ */
+static bool macronix_nor_has_sfdp(const struct spi_nor *nor)
+{
+ return nor->sfdp;
+}
+
+static int macronix_rdcr_late_init(struct spi_nor *nor)
+{
+ nor->params->opcodes.read_sr2 = MXIC_NOR_OP_RDCR;
+
+ return 0;
+}
+
+static const struct spi_nor_fixups macronix_rdcr_fixups = {
+ .late_init = macronix_rdcr_late_init,
+};
+
static int
mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
const struct sfdp_parameter_header *bfpt_header,
@@ -38,9 +60,15 @@ mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
* We need a way to differentiate MX25L25635E and MX25L25635F, and it
* seems that the F version advertises support for Fast Read 4-4-4 in
* its BFPT table.
+ *
+ * The MX25L25635F and MX25L25645G variants also have a configuration
+ * register readable with RDCR; the MX25L25635E does not. Use the same
+ * Fast Read 4-4-4 bit to enable both.
*/
- if (bfpt->dwords[SFDP_DWORD(5)] & BFPT_DWORD5_FAST_READ_4_4_4)
+ if (bfpt->dwords[SFDP_DWORD(5)] & BFPT_DWORD5_FAST_READ_4_4_4) {
nor->params->flags |= SNOR_F_4B_OPCODES;
+ nor->params->opcodes.read_sr2 = MXIC_NOR_OP_RDCR;
+ }
return 0;
}
@@ -359,6 +387,17 @@ static const struct spi_nor_fixups macronix_nor_fixups = {
static const struct spi_nor_fixup macronix_fixups[] = {
{ .fixups = ¯onix_nor_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x18), .match = macronix_nor_has_sfdp,
+ .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x1a), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x1b), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x1c), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x23, 0x14), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x25, 0x3a), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x25, 0x3b), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x25, 0x3c), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x28, 0x15), .fixups = ¯onix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x28, 0x16), .fixups = ¯onix_rdcr_fixups },
{ .id = SNOR_ID(0xc2, 0x20, 0x18), .fixups = &mx25l12805d_4pp3b_fixups },
{ .id = SNOR_ID(0xc2, 0x20, 0x19), .fixups = &mx25l25635_fixups },
{ .id = SNOR_ID(0xc2, 0x20, 0x1a), .fixups = ¯onix_qpp4b_fixups,
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/4] mtd: spi-nor: macronix: Describe locking support for MX25L51245G
2026-11-25 18:01 [PATCH 0/4] mtd: spi-nor: macronix: Improve general support Miquel Raynal
` (2 preceding siblings ...)
2026-11-25 18:01 ` [PATCH 3/4] mtd: spi-nor: macronix: Enable RDCR for the parts that support it Miquel Raynal
@ 2026-11-25 18:01 ` Miquel Raynal
2026-11-25 18:25 ` sashiko-bot
3 siblings, 1 reply; 8+ messages in thread
From: Miquel Raynal @ 2026-11-25 18:01 UTC (permalink / raw)
To: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd,
linux-kernel, Miquel Raynal
The MX25L51245G, MX25L51273G and MX66L51235F share JEDEC ID 0xc2201a.
They have the same 4-bit block protection scheme as the MX25L12805D:
BP0-BP3 in the status register. Their Top/Bottom select bit is however
located in the configuration register (bit 3) and is OTP, which means
TB choice cannot be supported as-is and would anyway become
inconsistent once the TB bit set.
Read the configuration register in a fixup and enable locking iff TB is
cleared.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/spi-nor/macronix.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index bbc41af14882..87fdbd6c3800 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -15,6 +15,7 @@
#define MXIC_NOR_REG_DOPI_EN 0x2 /* Enable Octal DTR */
#define MXIC_NOR_REG_SPI_EN 0x0 /* Enable SPI */
#define MXIC_NOR_OP_RDCR 0x15 /* Read Configuration Register opcode */
+#define MXIC_NOR_CR_TB BIT(3) /* Top/Bottom select, OTP */
/* Convert dummy cycles to bit pattern */
#define MXIC_NOR_REG_DC(p) \
@@ -86,6 +87,37 @@ macronix_qpp4b_post_sfdp_fixups(struct spi_nor *nor)
return 0;
}
+static int
+mx25l51245_late_init(struct spi_nor *nor)
+{
+ struct spi_nor_flash_parameter *params = nor->params;
+
+ /*
+ * Locking is optional, so leave locking disabled if the CR cannot be
+ * read (e.g. the controller does not support the 0x15 opcode).
+ */
+ if (spi_nor_read_sr2(nor, nor->bouncebuf))
+ return 0;
+
+ /*
+ * MX25L51245G supports locking, but TB bit is OTP. Since a TB=1 bit
+ * cannot be supported with the current software, prevent locking
+ * entirely in this case. Also do not advertize the TB bit at all to
+ * the capabilities set consistent.
+ */
+ if (nor->bouncebuf[0] & MXIC_NOR_CR_TB)
+ dev_dbg(nor->dev, "TB is set, bottom protection not supported\n");
+ else
+ params->flags |= SNOR_F_HAS_LOCK | SNOR_F_HAS_4BIT_BP;
+
+ return 0;
+}
+
+static const struct spi_nor_fixups mx25l51245_fixups = {
+ .late_init = mx25l51245_late_init,
+ .post_sfdp = macronix_qpp4b_post_sfdp_fixups,
+};
+
static int
mx25l3255e_late_init_fixups(struct spi_nor *nor)
{
@@ -400,7 +432,7 @@ static const struct spi_nor_fixup macronix_fixups[] = {
{ .id = SNOR_ID(0xc2, 0x28, 0x16), .fixups = ¯onix_rdcr_fixups },
{ .id = SNOR_ID(0xc2, 0x20, 0x18), .fixups = &mx25l12805d_4pp3b_fixups },
{ .id = SNOR_ID(0xc2, 0x20, 0x19), .fixups = &mx25l25635_fixups },
- { .id = SNOR_ID(0xc2, 0x20, 0x1a), .fixups = ¯onix_qpp4b_fixups,
+ { .id = SNOR_ID(0xc2, 0x20, 0x1a), .fixups = &mx25l51245_fixups,
.fixup_flags = SPI_NOR_4B_OPCODES },
{ .id = SNOR_ID(0xc2, 0x20, 0x1b), .fixups = ¯onix_qpp4b_fixups },
{ .id = SNOR_ID(0xc2, 0x20, 0x1c), .fixups = ¯onix_qpp4b_fixups },
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 4/4] mtd: spi-nor: macronix: Describe locking support for MX25L51245G
2026-11-25 18:01 ` [PATCH 4/4] mtd: spi-nor: macronix: Describe locking support for MX25L51245G Miquel Raynal
@ 2026-11-25 18:25 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-25 18:25 UTC (permalink / raw)
To: Miquel Raynal, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-mtd
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mtd: spi-nor: macronix: overlapping memcpy() in
mx25l51245_late_init()
--
commit 6981ddae179b4bc4f140785e21d8d0cec9e0f216
Author: Miquel Raynal <miquel.raynal@bootlin.com>
mtd: spi-nor: macronix: Describe locking support for MX25L51245G
This commit adds a late_init fixup for Macronix flash chips matching JEDEC
ID 0xc2201a to read the configuration register and enable block protection
locking if the OTP Top/Bottom bit is cleared.
> diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
> index bbc41af148826..87fdbd6c38009 100644
> --- a/drivers/mtd/spi-nor/macronix.c
> +++ b/drivers/mtd/spi-nor/macronix.c
[ ... ]
> @@ -86,6 +87,37 @@ macronix_qpp4b_post_sfdp_fixups(struct spi_nor *nor)
> return 0;
> }
>
> +static int
> +mx25l51245_late_init(struct spi_nor *nor)
> +{
> + struct spi_nor_flash_parameter *params = nor->params;
> +
> + /*
> + * Locking is optional, so leave locking disabled if the CR cannot be
> + * read (e.g. the controller does not support the 0x15 opcode).
> + */
> + if (spi_nor_read_sr2(nor, nor->bouncebuf))
> + return 0;
[Severity: Low]
Does passing nor->bouncebuf to spi_nor_read_sr2() cause an overlapping
memcpy()?
spi_nor_read_sr2() calls spi_nor_read_sr_ll(), which uses nor->bouncebuf
for the SPI transfer and then runs memcpy(sr, nor->bouncebuf, len) to copy
the result to the caller's buffer. Passing a stack u8 variable instead of
nor->bouncebuf avoids calling memcpy() with identical source and
destination pointers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-nor-cleanup-v1-0-0d1ab783fd8b@bootlin.com?part=4
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 8+ messages in thread