diff options
author | Denis Brockus <dbrockus@chromium.org> | 2019-12-18 14:38:39 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-08 19:59:52 +0000 |
commit | 069a813a70a45af5191b2ada0df6bfe6a4dace5c (patch) | |
tree | 619d8cbfedf9c123253825a30cb07c97127cb0d6 /common/usbc | |
parent | 8d09ae089e5f301f5d4545d125e80a997232e576 (diff) | |
download | chrome-ec-069a813a70a45af5191b2ada0df6bfe6a4dace5c.tar.gz |
TCPMv2: Add unattached polarity
Added the tri-state polarity that was added to the
old stack so the tcpci set cc would set the correct
CC line(s).
BUG=b:146003980
BRANCH=none
TEST=Charging works with both plug orientations with AP on
TEST=Device works with both plug orientations with AP on
TEST=Charging works with both plug orientations with AP off
Change-Id: I191dd86c645a46a6bf8acfda865eb0b7ab8388b4
Signed-off-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1976803
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/usbc')
-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 c507942072..4a1345cbae 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); @@ -2101,13 +2104,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); @@ -2607,7 +2615,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); /* @@ -2641,7 +2649,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); /* @@ -2829,10 +2837,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); @@ -2903,10 +2915,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: /* |