[PATCH v2 3/5] mtd: spi-nor: Support mixed 1S-xD-xD DTR protocols in spi_nor_spimem_setup_op()
From: Changhuang Liang
Date: Wed Oct 28 2026 - 08:11:58 EST
Currently spi_nor_spimem_setup_op() sets all four phases (cmd, addr,
dummy, data) to DTR whenever spi_nor_protocol_is_dtr(proto) is true.
This is too coarse: the 1S-xD-xD DTR protocols (1_1_1_DTR, 1_2_2_DTR,
1_4_4_DTR, 1_8_8_DTR) send the command phase in STR on a single line,
and only the address, dummy and data phases in DTR. SPIMEM supports
such mixed DTR modes.
Split the handling:
- For SNOR_PROTO_8_8_8_DTR, keep the existing behavior: set all
phases to DTR and use a 2-byte opcode (opcode + extension).
- For the other DTR protocols, set the command phase to STR and only
the address, dummy and data phases to DTR. Double op->dummy.nbytes
since DTR transfers 2 bytes per clock cycle, matching how the dummy
cycle count is specified for these protocols.
- Move the SWAP16 handling into the 8D-8D-8D branch as well, since
it only applies there.
No in-tree flash currently declares SNOR_HWCAPS_READ_1_x_x_DTR, so
this is not a bug fix but preparation for enabling these protocols.
A follow-up patch will enable 1S-4D-4D for the MX66L1G45G. The
8D-8D-8D path is unchanged.
Signed-off-by: Changhuang Liang <changhuang.liang@xxxxxxxxxxxxxxxx>
---
drivers/mtd/spi-nor/core.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 90524c58602e..78b8ee58382e 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -98,13 +98,7 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor,
op->data.buswidth = spi_nor_get_protocol_data_nbits(proto);
if (spi_nor_protocol_is_dtr(proto)) {
- /*
- * SPIMEM supports mixed DTR modes, but right now we can only
- * have all phases either DTR or STR. IOW, SPIMEM can have
- * something like 4S-4D-4D, but SPI NOR can't. So, set all 4
- * phases to either DTR or STR.
- */
- op->cmd.dtr = true;
+ /* we only support 1S-nD-nD or 8D-8D-8D */
op->addr.dtr = true;
op->dummy.dtr = true;
op->data.dtr = true;
@@ -112,13 +106,16 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor,
/* 2 bytes per clock cycle in DTR mode. */
op->dummy.nbytes *= 2;
- ext = spi_nor_get_cmd_ext(nor, op);
- op->cmd.opcode = (op->cmd.opcode << 8) | ext;
- op->cmd.nbytes = 2;
- }
+ if (proto == SNOR_PROTO_8_8_8_DTR) {
+ op->cmd.dtr = true;
+ ext = spi_nor_get_cmd_ext(nor, op);
+ op->cmd.opcode = (op->cmd.opcode << 8) | ext;
+ op->cmd.nbytes = 2;
- if (proto == SNOR_PROTO_8_8_8_DTR && params->flags & SNOR_F_SWAP16)
- op->data.swap16 = true;
+ if (params->flags & SNOR_F_SWAP16)
+ op->data.swap16 = true;
+ }
+ }
}
/**
--
2.25.1