From: Sarah Maedel <sarah.maedel@hetzner-cloud.de>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
Andi Shyti <andi.shyti@kernel.org>
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"David LaPorte" <dalaport@amazon.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] i2c: designware: Abort stuck master when disabling times out
Date: Tue, 10 Nov 2026 16:43:30 +0100 [thread overview]
Message-ID: <20261110154330.78515-3-sarah.maedel@hetzner-cloud.de> (raw)
In-Reply-To: <20261110154330.78515-1-sarah.maedel@hetzner-cloud.de>
__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@hetzner-cloud.de>
---
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
prev parent reply other threads:[~2026-11-10 15:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 15:43 [PATCH 0/2] i2c: designware: Fix stuck master on multi-master buses Sarah Maedel
2026-11-10 15:43 ` [PATCH 1/2] i2c: designware: Only check for spurious STOP without EMPTYFIFO_HOLD_MASTER Sarah Maedel
2026-11-10 15:43 ` Sarah Maedel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110154330.78515-3-sarah.maedel@hetzner-cloud.de \
--to=sarah.maedel@hetzner-cloud.de \
--cc=andi.shyti@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=benoit.monin@bootlin.com \
--cc=dalaport@amazon.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®