From icampbell@arcom.com Wed Aug 10 08:05:05 2005
Subject: I2C: i2c-algo-pca -- gracefully handle a busy bus
From: Ian Campbell <icampbell@arcom.com>
To: Greg KH <gregkh@suse.de>
Date: Wed, 10 Aug 2005 08:51:16 +0100
Message-Id: <1123660276.13258.28.camel@icampbell-debian>

I've been running with this patch for a while now, and while I've never
seen it trigger except with buggy hardware I think it is a cleaner way
to handle a busy bus. I had -EBUSY until about 10 minutes ago but -EIO
seems to be what most of the existing algo drivers will return in the
same circumstances.

Signed-off-by: Ian Campbell <icampbell@arcom.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/i2c/algos/i2c-algo-pca.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

--- gregkh-2.6.orig/drivers/i2c/algos/i2c-algo-pca.c	2005-08-10 14:40:03.000000000 -0700
+++ gregkh-2.6/drivers/i2c/algos/i2c-algo-pca.c	2005-08-10 14:40:08.000000000 -0700
@@ -187,12 +187,14 @@
 	int numbytes = 0;
 	int state;
 	int ret;
+	int timeout = 100;
 
-	state = pca_status(adap);
-	if ( state != 0xF8 ) {
-		dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state );
-		/* FIXME: what to do. Force stop ? */
-		return -EREMOTEIO;
+	while ((state = pca_status(adap)) != 0xf8 && timeout--) {
+		msleep(10);
+	}
+	if (state != 0xf8) {
+		dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state);
+		return -EIO;
 	}
 
 	DEB1("{{{ XFER %d messages\n", num);