diff options
author | Denis Brockus <dbrockus@chromium.org> | 2020-01-27 09:45:58 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-30 17:45:27 +0000 |
commit | 7dec638eb577aaa3a00d0551d73c276b94ebacb2 (patch) | |
tree | 18bae7940876301320ce569984f2d4ee58dea091 | |
parent | 41614aba60ca77cd566b9bf29494aaf562225292 (diff) | |
download | chrome-ec-7dec638eb577aaa3a00d0551d73c276b94ebacb2.tar.gz |
usb: differentiate DTS polarity and normal device polarity
When we have SNK_DTS polarity, we still want to drive both CC
lines with the appropriate pull. SRC_DTS should not show as
having a polarity. Non-DTS should show the correct polarity.
We were only handling the last sentence of that.
BUG=b:147754772
BRANCH=none
TEST=verify SuzyQ works on zork
Change-Id: I013f9d881427d6d97b655f88cfb3a94e3ed10c61
Signed-off-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2022914
Tested-by: David Schneider <dnschneid@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | common/usb_common.c | 17 | ||||
-rw-r--r-- | driver/tcpm/anx7447.c | 3 | ||||
-rw-r--r-- | driver/tcpm/anx74xx.c | 4 | ||||
-rw-r--r-- | driver/tcpm/fusb302.c | 6 | ||||
-rw-r--r-- | driver/tcpm/tcpci.c | 7 | ||||
-rw-r--r-- | include/usb_pd_tcpm.h | 44 |
6 files changed, 67 insertions, 14 deletions
diff --git a/common/usb_common.c b/common/usb_common.c index fb3ebe84e0..9ac17802d2 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -69,8 +69,11 @@ typec_current_t usb_get_typec_current_limit(enum tcpc_cc_polarity polarity, enum tcpc_cc_voltage_status cc1, enum tcpc_cc_voltage_status cc2) { typec_current_t charge = 0; - enum tcpc_cc_voltage_status cc = polarity ? cc2 : cc1; - enum tcpc_cc_voltage_status cc_alt = polarity ? cc1 : cc2; + enum tcpc_cc_voltage_status cc; + enum tcpc_cc_voltage_status cc_alt; + + cc = polarity_rm_dts(polarity) ? cc2 : cc1; + cc_alt = polarity_rm_dts(polarity) ? cc1 : cc2; switch (cc) { case TYPEC_CC_VOLT_RP_3_0: @@ -110,16 +113,20 @@ enum tcpc_cc_polarity get_snk_polarity(enum tcpc_cc_voltage_status cc1, * TYPEC_CC_VOLT_RP_1_5 > TYPEC_CC_VOLT_RP_DEF * TYPEC_CC_VOLT_RP_DEF > TYPEC_CC_VOLT_OPEN */ - return cc2 > cc1; + if (cc_is_src_dbg_acc(cc1, cc2)) + return (cc1 > cc2) ? POLARITY_CC1_DTS : POLARITY_CC2_DTS; + + return (cc1 > cc2) ? POLARITY_CC1 : POLARITY_CC2; } enum tcpc_cc_polarity get_src_polarity(enum tcpc_cc_voltage_status cc1, enum tcpc_cc_voltage_status cc2) { - if (cc_is_open(cc1, cc2)) + if (cc_is_open(cc1, cc2) || + cc_is_snk_dbg_acc(cc1, cc2)) return POLARITY_NONE; - return cc1 != TYPEC_CC_VOLT_RD; + return (cc1 == TYPEC_CC_VOLT_RD) ? POLARITY_CC1 : POLARITY_CC2; } enum pd_cc_states pd_get_cc_state( diff --git a/driver/tcpm/anx7447.c b/driver/tcpm/anx7447.c index a765af5c2e..ed4e601f6c 100644 --- a/driver/tcpm/anx7447.c +++ b/driver/tcpm/anx7447.c @@ -655,7 +655,8 @@ static int anx7447_set_polarity(int port, enum tcpc_cc_polarity polarity) return tcpc_update8(port, TCPC_REG_TCPC_CTRL, TCPC_REG_TCPC_CTRL_SET(1), - (polarity) ? MASK_SET : MASK_CLR); + polarity_rm_dts(polarity) + ? MASK_SET : MASK_CLR); } /* diff --git a/driver/tcpm/anx74xx.c b/driver/tcpm/anx74xx.c index c91c39bc58..7cdde05410 100644 --- a/driver/tcpm/anx74xx.c +++ b/driver/tcpm/anx74xx.c @@ -776,7 +776,7 @@ static int anx74xx_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) return EC_SUCCESS; rv |= tcpc_read(port, ANX74XX_REG_CC_SOFTWARE_CTRL, ®); - if (polarity) /* Inform ANX to use CC2 */ + if (polarity_rm_dts(polarity)) /* Inform ANX to use CC2 */ reg &= ~ANX74XX_REG_SELECT_CC1; else /* Inform ANX to use CC1 */ reg |= ANX74XX_REG_SELECT_CC1; @@ -787,7 +787,7 @@ static int anx74xx_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) /* Update mux polarity */ #ifdef CONFIG_USB_PD_TCPM_MUX mux_state = anx[port].mux_state & ~USB_PD_MUX_POLARITY_INVERTED; - if (polarity) + if (polarity_rm_dts(polarity)) mux_state |= USB_PD_MUX_POLARITY_INVERTED; anx74xx_tcpm_mux_set(port, mux_state); #endif diff --git a/driver/tcpm/fusb302.c b/driver/tcpm/fusb302.c index dc31228506..691e876435 100644 --- a/driver/tcpm/fusb302.c +++ b/driver/tcpm/fusb302.c @@ -586,7 +586,7 @@ static int fusb302_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) if (state[port].vconn_enabled) { /* set VCONN switch to be non-CC line */ - if (polarity) + if (polarity_rm_dts(polarity)) reg |= TCPC_REG_SWITCHES0_VCONN_CC1; else reg |= TCPC_REG_SWITCHES0_VCONN_CC2; @@ -597,7 +597,7 @@ static int fusb302_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) reg &= ~TCPC_REG_SWITCHES0_MEAS_CC2; /* set rx polarity */ - if (polarity) + if (polarity_rm_dts(polarity)) reg |= TCPC_REG_SWITCHES0_MEAS_CC2; else reg |= TCPC_REG_SWITCHES0_MEAS_CC1; @@ -611,7 +611,7 @@ static int fusb302_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) reg &= ~TCPC_REG_SWITCHES1_TXCC2_EN; /* set tx polarity */ - if (polarity) + if (polarity_rm_dts(polarity)) reg |= TCPC_REG_SWITCHES1_TXCC2_EN; else reg |= TCPC_REG_SWITCHES1_TXCC1_EN; diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index c369d0c48b..f97644a169 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -418,8 +418,8 @@ int tcpci_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) /* * TCPCI sets the CC lines based on polarity. If it is set to - * no connection then both CC lines are driven, otherwise only - * one is driven. + * no connection or SRC Debug Accessory then both CC lines are + * driven, otherwise only one is driven. */ rv = tcpm_set_cc(port, tcpci_get_cached_pull(port)); if (rv) @@ -431,7 +431,8 @@ int tcpci_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) return tcpc_update8(port, TCPC_REG_TCPC_CTRL, TCPC_REG_TCPC_CTRL_SET(1), - (polarity) ? MASK_SET : MASK_CLR); + polarity_rm_dts(polarity) + ? MASK_SET : MASK_CLR); } #ifdef CONFIG_USBC_PPC diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 9a4140afb4..97b0ec0864 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -50,11 +50,46 @@ enum tcpc_rp_value { }; enum tcpc_cc_polarity { + /* + * _NONE: either disconnected or connected to a SNK Debug + * Accessory + */ POLARITY_NONE = -1, + + /* + * _CCx: is used to indicate the polarity while not connected to + * a Debug Accessory. Only one CC line will assert a resistor and + * the other will be open. + */ POLARITY_CC1 = 0, POLARITY_CC2 = 1, + + /* + * CCx_DTS is used to indicate the polarity while connected to a + * SRC Debug Accessory. Assert resistors on both lines. + */ + POLARITY_CC1_DTS = 2, + POLARITY_CC2_DTS = 3, + + /* + * The current TCPC code relies on these specific POLARITY values. + * Adding in a check to verify if the list grows for any reason + * that this will give a hint that other places need to be + * adjusted. + */ + POLARITY_COUNT }; +/** + * Returns whether the polarity without the DTS extension + */ +static inline enum tcpc_cc_polarity polarity_rm_dts( + enum tcpc_cc_polarity polarity) +{ + BUILD_ASSERT(POLARITY_COUNT == 4); + return (polarity == POLARITY_NONE) ? polarity : polarity & BIT(0); +} + enum tcpm_transmit_type { TCPC_TX_SOP = 0, TCPC_TX_SOP_PRIME = 1, @@ -104,6 +139,15 @@ static inline int cc_is_snk_dbg_acc(enum tcpc_cc_voltage_status cc1, } /** + * Returns true if we detect the port partner is a src debug accessory. + */ +static inline int cc_is_src_dbg_acc(enum tcpc_cc_voltage_status cc1, + enum tcpc_cc_voltage_status cc2) +{ + return cc_is_rp(cc1) && cc_is_rp(cc2); +} + +/** * Returns true if the port partner is an audio accessory. */ static inline int cc_is_audio_acc(enum tcpc_cc_voltage_status cc1, |