diff options
author | Simon Glass <sjg@chromium.org> | 2020-12-30 12:55:26 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-15 03:56:33 +0000 |
commit | 2d24d9117407c6675d5c6dee4a91f0638e421b9d (patch) | |
tree | 42fba78cf3f990d4f774f355a4d6193bd61f47a9 | |
parent | 9d99eb123e96946abf45baed434107f6ff878106 (diff) | |
download | chrome-ec-2d24d9117407c6675d5c6dee4a91f0638e421b9d.tar.gz |
volteer: Use the EC version of usbc_config.c
Instead of using a copy, bring in the file from the EC tree. There are
two files, one for the baseboard and one for the board.
This needs a few missing GPIOs so add those here too.
BUG=b:175434113
TEST=with zephyr-chrome CL, build on volteer with full EC usb_pd_policy.c
Cq-Depend: chromium:2605277
Change-Id: I4226488066be216148bb0dab6e46df9ebe5f0ea8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/zephyr-chrome/+/2607400
Commit-Queue: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2630172
Tested-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | zephyr/projects/volteer/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/projects/volteer/include/gpio_map.h | 13 | ||||
-rw-r--r-- | zephyr/projects/volteer/src/battery.c | 8 | ||||
-rw-r--r-- | zephyr/projects/volteer/src/usbc_config.c | 148 |
4 files changed, 17 insertions, 157 deletions
diff --git a/zephyr/projects/volteer/CMakeLists.txt b/zephyr/projects/volteer/CMakeLists.txt index 60d2a73e9a..61d7bbb7f4 100644 --- a/zephyr/projects/volteer/CMakeLists.txt +++ b/zephyr/projects/volteer/CMakeLists.txt @@ -32,10 +32,13 @@ zephyr_include_directories( # Include selected EC source for the baseboard target_sources(app PRIVATE "${PLATFORM_EC_BASEBOARD}/battery_presence.c") +target_sources(app PRIVATE "${PLATFORM_EC_BASEBOARD}/charger.c") target_sources(app PRIVATE "${PLATFORM_EC_BASEBOARD}/usb_pd_policy.c") +# Include selected EC source for the board +target_sources(app PRIVATE "${PLATFORM_EC_BOARD}/usbc_config.c") + # Local sources to make things build. These are being removed as we are able # to build the EC source instead. target_sources(app PRIVATE "src/battery.c") target_sources(app PRIVATE "src/pwrok_signals.c") -target_sources(app PRIVATE "src/usbc_config.c") diff --git a/zephyr/projects/volteer/include/gpio_map.h b/zephyr/projects/volteer/include/gpio_map.h index f3bed679b1..29cbf26f2d 100644 --- a/zephyr/projects/volteer/include/gpio_map.h +++ b/zephyr/projects/volteer/include/gpio_map.h @@ -47,6 +47,19 @@ #define GPIO_SYS_RESET_L NAMED_GPIO(sys_rst_odl) #define GPIO_WP_L NAMED_GPIO(ec_wp_l) +/* USB-C interrupts */ +#define GPIO_USB_C0_TCPC_INT_ODL NAMED_GPIO(usb_c0_tcpc_int_odl) +#define GPIO_USB_C1_TCPC_INT_ODL NAMED_GPIO(usb_c1_tcpc_int_odl) + +#define GPIO_USB_C0_PPC_INT_ODL NAMED_GPIO(usb_c0_ppc_int_odl) +#define GPIO_USB_C1_PPC_INT_ODL NAMED_GPIO(usb_c1_ppc_int_odl) + +#define GPIO_USB_C0_BC12_INT_ODL NAMED_GPIO(usb_c0_bc12_int_odl) +#define GPIO_USB_C1_MIX_INT_ODL NAMED_GPIO(usb_c1_mix_int_odl) + +#define GPIO_USB_C0_OC_ODL NAMED_GPIO(usb_c0_oc_odl) +#define GPIO_USB_C1_OC_ODL NAMED_GPIO(usb_c1_oc_odl) + /* * Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items. * diff --git a/zephyr/projects/volteer/src/battery.c b/zephyr/projects/volteer/src/battery.c index d2530979fa..dab6c67b87 100644 --- a/zephyr/projects/volteer/src/battery.c +++ b/zephyr/projects/volteer/src/battery.c @@ -68,11 +68,3 @@ const struct board_batt_params board_battery_info[] = { BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_LGC011; - -const struct charger_config_t chg_chips[] = { - { - .i2c_port = I2C_PORT_CHARGER, - .i2c_addr_flags = ISL9241_ADDR_FLAGS, - .drv = &isl9241_drv, - }, -}; diff --git a/zephyr/projects/volteer/src/usbc_config.c b/zephyr/projects/volteer/src/usbc_config.c deleted file mode 100644 index f503a1914d..0000000000 --- a/zephyr/projects/volteer/src/usbc_config.c +++ /dev/null @@ -1,148 +0,0 @@ -/* Copyright 2020 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. - */ - -/* USBC PPC chip list. Copied from volteer board.c in platform/ec. */ - -#include <stdbool.h> -#include <zephyr.h> - -#include "charge_manager.h" -#include "charge_state.h" -#include "gpio_map.h" -#include "gpio_signal.h" -#include "usbc_ocp.h" -#include "usbc_ppc.h" -#include "../driver/ppc/sn5s330.h" -#include "../driver/ppc/syv682x.h" -#include "../driver/tcpm/tusb422.h" - -#define SN5S330_ADDR0_FLAGS 0x40 -#define SYV682X_ADDR0_FLAGS 0x40 - -#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args) -#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args) - -enum usbc_port { - USBC_PORT_C0 = 0, - USBC_PORT_C1, - USBC_PORT_COUNT -}; - -struct ppc_config_t ppc_chips[] = { - [USBC_PORT_C0] = { - .i2c_port = I2C_PORT_USB_C0, - .i2c_addr_flags = SN5S330_ADDR0_FLAGS, - .drv = &sn5s330_drv, - }, - [USBC_PORT_C1] = { - .i2c_port = I2C_PORT_USB_C1, - .i2c_addr_flags = SYV682X_ADDR0_FLAGS, - .drv = &syv682x_drv, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(ppc_chips) == USBC_PORT_COUNT); -unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); - -/* FIXME: For some reason these don't get defined by gpio_signal.h */ -#define GPIO_USB_C0_OC_ODL 0 -#define GPIO_USB_C1_OC_ODL 1 - -void board_overcurrent_event(int port, int is_overcurrented) -{ - /* Note that the level is inverted because the pin is active low. */ - switch (port) { - case USBC_PORT_C0: - gpio_set_level(GPIO_USB_C0_OC_ODL, !is_overcurrented); - break; - case USBC_PORT_C1: - gpio_set_level(GPIO_USB_C1_OC_ODL, !is_overcurrented); - break; - } -} - -/******************************************************************************/ -/* USBC TCPC configuration */ -struct tcpc_config_t tcpc_config[] = { - [USBC_PORT_C0] = { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C0, - .addr_flags = TUSB422_I2C_ADDR_FLAGS, - }, - .drv = &tusb422_tcpm_drv, - }, - [USBC_PORT_C1] = { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C1, - .addr_flags = TUSB422_I2C_ADDR_FLAGS, - }, - .drv = &tusb422_tcpm_drv, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == USBC_PORT_COUNT); -BUILD_ASSERT(CONFIG_USB_PD_PORT_MAX_COUNT == USBC_PORT_COUNT); - -int board_set_active_charge_port(int port) -{ - int is_valid_port = (port >= 0 && - port < CONFIG_USB_PD_PORT_MAX_COUNT); - int i; - - if (port == CHARGE_PORT_NONE) { - CPRINTSUSB("Disabling all charger ports"); - - /* Disable all ports. */ - for (i = 0; i < ppc_cnt; i++) { - /* - * Do not return early if one fails otherwise we can - * get into a boot loop assertion failure. - */ - if (ppc_vbus_sink_enable(i, 0)) - CPRINTSUSB("Disabling C%d as sink failed.", i); - } - - return EC_SUCCESS; - } else if (!is_valid_port) { - return EC_ERROR_INVAL; - } - - - /* Check if the port is sourcing VBUS. */ - if (ppc_is_sourcing_vbus(port)) { - CPRINTFUSB("Skip enable C%d", port); - return EC_ERROR_INVAL; - } - - CPRINTSUSB("New charge port: C%d", port); - - /* - * Turn off the other ports' sink path FETs, before enabling the - * requested charge port. - */ - for (i = 0; i < ppc_cnt; i++) { - if (i == port) - continue; - - if (ppc_vbus_sink_enable(i, 0)) - CPRINTSUSB("C%d: sink path disable failed.", i); - } - - /* Enable requested charge port. */ - if (ppc_vbus_sink_enable(port, 1)) { - CPRINTSUSB("C%d: sink path enable failed.", port); - return EC_ERROR_UNKNOWN; - } - - return EC_SUCCESS; -} - -__overridable void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) -{ - charge_set_input_current_limit(MAX(charge_ma, - CONFIG_CHARGER_INPUT_CURRENT), - charge_mv); -} |