hid-kye.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * HID driver for Kye/Genius devices not fully compliant with HID standard
  3. *
  4. * Copyright (c) 2009 Jiri Kosina
  5. * Copyright (c) 2009 Tomas Hanak
  6. * Copyright (c) 2012 Nikolai Kondrashov
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. */
  14. #include <linux/device.h>
  15. #include <linux/hid.h>
  16. #include <linux/module.h>
  17. #include "hid-ids.h"
  18. /*
  19. * See EasyPen i405X description, device and HID report descriptors at
  20. * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_i405X
  21. */
  22. /* Original EasyPen i405X report descriptor size */
  23. #define EASYPEN_I405X_RDESC_ORIG_SIZE 476
  24. /* Fixed EasyPen i405X report descriptor */
  25. static __u8 easypen_i405x_rdesc_fixed[] = {
  26. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  27. 0x09, 0x01, /* Usage (01h), */
  28. 0xA1, 0x01, /* Collection (Application), */
  29. 0x85, 0x05, /* Report ID (5), */
  30. 0x09, 0x01, /* Usage (01h), */
  31. 0x15, 0x80, /* Logical Minimum (-128), */
  32. 0x25, 0x7F, /* Logical Maximum (127), */
  33. 0x75, 0x08, /* Report Size (8), */
  34. 0x95, 0x07, /* Report Count (7), */
  35. 0xB1, 0x02, /* Feature (Variable), */
  36. 0xC0, /* End Collection, */
  37. 0x05, 0x0D, /* Usage Page (Digitizer), */
  38. 0x09, 0x02, /* Usage (Pen), */
  39. 0xA1, 0x01, /* Collection (Application), */
  40. 0x85, 0x10, /* Report ID (16), */
  41. 0x09, 0x20, /* Usage (Stylus), */
  42. 0xA0, /* Collection (Physical), */
  43. 0x14, /* Logical Minimum (0), */
  44. 0x25, 0x01, /* Logical Maximum (1), */
  45. 0x75, 0x01, /* Report Size (1), */
  46. 0x09, 0x42, /* Usage (Tip Switch), */
  47. 0x09, 0x44, /* Usage (Barrel Switch), */
  48. 0x09, 0x46, /* Usage (Tablet Pick), */
  49. 0x95, 0x03, /* Report Count (3), */
  50. 0x81, 0x02, /* Input (Variable), */
  51. 0x95, 0x04, /* Report Count (4), */
  52. 0x81, 0x03, /* Input (Constant, Variable), */
  53. 0x09, 0x32, /* Usage (In Range), */
  54. 0x95, 0x01, /* Report Count (1), */
  55. 0x81, 0x02, /* Input (Variable), */
  56. 0x75, 0x10, /* Report Size (16), */
  57. 0x95, 0x01, /* Report Count (1), */
  58. 0xA4, /* Push, */
  59. 0x05, 0x01, /* Usage Page (Desktop), */
  60. 0x55, 0xFD, /* Unit Exponent (-3), */
  61. 0x65, 0x13, /* Unit (Inch), */
  62. 0x34, /* Physical Minimum (0), */
  63. 0x09, 0x30, /* Usage (X), */
  64. 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
  65. 0x26, 0x00, 0x37, /* Logical Maximum (14080), */
  66. 0x81, 0x02, /* Input (Variable), */
  67. 0x09, 0x31, /* Usage (Y), */
  68. 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
  69. 0x26, 0x00, 0x28, /* Logical Maximum (10240), */
  70. 0x81, 0x02, /* Input (Variable), */
  71. 0xB4, /* Pop, */
  72. 0x09, 0x30, /* Usage (Tip Pressure), */
  73. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  74. 0x81, 0x02, /* Input (Variable), */
  75. 0xC0, /* End Collection, */
  76. 0xC0 /* End Collection */
  77. };
  78. /*
  79. * See MousePen i608X description, device and HID report descriptors at
  80. * http://sf.net/apps/mediawiki/digimend/?title=KYE_MousePen_i608X
  81. */
  82. /* Original MousePen i608X report descriptor size */
  83. #define MOUSEPEN_I608X_RDESC_ORIG_SIZE 476
  84. /* Fixed MousePen i608X report descriptor */
  85. static __u8 mousepen_i608x_rdesc_fixed[] = {
  86. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  87. 0x09, 0x01, /* Usage (01h), */
  88. 0xA1, 0x01, /* Collection (Application), */
  89. 0x85, 0x05, /* Report ID (5), */
  90. 0x09, 0x01, /* Usage (01h), */
  91. 0x15, 0x80, /* Logical Minimum (-128), */
  92. 0x25, 0x7F, /* Logical Maximum (127), */
  93. 0x75, 0x08, /* Report Size (8), */
  94. 0x95, 0x07, /* Report Count (7), */
  95. 0xB1, 0x02, /* Feature (Variable), */
  96. 0xC0, /* End Collection, */
  97. 0x05, 0x0D, /* Usage Page (Digitizer), */
  98. 0x09, 0x02, /* Usage (Pen), */
  99. 0xA1, 0x01, /* Collection (Application), */
  100. 0x85, 0x10, /* Report ID (16), */
  101. 0x09, 0x20, /* Usage (Stylus), */
  102. 0xA0, /* Collection (Physical), */
  103. 0x14, /* Logical Minimum (0), */
  104. 0x25, 0x01, /* Logical Maximum (1), */
  105. 0x75, 0x01, /* Report Size (1), */
  106. 0x09, 0x42, /* Usage (Tip Switch), */
  107. 0x09, 0x44, /* Usage (Barrel Switch), */
  108. 0x09, 0x46, /* Usage (Tablet Pick), */
  109. 0x95, 0x03, /* Report Count (3), */
  110. 0x81, 0x02, /* Input (Variable), */
  111. 0x95, 0x04, /* Report Count (4), */
  112. 0x81, 0x03, /* Input (Constant, Variable), */
  113. 0x09, 0x32, /* Usage (In Range), */
  114. 0x95, 0x01, /* Report Count (1), */
  115. 0x81, 0x02, /* Input (Variable), */
  116. 0x75, 0x10, /* Report Size (16), */
  117. 0x95, 0x01, /* Report Count (1), */
  118. 0xA4, /* Push, */
  119. 0x05, 0x01, /* Usage Page (Desktop), */
  120. 0x55, 0xFD, /* Unit Exponent (-3), */
  121. 0x65, 0x13, /* Unit (Inch), */
  122. 0x34, /* Physical Minimum (0), */
  123. 0x09, 0x30, /* Usage (X), */
  124. 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
  125. 0x26, 0x00, 0x50, /* Logical Maximum (20480), */
  126. 0x81, 0x02, /* Input (Variable), */
  127. 0x09, 0x31, /* Usage (Y), */
  128. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  129. 0x26, 0x00, 0x3C, /* Logical Maximum (15360), */
  130. 0x81, 0x02, /* Input (Variable), */
  131. 0xB4, /* Pop, */
  132. 0x09, 0x30, /* Usage (Tip Pressure), */
  133. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  134. 0x81, 0x02, /* Input (Variable), */
  135. 0xC0, /* End Collection, */
  136. 0xC0, /* End Collection, */
  137. 0x05, 0x01, /* Usage Page (Desktop), */
  138. 0x09, 0x02, /* Usage (Mouse), */
  139. 0xA1, 0x01, /* Collection (Application), */
  140. 0x85, 0x11, /* Report ID (17), */
  141. 0x09, 0x01, /* Usage (Pointer), */
  142. 0xA0, /* Collection (Physical), */
  143. 0x14, /* Logical Minimum (0), */
  144. 0xA4, /* Push, */
  145. 0x05, 0x09, /* Usage Page (Button), */
  146. 0x75, 0x01, /* Report Size (1), */
  147. 0x19, 0x01, /* Usage Minimum (01h), */
  148. 0x29, 0x03, /* Usage Maximum (03h), */
  149. 0x25, 0x01, /* Logical Maximum (1), */
  150. 0x95, 0x03, /* Report Count (3), */
  151. 0x81, 0x02, /* Input (Variable), */
  152. 0x95, 0x05, /* Report Count (5), */
  153. 0x81, 0x01, /* Input (Constant), */
  154. 0xB4, /* Pop, */
  155. 0x95, 0x01, /* Report Count (1), */
  156. 0xA4, /* Push, */
  157. 0x55, 0xFD, /* Unit Exponent (-3), */
  158. 0x65, 0x13, /* Unit (Inch), */
  159. 0x34, /* Physical Minimum (0), */
  160. 0x75, 0x10, /* Report Size (16), */
  161. 0x09, 0x30, /* Usage (X), */
  162. 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
  163. 0x26, 0x00, 0x50, /* Logical Maximum (20480), */
  164. 0x81, 0x02, /* Input (Variable), */
  165. 0x09, 0x31, /* Usage (Y), */
  166. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  167. 0x26, 0x00, 0x3C, /* Logical Maximum (15360), */
  168. 0x81, 0x02, /* Input (Variable), */
  169. 0xB4, /* Pop, */
  170. 0x75, 0x08, /* Report Size (8), */
  171. 0x09, 0x38, /* Usage (Wheel), */
  172. 0x15, 0xFF, /* Logical Minimum (-1), */
  173. 0x25, 0x01, /* Logical Maximum (1), */
  174. 0x81, 0x06, /* Input (Variable, Relative), */
  175. 0x81, 0x01, /* Input (Constant), */
  176. 0xC0, /* End Collection, */
  177. 0xC0 /* End Collection */
  178. };
  179. /*
  180. * See EasyPen M610X description, device and HID report descriptors at
  181. * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_M610X
  182. */
  183. /* Original EasyPen M610X report descriptor size */
  184. #define EASYPEN_M610X_RDESC_ORIG_SIZE 476
  185. /* Fixed EasyPen M610X report descriptor */
  186. static __u8 easypen_m610x_rdesc_fixed[] = {
  187. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  188. 0x09, 0x01, /* Usage (01h), */
  189. 0xA1, 0x01, /* Collection (Application), */
  190. 0x85, 0x05, /* Report ID (5), */
  191. 0x09, 0x01, /* Usage (01h), */
  192. 0x15, 0x80, /* Logical Minimum (-128), */
  193. 0x25, 0x7F, /* Logical Maximum (127), */
  194. 0x75, 0x08, /* Report Size (8), */
  195. 0x95, 0x07, /* Report Count (7), */
  196. 0xB1, 0x02, /* Feature (Variable), */
  197. 0xC0, /* End Collection, */
  198. 0x05, 0x0D, /* Usage Page (Digitizer), */
  199. 0x09, 0x02, /* Usage (Pen), */
  200. 0xA1, 0x01, /* Collection (Application), */
  201. 0x85, 0x10, /* Report ID (16), */
  202. 0x09, 0x20, /* Usage (Stylus), */
  203. 0xA0, /* Collection (Physical), */
  204. 0x14, /* Logical Minimum (0), */
  205. 0x25, 0x01, /* Logical Maximum (1), */
  206. 0x75, 0x01, /* Report Size (1), */
  207. 0x09, 0x42, /* Usage (Tip Switch), */
  208. 0x09, 0x44, /* Usage (Barrel Switch), */
  209. 0x09, 0x46, /* Usage (Tablet Pick), */
  210. 0x95, 0x03, /* Report Count (3), */
  211. 0x81, 0x02, /* Input (Variable), */
  212. 0x95, 0x04, /* Report Count (4), */
  213. 0x81, 0x03, /* Input (Constant, Variable), */
  214. 0x09, 0x32, /* Usage (In Range), */
  215. 0x95, 0x01, /* Report Count (1), */
  216. 0x81, 0x02, /* Input (Variable), */
  217. 0x75, 0x10, /* Report Size (16), */
  218. 0x95, 0x01, /* Report Count (1), */
  219. 0xA4, /* Push, */
  220. 0x05, 0x01, /* Usage Page (Desktop), */
  221. 0x55, 0xFD, /* Unit Exponent (-3), */
  222. 0x65, 0x13, /* Unit (Inch), */
  223. 0x34, /* Physical Minimum (0), */
  224. 0x09, 0x30, /* Usage (X), */
  225. 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
  226. 0x27, 0x00, 0xA0, 0x00, 0x00, /* Logical Maximum (40960), */
  227. 0x81, 0x02, /* Input (Variable), */
  228. 0x09, 0x31, /* Usage (Y), */
  229. 0x46, 0x6A, 0x18, /* Physical Maximum (6250), */
  230. 0x26, 0x00, 0x64, /* Logical Maximum (25600), */
  231. 0x81, 0x02, /* Input (Variable), */
  232. 0xB4, /* Pop, */
  233. 0x09, 0x30, /* Usage (Tip Pressure), */
  234. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  235. 0x81, 0x02, /* Input (Variable), */
  236. 0xC0, /* End Collection, */
  237. 0xC0, /* End Collection, */
  238. 0x05, 0x0C, /* Usage Page (Consumer), */
  239. 0x09, 0x01, /* Usage (Consumer Control), */
  240. 0xA1, 0x01, /* Collection (Application), */
  241. 0x85, 0x12, /* Report ID (18), */
  242. 0x14, /* Logical Minimum (0), */
  243. 0x25, 0x01, /* Logical Maximum (1), */
  244. 0x75, 0x01, /* Report Size (1), */
  245. 0x95, 0x04, /* Report Count (4), */
  246. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  247. 0x0A, 0x79, 0x02, /* Usage (AC Redo Or Repeat), */
  248. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  249. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  250. 0x81, 0x02, /* Input (Variable), */
  251. 0x95, 0x01, /* Report Count (1), */
  252. 0x75, 0x14, /* Report Size (20), */
  253. 0x81, 0x03, /* Input (Constant, Variable), */
  254. 0x75, 0x20, /* Report Size (32), */
  255. 0x81, 0x03, /* Input (Constant, Variable), */
  256. 0xC0 /* End Collection */
  257. };
  258. /* Original PenSketch M912 report descriptor size */
  259. #define PENSKETCH_M912_RDESC_ORIG_SIZE 482
  260. /* Fixed PenSketch M912 report descriptor */
  261. static __u8 pensketch_m912_rdesc_fixed[] = {
  262. 0x05, 0x01, /* Usage Page (Desktop), */
  263. 0x08, /* Usage (00h), */
  264. 0xA1, 0x01, /* Collection (Application), */
  265. 0x85, 0x05, /* Report ID (5), */
  266. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  267. 0x09, 0x01, /* Usage (01h), */
  268. 0x15, 0x81, /* Logical Minimum (-127), */
  269. 0x25, 0x7F, /* Logical Maximum (127), */
  270. 0x75, 0x08, /* Report Size (8), */
  271. 0x95, 0x07, /* Report Count (7), */
  272. 0xB1, 0x02, /* Feature (Variable), */
  273. 0xC0, /* End Collection, */
  274. 0x05, 0x0D, /* Usage Page (Digitizer), */
  275. 0x09, 0x02, /* Usage (Pen), */
  276. 0xA1, 0x01, /* Collection (Application), */
  277. 0x85, 0x10, /* Report ID (16), */
  278. 0x09, 0x20, /* Usage (Stylus), */
  279. 0xA0, /* Collection (Physical), */
  280. 0x09, 0x42, /* Usage (Tip Switch), */
  281. 0x09, 0x44, /* Usage (Barrel Switch), */
  282. 0x09, 0x46, /* Usage (Tablet Pick), */
  283. 0x14, /* Logical Minimum (0), */
  284. 0x25, 0x01, /* Logical Maximum (1), */
  285. 0x75, 0x01, /* Report Size (1), */
  286. 0x95, 0x03, /* Report Count (3), */
  287. 0x81, 0x02, /* Input (Variable), */
  288. 0x95, 0x04, /* Report Count (4), */
  289. 0x81, 0x03, /* Input (Constant, Variable), */
  290. 0x09, 0x32, /* Usage (In Range), */
  291. 0x95, 0x01, /* Report Count (1), */
  292. 0x81, 0x02, /* Input (Variable), */
  293. 0x75, 0x10, /* Report Size (16), */
  294. 0x95, 0x01, /* Report Count (1), */
  295. 0xA4, /* Push, */
  296. 0x05, 0x01, /* Usage Page (Desktop), */
  297. 0x55, 0xFD, /* Unit Exponent (-3), */
  298. 0x65, 0x13, /* Unit (Inch), */
  299. 0x14, /* Logical Minimum (0), */
  300. 0x34, /* Physical Minimum (0), */
  301. 0x09, 0x30, /* Usage (X), */
  302. 0x27, 0x00, 0xF0, 0x00, 0x00, /* Logical Maximum (61440), */
  303. 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
  304. 0x81, 0x02, /* Input (Variable), */
  305. 0x09, 0x31, /* Usage (Y), */
  306. 0x27, 0x00, 0xB4, 0x00, 0x00, /* Logical Maximum (46080), */
  307. 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
  308. 0x81, 0x02, /* Input (Variable), */
  309. 0xB4, /* Pop, */
  310. 0x09, 0x30, /* Usage (Tip Pressure), */
  311. 0x14, /* Logical Minimum (0), */
  312. 0x26, 0xFF, 0x07, /* Logical Maximum (2047), */
  313. 0x81, 0x02, /* Input (Variable), */
  314. 0xC0, /* End Collection, */
  315. 0xC0, /* End Collection, */
  316. 0x05, 0x0D, /* Usage Page (Digitizer), */
  317. 0x09, 0x21, /* Usage (Puck), */
  318. 0xA1, 0x01, /* Collection (Application), */
  319. 0x85, 0x11, /* Report ID (17), */
  320. 0x09, 0x21, /* Usage (Puck), */
  321. 0xA0, /* Collection (Physical), */
  322. 0x05, 0x09, /* Usage Page (Button), */
  323. 0x75, 0x01, /* Report Size (1), */
  324. 0x19, 0x01, /* Usage Minimum (01h), */
  325. 0x29, 0x03, /* Usage Maximum (03h), */
  326. 0x14, /* Logical Minimum (0), */
  327. 0x25, 0x01, /* Logical Maximum (1), */
  328. 0x95, 0x03, /* Report Count (3), */
  329. 0x81, 0x02, /* Input (Variable), */
  330. 0x95, 0x04, /* Report Count (4), */
  331. 0x81, 0x01, /* Input (Constant), */
  332. 0x95, 0x01, /* Report Count (1), */
  333. 0x0B, 0x32, 0x00, 0x0D, 0x00, /* Usage (Digitizer In Range), */
  334. 0x14, /* Logical Minimum (0), */
  335. 0x25, 0x01, /* Logical Maximum (1), */
  336. 0x81, 0x02, /* Input (Variable), */
  337. 0xA4, /* Push, */
  338. 0x05, 0x01, /* Usage Page (Desktop), */
  339. 0x75, 0x10, /* Report Size (16), */
  340. 0x95, 0x01, /* Report Count (1), */
  341. 0x55, 0xFD, /* Unit Exponent (-3), */
  342. 0x65, 0x13, /* Unit (Inch), */
  343. 0x14, /* Logical Minimum (0), */
  344. 0x34, /* Physical Minimum (0), */
  345. 0x09, 0x30, /* Usage (X), */
  346. 0x27, 0x00, 0xF0, 0x00, 0x00, /* Logical Maximum (61440), */
  347. 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
  348. 0x81, 0x02, /* Input (Variable), */
  349. 0x09, 0x31, /* Usage (Y), */
  350. 0x27, 0x00, 0xB4, 0x00, 0x00, /* Logical Maximum (46080), */
  351. 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
  352. 0x81, 0x02, /* Input (Variable), */
  353. 0x09, 0x38, /* Usage (Wheel), */
  354. 0x75, 0x08, /* Report Size (8), */
  355. 0x95, 0x01, /* Report Count (1), */
  356. 0x15, 0xFF, /* Logical Minimum (-1), */
  357. 0x25, 0x01, /* Logical Maximum (1), */
  358. 0x34, /* Physical Minimum (0), */
  359. 0x44, /* Physical Maximum (0), */
  360. 0x81, 0x06, /* Input (Variable, Relative), */
  361. 0xB4, /* Pop, */
  362. 0xC0, /* End Collection, */
  363. 0xC0, /* End Collection, */
  364. 0x05, 0x0C, /* Usage Page (Consumer), */
  365. 0x09, 0x01, /* Usage (Consumer Control), */
  366. 0xA1, 0x01, /* Collection (Application), */
  367. 0x85, 0x12, /* Report ID (18), */
  368. 0x14, /* Logical Minimum (0), */
  369. 0x25, 0x01, /* Logical Maximum (1), */
  370. 0x75, 0x01, /* Report Size (1), */
  371. 0x95, 0x08, /* Report Count (8), */
  372. 0x05, 0x0C, /* Usage Page (Consumer), */
  373. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  374. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  375. 0x0A, 0x01, 0x02, /* Usage (AC New), */
  376. 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
  377. 0x0A, 0x25, 0x02, /* Usage (AC Forward), */
  378. 0x0A, 0x24, 0x02, /* Usage (AC Back), */
  379. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  380. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  381. 0x81, 0x02, /* Input (Variable), */
  382. 0x95, 0x30, /* Report Count (48), */
  383. 0x81, 0x03, /* Input (Constant, Variable), */
  384. 0xC0 /* End Collection */
  385. };
  386. static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
  387. unsigned int *rsize, int offset, const char *device_name) {
  388. /*
  389. * the fixup that need to be done:
  390. * - change Usage Maximum in the Comsumer Control
  391. * (report ID 3) to a reasonable value
  392. */
  393. if (*rsize >= offset + 31 &&
  394. /* Usage Page (Consumer Devices) */
  395. rdesc[offset] == 0x05 && rdesc[offset + 1] == 0x0c &&
  396. /* Usage (Consumer Control) */
  397. rdesc[offset + 2] == 0x09 && rdesc[offset + 3] == 0x01 &&
  398. /* Usage Maximum > 12287 */
  399. rdesc[offset + 10] == 0x2a && rdesc[offset + 12] > 0x2f) {
  400. hid_info(hdev, "fixing up %s report descriptor\n", device_name);
  401. rdesc[offset + 12] = 0x2f;
  402. }
  403. return rdesc;
  404. }
  405. static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  406. unsigned int *rsize)
  407. {
  408. switch (hdev->product) {
  409. case USB_DEVICE_ID_KYE_ERGO_525V:
  410. /* the fixups that need to be done:
  411. * - change led usage page to button for extra buttons
  412. * - report size 8 count 1 must be size 1 count 8 for button
  413. * bitfield
  414. * - change the button usage range to 4-7 for the extra
  415. * buttons
  416. */
  417. if (*rsize >= 75 &&
  418. rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
  419. rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
  420. rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
  421. rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
  422. rdesc[73] == 0x95 && rdesc[74] == 0x01) {
  423. hid_info(hdev,
  424. "fixing up Kye/Genius Ergo Mouse "
  425. "report descriptor\n");
  426. rdesc[62] = 0x09;
  427. rdesc[64] = 0x04;
  428. rdesc[66] = 0x07;
  429. rdesc[72] = 0x01;
  430. rdesc[74] = 0x08;
  431. }
  432. break;
  433. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  434. if (*rsize == EASYPEN_I405X_RDESC_ORIG_SIZE) {
  435. rdesc = easypen_i405x_rdesc_fixed;
  436. *rsize = sizeof(easypen_i405x_rdesc_fixed);
  437. }
  438. break;
  439. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  440. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
  441. if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) {
  442. rdesc = mousepen_i608x_rdesc_fixed;
  443. *rsize = sizeof(mousepen_i608x_rdesc_fixed);
  444. }
  445. break;
  446. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  447. if (*rsize == EASYPEN_M610X_RDESC_ORIG_SIZE) {
  448. rdesc = easypen_m610x_rdesc_fixed;
  449. *rsize = sizeof(easypen_m610x_rdesc_fixed);
  450. }
  451. break;
  452. case USB_DEVICE_ID_KYE_PENSKETCH_M912:
  453. if (*rsize == PENSKETCH_M912_RDESC_ORIG_SIZE) {
  454. rdesc = pensketch_m912_rdesc_fixed;
  455. *rsize = sizeof(pensketch_m912_rdesc_fixed);
  456. }
  457. break;
  458. case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
  459. rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
  460. "Genius Gila Gaming Mouse");
  461. break;
  462. case USB_DEVICE_ID_GENIUS_GX_IMPERATOR:
  463. rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 83,
  464. "Genius Gx Imperator Keyboard");
  465. break;
  466. case USB_DEVICE_ID_GENIUS_MANTICORE:
  467. rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
  468. "Genius Manticore Keyboard");
  469. break;
  470. }
  471. return rdesc;
  472. }
  473. /**
  474. * Enable fully-functional tablet mode by setting a special feature report.
  475. *
  476. * @hdev: HID device
  477. *
  478. * The specific report ID and data were discovered by sniffing the
  479. * Windows driver traffic.
  480. */
  481. static int kye_tablet_enable(struct hid_device *hdev)
  482. {
  483. struct list_head *list;
  484. struct list_head *head;
  485. struct hid_report *report;
  486. __s32 *value;
  487. list = &hdev->report_enum[HID_FEATURE_REPORT].report_list;
  488. list_for_each(head, list) {
  489. report = list_entry(head, struct hid_report, list);
  490. if (report->id == 5)
  491. break;
  492. }
  493. if (head == list) {
  494. hid_err(hdev, "tablet-enabling feature report not found\n");
  495. return -ENODEV;
  496. }
  497. if (report->maxfield < 1 || report->field[0]->report_count < 7) {
  498. hid_err(hdev, "invalid tablet-enabling feature report\n");
  499. return -ENODEV;
  500. }
  501. value = report->field[0]->value;
  502. value[0] = 0x12;
  503. value[1] = 0x10;
  504. value[2] = 0x11;
  505. value[3] = 0x12;
  506. value[4] = 0x00;
  507. value[5] = 0x00;
  508. value[6] = 0x00;
  509. hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
  510. return 0;
  511. }
  512. static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
  513. {
  514. int ret;
  515. ret = hid_parse(hdev);
  516. if (ret) {
  517. hid_err(hdev, "parse failed\n");
  518. goto err;
  519. }
  520. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  521. if (ret) {
  522. hid_err(hdev, "hw start failed\n");
  523. goto err;
  524. }
  525. switch (id->product) {
  526. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  527. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  528. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
  529. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  530. case USB_DEVICE_ID_KYE_PENSKETCH_M912:
  531. ret = kye_tablet_enable(hdev);
  532. if (ret) {
  533. hid_err(hdev, "tablet enabling failed\n");
  534. goto enabling_err;
  535. }
  536. break;
  537. case USB_DEVICE_ID_GENIUS_MANTICORE:
  538. /*
  539. * The manticore keyboard needs to have all the interfaces
  540. * opened at least once to be fully functional.
  541. */
  542. if (hid_hw_open(hdev))
  543. hid_hw_close(hdev);
  544. break;
  545. }
  546. return 0;
  547. enabling_err:
  548. hid_hw_stop(hdev);
  549. err:
  550. return ret;
  551. }
  552. static const struct hid_device_id kye_devices[] = {
  553. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  554. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  555. USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  556. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  557. USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  558. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  559. USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
  560. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  561. USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  562. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  563. USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
  564. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  565. USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
  566. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  567. USB_DEVICE_ID_GENIUS_MANTICORE) },
  568. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  569. USB_DEVICE_ID_KYE_PENSKETCH_M912) },
  570. { }
  571. };
  572. MODULE_DEVICE_TABLE(hid, kye_devices);
  573. static struct hid_driver kye_driver = {
  574. .name = "kye",
  575. .id_table = kye_devices,
  576. .probe = kye_probe,
  577. .report_fixup = kye_report_fixup,
  578. };
  579. module_hid_driver(kye_driver);
  580. MODULE_LICENSE("GPL");