From 526cc1e4edacf23450380c5e3469576ade196acc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 8 Mar 2018 11:00:39 -0700 Subject: i2c: npcx: Check that unwedging succeeds If the I2C port is completely broken then there is no point in trying to continue with the transaction. This can happen if the pull-ups on the bus are not working because they are in a power domain which is not currently enabled. Check the return value from i2c_unwedge() and return if it doesn't work. Tidy up a few comments at the same time. BUG=b:72129419 BRANCH=none TEST=manually remove the check AP being off in sb_tsi_get_val() and see that it quickly fails now, rather than hanging the EC for a while trying the transaction. Change-Id: I66ab52943459726537dfc74355f8aeaa5817dba5 Signed-off-by: Simon Glass Reviewed-on: https://chromium-review.googlesource.com/956017 Reviewed-by: Edward Hill Reviewed-by: Aaron Durbin --- chip/npcx/i2c.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'chip/npcx') diff --git a/chip/npcx/i2c.c b/chip/npcx/i2c.c index bccdb3c084..16c85d4439 100644 --- a/chip/npcx/i2c.c +++ b/chip/npcx/i2c.c @@ -652,11 +652,14 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, p_status->oper_state != SMB_WRITE_SUSPEND && (i2c_bus_busy(ctrl) || (i2c_get_line_levels(port) != I2C_LINE_IDLE))) { + int ret; - /* Attempt to unwedge the i2c port. */ - i2c_unwedge(port); + /* Attempt to unwedge the i2c port */ + ret = i2c_unwedge(port); + if (ret) + return ret; p_status->err_code = SMB_BUS_BUSY; - /* recovery i2c controller */ + /* recover i2c controller */ i2c_recovery(ctrl, p_status); /* Select port again for recovery */ i2c_select_port(port); -- cgit v1.2.1