summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-04-30 09:21:40 -0600
committerchrome-bot <chrome-bot@chromium.org>2019-05-02 21:02:43 -0700
commit9c64c779dd08721f7d3b091ad9883edc01a87311 (patch)
treee8418771b0792eae426c15f1340350222db7379d /common
parentdfd943ee6e292378bd99d3b3c68d14f014ce9efa (diff)
downloadchrome-ec-9c64c779dd08721f7d3b091ad9883edc01a87311.tar.gz
usb: add inline helper method for CC lines
Expressing logic for CC lines can get very verbose. Add helper inline methods that logical describe the condition we are testing to clean up call sites. BRANCH=none BUG=none TEST=Builds, no functional change. Change-Id: I48c117437bc14f3c55473df7f7c778b55af2706d Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1589906 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Sam Hurst <shurst@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/usb_pd_protocol.c44
-rw-r--r--common/usb_pd_tcpc.c6
-rw-r--r--common/usb_tc_sm.c9
3 files changed, 15 insertions, 44 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)
*