summaryrefslogtreecommitdiff
path: root/board/brya/usbc_config.c
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-11-04 12:11:58 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-05 04:22:34 +0000
commit252457d4b21f46889eebad61d4c0a65331919cec (patch)
tree01856c4d31d710b20e85a74c8d7b5836e35c3b98 /board/brya/usbc_config.c
parent08f5a1e6fc2c9467230444ac9b582dcf4d9f0068 (diff)
downloadchrome-ec-stabilize-14682.B-ish.tar.gz
In the interest of making long-term branch maintenance incur as little technical debt on us as possible, we should not maintain any files on the branch we are not actually using. This has the added effect of making it extremely clear when merging CLs from the main branch when changes have the possibility to affect us. The follow-on CL adds a convenience script to actually pull updates from the main branch and generate a CL for the update. BUG=b:204206272 BRANCH=ish TEST=make BOARD=arcada_ish && make BOARD=drallion_ish Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I17e4694c38219b5a0823e0a3e55a28d1348f4b18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262038 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'board/brya/usbc_config.c')
-rw-r--r--board/brya/usbc_config.c465
1 files changed, 0 insertions, 465 deletions
diff --git a/board/brya/usbc_config.c b/board/brya/usbc_config.c
deleted file mode 100644
index 1780e1e16d..0000000000
--- a/board/brya/usbc_config.c
+++ /dev/null
@@ -1,465 +0,0 @@
-/* Copyright 2021 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 <stdint.h>
-#include <stdbool.h>
-
-#include "common.h"
-#include "compile_time_macros.h"
-#include "console.h"
-#include "driver/bc12/pi3usb9201_public.h"
-#include "driver/ppc/nx20p348x.h"
-#include "driver/ppc/syv682x_public.h"
-#include "driver/retimer/bb_retimer_public.h"
-#include "driver/tcpm/nct38xx.h"
-#include "driver/tcpm/ps8xxx_public.h"
-#include "driver/tcpm/tcpci.h"
-#include "ec_commands.h"
-#include "fw_config.h"
-#include "gpio.h"
-#include "gpio_signal.h"
-#include "hooks.h"
-#include "ioexpander.h"
-#include "system.h"
-#include "task.h"
-#include "task_id.h"
-#include "timer.h"
-#include "usbc_config.h"
-#include "usbc_ppc.h"
-#include "usb_charge.h"
-#include "usb_mux.h"
-#include "usb_pd.h"
-#include "usb_pd_tcpm.h"
-
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
-
-/* USBC TCPC configuration */
-const struct tcpc_config_t tcpc_config[] = {
- [USBC_PORT_C0] = {
- .bus_type = EC_BUS_TYPE_I2C,
- .i2c_info = {
- .port = I2C_PORT_USB_C0_C2_TCPC,
- .addr_flags = NCT38XX_I2C_ADDR1_1_FLAGS,
- },
- .drv = &nct38xx_tcpm_drv,
- .flags = TCPC_FLAGS_TCPCI_REV2_0 |
- TCPC_FLAGS_NO_DEBUG_ACC_CONTROL,
- },
- [USBC_PORT_C1] = {
- .bus_type = EC_BUS_TYPE_I2C,
- .i2c_info = {
- .port = I2C_PORT_USB_C1_TCPC,
- .addr_flags = PS8751_I2C_ADDR1_FLAGS,
- },
- .drv = &ps8xxx_tcpm_drv,
- .flags = TCPC_FLAGS_TCPCI_REV2_0 |
- TCPC_FLAGS_TCPCI_REV2_0_NO_VSAFE0V,
- },
- [USBC_PORT_C2] = {
- .bus_type = EC_BUS_TYPE_I2C,
- .i2c_info = {
- .port = I2C_PORT_USB_C0_C2_TCPC,
- .addr_flags = NCT38XX_I2C_ADDR2_1_FLAGS,
- },
- .drv = &nct38xx_tcpm_drv,
- .flags = TCPC_FLAGS_TCPCI_REV2_0,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == USBC_PORT_COUNT);
-BUILD_ASSERT(CONFIG_USB_PD_PORT_MAX_COUNT == USBC_PORT_COUNT);
-
-/* USBC PPC configuration */
-struct ppc_config_t ppc_chips[] = {
- [USBC_PORT_C0] = {
- .i2c_port = I2C_PORT_USB_C0_C2_PPC,
- .i2c_addr_flags = SYV682X_ADDR0_FLAGS,
- .drv = &syv682x_drv,
- },
- [USBC_PORT_C1] = {
- /* Compatible with Silicon Mitus SM536A0 */
- .i2c_port = I2C_PORT_USB_C1_PPC,
- .i2c_addr_flags = NX20P3483_ADDR2_FLAGS,
- .drv = &nx20p348x_drv,
- },
- [USBC_PORT_C2] = {
- .i2c_port = I2C_PORT_USB_C0_C2_PPC,
- /*
- * b/179987870
- * schematics I2C map says ADDR3
- */
- .i2c_addr_flags = SYV682X_ADDR2_FLAGS,
- .drv = &syv682x_drv,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(ppc_chips) == USBC_PORT_COUNT);
-
-unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
-
-/* USBC mux configuration - Alder Lake includes internal mux */
-static const struct usb_mux usbc0_tcss_usb_mux = {
- .usb_port = USBC_PORT_C0,
- .driver = &virtual_usb_mux_driver,
- .hpd_update = &virtual_hpd_update,
-};
-static const struct usb_mux usbc2_tcss_usb_mux = {
- .usb_port = USBC_PORT_C2,
- .driver = &virtual_usb_mux_driver,
- .hpd_update = &virtual_hpd_update,
-};
-
-/*
- * USB3 DB mux configuration - the top level mux still needs to be set
- * to the virtual_usb_mux_driver so the AP gets notified of mux changes
- * and updates the TCSS configuration on state changes.
- */
-static const struct usb_mux usbc1_usb3_db_retimer = {
- .usb_port = USBC_PORT_C1,
- .driver = &tcpci_tcpm_usb_mux_driver,
- .hpd_update = &ps8xxx_tcpc_update_hpd_status,
-};
-
-const struct usb_mux usb_muxes[] = {
- [USBC_PORT_C0] = {
- .usb_port = USBC_PORT_C0,
- .driver = &bb_usb_retimer,
- .hpd_update = bb_retimer_hpd_update,
- .i2c_port = I2C_PORT_USB_C0_C2_MUX,
- .i2c_addr_flags = USBC_PORT_C0_BB_RETIMER_I2C_ADDR,
- .next_mux = &usbc0_tcss_usb_mux,
- },
- [USBC_PORT_C1] = {
- /* PS8815 DB */
- .usb_port = USBC_PORT_C1,
- .driver = &virtual_usb_mux_driver,
- .hpd_update = &virtual_hpd_update,
- .next_mux = &usbc1_usb3_db_retimer,
- },
- [USBC_PORT_C2] = {
- .usb_port = USBC_PORT_C2,
- .driver = &bb_usb_retimer,
- .hpd_update = bb_retimer_hpd_update,
- .i2c_port = I2C_PORT_USB_C0_C2_MUX,
- .i2c_addr_flags = USBC_PORT_C2_BB_RETIMER_I2C_ADDR,
- .next_mux = &usbc2_tcss_usb_mux,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT);
-
-/* BC1.2 charger detect configuration */
-const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = {
- [USBC_PORT_C0] = {
- .i2c_port = I2C_PORT_USB_C0_C2_BC12,
- .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS,
- },
- [USBC_PORT_C1] = {
- .i2c_port = I2C_PORT_USB_C1_BC12,
- .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS,
- },
- [USBC_PORT_C2] = {
- .i2c_port = I2C_PORT_USB_C0_C2_BC12,
- .i2c_addr_flags = PI3USB9201_I2C_ADDR_1_FLAGS,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(pi3usb9201_bc12_chips) == USBC_PORT_COUNT);
-
-/*
- * USB C0 and C2 uses burnside bridge chips and have their reset
- * controlled by their respective TCPC chips acting as GPIO expanders.
- *
- * ioex_init() is normally called before we take the TCPCs out of
- * reset, so we need to start in disabled mode, then explicitly
- * call ioex_init().
- */
-
-struct ioexpander_config_t ioex_config[] = {
- [IOEX_C0_NCT38XX] = {
- .i2c_host_port = I2C_PORT_USB_C0_C2_TCPC,
- .i2c_addr_flags = NCT38XX_I2C_ADDR1_1_FLAGS,
- .drv = &nct38xx_ioexpander_drv,
- .flags = IOEX_FLAGS_DISABLED,
- },
- [IOEX_C2_NCT38XX] = {
- .i2c_host_port = I2C_PORT_USB_C0_C2_TCPC,
- .i2c_addr_flags = NCT38XX_I2C_ADDR2_1_FLAGS,
- .drv = &nct38xx_ioexpander_drv,
- .flags = IOEX_FLAGS_DISABLED,
- },
- [IOEX_ID_1_C0_NCT38XX] = {
- .i2c_host_port = I2C_PORT_USB_C0_C2_TCPC,
- .i2c_addr_flags = NCT38XX_I2C_ADDR1_1_FLAGS,
- .drv = &nct38xx_ioexpander_drv,
- .flags = IOEX_FLAGS_DISABLED,
- },
- [IOEX_ID_1_C2_NCT38XX] = {
- .i2c_host_port = I2C_PORT_USB_C0_C2_TCPC,
- .i2c_addr_flags = NCT38XX_I2C_ADDR2_1_FLAGS,
- .drv = &nct38xx_ioexpander_drv,
- .flags = IOEX_FLAGS_DISABLED,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(ioex_config) == CONFIG_IO_EXPANDER_PORT_COUNT);
-
-void config_usb_db_type(void)
-{
- enum ec_cfg_usb_db_type db_type = ec_cfg_usb_db_type();
-
- /*
- * TODO(b/180434685): implement multiple DB types
- */
-
- CPRINTS("Configured USB DB type number is %d", db_type);
-}
-
-__override int bb_retimer_power_enable(const struct usb_mux *me, bool enable)
-{
- enum ioex_signal rst_signal;
-
- if (me->usb_port == USBC_PORT_C0) {
- if (get_board_id() == 1)
- rst_signal = IOEX_ID_1_USB_C0_RT_RST_ODL;
- else
- rst_signal = IOEX_USB_C0_RT_RST_ODL;
- } else if (me->usb_port == USBC_PORT_C2) {
- if (get_board_id() == 1)
- rst_signal = IOEX_ID_1_USB_C2_RT_RST_ODL;
- else
- rst_signal = IOEX_USB_C2_RT_RST_ODL;
- } else {
- return EC_ERROR_INVAL;
- }
-
- /*
- * We do not have a load switch for the burnside bridge chips,
- * so we only need to sequence reset.
- */
-
- if (enable) {
- /*
- * Tpw, minimum time from VCC to RESET_N de-assertion is 100us.
- * For boards that don't provide a load switch control, the
- * retimer_init() function ensures power is up before calling
- * this function.
- */
- ioex_set_level(rst_signal, 1);
- /*
- * Allow 1ms time for the retimer to power up lc_domain
- * which powers I2C controller within retimer
- */
- msleep(1);
- if (get_board_id() == 1) {
- int val;
-
- /*
- * Check if we were able to deassert
- * reset. Board ID 1 uses a GPIO that is
- * uncontrollable when a debug accessory is
- * connected.
- */
- if (ioex_get_level(rst_signal, &val) != EC_SUCCESS)
- return EC_ERROR_UNKNOWN;
- if (val != 1)
- return EC_ERROR_NOT_POWERED;
- }
- } else {
- ioex_set_level(rst_signal, 0);
- msleep(1);
- }
- return EC_SUCCESS;
-}
-
-void board_reset_pd_mcu(void)
-{
- enum gpio_signal tcpc_rst;
-
- if (get_board_id() == 1)
- tcpc_rst = GPIO_ID_1_USB_C0_C2_TCPC_RST_ODL;
- else
- tcpc_rst = GPIO_USB_C0_C2_TCPC_RST_ODL;
-
- /*
- * TODO(b/179648104): figure out correct timing
- */
-
- gpio_set_level(tcpc_rst, 0);
- if (ec_cfg_usb_db_type() != DB_USB_ABSENT) {
- gpio_set_level(GPIO_USB_C1_RST_ODL, 0);
- gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 0);
- }
-
- /*
- * delay for power-on to reset-off and min. assertion time
- */
-
- msleep(20);
-
- gpio_set_level(tcpc_rst, 1);
- if (ec_cfg_usb_db_type() != DB_USB_ABSENT) {
- gpio_set_level(GPIO_USB_C1_RST_ODL, 1);
- gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 1);
- }
-
- /* wait for chips to come up */
-
- msleep(50);
-}
-
-static void enable_ioex(int ioex)
-{
- ioex_config[ioex].flags &= ~IOEX_FLAGS_DISABLED;
- ioex_init(ioex);
-}
-
-static void board_tcpc_init(void)
-{
- /* Don't reset TCPCs after initial reset */
- if (!system_jumped_late()) {
- board_reset_pd_mcu();
-
- /*
- * These IO expander pins are implemented using the
- * C0/C2 TCPC, so they must be set up after the TCPC has
- * been taken out of reset.
- */
- if (get_board_id() == 1) {
- enable_ioex(IOEX_ID_1_C0_NCT38XX);
- enable_ioex(IOEX_ID_1_C2_NCT38XX);
- } else {
- enable_ioex(IOEX_C0_NCT38XX);
- enable_ioex(IOEX_C2_NCT38XX);
- }
- }
-
- /* Enable PPC interrupts. */
- gpio_enable_interrupt(GPIO_USB_C0_PPC_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C2_PPC_INT_ODL);
-
- /* Enable TCPC interrupts. */
- gpio_enable_interrupt(GPIO_USB_C0_C2_TCPC_INT_ODL);
-
- /* Enable BC1.2 interrupts. */
- gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C2_BC12_INT_ODL);
-
- if (ec_cfg_usb_db_type() != DB_USB_ABSENT) {
- gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL);
- }
-}
-DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_CHIPSET);
-
-uint16_t tcpc_get_alert_status(void)
-{
- uint16_t status = 0;
-
- if (gpio_get_level(GPIO_USB_C0_C2_TCPC_INT_ODL) == 0)
- status |= PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_2;
-
- if ((ec_cfg_usb_db_type() != DB_USB_ABSENT) &&
- gpio_get_level(GPIO_USB_C1_TCPC_INT_ODL) == 0)
- status |= PD_STATUS_TCPC_ALERT_1;
-
- return status;
-}
-
-int ppc_get_alert_status(int port)
-{
- if (port == USBC_PORT_C0)
- return gpio_get_level(GPIO_USB_C0_PPC_INT_ODL) == 0;
- else if ((port == USBC_PORT_C1) &&
- (ec_cfg_usb_db_type() != DB_USB_ABSENT))
- return gpio_get_level(GPIO_USB_C1_PPC_INT_ODL) == 0;
- else if (port == USBC_PORT_C2)
- return gpio_get_level(GPIO_USB_C2_PPC_INT_ODL) == 0;
- return 0;
-}
-
-void tcpc_alert_event(enum gpio_signal signal)
-{
- switch (signal) {
- case GPIO_USB_C0_C2_TCPC_INT_ODL:
- schedule_deferred_pd_interrupt(USBC_PORT_C0);
- break;
- case GPIO_USB_C1_TCPC_INT_ODL:
- if (ec_cfg_usb_db_type() == DB_USB_ABSENT)
- break;
- schedule_deferred_pd_interrupt(USBC_PORT_C1);
- break;
- default:
- break;
- }
-}
-
-void bc12_interrupt(enum gpio_signal signal)
-{
- switch (signal) {
- case GPIO_USB_C0_BC12_INT_ODL:
- task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12);
- break;
- case GPIO_USB_C1_BC12_INT_ODL:
- if (ec_cfg_usb_db_type() == DB_USB_ABSENT)
- break;
- task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12);
- break;
- case GPIO_USB_C2_BC12_INT_ODL:
- task_set_event(TASK_ID_USB_CHG_P2, USB_CHG_EVENT_BC12);
- break;
- default:
- break;
- }
-}
-
-void ppc_interrupt(enum gpio_signal signal)
-{
- switch (signal) {
- case GPIO_USB_C0_PPC_INT_ODL:
- syv682x_interrupt(USBC_PORT_C0);
- break;
- case GPIO_USB_C1_PPC_INT_ODL:
- switch (ec_cfg_usb_db_type()) {
- case DB_USB_ABSENT:
- case DB_USB_ABSENT2:
- break;
- case DB_USB3_PS8815:
- nx20p348x_interrupt(USBC_PORT_C1);
- break;
- }
- break;
- case GPIO_USB_C2_PPC_INT_ODL:
- syv682x_interrupt(USBC_PORT_C2);
- break;
- default:
- break;
- }
-}
-
-void retimer_interrupt(enum gpio_signal signal)
-{
- /*
- * TODO(b/179513527): add USB-C support
- */
-}
-
-__override bool board_is_dts_port(int port)
-{
- return port == USBC_PORT_C0;
-}
-
-__override bool board_is_tbt_usb4_port(int port)
-{
- if (port == USBC_PORT_C0 || port == USBC_PORT_C2)
- return true;
-
- return false;
-}
-
-__override enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
-{
- if (!board_is_tbt_usb4_port(port))
- return TBT_SS_RES_0;
-
- return TBT_SS_TBT_GEN3;
-}