Skip to content

Commit

Permalink
i2c: sh_mobile: improve error handling
Browse files Browse the repository at this point in the history
Use standard i2c error codes for i2c failures. Also, don't print
something on timeout since it happens regularly with i2c. Simplify some,
logic, too.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Wolfram Sang authored and Wolfram Sang committed May 22, 2014
1 parent a78f6a4 commit 5a72b25
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions drivers/i2c/busses/i2c-sh_mobile.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
{
if (usr_msg->len == 0 && (usr_msg->flags & I2C_M_RD)) {
dev_err(pd->dev, "Unsupported zero length i2c read\n");
return -EIO;
return -EOPNOTSUPP;
}

if (do_init) {
Expand Down Expand Up @@ -515,17 +515,12 @@ static int poll_dte(struct sh_mobile_i2c_data *pd)
break;

if (val & ICSR_TACK)
return -EIO;
return -ENXIO;

udelay(10);
}

if (!i) {
dev_warn(pd->dev, "Timeout polling for DTE!\n");
return -ETIMEDOUT;
}

return 0;
return i ? 0 : -ETIMEDOUT;
}

static int poll_busy(struct sh_mobile_i2c_data *pd)
Expand All @@ -543,20 +538,18 @@ static int poll_busy(struct sh_mobile_i2c_data *pd)
*/
if (!(val & ICSR_BUSY)) {
/* handle missing acknowledge and arbitration lost */
if ((val | pd->sr) & (ICSR_TACK | ICSR_AL))
return -EIO;
val |= pd->sr;
if (val & ICSR_TACK)
return -ENXIO;
if (val & ICSR_AL)
return -EAGAIN;
break;
}

udelay(10);
}

if (!i) {
dev_err(pd->dev, "Polling timed out\n");
return -ETIMEDOUT;
}

return 0;
return i ? 0 : -ETIMEDOUT;
}

static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
Expand Down

0 comments on commit 5a72b25

Please sign in to comment.