diff options
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r-- | common/usb_pd_protocol.c | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 07b50363b9..abf75e8004 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -29,6 +29,7 @@ #include "usb_common.h" #include "usb_mux.h" #include "usb_pd.h" +#include "usb_pd_flags.h" #include "usb_pd_tcpm.h" #include "usb_pd_tcpc.h" #include "usbc_ocp.h" @@ -1570,10 +1571,10 @@ static void handle_data_request(int port, uint32_t head, if ((pd[port].task_state == PD_STATE_SNK_DISCOVERY) || (pd[port].task_state == PD_STATE_SNK_TRANSITION) || (pd[port].task_state == PD_STATE_SNK_REQUESTED) -#ifdef CONFIG_USB_PD_VBUS_DETECT_NONE - || (pd[port].task_state == - PD_STATE_SNK_HARD_RESET_RECOVER) -#endif + || ((get_usb_pd_vbus_detect() == + USB_PD_VBUS_DETECT_NONE) + && (pd[port].task_state == + PD_STATE_SNK_HARD_RESET_RECOVER)) || (pd[port].task_state == PD_STATE_SNK_READY)) { #ifdef CONFIG_USB_PD_REV30 /* @@ -4098,52 +4099,58 @@ void pd_task(void *u) case PD_STATE_SNK_HARD_RESET_RECOVER: if (pd[port].last_state != pd[port].task_state) pd[port].flags |= PD_FLAGS_CHECK_IDENTITY; -#ifdef CONFIG_USB_PD_VBUS_DETECT_NONE - /* - * Can't measure vbus state so this is the maximum - * recovery time for the source. - */ - if (pd[port].last_state != pd[port].task_state) - set_state_timeout(port, get_time().val + + + if (get_usb_pd_vbus_detect() == + USB_PD_VBUS_DETECT_NONE) { + /* + * Can't measure vbus state so this is the + * maximum recovery time for the source. + */ + if (pd[port].last_state != pd[port].task_state) + set_state_timeout(port, get_time().val + PD_T_SAFE_0V + PD_T_SRC_RECOVER_MAX + PD_T_SRC_TURN_ON, PD_STATE_SNK_DISCONNECTED); -#else - /* Wait for VBUS to go low and then high*/ - if (pd[port].last_state != pd[port].task_state) { - snk_hard_reset_vbus_off = 0; - set_state_timeout(port, + } else { +#ifndef CONFIG_USB_PD_VBUS_DETECT_NONE + /* Wait for VBUS to go low and then high*/ + if (pd[port].last_state != + pd[port].task_state) { + snk_hard_reset_vbus_off = 0; + set_state_timeout(port, get_time().val + PD_T_SAFE_0V, hard_reset_count < PD_HARD_RESET_COUNT ? PD_STATE_HARD_RESET_SEND : PD_STATE_SNK_DISCOVERY); - } + } - if (!pd_is_vbus_present(port) && - !snk_hard_reset_vbus_off) { - /* VBUS has gone low, reset timeout */ - snk_hard_reset_vbus_off = 1; - set_state_timeout(port, + if (!pd_is_vbus_present(port) && + !snk_hard_reset_vbus_off) { + /* VBUS has gone low, reset timeout */ + snk_hard_reset_vbus_off = 1; + set_state_timeout(port, get_time().val + PD_T_SRC_RECOVER_MAX + PD_T_SRC_TURN_ON, PD_STATE_SNK_DISCONNECTED); - } - if (pd_is_vbus_present(port) && - snk_hard_reset_vbus_off) { - /* VBUS went high again */ - set_state(port, PD_STATE_SNK_DISCOVERY); - timeout = 10*MSEC; - } + } + if (pd_is_vbus_present(port) && + snk_hard_reset_vbus_off) { + /* VBUS went high again */ + set_state(port, PD_STATE_SNK_DISCOVERY); + timeout = 10*MSEC; + } - /* - * Don't need to set timeout because VBUS changing - * will trigger an interrupt and wake us up. - */ + /* + * Don't need to set timeout because VBUS + * changing will trigger an interrupt and + * wake us up. + */ #endif + } break; case PD_STATE_SNK_DISCOVERY: /* Wait for source cap expired only if we are enabled */ @@ -4172,7 +4179,8 @@ void pd_task(void *u) int batt_soc = usb_get_battery_soc(); if (batt_soc < CONFIG_USB_PD_RESET_MIN_BATT_SOC || - battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED) + battery_get_disconnect_state() != + BATTERY_NOT_DISCONNECTED) pd[port].flags |= PD_FLAGS_SNK_WAITING_BATT; else |