[PATCH] Fixed i2c-mpc driver for multi-master i2c busses.

From: Clifford Wolf
Date: Mon Dec 22 2008 - 09:39:10 EST


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@xxxxxxxxxxx>

--- ./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;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/