[PATCH 3/4] mtd: spi-nor: macronix: Enable RDCR for the parts that support it

From: Miquel Raynal

Date: Wed Nov 25 2026 - 13:02:40 EST


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@xxxxxxxxxxx>
---
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 = &macronix_nor_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x18), .match = macronix_nor_has_sfdp,
+ .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x1a), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x1b), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x20, 0x1c), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x23, 0x14), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x25, 0x3a), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x25, 0x3b), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x25, 0x3c), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x28, 0x15), .fixups = &macronix_rdcr_fixups },
+ { .id = SNOR_ID(0xc2, 0x28, 0x16), .fixups = &macronix_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 = &macronix_qpp4b_fixups,

--
2.56.0