Skip to contentSkip to conversation

i2c: imx: do not acknowledge the last byte of a block read of one byte

PATCH New Mehmet Fide 1 participant 1 message Nov 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: imx: do not acknowledge the last byte of a block read of one byte

From: Mehmet Fide <[email protected]>

In the interrupt driven read, the read of I2DR that takes the count byte of an SMBus block read starts the reception of the next byte. With a count of 1 and no PEC that byte is the last one, but I2CR_TXAK is only set in i2c_imx_isr_read_continue() for the byte after it, so the last byte is acknowledged and the target goes on sending. The read fails with -ETIMEDOUT, the bus stays busy and the following transfers on it fail too.

Set I2CR_TXAK after taking the count when the message is then two bytes long, as the read before the interrupt driven state machine did and the atomic read still does.

Fixes 5f5c2d4579ca ("i2c: imx: prevent rescheduling in non dma mode")
Cc [email protected] # v6.13+

---

Notes:
Changes in v2:
- Test the length of the message instead of the count, so that with PEC the data byte is acknowledged and the PEC byte is not (Sashiko).
v1: https://lore.kernel.org/r/[email protected]/

Tested on a Colibri VF50 on the Iris carrier, kernel at this base plus "i2c: imx: acknowledge the count byte of an atomic block read" and "i2c: imx: keep the error of a failed read", with the M41T0 RTC at 0x68. A test-only hook passed the messages that i2c_smbus_xfer_emulated() builds for a block read to the adapter, alone and followed by a one byte read, with the read message starting at a length of 1 or, as with PEC,
2. Register 0x05 (0x01) as count byte on the interrupt driven read: v1 read 0xff in the PEC position (40 of 40); v2 reads 01 01, and 01 01 00 with the PEC length (250 of 250). Count bytes of 0, 0x13 and 0xae read as before.

 drivers/i2c/busses/i2c-imx.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/i2c/busses/i2c-imx.c +6 -0
index ccf08cd63151..eabadeb47e2e 100644
@@ -1095,6 +1095,12 @@ static inline void i2c_imx_isr_read_block_data_len(struct imx_i2c_struct *i2c_im
 	}
 	i2c_imx->msg->len += len;
 	i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = len;
+
+	if (i2c_imx->msg->len == 2) {
+		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
+		temp |= I2CR_TXAK;
+		imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
+	}
 }
 
 static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned int status)

base-commit: 25e7ab89f4774b0f842cee0e8a20c11f755924d5

Signature · 1 line
2.56.0