[PATCH v2 10/12] i2c: designware: stop transfer if spurious STOP is detected

Dmitry Guzman Dmitry.Guzman at mobileye.com
Wed Sep 2 22:38:17 PDT 2026


In `i2c_dw_process_transfer()`, if STOP_DET flag is set while read or
write is in progress, the transfer should be aborted. If this flag is
handled the same interrupt as TX_EMPTY flag, the driver first handles
TX_EMPTY flag and transmits the following messages, and only afterwards
checks STOP_DET flag.

Also, if STOP_DET flag is set, interrupts are not masked, so if TX_EMPTY
interrupts arrives later, the driver will also send further messages.

To abort transmitting data after spurious STOP, check STOP_DET flag
before TX_EMPTY flag, and if STOP_DET flag is set while transfer is in
progress, disable interrupts as it is done in case of TX_ABRT flag set.

Signed-off-by: Dmitry Guzman <Dmitry.Guzman at mobileye.com>
---
 drivers/i2c/busses/i2c-designware-master.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 76f28e1696bdc81326cf149dfe88c52dd2f0731f..936b9150754e85a1bac2d17a0fa65f6963e4ef3e 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -651,17 +651,19 @@ static void i2c_dw_process_transfer(struct dw_i2c_dev *dev, unsigned int stat)
 	if (stat & DW_IC_INTR_RX_FULL)
 		i2c_dw_read(dev);
 
-	if (stat & DW_IC_INTR_TX_EMPTY)
-		i2c_dw_xfer_msg(dev);
-
 	/* Abort if we detect a STOP in the middle of a read or a write */
 	if ((stat & DW_IC_INTR_STOP_DET) &&
 	    (dev->status & (STATUS_READ_IN_PROGRESS | STATUS_WRITE_IN_PROGRESS))) {
 		dev_err(dev->dev, "spurious STOP detected\n");
 		dev->rx_outstanding = 0;
 		dev->msg_err = -EIO;
+		__i2c_dw_write_intr_mask(dev, 0);
+		goto tx_aborted;
 	}
 
+	if (stat & DW_IC_INTR_TX_EMPTY)
+		i2c_dw_xfer_msg(dev);
+
 	/*
 	 * No need to modify or disable the interrupt mask here.
 	 * i2c_dw_xfer_msg() will take care of it according to

-- 
2.43.0




More information about the linux-arm-kernel mailing list