From 0237cc790983b9fa4159963ec6ee2feab5a7f512 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Wed, 8 May 2019 07:34:00 -0600 Subject: i2c: add i2clookup host command Add a new host command that will allow you to lookup a well known device on the EC. This is useful for FAFT tests that want to talk directly with i2c devices but don't know the physical address for each platform. BRANCH=octopus BUG=b:119065537 TEST=Used this with new faft test in CL:1601300 Change-Id: I82c2d5462fcb4edbc92ea60765971190fed7ae81 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/1601060 Reviewed-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1767514 Reviewed-by: Edward Hill Commit-Queue: Edward Hill Tested-by: Edward Hill --- common/i2c_master.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'common') diff --git a/common/i2c_master.c b/common/i2c_master.c index bda3561d34..afa40254d5 100644 --- a/common/i2c_master.c +++ b/common/i2c_master.c @@ -852,6 +852,34 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_I2C_PASSTHRU, i2c_command_passthru, EC_VER_MASK(0)); +static int i2c_command_lookup(struct host_cmd_handler_args *args) +{ + const struct ec_params_i2c_lookup *params = args->params; + struct ec_response_i2c_lookup *resp = args->response; + + switch (params->type) { + case I2C_LOOKUP_TYPE_CBI_EEPROM: +#ifdef CONFIG_CROS_BOARD_INFO + resp->i2c_port = I2C_PORT_EEPROM; + /* Convert from 8-bit address to 7-bit address */ + resp->i2c_addr = I2C_ADDR_EEPROM >> 1; +#else + /* Lookup type is supported, but not present on system. */ + return EC_RES_UNAVAILABLE; +#endif /* CONFIG_CROS_BOARD_INFO */ + break; + default: + /* The type was unrecognized */ + return EC_RES_INVALID_PARAM; + } + + args->response_size = sizeof(*resp); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_I2C_LOOKUP, i2c_command_lookup, EC_VER_MASK(0)); +/* If the params union expands in the future, need to bump EC_VER_MASK */ +BUILD_ASSERT(sizeof(struct ec_params_i2c_lookup) == 4); + void i2c_passthru_protect_port(uint32_t port) { if (port < I2C_PORT_COUNT) -- cgit v1.2.1