Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * HID driver for SiGma Micro-based keyboards
0004  *
0005  * Copyright (c) 2016 Kinglong Mee
0006  * Copyright (c) 2021 Desmond Lim
0007  */
0008 
0009 #include <linux/device.h>
0010 #include <linux/hid.h>
0011 #include <linux/module.h>
0012 
0013 #include "hid-ids.h"
0014 
0015 static const __u8 sm_0059_rdesc[] = {
0016     0x05, 0x0c,              /* Usage Page (Consumer Devices)       0   */
0017     0x09, 0x01,              /* Usage (Consumer Control)            2   */
0018     0xa1, 0x01,              /* Collection (Application)            4   */
0019     0x85, 0x01,              /*  Report ID (1)                      6   */
0020     0x19, 0x00,              /*  Usage Minimum (0)                  8   */
0021     0x2a, 0x3c, 0x02,        /*  Usage Maximum (572)                10  */
0022     0x15, 0x00,              /*  Logical Minimum (0)                13  */
0023     0x26, 0x3c, 0x02,        /*  Logical Maximum (572)              15  */
0024     0x95, 0x01,              /*  Report Count (1)                   18  */
0025     0x75, 0x10,              /*  Report Size (16)                   20  */
0026     0x81, 0x00,              /*  Input (Data,Arr,Abs)               22  */
0027     0xc0,                    /* End Collection                      24  */
0028     0x05, 0x01,              /* Usage Page (Generic Desktop)        25  */
0029     0x09, 0x80,              /* Usage (System Control)              27  */
0030     0xa1, 0x01,              /* Collection (Application)            29  */
0031     0x85, 0x02,              /*  Report ID (2)                      31  */
0032     0x19, 0x81,              /*  Usage Minimum (129)                33  */
0033     0x29, 0x83,              /*  Usage Maximum (131)                35  */
0034     0x25, 0x01,              /*  Logical Maximum (1)                37  */
0035     0x75, 0x01,              /*  Report Size (1)                    39  */
0036     0x95, 0x03,              /*  Report Count (3)                   41  */
0037     0x81, 0x02,              /*  Input (Data,Var,Abs)               43  */
0038     0x95, 0x05,              /*  Report Count (5)                   45  */
0039     0x81, 0x01,              /*  Input (Cnst,Arr,Abs)               47  */
0040     0xc0,                    /* End Collection                      49  */
0041     0x06, 0x00, 0xff,        /* Usage Page (Vendor Defined Page 1)  50  */
0042     0x09, 0x01,              /* Usage (Vendor Usage 1)              53  */
0043     0xa1, 0x01,              /* Collection (Application)            55  */
0044     0x85, 0x03,              /*  Report ID (3)                      57  */
0045     0x1a, 0xf1, 0x00,        /*  Usage Minimum (241)                59  */
0046     0x2a, 0xf8, 0x00,        /*  Usage Maximum (248)                62  */
0047     0x15, 0x00,              /*  Logical Minimum (0)                65  */
0048     0x25, 0x01,              /*  Logical Maximum (1)                67  */
0049     0x75, 0x01,              /*  Report Size (1)                    69  */
0050     0x95, 0x08,              /*  Report Count (8)                   71  */
0051     0x81, 0x02,              /*  Input (Data,Var,Abs)               73  */
0052     0xc0,                    /* End Collection                      75  */
0053     0x05, 0x01,              /* Usage Page (Generic Desktop)        76  */
0054     0x09, 0x06,              /* Usage (Keyboard)                    78  */
0055     0xa1, 0x01,              /* Collection (Application)            80  */
0056     0x85, 0x04,              /*  Report ID (4)                      82  */
0057     0x05, 0x07,              /*  Usage Page (Keyboard)              84  */
0058     0x19, 0xe0,              /*  Usage Minimum (224)                86  */
0059     0x29, 0xe7,              /*  Usage Maximum (231)                88  */
0060     0x15, 0x00,              /*  Logical Minimum (0)                90  */
0061     0x25, 0x01,              /*  Logical Maximum (1)                92  */
0062     0x75, 0x01,              /*  Report Size (1)                    94  */
0063     0x95, 0x08,              /*  Report Count (8)                   96  */
0064     0x81, 0x00,              /*  Input (Data,Arr,Abs)               98  */
0065     0x95, 0x30,              /*  Report Count (48)                  100 */
0066     0x75, 0x01,              /*  Report Size (1)                    102 */
0067     0x15, 0x00,              /*  Logical Minimum (0)                104 */
0068     0x25, 0x01,              /*  Logical Maximum (1)                106 */
0069     0x05, 0x07,              /*  Usage Page (Keyboard)              108 */
0070     0x19, 0x00,              /*  Usage Minimum (0)                  110 */
0071     0x29, 0x2f,              /*  Usage Maximum (47)                 112 */
0072     0x81, 0x02,              /*  Input (Data,Var,Abs)               114 */
0073     0xc0,                    /* End Collection                      116 */
0074     0x05, 0x01,              /* Usage Page (Generic Desktop)        117 */
0075     0x09, 0x06,              /* Usage (Keyboard)                    119 */
0076     0xa1, 0x01,              /* Collection (Application)            121 */
0077     0x85, 0x05,              /*  Report ID (5)                      123 */
0078     0x95, 0x38,              /*  Report Count (56)                  125 */
0079     0x75, 0x01,              /*  Report Size (1)                    127 */
0080     0x15, 0x00,              /*  Logical Minimum (0)                129 */
0081     0x25, 0x01,              /*  Logical Maximum (1)                131 */
0082     0x05, 0x07,              /*  Usage Page (Keyboard)              133 */
0083     0x19, 0x30,              /*  Usage Minimum (48)                 135 */
0084     0x29, 0x67,              /*  Usage Maximum (103)                137 */
0085     0x81, 0x02,              /*  Input (Data,Var,Abs)               139 */
0086     0xc0,                    /* End Collection                      141 */
0087     0x05, 0x01,              /* Usage Page (Generic Desktop)        142 */
0088     0x09, 0x06,              /* Usage (Keyboard)                    144 */
0089     0xa1, 0x01,              /* Collection (Application)            146 */
0090     0x85, 0x06,              /*  Report ID (6)                      148 */
0091     0x95, 0x38,              /*  Report Count (56)                  150 */
0092     0x75, 0x01,              /*  Report Size (1)                    152 */
0093     0x15, 0x00,              /*  Logical Minimum (0)                154 */
0094     0x25, 0x01,              /*  Logical Maximum (1)                156 */
0095     0x05, 0x07,              /*  Usage Page (Keyboard)              158 */
0096     0x19, 0x68,              /*  Usage Minimum (104)                160 */
0097     0x29, 0x9f,              /*  Usage Maximum (159)                162 */
0098     0x81, 0x02,              /*  Input (Data,Var,Abs)               164 */
0099     0xc0,                    /* End Collection                      166 */
0100 };
0101 
0102 static __u8 *sm_report_fixup(struct hid_device *hdev, __u8 *rdesc,
0103                  unsigned int *rsize)
0104 {
0105     if (*rsize == sizeof(sm_0059_rdesc) &&
0106         !memcmp(sm_0059_rdesc, rdesc, *rsize)) {
0107         hid_info(hdev, "Fixing up SiGma Micro report descriptor\n");
0108         rdesc[99] = 0x02;
0109     }
0110     return rdesc;
0111 }
0112 
0113 static const struct hid_device_id sm_devices[] = {
0114     { HID_USB_DEVICE(USB_VENDOR_ID_SIGMA_MICRO,
0115              USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD2) },
0116     { }
0117 };
0118 MODULE_DEVICE_TABLE(hid, sm_devices);
0119 
0120 static struct hid_driver sm_driver = {
0121     .name = "sigmamicro",
0122     .id_table = sm_devices,
0123     .report_fixup = sm_report_fixup,
0124 };
0125 module_hid_driver(sm_driver);
0126 
0127 MODULE_AUTHOR("Kinglong Mee <kinglongmee@gmail.com>");
0128 MODULE_AUTHOR("Desmond Lim <peckishrine@gmail.com>");
0129 MODULE_DESCRIPTION("SiGma Micro HID driver");
0130 MODULE_LICENSE("GPL");