summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-07-23 10:50:13 -0600
committerCommit Bot <commit-bot@chromium.org>2019-08-23 00:12:34 +0000
commitca5e6e59e03ec0da364832e567a488f28342ac15 (patch)
tree628019a8d29f74cad95b295686ee4d76775793b3
parent025d2bdcd4d9f742956ac538200a2ac9deb3f410 (diff)
downloadchrome-ec-ca5e6e59e03ec0da364832e567a488f28342ac15.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> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1767530 Reviewed-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org> Tested-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--chip/ish/i2c.c5
-rw-r--r--common/i2c_master.c9
-rw-r--r--include/i2c.h10
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 dcc9d12b83..c6d9d3db25 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 2cccc840c2..f1868dc8c8 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.
*/