diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-05-16 12:12:08 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-06-06 17:59:21 -0700 |
commit | 1cb4329139b988153f8c20e69c23ba8214257c79 (patch) | |
tree | efd155e5df8f4b2df6fe5e337604184de76a1ef1 /common/peripheral.c | |
parent | 4e6d315948367c53116e428828eac19dfbdfb429 (diff) | |
download | chrome-ec-1cb4329139b988153f8c20e69c23ba8214257c79.tar.gz |
common: Add EC_CMD_LOCATE_CHIP
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>
Diffstat (limited to 'common/peripheral.c')
-rw-r--r-- | common/peripheral.c | 55 |
1 files changed, 55 insertions, 0 deletions
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 */ |