* [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant
@ 2026-11-25 17:51 Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
` (15 more replies)
0 siblings, 16 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, 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 neglictible
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, all the trivial spi-mem controller drivers and then
SPI NOR to use dummy cycles instead of dummy bytes. SPI NAND may come
later.
This is only build tested for the moment and sent as an RFC because this
topic has raised a lot of questions, there may be things I have
forgotten about, so I would like all parties to agree on the direction
before I commit into something cleaner. I bet Sashiko will also have
interesting feedback to make...
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
Miquel Raynal (16):
spi: spi-mem: Handle a corner case while sanitizing ops
spi: spi-mem: Stop checking the dummy buswidth against board wiring
spi: spi-mem: Add support for dummy cycles
spi: amlogic-spifc-a1: Consume dummy cycles directly
spi: amlogic-spifc-a1: Fix a typo in a macro
spi: amlogic: spifc-a4: Consume dummy cycles directly
spi: cadence-qspi: Consume dummy cycles directly
spi: fsl-qspi: Consume dummy cycles directly
spi: microchip-core-qspi: Consume dummy cycles directly
spi: nxp-xspi: Consume dummy cycles directly
spi: nxp-xspi: Fix a comment
spi: rtk-nor: Consume dummy cycles directly
spi: sn-f-ospi: Consume dummy cycles directly
spi: stm32-ospi: Consume dummy cycles directly
spi: stm32-qspi: 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 | 6 +-
drivers/spi/spi-amlogic-spifc-a1.c | 9 +-
drivers/spi/spi-amlogic-spifc-a4.c | 12 +-
drivers/spi/spi-cadence-quadspi.c | 35 ++----
drivers/spi/spi-fsl-qspi.c | 12 +-
drivers/spi/spi-mem.c | 216 ++++++++++++++++++++++++++++++----
drivers/spi/spi-microchip-core-qspi.c | 8 +-
drivers/spi/spi-nxp-xspi.c | 14 +--
drivers/spi/spi-rtk-nor.c | 28 ++---
drivers/spi/spi-sn-f-ospi.c | 13 +-
drivers/spi/spi-stm32-ospi.c | 14 ++-
drivers/spi/spi-stm32-qspi.c | 12 +-
include/linux/spi/spi-mem.h | 36 +++++-
16 files changed, 303 insertions(+), 158 deletions(-)
---
base-commit: 19d1b4de6d37bccecc3ad9144d279f1baa405eb1
change-id: 20261125-macronix-upstreaming-spi-mem-cycles-103274708fec
Best regards,
--
Miquel Raynal <miquel.raynal@bootlin.com>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:58 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 02/16] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
` (14 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
Some mixed mode operations (such as 1S-xD-yD) will be flagged with
op_is_dtr but will not enter the ODTR checks. As a result, the number of
command bytes will never be checked.
Reorganize a little bit this helper:
- If the operation contains a DTR phase, sanitize it.
- Then sanitize the op, should it be:
- ODTR (8D-8D-8D)
- anything else
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 8047b7508c8d..c64e906ba919 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -170,6 +170,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)
@@ -177,23 +178,22 @@ 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;
-
- if ((op->addr.nbytes % 2) ||
- (op->dummy.nbytes % 2) ||
- (op->data.nbytes % 2)) {
- dev_err(&ctlr->dev,
- "Even byte numbers not allowed in octal DTR operations\n");
- return false;
- }
- }
- } else {
+ if (!op_is_odtr) {
if (op->cmd.nbytes != 1)
return false;
+ } else {
+ if (op->cmd.nbytes != 2)
+ return false;
+
+ if ((op->addr.nbytes % 2) ||
+ (op->dummy.nbytes % 2) ||
+ (op->data.nbytes % 2)) {
+ dev_err(&ctlr->dev,
+ "Even byte numbers not allowed in octal DTR operations\n");
+ return false;
+ }
}
if (op->data.ecc) {
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 02/16] spi: spi-mem: Stop checking the dummy buswidth against board wiring
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles Miquel Raynal
` (13 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, 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 c64e906ba919..9b8b8f2b3387 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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 02/16] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:07 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 04/16] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
` (12 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, 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/
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-mem.c | 181 ++++++++++++++++++++++++++++++++++++++++++--
include/linux/spi/spi-mem.h | 36 ++++++++-
2 files changed, 205 insertions(+), 12 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 9b8b8f2b3387..7f5849bf1a0d 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -224,6 +224,134 @@ 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_get_lossy_dummy_bytes() - Give a rounded number of dummy bytes
+ * @op: the SPI memory operation
+ *
+ * Return: an upper rounded amount of dummy bytes without touching the @op.
+ */
+static unsigned int spi_mem_get_lossy_dummy_bytes(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);
+}
+
+/**
+ * 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)
@@ -231,9 +359,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) ||
@@ -290,6 +422,9 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
*/
spi_mem_adjust_op_freq(mem, &eval_op);
+ if (spi_mem_convert_dummy(mem, &eval_op))
+ return false;
+
if (spi_mem_check_op(&eval_op))
return false;
@@ -338,6 +473,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_lossy_dummy_bytes(op);
struct spi_statistics *stats;
u64 len, l2len;
@@ -354,7 +490,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]);
@@ -381,7 +517,7 @@ 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.
*
@@ -390,22 +526,28 @@ static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats,
*
* 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);
+
+ /* 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_lossy_dummy_bytes(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',
@@ -597,6 +739,11 @@ 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);
@@ -673,9 +820,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);
@@ -781,6 +931,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) {
diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h
index 0cce6b57242a..adc7f53b8474 100644
--- a/include/linux/spi/spi-mem.h
+++ b/include/linux/spi/spi-mem.h
@@ -75,6 +75,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 +88,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 +167,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 +212,7 @@ struct spi_mem_op {
} addr;
struct {
+ u8 ncycles;
u8 nbytes;
u8 buswidth;
u8 dtr : 1;
@@ -392,6 +414,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 +427,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) \
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 04/16] spi: amlogic-spifc-a1: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (2 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 05/16] spi: amlogic-spifc-a1: Fix a typo in a macro Miquel Raynal
` (11 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
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 388bd2472dc0..282647cd6b56 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_SYCLES, (op)->dummy.nbytes << 3))
+ FIELD_PREP(SPIFC_A1_USER_DUMMY_CLK_SYCLES, (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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 05/16] spi: amlogic-spifc-a1: Fix a typo in a macro
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (3 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 04/16] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly Miquel Raynal
` (10 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
Correct the macro name: sycles -> cycles.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-amlogic-spifc-a1.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-amlogic-spifc-a1.c b/drivers/spi/spi-amlogic-spifc-a1.c
index 282647cd6b56..d99c72c7a965 100644
--- a/drivers/spi/spi-amlogic-spifc-a1.c
+++ b/drivers/spi/spi-amlogic-spifc-a1.c
@@ -43,7 +43,7 @@
#define SPIFC_A1_USER_CTRL2_REG 0x208
#define SPIFC_A1_USER_DUMMY_ENABLE BIT(31)
#define SPIFC_A1_USER_DUMMY_MODE GENMASK(30, 29)
-#define SPIFC_A1_USER_DUMMY_CLK_SYCLES GENMASK(28, 23)
+#define SPIFC_A1_USER_DUMMY_CLK_CYCLES GENMASK(28, 23)
#define SPIFC_A1_USER_CTRL3_REG 0x20c
#define SPIFC_A1_USER_DIN_ENABLE BIT(31)
@@ -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_SYCLES, (op)->dummy.ncycles))
+ 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)
@@ -195,7 +195,7 @@ static void amlogic_spifc_a1_set_dummy(struct amlogic_spifc_a1 *spifc,
{
u32 val = readl(spifc->base + SPIFC_A1_USER_CTRL2_REG);
- val &= ~(SPIFC_A1_USER_DUMMY_MODE | SPIFC_A1_USER_DUMMY_CLK_SYCLES);
+ val &= ~(SPIFC_A1_USER_DUMMY_MODE | SPIFC_A1_USER_DUMMY_CLK_CYCLES);
val |= dummy_cfg;
writel(val, spifc->base + SPIFC_A1_USER_CTRL2_REG);
}
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (4 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 05/16] spi: amlogic-spifc-a1: Fix a typo in a macro Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:59 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 07/16] spi: cadence-qspi: " Miquel Raynal
` (9 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-amlogic-spifc-a4.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/spi/spi-amlogic-spifc-a4.c b/drivers/spi/spi-amlogic-spifc-a4.c
index 16346f50c7d9..ac06ea735133 100644
--- a/drivers/spi/spi-amlogic-spifc-a4.c
+++ b/drivers/spi/spi-amlogic-spifc-a4.c
@@ -361,13 +361,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 +798,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 +1052,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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 07/16] spi: cadence-qspi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (5 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 08/16] spi: fsl-qspi: " Miquel Raynal
` (8 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-cadence-quadspi.c | 35 +++++++++--------------------------
1 file changed, 9 insertions(+), 26 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 44d96b8cf8f0..1bf21cadd1da 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);
@@ -1528,7 +1509,7 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
*/
all_true = op->cmd.dtr &&
(!op->addr.nbytes || op->addr.dtr) &&
- (!op->dummy.nbytes || op->dummy.dtr) &&
+ (!op->dummy.ncycles || op->dummy.dtr) &&
(!op->data.nbytes || op->data.dtr);
all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr &&
@@ -1739,12 +1720,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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 08/16] spi: fsl-qspi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (6 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 07/16] spi: cadence-qspi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:58 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 09/16] spi: microchip-core-qspi: " Miquel Raynal
` (7 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-fsl-qspi.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
index d2c2090442f8..a1d6357e3203 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++;
}
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 09/16] spi: microchip-core-qspi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (7 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 08/16] spi: fsl-qspi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:06 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 10/16] spi: nxp-xspi: " Miquel Raynal
` (6 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-microchip-core-qspi.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microchip-core-qspi.c
index c0ea65014d2e..2fc1df738062 100644
--- a/drivers/spi/spi-microchip-core-qspi.c
+++ b/drivers/spi/spi-microchip-core-qspi.c
@@ -420,7 +420,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 +458,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)
@@ -601,6 +596,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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 10/16] spi: nxp-xspi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (8 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 09/16] spi: microchip-core-qspi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 11/16] spi: nxp-xspi: Fix a comment Miquel Raynal
` (5 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 11/16] spi: nxp-xspi: Fix a comment
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (9 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 10/16] spi: nxp-xspi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly Miquel Raynal
` (4 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, 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.
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (10 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 11/16] spi: nxp-xspi: Fix a comment Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:02 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 13/16] spi: sn-f-ospi: " Miquel Raynal
` (3 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
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..6febeee2541d 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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 13/16] spi: sn-f-ospi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (11 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:01 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 14/16] spi: stm32-ospi: " Miquel Raynal
` (2 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/spi/spi-sn-f-ospi.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
index f0320e96fe23..ecfcf228c587 100644
--- a/drivers/spi/spi-sn-f-ospi.c
+++ b/drivers/spi/spi-sn-f-ospi.c
@@ -114,14 +114,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 +340,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,7 +545,7 @@ 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)
+ if (op.dummy.ncycles > OSPI_DUMMY_CYCLE_MAX)
return false;
if (op->addr.nbytes > 4)
@@ -580,6 +572,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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 14/16] spi: stm32-ospi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (12 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 13/16] spi: sn-f-ospi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:12 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 15/16] spi: stm32-qspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
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..9b28d1f24482 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.buswidth && 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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 15/16] spi: stm32-qspi: Consume dummy cycles directly
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (13 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 14/16] spi: stm32-ospi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, Miquel Raynal
The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
` (14 preceding siblings ...)
2026-11-25 17:51 ` [PATCH RFC 15/16] spi: stm32-qspi: " Miquel Raynal
@ 2026-11-25 17:51 ` Miquel Raynal
2026-11-25 18:08 ` sashiko-bot
15 siblings, 1 reply; 27+ messages in thread
From: Miquel Raynal @ 2026-11-25 17:51 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-spi,
linux-kernel, linux-amlogic, imx, linux-riscv, linux-stm32,
linux-arm-kernel, linux-mtd, 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 | 6 +++---
4 files changed, 18 insertions(+), 34 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..72cc11d3f1d3 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;
}
--
2.56.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 08/16] spi: fsl-qspi: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 08/16] spi: fsl-qspi: " Miquel Raynal
@ 2026-11-25 17:58 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 17: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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: fsl-qspi: missing dummy_cycles in fsl_qspi_mem_caps zeroes
ncycles
--
commit 96f0741ca2d71f7fc3b26b9f08845776854eb8a4
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: fsl-qspi: Consume dummy cycles directly
This commit converts fsl_qspi_supports_op() and fsl_qspi_prepare_lut() to
use op->dummy.ncycles directly instead of converting op->dummy.nbytes into
clock cycles.
> diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
> index d2c2090442f84..a1d6357e3203a 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++;
> }
[Severity: High]
Does fsl_qspi_mem_caps also need .dummy_cycles = true?
fsl_qspi_mem_caps only sets .per_op_freq = true. Without .dummy_cycles =
true, spi_mem_convert_dummy() converts any dummy cycles to op->dummy.nbytes
and sets op->dummy.ncycles = 0 before invoking the driver callbacks. As a
result, op->dummy.ncycles is always 0 in fsl_qspi_supports_op() and
fsl_qspi_prepare_lut(), so dummy validation is skipped and LUT_DUMMY is
never programmed into the hardware LUT for operations requiring dummy
cycles.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=8
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
@ 2026-11-25 17:58 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 17: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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] spi: spi-mem: missing Fixes trailer for
spi_mem_default_supports_op() fix
--
commit bb612cd08d5fd5887be36ce57a7159e805a4780d
Author: Miquel Raynal <miquel.raynal@bootlin.com>
> spi: spi-mem: Handle a corner case while sanitizing ops
>
> Some mixed mode operations (such as 1S-xD-yD) will be flagged with
> op_is_dtr but will not enter the ODTR checks. As a result, the number of
> command bytes will never be checked.
>
> Reorganize a little bit this helper:
> - If the operation contains a DTR phase, sanitize it.
> - Then sanitize the op, should it be:
> - ODTR (8D-8D-8D)
> - anything else
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
[Severity: Low]
This fixes the command-byte check skipped for non-ODTR operations with
DTR phases since 8618271887ca ("spi: spi-mem: Limit octal DTR constraints
to octal DTR situations"). Should this include:
Fixes: 8618271887ca ("spi: spi-mem: Limit octal DTR constraints to octal DTR situations")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly Miquel Raynal
@ 2026-11-25 17:59 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 17:59 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] spi: amlogic: unused dummy_cycle and aml_sfc_is_xio_op() in
spifc-a4
--
commit d55fa85d06375ffce26e0f147adc64d4704ca984
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: amlogic: spifc-a4: Consume dummy cycles directly
This commit enables the dummy_cycles spi-mem capability and updates the
driver to use op->dummy.ncycles directly instead of converting from
op->dummy.nbytes.
> diff --git a/drivers/spi/spi-amlogic-spifc-a4.c b/drivers/spi/spi-amlogic-spifc-a4.c
> index 16346f50c7d99..ac06ea735133b 100644
> --- a/drivers/spi/spi-amlogic-spifc-a4.c
> +++ b/drivers/spi/spi-amlogic-spifc-a4.c
> @@ -361,13 +361,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);
> }
[Severity: Medium]
Does removing this block leave the local variable dummy_cycle in
aml_sfc_send_cmd_addr_dummy() and the static helper aml_sfc_is_xio_op()
unused, causing -Wunused-variable and -Wunused-function warnings (and a
build failure with CONFIG_WERROR=y)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=6
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 13/16] spi: sn-f-ospi: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 13/16] spi: sn-f-ospi: " Miquel Raynal
@ 2026-11-25 18:01 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:01 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: sn-f-ospi: build failure in f_ospi_supports_op() due to
op.dummy.ncycles
--
commit 5b202d148b915b6297c8b1354c3c876aa99057c5
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: sn-f-ospi: Consume dummy cycles directly
This commit advertises the dummy_cycles capability in f_ospi_mem_caps and
updates the driver to use op->dummy.ncycles directly instead of converting
dummy bytes to cycles.
> diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
> index f0320e96fe232..ecfcf228c5870 100644
> --- a/drivers/spi/spi-sn-f-ospi.c
> +++ b/drivers/spi/spi-sn-f-ospi.c
[ ... ]
> @@ -553,7 +545,7 @@ 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)
> + if (op.dummy.ncycles > OSPI_DUMMY_CYCLE_MAX)
> return false;
[Severity: High]
Does this fail to build because op is a pointer (const struct spi_mem_op *)
accessed with '.' instead of '->'?
Also, op->dummy.ncycles is a u8 while OSPI_DUMMY_CYCLE_MAX is 255, so
comparing it with '> OSPI_DUMMY_CYCLE_MAX' is always false and triggers a
-Wtype-limits compiler warning.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=13
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly Miquel Raynal
@ 2026-11-25 18:02 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:02 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: rtk-nor: build failure in rtk_spi_command_read() from dot
on pointer op
--
commit 33482af3701e77a28660250c89cfba6bbad8b4a7
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: rtk-nor: Consume dummy cycles directly
This commit advertises spi-mem dummy_cycles support in the Realtek SPI NOR
controller driver and replaces the byte-to-cycle helper with direct use of
op->dummy.ncycles.
> diff --git a/drivers/spi/spi-rtk-nor.c b/drivers/spi/spi-rtk-nor.c
> index 55ea7c3718543..6febeee2541d6 100644
> --- a/drivers/spi/spi-rtk-nor.c
> +++ b/drivers/spi/spi-rtk-nor.c
[ ... ]
> @@ -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;
[Severity: High]
Should this be op->dummy.ncycles instead of op.dummy.ncycles? op is a
const struct spi_mem_op *, so using the dot operator fails to compile.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=12
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 09/16] spi: microchip-core-qspi: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 09/16] spi: microchip-core-qspi: " Miquel Raynal
@ 2026-11-25 18:06 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:06 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] spi: microchip-core-qspi: dummy_cycles drops dummy phase on
GPIO-CS fallback
- [Medium] spi: microchip-core-qspi: unchecked ncycles shift in
mchp_coreqspi_config_op()
--
commit 2317911309a9a0d90fc21347c53a3b7c2797fde4
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: microchip-core-qspi: Consume dummy cycles directly
This commit advertises the dummy_cycles capability in
mchp_coreqspi_mem_caps and uses op->dummy.ncycles directly in
mchp_coreqspi_config_op() instead of converting op->dummy.nbytes.
> diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microchip-core-qspi.c
> index c0ea65014d2ea..2fc1df7380620 100644
> --- a/drivers/spi/spi-microchip-core-qspi.c
> +++ b/drivers/spi/spi-microchip-core-qspi.c
> @@ -420,7 +420,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 +458,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;
[Severity: Medium]
Can op->dummy.ncycles << FRAMES_IDLE_SHIFT overflow the 4-bit
FRAMES_IDLE_MASK field in REG_FRAMES?
drivers/spi/spi-microchip-core-qspi.c:
#define FRAMES_IDLE_MASK GENMASK(29, 26)
#define FRAMES_IDLE_SHIFT 26
#define FRAMES_FLAGBYTE BIT(30)
#define FRAMES_FLAGWORD BIT(31)
mchp_coreqspi_supports_op() does not reject op->dummy.ncycles > 15.
When a flash operation requests more than 15 dummy cycles (such as SFDP
BFPT read modes with 16 or 20 cycles), shifting u8 op->dummy.ncycles (as a
signed int) by 26 overflows into FRAMES_FLAGBYTE and FRAMES_FLAGWORD (and
is undefined behavior when ncycles >= 32), while truncating the programmed
idle cycles to op->dummy.ncycles & 0xf.
Should mchp_coreqspi_supports_op() reject op->dummy.ncycles > 15?
> ctrl = readl_relaxed(qspi->regs + REG_CONTROL);
>
> if (ctrl & CONTROL_MODE12_MASK)
> @@ -601,6 +596,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,
> };
[Severity: High]
Does setting .dummy_cycles = true drop the dummy phase when a SPI memory
device uses a GPIO chip-select?
mchp_coreqspi_probe() sets ctlr->use_gpio_descriptors = true. In
spi_mem_exec_op(), spi_mem_convert_dummy() runs before the
!spi_get_csgpiod(mem->spi, 0) check:
drivers/spi/spi-mem.c:spi_mem_exec_op() {
...
spi_mem_convert_dummy(mem, op);
...
if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) {
...
if (op->dummy.nbytes) {
memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
xfers[xferpos].len = op->dummy.nbytes;
...
}
With .dummy_cycles = true, spi_mem_convert_dummy() stores the dummy phase
in op->dummy.ncycles and sets op->dummy.nbytes = 0. When a GPIO CS is
used, spi_mem_exec_op() falls back to spi_sync(), which only creates a
dummy transfer when op->dummy.nbytes is non-zero, while
mchp_coreqspi_prepare_message() hardcodes idle_cycles = 0. As a result,
no dummy cycles are transmitted on the bus, corrupting flash reads on
boards with GPIO chip-selects.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=9
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles
2026-11-25 17:51 ` [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles Miquel Raynal
@ 2026-11-25 18:07 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:07 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] spi: spi-mem: broken nodirmap fallback in
spi_mem_dirmap_create()
- [High] spi: spi-mem: missing dummy phase on spi_sync() path in
spi_mem_exec_op()
- [Medium] spi: spi-mem: missing dummy conversion in
spi_mem_poll_status()
- [Medium] spi: spi-mem: spi_mem_convert_dummy() bypasses
spi_mem_check_op()
- [Low] spi: spi-mem: trace_spi_mem_start_op() ignores dummy.ncycles
--
commit a302459c2782bc8488f61e01f3aac67fe9d71262
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 controller capability, converting between dummy clock cycles
and dummy bytes depending on what the SPI memory controller expects.
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 9b8b8f2b33877..7f5849bf1a0d7 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
[ ... ]
> @@ -231,9 +359,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) ||
> @@ -290,6 +422,9 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
> */
> spi_mem_adjust_op_freq(mem, &eval_op);
>
> + if (spi_mem_convert_dummy(mem, &eval_op))
> + return false;
> +
> if (spi_mem_check_op(&eval_op))
> return false;
[Severity: Medium]
Should spi_mem_check_op() run before spi_mem_convert_dummy() in
spi_mem_supports_op() and spi_mem_exec_op()?
On controllers without the dummy_cycles capability, an operation with both
dummy.ncycles and dummy.nbytes set enters the if (op->dummy.ncycles) branch
in spi_mem_convert_dummy(), which overwrites op->dummy.nbytes and zeroes
op->dummy.ncycles before spi_mem_check_op() can reject it with -EINVAL.
Running spi_mem_convert_dummy() first also causes spi_mem_exec_op() to
return -EOPNOTSUPP instead of -EINVAL when dummy.buswidth is 0.
[ ... ]
> @@ -390,22 +526,28 @@ static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats,
> *
> * 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);
> +
> + /* Also make sure the dummy phase can be consumed by the controller */
> + ret = spi_mem_convert_dummy(mem, op);
> + if (ret)
> + return ret;
[Severity: High]
Does calling spi_mem_convert_dummy() here drop the dummy phase when a
dummy_cycles-capable controller falls back to regular SPI transfers via
spi_sync()?
When the controller advertises dummy_cycles, spi_mem_convert_dummy() stores
the dummy phase in op->dummy.ncycles and zeroes op->dummy.nbytes. If
spi_get_csgpiod(mem->spi, 0) is non-NULL or ctlr->mem_ops->exec_op()
returns -ENOTSUPP or -EOPNOTSUPP, spi_mem_exec_op() falls back to building
spi_transfer entries from op->dummy.nbytes:
drivers/spi/spi-mem.c:spi_mem_exec_op() {
...
tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes;
...
if (op->dummy.nbytes) {
memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
xfers[xferpos].len = op->dummy.nbytes;
...
}
Because op->dummy.nbytes is 0, the fallback path omits the dummy transfer
completely instead of converting op->dummy.ncycles back to bytes (or
returning -EOPNOTSUPP if the cycle count is not byte-aligned), corrupting
flash transfers.
>
> 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_lossy_dummy_bytes(op),
[Severity: Low]
Does trace_spi_mem_start_op(mem, op) in spi_mem_exec_op() also need to
account for op->dummy.ncycles?
On dummy_cycles-capable controllers, op->dummy.nbytes is 0 after
spi_mem_convert_dummy(), so TRACE_EVENT(spi_mem_start_op) in
include/trace/events/spi-mem.h sizes its dynamic array with
op->dummy.nbytes and omits the dummy bytes from the trace event.
[ ... ]
> @@ -781,6 +931,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);
> + }
> + }
[Severity: High]
Does assigning ret = spi_mem_convert_dummy() here break the nodirmap
fallback on controllers that do not implement ctlr->mem_ops->dirmap_create?
spi_mem_dirmap_create() initializes ret to -ENOTSUPP so that when
ctlr->mem_ops->dirmap_create is absent, the if (ret) block below sets
desc->nodirmap = true and validates primary_op_tmpl:
drivers/spi/spi-mem.c:spi_mem_dirmap_create() {
...
if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) {
...
ret = ctlr->mem_ops->dirmap_create(desc);
spi_mem_access_end(mem);
}
if (ret) {
desc->nodirmap = true;
if (!spi_mem_supports_op(desc->mem, &desc->info.primary_op_tmpl))
ret = -EOPNOTSUPP;
else
ret = 0;
}
...
}
When spi_mem_convert_dummy() succeeds, it sets ret to 0. If the controller
does not provide dirmap_create, ret stays 0, leaving desc->nodirmap false
and causing all subsequent spi_mem_dirmap_read() and spi_mem_dirmap_write()
calls to fail with -ENOTSUPP.
> +
> if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) {
> ret = spi_mem_access_start(mem);
> if (ret) {
[Severity: Medium]
Should spi_mem_poll_status() also convert the operation with
spi_mem_convert_dummy() before calling ctlr->mem_ops->poll_status()?
drivers/spi/spi-mem.c:spi_mem_poll_status() {
...
if (ctlr->mem_ops && ctlr->mem_ops->poll_status && !spi_get_csgpiod(mem->spi, 0)) {
ret = spi_mem_access_start(mem);
if (ret)
return ret;
ret = ctlr->mem_ops->poll_status(mem, op, mask, match,
initial_delay_us, polling_delay_us,
timeout_ms);
spi_mem_access_end(mem);
}
...
}
Without converting a local copy of op in spi_mem_poll_status(),
ctlr->mem_ops->poll_status() receives the caller's unconverted dummy phase
and programs 0 dummy cycles whenever the caller and controller use
different dummy representations.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=3
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles
2026-11-25 17:51 ` [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
@ 2026-11-25 18:08 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:08 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mtd: spi-nor: spansion: s25fs256t_late_init() passes 1 dummy
cycle instead of 8
--
commit a9d3a1e024f3a4306e5fb27cb054e3ab383f7673
Author: Miquel Raynal <miquel.raynal@bootlin.com>
mtd: spi-nor: Express the dummy phase in cycles
This commit updates the SPI NOR core and manufacturer drivers to populate
spi_mem_op dummy phases in clock cycles rather than converting them to
bytes.
> diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
> index b1b14ed0fd467..72cc11d3f1d35 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))
[Severity: High]
Does changing CYPRESS_NOR_RD_ANY_REG_OP() to take dummy clock cycles
break s25fs256t_late_init()?
drivers/mtd/spi-nor/spansion.c:s25fs256t_late_init() {
...
/* 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,
nor->bouncebuf);
ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto);
...
}
Reading SPINOR_REG_CYPRESS_ARCFN in 1S-1S-1S mode requires 8 dummy clock
cycles (previously 1 dummy byte). With ncycles set to 1 at 1-bit buswidth,
spi_mem_dummy_cycles_to_bytes() fails with -EOPNOTSUPP on byte-granular
controllers, or cycle-capable controllers clock only 1 dummy cycle instead
of 8, causing S25FS256T probe to fail.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=16
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 14/16] spi: stm32-ospi: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 14/16] spi: stm32-ospi: " Miquel Raynal
@ 2026-11-25 18:12 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:12 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: stm32-ospi: dummy_cycles breaks GPIO-CS dummy phase in
spi_mem_exec_op()
--
commit 6211c6f8b4860424c9db9bbf573382699c7dae10
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: stm32-ospi: Consume dummy cycles directly
This commit enables the dummy_cycles spi-mem capability in the STM32 OSPI
driver and updates it to program dummy cycles directly from
op->dummy.ncycles instead of converting from op->dummy.nbytes.
> diff --git a/drivers/spi/spi-stm32-ospi.c b/drivers/spi/spi-stm32-ospi.c
> index fa0e8e83cb1be..9b28d1f244822 100644
> --- a/drivers/spi/spi-stm32-ospi.c
> +++ b/drivers/spi/spi-stm32-ospi.c
[ ... ]
> @@ -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,
> +};
[Severity: High]
Does setting .dummy_cycles = true drop the dummy phase when a GPIO
chip-select (cs-gpios) is used?
At the start of spi_mem_exec_op(), spi_mem_convert_dummy() converts any
dummy bytes to op->dummy.ncycles and clears op->dummy.nbytes to 0 when
dummy_cycles is advertised. When spi_get_csgpiod(mem->spi, 0) is
non-NULL, spi_mem_exec_op() then skips ctlr->mem_ops->exec_op() and falls
back to spi_sync() -> stm32_ospi_transfer_one_message(), but that fallback
only creates the dummy_data transfer if op->dummy.nbytes is non-zero:
drivers/spi/spi-mem.c:spi_mem_exec_op() {
...
ret = spi_mem_convert_dummy(mem, op);
if (ret)
return ret;
...
if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) {
...
}
...
if (op->dummy.nbytes) {
memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
xfers[xferpos].len = op->dummy.nbytes;
xfers[xferpos].tx_nbits = op->dummy.buswidth;
xfers[xferpos].dummy_data = 1;
...
}
Because op->dummy.nbytes is now 0, no dummy_data transfer is added to the
message, stm32_ospi_transfer_one_message() never enters the
if (transfer->dummy_data) block, and stm32_ospi_send() executes flash
operations with 0 dummy cycles on boards using cs-gpios.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=14
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH RFC 15/16] spi: stm32-qspi: Consume dummy cycles directly
2026-11-25 17:51 ` [PATCH RFC 15/16] spi: stm32-qspi: " Miquel Raynal
@ 2026-11-25 18:14 ` sashiko-bot
0 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-11-25 18:14 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
Cc: Thomas Petazzoni, Alvin Zhou, Cheng Ming Lin, linux-amlogic, imx,
linux-stm32, linux-mtd, Frank.Li, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] spi: stm32-qspi: missing dummy phase on GPIO CS fallback in
spi_mem_exec_op()
--
commit f2e2b0be96bbca647ad2610bfa7badf82f59967f
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: stm32-qspi: Consume dummy cycles directly
This commit advertises dummy_cycles in stm32_qspi_mem_caps and uses
op->dummy.ncycles directly in stm32_qspi_send() and
stm32_qspi_transfer_one_message().
> diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
> index b77daba6db83a..993b09cc51240 100644
> --- a/drivers/spi/spi-stm32-qspi.c
> +++ b/drivers/spi/spi-stm32-qspi.c
[ ... ]
> @@ -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;
[Severity: High]
Does enabling dummy_cycles drop the dummy phase when a GPIO chip-select is
used?
In spi_mem_exec_op(), spi_mem_convert_dummy() runs first and sets
op->dummy.nbytes = 0 because the controller advertises dummy_cycles. When
spi_get_csgpiod(mem->spi, 0) is non-NULL, spi_mem_exec_op() bypasses
ctlr->mem_ops->exec_op and falls back to building spi_transfers for
stm32_qspi_transfer_one_message(), but that fallback path only creates a
dummy_data transfer when op->dummy.nbytes is non-zero:
drivers/spi/spi-mem.c:spi_mem_exec_op() {
...
if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) {
...
if (op->dummy.nbytes) {
memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
xfers[xferpos].len = op->dummy.nbytes;
xfers[xferpos].tx_nbits = op->dummy.buswidth;
xfers[xferpos].dummy_data = 1;
...
}
As a result, no dummy_data transfer is added to the message, so
stm32_qspi_transfer_one_message() leaves op.dummy.ncycles at 0 and corrupts
flash operations that require dummy cycles on boards using cs-gpios (such
as dual-flash configurations).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=15
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2026-11-25 18:14 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
2026-11-25 17:58 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 02/16] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles Miquel Raynal
2026-11-25 18:07 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 04/16] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 05/16] spi: amlogic-spifc-a1: Fix a typo in a macro Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:59 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 07/16] spi: cadence-qspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 08/16] spi: fsl-qspi: " Miquel Raynal
2026-11-25 17:58 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 09/16] spi: microchip-core-qspi: " Miquel Raynal
2026-11-25 18:06 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 10/16] spi: nxp-xspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 11/16] spi: nxp-xspi: Fix a comment Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly Miquel Raynal
2026-11-25 18:02 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 13/16] spi: sn-f-ospi: " Miquel Raynal
2026-11-25 18:01 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 14/16] spi: stm32-ospi: " Miquel Raynal
2026-11-25 18:12 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 15/16] spi: stm32-qspi: " Miquel Raynal
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
2026-11-25 18:08 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).