From 4ff299e29da884c055c23044e307c523fd198b60 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 6 Jun 2013 09:42:44 -0700 Subject: [PATCH] Send STOP to clear bus when I2C encounters an error. Reading from a nonexistant/nonresponsive smart battery fails (as it should). But then it leaves the i2c clock line low, so that subsequent i2cscan commands fail too. This change just sends a STOP to clear the bus when an i2c error occurs. BUG=chromium:247037 BRANCH=none TEST=none Change-Id: I599bed7149ed3dd3748f1a939c2ea8fdf65e3d72 Signed-off-by: Bill Richardson Reviewed-on: https://gerrit.chromium.org/gerrit/57808 Reviewed-by: Randall Spangler --- chip/lm4/i2c.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c index 12b53c2aa8..6b43eb4a29 100644 --- a/chip/lm4/i2c.c +++ b/chip/lm4/i2c.c @@ -157,8 +157,10 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, LM4_I2C_MCS(port) = reg_mcs; rv = wait_idle(port); - if (rv) + if (rv) { + LM4_I2C_MCS(port) = LM4_I2C_MCS_STOP; return rv; + } } } @@ -189,8 +191,10 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, LM4_I2C_MCS(port) = reg_mcs; rv = wait_idle(port); - if (rv) + if (rv) { + LM4_I2C_MCS(port) = LM4_I2C_MCS_STOP; return rv; + } in[i] = LM4_I2C_MDR(port) & 0xff; } } @@ -401,6 +405,7 @@ static int command_i2cread(int argc, char **argv) LM4_I2C_MCS(port) = (i == count - 1 ? 0x05 : 0x09); rv = wait_idle(port); if (rv != EC_SUCCESS) { + LM4_I2C_MCS(port) = LM4_I2C_MCS_STOP; i2c_lock(port, 0); return rv; }