hid-sigmamicro.c 7.0 KB

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