Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: tcpci: don't touch CC line if it's Vconn source

With the AMS and Collision Avoidance, tcpm often needs to change the CC's
termination. When one CC line is sourcing Vconn, if we still change its
termination, the voltage of the another CC line is likely to be fluctuant
and unstable.

Therefore, we should verify whether a CC line is sourcing Vconn before
changing its termination and only change the termination that is not
a Vconn line. This can be done by reading the Vconn Present bit of
POWER_ STATUS register. To determine the polarity, we can read the
Plug Orientation bit of TCPC_CONTROL register. Since Vconn can only be
sourced if Plug Orientation is set.

Fixes: 0908c5aca31e ("usb: typec: tcpm: AMS and Collision Avoidance")
cc: <stable@vger.kernel.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Link: https://lore.kernel.org/r/20220113092943.752372-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Xu Yang and committed by
Greg Kroah-Hartman
5638b0df 945c37ed

+27
+26
drivers/usb/typec/tcpm/tcpci.c
··· 75 75 static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) 76 76 { 77 77 struct tcpci *tcpci = tcpc_to_tcpci(tcpc); 78 + bool vconn_pres; 79 + enum typec_cc_polarity polarity = TYPEC_POLARITY_CC1; 78 80 unsigned int reg; 79 81 int ret; 82 + 83 + ret = regmap_read(tcpci->regmap, TCPC_POWER_STATUS, &reg); 84 + if (ret < 0) 85 + return ret; 86 + 87 + vconn_pres = !!(reg & TCPC_POWER_STATUS_VCONN_PRES); 88 + if (vconn_pres) { 89 + ret = regmap_read(tcpci->regmap, TCPC_TCPC_CTRL, &reg); 90 + if (ret < 0) 91 + return ret; 92 + 93 + if (reg & TCPC_TCPC_CTRL_ORIENTATION) 94 + polarity = TYPEC_POLARITY_CC2; 95 + } 80 96 81 97 switch (cc) { 82 98 case TYPEC_CC_RA: ··· 126 110 reg = (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT) | 127 111 (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT); 128 112 break; 113 + } 114 + 115 + if (vconn_pres) { 116 + if (polarity == TYPEC_POLARITY_CC2) { 117 + reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT); 118 + reg |= (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT); 119 + } else { 120 + reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT); 121 + reg |= (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT); 122 + } 129 123 } 130 124 131 125 ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
+1
drivers/usb/typec/tcpm/tcpci.h
··· 98 98 #define TCPC_POWER_STATUS_SOURCING_VBUS BIT(4) 99 99 #define TCPC_POWER_STATUS_VBUS_DET BIT(3) 100 100 #define TCPC_POWER_STATUS_VBUS_PRES BIT(2) 101 + #define TCPC_POWER_STATUS_VCONN_PRES BIT(1) 101 102 #define TCPC_POWER_STATUS_SINKING_VBUS BIT(0) 102 103 103 104 #define TCPC_FAULT_STATUS 0x1f