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 /**