[PATCH 1/4] mtd: spi-nor: macronix: Clear the default RDCR opcode
Miquel Raynal
miquel.raynal at bootlin.com
Thu Nov 26 03:40:07 PST 2026
> [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")
No, this fixes tag is wrong. The problem has always existed but was not
easily fixable before that rework.
>> 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()?
Might be worth adding indeed.
> 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?
Yes, and that's the whole point. Certain flash do not overwrite it, so
for them we need a clean default.
...
> 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.
This is only set on a per-chip basis, not as a wide default, because it
is safer not to user SR2 when it is available rather than use it when
it's not there.
More information about the linux-mtd
mailing list