linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: usbhid: enable remote wakeup for mouse
@ 2021-05-17  6:01 Qiang Ma
  2021-05-17  8:31 ` Oliver Neukum
  2021-05-17  8:58 ` Greg KH
  0 siblings, 2 replies; 9+ messages in thread
From: Qiang Ma @ 2021-05-17  6:01 UTC (permalink / raw)
  To: jikos, benjamin.tissoires, linux-usb; +Cc: linux-input, linux-kernel, Qiang Ma

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(-)

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:	
-- 
2.20.1




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
  2021-05-17  6:01 [PATCH] HID: usbhid: enable remote wakeup for mouse Qiang Ma
@ 2021-05-17  8:31 ` Oliver Neukum
  2021-05-17 13:32   ` Alan Stern
  2021-05-17  8:58 ` Greg KH
  1 sibling, 1 reply; 9+ messages in thread
From: Oliver Neukum @ 2021-05-17  8:31 UTC (permalink / raw)
  To: Qiang Ma, jikos, benjamin.tissoires, linux-usb; +Cc: linux-input, linux-kernel

Am Montag, den 17.05.2021, 14:01 +0800 schrieb Qiang Ma:
> 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).
> 

Hi,

have you tested this? In my experience the issue with mice
is that they wake up only when you press a mouse button, not when you
move the mouse. Do we make a promise we cannot keep here?

	Regards
		Oliver



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
  2021-05-17  6:01 [PATCH] HID: usbhid: enable remote wakeup for mouse Qiang Ma
  2021-05-17  8:31 ` Oliver Neukum
@ 2021-05-17  8:58 ` Greg KH
       [not found]   ` <1547909475.114060.1621244274064.JavaMail.xmail@bj-wm-cp-4>
  1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2021-05-17  8:58 UTC (permalink / raw)
  To: Qiang Ma; +Cc: jikos, benjamin.tissoires, linux-usb, linux-input, linux-kernel

On Mon, May 17, 2021 at 02:01:45PM +0800, Qiang Ma wrote:
> 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>

Based on hardware testing, I do not think we can do this as no other
operating system does this, right?  It's not a requirement of the USB
specification to support this, so we can not enforce it either.


> ---
>  drivers/hid/usbhid/hid-core.c | 12 +++++++-----
>  drivers/hid/usbhid/usbmouse.c |  1 +
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> 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:	
> -- 
> 2.20.1

How many different devices did you test this on?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
       [not found]   ` <1547909475.114060.1621244274064.JavaMail.xmail@bj-wm-cp-4>
@ 2021-05-17  9:46     ` Greg KH
       [not found]       ` <1781917892.119659.1621247946603.JavaMail.xmail@bj-wm-cp-4>
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2021-05-17  9:46 UTC (permalink / raw)
  To: 马强
  Cc: jikos, benjamin.tissoires , linux-usb, linux-input, linux-kernel

On Mon, May 17, 2021 at 05:37:54PM +0800, 马强 wrote:
> 
> >> 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>  
>  
> > Based on hardware testing, I do not think we can do this as no other  
> > operating system does this, right? It's not a requirement of the USB  
> > specification to support this, so we can not enforce it either.  
>  
> 
> Thanks for the prompt response.
> 
> We can change "dev->power.should_wakeup" to enabled,

I do not understand this statement.

> but ultimately it depends on the hardware and BIOS for wakeup.

Yes, and the hardware here (USB mice), do not all support this, so you
can not enable it universally as it will cause problems, right?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
       [not found]       ` <1781917892.119659.1621247946603.JavaMail.xmail@bj-wm-cp-4>
@ 2021-05-17 10:42         ` Greg KH
       [not found]           ` <440071991.120491.1621248757251.JavaMail.xmail@bj-wm-cp-4>
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2021-05-17 10:42 UTC (permalink / raw)
  To: 马强
  Cc: jikos, benjamin.tissoires , linux-usb, linux-input, linux-kernel

On Mon, May 17, 2021 at 06:39:06PM +0800, 马强 wrote:
> 
> > >  
> 
> > > Thanks for the prompt response.  
> > >  
> > > We can change "dev->power.should_wakeup" to enabled,  
> >
> > I do not understand this statement.  
> >
> > > but ultimately it depends on the hardware and BIOS for wakeup.  
> >
> > Yes, and the hardware here (USB mice), do not all support this, so you  
> > can not enable it universally as it will cause problems, right?  
> 
> I mean, the kernel should set should_wakeup to enabled
> 
> so that system can be awakened when the hardware here(USB mice) supports the
> wake-up ability.

And how do you determine, in the kernel, if the mouse can do that?

