[PATCH RFC 14/16] spi: stm32-ospi: Consume dummy cycles directly

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Nov 25 10:12:07 PST 2026


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 at 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



More information about the linux-mtd mailing list