diff options
-rw-r--r-- | driver/tcpm/ps8xxx.c | 21 | ||||
-rw-r--r-- | driver/tcpm/tcpci.c | 29 |
2 files changed, 32 insertions, 18 deletions
diff --git a/driver/tcpm/ps8xxx.c b/driver/tcpm/ps8xxx.c index 09e4a404b9..21a20566ff 100644 --- a/driver/tcpm/ps8xxx.c +++ b/driver/tcpm/ps8xxx.c @@ -92,6 +92,25 @@ int ps8xxx_tcpc_get_fw_version(int port, int *version) return tcpc_read(port, FW_VER_REG, version); } +#ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC +/* + * Read Vbus level directly instead of using the cached version because some + * TPCPs do not fire the Vbus level change interrupt correctly after resuming + * from low-power mode. + */ +int ps8xxx_tcpm_get_vbus_level(int port) +{ + int reg; + + /* Read Power Status register */ + if (tcpc_read(port, TCPC_REG_POWER_STATUS, ®) == EC_SUCCESS) + return reg & TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0; + + /* If read failed, report that Vbus is off */ + return 0; +} +#endif + static int ps8xxx_tcpc_bist_mode_2(int port) { int rv; @@ -141,7 +160,7 @@ const struct tcpm_drv ps8xxx_tcpm_drv = { .release = &ps8xxx_tcpm_release, .get_cc = &tcpci_tcpm_get_cc, #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC - .get_vbus_level = &tcpci_tcpm_get_vbus_level, + .get_vbus_level = &ps8xxx_tcpm_get_vbus_level, #endif .select_rp_value = &tcpci_tcpm_select_rp_value, .set_cc = &tcpci_tcpm_set_cc, diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index 60083e312c..fd5488ca56 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -18,6 +18,8 @@ #include "usb_pd_tcpc.h" #include "util.h" +static int tcpc_vbus[CONFIG_USB_PD_PORT_COUNT]; + /* Save the selected rp value */ static int selected_rp[CONFIG_USB_PD_PORT_COUNT]; @@ -94,12 +96,10 @@ int tcpci_tcpm_get_cc(int port, int *cc1, int *cc2) return rv; } -#ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC static int tcpci_tcpm_get_power_status(int port, int *status) { return tcpc_read(port, TCPC_REG_POWER_STATUS, status); } -#endif /* #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC */ int tcpci_tcpm_select_rp_value(int port, int rp) { @@ -221,14 +221,7 @@ int tcpci_tcpm_set_rx_enable(int port, int enable) #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC int tcpci_tcpm_get_vbus_level(int port) { - int reg; - - /* Read Power Status register */ - if (tcpci_tcpm_get_power_status(port, ®) == EC_SUCCESS) - return reg & TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0; - - /* If read failed, report that Vbus is off */ - return 0; + return tcpc_vbus[port]; } #endif @@ -326,13 +319,15 @@ void tcpci_tcpc_alert(int port) */ task_set_event(PD_PORT_TO_TASK_ID(port), PD_EVENT_TCPC_RESET, 0); -#if defined(CONFIG_USB_PD_VBUS_DETECT_TCPC) && defined(CONFIG_USB_CHARGER) } else { /* Read Power Status register */ tcpci_tcpm_get_power_status(port, ®); + /* Update VBUS status */ + tcpc_vbus[port] = reg & + TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0; +#if defined(CONFIG_USB_PD_VBUS_DETECT_TCPC) && defined(CONFIG_USB_CHARGER) /* Update charge manager with new VBUS state */ - usb_charger_vbus_change(port, - reg & TCPC_REG_POWER_STATUS_VBUS_PRES); + usb_charger_vbus_change(port, tcpc_vbus[port]); task_wake(PD_PORT_TO_TASK_ID(port)); #endif /* CONFIG_USB_PD_VBUS_DETECT_TCPC && CONFIG_USB_CHARGER */ } @@ -456,12 +451,12 @@ int tcpci_tcpm_init(int port) msleep(10); } - /* Set Power Status mask */ - init_power_status_mask(port); - - /* Clear alert request and set alert mask */ tcpc_write16(port, TCPC_REG_ALERT, 0xffff); /* Initialize power_status_mask */ + init_power_status_mask(port); + /* Update VBUS status */ + tcpc_vbus[port] = power_status & + TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0; error = init_alert_mask(port); if (error) return error; |