mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Fixed i2c-mpc driver for multi-master i2c busses.
@ 2008-12-22 13:55 Clifford Wolf
  2008-12-22 21:01 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Clifford Wolf @ 2008-12-22 13:55 UTC (permalink / raw)
  To: LKML; +Cc: Adrian Cox

Fixed i2c-mpc driver for multi-master i2c busses.

Simply retry on arbitration lost until xfer is successfull,
a non-arbitration-lost error is triggered or the 1s timeout
is hit.

Tested with a freescale MPC8349E host cpu.

Signed-off-by: Clifford Wolf <clifford@clifford.at>

--- ./drivers/i2c/busses/i2c-mpc.c	(revision 2186)
+++ ./drivers/i2c/busses/i2c-mpc.c	(revision 2187)
@@ -133,16 +133,16 @@
 	if (result < 0)
 		return result;
 
+	if (x & CSR_MAL) {
+		pr_debug("I2C: MAL\n");
+		return -EAGAIN;
+	}
+
 	if (!(x & CSR_MCF)) {
 		pr_debug("I2C: unfinished\n");
 		return -EIO;
 	}
 
-	if (x & CSR_MAL) {
-		pr_debug("I2C: MAL\n");
-		return -EIO;
-	}
-
 	if (writing && (x & CSR_RXAK)) {
 		pr_debug("I2C: No RXAK\n");
 		/* generate stop */
@@ -256,11 +256,11 @@
 static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 {
 	struct i2c_msg *pmsg;
-	int i;
-	int ret = 0;
+	int i, ret;
 	unsigned long orig_jiffies = jiffies;
 	struct mpc_i2c *i2c = i2c_get_adapdata(adap);
 
+restart:
 	mpc_i2c_start(i2c);
 
 	/* Allow bus up to 1s to become not busy */
@@ -280,7 +280,7 @@
 		schedule();
 	}
 
-	for (i = 0; ret >= 0 && i < num; i++) {
+	for (i = 0, ret = 0; ret >= 0 && i < num; i++) {
 		pmsg = &msgs[i];
 		pr_debug("Doing %s %d bytes to 0x%02x - %d of %d messages\n",
 			 pmsg->flags & I2C_M_RD ? "read" : "write",
@@ -291,7 +291,13 @@
 		else
 			ret =
 			    mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+		if (ret == -EAGAIN) {
+			pr_debug("Lost i2c arbitration -> retry.\n");
+			mpc_i2c_stop(i2c);
+			goto restart;
+		}
 	}
+
 	mpc_i2c_stop(i2c);
 	return (ret < 0) ? ret : num;
 }

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

* Re: [PATCH] Fixed i2c-mpc driver for multi-master i2c busses.
  2008-12-22 13:55 [PATCH] Fixed i2c-mpc driver for multi-master i2c busses Clifford Wolf
@ 2008-12-22 21:01 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2008-12-22 21:01 UTC (permalink / raw)
  To: Clifford Wolf; +Cc: linux-kernel, adrian, i2c

(cc i2c@lm-sensors.org)

On Mon, 22 Dec 2008 14:55:42 +0100
Clifford Wolf <clifford@clifford.at> wrote:

> Fixed i2c-mpc driver for multi-master i2c busses.
> 
> Simply retry on arbitration lost until xfer is successfull,
> a non-arbitration-lost error is triggered or the 1s timeout
> is hit.
> 
> Tested with a freescale MPC8349E host cpu.
> 
> Signed-off-by: Clifford Wolf <clifford@clifford.at>

From: Clifford Wolf <clifford@clifford.at>

Simply retry on arbitration lost until xfer is successfull, a
non-arbitration-lost error is triggered or the 1s timeout is hit.

Tested with a freescale MPC8349E host cpu.

Signed-off-by: Clifford Wolf <clifford@clifford.at>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/i2c/busses/i2c-mpc.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff -puN drivers/i2c/busses/i2c-mpc.c~fixed-i2c-mpc-driver-for-multi-master-i2c-busses drivers/i2c/busses/i2c-mpc.c
--- a/drivers/i2c/busses/i2c-mpc.c~fixed-i2c-mpc-driver-for-multi-master-i2c-busses
+++ a/drivers/i2c/busses/i2c-mpc.c
@@ -134,13 +134,13 @@ static int i2c_wait(struct mpc_i2c *i2c,
 	if (result < 0)
 		return result;
 
-	if (!(x & CSR_MCF)) {
-		pr_debug("I2C: unfinished\n");
-		return -EIO;
-	}
-
 	if (x & CSR_MAL) {
 		pr_debug("I2C: MAL\n");
+		return -EAGAIN;
+	}
+
+	if (!(x & CSR_MCF)) {
+		pr_debug("I2C: unfinished\n");
 		return -EIO;
 	}
 
@@ -257,11 +257,11 @@ static int mpc_read(struct mpc_i2c *i2c,
 static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 {
 	struct i2c_msg *pmsg;
-	int i;
-	int ret = 0;
+	int i, ret;
 	unsigned long orig_jiffies = jiffies;
 	struct mpc_i2c *i2c = i2c_get_adapdata(adap);
 
+restart:
 	mpc_i2c_start(i2c);
 
 	/* Allow bus up to 1s to become not busy */
@@ -281,7 +281,7 @@ static int mpc_xfer(struct i2c_adapter *
 		schedule();
 	}
 
-	for (i = 0; ret >= 0 && i < num; i++) {
+	for (i = 0, ret = 0; ret >= 0 && i < num; i++) {
 		pmsg = &msgs[i];
 		pr_debug("Doing %s %d bytes to 0x%02x - %d of %d messages\n",
 			 pmsg->flags & I2C_M_RD ? "read" : "write",
@@ -292,7 +292,13 @@ static int mpc_xfer(struct i2c_adapter *
 		else
 			ret =
 			    mpc_write(i2c, pmsg->addr, pmsg->buf, pmsg->len, i);
+		if (ret == -EAGAIN) {
+			pr_debug("Lost i2c arbitration -> retry.\n");
+			mpc_i2c_stop(i2c);
+			goto restart;
+		}
 	}
+
 	mpc_i2c_stop(i2c);
 	return (ret < 0) ? ret : num;
 }
_


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

end of thread, other threads:[~2008-12-22 21:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-22 13:55 [PATCH] Fixed i2c-mpc driver for multi-master i2c busses Clifford Wolf
2008-12-22 21:01 ` Andrew Morton

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®