summaryrefslogtreecommitdiff
path: root/driver/tcpm/anx74xx.c
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-12-11 16:04:03 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-08 17:15:04 +0000
commitb560141a1d8ce034ae5b85718c163fb7ab83c24f (patch)
tree1b0505d2eeaa5bc7c1f521e6fed1015e9ab2d023 /driver/tcpm/anx74xx.c
parent5750cc926d64033fe7f19b760165011120915ab0 (diff)
downloadchrome-ec-b560141a1d8ce034ae5b85718c163fb7ab83c24f.tar.gz
tcpci: Only drive one CC line when attached
Some of the NCT38XX driver code was more generic TCPCI than specific to the chip. So moved a number of the functions over to be generically handled. In doing this I propagated the idea of tri-state polarity. It is now either NORMAL, FLIPPED, or NONE for unattached. This is needed for the generic handling of correctly setting CC. This required changing the polarity from NONE to the appropriate detected polarity when in auto toggle. tcpci_tcpm_set_cc will now only set a single CC line when attached and both when unattached. BUG=b:146003980, chromium:951681 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: Ie4b5cc998902a346a4f4a2c1480204b3a81017dd Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1967932 Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'driver/tcpm/anx74xx.c')
-rw-r--r--driver/tcpm/anx74xx.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/driver/tcpm/anx74xx.c b/driver/tcpm/anx74xx.c
index 0e7ec021d8..2e37d65a13 100644
--- a/driver/tcpm/anx74xx.c
+++ b/driver/tcpm/anx74xx.c
@@ -45,9 +45,6 @@ struct anx_state {
static struct anx_state anx[CONFIG_USB_PD_PORT_MAX_COUNT];
-/* Save the selected rp value */
-static int selected_rp[CONFIG_USB_PD_PORT_MAX_COUNT];
-
#ifdef CONFIG_USB_PD_DECODE_SOP
/* Save the message address */
static int msg_sop[CONFIG_USB_PD_PORT_MAX_COUNT];
@@ -699,8 +696,10 @@ static int anx74xx_rp_control(int port, int rp)
static int anx74xx_tcpm_select_rp_value(int port, int rp)
{
+ /* Keep track of current RP value */
+ tcpci_set_cached_rp(port, rp);
+
/* For ANX3429 cannot get cc correctly when Rp != USB_Default */
- selected_rp[port] = rp;
return EC_SUCCESS;
}
@@ -728,6 +727,9 @@ static int anx74xx_tcpm_set_cc(int port, int pull)
int rv = EC_SUCCESS;
int reg;
+ /* Keep track of current CC pull value */
+ tcpci_set_cached_pull(port, pull);
+
/* Enable CC software Control */
rv = anx74xx_cc_software_ctrl(port, 1);
if (rv)
@@ -758,10 +760,20 @@ static int anx74xx_tcpm_set_cc(int port, int pull)
return rv;
}
-static int anx74xx_tcpm_set_polarity(int port, int polarity)
+static int anx74xx_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity)
{
int reg, mux_state, rv = EC_SUCCESS;
+ /*
+ * 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. This driver does not appear to do this. If
+ * that changes, this would be the location you would want to
+ * adjust the CC lines for the current polarity
+ */
+ if (polarity == POLARITY_NONE)
+ return EC_SUCCESS;
+
rv |= tcpc_read(port, ANX74XX_REG_CC_SOFTWARE_CTRL, &reg);
if (polarity) /* Inform ANX to use CC2 */
reg &= ~ANX74XX_REG_SELECT_CC1;
@@ -836,7 +848,7 @@ static int anx74xx_tcpm_set_rx_enable(int port, int enable)
if (enable) {
reg &= ~(ANX74XX_REG_IRQ_CC_MSG_INT);
anx74xx_tcpm_set_auto_good_crc(port, 1);
- anx74xx_rp_control(port, selected_rp[port]);
+ anx74xx_rp_control(port, tcpci_get_cached_rp(port));
} else {
/* Disable RX message by masking interrupt */
reg |= (ANX74XX_REG_IRQ_CC_MSG_INT);
@@ -1033,6 +1045,9 @@ static int anx74xx_tcpm_init(int port)
{
int rv = 0, reg;
+ /* Start with an unknown connection */
+ tcpci_set_cached_pull(port, TYPEC_CC_OPEN);
+
memset(&anx[port], 0, sizeof(struct anx_state));
/* Bring chip in normal mode to work */
anx74xx_set_power_mode(port, ANX74XX_NORMAL_MODE);