From 6f03934e9564ac28f6a0f564cf1429f209ebfc99 Mon Sep 17 00:00:00 2001 From: Samsp_Liu Date: Fri, 7 Aug 2020 15:36:57 +0800 Subject: volteer: Support board-specific TCPC config Separate tcpc_config from volteer baseboard to each project board. To meet different configurations on each board. BUG=b:153705222 BRANCH=none TEST=make buildall Change-Id: Iea59518123a542ebe38be195eaf71b4a8f796550 Signed-off-by: Samsp_Liu Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2342183 Tested-by: SamSP Liu Commit-Queue: Keith Short Reviewed-by: Keith Short --- board/trondo/board.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++- board/trondo/board.h | 9 ++++ 2 files changed, 134 insertions(+), 1 deletion(-) (limited to 'board/trondo') diff --git a/board/trondo/board.c b/board/trondo/board.c index 3570d34cec..06805a46fe 100644 --- a/board/trondo/board.c +++ b/board/trondo/board.c @@ -4,7 +4,7 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" @@ -12,8 +12,11 @@ #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi260.h" #include "driver/als_tcs3400.h" +#include "driver/bc12/pi3usb9201.h" #include "driver/ppc/sn5s330.h" #include "driver/ppc/syv682x.h" +#include "driver/tcpm/tcpci.h" +#include "driver/tcpm/tusb422.h" #include "driver/retimer/bb_retimer.h" #include "driver/sync.h" #include "extpower.h" @@ -32,7 +35,10 @@ #include "tablet_mode.h" #include "throttle_ap.h" #include "uart.h" +#include "usb_mux.h" +#include "usb_pd.h" #include "usb_pd_tbt.h" +#include "usb_pd_tcpm.h" #include "usbc_ppc.h" #include "util.h" @@ -257,3 +263,121 @@ void ppc_interrupt(enum gpio_signal signal) } } +/******************************************************************************/ +/* BC1.2 charger detect configuration */ +const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { + [USBC_PORT_C0] = { + .i2c_port = I2C_PORT_USB_C0, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, + }, + [USBC_PORT_C1] = { + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(pi3usb9201_bc12_chips) == USBC_PORT_COUNT); + +/******************************************************************************/ +/* 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, + .usb23 = USBC_PORT_0_USB2_NUM | (USBC_PORT_0_USB3_NUM << 4), + }, + [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, + .usb23 = USBC_PORT_1_USB2_NUM | (USBC_PORT_1_USB3_NUM << 4), + }, +}; +BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == USBC_PORT_COUNT); +BUILD_ASSERT(CONFIG_USB_PD_PORT_MAX_COUNT == USBC_PORT_COUNT); + +/******************************************************************************/ +/* USBC mux configuration - Tiger Lake includes internal mux */ +struct usb_mux usbc1_usb4_db_retimer = { + .usb_port = USBC_PORT_C1, + .driver = &bb_usb_retimer, + .i2c_port = I2C_PORT_USB_1_MIX, + .i2c_addr_flags = USBC_PORT_C1_BB_RETIMER_I2C_ADDR, +}; +struct usb_mux usb_muxes[] = { + [USBC_PORT_C0] = { + .usb_port = USBC_PORT_C0, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + }, + [USBC_PORT_C1] = { + .usb_port = USBC_PORT_C1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + .next_mux = &usbc1_usb4_db_retimer, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT); + +struct bb_usb_control bb_controls[] = { + [USBC_PORT_C0] = { + /* USB-C port 0 doesn't have a retimer */ + }, + [USBC_PORT_C1] = { + .usb_ls_en_gpio = GPIO_USB_C1_LS_EN, + .retimer_rst_gpio = GPIO_USB_C1_RT_RST_ODL, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(bb_controls) == USBC_PORT_COUNT); + +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); + gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL); + + /* Enable TCPC interrupts. */ + gpio_enable_interrupt(GPIO_USB_C0_TCPC_INT_ODL); + gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL); + + /* Enable BC1.2 interrupts. */ + gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_ODL); + gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL); +} +DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_CHIPSET); + +/******************************************************************************/ +/* TCPC support routines */ +uint16_t tcpc_get_alert_status(void) +{ + uint16_t status = 0; + + /* + * Check which port has the ALERT line set + */ + if (!gpio_get_level(GPIO_USB_C0_TCPC_INT_ODL)) + status |= PD_STATUS_TCPC_ALERT_0; + if (!gpio_get_level(GPIO_USB_C1_TCPC_INT_ODL)) + 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 + return gpio_get_level(GPIO_USB_C1_PPC_INT_ODL) == 0; +} + diff --git a/board/trondo/board.h b/board/trondo/board.h index f4677d2f0c..c81bc1a5db 100644 --- a/board/trondo/board.h +++ b/board/trondo/board.h @@ -47,6 +47,8 @@ (BIT(LID_ACCEL) | BIT(CLEAR_ALS)) /* USB Type C and USB PD defines */ +#define CONFIG_USB_PD_PORT_MAX_COUNT 2 + /* * USB-C port's USB2 & USB3 mapping from schematics * USB2 numbering on PCH - 1 to n @@ -76,6 +78,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -173,6 +176,12 @@ enum sensor_id { SENSOR_COUNT, }; +enum usbc_port { + USBC_PORT_C0 = 0, + USBC_PORT_C1, + USBC_PORT_COUNT +}; + void board_reset_pd_mcu(void); #endif /* !__ASSEMBLER__ */ -- cgit v1.2.1