summaryrefslogtreecommitdiff
path: root/drivers/hid/hid-winwing.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2025-12-04 15:44:48 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2025-12-04 15:44:48 -0800
commitfde4ce068d1bccacf1e2d6a28697a3847f28e0a6 (patch)
tree44d49678a5013e46a8b358402fb3a65bee178840 /drivers/hid/hid-winwing.c
parentd1b46f53a51e328202ae049f44b86336d124aeac (diff)
parent8af1d3fe5f186bff53057c6856046b0752fe71e8 (diff)
Merge tag 'hid-for-linus-2025120201' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID updates from Jiri Kosina: - Proper mapping of HID_GD_Z to ABS_DISTANCE for stylus/pen types of devices (Ping Cheng) - Power management/hibernation improvements in intel-ish (Zhang Lixu) - Improved support for several Logitech devices, e.g. G Pro X Superlight 2, new iteration of Lighspeed receiver, G13, G510 (Nathan Rossi, Mavroudis Chatzilazaridis, Leo L Schwab, Hans de Goede) - Support for UcLogic XP-PEN Artist 24 Pro (Joshua Goins) - WinWing Orion2 throttle support improvement (Ivan Gorinov) - other assorted small fixes and device ID additions * tag 'hid-for-linus-2025120201' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (37 commits) drivers: hid: renegotiate resolution multipliers with device after reset HID: evision: Fix Report Descriptor for Evision Wireless Receiver 320f:226f HID: logitech-dj: Fix probe failure when used with KVM HID: logitech-dj: Remove duplicate error logging HID: logitech-dj: Add support for G Pro X Superlight 2 receiver selftests/hid-tablet: add ABS_DISTANCE test for stylus/pen HID: input: map HID_GD_Z to ABS_DISTANCE for stylus/pen HID: bpf: fix typo in HID usage table HID: bpf: add the Huion Kamvas 27 Pro HID: bpf: add heuristics to the Huion Inspiroy 2S eraser button HID: bpf: Add support for XP-Pen Deco02 HID: bpf: Add support for the XP-Pen Deco 01 V3 HID: bpf: Add support for the Waltop Batteryless Tablet HID: bpf: Add fixup for Logitech SpaceNavigator variants HID: bpf: support for Huion Kamvas 16 Gen 3 HID: bpf: add support for Huion Kamvas 13 (Gen 3) (model GS1333) HID: bpf: Add support for the Inspiroy 2M Documentation: hid-alps: Format DataByte* subsection headings Documentation: hid-alps: Fix packet format section headings HID: nintendo: add WQ_PERCPU to alloc_workqueue users ...
Diffstat (limited to 'drivers/hid/hid-winwing.c')
-rw-r--r--drivers/hid/hid-winwing.c171
1 files changed, 105 insertions, 66 deletions
diff --git a/drivers/hid/hid-winwing.c b/drivers/hid/hid-winwing.c
index d4afbbd27807..ab65dc12d1e0 100644
--- a/drivers/hid/hid-winwing.c
+++ b/drivers/hid/hid-winwing.c
@@ -37,6 +37,7 @@ struct winwing_drv_data {
struct hid_device *hdev;
__u8 *report_buf;
struct mutex lock;
+ int map_more_buttons;
unsigned int num_leds;
struct winwing_led leds[];
};
@@ -81,12 +82,10 @@ static int winwing_init_led(struct hid_device *hdev,
int ret;
int i;
- size_t data_size = struct_size(data, leds, 3);
-
- data = devm_kzalloc(&hdev->dev, data_size, GFP_KERNEL);
+ data = hid_get_drvdata(hdev);
if (!data)
- return -ENOMEM;
+ return -EINVAL;
data->report_buf = devm_kmalloc(&hdev->dev, MAX_REPORT, GFP_KERNEL);
@@ -106,6 +105,7 @@ static int winwing_init_led(struct hid_device *hdev,
"%s::%s",
dev_name(&input->dev),
info->led_name);
+
if (!led->cdev.name)
return -ENOMEM;
@@ -114,14 +114,98 @@ static int winwing_init_led(struct hid_device *hdev,
return ret;
}
- hid_set_drvdata(hdev, data);
-
return ret;
}
+static int winwing_map_button(int button, int map_more_buttons)
+{
+ if (button < 1)
+ return KEY_RESERVED;
+
+ if (button > 112)
+ return KEY_RESERVED;
+
+ if (button <= 16) {
+ /*
+ * Grip buttons [1 .. 16] are mapped to
+ * key codes BTN_TRIGGER .. BTN_DEAD
+ */
+ return (button - 1) + BTN_JOYSTICK;
+ }
+
+ if (button >= 65) {
+ /*
+ * Base buttons [65 .. 112] are mapped to
+ * key codes BTN_TRIGGER_HAPPY17 .. KEY_MAX
+ */
+ return (button - 65) + BTN_TRIGGER_HAPPY17;
+ }
+
+ if (!map_more_buttons) {
+ /*
+ * Not mapping numbers [33 .. 64] which
+ * are not assigned to any real buttons
+ */
+ if (button >= 33)
+ return KEY_RESERVED;
+ /*
+ * Grip buttons [17 .. 32] are mapped to
+ * BTN_TRIGGER_HAPPY1 .. BTN_TRIGGER_HAPPY16
+ */
+ return (button - 17) + BTN_TRIGGER_HAPPY1;
+ }
+
+ if (button >= 49) {
+ /*
+ * Grip buttons [49 .. 64] are mapped to
+ * BTN_TRIGGER_HAPPY1 .. BTN_TRIGGER_HAPPY16
+ */
+ return (button - 49) + BTN_TRIGGER_HAPPY1;
+ }
+
+ /*
+ * Grip buttons [17 .. 44] are mapped to
+ * key codes KEY_MACRO1 .. KEY_MACRO28;
+ * also mapping numbers [45 .. 48] which
+ * are not assigned to any real buttons.
+ */
+ return (button - 17) + KEY_MACRO1;
+}
+
+static int winwing_input_mapping(struct hid_device *hdev,
+ struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
+ unsigned long **bit, int *max)
+{
+ struct winwing_drv_data *data;
+ int code = KEY_RESERVED;
+ int button = 0;
+
+ data = hid_get_drvdata(hdev);
+
+ if (!data)
+ return -EINVAL;
+
+ if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
+ return 0;
+
+ if (field->application != HID_GD_JOYSTICK)
+ return 0;
+
+ /* Button numbers start with 1 */
+ button = usage->hid & HID_USAGE;
+
+ code = winwing_map_button(button, data->map_more_buttons);
+
+ hid_map_usage(hi, usage, bit, max, EV_KEY, code);
+
+ return 1;
+}
+
static int winwing_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
+ struct winwing_drv_data *data;
+ size_t data_size = struct_size(data, leds, 3);
int ret;
ret = hid_parse(hdev);
@@ -130,6 +214,15 @@ static int winwing_probe(struct hid_device *hdev,
return ret;
}
+ data = devm_kzalloc(&hdev->dev, data_size, GFP_KERNEL);
+
+ if (!data)
+ return -ENOMEM;
+
+ data->map_more_buttons = id->driver_data;
+
+ hid_set_drvdata(hdev, data);
+
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
if (ret) {
hid_err(hdev, "hw start failed\n");
@@ -152,64 +245,11 @@ static int winwing_input_configured(struct hid_device *hdev,
return ret;
}
-static const __u8 original_rdesc_buttons[] = {
- 0x05, 0x09, 0x19, 0x01, 0x29, 0x6F,
- 0x15, 0x00, 0x25, 0x01, 0x35, 0x00,
- 0x45, 0x01, 0x75, 0x01, 0x95, 0x6F,
- 0x81, 0x02, 0x75, 0x01, 0x95, 0x01,
- 0x81, 0x01
-};
-
-/*
- * HID report descriptor shows 111 buttons, which exceeds maximum
- * number of buttons (80) supported by Linux kernel HID subsystem.
- *
- * This module skips numbers 32-63, unused on some throttle grips.
- */
-
-static const __u8 *winwing_report_fixup(struct hid_device *hdev, __u8 *rdesc,
- unsigned int *rsize)
-{
- int sig_length = sizeof(original_rdesc_buttons);
- int unused_button_numbers = 32;
-
- if (*rsize < 34)
- return rdesc;
-
- if (memcmp(rdesc + 8, original_rdesc_buttons, sig_length) == 0) {
-
- /* Usage Maximum */
- rdesc[13] -= unused_button_numbers;
-
- /* Report Count for buttons */
- rdesc[25] -= unused_button_numbers;
-
- /* Report Count for padding [HID1_11, 6.2.2.9] */
- rdesc[31] += unused_button_numbers;
-
- hid_info(hdev, "winwing descriptor fixed\n");
- }
-
- return rdesc;
-}
-
-static int winwing_raw_event(struct hid_device *hdev,
- struct hid_report *report, u8 *raw_data, int size)
-{
- if (size >= 15) {
- /* Skip buttons 32 .. 63 */
- memmove(raw_data + 5, raw_data + 9, 6);
-
- /* Clear the padding */
- memset(raw_data + 11, 0, 4);
- }
-
- return 0;
-}
-
static const struct hid_device_id winwing_devices[] = {
- { HID_USB_DEVICE(0x4098, 0xbe62) }, /* TGRIP-18 */
- { HID_USB_DEVICE(0x4098, 0xbe68) }, /* TGRIP-16EX */
+ { HID_USB_DEVICE(0x4098, 0xbd65), .driver_data = 1 }, /* TGRIP-15E */
+ { HID_USB_DEVICE(0x4098, 0xbd64), .driver_data = 1 }, /* TGRIP-15EX */
+ { HID_USB_DEVICE(0x4098, 0xbe68), .driver_data = 0 }, /* TGRIP-16EX */
+ { HID_USB_DEVICE(0x4098, 0xbe62), .driver_data = 0 }, /* TGRIP-18 */
{}
};
@@ -218,10 +258,9 @@ MODULE_DEVICE_TABLE(hid, winwing_devices);
static struct hid_driver winwing_driver = {
.name = "winwing",
.id_table = winwing_devices,
- .probe = winwing_probe,
.input_configured = winwing_input_configured,
- .report_fixup = winwing_report_fixup,
- .raw_event = winwing_raw_event,
+ .input_mapping = winwing_input_mapping,
+ .probe = winwing_probe,
};
module_hid_driver(winwing_driver);