* [PATCH 0/4] mtd: spi-nor: macronix: Improve general support
@ 2026-11-25 18:01 Miquel Raynal
2026-11-25 18:01 ` [PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode Miquel Raynal
` (3 more replies)
0 siblings, 4 replies; 7+ 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
There are multiple ongoing issues with the current state of the Macronix
vendor driver:
- wrong RDCR opcode in general
- erroneous QER handling
- issues with locking
This series aims at fixing all those open points. One reason they have
stayed for so long, is because there was no easy way to define a clean
per-vendor RDCR opcode nor to easily hook fixups to JEDEC IDs *and*
extra conditions. This is all possible now thanks to the recently merged
heavy QER handling rework, so let's use these capabilities.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
Miquel Raynal (4):
mtd: spi-nor: macronix: Clear the default RDCR opcode
mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E
mtd: spi-nor: macronix: Enable RDCR for the parts that support it
mtd: spi-nor: macronix: Describe locking support for MX25L51245G
drivers/mtd/spi-nor/macronix.c | 91 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 85 insertions(+), 6 deletions(-)
---
base-commit: 19d1b4de6d37bccecc3ad9144d279f1baa405eb1
change-id: 20261125-macronix-upstreaming-spi-nor-cleanup-a08351bbe71d
Best regards,
--
Miquel Raynal <miquel.raynal@bootlin.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [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:01 ` [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E Miquel Raynal
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ 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
^ permalink raw reply [flat|nested] 7+ 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-26 5:25 ` Cheng Ming Lin
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; 7+ 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
^ permalink raw reply [flat|nested] 7+ 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; 7+ 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
^ permalink raw reply [flat|nested] 7+ 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
3 siblings, 0 replies; 7+ 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
^ permalink raw reply [flat|nested] 7+ 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-26 5:25 ` Cheng Ming Lin
2026-11-26 11:18 ` Miquel Raynal
0 siblings, 1 reply; 7+ messages in thread
From: Cheng Ming Lin @ 2026-11-26 5:25 UTC (permalink / raw)
To: Miquel Raynal
Cc: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Thomas Petazzoni,
Alvin Zhou, linux-mtd, linux-kernel
Hi Miquel,
On Wed, Nov 25, 2026 at 07:01:35PM +0100, Miquel Raynal wrote:
> The MX25L3255E BFPT table is incorrect which leads to the RDCR opcode to
> be reset. Make sure the configuration for this chip remains correct.
I think this patch is not needed.
The MX25L3255E BFPT is JESD216 rev 0, its parameter table length is
0x09 DWORDs (see Table 9, offset 0Bh, on page 64 of the datasheet [1]).
spi_nor_parse_bfpt() returns before touching the SR opcodes and the
QE mask in this case:
/* Stop here if not JESD216 rev A or later. */
if (bfpt_header->length == BFPT_DWORD_MAX_JESD216)
return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt);
Since macronix_nor_default_init() now always runs before
spi_nor_parse_sfdp(), the read_sr2 = 0 set in patch 1 is kept for
this part. So the BFPT is not incorrect, it just predates the QER
field.
> params->qe_mask[0] = BIT(6);
> params->qe_mask[1] = 0;
> + params->opcodes.read_sr2 = 0;
The same is true for the qe_mask lines above. They were only needed
because the old spi_nor_init_params() did not call the manufacturer
default_init() when SFDP was required. With the reworked init flow
they can be dropped too, and only the 1-4-4 PP part needs to stay.
[1] https://media.digikey.com/pdf/data%20sheets/macronix/mx25l3255e.pdf
Thanks,
Cheng Ming Lin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] mtd: spi-nor: macronix: Clear the RDCR opcode on MX25L3255E
2026-11-26 5:25 ` Cheng Ming Lin
@ 2026-11-26 11:18 ` Miquel Raynal
0 siblings, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2026-11-26 11:18 UTC (permalink / raw)
To: Cheng Ming Lin
Cc: Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Thomas Petazzoni,
Alvin Zhou, linux-mtd, linux-kernel
On 26/11/2026 at 13:25:24 +08, Cheng Ming Lin <linchengming884@gmail.com> wrote:
> Hi Miquel,
>
> On Wed, Nov 25, 2026 at 07:01:35PM +0100, Miquel Raynal wrote:
>> The MX25L3255E BFPT table is incorrect which leads to the RDCR opcode to
>> be reset. Make sure the configuration for this chip remains correct.
>
> I think this patch is not needed.
>
> The MX25L3255E BFPT is JESD216 rev 0, its parameter table length is
> 0x09 DWORDs (see Table 9, offset 0Bh, on page 64 of the datasheet [1]).
> spi_nor_parse_bfpt() returns before touching the SR opcodes and the
> QE mask in this case:
>
> /* Stop here if not JESD216 rev A or later. */
> if (bfpt_header->length == BFPT_DWORD_MAX_JESD216)
> return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt);
>
> Since macronix_nor_default_init() now always runs before
> spi_nor_parse_sfdp(), the read_sr2 = 0 set in patch 1 is kept for
> this part. So the BFPT is not incorrect, it just predates the QER
> field.
>
>> params->qe_mask[0] = BIT(6);
>> params->qe_mask[1] = 0;
>> + params->opcodes.read_sr2 = 0;
>
> The same is true for the qe_mask lines above. They were only needed
> because the old spi_nor_init_params() did not call the manufacturer
> default_init() when SFDP was required. With the reworked init flow
> they can be dropped too, and only the 1-4-4 PP part needs to stay.
Ah, great, I thought it was still the case, but that's good news.
I'll instead drop the QE mask then.
Thanks for the feedback!
Miquèl
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-26 11:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-26 5:25 ` Cheng Ming Lin
2026-11-26 11:18 ` Miquel Raynal
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®