1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25
26
27
28
29
30
31
32
33
34
35
36
37#define MOUSE_BUTTONS_MAX 8
38static void mouse_button_fixup(struct hid_device *hdev,
39 __u8 *rdesc, unsigned int rsize,
40 int nbuttons)
41{
42 if (rsize < 32 || rdesc[12] != 0x95 ||
43 rdesc[14] != 0x75 || rdesc[15] != 0x01 ||
44 rdesc[20] != 0x29 || rdesc[30] != 0x75)
45 return;
46 hid_info(hdev, "Fixing up Elecom mouse button count\n");
47 nbuttons = clamp(nbuttons, 0, MOUSE_BUTTONS_MAX);
48 rdesc[13] = nbuttons;
49 rdesc[21] = nbuttons;
50 rdesc[31] = MOUSE_BUTTONS_MAX - nbuttons;
51}
52
53static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
54 unsigned int *rsize)
55{
56 switch (hdev->product) {
57 case USB_DEVICE_ID_ELECOM_BM084:
58
59
60 if (*rsize >= 48 && rdesc[46] == 0x05 && rdesc[47] == 0x0c) {
61 hid_info(hdev, "Fixing up Elecom BM084 report descriptor\n");
62 rdesc[47] = 0x00;
63 }
64 break;
65 case USB_DEVICE_ID_ELECOM_M_XT3URBK:
66 case USB_DEVICE_ID_ELECOM_M_XT3DRBK:
67 case USB_DEVICE_ID_ELECOM_M_XT4DRBK:
68 mouse_button_fixup(hdev, rdesc, *rsize, 6);
69 break;
70 case USB_DEVICE_ID_ELECOM_M_DT1URBK:
71 case USB_DEVICE_ID_ELECOM_M_DT1DRBK:
72 case USB_DEVICE_ID_ELECOM_M_HT1URBK:
73 case USB_DEVICE_ID_ELECOM_M_HT1DRBK:
74 mouse_button_fixup(hdev, rdesc, *rsize, 8);
75 break;
76 }
77 return rdesc;
78}
79
80static const struct hid_device_id elecom_devices[] = {
81 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
82 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK) },
83 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3DRBK) },
84 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT4DRBK) },
85 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT1URBK) },
86 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_DT1DRBK) },
87 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1URBK) },
88 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1DRBK) },
89 { }
90};
91MODULE_DEVICE_TABLE(hid, elecom_devices);
92
93static struct hid_driver elecom_driver = {
94 .name = "elecom",
95 .id_table = elecom_devices,
96 .report_fixup = elecom_report_fixup
97};
98module_hid_driver(elecom_driver);
99
100MODULE_LICENSE("GPL");
101