From 3e2f184b5bb43461adc3c4ec791ef1ae34441946 Mon Sep 17 00:00:00 2001 From: Paul Fagerburg Date: Mon, 25 Nov 2019 16:23:34 -0700 Subject: ec: use symbolic names instead of magic numbers PD_DP_PIN_CAPS used a lot of magic numbers, which made it difficult to work out what it's doing. Added a comment about using the "receptacle type" field to deterimine whether the UFP_D or DFP_D pin assignments should be used, and replaced magic numbers with #define'd constants. BUG=None BRANCH=None TEST=`make -j buildall && ./util/flash_ec --board=kohaku` (or whatever board you're testing with), then verify that a USB-C dock with HDMI or DisplayPort still works. Change-Id: I1b5cf6d6cf7d0e1698bd7c727226f10f804ed5e9 Signed-off-by: Paul Fagerburg Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1935088 Reviewed-by: Jett Rink --- include/usb_pd.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/include/usb_pd.h b/include/usb_pd.h index 6051706670..08236b8813 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -847,8 +847,6 @@ struct pd_cable { (((snkp) & 0xff) << 16 | ((srcp) & 0xff) << 8 \ | ((usb) & 1) << 7 | ((gdr) & 1) << 6 | ((sign) & 0xF) << 2 \ | ((sdir) & 0x3)) -#define PD_DP_PIN_CAPS(x) ((((x) >> 6) & 0x1) ? (((x) >> 16) & 0x3f) \ - : (((x) >> 8) & 0x3f)) #define MODE_DP_PIN_A 0x01 #define MODE_DP_PIN_B 0x02 @@ -867,6 +865,8 @@ struct pd_cable { #define MODE_DP_PIN_BR2_MASK 0x3 /* Pin configs C/D/E/F support DP signaling levels */ #define MODE_DP_PIN_DP_MASK 0x3c +/* Pin configs A/B/C/D/E/F */ +#define MODE_DP_PIN_CAPS_MASK 0x3f #define MODE_DP_V13 0x1 #define MODE_DP_GEN2 0x2 @@ -875,6 +875,24 @@ struct pd_cable { #define MODE_DP_SRC 0x2 #define MODE_DP_BOTH 0x3 +#define MODE_DP_CABLE_SHIFT 6 + +/* + * Determine which pin assignments are valid for DP + * + * Based on whether the DP adapter identifies itself as a plug (permanently + * attached cable) or a receptacle, the pin assignments may be in the DFP_D + * field or the UFP_D field. + * + * Refer to DisplayPort Alt Mode On USB Type-C Standard version 1.0, table 5-2 + * depending on state of receptacle bit, use pins for DFP_D (if receptacle==0) + * or UFP_D (if receptacle==1) + * Also refer to DisplayPort Alt Mode Capabilities Clarification (4/30/2015) + */ +#define PD_DP_PIN_CAPS(x) ((((x) >> MODE_DP_CABLE_SHIFT) & 0x1) \ + ? (((x) >> MODE_DP_UFP_PIN_SHIFT) & MODE_DP_PIN_CAPS_MASK) \ + : (((x) >> MODE_DP_DFP_PIN_SHIFT) & MODE_DP_PIN_CAPS_MASK)) + /* * DisplayPort Status VDO * ---------------------- -- cgit v1.2.1