hid-uclogic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * HID driver for UC-Logic devices not fully compliant with HID standard
  3. *
  4. * Copyright (c) 2010 Nikolai Kondrashov
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/hid.h>
  14. #include <linux/module.h>
  15. #include "hid-ids.h"
  16. /*
  17. * The original descriptors of WPXXXXU tablets have three report IDs, of
  18. * which only two are used (8 and 9), and the remaining (7) seems to have
  19. * the originally intended pen description which was abandoned for some
  20. * reason. From this unused description it is possible to extract the
  21. * actual physical extents and resolution. All the models use the same
  22. * descriptor with different extents for the unused report ID.
  23. *
  24. * Here it is:
  25. *
  26. * Usage Page (Digitizer), ; Digitizer (0Dh)
  27. * Usage (Pen), ; Pen (02h, application collection)
  28. * Collection (Application),
  29. * Report ID (7),
  30. * Usage (Stylus), ; Stylus (20h, logical collection)
  31. * Collection (Physical),
  32. * Usage (Tip Switch), ; Tip switch (42h, momentary control)
  33. * Usage (Barrel Switch), ; Barrel switch (44h, momentary control)
  34. * Usage (Eraser), ; Eraser (45h, momentary control)
  35. * Logical Minimum (0),
  36. * Logical Maximum (1),
  37. * Report Size (1),
  38. * Report Count (3),
  39. * Input (Variable),
  40. * Report Count (3),
  41. * Input (Constant, Variable),
  42. * Usage (In Range), ; In range (32h, momentary control)
  43. * Report Count (1),
  44. * Input (Variable),
  45. * Report Count (1),
  46. * Input (Constant, Variable),
  47. * Usage Page (Desktop), ; Generic desktop controls (01h)
  48. * Usage (X), ; X (30h, dynamic value)
  49. * Report Size (16),
  50. * Report Count (1),
  51. * Push,
  52. * Unit Exponent (13),
  53. * Unit (Inch^3),
  54. * Physical Minimum (0),
  55. * Physical Maximum (Xpm),
  56. * Logical Maximum (Xlm),
  57. * Input (Variable),
  58. * Usage (Y), ; Y (31h, dynamic value)
  59. * Physical Maximum (Ypm),
  60. * Logical Maximum (Ylm),
  61. * Input (Variable),
  62. * Pop,
  63. * Usage Page (Digitizer), ; Digitizer (0Dh)
  64. * Usage (Tip Pressure), ; Tip pressure (30h, dynamic value)
  65. * Logical Maximum (1023),
  66. * Input (Variable),
  67. * Report Size (16),
  68. * End Collection,
  69. * End Collection,
  70. * Usage Page (Desktop), ; Generic desktop controls (01h)
  71. * Usage (Mouse), ; Mouse (02h, application collection)
  72. * Collection (Application),
  73. * Report ID (8),
  74. * Usage (Pointer), ; Pointer (01h, physical collection)
  75. * Collection (Physical),
  76. * Usage Page (Button), ; Button (09h)
  77. * Usage Minimum (01h),
  78. * Usage Maximum (03h),
  79. * Logical Minimum (0),
  80. * Logical Maximum (1),
  81. * Report Count (3),
  82. * Report Size (1),
  83. * Input (Variable),
  84. * Report Count (5),
  85. * Input (Constant),
  86. * Usage Page (Desktop), ; Generic desktop controls (01h)
  87. * Usage (X), ; X (30h, dynamic value)
  88. * Usage (Y), ; Y (31h, dynamic value)
  89. * Usage (Wheel), ; Wheel (38h, dynamic value)
  90. * Usage (00h),
  91. * Logical Minimum (-127),
  92. * Logical Maximum (127),
  93. * Report Size (8),
  94. * Report Count (4),
  95. * Input (Variable, Relative),
  96. * End Collection,
  97. * End Collection,
  98. * Usage Page (Desktop), ; Generic desktop controls (01h)
  99. * Usage (Mouse), ; Mouse (02h, application collection)
  100. * Collection (Application),
  101. * Report ID (9),
  102. * Usage (Pointer), ; Pointer (01h, physical collection)
  103. * Collection (Physical),
  104. * Usage Page (Button), ; Button (09h)
  105. * Usage Minimum (01h),
  106. * Usage Maximum (03h),
  107. * Logical Minimum (0),
  108. * Logical Maximum (1),
  109. * Report Count (3),
  110. * Report Size (1),
  111. * Input (Variable),
  112. * Report Count (5),
  113. * Input (Constant),
  114. * Usage Page (Desktop), ; Generic desktop controls (01h)
  115. * Usage (X), ; X (30h, dynamic value)
  116. * Usage (Y), ; Y (31h, dynamic value)
  117. * Logical Minimum (0),
  118. * Logical Maximum (32767),
  119. * Physical Minimum (0),
  120. * Physical Maximum (32767),
  121. * Report Count (2),
  122. * Report Size (16),
  123. * Input (Variable),
  124. * Usage Page (Digitizer), ; Digitizer (0Dh)
  125. * Usage (Tip Pressure), ; Tip pressure (30h, dynamic value)
  126. * Logical Maximum (1023),
  127. * Report Count (1),
  128. * Report Size (16),
  129. * Input (Variable),
  130. * End Collection,
  131. * End Collection
  132. *
  133. * Here are the extents values for the WPXXXXU models:
  134. *
  135. * Xpm Xlm Ypm Ylm
  136. * WP4030U 4000 8000 3000 6000
  137. * WP5540U 5500 11000 4000 8000
  138. * WP8060U 8000 16000 6000 12000
  139. *
  140. * This suggests that all of them have 2000 LPI resolution, as advertised.
  141. */
  142. /* Size of the original descriptor of WPXXXXU tablets */
  143. #define WPXXXXU_RDESC_ORIG_SIZE 212
  144. /*
  145. * Fixed WP4030U report descriptor.
  146. * Although the hardware might actually support it, the mouse description
  147. * has been removed, since there seems to be no devices having one and it
  148. * wouldn't make much sense because of the working area size.
  149. */
  150. static __u8 wp4030u_rdesc_fixed[] = {
  151. 0x05, 0x0D, /* Usage Page (Digitizer), */
  152. 0x09, 0x02, /* Usage (Pen), */
  153. 0xA1, 0x01, /* Collection (Application), */
  154. 0x85, 0x09, /* Report ID (9), */
  155. 0x09, 0x20, /* Usage (Stylus), */
  156. 0xA0, /* Collection (Physical), */
  157. 0x75, 0x01, /* Report Size (1), */
  158. 0x09, 0x42, /* Usage (Tip Switch), */
  159. 0x09, 0x44, /* Usage (Barrel Switch), */
  160. 0x09, 0x46, /* Usage (Tablet Pick), */
  161. 0x14, /* Logical Minimum (0), */
  162. 0x25, 0x01, /* Logical Maximum (1), */
  163. 0x95, 0x03, /* Report Count (3), */
  164. 0x81, 0x02, /* Input (Variable), */
  165. 0x95, 0x05, /* Report Count (5), */
  166. 0x81, 0x01, /* Input (Constant), */
  167. 0x75, 0x10, /* Report Size (16), */
  168. 0x95, 0x01, /* Report Count (1), */
  169. 0x14, /* Logical Minimum (0), */
  170. 0xA4, /* Push, */
  171. 0x05, 0x01, /* Usage Page (Desktop), */
  172. 0x55, 0xFD, /* Unit Exponent (-3), */
  173. 0x65, 0x13, /* Unit (Inch), */
  174. 0x34, /* Physical Minimum (0), */
  175. 0x09, 0x30, /* Usage (X), */
  176. 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
  177. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  178. 0x81, 0x02, /* Input (Variable), */
  179. 0x09, 0x31, /* Usage (Y), */
  180. 0x46, 0xB8, 0x0B, /* Physical Maximum (3000), */
  181. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  182. 0x81, 0x02, /* Input (Variable), */
  183. 0xB4, /* Pop, */
  184. 0x09, 0x30, /* Usage (Tip Pressure), */
  185. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  186. 0x81, 0x02, /* Input (Variable), */
  187. 0xC0, /* End Collection, */
  188. 0xC0 /* End Collection */
  189. };
  190. /* Fixed WP5540U report descriptor */
  191. static __u8 wp5540u_rdesc_fixed[] = {
  192. 0x05, 0x0D, /* Usage Page (Digitizer), */
  193. 0x09, 0x02, /* Usage (Pen), */
  194. 0xA1, 0x01, /* Collection (Application), */
  195. 0x85, 0x09, /* Report ID (9), */
  196. 0x09, 0x20, /* Usage (Stylus), */
  197. 0xA0, /* Collection (Physical), */
  198. 0x75, 0x01, /* Report Size (1), */
  199. 0x09, 0x42, /* Usage (Tip Switch), */
  200. 0x09, 0x44, /* Usage (Barrel Switch), */
  201. 0x09, 0x46, /* Usage (Tablet Pick), */
  202. 0x14, /* Logical Minimum (0), */
  203. 0x25, 0x01, /* Logical Maximum (1), */
  204. 0x95, 0x03, /* Report Count (3), */
  205. 0x81, 0x02, /* Input (Variable), */
  206. 0x95, 0x05, /* Report Count (5), */
  207. 0x81, 0x01, /* Input (Constant), */
  208. 0x75, 0x10, /* Report Size (16), */
  209. 0x95, 0x01, /* Report Count (1), */
  210. 0x14, /* Logical Minimum (0), */
  211. 0xA4, /* Push, */
  212. 0x05, 0x01, /* Usage Page (Desktop), */
  213. 0x55, 0xFD, /* Unit Exponent (-3), */
  214. 0x65, 0x13, /* Unit (Inch), */
  215. 0x34, /* Physical Minimum (0), */
  216. 0x09, 0x30, /* Usage (X), */
  217. 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
  218. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  219. 0x81, 0x02, /* Input (Variable), */
  220. 0x09, 0x31, /* Usage (Y), */
  221. 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
  222. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  223. 0x81, 0x02, /* Input (Variable), */
  224. 0xB4, /* Pop, */
  225. 0x09, 0x30, /* Usage (Tip Pressure), */
  226. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  227. 0x81, 0x02, /* Input (Variable), */
  228. 0xC0, /* End Collection, */
  229. 0xC0, /* End Collection, */
  230. 0x05, 0x01, /* Usage Page (Desktop), */
  231. 0x09, 0x02, /* Usage (Mouse), */
  232. 0xA1, 0x01, /* Collection (Application), */
  233. 0x85, 0x08, /* Report ID (8), */
  234. 0x09, 0x01, /* Usage (Pointer), */
  235. 0xA0, /* Collection (Physical), */
  236. 0x75, 0x01, /* Report Size (1), */
  237. 0x05, 0x09, /* Usage Page (Button), */
  238. 0x19, 0x01, /* Usage Minimum (01h), */
  239. 0x29, 0x03, /* Usage Maximum (03h), */
  240. 0x14, /* Logical Minimum (0), */
  241. 0x25, 0x01, /* Logical Maximum (1), */
  242. 0x95, 0x03, /* Report Count (3), */
  243. 0x81, 0x02, /* Input (Variable), */
  244. 0x95, 0x05, /* Report Count (5), */
  245. 0x81, 0x01, /* Input (Constant), */
  246. 0x05, 0x01, /* Usage Page (Desktop), */
  247. 0x75, 0x08, /* Report Size (8), */
  248. 0x09, 0x30, /* Usage (X), */
  249. 0x09, 0x31, /* Usage (Y), */
  250. 0x15, 0x81, /* Logical Minimum (-127), */
  251. 0x25, 0x7F, /* Logical Maximum (127), */
  252. 0x95, 0x02, /* Report Count (2), */
  253. 0x81, 0x06, /* Input (Variable, Relative), */
  254. 0x09, 0x38, /* Usage (Wheel), */
  255. 0x15, 0xFF, /* Logical Minimum (-1), */
  256. 0x25, 0x01, /* Logical Maximum (1), */
  257. 0x95, 0x01, /* Report Count (1), */
  258. 0x81, 0x06, /* Input (Variable, Relative), */
  259. 0x81, 0x01, /* Input (Constant), */
  260. 0xC0, /* End Collection, */
  261. 0xC0 /* End Collection */
  262. };
  263. /* Fixed WP8060U report descriptor */
  264. static __u8 wp8060u_rdesc_fixed[] = {
  265. 0x05, 0x0D, /* Usage Page (Digitizer), */
  266. 0x09, 0x02, /* Usage (Pen), */
  267. 0xA1, 0x01, /* Collection (Application), */
  268. 0x85, 0x09, /* Report ID (9), */
  269. 0x09, 0x20, /* Usage (Stylus), */
  270. 0xA0, /* Collection (Physical), */
  271. 0x75, 0x01, /* Report Size (1), */
  272. 0x09, 0x42, /* Usage (Tip Switch), */
  273. 0x09, 0x44, /* Usage (Barrel Switch), */
  274. 0x09, 0x46, /* Usage (Tablet Pick), */
  275. 0x14, /* Logical Minimum (0), */
  276. 0x25, 0x01, /* Logical Maximum (1), */
  277. 0x95, 0x03, /* Report Count (3), */
  278. 0x81, 0x02, /* Input (Variable), */
  279. 0x95, 0x05, /* Report Count (5), */
  280. 0x81, 0x01, /* Input (Constant), */
  281. 0x75, 0x10, /* Report Size (16), */
  282. 0x95, 0x01, /* Report Count (1), */
  283. 0x14, /* Logical Minimum (0), */
  284. 0xA4, /* Push, */
  285. 0x05, 0x01, /* Usage Page (Desktop), */
  286. 0x55, 0xFD, /* Unit Exponent (-3), */
  287. 0x65, 0x13, /* Unit (Inch), */
  288. 0x34, /* Physical Minimum (0), */
  289. 0x09, 0x30, /* Usage (X), */
  290. 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
  291. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  292. 0x81, 0x02, /* Input (Variable), */
  293. 0x09, 0x31, /* Usage (Y), */
  294. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  295. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  296. 0x81, 0x02, /* Input (Variable), */
  297. 0xB4, /* Pop, */
  298. 0x09, 0x30, /* Usage (Tip Pressure), */
  299. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  300. 0x81, 0x02, /* Input (Variable), */
  301. 0xC0, /* End Collection, */
  302. 0xC0, /* End Collection, */
  303. 0x05, 0x01, /* Usage Page (Desktop), */
  304. 0x09, 0x02, /* Usage (Mouse), */
  305. 0xA1, 0x01, /* Collection (Application), */
  306. 0x85, 0x08, /* Report ID (8), */
  307. 0x09, 0x01, /* Usage (Pointer), */
  308. 0xA0, /* Collection (Physical), */
  309. 0x75, 0x01, /* Report Size (1), */
  310. 0x05, 0x09, /* Usage Page (Button), */
  311. 0x19, 0x01, /* Usage Minimum (01h), */
  312. 0x29, 0x03, /* Usage Maximum (03h), */
  313. 0x14, /* Logical Minimum (0), */
  314. 0x25, 0x01, /* Logical Maximum (1), */
  315. 0x95, 0x03, /* Report Count (3), */
  316. 0x81, 0x02, /* Input (Variable), */
  317. 0x95, 0x05, /* Report Count (5), */
  318. 0x81, 0x01, /* Input (Constant), */
  319. 0x05, 0x01, /* Usage Page (Desktop), */
  320. 0x75, 0x08, /* Report Size (8), */
  321. 0x09, 0x30, /* Usage (X), */
  322. 0x09, 0x31, /* Usage (Y), */
  323. 0x15, 0x81, /* Logical Minimum (-127), */
  324. 0x25, 0x7F, /* Logical Maximum (127), */
  325. 0x95, 0x02, /* Report Count (2), */
  326. 0x81, 0x06, /* Input (Variable, Relative), */
  327. 0x09, 0x38, /* Usage (Wheel), */
  328. 0x15, 0xFF, /* Logical Minimum (-1), */
  329. 0x25, 0x01, /* Logical Maximum (1), */
  330. 0x95, 0x01, /* Report Count (1), */
  331. 0x81, 0x06, /* Input (Variable, Relative), */
  332. 0x81, 0x01, /* Input (Constant), */
  333. 0xC0, /* End Collection, */
  334. 0xC0 /* End Collection */
  335. };
  336. static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  337. unsigned int *rsize)
  338. {
  339. switch (hdev->product) {
  340. case USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U:
  341. if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
  342. rdesc = wp4030u_rdesc_fixed;
  343. *rsize = sizeof(wp4030u_rdesc_fixed);
  344. }
  345. break;
  346. case USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U:
  347. if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
  348. rdesc = wp5540u_rdesc_fixed;
  349. *rsize = sizeof(wp5540u_rdesc_fixed);
  350. }
  351. break;
  352. case USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U:
  353. if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
  354. rdesc = wp8060u_rdesc_fixed;
  355. *rsize = sizeof(wp8060u_rdesc_fixed);
  356. }
  357. break;
  358. }
  359. return rdesc;
  360. }
  361. static const struct hid_device_id uclogic_devices[] = {
  362. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  363. USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
  364. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  365. USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
  366. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  367. USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
  368. { }
  369. };
  370. MODULE_DEVICE_TABLE(hid, uclogic_devices);
  371. static struct hid_driver uclogic_driver = {
  372. .name = "uclogic",
  373. .id_table = uclogic_devices,
  374. .report_fixup = uclogic_report_fixup,
  375. };
  376. static int __init uclogic_init(void)
  377. {
  378. return hid_register_driver(&uclogic_driver);
  379. }
  380. static void __exit uclogic_exit(void)
  381. {
  382. hid_unregister_driver(&uclogic_driver);
  383. }
  384. module_init(uclogic_init);
  385. module_exit(uclogic_exit);
  386. MODULE_LICENSE("GPL");