summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-12-18 14:38:39 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-08 17:57:52 +0000
commitf08390c6974ba54746adc45b84450df3aae8c753 (patch)
treedbbca2ab79528e52fa1df221a320518df88064f1
parent5f6a1a7cdbec4bf1d2b8cec32794cb03edbef828 (diff)
downloadchrome-ec-f08390c6974ba54746adc45b84450df3aae8c753.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/+/1991851 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org> Tested-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c64
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:
/*