i2c: davinci: Refactor i2c_davinci_wait_bus_not_busy()
There are several problems in the function: - "to_cnt" variable does nothing - schedule_timeout() call without setting current state does nothing - "allow_sleep" parameter is not really used Refactor the function so that it really tries to wait. In case of timeout try to recover the bus. Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
dd1aa2524b
commit
72a956c556
|
@ -350,29 +350,25 @@ static struct i2c_bus_recovery_info davinci_i2c_scl_recovery_info = {
|
||||||
/*
|
/*
|
||||||
* Waiting for bus not busy
|
* Waiting for bus not busy
|
||||||
*/
|
*/
|
||||||
static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
|
static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev)
|
||||||
char allow_sleep)
|
|
||||||
{
|
{
|
||||||
unsigned long timeout;
|
unsigned long timeout = jiffies + dev->adapter.timeout;
|
||||||
static u16 to_cnt;
|
|
||||||
|
|
||||||
timeout = jiffies + dev->adapter.timeout;
|
do {
|
||||||
while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
|
if (!(davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) & DAVINCI_I2C_STR_BB))
|
||||||
& DAVINCI_I2C_STR_BB) {
|
return 0;
|
||||||
if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
|
schedule_timeout_uninterruptible(1);
|
||||||
if (time_after(jiffies, timeout)) {
|
} while (time_before_eq(jiffies, timeout));
|
||||||
dev_warn(dev->dev,
|
|
||||||
"timeout waiting for bus ready\n");
|
dev_warn(dev->dev, "timeout waiting for bus ready\n");
|
||||||
to_cnt++;
|
i2c_recover_bus(&dev->adapter);
|
||||||
return -ETIMEDOUT;
|
|
||||||
} else {
|
/*
|
||||||
to_cnt = 0;
|
* if bus is still "busy" here, it's most probably a HW problem like
|
||||||
i2c_recover_bus(&dev->adapter);
|
* short-circuit
|
||||||
}
|
*/
|
||||||
}
|
if (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) & DAVINCI_I2C_STR_BB)
|
||||||
if (allow_sleep)
|
return -EIO;
|
||||||
schedule_timeout(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -505,7 +501,7 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
||||||
|
|
||||||
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
|
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
|
||||||
|
|
||||||
ret = i2c_davinci_wait_bus_not_busy(dev, 1);
|
ret = i2c_davinci_wait_bus_not_busy(dev);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_warn(dev->dev, "timeout waiting for bus ready\n");
|
dev_warn(dev->dev, "timeout waiting for bus ready\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue