hid-uclogic.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. * See WPXXXXU model descriptions, device and HID report descriptors at
  18. * http://sf.net/apps/mediawiki/digimend/?title=UC-Logic_Tablet_WP4030U
  19. * http://sf.net/apps/mediawiki/digimend/?title=UC-Logic_Tablet_WP5540U
  20. * http://sf.net/apps/mediawiki/digimend/?title=UC-Logic_Tablet_WP8060U
  21. */
  22. /* Size of the original descriptor of WPXXXXU tablets */
  23. #define WPXXXXU_RDESC_ORIG_SIZE 212
  24. /* Fixed WP4030U report descriptor */
  25. static __u8 wp4030u_rdesc_fixed[] = {
  26. 0x05, 0x0D, /* Usage Page (Digitizer), */
  27. 0x09, 0x02, /* Usage (Pen), */
  28. 0xA1, 0x01, /* Collection (Application), */
  29. 0x85, 0x09, /* Report ID (9), */
  30. 0x09, 0x20, /* Usage (Stylus), */
  31. 0xA0, /* Collection (Physical), */
  32. 0x75, 0x01, /* Report Size (1), */
  33. 0x09, 0x42, /* Usage (Tip Switch), */
  34. 0x09, 0x44, /* Usage (Barrel Switch), */
  35. 0x09, 0x46, /* Usage (Tablet Pick), */
  36. 0x14, /* Logical Minimum (0), */
  37. 0x25, 0x01, /* Logical Maximum (1), */
  38. 0x95, 0x03, /* Report Count (3), */
  39. 0x81, 0x02, /* Input (Variable), */
  40. 0x95, 0x05, /* Report Count (5), */
  41. 0x81, 0x01, /* Input (Constant), */
  42. 0x75, 0x10, /* Report Size (16), */
  43. 0x95, 0x01, /* Report Count (1), */
  44. 0x14, /* Logical Minimum (0), */
  45. 0xA4, /* Push, */
  46. 0x05, 0x01, /* Usage Page (Desktop), */
  47. 0x55, 0xFD, /* Unit Exponent (-3), */
  48. 0x65, 0x13, /* Unit (Inch), */
  49. 0x34, /* Physical Minimum (0), */
  50. 0x09, 0x30, /* Usage (X), */
  51. 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
  52. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  53. 0x81, 0x02, /* Input (Variable), */
  54. 0x09, 0x31, /* Usage (Y), */
  55. 0x46, 0xB8, 0x0B, /* Physical Maximum (3000), */
  56. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  57. 0x81, 0x02, /* Input (Variable), */
  58. 0xB4, /* Pop, */
  59. 0x09, 0x30, /* Usage (Tip Pressure), */
  60. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  61. 0x81, 0x02, /* Input (Variable), */
  62. 0xC0, /* End Collection, */
  63. 0xC0 /* End Collection */
  64. };
  65. /* Fixed WP5540U report descriptor */
  66. static __u8 wp5540u_rdesc_fixed[] = {
  67. 0x05, 0x0D, /* Usage Page (Digitizer), */
  68. 0x09, 0x02, /* Usage (Pen), */
  69. 0xA1, 0x01, /* Collection (Application), */
  70. 0x85, 0x09, /* Report ID (9), */
  71. 0x09, 0x20, /* Usage (Stylus), */
  72. 0xA0, /* Collection (Physical), */
  73. 0x75, 0x01, /* Report Size (1), */
  74. 0x09, 0x42, /* Usage (Tip Switch), */
  75. 0x09, 0x44, /* Usage (Barrel Switch), */
  76. 0x09, 0x46, /* Usage (Tablet Pick), */
  77. 0x14, /* Logical Minimum (0), */
  78. 0x25, 0x01, /* Logical Maximum (1), */
  79. 0x95, 0x03, /* Report Count (3), */
  80. 0x81, 0x02, /* Input (Variable), */
  81. 0x95, 0x05, /* Report Count (5), */
  82. 0x81, 0x01, /* Input (Constant), */
  83. 0x75, 0x10, /* Report Size (16), */
  84. 0x95, 0x01, /* Report Count (1), */
  85. 0x14, /* Logical Minimum (0), */
  86. 0xA4, /* Push, */
  87. 0x05, 0x01, /* Usage Page (Desktop), */
  88. 0x55, 0xFD, /* Unit Exponent (-3), */
  89. 0x65, 0x13, /* Unit (Inch), */
  90. 0x34, /* Physical Minimum (0), */
  91. 0x09, 0x30, /* Usage (X), */
  92. 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
  93. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  94. 0x81, 0x02, /* Input (Variable), */
  95. 0x09, 0x31, /* Usage (Y), */
  96. 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
  97. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  98. 0x81, 0x02, /* Input (Variable), */
  99. 0xB4, /* Pop, */
  100. 0x09, 0x30, /* Usage (Tip Pressure), */
  101. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  102. 0x81, 0x02, /* Input (Variable), */
  103. 0xC0, /* End Collection, */
  104. 0xC0, /* End Collection, */
  105. 0x05, 0x01, /* Usage Page (Desktop), */
  106. 0x09, 0x02, /* Usage (Mouse), */
  107. 0xA1, 0x01, /* Collection (Application), */
  108. 0x85, 0x08, /* Report ID (8), */
  109. 0x09, 0x01, /* Usage (Pointer), */
  110. 0xA0, /* Collection (Physical), */
  111. 0x75, 0x01, /* Report Size (1), */
  112. 0x05, 0x09, /* Usage Page (Button), */
  113. 0x19, 0x01, /* Usage Minimum (01h), */
  114. 0x29, 0x03, /* Usage Maximum (03h), */
  115. 0x14, /* Logical Minimum (0), */
  116. 0x25, 0x01, /* Logical Maximum (1), */
  117. 0x95, 0x03, /* Report Count (3), */
  118. 0x81, 0x02, /* Input (Variable), */
  119. 0x95, 0x05, /* Report Count (5), */
  120. 0x81, 0x01, /* Input (Constant), */
  121. 0x05, 0x01, /* Usage Page (Desktop), */
  122. 0x75, 0x08, /* Report Size (8), */
  123. 0x09, 0x30, /* Usage (X), */
  124. 0x09, 0x31, /* Usage (Y), */
  125. 0x15, 0x81, /* Logical Minimum (-127), */
  126. 0x25, 0x7F, /* Logical Maximum (127), */
  127. 0x95, 0x02, /* Report Count (2), */
  128. 0x81, 0x06, /* Input (Variable, Relative), */
  129. 0x09, 0x38, /* Usage (Wheel), */
  130. 0x15, 0xFF, /* Logical Minimum (-1), */
  131. 0x25, 0x01, /* Logical Maximum (1), */
  132. 0x95, 0x01, /* Report Count (1), */
  133. 0x81, 0x06, /* Input (Variable, Relative), */
  134. 0x81, 0x01, /* Input (Constant), */
  135. 0xC0, /* End Collection, */
  136. 0xC0 /* End Collection */
  137. };
  138. /* Fixed WP8060U report descriptor */
  139. static __u8 wp8060u_rdesc_fixed[] = {
  140. 0x05, 0x0D, /* Usage Page (Digitizer), */
  141. 0x09, 0x02, /* Usage (Pen), */
  142. 0xA1, 0x01, /* Collection (Application), */
  143. 0x85, 0x09, /* Report ID (9), */
  144. 0x09, 0x20, /* Usage (Stylus), */
  145. 0xA0, /* Collection (Physical), */
  146. 0x75, 0x01, /* Report Size (1), */
  147. 0x09, 0x42, /* Usage (Tip Switch), */
  148. 0x09, 0x44, /* Usage (Barrel Switch), */
  149. 0x09, 0x46, /* Usage (Tablet Pick), */
  150. 0x14, /* Logical Minimum (0), */
  151. 0x25, 0x01, /* Logical Maximum (1), */
  152. 0x95, 0x03, /* Report Count (3), */
  153. 0x81, 0x02, /* Input (Variable), */
  154. 0x95, 0x05, /* Report Count (5), */
  155. 0x81, 0x01, /* Input (Constant), */
  156. 0x75, 0x10, /* Report Size (16), */
  157. 0x95, 0x01, /* Report Count (1), */
  158. 0x14, /* Logical Minimum (0), */
  159. 0xA4, /* Push, */
  160. 0x05, 0x01, /* Usage Page (Desktop), */
  161. 0x55, 0xFD, /* Unit Exponent (-3), */
  162. 0x65, 0x13, /* Unit (Inch), */
  163. 0x34, /* Physical Minimum (0), */
  164. 0x09, 0x30, /* Usage (X), */
  165. 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
  166. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  167. 0x81, 0x02, /* Input (Variable), */
  168. 0x09, 0x31, /* Usage (Y), */
  169. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  170. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  171. 0x81, 0x02, /* Input (Variable), */
  172. 0xB4, /* Pop, */
  173. 0x09, 0x30, /* Usage (Tip Pressure), */
  174. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  175. 0x81, 0x02, /* Input (Variable), */
  176. 0xC0, /* End Collection, */
  177. 0xC0, /* End Collection, */
  178. 0x05, 0x01, /* Usage Page (Desktop), */
  179. 0x09, 0x02, /* Usage (Mouse), */
  180. 0xA1, 0x01, /* Collection (Application), */
  181. 0x85, 0x08, /* Report ID (8), */
  182. 0x09, 0x01, /* Usage (Pointer), */
  183. 0xA0, /* Collection (Physical), */
  184. 0x75, 0x01, /* Report Size (1), */
  185. 0x05, 0x09, /* Usage Page (Button), */
  186. 0x19, 0x01, /* Usage Minimum (01h), */
  187. 0x29, 0x03, /* Usage Maximum (03h), */
  188. 0x14, /* Logical Minimum (0), */
  189. 0x25, 0x01, /* Logical Maximum (1), */
  190. 0x95, 0x03, /* Report Count (3), */
  191. 0x81, 0x02, /* Input (Variable), */
  192. 0x95, 0x05, /* Report Count (5), */
  193. 0x81, 0x01, /* Input (Constant), */
  194. 0x05, 0x01, /* Usage Page (Desktop), */
  195. 0x75, 0x08, /* Report Size (8), */
  196. 0x09, 0x30, /* Usage (X), */
  197. 0x09, 0x31, /* Usage (Y), */
  198. 0x15, 0x81, /* Logical Minimum (-127), */
  199. 0x25, 0x7F, /* Logical Maximum (127), */
  200. 0x95, 0x02, /* Report Count (2), */
  201. 0x81, 0x06, /* Input (Variable, Relative), */
  202. 0x09, 0x38, /* Usage (Wheel), */
  203. 0x15, 0xFF, /* Logical Minimum (-1), */
  204. 0x25, 0x01, /* Logical Maximum (1), */
  205. 0x95, 0x01, /* Report Count (1), */
  206. 0x81, 0x06, /* Input (Variable, Relative), */
  207. 0x81, 0x01, /* Input (Constant), */
  208. 0xC0, /* End Collection, */
  209. 0xC0 /* End Collection */
  210. };
  211. /*
  212. * See WP1062 description, device and HID report descriptors at
  213. * http://sf.net/apps/mediawiki/digimend/?title=UC-Logic_Tablet_WP1062
  214. */
  215. /* Size of the original descriptor of WP1062 tablet */
  216. #define WP1062_RDESC_ORIG_SIZE 254
  217. /* Fixed WP1062 report descriptor */
  218. static __u8 wp1062_rdesc_fixed[] = {
  219. 0x05, 0x0D, /* Usage Page (Digitizer), */
  220. 0x09, 0x02, /* Usage (Pen), */
  221. 0xA1, 0x01, /* Collection (Application), */
  222. 0x85, 0x09, /* Report ID (9), */
  223. 0x09, 0x20, /* Usage (Stylus), */
  224. 0xA0, /* Collection (Physical), */
  225. 0x75, 0x01, /* Report Size (1), */
  226. 0x09, 0x42, /* Usage (Tip Switch), */
  227. 0x09, 0x44, /* Usage (Barrel Switch), */
  228. 0x09, 0x46, /* Usage (Tablet Pick), */
  229. 0x14, /* Logical Minimum (0), */
  230. 0x25, 0x01, /* Logical Maximum (1), */
  231. 0x95, 0x03, /* Report Count (3), */
  232. 0x81, 0x02, /* Input (Variable), */
  233. 0x95, 0x04, /* Report Count (4), */
  234. 0x81, 0x01, /* Input (Constant), */
  235. 0x09, 0x32, /* Usage (In Range), */
  236. 0x95, 0x01, /* Report Count (1), */
  237. 0x81, 0x02, /* Input (Variable), */
  238. 0x75, 0x10, /* Report Size (16), */
  239. 0x95, 0x01, /* Report Count (1), */
  240. 0x14, /* Logical Minimum (0), */
  241. 0xA4, /* Push, */
  242. 0x05, 0x01, /* Usage Page (Desktop), */
  243. 0x55, 0xFD, /* Unit Exponent (-3), */
  244. 0x65, 0x13, /* Unit (Inch), */
  245. 0x34, /* Physical Minimum (0), */
  246. 0x09, 0x30, /* Usage (X), */
  247. 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
  248. 0x26, 0x20, 0x4E, /* Logical Maximum (20000), */
  249. 0x81, 0x02, /* Input (Variable), */
  250. 0x09, 0x31, /* Usage (Y), */
  251. 0x46, 0xB7, 0x19, /* Physical Maximum (6583), */
  252. 0x26, 0x6E, 0x33, /* Logical Maximum (13166), */
  253. 0x81, 0x02, /* Input (Variable), */
  254. 0xB4, /* Pop, */
  255. 0x09, 0x30, /* Usage (Tip Pressure), */
  256. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  257. 0x81, 0x02, /* Input (Variable), */
  258. 0xC0, /* End Collection, */
  259. 0xC0 /* End Collection */
  260. };
  261. /*
  262. * See PF1209 description, device and HID report descriptors at
  263. * http://sf.net/apps/mediawiki/digimend/?title=UC-Logic_Tablet_PF1209
  264. */
  265. /* Size of the original descriptor of PF1209 tablet */
  266. #define PF1209_RDESC_ORIG_SIZE 234
  267. /* Fixed PF1209 report descriptor */
  268. static __u8 pf1209_rdesc_fixed[] = {
  269. 0x05, 0x0D, /* Usage Page (Digitizer), */
  270. 0x09, 0x02, /* Usage (Pen), */
  271. 0xA1, 0x01, /* Collection (Application), */
  272. 0x85, 0x09, /* Report ID (9), */
  273. 0x09, 0x20, /* Usage (Stylus), */
  274. 0xA0, /* Collection (Physical), */
  275. 0x75, 0x01, /* Report Size (1), */
  276. 0x09, 0x42, /* Usage (Tip Switch), */
  277. 0x09, 0x44, /* Usage (Barrel Switch), */
  278. 0x09, 0x46, /* Usage (Tablet Pick), */
  279. 0x14, /* Logical Minimum (0), */
  280. 0x25, 0x01, /* Logical Maximum (1), */
  281. 0x95, 0x03, /* Report Count (3), */
  282. 0x81, 0x02, /* Input (Variable), */
  283. 0x95, 0x05, /* Report Count (5), */
  284. 0x81, 0x01, /* Input (Constant), */
  285. 0x75, 0x10, /* Report Size (16), */
  286. 0x95, 0x01, /* Report Count (1), */
  287. 0x14, /* Logical Minimum (0), */
  288. 0xA4, /* Push, */
  289. 0x05, 0x01, /* Usage Page (Desktop), */
  290. 0x55, 0xFD, /* Unit Exponent (-3), */
  291. 0x65, 0x13, /* Unit (Inch), */
  292. 0x34, /* Physical Minimum (0), */
  293. 0x09, 0x30, /* Usage (X), */
  294. 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
  295. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  296. 0x81, 0x02, /* Input (Variable), */
  297. 0x09, 0x31, /* Usage (Y), */
  298. 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
  299. 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
  300. 0x81, 0x02, /* Input (Variable), */
  301. 0xB4, /* Pop, */
  302. 0x09, 0x30, /* Usage (Tip Pressure), */
  303. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  304. 0x81, 0x02, /* Input (Variable), */
  305. 0xC0, /* End Collection, */
  306. 0xC0, /* End Collection, */
  307. 0x05, 0x01, /* Usage Page (Desktop), */
  308. 0x09, 0x02, /* Usage (Mouse), */
  309. 0xA1, 0x01, /* Collection (Application), */
  310. 0x85, 0x08, /* Report ID (8), */
  311. 0x09, 0x01, /* Usage (Pointer), */
  312. 0xA0, /* Collection (Physical), */
  313. 0x75, 0x01, /* Report Size (1), */
  314. 0x05, 0x09, /* Usage Page (Button), */
  315. 0x19, 0x01, /* Usage Minimum (01h), */
  316. 0x29, 0x03, /* Usage Maximum (03h), */
  317. 0x14, /* Logical Minimum (0), */
  318. 0x25, 0x01, /* Logical Maximum (1), */
  319. 0x95, 0x03, /* Report Count (3), */
  320. 0x81, 0x02, /* Input (Variable), */
  321. 0x95, 0x05, /* Report Count (5), */
  322. 0x81, 0x01, /* Input (Constant), */
  323. 0x05, 0x01, /* Usage Page (Desktop), */
  324. 0x75, 0x08, /* Report Size (8), */
  325. 0x09, 0x30, /* Usage (X), */
  326. 0x09, 0x31, /* Usage (Y), */
  327. 0x15, 0x81, /* Logical Minimum (-127), */
  328. 0x25, 0x7F, /* Logical Maximum (127), */
  329. 0x95, 0x02, /* Report Count (2), */
  330. 0x81, 0x06, /* Input (Variable, Relative), */
  331. 0x09, 0x38, /* Usage (Wheel), */
  332. 0x15, 0xFF, /* Logical Minimum (-1), */
  333. 0x25, 0x01, /* Logical Maximum (1), */
  334. 0x95, 0x01, /* Report Count (1), */
  335. 0x81, 0x06, /* Input (Variable, Relative), */
  336. 0x81, 0x01, /* Input (Constant), */
  337. 0xC0, /* End Collection, */
  338. 0xC0 /* End Collection */
  339. };
  340. static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  341. unsigned int *rsize)
  342. {
  343. switch (hdev->product) {
  344. case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209:
  345. if (*rsize == PF1209_RDESC_ORIG_SIZE) {
  346. rdesc = pf1209_rdesc_fixed;
  347. *rsize = sizeof(pf1209_rdesc_fixed);
  348. }
  349. break;
  350. case USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U:
  351. if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
  352. rdesc = wp4030u_rdesc_fixed;
  353. *rsize = sizeof(wp4030u_rdesc_fixed);
  354. }
  355. break;
  356. case USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U:
  357. if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
  358. rdesc = wp5540u_rdesc_fixed;
  359. *rsize = sizeof(wp5540u_rdesc_fixed);
  360. }
  361. break;
  362. case USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U:
  363. if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
  364. rdesc = wp8060u_rdesc_fixed;
  365. *rsize = sizeof(wp8060u_rdesc_fixed);
  366. }
  367. break;
  368. case USB_DEVICE_ID_UCLOGIC_TABLET_WP1062:
  369. if (*rsize == WP1062_RDESC_ORIG_SIZE) {
  370. rdesc = wp1062_rdesc_fixed;
  371. *rsize = sizeof(wp1062_rdesc_fixed);
  372. }
  373. break;
  374. }
  375. return rdesc;
  376. }
  377. static const struct hid_device_id uclogic_devices[] = {
  378. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  379. USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
  380. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  381. USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
  382. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  383. USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
  384. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  385. USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
  386. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
  387. USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
  388. { }
  389. };
  390. MODULE_DEVICE_TABLE(hid, uclogic_devices);
  391. static struct hid_driver uclogic_driver = {
  392. .name = "uclogic",
  393. .id_table = uclogic_devices,
  394. .report_fixup = uclogic_report_fixup,
  395. };
  396. static int __init uclogic_init(void)
  397. {
  398. return hid_register_driver(&uclogic_driver);
  399. }
  400. static void __exit uclogic_exit(void)
  401. {
  402. hid_unregister_driver(&uclogic_driver);
  403. }
  404. module_init(uclogic_init);
  405. module_exit(uclogic_exit);
  406. MODULE_LICENSE("GPL");