diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c index 5c42640d5b..88d4996844 100644 --- a/common/usb_pd_tcpc.c +++ b/common/usb_pd_tcpc.c @@ -744,25 +744,6 @@ static void alert(int port, int mask) tcpc_alert(port); } -void tcpc_init(int port) -{ - int i; - - /* Initialize physical layer */ - pd_hw_init(port, PD_ROLE_DEFAULT); - pd[port].cc_pull = PD_ROLE_DEFAULT == PD_ROLE_SOURCE ? TYPEC_CC_RP : - TYPEC_CC_RD; - - /* make sure PD monitoring is disabled initially */ - pd[port].rx_enabled = 0; - - /* make initial readings of CC voltages */ - for (i = 0; i < 2; i++) { - pd[port].cc_status[i] = cc_voltage_to_status(port, - pd_adc_read(port, i)); - } -} - int tcpc_run(int port, int evt) { int cc, i, res; @@ -1037,6 +1018,34 @@ int tcpc_get_message(int port, uint32_t *payload, int *head) return EC_SUCCESS; } +void tcpc_init(int port) +{ + int i; + + /* Initialize physical layer */ + pd_hw_init(port, PD_ROLE_DEFAULT); + pd[port].cc_pull = PD_ROLE_DEFAULT == PD_ROLE_SOURCE ? TYPEC_CC_RP : + TYPEC_CC_RD; + + /* make sure PD monitoring is disabled initially */ + pd[port].rx_enabled = 0; + + /* make initial readings of CC voltages */ + for (i = 0; i < 2; i++) { + pd[port].cc_status[i] = cc_voltage_to_status(port, + pd_adc_read(port, i)); + } + +#ifdef CONFIG_USB_PD_TCPM_VBUS +#if CONFIG_USB_PD_PORT_COUNT >= 2 + tcpc_set_power_status(port, !gpio_get_level(port ? + GPIO_USB_C1_VBUS_WAKE_L : + GPIO_USB_C0_VBUS_WAKE_L)); +#else + tcpc_set_power_status(port, !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L)); +#endif /* CONFIG_USB_PD_PORT_COUNT >= 2 */ +#endif /* CONFIG_USB_PD_TCPM_VBUS */ +} #ifdef CONFIG_USB_PD_TCPM_VBUS void pd_vbus_evt_p0(enum gpio_signal signal) diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index 939ab9ccf2..926a1dda1b 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -55,31 +55,6 @@ static int init_power_status_mask(int port) } #endif -int tcpm_init(int port) -{ - int rv, err = 0; - - while (1) { - rv = i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), - TCPC_REG_ERROR_STATUS, &err); - /* - * If i2c succeeds and the uninitialized bit is clear, then - * initalization is complete, clear all alert bits and write - * the initial alert mask. - */ - if (rv == EC_SUCCESS && !(err & TCPC_REG_ERROR_STATUS_UNINIT)) { - i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), - TCPC_REG_ALERT, 0xff); -#ifdef CONFIG_USB_PD_TCPM_VBUS - /* Initialize power_status_mask */ - init_power_status_mask(port); -#endif - return init_alert_mask(port); - } - msleep(10); - } -} - int tcpm_get_cc(int port, int *cc1, int *cc2) { int status; @@ -294,3 +269,36 @@ void tcpc_alert(int port) TCPC_TX_COMPLETE_FAILED); } } + +int tcpm_init(int port) +{ + int rv, err = 0; +#ifdef CONFIG_USB_PD_TCPM_VBUS + int power_status; +#endif + + while (1) { + rv = i2c_read16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), + TCPC_REG_ERROR_STATUS, &err); + /* + * If i2c succeeds and the uninitialized bit is clear, then + * initalization is complete, clear all alert bits and write + * the initial alert mask. + */ + if (rv == EC_SUCCESS && !(err & TCPC_REG_ERROR_STATUS_UNINIT)) { + i2c_write16(I2C_PORT_TCPC, I2C_ADDR_TCPC(port), + TCPC_REG_ALERT, 0xff); +#ifdef CONFIG_USB_PD_TCPM_VBUS + /* Initialize power_status_mask */ + init_power_status_mask(port); + /* Read Power Status register */ + tcpm_get_power_status(port, &power_status); + /* Update VBUS status */ + tcpc_vbus[port] = power_status & + TCPC_REG_POWER_VBUS_PRES ? 1 : 0; +#endif + return init_alert_mask(port); + } + msleep(10); + } +}