summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2017-08-14 11:45:48 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-08-15 05:20:21 -0700
commit72ea1febb128b4a14ccab5a093bd9abd267b9946 (patch)
tree5812b37e74cbb95b405cf576ab5d403c55ecc15d /chip
parent64ecddfd861002cb5cff04b22211d23cf5fbcb5d (diff)
downloadchrome-ec-72ea1febb128b4a14ccab5a093bd9abd267b9946.tar.gz
chip/stm32/usb: Split usb wake handler as a different function
Indentation is growing out of control, let's move to a separate function so that we can return early. BRANCH=none BUG=b:35775048 TEST=Flash hammer, usb_wake works. Change-Id: I9abf99ff55b3977dfc307fc99aac6f1ab7dd1f6a Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/612922 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/stm32/usb.c92
1 files changed, 49 insertions, 43 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c
index cc6b796b0b..fc6cda9ab5 100644
--- a/chip/stm32/usb.c
+++ b/chip/stm32/usb.c
@@ -422,6 +422,53 @@ int usb_is_suspended(void)
}
#endif /* CONFIG_USB_SUSPEND */
+#if defined(CONFIG_USB_SUSPEND) && defined(CONFIG_USB_REMOTE_WAKEUP)
+/*
+ * Called by usb_interrupt when usb_wake is asking us to count esof_count ESOF
+ * interrupts (one per millisecond), then disable RESUME, then wait for resume
+ * to complete.
+ */
+static void usb_interrupt_handle_wake(uint16_t status)
+{
+ int state;
+ int good;
+
+ esof_count--;
+
+ /* Keep counting. */
+ if (esof_count > 0)
+ return;
+
+ /* Clear RESUME bit. */
+ if (esof_count == 0)
+ STM32_USB_CNTR &= ~STM32_USB_CNTR_RESUME;
+
+ /* Then count down until state is resumed. */
+ state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK)
+ >> STM32_USB_FNR_RXDP_RXDM_SHIFT;
+
+ /*
+ * state 2, or receiving an SOF, means resume
+ * completed successfully.
+ */
+ good = (status & STM32_USB_ISTR_SOF) || (state == 2);
+
+ /* Either: state is ready, or we timed out. */
+ if (good || state == 3 || esof_count <= -USB_RESUME_TIMEOUT_MS) {
+ STM32_USB_CNTR &= ~(STM32_USB_CNTR_ESOFM | STM32_USB_CNTR_SOFM);
+ usb_wake_done = 1;
+ if (!good) {
+ CPRINTF("wake error: cnt=%d state=%d\n",
+ esof_count, state);
+ usb_suspend();
+ return;
+ }
+
+ CPRINTF("RSMOK%d %d\n", -esof_count, state);
+ }
+}
+#endif /* CONFIG_USB_SUSPEND && CONFIG_USB_REMOTE_WAKEUP */
+
void usb_interrupt(void)
{
uint16_t status = STM32_USB_ISTR;
@@ -431,50 +478,9 @@ void usb_interrupt(void)
#ifdef CONFIG_USB_SUSPEND
#ifdef CONFIG_USB_REMOTE_WAKEUP
- /*
- * usb_wake is asking us to count esof_count ESOF interrupts (one
- * per millisecond), then disable RESUME, then wait for resume to
- * complete.
- */
if (status & (STM32_USB_ISTR_ESOF | STM32_USB_ISTR_SOF) &&
- !usb_wake_done) {
- esof_count--;
-
- /* Clear RESUME bit. */
- if (esof_count == 0)
- STM32_USB_CNTR &= ~STM32_USB_CNTR_RESUME;
-
- /* Then count down until state is resumed. */
- if (esof_count <= 0) {
- int state;
- int good;
-
- state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK)
- >> STM32_USB_FNR_RXDP_RXDM_SHIFT;
-
- /*
- * state 2, or receiving an SOF, means resume
- * completed successfully.
- */
- good = (status & STM32_USB_ISTR_SOF) || (state == 2);
-
- /* Either: state is ready, or we timed out. */
- if (good || state == 3 ||
- esof_count <= -USB_RESUME_TIMEOUT_MS) {
- STM32_USB_CNTR &= ~(STM32_USB_CNTR_ESOFM |
- STM32_USB_CNTR_SOFM);
- usb_wake_done = 1;
- if (!good) {
- CPRINTF("wake error: cnt=%d state=%d\n",
- esof_count, state);
- usb_suspend();
- } else {
- CPRINTF("RSMOK%d %d\n",
- -esof_count, state);
- }
- }
- }
- }
+ !usb_wake_done)
+ usb_interrupt_handle_wake(status);
#endif
if (status & STM32_USB_ISTR_SUSP)