hid-holtek-mouse.c 3.0 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * HID driver for Holtek gaming mice
 * Copyright (c) 2013 Christian Ohm
 * Heavily inspired by various other HID drivers that adjust the report
 * descriptor.
*/

/*
 */

#include <linux/hid.h>
#include <linux/module.h>
#include <linux/usb.h>

#include "hid-ids.h"

/*
 * The report descriptor of some Holtek based gaming mice specifies an
 * excessively large number of consumer usages (2^15), which is more than
 * HID_MAX_USAGES. This prevents proper parsing of the report descriptor.
 *
23 24 25 26
 * This driver fixes the report descriptor for:
 * - USB ID 04d9:a067, sold as Sharkoon Drakonia and Perixx MX-2000
 * - USB ID 04d9:a04a, sold as Tracer Sniper TRM-503, NOVA Gaming Slider X200
 *   and Zalman ZM-GM1
27
 * - USB ID 04d9:a081, sold as SHARKOON DarkGlider Gaming mouse
28
 * - USB ID 04d9:a072, sold as LEETGION Hellion Gaming Mouse
29
 * - USB ID 04d9:a0c2, sold as ETEKCITY Scroll T-140 Gaming Mouse
30 31 32 33 34 35 36 37 38 39
 */

static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
		unsigned int *rsize)
{
	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);

	if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
		/* Change usage maximum and logical maximum from 0x7fff to
		 * 0x2fff, so they don't exceed HID_MAX_USAGES */
40 41
		switch (hdev->product) {
		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067:
42
		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072:
43
		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2:
44 45 46 47 48 49 50
			if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
					&& rdesc[120] == 0xff && rdesc[121] == 0x7f) {
				hid_info(hdev, "Fixing up report descriptor\n");
				rdesc[116] = rdesc[121] = 0x2f;
			}
			break;
		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A:
51
		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070:
52
		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081:
53 54 55 56 57 58
			if (*rsize >= 113 && rdesc[106] == 0xff && rdesc[107] == 0x7f
					&& rdesc[111] == 0xff && rdesc[112] == 0x7f) {
				hid_info(hdev, "Fixing up report descriptor\n");
				rdesc[107] = rdesc[112] = 0x2f;
			}
			break;
59
		}
60

61 62 63 64
	}
	return rdesc;
}

65 66 67 68 69 70 71 72
static int holtek_mouse_probe(struct hid_device *hdev,
			      const struct hid_device_id *id)
{
	if (!hid_is_usb(hdev))
		return -EINVAL;
	return 0;
}

73 74 75
static const struct hid_device_id holtek_mouse_devices[] = {
	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
76 77
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
78 79
	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
80 81
	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
82 83
	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
84 85
	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
86 87 88 89 90 91 92 93
	{ }
};
MODULE_DEVICE_TABLE(hid, holtek_mouse_devices);

static struct hid_driver holtek_mouse_driver = {
	.name = "holtek_mouse",
	.id_table = holtek_mouse_devices,
	.report_fixup = holtek_mouse_report_fixup,
94
	.probe = holtek_mouse_probe,
95 96
};

97
module_hid_driver(holtek_mouse_driver);
98
MODULE_LICENSE("GPL");