hid-maltron.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * HID driver for Maltron L90
  4. *
  5. * Copyright (c) 1999 Andreas Gal
  6. * Copyright (c) 2000-2005 Vojtech Pavlik <[email protected]>
  7. * Copyright (c) 2005 Michael Haboustak <[email protected]> for Concept2, Inc
  8. * Copyright (c) 2008 Jiri Slaby
  9. * Copyright (c) 2012 David Dillow <[email protected]>
  10. * Copyright (c) 2006-2013 Jiri Kosina
  11. * Copyright (c) 2013 Colin Leitner <[email protected]>
  12. * Copyright (c) 2014-2016 Frank Praznik <[email protected]>
  13. * Copyright (c) 2010 Richard Nauber <[email protected]>
  14. * Copyright (c) 2016 Yuxuan Shui <[email protected]>
  15. * Copyright (c) 2018 William Whistler <[email protected]>
  16. */
  17. #include <linux/device.h>
  18. #include <linux/hid.h>
  19. #include <linux/module.h>
  20. #include "hid-ids.h"
  21. /* The original buggy USB descriptor */
  22. static u8 maltron_rdesc_o[] = {
  23. 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
  24. 0x09, 0x80, /* Usage (Sys Control) */
  25. 0xA1, 0x01, /* Collection (Application) */
  26. 0x85, 0x02, /* Report ID (2) */
  27. 0x75, 0x01, /* Report Size (1) */
  28. 0x95, 0x01, /* Report Count (1) */
  29. 0x15, 0x00, /* Logical Minimum (0) */
  30. 0x25, 0x01, /* Logical Maximum (1) */
  31. 0x09, 0x82, /* Usage (Sys Sleep) */
  32. 0x81, 0x06, /* Input (Data,Var,Rel) */
  33. 0x09, 0x82, /* Usage (Sys Sleep) */
  34. 0x81, 0x06, /* Input (Data,Var,Rel) */
  35. 0x09, 0x83, /* Usage (Sys Wake Up) */
  36. 0x81, 0x06, /* Input (Data,Var,Rel) */
  37. 0x75, 0x05, /* Report Size (5) */
  38. 0x81, 0x01, /* Input (Const,Array,Abs) */
  39. 0xC0, /* End Collection */
  40. 0x05, 0x0C, /* Usage Page (Consumer) */
  41. 0x09, 0x01, /* Usage (Consumer Control) */
  42. 0xA1, 0x01, /* Collection (Application) */
  43. 0x85, 0x03, /* Report ID (3) */
  44. 0x95, 0x01, /* Report Count (1) */
  45. 0x75, 0x10, /* Report Size (16) */
  46. 0x19, 0x00, /* Usage Minimum (Unassigned) */
  47. 0x2A, 0xFF, 0x7F, /* Usage Maximum (0x7FFF) */
  48. 0x81, 0x00, /* Input (Data,Array,Abs) */
  49. 0xC0, /* End Collection */
  50. 0x06, 0x7F, 0xFF, /* Usage Page (Vendor Defined 0xFF7F) */
  51. 0x09, 0x01, /* Usage (0x01) */
  52. 0xA1, 0x01, /* Collection (Application) */
  53. 0x85, 0x04, /* Report ID (4) */
  54. 0x95, 0x01, /* Report Count (1) */
  55. 0x75, 0x10, /* Report Size (16) */
  56. 0x19, 0x00, /* Usage Minimum (0x00) */
  57. 0x2A, 0xFF, 0x7F, /* Usage Maximum (0x7FFF) */
  58. 0x81, 0x00, /* Input (Data,Array,Abs) */
  59. 0x75, 0x02, /* Report Size (2) */
  60. 0x25, 0x02, /* Logical Maximum (2) */
  61. 0x09, 0x90, /* Usage (0x90) */
  62. 0xB1, 0x02, /* Feature (Data,Var,Abs) */
  63. 0x75, 0x06, /* Report Size (6) */
  64. 0xB1, 0x01, /* Feature (Const,Array,Abs) */
  65. 0x75, 0x01, /* Report Size (1) */
  66. 0x25, 0x01, /* Logical Maximum (1) */
  67. 0x05, 0x08, /* Usage Page (LEDs) */
  68. 0x09, 0x2A, /* Usage (On-Line) */
  69. 0x91, 0x02, /* Output (Data,Var,Abs) */
  70. 0x09, 0x4B, /* Usage (Generic Indicator) */
  71. 0x91, 0x02, /* Output (Data,Var,Abs) */
  72. 0x75, 0x06, /* Report Size (6) */
  73. 0x95, 0x01, /* Report Count (1) */
  74. 0x91, 0x01, /* Output (Const,Array,Abs) */
  75. 0xC0 /* End Collection */
  76. };
  77. /* The patched descriptor, allowing media key events to be accepted as valid */
  78. static u8 maltron_rdesc[] = {
  79. 0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
  80. 0x09, 0x80, /* Usage (Sys Control) */
  81. 0xA1, 0x01, /* Collection (Application) */
  82. 0x85, 0x02, /* Report ID (2) */
  83. 0x75, 0x01, /* Report Size (1) */
  84. 0x95, 0x01, /* Report Count (1) */
  85. 0x15, 0x00, /* Logical Minimum (0) */
  86. 0x25, 0x01, /* Logical Maximum (1) */
  87. 0x09, 0x82, /* Usage (Sys Sleep) */
  88. 0x81, 0x06, /* Input (Data,Var,Rel) */
  89. 0x09, 0x82, /* Usage (Sys Sleep) */
  90. 0x81, 0x06, /* Input (Data,Var,Rel) */
  91. 0x09, 0x83, /* Usage (Sys Wake Up) */
  92. 0x81, 0x06, /* Input (Data,Var,Rel) */
  93. 0x75, 0x05, /* Report Size (5) */
  94. 0x81, 0x01, /* Input (Const,Array,Abs) */
  95. 0xC0, /* End Collection */
  96. 0x05, 0x0C, /* Usage Page (Consumer) */
  97. 0x09, 0x01, /* Usage (Consumer Control) */
  98. 0xA1, 0x01, /* Collection (Application) */
  99. 0x85, 0x03, /* Report ID (3) */
  100. 0x15, 0x00, /* Logical Minimum (0) - changed */
  101. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767) - changed */
  102. 0x95, 0x01, /* Report Count (1) */
  103. 0x75, 0x10, /* Report Size (16) */
  104. 0x19, 0x00, /* Usage Minimum (Unassigned) */
  105. 0x2A, 0xFF, 0x7F, /* Usage Maximum (0x7FFF) */
  106. 0x81, 0x00, /* Input (Data,Array,Abs) */
  107. 0xC0, /* End Collection */
  108. 0x06, 0x7F, 0xFF, /* Usage Page (Vendor Defined 0xFF7F) */
  109. 0x09, 0x01, /* Usage (0x01) */
  110. 0xA1, 0x01, /* Collection (Application) */
  111. 0x85, 0x04, /* Report ID (4) */
  112. 0x95, 0x01, /* Report Count (1) */
  113. 0x75, 0x10, /* Report Size (16) */
  114. 0x19, 0x00, /* Usage Minimum (0x00) */
  115. 0x2A, 0xFF, 0x7F, /* Usage Maximum (0x7FFF) */
  116. 0x81, 0x00, /* Input (Data,Array,Abs) */
  117. 0x75, 0x02, /* Report Size (2) */
  118. 0x25, 0x02, /* Logical Maximum (2) */
  119. 0x09, 0x90, /* Usage (0x90) */
  120. 0xB1, 0x02, /* Feature (Data,Var,Abs) */
  121. 0x75, 0x06, /* Report Size (6) */
  122. 0xB1, 0x01, /* Feature (Const,Array,Abs) */
  123. 0x75, 0x01, /* Report Size (1) */
  124. 0x25, 0x01, /* Logical Maximum (1) */
  125. 0x05, 0x08, /* Usage Page (LEDs) */
  126. 0x09, 0x2A, /* Usage (On-Line) */
  127. 0x91, 0x02, /* Output (Data,Var,Abs) */
  128. 0x09, 0x4B, /* Usage (Generic Indicator) */
  129. 0x91, 0x02, /* Output (Data,Var,Abs) */
  130. 0x75, 0x06, /* Report Size (6) */
  131. 0x95, 0x01, /* Report Count (1) */
  132. 0x91, 0x01, /* Output (Const,Array,Abs) */
  133. 0xC0 /* End Collection */
  134. };
  135. static __u8 *maltron_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  136. unsigned int *rsize)
  137. {
  138. if (*rsize == sizeof(maltron_rdesc_o) &&
  139. !memcmp(maltron_rdesc_o, rdesc, sizeof(maltron_rdesc_o))) {
  140. hid_info(hdev, "Replacing Maltron L90 keyboard report descriptor\n");
  141. *rsize = sizeof(maltron_rdesc);
  142. return maltron_rdesc;
  143. }
  144. return rdesc;
  145. }
  146. static const struct hid_device_id maltron_devices[] = {
  147. { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_MALTRON_KB)},
  148. { }
  149. };
  150. MODULE_DEVICE_TABLE(hid, maltron_devices);
  151. static struct hid_driver maltron_driver = {
  152. .name = "maltron",
  153. .id_table = maltron_devices,
  154. .report_fixup = maltron_report_fixup
  155. };
  156. module_hid_driver(maltron_driver);
  157. MODULE_LICENSE("GPL");