From cc4cef5170506a455bc9f8cf6fe45df331f9726d Mon Sep 17 00:00:00 2001 From: Todd Broch Date: Thu, 28 Aug 2014 14:51:05 -0700 Subject: pd: Expand polarity logic to include Ra pull-down logic. Original implemenation of polarity only addressed Rd. This CL hopes to address the addition of the Ra pull-down for powered accessories. Truth table based on type-C specfication document is included in source as well. BRANCH=none BUG=chrome-os-partner:28585 TEST=manual, Setup: # from PD MCU console typec Result: See appropriate polarity. For example, typec 1 Port C1: CC1 445 mV CC2 115 mV (polarity:CC1) Superspeed USB1 typec 1 Port C1: CC1 119 mV CC2 426 mV (polarity:CC2) Superspeed USB1 Also see correct polarity when just Rd is present. Change-Id: I09073d731e4a6050281add3673cb4ec24c053da9 Signed-off-by: Todd Broch Reviewed-on: https://chromium-review.googlesource.com/215666 Reviewed-by: Alec Berg Reviewed-by: Vincent Palatin (cherry picked from commit 6bc911d978cb96694cb3f00d11fbe1848e10ab27) Reviewed-on: https://chromium-review.googlesource.com/216257 Tested-by: Vic Yang Commit-Queue: Vic Yang --- common/usb_pd_protocol.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 3ab4719bb5..7952f12589 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -124,6 +124,33 @@ static const uint8_t dec4b5b[] = { #define PD_HARD_RESET (PD_RST1 | (PD_RST1 << 5) |\ (PD_RST1 << 10) | (PD_RST2 << 15)) +/* Polarity is based 'DFP Perspective' (see table USB Type-C Cable and Connector + * Specification) + * + * CC1 CC2 STATE POSITION + * ---------------------------------------- + * open open NC N/A + * Rd open UFP attached 1 + * open Rd UFP attached 2 + * open Ra pwr cable no UFP 1 + * Ra open pwr cable no UFP 2 + * Rd Ra pwr cable & UFP 1 + * Ra Rd pwr cable & UFP 2 + * Rd Rd dbg accessory N/A + * Ra Ra audio accessory N/A + * + * Note, V(Rd) > V(Ra) + * TODO(crosbug.com/p/31197): Need to identify necessary polarity switching for + * debug dongle. + * + */ +#ifndef PD_SRC_RD_THRESHOLD +#define PD_SRC_RD_THRESHOLD 200 /* mV */ +#endif +#define CC_RA(cc) (cc < PD_SRC_RD_THRESHOLD) +#define CC_RD(cc) ((cc > PD_SRC_RD_THRESHOLD) && (cc < PD_SRC_VNC)) +#define GET_POLARITY(cc1, cc2) (CC_RD(cc2) || CC_RA(cc1)) + /* PD counter definitions */ #define PD_MESSAGE_ID_COUNT 7 #define PD_RETRY_COUNT 2 @@ -1195,7 +1222,8 @@ void pd_task(void) cc2_volt = pd_adc_read(port, 1); if ((cc1_volt < PD_SRC_VNC) || (cc2_volt < PD_SRC_VNC)) { - pd[port].polarity = !(cc1_volt < PD_SRC_VNC); + pd[port].polarity = + GET_POLARITY(cc1_volt, cc2_volt); pd_select_polarity(port, pd[port].polarity); /* Set to USB SS initially */ #ifdef CONFIG_USBC_SS_MUX -- cgit v1.2.1