2aadecc357ffc4ff0c2cd2a1995768351393a134
[openwrt/openwrt.git] /
1 From: Russell King <rmk+kernel@armlinux.org.uk>
2 Bcc: linux@mail.armlinux.org.uk
3 Cc: linux-i2c@vger.kernel.org
4 Subject: [PATCH 12/17] i2c: pxa: fix i2c_pxa_wait_bus_not_busy() boundary
5 condition
6 MIME-Version: 1.0
7 Content-Disposition: inline
8 Content-Transfer-Encoding: 8bit
9 Content-Type: text/plain; charset="utf-8"
10
11 Fix i2c_pxa_wait_bus_not_busy()'s boundary conditions, so that a
12 coincidental success and timeout results in the function returning
13 success.
14
15 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
16 ---
17 drivers/i2c/busses/i2c-pxa.c | 17 ++++++++++++-----
18 1 file changed, 12 insertions(+), 5 deletions(-)
19
20 --- a/drivers/i2c/busses/i2c-pxa.c
21 +++ b/drivers/i2c/busses/i2c-pxa.c
22 @@ -417,19 +417,26 @@ static void i2c_pxa_abort(struct pxa_i2c
23 static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
24 {
25 int timeout = DEF_TIMEOUT;
26 + u32 isr;
27
28 - while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
29 - if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
30 + while (1) {
31 + isr = readl(_ISR(i2c));
32 + if (!(isr & (ISR_IBB | ISR_UB)))
33 + return 0;
34 +
35 + if (isr & ISR_SAD)
36 timeout += 4;
37
38 + if (!timeout--)
39 + break;
40 +
41 msleep(2);
42 show_state(i2c);
43 }
44
45 - if (timeout < 0)
46 - show_state(i2c);
47 + show_state(i2c);
48
49 - return timeout < 0 ? I2C_RETRY : 0;
50 + return I2C_RETRY;
51 }
52
53 static int i2c_pxa_wait_master(struct pxa_i2c *i2c)