summaryrefslogtreecommitdiff
path: root/common/usb_pd_protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r--common/usb_pd_protocol.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 78578aaf9f..c7a7bbe6e9 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -317,6 +317,29 @@ static inline int pd_is_vbus_present(int port)
}
#endif
+static void set_polarity(int port, int polarity)
+{
+ tcpm_set_polarity(port, polarity);
+#ifdef CONFIG_USBC_PPC
+ ppc_set_polarity(port, polarity);
+#endif /* defined(CONFIG_USBC_PPC) */
+}
+
+#ifdef CONFIG_USBC_VCONN
+static void set_vconn(int port, int enable)
+{
+#ifdef CONFIG_USBC_PPC
+ /*
+ * USB-C PPCs can source their own Vconn. No need to tell the TCPC
+ * to source its own.
+ */
+ ppc_set_vconn(port, enable);
+#else /* !defined(CONFIG_USBC_PPC) */
+ tcpm_set_vconn(port, enable);
+#endif /* defined(CONFIG_USBC_PPC) */
+}
+#endif /* defined(CONFIG_USBC_VCONN) */
+
static inline void set_state(int port, enum pd_states next_state)
{
enum pd_states last_state = pd[port].task_state;
@@ -355,8 +378,8 @@ static inline void set_state(int port, enum pd_states next_state)
CHARGE_CEIL_NONE);
#endif
#ifdef CONFIG_USBC_VCONN
- tcpm_set_vconn(port, 0);
-#endif
+ set_vconn(port, 0);
+#endif /* defined(CONFIG_USBC_VCONN) */
#else /* CONFIG_USB_PD_DUAL_ROLE */
if (next_state == PD_STATE_SRC_DISCONNECTED) {
#endif
@@ -2180,7 +2203,7 @@ void pd_task(void *u)
#endif
(PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE &&
pd[port].task_state == PD_STATE_SRC_READY))) {
- tcpm_set_polarity(port, pd[port].polarity);
+ set_polarity(port, pd[port].polarity);
tcpm_set_msg_header(port, pd[port].power_role,
pd[port].data_role);
tcpm_set_rx_enable(port, 1);
@@ -2311,7 +2334,7 @@ void pd_task(void *u)
if (new_cc_state == PD_CC_UFP_ATTACHED ||
new_cc_state == PD_CC_DEBUG_ACC) {
pd[port].polarity = (cc1 != TYPEC_CC_VOLT_RD);
- tcpm_set_polarity(port, pd[port].polarity);
+ set_polarity(port, pd[port].polarity);
/* initial data role for source is DFP */
pd_set_data_role(port, PD_ROLE_DFP);
@@ -2336,7 +2359,7 @@ void pd_task(void *u)
tcpm_set_rx_enable(port, 1);
#ifdef CONFIG_USBC_VCONN
- tcpm_set_vconn(port, 1);
+ set_vconn(port, 1);
pd[port].flags |= PD_FLAGS_VCONN_ON;
#endif
@@ -2794,7 +2817,7 @@ void pd_task(void *u)
/* We are attached */
pd[port].polarity = get_snk_polarity(cc1, cc2);
- tcpm_set_polarity(port, pd[port].polarity);
+ set_polarity(port, pd[port].polarity);
/* reset message ID on connection */
pd[port].msg_id = 0;
/* initial data role for sink is UFP */
@@ -3128,7 +3151,7 @@ void pd_task(void *u)
if (pd[port].last_state != pd[port].task_state) {
if (!(pd[port].flags & PD_FLAGS_VCONN_ON)) {
/* Turn VCONN on and wait for it */
- tcpm_set_vconn(port, 1);
+ set_vconn(port, 1);
set_state_timeout(port,
get_time().val + PD_VCONN_SWAP_DELAY,
PD_STATE_VCONN_SWAP_READY);
@@ -3160,7 +3183,7 @@ void pd_task(void *u)
READY_RETURN_STATE(port));
} else {
/* Turn VCONN off and wait for it */
- tcpm_set_vconn(port, 0);
+ set_vconn(port, 0);
pd[port].flags &= ~PD_FLAGS_VCONN_ON;
set_state_timeout(port,
get_time().val + PD_VCONN_SWAP_DELAY,