hid-waltop.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * HID driver for Waltop 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. * There exists an official driver on the manufacturer's website, which
  18. * wasn't submitted to the kernel, for some reason. The official driver
  19. * doesn't seem to support extra features of some tablets, like wheels.
  20. *
  21. * It shows that the feature report ID 2 could be used to control any waltop
  22. * tablet input mode, switching it between "default", "tablet" and "ink".
  23. *
  24. * This driver only uses "default" mode for all the supported tablets. This
  25. * mode tries to be HID-compatible (not very successfully), but cripples the
  26. * resolution of some tablets.
  27. *
  28. * The "tablet" mode uses some proprietary, yet decipherable protocol, which
  29. * represents the correct resolution, but is possibly HID-incompatible (i.e.
  30. * indescribable by a report descriptor).
  31. *
  32. * The purpose of the "ink" mode is unknown.
  33. *
  34. * The feature reports needed for switching to each mode are these:
  35. *
  36. * 02 16 00 default
  37. * 02 16 01 tablet
  38. * 02 16 02 ink
  39. */
  40. /* Size of the original report descriptor of Slim Tablet 5.8 inch */
  41. #define SLIM_TABLET_5_8_INCH_RDESC_ORIG_SIZE 222
  42. /* Fixed Slim Tablet 5.8 inch descriptor */
  43. static __u8 slim_tablet_5_8_inch_rdesc_fixed[] = {
  44. 0x05, 0x0D, /* Usage Page (Digitizer), */
  45. 0x09, 0x02, /* Usage (Pen), */
  46. 0xA1, 0x01, /* Collection (Application), */
  47. 0x85, 0x10, /* Report ID (16), */
  48. 0x09, 0x20, /* Usage (Stylus), */
  49. 0xA0, /* Collection (Physical), */
  50. 0x09, 0x42, /* Usage (Tip Switch), */
  51. 0x09, 0x44, /* Usage (Barrel Switch), */
  52. 0x09, 0x46, /* Usage (Tablet Pick), */
  53. 0x15, 0x01, /* Logical Minimum (1), */
  54. 0x25, 0x03, /* Logical Maximum (3), */
  55. 0x75, 0x04, /* Report Size (4), */
  56. 0x95, 0x01, /* Report Count (1), */
  57. 0x80, /* Input, */
  58. 0x09, 0x32, /* Usage (In Range), */
  59. 0x14, /* Logical Minimum (0), */
  60. 0x25, 0x01, /* Logical Maximum (1), */
  61. 0x75, 0x01, /* Report Size (1), */
  62. 0x95, 0x01, /* Report Count (1), */
  63. 0x81, 0x02, /* Input (Variable), */
  64. 0x95, 0x03, /* Report Count (3), */
  65. 0x81, 0x03, /* Input (Constant, Variable), */
  66. 0x75, 0x10, /* Report Size (16), */
  67. 0x95, 0x01, /* Report Count (1), */
  68. 0x14, /* Logical Minimum (0), */
  69. 0xA4, /* Push, */
  70. 0x05, 0x01, /* Usage Page (Desktop), */
  71. 0x65, 0x13, /* Unit (Inch), */
  72. 0x55, 0xFD, /* Unit Exponent (-3), */
  73. 0x34, /* Physical Minimum (0), */
  74. 0x09, 0x30, /* Usage (X), */
  75. 0x46, 0x88, 0x13, /* Physical Maximum (5000), */
  76. 0x26, 0x10, 0x27, /* Logical Maximum (10000), */
  77. 0x81, 0x02, /* Input (Variable), */
  78. 0x09, 0x31, /* Usage (Y), */
  79. 0x46, 0xB8, 0x0B, /* Physical Maximum (3000), */
  80. 0x26, 0x70, 0x17, /* Logical Maximum (6000), */
  81. 0x81, 0x02, /* Input (Variable), */
  82. 0xB4, /* Pop, */
  83. 0x09, 0x30, /* Usage (Tip Pressure), */
  84. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  85. 0x81, 0x02, /* Input (Variable), */
  86. 0xC0, /* End Collection, */
  87. 0xC0 /* End Collection */
  88. };
  89. /* Size of the original report descriptor of Slim Tablet 12.1 inch */
  90. #define SLIM_TABLET_12_1_INCH_RDESC_ORIG_SIZE 269
  91. /* Fixed Slim Tablet 12.1 inch descriptor */
  92. static __u8 slim_tablet_12_1_inch_rdesc_fixed[] = {
  93. 0x05, 0x0D, /* Usage Page (Digitizer), */
  94. 0x09, 0x02, /* Usage (Pen), */
  95. 0xA1, 0x01, /* Collection (Application), */
  96. 0x85, 0x10, /* Report ID (16), */
  97. 0x09, 0x20, /* Usage (Stylus), */
  98. 0xA0, /* Collection (Physical), */
  99. 0x09, 0x42, /* Usage (Tip Switch), */
  100. 0x09, 0x44, /* Usage (Barrel Switch), */
  101. 0x09, 0x46, /* Usage (Tablet Pick), */
  102. 0x15, 0x01, /* Logical Minimum (1), */
  103. 0x25, 0x03, /* Logical Maximum (3), */
  104. 0x75, 0x04, /* Report Size (4), */
  105. 0x95, 0x01, /* Report Count (1), */
  106. 0x80, /* Input, */
  107. 0x09, 0x32, /* Usage (In Range), */
  108. 0x14, /* Logical Minimum (0), */
  109. 0x25, 0x01, /* Logical Maximum (1), */
  110. 0x75, 0x01, /* Report Size (1), */
  111. 0x95, 0x01, /* Report Count (1), */
  112. 0x81, 0x02, /* Input (Variable), */
  113. 0x95, 0x03, /* Report Count (3), */
  114. 0x81, 0x03, /* Input (Constant, Variable), */
  115. 0x75, 0x10, /* Report Size (16), */
  116. 0x95, 0x01, /* Report Count (1), */
  117. 0x14, /* Logical Minimum (0), */
  118. 0xA4, /* Push, */
  119. 0x05, 0x01, /* Usage Page (Desktop), */
  120. 0x65, 0x13, /* Unit (Inch), */
  121. 0x55, 0xFD, /* Unit Exponent (-3), */
  122. 0x34, /* Physical Minimum (0), */
  123. 0x09, 0x30, /* Usage (X), */
  124. 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
  125. 0x26, 0x20, 0x4E, /* Logical Maximum (20000), */
  126. 0x81, 0x02, /* Input (Variable), */
  127. 0x09, 0x31, /* Usage (Y), */
  128. 0x46, 0x6A, 0x18, /* Physical Maximum (6250), */
  129. 0x26, 0xD4, 0x30, /* Logical Maximum (12500), */
  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. };
  138. /* Size of the original report descriptor of Q Pad */
  139. #define Q_PAD_RDESC_ORIG_SIZE 241
  140. /* Fixed Q Pad descriptor */
  141. static __u8 q_pad_rdesc_fixed[] = {
  142. 0x05, 0x0D, /* Usage Page (Digitizer), */
  143. 0x09, 0x02, /* Usage (Pen), */
  144. 0xA1, 0x01, /* Collection (Application), */
  145. 0x85, 0x10, /* Report ID (16), */
  146. 0x09, 0x20, /* Usage (Stylus), */
  147. 0xA0, /* Collection (Physical), */
  148. 0x09, 0x42, /* Usage (Tip Switch), */
  149. 0x09, 0x44, /* Usage (Barrel Switch), */
  150. 0x09, 0x46, /* Usage (Tablet Pick), */
  151. 0x15, 0x01, /* Logical Minimum (1), */
  152. 0x25, 0x03, /* Logical Maximum (3), */
  153. 0x75, 0x04, /* Report Size (4), */
  154. 0x95, 0x01, /* Report Count (1), */
  155. 0x80, /* Input, */
  156. 0x09, 0x32, /* Usage (In Range), */
  157. 0x14, /* Logical Minimum (0), */
  158. 0x25, 0x01, /* Logical Maximum (1), */
  159. 0x75, 0x01, /* Report Size (1), */
  160. 0x95, 0x01, /* Report Count (1), */
  161. 0x81, 0x02, /* Input (Variable), */
  162. 0x95, 0x03, /* Report Count (3), */
  163. 0x81, 0x03, /* Input (Constant, Variable), */
  164. 0x75, 0x10, /* Report Size (16), */
  165. 0x95, 0x01, /* Report Count (1), */
  166. 0x14, /* Logical Minimum (0), */
  167. 0xA4, /* Push, */
  168. 0x05, 0x01, /* Usage Page (Desktop), */
  169. 0x65, 0x13, /* Unit (Inch), */
  170. 0x55, 0xFD, /* Unit Exponent (-3), */
  171. 0x34, /* Physical Minimum (0), */
  172. 0x09, 0x30, /* Usage (X), */
  173. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  174. 0x26, 0x00, 0x30, /* Logical Maximum (12288), */
  175. 0x81, 0x02, /* Input (Variable), */
  176. 0x09, 0x31, /* Usage (Y), */
  177. 0x46, 0x94, 0x11, /* Physical Maximum (4500), */
  178. 0x26, 0x00, 0x24, /* Logical Maximum (9216), */
  179. 0x81, 0x02, /* Input (Variable), */
  180. 0xB4, /* Pop, */
  181. 0x09, 0x30, /* Usage (Tip Pressure), */
  182. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  183. 0x81, 0x02, /* Input (Variable), */
  184. 0xC0, /* End Collection, */
  185. 0xC0 /* End Collection */
  186. };
  187. /* Size of the original report descriptor of tablet with PID 0038 */
  188. #define PID_0038_RDESC_ORIG_SIZE 241
  189. /*
  190. * Fixed report descriptor for tablet with PID 0038.
  191. */
  192. static __u8 pid_0038_rdesc_fixed[] = {
  193. 0x05, 0x0D, /* Usage Page (Digitizer), */
  194. 0x09, 0x02, /* Usage (Pen), */
  195. 0xA1, 0x01, /* Collection (Application), */
  196. 0x85, 0x10, /* Report ID (16), */
  197. 0x09, 0x20, /* Usage (Stylus), */
  198. 0xA0, /* Collection (Physical), */
  199. 0x09, 0x42, /* Usage (Tip Switch), */
  200. 0x09, 0x44, /* Usage (Barrel Switch), */
  201. 0x09, 0x46, /* Usage (Tablet Pick), */
  202. 0x15, 0x01, /* Logical Minimum (1), */
  203. 0x25, 0x03, /* Logical Maximum (3), */
  204. 0x75, 0x04, /* Report Size (4), */
  205. 0x95, 0x01, /* Report Count (1), */
  206. 0x80, /* Input, */
  207. 0x09, 0x32, /* Usage (In Range), */
  208. 0x14, /* Logical Minimum (0), */
  209. 0x25, 0x01, /* Logical Maximum (1), */
  210. 0x75, 0x01, /* Report Size (1), */
  211. 0x95, 0x01, /* Report Count (1), */
  212. 0x81, 0x02, /* Input (Variable), */
  213. 0x95, 0x03, /* Report Count (3), */
  214. 0x81, 0x03, /* Input (Constant, Variable), */
  215. 0x75, 0x10, /* Report Size (16), */
  216. 0x95, 0x01, /* Report Count (1), */
  217. 0x14, /* Logical Minimum (0), */
  218. 0xA4, /* Push, */
  219. 0x05, 0x01, /* Usage Page (Desktop), */
  220. 0x65, 0x13, /* Unit (Inch), */
  221. 0x55, 0xFD, /* Unit Exponent (-3), */
  222. 0x34, /* Physical Minimum (0), */
  223. 0x09, 0x30, /* Usage (X), */
  224. 0x46, 0x2E, 0x22, /* Physical Maximum (8750), */
  225. 0x26, 0x00, 0x46, /* Logical Maximum (17920), */
  226. 0x81, 0x02, /* Input (Variable), */
  227. 0x09, 0x31, /* Usage (Y), */
  228. 0x46, 0x82, 0x14, /* Physical Maximum (5250), */
  229. 0x26, 0x00, 0x2A, /* Logical Maximum (10752), */
  230. 0x81, 0x02, /* Input (Variable), */
  231. 0xB4, /* Pop, */
  232. 0x09, 0x30, /* Usage (Tip Pressure), */
  233. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  234. 0x81, 0x02, /* Input (Variable), */
  235. 0xC0, /* End Collection, */
  236. 0xC0 /* End Collection */
  237. };
  238. /* Size of the original report descriptor of Media Tablet 10.6 inch */
  239. #define MEDIA_TABLET_10_6_INCH_RDESC_ORIG_SIZE 300
  240. /* Fixed Media Tablet 10.6 inch descriptor */
  241. static __u8 media_tablet_10_6_inch_rdesc_fixed[] = {
  242. 0x05, 0x0D, /* Usage Page (Digitizer), */
  243. 0x09, 0x02, /* Usage (Pen), */
  244. 0xA1, 0x01, /* Collection (Application), */
  245. 0x85, 0x10, /* Report ID (16), */
  246. 0x09, 0x20, /* Usage (Stylus), */
  247. 0xA0, /* Collection (Physical), */
  248. 0x09, 0x42, /* Usage (Tip Switch), */
  249. 0x09, 0x44, /* Usage (Barrel Switch), */
  250. 0x09, 0x46, /* Usage (Tablet Pick), */
  251. 0x15, 0x01, /* Logical Minimum (1), */
  252. 0x25, 0x03, /* Logical Maximum (3), */
  253. 0x75, 0x04, /* Report Size (4), */
  254. 0x95, 0x01, /* Report Count (1), */
  255. 0x80, /* Input, */
  256. 0x75, 0x01, /* Report Size (1), */
  257. 0x09, 0x32, /* Usage (In Range), */
  258. 0x14, /* Logical Minimum (0), */
  259. 0x25, 0x01, /* Logical Maximum (1), */
  260. 0x95, 0x01, /* Report Count (1), */
  261. 0x81, 0x02, /* Input (Variable), */
  262. 0x95, 0x03, /* Report Count (3), */
  263. 0x81, 0x03, /* Input (Constant, Variable), */
  264. 0x75, 0x10, /* Report Size (16), */
  265. 0x95, 0x01, /* Report Count (1), */
  266. 0x14, /* Logical Minimum (0), */
  267. 0xA4, /* Push, */
  268. 0x05, 0x01, /* Usage Page (Desktop), */
  269. 0x65, 0x13, /* Unit (Inch), */
  270. 0x55, 0xFD, /* Unit Exponent (-3), */
  271. 0x34, /* Physical Minimum (0), */
  272. 0x09, 0x30, /* Usage (X), */
  273. 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
  274. 0x26, 0x50, 0x46, /* Logical Maximum (18000), */
  275. 0x81, 0x02, /* Input (Variable), */
  276. 0x09, 0x31, /* Usage (Y), */
  277. 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
  278. 0x26, 0xF8, 0x2A, /* Logical Maximum (11000), */
  279. 0x81, 0x02, /* Input (Variable), */
  280. 0xB4, /* Pop, */
  281. 0x09, 0x30, /* Usage (Tip Pressure), */
  282. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  283. 0x81, 0x02, /* Input (Variable), */
  284. 0xC0, /* End Collection, */
  285. 0xC0, /* End Collection, */
  286. 0x05, 0x01, /* Usage Page (Desktop), */
  287. 0x09, 0x02, /* Usage (Mouse), */
  288. 0xA1, 0x01, /* Collection (Application), */
  289. 0x85, 0x01, /* Report ID (1), */
  290. 0x09, 0x01, /* Usage (Pointer), */
  291. 0xA0, /* Collection (Physical), */
  292. 0x75, 0x08, /* Report Size (8), */
  293. 0x95, 0x03, /* Report Count (3), */
  294. 0x81, 0x03, /* Input (Constant, Variable), */
  295. 0x95, 0x02, /* Report Count (2), */
  296. 0x15, 0xFF, /* Logical Minimum (-1), */
  297. 0x25, 0x01, /* Logical Maximum (1), */
  298. 0x09, 0x38, /* Usage (Wheel), */
  299. 0x0B, 0x38, 0x02, /* Usage (Consumer AC Pan), */
  300. 0x0C, 0x00,
  301. 0x81, 0x06, /* Input (Variable, Relative), */
  302. 0x95, 0x02, /* Report Count (2), */
  303. 0x81, 0x03, /* Input (Constant, Variable), */
  304. 0xC0, /* End Collection, */
  305. 0xC0, /* End Collection, */
  306. 0x05, 0x0C, /* Usage Page (Consumer), */
  307. 0x09, 0x01, /* Usage (Consumer Control), */
  308. 0xA1, 0x01, /* Collection (Application), */
  309. 0x85, 0x0D, /* Report ID (13), */
  310. 0x95, 0x01, /* Report Count (1), */
  311. 0x75, 0x10, /* Report Size (16), */
  312. 0x81, 0x03, /* Input (Constant, Variable), */
  313. 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
  314. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  315. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  316. 0x09, 0xB6, /* Usage (Scan Previous Track), */
  317. 0x09, 0xB5, /* Usage (Scan Next Track), */
  318. 0x08, /* Usage (00h), */
  319. 0x08, /* Usage (00h), */
  320. 0x08, /* Usage (00h), */
  321. 0x08, /* Usage (00h), */
  322. 0x08, /* Usage (00h), */
  323. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  324. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  325. 0x15, 0x0C, /* Logical Minimum (12), */
  326. 0x25, 0x17, /* Logical Maximum (23), */
  327. 0x75, 0x05, /* Report Size (5), */
  328. 0x80, /* Input, */
  329. 0x75, 0x03, /* Report Size (3), */
  330. 0x81, 0x03, /* Input (Constant, Variable), */
  331. 0x75, 0x20, /* Report Size (32), */
  332. 0x81, 0x03, /* Input (Constant, Variable), */
  333. 0xC0, /* End Collection, */
  334. 0x09, 0x01, /* Usage (Consumer Control), */
  335. 0xA1, 0x01, /* Collection (Application), */
  336. 0x85, 0x0C, /* Report ID (12), */
  337. 0x75, 0x01, /* Report Size (1), */
  338. 0x09, 0xE9, /* Usage (Volume Inc), */
  339. 0x09, 0xEA, /* Usage (Volume Dec), */
  340. 0x09, 0xE2, /* Usage (Mute), */
  341. 0x14, /* Logical Minimum (0), */
  342. 0x25, 0x01, /* Logical Maximum (1), */
  343. 0x95, 0x03, /* Report Count (3), */
  344. 0x81, 0x06, /* Input (Variable, Relative), */
  345. 0x95, 0x35, /* Report Count (53), */
  346. 0x81, 0x03, /* Input (Constant, Variable), */
  347. 0xC0 /* End Collection */
  348. };
  349. /* Size of the original report descriptor of Media Tablet 14.1 inch */
  350. #define MEDIA_TABLET_14_1_INCH_RDESC_ORIG_SIZE 309
  351. /* Fixed Media Tablet 14.1 inch descriptor */
  352. static __u8 media_tablet_14_1_inch_rdesc_fixed[] = {
  353. 0x05, 0x0D, /* Usage Page (Digitizer), */
  354. 0x09, 0x02, /* Usage (Pen), */
  355. 0xA1, 0x01, /* Collection (Application), */
  356. 0x85, 0x10, /* Report ID (16), */
  357. 0x09, 0x20, /* Usage (Stylus), */
  358. 0xA0, /* Collection (Physical), */
  359. 0x09, 0x42, /* Usage (Tip Switch), */
  360. 0x09, 0x44, /* Usage (Barrel Switch), */
  361. 0x09, 0x46, /* Usage (Tablet Pick), */
  362. 0x15, 0x01, /* Logical Minimum (1), */
  363. 0x25, 0x03, /* Logical Maximum (3), */
  364. 0x75, 0x04, /* Report Size (4), */
  365. 0x95, 0x01, /* Report Count (1), */
  366. 0x80, /* Input, */
  367. 0x75, 0x01, /* Report Size (1), */
  368. 0x09, 0x32, /* Usage (In Range), */
  369. 0x14, /* Logical Minimum (0), */
  370. 0x25, 0x01, /* Logical Maximum (1), */
  371. 0x95, 0x01, /* Report Count (1), */
  372. 0x81, 0x02, /* Input (Variable), */
  373. 0x95, 0x03, /* Report Count (3), */
  374. 0x81, 0x03, /* Input (Constant, Variable), */
  375. 0x75, 0x10, /* Report Size (16), */
  376. 0x95, 0x01, /* Report Count (1), */
  377. 0x14, /* Logical Minimum (0), */
  378. 0xA4, /* Push, */
  379. 0x05, 0x01, /* Usage Page (Desktop), */
  380. 0x65, 0x13, /* Unit (Inch), */
  381. 0x55, 0xFD, /* Unit Exponent (-3), */
  382. 0x34, /* Physical Minimum (0), */
  383. 0x09, 0x30, /* Usage (X), */
  384. 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
  385. 0x26, 0xFF, 0x3F, /* Logical Maximum (16383), */
  386. 0x81, 0x02, /* Input (Variable), */
  387. 0x09, 0x31, /* Usage (Y), */
  388. 0x46, 0x52, 0x1C, /* Physical Maximum (7250), */
  389. 0x26, 0xFF, 0x3F, /* Logical Maximum (16383), */
  390. 0x81, 0x02, /* Input (Variable), */
  391. 0xB4, /* Pop, */
  392. 0x09, 0x30, /* Usage (Tip Pressure), */
  393. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  394. 0x81, 0x02, /* Input (Variable), */
  395. 0xC0, /* End Collection, */
  396. 0xC0, /* End Collection, */
  397. 0x05, 0x01, /* Usage Page (Desktop), */
  398. 0x09, 0x02, /* Usage (Mouse), */
  399. 0xA1, 0x01, /* Collection (Application), */
  400. 0x85, 0x01, /* Report ID (1), */
  401. 0x09, 0x01, /* Usage (Pointer), */
  402. 0xA0, /* Collection (Physical), */
  403. 0x75, 0x08, /* Report Size (8), */
  404. 0x95, 0x03, /* Report Count (3), */
  405. 0x81, 0x03, /* Input (Constant, Variable), */
  406. 0x95, 0x02, /* Report Count (2), */
  407. 0x15, 0xFF, /* Logical Minimum (-1), */
  408. 0x25, 0x01, /* Logical Maximum (1), */
  409. 0x09, 0x38, /* Usage (Wheel), */
  410. 0x0B, 0x38, 0x02, /* Usage (Consumer AC Pan), */
  411. 0x0C, 0x00,
  412. 0x81, 0x06, /* Input (Variable, Relative), */
  413. 0xC0, /* End Collection, */
  414. 0xC0, /* End Collection, */
  415. 0x05, 0x0C, /* Usage Page (Consumer), */
  416. 0x09, 0x01, /* Usage (Consumer Control), */
  417. 0xA1, 0x01, /* Collection (Application), */
  418. 0x85, 0x0D, /* Report ID (13), */
  419. 0x95, 0x01, /* Report Count (1), */
  420. 0x75, 0x10, /* Report Size (16), */
  421. 0x81, 0x03, /* Input (Constant, Variable), */
  422. 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
  423. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  424. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  425. 0x09, 0xB6, /* Usage (Scan Previous Track), */
  426. 0x09, 0xB5, /* Usage (Scan Next Track), */
  427. 0x08, /* Usage (00h), */
  428. 0x08, /* Usage (00h), */
  429. 0x08, /* Usage (00h), */
  430. 0x08, /* Usage (00h), */
  431. 0x08, /* Usage (00h), */
  432. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  433. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  434. 0x15, 0x0C, /* Logical Minimum (12), */
  435. 0x25, 0x17, /* Logical Maximum (23), */
  436. 0x75, 0x05, /* Report Size (5), */
  437. 0x80, /* Input, */
  438. 0x75, 0x03, /* Report Size (3), */
  439. 0x81, 0x03, /* Input (Constant, Variable), */
  440. 0x75, 0x20, /* Report Size (32), */
  441. 0x81, 0x03, /* Input (Constant, Variable), */
  442. 0xC0, /* End Collection, */
  443. 0x09, 0x01, /* Usage (Consumer Control), */
  444. 0xA1, 0x01, /* Collection (Application), */
  445. 0x85, 0x0C, /* Report ID (12), */
  446. 0x75, 0x01, /* Report Size (1), */
  447. 0x09, 0xE9, /* Usage (Volume Inc), */
  448. 0x09, 0xEA, /* Usage (Volume Dec), */
  449. 0x09, 0xE2, /* Usage (Mute), */
  450. 0x14, /* Logical Minimum (0), */
  451. 0x25, 0x01, /* Logical Maximum (1), */
  452. 0x95, 0x03, /* Report Count (3), */
  453. 0x81, 0x06, /* Input (Variable, Relative), */
  454. 0x75, 0x05, /* Report Size (5), */
  455. 0x81, 0x03, /* Input (Constant, Variable), */
  456. 0xC0 /* End Collection */
  457. };
  458. /* Size of the original report descriptor of Sirius Battery Free Tablet */
  459. #define SIRIUS_BATTERY_FREE_TABLET_RDESC_ORIG_SIZE 335
  460. /* Fixed Sirius Battery Free Tablet descriptor */
  461. static __u8 sirius_battery_free_tablet_rdesc_fixed[] = {
  462. 0x05, 0x0D, /* Usage Page (Digitizer), */
  463. 0x09, 0x02, /* Usage (Pen), */
  464. 0xA1, 0x01, /* Collection (Application), */
  465. 0x85, 0x10, /* Report ID (16), */
  466. 0x09, 0x20, /* Usage (Stylus), */
  467. 0xA0, /* Collection (Physical), */
  468. 0x95, 0x01, /* Report Count (1), */
  469. 0x15, 0x01, /* Logical Minimum (1), */
  470. 0x25, 0x03, /* Logical Maximum (3), */
  471. 0x75, 0x02, /* Report Size (2), */
  472. 0x09, 0x42, /* Usage (Tip Switch), */
  473. 0x09, 0x44, /* Usage (Barrel Switch), */
  474. 0x09, 0x46, /* Usage (Tablet Pick), */
  475. 0x80, /* Input, */
  476. 0x14, /* Logical Minimum (0), */
  477. 0x25, 0x01, /* Logical Maximum (1), */
  478. 0x75, 0x01, /* Report Size (1), */
  479. 0x09, 0x3C, /* Usage (Invert), */
  480. 0x81, 0x02, /* Input (Variable), */
  481. 0x81, 0x03, /* Input (Constant, Variable), */
  482. 0x09, 0x32, /* Usage (In Range), */
  483. 0x81, 0x02, /* Input (Variable), */
  484. 0x95, 0x03, /* Report Count (3), */
  485. 0x81, 0x03, /* Input (Constant, Variable), */
  486. 0xA4, /* Push, */
  487. 0x05, 0x01, /* Usage Page (Desktop), */
  488. 0x55, 0xFD, /* Unit Exponent (-3), */
  489. 0x65, 0x13, /* Unit (Inch), */
  490. 0x34, /* Physical Minimum (0), */
  491. 0x14, /* Logical Minimum (0), */
  492. 0x75, 0x10, /* Report Size (16), */
  493. 0x95, 0x01, /* Report Count (1), */
  494. 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
  495. 0x26, 0x20, 0x4E, /* Logical Maximum (20000), */
  496. 0x09, 0x30, /* Usage (X), */
  497. 0x81, 0x02, /* Input (Variable), */
  498. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  499. 0x26, 0xE0, 0x2E, /* Logical Maximum (12000), */
  500. 0x09, 0x31, /* Usage (Y), */
  501. 0x81, 0x02, /* Input (Variable), */
  502. 0xB4, /* Pop, */
  503. 0x75, 0x10, /* Report Size (16), */
  504. 0x95, 0x01, /* Report Count (1), */
  505. 0x14, /* Logical Minimum (0), */
  506. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  507. 0x09, 0x30, /* Usage (Tip Pressure), */
  508. 0x81, 0x02, /* Input (Variable), */
  509. 0xA4, /* Push, */
  510. 0x55, 0xFE, /* Unit Exponent (-2), */
  511. 0x65, 0x12, /* Unit (Radians), */
  512. 0x35, 0x97, /* Physical Minimum (-105), */
  513. 0x45, 0x69, /* Physical Maximum (105), */
  514. 0x15, 0x97, /* Logical Minimum (-105), */
  515. 0x25, 0x69, /* Logical Maximum (105), */
  516. 0x75, 0x08, /* Report Size (8), */
  517. 0x95, 0x02, /* Report Count (2), */
  518. 0x09, 0x3D, /* Usage (X Tilt), */
  519. 0x09, 0x3E, /* Usage (Y Tilt), */
  520. 0x81, 0x02, /* Input (Variable), */
  521. 0xB4, /* Pop, */
  522. 0xC0, /* End Collection, */
  523. 0xC0, /* End Collection, */
  524. 0x05, 0x01, /* Usage Page (Desktop), */
  525. 0x09, 0x02, /* Usage (Mouse), */
  526. 0xA1, 0x01, /* Collection (Application), */
  527. 0x85, 0x01, /* Report ID (1), */
  528. 0x09, 0x01, /* Usage (Pointer), */
  529. 0xA0, /* Collection (Physical), */
  530. 0x75, 0x08, /* Report Size (8), */
  531. 0x95, 0x03, /* Report Count (3), */
  532. 0x81, 0x03, /* Input (Constant, Variable), */
  533. 0x09, 0x38, /* Usage (Wheel), */
  534. 0x15, 0xFF, /* Logical Minimum (-1), */
  535. 0x25, 0x01, /* Logical Maximum (1), */
  536. 0x75, 0x08, /* Report Size (8), */
  537. 0x95, 0x01, /* Report Count (1), */
  538. 0x81, 0x06, /* Input (Variable, Relative), */
  539. 0x75, 0x08, /* Report Size (8), */
  540. 0x95, 0x03, /* Report Count (3), */
  541. 0x81, 0x03, /* Input (Constant, Variable), */
  542. 0xC0, /* End Collection, */
  543. 0xC0, /* End Collection, */
  544. 0x05, 0x01, /* Usage Page (Desktop), */
  545. 0x09, 0x06, /* Usage (Keyboard), */
  546. 0xA1, 0x01, /* Collection (Application), */
  547. 0x85, 0x0D, /* Report ID (13), */
  548. 0x05, 0x07, /* Usage Page (Keyboard), */
  549. 0x19, 0xE0, /* Usage Minimum (KB Leftcontrol), */
  550. 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */
  551. 0x14, /* Logical Minimum (0), */
  552. 0x25, 0x01, /* Logical Maximum (1), */
  553. 0x75, 0x01, /* Report Size (1), */
  554. 0x95, 0x08, /* Report Count (8), */
  555. 0x81, 0x02, /* Input (Variable), */
  556. 0x75, 0x08, /* Report Size (8), */
  557. 0x95, 0x01, /* Report Count (1), */
  558. 0x81, 0x01, /* Input (Constant), */
  559. 0x18, /* Usage Minimum (None), */
  560. 0x29, 0x65, /* Usage Maximum (KB Application), */
  561. 0x14, /* Logical Minimum (0), */
  562. 0x25, 0x65, /* Logical Maximum (101), */
  563. 0x75, 0x08, /* Report Size (8), */
  564. 0x95, 0x05, /* Report Count (5), */
  565. 0x80, /* Input, */
  566. 0xC0, /* End Collection, */
  567. 0x05, 0x0C, /* Usage Page (Consumer), */
  568. 0x09, 0x01, /* Usage (Consumer Control), */
  569. 0xA1, 0x01, /* Collection (Application), */
  570. 0x85, 0x0C, /* Report ID (12), */
  571. 0x09, 0xE9, /* Usage (Volume Inc), */
  572. 0x09, 0xEA, /* Usage (Volume Dec), */
  573. 0x14, /* Logical Minimum (0), */
  574. 0x25, 0x01, /* Logical Maximum (1), */
  575. 0x75, 0x01, /* Report Size (1), */
  576. 0x95, 0x02, /* Report Count (2), */
  577. 0x81, 0x02, /* Input (Variable), */
  578. 0x75, 0x06, /* Report Size (6), */
  579. 0x95, 0x01, /* Report Count (1), */
  580. 0x81, 0x03, /* Input (Constant, Variable), */
  581. 0x75, 0x10, /* Report Size (16), */
  582. 0x95, 0x03, /* Report Count (3), */
  583. 0x81, 0x03, /* Input (Constant, Variable), */
  584. 0xC0 /* End Collection */
  585. };
  586. static __u8 *waltop_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  587. unsigned int *rsize)
  588. {
  589. switch (hdev->product) {
  590. case USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH:
  591. if (*rsize == SLIM_TABLET_5_8_INCH_RDESC_ORIG_SIZE) {
  592. rdesc = slim_tablet_5_8_inch_rdesc_fixed;
  593. *rsize = sizeof(slim_tablet_5_8_inch_rdesc_fixed);
  594. }
  595. break;
  596. case USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH:
  597. if (*rsize == SLIM_TABLET_12_1_INCH_RDESC_ORIG_SIZE) {
  598. rdesc = slim_tablet_12_1_inch_rdesc_fixed;
  599. *rsize = sizeof(slim_tablet_12_1_inch_rdesc_fixed);
  600. }
  601. break;
  602. case USB_DEVICE_ID_WALTOP_Q_PAD:
  603. if (*rsize == Q_PAD_RDESC_ORIG_SIZE) {
  604. rdesc = q_pad_rdesc_fixed;
  605. *rsize = sizeof(q_pad_rdesc_fixed);
  606. }
  607. break;
  608. case USB_DEVICE_ID_WALTOP_PID_0038:
  609. if (*rsize == PID_0038_RDESC_ORIG_SIZE) {
  610. rdesc = pid_0038_rdesc_fixed;
  611. *rsize = sizeof(pid_0038_rdesc_fixed);
  612. }
  613. break;
  614. case USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH:
  615. if (*rsize == MEDIA_TABLET_10_6_INCH_RDESC_ORIG_SIZE) {
  616. rdesc = media_tablet_10_6_inch_rdesc_fixed;
  617. *rsize = sizeof(media_tablet_10_6_inch_rdesc_fixed);
  618. }
  619. break;
  620. case USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH:
  621. if (*rsize == MEDIA_TABLET_14_1_INCH_RDESC_ORIG_SIZE) {
  622. rdesc = media_tablet_14_1_inch_rdesc_fixed;
  623. *rsize = sizeof(media_tablet_14_1_inch_rdesc_fixed);
  624. }
  625. break;
  626. case USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET:
  627. if (*rsize == SIRIUS_BATTERY_FREE_TABLET_RDESC_ORIG_SIZE) {
  628. rdesc = sirius_battery_free_tablet_rdesc_fixed;
  629. *rsize = sizeof(sirius_battery_free_tablet_rdesc_fixed);
  630. }
  631. break;
  632. }
  633. return rdesc;
  634. }
  635. static int waltop_raw_event(struct hid_device *hdev, struct hid_report *report,
  636. u8 *data, int size)
  637. {
  638. /* If this is a pen input report */
  639. if (report->type == HID_INPUT_REPORT && report->id == 16 && size >= 8) {
  640. /*
  641. * Ignore reported pressure when a barrel button is pressed,
  642. * because it is rarely correct.
  643. */
  644. /* If a barrel button is pressed */
  645. if ((data[1] & 0xF) > 1) {
  646. /* Report zero pressure */
  647. data[6] = 0;
  648. data[7] = 0;
  649. }
  650. }
  651. /* If this is a pen input report of Sirius Battery Free Tablet */
  652. if (hdev->product == USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET &&
  653. report->type == HID_INPUT_REPORT &&
  654. report->id == 16 &&
  655. size == 10) {
  656. /*
  657. * The tablet reports tilt as roughly sin(a)*21 (18 means 60
  658. * degrees).
  659. *
  660. * This array stores angles as radians * 100, corresponding to
  661. * reported values up to 60 degrees, as expected by userspace.
  662. */
  663. static const s8 tilt_to_radians[] = {
  664. 0, 5, 10, 14, 19, 24, 29, 34, 40, 45,
  665. 50, 56, 62, 68, 74, 81, 88, 96, 105
  666. };
  667. s8 tilt_x = (s8)data[8];
  668. s8 tilt_y = (s8)data[9];
  669. s8 sign_x = tilt_x >= 0 ? 1 : -1;
  670. s8 sign_y = tilt_y >= 0 ? 1 : -1;
  671. tilt_x *= sign_x;
  672. tilt_y *= sign_y;
  673. /*
  674. * Reverse the Y Tilt direction to match the HID standard and
  675. * userspace expectations. See HID Usage Tables v1.12 16.3.2
  676. * Tilt Orientation.
  677. */
  678. sign_y *= -1;
  679. /*
  680. * This effectively clamps reported tilt to 60 degrees - the
  681. * range expected by userspace
  682. */
  683. if (tilt_x > ARRAY_SIZE(tilt_to_radians) - 1)
  684. tilt_x = ARRAY_SIZE(tilt_to_radians) - 1;
  685. if (tilt_y > ARRAY_SIZE(tilt_to_radians) - 1)
  686. tilt_y = ARRAY_SIZE(tilt_to_radians) - 1;
  687. data[8] = tilt_to_radians[tilt_x] * sign_x;
  688. data[9] = tilt_to_radians[tilt_y] * sign_y;
  689. }
  690. return 0;
  691. }
  692. static const struct hid_device_id waltop_devices[] = {
  693. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  694. USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
  695. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  696. USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
  697. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  698. USB_DEVICE_ID_WALTOP_Q_PAD) },
  699. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  700. USB_DEVICE_ID_WALTOP_PID_0038) },
  701. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  702. USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
  703. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  704. USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
  705. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
  706. USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
  707. { }
  708. };
  709. MODULE_DEVICE_TABLE(hid, waltop_devices);
  710. static struct hid_driver waltop_driver = {
  711. .name = "waltop",
  712. .id_table = waltop_devices,
  713. .report_fixup = waltop_report_fixup,
  714. .raw_event = waltop_raw_event,
  715. };
  716. module_hid_driver(waltop_driver);
  717. MODULE_LICENSE("GPL");