summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Cernekee <cernekee@chromium.org>2015-08-21 10:46:00 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-22 01:37:45 +0000
commit5ca252d4ef2511b9233f1f42efc9ceda5afe5aec (patch)
treedb75bc16093614ca8863878b2b4b0c5d37cbf47f
parentad8ce3f806961e2c4548c2f552b7f94adf0fd4b5 (diff)
downloadchrome-ec-5ca252d4ef2511b9233f1f42efc9ceda5afe5aec.tar.gz
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 <cernekee@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/295043 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/i2c.c19
1 files 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))