blob: 7c907939bfae1d9a5398f574a284b66190fcbfd5 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Christian Ohm41de3262013-05-21 01:31:08 +02002/*
3 * HID driver for Holtek gaming mice
4 * Copyright (c) 2013 Christian Ohm
5 * Heavily inspired by various other HID drivers that adjust the report
6 * descriptor.
7*/
8
9/*
Christian Ohm41de3262013-05-21 01:31:08 +020010 */
11
12#include <linux/hid.h>
13#include <linux/module.h>
14#include <linux/usb.h>
15
16#include "hid-ids.h"
17
18/*
19 * The report descriptor of some Holtek based gaming mice specifies an
20 * excessively large number of consumer usages (2^15), which is more than
21 * HID_MAX_USAGES. This prevents proper parsing of the report descriptor.
22 *
Christian Ohmd4f51892013-05-21 01:31:09 +020023 * This driver fixes the report descriptor for:
24 * - USB ID 04d9:a067, sold as Sharkoon Drakonia and Perixx MX-2000
25 * - USB ID 04d9:a04a, sold as Tracer Sniper TRM-503, NOVA Gaming Slider X200
26 * and Zalman ZM-GM1
Anders F. U. Kiær7da7cbb2013-10-01 19:22:05 +020027 * - USB ID 04d9:a081, sold as SHARKOON DarkGlider Gaming mouse
Anders F. U. Kiærf1a49142013-10-21 23:42:22 +020028 * - USB ID 04d9:a072, sold as LEETGION Hellion Gaming Mouse
John DeSilva5df4eb02014-09-05 11:13:17 -040029 * - USB ID 04d9:a0c2, sold as ETEKCITY Scroll T-140 Gaming Mouse
Christian Ohm41de3262013-05-21 01:31:08 +020030 */
31
32static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
33 unsigned int *rsize)
34{
35 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
36
37 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
38 /* Change usage maximum and logical maximum from 0x7fff to
39 * 0x2fff, so they don't exceed HID_MAX_USAGES */
Christian Ohmd4f51892013-05-21 01:31:09 +020040 switch (hdev->product) {
41 case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067:
Anders F. U. Kiærf1a49142013-10-21 23:42:22 +020042 case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072:
John DeSilva5df4eb02014-09-05 11:13:17 -040043 case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2:
Christian Ohmd4f51892013-05-21 01:31:09 +020044 if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
45 && rdesc[120] == 0xff && rdesc[121] == 0x7f) {
46 hid_info(hdev, "Fixing up report descriptor\n");
47 rdesc[116] = rdesc[121] = 0x2f;
48 }
49 break;
50 case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A:
Kharlamov Alexey274be3e2014-01-14 16:09:09 +040051 case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070:
Anders F. U. Kiær7da7cbb2013-10-01 19:22:05 +020052 case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081:
Christian Ohmd4f51892013-05-21 01:31:09 +020053 if (*rsize >= 113 && rdesc[106] == 0xff && rdesc[107] == 0x7f
54 && rdesc[111] == 0xff && rdesc[112] == 0x7f) {
55 hid_info(hdev, "Fixing up report descriptor\n");
56 rdesc[107] = rdesc[112] = 0x2f;
57 }
58 break;
Christian Ohm41de3262013-05-21 01:31:08 +020059 }
Christian Ohmd4f51892013-05-21 01:31:09 +020060
Christian Ohm41de3262013-05-21 01:31:08 +020061 }
62 return rdesc;
63}
64
Greg Kroah-Hartman93020952021-12-01 19:35:03 +010065static int holtek_mouse_probe(struct hid_device *hdev,
66 const struct hid_device_id *id)
67{
Benjamin Tissoires93a22072021-12-20 10:51:20 +010068 int ret;
69
Greg Kroah-Hartman93020952021-12-01 19:35:03 +010070 if (!hid_is_usb(hdev))
71 return -EINVAL;
Benjamin Tissoires93a22072021-12-20 10:51:20 +010072
73 ret = hid_parse(hdev);
74 if (ret) {
75 hid_err(hdev, "hid parse failed: %d\n", ret);
76 return ret;
77 }
78
79 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
80 if (ret) {
81 hid_err(hdev, "hw start failed: %d\n", ret);
82 return ret;
83 }
84
Greg Kroah-Hartman93020952021-12-01 19:35:03 +010085 return 0;
86}
87
Christian Ohm41de3262013-05-21 01:31:08 +020088static const struct hid_device_id holtek_mouse_devices[] = {
89 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
90 USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
Kharlamov Alexey274be3e2014-01-14 16:09:09 +040091 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
92 USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
Christian Ohmd4f51892013-05-21 01:31:09 +020093 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
94 USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
Anders F. U. Kiær7da7cbb2013-10-01 19:22:05 +020095 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
Anders F. U. Kiærf1a49142013-10-21 23:42:22 +020096 USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
97 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
Anders F. U. Kiær7da7cbb2013-10-01 19:22:05 +020098 USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
John DeSilva5df4eb02014-09-05 11:13:17 -040099 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
100 USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
Christian Ohm41de3262013-05-21 01:31:08 +0200101 { }
102};
103MODULE_DEVICE_TABLE(hid, holtek_mouse_devices);
104
105static struct hid_driver holtek_mouse_driver = {
106 .name = "holtek_mouse",
107 .id_table = holtek_mouse_devices,
108 .report_fixup = holtek_mouse_report_fixup,
Greg Kroah-Hartman93020952021-12-01 19:35:03 +0100109 .probe = holtek_mouse_probe,
Christian Ohm41de3262013-05-21 01:31:08 +0200110};
111
Wei Yongjunc99f8182013-05-29 18:09:22 +0800112module_hid_driver(holtek_mouse_driver);
Christian Ohm41de3262013-05-21 01:31:08 +0200113MODULE_LICENSE("GPL");