Skip to content

Commit cdbf262

Browse files
thierryredingwsakernel
authored andcommitted
i2c: tegra: Allocate DMA memory for DMA engine
When the I2C controllers are running in DMA mode, it is the DMA engine that performs the memory accesses rather than the I2C controller. Pass the DMA engine's struct device pointer to the DMA API to make sure the correct DMA operations are used. This fixes an issue where the DMA engine's SMMU stream ID needs to be misleadingly set for the I2C controllers in device tree. Suggested-by: Robin Murphy <[email protected]> Signed-off-by: Thierry Reding <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 569bea7 commit cdbf262

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/i2c/busses/i2c-tegra.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct tegra_i2c_dev {
284284
struct dma_chan *tx_dma_chan;
285285
struct dma_chan *rx_dma_chan;
286286
unsigned int dma_buf_size;
287+
struct device *dma_dev;
287288
dma_addr_t dma_phys;
288289
void *dma_buf;
289290

@@ -420,7 +421,7 @@ static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len)
420421
static void tegra_i2c_release_dma(struct tegra_i2c_dev *i2c_dev)
421422
{
422423
if (i2c_dev->dma_buf) {
423-
dma_free_coherent(i2c_dev->dev, i2c_dev->dma_buf_size,
424+
dma_free_coherent(i2c_dev->dma_dev, i2c_dev->dma_buf_size,
424425
i2c_dev->dma_buf, i2c_dev->dma_phys);
425426
i2c_dev->dma_buf = NULL;
426427
}
@@ -472,10 +473,13 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev)
472473

473474
i2c_dev->tx_dma_chan = chan;
474475

476+
WARN_ON(i2c_dev->tx_dma_chan->device != i2c_dev->rx_dma_chan->device);
477+
i2c_dev->dma_dev = chan->device->dev;
478+
475479
i2c_dev->dma_buf_size = i2c_dev->hw->quirks->max_write_len +
476480
I2C_PACKET_HEADER_SIZE;
477481

478-
dma_buf = dma_alloc_coherent(i2c_dev->dev, i2c_dev->dma_buf_size,
482+
dma_buf = dma_alloc_coherent(i2c_dev->dma_dev, i2c_dev->dma_buf_size,
479483
&dma_phys, GFP_KERNEL | __GFP_NOWARN);
480484
if (!dma_buf) {
481485
dev_err(i2c_dev->dev, "failed to allocate DMA buffer\n");
@@ -1272,15 +1276,15 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
12721276

12731277
if (i2c_dev->dma_mode) {
12741278
if (i2c_dev->msg_read) {
1275-
dma_sync_single_for_device(i2c_dev->dev,
1279+
dma_sync_single_for_device(i2c_dev->dma_dev,
12761280
i2c_dev->dma_phys,
12771281
xfer_size, DMA_FROM_DEVICE);
12781282

12791283
err = tegra_i2c_dma_submit(i2c_dev, xfer_size);
12801284
if (err)
12811285
return err;
12821286
} else {
1283-
dma_sync_single_for_cpu(i2c_dev->dev,
1287+
dma_sync_single_for_cpu(i2c_dev->dma_dev,
12841288
i2c_dev->dma_phys,
12851289
xfer_size, DMA_TO_DEVICE);
12861290
}
@@ -1293,7 +1297,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
12931297
memcpy(i2c_dev->dma_buf + I2C_PACKET_HEADER_SIZE,
12941298
msg->buf, msg->len);
12951299

1296-
dma_sync_single_for_device(i2c_dev->dev,
1300+
dma_sync_single_for_device(i2c_dev->dma_dev,
12971301
i2c_dev->dma_phys,
12981302
xfer_size, DMA_TO_DEVICE);
12991303

@@ -1344,7 +1348,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
13441348
}
13451349

13461350
if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) {
1347-
dma_sync_single_for_cpu(i2c_dev->dev,
1351+
dma_sync_single_for_cpu(i2c_dev->dma_dev,
13481352
i2c_dev->dma_phys,
13491353
xfer_size, DMA_FROM_DEVICE);
13501354

0 commit comments

Comments
 (0)