[PATCH v2 4/4] mtd: spi-nor: macronix: Describe locking support for MX25L51245G

Miquel Raynal miquel.raynal at bootlin.com
Thu Nov 26 05:42:29 PST 2026


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 at bootlin.com>
---
 drivers/mtd/spi-nor/macronix.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 9a40c2b14cb4..06ebd5482bc8 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,38 @@ 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;
+	u8 cr;
+
+	/*
+	 * 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, &cr))
+		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 (cr & 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)
 {
@@ -406,7 +439,7 @@ static const struct spi_nor_fixup macronix_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,
+	{ .id = SNOR_ID(0xc2, 0x20, 0x1a), .fixups = &mx25l51245_fixups,
 	  .fixup_flags = SPI_NOR_4B_OPCODES },
 	{ .id = SNOR_ID(0xc2, 0x20, 0x1b), .fixups = &macronix_qpp4b_fixups },
 	{ .id = SNOR_ID(0xc2, 0x20, 0x1c), .fixups = &macronix_qpp4b_fixups },

-- 
2.56.0




More information about the linux-mtd mailing list