From 5ca252d4ef2511b9233f1f42efc9ceda5afe5aec Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Fri, 21 Aug 2015 10:46:00 -0700 Subject: i2c: Fix SCL unwedge logic The current logic breaks out of the for() loop if SCL gets unwedged (goes high), but still falls through to the "I2C unwedge failed, SCL is being held low" case. Fix this so that we only hit the "SCL is being held low" case if SCL actually is stuck low. BUG=none BRANCH=None TEST=compile-test only, on samus Change-Id: I39df1966dc25517ee03a56109e7d0b740c5ca12b Signed-off-by: Kevin Cernekee Reviewed-on: https://chromium-review.googlesource.com/295043 Reviewed-by: Randall Spangler --- common/i2c.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/common/i2c.c b/common/i2c.c index 3f9b586bb4..24f0d95354 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -391,19 +391,20 @@ int i2c_unwedge(int port) * by a slave. */ if (!i2c_raw_get_scl(port)) { - for (i = 0; i < UNWEDGE_SCL_ATTEMPTS; i++) { + for (i = 0;; i++) { + if (i >= UNWEDGE_SCL_ATTEMPTS) { + /* + * If we get here, a slave is holding the clock + * low and there is nothing we can do. + */ + CPRINTS("I2C unwedge failed, SCL is being held low"); + ret = EC_ERROR_UNKNOWN; + goto unwedge_done; + } udelay(I2C_BITBANG_DELAY_US); if (i2c_raw_get_scl(port)) break; } - - /* - * If we get here, a slave is holding the clock low and there - * is nothing we can do. - */ - CPRINTS("I2C unwedge failed, SCL is being held low"); - ret = EC_ERROR_UNKNOWN; - goto unwedge_done; } if (i2c_raw_get_sda(port)) -- cgit v1.2.1