308dba0fb9aefb88a712a53194ef2e99c89371a3
[openwrt/staging/luka.git] /
1 From: Russell King <rmk+kernel@armlinux.org.uk>
2 Bcc: linux@mail.armlinux.org.uk
3 Subject: [PATCH 2/7] i2c: pxa: avoid complaints with non-responsive slaves
4 MIME-Version: 1.0
5 Content-Disposition: inline
6 Content-Transfer-Encoding: 8bit
7 Content-Type: text/plain; charset="utf-8"
8
9 Running i2cdetect on a PXA I2C adapter is very noisy; it complains
10 whenever a slave fails to respond to the address cycle. Since it is
11 normal to probe for slaves in this way, we should not fill the kernel
12 log. This is especially true with SFP modules that take a while to
13 respond on the I2C bus, and probing via the I2C bus is the only way to
14 detect that they are ready.
15
16 Fix this by changing the internal transfer return code from I2C_RETRY
17 to a new NO_SLAVE code (mapped to -ENXIO, as per the I2C documentation
18 for this condition, but we still return -EREMOTEIO to the I2C stack to
19 maintain long established driver behaviour.)
20
21 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
22 ---
23 drivers/i2c/busses/i2c-pxa.c | 12 ++++++++----
24 1 file changed, 8 insertions(+), 4 deletions(-)
25
26 diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
27 index 46f1cf97d955..f20f8b905793 100644
28 --- a/drivers/i2c/busses/i2c-pxa.c
29 +++ b/drivers/i2c/busses/i2c-pxa.c
30 @@ -90,6 +90,7 @@
31 */
32 #define DEF_TIMEOUT 32
33
34 +#define NO_SLAVE (-ENXIO)
35 #define BUS_ERROR (-EREMOTEIO)
36 #define XFER_NAKED (-ECONNREFUSED)
37 #define I2C_RETRY (-2000) /* an error has occurred retry transmit */
38 @@ -881,7 +882,7 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
39 */
40 if (isr & ISR_ACKNAK) {
41 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0)
42 - ret = I2C_RETRY;
43 + ret = NO_SLAVE;
44 else
45 ret = XFER_NAKED;
46 }
47 @@ -1109,16 +1110,19 @@ static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c,
48 {
49 int ret, i;
50
51 - for (i = i2c->adap.retries; i >= 0; i--) {
52 + for (i = 0; ; ) {
53 ret = xfer(i2c, msgs, num);
54 - if (ret != I2C_RETRY)
55 + if (ret != I2C_RETRY && ret != NO_SLAVE)
56 goto out;
57 + if (++i >= i2c->adap.retries)
58 + break;
59
60 if (i2c_debug)
61 dev_dbg(&i2c->adap.dev, "Retrying transmission\n");
62 udelay(100);
63 }
64 - i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
65 + if (ret != NO_SLAVE)
66 + i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
67 ret = -EREMOTEIO;
68 out:
69 i2c_pxa_set_slave(i2c, ret);
70 --
71 2.20.1
72