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 | |
parent | 1be23dd331673e5d5d8390b309f2e86eccff46a6 (diff) | |
download | chrome-ec-9fc96c25f373ffee3a496fd24a6e1470dce466bb.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>
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/i2c_master.c | 28 | ||||
-rw-r--r-- | common/peripheral.c | 55 | ||||
-rw-r--r-- | include/config.h | 5 | ||||
-rw-r--r-- | include/ec_commands.h | 47 | ||||
-rw-r--r-- | util/ectool.c | 58 |
6 files changed, 134 insertions, 61 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 */ diff --git a/include/config.h b/include/config.h index b0adce15d9..4dd4ef4e82 100644 --- a/include/config.h +++ b/include/config.h @@ -1903,6 +1903,11 @@ /* Command to issue AP reset */ #undef CONFIG_HOSTCMD_AP_RESET +#if !defined(TEST_BUILD) && !defined(TEST_FUZZ) +/* Enable EC_CMD_LOCATE_CHIP */ +#define CONFIG_HOSTCMD_LOCATE_CHIP +#endif + /* List of host commands whose debug output will be suppressed */ #undef CONFIG_SUPPRESSED_HOST_COMMANDS diff --git a/include/ec_commands.h b/include/ec_commands.h index 83de527fb0..ab5d193719 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -5176,33 +5176,50 @@ struct ec_response_rollback_info { #define EC_CMD_AP_RESET 0x0125 /*****************************************************************************/ -/* I2C lookup command +/* Locate peripheral chips * * Return values: - * EC_RES_UNAVAILABLE: Lookup type is supported but not present on system. - * EC_RES_INVALID_PARAM: The type was unrecognized. + * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. + * EC_RES_INVALID_PARAM: The chip type was unrecognized. + * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. */ +#define EC_CMD_LOCATE_CHIP 0x0126 -#define EC_CMD_I2C_LOOKUP 0x0126 +enum ec_chip_type { + EC_CHIP_TYPE_CBI_EEPROM = 0, + EC_CHIP_TYPE_TCPC = 1, + EC_CHIP_TYPE_COUNT, + EC_CHIP_TYPE_MAX = 0xFF, +}; + +enum ec_bus_type { + EC_BUS_TYPE_I2C = 0, + EC_BUS_TYPE_COUNT, + EC_BUS_TYPE_MAX = 0xFF, +}; -enum i2c_device_type { - I2C_LOOKUP_TYPE_CBI_EEPROM = 1, - I2C_LOOKUP_TYPE_COUNT, - I2C_LOOKUP_TYPE_MAX = 0xFFFF, +struct ec_i2c_info { + uint16_t port; /* Physical port for device */ + uint16_t addr; /* 7-bit (or 10-bit) address */ }; -struct ec_params_i2c_lookup { - uint16_t type; /* enum i2c_device_type */ +struct ec_params_locate_chip { + uint8_t type; /* enum ec_chip_type */ + uint8_t index; /* Specifies one instance of chip type */ /* Used for type specific parameters in future */ union { - uint16_t reseved; + uint16_t reserved; }; } __ec_align2; -struct ec_response_i2c_lookup { - uint16_t i2c_port; /* Physical port for device */ - uint16_t i2c_addr; /* 7-bit (or 10-bit) address */ -} __ec_align1; + +struct ec_response_locate_chip { + uint8_t bus_type; /* enum ec_bus_type */ + uint8_t reserved; /* Aligning the following union to 2 bytes */ + union { + struct ec_i2c_info i2c_info; + }; +} __ec_align2; /*****************************************************************************/ /* The command range 0x200-0x2FF is reserved for Rotor. */ diff --git a/util/ectool.c b/util/ectool.c index 63c5bad3d9..aa124edf5e 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -6098,55 +6098,79 @@ int cmd_i2c_xfer(int argc, char *argv[]) return 0; } -static void cmd_i2c_lookup_help(const char *const cmd) +static void cmd_locate_chip_help(const char *const cmd) { fprintf(stderr, - "Usage: %s <type>\n" + "Usage: %s <type> <index>\n" " <type> is one of:\n" - " 1: CBI_EEPROM\n", + " 0: CBI_EEPROM\n" + " 1: TCPCs\n" + " <index> instance # of <type>\n", cmd); } -int cmd_i2c_lookup(int argc, char *argv[]) +static const char *bus_type[] = { + "I2C", +}; + +int cmd_locate_chip(int argc, char *argv[]) { - struct ec_params_i2c_lookup p; - struct ec_response_i2c_lookup r; + struct ec_params_locate_chip p; + struct ec_response_locate_chip r; char *e; int rv; - if (argc != 2) { - cmd_i2c_lookup_help(argv[0]); + if (argc != 3) { + cmd_locate_chip_help(argv[0]); return -1; } p.type = strtol(argv[1], &e, 0); if (e && *e) { fprintf(stderr, "Bad type.\n"); - cmd_i2c_lookup_help(argv[0]); + cmd_locate_chip_help(argv[0]); return -1; } - rv = ec_command(EC_CMD_I2C_LOOKUP, 0, &p, sizeof(p), &r, sizeof(r)); + p.index = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad index.\n"); + cmd_locate_chip_help(argv[0]); + return -1; + } + + rv = ec_command(EC_CMD_LOCATE_CHIP, 0, &p, sizeof(p), &r, sizeof(r)); if (rv == -EC_RES_INVALID_PARAM - EECRESULT) { - fprintf(stderr, "Lookup type %d not supported.\n", p.type); + fprintf(stderr, "Bus type %d not supported.\n", p.type); return rv; } if (rv == -EC_RES_UNAVAILABLE - EECRESULT) { - fprintf(stderr, "Device not found\n"); + fprintf(stderr, "Chip not found\n"); + return rv; + } + + if (rv == -EC_RES_OVERFLOW - EECRESULT) { + fprintf(stderr, "Index too large\n"); return rv; } if (rv < 0) return rv; + if (r.bus_type >= EC_BUS_TYPE_COUNT + || r.bus_type >= ARRAY_SIZE(bus_type)) { + fprintf(stderr, "Unknown bus type (%d)\n", r.bus_type); + return -1; + } + /* - * Do not change the format of this print. firmware_ECCbiEeprom FAFT - * test depends on this, and will silently start skipping tests. + * When changing the format of this print, make sure FAFT + * (firmware_ECCbiEeprom) still passes. It may silently skip the test. */ - printf("Port: %d; Address: 0x%02x (7-bit format)\n", r.i2c_port, - r.i2c_addr); + printf("Bus: %s; Port: %d; Address: 0x%02x (7-bit format)\n", + bus_type[r.bus_type], r.i2c_info.port, r.i2c_info.addr); return 0; } @@ -8515,7 +8539,7 @@ const struct command commands[] = { {"hello", cmd_hello}, {"hibdelay", cmd_hibdelay}, {"hostsleepstate", cmd_hostsleepstate}, - {"i2clookup", cmd_i2c_lookup}, + {"locatechip", cmd_locate_chip}, {"i2cprotect", cmd_i2c_protect}, {"i2cread", cmd_i2c_read}, {"i2cwrite", cmd_i2c_write}, |