diff options
-rw-r--r-- | baseboard/volteer/baseboard.c | 123 | ||||
-rw-r--r-- | baseboard/volteer/baseboard.h | 8 | ||||
-rw-r--r-- | board/delbin/board.c | 125 | ||||
-rw-r--r-- | board/delbin/board.h | 9 | ||||
-rw-r--r-- | board/eldrid/board.c | 125 | ||||
-rw-r--r-- | board/eldrid/board.h | 9 | ||||
-rw-r--r-- | board/halvor/board.c | 126 | ||||
-rw-r--r-- | board/halvor/board.h | 9 | ||||
-rw-r--r-- | board/lindar/board.c | 124 | ||||
-rw-r--r-- | board/lindar/board.h | 11 | ||||
-rw-r--r-- | board/lingcod/board.c | 125 | ||||
-rw-r--r-- | board/lingcod/board.h | 11 | ||||
-rw-r--r-- | board/malefor/board.c | 124 | ||||
-rw-r--r-- | board/malefor/board.h | 10 | ||||
-rw-r--r-- | board/terrador/board.c | 125 | ||||
-rw-r--r-- | board/terrador/board.h | 9 | ||||
-rw-r--r-- | board/todor/board.c | 125 | ||||
-rw-r--r-- | board/todor/board.h | 9 | ||||
-rw-r--r-- | board/trondo/board.c | 126 | ||||
-rw-r--r-- | board/trondo/board.h | 9 | ||||
-rw-r--r-- | board/volteer/board.c | 125 | ||||
-rw-r--r-- | board/volteer/board.h | 9 | ||||
-rw-r--r-- | board/voxel/board.c | 126 | ||||
-rw-r--r-- | board/voxel/board.h | 10 |
24 files changed, 1467 insertions, 145 deletions
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c index 59016b7f79..1fa95af8f3 100644 --- a/baseboard/volteer/baseboard.c +++ b/baseboard/volteer/baseboard.c @@ -5,17 +5,13 @@ /* Volteer family-specific configuration */ #include "adc_chip.h" -#include "bb_retimer.h" #include "button.h" #include "cbi_ec_fw_config.h" #include "charge_manager.h" #include "charge_state.h" #include "cros_board_info.h" -#include "driver/bc12/pi3usb9201.h" #include "driver/charger/isl9241.h" #include "driver/tcpm/ps8xxx.h" -#include "driver/tcpm/tcpci.h" -#include "driver/tcpm/tusb422.h" #include "driver/temp_sensor/thermistor.h" #include "gpio.h" #include "hooks.h" @@ -26,9 +22,6 @@ #include "task.h" #include "temp_sensor.h" #include "usbc_ppc.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usb_pd_tcpm.h" #include "util.h" #define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args) @@ -72,20 +65,6 @@ const struct adc_t adc_channels[] = { BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); /******************************************************************************/ -/* 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); - -/******************************************************************************/ /* Wake up pins */ const enum gpio_signal hibernate_wake_pins[] = { GPIO_LID_OPEN, @@ -239,108 +218,6 @@ struct ec_thermal_config thermal_params[] = { BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_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 baseboard_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, baseboard_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; -} void tcpc_alert_event(enum gpio_signal signal) { diff --git a/baseboard/volteer/baseboard.h b/baseboard/volteer/baseboard.h index 3bd7f52315..5e0bf5cd64 100644 --- a/baseboard/volteer/baseboard.h +++ b/baseboard/volteer/baseboard.h @@ -156,7 +156,6 @@ #define CONFIG_USB_PD_DISCHARGE_PPC #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 -#define CONFIG_USB_PD_PORT_MAX_COUNT 2 #define CONFIG_USB_PD_TCPC_RUNTIME_CONFIG #define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE #define CONFIG_USB_PD_TCPC_LOW_POWER @@ -225,7 +224,6 @@ /* Retimer */ #define CONFIG_USBC_RETIMER_INTEL_BB #define CONFIG_USBC_RETIMER_INTEL_BB_RUNTIME_CONFIG -#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 #ifndef __ASSEMBLER__ @@ -260,12 +258,6 @@ enum temp_sensor_id { TEMP_SENSOR_COUNT }; -enum usbc_port { - USBC_PORT_C0 = 0, - USBC_PORT_C1, - USBC_PORT_COUNT -}; - /* Common definition for the USB PD interrupt handlers. */ void ppc_interrupt(enum gpio_signal signal); void tcpc_alert_event(enum gpio_signal signal); diff --git a/board/delbin/board.c b/board/delbin/board.c index ad8c9e44bb..6c8e2b1884 100644 --- a/board/delbin/board.c +++ b/board/delbin/board.c @@ -4,17 +4,19 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" #include "cbi_ec_fw_config.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi260.h" +#include "driver/bc12/pi3usb9201.h" #include "driver/ppc/syv682x.h" #include "driver/retimer/bb_retimer.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" +#include "driver/tcpm/tusb422.h" #include "extpower.h" #include "fan.h" #include "fan_chip.h" @@ -32,7 +34,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" @@ -411,3 +416,121 @@ static void board_chipset_suspend(void) gpio_set_level(GPIO_EC_KB_BL_EN, 0); } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); + +/******************************************************************************/ +/* 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/delbin/board.h b/board/delbin/board.h index fd43315be3..7b94edf039 100644 --- a/board/delbin/board.h +++ b/board/delbin/board.h @@ -53,6 +53,8 @@ #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL /* 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 @@ -82,6 +84,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ #define USB_PORT_COUNT 1 @@ -171,6 +174,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__ */ diff --git a/board/eldrid/board.c b/board/eldrid/board.c index bb7b47f484..14b528c214 100644 --- a/board/eldrid/board.c +++ b/board/eldrid/board.c @@ -4,7 +4,7 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" @@ -12,12 +12,14 @@ #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/retimer/bb_retimer.h" #include "driver/sync.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" +#include "driver/tcpm/tusb422.h" #include "extpower.h" #include "fan.h" #include "fan_chip.h" @@ -34,7 +36,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" @@ -421,3 +426,121 @@ void ppc_interrupt(enum gpio_signal signal) break; } } + +/******************************************************************************/ +/* 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/eldrid/board.h b/board/eldrid/board.h index 6714ccaf78..af577086a0 100644 --- a/board/eldrid/board.h +++ b/board/eldrid/board.h @@ -65,6 +65,8 @@ #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL /* 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 @@ -95,6 +97,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* Disabled PD extended message support to save flash space. */ #undef CONFIG_USB_PD_EXTENDED_MESSAGES @@ -194,6 +197,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__ */ diff --git a/board/halvor/board.c b/board/halvor/board.c index f5341f136c..4e1d8a3479 100644 --- a/board/halvor/board.c +++ b/board/halvor/board.c @@ -4,15 +4,18 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" #include "cbi_ec_fw_config.h" #include "driver/accel_bma2x2.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/sync.h" #include "extpower.h" #include "gpio.h" @@ -27,7 +30,10 @@ #include "task.h" #include "tablet_mode.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" @@ -231,3 +237,121 @@ void ppc_interrupt(enum gpio_signal signal) break; } } + +/******************************************************************************/ +/* 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/halvor/board.h b/board/halvor/board.h index 4867229a4c..db76698b8f 100644 --- a/board/halvor/board.h +++ b/board/halvor/board.h @@ -42,6 +42,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 @@ -71,6 +73,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -163,6 +166,12 @@ enum sensor_id { SENSOR_COUNT, }; +enum usbc_port { + USBC_PORT_C0 = 0, + USBC_PORT_C1, + USBC_PORT_COUNT +}; + /* Definition for Halvor USB PD interrupt handlers. */ void halvor_tcpc_alert_event(enum gpio_signal signal); void halvor_ppc_interrupt(enum gpio_signal signal); diff --git a/board/lindar/board.c b/board/lindar/board.c index d9e28f340c..b65ee1ef6c 100644 --- a/board/lindar/board.c +++ b/board/lindar/board.c @@ -4,15 +4,17 @@ */ /* Malefor board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "cbi_ec_fw_config.h" #include "common.h" +#include "driver/bc12/pi3usb9201.h" #include "driver/ppc/sn5s330.h" #include "driver/ppc/syv682x.h" #include "driver/sync.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" +#include "driver/tcpm/tusb422.h" #include "extpower.h" #include "fan.h" #include "fan_chip.h" @@ -29,6 +31,9 @@ #include "task.h" #include "tablet_mode.h" #include "uart.h" +#include "usb_mux.h" +#include "usb_pd.h" +#include "usb_pd_tcpm.h" #include "usbc_ppc.h" #include "util.h" @@ -239,3 +244,120 @@ 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/lindar/board.h b/board/lindar/board.h index 7af00f45b2..e749275e26 100644 --- a/board/lindar/board.h +++ b/board/lindar/board.h @@ -31,6 +31,8 @@ #undef CONFIG_MKBP_EVENT /* 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 @@ -54,6 +56,8 @@ #define PD_MAX_POWER_MW 60000 #define PD_MAX_CURRENT_MA 3000 #define PD_MAX_VOLTAGE_MV 20000 +/* Enabling USB4 mode */ +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -116,7 +120,6 @@ #define I2C_ADDR_EEPROM_FLAGS 0x50 #define CONFIG_I2C_MASTER - #ifndef __ASSEMBLER__ #include "gpio_signal.h" @@ -136,6 +139,12 @@ enum pwm_channel { PWM_CH_COUNT }; +enum usbc_port { + USBC_PORT_C0 = 0, + USBC_PORT_C1, + USBC_PORT_COUNT +}; + void board_reset_pd_mcu(void); #endif /* !__ASSEMBLER__ */ diff --git a/board/lingcod/board.c b/board/lingcod/board.c index 5841ea0385..ac199a4836 100644 --- a/board/lingcod/board.c +++ b/board/lingcod/board.c @@ -4,14 +4,17 @@ */ /* Malefor board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "cbi_ec_fw_config.h" #include "common.h" #include "driver/accel_lis2dh.h" #include "driver/accelgyro_lsm6dsm.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/sync.h" #include "extpower.h" #include "fan.h" @@ -29,6 +32,9 @@ #include "task.h" #include "tablet_mode.h" #include "uart.h" +#include "usb_mux.h" +#include "usb_pd.h" +#include "usb_pd_tcpm.h" #include "usbc_ppc.h" #include "util.h" @@ -351,3 +357,120 @@ 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/lingcod/board.h b/board/lingcod/board.h index 27d30365d9..230b40fd84 100644 --- a/board/lingcod/board.h +++ b/board/lingcod/board.h @@ -43,6 +43,8 @@ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) /* 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 @@ -66,6 +68,8 @@ #define PD_MAX_POWER_MW 60000 #define PD_MAX_CURRENT_MA 3000 #define PD_MAX_VOLTAGE_MV 20000 +/* Enabling USB4 mode */ +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -128,7 +132,6 @@ #define I2C_ADDR_EEPROM_FLAGS 0x50 #define CONFIG_I2C_MASTER - #ifndef __ASSEMBLER__ #include "gpio_signal.h" @@ -155,6 +158,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__ */ diff --git a/board/malefor/board.c b/board/malefor/board.c index ecac587c49..473f9f90f8 100644 --- a/board/malefor/board.c +++ b/board/malefor/board.c @@ -4,17 +4,19 @@ */ /* Malefor board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "cbi_ec_fw_config.h" #include "common.h" #include "driver/accel_lis2dh.h" #include "driver/accelgyro_lsm6dsm.h" +#include "driver/bc12/pi3usb9201.h" #include "driver/ppc/sn5s330.h" #include "driver/ppc/syv682x.h" #include "driver/sync.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" +#include "driver/tcpm/tusb422.h" #include "extpower.h" #include "fan.h" #include "fan_chip.h" @@ -31,6 +33,9 @@ #include "task.h" #include "tablet_mode.h" #include "uart.h" +#include "usb_mux.h" +#include "usb_pd.h" +#include "usb_pd_tcpm.h" #include "usbc_ppc.h" #include "util.h" @@ -406,3 +411,120 @@ 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/malefor/board.h b/board/malefor/board.h index 27d30365d9..321fbc130f 100644 --- a/board/malefor/board.h +++ b/board/malefor/board.h @@ -43,6 +43,8 @@ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) /* 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 @@ -66,6 +68,8 @@ #define PD_MAX_POWER_MW 60000 #define PD_MAX_CURRENT_MA 3000 #define PD_MAX_VOLTAGE_MV 20000 +/* Enabling USB4 mode */ +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -155,6 +159,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__ */ diff --git a/board/terrador/board.c b/board/terrador/board.c index 3781dfc356..7f4cc046e6 100644 --- a/board/terrador/board.c +++ b/board/terrador/board.c @@ -4,15 +4,18 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" #include "cbi_ec_fw_config.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi260.h" +#include "driver/bc12/pi3usb9201.h" #include "driver/als_tcs3400.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" @@ -31,7 +34,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" @@ -217,3 +223,120 @@ 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/terrador/board.h b/board/terrador/board.h index 4eae0df382..5a67fbc8fa 100644 --- a/board/terrador/board.h +++ b/board/terrador/board.h @@ -54,6 +54,8 @@ #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL /* 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 @@ -84,6 +86,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 #define USBC_PORT_C0_BB_RETIMER_I2C_ADDR 0x40 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -178,6 +181,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__ */ diff --git a/board/todor/board.c b/board/todor/board.c index 215725129e..377af50ff3 100644 --- a/board/todor/board.c +++ b/board/todor/board.c @@ -4,7 +4,7 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" @@ -12,7 +12,10 @@ #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi260.h" #include "driver/als_tcs3400.h" +#include "driver/bc12/pi3usb9201.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" @@ -31,7 +34,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" @@ -243,3 +249,120 @@ 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/todor/board.h b/board/todor/board.h index cb6b210f31..011fd8e359 100644 --- a/board/todor/board.h +++ b/board/todor/board.h @@ -54,6 +54,8 @@ #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL /* 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 @@ -84,6 +86,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 #define USBC_PORT_C0_BB_RETIMER_I2C_ADDR 0x40 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ @@ -177,6 +180,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__ */ 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__ */ diff --git a/board/volteer/board.c b/board/volteer/board.c index 7a88d8b165..2eaa4c4408 100644 --- a/board/volteer/board.c +++ b/board/volteer/board.c @@ -4,7 +4,7 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" @@ -12,12 +12,14 @@ #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/retimer/bb_retimer.h" #include "driver/sync.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" +#include "driver/tcpm/tusb422.h" #include "extpower.h" #include "fan.h" #include "fan_chip.h" @@ -34,7 +36,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" @@ -421,3 +426,121 @@ void ppc_interrupt(enum gpio_signal signal) break; } } + +/******************************************************************************/ +/* 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/volteer/board.h b/board/volteer/board.h index de1431b4e7..4aa02f6d6b 100644 --- a/board/volteer/board.h +++ b/board/volteer/board.h @@ -72,6 +72,8 @@ #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL /* 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 @@ -102,6 +104,7 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 +#define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x40 /* USB Type A Features */ #define USB_PORT_COUNT 1 @@ -197,6 +200,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__ */ diff --git a/board/voxel/board.c b/board/voxel/board.c index a46bf3ee83..01b225dcfa 100644 --- a/board/voxel/board.c +++ b/board/voxel/board.c @@ -4,14 +4,18 @@ */ /* Volteer board-specific configuration */ - +#include "bb_retimer.h" #include "button.h" #include "common.h" #include "accelgyro.h" #include "cbi_ec_fw_config.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi160.h" +#include "driver/als_tcs3400.h" +#include "driver/bc12/pi3usb9201.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" @@ -30,7 +34,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" @@ -279,3 +286,120 @@ 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/voxel/board.h b/board/voxel/board.h index 0a055078c2..5adc22c118 100644 --- a/board/voxel/board.h +++ b/board/voxel/board.h @@ -54,6 +54,8 @@ #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL /* 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 @@ -84,7 +86,6 @@ /* Enabling USB4 mode */ #define CONFIG_USB_PD_USB4 #define USBC_PORT_C0_BB_RETIMER_I2C_ADDR 0x40 -#undef USBC_PORT_C1_BB_RETIMER_I2C_ADDR #define USBC_PORT_C1_BB_RETIMER_I2C_ADDR 0x41 /* USB Type A Features */ @@ -151,6 +152,7 @@ #define I2C_ADDR_EEPROM_FLAGS 0x50 #define CONFIG_I2C_MASTER + #ifndef __ASSEMBLER__ #include "gpio_signal.h" @@ -175,6 +177,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__ */ |