From fee1bde58def62ff7cbd40e060844c0cc496a032 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Mon, 6 Nov 2017 12:27:07 -0800 Subject: [PATCH] pd: Add pd_capable() to check PD capability of partner port It's undesirable to do BC1.2 detection on power swap, so add a function to check if the partner port is known to be PD-capable. BUG=chromium:780905 BRANCH=gru TEST=With subsequent CL, attach USB-PD phone capable of role swap. Verify USB 2.0 device is enumerated on plug, and not re-enumerated through a series of "pd # swap power" commands on the EC console. Also verify BC1.2 charging and PD charging are still functional on kevin. Signed-off-by: Shawn Nematbakhsh Change-Id: Ifa75c94e9758d3e407492bbda6fc52ed7bc378fa Reviewed-on: https://chromium-review.googlesource.com/755877 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 13 +++++++++---- include/usb_pd.h | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index c1628beff0..5dd8c87b1e 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -294,6 +294,12 @@ int pd_ts_dts_plugged(int port) return pd[port].flags & PD_FLAGS_TS_DTS_PARTNER; } +/* Return true if partner port is known to be PD capable. */ +int pd_capable(int port) +{ + return pd[port].flags & PD_FLAGS_PREVIOUS_PD_CONN; +} + #ifdef CONFIG_USB_PD_DUAL_ROLE void pd_vbus_low(int port) { @@ -393,7 +399,7 @@ static inline void set_state(int port, enum pd_states next_state) #ifdef CONFIG_LOW_POWER_IDLE /* If a PD device is attached then disable deep sleep */ for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) { - if (pd[i].flags & PD_FLAGS_PREVIOUS_PD_CONN) + if (pd_capable(i)) break; } if (i == CONFIG_USB_PD_PORT_COUNT) @@ -2399,7 +2405,7 @@ void pd_task(void *u) * If we have had PD connection with this port * partner, then start NoResponseTimer. */ - if (pd[port].flags & PD_FLAGS_PREVIOUS_PD_CONN) + if (pd_capable(port)) set_state_timeout(port, get_time().val + PD_T_NO_RESPONSE, @@ -2898,8 +2904,7 @@ void pd_task(void *u) get_time().val + PD_T_SINK_WAIT_CAP, PD_STATE_HARD_RESET_SEND); - else if (pd[port].flags & - PD_FLAGS_PREVIOUS_PD_CONN) + else if (pd_capable(port)) /* ErrorRecovery */ set_state_timeout(port, get_time().val + diff --git a/include/usb_pd.h b/include/usb_pd.h index d068e2e4ce..ac3d16cbc5 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1739,6 +1739,13 @@ void pd_set_new_power_request(int port); */ int pd_ts_dts_plugged(int port); +/** + * Return true if partner port is known to be PD capable. + * + * @param port USB-C port number + */ +int pd_capable(int port); + /* ----- Logging ----- */ #ifdef CONFIG_USB_PD_LOGGING /**