Christian Ohm | 41de326 | 2013-05-21 01:31:08 +0200 | [diff] [blame] | 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 | * |
Christian Ohm | d4f5189 | 2013-05-21 01:31:09 +0200 | [diff] [blame] | 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 |
Anders F. U. Kiær | 7da7cbb | 2013-10-01 19:22:05 +0200 | [diff] [blame] | 30 | * - USB ID 04d9:a081, sold as SHARKOON DarkGlider Gaming mouse |
Anders F. U. Kiær | f1a4914 | 2013-10-21 23:42:22 +0200 | [diff] [blame] | 31 | * - USB ID 04d9:a072, sold as LEETGION Hellion Gaming Mouse |
John DeSilva | 5df4eb0 | 2014-09-05 11:13:17 -0400 | [diff] [blame] | 32 | * - USB ID 04d9:a0c2, sold as ETEKCITY Scroll T-140 Gaming Mouse |
Christian Ohm | 41de326 | 2013-05-21 01:31:08 +0200 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | static __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 */ |
Christian Ohm | d4f5189 | 2013-05-21 01:31:09 +0200 | [diff] [blame] | 43 | switch (hdev->product) { |
| 44 | case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067: |
Anders F. U. Kiær | f1a4914 | 2013-10-21 23:42:22 +0200 | [diff] [blame] | 45 | case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072: |
John DeSilva | 5df4eb0 | 2014-09-05 11:13:17 -0400 | [diff] [blame] | 46 | case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2: |
Christian Ohm | d4f5189 | 2013-05-21 01:31:09 +0200 | [diff] [blame] | 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: |
Kharlamov Alexey | 274be3e | 2014-01-14 16:09:09 +0400 | [diff] [blame] | 54 | case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070: |
Anders F. U. Kiær | 7da7cbb | 2013-10-01 19:22:05 +0200 | [diff] [blame] | 55 | case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081: |
Christian Ohm | d4f5189 | 2013-05-21 01:31:09 +0200 | [diff] [blame] | 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; |
Christian Ohm | 41de326 | 2013-05-21 01:31:08 +0200 | [diff] [blame] | 62 | } |
Christian Ohm | d4f5189 | 2013-05-21 01:31:09 +0200 | [diff] [blame] | 63 | |
Christian Ohm | 41de326 | 2013-05-21 01:31:08 +0200 | [diff] [blame] | 64 | } |
| 65 | return rdesc; |
| 66 | } |
| 67 | |
| 68 | static 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) }, |
Kharlamov Alexey | 274be3e | 2014-01-14 16:09:09 +0400 | [diff] [blame] | 71 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, |
| 72 | USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) }, |
Christian Ohm | d4f5189 | 2013-05-21 01:31:09 +0200 | [diff] [blame] | 73 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, |
| 74 | USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) }, |
Anders F. U. Kiær | 7da7cbb | 2013-10-01 19:22:05 +0200 | [diff] [blame] | 75 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, |
Anders F. U. Kiær | f1a4914 | 2013-10-21 23:42:22 +0200 | [diff] [blame] | 76 | USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) }, |
| 77 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, |
Anders F. U. Kiær | 7da7cbb | 2013-10-01 19:22:05 +0200 | [diff] [blame] | 78 | USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) }, |
John DeSilva | 5df4eb0 | 2014-09-05 11:13:17 -0400 | [diff] [blame] | 79 | { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, |
| 80 | USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) }, |
Christian Ohm | 41de326 | 2013-05-21 01:31:08 +0200 | [diff] [blame] | 81 | { } |
| 82 | }; |
| 83 | MODULE_DEVICE_TABLE(hid, holtek_mouse_devices); |
| 84 | |
| 85 | static 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 | |
Wei Yongjun | c99f818 | 2013-05-29 18:09:22 +0800 | [diff] [blame] | 91 | module_hid_driver(holtek_mouse_driver); |
Christian Ohm | 41de326 | 2013-05-21 01:31:08 +0200 | [diff] [blame] | 92 | MODULE_LICENSE("GPL"); |