[PATCH v7 8/9] spi: dw: Use dma_slave_caps bus width helpers

From: Nuno Sá

Date: Tue Nov 24 2026 - 06:21:46 EST


Store the common TX destination and RX source bus widths in a
driver-owned DMA bus width bitmap and populate it through the
dma_slave_caps helper.

This avoids depending on the legacy src_addr_widths and dst_addr_widths
masks returned by dma_get_slave_caps().

Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
Acked-by: Mark Brown <broonie@xxxxxxxxxx>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
Signed-off-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
---
drivers/spi/spi-dw-dma.c | 13 +++++++------
drivers/spi/spi-dw.h | 3 ++-
2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c
index b706770334a6..f151dac59174 100644
--- a/drivers/spi/spi-dw-dma.c
+++ b/drivers/spi/spi-dw-dma.c
@@ -103,13 +103,13 @@ static int dw_spi_dma_caps_init(struct dw_spi *dws)
/* With a single channel only one direction is available at a time */
if (!dws->rxchan) {
dws->dma_sg_burst = tx.max_sg_burst;
- dws->dma_addr_widths = tx.dst_addr_widths;
+ dmaengine_bus_width_copy(&dws->dma_bus_widths, &tx.dst_bus_widths);
return 0;
}

if (!dws->txchan) {
dws->dma_sg_burst = rx.max_sg_burst;
- dws->dma_addr_widths = rx.src_addr_widths;
+ dmaengine_bus_width_copy(&dws->dma_bus_widths, &rx.src_bus_widths);
return 0;
}

@@ -124,10 +124,11 @@ static int dw_spi_dma_caps_init(struct dw_spi *dws)

/*
* Assuming both channels belong to the same DMA controller hence the
- * peripheral side address width capabilities most likely would be
+ * peripheral side bus width capabilities most likely would be
* the same.
*/
- dws->dma_addr_widths = tx.dst_addr_widths & rx.src_addr_widths;
+ dmaengine_bus_width_and(&dws->dma_bus_widths, &tx.dst_bus_widths,
+ &rx.src_bus_widths);

return 0;
}
@@ -292,7 +293,7 @@ static bool dw_spi_can_dma(struct spi_controller *ctlr,

dma_bus_width = dw_spi_dma_convert_width(n_bytes);

- return dws->dma_addr_widths & BIT(dma_bus_width);
+ return dmaengine_bus_width_test(&dws->dma_bus_widths, dma_bus_width);
}

static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed)
@@ -845,7 +846,7 @@ static bool dw_spi_enh_mem_can_dma(struct spi_controller *ctlr)

dma_bus_width = dw_spi_dma_convert_width(dws->n_bytes);

- return dws->dma_addr_widths & BIT(dma_bus_width);
+ return dmaengine_bus_width_test(&dws->dma_bus_widths, dma_bus_width);
}

static int dw_spi_enh_mem_dma_transfer(struct spi_mem *mem, const struct spi_mem_op *op)
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index c16225c5c887..ecbcca50026e 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -5,6 +5,7 @@
#include <linux/bits.h>
#include <linux/completion.h>
#include <linux/debugfs.h>
+#include <linux/dmaengine.h>
#include <linux/irqreturn.h>
#include <linux/io.h>
#include <linux/scatterlist.h>
@@ -220,7 +221,7 @@ struct dw_spi {
unsigned int dma_nr_chans;
bool tx_dir;
u32 dma_sg_burst;
- u32 dma_addr_widths;
+ dma_buswidth_mask_t dma_bus_widths;
unsigned long dma_chan_busy;
dma_addr_t dma_addr; /* phy address of the Data register */
const struct dw_spi_dma_ops *dma_ops;

--
2.56.0