summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2018-08-19 17:14:29 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-08-22 00:10:38 -0700
commitfe16ade3ea5dfdd01cf466a9a6bff76d8fa17f11 (patch)
treef8dde4ea45bb74f588ea111b6094a0e2a8c0e14f
parentaf908bfce225415c01d56b3f57cfc399d8485d3e (diff)
downloadchrome-ec-fe16ade3ea5dfdd01cf466a9a6bff76d8fa17f11.tar.gz
i2c: Don't try to unwedge unpowered busses.
If an i2c bus is known to be unpowered, we should not spend time trying to unwedge it. It's futile, so stop trying. This commit adds a config option, CONFIG_I2C_BUS_MAY_BE_UNPOWERED which can be defined by a board if a bus may be unpowered during runtime. BUG=b:111683988 BRANCH=nocturne TEST=Verify that unwedge attempts are skipped if the bus is deemed unpowered. Change-Id: Ice12b3957121be476ef0173a86f239f183010b47 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/1182877 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Alexandru M Stan <amstan@chromium.org>
-rw-r--r--common/i2c_master.c10
-rw-r--r--include/config.h9
-rw-r--r--include/i2c.h10
3 files changed, 29 insertions, 0 deletions
diff --git a/common/i2c_master.c b/common/i2c_master.c
index e02a479aeb..fb967afd0f 100644
--- a/common/i2c_master.c
+++ b/common/i2c_master.c
@@ -491,6 +491,16 @@ int i2c_unwedge(int port)
int i, j;
int ret = EC_SUCCESS;
+#ifdef CONFIG_I2C_BUS_MAY_BE_UNPOWERED
+ /*
+ * Don't try to unwedge the port if we know it's unpowered; it's futile.
+ */
+ if (!board_is_i2c_port_powered(port)) {
+ CPRINTS("Skipping i2c unwedge, bus not powered.");
+ return EC_ERROR_NOT_POWERED;
+ }
+#endif /* CONFIG_I2C_BUS_MAY_BE_UNPOWERED */
+
/* Try to put port in to raw bit bang mode. */
if (i2c_raw_mode(port, 1) != EC_SUCCESS)
return EC_ERROR_UNKNOWN;
diff --git a/include/config.h b/include/config.h
index a5c17ad9b5..84f3b0ad65 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1857,6 +1857,15 @@
#undef CONFIG_I2C_VIRTUAL_BATTERY
/*
+ * Define this option if an i2c bus may be unpowered at a certain point during
+ * runtime. An example could be, a sensor bus which is not needed in lower
+ * power states so the power rail for those sensors is completely disabled.
+ *
+ * If defined, your board must provide a board_is_i2c_port_powered() function.
+ */
+#undef CONFIG_I2C_BUS_MAY_BE_UNPOWERED
+
+/*
* Conservative I2C reading size per single transaction. For example, register
* of stm32f0 and stm32l4 are limited to be 8 bits for this field.
*/
diff --git a/include/i2c.h b/include/i2c.h
index 8ae21566cb..1dcfe46332 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -361,6 +361,16 @@ void i2cm_init(void);
int board_allow_i2c_passthru(int port);
/**
+ * Board level function that can indicate if a particular i2c bus is known to be
+ * currently powered or not.
+ *
+ * @param port: I2C port number
+ *
+ * @return non-zero if powered, 0 if the bus is not powered.
+ */
+int board_is_i2c_port_powered(int port);
+
+/**
* Function to allow board to take any action before starting a new i2c
* transaction on a given port. Board must implement this if it defines
* CONFIG_I2C_XFER_BOARD_CALLBACK.