Skip to contentSkip to conversation

i2c: designware: report aborted reads and writes

PATCH New Terry Zhou (Synaptics) 1 participant 1 message Nov 23 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: designware: report aborted reads and writes

Writes to an unresponsive slave can raise TX_ABRT and leave the bus idle. The completion path only checks STOP_DET and bus activity, so an aborted write can incorrectly return success. Reads wait for data until a timeout instead of detecting the abort.

Detect TX_ABRT in the read/write loops and after the bus becomes idle. Clear the abort and return -EREMOTEIO.

---
Testing:
Validated using downstream Synaptics SDK U-Boot on SL2610 RDK:

Bus 0 ran at 100 kHz. Address 0x60 had no responding device; address 0x43 was used to verify access to a responding device after a failure.

Without the fix:
- Reads from 0x60 reported -EREMOTEIO via the existing DM error mapping after timing out.
- Single-byte and 4096-byte writes to 0x60 incorrectly returned success with shell status 0.

With the fix:
- Reads (with and without an offset byte), single-byte writes and 4096-byte writes to 0x60 reported -EREMOTEIO with shell status 1.
- Subsequent reads from 0x43 succeeded with shell status 0.

Each test case was repeated three times with consistent results.

 drivers/i2c/designware_i2c.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/i2c/designware_i2c.c +14 -1
index 2a4c3f8a398..9185888639e 100644
@@ -451,7 +451,14 @@ static int i2c_xfer_finish(struct i2c_regs *i2c_base)
 
 	i2c_flush_rxfifo(i2c_base);
 
-	return 0;
+	/* Check after the bus is idle so a late abort cannot be missed. */
+	if (!(readl(&i2c_base->ic_raw_intr_stat) & IC_TX_ABRT))
+		return 0;
+
+	/* Clear the abort and release the controller TX FIFO. */
+	readl(&i2c_base->ic_clr_tx_abrt);
+
+	return -EREMOTEIO;
 }
 
 /*
@@ -502,6 +509,9 @@ static int __dw_i2c_read(struct i2c_regs *i2c_base, u8 dev, uint addr,
 
 	start_time_rx = get_timer(0);
 	while (len) {
+		if (readl(&i2c_base->ic_raw_intr_stat) & IC_TX_ABRT)
+			break;
+
 		/*
 		 * Queue reads without waiting for each response. Reserve an RX
 		 * FIFO slot for every outstanding command, including those whose
@@ -572,6 +582,9 @@ static int __dw_i2c_write(struct i2c_regs *i2c_base, u8 dev, uint addr,
 
 	start_time_tx = get_timer(0);
 	while (len) {
+		if (readl(&i2c_base->ic_raw_intr_stat) & IC_TX_ABRT)
+			break;
+
 		if (readl(&i2c_base->ic_status) & IC_STATUS_TFNF) {
 			if (--len == 0) {
 				writel(*buffer | IC_STOP,

base-commit: e578056c766d653270b14557c2a9d8daec414c17

Signature · 1 line
2.34.1