From 520bd3f6ad2098e6969dd353350e2e2281f28989 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Tue, 25 Apr 2017 11:58:18 +0800 Subject: chip/stm32/usb: More reliable implementation of usb_wake Current usb_wake was sleeping between setting and clearing RESUME bit, which is unprecise. Instead, we count ESOF interrupts in usb_interrupt to detect when to clear RESUME. It is also important that usb_wake does not block, as the calling task (e.g. keyboard scanning) must continue to service events while the USB device is resuming. BRANCH=none BUG=b:35587173 TEST=Connect hammer, force autosuspend using: DEVICE=$(dirname $(grep 5022 /sys/bus/usb/devices/*/idProduct)) echo 500 > $DEVICE/power/autosuspend_delay_ms echo auto > $DEVICE/power/control Wait a second, type something quickly, verify that no keys are lost. Change-Id: I53b46cce5a4adb0ee4c4a7e9f935c00f7f321636 Reviewed-on: https://chromium-review.googlesource.com/490129 Commit-Ready: Nicolas Boichat Tested-by: Nicolas Boichat Reviewed-by: Vincent Palatin --- include/usb_api.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include/usb_api.h') diff --git a/include/usb_api.h b/include/usb_api.h index a251b3f857..c6a949ab61 100644 --- a/include/usb_api.h +++ b/include/usb_api.h @@ -42,11 +42,17 @@ void usb_disconnect(void); */ void usb_release(void); +/* + * Returns true if USB device is currently suspended. + * Requires CONFIG_USB_SUSPEND to be defined. + */ +int usb_is_suspended(void); + /* * Tell the host to wake up. Requires CONFIG_USB_REMOTE_WAKEUP to be defined, * and a chip that implements the function. * - * This function sleeps, so it must not be used in interrupt context. + * Returns immediately, suspend status can be checked using usb_is_suspended. */ void usb_wake(void); -- cgit v1.2.1