summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2019-10-30 11:34:19 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-06 22:11:56 +0000
commit73fb9377aa6028c2ad95eb939fa0615448750767 (patch)
tree018bb59f3620a7b516f7ba2ffeea7e530c7b5e60
parent091a4b8b702a7cc686457efaebdc431e790b85d4 (diff)
downloadchrome-ec-73fb9377aa6028c2ad95eb939fa0615448750767.tar.gz
servo_v4: The polarity is based on the flags in SRC DTS mode
When the port in SRC DTS mode, it should not perform the polarity detection. The polarity is predetermined, as a board-specific setting. In the servo case, the polarity is based on the flags. This CL changes the protocol layer to check the port in SRC DTS mode and call the board-specific function board_get_src_dts_polarity() for the polarity. BRANCH=servo BUG=b:140876537 TEST=Configed servo as srcdts and unflipped direction: > cc srcdts cc2 Verified the power negotiation good and detected the correct polarity: > pd 1 state Port C1 CC2, Ena - Role: SRC-UFP State: SRC_READY, Flags: 0x415e Without this patch, it detected the wrong polarity and the power negotiation failed: > pd 1 state Port C1 CC1, Ena - Role: SRC-DFP State: SRC_DISCOVERY, Flags: 0x10608 Change-Id: I32c5dfffeaeb20a21db1417f3a1c98566b7f5e38 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1891255 Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Sean Abraham <seanabraham@chromium.org> (cherry picked from commit 3c1eff2e293adeca40c0c919e63db4c62b89de41) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1902098
-rw-r--r--board/servo_v4/usb_pd_policy.c12
-rw-r--r--common/usb_pd_protocol.c24
-rw-r--r--include/usb_pd.h11
3 files changed, 46 insertions, 1 deletions
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c
index ddc529ece0..63392a100f 100644
--- a/board/servo_v4/usb_pd_policy.c
+++ b/board/servo_v4/usb_pd_policy.c
@@ -349,6 +349,18 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
update_ports();
}
+__override uint8_t board_get_src_dts_polarity(int port)
+{
+ /*
+ * When servo configured as srcdts, the CC polarity is based
+ * on the flags.
+ */
+ if (port == DUT)
+ return !!(cc_config & CC_POLARITY);
+
+ return 0;
+}
+
int pd_tcpc_cc_nc(int port, int cc_volt, int cc_sel)
{
int rp_index;
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 79f66aa57b..327565455d 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -2246,6 +2246,16 @@ static inline int get_snk_polarity(int cc1, int cc2)
return (cc2 > cc1);
}
+__overridable uint8_t board_get_src_dts_polarity(int port)
+{
+ /*
+ * If the port in SRC DTS, the polarity is determined by the board,
+ * i.e. what Rp impedance the CC lines are pulled. If this function
+ * is not overridden, assume CC1 is primary.
+ */
+ return 0;
+}
+
#if defined(CONFIG_CHARGE_MANAGER)
/**
* Returns type C current limit (mA) based upon cc_voltage (mV).
@@ -2562,6 +2572,11 @@ void pd_task(void *u)
if (pd[port].power_role == PD_ROLE_SINK) {
pd[port].polarity =
get_snk_polarity(cc1, cc2);
+ } else if (cc1 == TYPEC_CC_VOLT_RD &&
+ cc2 == TYPEC_CC_VOLT_RD) {
+ pd[port].polarity =
+ board_get_src_dts_polarity(
+ port);
} else {
pd[port].polarity =
(cc1 != TYPEC_CC_VOLT_RD);
@@ -2720,7 +2735,14 @@ void pd_task(void *u)
/* UFP is attached */
if (new_cc_state == PD_CC_UFP_ATTACHED ||
new_cc_state == PD_CC_DEBUG_ACC) {
- pd[port].polarity = (cc1 != TYPEC_CC_VOLT_RD);
+ if (new_cc_state == PD_CC_DEBUG_ACC) {
+ pd[port].polarity =
+ board_get_src_dts_polarity(
+ port);
+ } else {
+ pd[port].polarity =
+ (cc1 != TYPEC_CC_VOLT_RD);
+ }
set_polarity(port, pd[port].polarity);
/* initial data role for source is DFP */
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 5675bac4ef..8f3cad9b52 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1803,6 +1803,17 @@ int pd_capable(int port);
*/
int pd_is_vbus_present(int port);
+/*
+ * Optional, get the board-specific SRC DTS polarity.
+ *
+ * This function is used for SRC DTS mode. The polarity is predetermined as a
+ * board-specific setting, i.e. what Rp impedance the CC lines are pulled.
+ *
+ * @param port USB-C port number
+ * @return port polarity (0=CC1, 1=CC2)
+ */
+__override_proto uint8_t board_get_src_dts_polarity(int port);
+
/* ----- Logging ----- */
#ifdef CONFIG_USB_PD_LOGGING
/**