Skip to contentSkip to conversation

i2c: npcm7xx: Clear LAST bit after a failed transaction.

PATCH Applied Tali Perry 2 participants 2 messages Sep 20, 2020 – Sep 27, 2020

Subsystems (2)
lore
Share & tools
lore

Tali Perry

author maintainer
#0 lore raw

PATCH 1/1 i2c: npcm7xx: Clear LAST bit after a failed transaction.

Due to a HW issue, in some scenarios the LAST bit might remain set. This will cause an unexpected NACK after reading 16 bytes on the next read.

Example: if user tries to read from a missing device, get a NACK, then if the next command is a long read ( > 16 bytes), the master will stop reading after 16 bytes.
To solve this, if a command fails, check if LAST bit is still set. If it does, reset the module.

Fixes 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver)
---
 drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/i2c/busses/i2c-npcm7xx.c +9 -0
index dfcf04e1967f..2ad166355ec9 100644
@@ -2163,6 +2163,15 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 	if (bus->cmd_err == -EAGAIN)
 		ret = i2c_recover_bus(adap);
 
+	/*
+	 * After any type of error, check if LAST bit is still set,
+	 * due to a HW issue.
+	 * It cannot be cleared without resetting the module.
+	 */
+	if (bus->cmd_err &&
+	    (NPCM_I2CRXF_CTL_LAST_PEC & ioread8(bus->reg + NPCM_I2CRXF_CTL)))
+		npcm_i2c_reset(bus);
+
 #if IS_ENABLED(CONFIG_I2C_SLAVE)
 	/* reenable slave if it was enabled */
 	if (bus->slave)

base-commit: 856deb866d16e29bd65952e0289066f6078af773

Signature · 1 line
2.22.0
Applied
#1 lore raw
Quoted 4 lines · Tali Perry

Due to a HW issue, in some scenarios the LAST bit might remain set. This will cause an unexpected NACK after reading 16 bytes on the next read.

Quoted 8 lines

Example: if user tries to read from a missing device, get a NACK, then if the next command is a long read ( > 16 bytes), the master will stop reading after 16 bytes.
To solve this, if a command fails, check if LAST bit is still set. If it does, reset the module.

Fixes 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver)

Applied to for-current, thanks!