[PATCH] spi: use dmaengine_get_dma_device() for DMA mapping

Peng Fan (OSS) posted 1 patch 1 week, 1 day ago
drivers/spi/spi-mem.c | 8 ++++----
drivers/spi/spi.c     | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
[PATCH] spi: use dmaengine_get_dma_device() for DMA mapping
Posted by Peng Fan (OSS) 1 week, 1 day ago
From: Peng Fan <peng.fan@nxp.com>

Replace chan->device->dev with dmaengine_get_dma_device(chan) in the
SPI core (spi.c) and SPI mem (spi-mem.c) DMA mapping helpers so that
DMA mapping goes through the correct device when the DMA controller
has per-channel IOMMU domains (chan_dma_dev=true).

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/spi/spi-mem.c | 8 ++++----
 drivers/spi/spi.c     | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 94d122be1c930..b94680b60af95 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -46,9 +46,9 @@ int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
 		return -EINVAL;
 
 	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
-		dmadev = ctlr->dma_tx->device->dev;
+		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
 	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
-		dmadev = ctlr->dma_rx->device->dev;
+		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
 	else
 		dmadev = ctlr->dev.parent;
 
@@ -92,9 +92,9 @@ void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
 		return;
 
 	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
-		dmadev = ctlr->dma_tx->device->dev;
+		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
 	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
-		dmadev = ctlr->dma_rx->device->dev;
+		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
 	else
 		dmadev = ctlr->dev.parent;
 
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 172141650b648..4f9f34b798b66 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1456,14 +1456,14 @@ int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
 		return 0;
 
 	if (ctlr->dma_tx)
-		tx_dev = ctlr->dma_tx->device->dev;
+		tx_dev = dmaengine_get_dma_device(ctlr->dma_tx);
 	else if (ctlr->dma_map_dev)
 		tx_dev = ctlr->dma_map_dev;
 	else
 		tx_dev = ctlr->dev.parent;
 
 	if (ctlr->dma_rx)
-		rx_dev = ctlr->dma_rx->device->dev;
+		rx_dev = dmaengine_get_dma_device(ctlr->dma_rx);
 	else if (ctlr->dma_map_dev)
 		rx_dev = ctlr->dma_map_dev;
 	else

---
base-commit: e6e35979777d646fe3c7c94dca7dd32fb25d45f4
change-id: 20260916-spi-dma-466d0a92bd28

Best regards,
--  
Peng Fan <peng.fan@nxp.com>
Re: [PATCH] spi: use dmaengine_get_dma_device() for DMA mapping
Posted by Mark Brown 11 hours ago
On Wed, 16 Sep 2026 23:30:55 +0800, Peng Fan (OSS) wrote:
> spi: use dmaengine_get_dma_device() for DMA mapping

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4

Thanks!

[1/1] spi: use dmaengine_get_dma_device() for DMA mapping
      https://git.kernel.org/broonie/spi/c/cb5a15943d7d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Re: [PATCH] spi: use dmaengine_get_dma_device() for DMA mapping
Posted by Mark Brown 11 hours ago
On Wed, Sep 16, 2026 at 11:30:55PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Replace chan->device->dev with dmaengine_get_dma_device(chan) in the
> SPI core (spi.c) and SPI mem (spi-mem.c) DMA mapping helpers so that
> DMA mapping goes through the correct device when the DMA controller
> has per-channel IOMMU domains (chan_dma_dev=true).

> @@ -46,9 +46,9 @@ int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
>  		return -EINVAL;
>  
>  	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
> -		dmadev = ctlr->dma_tx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
> -		dmadev = ctlr->dma_rx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else
>  		dmadev = ctlr->dev.parent;
>  

