blob: f4377c45878756792087f87ff8edeadd32cee821 [file] [log] [blame]
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001/*
2 * HID driver for UC-Logic devices not fully compliant with HID standard
3 *
Nikolai Kondrashov08177f42015-03-03 12:44:01 -05004 * Copyright (c) 2010-2014 Nikolai Kondrashov
5 * Copyright (c) 2013 Martin Rusko
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04006 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
Nikolai Kondrashovd1257082012-05-14 20:30:38 +030018#include <linux/usb.h>
Nikolai Kondrashov08177f42015-03-03 12:44:01 -050019#include <asm/unaligned.h>
20#include "usbhid/usbhid.h"
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +040021
22#include "hid-ids.h"
23
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +040024/* Size of the original descriptor of WPXXXXU tablets */
25#define WPXXXXU_RDESC_ORIG_SIZE 212
26
Nikolai Kondrashov51153a72012-03-06 09:54:22 +020027/* Fixed WP4030U report descriptor */
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +040028static __u8 wp4030u_rdesc_fixed[] = {
29 0x05, 0x0D, /* Usage Page (Digitizer), */
30 0x09, 0x02, /* Usage (Pen), */
31 0xA1, 0x01, /* Collection (Application), */
32 0x85, 0x09, /* Report ID (9), */
33 0x09, 0x20, /* Usage (Stylus), */
34 0xA0, /* Collection (Physical), */
35 0x75, 0x01, /* Report Size (1), */
36 0x09, 0x42, /* Usage (Tip Switch), */
37 0x09, 0x44, /* Usage (Barrel Switch), */
38 0x09, 0x46, /* Usage (Tablet Pick), */
39 0x14, /* Logical Minimum (0), */
40 0x25, 0x01, /* Logical Maximum (1), */
41 0x95, 0x03, /* Report Count (3), */
42 0x81, 0x02, /* Input (Variable), */
43 0x95, 0x05, /* Report Count (5), */
44 0x81, 0x01, /* Input (Constant), */
45 0x75, 0x10, /* Report Size (16), */
46 0x95, 0x01, /* Report Count (1), */
47 0x14, /* Logical Minimum (0), */
48 0xA4, /* Push, */
49 0x05, 0x01, /* Usage Page (Desktop), */
50 0x55, 0xFD, /* Unit Exponent (-3), */
51 0x65, 0x13, /* Unit (Inch), */
52 0x34, /* Physical Minimum (0), */
53 0x09, 0x30, /* Usage (X), */
54 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
55 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
56 0x81, 0x02, /* Input (Variable), */
57 0x09, 0x31, /* Usage (Y), */
58 0x46, 0xB8, 0x0B, /* Physical Maximum (3000), */
59 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
60 0x81, 0x02, /* Input (Variable), */
61 0xB4, /* Pop, */
62 0x09, 0x30, /* Usage (Tip Pressure), */
63 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
64 0x81, 0x02, /* Input (Variable), */
65 0xC0, /* End Collection, */
66 0xC0 /* End Collection */
67};
68
69/* Fixed WP5540U report descriptor */
70static __u8 wp5540u_rdesc_fixed[] = {
71 0x05, 0x0D, /* Usage Page (Digitizer), */
72 0x09, 0x02, /* Usage (Pen), */
73 0xA1, 0x01, /* Collection (Application), */
74 0x85, 0x09, /* Report ID (9), */
75 0x09, 0x20, /* Usage (Stylus), */
76 0xA0, /* Collection (Physical), */
77 0x75, 0x01, /* Report Size (1), */
78 0x09, 0x42, /* Usage (Tip Switch), */
79 0x09, 0x44, /* Usage (Barrel Switch), */
80 0x09, 0x46, /* Usage (Tablet Pick), */
81 0x14, /* Logical Minimum (0), */
82 0x25, 0x01, /* Logical Maximum (1), */
83 0x95, 0x03, /* Report Count (3), */
84 0x81, 0x02, /* Input (Variable), */
85 0x95, 0x05, /* Report Count (5), */
86 0x81, 0x01, /* Input (Constant), */
87 0x75, 0x10, /* Report Size (16), */
88 0x95, 0x01, /* Report Count (1), */
89 0x14, /* Logical Minimum (0), */
90 0xA4, /* Push, */
91 0x05, 0x01, /* Usage Page (Desktop), */
92 0x55, 0xFD, /* Unit Exponent (-3), */
93 0x65, 0x13, /* Unit (Inch), */
94 0x34, /* Physical Minimum (0), */
95 0x09, 0x30, /* Usage (X), */
96 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
97 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
98 0x81, 0x02, /* Input (Variable), */
99 0x09, 0x31, /* Usage (Y), */
100 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
101 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
102 0x81, 0x02, /* Input (Variable), */
103 0xB4, /* Pop, */
104 0x09, 0x30, /* Usage (Tip Pressure), */
105 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
106 0x81, 0x02, /* Input (Variable), */
107 0xC0, /* End Collection, */
108 0xC0, /* End Collection, */
109 0x05, 0x01, /* Usage Page (Desktop), */
110 0x09, 0x02, /* Usage (Mouse), */
111 0xA1, 0x01, /* Collection (Application), */
112 0x85, 0x08, /* Report ID (8), */
113 0x09, 0x01, /* Usage (Pointer), */
114 0xA0, /* Collection (Physical), */
115 0x75, 0x01, /* Report Size (1), */
116 0x05, 0x09, /* Usage Page (Button), */
117 0x19, 0x01, /* Usage Minimum (01h), */
118 0x29, 0x03, /* Usage Maximum (03h), */
119 0x14, /* Logical Minimum (0), */
120 0x25, 0x01, /* Logical Maximum (1), */
121 0x95, 0x03, /* Report Count (3), */
122 0x81, 0x02, /* Input (Variable), */
123 0x95, 0x05, /* Report Count (5), */
124 0x81, 0x01, /* Input (Constant), */
125 0x05, 0x01, /* Usage Page (Desktop), */
126 0x75, 0x08, /* Report Size (8), */
127 0x09, 0x30, /* Usage (X), */
128 0x09, 0x31, /* Usage (Y), */
129 0x15, 0x81, /* Logical Minimum (-127), */
130 0x25, 0x7F, /* Logical Maximum (127), */
131 0x95, 0x02, /* Report Count (2), */
132 0x81, 0x06, /* Input (Variable, Relative), */
133 0x09, 0x38, /* Usage (Wheel), */
134 0x15, 0xFF, /* Logical Minimum (-1), */
135 0x25, 0x01, /* Logical Maximum (1), */
136 0x95, 0x01, /* Report Count (1), */
137 0x81, 0x06, /* Input (Variable, Relative), */
138 0x81, 0x01, /* Input (Constant), */
139 0xC0, /* End Collection, */
140 0xC0 /* End Collection */
141};
142
143/* Fixed WP8060U report descriptor */
144static __u8 wp8060u_rdesc_fixed[] = {
145 0x05, 0x0D, /* Usage Page (Digitizer), */
146 0x09, 0x02, /* Usage (Pen), */
147 0xA1, 0x01, /* Collection (Application), */
148 0x85, 0x09, /* Report ID (9), */
149 0x09, 0x20, /* Usage (Stylus), */
150 0xA0, /* Collection (Physical), */
151 0x75, 0x01, /* Report Size (1), */
152 0x09, 0x42, /* Usage (Tip Switch), */
153 0x09, 0x44, /* Usage (Barrel Switch), */
154 0x09, 0x46, /* Usage (Tablet Pick), */
155 0x14, /* Logical Minimum (0), */
156 0x25, 0x01, /* Logical Maximum (1), */
157 0x95, 0x03, /* Report Count (3), */
158 0x81, 0x02, /* Input (Variable), */
159 0x95, 0x05, /* Report Count (5), */
160 0x81, 0x01, /* Input (Constant), */
161 0x75, 0x10, /* Report Size (16), */
162 0x95, 0x01, /* Report Count (1), */
163 0x14, /* Logical Minimum (0), */
164 0xA4, /* Push, */
165 0x05, 0x01, /* Usage Page (Desktop), */
166 0x55, 0xFD, /* Unit Exponent (-3), */
167 0x65, 0x13, /* Unit (Inch), */
168 0x34, /* Physical Minimum (0), */
169 0x09, 0x30, /* Usage (X), */
170 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
171 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
172 0x81, 0x02, /* Input (Variable), */
173 0x09, 0x31, /* Usage (Y), */
174 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
175 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
176 0x81, 0x02, /* Input (Variable), */
177 0xB4, /* Pop, */
178 0x09, 0x30, /* Usage (Tip Pressure), */
179 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
180 0x81, 0x02, /* Input (Variable), */
181 0xC0, /* End Collection, */
182 0xC0, /* End Collection, */
183 0x05, 0x01, /* Usage Page (Desktop), */
184 0x09, 0x02, /* Usage (Mouse), */
185 0xA1, 0x01, /* Collection (Application), */
186 0x85, 0x08, /* Report ID (8), */
187 0x09, 0x01, /* Usage (Pointer), */
188 0xA0, /* Collection (Physical), */
189 0x75, 0x01, /* Report Size (1), */
190 0x05, 0x09, /* Usage Page (Button), */
191 0x19, 0x01, /* Usage Minimum (01h), */
192 0x29, 0x03, /* Usage Maximum (03h), */
193 0x14, /* Logical Minimum (0), */
194 0x25, 0x01, /* Logical Maximum (1), */
195 0x95, 0x03, /* Report Count (3), */
196 0x81, 0x02, /* Input (Variable), */
197 0x95, 0x05, /* Report Count (5), */
198 0x81, 0x01, /* Input (Constant), */
199 0x05, 0x01, /* Usage Page (Desktop), */
200 0x75, 0x08, /* Report Size (8), */
201 0x09, 0x30, /* Usage (X), */
202 0x09, 0x31, /* Usage (Y), */
203 0x15, 0x81, /* Logical Minimum (-127), */
204 0x25, 0x7F, /* Logical Maximum (127), */
205 0x95, 0x02, /* Report Count (2), */
206 0x81, 0x06, /* Input (Variable, Relative), */
207 0x09, 0x38, /* Usage (Wheel), */
208 0x15, 0xFF, /* Logical Minimum (-1), */
209 0x25, 0x01, /* Logical Maximum (1), */
210 0x95, 0x01, /* Report Count (1), */
211 0x81, 0x06, /* Input (Variable, Relative), */
212 0x81, 0x01, /* Input (Constant), */
213 0xC0, /* End Collection, */
214 0xC0 /* End Collection */
215};
216
Nikolai Kondrashov6be914f2011-07-06 09:23:41 +0300217/* Size of the original descriptor of WP1062 tablet */
218#define WP1062_RDESC_ORIG_SIZE 254
219
Nikolai Kondrashov51153a72012-03-06 09:54:22 +0200220/* Fixed WP1062 report descriptor */
Nikolai Kondrashov6be914f2011-07-06 09:23:41 +0300221static __u8 wp1062_rdesc_fixed[] = {
222 0x05, 0x0D, /* Usage Page (Digitizer), */
223 0x09, 0x02, /* Usage (Pen), */
224 0xA1, 0x01, /* Collection (Application), */
225 0x85, 0x09, /* Report ID (9), */
226 0x09, 0x20, /* Usage (Stylus), */
227 0xA0, /* Collection (Physical), */
228 0x75, 0x01, /* Report Size (1), */
229 0x09, 0x42, /* Usage (Tip Switch), */
230 0x09, 0x44, /* Usage (Barrel Switch), */
231 0x09, 0x46, /* Usage (Tablet Pick), */
232 0x14, /* Logical Minimum (0), */
233 0x25, 0x01, /* Logical Maximum (1), */
234 0x95, 0x03, /* Report Count (3), */
235 0x81, 0x02, /* Input (Variable), */
236 0x95, 0x04, /* Report Count (4), */
237 0x81, 0x01, /* Input (Constant), */
238 0x09, 0x32, /* Usage (In Range), */
239 0x95, 0x01, /* Report Count (1), */
240 0x81, 0x02, /* Input (Variable), */
241 0x75, 0x10, /* Report Size (16), */
242 0x95, 0x01, /* Report Count (1), */
243 0x14, /* Logical Minimum (0), */
244 0xA4, /* Push, */
245 0x05, 0x01, /* Usage Page (Desktop), */
246 0x55, 0xFD, /* Unit Exponent (-3), */
247 0x65, 0x13, /* Unit (Inch), */
248 0x34, /* Physical Minimum (0), */
249 0x09, 0x30, /* Usage (X), */
250 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
251 0x26, 0x20, 0x4E, /* Logical Maximum (20000), */
252 0x81, 0x02, /* Input (Variable), */
253 0x09, 0x31, /* Usage (Y), */
254 0x46, 0xB7, 0x19, /* Physical Maximum (6583), */
255 0x26, 0x6E, 0x33, /* Logical Maximum (13166), */
256 0x81, 0x02, /* Input (Variable), */
257 0xB4, /* Pop, */
258 0x09, 0x30, /* Usage (Tip Pressure), */
259 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
260 0x81, 0x02, /* Input (Variable), */
261 0xC0, /* End Collection, */
262 0xC0 /* End Collection */
263};
264
Nikolai Kondrashov41fa9232010-08-23 15:09:01 +0400265/* Size of the original descriptor of PF1209 tablet */
266#define PF1209_RDESC_ORIG_SIZE 234
267
Nikolai Kondrashov51153a72012-03-06 09:54:22 +0200268/* Fixed PF1209 report descriptor */
Nikolai Kondrashov41fa9232010-08-23 15:09:01 +0400269static __u8 pf1209_rdesc_fixed[] = {
270 0x05, 0x0D, /* Usage Page (Digitizer), */
271 0x09, 0x02, /* Usage (Pen), */
272 0xA1, 0x01, /* Collection (Application), */
273 0x85, 0x09, /* Report ID (9), */
274 0x09, 0x20, /* Usage (Stylus), */
275 0xA0, /* Collection (Physical), */
276 0x75, 0x01, /* Report Size (1), */
277 0x09, 0x42, /* Usage (Tip Switch), */
278 0x09, 0x44, /* Usage (Barrel Switch), */
279 0x09, 0x46, /* Usage (Tablet Pick), */
280 0x14, /* Logical Minimum (0), */
281 0x25, 0x01, /* Logical Maximum (1), */
282 0x95, 0x03, /* Report Count (3), */
283 0x81, 0x02, /* Input (Variable), */
284 0x95, 0x05, /* Report Count (5), */
285 0x81, 0x01, /* Input (Constant), */
286 0x75, 0x10, /* Report Size (16), */
287 0x95, 0x01, /* Report Count (1), */
288 0x14, /* Logical Minimum (0), */
289 0xA4, /* Push, */
290 0x05, 0x01, /* Usage Page (Desktop), */
291 0x55, 0xFD, /* Unit Exponent (-3), */
292 0x65, 0x13, /* Unit (Inch), */
293 0x34, /* Physical Minimum (0), */
294 0x09, 0x30, /* Usage (X), */
295 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
296 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
297 0x81, 0x02, /* Input (Variable), */
298 0x09, 0x31, /* Usage (Y), */
299 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
300 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
301 0x81, 0x02, /* Input (Variable), */
302 0xB4, /* Pop, */
303 0x09, 0x30, /* Usage (Tip Pressure), */
304 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
305 0x81, 0x02, /* Input (Variable), */
306 0xC0, /* End Collection, */
307 0xC0, /* End Collection, */
308 0x05, 0x01, /* Usage Page (Desktop), */
309 0x09, 0x02, /* Usage (Mouse), */
310 0xA1, 0x01, /* Collection (Application), */
311 0x85, 0x08, /* Report ID (8), */
312 0x09, 0x01, /* Usage (Pointer), */
313 0xA0, /* Collection (Physical), */
314 0x75, 0x01, /* Report Size (1), */
315 0x05, 0x09, /* Usage Page (Button), */
316 0x19, 0x01, /* Usage Minimum (01h), */
317 0x29, 0x03, /* Usage Maximum (03h), */
318 0x14, /* Logical Minimum (0), */
319 0x25, 0x01, /* Logical Maximum (1), */
320 0x95, 0x03, /* Report Count (3), */
321 0x81, 0x02, /* Input (Variable), */
322 0x95, 0x05, /* Report Count (5), */
323 0x81, 0x01, /* Input (Constant), */
324 0x05, 0x01, /* Usage Page (Desktop), */
325 0x75, 0x08, /* Report Size (8), */
326 0x09, 0x30, /* Usage (X), */
327 0x09, 0x31, /* Usage (Y), */
328 0x15, 0x81, /* Logical Minimum (-127), */
329 0x25, 0x7F, /* Logical Maximum (127), */
330 0x95, 0x02, /* Report Count (2), */
331 0x81, 0x06, /* Input (Variable, Relative), */
332 0x09, 0x38, /* Usage (Wheel), */
333 0x15, 0xFF, /* Logical Minimum (-1), */
334 0x25, 0x01, /* Logical Maximum (1), */
335 0x95, 0x01, /* Report Count (1), */
336 0x81, 0x06, /* Input (Variable, Relative), */
337 0x81, 0x01, /* Input (Constant), */
338 0xC0, /* End Collection, */
339 0xC0 /* End Collection */
340};
341
Nikolai Kondrashovd1257082012-05-14 20:30:38 +0300342/* Size of the original descriptors of TWHL850 tablet */
343#define TWHL850_RDESC_ORIG_SIZE0 182
344#define TWHL850_RDESC_ORIG_SIZE1 161
345#define TWHL850_RDESC_ORIG_SIZE2 92
346
347/* Fixed PID 0522 tablet report descriptor, interface 0 (stylus) */
348static __u8 twhl850_rdesc_fixed0[] = {
349 0x05, 0x0D, /* Usage Page (Digitizer), */
350 0x09, 0x02, /* Usage (Pen), */
351 0xA1, 0x01, /* Collection (Application), */
352 0x85, 0x09, /* Report ID (9), */
353 0x09, 0x20, /* Usage (Stylus), */
354 0xA0, /* Collection (Physical), */
355 0x14, /* Logical Minimum (0), */
356 0x25, 0x01, /* Logical Maximum (1), */
357 0x75, 0x01, /* Report Size (1), */
358 0x95, 0x03, /* Report Count (3), */
359 0x09, 0x42, /* Usage (Tip Switch), */
360 0x09, 0x44, /* Usage (Barrel Switch), */
361 0x09, 0x46, /* Usage (Tablet Pick), */
362 0x81, 0x02, /* Input (Variable), */
363 0x81, 0x03, /* Input (Constant, Variable), */
364 0x95, 0x01, /* Report Count (1), */
365 0x09, 0x32, /* Usage (In Range), */
366 0x81, 0x02, /* Input (Variable), */
367 0x81, 0x03, /* Input (Constant, Variable), */
368 0x75, 0x10, /* Report Size (16), */
369 0xA4, /* Push, */
370 0x05, 0x01, /* Usage Page (Desktop), */
371 0x65, 0x13, /* Unit (Inch), */
372 0x55, 0xFD, /* Unit Exponent (-3), */
373 0x34, /* Physical Minimum (0), */
374 0x09, 0x30, /* Usage (X), */
375 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
376 0x26, 0x00, 0x7D, /* Logical Maximum (32000), */
377 0x81, 0x02, /* Input (Variable), */
378 0x09, 0x31, /* Usage (Y), */
379 0x46, 0x88, 0x13, /* Physical Maximum (5000), */
380 0x26, 0x20, 0x4E, /* Logical Maximum (20000), */
381 0x81, 0x02, /* Input (Variable), */
382 0xB4, /* Pop, */
383 0x09, 0x30, /* Usage (Tip Pressure), */
384 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
385 0x81, 0x02, /* Input (Variable), */
386 0xC0, /* End Collection, */
387 0xC0 /* End Collection */
388};
389
390/* Fixed PID 0522 tablet report descriptor, interface 1 (mouse) */
391static __u8 twhl850_rdesc_fixed1[] = {
392 0x05, 0x01, /* Usage Page (Desktop), */
393 0x09, 0x02, /* Usage (Mouse), */
394 0xA1, 0x01, /* Collection (Application), */
395 0x85, 0x01, /* Report ID (1), */
396 0x09, 0x01, /* Usage (Pointer), */
397 0xA0, /* Collection (Physical), */
398 0x05, 0x09, /* Usage Page (Button), */
399 0x75, 0x01, /* Report Size (1), */
400 0x95, 0x03, /* Report Count (3), */
401 0x19, 0x01, /* Usage Minimum (01h), */
402 0x29, 0x03, /* Usage Maximum (03h), */
403 0x14, /* Logical Minimum (0), */
404 0x25, 0x01, /* Logical Maximum (1), */
405 0x81, 0x02, /* Input (Variable), */
406 0x95, 0x05, /* Report Count (5), */
407 0x81, 0x03, /* Input (Constant, Variable), */
408 0x05, 0x01, /* Usage Page (Desktop), */
409 0x09, 0x30, /* Usage (X), */
410 0x09, 0x31, /* Usage (Y), */
411 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
412 0x26, 0xFF, 0x7F, /* Logical Maximum (32767), */
413 0x75, 0x10, /* Report Size (16), */
414 0x95, 0x02, /* Report Count (2), */
415 0x81, 0x06, /* Input (Variable, Relative), */
416 0x09, 0x38, /* Usage (Wheel), */
417 0x15, 0xFF, /* Logical Minimum (-1), */
418 0x25, 0x01, /* Logical Maximum (1), */
419 0x95, 0x01, /* Report Count (1), */
420 0x75, 0x08, /* Report Size (8), */
421 0x81, 0x06, /* Input (Variable, Relative), */
422 0x81, 0x03, /* Input (Constant, Variable), */
423 0xC0, /* End Collection, */
424 0xC0 /* End Collection */
425};
426
427/* Fixed PID 0522 tablet report descriptor, interface 2 (frame buttons) */
428static __u8 twhl850_rdesc_fixed2[] = {
429 0x05, 0x01, /* Usage Page (Desktop), */
430 0x09, 0x06, /* Usage (Keyboard), */
431 0xA1, 0x01, /* Collection (Application), */
432 0x85, 0x03, /* Report ID (3), */
433 0x05, 0x07, /* Usage Page (Keyboard), */
434 0x14, /* Logical Minimum (0), */
435 0x19, 0xE0, /* Usage Minimum (KB Leftcontrol), */
436 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */
437 0x25, 0x01, /* Logical Maximum (1), */
438 0x75, 0x01, /* Report Size (1), */
439 0x95, 0x08, /* Report Count (8), */
440 0x81, 0x02, /* Input (Variable), */
441 0x18, /* Usage Minimum (None), */
442 0x29, 0xFF, /* Usage Maximum (FFh), */
443 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
444 0x75, 0x08, /* Report Size (8), */
445 0x95, 0x06, /* Report Count (6), */
446 0x80, /* Input, */
447 0xC0 /* End Collection */
448};
449
Nikolai Kondrashoveb4e4262012-08-26 20:55:08 +0300450/* Size of the original descriptors of TWHA60 tablet */
451#define TWHA60_RDESC_ORIG_SIZE0 254
452#define TWHA60_RDESC_ORIG_SIZE1 139
453
454/* Fixed TWHA60 report descriptor, interface 0 (stylus) */
455static __u8 twha60_rdesc_fixed0[] = {
456 0x05, 0x0D, /* Usage Page (Digitizer), */
457 0x09, 0x02, /* Usage (Pen), */
458 0xA1, 0x01, /* Collection (Application), */
459 0x85, 0x09, /* Report ID (9), */
460 0x09, 0x20, /* Usage (Stylus), */
461 0xA0, /* Collection (Physical), */
462 0x75, 0x01, /* Report Size (1), */
463 0x09, 0x42, /* Usage (Tip Switch), */
464 0x09, 0x44, /* Usage (Barrel Switch), */
465 0x09, 0x46, /* Usage (Tablet Pick), */
466 0x14, /* Logical Minimum (0), */
467 0x25, 0x01, /* Logical Maximum (1), */
468 0x95, 0x03, /* Report Count (3), */
469 0x81, 0x02, /* Input (Variable), */
470 0x95, 0x04, /* Report Count (4), */
471 0x81, 0x01, /* Input (Constant), */
472 0x09, 0x32, /* Usage (In Range), */
473 0x95, 0x01, /* Report Count (1), */
474 0x81, 0x02, /* Input (Variable), */
475 0x75, 0x10, /* Report Size (16), */
476 0x95, 0x01, /* Report Count (1), */
477 0x14, /* Logical Minimum (0), */
478 0xA4, /* Push, */
479 0x05, 0x01, /* Usage Page (Desktop), */
480 0x55, 0xFD, /* Unit Exponent (-3), */
481 0x65, 0x13, /* Unit (Inch), */
482 0x34, /* Physical Minimum (0), */
483 0x09, 0x30, /* Usage (X), */
484 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
485 0x27, 0x3F, 0x9C,
486 0x00, 0x00, /* Logical Maximum (39999), */
487 0x81, 0x02, /* Input (Variable), */
488 0x09, 0x31, /* Usage (Y), */
489 0x46, 0x6A, 0x18, /* Physical Maximum (6250), */
490 0x26, 0xA7, 0x61, /* Logical Maximum (24999), */
491 0x81, 0x02, /* Input (Variable), */
492 0xB4, /* Pop, */
493 0x09, 0x30, /* Usage (Tip Pressure), */
494 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
495 0x81, 0x02, /* Input (Variable), */
496 0xC0, /* End Collection, */
497 0xC0 /* End Collection */
498};
499
500/* Fixed TWHA60 report descriptor, interface 1 (frame buttons) */
501static __u8 twha60_rdesc_fixed1[] = {
502 0x05, 0x01, /* Usage Page (Desktop), */
503 0x09, 0x06, /* Usage (Keyboard), */
504 0xA1, 0x01, /* Collection (Application), */
505 0x85, 0x05, /* Report ID (5), */
506 0x05, 0x07, /* Usage Page (Keyboard), */
507 0x14, /* Logical Minimum (0), */
508 0x25, 0x01, /* Logical Maximum (1), */
509 0x75, 0x01, /* Report Size (1), */
510 0x95, 0x08, /* Report Count (8), */
511 0x81, 0x01, /* Input (Constant), */
512 0x95, 0x0C, /* Report Count (12), */
513 0x19, 0x3A, /* Usage Minimum (KB F1), */
514 0x29, 0x45, /* Usage Maximum (KB F12), */
515 0x81, 0x02, /* Input (Variable), */
516 0x95, 0x0C, /* Report Count (12), */
517 0x19, 0x68, /* Usage Minimum (KB F13), */
518 0x29, 0x73, /* Usage Maximum (KB F24), */
519 0x81, 0x02, /* Input (Variable), */
520 0x95, 0x08, /* Report Count (8), */
521 0x81, 0x01, /* Input (Constant), */
522 0xC0 /* End Collection */
523};
524
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500525/* Report descriptor template placeholder head */
526#define UCLOGIC_PH_HEAD 0xFE, 0xED, 0x1D
527
528/* Report descriptor template placeholder IDs */
529enum uclogic_ph_id {
530 UCLOGIC_PH_ID_X_LM,
531 UCLOGIC_PH_ID_X_PM,
532 UCLOGIC_PH_ID_Y_LM,
533 UCLOGIC_PH_ID_Y_PM,
534 UCLOGIC_PH_ID_PRESSURE_LM,
535 UCLOGIC_PH_ID_NUM
536};
537
538/* Report descriptor template placeholder */
539#define UCLOGIC_PH(_ID) UCLOGIC_PH_HEAD, UCLOGIC_PH_ID_##_ID
Benjamin Tissoiresfce8c5f2015-03-03 12:44:05 -0500540#define UCLOGIC_PEN_REPORT_ID 0x07
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500541
542/* Fixed report descriptor template */
543static const __u8 uclogic_tablet_rdesc_template[] = {
544 0x05, 0x0D, /* Usage Page (Digitizer), */
545 0x09, 0x02, /* Usage (Pen), */
546 0xA1, 0x01, /* Collection (Application), */
547 0x85, 0x07, /* Report ID (7), */
548 0x09, 0x20, /* Usage (Stylus), */
549 0xA0, /* Collection (Physical), */
550 0x14, /* Logical Minimum (0), */
551 0x25, 0x01, /* Logical Maximum (1), */
552 0x75, 0x01, /* Report Size (1), */
553 0x09, 0x42, /* Usage (Tip Switch), */
554 0x09, 0x44, /* Usage (Barrel Switch), */
555 0x09, 0x46, /* Usage (Tablet Pick), */
556 0x95, 0x03, /* Report Count (3), */
557 0x81, 0x02, /* Input (Variable), */
558 0x95, 0x03, /* Report Count (3), */
559 0x81, 0x03, /* Input (Constant, Variable), */
560 0x09, 0x32, /* Usage (In Range), */
561 0x95, 0x01, /* Report Count (1), */
562 0x81, 0x02, /* Input (Variable), */
563 0x95, 0x01, /* Report Count (1), */
564 0x81, 0x03, /* Input (Constant, Variable), */
565 0x75, 0x10, /* Report Size (16), */
566 0x95, 0x01, /* Report Count (1), */
567 0xA4, /* Push, */
568 0x05, 0x01, /* Usage Page (Desktop), */
569 0x65, 0x13, /* Unit (Inch), */
570 0x55, 0xFD, /* Unit Exponent (-3), */
571 0x34, /* Physical Minimum (0), */
572 0x09, 0x30, /* Usage (X), */
573 0x27, UCLOGIC_PH(X_LM), /* Logical Maximum (PLACEHOLDER), */
574 0x47, UCLOGIC_PH(X_PM), /* Physical Maximum (PLACEHOLDER), */
575 0x81, 0x02, /* Input (Variable), */
576 0x09, 0x31, /* Usage (Y), */
577 0x27, UCLOGIC_PH(Y_LM), /* Logical Maximum (PLACEHOLDER), */
578 0x47, UCLOGIC_PH(Y_PM), /* Physical Maximum (PLACEHOLDER), */
579 0x81, 0x02, /* Input (Variable), */
580 0xB4, /* Pop, */
581 0x09, 0x30, /* Usage (Tip Pressure), */
582 0x27,
583 UCLOGIC_PH(PRESSURE_LM),/* Logical Maximum (PLACEHOLDER), */
584 0x81, 0x02, /* Input (Variable), */
585 0xC0, /* End Collection, */
586 0xC0 /* End Collection */
587};
588
Benjamin Tissoires21003962016-09-14 21:38:16 +0300589/* Fixed virtual pad report descriptor */
590static const __u8 uclogic_buttonpad_rdesc[] = {
591 0x05, 0x01, /* Usage Page (Desktop), */
592 0x09, 0x07, /* Usage (Keypad), */
593 0xA1, 0x01, /* Collection (Application), */
594 0x85, 0xF7, /* Report ID (247), */
595 0x05, 0x0D, /* Usage Page (Digitizers), */
596 0x09, 0x39, /* Usage (Tablet Function Keys), */
597 0xA0, /* Collection (Physical), */
598 0x05, 0x09, /* Usage Page (Button), */
599 0x75, 0x01, /* Report Size (1), */
600 0x95, 0x18, /* Report Count (24), */
601 0x81, 0x03, /* Input (Constant, Variable), */
602 0x19, 0x01, /* Usage Minimum (01h), */
603 0x29, 0x08, /* Usage Maximum (08h), */
604 0x95, 0x08, /* Report Count (8), */
605 0x81, 0x02, /* Input (Variable), */
606 0xC0, /* End Collection */
607 0xC0 /* End Collection */
608};
609
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500610/* Parameter indices */
611enum uclogic_prm {
612 UCLOGIC_PRM_X_LM = 1,
613 UCLOGIC_PRM_Y_LM = 2,
614 UCLOGIC_PRM_PRESSURE_LM = 4,
615 UCLOGIC_PRM_RESOLUTION = 5,
616 UCLOGIC_PRM_NUM
617};
618
619/* Driver data */
620struct uclogic_drvdata {
621 __u8 *rdesc;
622 unsigned int rsize;
Benjamin Tissoiresfce8c5f2015-03-03 12:44:05 -0500623 bool invert_pen_inrange;
Benjamin Tissoiresee20fe22015-03-15 14:26:27 -0400624 bool ignore_pen_usage;
Benjamin Tissoires21003962016-09-14 21:38:16 +0300625 bool has_virtual_pad_interface;
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500626};
627
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400628static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
Nikolai Kondrashovbd9033e2010-08-23 15:09:00 +0400629 unsigned int *rsize)
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400630{
Nikolai Kondrashovd1257082012-05-14 20:30:38 +0300631 struct usb_interface *iface = to_usb_interface(hdev->dev.parent);
632 __u8 iface_num = iface->cur_altsetting->desc.bInterfaceNumber;
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500633 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
Nikolai Kondrashovd1257082012-05-14 20:30:38 +0300634
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400635 switch (hdev->product) {
Nikolai Kondrashov41fa9232010-08-23 15:09:01 +0400636 case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209:
637 if (*rsize == PF1209_RDESC_ORIG_SIZE) {
638 rdesc = pf1209_rdesc_fixed;
639 *rsize = sizeof(pf1209_rdesc_fixed);
640 }
641 break;
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400642 case USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U:
Nikolai Kondrashovbd9033e2010-08-23 15:09:00 +0400643 if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400644 rdesc = wp4030u_rdesc_fixed;
645 *rsize = sizeof(wp4030u_rdesc_fixed);
646 }
647 break;
648 case USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U:
Nikolai Kondrashovbd9033e2010-08-23 15:09:00 +0400649 if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400650 rdesc = wp5540u_rdesc_fixed;
651 *rsize = sizeof(wp5540u_rdesc_fixed);
652 }
653 break;
654 case USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U:
Nikolai Kondrashovbd9033e2010-08-23 15:09:00 +0400655 if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400656 rdesc = wp8060u_rdesc_fixed;
657 *rsize = sizeof(wp8060u_rdesc_fixed);
658 }
659 break;
Nikolai Kondrashov6be914f2011-07-06 09:23:41 +0300660 case USB_DEVICE_ID_UCLOGIC_TABLET_WP1062:
661 if (*rsize == WP1062_RDESC_ORIG_SIZE) {
662 rdesc = wp1062_rdesc_fixed;
663 *rsize = sizeof(wp1062_rdesc_fixed);
664 }
665 break;
Nikolai Kondrashovd1257082012-05-14 20:30:38 +0300666 case USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850:
667 switch (iface_num) {
668 case 0:
669 if (*rsize == TWHL850_RDESC_ORIG_SIZE0) {
670 rdesc = twhl850_rdesc_fixed0;
671 *rsize = sizeof(twhl850_rdesc_fixed0);
672 }
673 break;
674 case 1:
675 if (*rsize == TWHL850_RDESC_ORIG_SIZE1) {
676 rdesc = twhl850_rdesc_fixed1;
677 *rsize = sizeof(twhl850_rdesc_fixed1);
678 }
679 break;
680 case 2:
681 if (*rsize == TWHL850_RDESC_ORIG_SIZE2) {
682 rdesc = twhl850_rdesc_fixed2;
683 *rsize = sizeof(twhl850_rdesc_fixed2);
684 }
685 break;
686 }
687 break;
Nikolai Kondrashoveb4e4262012-08-26 20:55:08 +0300688 case USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60:
689 switch (iface_num) {
690 case 0:
691 if (*rsize == TWHA60_RDESC_ORIG_SIZE0) {
692 rdesc = twha60_rdesc_fixed0;
693 *rsize = sizeof(twha60_rdesc_fixed0);
694 }
695 break;
696 case 1:
697 if (*rsize == TWHA60_RDESC_ORIG_SIZE1) {
698 rdesc = twha60_rdesc_fixed1;
699 *rsize = sizeof(twha60_rdesc_fixed1);
700 }
701 break;
702 }
703 break;
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500704 default:
705 if (drvdata->rdesc != NULL) {
706 rdesc = drvdata->rdesc;
707 *rsize = drvdata->rsize;
708 }
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +0400709 }
710
711 return rdesc;
712}
713
Benjamin Tissoiresaa2121a2015-03-03 12:44:04 -0500714static int uclogic_input_mapping(struct hid_device *hdev, struct hid_input *hi,
715 struct hid_field *field, struct hid_usage *usage,
716 unsigned long **bit, int *max)
717{
Benjamin Tissoiresee20fe22015-03-15 14:26:27 -0400718 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
Benjamin Tissoiresaa2121a2015-03-03 12:44:04 -0500719
Benjamin Tissoiresee20fe22015-03-15 14:26:27 -0400720 /* discard the unused pen interface */
721 if ((drvdata->ignore_pen_usage) &&
722 (field->application == HID_DG_PEN))
723 return -1;
Benjamin Tissoiresaa2121a2015-03-03 12:44:04 -0500724
725 /* let hid-core decide what to do */
726 return 0;
727}
728
Dmitry Torokhov91543012015-09-29 15:52:59 -0700729static int uclogic_input_configured(struct hid_device *hdev,
Benjamin Tissoirescce2dbd2015-03-03 12:44:02 -0500730 struct hid_input *hi)
731{
732 char *name;
733 const char *suffix = NULL;
734 struct hid_field *field;
735 size_t len;
736
737 /* no report associated (HID_QUIRK_MULTI_INPUT not set) */
738 if (!hi->report)
Dmitry Torokhov91543012015-09-29 15:52:59 -0700739 return 0;
Benjamin Tissoirescce2dbd2015-03-03 12:44:02 -0500740
741 field = hi->report->field[0];
742
743 switch (field->application) {
744 case HID_GD_KEYBOARD:
745 suffix = "Keyboard";
746 break;
747 case HID_GD_MOUSE:
748 suffix = "Mouse";
749 break;
750 case HID_GD_KEYPAD:
751 suffix = "Pad";
752 break;
753 case HID_DG_PEN:
754 suffix = "Pen";
755 break;
756 case HID_CP_CONSUMER_CONTROL:
757 suffix = "Consumer Control";
758 break;
759 case HID_GD_SYSTEM_CONTROL:
760 suffix = "System Control";
761 break;
762 }
763
764 if (suffix) {
765 len = strlen(hdev->name) + 2 + strlen(suffix);
766 name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL);
767 if (name) {
768 snprintf(name, len, "%s %s", hdev->name, suffix);
769 hi->input->name = name;
770 }
771 }
Dmitry Torokhov91543012015-09-29 15:52:59 -0700772
773 return 0;
Benjamin Tissoirescce2dbd2015-03-03 12:44:02 -0500774}
775
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500776/**
777 * Enable fully-functional tablet mode and determine device parameters.
778 *
779 * @hdev: HID device
780 */
781static int uclogic_tablet_enable(struct hid_device *hdev)
782{
783 int rc;
784 struct usb_device *usb_dev = hid_to_usb_dev(hdev);
785 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
786 __le16 *buf = NULL;
787 size_t len;
788 s32 params[UCLOGIC_PH_ID_NUM];
789 s32 resolution;
790 __u8 *p;
791 s32 v;
792
793 /*
794 * Read string descriptor containing tablet parameters. The specific
795 * string descriptor and data were discovered by sniffing the Windows
796 * driver traffic.
797 * NOTE: This enables fully-functional tablet mode.
798 */
799 len = UCLOGIC_PRM_NUM * sizeof(*buf);
800 buf = kmalloc(len, GFP_KERNEL);
801 if (buf == NULL) {
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500802 rc = -ENOMEM;
803 goto cleanup;
804 }
805 rc = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
806 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
807 (USB_DT_STRING << 8) + 0x64,
808 0x0409, buf, len,
809 USB_CTRL_GET_TIMEOUT);
810 if (rc == -EPIPE) {
811 hid_err(hdev, "device parameters not found\n");
812 rc = -ENODEV;
813 goto cleanup;
814 } else if (rc < 0) {
815 hid_err(hdev, "failed to get device parameters: %d\n", rc);
816 rc = -ENODEV;
817 goto cleanup;
818 } else if (rc != len) {
819 hid_err(hdev, "invalid device parameters\n");
820 rc = -ENODEV;
821 goto cleanup;
822 }
823
824 /* Extract device parameters */
825 params[UCLOGIC_PH_ID_X_LM] = le16_to_cpu(buf[UCLOGIC_PRM_X_LM]);
826 params[UCLOGIC_PH_ID_Y_LM] = le16_to_cpu(buf[UCLOGIC_PRM_Y_LM]);
827 params[UCLOGIC_PH_ID_PRESSURE_LM] =
828 le16_to_cpu(buf[UCLOGIC_PRM_PRESSURE_LM]);
829 resolution = le16_to_cpu(buf[UCLOGIC_PRM_RESOLUTION]);
830 if (resolution == 0) {
831 params[UCLOGIC_PH_ID_X_PM] = 0;
832 params[UCLOGIC_PH_ID_Y_PM] = 0;
833 } else {
834 params[UCLOGIC_PH_ID_X_PM] = params[UCLOGIC_PH_ID_X_LM] *
835 1000 / resolution;
836 params[UCLOGIC_PH_ID_Y_PM] = params[UCLOGIC_PH_ID_Y_LM] *
837 1000 / resolution;
838 }
839
840 /* Allocate fixed report descriptor */
841 drvdata->rdesc = devm_kzalloc(&hdev->dev,
842 sizeof(uclogic_tablet_rdesc_template),
843 GFP_KERNEL);
844 if (drvdata->rdesc == NULL) {
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500845 rc = -ENOMEM;
846 goto cleanup;
847 }
848 drvdata->rsize = sizeof(uclogic_tablet_rdesc_template);
849
850 /* Format fixed report descriptor */
851 memcpy(drvdata->rdesc, uclogic_tablet_rdesc_template,
852 drvdata->rsize);
853 for (p = drvdata->rdesc;
854 p <= drvdata->rdesc + drvdata->rsize - 4;) {
855 if (p[0] == 0xFE && p[1] == 0xED && p[2] == 0x1D &&
Dan Carpenter4a8e70f2015-07-29 13:16:06 +0300856 p[3] < ARRAY_SIZE(params)) {
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500857 v = params[p[3]];
858 put_unaligned(cpu_to_le32(v), (s32 *)p);
859 p += 4;
860 } else {
861 p++;
862 }
863 }
864
865 rc = 0;
866
867cleanup:
868 kfree(buf);
869 return rc;
870}
871
Benjamin Tissoires21003962016-09-14 21:38:16 +0300872/**
873 * Enable actual button mode.
874 *
875 * @hdev: HID device
876 */
877static int uclogic_button_enable(struct hid_device *hdev)
878{
879 int rc;
880 struct usb_device *usb_dev = hid_to_usb_dev(hdev);
881 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
882 char *str_buf;
883 size_t str_len = 16;
884 unsigned char *rdesc;
885 size_t rdesc_len;
886
887 str_buf = kzalloc(str_len, GFP_KERNEL);
888 if (str_buf == NULL) {
889 rc = -ENOMEM;
890 goto cleanup;
891 }
892
893 /* Enable abstract keyboard mode */
894 rc = usb_string(usb_dev, 0x7b, str_buf, str_len);
895 if (rc == -EPIPE) {
896 hid_info(hdev, "button mode setting not found\n");
897 rc = 0;
898 goto cleanup;
899 } else if (rc < 0) {
900 hid_err(hdev, "failed to enable abstract keyboard\n");
901 goto cleanup;
902 } else if (strncmp(str_buf, "HK On", rc)) {
903 hid_info(hdev, "invalid answer when requesting buttons: '%s'\n",
904 str_buf);
905 rc = -EINVAL;
906 goto cleanup;
907 }
908
909 /* Re-allocate fixed report descriptor */
910 rdesc_len = drvdata->rsize + sizeof(uclogic_buttonpad_rdesc);
911 rdesc = devm_kzalloc(&hdev->dev, rdesc_len, GFP_KERNEL);
912 if (!rdesc) {
913 rc = -ENOMEM;
914 goto cleanup;
915 }
916
917 memcpy(rdesc, drvdata->rdesc, drvdata->rsize);
918
919 /* Append the buttonpad descriptor */
920 memcpy(rdesc + drvdata->rsize, uclogic_buttonpad_rdesc,
921 sizeof(uclogic_buttonpad_rdesc));
922
923 /* clean up old rdesc and use the new one */
924 drvdata->rsize = rdesc_len;
925 devm_kfree(&hdev->dev, drvdata->rdesc);
926 drvdata->rdesc = rdesc;
927
928 rc = 0;
929
930cleanup:
931 kfree(str_buf);
932 return rc;
933}
934
Benjamin Tissoires70b69cf2015-03-03 12:44:00 -0500935static int uclogic_probe(struct hid_device *hdev,
936 const struct hid_device_id *id)
937{
938 int rc;
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500939 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
940 struct uclogic_drvdata *drvdata;
Benjamin Tissoires70b69cf2015-03-03 12:44:00 -0500941
942 /*
943 * libinput requires the pad interface to be on a different node
944 * than the pen, so use QUIRK_MULTI_INPUT for all tablets.
945 */
946 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
Benjamin Tissoires002a82d2015-03-03 12:44:03 -0500947 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
Benjamin Tissoires70b69cf2015-03-03 12:44:00 -0500948
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500949 /* Allocate and assign driver data */
950 drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
951 if (drvdata == NULL)
952 return -ENOMEM;
953
954 hid_set_drvdata(hdev, drvdata);
955
956 switch (id->product) {
957 case USB_DEVICE_ID_HUION_TABLET:
Nikolai Kondrashov4b7e7e52016-09-14 21:38:17 +0300958 case USB_DEVICE_ID_YIYNOVA_TABLET:
959 case USB_DEVICE_ID_UGEE_TABLET_81:
960 case USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3:
961 case USB_DEVICE_ID_UGEE_TABLET_45:
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500962 /* If this is the pen interface */
963 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
964 rc = uclogic_tablet_enable(hdev);
965 if (rc) {
966 hid_err(hdev, "tablet enabling failed\n");
967 return rc;
968 }
Benjamin Tissoiresfce8c5f2015-03-03 12:44:05 -0500969 drvdata->invert_pen_inrange = true;
Benjamin Tissoires21003962016-09-14 21:38:16 +0300970
971 rc = uclogic_button_enable(hdev);
972 drvdata->has_virtual_pad_interface = !rc;
Benjamin Tissoiresee20fe22015-03-15 14:26:27 -0400973 } else {
974 drvdata->ignore_pen_usage = true;
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500975 }
976 break;
977 }
978
Benjamin Tissoires70b69cf2015-03-03 12:44:00 -0500979 rc = hid_parse(hdev);
980 if (rc) {
981 hid_err(hdev, "parse failed\n");
982 return rc;
983 }
984
985 rc = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
986 if (rc) {
987 hid_err(hdev, "hw start failed\n");
988 return rc;
989 }
990
991 return 0;
992}
993
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500994static int uclogic_raw_event(struct hid_device *hdev, struct hid_report *report,
995 u8 *data, int size)
996{
Benjamin Tissoiresfce8c5f2015-03-03 12:44:05 -0500997 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
Nikolai Kondrashov08177f42015-03-03 12:44:01 -0500998
Benjamin Tissoires21003962016-09-14 21:38:16 +0300999 if ((report->type == HID_INPUT_REPORT) &&
Benjamin Tissoiresfce8c5f2015-03-03 12:44:05 -05001000 (report->id == UCLOGIC_PEN_REPORT_ID) &&
Benjamin Tissoires21003962016-09-14 21:38:16 +03001001 (size >= 2)) {
1002 if (drvdata->has_virtual_pad_interface && (data[1] & 0x20))
1003 /* Change to virtual frame button report ID */
1004 data[0] = 0xf7;
1005 else if (drvdata->invert_pen_inrange)
1006 /* Invert the in-range bit */
1007 data[1] ^= 0x40;
1008 }
Nikolai Kondrashov08177f42015-03-03 12:44:01 -05001009
1010 return 0;
1011}
1012
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001013static const struct hid_device_id uclogic_devices[] = {
1014 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
Nikolai Kondrashov41fa9232010-08-23 15:09:01 +04001015 USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1016 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001017 USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1018 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
1019 USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1020 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
1021 USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
Nikolai Kondrashov6be914f2011-07-06 09:23:41 +03001022 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
1023 USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
Nikolai Kondrashovd1257082012-05-14 20:30:38 +03001024 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
1025 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
Nikolai Kondrashoveb4e4262012-08-26 20:55:08 +03001026 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
1027 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
Nikolai Kondrashov08177f42015-03-03 12:44:01 -05001028 { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
1029 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_HUION_TABLET) },
Nikolai Kondrashov4b7e7e52016-09-14 21:38:17 +03001030 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_YIYNOVA_TABLET) },
1031 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UGEE_TABLET_81) },
1032 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UGEE_TABLET_45) },
1033 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3) },
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001034 { }
1035};
1036MODULE_DEVICE_TABLE(hid, uclogic_devices);
1037
1038static struct hid_driver uclogic_driver = {
1039 .name = "uclogic",
1040 .id_table = uclogic_devices,
Benjamin Tissoires70b69cf2015-03-03 12:44:00 -05001041 .probe = uclogic_probe,
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001042 .report_fixup = uclogic_report_fixup,
Nikolai Kondrashov08177f42015-03-03 12:44:01 -05001043 .raw_event = uclogic_raw_event,
Benjamin Tissoiresaa2121a2015-03-03 12:44:04 -05001044 .input_mapping = uclogic_input_mapping,
Benjamin Tissoirescce2dbd2015-03-03 12:44:02 -05001045 .input_configured = uclogic_input_configured,
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001046};
H Hartley Sweetenf4254582012-12-17 15:28:26 -07001047module_hid_driver(uclogic_driver);
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001048
Nikolai Kondrashov08177f42015-03-03 12:44:01 -05001049MODULE_AUTHOR("Martin Rusko");
1050MODULE_AUTHOR("Nikolai Kondrashov");
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001051MODULE_LICENSE("GPL");