* [PATCH 1/2] Add functions for HID drivers to react on first open and last close call
@ 2025-02-11 13:39 Werner Sembach
2025-02-11 13:39 ` [PATCH 2/2] Disable touchpad on firmware level while not in use Werner Sembach
2025-05-13 16:36 ` [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Benjamin Tissoires
0 siblings, 2 replies; 7+ messages in thread
From: Werner Sembach @ 2025-02-11 13:39 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires; +Cc: Werner Sembach, linux-input, linux-kernel
Adds a new function to the hid_driver struct that is called when the
userspace starts using the device, and another one that is called when
userspace stop using the device. With this a hid driver can implement
special suspend handling for devices currently not in use.
Signed-off-by: Werner Sembach <wse@tuxedocomputers.com>
---
drivers/hid/hid-core.c | 9 ++++++++-
include/linux/hid.h | 4 ++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 4497b50799dbf..283917a79ac86 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2392,6 +2392,9 @@ int hid_hw_open(struct hid_device *hdev)
ret = hdev->ll_driver->open(hdev);
if (ret)
hdev->ll_open_count--;
+
+ if (hdev->driver->on_hid_hw_open)
+ hdev->driver->on_hid_hw_open(hdev);
}
mutex_unlock(&hdev->ll_open_lock);
@@ -2411,8 +2414,12 @@ EXPORT_SYMBOL_GPL(hid_hw_open);
void hid_hw_close(struct hid_device *hdev)
{
mutex_lock(&hdev->ll_open_lock);
- if (!--hdev->ll_open_count)
+ if (!--hdev->ll_open_count) {
hdev->ll_driver->close(hdev);
+
+ if (hdev->driver->on_hid_hw_close)
+ hdev->driver->on_hid_hw_close(hdev);
+ }
mutex_unlock(&hdev->ll_open_lock);
}
EXPORT_SYMBOL_GPL(hid_hw_close);
diff --git a/include/linux/hid.h b/include/linux/hid.h
index cdc0dc13c87fe..3b7db4eb3f2f6 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -790,6 +790,8 @@ struct hid_usage_id {
* @suspend: invoked on suspend (NULL means nop)
* @resume: invoked on resume if device was not reset (NULL means nop)
* @reset_resume: invoked on resume if device was reset (NULL means nop)
+ * @on_hid_hw_open: invoked when hid core opens first instance (NULL means nop)
+ * @on_hid_hw_close: invoked when hid core closes last instance (NULL means nop)
*
* probe should return -errno on error, or 0 on success. During probe,
* input will not be passed to raw_event unless hid_device_io_start is
@@ -845,6 +847,8 @@ struct hid_driver {
int (*suspend)(struct hid_device *hdev, pm_message_t message);
int (*resume)(struct hid_device *hdev);
int (*reset_resume)(struct hid_device *hdev);
+ void (*on_hid_hw_open)(struct hid_device *hdev);
+ void (*on_hid_hw_close)(struct hid_device *hdev);
/* private: */
struct device_driver driver;
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 2/2] Disable touchpad on firmware level while not in use
2025-02-11 13:39 [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Werner Sembach
@ 2025-02-11 13:39 ` Werner Sembach
2025-03-04 12:14 ` Werner Sembach
2025-05-13 16:36 ` [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Benjamin Tissoires
1 sibling, 1 reply; 7+ messages in thread
From: Werner Sembach @ 2025-02-11 13:39 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires; +Cc: Werner Sembach, linux-input, linux-kernel
Using the new on_hid_hw_open and on_hid_hw_close functions to disable the
touchpad on firmware level while not being in use.
This safes some battery and triggers touchpad-disabled-leds hardwired to
the touchpads firmware, that exist for example on some TongFang barebones.
For a lengthy discussion with all the details see
https://gitlab.freedesktop.org/libinput/libinput/-/issues/558
Signed-off-by: Werner Sembach <wse@tuxedocomputers.com>
---
drivers/hid/hid-multitouch.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 82900857bfd87..7289c04f47f17 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -1884,6 +1884,16 @@ static void mt_remove(struct hid_device *hdev)
hid_hw_stop(hdev);
}
+static void mt_on_hid_hw_open(struct hid_device *hdev)
+{
+ mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
+}
+
+static void mt_on_hid_hw_close(struct hid_device *hdev)
+{
+ mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE);
+}
+
/*
* This list contains only:
* - VID/PID of products not working with the default multitouch handling
@@ -2351,5 +2361,7 @@ static struct hid_driver mt_driver = {
.suspend = pm_ptr(mt_suspend),
.reset_resume = pm_ptr(mt_reset_resume),
.resume = pm_ptr(mt_resume),
+ .on_hid_hw_open = mt_on_hid_hw_open,
+ .on_hid_hw_close = mt_on_hid_hw_close,
};
module_hid_driver(mt_driver);
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 2/2] Disable touchpad on firmware level while not in use
2025-02-11 13:39 ` [PATCH 2/2] Disable touchpad on firmware level while not in use Werner Sembach
@ 2025-03-04 12:14 ` Werner Sembach
2025-04-24 9:20 ` Jiri Kosina
0 siblings, 1 reply; 7+ messages in thread
From: Werner Sembach @ 2025-03-04 12:14 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires; +Cc: linux-input, linux-kernel
Hi,
Am 11.02.25 um 14:39 schrieb Werner Sembach:
> Using the new on_hid_hw_open and on_hid_hw_close functions to disable the
> touchpad on firmware level while not being in use.
>
> This safes some battery and triggers touchpad-disabled-leds hardwired to
> the touchpads firmware, that exist for example on some TongFang barebones.
>
> For a lengthy discussion with all the details see
> https://gitlab.freedesktop.org/libinput/libinput/-/issues/558
Any comments if this is a good idea or not?
Best regards,
Werner
> Signed-off-by: Werner Sembach <wse@tuxedocomputers.com>
> ---
> drivers/hid/hid-multitouch.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
> index 82900857bfd87..7289c04f47f17 100644
> --- a/drivers/hid/hid-multitouch.c
> +++ b/drivers/hid/hid-multitouch.c
> @@ -1884,6 +1884,16 @@ static void mt_remove(struct hid_device *hdev)
> hid_hw_stop(hdev);
> }
>
> +static void mt_on_hid_hw_open(struct hid_device *hdev)
> +{
> + mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
> +}
> +
> +static void mt_on_hid_hw_close(struct hid_device *hdev)
> +{
> + mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE);
> +}
> +
> /*
> * This list contains only:
> * - VID/PID of products not working with the default multitouch handling
> @@ -2351,5 +2361,7 @@ static struct hid_driver mt_driver = {
> .suspend = pm_ptr(mt_suspend),
> .reset_resume = pm_ptr(mt_reset_resume),
> .resume = pm_ptr(mt_resume),
> + .on_hid_hw_open = mt_on_hid_hw_open,
> + .on_hid_hw_close = mt_on_hid_hw_close,
> };
> module_hid_driver(mt_driver);
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 2/2] Disable touchpad on firmware level while not in use
2025-03-04 12:14 ` Werner Sembach
@ 2025-04-24 9:20 ` Jiri Kosina
2025-04-24 10:58 ` Werner Sembach
2025-05-13 16:39 ` Benjamin Tissoires
0 siblings, 2 replies; 7+ messages in thread
From: Jiri Kosina @ 2025-04-24 9:20 UTC (permalink / raw)
To: Werner Sembach; +Cc: Benjamin Tissoires, linux-input, linux-kernel
On Tue, 4 Mar 2025, Werner Sembach wrote:
> > Using the new on_hid_hw_open and on_hid_hw_close functions to disable the
> > touchpad on firmware level while not being in use.
> >
> > This safes some battery and triggers touchpad-disabled-leds hardwired to
> > the touchpads firmware, that exist for example on some TongFang barebones.
> >
> > For a lengthy discussion with all the details see
> > https://gitlab.freedesktop.org/libinput/libinput/-/issues/558
>
> Any comments if this is a good idea or not?
Sorry for the delay.
To me this looks like generally a good idea; Benjamin, any comments on the
hid-mt part?
BTW you'd need to adjust the Subject line of the patches to conform to the
subsystem style (i.e. HID: core: ....)
Thanks,
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] Disable touchpad on firmware level while not in use
2025-04-24 9:20 ` Jiri Kosina
@ 2025-04-24 10:58 ` Werner Sembach
2025-05-13 16:39 ` Benjamin Tissoires
1 sibling, 0 replies; 7+ messages in thread
From: Werner Sembach @ 2025-04-24 10:58 UTC (permalink / raw)
To: Jiri Kosina; +Cc: Benjamin Tissoires, linux-input, linux-kernel
Am 24.04.25 um 11:20 schrieb Jiri Kosina:
> On Tue, 4 Mar 2025, Werner Sembach wrote:
>
>>> Using the new on_hid_hw_open and on_hid_hw_close functions to disable the
>>> touchpad on firmware level while not being in use.
>>>
>>> This safes some battery and triggers touchpad-disabled-leds hardwired to
>>> the touchpads firmware, that exist for example on some TongFang barebones.
>>>
>>> For a lengthy discussion with all the details see
>>> https://gitlab.freedesktop.org/libinput/libinput/-/issues/558
>> Any comments if this is a good idea or not?
> Sorry for the delay.
np
>
> To me this looks like generally a good idea; Benjamin, any comments on the
> hid-mt part?
>
> BTW you'd need to adjust the Subject line of the patches to conform to the
> subsystem style (i.e. HID: core: ....)
sorry an oversight when rewriting the commit log from local testing branch to
upstream ready
will do in v2 after Benjamins reply
Thanks for looking at this,
Werner
>
> Thanks,
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] Disable touchpad on firmware level while not in use
2025-04-24 9:20 ` Jiri Kosina
2025-04-24 10:58 ` Werner Sembach
@ 2025-05-13 16:39 ` Benjamin Tissoires
1 sibling, 0 replies; 7+ messages in thread
From: Benjamin Tissoires @ 2025-05-13 16:39 UTC (permalink / raw)
To: Jiri Kosina; +Cc: Werner Sembach, linux-input, linux-kernel
On Apr 24 2025, Jiri Kosina wrote:
> On Tue, 4 Mar 2025, Werner Sembach wrote:
>
> > > Using the new on_hid_hw_open and on_hid_hw_close functions to disable the
> > > touchpad on firmware level while not being in use.
> > >
> > > This safes some battery and triggers touchpad-disabled-leds hardwired to
> > > the touchpads firmware, that exist for example on some TongFang barebones.
> > >
> > > For a lengthy discussion with all the details see
> > > https://gitlab.freedesktop.org/libinput/libinput/-/issues/558
> >
> > Any comments if this is a good idea or not?
>
> Sorry for the delay.
>
> To me this looks like generally a good idea; Benjamin, any comments on the
> hid-mt part?
Looks good to me, though my CI is now taking way more time because it's
not expecting to receive data from the device once the initial setup is
done.
>
> BTW you'd need to adjust the Subject line of the patches to conform to the
> subsystem style (i.e. HID: core: ....)
Amended locally and pushed (see the notification email).
Cheers,
Benjamin
>
> Thanks,
>
> --
> Jiri Kosina
> SUSE Labs
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Add functions for HID drivers to react on first open and last close call
2025-02-11 13:39 [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Werner Sembach
2025-02-11 13:39 ` [PATCH 2/2] Disable touchpad on firmware level while not in use Werner Sembach
@ 2025-05-13 16:36 ` Benjamin Tissoires
1 sibling, 0 replies; 7+ messages in thread
From: Benjamin Tissoires @ 2025-05-13 16:36 UTC (permalink / raw)
To: Jiri Kosina, Werner Sembach; +Cc: linux-input, linux-kernel
On Tue, 11 Feb 2025 14:39:05 +0100, Werner Sembach wrote:
> Adds a new function to the hid_driver struct that is called when the
> userspace starts using the device, and another one that is called when
> userspace stop using the device. With this a hid driver can implement
> special suspend handling for devices currently not in use.
>
>
Applied to hid/hid.git (for-6.16/core), thanks!
[1/2] Add functions for HID drivers to react on first open and last close call
https://git.kernel.org/hid/hid/c/a98e892c6942
[2/2] Disable touchpad on firmware level while not in use
https://git.kernel.org/hid/hid/c/6a9e76f75c1a
Cheers,
--
Benjamin Tissoires <bentiss@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-13 16:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-11 13:39 [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Werner Sembach
2025-02-11 13:39 ` [PATCH 2/2] Disable touchpad on firmware level while not in use Werner Sembach
2025-03-04 12:14 ` Werner Sembach
2025-04-24 9:20 ` Jiri Kosina
2025-04-24 10:58 ` Werner Sembach
2025-05-13 16:39 ` Benjamin Tissoires
2025-05-13 16:36 ` [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Benjamin Tissoires
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®