diff options
author | Jett Rink <jettrink@chromium.org> | 2019-07-23 10:50:13 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-25 16:50:42 +0000 |
commit | 286e3b9033c551f5fe24fe8c41de17b35bf27c81 (patch) | |
tree | 3f27651b0f4c440c3715b76aa2535b24089ff6c0 | |
parent | 7e0885d97099d8c3e51913103d442fec6a31fb4c (diff) | |
download | chrome-ec-286e3b9033c551f5fe24fe8c41de17b35bf27c81.tar.gz |
i2c: don't scan i2c addresses less than 0x08
None of the existing i2c addresses in the EC code base are less than 0x08
and those addresses are reserved by the i2c and SMBus specification.
BRANCH=none
BUG=b:138156666
TEST=i2c bus scan with a smart battery doesn't "misbehave" any more and
other devices can be detected properly.
Change-Id: I561b082c4c7e3df7caaa33b6ef6ad467dabbd5a5
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1715326
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | chip/ish/i2c.c | 5 | ||||
-rw-r--r-- | common/i2c_master.c | 9 | ||||
-rw-r--r-- | include/i2c.h | 10 |
3 files changed, 19 insertions, 5 deletions
diff --git a/chip/ish/i2c.c b/chip/ish/i2c.c index 405e63935e..b4cc32f0ad 100644 --- a/chip/ish/i2c.c +++ b/chip/ish/i2c.c @@ -306,10 +306,9 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags, return EC_ERROR_INVAL; /* Check for reserved I2C addresses, pg. 74 in DW_apb_i2c.pdf - * Address cannot be any of the reserved address locations: - * 0x00 to 0x07 or 0x78 to 0x7f. + * Address cannot be any of the reserved address locations */ - if (addr <= 0x07 || (addr >= 0x78 && addr <= 0x7F)) + if (addr < I2C_FIRST_VALID_ADDR || addr > I2C_LAST_VALID_ADDR) return EC_ERROR_INVAL; /* assume that if both out_size and in_size are not zero, diff --git a/common/i2c_master.c b/common/i2c_master.c index 5975570fdb..d5eeaab04b 100644 --- a/common/i2c_master.c +++ b/common/i2c_master.c @@ -1029,8 +1029,13 @@ static void scan_bus(int port, const char *desc) (level & I2C_LINE_SCL_HIGH) ? 1 : 0); goto scan_bus_exit; } - - for (addr_flags = 0; addr_flags <= 0xEF; ++addr_flags) { + /* + * Only scan in the valid client device address range, otherwise some + * client devices stretch the clock in weird ways that prevent the + * discovery of other devices. + */ + for (addr_flags = I2C_FIRST_VALID_ADDR; + addr_flags <= I2C_LAST_VALID_ADDR; ++addr_flags) { watchdog_reload(); /* Otherwise a full scan trips watchdog */ ccputs("."); diff --git a/include/i2c.h b/include/i2c.h index ccb65fc7a0..ed041b2876 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -43,6 +43,16 @@ #define I2C_IS_BIG_ENDIAN(addr_flags) ((addr_flags) & I2C_FLAG_BIG_ENDIAN) /* + * All 7-bit addresses in the following formats + * 0000 XXX + * 1111 XXX + * are reserved for various purposes. Valid 7-bit client adderesses start at + * 0x08 and end at 0x77 inclusive. + */ +#define I2C_FIRST_VALID_ADDR 0x08 +#define I2C_LAST_VALID_ADDR 0x77 + +/* * Max data size for a version 3 request/response packet. This is * big enough for EC_CMD_GET_VERSION plus header info. */ |