summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorZhuohao Lee <zhuohao@chromium.org>2018-08-06 10:51:35 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-08-07 01:50:38 -0700
commitb3ff32c510e8842d9ee043d9c9b09a1efb60f9db (patch)
tree61c2b92bd9a535daa832f458adbcb77aed327910 /common
parent30b09cea62d5dab06301223020140788dbe6e4de (diff)
downloadchrome-ec-b3ff32c510e8842d9ee043d9c9b09a1efb60f9db.tar.gz
cbi: lock the i2c port before using it
i2c bus is the share resource. We need to lock the port before using it. Otherwise, it will break the other who is using the i2c bus. BUG=b:78538360 BRANCH=master TEST=Use command `ectool cbi get 0 1` without error Change-Id: I0adde0b0e912420813cfdec444ae8e531d90042f Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1163542 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/cbi.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/cbi.c b/common/cbi.c
index 0b6704a6a3..231ee18e13 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -72,8 +72,14 @@ static struct cbi_header * const head = (struct cbi_header *)cbi;
static int read_eeprom(uint8_t offset, uint8_t *in, int in_size)
{
- return i2c_xfer(I2C_PORT_EEPROM, I2C_ADDR_EEPROM,
+ int ret;
+
+ i2c_lock(I2C_PORT_EEPROM, 1);
+ ret = i2c_xfer(I2C_PORT_EEPROM, I2C_ADDR_EEPROM,
&offset, 1, in, in_size, I2C_XFER_SINGLE);
+ i2c_lock(I2C_PORT_EEPROM, 0);
+
+ return ret;
}
/*
@@ -208,8 +214,10 @@ static int write_board_info(void)
int rv;
rest -= size;
memcpy(&buf[1], p, size);
+ i2c_lock(I2C_PORT_EEPROM, 1);
rv = i2c_xfer(I2C_PORT_EEPROM, I2C_ADDR_EEPROM, buf, size + 1,
NULL, 0, I2C_XFER_SINGLE);
+ i2c_lock(I2C_PORT_EEPROM, 0);
if (rv) {
CPRINTS("Failed to write for %d", rv);
return rv;