summaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/usb_pd_tcpm.h41
-rw-r--r--include/usb_tc_ctvpd_sm.h8
2 files changed, 44 insertions, 5 deletions
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;