diff options
author | Wai-Hong Tam <waihong@google.com> | 2019-10-30 11:34:19 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-02 04:26:39 +0000 |
commit | 3c1eff2e293adeca40c0c919e63db4c62b89de41 (patch) | |
tree | e0d509c80610365972c61874e1c5a8fb46dc96d6 | |
parent | 7d4547799ca33dbc8806f2d7db99ca58d26173c6 (diff) | |
download | chrome-ec-3c1eff2e293adeca40c0c919e63db4c62b89de41.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>
-rw-r--r-- | board/servo_v4/usb_pd_policy.c | 12 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 23 | ||||
-rw-r--r-- | include/usb_pd.h | 11 |
3 files changed, 45 insertions, 1 deletions
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c index 5c8019dc08..1f42b1829a 100644 --- a/board/servo_v4/usb_pd_policy.c +++ b/board/servo_v4/usb_pd_policy.c @@ -352,6 +352,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 5d5df2d4e5..71a3f5385b 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -2697,6 +2697,16 @@ void pd_ping_enable(int port, int enable) pd[port].flags &= ~PD_FLAGS_PING_ENABLED; } +__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) /** @@ -3143,6 +3153,10 @@ void pd_task(void *u) if (pd[port].power_role == PD_ROLE_SINK) { pd[port].polarity = get_snk_polarity(cc1, cc2); + } else if (cc_is_snk_dbg_acc(cc1, cc2)) { + pd[port].polarity = + board_get_src_dts_polarity( + port); } else { pd[port].polarity = (cc1 != TYPEC_CC_VOLT_RD); @@ -3386,7 +3400,14 @@ void pd_task(void *u) /* Inform PPC that a sink is connected. */ ppc_sink_is_connected(port, 1); #endif /* CONFIG_USBC_PPC */ - pd[port].polarity = (cc1 != TYPEC_CC_VOLT_RD); + if (new_cc_state == PD_CC_UFP_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 c5e778d35b..183f40e7b0 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -2286,6 +2286,17 @@ void pd_notify_dp_alt_mode_entry(void); enum pd_cc_states pd_get_cc_state( enum tcpc_cc_voltage_status cc1, enum tcpc_cc_voltage_status cc2); +/* + * 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 /** |