linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c-omap: Trigger bus recovery in lockup case
@ 2017-09-14 15:39 Claudio Foellmi
  2017-09-15 23:31 ` Grygorii Strashko
  0 siblings, 1 reply; 20+ messages in thread
From: Claudio Foellmi @ 2017-09-14 15:39 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Claudio Foellmi, Aaro Koskinen, Wolfram Sang, linux-omap,
	linux-i2c

A very conservative check for bus activity (to prevent interference
in multimaster setups) prevented the bus recovery methods from being
triggered in the case that SDA or SCL was stuck low.
This defeats the purpose of the recovery mechanism, which was introduced
for exactly this situation (a slave device keeping SDA pulled down).

Note that bus lockups can persist across reboots. The only other options
are to reset or power cycle the offending slave device, and many i2c
slaves do not even have a reset pin.

If we see that one of the lines is low for the entire timeout duration,
we can actually be sure that there is no other master driving the bus.
It is therefore save for us to attempt a bus recovery.

Signed-off-by: Claudio Foellmi <claudio.foellmi@ergon.ch>
---
Caveat: It turns out I don't have the hardware to fully test the
recovery mechanism. My faulty i2c slave device actually pulls down SCL,
not SDA (so the recovery will not succeed in my case).
But by directly connecting SDA to ground, I could at least make sure
the recovery function gets called after applying this patch.

 drivers/i2c/busses/i2c-omap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 1ebb5e9..4b25fd1 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -563,8 +563,13 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
 		}
 
 		if (time_after(jiffies, timeout)) {
+			/*
+			 * SDA or SCL were low for the entire timeout without
+			 * any activity detected. Most likely, a slave is
+			 * locking up the bus with no master driving the clock.
+			 */
 			dev_warn(omap->dev, "timeout waiting for bus ready\n");
-			return -ETIMEDOUT;
+			return i2c_recover_bus(&omap->adapter);
 		}
 
 		msleep(1);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-10-30 14:19 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-14 15:39 [PATCH] i2c-omap: Trigger bus recovery in lockup case Claudio Foellmi
2017-09-15 23:31 ` Grygorii Strashko
2017-09-18  5:24   ` Vignesh R
2017-09-18 12:01     ` Claudio Foellmi
2017-09-19 10:50       ` Vignesh R
2017-09-20  9:24         ` Claudio Foellmi
2017-09-20 15:02         ` Sebastian Reichel
2017-09-26 12:24         ` Claudio Foellmi
2017-09-29 12:52           ` Sebastian Reichel
2017-09-29 15:17             ` Claudio Foellmi
2017-09-29 16:37               ` Sebastian Reichel
2017-10-02 23:01                 ` Grygorii Strashko
2017-10-06 15:22                   ` Sebastian Reichel
2017-10-03 10:32               ` Vignesh R
2017-10-04  9:43                 ` [PATCH v2] i2c: omap: " Claudio Foellmi
2017-10-05  6:01                   ` Vignesh R
2017-10-05 12:30                     ` Grygorii Strashko
2017-10-28 20:52                   ` Wolfram Sang
2017-10-30  9:11                     ` Claudio Foellmi
2017-10-30 14:19                   ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).