[PATCH v3] mtd: spi-nor: clear the default read_sr2 opcode for xSPI Profile 1.0 flashes
haibo.chen at oss.nxp.com
haibo.chen at oss.nxp.com
Thu Oct 22 01:07:25 PDT 2026
From: Haibo Chen <haibo.chen at nxp.com>
The core defaults opcodes.read_sr2 to the legacy RDCR opcode (0x35), and
spi_nor_cache_sr_lock_bits() reads SR2 during spi_nor_init(), i.e. after
the flash has been switched to its runtime protocol. On an octal flash
running in 8D-8D-8D mode the opcode is extended per cmd_ext_type (e.g.
0x3535), but RDCR is not a valid register read there: these parts access
their status/configuration registers through a vendor-specific indirect
space, if at all. The flash does not answer, the register read times out
and probe fails (on i.MX FlexSPI: -ETIMEDOUT and a controller WARN(),
seen with a Micron MT35XU01G and a Macronix MX25UW51345G).
A flash that supports 8D-8D-8D publishes the xSPI Profile 1.0 SFDP table,
and that table does not describe any SR2/RDCR read. Clear read_sr2 in
spi_nor_parse_profile1(): it runs only for octal-capable parts and before
the manufacturer late_init hooks, so spi_nor_read_sr1_and_sr2() degrades
to an SR1-only read and no unsupported command is issued. A manufacturer
driver that genuinely needs an SR2 read in this mode can still install
its own opcode in a later fixup.
CMP (the only user of SR2 beyond quad-enable in the locking code) is
Winbond-specific and is not placed in SR2 on their 8D-capable parts, so
no octal flash loses a usable SR2 read because of this change.
Fixes: b7b63475903c ("mtd: spi-nor: Create a local SR cache")
Fixes: 63489002d397 ("mtd: spi-nor: Refactor Read Status/Write Status support")
Signed-off-by: Haibo Chen <haibo.chen at nxp.com>
---
Changes in v3:
- Clear opcodes.read_sr2 in spi_nor_parse_profile1() (capability based)
instead of in spi_nor_set_octal_dtr() (runtime-protocol based), as
suggested by Miquel and Michael. It runs for octal-capable parts and
before the manufacturer late_init, so a driver can still install its
own SR2 opcode afterwards.
- Confirmed on a Micron MT35XU01G (i.MX95) and a Macronix MX25UW51345G
(i.MX8ULP): both publish the xSPI Profile 1.0 table, and 0x35 is not a
valid SR2 read in 8D mode on either.
- Drop the Assisted-by tag (removed upstream for 7.3).
- Link to v2: https://lore.kernel.org/r/20260929-spi-nor-fix-v2-1-75440cfe4e76@nxp.com
Changes in v2:
- Rework the fix following review: instead of guarding the read at runtime
in spi_nor_read_sr2(), clear the default RDCR opcode.read_sr2 once, at the
point the switch to Octal DTR succeeds (spi_nor_set_octal_dtr()).
- Key the clear off the real runtime protocol so a flash that advertises
Octal DTR but runs in (x)STR (host without 8D support) keeps its RDCR.
- Drop the swp.c change and the -EOPNOTSUPP handling; a cleared read_sr2
already means "no SR2 read", handled by the existing debugfs caching path.
- Trim the code comment; move the details to the commit message.
- Link to v1: https://lore.kernel.org/r/20260928-spi-nor-fix-v1-1-ce65ba90cfbd@nxp.com
---
drivers/mtd/spi-nor/sfdp.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index 4a3f82e97cef8a76c9704918aa6558ca4e2f2b97..722eeff71d0df8c47ec7bdd795c08ba1bdf5e9cc 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -1344,6 +1344,17 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
*/
nor->params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR;
+ /*
+ * The xSPI Profile 1.0 table does not describe a Read Configuration
+ * Register (RDCR, 35h) instruction, and the single-byte RDCR default
+ * is not usable in 8D-8D-8D mode. Drop the SR2 read opcode for these
+ * octal-capable flashes so spi_nor_read_sr1_and_sr2() degrades to an
+ * SR1-only read and spi_nor_init() does not issue an unsupported
+ * command that the flash never answers. A manufacturer driver that
+ * actually needs SR2 can install its own opcode in a later fixup.
+ */
+ nor->params->opcodes.read_sr2 = 0;
+
out:
kfree(dwords);
return ret;
---
base-commit: 9a482184d910775cf648863148944945b74e2815
change-id: 20260928-spi-nor-fix-eb7ebe22a740
Best regards,
--
Haibo Chen <haibo.chen at nxp.com>
More information about the linux-mtd
mailing list