Root/target/linux/cns3xxx/patches-3.3/440-i2c_retry.patch

1--- a/drivers/i2c/busses/i2c-cns3xxx.c
2+++ b/drivers/i2c/busses/i2c-cns3xxx.c
3@@ -2,8 +2,9 @@
4  * Cavium CNS3xxx I2C Host Controller
5  *
6  * Copyright 2010 Cavium Network
7- * Copyright 2011 Gateworks Corporation
8+ * Copyright 2012 Gateworks Corporation
9  * Chris Lang <clang@gateworks.com>
10+ * Tim Harvey <tharvey@gateworks.com>
11  *
12  * This file is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License, Version 2, as
14@@ -63,13 +64,15 @@
15 #define STATE_ERROR 2
16 
17 struct cns3xxx_i2c {
18- void __iomem *base;
19- wait_queue_head_t wait;
20- struct i2c_adapter adap;
21- struct i2c_msg *msg;
22- int state; /* see STATE_ */
23- int rd_wr_len;
24- u8 *buf;
25+ struct device *dev;
26+ void __iomem *base; /* virtual */
27+ wait_queue_head_t wait;
28+ struct i2c_adapter adap;
29+ struct i2c_msg *msg;
30+ u8 state; /* see STATE_ */
31+ u8 error; /* see TWI_STATUS register */
32+ int rd_wr_len;
33+ u8 *buf;
34 };
35 
36 static u32 cns3xxx_i2c_func(struct i2c_adapter *adap)
37@@ -150,14 +153,18 @@ cns3xxx_i2c_xfer_msg(struct i2c_adapter
38 
39         // Start the Transfer
40         i2c->state = 0; // Clear out the State
41+ i2c->error = 0;
42         I2C_CONTROLLER_REG |= (1 << 6);
43 
44         if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) ||
45                 (i2c->state == STATE_DONE), TWI_TIMEOUT)) {
46             if (i2c->state == STATE_ERROR) {
47- return -EIO;
48+ dev_dbg(i2c->dev, "controller error: 0x%2x", i2c->error);
49+ return -EAGAIN; // try again
50             }
51         } else {
52+ dev_err(i2c->dev, "controller timed out "
53+ "waiting for start condition to finish\n");
54             return -ETIMEDOUT;
55         }
56     }
57@@ -238,6 +245,7 @@ static irqreturn_t cns3xxx_i2c_isr(int i
58 
59     if (stat & I2C_BUS_ERROR_FLAG) {
60         i2c->state = STATE_ERROR;
61+ i2c->error = (I2C_INTERRUPT_STATUS_REG & 0xff00)>>8;
62     } else {
63         if (i2c->msg->flags & I2C_M_RD) {
64             for (i = 0; i <= i2c->rd_wr_len; i++)
65@@ -280,6 +288,7 @@ static int __devinit cns3xxx_i2c_probe(s
66         goto request_mem_failed;
67     }
68 
69+ i2c->dev = &pdev->dev;
70     i2c->base = ioremap(res->start, res->end - res->start + 1);
71     if (!i2c->base) {
72         dev_err(&pdev->dev, "Unable to map registers\n");
73

Archive Download this file



interactive