What range of hardware did you test this change with?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: Re: Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
       [not found]           ` <440071991.120491.1621248757251.JavaMail.xmail@bj-wm-cp-4>
@ 2021-05-17 11:19             ` Greg KH
       [not found]               ` <671637326.122188.1621250895330.JavaMail.xmail@bj-wm-cp-4>
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2021-05-17 11:19 UTC (permalink / raw)
  To: 马强
  Cc: jikos, benjamin.tissoires , linux-usb, linux-input, linux-kernel

On Mon, May 17, 2021 at 06:52:37PM +0800, 马强 wrote:
> 
> > >  
> 
> > > > >  
> > >  
> > > > > Thanks for the prompt response.  
> > > > >  
> > > > > We can change "dev->power.should_wakeup" to enabled,  
> > > >  
> > > > I do not understand this statement.  
> > > >  
> > > > > but ultimately it depends on the hardware and BIOS for wakeup.  
> > > >  
> > > > Yes, and the hardware here (USB mice), do not all support this, so you  
> > > > can not enable it universally as it will cause problems, right?  
> > >  
> > > I mean, the kernel should set should_wakeup to enabled  
> > >  
> > > so that system can be awakened when the hardware here(USB mice) supports
> the  
> > > wake-up ability.  
> > 
> > And how do you determine, in the kernel, if the mouse can do that?  
> > 
> > What range of hardware did you test this change with?  
>  
> At the kernel level, "dev->power.should_wakeup" is the device property
> 
> that should enable the wake-up capability. 
> 


Given that you have not tested this change, why should we take this?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: Re: Re: Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
       [not found]               ` <671637326.122188.1621250895330.JavaMail.xmail@bj-wm-cp-4>
@ 2021-05-17 11:44                 ` Greg KH
  0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2021-05-17 11:44 UTC (permalink / raw)
  To: 马强
  Cc: jikos, benjamin.tissoires , linux-usb, linux-input, linux-kernel

On Mon, May 17, 2021 at 07:28:15PM +0800, 马强 wrote:
> 
> > Given that you have not tested this change, why should we take this? 
> 
> 
> I have tested this change.
> 
> Before adding the patch, "dev->power.should_wakeup" is disabled after the
> insertion of the USB mouse,
> 
> and after adding the patch, "dev->power.should_wakeup" is enabled after the
> insertion of the USB mouse.
> 
>  
>  
> 

How many different mice did you test this on?  What specific models?

Again, this is not a requirement of all Mice devices, as it is not a
requirement of the USB specification, which is why we can not enable it
for all devices of this type.

And no other operating system does so either that I know of.  Do you
know of one?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
  2021-05-17  8:31 ` Oliver Neukum
@ 2021-05-17 13:32   ` Alan Stern
       [not found]     ` <1209199573.51584.1621492845444.JavaMail.xmail@bj-wm-cp-1>
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Stern @ 2021-05-17 13:32 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Qiang Ma, jikos, benjamin.tissoires, linux-usb, linux-input,
	linux-kernel

On Mon, May 17, 2021 at 10:31:45AM +0200, Oliver Neukum wrote:
> Am Montag, den 17.05.2021, 14:01 +0800 schrieb Qiang Ma:
> > This patch enables remote wakeup by default for USB mouse
> > devices.  Mouse in general are supposed to be wakeup devices, but

I disagree with that statement.  Who decided that mice are supposed to 
be wakeup devices?

> > 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).
> > 
> 
> Hi,
> 
> have you tested this? In my experience the issue with mice
> is that they wake up only when you press a mouse button, not when you
> move the mouse. Do we make a promise we cannot keep here?

Even worse, if a mouse is enabled for wakeup then the system may get 
woken up at the wrong time.  The example people often use is a laptop 
with a USB mouse thrown into a backpack while it is asleep.  Something 
else inside the backpack may accidentally press against a mouse button, 
causing the system to wake up even though the user wants it to remain 
asleep.

Alan Stern

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: [PATCH] HID: usbhid: enable remote wakeup for mouse
       [not found]     ` <1209199573.51584.1621492845444.JavaMail.xmail@bj-wm-cp-1>
@ 2021-05-25  9:55       ` Oliver Neukum
  0 siblings, 0 replies; 9+ messages in thread
From: Oliver Neukum @ 2021-05-25  9:55 UTC (permalink / raw)
  To: 马强, Alan Stern
  Cc: jikos, benjamin.tissoires, linux-usb, linux-input, linux-kernel

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-25  9:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  6:01 [PATCH] HID: usbhid: enable remote wakeup for mouse Qiang Ma
2021-05-17  8:31 ` Oliver Neukum
2021-05-17 13:32   ` Alan Stern
     [not found]     ` <1209199573.51584.1621492845444.JavaMail.xmail@bj-wm-cp-1>
2021-05-25  9:55       ` Oliver Neukum
2021-05-17  8:58 ` Greg KH
     [not found]   ` <1547909475.114060.1621244274064.JavaMail.xmail@bj-wm-cp-4>
2021-05-17  9:46     ` Greg KH
     [not found]       ` <1781917892.119659.1621247946603.JavaMail.xmail@bj-wm-cp-4>
2021-05-17 10:42         ` Greg KH
     [not found]           ` <440071991.120491.1621248757251.JavaMail.xmail@bj-wm-cp-4>
2021-05-17 11:19             ` Greg KH
     [not found]               ` <671637326.122188.1621250895330.JavaMail.xmail@bj-wm-cp-4>
2021-05-17 11:44                 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).