From d7bb1b0e0a24571f01ca048185bd8b9d882c4f8f Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Fri, 2 Aug 2019 16:16:22 -0600 Subject: usb: state machines will resume immediately Instead of waiting for one iteration to resume when we enable it, restart the state machine immediately BRANCH=none BUG=none TEST=build and units tests Change-Id: I6e1d1b281798ad8bd67fb552d4e2c2b36859a7f9 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1733743 Reviewed-by: Denis Brockus --- common/usbc/usb_pe_ctvpd_sm.c | 31 ++++++++++++++----------------- common/usbc/usb_prl_sm.c | 4 +++- 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/usbc/usb_pe_ctvpd_sm.c b/common/usbc/usb_pe_ctvpd_sm.c index fd4cbcbf0e..57c5663e73 100644 --- a/common/usbc/usb_pe_ctvpd_sm.c +++ b/common/usbc/usb_pe_ctvpd_sm.c @@ -18,15 +18,7 @@ /* USB Policy Engine Charge-Through VCONN Powered Device module */ /* Policy Engine Flags */ -#define PE_FLAGS_MSG_RECEIVED (1 << 0) - -enum l_state { - PE_INIT, - PE_RUN, - PE_PAUSED -}; - -static enum l_state local_state = PE_INIT; +#define PE_FLAGS_MSG_RECEIVED BIT(0) /** * This is the PE Port object that contains information needed to @@ -54,22 +46,27 @@ void pe_init(int port) void usbc_policy_engine(int port, int evt, int en) { - switch (local_state) { - case PE_INIT: + static enum sm_local_state local_state[CONFIG_USB_PD_PORT_COUNT]; + + switch (local_state[port]) { + case SM_INIT: pe_init(port); - local_state = PE_RUN; + local_state[port] = SM_RUN; /* fall through */ - case PE_RUN: + case SM_RUN: if (!en) { - local_state = PE_PAUSED; + local_state[port] = SM_PAUSED; break; } sm_run_state_machine(port, PE_OBJ(port), SM_RUN_SIG); break; - case PE_PAUSED: - if (en) - local_state = PE_INIT; + case SM_PAUSED: + if (en) { + /* Restart state machine right now. */ + local_state[port] = SM_INIT; + usbc_policy_engine(port, evt, en); + } break; } } diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c index a08f662e76..e99a2e208a 100644 --- a/common/usbc/usb_prl_sm.c +++ b/common/usbc/usb_prl_sm.c @@ -366,8 +366,10 @@ void usbc_protocol_layer(int port, int evt, int en) sm_run_state_machine(port, PRL_HR_OBJ(port), SM_RUN_SIG); break; case SM_PAUSED: - if (en) + if (en) { local_state[port] = SM_INIT; + usbc_protocol_layer(port, evt, en); + } break; } } -- cgit v1.2.1