63e6db80ad00b57d700c70a0822033e400b82aee
[openwrt/staging/mkresin.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 --- a/drivers/i2c/busses/i2c-pxa.c
27 +++ b/drivers/i2c/busses/i2c-pxa.c
28 @@ -91,6 +91,7 @@
29 */
30 #define DEF_TIMEOUT 32
31
32 +#define NO_SLAVE (-ENXIO)
33 #define BUS_ERROR (-EREMOTEIO)
34 #define XFER_NAKED (-ECONNREFUSED)
35 #define I2C_RETRY (-2000) /* an error has occurred retry transmit */
36 @@ -838,7 +839,7 @@ static void i2c_pxa_irq_txempty(struct p
37 */
38 if (isr & ISR_ACKNAK) {
39 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0)
40 - ret = I2C_RETRY;
41 + ret = NO_SLAVE;
42 else
43 ret = XFER_NAKED;
44 }
45 @@ -1066,16 +1067,19 @@ static int i2c_pxa_internal_xfer(struct
46 {
47 int ret, i;
48
49 - for (i = i2c->adap.retries; i >= 0; i--) {
50 + for (i = 0; ; ) {
51 ret = xfer(i2c, msgs, num);
52 - if (ret != I2C_RETRY)
53 + if (ret != I2C_RETRY && ret != NO_SLAVE)
54 goto out;
55 + if (++i >= i2c->adap.retries)
56 + break;
57
58 if (i2c_debug)
59 dev_dbg(&i2c->adap.dev, "Retrying transmission\n");
60 udelay(100);
61 }
62 - i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
63 + if (ret != NO_SLAVE)
64 + i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
65 ret = -EREMOTEIO;
66 out:
67 i2c_pxa_set_slave(i2c, ret);