[PATCH 2/2] i2c: designware: Abort stuck master when disabling times out
From: Sarah Maedel
Date: Tue Nov 10 2026 - 11:15:51 EST
__i2c_dw_disable() only aborts the current transfer if MST_ON_HOLD or
MASTER_HOLD_TX_FIFO_EMPTY is set. These bits only exist with
IC_STAT_FOR_CLK_STRETCH, so on other configurations a master left
holding the bus can't be disabled: IC_ENABLE_STATUS stays set and
IC_STATUS keeps reporting MST_ACTIVITY.
If the master is still active once the disable loop has timed out,
abort the transfer and try again. Also disable the adapter from
i2c_dw_wait_bus_not_busy() when bus recovery didn't help, so the next
transfer recovers the controller.
Tested on Ampere Altra by putting the controller into this state
through /dev/mem (a write without STOP, then clearing IC_ENABLE).
Signed-off-by: Sarah Maedel <sarah.maedel@xxxxxxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-designware-common.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index a1eca6cd4b75..2e8de0f6c1ed 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -643,6 +643,7 @@ void __i2c_dw_disable(struct dw_i2c_dev *dev)
if (dev->mode == DW_IC_SLAVE && (ic_stats & DW_IC_STATUS_SLAVE_ACTIVITY))
abort_needed = true;
+retry:
if (abort_needed) {
if (!(enable & DW_IC_ENABLE_ENABLE)) {
regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
@@ -684,6 +685,19 @@ void __i2c_dw_disable(struct dw_i2c_dev *dev)
usleep_range(25, 250);
} while (timeout--);
+ /*
+ * Without IC_STAT_FOR_CLK_STRETCH the hold status bits above don't
+ * exist, so a stuck master is only noticed here.
+ */
+ regmap_read(dev->map, DW_IC_STATUS, &ic_stats);
+ if (!abort_needed && (ic_stats & DW_IC_STATUS_MASTER_ACTIVITY)) {
+ dev_warn(dev->dev, "controller stuck active, aborting\n");
+ regmap_read(dev->map, DW_IC_ENABLE, &enable);
+ abort_needed = true;
+ timeout = 100;
+ goto retry;
+ }
+
dev_warn(dev->dev, "timeout in disabling adapter\n");
}
@@ -764,6 +778,11 @@ int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev)
i2c_recover_bus(&dev->adapter);
regmap_read(dev->map, DW_IC_STATUS, &status);
+ if (status & DW_IC_STATUS_MASTER_ACTIVITY) {
+ /* Disabling aborts a master stuck on the bus */
+ __i2c_dw_disable(dev);
+ regmap_read(dev->map, DW_IC_STATUS, &status);
+ }
if (!(status & DW_IC_STATUS_ACTIVITY))
ret = 0;
}
--
2.47.3