* [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant
@ 2026-11-27 14:22 Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 01/35] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
` (34 more replies)
0 siblings, 35 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
SPI NOR SFDP data gives dummy cycles. SPI NAND devices express the dummy
phase using cycles as well. Those numbers are converted to bytes, then
passed to the spi and spi-mem controller drivers. A non-negligible
amount of those controller drivers convert bytes into cycles before
programming the registers.
When the conversions are lossless, it is not a big deal, just time
spent. However these silent conversions sometimes hide bugs and
sometimes also prevent using certain chips/configurations, as recently
reported on Macronix 1-1-8 chips requiring 20 cycles. Not all
controllers can do that, but the ones that can, would anyway reject
those chips.
Convert spi-mem, the trivial spi-mem controller drivers and then SPI NOR
to use dummy cycles instead of dummy bytes. SPI NAND may come later. As
part of those conversions, I also instated new de-facto sanity
checks. Those core checks allow us to drop many redundant checks from
the drivers after the conversion into using the cycles.
This second RFC adds the remaining controller conversions (nxp-fspi,
zynqmp-gqspi, atmel-quadspi and rpc-if), the range checks for the
controllers with limited dummy cycle fields, and the controller-specific
dummy buswidth fixes that depend on the cycles conversion. The dummy
buswidth fixes that do not depend on it have been (mostly) sent as a
separate series.
The series is build tested, but not run on hardware yet. I plan do
perform testing on the various controllers I have access to. This
version is not meant to be applied in the spi tree yet. Applying it for
your own review or testing requires the previous patch series cleaning
up the drivers (I split the two because of the size of the number of
patches...).
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
Changes in v2:
- Better sanitize the operations in the core.
- Drop more redundant checks from the controller drivers.
- Add a Fixes tag and fix the DTR sanitizing corner case.
- Fix the dummy conversion ordering, the spi_sync() fallback, the
poll_status() path and the dirmap fallback.
- Fix the trace event to report the dummy phase for both representations.
- Fix the listed controller driver bugs (unused code, missing capability,
pointer typos, range checks) and the s25fs256t dummy count.
- Convert nxp-fspi, zynqmp-gqspi, atmel-quadspi and rpc-if to dummy
cycles.
- Add range checks for the controllers with limited dummy cycle fields.
- Link to v1: https://lore.kernel.org/r/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com
---
Miquel Raynal (35):
spi: spi-mem: Stop checking the dummy buswidth against board wiring
spi: spi-mem: Fix the odd byte count error message
spi: spi-mem: Handle a corner case while sanitizing ops
spi: spi-mem: Sanitize mixed DTR modes
spi: spi-mem: Sanitize mixed buswidth
spi: spi-mem: Add support for dummy cycles
spi: amlogic-spifc-a1: Consume dummy cycles directly
spi: amlogic-spifc-a1: Reject excessive dummy cycle counts
spi: amlogic-spifc-a4: Consume dummy cycles directly
spi: atmel-quadspi: Consume dummy cycles directly
spi: atmel-quadspi: Reject excessive dummy cycle counts
spi: cadence-qspi: Consume dummy cycles directly
spi: cadence-qspi: Drop redundant checks
spi: cadence-qspi: Drop now useless checks
spi: fsl-qspi: Consume dummy cycles directly
spi: microchip-core-qspi: Consume dummy cycles directly
spi: mtk-snfi: Drop redundant check
spi: nxp-fspi: Consume dummy cycles directly
spi: nxp-fspi: Reject mixed DTR modes
spi: nxp-xspi: Consume dummy cycles directly
spi: nxp-xspi: Fix a comment
spi: nxp-xspi: Reject mixed DTR modes
spi: realtek-rtl-snand: Drop redundant check
spi: rpc-if: Consume dummy cycles directly
spi: rtk-nor: Consume dummy cycles directly
spi: rtk-nor: Drop redundant checks
spi: sn-f-ospi: Consume dummy cycles directly
spi: spi-qpic-snand: Drop redundant check
spi: stm32-ospi: Consume dummy cycles directly
spi: stm32-ospi: Reject excessive dummy cycle counts
spi: stm32-qspi: Consume dummy cycles directly
spi: stm32-qspi: Reject excessive dummy cycle counts
spi: wpcm-fiu: Drop redundant checks
spi: zynqmp-gqspi: Consume dummy cycles directly
mtd: spi-nor: Express the dummy phase in cycles
drivers/mtd/spi-nor/core.c | 36 ++---
drivers/mtd/spi-nor/core.h | 8 +-
drivers/mtd/spi-nor/micron-st.c | 2 +-
drivers/mtd/spi-nor/spansion.c | 8 +-
drivers/spi/atmel-quadspi.c | 27 ++--
drivers/spi/spi-amlogic-spifc-a1.c | 15 +-
drivers/spi/spi-amlogic-spifc-a4.c | 29 +---
drivers/spi/spi-cadence-quadspi.c | 50 ++----
drivers/spi/spi-fsl-qspi.c | 13 +-
drivers/spi/spi-mem.c | 287 ++++++++++++++++++++++++++++++----
drivers/spi/spi-microchip-core-qspi.c | 12 +-
drivers/spi/spi-mtk-snfi.c | 2 +-
drivers/spi/spi-nxp-fspi.c | 24 ++-
drivers/spi/spi-nxp-xspi.c | 24 ++-
drivers/spi/spi-qpic-snand.c | 2 +-
drivers/spi/spi-realtek-rtl-snand.c | 2 +-
drivers/spi/spi-rpc-if.c | 10 +-
drivers/spi/spi-rtk-nor.c | 31 ++--
drivers/spi/spi-sn-f-ospi.c | 15 +-
drivers/spi/spi-stm32-ospi.c | 28 ++--
drivers/spi/spi-stm32-qspi.c | 26 ++-
drivers/spi/spi-wpcm-fiu.c | 3 -
drivers/spi/spi-zynqmp-gqspi.c | 29 +++-
include/linux/spi/spi-mem.h | 39 ++++-
include/trace/events/spi-mem.h | 5 +-
25 files changed, 482 insertions(+), 245 deletions(-)
---
base-commit: 19d1b4de6d37bccecc3ad9144d279f1baa405eb1
change-id: 20261125-macronix-upstreaming-spi-mem-cycles-103274708fec
prerequisite-message-id: <20261126-macronix-upstreaming-spi-driver-fixes-v1-0-ca8e924cca1b@bootlin.com>
prerequisite-patch-id: 2f68de4139876dfa8e57afb65b429a69628214ab
prerequisite-patch-id: 7182a6b4808193323664f79c226ae2a57104b473
prerequisite-patch-id: 34a99e8e6644d1db0978b5aa6ca90342a42561f8
prerequisite-patch-id: cc060f58179f09af4593df6909b958a29bf11cb2
prerequisite-patch-id: c5a7a78ef01696c25c10b6d2968c0b65ab0f4ec6
prerequisite-patch-id: 340ee3d69095259d6141c017ea59c0c137d353b5
prerequisite-patch-id: 1629dd27a1f0b1d6622199cc7603dad4b17d29b6
prerequisite-patch-id: 29bc9e59b1d732a00cd65ba1d73270e051898fd7
prerequisite-patch-id: 7a028831f1df214099241bfac0dc290e2f799276
prerequisite-patch-id: c28c78ff316ce2ac8c1b6151367662ca8039acd3
prerequisite-patch-id: eea3b5adeb19b753a14bf03c5114eb407566c248
prerequisite-patch-id: 87bd95813776fe216ac157f9fad23586c71db87b
Best regards,
--
Miquel Raynal <miquel.raynal@bootlin.com>
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH RFC v2 01/35] spi: spi-mem: Stop checking the dummy buswidth against board wiring
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 02/35] spi: spi-mem: Fix the odd byte count error message Miquel Raynal
` (33 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The dummy phase does not transfer any data. Its buswidth only describes
the pin state during the dummy cycles, so it must not be validated
against the board's Tx/Rx wiring.
Drop that check (the sanity check in spi_mem_check_op() stays).
Suggested-by: Pratyush Yadav <pratyush@kernel.org>
Link: https://lore.kernel.org/linux-mtd/20241112075242.174010-1-linchengming884@gmail.com/T/#m7cc1a5055702f5a42a8f3949c968842d845914d7
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
This is not really a fix, so no fixes/cc:stable is on purpose.
---
drivers/spi/spi-mem.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 8047b7508c8d..648982350863 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -152,9 +152,10 @@ static bool spi_mem_check_buswidth(struct spi_mem *mem,
spi_check_buswidth_req(mem, op->addr.buswidth, true))
return false;
- if (op->dummy.nbytes &&
- spi_check_buswidth_req(mem, op->dummy.buswidth, true))
- return false;
+ /*
+ * The dummy phase implies no actual transmission nor reception.
+ * Its buswidth therefore does not matter much.
+ */
if (op->data.dir != SPI_MEM_NO_DATA &&
spi_check_buswidth_req(mem, op->data.buswidth,
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 02/35] spi: spi-mem: Fix the odd byte count error message
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 01/35] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 03/35] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
` (32 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The check rejects odd byte counts but the error message claims that
even byte numbers are not allowed. Fix the wording.
Fixes: 8618271887ca ("spi: spi-mem: Limit octal DTR constraints to octal DTR situations")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 648982350863..f4d71f740163 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -188,7 +188,7 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
(op->dummy.nbytes % 2) ||
(op->data.nbytes % 2)) {
dev_err(&ctlr->dev,
- "Even byte numbers not allowed in octal DTR operations\n");
+ "Odd byte numbers not allowed in octal DTR operations\n");
return false;
}
}
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 03/35] spi: spi-mem: Handle a corner case while sanitizing ops
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 01/35] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 02/35] spi: spi-mem: Fix the odd byte count error message Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 04/35] spi: spi-mem: Sanitize mixed DTR modes Miquel Raynal
` (31 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
Mixed DTR operations (eg. 1S-xD-yD) set op_is_dtr but do not enter the
ODTR checks, so their command size is never validated.
Always check the command size: one byte, or two bytes in ODTR mode.
Require an even byte count only on 8-bit DTR phases, which carry two
bytes per clock cycle. Narrower DTR phases may use odd counts.
Regarding the dummy phase, either the controller is only supporting
"bytes", in which case the check must be performed, or (soon) they might
advertize the dummy_cycles capability for which sending an even number
of dummy bytes is irrelevant. The check can remain though, since in this
case dummy.nbytes will be 0 (those values are mutually exclusive, the
core will check that).
Fixes: 8618271887ca ("spi: spi-mem: Limit octal DTR constraints to octal DTR situations")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index f4d71f740163..3989017dd86f 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -171,6 +171,7 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
struct spi_controller *ctlr = mem->spi->controller;
bool op_is_dtr =
op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr;
+ bool op_is_odtr = op->cmd.dtr && op->cmd.buswidth == 8;
if (op_is_dtr) {
if (!spi_mem_controller_is_capable(ctlr, dtr) && !ctlr->dtr_caps)
@@ -178,23 +179,20 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
if (op->data.swap16 && !spi_mem_controller_is_capable(ctlr, swap16))
return false;
+ }
- /* Extra 8D-8D-8D limitations */
- if (op->cmd.dtr && op->cmd.buswidth == 8) {
- if (op->cmd.nbytes != 2)
- return false;
+ /* Command phase is single byte, except in ODTR mode where it is two */
+ if ((!op_is_odtr && op->cmd.nbytes != 1) ||
+ (op_is_odtr && op->cmd.nbytes != 2))
+ return false;
- if ((op->addr.nbytes % 2) ||
- (op->dummy.nbytes % 2) ||
- (op->data.nbytes % 2)) {
- dev_err(&ctlr->dev,
- "Odd byte numbers not allowed in octal DTR operations\n");
- return false;
- }
- }
- } else {
- if (op->cmd.nbytes != 1)
- return false;
+ /* ODTR phases shall carry even byte numbers */
+ if ((op->addr.dtr && op->addr.buswidth == 8 && op->addr.nbytes % 2) ||
+ (op->dummy.dtr && op->dummy.buswidth == 8 && op->dummy.nbytes % 2) ||
+ (op->data.dtr && op->data.buswidth == 8 && op->data.nbytes % 2)) {
+ dev_err(&ctlr->dev,
+ "Odd byte numbers not allowed in octal DTR phases\n");
+ return false;
}
if (op->data.ecc) {
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 04/35] spi: spi-mem: Sanitize mixed DTR modes
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (2 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 03/35] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 05/35] spi: spi-mem: Sanitize mixed buswidth Miquel Raynal
` (30 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The following operations are supported:
- S-S-D
- S-D-D
- D-D-D
But the following are not:
- S-D-S
- D-D-S
- D-S-S
Make sure these cases are refused by the core.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 3989017dd86f..25f795d5e9ba 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -195,6 +195,27 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
return false;
}
+ /* xD-xS-xS is not allowed */
+ if (op->cmd.dtr) {
+ if ((op->addr.nbytes && !op->addr.dtr) ||
+ (op->dummy.nbytes && !op->dummy.dtr) ||
+ (op->data.nbytes && !op->data.dtr))
+ return false;
+ }
+
+ /* xS-xD-xS is not allowed */
+ if (op->addr.nbytes && op->addr.dtr) {
+ if ((op->dummy.nbytes && !op->dummy.dtr) ||
+ (op->data.nbytes && !op->data.dtr))
+ return false;
+ }
+
+ /* xS-xS-xD-xS is not allowed */
+ if (op->dummy.nbytes && op->dummy.dtr) {
+ if (op->data.nbytes && !op->data.dtr)
+ return false;
+ }
+
if (op->data.ecc) {
if (!spi_mem_controller_is_capable(ctlr, ecc))
return false;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 05/35] spi: spi-mem: Sanitize mixed buswidth
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (3 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 04/35] spi: spi-mem: Sanitize mixed DTR modes Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles Miquel Raynal
` (29 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
Buswidth is allowed to evolve over phases. Many controllers strictly
apply the settings passed by the core. In practice for an X-Y-Z
operation where X, Y and Z represent the buswidth of the command,
address and data phase, respectively. We do not support:
- Y < X
- Z < Y
- Z < X
Make sure those conditions are sanitized early by the core, to avoid the
feeling that these needs to be checked in controller drivers. The
implementation also covers the dummy.nbytes case with the same logic.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 25f795d5e9ba..a1f129c47698 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -216,6 +216,15 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
return false;
}
+ /* Bus width can only grow across phases, ie. 1-4-1, or 1-8-4 are not allowed */
+ if ((op->addr.nbytes && op->addr.buswidth < op->cmd.buswidth) ||
+ (op->dummy.nbytes && op->dummy.buswidth < op->cmd.buswidth) ||
+ (op->data.nbytes && op->data.buswidth < op->cmd.buswidth) ||
+ (op->addr.nbytes && op->dummy.nbytes && op->dummy.buswidth < op->addr.buswidth) ||
+ (op->addr.nbytes && op->data.nbytes && op->data.buswidth < op->addr.buswidth) ||
+ (op->dummy.nbytes && op->data.nbytes && op->data.buswidth < op->dummy.buswidth))
+ return false;
+
if (op->data.ecc) {
if (!spi_mem_controller_is_capable(ctlr, ecc))
return false;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (4 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 05/35] spi: spi-mem: Sanitize mixed buswidth Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:43 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 07/35] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
` (28 subsequent siblings)
34 siblings, 1 reply; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The dummy phase is a number of clock cycles, not a number of bytes. SPI
NOR flashes commonly require a number of dummy cycles that is not a
multiple of 8, and the byte-based representation cannot express it.
Add a dummy.ncycles field and make it the primary representation. Keep
dummy.nbytes for the legacy byte-oriented controllers and users. The two
fields are mutually exclusive and spi_mem_check_op() enforces that rule.
Controllers that can program an arbitrary number of cycles advertise the
dummy_cycles capability and consume dummy.ncycles directly. The core
converts the legacy dummy.nbytes to cycles for them, so the users that
still describe the dummy phase in bytes keep working. If the byte count
cannot be expressed as a whole number of cycles, the operation is
rejected.
For the other controllers the core converts dummy.ncycles to the legacy
dummy.nbytes representation using the usual maths. If the cycle count
cannot be represented exactly, the operation is rejected instead of
being silently truncated.
Link: https://lore.kernel.org/all/20220911174551.653599-1-sergiu.moga@microchip.com/
Link: https://lore.kernel.org/all/20250115134158.19908-1-pratyush@kernel.org/
Link: https://lore.kernel.org/all/20220911174551.653599-1-sergiu.moga@microchip.com/
Link: https://lore.kernel.org/all/20250115134158.19908-1-pratyush@kernel.org/
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 224 ++++++++++++++++++++++++++++++++++++++---
include/linux/spi/spi-mem.h | 39 ++++++-
include/trace/events/spi-mem.h | 5 +-
3 files changed, 245 insertions(+), 23 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index a1f129c47698..1642388b7004 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -12,6 +12,24 @@
#include <linux/spi/spi-mem.h>
#include <linux/sched/task_stack.h>
+static unsigned int
+spi_mem_get_dummy_nbytes(const struct spi_mem_op *op)
+{
+ u32 bits;
+
+ if (!op->dummy.ncycles)
+ return op->dummy.nbytes;
+
+ if (!op->dummy.buswidth)
+ return 0;
+
+ bits = (u32)op->dummy.ncycles * op->dummy.buswidth;
+ if (op->dummy.dtr)
+ bits *= 2;
+
+ return DIV_ROUND_UP(bits, 8);
+}
+
#define CREATE_TRACE_POINTS
#include <trace/events/spi-mem.h>
@@ -252,6 +270,111 @@ static bool spi_mem_buswidth_is_valid(u8 buswidth)
return true;
}
+/**
+ * spi_mem_dummy_cycles_to_bytes() - Convert the dummy phase cycles to bytes
+ * @op: the SPI memory operation
+ *
+ * Return: the number of dummy bytes on success, a negative error code if the
+ * dummy phase cannot be represented as a whole number of bytes.
+ * If @op->dummy.ncycles is zero, @op->dummy.nbytes is returned.
+ *
+ * This helper can be used to convert dummy cycles into dummy bytes for
+ * controllers that can only insert a whole number of dummy bytes.
+ */
+static int spi_mem_dummy_cycles_to_bytes(const struct spi_mem_op *op)
+{
+ u32 bits;
+
+ if (!op->dummy.ncycles)
+ return op->dummy.nbytes;
+
+ if (!op->dummy.buswidth)
+ return -EOPNOTSUPP;
+
+ bits = (u32)op->dummy.ncycles * op->dummy.buswidth;
+ if (op->dummy.dtr)
+ bits *= 2;
+
+ if (bits % 8 || bits / 8 > U8_MAX)
+ return -EOPNOTSUPP;
+
+ return bits / 8;
+}
+
+/**
+ * spi_mem_dummy_bytes_to_cycles() - Convert the dummy phase bytes to cycles
+ * @op: the SPI memory operation
+ *
+ * Return: the number of dummy clock cycles on success, a negative error code
+ * if the dummy phase cannot be represented as a whole number of clock
+ * cycles. If @op->dummy.nbytes is zero, @op->dummy.ncycles is returned.
+ *
+ * This helper can be used to convert inlet operations using dummy bytes
+ * into operations using dummy cycles.
+ */
+static int spi_mem_dummy_bytes_to_cycles(const struct spi_mem_op *op)
+{
+ u32 bits, bits_per_cycle;
+
+ if (!op->dummy.nbytes)
+ return op->dummy.ncycles;
+
+ bits_per_cycle = op->dummy.buswidth;
+ if (op->dummy.dtr)
+ bits_per_cycle *= 2;
+ if (!bits_per_cycle)
+ return -EOPNOTSUPP;
+
+ bits = (u32)op->dummy.nbytes * 8;
+ if (bits % bits_per_cycle)
+ return -EOPNOTSUPP;
+
+ bits /= bits_per_cycle;
+ if (bits > U8_MAX)
+ return -EOPNOTSUPP;
+
+ return bits;
+}
+
+/*
+ * Controllers either program the dummy phase in clock cycles or in whole
+ * bytes. Convert the representation used by the operation to the one the
+ * controller expects.
+ *
+ * Return: 0 if the operation is lossless, -EOPNOTSUPP otherwise.
+ */
+static int spi_mem_convert_dummy(struct spi_mem *mem, struct spi_mem_op *op)
+{
+ struct spi_controller *ctlr = mem->spi->controller;
+ int n;
+
+ if (op->dummy.ncycles) {
+ if (spi_mem_controller_is_capable(ctlr, dummy_cycles))
+ return 0;
+
+ n = spi_mem_dummy_cycles_to_bytes(op);
+ if (n < 0)
+ return n;
+
+ op->dummy.nbytes = n;
+ op->dummy.ncycles = 0;
+ } else if (op->dummy.nbytes) {
+ if (!spi_mem_controller_is_capable(ctlr, dummy_cycles))
+ return 0;
+
+ n = spi_mem_dummy_bytes_to_cycles(op);
+ if (n < 0)
+ return n;
+
+ op->dummy.ncycles = n;
+ op->dummy.nbytes = 0;
+
+ return 0;
+ }
+
+ return 0;
+}
+
static int spi_mem_check_op(const struct spi_mem_op *op)
{
if (!op->cmd.buswidth || !op->cmd.nbytes)
@@ -259,9 +382,13 @@ static int spi_mem_check_op(const struct spi_mem_op *op)
if ((op->addr.nbytes && !op->addr.buswidth) ||
(op->dummy.nbytes && !op->dummy.buswidth) ||
+ (op->dummy.ncycles && !op->dummy.buswidth) ||
(op->data.nbytes && !op->data.buswidth))
return -EINVAL;
+ if (op->dummy.nbytes && op->dummy.ncycles)
+ return -EINVAL;
+
if (!spi_mem_buswidth_is_valid(op->cmd.buswidth) ||
!spi_mem_buswidth_is_valid(op->addr.buswidth) ||
!spi_mem_buswidth_is_valid(op->dummy.buswidth) ||
@@ -321,6 +448,9 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
if (spi_mem_check_op(&eval_op))
return false;
+ if (spi_mem_convert_dummy(mem, &eval_op))
+ return false;
+
return spi_mem_internal_supports_op(mem, &eval_op);
}
EXPORT_SYMBOL_GPL(spi_mem_supports_op);
@@ -366,6 +496,7 @@ static void spi_mem_access_end(struct spi_mem *mem)
static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats,
const struct spi_mem_op *op, int exec_op_ret)
{
+ int dummy_nbytes = spi_mem_get_dummy_nbytes(op);
struct spi_statistics *stats;
u64 len, l2len;
@@ -382,7 +513,7 @@ static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats,
/* Use the sum of all lengths as bytes count and histogram value. */
len = op->cmd.nbytes + op->addr.nbytes;
- len += op->dummy.nbytes + op->data.nbytes;
+ len += dummy_nbytes + op->data.nbytes;
u64_stats_add(&stats->bytes, len);
l2len = min(fls(len), SPI_STATISTICS_HISTO_SIZE) - 1;
u64_stats_inc(&stats->transfer_bytes_histo[l2len]);
@@ -409,31 +540,41 @@ static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats,
/**
* spi_mem_exec_op() - Execute a memory operation
* @mem: the SPI memory
- * @op: the memory operation to execute
+ * @ro_op: the memory operation to execute (shall not be edited)
*
* Executes a memory operation.
*
- * This function first checks that @op is supported and then tries to execute
- * it.
+ * This function first checks that @ro_op is supported and then tries to
+ * execute it.
*
* Return: 0 in case of success, a negative error code otherwise.
*/
-int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
+int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *ro_op)
{
unsigned int tmpbufsize, xferpos = 0, totalxferlen = 0;
struct spi_controller *ctlr = mem->spi->controller;
+ struct spi_mem_op wr_op = *ro_op, *op = &wr_op;
struct spi_transfer xfers[4] = { };
struct spi_message msg;
u8 *tmpbuf;
int ret;
/* Make sure the operation frequency is correct before going futher */
- spi_mem_adjust_op_freq(mem, (struct spi_mem_op *)op);
+ spi_mem_adjust_op_freq(mem, op);
+
+ ret = spi_mem_check_op(op);
+ if (ret)
+ return ret;
+
+ /* Also make sure the dummy phase can be consumed by the controller */
+ ret = spi_mem_convert_dummy(mem, op);
+ if (ret)
+ return ret;
dev_vdbg(&mem->spi->dev, "[cmd: 0x%02x][%dB addr: %#8llx][%2dB dummy][%4dB data %s] %d%c-%d%c-%d%c-%d%c @ %uHz\n",
op->cmd.opcode,
op->addr.nbytes, (op->addr.nbytes ? op->addr.val : 0),
- op->dummy.nbytes,
+ spi_mem_get_dummy_nbytes(op),
op->data.nbytes, (op->data.nbytes ? (op->data.dir == SPI_MEM_DATA_IN ? " read" : "write") : " "),
op->cmd.buswidth, op->cmd.dtr ? 'D' : 'S',
op->addr.buswidth, op->addr.dtr ? 'D' : 'S',
@@ -441,10 +582,6 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
op->data.buswidth, op->data.dtr ? 'D' : 'S',
op->max_freq ? op->max_freq : mem->spi->max_speed_hz);
- ret = spi_mem_check_op(op);
- if (ret)
- return ret;
-
if (!spi_mem_internal_supports_op(mem, op))
return -EOPNOTSUPP;
@@ -472,6 +609,22 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
}
}
+ /*
+ * spi_mem_convert_dummy() converted the dummy phase to cycles because
+ * the controller advertised the dummy_cycles capability. The regular
+ * SPI transfer path below builds spi_transfer segments and can only
+ * express the dummy phase in bytes, so convert it back. Reject the
+ * operation if the cycle count cannot be represented exactly.
+ */
+ if (op->dummy.ncycles) {
+ ret = spi_mem_dummy_cycles_to_bytes(op);
+ if (ret < 0)
+ return ret;
+
+ op->dummy.nbytes = ret;
+ op->dummy.ncycles = 0;
+ }
+
tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
/*
@@ -625,12 +778,22 @@ int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
{
struct spi_controller *ctlr = mem->spi->controller;
size_t len;
+ int ret;
+
+ ret = spi_mem_convert_dummy(mem, op);
+ if (ret)
+ return ret;
if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)
return ctlr->mem_ops->adjust_op_size(mem, op);
if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) {
- len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
+ int dummy_nbytes = spi_mem_dummy_cycles_to_bytes(op);
+
+ if (dummy_nbytes < 0)
+ return dummy_nbytes;
+
+ len = op->cmd.nbytes + op->addr.nbytes + dummy_nbytes;
if (len > spi_max_transfer_size(mem->spi))
return -EINVAL;
@@ -701,9 +864,12 @@ u64 spi_mem_calc_op_duration(struct spi_mem *mem, struct spi_mem_op *op)
ncycles += ((op->cmd.nbytes * 8) / op->cmd.buswidth) / (op->cmd.dtr ? 2 : 1);
ncycles += ((op->addr.nbytes * 8) / op->addr.buswidth) / (op->addr.dtr ? 2 : 1);
- /* Dummy bytes are optional for some SPI flash memory operations */
- if (op->dummy.nbytes)
- ncycles += ((op->dummy.nbytes * 8) / op->dummy.buswidth) / (op->dummy.dtr ? 2 : 1);
+ /* Dummy cycles are optional for some SPI flash memory operations */
+ if (op->dummy.ncycles)
+ ncycles += op->dummy.ncycles;
+ else if (op->dummy.nbytes)
+ ncycles += ((op->dummy.nbytes * 8) / op->dummy.buswidth) /
+ (op->dummy.dtr ? 2 : 1);
ncycles += ((op->data.nbytes * 8) / op->data.buswidth) / (op->data.dtr ? 2 : 1);
@@ -809,6 +975,21 @@ spi_mem_dirmap_create(struct spi_mem *mem,
desc->mem = mem;
desc->info = *info;
desc->info.op_tmpl = &desc->info.primary_op_tmpl;
+
+ ret = spi_mem_convert_dummy(mem, &desc->info.primary_op_tmpl);
+ if (ret) {
+ kfree(desc);
+ return ERR_PTR(ret);
+ }
+
+ if (desc->info.secondary_op_tmpl.cmd.opcode) {
+ ret = spi_mem_convert_dummy(mem, &desc->info.secondary_op_tmpl);
+ if (ret) {
+ kfree(desc);
+ return ERR_PTR(ret);
+ }
+ }
+
if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) {
ret = spi_mem_access_start(mem);
if (ret) {
@@ -819,6 +1000,8 @@ spi_mem_dirmap_create(struct spi_mem *mem,
ret = ctlr->mem_ops->dirmap_create(desc);
spi_mem_access_end(mem);
+ } else {
+ ret = -EOPNOTSUPP;
}
if (ret) {
@@ -1065,6 +1248,7 @@ int spi_mem_poll_status(struct spi_mem *mem,
u16 timeout_ms)
{
struct spi_controller *ctlr = mem->spi->controller;
+ struct spi_mem_op eval_op = *op;
int ret = -EOPNOTSUPP;
int read_status_ret;
u16 status;
@@ -1074,11 +1258,19 @@ int spi_mem_poll_status(struct spi_mem *mem,
return -EINVAL;
if (ctlr->mem_ops && ctlr->mem_ops->poll_status && !spi_get_csgpiod(mem->spi, 0)) {
+ ret = spi_mem_check_op(&eval_op);
+ if (ret)
+ return ret;
+
+ ret = spi_mem_convert_dummy(mem, &eval_op);
+ if (ret)
+ return ret;
+
ret = spi_mem_access_start(mem);
if (ret)
return ret;
- ret = ctlr->mem_ops->poll_status(mem, op, mask, match,
+ ret = ctlr->mem_ops->poll_status(mem, &eval_op, mask, match,
initial_delay_us, polling_delay_us,
timeout_ms);
diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h
index 0cce6b57242a..fc9f75c0609f 100644
--- a/include/linux/spi/spi-mem.h
+++ b/include/linux/spi/spi-mem.h
@@ -11,6 +11,7 @@
#ifndef __LINUX_SPI_MEM_H
#define __LINUX_SPI_MEM_H
+#include <linux/math.h>
#include <linux/spi/spi.h>
#define SPI_MEM_OP_CMD(__opcode, __buswidth) \
@@ -75,6 +76,12 @@
.buswidth = __buswidth, \
}
+#define SPI_MEM_OP_DUMMY_CYCLES(__ncycles, __buswidth) \
+ { \
+ .ncycles = __ncycles, \
+ .buswidth = __buswidth, \
+ }
+
#define SPI_MEM_DTR_OP_DUMMY(__nbytes, __buswidth) \
{ \
.nbytes = __nbytes, \
@@ -82,6 +89,13 @@
.dtr = true, \
}
+#define SPI_MEM_DTR_OP_DUMMY_CYCLES(__ncycles, __buswidth) \
+ { \
+ .ncycles = __ncycles, \
+ .buswidth = __buswidth, \
+ .dtr = true, \
+ }
+
#define SPI_MEM_OP_NO_DUMMY { }
#define SPI_MEM_OP_DATA_IN(__nbytes, __buf, __buswidth) \
@@ -154,10 +168,18 @@ enum spi_mem_data_dir {
* address value, so users should make sure the value fits in the
* assigned number of bytes.
* @dummy: data for dummy operation
- * @dummy.nbytes: number of dummy bytes to send after an opcode or address. Can
- * be zero if the operation does not require dummy bytes
- * @dummy.buswidth: number of IO lanes used to transmit the dummy bytes
- * @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not
+ * @dummy.ncycles: number of dummy clock cycles to insert after an opcode or
+ * address. Can be zero if the operation does not require
+ * dummy cycles. Mutually exclusive with @dummy.nbytes.
+ * @dummy.nbytes: legacy number of dummy bytes to send after an opcode or
+ * address. Can be zero if the operation does not require dummy
+ * bytes. Mutually exclusive with @dummy.ncycles.
+ * @dummy.buswidth: number of IO lanes used during the dummy phase. It is
+ * also used to convert @dummy.ncycles to bytes for controllers
+ * that can only insert a whole number of dummy bytes.
+ * @dummy.dtr: whether the dummy phase is clocked in DTR mode. This only
+ * describes the pin state and does not change the number of
+ * clock cycles.
* @data: the data attributes
* @data.buswidth: number of IO lanes used to send/receive the data
* @data.dtr: whether the data should be sent in DTR mode or not
@@ -191,6 +213,7 @@ struct spi_mem_op {
} addr;
struct {
+ u8 ncycles;
u8 nbytes;
u8 buswidth;
u8 dtr : 1;
@@ -392,6 +415,11 @@ struct spi_controller_mem_ops {
* is a pause in the transfer (eg. internal bus contention or
* DMA arbitration on an interconnect). Features such as NAND
* continuous reads shall not be leveraged.
+ * @dummy_cycles: Supports programming the exact number of dummy clock cycles.
+ * When set, the core converts the legacy @dummy.nbytes to clock
+ * cycles. When unset, the core converts @dummy.ncycles to whole
+ * dummy bytes for the controller and rejects operations that
+ * cannot be converted exactly.
*/
struct spi_controller_mem_caps {
bool dtr;
@@ -400,6 +428,7 @@ struct spi_controller_mem_caps {
bool per_op_freq;
bool secondary_op_tmpl;
bool no_cs_assertion;
+ bool dummy_cycles;
};
#define spi_mem_controller_is_capable(ctlr, cap) \
@@ -473,7 +502,7 @@ bool spi_mem_supports_op(struct spi_mem *mem,
const struct spi_mem_op *op);
int spi_mem_exec_op(struct spi_mem *mem,
- const struct spi_mem_op *op);
+ const struct spi_mem_op *ro_op);
const char *spi_mem_get_name(struct spi_mem *mem);
diff --git a/include/trace/events/spi-mem.h b/include/trace/events/spi-mem.h
index d13f0bcff5e7..9df571d7799d 100644
--- a/include/trace/events/spi-mem.h
+++ b/include/trace/events/spi-mem.h
@@ -22,7 +22,8 @@ TRACE_EVENT(spi_mem_start_op,
TP_STRUCT__entry(
__string(name, mem->name)
- __dynamic_array(u8, op, 1 + op->addr.nbytes + op->dummy.nbytes)
+ __dynamic_array(u8, op, 1 + op->addr.nbytes +
+ spi_mem_get_dummy_nbytes(op))
__dynamic_array(u8, data, op->data.dir == SPI_MEM_DATA_OUT ?
min(op->data.nbytes, 64) : 0)
__field(u32, data_len)
@@ -53,7 +54,7 @@ TRACE_EVENT(spi_mem_start_op,
op->addr.val >> (8 * (op->addr.nbytes - i - 1));
memset(((u8 *)__get_dynamic_array(op)) + op->addr.nbytes + 1,
- 0xff, op->dummy.nbytes);
+ 0xff, spi_mem_get_dummy_nbytes(op));
__entry->data_len = op->data.nbytes;
__entry->data_buswidth = op->data.buswidth;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 07/35] spi: amlogic-spifc-a1: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (5 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 08/35] spi: amlogic-spifc-a1: Reject excessive dummy cycle counts Miquel Raynal
` (27 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-amlogic-spifc-a1.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-amlogic-spifc-a1.c b/drivers/spi/spi-amlogic-spifc-a1.c
index c7cccc8de6dc..d99c72c7a965 100644
--- a/drivers/spi/spi-amlogic-spifc-a1.c
+++ b/drivers/spi/spi-amlogic-spifc-a1.c
@@ -90,7 +90,7 @@
#define SPIFC_A1_USER_DUMMY(op) ( \
SPIFC_A1_USER_DUMMY_ENABLE | \
FIELD_PREP(SPIFC_A1_USER_DUMMY_MODE, ilog2((op)->dummy.buswidth)) | \
- FIELD_PREP(SPIFC_A1_USER_DUMMY_CLK_CYCLES, (op)->dummy.nbytes << 3))
+ FIELD_PREP(SPIFC_A1_USER_DUMMY_CLK_CYCLES, (op)->dummy.ncycles))
#define SPIFC_A1_TSLCH_VAL FIELD_PREP(SPIFC_A1_TSLCH, 1)
#define SPIFC_A1_TCLSH_VAL FIELD_PREP(SPIFC_A1_TCLSH, 1)
@@ -269,7 +269,7 @@ static int amlogic_spifc_a1_exec_op(struct spi_mem *mem,
amlogic_spifc_a1_set_addr(spifc, op->addr.val,
SPIFC_A1_USER_ADDR(op));
- if (op->dummy.nbytes)
+ if (op->dummy.ncycles)
amlogic_spifc_a1_set_dummy(spifc, SPIFC_A1_USER_DUMMY(op));
if (data_size) {
@@ -321,6 +321,7 @@ static const struct spi_controller_mem_ops amlogic_spifc_a1_mem_ops = {
static const struct spi_controller_mem_caps amlogic_spifc_a1_mem_caps = {
.per_op_freq = true,
+ .dummy_cycles = true,
};
static int amlogic_spifc_a1_probe(struct platform_device *pdev)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 08/35] spi: amlogic-spifc-a1: Reject excessive dummy cycle counts
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (6 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 07/35] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 09/35] spi: amlogic-spifc-a4: Consume dummy cycles directly Miquel Raynal
` (26 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller stores the number of dummy cycles in a 6-bit field.
Prevent field corruption by adding a proper ->supports_op() callback.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-amlogic-spifc-a1.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/spi/spi-amlogic-spifc-a1.c b/drivers/spi/spi-amlogic-spifc-a1.c
index d99c72c7a965..bbe1b6b52b85 100644
--- a/drivers/spi/spi-amlogic-spifc-a1.c
+++ b/drivers/spi/spi-amlogic-spifc-a1.c
@@ -314,7 +314,17 @@ static void amlogic_spifc_a1_hw_init(struct amlogic_spifc_a1 *spifc)
writel(0, spifc->base + SPIFC_A1_USER_DBUF_ADDR_REG);
}
+static bool amlogic_spifc_a1_supports_op(struct spi_mem *mem,
+ const struct spi_mem_op *op)
+{
+ if (op->dummy.ncycles > FIELD_MAX(SPIFC_A1_USER_DUMMY_CLK_CYCLES))
+ return false;
+
+ return spi_mem_default_supports_op(mem, op);
+}
+
static const struct spi_controller_mem_ops amlogic_spifc_a1_mem_ops = {
+ .supports_op = amlogic_spifc_a1_supports_op,
.exec_op = amlogic_spifc_a1_exec_op,
.adjust_op_size = amlogic_spifc_a1_adjust_op_size,
};
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 09/35] spi: amlogic-spifc-a4: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (7 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 08/35] spi: amlogic-spifc-a1: Reject excessive dummy cycle counts Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 10/35] spi: atmel-quadspi: " Miquel Raynal
` (25 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-amlogic-spifc-a4.c | 29 +++++------------------------
1 file changed, 5 insertions(+), 24 deletions(-)
diff --git a/drivers/spi/spi-amlogic-spifc-a4.c b/drivers/spi/spi-amlogic-spifc-a4.c
index 16346f50c7d9..9b658ed1a580 100644
--- a/drivers/spi/spi-amlogic-spifc-a4.c
+++ b/drivers/spi/spi-amlogic-spifc-a4.c
@@ -148,7 +148,6 @@
#define SFC_MAX_CS_NUM 2
/* SPI-FLASH R/W operation cmd */
-#define SPIFLASH_RD_OCTALIO 0xcb
#define SPIFLASH_RD_OCTAL 0x8b
#define SPIFLASH_RD_QUADIO 0xeb
#define SPIFLASH_RD_QUAD 0x6b
@@ -334,23 +333,9 @@ static int aml_sfc_send_addr(struct aml_sfc *sfc, const struct spi_mem_op *op)
return 0;
}
-static bool aml_sfc_is_xio_op(const struct spi_mem_op *op)
-{
- switch (op->cmd.opcode) {
- case SPIFLASH_RD_OCTALIO:
- case SPIFLASH_RD_QUADIO:
- case SPIFLASH_RD_DUALIO:
- return true;
- default:
- break;
- }
-
- return false;
-}
-
static int aml_sfc_send_cmd_addr_dummy(struct aml_sfc *sfc, const struct spi_mem_op *op)
{
- u32 dummy_cycle, cmd;
+ u32 cmd;
int ret;
ret = aml_sfc_send_cmd(sfc, op);
@@ -361,13 +346,8 @@ static int aml_sfc_send_cmd_addr_dummy(struct aml_sfc *sfc, const struct spi_mem
if (ret)
return ret;
- if (op->dummy.nbytes) {
- /* Dummy buswidth configuration is not supported */
- if (aml_sfc_is_xio_op(op))
- dummy_cycle = op->dummy.nbytes * 8 / op->data.buswidth;
- else
- dummy_cycle = op->dummy.nbytes * 8;
- cmd = CMD_DUMMY(sfc->cs_sel, dummy_cycle - 1);
+ if (op->dummy.ncycles) {
+ cmd = CMD_DUMMY(sfc->cs_sel, op->dummy.ncycles - 1);
return regmap_write(sfc->regmap_base, SFC_CMD, cmd);
}
@@ -803,7 +783,7 @@ static int aml_sfc_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
dev_dbg(sfc->dev, "cmd:0x%02x - addr:%08llX@%d:%u - dummy:%d:%u - data:%d:%u",
op->cmd.opcode, op->addr.val, op->addr.buswidth, op->addr.nbytes,
- op->dummy.buswidth, op->dummy.nbytes, op->data.buswidth, op->data.nbytes);
+ op->dummy.buswidth, op->dummy.ncycles, op->data.buswidth, op->data.nbytes);
ret = aml_sfc_pre_transfer(sfc, DEFAULT_PULLUP_CYCLE, CS_SETUP_CYCLE);
if (ret)
@@ -1057,6 +1037,7 @@ static int aml_sfc_ecc_finish_io_req(struct nand_device *nand,
static const struct spi_controller_mem_caps aml_sfc_mem_caps = {
.ecc = true,
+ .dummy_cycles = true,
};
static const struct nand_ecc_engine_ops aml_sfc_ecc_engine_ops = {
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 10/35] spi: atmel-quadspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (8 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 09/35] spi: amlogic-spifc-a4: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:41 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 11/35] spi: atmel-quadspi: Reject excessive dummy cycle counts Miquel Raynal
` (24 subsequent siblings)
34 siblings, 1 reply; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/atmel-quadspi.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index 0b695b0b3c98..abca99b32b61 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -502,7 +502,7 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem,
/* special case not supported by hardware */
if (op->addr.nbytes == 2 && op->cmd.buswidth != op->addr.buswidth &&
- op->dummy.nbytes == 0)
+ !op->dummy.ncycles)
return false;
return true;
@@ -543,8 +543,8 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
return mode;
ifr |= atmel_qspi_modes[mode].config;
- if (op->dummy.nbytes)
- dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
+ dummy_cycles = op->dummy.ncycles;
+
/*
* The controller allows 24 and 32-bit addressing while NAND-flash
@@ -706,14 +706,8 @@ static int atmel_qspi_sama7g5_set_cfg(struct atmel_qspi *aq,
return mode;
ifr |= atmel_qspi_sama7g5_modes[mode].config;
- if (op->dummy.buswidth && op->dummy.nbytes) {
- if (op->addr.dtr && op->dummy.dtr && op->data.dtr)
- ifr |= QSPI_IFR_NBDUM(op->dummy.nbytes * 8 /
- (2 * op->dummy.buswidth));
- else
- ifr |= QSPI_IFR_NBDUM(op->dummy.nbytes * 8 /
- op->dummy.buswidth);
- }
+ if (op->dummy.ncycles)
+ ifr |= QSPI_IFR_NBDUM(op->dummy.ncycles);
if (op->addr.nbytes) {
ifr |= FIELD_PREP(QSPI_IFR_ADDRL_SAMA7G5, op->addr.nbytes - 1) |
@@ -990,6 +984,10 @@ static const struct spi_controller_mem_ops atmel_qspi_mem_ops = {
.get_name = atmel_qspi_get_name
};
+static const struct spi_controller_mem_caps atmel_qspi_mem_caps = {
+ .dummy_cycles = true,
+};
+
static int atmel_qspi_set_pad_calibration(struct atmel_qspi *aq)
{
unsigned long pclk_rate;
@@ -1441,6 +1439,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
ctrl->set_cs_timing = atmel_qspi_set_cs_timing;
ctrl->bus_num = -1;
ctrl->mem_ops = &atmel_qspi_mem_ops;
+ ctrl->mem_caps = &atmel_qspi_mem_caps;
ctrl->num_chipselect = 1;
platform_set_drvdata(pdev, ctrl);
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 11/35] spi: atmel-quadspi: Reject excessive dummy cycle counts
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (9 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 10/35] spi: atmel-quadspi: " Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:47 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 12/35] spi: cadence-qspi: Consume dummy cycles directly Miquel Raynal
` (23 subsequent siblings)
34 siblings, 1 reply; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller stores the number of dummy cycles in a 5-bit field.
Programming more cycles would silently truncate the value and corrupt
the transfer. Add an extra ->supports_op() check for that.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/atmel-quadspi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index abca99b32b61..8946abaafa81 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -487,9 +487,15 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem,
if (!spi_mem_default_supports_op(mem, op))
return false;
+ if (op->dummy.ncycles && op->dummy.buswidth != op->addr.buswidth)
+ return false;
+
if (!op->addr.dtr && op->data.dtr)
return false;
+ if (op->dummy.ncycles > FIELD_MAX(QSPI_IFR_NBDUM_MASK))
+ return false;
+
if (aq->caps->octal) {
if (atmel_qspi_sama7g5_find_mode(op) < 0)
return false;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 12/35] spi: cadence-qspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (10 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 11/35] spi: atmel-quadspi: Reject excessive dummy cycle counts Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 13/35] spi: cadence-qspi: Drop redundant checks Miquel Raynal
` (22 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-cadence-quadspi.c | 48 +++++++++++++++------------------------
1 file changed, 18 insertions(+), 30 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 44d96b8cf8f0..df7c04e0e2d2 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -410,20 +410,6 @@ static unsigned int cqspi_calc_rdreg(const struct spi_mem_op *op)
return rdreg;
}
-static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op)
-{
- unsigned int dummy_clk;
-
- if (!op->dummy.nbytes)
- return 0;
-
- dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
- if (op->cmd.dtr)
- dummy_clk /= 2;
-
- return dummy_clk;
-}
-
static int cqspi_wait_idle(struct cqspi_st *cqspi)
{
const unsigned int poll_idle_retry = 3;
@@ -549,7 +535,6 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
size_t n_rx = op->data.nbytes;
unsigned int rdreg;
unsigned int reg;
- unsigned int dummy_clk;
size_t read_len;
int status;
@@ -574,12 +559,11 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
rdreg = cqspi_calc_rdreg(op);
writel(rdreg, reg_base + CQSPI_REG_RD_INSTR);
- dummy_clk = cqspi_calc_dummy(op);
- if (dummy_clk > CQSPI_DUMMY_CLKS_MAX)
+ if (op->dummy.ncycles > CQSPI_DUMMY_CLKS_MAX)
return -EOPNOTSUPP;
- if (dummy_clk)
- reg |= (dummy_clk & CQSPI_REG_CMDCTRL_DUMMY_MASK)
+ if (op->dummy.ncycles)
+ reg |= (op->dummy.ncycles & CQSPI_REG_CMDCTRL_DUMMY_MASK)
<< CQSPI_REG_CMDCTRL_DUMMY_LSB;
reg |= BIT(CQSPI_REG_CMDCTRL_RD_EN_LSB);
@@ -696,7 +680,6 @@ static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
{
struct cqspi_st *cqspi = f_pdata->cqspi;
void __iomem *reg_base = cqspi->iobase;
- unsigned int dummy_clk = 0;
unsigned int reg;
int ret;
u8 opcode;
@@ -714,13 +697,11 @@ static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
reg |= cqspi_calc_rdreg(op);
/* Setup dummy clock cycles */
- dummy_clk = cqspi_calc_dummy(op);
-
- if (dummy_clk > CQSPI_DUMMY_CLKS_MAX)
+ if (op->dummy.ncycles > CQSPI_DUMMY_CLKS_MAX)
return -EOPNOTSUPP;
- if (dummy_clk)
- reg |= (dummy_clk & CQSPI_REG_RD_INSTR_DUMMY_MASK)
+ if (op->dummy.ncycles)
+ reg |= (op->dummy.ncycles & CQSPI_REG_RD_INSTR_DUMMY_MASK)
<< CQSPI_REG_RD_INSTR_DUMMY_LSB;
writel(reg, reg_base + CQSPI_REG_RD_INSTR);
@@ -1523,16 +1504,14 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
bool all_true, all_false;
/*
- * op->dummy.dtr is required for converting nbytes into ncycles.
- * Also, don't check the dtr field of the op phase having zero nbytes.
+ * The controller only supports operations where all phases use the
+ * same DTR mode.
*/
all_true = op->cmd.dtr &&
(!op->addr.nbytes || op->addr.dtr) &&
- (!op->dummy.nbytes || op->dummy.dtr) &&
(!op->data.nbytes || op->data.dtr);
- all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr &&
- !op->data.dtr;
+ all_false = !op->cmd.dtr && !op->addr.dtr && !op->data.dtr;
if (all_true) {
/* Right now we only support 8-8-8 DTR mode. */
@@ -1550,6 +1529,13 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
return false;
}
+ /*
+ * The controller has no separate dummy buswidth: the dummy phase is
+ * clocked with the address buswidth.
+ */
+ if (op->dummy.ncycles && op->dummy.buswidth != op->addr.buswidth)
+ return false;
+
return spi_mem_default_supports_op(mem, op);
}
@@ -1739,12 +1725,14 @@ static const struct spi_controller_mem_ops cqspi_mem_ops = {
static const struct spi_controller_mem_caps cqspi_mem_caps = {
.dtr = true,
.per_op_freq = true,
+ .dummy_cycles = true,
};
static const struct spi_controller_mem_caps cqspi_am654_mem_caps = {
.dtr = true,
.per_op_freq = true,
.no_cs_assertion = true,
+ .dummy_cycles = true,
};
static int cqspi_setup_flash(struct cqspi_st *cqspi)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 13/35] spi: cadence-qspi: Drop redundant checks
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (11 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 12/35] spi: cadence-qspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 14/35] spi: cadence-qspi: Drop now useless checks Miquel Raynal
` (21 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The core already sanitizes the spi-mem operations, these checks are
redundant so let's drop them.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-cadence-quadspi.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index df7c04e0e2d2..97725ffeae93 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -476,9 +476,6 @@ static int cqspi_setup_opcode_ext(struct cqspi_flash_pdata *f_pdata,
unsigned int reg;
u8 ext;
- if (op->cmd.nbytes != 2)
- return -EINVAL;
-
/* Opcode extension is the LSB. */
ext = op->cmd.opcode & 0xff;
@@ -1515,11 +1512,7 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
if (all_true) {
/* Right now we only support 8-8-8 DTR mode. */
- if (op->cmd.nbytes && op->cmd.buswidth != 8)
- return false;
- if (op->addr.nbytes && op->addr.buswidth != 8)
- return false;
- if (op->data.nbytes && op->data.buswidth != 8)
+ if (op->cmd.buswidth != 8)
return false;
if (cqspi->is_rzn1)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 14/35] spi: cadence-qspi: Drop now useless checks
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (12 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 13/35] spi: cadence-qspi: Drop redundant checks Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 15/35] spi: fsl-qspi: Consume dummy cycles directly Miquel Raynal
` (20 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, so the dummy
buswidth is no longer used. Drop the check requiring it to match the
address buswidth.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-cadence-quadspi.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 97725ffeae93..d52e0aa1ea41 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1522,13 +1522,6 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
return false;
}
- /*
- * The controller has no separate dummy buswidth: the dummy phase is
- * clocked with the address buswidth.
- */
- if (op->dummy.ncycles && op->dummy.buswidth != op->addr.buswidth)
- return false;
-
return spi_mem_default_supports_op(mem, op);
}
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 15/35] spi: fsl-qspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (13 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 14/35] spi: cadence-qspi: Drop now useless checks Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 16/35] spi: microchip-core-qspi: " Miquel Raynal
` (19 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-fsl-qspi.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
index d2c2090442f8..383915b3ed41 100644
--- a/drivers/spi/spi-fsl-qspi.c
+++ b/drivers/spi/spi-fsl-qspi.c
@@ -399,7 +399,7 @@ static bool fsl_qspi_supports_op(struct spi_mem *mem,
if (op->addr.nbytes)
ret |= fsl_qspi_check_buswidth(q, op->addr.buswidth);
- if (op->dummy.nbytes)
+ if (op->dummy.ncycles)
ret |= fsl_qspi_check_buswidth(q, op->dummy.buswidth);
if (op->data.nbytes)
@@ -413,13 +413,12 @@ static bool fsl_qspi_supports_op(struct spi_mem *mem,
* to fit into a single LUT entry.
*/
if (op->addr.nbytes +
- (op->dummy.nbytes ? 1:0) +
+ (op->dummy.ncycles ? 1:0) +
(op->data.nbytes ? 1:0) > 6)
return false;
/* Max 64 dummy clock cycles supported */
- if (op->dummy.nbytes &&
- (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
+ if (op->dummy.ncycles > 64)
return false;
/* Max data length, check controller limits and alignment */
@@ -460,11 +459,10 @@ static void fsl_qspi_prepare_lut(struct fsl_qspi *q,
lutidx++;
}
- if (op->dummy.nbytes) {
+ if (op->dummy.ncycles) {
lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
LUT_PAD(op->dummy.buswidth),
- op->dummy.nbytes * 8 /
- op->dummy.buswidth);
+ op->dummy.ncycles);
lutidx++;
}
@@ -872,6 +870,7 @@ static const struct spi_controller_mem_ops fsl_qspi_mem_ops = {
static const struct spi_controller_mem_caps fsl_qspi_mem_caps = {
.per_op_freq = true,
+ .dummy_cycles = true,
};
static void fsl_qspi_disable(void *data)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 16/35] spi: microchip-core-qspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (14 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 15/35] spi: fsl-qspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 17/35] spi: mtk-snfi: Drop redundant check Miquel Raynal
` (18 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-microchip-core-qspi.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microchip-core-qspi.c
index c0ea65014d2e..80481011b83e 100644
--- a/drivers/spi/spi-microchip-core-qspi.c
+++ b/drivers/spi/spi-microchip-core-qspi.c
@@ -8,6 +8,7 @@
*
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/init.h>
@@ -420,7 +421,6 @@ static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct spi_devi
static void mchp_coreqspi_config_op(struct mchp_coreqspi *qspi, const struct spi_mem_op *op)
{
- u32 idle_cycles = 0;
int total_bytes, cmd_bytes, frames, ctrl;
cmd_bytes = op->cmd.nbytes + op->addr.nbytes;
@@ -459,11 +459,7 @@ static void mchp_coreqspi_config_op(struct mchp_coreqspi *qspi, const struct spi
writel_relaxed(frames, qspi->regs + REG_FRAMESUP);
frames = total_bytes & BYTESLOWER_MASK;
frames |= cmd_bytes << FRAMES_CMDBYTES_SHIFT;
-
- if (op->dummy.buswidth)
- idle_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
-
- frames |= idle_cycles << FRAMES_IDLE_SHIFT;
+ frames |= op->dummy.ncycles << FRAMES_IDLE_SHIFT;
ctrl = readl_relaxed(qspi->regs + REG_CONTROL);
if (ctrl & CONTROL_MODE12_MASK)
@@ -561,6 +557,9 @@ static bool mchp_coreqspi_supports_op(struct spi_mem *mem, const struct spi_mem_
if (!spi_mem_default_supports_op(mem, op))
return false;
+ if (op->dummy.ncycles > FIELD_MAX(FRAMES_IDLE_MASK))
+ return false;
+
if ((op->data.buswidth == 4 || op->data.buswidth == 2) &&
(op->cmd.buswidth == 1 && (op->addr.buswidth == 1 || op->addr.buswidth == 0))) {
/*
@@ -601,6 +600,7 @@ static const struct spi_controller_mem_ops mchp_coreqspi_mem_ops = {
static const struct spi_controller_mem_caps mchp_coreqspi_mem_caps = {
.per_op_freq = true,
+ .dummy_cycles = true,
};
static int mchp_coreqspi_unprepare_message(struct spi_controller *ctlr, struct spi_message *m)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 17/35] spi: mtk-snfi: Drop redundant check
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (15 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 16/35] spi: microchip-core-qspi: " Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 18/35] spi: nxp-fspi: Consume dummy cycles directly Miquel Raynal
` (17 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The core already sanitizes the spi-mem operations, this check is
redundant so let's drop it.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mtk-snfi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-mtk-snfi.c b/drivers/spi/spi-mtk-snfi.c
index 6e96e50fedad..882c64341e6d 100644
--- a/drivers/spi/spi-mtk-snfi.c
+++ b/drivers/spi/spi-mtk-snfi.c
@@ -1243,7 +1243,7 @@ static bool mtk_snand_supports_op(struct spi_mem *mem,
{
if (!spi_mem_default_supports_op(mem, op))
return false;
- if (op->cmd.nbytes != 1 || op->cmd.buswidth != 1)
+ if (op->cmd.buswidth != 1)
return false;
if (mtk_snand_is_page_ops(op))
return true;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 18/35] spi: nxp-fspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (16 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 17/35] spi: mtk-snfi: Drop redundant check Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:50 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 19/35] spi: nxp-fspi: Reject mixed DTR modes Miquel Raynal
` (16 subsequent siblings)
34 siblings, 1 reply; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles in the LUT, but
the driver converts the legacy dummy byte count itself. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-nxp-fspi.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index 66cb58f95fdb..e6fdded67a00 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -543,7 +543,7 @@ static bool nxp_fspi_supports_op(struct spi_mem *mem,
if (op->addr.nbytes)
ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth);
- if (op->dummy.nbytes)
+ if (op->dummy.ncycles)
ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth);
if (op->data.nbytes)
@@ -567,8 +567,7 @@ static bool nxp_fspi_supports_op(struct spi_mem *mem,
return false;
/* Max 64 dummy clock cycles supported */
- if (op->dummy.buswidth &&
- (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
+ if (op->dummy.ncycles > 64)
return false;
/* Max data length, check controller limits and alignment */
@@ -652,16 +651,15 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,
lutidx++;
}
- /* dummy bytes, if needed */
- if (op->dummy.nbytes) {
+ /* dummy cycles, if needed */
+ if (op->dummy.ncycles) {
lutval[lutidx / 2] |= LUT_DEF(lutidx, op->dummy.dtr ? LUT_DUMMY_DDR : LUT_DUMMY,
/*
* Due to FlexSPI controller limitation number of PAD for dummy
* buswidth needs to be programmed as equal to data buswidth.
*/
LUT_PAD(op->data.buswidth),
- op->dummy.nbytes * 8 /
- op->dummy.buswidth);
+ op->dummy.ncycles);
lutidx++;
}
@@ -1372,11 +1370,13 @@ static const struct spi_controller_mem_caps nxp_fspi_mem_caps = {
.dtr = true,
.swap16 = false,
.per_op_freq = true,
+ .dummy_cycles = true,
};
static const struct spi_controller_mem_caps nxp_fspi_mem_caps_disable_dtr = {
.dtr = false,
.per_op_freq = true,
+ .dummy_cycles = true,
};
static void nxp_fspi_cleanup(void *data)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 19/35] spi: nxp-fspi: Reject mixed DTR modes
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (17 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 18/35] spi: nxp-fspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 20/35] spi: nxp-xspi: Consume dummy cycles directly Miquel Raynal
` (15 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller only supports operations where all phases use the same
DTR mode. The mode selection in nxp_fspi_select_mem() assumes either an
all-DTR or an all-SDR operation; mixed DTR operations would be
misconfigured.
Reject mixed DTR operations from ->supports_op().
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-nxp-fspi.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index e6fdded67a00..04999369dd1b 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -536,8 +536,18 @@ static bool nxp_fspi_supports_op(struct spi_mem *mem,
const struct spi_mem_op *op)
{
struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller);
+ bool all_true, all_false;
int ret;
+ all_true = op->cmd.dtr &&
+ (!op->addr.nbytes || op->addr.dtr) &&
+ (!op->data.nbytes || op->data.dtr);
+
+ all_false = !op->cmd.dtr && !op->addr.dtr && !op->data.dtr;
+
+ if (!all_true && !all_false)
+ return false;
+
ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth);
if (op->addr.nbytes)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 20/35] spi: nxp-xspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (18 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 19/35] spi: nxp-fspi: Reject mixed DTR modes Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 21/35] spi: nxp-xspi: Fix a comment Miquel Raynal
` (14 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-nxp-xspi.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi-nxp-xspi.c b/drivers/spi/spi-nxp-xspi.c
index 38c8d6269aad..8b836662a5da 100644
--- a/drivers/spi/spi-nxp-xspi.c
+++ b/drivers/spi/spi-nxp-xspi.c
@@ -392,7 +392,7 @@ static bool nxp_xspi_supports_op(struct spi_mem *mem,
if (op->addr.nbytes)
ret |= nxp_xspi_check_buswidth(xspi, op->addr.buswidth);
- if (op->dummy.nbytes)
+ if (op->dummy.ncycles)
ret |= nxp_xspi_check_buswidth(xspi, op->dummy.buswidth);
if (op->data.nbytes)
@@ -408,8 +408,7 @@ static bool nxp_xspi_supports_op(struct spi_mem *mem,
return false;
/* Max 32 dummy clock cycles supported */
- if (op->dummy.buswidth &&
- (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
+ if (op->dummy.ncycles > 64)
return false;
if (needs_ip_only(xspi) && op->data.dir == SPI_MEM_DATA_IN &&
@@ -453,12 +452,10 @@ static void nxp_xspi_prepare_lut(struct nxp_xspi *xspi,
}
/* Dummy bytes, if needed */
- if (op->dummy.nbytes) {
+ if (op->dummy.ncycles) {
lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
LUT_PAD(op->data.buswidth),
- op->dummy.nbytes * 8 /
- /* need distinguish ddr mode */
- op->dummy.buswidth / (op->dummy.dtr ? 2 : 1));
+ op->dummy.ncycles);
lutidx++;
}
@@ -1307,6 +1304,7 @@ static const struct spi_controller_mem_caps nxp_xspi_mem_caps = {
.dtr = true,
.per_op_freq = true,
.swap16 = true,
+ .dummy_cycles = true,
};
static void nxp_xspi_cleanup(void *data)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 21/35] spi: nxp-xspi: Fix a comment
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (19 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 20/35] spi: nxp-xspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 22/35] spi: nxp-xspi: Reject mixed DTR modes Miquel Raynal
` (13 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
Looking at the i.MX952 TRM which is I believe one of the SoCs with this
controller inside, the maximum number of supported dummy clock cycles is
64 and not 32, so the code seems more accurate than the comment, which
needs fixing.
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-nxp-xspi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-nxp-xspi.c b/drivers/spi/spi-nxp-xspi.c
index 8b836662a5da..ccd00c744d18 100644
--- a/drivers/spi/spi-nxp-xspi.c
+++ b/drivers/spi/spi-nxp-xspi.c
@@ -407,7 +407,7 @@ static bool nxp_xspi_supports_op(struct spi_mem *mem,
if (op->addr.nbytes > 4)
return false;
- /* Max 32 dummy clock cycles supported */
+ /* Max 64 dummy clock cycles supported */
if (op->dummy.ncycles > 64)
return false;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 22/35] spi: nxp-xspi: Reject mixed DTR modes
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (20 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 21/35] spi: nxp-xspi: Fix a comment Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:58 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 23/35] spi: realtek-rtl-snand: Drop redundant check Miquel Raynal
` (12 subsequent siblings)
34 siblings, 1 reply; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller only supports operations where all phases use the same
DTR mode. The mode selection in nxp_xspi_select_mem() assumes either an
all-DTR or an all-SDR operation; mixed DTR operations would be
misconfigured.
Reject mixed DTR operations from ->supports_op().
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-nxp-xspi.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/spi/spi-nxp-xspi.c b/drivers/spi/spi-nxp-xspi.c
index ccd00c744d18..f2a847b5fd27 100644
--- a/drivers/spi/spi-nxp-xspi.c
+++ b/drivers/spi/spi-nxp-xspi.c
@@ -385,8 +385,18 @@ static bool nxp_xspi_supports_op(struct spi_mem *mem,
const struct spi_mem_op *op)
{
struct nxp_xspi *xspi = spi_controller_get_devdata(mem->spi->controller);
+ bool all_true, all_false;
int ret;
+ all_true = op->cmd.dtr &&
+ (!op->addr.nbytes || op->addr.dtr) &&
+ (!op->data.nbytes || op->data.dtr);
+
+ all_false = !op->cmd.dtr && !op->addr.dtr && !op->data.dtr;
+
+ if (!all_true && !all_false)
+ return false;
+
ret = nxp_xspi_check_buswidth(xspi, op->cmd.buswidth);
if (op->addr.nbytes)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 23/35] spi: realtek-rtl-snand: Drop redundant check
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (21 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 22/35] spi: nxp-xspi: Reject mixed DTR modes Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 24/35] spi: rpc-if: Consume dummy cycles directly Miquel Raynal
` (11 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The core already sanitizes the spi-mem operations, this check is
redundant so let's drop it.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-realtek-rtl-snand.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-realtek-rtl-snand.c b/drivers/spi/spi-realtek-rtl-snand.c
index 61fe54d8167a..e2394842800b 100644
--- a/drivers/spi/spi-realtek-rtl-snand.c
+++ b/drivers/spi/spi-realtek-rtl-snand.c
@@ -54,7 +54,7 @@ static bool rtl_snand_supports_op(struct spi_mem *mem,
{
if (!spi_mem_default_supports_op(mem, op))
return false;
- if (op->cmd.nbytes != 1 || op->cmd.buswidth != 1)
+ if (op->cmd.buswidth != 1)
return false;
return true;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 24/35] spi: rpc-if: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (22 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 23/35] spi: realtek-rtl-snand: Drop redundant check Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 25/35] spi: rtk-nor: " Miquel Raynal
` (10 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-rpc-if.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-rpc-if.c b/drivers/spi/spi-rpc-if.c
index 9a740342d0f7..fb27ee6064c2 100644
--- a/drivers/spi/spi-rpc-if.c
+++ b/drivers/spi/spi-rpc-if.c
@@ -32,10 +32,9 @@ static void rpcif_spi_mem_prepare(struct spi_device *spi_dev,
rpc_op.addr.val = spi_op->addr.val;
}
- if (spi_op->dummy.nbytes) {
+ if (spi_op->dummy.ncycles) {
rpc_op.dummy.buswidth = spi_op->dummy.buswidth;
- rpc_op.dummy.ncycles = spi_op->dummy.nbytes * 8 /
- spi_op->dummy.buswidth;
+ rpc_op.dummy.ncycles = spi_op->dummy.ncycles;
}
if (spi_op->data.nbytes || (offs && len)) {
@@ -141,6 +140,10 @@ static const struct spi_controller_mem_ops rpcif_spi_mem_ops = {
.dirmap_write = xspi_spi_mem_dirmap_write,
};
+static const struct spi_controller_mem_caps rpcif_spi_mem_caps = {
+ .dummy_cycles = true,
+};
+
static int rpcif_spi_probe(struct platform_device *pdev)
{
struct device *parent = pdev->dev.parent;
@@ -167,6 +170,7 @@ static int rpcif_spi_probe(struct platform_device *pdev)
ctlr->num_chipselect = 1;
ctlr->mem_ops = &rpcif_spi_mem_ops;
+ ctlr->mem_caps = &rpcif_spi_mem_caps;
ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_TX_QUAD | SPI_RX_QUAD;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 25/35] spi: rtk-nor: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (23 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 24/35] spi: rpc-if: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 26/35] spi: rtk-nor: Drop redundant checks Miquel Raynal
` (9 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-rtk-nor.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/spi/spi-rtk-nor.c b/drivers/spi/spi-rtk-nor.c
index 55ea7c371854..28fafa69cfbd 100644
--- a/drivers/spi/spi-rtk-nor.c
+++ b/drivers/spi/spi-rtk-nor.c
@@ -92,18 +92,10 @@ struct rtk_spi_host {
size_t dirmap_size;
};
-static u32 rtk_spi_calc_dummy_cycles(const struct spi_mem_op *op)
-{
- if (!op->dummy.nbytes)
- return 0;
-
- return (op->dummy.nbytes * 8) / op->dummy.buswidth;
-}
-
static void rtk_spi_read_mode(struct rtk_spi_host *host, const struct spi_mem_op *op)
{
u32 opcode = op->cmd.opcode;
- u32 dummy_cycles, val;
+ u32 val;
if (op->data.buswidth == 2)
opcode |= DUAL_MODE_EN;
@@ -113,10 +105,8 @@ static void rtk_spi_read_mode(struct rtk_spi_host *host, const struct spi_mem_op
val = readl(host->regbase + SFC_CTL);
val |= RW_DATAEN | ADDR_EN;
- dummy_cycles = rtk_spi_calc_dummy_cycles(op);
-
val &= ~SFC_CTL_DMYCNT_MASK;
- val |= (dummy_cycles << SFC_CTL_DMYCNT_SHIFT) & SFC_CTL_DMYCNT_MASK;
+ val |= (op->dummy.ncycles << SFC_CTL_DMYCNT_SHIFT) & SFC_CTL_DMYCNT_MASK;
writel(val, host->regbase + SFC_CTL);
readl(host->iobase);
@@ -192,7 +182,7 @@ static int rtk_spi_command_read(struct rtk_spi_host *host, const struct spi_mem_
size_t len = op->data.nbytes;
loff_t offset = op->addr.val;
u8 opcode = op->cmd.opcode;
- u32 dummy_cycles, val;
+ u32 val;
writel(opcode, host->regbase + SFC_OPCODE);
@@ -203,8 +193,7 @@ static int rtk_spi_command_read(struct rtk_spi_host *host, const struct spi_mem_
if (op->addr.nbytes > 0)
val |= ADDR_EN;
- dummy_cycles = rtk_spi_calc_dummy_cycles(op);
- val |= (dummy_cycles << SFC_CTL_DMYCNT_SHIFT) & SFC_CTL_DMYCNT_MASK;
+ val |= (op->dummy.ncycles << SFC_CTL_DMYCNT_SHIFT) & SFC_CTL_DMYCNT_MASK;
writel(val, host->regbase + SFC_CTL);
return rtk_spi_byte_transfer(host, offset, len, op->data.buf.in, true);
@@ -346,8 +335,8 @@ static bool rtk_spi_supports_op(struct spi_mem *mem,
if (!op->addr.nbytes && op->data.nbytes > 1)
return false;
- if (op->dummy.nbytes != 0) {
- if (op->dummy.buswidth > 1 || op->dummy.nbytes > 7)
+ if (op->dummy.ncycles) {
+ if (op->dummy.buswidth > 1 || op->dummy.ncycles > 7 * BITS_PER_BYTE)
return false;
}
@@ -464,6 +453,10 @@ static const struct spi_controller_mem_ops rtk_spi_mem_ops = {
.adjust_op_size = rtk_spi_adjust_op_size,
};
+static const struct spi_controller_mem_caps rtk_spi_mem_caps = {
+ .dummy_cycles = true,
+};
+
static int rtk_spi_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -535,6 +528,7 @@ static int rtk_spi_probe(struct platform_device *pdev)
ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL;
ctrl->bus_num = -1;
ctrl->mem_ops = &rtk_spi_mem_ops;
+ ctrl->mem_caps = &rtk_spi_mem_caps;
ctrl->num_chipselect = 1;
ctrl->auto_runtime_pm = true;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 26/35] spi: rtk-nor: Drop redundant checks
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (24 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 25/35] spi: rtk-nor: " Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 27/35] spi: sn-f-ospi: Consume dummy cycles directly Miquel Raynal
` (8 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The core already sanitizes the spi-mem operations, these checks are
redundant so let's drop them.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-rtk-nor.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/spi/spi-rtk-nor.c b/drivers/spi/spi-rtk-nor.c
index 28fafa69cfbd..2fcd2172a0b4 100644
--- a/drivers/spi/spi-rtk-nor.c
+++ b/drivers/spi/spi-rtk-nor.c
@@ -316,9 +316,6 @@ static bool rtk_spi_supports_op(struct spi_mem *mem,
if (op->cmd.buswidth != 1)
return false;
- if (op->cmd.dtr || op->addr.dtr || op->data.dtr)
- return false;
-
if (op->addr.nbytes != 0) {
if (op->addr.buswidth > 1)
return false;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 27/35] spi: sn-f-ospi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (25 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 26/35] spi: rtk-nor: Drop redundant checks Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 28/35] spi: spi-qpic-snand: Drop redundant check Miquel Raynal
` (7 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-sn-f-ospi.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
index f0320e96fe23..2f6d493a1ba4 100644
--- a/drivers/spi/spi-sn-f-ospi.c
+++ b/drivers/spi/spi-sn-f-ospi.c
@@ -104,7 +104,6 @@
/* Parameters */
#define OSPI_NUM_CS 4
-#define OSPI_DUMMY_CYCLE_MAX 255
#define OSPI_WAIT_MAX_MSEC 100
struct f_ospi {
@@ -114,14 +113,6 @@ struct f_ospi {
struct mutex mlock;
};
-static u32 f_ospi_get_dummy_cycle(const struct spi_mem_op *op)
-{
- if (!op->dummy.nbytes)
- return 0;
-
- return (op->dummy.nbytes * 8) / op->dummy.buswidth;
-}
-
static void f_ospi_clear_irq(struct f_ospi *ospi)
{
writel(OSPI_IRQ_CS_DEASSERT | OSPI_IRQ_CS_TRANS_COMP,
@@ -348,7 +339,7 @@ static int f_ospi_indir_prepare_op(struct f_ospi *ospi, struct spi_mem *mem,
f_ospi_config_indir_protocol(ospi, mem, op);
- writel(f_ospi_get_dummy_cycle(op), ospi->base + OSPI_DMY_INDIR);
+ writel(op->dummy.ncycles, ospi->base + OSPI_DMY_INDIR);
writel(op->addr.val, ospi->base + OSPI_ADDR);
writel(op->cmd.opcode, ospi->base + OSPI_CMD_IDX_INDIR);
@@ -553,9 +544,6 @@ static bool f_ospi_supports_op_width(struct spi_mem *mem,
static bool f_ospi_supports_op(struct spi_mem *mem,
const struct spi_mem_op *op)
{
- if (f_ospi_get_dummy_cycle(op) > OSPI_DUMMY_CYCLE_MAX)
- return false;
-
if (op->addr.nbytes > 4)
return false;
@@ -580,6 +568,7 @@ static const struct spi_controller_mem_ops f_ospi_mem_ops = {
static const struct spi_controller_mem_caps f_ospi_mem_caps = {
.per_op_freq = true,
+ .dummy_cycles = true,
};
static int f_ospi_init(struct f_ospi *ospi)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 28/35] spi: spi-qpic-snand: Drop redundant check
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (26 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 27/35] spi: sn-f-ospi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 29/35] spi: stm32-ospi: Consume dummy cycles directly Miquel Raynal
` (6 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The core already sanitizes the spi-mem operations, this check is
redundant so let's drop it.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-qpic-snand.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index b03e2e4f0f0b..23f78171d27d 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -1531,7 +1531,7 @@ static bool qcom_spi_supports_op(struct spi_mem *mem, const struct spi_mem_op *o
if (!spi_mem_default_supports_op(mem, op))
return false;
- if (op->cmd.nbytes != 1 || op->cmd.buswidth != 1)
+ if (op->cmd.buswidth != 1)
return false;
if (qcom_spi_is_page_op(op))
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 29/35] spi: stm32-ospi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (27 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 28/35] spi: spi-qpic-snand: Drop redundant check Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 30/35] spi: stm32-ospi: Reject excessive dummy cycle counts Miquel Raynal
` (5 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-stm32-ospi.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/spi-stm32-ospi.c b/drivers/spi/spi-stm32-ospi.c
index fa0e8e83cb1b..bf42f46ce194 100644
--- a/drivers/spi/spi-stm32-ospi.c
+++ b/drivers/spi/spi-stm32-ospi.c
@@ -492,10 +492,9 @@ static int stm32_ospi_send(struct spi_device *spi, const struct spi_mem_op *op)
}
tcr = TCR_SSHIFT;
- if (op->dummy.buswidth && op->dummy.nbytes) {
- tcr |= FIELD_PREP(TCR_DCYC_MASK,
- op->dummy.nbytes * 8 / op->dummy.buswidth);
- }
+ if (op->dummy.ncycles)
+ tcr |= FIELD_PREP(TCR_DCYC_MASK, op->dummy.ncycles);
+
writel_relaxed(tcr, regs_base + OSPI_TCR);
if (op->data.nbytes) {
@@ -691,7 +690,7 @@ static int stm32_ospi_transfer_one_message(struct spi_controller *ctrl,
*/
if (transfer->dummy_data) {
op.dummy.buswidth = transfer->tx_nbits;
- op.dummy.nbytes = transfer->len;
+ op.dummy.ncycles = transfer->len * 8 / transfer->tx_nbits;
dummy_bytes = transfer->len;
/* If happens, means that message is not correctly built */
@@ -784,6 +783,10 @@ static const struct spi_controller_mem_ops stm32_ospi_mem_ops = {
.poll_status = stm32_ospi_poll_status,
};
+static const struct spi_controller_mem_caps stm32_ospi_mem_caps = {
+ .dummy_cycles = true,
+};
+
static int stm32_ospi_get_resources(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -933,6 +936,7 @@ static int stm32_ospi_probe(struct platform_device *pdev)
ctrl->setup = stm32_ospi_setup;
ctrl->bus_num = -1;
ctrl->mem_ops = &stm32_ospi_mem_ops;
+ ctrl->mem_caps = &stm32_ospi_mem_caps;
ctrl->use_gpio_descriptors = true;
ctrl->transfer_one_message = stm32_ospi_transfer_one_message;
ctrl->num_chipselect = STM32_OSPI_MAX_NORCHIP;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 30/35] spi: stm32-ospi: Reject excessive dummy cycle counts
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (28 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 29/35] spi: stm32-ospi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 31/35] spi: stm32-qspi: Consume dummy cycles directly Miquel Raynal
` (4 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller stores the number of dummy cycles in a 5-bit field.
Prevent field corruption by adding a proper ->supports_op() callback.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-stm32-ospi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-stm32-ospi.c b/drivers/spi/spi-stm32-ospi.c
index bf42f46ce194..30d48ee1be21 100644
--- a/drivers/spi/spi-stm32-ospi.c
+++ b/drivers/spi/spi-stm32-ospi.c
@@ -772,11 +772,17 @@ static int stm32_ospi_setup(struct spi_device *spi)
return 0;
}
-/*
- * No special host constraint, so use default spi_mem_default_supports_op
- * to check supported mode.
- */
+static bool stm32_ospi_supports_op(struct spi_mem *mem,
+ const struct spi_mem_op *op)
+{
+ if (op->dummy.ncycles > FIELD_MAX(TCR_DCYC_MASK))
+ return false;
+
+ return spi_mem_default_supports_op(mem, op);
+}
+
static const struct spi_controller_mem_ops stm32_ospi_mem_ops = {
+ .supports_op = stm32_ospi_supports_op,
.exec_op = stm32_ospi_exec_op,
.dirmap_create = stm32_ospi_dirmap_create,
.dirmap_read = stm32_ospi_dirmap_read,
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 31/35] spi: stm32-qspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (29 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 30/35] spi: stm32-ospi: Reject excessive dummy cycle counts Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 32/35] spi: stm32-qspi: Reject excessive dummy cycle counts Miquel Raynal
` (3 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles, but the driver
converts the legacy dummy byte count into cycles. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-stm32-qspi.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
index b77daba6db83..993b09cc5124 100644
--- a/drivers/spi/spi-stm32-qspi.c
+++ b/drivers/spi/spi-stm32-qspi.c
@@ -393,9 +393,8 @@ static int stm32_qspi_send(struct spi_device *spi, const struct spi_mem_op *op)
ccr |= FIELD_PREP(CCR_ADSIZE_MASK, op->addr.nbytes - 1);
}
- if (op->dummy.nbytes)
- ccr |= FIELD_PREP(CCR_DCYC_MASK,
- op->dummy.nbytes * 8 / op->dummy.buswidth);
+ if (op->dummy.ncycles)
+ ccr |= FIELD_PREP(CCR_DCYC_MASK, op->dummy.ncycles);
if (op->data.nbytes) {
ccr |= FIELD_PREP(CCR_DMODE_MASK,
@@ -593,7 +592,7 @@ static int stm32_qspi_transfer_one_message(struct spi_controller *ctrl,
*/
if (transfer->dummy_data) {
op.dummy.buswidth = transfer->tx_nbits;
- op.dummy.nbytes = transfer->len;
+ op.dummy.ncycles = transfer->len * 8 / transfer->tx_nbits;
dummy_bytes = transfer->len;
/* if happens, means that message is not correctly built */
@@ -773,6 +772,10 @@ static const struct spi_controller_mem_ops stm32_qspi_mem_ops = {
.poll_status = stm32_qspi_poll_status,
};
+static const struct spi_controller_mem_caps stm32_qspi_mem_caps = {
+ .dummy_cycles = true,
+};
+
static int stm32_qspi_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -856,6 +859,7 @@ static int stm32_qspi_probe(struct platform_device *pdev)
ctrl->setup = stm32_qspi_setup;
ctrl->bus_num = -1;
ctrl->mem_ops = &stm32_qspi_mem_ops;
+ ctrl->mem_caps = &stm32_qspi_mem_caps;
ctrl->use_gpio_descriptors = true;
ctrl->transfer_one_message = stm32_qspi_transfer_one_message;
ctrl->num_chipselect = STM32_QSPI_MAX_NORCHIP;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 32/35] spi: stm32-qspi: Reject excessive dummy cycle counts
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (30 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 31/35] spi: stm32-qspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 33/35] spi: wpcm-fiu: Drop redundant checks Miquel Raynal
` (2 subsequent siblings)
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller stores the number of dummy cycles in a 5-bit field.
Prevent field corruption by adding a proper ->supports_op() callback.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-stm32-qspi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
index 993b09cc5124..751810a267ff 100644
--- a/drivers/spi/spi-stm32-qspi.c
+++ b/drivers/spi/spi-stm32-qspi.c
@@ -761,11 +761,17 @@ static void stm32_qspi_dma_free(struct stm32_qspi *qspi)
dma_release_channel(qspi->dma_chrx);
}
-/*
- * no special host constraint, so use default spi_mem_default_supports_op
- * to check supported mode.
- */
+static bool stm32_qspi_supports_op(struct spi_mem *mem,
+ const struct spi_mem_op *op)
+{
+ if (op->dummy.ncycles > FIELD_MAX(CCR_DCYC_MASK))
+ return false;
+
+ return spi_mem_default_supports_op(mem, op);
+}
+
static const struct spi_controller_mem_ops stm32_qspi_mem_ops = {
+ .supports_op = stm32_qspi_supports_op,
.exec_op = stm32_qspi_exec_op,
.dirmap_create = stm32_qspi_dirmap_create,
.dirmap_read = stm32_qspi_dirmap_read,
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 33/35] spi: wpcm-fiu: Drop redundant checks
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (31 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 32/35] spi: stm32-qspi: Reject excessive dummy cycle counts Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 34/35] spi: zynqmp-gqspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 35/35] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The core already sanitizes the spi-mem operations, these checks are
redundant so let's drop them.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-wpcm-fiu.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/spi/spi-wpcm-fiu.c b/drivers/spi/spi-wpcm-fiu.c
index 884e5042bad5..4142fd894adb 100644
--- a/drivers/spi/spi-wpcm-fiu.c
+++ b/drivers/spi/spi-wpcm-fiu.c
@@ -323,9 +323,6 @@ static bool wpcm_fiu_supports_op(struct spi_mem *mem, const struct spi_mem_op *o
if (!spi_mem_default_supports_op(mem, op))
return false;
- if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
- return false;
-
if (op->cmd.buswidth > 1 || op->addr.buswidth > 1 ||
op->dummy.buswidth > 1 || op->data.buswidth > 1)
return false;
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 34/35] spi: zynqmp-gqspi: Consume dummy cycles directly
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (32 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 33/35] spi: wpcm-fiu: Drop redundant checks Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 35/35] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
The controller programs the dummy phase in clock cycles in the GEN_FIFO,
but the driver converts the legacy dummy byte count itself. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Store the dummy cycle count in a dedicated dummy_cycles field instead of
reusing bytes_to_transfer, which is reserved for byte-oriented transfers.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-zynqmp-gqspi.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index 15e9d3ef8839..6289e33c2807 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -176,6 +176,8 @@ struct qspi_platform_data {
* @rxbuf: Pointer to the RX buffer
* @bytes_to_transfer: Number of bytes left to transfer
* @bytes_to_receive: Number of bytes left to receive
+ * @dummy_cycles: Number of dummy cycles to insert
+ * @dummy_phase: Whether the dummy phase is currently executing
* @genfifocs: Used for chip select
* @genfifobus: Used to select the upper or lower bus
* @dma_rx_bytes: Remaining bytes to receive by DMA mode
@@ -198,6 +200,8 @@ struct zynqmp_qspi {
void *rxbuf;
int bytes_to_transfer;
int bytes_to_receive;
+ u32 dummy_cycles;
+ bool dummy_phase;
u32 genfifocs;
u32 genfifobus;
u32 dma_rx_bytes;
@@ -681,8 +685,14 @@ static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits,
transfer_len = xqspi->dma_rx_bytes;
else
transfer_len = xqspi->bytes_to_receive;
- } else {
+ } else if (xqspi->txbuf) {
transfer_len = xqspi->bytes_to_transfer;
+ } else {
+ /*
+ * The GEN_FIFO immediate_data field carries a number of
+ * dummy SCLK cycles, not a byte count.
+ */
+ transfer_len = xqspi->dummy_cycles;
}
if (xqspi->txbuf)
@@ -832,7 +842,8 @@ static irqreturn_t zynqmp_qspi_irq(int irq, void *dev_id)
(mask & GQSPI_IER_GENFIFOEMPTY_MASK))
zynqmp_qspi_readrxfifo(xqspi, GQSPI_RX_FIFO_FILL);
- if (xqspi->bytes_to_receive == 0 && xqspi->bytes_to_transfer == 0 &&
+ if (!xqspi->dummy_phase &&
+ xqspi->bytes_to_receive == 0 && xqspi->bytes_to_transfer == 0 &&
((status & GQSPI_IRQ_MASK) == GQSPI_IRQ_MASK)) {
zynqmp_gqspi_write(xqspi, GQSPI_IDR_OFST, GQSPI_ISR_IDR_MASK);
complete(&xqspi->data_completion);
@@ -1109,15 +1120,13 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
}
}
- if (op->dummy.nbytes) {
+ if (op->dummy.ncycles) {
xqspi->txbuf = NULL;
xqspi->rxbuf = NULL;
- /*
- * xqspi->bytes_to_transfer here represents the dummy circles
- * which need to be sent.
- */
- xqspi->bytes_to_transfer = op->dummy.nbytes * 8 / op->dummy.buswidth;
+ xqspi->dummy_cycles = op->dummy.ncycles;
+ xqspi->bytes_to_transfer = 0;
xqspi->bytes_to_receive = 0;
+ xqspi->dummy_phase = true;
/*
* Using op->data.buswidth instead of op->dummy.buswidth here because
* we need to use it to configure the correct SPI mode.
@@ -1136,6 +1145,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
xqspi->rxbuf = NULL;
xqspi->bytes_to_transfer = op->data.nbytes;
xqspi->bytes_to_receive = 0;
+ xqspi->dummy_phase = false;
zynqmp_qspi_write_op(xqspi, op->data.buswidth,
genfifoentry);
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
@@ -1151,6 +1161,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
xqspi->rxbuf = (u8 *)op->data.buf.in;
xqspi->bytes_to_receive = op->data.nbytes;
xqspi->bytes_to_transfer = 0;
+ xqspi->dummy_phase = false;
err = zynqmp_qspi_read_op(xqspi, op->data.buswidth,
genfifoentry);
if (err)
@@ -1179,6 +1190,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
return_err:
+ xqspi->dummy_phase = false;
zynqmp_qspi_chipselect(mem->spi, true);
mutex_unlock(&xqspi->op_lock);
@@ -1206,6 +1218,7 @@ static const struct spi_controller_mem_ops zynqmp_qspi_mem_ops = {
static const struct spi_controller_mem_caps zynqmp_qspi_mem_caps = {
.per_op_freq = true,
+ .dummy_cycles = true,
};
/**
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH RFC v2 35/35] mtd: spi-nor: Express the dummy phase in cycles
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (33 preceding siblings ...)
2026-11-27 14:22 ` [PATCH RFC v2 34/35] spi: zynqmp-gqspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:22 ` Miquel Raynal
34 siblings, 0 replies; 41+ messages in thread
From: Miquel Raynal @ 2026-11-27 14:22 UTC (permalink / raw)
To: Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao, Han Xu,
Conor Dooley, Valentina Fernandez, Daire McNamara, Haibo Chen,
Jyan Chou, Yu-Chun Lin, Maxime Coquelin, Alexandre Torgue,
Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, linux-trace-kernel, linux-mediatek,
openbmc, Miquel Raynal
SFDP tables and datasheets provide the number of dummy cycles, not the
number of dummy bytes. Set dummy.ncycles directly instead of converting
it to dummy.nbytes. Depending on controller capabilities, this may help
supporting more use cases (typically Macronix 1S-8S-8S 20 dummy cycles)
while performing less useless maths in the core.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/spi-nor/core.c | 36 ++++++++++--------------------------
drivers/mtd/spi-nor/core.h | 8 ++++----
drivers/mtd/spi-nor/micron-st.c | 2 +-
drivers/mtd/spi-nor/spansion.c | 8 ++++----
4 files changed, 19 insertions(+), 35 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index a04d22d2e2e1..dcc36f532aaa 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -91,7 +91,7 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor,
if (op->addr.nbytes)
op->addr.buswidth = spi_nor_get_protocol_addr_nbits(proto);
- if (op->dummy.nbytes)
+ if (op->dummy.nbytes || op->dummy.ncycles)
op->dummy.buswidth = spi_nor_get_protocol_addr_nbits(proto);
if (op->data.nbytes)
@@ -109,9 +109,6 @@ void spi_nor_spimem_setup_op(const struct spi_nor *nor,
op->dummy.dtr = true;
op->data.dtr = true;
- /* 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;
@@ -205,7 +202,7 @@ static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from,
struct spi_mem_op op =
SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0),
SPI_MEM_OP_ADDR(nor->addr_nbytes, from, 0),
- SPI_MEM_OP_DUMMY(nor->read_dummy, 0),
+ SPI_MEM_OP_DUMMY_CYCLES(nor->read_dummy, 0),
SPI_MEM_OP_DATA_IN(len, buf, 0));
bool usebouncebuf;
ssize_t nbytes;
@@ -213,11 +210,6 @@ static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from,
spi_nor_spimem_setup_op(nor, &op, nor->read_proto);
- /* convert the dummy cycles to the number of bytes */
- op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
- if (spi_nor_protocol_is_dtr(nor->read_proto))
- op.dummy.nbytes *= 2;
-
usebouncebuf = spi_nor_spimem_bounce(nor, &op);
if (nor->dirmap.rdesc) {
@@ -418,22 +410,23 @@ int spi_nor_write_disable(struct spi_nor *nor)
* @nor: pointer to 'struct spi_nor'.
* @naddr: number of address bytes to send. Can be zero if the operation
* does not need to send an address.
- * @ndummy: number of dummy bytes to send after an opcode or address. Can
- * be zero if the operation does not require dummy bytes.
+ * @ncycles: number of dummy clock cycles to insert after an opcode or
+ * address. Can be zero if the operation does not require dummy
+ * cycles.
* @id: pointer to a DMA-able buffer where the value of the JEDEC ID
* will be written.
* @proto: the SPI protocol for register operation.
*
* Return: 0 on success, -errno otherwise.
*/
-int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ndummy, u8 *id,
+int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ncycles, u8 *id,
enum spi_nor_protocol proto)
{
int ret;
if (nor->spimem) {
struct spi_mem_op op =
- SPI_NOR_READID_OP(naddr, ndummy, id, SPI_NOR_MAX_ID_LEN);
+ SPI_NOR_READID_OP(naddr, ncycles, id, SPI_NOR_MAX_ID_LEN);
spi_nor_spimem_setup_op(nor, &op, proto);
ret = spi_mem_exec_op(nor->spimem, &op);
@@ -741,7 +734,7 @@ int spi_nor_read_sr_ll(struct spi_nor *nor, u8 opcode, u8 *sr,
if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) {
op.addr.nbytes = nor->params->rdsr_addr_nbytes;
- op.dummy.nbytes = nor->params->rdsr_dummy;
+ op.dummy.ncycles = nor->params->rdsr_dummy;
/*
* We don't want to read only one byte in DTR mode. So,
* read 2 and then discard the second byte.
@@ -2247,11 +2240,7 @@ static int spi_nor_spimem_check_readop(struct spi_nor *nor,
spi_nor_spimem_setup_op(nor, &op, read->proto);
- /* convert the dummy cycles to the number of bytes */
- op.dummy.nbytes = (read->num_mode_clocks + read->num_wait_states) *
- op.dummy.buswidth / 8;
- if (spi_nor_protocol_is_dtr(read->proto))
- op.dummy.nbytes *= 2;
+ op.dummy.ncycles = read->num_mode_clocks + read->num_wait_states;
return spi_nor_spimem_check_read_pp_op(nor, &op);
}
@@ -3492,7 +3481,7 @@ static int spi_nor_create_read_dirmap(struct spi_nor *nor)
.op_tmpl = &info.primary_op_tmpl,
.primary_op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0),
SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0),
- SPI_MEM_OP_DUMMY(nor->read_dummy, 0),
+ SPI_MEM_OP_DUMMY_CYCLES(nor->read_dummy, 0),
SPI_MEM_OP_DATA_IN(0, NULL, 0)),
.offset = 0,
.length = nor->params->size,
@@ -3501,11 +3490,6 @@ static int spi_nor_create_read_dirmap(struct spi_nor *nor)
spi_nor_spimem_setup_op(nor, op, nor->read_proto);
- /* convert the dummy cycles to the number of bytes */
- op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8;
- if (spi_nor_protocol_is_dtr(nor->read_proto))
- op->dummy.nbytes *= 2;
-
/*
* Since spi_nor_spimem_setup_op() only sets buswidth when the number
* of data bytes is non-zero, the data buswidth won't be set here. So,
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 670182b3c2ad..11817280f650 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -19,10 +19,10 @@
#define SPI_NOR_DEFAULT_SECTOR_SIZE SZ_64K
/* Standard SPI NOR flash operations. */
-#define SPI_NOR_READID_OP(naddr, ndummy, buf, len) \
+#define SPI_NOR_READID_OP(naddr, ncycles, buf, len) \
SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0), \
SPI_MEM_OP_ADDR(naddr, 0, 0), \
- SPI_MEM_OP_DUMMY(ndummy, 0), \
+ SPI_MEM_OP_DUMMY_CYCLES(ncycles, 0), \
SPI_MEM_OP_DATA_IN(len, buf, 0))
#define SPI_NOR_WREN_OP \
@@ -82,7 +82,7 @@
#define SPI_NOR_READ_OP(opcode) \
SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), \
SPI_MEM_OP_ADDR(3, 0, 0), \
- SPI_MEM_OP_DUMMY(1, 0), \
+ SPI_MEM_OP_DUMMY_CYCLES(1, 0), \
SPI_MEM_OP_DATA_IN(2, NULL, 0))
#define SPI_NOR_PP_OP(opcode) \
@@ -652,7 +652,7 @@ int spi_nor_wait_till_ready(struct spi_nor *nor);
int spi_nor_global_block_unlock(struct spi_nor *nor);
int spi_nor_prep_and_lock(struct spi_nor *nor);
void spi_nor_unlock_and_unprep(struct spi_nor *nor);
-int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ndummy, u8 *id,
+int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ncycles, u8 *id,
enum spi_nor_protocol reg_proto);
int spi_nor_sr_ready(struct spi_nor *nor);
int spi_nor_read_sr_ll(struct spi_nor *nor, u8 opcode, u8 *sr,
diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
index f97f2dead8c2..34eb15c7d3b3 100644
--- a/drivers/mtd/spi-nor/micron-st.c
+++ b/drivers/mtd/spi-nor/micron-st.c
@@ -525,7 +525,7 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr)
if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) {
op.addr.nbytes = nor->params->rdsr_addr_nbytes;
- op.dummy.nbytes = nor->params->rdsr_dummy;
+ op.dummy.ncycles = nor->params->rdsr_dummy;
/*
* We don't want to read only one byte in DTR mode. So,
* read 2 and then discard the second byte.
diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index b1b14ed0fd46..96bb2383448c 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -53,10 +53,10 @@
SPI_MEM_OP_NO_DUMMY, \
SPI_MEM_OP_DATA_OUT(ndata, buf, 0))
-#define CYPRESS_NOR_RD_ANY_REG_OP(naddr, addr, ndummy, buf) \
+#define CYPRESS_NOR_RD_ANY_REG_OP(naddr, addr, ncycles, buf) \
SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RD_ANY_REG, 0), \
SPI_MEM_OP_ADDR(naddr, addr, 0), \
- SPI_MEM_OP_DUMMY(ndummy, 0), \
+ SPI_MEM_OP_DUMMY_CYCLES(ncycles, 0), \
SPI_MEM_OP_DATA_IN(1, buf, 0))
#define CYPRESS_NOR_EN4B_EX4B_OP(enable) \
@@ -115,7 +115,7 @@ static int cypress_nor_sr_ready_and_clear_reg(struct spi_nor *nor, u64 addr)
if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) {
op.addr.nbytes = nor->addr_nbytes;
- op.dummy.nbytes = params->rdsr_dummy;
+ op.dummy.ncycles = params->rdsr_dummy;
op.data.nbytes = 2;
}
@@ -591,7 +591,7 @@ static int s25fs256t_late_init(struct spi_nor *nor)
/* Read Architecture Configuration Register (ARCFN) */
op = (struct spi_mem_op)
CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes,
- SPINOR_REG_CYPRESS_ARCFN, 1,
+ SPINOR_REG_CYPRESS_ARCFN, 8,
nor->bouncebuf);
ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto);
if (ret)
--
2.56.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH RFC v2 10/35] spi: atmel-quadspi: Consume dummy cycles directly
2026-11-27 14:22 ` [PATCH RFC v2 10/35] spi: atmel-quadspi: " Miquel Raynal
@ 2026-11-27 14:41 ` sashiko-bot
0 siblings, 0 replies; 41+ messages in thread
From: sashiko-bot @ 2026-11-27 14:41 UTC (permalink / raw)
To: Miquel Raynal, Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao,
Han Xu, Conor Dooley, Valentina Fernandez, Daire McNamara,
Haibo Chen, Jyan Chou, Yu-Chun Lin, Maxime Coquelin,
Alexandre Torgue, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, linux-trace-kernel, Frank.Li,
neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] spi: atmel-quadspi: incomplete dummy cycle check in
atmel_qspi_supports_op()
--
commit 07ba105643bc7f3f3737d56084ca2bed8b3821f6
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: atmel-quadspi: Consume dummy cycles directly
This commit advertises the dummy_cycles spi-mem capability and switches
the driver from converting op->dummy.nbytes to consuming
op->dummy.ncycles directly.
> diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
> index 0b695b0b3c98f..abca99b32b619 100644
> --- a/drivers/spi/atmel-quadspi.c
> +++ b/drivers/spi/atmel-quadspi.c
> @@ -502,7 +502,7 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem,
>
> /* special case not supported by hardware */
> if (op->addr.nbytes == 2 && op->cmd.buswidth != op->addr.buswidth &&
> - op->dummy.nbytes == 0)
> + !op->dummy.ncycles)
> return false;
>
> return true;
[Severity: Medium]
Should this check reject op->dummy.ncycles < 8 / op->addr.buswidth
instead of !op->dummy.ncycles?
For 2-byte addresses in atmel_qspi_set_cfg(), shifting the address into
the first dummy byte requires at least 8 / op->addr.buswidth dummy
cycles:
drivers/spi/atmel-quadspi.c:atmel_qspi_set_cfg() {
...
case 2:
if (dummy_cycles < 8 / op->addr.buswidth) {
ifr &= ~QSPI_IFR_INSTEN;
ifr |= QSPI_IFR_ADDREN;
iar = (op->cmd.opcode << 16) |
(op->addr.val & 0xffff);
} else {
ifr |= QSPI_IFR_ADDREN;
iar = (op->addr.val << 8) & 0xffffff;
dummy_cycles -= 8 / op->addr.buswidth;
}
break;
...
}
When op->cmd.buswidth != op->addr.buswidth and op->dummy.ncycles is
non-zero but less than 8 / op->addr.buswidth (for example, 2 dummy
cycles in 1-2-2 mode), atmel_qspi_supports_op() now accepts the
operation, causing atmel_qspi_set_cfg() to pack op->cmd.opcode into iar
and transmit the opcode on op->addr.buswidth lines instead of
op->cmd.buswidth lines.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com?part=10
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles
2026-11-27 14:22 ` [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles Miquel Raynal
@ 2026-11-27 14:43 ` sashiko-bot
0 siblings, 0 replies; 41+ messages in thread
From: sashiko-bot @ 2026-11-27 14:43 UTC (permalink / raw)
To: Miquel Raynal, Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao,
Han Xu, Conor Dooley, Valentina Fernandez, Daire McNamara,
Haibo Chen, Jyan Chou, Yu-Chun Lin, Maxime Coquelin,
Alexandre Torgue, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, linux-trace-kernel, Frank.Li,
neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] spi: spi-mem: missing dummy.ncycles checks in
spi_mem_default_supports_op()
--
commit 5399654721195bff49303bc619a04db290c22c52
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: spi-mem: Add support for dummy cycles
This commit adds a dummy.ncycles field to struct spi_mem_op and a
dummy_cycles capability to struct spi_controller_mem_caps, converting
between dummy bytes and dummy clock cycles depending on controller
capabilities.
Link: https://lore.kernel.org/all/20220911174551.653599-1-sergiu.moga@microchip.com/
Link: https://lore.kernel.org/all/20250115134158.19908-1-pratyush@kernel.org/
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index a1f129c476984..1642388b70048 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
[ ... ]
> +/*
> + * Controllers either program the dummy phase in clock cycles or in whole
> + * bytes. Convert the representation used by the operation to the one the
> + * controller expects.
> + *
> + * Return: 0 if the operation is lossless, -EOPNOTSUPP otherwise.
> + */
> +static int spi_mem_convert_dummy(struct spi_mem *mem, struct spi_mem_op *op)
> +{
> + struct spi_controller *ctlr = mem->spi->controller;
> + int n;
> +
> + if (op->dummy.ncycles) {
> + if (spi_mem_controller_is_capable(ctlr, dummy_cycles))
> + return 0;
> +
> + n = spi_mem_dummy_cycles_to_bytes(op);
> + if (n < 0)
> + return n;
> +
> + op->dummy.nbytes = n;
> + op->dummy.ncycles = 0;
> + } else if (op->dummy.nbytes) {
> + if (!spi_mem_controller_is_capable(ctlr, dummy_cycles))
> + return 0;
> +
> + n = spi_mem_dummy_bytes_to_cycles(op);
> + if (n < 0)
> + return n;
> +
> + op->dummy.ncycles = n;
> + op->dummy.nbytes = 0;
> +
> + return 0;
> + }
> +
> + return 0;
> +}
[ ... ]
> @@ -321,6 +448,9 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
> if (spi_mem_check_op(&eval_op))
> return false;
>
> + if (spi_mem_convert_dummy(mem, &eval_op))
> + return false;
> +
> return spi_mem_internal_supports_op(mem, &eval_op);
> }
> EXPORT_SYMBOL_GPL(spi_mem_supports_op);
[Severity: Medium]
Should spi_mem_default_supports_op() also check op->dummy.ncycles in its
dummy-phase DTR and buswidth checks?
When a controller advertises dummy_cycles, spi_mem_convert_dummy() leaves
the dummy duration in op->dummy.ncycles with op->dummy.nbytes set to 0
before spi_mem_supports_op() and spi_mem_exec_op() call
spi_mem_internal_supports_op(). Because spi_mem_default_supports_op() only
tests op->dummy.nbytes:
drivers/spi/spi-mem.c:spi_mem_default_supports_op() {
...
/* xS-xS-xD-xS is not allowed */
if (op->dummy.nbytes && op->dummy.dtr) {
if (op->data.nbytes && !op->data.dtr)
return false;
}
/* Bus width can only grow across phases, ie. 1-4-1, or 1-8-4 are not allowed */
if ((op->addr.nbytes && op->addr.buswidth < op->cmd.buswidth) ||
(op->dummy.nbytes && op->dummy.buswidth < op->cmd.buswidth) ||
(op->data.nbytes && op->data.buswidth < op->cmd.buswidth) ||
(op->addr.nbytes && op->dummy.nbytes && op->dummy.buswidth < op->addr.buswidth) ||
(op->addr.nbytes && op->data.nbytes && op->data.buswidth < op->addr.buswidth) ||
(op->dummy.nbytes && op->data.nbytes && op->data.buswidth < op->dummy.buswidth))
return false;
...
}
those checks are skipped whenever op->dummy.ncycles is used, allowing
operations with invalid DTR transitions or decreasing buswidth across the
dummy phase to pass spi_mem_supports_op() and reach controller execution.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com?part=6
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH RFC v2 11/35] spi: atmel-quadspi: Reject excessive dummy cycle counts
2026-11-27 14:22 ` [PATCH RFC v2 11/35] spi: atmel-quadspi: Reject excessive dummy cycle counts Miquel Raynal
@ 2026-11-27 14:47 ` sashiko-bot
0 siblings, 0 replies; 41+ messages in thread
From: sashiko-bot @ 2026-11-27 14:47 UTC (permalink / raw)
To: Miquel Raynal, Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao,
Han Xu, Conor Dooley, Valentina Fernandez, Daire McNamara,
Haibo Chen, Jyan Chou, Yu-Chun Lin, Maxime Coquelin,
Alexandre Torgue, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, linux-trace-kernel, Frank.Li,
neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: atmel-quadspi: broken dummy buswidth check in
atmel_qspi_supports_op()
--
commit 841dc168dae61bbe3593e703339f362587a598fd
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: atmel-quadspi: Reject excessive dummy cycle counts
This commit adds checks to atmel_qspi_supports_op() to reject operations
whose dummy cycle count exceeds QSPI_IFR_NBDUM_MASK or whose dummy
buswidth differs from the address buswidth.
> diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
> index abca99b32b619..8946abaafa81b 100644
> --- a/drivers/spi/atmel-quadspi.c
> +++ b/drivers/spi/atmel-quadspi.c
> @@ -487,9 +487,15 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem,
> if (!spi_mem_default_supports_op(mem, op))
> return false;
>
> + if (op->dummy.ncycles && op->dummy.buswidth != op->addr.buswidth)
> + return false;
[Severity: High]
Does this reject every operation that has dummy cycles but no address
phase?
When op->addr.nbytes is 0, op->addr.buswidth is 0 (for example, in
spi_nor_spimem_setup_op() when micron_st_nor_octal_dtr_en() issues an
8D-8D-8D Read ID with 0 address bytes and 8 dummy bytes, or in SPI NAND
operations using SPI_MEM_OP_NO_ADDR with dummy bytes), so comparing
op->dummy.buswidth against op->addr.buswidth without checking
op->addr.nbytes causes atmel_qspi_supports_op() to return false and fails
those operations with -EOPNOTSUPP.
Also, this buswidth check is not mentioned in the commit message.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com?part=11
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH RFC v2 18/35] spi: nxp-fspi: Consume dummy cycles directly
2026-11-27 14:22 ` [PATCH RFC v2 18/35] spi: nxp-fspi: Consume dummy cycles directly Miquel Raynal
@ 2026-11-27 14:50 ` sashiko-bot
0 siblings, 0 replies; 41+ messages in thread
From: sashiko-bot @ 2026-11-27 14:50 UTC (permalink / raw)
To: Miquel Raynal, Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao,
Han Xu, Conor Dooley, Valentina Fernandez, Daire McNamara,
Haibo Chen, Jyan Chou, Yu-Chun Lin, Maxime Coquelin,
Alexandre Torgue, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, linux-trace-kernel, Frank.Li,
neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: nxp-fspi: LUT_DUMMY_DDR operand halved in
nxp_fspi_prepare_lut()
--
commit 1599225157c651da7c372805ec30cf72cfe8b69c
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: nxp-fspi: Consume dummy cycles directly
This commit enables the dummy_cycles capability in the NXP FlexSPI driver
and replaces the dummy byte-to-cycle conversions with op->dummy.ncycles.
> diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
> index 66cb58f95fdb1..e6fdded67a00e 100644
> --- a/drivers/spi/spi-nxp-fspi.c
> +++ b/drivers/spi/spi-nxp-fspi.c
[ ... ]
> @@ -567,8 +567,7 @@ static bool nxp_fspi_supports_op(struct spi_mem *mem,
> return false;
>
> /* Max 64 dummy clock cycles supported */
> - if (op->dummy.buswidth &&
> - (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
> + if (op->dummy.ncycles > 64)
> return false;
>
> /* Max data length, check controller limits and alignment */
> @@ -652,16 +651,15 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,
> lutidx++;
> }
>
> - /* dummy bytes, if needed */
> - if (op->dummy.nbytes) {
> + /* dummy cycles, if needed */
> + if (op->dummy.ncycles) {
> lutval[lutidx / 2] |= LUT_DEF(lutidx, op->dummy.dtr ? LUT_DUMMY_DDR : LUT_DUMMY,
> /*
> * Due to FlexSPI controller limitation number of PAD for dummy
> * buswidth needs to be programmed as equal to data buswidth.
> */
> LUT_PAD(op->data.buswidth),
> - op->dummy.nbytes * 8 /
> - op->dummy.buswidth);
> + op->dummy.ncycles);
> lutidx++;
> }
[Severity: High]
Does passing op->dummy.ncycles directly to LUT_DUMMY_DDR halve the dummy
cycles programmed in DTR mode?
In DTR mode, FlexSPI runs the serial root clock at 2x the flash SCLK rate
and LUT_DUMMY_DDR counts DDR half-cycles (2 * ncycles). Previously, DTR
callers doubled op->dummy.nbytes to account for two transfers per clock,
and op->dummy.nbytes * 8 / op->dummy.buswidth intentionally did not divide
by 2, yielding 2 * ncycles. With .dummy_cycles set,
spi_mem_dummy_bytes_to_cycles() divides by 2 * op->dummy.buswidth when
op->dummy.dtr is true (and direct ncycles callers pass full SCLK cycles),
so nxp_fspi_prepare_lut() now programs half the required LUT_DUMMY_DDR
operand and breaks DTR flash reads.
For the same reason, the > 64 check in nxp_fspi_supports_op() no longer
accounts for the 2x factor when op->dummy.dtr is set.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com?part=18
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH RFC v2 22/35] spi: nxp-xspi: Reject mixed DTR modes
2026-11-27 14:22 ` [PATCH RFC v2 22/35] spi: nxp-xspi: Reject mixed DTR modes Miquel Raynal
@ 2026-11-27 14:58 ` sashiko-bot
0 siblings, 0 replies; 41+ messages in thread
From: sashiko-bot @ 2026-11-27 14:58 UTC (permalink / raw)
To: Miquel Raynal, Mark Brown, Liang Yang, Feng Chen, Xianwei Zhao,
Han Xu, Conor Dooley, Valentina Fernandez, Daire McNamara,
Haibo Chen, Jyan Chou, Yu-Chun Lin, Maxime Coquelin,
Alexandre Torgue, Pratyush Yadav, Michael Walle, Takahiro Kuwano,
Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Matthias Brugger, AngeloGioacchino Del Regno, Yogesh Gaur,
Chris Packham, Jonathan Neuschäfer, Michal Simek
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, linux-trace-kernel, Frank.Li,
neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] spi: nxp-xspi: inconsistent DTR detection in
nxp_xspi_supports_op()
--
commit ce8d7a3ff5fbe9ec51a6d3a172d4b7891aaf62c1
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: nxp-xspi: Reject mixed DTR modes
This commit updates nxp_xspi_supports_op() to reject SPI memory operations
that mix DTR and SDR phases.
> diff --git a/drivers/spi/spi-nxp-xspi.c b/drivers/spi/spi-nxp-xspi.c
> index ccd00c744d186..f2a847b5fd27d 100644
> --- a/drivers/spi/spi-nxp-xspi.c
> +++ b/drivers/spi/spi-nxp-xspi.c
> @@ -385,8 +385,18 @@ static bool nxp_xspi_supports_op(struct spi_mem *mem,
> const struct spi_mem_op *op)
> {
> struct nxp_xspi *xspi = spi_controller_get_devdata(mem->spi->controller);
> + bool all_true, all_false;
> int ret;
>
> + all_true = op->cmd.dtr &&
> + (!op->addr.nbytes || op->addr.dtr) &&
> + (!op->data.nbytes || op->data.dtr);
> +
> + all_false = !op->cmd.dtr && !op->addr.dtr && !op->data.dtr;
> +
> + if (!all_true && !all_false)
> + return false;
[Severity: Medium]
Does this DTR check match how nxp_xspi_select_mem() detects DTR operations
and how the dummy phase is validated?
In nxp_xspi_select_mem(), op_is_dtr requires dtr to be set on all four
phases unconditionally:
drivers/spi/spi-nxp-xspi.c:nxp_xspi_select_mem() {
...
/* xspi only support one DTR mode: 8D-8D-8D */
bool op_is_dtr = op->cmd.dtr && op->addr.dtr && op->dummy.dtr && op->data.dtr;
...
}
Standard Octal DTR templates that omit an address, dummy, or data phase
(such as SPINAND_PROG_LOAD_8D_8D_8D_OP or SPINAND_WR_EN_8D_0_0_OP) leave
dtr as false on the unused phase via SPI_MEM_OP_NO_DUMMY,
SPI_MEM_OP_NO_ADDR, or SPI_MEM_OP_NO_DATA. Those operations pass
all_true here, and nxp_xspi_prepare_lut() emits DDR LUT instructions for
the active phases, but nxp_xspi_select_mem() evaluates op_is_dtr as false
and calls nxp_xspi_disable_ddr().
In addition, neither all_true nor all_false checks op->dummy.dtr when
op->dummy.ncycles > 0. Because this driver sets dummy_cycles = true in
nxp_xspi_mem_caps, spi_mem_convert_dummy() clears op->dummy.nbytes to 0
before nxp_xspi_supports_op() and spi_mem_default_supports_op() run, so a
mismatched op->dummy.dtr is not caught by spi_mem_default_supports_op()
either.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com?part=22
^ permalink raw reply [flat|nested] 41+ messages in thread
end of thread, other threads:[~2026-11-27 14:58 UTC | newest]
Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 14:22 [PATCH RFC v2 00/35] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 01/35] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 02/35] spi: spi-mem: Fix the odd byte count error message Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 03/35] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 04/35] spi: spi-mem: Sanitize mixed DTR modes Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 05/35] spi: spi-mem: Sanitize mixed buswidth Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles Miquel Raynal
2026-11-27 14:43 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 07/35] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 08/35] spi: amlogic-spifc-a1: Reject excessive dummy cycle counts Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 09/35] spi: amlogic-spifc-a4: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 10/35] spi: atmel-quadspi: " Miquel Raynal
2026-11-27 14:41 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 11/35] spi: atmel-quadspi: Reject excessive dummy cycle counts Miquel Raynal
2026-11-27 14:47 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 12/35] spi: cadence-qspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 13/35] spi: cadence-qspi: Drop redundant checks Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 14/35] spi: cadence-qspi: Drop now useless checks Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 15/35] spi: fsl-qspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 16/35] spi: microchip-core-qspi: " Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 17/35] spi: mtk-snfi: Drop redundant check Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 18/35] spi: nxp-fspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:50 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 19/35] spi: nxp-fspi: Reject mixed DTR modes Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 20/35] spi: nxp-xspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 21/35] spi: nxp-xspi: Fix a comment Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 22/35] spi: nxp-xspi: Reject mixed DTR modes Miquel Raynal
2026-11-27 14:58 ` sashiko-bot
2026-11-27 14:22 ` [PATCH RFC v2 23/35] spi: realtek-rtl-snand: Drop redundant check Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 24/35] spi: rpc-if: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 25/35] spi: rtk-nor: " Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 26/35] spi: rtk-nor: Drop redundant checks Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 27/35] spi: sn-f-ospi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 28/35] spi: spi-qpic-snand: Drop redundant check Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 29/35] spi: stm32-ospi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 30/35] spi: stm32-ospi: Reject excessive dummy cycle counts Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 31/35] spi: stm32-qspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 32/35] spi: stm32-qspi: Reject excessive dummy cycle counts Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 33/35] spi: wpcm-fiu: Drop redundant checks Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 34/35] spi: zynqmp-gqspi: Consume dummy cycles directly Miquel Raynal
2026-11-27 14:22 ` [PATCH RFC v2 35/35] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox