[PATCH v3] i2c: imx: honour I2C_M_IGNORE_NAK

Haobin Jiang lemonoutput at foxmail.com
Tue Sep 8 09:01:45 PDT 2026


I2C_M_IGNORE_NAK is removed from the flags rejected by
i2c_imx_check_msgs(), so the flag is honoured as documented. I2C_M_STOP
stays unhandled to preserve existing behaviour and backward
compatibility. I2C_M_NO_RD_ACK stays rejected.

This change is meant to apply on top of the I2C_M_REV_DIR_ADDR and
I2C_M_NOSTART series [1], which is not yet merged.

Tested on an ALIENTEK i.MX6ULL mini board (v6.6.44, equivalent
backport) with a logic analyzer: with the flag, a 3-byte write to an
unpopulated address clocks out every byte (each NAK'd) and returns 0;
without the flag it aborts with -ENXIO after the address byte. A
4-byte read with the flag completes and returns 0 as well. Waveforms
and test logs: https://github.com/JHB11Hinson/i2c-imx-ignore-nak-test

Note: part of the code was generated with the assistance
of a generative AI tool (GLM 5.3) from the author's description of
the problem, then reviewed and verified by the author.

Link: https://lore.kernel.org/linux-i2c/20260812-for-upstream-i2c-imx-lx2160-reverse-v2-1-f1343714c5a9@free.fr/ # [1]

Signed-off-by: Haobin Jiang <lemonoutput at foxmail.com>
---

v1 -> v2:
	- Honour I2C_M_IGNORE_NAK on the read path as well, mirroring
	  i2c-img-scb, instead of silently dropping the flag there.
	- Force the PIO path for every message with I2C_M_IGNORE_NAK:
	  a NAK'd byte does not generate a further DMA request, so a
	  DMA write to a deliberately-NAKing target would stall until
	  DMA_TIMEOUT.
	- Reject I2C_M_NO_RD_ACK instead of advertising blanket support
	  and silently ignoring it. I2C_M_STOP is not rejected: the
	  controller already emits a STOP after the final message, and
	  rejecting it would break the ov2659 camera on imx6qdl-ds.

v2 -> v3:
	- Rebase on top of the I2C_M_REV_DIR_ADDR and I2C_M_NOSTART
	  series; the flag rejection moved to i2c_imx_check_msgs().
	  I2C_M_IGNORE_NAK is now honoured and I2C_M_STOP stays
	  unhandled, preserving the ov2659/SCCB use case and backward
	  compatibility as agreed during review.
	- Keep the DMA write path checking ACK with ignore_nak=false,
	  as suggested during review; messages carrying
	  I2C_M_IGNORE_NAK are forced onto the PIO path.
	- Fix double spaces after periods in the changelog and comments.
	- State the use of a generative AI tool in the changelog.
	- Test on an ALIENTEK i.MX6ULL mini board (v6.6.44, equivalent
	  backport); results linked in the commit message.

 drivers/i2c/busses/i2c-imx.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index ab6794bf3ea5..9cd1fa0f4021 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -612,9 +612,12 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic)
 	return 0;
 }
 
-static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
+static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx, bool ignore_nak)
 {
 	if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) {
+		if (ignore_nak)
+			return 0;
+
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
 		return -ENXIO;  /* No ACK */
 	}
@@ -968,11 +971,15 @@ static int i2c_imx_unreg_slave(struct i2c_client *client)
 	return ret;
 }
 
-static inline int i2c_imx_isr_acked(struct imx_i2c_struct *i2c_imx)
+static inline int i2c_imx_isr_acked(struct imx_i2c_struct *i2c_imx,
+				    bool ignore_nak)
 {
 	i2c_imx->isr_result = 0;
 
 	if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) {
+		if (ignore_nak)
+			return 0;
+
 		i2c_imx->state = IMX_I2C_STATE_FAILED;
 		i2c_imx->isr_result = -ENXIO;
 		wake_up(&i2c_imx->queue);
@@ -985,7 +992,7 @@ static inline int i2c_imx_isr_write(struct imx_i2c_struct *i2c_imx)
 {
 	int result;
 
-	result = i2c_imx_isr_acked(i2c_imx);
+	result = i2c_imx_isr_acked(i2c_imx, i2c_imx->msg->flags & I2C_M_IGNORE_NAK);
 	if (result)
 		return result;
 
@@ -1014,7 +1021,7 @@ static inline int i2c_imx_isr_read(struct imx_i2c_struct *i2c_imx)
 {
 	int result;
 
-	result = i2c_imx_isr_acked(i2c_imx);
+	result = i2c_imx_isr_acked(i2c_imx, i2c_imx->msg->flags & I2C_M_IGNORE_NAK);
 	if (result)
 		return result;
 
@@ -1229,7 +1236,8 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
 	if (result)
 		return result;
 
-	return i2c_imx_acked(i2c_imx);
+	/* I2C_M_IGNORE_NAK messages never take the DMA path. */
+	return i2c_imx_acked(i2c_imx, false);
 }
 
 static int i2c_imx_prepare_read(struct imx_i2c_struct *i2c_imx,
@@ -1248,7 +1256,7 @@ static int i2c_imx_prepare_read(struct imx_i2c_struct *i2c_imx,
 		result = i2c_imx_trx_complete(i2c_imx, !use_dma);
 		if (result)
 			return result;
-		result = i2c_imx_acked(i2c_imx);
+		result = i2c_imx_acked(i2c_imx, msgs->flags & I2C_M_IGNORE_NAK);
 		if (result)
 			return result;
 	}
@@ -1381,7 +1389,7 @@ static int i2c_imx_atomic_write(struct imx_i2c_struct *i2c_imx,
 		result = i2c_imx_trx_complete(i2c_imx, true);
 		if (result)
 			return result;
-		result = i2c_imx_acked(i2c_imx);
+		result = i2c_imx_acked(i2c_imx, msgs->flags & I2C_M_IGNORE_NAK);
 		if (result)
 			return result;
 	}
@@ -1396,7 +1404,7 @@ static int i2c_imx_atomic_write(struct imx_i2c_struct *i2c_imx,
 		result = i2c_imx_trx_complete(i2c_imx, true);
 		if (result)
 			return result;
-		result = i2c_imx_acked(i2c_imx);
+		result = i2c_imx_acked(i2c_imx, msgs->flags & I2C_M_IGNORE_NAK);
 		if (result)
 			return result;
 	}
@@ -1580,8 +1588,9 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs,
 	return ret;
 }
 
+	/* I2C_M_STOP is the controller's native behaviour; don't reject it. */
 #define I2C_IMX_UNSUPPORTED_PROTOCOL_MANGLING_FLAGS \
-	(I2C_M_IGNORE_NAK | I2C_M_NO_RD_ACK | I2C_M_STOP)
+	I2C_M_NO_RD_ACK
 
 static int i2c_imx_check_msgs(struct i2c_msg *msgs, int num)
 {
@@ -1675,6 +1684,10 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter,
 		use_dma = i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD &&
 			msgs[i].flags & I2C_M_DMA_SAFE &&
 			!(msgs[i].flags & I2C_M_NOSTART);
+
+		/* A NAK'd byte may not generate a further DMA request. */
+		if (msgs[i].flags & I2C_M_IGNORE_NAK)
+			use_dma = false;
 		if (msgs[i].flags & I2C_M_RD) {
 			int block_data = msgs->flags & I2C_M_RECV_LEN;
 

base-commit: 04e9bf1648f846976b543e91c1838a712433772a
prerequisite-patch-id: 24876ef6d4dc440b8d8080e65d369b2b37709b0b
-- 
2.34.1




More information about the linux-arm-kernel mailing list