At least OMAP McSPI has different DMA channels per chip select for some
reason, that's broken either way though I think.
Re: [PATCH] spi: use dmaengine_get_dma_device() for DMA mapping
Posted by Frank Li 1 week, 1 day ago
On Wed, Sep 16, 2026 at 11:30:55PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> Replace chan->device->dev with dmaengine_get_dma_device(chan) in the
> SPI core (spi.c) and SPI mem (spi-mem.c) DMA mapping helpers so that
> DMA mapping goes through the correct device when the DMA controller
> has per-channel IOMMU domains (chan_dma_dev=true).
>
> Assisted-by: Claude:claude-opus-4-6
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/spi/spi-mem.c | 8 ++++----
>  drivers/spi/spi.c     | 4 ++--
>  2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 94d122be1c930..b94680b60af95 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -46,9 +46,9 @@ int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
>  		return -EINVAL;
>
>  	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
> -		dmadev = ctlr->dma_tx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
> -		dmadev = ctlr->dma_rx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else
>  		dmadev = ctlr->dev.parent;
>
> @@ -92,9 +92,9 @@ void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
>  		return;
>
>  	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
> -		dmadev = ctlr->dma_tx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
> -		dmadev = ctlr->dma_rx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else
>  		dmadev = ctlr->dev.parent;
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 172141650b648..4f9f34b798b66 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1456,14 +1456,14 @@ int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
>  		return 0;
>
>  	if (ctlr->dma_tx)
> -		tx_dev = ctlr->dma_tx->device->dev;
> +		tx_dev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (ctlr->dma_map_dev)
>  		tx_dev = ctlr->dma_map_dev;
>  	else
>  		tx_dev = ctlr->dev.parent;
>
>  	if (ctlr->dma_rx)
> -		rx_dev = ctlr->dma_rx->device->dev;
> +		rx_dev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else if (ctlr->dma_map_dev)
>  		rx_dev = ctlr->dma_map_dev;
>  	else
>
> ---
> base-commit: e6e35979777d646fe3c7c94dca7dd32fb25d45f4
> change-id: 20260916-spi-dma-466d0a92bd28
>
> Best regards,
> --
> Peng Fan <peng.fan@nxp.com>
>
>
Re: [PATCH] spi: use dmaengine_get_dma_device() for DMA mapping
Posted by Frank Li 1 week, 1 day ago
On Wed, Sep 16, 2026 at 11:30:55PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> Replace chan->device->dev with dmaengine_get_dma_device(chan) in the
> SPI core (spi.c) and SPI mem (spi-mem.c) DMA mapping helpers so that
> DMA mapping goes through the correct device when the DMA controller
> has per-channel IOMMU domains (chan_dma_dev=true).
>
> Assisted-by: Claude:claude-opus-4-6
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---

Thank you for these, it is on my todo list.

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/spi/spi-mem.c | 8 ++++----
>  drivers/spi/spi.c     | 4 ++--
>  2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 94d122be1c930..b94680b60af95 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -46,9 +46,9 @@ int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
>  		return -EINVAL;
>
>  	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
> -		dmadev = ctlr->dma_tx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
> -		dmadev = ctlr->dma_rx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else
>  		dmadev = ctlr->dev.parent;
>
> @@ -92,9 +92,9 @@ void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
>  		return;
>
>  	if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx)
> -		dmadev = ctlr->dma_tx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx)
> -		dmadev = ctlr->dma_rx->device->dev;
> +		dmadev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else
>  		dmadev = ctlr->dev.parent;
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 172141650b648..4f9f34b798b66 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1456,14 +1456,14 @@ int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
>  		return 0;
>
>  	if (ctlr->dma_tx)
> -		tx_dev = ctlr->dma_tx->device->dev;
> +		tx_dev = dmaengine_get_dma_device(ctlr->dma_tx);
>  	else if (ctlr->dma_map_dev)
>  		tx_dev = ctlr->dma_map_dev;
>  	else
>  		tx_dev = ctlr->dev.parent;
>
>  	if (ctlr->dma_rx)
> -		rx_dev = ctlr->dma_rx->device->dev;
> +		rx_dev = dmaengine_get_dma_device(ctlr->dma_rx);
>  	else if (ctlr->dma_map_dev)
>  		rx_dev = ctlr->dma_map_dev;
>  	else
>
> ---
> base-commit: e6e35979777d646fe3c7c94dca7dd32fb25d45f4
> change-id: 20260916-spi-dma-466d0a92bd28
>
> Best regards,
> --
> Peng Fan <peng.fan@nxp.com>
>
>