[PATCH 1/1] i2c: use dmaengine_get_dma_device() instead of chan->device->dev

From: Frank . Li

Date: Tue Nov 03 2026 - 16:27:46 EST


From: Frank Li <Frank.Li@xxxxxxx>

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.

Signed-off-by: Frank Li <Frank.Li@xxxxxxx>
---
drivers/i2c/busses/i2c-rcar.c | 6 +++---
drivers/i2c/busses/i2c-sh_mobile.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 755064804cb21..86b1df3a56c4d 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -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;
}
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 3a55f803e4f15..023813c2f7809 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -452,7 +452,7 @@ static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd, bool termin
if (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;
}
--
2.43.0