diff options
-rw-r--r-- | baseboard/hatch/baseboard.c | 85 | ||||
-rw-r--r-- | baseboard/hatch/baseboard.h | 5 | ||||
-rw-r--r-- | board/hatch/board.c | 31 | ||||
-rw-r--r-- | board/hatch/board.h | 8 | ||||
-rw-r--r-- | board/kohaku/board.c | 30 | ||||
-rw-r--r-- | board/kohaku/board.h | 7 |
6 files changed, 107 insertions, 59 deletions
diff --git a/baseboard/hatch/baseboard.c b/baseboard/hatch/baseboard.c index ba90e10fa2..6253c43469 100644 --- a/baseboard/hatch/baseboard.c +++ b/baseboard/hatch/baseboard.c @@ -33,9 +33,6 @@ #define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args) #define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args) -#define USB_PD_PORT_TCPC_0 0 -#define USB_PD_PORT_TCPC_1 1 - /******************************************************************************/ /* Wake up pins */ const enum gpio_signal hibernate_wake_pins[] = { @@ -145,25 +142,6 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, baseboard_chipset_shutdown, HOOK_PRIO_DEFAULT); /******************************************************************************/ -/* USB-C TPCP Configuration */ -const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - [USB_PD_PORT_TCPC_0] = { - .i2c_host_port = I2C_PORT_TCPC0, - .i2c_slave_addr = AN7447_TCPC0_I2C_ADDR, - .drv = &anx7447_tcpm_drv, - /* Alert is active-low, push-pull */ - .flags = 0, - }, - [USB_PD_PORT_TCPC_1] = { - .i2c_host_port = I2C_PORT_TCPC1, - .i2c_slave_addr = PS8751_I2C_ADDR1, - .drv = &ps8xxx_tcpm_drv, - /* Alert is active-low, push-pull */ - .flags = 0, - }, -}; - -/******************************************************************************/ /* USB-C PPC Configuration */ struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = { [USB_PD_PORT_TCPC_0] = { @@ -180,17 +158,6 @@ struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = { }; unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); -struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { - [USB_PD_PORT_TCPC_0] = { - .driver = &anx7447_usb_mux_driver, - .hpd_update = &anx7447_tcpc_update_hpd_status, - }, - [USB_PD_PORT_TCPC_1] = { - .driver = &tcpci_tcpm_usb_mux_driver, - .hpd_update = &ps8xxx_tcpc_update_hpd_status, - } -}; - const struct pi3usb2901_config_t pi3usb2901_bc12_chips[] = { [USB_PD_PORT_TCPC_0] = { .i2c_port = I2C_PORT_PPC0, @@ -251,34 +218,38 @@ uint16_t tcpc_get_alert_status(void) return status; } +static void reset_pd_port(int port, enum gpio_signal reset_gpio, + int hold_delay, int finish_delay) +{ + int level = !!(tcpc_config[port].flags & TCPC_FLAGS_RESET_ACTIVE_HIGH); + + gpio_set_level(reset_gpio, level); + msleep(hold_delay); + gpio_set_level(reset_gpio, !level); + if (finish_delay) + msleep(finish_delay); +} + void board_reset_pd_mcu(void) { /* - * C0: Assert reset to TCPC0 (ANX7447) for required delay (1ms) only if - * we have a battery - * - */ - if (battery_is_present() == BP_YES) { - gpio_set_level(GPIO_USB_C0_TCPC_RST, 1); - msleep(ANX74XX_RESET_HOLD_MS); - gpio_set_level(GPIO_USB_C0_TCPC_RST, 0); - msleep(ANX74XX_RESET_FINISH_MS); - } - /* - * C1: Assert reset to TCPC1 (PS8751) for required delay (1ms) only if - * we have a battery, otherwise we may brown out the system. + * TODO(b/130194590): This should be replaced with a common function + * once the gpio signal and delays are added to tcpc_config struct. */ - if (battery_is_present() == BP_YES) { - /* - * TODO(crbug:846412): After refactor, ensure that battery has - * enough charge to last the reboot as well - */ - gpio_set_level(GPIO_USB_C1_TCPC_RST_ODL, 0); - msleep(PS8XXX_RESET_DELAY_MS); - gpio_set_level(GPIO_USB_C1_TCPC_RST_ODL, 1); - } else { - CPRINTS("Skipping C1 TCPC reset because no battery"); - } + + /* Assert reset to TCPC for required delay only if we have a battery. */ + if (battery_is_present() != BP_YES) + return; + + /* Reset TCPC0 */ + reset_pd_port(USB_PD_PORT_TCPC_0, GPIO_USB_C0_TCPC_RST, + BOARD_TCPC_C0_RESET_HOLD_DELAY, + BOARD_TCPC_C0_RESET_POST_DELAY); + + /* Reset TCPC1 */ + reset_pd_port(USB_PD_PORT_TCPC_1, GPIO_USB_C1_TCPC_RST_ODL, + BOARD_TCPC_C1_RESET_HOLD_DELAY, + BOARD_TCPC_C1_RESET_POST_DELAY); } void board_pd_vconn_ctrl(int port, int cc_pin, int enabled) diff --git a/baseboard/hatch/baseboard.h b/baseboard/hatch/baseboard.h index 5028e556b9..81b91dcb6c 100644 --- a/baseboard/hatch/baseboard.h +++ b/baseboard/hatch/baseboard.h @@ -96,8 +96,6 @@ #define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 #define CONFIG_USB_PD_TCPC_LOW_POWER #define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#define CONFIG_USB_PD_TCPM_ANX7447 -#define CONFIG_USB_PD_TCPM_PS8751 #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_LOGGING #define CONFIG_USB_PD_ALT_MODE @@ -116,6 +114,9 @@ #define CONFIG_CMD_PD_CONTROL #define CONFIG_CMD_PPC_DUMP +#define USB_PD_PORT_TCPC_0 0 +#define USB_PD_PORT_TCPC_1 1 + /* BC 1.2 */ #define CONFIG_USB_CHARGER #define CONFIG_BC12_DETECT_PI3USB9201 diff --git a/board/hatch/board.c b/board/hatch/board.c index ae4a26aad4..4b1f8fa883 100644 --- a/board/hatch/board.c +++ b/board/hatch/board.c @@ -14,6 +14,9 @@ #include "driver/accelgyro_bmi160.h" #include "driver/als_opt3001.h" #include "driver/ppc/sn5s330.h" +#include "driver/tcpm/anx7447.h" +#include "driver/tcpm/ps8xxx.h" +#include "driver/tcpm/tcpci.h" #include "ec_commands.h" #include "extpower.h" #include "fan.h" @@ -115,6 +118,34 @@ const struct pwm_t pwm_channels[] = { BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); /******************************************************************************/ +/* USB-C TPCP Configuration */ +const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .i2c_host_port = I2C_PORT_TCPC0, + .i2c_slave_addr = AN7447_TCPC0_I2C_ADDR, + .drv = &anx7447_tcpm_drv, + .flags = TCPC_FLAGS_RESET_ACTIVE_HIGH, + }, + [USB_PD_PORT_TCPC_1] = { + .i2c_host_port = I2C_PORT_TCPC1, + .i2c_slave_addr = PS8751_I2C_ADDR1, + .drv = &ps8xxx_tcpm_drv, + .flags = 0, + }, +}; + +struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .driver = &anx7447_usb_mux_driver, + .hpd_update = &anx7447_tcpc_update_hpd_status, + }, + [USB_PD_PORT_TCPC_1] = { + .driver = &tcpci_tcpm_usb_mux_driver, + .hpd_update = &ps8xxx_tcpc_update_hpd_status, + } +}; + +/******************************************************************************/ /* Sensors */ /* Base Sensor mutex */ static struct mutex g_base_mutex; diff --git a/board/hatch/board.h b/board/hatch/board.h index 0548147c94..3370b46cd4 100644 --- a/board/hatch/board.h +++ b/board/hatch/board.h @@ -49,6 +49,14 @@ #define CONFIG_ALS_OPT3001 #define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 +/* USB Type C and USB PD defines */ +#define CONFIG_USB_PD_TCPM_ANX7447 +#define CONFIG_USB_PD_TCPM_PS8751 +#define BOARD_TCPC_C0_RESET_HOLD_DELAY ANX74XX_RESET_HOLD_MS +#define BOARD_TCPC_C0_RESET_POST_DELAY ANX74XX_RESET_HOLD_MS +#define BOARD_TCPC_C1_RESET_HOLD_DELAY PS8XXX_RESET_DELAY_MS +#define BOARD_TCPC_C1_RESET_POST_DELAY 0 + /* Volume Button feature */ #define CONFIG_VOLUME_BUTTONS #define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL diff --git a/board/kohaku/board.c b/board/kohaku/board.c index db5d3d3399..d14a327655 100644 --- a/board/kohaku/board.c +++ b/board/kohaku/board.c @@ -14,6 +14,8 @@ #include "driver/accelgyro_bmi160.h" #include "driver/als_opt3001.h" #include "driver/ppc/sn5s330.h" +#include "driver/tcpm/ps8xxx.h" +#include "driver/tcpm/tcpci.h" #include "ec_commands.h" #include "extpower.h" #include "fan.h" @@ -115,6 +117,34 @@ const struct pwm_t pwm_channels[] = { BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); /******************************************************************************/ +/* USB-C TPCP Configuration */ +const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .i2c_host_port = I2C_PORT_TCPC0, + .i2c_slave_addr = PS8751_I2C_ADDR1, + .drv = &ps8xxx_tcpm_drv, + .flags = 0, + }, + [USB_PD_PORT_TCPC_1] = { + .i2c_host_port = I2C_PORT_TCPC1, + .i2c_slave_addr = PS8751_I2C_ADDR1, + .drv = &ps8xxx_tcpm_drv, + .flags = 0, + }, +}; + +struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .driver = &tcpci_tcpm_usb_mux_driver, + .hpd_update = &ps8xxx_tcpc_update_hpd_status, + }, + [USB_PD_PORT_TCPC_1] = { + .driver = &tcpci_tcpm_usb_mux_driver, + .hpd_update = &ps8xxx_tcpc_update_hpd_status, + } +}; + +/******************************************************************************/ /* Sensors */ /* Base Sensor mutex */ static struct mutex g_base_mutex; diff --git a/board/kohaku/board.h b/board/kohaku/board.h index 73358c744c..aa609a051b 100644 --- a/board/kohaku/board.h +++ b/board/kohaku/board.h @@ -49,6 +49,13 @@ #define CONFIG_ALS_OPT3001 #define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 +/* USB Type C and USB PD defines */ +#define CONFIG_USB_PD_TCPM_PS8751 +#define BOARD_TCPC_C0_RESET_HOLD_DELAY PS8XXX_RESET_DELAY_MS +#define BOARD_TCPC_C0_RESET_POST_DELAY 0 +#define BOARD_TCPC_C1_RESET_HOLD_DELAY PS8XXX_RESET_DELAY_MS +#define BOARD_TCPC_C1_RESET_POST_DELAY 0 + /* Volume Button feature */ #define CONFIG_VOLUME_BUTTONS #define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL |