]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: dw: fix first spi transfer with dma always fallback to PIO
authorJisheng Zhang <jszhang@kernel.org>
Mon, 15 Jun 2026 04:40:35 +0000 (12:40 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 29 Jun 2026 17:27:48 +0000 (18:27 +0100)
Even with proper dma engine support, the first spi transfer always
fallback to PIO, the reason is the dws->n_bytes is 0 after
initialization, so the dw_spi_can_dma() calling from __spi_map_msg()
return false, thus both tx_sg_mapped and rx_sg_mapped are false, so
for the first spi transfer, the spi_xfer_is_dma_mapped() reports false
thus fallback to PIO.

Although this brings no harm, we can simply fix this issue by
calcuating the "n_bytes" from xfer->bits_per_word.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Link: https://patch.msgid.link/20260615044039.9750-2-jszhang@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-dw-dma.c

index fe726b9b1780d2642b46e80f63d105f7c6c372ec..bd70a7ed8067dcd0c62287c5ba0d0da5728b9dce 100644 (file)
@@ -247,11 +247,12 @@ static bool dw_spi_can_dma(struct spi_controller *ctlr,
 {
        struct dw_spi *dws = spi_controller_get_devdata(ctlr);
        enum dma_slave_buswidth dma_bus_width;
+       u8 n_bytes = roundup_pow_of_two(BITS_TO_BYTES(xfer->bits_per_word));
 
        if (xfer->len <= dws->fifo_len)
                return false;
 
-       dma_bus_width = dw_spi_dma_convert_width(dws->n_bytes);
+       dma_bus_width = dw_spi_dma_convert_width(n_bytes);
 
        return dws->dma_addr_widths & BIT(dma_bus_width);
 }