197673404SDesmond Lim // SPDX-License-Identifier: GPL-2.0-or-later
297673404SDesmond Lim /*
397673404SDesmond Lim * HID driver for SiGma Micro-based keyboards
497673404SDesmond Lim *
597673404SDesmond Lim * Copyright (c) 2016 Kinglong Mee
697673404SDesmond Lim * Copyright (c) 2021 Desmond Lim
797673404SDesmond Lim */
897673404SDesmond Lim
997673404SDesmond Lim #include <linux/device.h>
1097673404SDesmond Lim #include <linux/hid.h>
1197673404SDesmond Lim #include <linux/module.h>
1297673404SDesmond Lim
1397673404SDesmond Lim #include "hid-ids.h"
1497673404SDesmond Lim
1597673404SDesmond Lim static const __u8 sm_0059_rdesc[] = {
1697673404SDesmond Lim 0x05, 0x0c, /* Usage Page (Consumer Devices) 0 */
1797673404SDesmond Lim 0x09, 0x01, /* Usage (Consumer Control) 2 */
1897673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 4 */
1997673404SDesmond Lim 0x85, 0x01, /* Report ID (1) 6 */
2097673404SDesmond Lim 0x19, 0x00, /* Usage Minimum (0) 8 */
2197673404SDesmond Lim 0x2a, 0x3c, 0x02, /* Usage Maximum (572) 10 */
2297673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 13 */
2397673404SDesmond Lim 0x26, 0x3c, 0x02, /* Logical Maximum (572) 15 */
2497673404SDesmond Lim 0x95, 0x01, /* Report Count (1) 18 */
2597673404SDesmond Lim 0x75, 0x10, /* Report Size (16) 20 */
2697673404SDesmond Lim 0x81, 0x00, /* Input (Data,Arr,Abs) 22 */
2797673404SDesmond Lim 0xc0, /* End Collection 24 */
2897673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 25 */
2997673404SDesmond Lim 0x09, 0x80, /* Usage (System Control) 27 */
3097673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 29 */
3197673404SDesmond Lim 0x85, 0x02, /* Report ID (2) 31 */
3297673404SDesmond Lim 0x19, 0x81, /* Usage Minimum (129) 33 */
3397673404SDesmond Lim 0x29, 0x83, /* Usage Maximum (131) 35 */
3497673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 37 */
3597673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 39 */
3697673404SDesmond Lim 0x95, 0x03, /* Report Count (3) 41 */
3797673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 43 */
3897673404SDesmond Lim 0x95, 0x05, /* Report Count (5) 45 */
3997673404SDesmond Lim 0x81, 0x01, /* Input (Cnst,Arr,Abs) 47 */
4097673404SDesmond Lim 0xc0, /* End Collection 49 */
4197673404SDesmond Lim 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) 50 */
4297673404SDesmond Lim 0x09, 0x01, /* Usage (Vendor Usage 1) 53 */
4397673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 55 */
4497673404SDesmond Lim 0x85, 0x03, /* Report ID (3) 57 */
4597673404SDesmond Lim 0x1a, 0xf1, 0x00, /* Usage Minimum (241) 59 */
4697673404SDesmond Lim 0x2a, 0xf8, 0x00, /* Usage Maximum (248) 62 */
4797673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 65 */
4897673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 67 */
4997673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 69 */
5097673404SDesmond Lim 0x95, 0x08, /* Report Count (8) 71 */
5197673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 73 */
5297673404SDesmond Lim 0xc0, /* End Collection 75 */
5397673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 76 */
5497673404SDesmond Lim 0x09, 0x06, /* Usage (Keyboard) 78 */
5597673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 80 */
5697673404SDesmond Lim 0x85, 0x04, /* Report ID (4) 82 */
5797673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 84 */
5897673404SDesmond Lim 0x19, 0xe0, /* Usage Minimum (224) 86 */
5997673404SDesmond Lim 0x29, 0xe7, /* Usage Maximum (231) 88 */
6097673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 90 */
6197673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 92 */
6297673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 94 */
6397673404SDesmond Lim 0x95, 0x08, /* Report Count (8) 96 */
6497673404SDesmond Lim 0x81, 0x00, /* Input (Data,Arr,Abs) 98 */
6597673404SDesmond Lim 0x95, 0x30, /* Report Count (48) 100 */
6697673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 102 */
6797673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 104 */
6897673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 106 */
6997673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 108 */
7097673404SDesmond Lim 0x19, 0x00, /* Usage Minimum (0) 110 */
7197673404SDesmond Lim 0x29, 0x2f, /* Usage Maximum (47) 112 */
7297673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 114 */
7397673404SDesmond Lim 0xc0, /* End Collection 116 */
7497673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 117 */
7597673404SDesmond Lim 0x09, 0x06, /* Usage (Keyboard) 119 */
7697673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 121 */
7797673404SDesmond Lim 0x85, 0x05, /* Report ID (5) 123 */
7897673404SDesmond Lim 0x95, 0x38, /* Report Count (56) 125 */
7997673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 127 */
8097673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 129 */
8197673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 131 */
8297673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 133 */
8397673404SDesmond Lim 0x19, 0x30, /* Usage Minimum (48) 135 */
8497673404SDesmond Lim 0x29, 0x67, /* Usage Maximum (103) 137 */
8597673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 139 */
8697673404SDesmond Lim 0xc0, /* End Collection 141 */
8797673404SDesmond Lim 0x05, 0x01, /* Usage Page (Generic Desktop) 142 */
8897673404SDesmond Lim 0x09, 0x06, /* Usage (Keyboard) 144 */
8997673404SDesmond Lim 0xa1, 0x01, /* Collection (Application) 146 */
9097673404SDesmond Lim 0x85, 0x06, /* Report ID (6) 148 */
9197673404SDesmond Lim 0x95, 0x38, /* Report Count (56) 150 */
9297673404SDesmond Lim 0x75, 0x01, /* Report Size (1) 152 */
9397673404SDesmond Lim 0x15, 0x00, /* Logical Minimum (0) 154 */
9497673404SDesmond Lim 0x25, 0x01, /* Logical Maximum (1) 156 */
9597673404SDesmond Lim 0x05, 0x07, /* Usage Page (Keyboard) 158 */
9697673404SDesmond Lim 0x19, 0x68, /* Usage Minimum (104) 160 */
9797673404SDesmond Lim 0x29, 0x9f, /* Usage Maximum (159) 162 */
9897673404SDesmond Lim 0x81, 0x02, /* Input (Data,Var,Abs) 164 */
9997673404SDesmond Lim 0xc0, /* End Collection 166 */
10097673404SDesmond Lim };
10197673404SDesmond Lim
sm_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * rsize)102*fe73965dSThomas Weißschuh static const __u8 *sm_report_fixup(struct hid_device *hdev, __u8 *rdesc,
10397673404SDesmond Lim unsigned int *rsize)
10497673404SDesmond Lim {
10597673404SDesmond Lim if (*rsize == sizeof(sm_0059_rdesc) &&
10697673404SDesmond Lim !memcmp(sm_0059_rdesc, rdesc, *rsize)) {
10797673404SDesmond Lim hid_info(hdev, "Fixing up SiGma Micro report descriptor\n");
10897673404SDesmond Lim rdesc[99] = 0x02;
10997673404SDesmond Lim }
11097673404SDesmond Lim return rdesc;
11197673404SDesmond Lim }
11297673404SDesmond Lim
11397673404SDesmond Lim static const struct hid_device_id sm_devices[] = {
11497673404SDesmond Lim { HID_USB_DEVICE(USB_VENDOR_ID_SIGMA_MICRO,
11597673404SDesmond Lim USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD2) },
11697673404SDesmond Lim { }
11797673404SDesmond Lim };
11897673404SDesmond Lim MODULE_DEVICE_TABLE(hid, sm_devices);
11997673404SDesmond Lim
12097673404SDesmond Lim static struct hid_driver sm_driver = {
12197673404SDesmond Lim .name = "sigmamicro",
12297673404SDesmond Lim .id_table = sm_devices,
12397673404SDesmond Lim .report_fixup = sm_report_fixup,
12497673404SDesmond Lim };
12597673404SDesmond Lim module_hid_driver(sm_driver);
12697673404SDesmond Lim
12797673404SDesmond Lim MODULE_AUTHOR("Kinglong Mee <kinglongmee@gmail.com>");
12897673404SDesmond Lim MODULE_AUTHOR("Desmond Lim <peckishrine@gmail.com>");
12997673404SDesmond Lim MODULE_DESCRIPTION("SiGma Micro HID driver");
13097673404SDesmond Lim MODULE_LICENSE("GPL");
131