diff options
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r-- | common/usb_pd_protocol.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index aa744b819c..3e1fd1bf75 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -550,6 +550,21 @@ static void handle_vdm_request(int port, int cnt, uint32_t *payload) vid, payload[0] & 0xFFFF); } +/* Return flag for pd state is connected */ +static int pd_is_connected(int port) +{ + if (pd[port].task_state == PD_STATE_DISABLED) + return 0; + +#ifdef CONFIG_USB_PD_DUAL_ROLE + /* Check if sink is connected */ + if (pd[port].role == PD_ROLE_SINK) + return pd[port].task_state != PD_STATE_SNK_DISCONNECTED; +#endif + /* Must be a source */ + return pd[port].task_state != PD_STATE_SRC_DISCONNECTED; +} + #ifdef CONFIG_USB_PD_DUAL_ROLE static void pd_store_src_cap(int port, int cnt, uint32_t *src_caps) { @@ -695,6 +710,13 @@ static void handle_request(int port, uint16_t head, CPRINTF("[%d]%08x ", p, payload[p]); CPRINTF("\n"); + /* + * If we are in disconnected state, we shouldn't get a request. Do + * a hard reset if we get one. + */ + if (!pd_is_connected(port)) + set_state(port, PD_STATE_HARD_RESET); + if (cnt) handle_data_request(port, head, payload); else @@ -911,21 +933,6 @@ void pd_set_dual_role(enum pd_dual_role_states state) } #endif -/* Return flag for pd state is connected */ -static int pd_is_connected(int port) -{ - if (pd[port].task_state == PD_STATE_DISABLED) - return 0; - -#ifdef CONFIG_USB_PD_DUAL_ROLE - /* Check if sink is connected */ - if (pd[port].role == PD_ROLE_SINK) - return pd[port].task_state != PD_STATE_SNK_DISCONNECTED; -#endif - /* Must be a source */ - return pd[port].task_state != PD_STATE_SRC_DISCONNECTED; -} - int pd_get_polarity(int port) { return pd[port].polarity; |