diff options
-rw-r--r-- | common/usb_pd_protocol.c | 44 | ||||
-rw-r--r-- | common/usb_pd_tcpc.c | 6 | ||||
-rw-r--r-- | common/usb_tc_sm.c | 9 | ||||
-rw-r--r-- | include/usb_pd_tcpm.h | 41 | ||||
-rw-r--r-- | include/usb_tc_ctvpd_sm.h | 8 |
5 files changed, 59 insertions, 49 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 90ca779d8d..b6b987b3da 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -682,7 +682,7 @@ static inline void set_state(int port, enum pd_states next_state) * Neither a debug accessory nor UFP attached. * Tell the PPC module that there is no sink connected. */ - if (cc1 != TYPEC_CC_VOLT_RD && cc2 != TYPEC_CC_VOLT_RD) { + if (!cc_is_at_least_one_rd(cc1, cc2)) { ppc_sink_is_connected(port, 0); /* * Clear the overcurrent event counter @@ -2373,33 +2373,21 @@ static void pd_partner_port_reset(int port) } #endif /* CONFIG_USB_PD_DUAL_ROLE */ -/** - * Returns whether the sink has detected a Rp resistor on the other side. - */ -static inline int cc_is_rp(int cc) -{ - return (cc == TYPEC_CC_VOLT_RP_DEF) || (cc == TYPEC_CC_VOLT_RP_1_5) || - (cc == TYPEC_CC_VOLT_RP_3_0); -} - #ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE static enum pd_states drp_auto_toggle_next_state(int port, int cc1, int cc2) { enum pd_states next_state; /* Set to appropriate port state */ - if (cc1 == TYPEC_CC_VOLT_OPEN && - cc2 == TYPEC_CC_VOLT_OPEN) + if (cc_is_open(cc1, cc2)) /* nothing connected, keep toggling*/ next_state = PD_STATE_DRP_AUTO_TOGGLE; else if ((cc_is_rp(cc1) || cc_is_rp(cc2)) && drp_state[port] != PD_DRP_FORCE_SOURCE) { /* SNK allowed unless ForceSRC */ next_state = PD_STATE_SNK_DISCONNECTED; - } else if ((cc1 == TYPEC_CC_VOLT_RD || - cc2 == TYPEC_CC_VOLT_RD) || - (cc1 == TYPEC_CC_VOLT_RA && - cc2 == TYPEC_CC_VOLT_RA)) { + } else if (cc_is_at_least_one_rd(cc1, cc2) || + cc_is_audio_acc(cc1, cc2)) { /* * SRC allowed unless ForceSNK or Toggle Off * @@ -3015,8 +3003,7 @@ void pd_task(void *u) if (auto_toggle_supported && !(pd[port].flags & PD_FLAGS_TCPC_DRP_TOGGLE) && !(pd[port].flags & PD_FLAGS_TRY_SRC) && - (cc1 == TYPEC_CC_VOLT_OPEN && - cc2 == TYPEC_CC_VOLT_OPEN)) { + cc_is_open(cc1, cc2)) { set_state(port, PD_STATE_DRP_AUTO_TOGGLE); timeout = 2*MSEC; break; @@ -3024,10 +3011,8 @@ void pd_task(void *u) #endif /* Vnc monitoring */ - if ((cc1 == TYPEC_CC_VOLT_RD || - cc2 == TYPEC_CC_VOLT_RD) || - (cc1 == TYPEC_CC_VOLT_RA && - cc2 == TYPEC_CC_VOLT_RA)) { + if (cc_is_at_least_one_rd(cc1, cc2) || + cc_is_audio_acc(cc1, cc2)) { #ifdef CONFIG_USBC_BACKWARDS_COMPATIBLE_DFP /* Enable VBUS */ if (pd_set_power_supply_ready(port)) @@ -3094,16 +3079,13 @@ void pd_task(void *u) timeout = 20*MSEC; tcpm_get_cc(port, &cc1, &cc2); - if (cc1 == TYPEC_CC_VOLT_RD && - cc2 == TYPEC_CC_VOLT_RD) { + if (cc_is_snk_dbg_acc(cc1, cc2)) { /* Debug accessory */ new_cc_state = PD_CC_DEBUG_ACC; - } else if (cc1 == TYPEC_CC_VOLT_RD || - cc2 == TYPEC_CC_VOLT_RD) { + } else if (cc_is_at_least_one_rd(cc1, cc2)) { /* UFP attached */ new_cc_state = PD_CC_UFP_ATTACHED; - } else if (cc1 == TYPEC_CC_VOLT_RA && - cc2 == TYPEC_CC_VOLT_RA) { + } else if (cc_is_audio_acc(cc1, cc2)) { /* Audio accessory */ new_cc_state = PD_CC_AUDIO_ACC; } else { @@ -3591,8 +3573,7 @@ void pd_task(void *u) if (auto_toggle_supported && !(pd[port].flags & PD_FLAGS_TCPC_DRP_TOGGLE) && !(pd[port].flags & PD_FLAGS_TRY_SRC) && - (cc1 == TYPEC_CC_VOLT_OPEN && - cc2 == TYPEC_CC_VOLT_OPEN)) { + cc_is_open(cc1, cc2)) { set_state(port, PD_STATE_DRP_AUTO_TOGGLE); timeout = 2*MSEC; break; @@ -3600,8 +3581,7 @@ void pd_task(void *u) #endif /* Source connection monitoring */ - if (cc1 != TYPEC_CC_VOLT_OPEN || - cc2 != TYPEC_CC_VOLT_OPEN) { + if (!cc_is_open(cc1, cc2)) { pd[port].cc_state = PD_CC_NONE; hard_reset_count = 0; new_cc_state = PD_CC_NONE; diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c index 2bdadcec7e..e39ca998f4 100644 --- a/common/usb_pd_tcpc.c +++ b/common/usb_pd_tcpc.c @@ -954,9 +954,9 @@ int tcpc_run(int port, int evt) */ return (get_time().val >= pd[port].low_power_ts.val && pd[port].cc_pull == TYPEC_CC_RD && - pd[port].cc_status[0] == TYPEC_CC_VOLT_OPEN && - pd[port].cc_status[1] == TYPEC_CC_VOLT_OPEN) ? 200 * MSEC : - 10 * MSEC; + cc_is_open(pd[port].cc_status[0], pd[port].cc_status[1])) + ? 200 * MSEC + : 10 * MSEC; #else return 10*MSEC; #endif diff --git a/common/usb_tc_sm.c b/common/usb_tc_sm.c index d9c7992b82..4f7039a546 100644 --- a/common/usb_tc_sm.c +++ b/common/usb_tc_sm.c @@ -118,15 +118,6 @@ enum typec_state_id get_typec_state_id(int port) /* Private Functions */ -/** - * Returns whether the sink has detected a Rp resistor on the other side. - */ -static inline int cc_is_rp(int cc) -{ - return (cc == TYPEC_CC_VOLT_RP_DEF) || (cc == TYPEC_CC_VOLT_RP_1_5) || - (cc == TYPEC_CC_VOLT_RP_3_0); -} - /* * CC values for regular sources and Debug sources (aka DTS) * diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 874b231dce..1bfae8b540 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -64,6 +64,47 @@ enum tcpc_transmit_complete { TCPC_TX_COMPLETE_FAILED = 2, }; +/** + * Returns whether the sink has detected a Rp resistor on the other side. + */ +static inline int cc_is_rp(int cc) +{ + return (cc == TYPEC_CC_VOLT_RP_DEF) || (cc == TYPEC_CC_VOLT_RP_1_5) || + (cc == TYPEC_CC_VOLT_RP_3_0); +} + +/** + * Returns true if both CC lines are completely open. + */ +static inline int cc_is_open(int cc1, int cc2) +{ + return cc1 == TYPEC_CC_VOLT_OPEN && cc2 == TYPEC_CC_VOLT_OPEN; +} + +/** + * Returns true if we detect the port partner is a snk debug accessory. + */ +static inline int cc_is_snk_dbg_acc(int cc1, int cc2) +{ + return cc1 == TYPEC_CC_VOLT_RD && cc2 == TYPEC_CC_VOLT_RD; +} + +/** + * Returns true if the port partner is an audio accessory. + */ +static inline int cc_is_audio_acc(int cc1, int cc2) +{ + return cc1 == TYPEC_CC_VOLT_RA && cc2 == TYPEC_CC_VOLT_RA; +} + +/** + * Returns true if the port partner is presenting at least one Rd + */ +static inline int cc_is_at_least_one_rd(int cc1, int cc2) +{ + return cc1 == TYPEC_CC_VOLT_RD || cc2 == TYPEC_CC_VOLT_RD; +} + struct tcpm_drv { /** * Initialize TCPM driver and wait for TCPC readiness. diff --git a/include/usb_tc_ctvpd_sm.h b/include/usb_tc_ctvpd_sm.h index 3b47d35ffa..8e0e1eaf2f 100644 --- a/include/usb_tc_ctvpd_sm.h +++ b/include/usb_tc_ctvpd_sm.h @@ -1378,9 +1378,9 @@ static unsigned int tc_state_ct_attach_wait_unsupported_run(int port) /* Check CT CC for connection */ vpd_ct_get_cc(&cc1, &cc2); - if (cc1 == TYPEC_CC_VOLT_RD || cc2 == TYPEC_CC_VOLT_RD) + if (cc_is_at_least_one_rd(cc1, cc2)) new_cc_state = PD_CC_DFP_ATTACHED; - else if (cc1 == TYPEC_CC_VOLT_RA && cc2 == TYPEC_CC_VOLT_RA) + else if (cc_is_audio_acc(cc1, cc2)) new_cc_state = PD_CC_AUDIO_ACC; else /* (cc1 == TYPEC_CC_VOLT_OPEN or cc2 == TYPEC_CC_VOLT_OPEN */ new_cc_state = PD_CC_NONE; @@ -1545,9 +1545,7 @@ static unsigned int tc_state_ct_unattached_unsupported_run(int port) * least one of the Charge-Through port’s CC pins or SRC.Ra state * on both the CC1 and CC2 pins. */ - if ((cc1 == TYPEC_CC_VOLT_RD || cc2 == TYPEC_CC_VOLT_RD) || - (cc1 == TYPEC_CC_VOLT_RA && - cc2 == TYPEC_CC_VOLT_RA)) { + if (cc_is_at_least_one_rd(cc1, cc2) || cc_is_audio_acc(cc1, cc2)) { set_state(port, TC_OBJ(port), tc_state_ct_attach_wait_unsupported); return 0; |