/* Copyright 2022 The ChromiumOS Authors * 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 "console.h" #include "driver/bc12/pi3usb9201_public.h" #include "driver/ppc/syv682x_public.h" #include "driver/retimer/bb_retimer_public.h" #include "driver/retimer/kb800x.h" #include "driver/tcpm/rt1715.h" #include "driver/tcpm/tcpci.h" #include "ec_commands.h" #include "gpio.h" #include "gpio_signal.h" #include "hooks.h" #include "system.h" #include "task.h" #include "task_id.h" #include "timer.h" #include "usb_charge.h" #include "usb_mux.h" #include "usb_pd.h" #include "usb_pd_tcpm.h" #include "usbc_config.h" #include "usbc_ppc.h" #include #include #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[CONFIG_USB_PD_PORT_MAX_COUNT] = { [USBC_PORT_C0] = { .bus_type = EC_BUS_TYPE_I2C, .i2c_info = { .port = I2C_PORT_USB_C0_C2_TCPC, .addr_flags = RT1715_I2C_ADDR_FLAGS, }, .drv = &rt1715_tcpm_drv, }, }; /* USBC PPC configuration */ struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = { [USBC_PORT_C0] = { .i2c_port = I2C_PORT_USB_C0_C2_PPC, .i2c_addr_flags = SYV682X_ADDR0_FLAGS, .drv = &syv682x_drv, }, }; unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); /* USBC mux configuration - Alder Lake includes internal mux */ static const struct usb_mux_chain usbc0_tcss_usb_mux = { .mux = &(const struct usb_mux){ .usb_port = USBC_PORT_C0, .driver = &virtual_usb_mux_driver, .hpd_update = &virtual_hpd_update, }, }; const struct usb_mux_chain usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { [USBC_PORT_C0] = { .mux = &(const struct usb_mux) { .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 = &usbc0_tcss_usb_mux, }, }; /* BC1.2 charger detect configuration */ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = { [USBC_PORT_C0] = { .i2c_port = I2C_PORT_USB_C0_C2_BC12, .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, }, }; __override int bb_retimer_power_enable(const struct usb_mux *me, bool enable) { enum gpio_signal rst_signal; if (me->usb_port == USBC_PORT_C0) { rst_signal = GPIO_USB_C0_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. */ gpio_set_level(rst_signal, 1); /* * Allow 1ms time for the retimer to power up lc_domain * which powers I2C controller within retimer */ msleep(1); } else { gpio_set_level(rst_signal, 0); msleep(1); } return EC_SUCCESS; } __override int bb_retimer_reset(const struct usb_mux *me) { /* * TODO(b/193402306, b/195375738): Remove this once transition to * QS Silicon is complete */ bb_retimer_power_enable(me, false); msleep(5); bb_retimer_power_enable(me, true); msleep(25); return EC_SUCCESS; } void board_reset_pd_mcu(void) { /* * TODO(b/179648104): figure out correct timing */ } static void board_tcpc_init(void) { /* Don't reset TCPCs after initial reset */ if (!system_jumped_late()) { board_reset_pd_mcu(); } /* Enable PPC interrupts. */ gpio_enable_interrupt(GPIO_USB_C0_PPC_INT_ODL); /* Enable TCPC interrupts. */ gpio_enable_interrupt(GPIO_USB_C0_C2_TCPC_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; 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; 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; default: break; } } void bc12_interrupt(enum gpio_signal signal) { switch (signal) { case GPIO_USB_C0_BC12_INT_ODL: usb_charger_task_set_event(0, 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; 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) { return true; } __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; }