From 1af3e5362689497cbc5896cad8e907dd85c7e8ce Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 1 Feb 2018 11:38:29 +0800 Subject: keyboard_scan: Disable when USB is suspended without wake Keyboard matrix scanning can be disabled when the USB interface is disabled without setting the remote wake feature (USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP), as events would be ignored anyway. BRANCH=none BUG=b:72683995 TEST=keyboard matrix scanning is disabled when lid is closed. Change-Id: I0b2346cc3426b9ef51127424f9953fd5c20ecd49 Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/897068 Reviewed-by: Vincent Palatin --- common/keyboard_scan.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'common') diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c index 23925fc218..34474917b3 100644 --- a/common/keyboard_scan.c +++ b/common/keyboard_scan.c @@ -20,6 +20,7 @@ #include "system.h" #include "task.h" #include "timer.h" +#include "usb_api.h" #include "util.h" /* Console output macros */ @@ -777,6 +778,21 @@ DECLARE_HOOK(HOOK_INIT, keyboard_lid_change, HOOK_PRIO_INIT_LID + 1); #endif +#ifdef CONFIG_USB_SUSPEND +static void keyboard_usb_pm_change(void) +{ + /* + * If USB interface is suspended, and host is not asking us to do remote + * wakeup, we can turn off the key scanning. + */ + if (usb_is_suspended() && !usb_is_remote_wakeup_enabled()) + keyboard_scan_enable(0, KB_SCAN_DISABLE_USB_SUSPENDED); + else + keyboard_scan_enable(1, KB_SCAN_DISABLE_USB_SUSPENDED); +} +DECLARE_HOOK(HOOK_USB_PM_CHANGE, keyboard_usb_pm_change, HOOK_PRIO_DEFAULT); +#endif + /*****************************************************************************/ /* Host commands */ -- cgit v1.2.1