From 096ea20ed18095a967e1829b6ae60b13453416be Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Thu, 7 Sep 2017 15:13:18 +0200 Subject: g: restore DATA PID after USB suspend/resume In USB FS on a bulk/interrupt endpoint, the transactions normally toggles between DATA0 and DATA1 PIDs. After a USB suspend/resume cycle, we need to restart from the PID we were at before suspend. In our current code, when going to deep-sleep during USB suspend, we are re-initializing everything when the MCU restarts at each resume. So we set implicitly the PID to DATA0. The USB Hardware IP just silently discards the packet when the PID of an incoming OUT packet is not matching the expectation in the endpoint register. In order to preserve DATA PIDS, record the state of the PID toggling on each endpoint when going to deep-sleep and restore it during the USB initialization. Signed-off-by: Vincent Palatin BRANCH=none BUG=b:38160821 TEST=manual, plug a HG proto2 on a Linux host machine and enable 'auto-suspend' for this USB device. Let it go to sleep and wake-it up by sending a U2FHID request. Repeat the process several times and see that the key answers every time (while it was failing after the second cycle before). Change-Id: I75e2cfc39f22483d9e9b32c5f8b887dbafc37108 Reviewed-on: https://chromium-review.googlesource.com/655238 Commit-Ready: Marius Schilder Tested-by: Vincent Palatin Reviewed-by: Marius Schilder Reviewed-by: Vadim Bendebury --- include/usb_api.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/usb_api.h') diff --git a/include/usb_api.h b/include/usb_api.h index 6a08916031..8778dcc54e 100644 --- a/include/usb_api.h +++ b/include/usb_api.h @@ -48,6 +48,18 @@ void usb_release(void); */ int usb_is_suspended(void); +/* + * Preserve in non-volatile memory the state of the USB hardware registers + * which cannot be simply re-initialized when powered up again. + */ +void usb_save_suspended_state(void); + +/* + * Restore from non-volatile memory the state of the USB hardware registers + * which was lost by powering them down. + */ +void usb_restore_suspended_state(void); + /* * Tell the host to wake up. Does nothing if CONFIG_USB_REMOTE_WAKEUP is not * defined. -- cgit v1.2.1