1*97673404SDesmond Lim // SPDX-License-Identifier: GPL-2.0-or-later
2*97673404SDesmond Lim /*
3*97673404SDesmond Lim * HID driver for SiGma Micro-based keyboards
4*97673404SDesmond Lim *
5*97673404SDesmond Lim * Copyright (c) 2016 Kinglong Mee
6*97673404SDesmond Lim * Copyright (c) 2021 Desmond Lim
7*97673404SDesmond Lim */
8*97673404SDesmond Lim
9*97673404SDesmond Lim #include <linux/device.h>
10*97673404SDesmond Lim #include <linux/hid.h>
11*97673404SDesmond Lim #include <linux/module.h>
12*97673404SDesmond Lim
13*97673404SDesmond Lim #include "hid-ids.h"
14*97673404SDesmond Lim
15*97673404SDesmond Lim static const __u8 sm_0059_rdesc[] = {
16*97673404SDesmond Lim 0x05, 0x0c, /* Usage Page (Consumer Devices) 0 */
17*97673404SDesmond Lim 0x09, 0x01, /* Usage (Consumer Control) 2 */
18*97673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 4 */
19*97673404SDesmond Lim 0x85, 0x01, /* Report ID (1) 6 */
20*97673404SDesmond Lim 0x19, 0x00, /* Usage Minimum (0) 8 */
21*97673404SDesmond Lim 0x2a, 0x3c, 0x02, /* Usage Maximum (572) 10 */
22*97673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 13 */
23*97673404SDesmond Lim 0x26, 0x3c, 0x02, /* Logical Maximum (572) 15 */
24*97673404SDesmond Lim 0x95, 0x01, /* Report Count (1) 18 */
25*97673404SDesmond Lim 0x75, 0x10, /* Report Size (16) 20 */
26*97673404SDesmond Lim 0x81, 0x00, /* Input (Data,Arr,Abs) 22 */
27*97673404SDesmond Lim 0xc0, /* End Collection 24 */
28*97673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 25 */
29*97673404SDesmond Lim 0x09, 0x80, /* Usage (System Control) 27 */
30*97673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 29 */
31*97673404SDesmond Lim 0x85, 0x02, /* Report ID (2) 31 */
32*97673404SDesmond Lim 0x19, 0x81, /* Usage Minimum (129) 33 */
33*97673404SDesmond Lim 0x29, 0x83, /* Usage Maximum (131) 35 */
34*97673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 37 */
35*97673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 39 */
36*97673404SDesmond Lim 0x95, 0x03, /* Report Count (3) 41 */
37*97673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 43 */
38*97673404SDesmond Lim 0x95, 0x05, /* Report Count (5) 45 */
39*97673404SDesmond Lim 0x81, 0x01, /* Input (Cnst,Arr,Abs) 47 */
40*97673404SDesmond Lim 0xc0, /* End Collection 49 */
41*97673404SDesmond Lim 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) 50 */
42*97673404SDesmond Lim 0x09, 0x01, /* Usage (Vendor Usage 1) 53 */
43*97673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 55 */
44*97673404SDesmond Lim 0x85, 0x03, /* Report ID (3) 57 */
45*97673404SDesmond Lim 0x1a, 0xf1, 0x00, /* Usage Minimum (241) 59 */
46*97673404SDesmond Lim 0x2a, 0xf8, 0x00, /* Usage Maximum (248) 62 */
47*97673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 65 */
48*97673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 67 */
49*97673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 69 */
50*97673404SDesmond Lim 0x95, 0x08, /* Report Count (8) 71 */
51*97673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 73 */
52*97673404SDesmond Lim 0xc0, /* End Collection 75 */
53*97673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 76 */
54*97673404SDesmond Lim 0x09, 0x06, /* Usage (Keyboard) 78 */
55*97673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 80 */
56*97673404SDesmond Lim 0x85, 0x04, /* Report ID (4) 82 */
57*97673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 84 */
58*97673404SDesmond Lim 0x19, 0xe0, /* Usage Minimum (224) 86 */
59*97673404SDesmond Lim 0x29, 0xe7, /* Usage Maximum (231) 88 */
60*97673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 90 */
61*97673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 92 */
62*97673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 94 */
63*97673404SDesmond Lim 0x95, 0x08, /* Report Count (8) 96 */
64*97673404SDesmond Lim 0x81, 0x00, /* Input (Data,Arr,Abs) 98 */
65*97673404SDesmond Lim 0x95, 0x30, /* Report Count (48) 100 */
66*97673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 102 */
67*97673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 104 */
68*97673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 106 */
69*97673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 108 */
70*97673404SDesmond Lim 0x19, 0x00, /* Usage Minimum (0) 110 */
71*97673404SDesmond Lim 0x29, 0x2f, /* Usage Maximum (47) 112 */
72*97673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 114 */
73*97673404SDesmond Lim 0xc0, /* End Collection 116 */
74*97673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 117 */
75*97673404SDesmond Lim 0x09, 0x06, /* Usage (Keyboard) 119 */
76*97673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 121 */
77*97673404SDesmond Lim 0x85, 0x05, /* Report ID (5) 123 */
78*97673404SDesmond Lim 0x95, 0x38, /* Report Count (56) 125 */
79*97673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 127 */
80*97673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 129 */
81*97673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 131 */
82*97673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 133 */
83*97673404SDesmond Lim 0x19, 0x30, /* Usage Minimum (48) 135 */
84*97673404SDesmond Lim 0x29, 0x67, /* Usage Maximum (103) 137 */
85*97673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 139 */
86*97673404SDesmond Lim 0xc0, /* End Collection 141 */
87*97673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 142 */
88*97673404SDesmond Lim 0x09, 0x06, /* Usage (Keyboard) 144 */
89*97673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 146 */
90*97673404SDesmond Lim 0x85, 0x06, /* Report ID (6) 148 */
91*97673404SDesmond Lim 0x95, 0x38, /* Report Count (56) 150 */
92*97673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 152 */
93*97673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 154 */
94*97673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 156 */
95*97673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 158 */
96*97673404SDesmond Lim 0x19, 0x68, /* Usage Minimum (104) 160 */
97*97673404SDesmond Lim 0x29, 0x9f, /* Usage Maximum (159) 162 */
98*97673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 164 */
99*97673404SDesmond Lim 0xc0, /* End Collection 166 */
100*97673404SDesmond Lim };
101*97673404SDesmond Lim
sm_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * rsize)102*97673404SDesmond Lim static __u8 *sm_report_fixup(struct hid_device *hdev, __u8 *rdesc,
103*97673404SDesmond Lim unsigned int *rsize)
104*97673404SDesmond Lim {
105*97673404SDesmond Lim if (*rsize == sizeof(sm_0059_rdesc) &&
106*97673404SDesmond Lim !memcmp(sm_0059_rdesc, rdesc, *rsize)) {
107*97673404SDesmond Lim hid_info(hdev, "Fixing up SiGma Micro report descriptor\n");
108*97673404SDesmond Lim rdesc[99] = 0x02;
109*97673404SDesmond Lim }
110*97673404SDesmond Lim return rdesc;
111*97673404SDesmond Lim }
112*97673404SDesmond Lim
113*97673404SDesmond Lim static const struct hid_device_id sm_devices[] = {
114*97673404SDesmond Lim { HID_USB_DEVICE(USB_VENDOR_ID_SIGMA_MICRO,
115*97673404SDesmond Lim USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD2) },
116*97673404SDesmond Lim { }
117*97673404SDesmond Lim };
118*97673404SDesmond Lim MODULE_DEVICE_TABLE(hid, sm_devices);
119*97673404SDesmond Lim
120*97673404SDesmond Lim static struct hid_driver sm_driver = {
121*97673404SDesmond Lim .name = "sigmamicro",
122*97673404SDesmond Lim .id_table = sm_devices,
123*97673404SDesmond Lim .report_fixup = sm_report_fixup,
124*97673404SDesmond Lim };
125*97673404SDesmond Lim module_hid_driver(sm_driver);
126*97673404SDesmond Lim
127*97673404SDesmond Lim MODULE_AUTHOR("Kinglong Mee <kinglongmee@gmail.com>");
128*97673404SDesmond Lim MODULE_AUTHOR("Desmond Lim <peckishrine@gmail.com>");
129*97673404SDesmond Lim MODULE_DESCRIPTION("SiGma Micro HID driver");
130*97673404SDesmond Lim MODULE_LICENSE("GPL");
131