diff mbox series

HID: usbhid: enable remote wakeup for mouse

Message ID 20210517060145.32359-1-maqianga@uniontech.com
State New
Headers show
Series HID: usbhid: enable remote wakeup for mouse | expand

Commit Message

Qiang Ma May 17, 2021, 6:01 a.m. UTC
This patch enables remote wakeup by default for USB mouse
devices.  Mouse in general are supposed to be wakeup devices, but
the correct place to enable it depends on the device's bus; no single
approach will work for all mouse devices.  In particular, this
covers only USB mouse (and then only those supporting the boot
protocol).

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 drivers/hid/usbhid/hid-core.c | 12 +++++++-----
 drivers/hid/usbhid/usbmouse.c |  1 +
 2 files changed, 8 insertions(+), 5 deletions(-)

Comments

Oliver Neukum May 25, 2021, 9:55 a.m. UTC | #1
Am Donnerstag, den 20.05.2021, 14:40 +0800 schrieb 马强:
> This is caused by external reasons, as the kernel cannot sense 
> whether it is accidentally triggered or actively triggered. 
> If this kind of unintentional situation is avoided, 
> the keyboard should also be disabled wakeup by default. 
> Otherwise, the normally used computer may be awakened 
> by someone else accidentally pressing the keyboard on standby.
> 

The kernel has to manage keyboards. There just is no genuine
keyboard device user space could open, nor could we do sysrq
or sak if we left the keyboard fully to user space.

Hence keyboards are a special case unfortunately. We will
have to live with two classes of wakeup, keyboards and power
buttons on the one hand, versus everything else.

	Regards
		Oliver
diff mbox series

Patch

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 86257ce6d619..592aa57a97f5 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1186,11 +1186,13 @@  static int usbhid_start(struct hid_device *hid)
 	 * In addition, enable remote wakeup by default for all keyboard
 	 * devices supporting the boot protocol.
 	 */
-	if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT &&
-			interface->desc.bInterfaceProtocol ==
-				USB_INTERFACE_PROTOCOL_KEYBOARD) {
-		usbhid_set_leds(hid);
-		device_set_wakeup_enable(&dev->dev, 1);
+	if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
+		if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
+			interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) {
+			if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD)
+				usbhid_set_leds(hid);
+			device_set_wakeup_enable(&dev->dev, 1);
+		}
 	}
 
 	mutex_unlock(&usbhid->mutex);
diff --git a/drivers/hid/usbhid/usbmouse.c b/drivers/hid/usbhid/usbmouse.c
index 073127e65ac1..cf785369a5ed 100644
--- a/drivers/hid/usbhid/usbmouse.c
+++ b/drivers/hid/usbhid/usbmouse.c
@@ -188,6 +188,7 @@  static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_i
 		goto fail3;
 
 	usb_set_intfdata(intf, mouse);
+	device_set_wakeup_enable(&dev->dev, 1);
 	return 0;
 
 fail3: