diff options
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 */ |