hid-kye.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * HID driver for Kye/Genius devices not fully compliant with HID standard
  4. *
  5. * Copyright (c) 2009 Jiri Kosina
  6. * Copyright (c) 2009 Tomas Hanak
  7. * Copyright (c) 2012 Nikolai Kondrashov
  8. * Copyright (c) 2023 David Yang
  9. */
  10. #include <linux/unaligned.h>
  11. #include <linux/device.h>
  12. #include <linux/hid.h>
  13. #include <linux/module.h>
  14. #include "hid-ids.h"
  15. /* Data gathered from Database/VID0458_PID????/Vista/TBoard/default.xml in ioTablet driver
  16. *
  17. * TODO:
  18. * - Add battery and sleep support for EasyPen M406W and MousePen M508WX
  19. * - Investigate ScrollZ.MiceFMT buttons of EasyPen M406
  20. */
  21. static const __u8 easypen_m406_control_rdesc[] = {
  22. 0x05, 0x0C, /* Usage Page (Consumer), */
  23. 0x09, 0x01, /* Usage (Consumer Control), */
  24. 0xA1, 0x01, /* Collection (Application), */
  25. 0x85, 0x12, /* Report ID (18), */
  26. 0x0A, 0x45, 0x02, /* Usage (AC Rotate), */
  27. 0x09, 0x40, /* Usage (Menu), */
  28. 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
  29. 0x0A, 0x46, 0x02, /* Usage (AC Resize), */
  30. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  31. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  32. 0x0A, 0x24, 0x02, /* Usage (AC Back), */
  33. 0x0A, 0x25, 0x02, /* Usage (AC Forward), */
  34. 0x14, /* Logical Minimum (0), */
  35. 0x25, 0x01, /* Logical Maximum (1), */
  36. 0x75, 0x01, /* Report Size (1), */
  37. 0x95, 0x08, /* Report Count (8), */
  38. 0x81, 0x02, /* Input (Variable), */
  39. 0x95, 0x30, /* Report Count (48), */
  40. 0x81, 0x01, /* Input (Constant), */
  41. 0xC0 /* End Collection */
  42. };
  43. static const __u8 easypen_m506_control_rdesc[] = {
  44. 0x05, 0x0C, /* Usage Page (Consumer), */
  45. 0x09, 0x01, /* Usage (Consumer Control), */
  46. 0xA1, 0x01, /* Collection (Application), */
  47. 0x85, 0x12, /* Report ID (18), */
  48. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  49. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  50. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  51. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  52. 0x14, /* Logical Minimum (0), */
  53. 0x25, 0x01, /* Logical Maximum (1), */
  54. 0x75, 0x01, /* Report Size (1), */
  55. 0x95, 0x04, /* Report Count (4), */
  56. 0x81, 0x02, /* Input (Variable), */
  57. 0x95, 0x34, /* Report Count (52), */
  58. 0x81, 0x01, /* Input (Constant), */
  59. 0xC0 /* End Collection */
  60. };
  61. static const __u8 easypen_m406w_control_rdesc[] = {
  62. 0x05, 0x0C, /* Usage Page (Consumer), */
  63. 0x09, 0x01, /* Usage (Consumer Control), */
  64. 0xA1, 0x01, /* Collection (Application), */
  65. 0x85, 0x12, /* Report ID (18), */
  66. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  67. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  68. 0x0A, 0x01, 0x02, /* Usage (AC New), */
  69. 0x09, 0x40, /* Usage (Menu), */
  70. 0x14, /* Logical Minimum (0), */
  71. 0x25, 0x01, /* Logical Maximum (1), */
  72. 0x75, 0x01, /* Report Size (1), */
  73. 0x95, 0x04, /* Report Count (4), */
  74. 0x81, 0x02, /* Input (Variable), */
  75. 0x95, 0x34, /* Report Count (52), */
  76. 0x81, 0x01, /* Input (Constant), */
  77. 0xC0 /* End Collection */
  78. };
  79. static const __u8 easypen_m610x_control_rdesc[] = {
  80. 0x05, 0x0C, /* Usage Page (Consumer), */
  81. 0x09, 0x01, /* Usage (Consumer Control), */
  82. 0xA1, 0x01, /* Collection (Application), */
  83. 0x85, 0x12, /* Report ID (18), */
  84. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  85. 0x0A, 0x79, 0x02, /* Usage (AC Redo Or Repeat), */
  86. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  87. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  88. 0x14, /* Logical Minimum (0), */
  89. 0x25, 0x01, /* Logical Maximum (1), */
  90. 0x75, 0x01, /* Report Size (1), */
  91. 0x95, 0x04, /* Report Count (4), */
  92. 0x81, 0x02, /* Input (Variable), */
  93. 0x95, 0x34, /* Report Count (52), */
  94. 0x81, 0x01, /* Input (Constant), */
  95. 0xC0 /* End Collection */
  96. };
  97. static const __u8 pensketch_m912_control_rdesc[] = {
  98. 0x05, 0x0C, /* Usage Page (Consumer), */
  99. 0x09, 0x01, /* Usage (Consumer Control), */
  100. 0xA1, 0x01, /* Collection (Application), */
  101. 0x85, 0x12, /* Report ID (18), */
  102. 0x14, /* Logical Minimum (0), */
  103. 0x25, 0x01, /* Logical Maximum (1), */
  104. 0x75, 0x01, /* Report Size (1), */
  105. 0x95, 0x08, /* Report Count (8), */
  106. 0x05, 0x0C, /* Usage Page (Consumer), */
  107. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  108. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  109. 0x0A, 0x01, 0x02, /* Usage (AC New), */
  110. 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
  111. 0x0A, 0x25, 0x02, /* Usage (AC Forward), */
  112. 0x0A, 0x24, 0x02, /* Usage (AC Back), */
  113. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  114. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  115. 0x81, 0x02, /* Input (Variable), */
  116. 0x95, 0x30, /* Report Count (48), */
  117. 0x81, 0x03, /* Input (Constant, Variable), */
  118. 0xC0 /* End Collection */
  119. };
  120. static const __u8 mousepen_m508wx_control_rdesc[] = {
  121. 0x05, 0x0C, /* Usage Page (Consumer), */
  122. 0x09, 0x01, /* Usage (Consumer Control), */
  123. 0xA1, 0x01, /* Collection (Application), */
  124. 0x85, 0x12, /* Report ID (18), */
  125. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  126. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  127. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  128. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  129. 0x14, /* Logical Minimum (0), */
  130. 0x25, 0x01, /* Logical Maximum (1), */
  131. 0x75, 0x01, /* Report Size (1), */
  132. 0x95, 0x04, /* Report Count (4), */
  133. 0x81, 0x02, /* Input (Variable), */
  134. 0x95, 0x34, /* Report Count (52), */
  135. 0x81, 0x01, /* Input (Constant), */
  136. 0xC0 /* End Collection */
  137. };
  138. static const __u8 mousepen_m508x_control_rdesc[] = {
  139. 0x05, 0x0C, /* Usage Page (Consumer), */
  140. 0x09, 0x01, /* Usage (Consumer Control), */
  141. 0xA1, 0x01, /* Collection (Application), */
  142. 0x85, 0x12, /* Report ID (18), */
  143. 0x0A, 0x01, 0x02, /* Usage (AC New), */
  144. 0x09, 0x40, /* Usage (Menu), */
  145. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  146. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  147. 0x14, /* Logical Minimum (0), */
  148. 0x25, 0x01, /* Logical Maximum (1), */
  149. 0x75, 0x01, /* Report Size (1), */
  150. 0x95, 0x04, /* Report Count (4), */
  151. 0x81, 0x02, /* Input (Variable), */
  152. 0x81, 0x01, /* Input (Constant), */
  153. 0x15, 0xFF, /* Logical Minimum (-1), */
  154. 0x95, 0x10, /* Report Count (16), */
  155. 0x81, 0x01, /* Input (Constant), */
  156. 0x0A, 0x35, 0x02, /* Usage (AC Scroll), */
  157. 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
  158. 0x0A, 0x38, 0x02, /* Usage (AC Pan), */
  159. 0x75, 0x08, /* Report Size (8), */
  160. 0x95, 0x03, /* Report Count (3), */
  161. 0x81, 0x06, /* Input (Variable, Relative), */
  162. 0x95, 0x01, /* Report Count (1), */
  163. 0x81, 0x01, /* Input (Constant), */
  164. 0xC0 /* End Collection */
  165. };
  166. static const __u8 easypen_m406xe_control_rdesc[] = {
  167. 0x05, 0x0C, /* Usage Page (Consumer), */
  168. 0x09, 0x01, /* Usage (Consumer Control), */
  169. 0xA1, 0x01, /* Collection (Application), */
  170. 0x85, 0x12, /* Report ID (18), */
  171. 0x14, /* Logical Minimum (0), */
  172. 0x25, 0x01, /* Logical Maximum (1), */
  173. 0x75, 0x01, /* Report Size (1), */
  174. 0x95, 0x04, /* Report Count (4), */
  175. 0x0A, 0x79, 0x02, /* Usage (AC Redo Or Repeat), */
  176. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  177. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  178. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  179. 0x81, 0x02, /* Input (Variable), */
  180. 0x95, 0x34, /* Report Count (52), */
  181. 0x81, 0x03, /* Input (Constant, Variable), */
  182. 0xC0 /* End Collection */
  183. };
  184. static const __u8 pensketch_t609a_control_rdesc[] = {
  185. 0x05, 0x0C, /* Usage Page (Consumer), */
  186. 0x09, 0x01, /* Usage (Consumer Control), */
  187. 0xA1, 0x01, /* Collection (Application), */
  188. 0x85, 0x12, /* Report ID (18), */
  189. 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
  190. 0x14, /* Logical Minimum (0), */
  191. 0x25, 0x01, /* Logical Maximum (1), */
  192. 0x75, 0x01, /* Report Size (1), */
  193. 0x95, 0x08, /* Report Count (8), */
  194. 0x81, 0x02, /* Input (Variable), */
  195. 0x95, 0x37, /* Report Count (55), */
  196. 0x81, 0x01, /* Input (Constant), */
  197. 0xC0 /* End Collection */
  198. };
  199. /* Fix indexes in kye_tablet_fixup() if you change this */
  200. static const __u8 kye_tablet_rdesc[] = {
  201. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  202. 0x09, 0x01, /* Usage (01h), */
  203. 0xA1, 0x01, /* Collection (Application), */
  204. 0x85, 0x05, /* Report ID (5), */
  205. 0x09, 0x01, /* Usage (01h), */
  206. 0x15, 0x81, /* Logical Minimum (-127), */
  207. 0x25, 0x7F, /* Logical Maximum (127), */
  208. 0x75, 0x08, /* Report Size (8), */
  209. 0x95, 0x07, /* Report Count (7), */
  210. 0xB1, 0x02, /* Feature (Variable), */
  211. 0xC0, /* End Collection, */
  212. 0x05, 0x0D, /* Usage Page (Digitizer), */
  213. 0x09, 0x01, /* Usage (Digitizer), */
  214. 0xA1, 0x01, /* Collection (Application), */
  215. 0x85, 0x10, /* Report ID (16), */
  216. 0x09, 0x20, /* Usage (Stylus), */
  217. 0xA0, /* Collection (Physical), */
  218. 0x09, 0x42, /* Usage (Tip Switch), */
  219. 0x09, 0x44, /* Usage (Barrel Switch), */
  220. 0x09, 0x46, /* Usage (Tablet Pick), */
  221. 0x14, /* Logical Minimum (0), */
  222. 0x25, 0x01, /* Logical Maximum (1), */
  223. 0x75, 0x01, /* Report Size (1), */
  224. 0x95, 0x03, /* Report Count (3), */
  225. 0x81, 0x02, /* Input (Variable), */
  226. 0x95, 0x04, /* Report Count (4), */
  227. 0x81, 0x01, /* Input (Constant), */
  228. 0x09, 0x32, /* Usage (In Range), */
  229. 0x95, 0x01, /* Report Count (1), */
  230. 0x81, 0x02, /* Input (Variable), */
  231. 0x75, 0x10, /* Report Size (16), */
  232. 0xA4, /* Push, */
  233. 0x05, 0x01, /* Usage Page (Desktop), */
  234. 0x09, 0x30, /* Usage (X), */
  235. 0x27, 0xFF, 0x7F, 0x00, 0x00, /* Logical Maximum (32767), */
  236. 0x34, /* Physical Minimum (0), */
  237. 0x47, 0x00, 0x00, 0x00, 0x00, /* Physical Maximum (0), */
  238. 0x65, 0x11, /* Unit (Centimeter), */
  239. 0x55, 0x00, /* Unit Exponent (0), */
  240. 0x75, 0x10, /* Report Size (16), */
  241. 0x81, 0x02, /* Input (Variable), */
  242. 0x09, 0x31, /* Usage (Y), */
  243. 0x27, 0xFF, 0x7F, 0x00, 0x00, /* Logical Maximum (32767), */
  244. 0x47, 0x00, 0x00, 0x00, 0x00, /* Physical Maximum (0), */
  245. 0x81, 0x02, /* Input (Variable), */
  246. 0xB4, /* Pop, */
  247. 0x05, 0x0D, /* Usage Page (Digitizer), */
  248. 0x09, 0x30, /* Usage (Tip Pressure), */
  249. 0x27, 0xFF, 0x07, 0x00, 0x00, /* Logical Maximum (2047), */
  250. 0x81, 0x02, /* Input (Variable), */
  251. 0xC0, /* End Collection, */
  252. 0xC0 /* End Collection, */
  253. };
  254. /* Fix indexes in kye_tablet_fixup() if you change this */
  255. static const __u8 kye_tablet_mouse_rdesc[] = {
  256. 0x05, 0x01, /* Usage Page (Desktop), */
  257. 0x09, 0x02, /* Usage (Mouse), */
  258. 0xA1, 0x01, /* Collection (Application), */
  259. 0x85, 0x11, /* Report ID (17), */
  260. 0x09, 0x01, /* Usage (Pointer), */
  261. 0xA0, /* Collection (Physical), */
  262. 0x05, 0x09, /* Usage Page (Button), */
  263. 0x19, 0x01, /* Usage Minimum (01h), */
  264. 0x29, 0x03, /* Usage Maximum (03h), */
  265. 0x14, /* Logical Minimum (0), */
  266. 0x25, 0x01, /* Logical Maximum (1), */
  267. 0x75, 0x01, /* Report Size (1), */
  268. 0x95, 0x03, /* Report Count (3), */
  269. 0x81, 0x02, /* Input (Variable), */
  270. 0x95, 0x04, /* Report Count (4), */
  271. 0x81, 0x01, /* Input (Constant), */
  272. 0x05, 0x0D, /* Usage Page (Digitizer), */
  273. 0x09, 0x37, /* Usage (Data Valid), */
  274. 0x95, 0x01, /* Report Count (1), */
  275. 0x81, 0x02, /* Input (Variable), */
  276. 0x05, 0x01, /* Usage Page (Desktop), */
  277. 0xA4, /* Push, */
  278. 0x09, 0x30, /* Usage (X), */
  279. 0x27, 0xFF, 0x7F, 0x00, 0x00, /* Logical Maximum (32767), */
  280. 0x34, /* Physical Minimum (0), */
  281. 0x47, 0x00, 0x00, 0x00, 0x00, /* Physical Maximum (0), */
  282. 0x65, 0x11, /* Unit (Centimeter), */
  283. 0x55, 0x00, /* Unit Exponent (0), */
  284. 0x75, 0x10, /* Report Size (16), */
  285. 0x81, 0x02, /* Input (Variable), */
  286. 0x09, 0x31, /* Usage (Y), */
  287. 0x27, 0xFF, 0x7F, 0x00, 0x00, /* Logical Maximum (32767), */
  288. 0x47, 0x00, 0x00, 0x00, 0x00, /* Physical Maximum (0), */
  289. 0x81, 0x02, /* Input (Variable), */
  290. 0xB4, /* Pop, */
  291. 0x09, 0x38, /* Usage (Wheel), */
  292. 0x15, 0xFF, /* Logical Minimum (-1), */
  293. 0x75, 0x08, /* Report Size (8), */
  294. 0x95, 0x01, /* Report Count (1), */
  295. 0x81, 0x06, /* Input (Variable, Relative), */
  296. 0x81, 0x01, /* Input (Constant), */
  297. 0xC0, /* End Collection, */
  298. 0xC0 /* End Collection */
  299. };
  300. static const struct kye_tablet_info {
  301. __u32 product;
  302. __s32 x_logical_maximum;
  303. __s32 y_logical_maximum;
  304. __s32 pressure_logical_maximum;
  305. __s32 x_physical_maximum;
  306. __s32 y_physical_maximum;
  307. __s8 unit_exponent;
  308. __s8 unit;
  309. bool has_mouse;
  310. unsigned int control_rsize;
  311. const __u8 *control_rdesc;
  312. } kye_tablets_info[] = {
  313. {USB_DEVICE_ID_KYE_EASYPEN_M406, /* 0x5005 */
  314. 15360, 10240, 1023, 6, 4, 0, 0x13, false,
  315. sizeof(easypen_m406_control_rdesc), easypen_m406_control_rdesc},
  316. {USB_DEVICE_ID_KYE_EASYPEN_M506, /* 0x500F */
  317. 24576, 20480, 1023, 6, 5, 0, 0x13, false,
  318. sizeof(easypen_m506_control_rdesc), easypen_m506_control_rdesc},
  319. {USB_DEVICE_ID_KYE_EASYPEN_I405X, /* 0x5010 */
  320. 14080, 10240, 1023, 55, 40, -1, 0x13, false},
  321. {USB_DEVICE_ID_KYE_MOUSEPEN_I608X, /* 0x5011 */
  322. 20480, 15360, 2047, 8, 6, 0, 0x13, true},
  323. {USB_DEVICE_ID_KYE_EASYPEN_M406W, /* 0x5012 */
  324. 15360, 10240, 1023, 6, 4, 0, 0x13, false,
  325. sizeof(easypen_m406w_control_rdesc), easypen_m406w_control_rdesc},
  326. {USB_DEVICE_ID_KYE_EASYPEN_M610X, /* 0x5013 */
  327. 40960, 25600, 1023, 1000, 625, -2, 0x13, false,
  328. sizeof(easypen_m610x_control_rdesc), easypen_m610x_control_rdesc},
  329. {USB_DEVICE_ID_KYE_EASYPEN_340, /* 0x5014 */
  330. 10240, 7680, 1023, 4, 3, 0, 0x13, false},
  331. {USB_DEVICE_ID_KYE_PENSKETCH_M912, /* 0x5015 */
  332. 61440, 46080, 2047, 12, 9, 0, 0x13, true,
  333. sizeof(pensketch_m912_control_rdesc), pensketch_m912_control_rdesc},
  334. {USB_DEVICE_ID_KYE_MOUSEPEN_M508WX, /* 0x5016 */
  335. 40960, 25600, 2047, 8, 5, 0, 0x13, true,
  336. sizeof(mousepen_m508wx_control_rdesc), mousepen_m508wx_control_rdesc},
  337. {USB_DEVICE_ID_KYE_MOUSEPEN_M508X, /* 0x5017 */
  338. 40960, 25600, 2047, 8, 5, 0, 0x13, true,
  339. sizeof(mousepen_m508x_control_rdesc), mousepen_m508x_control_rdesc},
  340. {USB_DEVICE_ID_KYE_EASYPEN_M406XE, /* 0x5019 */
  341. 15360, 10240, 1023, 6, 4, 0, 0x13, false,
  342. sizeof(easypen_m406xe_control_rdesc), easypen_m406xe_control_rdesc},
  343. {USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2, /* 0x501A */
  344. 40960, 30720, 2047, 8, 6, 0, 0x13, true},
  345. {USB_DEVICE_ID_KYE_PENSKETCH_T609A, /* 0x501B */
  346. 43520, 28160, 1023, 85, 55, -1, 0x13, false,
  347. sizeof(pensketch_t609a_control_rdesc), pensketch_t609a_control_rdesc},
  348. {}
  349. };
  350. static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
  351. unsigned int *rsize, int offset, const char *device_name)
  352. {
  353. /*
  354. * the fixup that need to be done:
  355. * - change Usage Maximum in the Consumer Control
  356. * (report ID 3) to a reasonable value
  357. */
  358. if (*rsize >= offset + 31 &&
  359. /* Usage Page (Consumer Devices) */
  360. rdesc[offset] == 0x05 && rdesc[offset + 1] == 0x0c &&
  361. /* Usage (Consumer Control) */
  362. rdesc[offset + 2] == 0x09 && rdesc[offset + 3] == 0x01 &&
  363. /* Usage Maximum > 12287 */
  364. rdesc[offset + 10] == 0x2a && rdesc[offset + 12] > 0x2f) {
  365. hid_info(hdev, "fixing up %s report descriptor\n", device_name);
  366. rdesc[offset + 12] = 0x2f;
  367. }
  368. return rdesc;
  369. }
  370. /*
  371. * Fix tablet descriptor of so-called "DataFormat 2".
  372. *
  373. * Though we may achieve a usable descriptor from original vendor-defined one,
  374. * some problems exist:
  375. * - Their Logical Maximum never exceed 32767 (7F FF), though device do report
  376. * values greater than that;
  377. * - Physical Maximums are arbitrarily filled (always equal to Logical
  378. * Maximum);
  379. * - Detail for control buttons are not provided (a vendor-defined Usage Page
  380. * with fixed content).
  381. *
  382. * Thus we use a pre-defined parameter table rather than digging it from
  383. * original descriptor.
  384. *
  385. * We may as well write a fallback routine for unrecognized kye tablet, but it's
  386. * clear kye are unlikely to produce new models in the foreseeable future, so we
  387. * simply enumerate all possible models.
  388. */
  389. static __u8 *kye_tablet_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize)
  390. {
  391. const struct kye_tablet_info *info;
  392. __u8 *newdesc = rdesc;
  393. if (*rsize < sizeof(kye_tablet_rdesc)) {
  394. hid_warn(hdev,
  395. "tablet report size too small, or kye_tablet_rdesc unexpectedly large\n");
  396. return rdesc;
  397. }
  398. for (info = kye_tablets_info; info->product; info++) {
  399. if (hdev->product == info->product)
  400. break;
  401. }
  402. if (!info->product) {
  403. hid_err(hdev, "tablet unknown, someone forget to add kye_tablet_info entry?\n");
  404. return rdesc;
  405. }
  406. memcpy(newdesc, kye_tablet_rdesc, sizeof(kye_tablet_rdesc));
  407. put_unaligned_le32(info->x_logical_maximum, newdesc + 66);
  408. put_unaligned_le32(info->x_physical_maximum, newdesc + 72);
  409. newdesc[77] = info->unit;
  410. newdesc[79] = info->unit_exponent;
  411. put_unaligned_le32(info->y_logical_maximum, newdesc + 87);
  412. put_unaligned_le32(info->y_physical_maximum, newdesc + 92);
  413. put_unaligned_le32(info->pressure_logical_maximum, newdesc + 104);
  414. newdesc += sizeof(kye_tablet_rdesc);
  415. if (info->has_mouse) {
  416. if (newdesc + sizeof(kye_tablet_mouse_rdesc) > rdesc + *rsize)
  417. hid_err(hdev, "control desc unexpectedly large\n");
  418. else {
  419. memcpy(newdesc, kye_tablet_mouse_rdesc, sizeof(kye_tablet_mouse_rdesc));
  420. put_unaligned_le32(info->x_logical_maximum, newdesc + 44);
  421. put_unaligned_le32(info->x_physical_maximum, newdesc + 50);
  422. newdesc[55] = info->unit;
  423. newdesc[57] = info->unit_exponent;
  424. put_unaligned_le32(info->y_logical_maximum, newdesc + 65);
  425. put_unaligned_le32(info->y_physical_maximum, newdesc + 70);
  426. newdesc += sizeof(kye_tablet_mouse_rdesc);
  427. }
  428. }
  429. if (info->control_rsize) {
  430. if (newdesc + info->control_rsize > rdesc + *rsize)
  431. hid_err(hdev, "control desc unexpectedly large\n");
  432. else {
  433. memcpy(newdesc, info->control_rdesc, info->control_rsize);
  434. newdesc += info->control_rsize;
  435. }
  436. }
  437. *rsize = newdesc - rdesc;
  438. return rdesc;
  439. }
  440. static const __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  441. unsigned int *rsize)
  442. {
  443. switch (hdev->product) {
  444. case USB_DEVICE_ID_KYE_ERGO_525V:
  445. /* the fixups that need to be done:
  446. * - change led usage page to button for extra buttons
  447. * - report size 8 count 1 must be size 1 count 8 for button
  448. * bitfield
  449. * - change the button usage range to 4-7 for the extra
  450. * buttons
  451. */
  452. if (*rsize >= 75 &&
  453. rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
  454. rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
  455. rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
  456. rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
  457. rdesc[73] == 0x95 && rdesc[74] == 0x01) {
  458. hid_info(hdev,
  459. "fixing up Kye/Genius Ergo Mouse "
  460. "report descriptor\n");
  461. rdesc[62] = 0x09;
  462. rdesc[64] = 0x04;
  463. rdesc[66] = 0x07;
  464. rdesc[72] = 0x01;
  465. rdesc[74] = 0x08;
  466. }
  467. break;
  468. case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
  469. rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
  470. "Genius Gila Gaming Mouse");
  471. break;
  472. case USB_DEVICE_ID_GENIUS_MANTICORE:
  473. rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
  474. "Genius Manticore Keyboard");
  475. break;
  476. case USB_DEVICE_ID_GENIUS_GX_IMPERATOR:
  477. rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 83,
  478. "Genius Gx Imperator Keyboard");
  479. break;
  480. case USB_DEVICE_ID_KYE_EASYPEN_M406:
  481. case USB_DEVICE_ID_KYE_EASYPEN_M506:
  482. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  483. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  484. case USB_DEVICE_ID_KYE_EASYPEN_M406W:
  485. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  486. case USB_DEVICE_ID_KYE_EASYPEN_340:
  487. case USB_DEVICE_ID_KYE_PENSKETCH_M912:
  488. case USB_DEVICE_ID_KYE_MOUSEPEN_M508WX:
  489. case USB_DEVICE_ID_KYE_MOUSEPEN_M508X:
  490. case USB_DEVICE_ID_KYE_EASYPEN_M406XE:
  491. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2:
  492. case USB_DEVICE_ID_KYE_PENSKETCH_T609A:
  493. rdesc = kye_tablet_fixup(hdev, rdesc, rsize);
  494. break;
  495. }
  496. return rdesc;
  497. }
  498. static int kye_tablet_enable(struct hid_device *hdev)
  499. {
  500. struct list_head *list;
  501. struct list_head *head;
  502. struct hid_report *report;
  503. __s32 *value;
  504. list = &hdev->report_enum[HID_FEATURE_REPORT].report_list;
  505. list_for_each(head, list) {
  506. report = list_entry(head, struct hid_report, list);
  507. if (report->id == 5)
  508. break;
  509. }
  510. if (head == list) {
  511. hid_err(hdev, "tablet-enabling feature report not found\n");
  512. return -ENODEV;
  513. }
  514. if (report->maxfield < 1 || report->field[0]->report_count < 7) {
  515. hid_err(hdev, "invalid tablet-enabling feature report\n");
  516. return -ENODEV;
  517. }
  518. value = report->field[0]->value;
  519. /*
  520. * The code is for DataFormat 2 of config xml. They have no obvious
  521. * meaning (at least not configurable in Windows driver) except enabling
  522. * fully-functional tablet mode (absolute positioning). Otherwise, the
  523. * tablet acts like a relative mouse.
  524. *
  525. * Though there're magic codes for DataFormat 3 and 4, no devices use
  526. * these DataFormats.
  527. */
  528. value[0] = 0x12;
  529. value[1] = 0x10;
  530. value[2] = 0x11;
  531. value[3] = 0x12;
  532. value[4] = 0x00;
  533. value[5] = 0x00;
  534. value[6] = 0x00;
  535. hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
  536. return 0;
  537. }
  538. static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
  539. {
  540. int ret;
  541. ret = hid_parse(hdev);
  542. if (ret) {
  543. hid_err(hdev, "parse failed\n");
  544. goto err;
  545. }
  546. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  547. if (ret) {
  548. hid_err(hdev, "hw start failed\n");
  549. goto err;
  550. }
  551. switch (id->product) {
  552. case USB_DEVICE_ID_GENIUS_MANTICORE:
  553. /*
  554. * The manticore keyboard needs to have all the interfaces
  555. * opened at least once to be fully functional.
  556. */
  557. if (hid_hw_open(hdev))
  558. hid_hw_close(hdev);
  559. break;
  560. case USB_DEVICE_ID_KYE_EASYPEN_M406:
  561. case USB_DEVICE_ID_KYE_EASYPEN_M506:
  562. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  563. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  564. case USB_DEVICE_ID_KYE_EASYPEN_M406W:
  565. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  566. case USB_DEVICE_ID_KYE_EASYPEN_340:
  567. case USB_DEVICE_ID_KYE_PENSKETCH_M912:
  568. case USB_DEVICE_ID_KYE_MOUSEPEN_M508WX:
  569. case USB_DEVICE_ID_KYE_MOUSEPEN_M508X:
  570. case USB_DEVICE_ID_KYE_EASYPEN_M406XE:
  571. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2:
  572. case USB_DEVICE_ID_KYE_PENSKETCH_T609A:
  573. ret = kye_tablet_enable(hdev);
  574. if (ret) {
  575. hid_err(hdev, "tablet enabling failed\n");
  576. goto enabling_err;
  577. }
  578. break;
  579. }
  580. return 0;
  581. enabling_err:
  582. hid_hw_stop(hdev);
  583. err:
  584. return ret;
  585. }
  586. static const struct hid_device_id kye_devices[] = {
  587. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  588. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  589. USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
  590. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  591. USB_DEVICE_ID_GENIUS_MANTICORE) },
  592. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  593. USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
  594. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  595. USB_DEVICE_ID_KYE_EASYPEN_M406) },
  596. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  597. USB_DEVICE_ID_KYE_EASYPEN_M506) },
  598. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  599. USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  600. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  601. USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  602. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  603. USB_DEVICE_ID_KYE_EASYPEN_M406W) },
  604. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  605. USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  606. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  607. USB_DEVICE_ID_KYE_EASYPEN_340) },
  608. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  609. USB_DEVICE_ID_KYE_PENSKETCH_M912) },
  610. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  611. USB_DEVICE_ID_KYE_MOUSEPEN_M508WX) },
  612. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  613. USB_DEVICE_ID_KYE_MOUSEPEN_M508X) },
  614. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  615. USB_DEVICE_ID_KYE_EASYPEN_M406XE) },
  616. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  617. USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2) },
  618. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  619. USB_DEVICE_ID_KYE_PENSKETCH_T609A) },
  620. { }
  621. };
  622. MODULE_DEVICE_TABLE(hid, kye_devices);
  623. static struct hid_driver kye_driver = {
  624. .name = "kye",
  625. .id_table = kye_devices,
  626. .probe = kye_probe,
  627. .report_fixup = kye_report_fixup,
  628. };
  629. module_hid_driver(kye_driver);
  630. MODULE_DESCRIPTION("HID driver for Kye/Genius devices not fully compliant with HID standard");
  631. MODULE_LICENSE("GPL");