Message ID | 20210529151424.12212-1-hdegoede@redhat.com |
---|---|
Headers | show |
Series | HID: multitouch: Disable event reporting on suspend when the device is not a wakeup-source | expand |
Hi Hans, On 5/29/21 5:14 PM, Hans de Goede wrote: > Add a hid_hw_may_wakeup() function, which is the equivalent of > hid_hw_may_wakeup() for hid devices. nitpick here, but I think the second `hid_hw_may_wakeup()` is probably wrong. > > In most cases this just returns device_may_wakeup(hdev->dev.parent), > but for some ll-drivers this is not correct. E.g. usb_hid_driver > instantiated hid devices have their parent set to the usb-interface > to which the usb_hid_driver is bound, but the power/wakeup* sysfs > attributes are part of the usb-device, which is the usb-interface's > parent. I never spent enough time in suspend/resume. But isn't the big consumer of wakeup sources be USB? Is there a point having a generic return path when returning false earlier will keep the same code path for all other transport layers (I2C and bluetooth)? Other than those two questions, I like the series and the approach to not break the existing: For the series: Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cheers, Benjamin > > For these special cases a new may_wakeup callback is added to > hid_ll_driver, so that ll-drivers can override the default behavior. > > Signed-off-by: Hans de Goede <hdegoede@redhat.com> > --- > include/linux/hid.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/include/linux/hid.h b/include/linux/hid.h > index 271021e20a3f..4d2b2212f079 100644 > --- a/include/linux/hid.h > +++ b/include/linux/hid.h > @@ -800,6 +800,7 @@ struct hid_driver { > * @raw_request: send raw report request to device (e.g. feature report) > * @output_report: send output report to device > * @idle: send idle request to device > + * @may_wakeup: return if device may act as a wakeup source during system-suspend > */ > struct hid_ll_driver { > int (*start)(struct hid_device *hdev); > @@ -824,6 +825,7 @@ struct hid_ll_driver { > int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len); > > int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype); > + bool (*may_wakeup)(struct hid_device *hdev); > }; > > extern struct hid_ll_driver i2c_hid_ll_driver; > @@ -1149,6 +1151,22 @@ static inline int hid_hw_idle(struct hid_device *hdev, int report, int idle, > return 0; > } > > +/** > + * hid_may_wakeup - return if the hid device may act as a wakeup source during system-suspend > + * > + * @hdev: hid device > + */ > +static inline bool hid_hw_may_wakeup(struct hid_device *hdev) > +{ > + if (hdev->ll_driver->may_wakeup) > + return hdev->ll_driver->may_wakeup(hdev); > + > + if (hdev->dev.parent) > + return device_may_wakeup(hdev->dev.parent); > + > + return false; > +} > + > /** > * hid_hw_wait - wait for buffered io to complete > * >
Hi, On 6/24/21 2:16 PM, Benjamin Tissoires wrote: > Hi Hans, > > On 5/29/21 5:14 PM, Hans de Goede wrote: >> Add a hid_hw_may_wakeup() function, which is the equivalent of >> hid_hw_may_wakeup() for hid devices. > > nitpick here, but I think the second `hid_hw_may_wakeup()` is probably wrong. Right, the second `hid_hw_may_wakeup()` here should be `device_may_wakeup()`. Jiri can you fix this up while applying or do you want a new version ? >> In most cases this just returns device_may_wakeup(hdev->dev.parent), >> but for some ll-drivers this is not correct. E.g. usb_hid_driver >> instantiated hid devices have their parent set to the usb-interface >> to which the usb_hid_driver is bound, but the power/wakeup* sysfs >> attributes are part of the usb-device, which is the usb-interface's >> parent. > > I never spent enough time in suspend/resume. But isn't the big consumer of wakeup sources be USB? Is there a point having a generic return path when returning false earlier will keep the same code path for all other transport layers (I2C and bluetooth)? I can see why you primarily associate wakeup-sources with USB, but pretty much any device can be a wakeup-source, e.g. embedded-controllers typically are wakeup sources, network-cards can be wakeup-sources, etc. One relevant HID example would be an I2C-HID attached keyboard which is configured to wake the system from suspend on a keypress. At least the Toshiba Click Mini L9W-B is using an I2C-HID keyboard and I'm sure there are others. So it seems best here to not make any assumptions and in cases where the device which is expected to have the power/wakeup* sysfs attributes is simply the direct parent of the hid-device call device_may_wakeup() on hdev->dev.parent. Note that in many cases this will indeed simply return false, which is fine. But in e.g. the i2c-hid attached keyboard it might return true. Regards, Hans > Other than those two questions, I like the series and the approach to not break the existing: > > For the series: > Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > > Cheers, > Benjamin > >> >> For these special cases a new may_wakeup callback is added to >> hid_ll_driver, so that ll-drivers can override the default behavior. >> >> Signed-off-by: Hans de Goede <hdegoede@redhat.com> >> --- >> include/linux/hid.h | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/include/linux/hid.h b/include/linux/hid.h >> index 271021e20a3f..4d2b2212f079 100644 >> --- a/include/linux/hid.h >> +++ b/include/linux/hid.h >> @@ -800,6 +800,7 @@ struct hid_driver { >> * @raw_request: send raw report request to device (e.g. feature report) >> * @output_report: send output report to device >> * @idle: send idle request to device >> + * @may_wakeup: return if device may act as a wakeup source during system-suspend >> */ >> struct hid_ll_driver { >> int (*start)(struct hid_device *hdev); >> @@ -824,6 +825,7 @@ struct hid_ll_driver { >> int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len); >> int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype); >> + bool (*may_wakeup)(struct hid_device *hdev); >> }; >> extern struct hid_ll_driver i2c_hid_ll_driver; >> @@ -1149,6 +1151,22 @@ static inline int hid_hw_idle(struct hid_device *hdev, int report, int idle, >> return 0; >> } >> +/** >> + * hid_may_wakeup - return if the hid device may act as a wakeup source during system-suspend >> + * >> + * @hdev: hid device >> + */ >> +static inline bool hid_hw_may_wakeup(struct hid_device *hdev) >> +{ >> + if (hdev->ll_driver->may_wakeup) >> + return hdev->ll_driver->may_wakeup(hdev); >> + >> + if (hdev->dev.parent) >> + return device_may_wakeup(hdev->dev.parent); >> + >> + return false; >> +} >> + >> /** >> * hid_hw_wait - wait for buffered io to complete >> * >> >
On Thu, 24 Jun 2021, Hans de Goede wrote: > >> Add a hid_hw_may_wakeup() function, which is the equivalent of > >> hid_hw_may_wakeup() for hid devices. > > > > nitpick here, but I think the second `hid_hw_may_wakeup()` is probably wrong. > > Right, the second `hid_hw_may_wakeup()` here should be > `device_may_wakeup()`. Jiri can you fix this up while applying > or do you want a new version ? No worries, I have fixed that up and applied. Thanks, -- Jiri Kosina SUSE Labs