Skip to content

Commit a98e892

Browse files
tuxedo-wseBenjamin Tissoires
authored andcommitted
HID: core: Add functions for HID drivers to react on first open and last close call
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent a058002 commit a98e892

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

drivers/hid/hid-core.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,9 @@ int hid_hw_open(struct hid_device *hdev)
23962396
ret = hdev->ll_driver->open(hdev);
23972397
if (ret)
23982398
hdev->ll_open_count--;
2399+
2400+
if (hdev->driver->on_hid_hw_open)
2401+
hdev->driver->on_hid_hw_open(hdev);
23992402
}
24002403

24012404
mutex_unlock(&hdev->ll_open_lock);
@@ -2415,8 +2418,12 @@ EXPORT_SYMBOL_GPL(hid_hw_open);
24152418
void hid_hw_close(struct hid_device *hdev)
24162419
{
24172420
mutex_lock(&hdev->ll_open_lock);
2418-
if (!--hdev->ll_open_count)
2421+
if (!--hdev->ll_open_count) {
24192422
hdev->ll_driver->close(hdev);
2423+
2424+
if (hdev->driver->on_hid_hw_close)
2425+
hdev->driver->on_hid_hw_close(hdev);
2426+
}
24202427
mutex_unlock(&hdev->ll_open_lock);
24212428
}
24222429
EXPORT_SYMBOL_GPL(hid_hw_close);

include/linux/hid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ struct hid_usage_id {
795795
* @suspend: invoked on suspend (NULL means nop)
796796
* @resume: invoked on resume if device was not reset (NULL means nop)
797797
* @reset_resume: invoked on resume if device was reset (NULL means nop)
798+
* @on_hid_hw_open: invoked when hid core opens first instance (NULL means nop)
799+
* @on_hid_hw_close: invoked when hid core closes last instance (NULL means nop)
798800
*
799801
* probe should return -errno on error, or 0 on success. During probe,
800802
* input will not be passed to raw_event unless hid_device_io_start is
@@ -850,6 +852,8 @@ struct hid_driver {
850852
int (*suspend)(struct hid_device *hdev, pm_message_t message);
851853
int (*resume)(struct hid_device *hdev);
852854
int (*reset_resume)(struct hid_device *hdev);
855+
void (*on_hid_hw_open)(struct hid_device *hdev);
856+
void (*on_hid_hw_close)(struct hid_device *hdev);
853857

854858
/* private: */
855859
struct device_driver driver;

0 commit comments

Comments
 (0)