summaryrefslogtreecommitdiff
path: root/util/comm-host.c
diff options
context:
space:
mode:
authorHarry Cutts <hcutts@chromium.org>2019-09-25 11:20:20 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-04 06:59:27 +0000
commit5f7e4c337dae601208f308efba15ad6d9ffbe788 (patch)
treedd88337d1ede373e381fad8c6c0df91634871890 /util/comm-host.c
parent2ee2d6fe8711f51343bb08e0fde599c2643c93e6 (diff)
downloadchrome-ec-5f7e4c337dae601208f308efba15ad6d9ffbe788.tar.gz
util/comm-i2c: Add switch to specify I2C bus
Currently, devices running CrOS EC that aren't actually the embedded controller (such as touchpad or fingerprint MCUs) can only be contacted over I2C if they are in the device tree. To avoid having to recompile the Kernel, Coreboot, or `ectool`, the `--i2c_bus` switch allows `ectool` to be used for testing as-is. BRANCH=none BUG=none TEST=Checked various commands (hello, version, inventory...) with `--i2c_bus=7`, connecting to a MAX32660. Verified that a contradictory `--interface` switch is rejected. Checked that invalid bus numbers (≥32) are rejected. Change-Id: I92f3307bbbdf88978b9f8271610a3ae222279767 Signed-off-by: Harry Cutts <hcutts@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1828064 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'util/comm-host.c')
-rw-r--r--util/comm-host.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/util/comm-host.c b/util/comm-host.c
index 947b240bfa..dd42df1aa8 100644
--- a/util/comm-host.c
+++ b/util/comm-host.c
@@ -4,6 +4,7 @@
*/
#include <errno.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -31,7 +32,7 @@ static int command_offset;
int comm_init_dev(const char *device_name) __attribute__((weak));
int comm_init_lpc(void) __attribute__((weak));
-int comm_init_i2c(void) __attribute__((weak));
+int comm_init_i2c(int i2c_bus) __attribute__((weak));
int comm_init_servo_spi(const char *device_name) __attribute__((weak));
static int fake_readmem(int offset, int bytes, void *dest)
@@ -82,8 +83,10 @@ int ec_command(int command, int version,
indata, insize);
}
-int comm_init_alt(int interfaces, const char *device_name)
+int comm_init_alt(int interfaces, const char *device_name, int i2c_bus)
{
+ bool dev_is_cros_ec;
+
/* Default memmap access */
ec_readmem = fake_readmem;
@@ -93,17 +96,17 @@ int comm_init_alt(int interfaces, const char *device_name)
/* Do not fallback to other communication methods if target is not a
* cros_ec device */
- if (!strcmp(CROS_EC_DEV_NAME, device_name)) {
- /* Fallback to direct LPC on x86 */
- if ((interfaces & COMM_LPC) &&
- comm_init_lpc && !comm_init_lpc())
- return 0;
-
- /* Fallback to direct i2c on ARM */
- if ((interfaces & COMM_I2C) &&
- comm_init_i2c && !comm_init_i2c())
- return 0;
- }
+ dev_is_cros_ec = !strcmp(CROS_EC_DEV_NAME, device_name);
+
+ /* Fallback to direct LPC on x86 */
+ if (dev_is_cros_ec && (interfaces & COMM_LPC) &&
+ comm_init_lpc && !comm_init_lpc())
+ return 0;
+
+ /* Fallback to direct I2C */
+ if ((dev_is_cros_ec || i2c_bus != -1) && (interfaces & COMM_I2C) &&
+ comm_init_i2c && !comm_init_i2c(i2c_bus))
+ return 0;
/* Give up */
fprintf(stderr, "Unable to establish host communication\n");