Skip to contentSkip to conversation

HID: mcp2221: cancel last I2C command on read error

PATCH Applied Romain Sioen 2 participants 2 messages Feb 6 – Feb 27

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

PATCH 1/1 HID: mcp2221: cancel last I2C command on read error

When an I2C SMBus read operation fails, the MCP2221 internal state machine may not reset correctly, causing subsequent transactions to fail.

By adding a short delay and explicitly cancelling the last command, we ensure the device is ready for the next operation.

Fix an issue where i2cdetect was not able to detect all devices correctly on the bus.

---
 drivers/hid/hid-mcp2221.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/hid-mcp2221.c +2 -0
index 64dcedbcc0fc9..5eefdcc477b9d 100644
@@ -353,6 +353,8 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
 				usleep_range(90, 100);
 				retries++;
 			} else {
+				usleep_range(980, 1000);
+				mcp_cancel_last_cmd(mcp);
 				return ret;
 			}
 		} else {
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 19 lines · Romain Sioen

When an I2C SMBus read operation fails, the MCP2221 internal state machine may not reset correctly, causing subsequent transactions to fail.

By adding a short delay and explicitly cancelling the last command, we ensure the device is ready for the next operation.

Fix an issue where i2cdetect was not able to detect all devices correctly on the bus.

---
 drivers/hid/hid-mcp2221.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/hid-mcp2221.c +0 -0
index 64dcedbcc0fc9..5eefdcc477b9d 100644

drivers/hid/hid-mcp2221.c static int mcp_i2c_smbus_read(struct mcp2221 *mcp, · line 358

Quoted 6 lines
drivers/hid/hid-mcp2221.c +2 -0
@@ -353,6 +353,8 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
 				usleep_range(90, 100);
 				retries++;
 			} else {
+				usleep_range(980, 1000);
+				mcp_cancel_last_cmd(mcp);
 				return ret;

Applied to hid.git#for-7.0/upstream-fixes, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs