* [PATCH v2 1/3] i2c: imx: do not carry the interrupt status over to the next transfer
2026-11-19 13:42 [PATCH v2 0/3] i2c: imx: fixes for a DMA write that is not acknowledged Mehmet Fide
@ 2026-11-19 13:42 ` Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 2/3] i2c: imx: unmap the DMA buffer when a transfer is terminated Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 3/3] i2c: imx: return -ENXIO at once when a DMA write is not acknowledged Mehmet Fide
2 siblings, 0 replies; 4+ messages in thread
From: Mehmet Fide @ 2026-11-19 13:42 UTC (permalink / raw)
To: Andi Shyti, Oleksij Rempel
Cc: Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Stefan Eichenberger, Yao Yuan, Wolfram Sang, linux-i2c, imx,
linux-arm-kernel, linux-kernel, stable, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
In DMA mode the interrupt handler stores I2SR in i2c_imx->i2csr and only
i2c_imx_trx_complete() clears it. A DMA transfer that fails returns
without doing so, for example a DMA write whose address is not
acknowledged.
The stale status stays until the next DMA read. There
i2c_imx_prepare_read() calls i2c_imx_trx_complete(), which finds IIF set
and returns before the address byte has been sent, so the read returns
0xff for every byte without an error:
i2ctransfer -a -y 0 w20@0x03 0x00- # unused address, -ETIMEDOUT
i2ctransfer -y 0 w1@0x54 0x00 r32 # 32 times 0xff
i2ctransfer -y 0 w1@0x54 0x00 r32 # correct data
Clear the status when a transfer starts.
Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver")
Cc: stable@vger.kernel.org
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
drivers/i2c/busses/i2c-imx.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 89f2b764bbc4..f20727ffb5ce 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1657,6 +1657,8 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter,
if (result)
return result;
+ i2c_imx->i2csr = 0;
+
/* Start I2C transfer */
result = i2c_imx_start(i2c_imx, atomic);
if (result) {
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/3] i2c: imx: unmap the DMA buffer when a transfer is terminated
2026-11-19 13:42 [PATCH v2 0/3] i2c: imx: fixes for a DMA write that is not acknowledged Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 1/3] i2c: imx: do not carry the interrupt status over to the next transfer Mehmet Fide
@ 2026-11-19 13:42 ` Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 3/3] i2c: imx: return -ENXIO at once when a DMA write is not acknowledged Mehmet Fide
2 siblings, 0 replies; 4+ messages in thread
From: Mehmet Fide @ 2026-11-19 13:42 UTC (permalink / raw)
To: Andi Shyti, Oleksij Rempel
Cc: Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Stefan Eichenberger, Yao Yuan, Wolfram Sang, linux-i2c, imx,
linux-arm-kernel, linux-kernel, stable, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The buffer of a DMA transfer is unmapped in the DMA completion callback
only. When the wait for the completion times out the transfer is
terminated, the callback does not run and the mapping is never released.
Unmap the buffer where the transfer is waited for, after the transfer
has completed or has been terminated.
Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver")
Cc: stable@vger.kernel.org
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
drivers/i2c/busses/i2c-imx.c | 41 ++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f20727ffb5ce..fbfabceb29ac 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -469,11 +469,26 @@ static void i2c_imx_dma_callback(void *arg)
struct imx_i2c_struct *i2c_imx = (struct imx_i2c_struct *)arg;
struct imx_i2c_dma *dma = i2c_imx->dma;
- dma_unmap_single(dma->chan_using->device->dev, dma->dma_buf,
- dma->dma_len, dma->dma_data_dir);
complete(&dma->cmd_complete);
}
+static int i2c_imx_dma_wait(struct imx_i2c_struct *i2c_imx)
+{
+ struct imx_i2c_dma *dma = i2c_imx->dma;
+ int result = 0;
+
+ if (!wait_for_completion_timeout(&dma->cmd_complete,
+ msecs_to_jiffies(DMA_TIMEOUT)))
+ result = -ETIMEDOUT;
+
+ if (result)
+ dmaengine_terminate_sync(dma->chan_using);
+ dma_unmap_single(dma->chan_using->device->dev, dma->dma_buf,
+ dma->dma_len, dma->dma_data_dir);
+
+ return result;
+}
+
static int i2c_imx_dma_xfer(struct imx_i2c_struct *i2c_imx,
struct i2c_msg *msgs)
{
@@ -1192,7 +1207,6 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
struct i2c_msg *msgs)
{
int result;
- unsigned long time_left;
unsigned int temp = 0;
unsigned long orig_jiffies = jiffies;
struct imx_i2c_dma *dma = i2c_imx->dma;
@@ -1217,13 +1231,9 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
* The first byte must be transmitted by the CPU.
*/
imx_i2c_write_reg(i2c_imx_addr_byte(msgs), i2c_imx, IMX_I2C_I2DR);
- time_left = wait_for_completion_timeout(
- &i2c_imx->dma->cmd_complete,
- msecs_to_jiffies(DMA_TIMEOUT));
- if (time_left == 0) {
- dmaengine_terminate_sync(dma->chan_using);
- return -ETIMEDOUT;
- }
+ result = i2c_imx_dma_wait(i2c_imx);
+ if (result)
+ return result;
/* Waiting for transfer complete. */
while (1) {
@@ -1298,7 +1308,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
struct i2c_msg *msgs, bool is_lastmsg)
{
int result;
- unsigned long time_left;
unsigned int temp;
unsigned long orig_jiffies = jiffies;
struct imx_i2c_dma *dma = i2c_imx->dma;
@@ -1321,13 +1330,9 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
if (result)
return result;
- time_left = wait_for_completion_timeout(
- &i2c_imx->dma->cmd_complete,
- msecs_to_jiffies(DMA_TIMEOUT));
- if (time_left == 0) {
- dmaengine_terminate_sync(dma->chan_using);
- return -ETIMEDOUT;
- }
+ result = i2c_imx_dma_wait(i2c_imx);
+ if (result)
+ return result;
/* waiting for transfer complete. */
while (1) {
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 3/3] i2c: imx: return -ENXIO at once when a DMA write is not acknowledged
2026-11-19 13:42 [PATCH v2 0/3] i2c: imx: fixes for a DMA write that is not acknowledged Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 1/3] i2c: imx: do not carry the interrupt status over to the next transfer Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 2/3] i2c: imx: unmap the DMA buffer when a transfer is terminated Mehmet Fide
@ 2026-11-19 13:42 ` Mehmet Fide
2 siblings, 0 replies; 4+ messages in thread
From: Mehmet Fide @ 2026-11-19 13:42 UTC (permalink / raw)
To: Andi Shyti, Oleksij Rempel
Cc: Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Stefan Eichenberger, Yao Yuan, Wolfram Sang, linux-i2c, imx,
linux-arm-kernel, linux-kernel, stable, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
When a byte of a DMA write is not acknowledged the controller raises its
interrupt and no DMA request, so i2c_imx_dma_write() blocks for
DMA_TIMEOUT (1 s) and returns -ETIMEDOUT, where the interrupt driven
write returns -ENXIO.
Let the interrupt handler end the wait when it sees a missing
acknowledge during a DMA write, and return -ENXIO. The last byte the DMA
writes is still on the bus when its completion arrives: look at its
acknowledge once the byte is out, before the final byte is sent.
Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver")
Cc: stable@vger.kernel.org
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
drivers/i2c/busses/i2c-imx.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index fbfabceb29ac..06b082c677a3 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -480,6 +480,9 @@ static int i2c_imx_dma_wait(struct imx_i2c_struct *i2c_imx)
if (!wait_for_completion_timeout(&dma->cmd_complete,
msecs_to_jiffies(DMA_TIMEOUT)))
result = -ETIMEDOUT;
+ else if (dma->dma_transfer_dir == DMA_MEM_TO_DEV &&
+ (i2c_imx->i2csr & I2SR_RXAK))
+ result = -ENXIO;
if (result)
dmaengine_terminate_sync(dma->chan_using);
@@ -1123,6 +1126,9 @@ static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned i
switch (i2c_imx->state) {
case IMX_I2C_STATE_DMA:
i2c_imx->i2csr = status;
+ if ((status & I2SR_RXAK) &&
+ i2c_imx->dma->dma_transfer_dir == DMA_MEM_TO_DEV)
+ complete(&i2c_imx->dma->cmd_complete);
wake_up(&i2c_imx->queue);
break;
@@ -1248,6 +1254,9 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
schedule();
}
+ if (temp & I2SR_RXAK)
+ return -ENXIO;
+
temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
temp &= ~I2CR_DMAEN;
imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread