diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-05-16 12:12:08 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-11 15:19:36 +0000 |
commit | 9fc96c25f373ffee3a496fd24a6e1470dce466bb (patch) | |
tree | f17c674e54c6b645f559a477e51581bb7f17c655 /common | |
parent | 1be23dd331673e5d5d8390b309f2e86eccff46a6 (diff) | |
download | chrome-ec-firmware-octopus-11297.81.B.tar.gz |
common: Add EC_CMD_LOCATE_CHIPfirmware-octopus-11297.81.B
This patch replaces EC_CMD_I2C_LOOKUP with EC_CMD_LOCATE_CHIP.
This is a more generic command which locates a peripheral chip in
i2c or other bus types.
Additionally, it includes the following changes:
- Change chip (device) type # of CBI_EEPROM (from 1 to 0).
- Support TCPCs.
localhost ~ # ectool locatechip 0 0
BUS: I2C; Port: 0; Address: 0x50 (7-bit format)
localhost ~ # ectool locatechip 1 0
BUS: I2C; Port: 0; Address: 0x0b (7-bit format)
localhost ~ # ectool locatechip 1 1
BUS: I2C; Port: 1; Address: 0x29 (7-bit format)
localhost ~ # ectool locatechip 1 2
EC result 11 (OVERFLOW)
Index too large
localhost ~ # ectool locatechip 2
Usage: locatechip <type> <index>
<type> is one of:
0: CBI_EEPROM
1: TCPCs
<index> instance # of <type>
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=none
BRANCH=none
TEST=Verified ectool locatechip work on Nami.
Change-Id: I1a773ced65b1c5ce3656f03eff04a6eadd4bc5ff
Reviewed-on: https://chromium-review.googlesource.com/1614582
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
(cherry picked from commit 1cb4329139b988153f8c20e69c23ba8214257c79)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1652284
Tested-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/i2c_master.c | 28 | ||||
-rw-r--r-- | common/peripheral.c | 55 |
3 files changed, 56 insertions, 29 deletions
diff --git a/common/build.mk b/common/build.mk index 3b25e0bc99..c735080850 100644 --- a/common/build.mk +++ b/common/build.mk @@ -43,7 +43,7 @@ common-$(CONFIG_CHARGER_V2)+=charge_state_v2.o common-$(CONFIG_CMD_I2CWEDGE)+=i2c_wedge.o common-$(CONFIG_COMMON_GPIO)+=gpio.o gpio_commands.o common-$(CONFIG_COMMON_PANIC_OUTPUT)+=panic_output.o -common-$(CONFIG_COMMON_RUNTIME)+=hooks.o main.o system.o +common-$(CONFIG_COMMON_RUNTIME)+=hooks.o main.o system.o peripheral.o common-$(CONFIG_COMMON_TIMER)+=timer.o common-$(CONFIG_CRC8)+= crc8.o common-$(CONFIG_CURVE25519)+=curve25519.o diff --git a/common/i2c_master.c b/common/i2c_master.c index 591afff579..fb6ed6c4c0 100644 --- a/common/i2c_master.c +++ b/common/i2c_master.c @@ -762,34 +762,6 @@ 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); - static void i2c_passthru_protect_port(uint32_t port) { if (port < I2C_PORT_COUNT) diff --git a/common/peripheral.c b/common/peripheral.c new file mode 100644 index 0000000000..103a32206e --- /dev/null +++ b/common/peripheral.c @@ -0,0 +1,55 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "common.h" +#include "compile_time_macros.h" +#include "ec_commands.h" +#include "host_command.h" +#include "usb_pd_tcpm.h" + +#ifdef CONFIG_HOSTCMD_LOCATE_CHIP +static int hc_locate_chip(struct host_cmd_handler_args *args) +{ + const struct ec_params_locate_chip *params = args->params; + struct ec_response_locate_chip *resp = args->response; + + switch (params->type) { + case EC_CHIP_TYPE_CBI_EEPROM: +#ifdef CONFIG_CROS_BOARD_INFO + if (params->index >= 1) + return EC_RES_OVERFLOW; + resp->bus_type = EC_BUS_TYPE_I2C; + resp->i2c_info.port = I2C_PORT_EEPROM; + /* Convert from 8-bit address to 7-bit address */ + resp->i2c_info.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; + case EC_CHIP_TYPE_TCPC: +#if defined(CONFIG_USB_PD_PORT_COUNT) && !defined(CONFIG_USB_PD_TCPC) + if (params->index >= CONFIG_USB_PD_PORT_COUNT) + return EC_RES_OVERFLOW; + resp->bus_type = EC_BUS_TYPE_I2C; + resp->i2c_info.port = tcpc_config[params->index].i2c_host_port; + resp->i2c_info.addr = + tcpc_config[params->index].i2c_slave_addr >> 1; +#else + return EC_RES_UNAVAILABLE; +#endif /* CONFIG_USB_PD_PORT_COUNT */ + 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_LOCATE_CHIP, hc_locate_chip, EC_VER_MASK(0)); +/* If the params union expands in the future, need to bump EC_VER_MASK */ +BUILD_ASSERT(sizeof(struct ec_params_locate_chip) == 4); +#endif /* CONFIG_HOSTCMD_LOCATE_CHIP */ |