Linux Audio

Check our new training course

Buildroot integration, development and maintenance

Need a Buildroot system for your embedded project?
Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  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/*
 
 
 
 
 10 */
 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 *
 23 * 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
 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
 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 */
 40		switch (hdev->product) {
 41		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			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:
 51		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070:
 52		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081:
 53			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;
 59		}
 60
 61	}
 62	return rdesc;
 63}
 64
 65static int holtek_mouse_probe(struct hid_device *hdev,
 66			      const struct hid_device_id *id)
 67{
 68	int ret;
 69
 70	if (!hid_is_usb(hdev))
 71		return -EINVAL;
 72
 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
 85	return 0;
 86}
 87
 88static 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) },
 91        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
 92			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
 93	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
 94			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
 95	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
 96			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
 97	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
 98			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
 99	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
100			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
101	{ }
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,
109	.probe = holtek_mouse_probe,
110};
111
112module_hid_driver(holtek_mouse_driver);
113MODULE_LICENSE("GPL");
v4.6
 
 1/*
 2 * HID driver for Holtek gaming mice
 3 * Copyright (c) 2013 Christian Ohm
 4 * Heavily inspired by various other HID drivers that adjust the report
 5 * descriptor.
 6*/
 7
 8/*
 9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/hid.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18
19#include "hid-ids.h"
20
21/*
22 * The report descriptor of some Holtek based gaming mice specifies an
23 * excessively large number of consumer usages (2^15), which is more than
24 * HID_MAX_USAGES. This prevents proper parsing of the report descriptor.
25 *
26 * This driver fixes the report descriptor for:
27 * - USB ID 04d9:a067, sold as Sharkoon Drakonia and Perixx MX-2000
28 * - USB ID 04d9:a04a, sold as Tracer Sniper TRM-503, NOVA Gaming Slider X200
29 *   and Zalman ZM-GM1
30 * - USB ID 04d9:a081, sold as SHARKOON DarkGlider Gaming mouse
31 * - USB ID 04d9:a072, sold as LEETGION Hellion Gaming Mouse
32 * - USB ID 04d9:a0c2, sold as ETEKCITY Scroll T-140 Gaming Mouse
33 */
34
35static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
36		unsigned int *rsize)
37{
38	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
39
40	if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
41		/* Change usage maximum and logical maximum from 0x7fff to
42		 * 0x2fff, so they don't exceed HID_MAX_USAGES */
43		switch (hdev->product) {
44		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067:
45		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072:
46		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2:
47			if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
48					&& rdesc[120] == 0xff && rdesc[121] == 0x7f) {
49				hid_info(hdev, "Fixing up report descriptor\n");
50				rdesc[116] = rdesc[121] = 0x2f;
51			}
52			break;
53		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A:
54		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070:
55		case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081:
56			if (*rsize >= 113 && rdesc[106] == 0xff && rdesc[107] == 0x7f
57					&& rdesc[111] == 0xff && rdesc[112] == 0x7f) {
58				hid_info(hdev, "Fixing up report descriptor\n");
59				rdesc[107] = rdesc[112] = 0x2f;
60			}
61			break;
62		}
63
64	}
65	return rdesc;
66}
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68static const struct hid_device_id holtek_mouse_devices[] = {
69	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
70			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
71        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
72			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
73	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
74			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
75	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
76			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
77	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
78			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
79	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
80			USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
81	{ }
82};
83MODULE_DEVICE_TABLE(hid, holtek_mouse_devices);
84
85static struct hid_driver holtek_mouse_driver = {
86	.name = "holtek_mouse",
87	.id_table = holtek_mouse_devices,
88	.report_fixup = holtek_mouse_report_fixup,
 
89};
90
91module_hid_driver(holtek_mouse_driver);
92MODULE_LICENSE("GPL");