git: 5f47c5a3a35d - main - hid: Add hid_ioctl method to HID interface

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Wed, 02 Mar 2022 23:36:37 UTC
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=5f47c5a3a35de67546ce74cb01d45e62d414a179

commit 5f47c5a3a35de67546ce74cb01d45e62d414a179
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2022-03-02 23:35:23 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-03-02 23:35:23 +0000

    hid: Add hid_ioctl method to HID interface
    
    hid_ioctl method executes arbitrary transport backend command.
    Format of the command is defined by hardware transport driver.
    
    It is intended to assist HID device drivers to execute non-HID commands
    on hybrid devices like Elan and Apple touchpads which can be switched
    between HID and proprietary modes.
    
    MFC after:      2 month
---
 sys/dev/hid/hid.c    |  6 ++++++
 sys/dev/hid/hid.h    |  1 +
 sys/dev/hid/hid_if.m | 10 ++++++++++
 sys/dev/hid/hidbus.c |  1 +
 4 files changed, 18 insertions(+)

diff --git a/sys/dev/hid/hid.c b/sys/dev/hid/hid.c
index f201182ac20f..bd5fc79ff0d9 100644
--- a/sys/dev/hid/hid.c
+++ b/sys/dev/hid/hid.c
@@ -1077,4 +1077,10 @@ hid_set_protocol(device_t dev, uint16_t protocol)
 	return (HID_SET_PROTOCOL(device_get_parent(dev), protocol));
 }
 
+int
+hid_ioctl(device_t dev, unsigned long cmd, uintptr_t data)
+{
+	return (HID_IOCTL(device_get_parent(dev), cmd, data));
+}
+
 MODULE_VERSION(hid, 1);
diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
index f0311bae689c..df822fcddffb 100644
--- a/sys/dev/hid/hid.h
+++ b/sys/dev/hid/hid.h
@@ -344,5 +344,6 @@ int	hid_get_report(device_t, void *, hid_size_t, hid_size_t *, uint8_t,
 int	hid_set_report(device_t, const void *, hid_size_t, uint8_t, uint8_t);
 int	hid_set_idle(device_t, uint16_t, uint8_t);
 int	hid_set_protocol(device_t, uint16_t);
+int	hid_ioctl(device_t, unsigned long, uintptr_t);
 #endif	/* _KERNEL || _STANDALONE */
 #endif	/* _HID_HID_H_ */
diff --git a/sys/dev/hid/hid_if.m b/sys/dev/hid/hid_if.m
index 896308fccd17..9f920e4dd4b1 100644
--- a/sys/dev/hid/hid_if.m
+++ b/sys/dev/hid/hid_if.m
@@ -164,3 +164,13 @@ METHOD int set_protocol {
 	device_t dev;
 	uint16_t protocol;
 };
+
+#
+# Executes arbitrary transport backend command.
+# Format of command is defined by hardware transport driver.
+#
+METHOD int ioctl {
+	device_t dev;
+	unsigned long cmd;
+	uintptr_t data;
+};
diff --git a/sys/dev/hid/hidbus.c b/sys/dev/hid/hidbus.c
index 4a3a3e21bf03..a635ca3de026 100644
--- a/sys/dev/hid/hidbus.c
+++ b/sys/dev/hid/hidbus.c
@@ -911,6 +911,7 @@ static device_method_t hidbus_methods[] = {
 	DEVMETHOD(hid_set_report,	hid_set_report),
 	DEVMETHOD(hid_set_idle,		hid_set_idle),
 	DEVMETHOD(hid_set_protocol,	hid_set_protocol),
+	DEVMETHOD(hid_ioctl,		hid_ioctl),
 
 	DEVMETHOD_END
 };