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

From: Miquel Raynal

Date: Wed Nov 25 2026 - 12:53:38 EST


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@xxxxxxxxxxx>
---
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