i2c: use dmaengine_get_dma_device() instead of chan->device->dev
Subsystems (5)
PATCH 1/1 i2c: use dmaengine_get_dma_device() instead of chan->device->dev
From: Frank Li <[email protected]>
Replace direct dma_chan::device::dev access with the proper dmaengine_get_dma_device() for consumer API.
chan->device->dev is not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices. dmaengine_get_dma_device() returns the correct device for each channel.
This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
--- drivers/i2c/busses/i2c-rcar.c | 6 +++--- drivers/i2c/busses/i2c-sh_mobile.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-rcar.c +3 -3
@@ -455,7 +455,7 @@ static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv, bool terminate)if (terminate)dmaengine_terminate_sync (chan); -dma_unmap_single (chan->device->dev,sg_dma_address (&priv->sg), +dma_unmap_single (dmaengine_get_dma_device (chan),sg_dma_address (&priv->sg),sg_dma_len (&priv->sg), priv->dma_direction);/* Gen3+ can only do one RXDMA per transfer and we just completed it */
@@ -511,8 +511,8 @@ static bool rcar_i2c_dma(struct rcar_i2c_priv *priv) len = priv->msg->len -1 ; } - dma_addr =dma_map_single (chan->device->dev, buf, len, dir); -if (dma_mapping_error (chan->device->dev, dma_addr)) { + dma_addr =dma_map_single (dmaengine_get_dma_device (chan), buf, len, dir); +if (dma_mapping_error (dmaengine_get_dma_device (chan), dma_addr)) {dev_dbg (dev,"dma map failed, using PIO\n" );return false; }
drivers/i2c/busses/i2c-sh_mobile.c +3 -3
@@ -452,7 +452,7 @@ static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd, bool terminif (terminate)dmaengine_terminate_sync (chan); -dma_unmap_single (chan->device->dev,sg_dma_address (&pd->sg), +dma_unmap_single (dmaengine_get_dma_device (chan),sg_dma_address (&pd->sg), pd->msg->len, pd->dma_direction); pd->dma_direction =DMA_NONE ;
@@ -526,8 +526,8 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)if (IS_ERR (chan))return ; - dma_addr =dma_map_single (chan->device->dev, pd->dma_buf, pd->msg->len, dir); -if (dma_mapping_error (chan->device->dev, dma_addr)) { + dma_addr =dma_map_single (dmaengine_get_dma_device (chan), pd->dma_buf, pd->msg->len, dir); +if (dma_mapping_error (dmaengine_get_dma_device (chan), dma_addr)) {dev_dbg (pd->dev,"dma map failed, using PIO\n" );return ; }
Signature · 1 line
2.43.0
Wolfram Sang
maintainerHi Frank,
Quoted 5 lines · On Tue, Nov 03, 2026 at 04:26:54PM -0500, [email protected] wrote:
From: Frank Li <[email protected]>
Replace direct
dma_chan::device::devaccess with the properdmaengine_get_dma_device()for consumer API.
Quoted 7 lines
chan->device->devis not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices.dmaengine_get_dma_device()returns the correct device for each channel.This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
Thanks for this, looks useful.
drivers/i2c/busses/i2c-rcar.c static bool rcar_i2c_dma(struct rcar_i2c_priv *priv) · line 516
Quoted 5 lines
drivers/i2c/busses/i2c-rcar.c +2
-2- dma_addr =dma_map_single (chan->device->dev, buf, len, dir); -if (dma_mapping_error (chan->device->dev, dma_addr)) { + dma_addr =dma_map_single (dmaengine_get_dma_device (chan), buf, len, dir); +if (dma_mapping_error (dmaengine_get_dma_device (chan), dma_addr)) {dev_dbg (dev,"dma map failed, using PIO\n" );
I think we should populate a dma_dev-variable here and reuse it instead of calling dmaengine_get_dma_device() twice.
Happy hacking,
Wolfram