diff options
-rw-r--r-- | common/usbc/usb_tc_drp_acc_trysrc_sm.c | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 86d6ef28c2..cc4cebb037 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -192,8 +192,8 @@ static struct type_c { /* Power supply reset sequence during a hard reset */ enum ps_reset_sequence ps_reset_state; #endif - /* Port polarity : 0 => CC1 is CC line, 1 => CC2 is CC line */ - uint8_t polarity; + /* Port polarity */ + enum tcpc_cc_polarity polarity; /* port flags, see TC_FLAGS_* */ uint32_t flags; /* event timeout */ @@ -832,6 +832,9 @@ static void restart_tc_sm(int port, enum usb_tc_state start_state) void tc_state_init(int port) { + /* Start as not connected */ + tc[port].polarity = POLARITY_NONE; + /* Unattached.SNK is the default starting state. */ restart_tc_sm(port, TC_UNATTACHED_SNK); @@ -2100,13 +2103,18 @@ static void tc_attached_snk_run(const int port) static void tc_attached_snk_exit(const int port) { - /* - * If supplying VCONN, the port shall cease to supply - * it within tVCONNOFF of exiting Attached.SNK if not PR swapping. - */ - if (TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON) && - !TC_CHK_FLAG(port, TC_FLAGS_DO_PR_SWAP)) - set_vconn(port, 0); + if (!TC_CHK_FLAG(port, TC_FLAGS_DO_PR_SWAP)) { + /* + * If supplying VCONN, the port shall cease to supply + * it within tVCONNOFF of exiting Attached.SNK if not + * PR swapping. + */ + if (TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON)) + set_vconn(port, 0); + + /* Unattached should not have a polarity */ + tc[port].polarity = POLARITY_NONE; + } /* Clear flags after checking Vconn status */ TC_CLR_FLAG(port, TC_FLAGS_DO_PR_SWAP | TC_FLAGS_POWER_OFF_SNK); @@ -2606,7 +2614,7 @@ static void tc_attached_src_entry(const int port) } else { /* Get connector orientation */ tcpm_get_cc(port, &cc1, &cc2); - tc[port].polarity = (cc1 != TYPEC_CC_VOLT_RD); + tc[port].polarity = get_src_polarity(cc1, cc2); set_polarity(port, tc[port].polarity); /* @@ -2640,7 +2648,7 @@ static void tc_attached_src_entry(const int port) #else /* Get connector orientation */ tcpm_get_cc(port, &cc1, &cc2); - tc[port].polarity = (cc1 != TYPEC_CC_VOLT_RD); + tc[port].polarity = get_src_polarity(cc1, cc2); set_polarity(port, tc[port].polarity); /* @@ -2828,10 +2836,14 @@ static void tc_attached_src_exit(const int port) */ tc_src_power_off(port); - /* Disable VCONN if not power role swapping */ - if (TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON) && - !TC_CHK_FLAG(port, TC_FLAGS_DO_PR_SWAP)) - set_vconn(port, 0); + if (!TC_CHK_FLAG(port, TC_FLAGS_DO_PR_SWAP)) { + /* Disable VCONN if not power role swapping */ + if (TC_CHK_FLAG(port, TC_FLAGS_VCONN_ON)) + set_vconn(port, 0); + + /* Unattached should not have a polarity */ + tc[port].polarity = POLARITY_NONE; + } /* Clear PR swap flag after checking for Vconn */ TC_CLR_FLAG(port, TC_FLAGS_DO_PR_SWAP); @@ -2902,10 +2914,28 @@ static void tc_drp_auto_toggle_run(const int port) set_state_tc(port, PD_DEFAULT_STATE(port)); break; case DRP_TC_UNATTACHED_SNK: - set_state_tc(port, TC_UNATTACHED_SNK); + /* + * The TCPCI comes out of auto toggle with a prospective + * connection. It is expecting us to set the CC lines to + * what it is thinking is best or it goes direct back to + * unattached. So get the SNK polarity to be able to setup + * the CC lines to avoid this. + */ + tc[port].polarity = get_snk_polarity(cc1, cc2); + + set_state_tc(port, TC_ATTACH_WAIT_SNK); break; case DRP_TC_UNATTACHED_SRC: - set_state_tc(port, TC_UNATTACHED_SRC); + /* + * The TCPCI comes out of auto toggle with a prospective + * connection. It is expecting us to set the CC lines to + * what it is thinking is best or it goes direct back to + * unattached. So get the SRC polarity to be able to setup + * the CC lines to avoid this. + */ + tc[port].polarity = get_src_polarity(cc1, cc2); + + set_state_tc(port, TC_ATTACH_WAIT_SRC); break; case DRP_TC_DRP_AUTO_TOGGLE: /* |