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