From d0d1ea3d46faa5c1141157fe9ef27967aafe85e0 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Mon, 30 Apr 2018 09:32:31 -0700 Subject: usb_pd_protocol: Add PD_ROLE_DISCONNECTED for data role swaps Add a state to indicate that a data role is actually disconnected and notify the board-level data swap function with this state when a cable is unplugged. This allows the board to clean up and restore any state that may have been set up with a data role swap. BUG=b:78308749 BRANCH=eve,poppy TEST=manual on eve: plug in C-to-C cable, execute data swap on port 0 with 'pd 0 swap data' and ensure the OTG pins are asserted. Then unplug the cable and ensure OTG pins are now deasserted. Change-Id: I7d8fff22dd5836b4b5af54f0ede71ee1b6e40b5c Signed-off-by: Duncan Laurie Reviewed-on: https://chromium-review.googlesource.com/1035423 Reviewed-by: Aseda Aboagye Reviewed-by: Furquan Shaikh --- common/usb_pd_protocol.c | 5 +++++ include/usb_pd.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 1d8b82f19d..180f353a4d 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -467,6 +467,11 @@ static inline void set_state(int port, enum pd_states next_state) #ifdef CONFIG_USB_PD_ALT_MODE_DFP pd_dfp_exit_mode(port, 0, 0); #endif + /* + * Indicate that the port is disconnected so the board + * can restore state from any previous data swap. + */ + pd_execute_data_swap(port, PD_ROLE_DISCONNECTED); #ifdef CONFIG_USBC_SS_MUX usb_mux_set(port, TYPEC_MUX_NONE, USB_SWITCH_DISCONNECT, pd[port].polarity); diff --git a/include/usb_pd.h b/include/usb_pd.h index acad78fb42..7cdc79c198 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -871,8 +871,9 @@ enum pd_data_msg_type { #define PD_ROLE_SINK 0 #define PD_ROLE_SOURCE 1 /* Data role */ -#define PD_ROLE_UFP 0 -#define PD_ROLE_DFP 1 +#define PD_ROLE_UFP 0 +#define PD_ROLE_DFP 1 +#define PD_ROLE_DISCONNECTED 2 /* Vconn role */ #define PD_ROLE_VCONN_OFF 0 #define PD_ROLE_VCONN_ON 1 -- cgit v1.2.1