diff options
author | Vic Yang <victoryang@chromium.org> | 2014-08-05 01:45:49 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-08-07 22:41:30 +0000 |
commit | 43b75cc5864f7d39212c306fcb31b7f79c430ad2 (patch) | |
tree | c45d41a862c29b963ba7262d4f62a7dc7d4de131 | |
parent | eb23eaeed3926350f876756475682d25c5fa958d (diff) | |
download | chrome-ec-43b75cc5864f7d39212c306fcb31b7f79c430ad2.tar.gz |
pd: hard reset if we get a request in disconnected states
If we are in disconnected states and get a request, it's likely either
ourself or whatever on the other side is confused. Do a hard reset in
this case.
BUG=None
TEST=None
BRANCH=None
Change-Id: Ic6504fccc55b79bd3ec4cc47007252e7dc69c778
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/210924
Reviewed-by: Alec Berg <alecaberg@chromium.org>
-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; |