i2c-eg20t: Fix bus-idle waiting issue
authorTomoya MORINAGA <tomoya-linux@dsn.lapis-semi.com>
Wed, 12 Oct 2011 04:13:00 +0000 (13:13 +0900)
committerBen Dooks <ben-linux@fluff.org>
Sat, 29 Oct 2011 10:09:32 +0000 (11:09 +0100)
Currently, when checking whether bus is idle or not,
if timeout occurs,
this function always returns success(zero).
This patch fixes the issue.

Signed-off-by: Tomoya MORINAGA <tomoya-linux@dsn.lapis-semi.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
drivers/i2c/busses/i2c-eg20t.c

index ce1a32b71e47499fa70292dff187dc8124c3d15a..a4f76cb76c46c311704ab7299a93f176e88e726d 100644 (file)
@@ -273,23 +273,23 @@ static s32 pch_i2c_wait_for_bus_idle(struct i2c_algo_pch_data *adap,
                                     s32 timeout)
 {
        void __iomem *p = adap->pch_base_address;
+       ktime_t ns_val;
+
+       if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
+               return 0;
 
        /* MAX timeout value is timeout*1000*1000nsec */
-       ktime_t ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000);
+       ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000);
        do {
-               if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
-                       break;
                msleep(20);
+               if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
+                       return 0;
        } while (ktime_lt(ktime_get(), ns_val));
 
        pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR));
+       pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME);
 
-       if (timeout == 0) {
-               pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME);
-               return -ETIME;
-       }
-
-       return 0;
+       return -ETIME;
 }
 
 /**