1 /*
2  *  HID driver for UC-Logic devices not fully compliant with HID standard
3  *
4  *  Copyright (c) 2010 Nikolai Kondrashov
5  */
6 
7 /*
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the Free
10  * Software Foundation; either version 2 of the License, or (at your option)
11  * any later version.
12  */
13 
14 #include <linux/device.h>
15 #include <linux/hid.h>
16 #include <linux/module.h>
17 
18 #include "hid-ids.h"
19 
20 /*
21  * The original descriptors of WPXXXXU tablets have three report IDs, of
22  * which only two are used (8 and 9), and the remaining (7) seems to have
23  * the originally intended pen description which was abandoned for some
24  * reason.  From this unused description it is possible to extract the
25  * actual physical extents and resolution. All the models use the same
26  * descriptor with different extents for the unused report ID.
27  *
28  * Here it is:
29  *
30  *  Usage Page (Digitizer),         ; Digitizer (0Dh)
31  *  Usage (Pen),                    ; Pen (02h, application collection)
32  *  Collection (Application),
33  *    Report ID (7),
34  *    Usage (Stylus),               ; Stylus (20h, logical collection)
35  *    Collection (Physical),
36  *      Usage (Tip Switch),         ; Tip switch (42h, momentary control)
37  *      Usage (Barrel Switch),      ; Barrel switch (44h, momentary control)
38  *      Usage (Eraser),             ; Eraser (45h, momentary control)
39  *      Logical Minimum (0),
40  *      Logical Maximum (1),
41  *      Report Size (1),
42  *      Report Count (3),
43  *      Input (Variable),
44  *      Report Count (3),
45  *      Input (Constant, Variable),
46  *      Usage (In Range),           ; In range (32h, momentary control)
47  *      Report Count (1),
48  *      Input (Variable),
49  *      Report Count (1),
50  *      Input (Constant, Variable),
51  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
52  *      Usage (X),                  ; X (30h, dynamic value)
53  *      Report Size (16),
54  *      Report Count (1),
55  *      Push,
56  *      Unit Exponent (13),
57  *      Unit (Inch^3),
58  *      Physical Minimum (0),
59  *      Physical Maximum (Xpm),
60  *      Logical Maximum (Xlm),
61  *      Input (Variable),
62  *      Usage (Y),                  ; Y (31h, dynamic value)
63  *      Physical Maximum (Ypm),
64  *      Logical Maximum (Ylm),
65  *      Input (Variable),
66  *      Pop,
67  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
68  *      Usage (Tip Pressure),       ; Tip pressure (30h, dynamic value)
69  *      Logical Maximum (1023),
70  *      Input (Variable),
71  *      Report Size (16),
72  *    End Collection,
73  *  End Collection,
74  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
75  *  Usage (Mouse),                  ; Mouse (02h, application collection)
76  *  Collection (Application),
77  *    Report ID (8),
78  *    Usage (Pointer),              ; Pointer (01h, physical collection)
79  *    Collection (Physical),
80  *      Usage Page (Button),        ; Button (09h)
81  *      Usage Minimum (01h),
82  *      Usage Maximum (03h),
83  *      Logical Minimum (0),
84  *      Logical Maximum (1),
85  *      Report Count (3),
86  *      Report Size (1),
87  *      Input (Variable),
88  *      Report Count (5),
89  *      Input (Constant),
90  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
91  *      Usage (X),                  ; X (30h, dynamic value)
92  *      Usage (Y),                  ; Y (31h, dynamic value)
93  *      Usage (Wheel),              ; Wheel (38h, dynamic value)
94  *      Usage (00h),
95  *      Logical Minimum (-127),
96  *      Logical Maximum (127),
97  *      Report Size (8),
98  *      Report Count (4),
99  *      Input (Variable, Relative),
100  *    End Collection,
101  *  End Collection,
102  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
103  *  Usage (Mouse),                  ; Mouse (02h, application collection)
104  *  Collection (Application),
105  *    Report ID (9),
106  *    Usage (Pointer),              ; Pointer (01h, physical collection)
107  *    Collection (Physical),
108  *      Usage Page (Button),        ; Button (09h)
109  *      Usage Minimum (01h),
110  *      Usage Maximum (03h),
111  *      Logical Minimum (0),
112  *      Logical Maximum (1),
113  *      Report Count (3),
114  *      Report Size (1),
115  *      Input (Variable),
116  *      Report Count (5),
117  *      Input (Constant),
118  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
119  *      Usage (X),                  ; X (30h, dynamic value)
120  *      Usage (Y),                  ; Y (31h, dynamic value)
121  *      Logical Minimum (0),
122  *      Logical Maximum (32767),
123  *      Physical Minimum (0),
124  *      Physical Maximum (32767),
125  *      Report Count (2),
126  *      Report Size (16),
127  *      Input (Variable),
128  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
129  *      Usage (Tip Pressure),       ; Tip pressure (30h, dynamic value)
130  *      Logical Maximum (1023),
131  *      Report Count (1),
132  *      Report Size (16),
133  *      Input (Variable),
134  *    End Collection,
135  *  End Collection
136  *
137  * Here are the extents values for the WPXXXXU models:
138  *
139  *              Xpm     Xlm     Ypm     Ylm
140  *  WP4030U     4000    8000    3000    6000
141  *  WP5540U     5500    11000   4000    8000
142  *  WP8060U     8000    16000   6000    12000
143  *
144  * This suggests that all of them have 2000 LPI resolution, as advertised.
145  */
146 
147 /* Size of the original descriptor of WPXXXXU tablets */
148 #define WPXXXXU_RDESC_ORIG_SIZE	212
149 
150 /*
151  * Fixed WP4030U report descriptor.
152  * Although the hardware might actually support it, the mouse description
153  * has been removed, since there seems to be no devices having one and it
154  * wouldn't make much sense because of the working area size.
155  */
156 static __u8 wp4030u_rdesc_fixed[] = {
157 	0x05, 0x0D,         /*  Usage Page (Digitizer),             */
158 	0x09, 0x02,         /*  Usage (Pen),                        */
159 	0xA1, 0x01,         /*  Collection (Application),           */
160 	0x85, 0x09,         /*      Report ID (9),                  */
161 	0x09, 0x20,         /*      Usage (Stylus),                 */
162 	0xA0,               /*      Collection (Physical),          */
163 	0x75, 0x01,         /*          Report Size (1),            */
164 	0x09, 0x42,         /*          Usage (Tip Switch),         */
165 	0x09, 0x44,         /*          Usage (Barrel Switch),      */
166 	0x09, 0x46,         /*          Usage (Tablet Pick),        */
167 	0x14,               /*          Logical Minimum (0),        */
168 	0x25, 0x01,         /*          Logical Maximum (1),        */
169 	0x95, 0x03,         /*          Report Count (3),           */
170 	0x81, 0x02,         /*          Input (Variable),           */
171 	0x95, 0x05,         /*          Report Count (5),           */
172 	0x81, 0x01,         /*          Input (Constant),           */
173 	0x75, 0x10,         /*          Report Size (16),           */
174 	0x95, 0x01,         /*          Report Count (1),           */
175 	0x14,               /*          Logical Minimum (0),        */
176 	0xA4,               /*          Push,                       */
177 	0x05, 0x01,         /*          Usage Page (Desktop),       */
178 	0x55, 0xFD,         /*          Unit Exponent (-3),         */
179 	0x65, 0x13,         /*          Unit (Inch),                */
180 	0x34,               /*          Physical Minimum (0),       */
181 	0x09, 0x30,         /*          Usage (X),                  */
182 	0x46, 0xA0, 0x0F,   /*          Physical Maximum (4000),    */
183 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
184 	0x81, 0x02,         /*          Input (Variable),           */
185 	0x09, 0x31,         /*          Usage (Y),                  */
186 	0x46, 0xB8, 0x0B,   /*          Physical Maximum (3000),    */
187 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
188 	0x81, 0x02,         /*          Input (Variable),           */
189 	0xB4,               /*          Pop,                        */
190 	0x09, 0x30,         /*          Usage (Tip Pressure),       */
191 	0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
192 	0x81, 0x02,         /*          Input (Variable),           */
193 	0xC0,               /*      End Collection,                 */
194 	0xC0                /*  End Collection                      */
195 };
196 
197 /* Fixed WP5540U report descriptor */
198 static __u8 wp5540u_rdesc_fixed[] = {
199 	0x05, 0x0D,         /*  Usage Page (Digitizer),             */
200 	0x09, 0x02,         /*  Usage (Pen),                        */
201 	0xA1, 0x01,         /*  Collection (Application),           */
202 	0x85, 0x09,         /*      Report ID (9),                  */
203 	0x09, 0x20,         /*      Usage (Stylus),                 */
204 	0xA0,               /*      Collection (Physical),          */
205 	0x75, 0x01,         /*          Report Size (1),            */
206 	0x09, 0x42,         /*          Usage (Tip Switch),         */
207 	0x09, 0x44,         /*          Usage (Barrel Switch),      */
208 	0x09, 0x46,         /*          Usage (Tablet Pick),        */
209 	0x14,               /*          Logical Minimum (0),        */
210 	0x25, 0x01,         /*          Logical Maximum (1),        */
211 	0x95, 0x03,         /*          Report Count (3),           */
212 	0x81, 0x02,         /*          Input (Variable),           */
213 	0x95, 0x05,         /*          Report Count (5),           */
214 	0x81, 0x01,         /*          Input (Constant),           */
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 	0x55, 0xFD,         /*          Unit Exponent (-3),         */
221 	0x65, 0x13,         /*          Unit (Inch),                */
222 	0x34,               /*          Physical Minimum (0),       */
223 	0x09, 0x30,         /*          Usage (X),                  */
224 	0x46, 0x7C, 0x15,   /*          Physical Maximum (5500),    */
225 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
226 	0x81, 0x02,         /*          Input (Variable),           */
227 	0x09, 0x31,         /*          Usage (Y),                  */
228 	0x46, 0xA0, 0x0F,   /*          Physical Maximum (4000),    */
229 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
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 	0x05, 0x01,         /*  Usage Page (Desktop),               */
238 	0x09, 0x02,         /*  Usage (Mouse),                      */
239 	0xA1, 0x01,         /*  Collection (Application),           */
240 	0x85, 0x08,         /*      Report ID (8),                  */
241 	0x09, 0x01,         /*      Usage (Pointer),                */
242 	0xA0,               /*      Collection (Physical),          */
243 	0x75, 0x01,         /*          Report Size (1),            */
244 	0x05, 0x09,         /*          Usage Page (Button),        */
245 	0x19, 0x01,         /*          Usage Minimum (01h),        */
246 	0x29, 0x03,         /*          Usage Maximum (03h),        */
247 	0x14,               /*          Logical Minimum (0),        */
248 	0x25, 0x01,         /*          Logical Maximum (1),        */
249 	0x95, 0x03,         /*          Report Count (3),           */
250 	0x81, 0x02,         /*          Input (Variable),           */
251 	0x95, 0x05,         /*          Report Count (5),           */
252 	0x81, 0x01,         /*          Input (Constant),           */
253 	0x05, 0x01,         /*          Usage Page (Desktop),       */
254 	0x75, 0x08,         /*          Report Size (8),            */
255 	0x09, 0x30,         /*          Usage (X),                  */
256 	0x09, 0x31,         /*          Usage (Y),                  */
257 	0x15, 0x81,         /*          Logical Minimum (-127),     */
258 	0x25, 0x7F,         /*          Logical Maximum (127),      */
259 	0x95, 0x02,         /*          Report Count (2),           */
260 	0x81, 0x06,         /*          Input (Variable, Relative), */
261 	0x09, 0x38,         /*          Usage (Wheel),              */
262 	0x15, 0xFF,         /*          Logical Minimum (-1),       */
263 	0x25, 0x01,         /*          Logical Maximum (1),        */
264 	0x95, 0x01,         /*          Report Count (1),           */
265 	0x81, 0x06,         /*          Input (Variable, Relative), */
266 	0x81, 0x01,         /*          Input (Constant),           */
267 	0xC0,               /*      End Collection,                 */
268 	0xC0                /*  End Collection                      */
269 };
270 
271 /* Fixed WP8060U report descriptor */
272 static __u8 wp8060u_rdesc_fixed[] = {
273 	0x05, 0x0D,         /*  Usage Page (Digitizer),             */
274 	0x09, 0x02,         /*  Usage (Pen),                        */
275 	0xA1, 0x01,         /*  Collection (Application),           */
276 	0x85, 0x09,         /*      Report ID (9),                  */
277 	0x09, 0x20,         /*      Usage (Stylus),                 */
278 	0xA0,               /*      Collection (Physical),          */
279 	0x75, 0x01,         /*          Report Size (1),            */
280 	0x09, 0x42,         /*          Usage (Tip Switch),         */
281 	0x09, 0x44,         /*          Usage (Barrel Switch),      */
282 	0x09, 0x46,         /*          Usage (Tablet Pick),        */
283 	0x14,               /*          Logical Minimum (0),        */
284 	0x25, 0x01,         /*          Logical Maximum (1),        */
285 	0x95, 0x03,         /*          Report Count (3),           */
286 	0x81, 0x02,         /*          Input (Variable),           */
287 	0x95, 0x05,         /*          Report Count (5),           */
288 	0x81, 0x01,         /*          Input (Constant),           */
289 	0x75, 0x10,         /*          Report Size (16),           */
290 	0x95, 0x01,         /*          Report Count (1),           */
291 	0x14,               /*          Logical Minimum (0),        */
292 	0xA4,               /*          Push,                       */
293 	0x05, 0x01,         /*          Usage Page (Desktop),       */
294 	0x55, 0xFD,         /*          Unit Exponent (-3),         */
295 	0x65, 0x13,         /*          Unit (Inch),                */
296 	0x34,               /*          Physical Minimum (0),       */
297 	0x09, 0x30,         /*          Usage (X),                  */
298 	0x46, 0x40, 0x1F,   /*          Physical Maximum (8000),    */
299 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
300 	0x81, 0x02,         /*          Input (Variable),           */
301 	0x09, 0x31,         /*          Usage (Y),                  */
302 	0x46, 0x70, 0x17,   /*          Physical Maximum (6000),    */
303 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
304 	0x81, 0x02,         /*          Input (Variable),           */
305 	0xB4,               /*          Pop,                        */
306 	0x09, 0x30,         /*          Usage (Tip Pressure),       */
307 	0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
308 	0x81, 0x02,         /*          Input (Variable),           */
309 	0xC0,               /*      End Collection,                 */
310 	0xC0,               /*  End Collection,                     */
311 	0x05, 0x01,         /*  Usage Page (Desktop),               */
312 	0x09, 0x02,         /*  Usage (Mouse),                      */
313 	0xA1, 0x01,         /*  Collection (Application),           */
314 	0x85, 0x08,         /*      Report ID (8),                  */
315 	0x09, 0x01,         /*      Usage (Pointer),                */
316 	0xA0,               /*      Collection (Physical),          */
317 	0x75, 0x01,         /*          Report Size (1),            */
318 	0x05, 0x09,         /*          Usage Page (Button),        */
319 	0x19, 0x01,         /*          Usage Minimum (01h),        */
320 	0x29, 0x03,         /*          Usage Maximum (03h),        */
321 	0x14,               /*          Logical Minimum (0),        */
322 	0x25, 0x01,         /*          Logical Maximum (1),        */
323 	0x95, 0x03,         /*          Report Count (3),           */
324 	0x81, 0x02,         /*          Input (Variable),           */
325 	0x95, 0x05,         /*          Report Count (5),           */
326 	0x81, 0x01,         /*          Input (Constant),           */
327 	0x05, 0x01,         /*          Usage Page (Desktop),       */
328 	0x75, 0x08,         /*          Report Size (8),            */
329 	0x09, 0x30,         /*          Usage (X),                  */
330 	0x09, 0x31,         /*          Usage (Y),                  */
331 	0x15, 0x81,         /*          Logical Minimum (-127),     */
332 	0x25, 0x7F,         /*          Logical Maximum (127),      */
333 	0x95, 0x02,         /*          Report Count (2),           */
334 	0x81, 0x06,         /*          Input (Variable, Relative), */
335 	0x09, 0x38,         /*          Usage (Wheel),              */
336 	0x15, 0xFF,         /*          Logical Minimum (-1),       */
337 	0x25, 0x01,         /*          Logical Maximum (1),        */
338 	0x95, 0x01,         /*          Report Count (1),           */
339 	0x81, 0x06,         /*          Input (Variable, Relative), */
340 	0x81, 0x01,         /*          Input (Constant),           */
341 	0xC0,               /*      End Collection,                 */
342 	0xC0                /*  End Collection                      */
343 };
344 
345 /*
346  * Original WP1062 report descriptor.
347  *
348  * Only report ID 9 is actually used.
349  *
350  *  Usage Page (Digitizer),         ; Digitizer (0Dh)
351  *  Usage (Pen),                    ; Pen (02h, application collection)
352  *  Collection (Application),
353  *    Report ID (7),
354  *    Usage (Stylus),               ; Stylus (20h, logical collection)
355  *    Collection (Physical),
356  *      Usage (Tip Switch),         ; Tip switch (42h, momentary control)
357  *      Usage (Barrel Switch),      ; Barrel switch (44h, momentary control)
358  *      Usage (Eraser),             ; Eraser (45h, momentary control)
359  *      Logical Minimum (0),
360  *      Logical Maximum (1),
361  *      Report Size (1),
362  *      Report Count (3),
363  *      Input (Variable),
364  *      Report Count (3),
365  *      Input (Constant, Variable),
366  *      Usage (In Range),           ; In range (32h, momentary control)
367  *      Report Count (1),
368  *      Input (Variable),
369  *      Report Count (1),
370  *      Input (Constant, Variable),
371  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
372  *      Usage (X),                  ; X (30h, dynamic value)
373  *      Report Size (16),
374  *      Report Count (1),
375  *      Push,
376  *      Unit Exponent (13),
377  *      Unit (Inch),
378  *      Physical Minimum (0),
379  *      Physical Maximum (10000),
380  *      Logical Maximum (20000),
381  *      Input (Variable),
382  *      Usage (Y),                  ; Y (31h, dynamic value)
383  *      Physical Maximum (6583),
384  *      Logical Maximum (13166),
385  *      Input (Variable),
386  *      Pop,
387  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
388  *      Usage (Tip Pressure),       ; Tip pressure (30h, dynamic value)
389  *      Logical Maximum (1023),
390  *      Input (Variable),
391  *      Report Size (16),
392  *    End Collection,
393  *  End Collection,
394  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
395  *  Usage (Mouse),                  ; Mouse (02h, application collection)
396  *  Collection (Application),
397  *    Report ID (8),
398  *    Usage (Pointer),              ; Pointer (01h, physical collection)
399  *    Collection (Physical),
400  *      Usage Page (Button),        ; Button (09h)
401  *      Usage Minimum (01h),
402  *      Usage Maximum (03h),
403  *      Logical Minimum (0),
404  *      Logical Maximum (1),
405  *      Report Count (3),
406  *      Report Size (1),
407  *      Input (Variable),
408  *      Report Count (5),
409  *      Input (Constant),
410  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
411  *      Usage (X),                  ; X (30h, dynamic value)
412  *      Usage (Y),                  ; Y (31h, dynamic value)
413  *      Usage (Wheel),              ; Wheel (38h, dynamic value)
414  *      Usage (00h),
415  *      Logical Minimum (-127),
416  *      Logical Maximum (127),
417  *      Report Size (8),
418  *      Report Count (4),
419  *      Input (Variable, Relative),
420  *    End Collection,
421  *  End Collection,
422  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
423  *  Usage (Mouse),                  ; Mouse (02h, application collection)
424  *  Collection (Application),
425  *    Report ID (9),
426  *    Usage (Pointer),              ; Pointer (01h, physical collection)
427  *    Collection (Physical),
428  *      Usage Page (Button),        ; Button (09h)
429  *      Usage Minimum (01h),
430  *      Usage Maximum (03h),
431  *      Logical Minimum (0),
432  *      Logical Maximum (1),
433  *      Report Count (3),
434  *      Report Size (1),
435  *      Input (Variable),
436  *      Report Count (4),
437  *      Input (Constant),
438  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
439  *      Usage (In Range),           ; In range (32h, momentary control)
440  *      Report Count (1),
441  *      Input (Variable),
442  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
443  *      Usage (X),                  ; X (30h, dynamic value)
444  *      Report Size (16),
445  *      Report Count (1),
446  *      Push,
447  *      Unit Exponent (13),
448  *      Unit (Inch),
449  *      Physical Minimum (0),
450  *      Physical Maximum (10000),
451  *      Logical Maximum (20000),
452  *      Input (Variable),
453  *      Usage (Y),                  ; Y (31h, dynamic value)
454  *      Physical Maximum (6583),
455  *      Logical Maximum (13166),
456  *      Input (Variable),
457  *      Pop,
458  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
459  *      Usage (Tip Pressure),       ; Tip pressure (30h, dynamic value)
460  *      Logical Maximum (1023),
461  *      Report Count (1),
462  *      Report Size (16),
463  *      Input (Variable),
464  *    End Collection,
465  *  End Collection,
466  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
467  *  Usage (00h),
468  *  Collection (Application),
469  *    Report ID (4),
470  *    Logical Minimum (0),
471  *    Logical Maximum (255),
472  *    Usage (00h),
473  *    Report Size (8),
474  *    Report Count (3),
475  *    Feature (Variable),
476  *  End Collection
477  */
478 
479 /* Size of the original descriptor of WP1062 tablet */
480 #define WP1062_RDESC_ORIG_SIZE	254
481 
482 /*
483  * Fixed WP1062 report descriptor.
484  *
485  * Removed unused reports, corrected second barrel button usage code, physical
486  * units.
487  */
488 static __u8 wp1062_rdesc_fixed[] = {
489 	0x05, 0x0D,         /*  Usage Page (Digitizer),             */
490 	0x09, 0x02,         /*  Usage (Pen),                        */
491 	0xA1, 0x01,         /*  Collection (Application),           */
492 	0x85, 0x09,         /*      Report ID (9),                  */
493 	0x09, 0x20,         /*      Usage (Stylus),                 */
494 	0xA0,               /*      Collection (Physical),          */
495 	0x75, 0x01,         /*          Report Size (1),            */
496 	0x09, 0x42,         /*          Usage (Tip Switch),         */
497 	0x09, 0x44,         /*          Usage (Barrel Switch),      */
498 	0x09, 0x46,         /*          Usage (Tablet Pick),        */
499 	0x14,               /*          Logical Minimum (0),        */
500 	0x25, 0x01,         /*          Logical Maximum (1),        */
501 	0x95, 0x03,         /*          Report Count (3),           */
502 	0x81, 0x02,         /*          Input (Variable),           */
503 	0x95, 0x04,         /*          Report Count (4),           */
504 	0x81, 0x01,         /*          Input (Constant),           */
505 	0x09, 0x32,         /*          Usage (In Range),           */
506 	0x95, 0x01,         /*          Report Count (1),           */
507 	0x81, 0x02,         /*          Input (Variable),           */
508 	0x75, 0x10,         /*          Report Size (16),           */
509 	0x95, 0x01,         /*          Report Count (1),           */
510 	0x14,               /*          Logical Minimum (0),        */
511 	0xA4,               /*          Push,                       */
512 	0x05, 0x01,         /*          Usage Page (Desktop),       */
513 	0x55, 0xFD,         /*          Unit Exponent (-3),         */
514 	0x65, 0x13,         /*          Unit (Inch),                */
515 	0x34,               /*          Physical Minimum (0),       */
516 	0x09, 0x30,         /*          Usage (X),                  */
517 	0x46, 0x10, 0x27,   /*          Physical Maximum (10000),   */
518 	0x26, 0x20, 0x4E,   /*          Logical Maximum (20000),    */
519 	0x81, 0x02,         /*          Input (Variable),           */
520 	0x09, 0x31,         /*          Usage (Y),                  */
521 	0x46, 0xB7, 0x19,   /*          Physical Maximum (6583),    */
522 	0x26, 0x6E, 0x33,   /*          Logical Maximum (13166),    */
523 	0x81, 0x02,         /*          Input (Variable),           */
524 	0xB4,               /*          Pop,                        */
525 	0x09, 0x30,         /*          Usage (Tip Pressure),       */
526 	0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
527 	0x81, 0x02,         /*          Input (Variable),           */
528 	0xC0,               /*      End Collection,                 */
529 	0xC0                /*  End Collection                      */
530 };
531 
532 /*
533  * Original PF1209 report descriptor.
534  *
535  * The descriptor is similar to WPXXXXU descriptors, with an addition of a
536  * feature report (ID 4) of unknown purpose.
537  *
538  * Although the advertised resolution is 4000 LPI the unused report ID
539  * (taken from WPXXXXU, it seems) states 2000 LPI, but it is probably
540  * incorrect and is a result of blind copying without understanding. Anyway
541  * the real logical extents are always scaled to 0..32767, which IMHO spoils
542  * the precision.
543  *
544  *  Usage Page (Digitizer),         ; Digitizer (0Dh)
545  *  Usage (Pen),                    ; Pen (02h, application collection)
546  *  Collection (Application),
547  *    Report ID (7),
548  *    Usage (Stylus),               ; Stylus (20h, logical collection)
549  *    Collection (Physical),
550  *      Usage (Tip Switch),         ; Tip switch (42h, momentary control)
551  *      Usage (Barrel Switch),      ; Barrel switch (44h, momentary control)
552  *      Usage (Eraser),             ; Eraser (45h, momentary control)
553  *      Logical Minimum (0),
554  *      Logical Maximum (1),
555  *      Report Size (1),
556  *      Report Count (3),
557  *      Input (Variable),
558  *      Report Count (3),
559  *      Input (Constant, Variable),
560  *      Usage (In Range),           ; In range (32h, momentary control)
561  *      Report Count (1),
562  *      Input (Variable),
563  *      Report Count (1),
564  *      Input (Constant, Variable),
565  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
566  *      Usage (X),                  ; X (30h, dynamic value)
567  *      Report Size (16),
568  *      Report Count (1),
569  *      Push,
570  *      Unit Exponent (13),
571  *      Unit (Inch^3),
572  *      Physical Minimum (0),
573  *      Physical Maximum (12000),
574  *      Logical Maximum (24000),
575  *      Input (Variable),
576  *      Usage (Y),                  ; Y (31h, dynamic value)
577  *      Physical Maximum (9000),
578  *      Logical Maximum (18000),
579  *      Input (Variable),
580  *      Pop,
581  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
582  *      Usage (Tip Pressure),       ; Tip pressure (30h, dynamic value)
583  *      Logical Maximum (1023),
584  *      Input (Variable),
585  *      Report Size (16),
586  *    End Collection,
587  *  End Collection,
588  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
589  *  Usage (Mouse),                  ; Mouse (02h, application collection)
590  *  Collection (Application),
591  *    Report ID (8),
592  *    Usage (Pointer),              ; Pointer (01h, physical collection)
593  *    Collection (Physical),
594  *      Usage Page (Button),        ; Button (09h)
595  *      Usage Minimum (01h),
596  *      Usage Maximum (03h),
597  *      Logical Minimum (0),
598  *      Logical Maximum (1),
599  *      Report Count (3),
600  *      Report Size (1),
601  *      Input (Variable),
602  *      Report Count (5),
603  *      Input (Constant),
604  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
605  *      Usage (X),                  ; X (30h, dynamic value)
606  *      Usage (Y),                  ; Y (31h, dynamic value)
607  *      Usage (Wheel),              ; Wheel (38h, dynamic value)
608  *      Usage (00h),
609  *      Logical Minimum (-127),
610  *      Logical Maximum (127),
611  *      Report Size (8),
612  *      Report Count (4),
613  *      Input (Variable, Relative),
614  *    End Collection,
615  *  End Collection,
616  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
617  *  Usage (Mouse),                  ; Mouse (02h, application collection)
618  *  Collection (Application),
619  *    Report ID (9),
620  *    Usage (Pointer),              ; Pointer (01h, physical collection)
621  *    Collection (Physical),
622  *      Usage Page (Button),        ; Button (09h)
623  *      Usage Minimum (01h),
624  *      Usage Maximum (03h),
625  *      Logical Minimum (0),
626  *      Logical Maximum (1),
627  *      Report Count (3),
628  *      Report Size (1),
629  *      Input (Variable),
630  *      Report Count (5),
631  *      Input (Constant),
632  *      Usage Page (Desktop),       ; Generic desktop controls (01h)
633  *      Usage (X),                  ; X (30h, dynamic value)
634  *      Usage (Y),                  ; Y (31h, dynamic value)
635  *      Logical Minimum (0),
636  *      Logical Maximum (32767),
637  *      Physical Minimum (0),
638  *      Physical Maximum (32767),
639  *      Report Count (2),
640  *      Report Size (16),
641  *      Input (Variable),
642  *      Usage Page (Digitizer),     ; Digitizer (0Dh)
643  *      Usage (Tip Pressure),       ; Tip pressure (30h, dynamic value)
644  *      Logical Maximum (1023),
645  *      Report Count (1),
646  *      Report Size (16),
647  *      Input (Variable),
648  *    End Collection,
649  *  End Collection,
650  *  Usage Page (Desktop),           ; Generic desktop controls (01h)
651  *  Usage (00h),
652  *  Collection (Application),
653  *    Report ID (4),
654  *    Logical Minimum (0),
655  *    Logical Maximum (255),
656  *    Usage (00h),
657  *    Report Size (8),
658  *    Report Count (3),
659  *    Feature (Variable),
660  *  End Collection
661  */
662 
663 /* Size of the original descriptor of PF1209 tablet */
664 #define PF1209_RDESC_ORIG_SIZE	234
665 
666 /*
667  * Fixed PF1209 report descriptor
668  *
669  * The descriptor is fixed similarly to WP5540U and WP8060U, plus the
670  * feature report is removed, because its purpose is unknown and it is of no
671  * use to the generic HID driver anyway for now.
672  */
673 static __u8 pf1209_rdesc_fixed[] = {
674 	0x05, 0x0D,         /*  Usage Page (Digitizer),             */
675 	0x09, 0x02,         /*  Usage (Pen),                        */
676 	0xA1, 0x01,         /*  Collection (Application),           */
677 	0x85, 0x09,         /*      Report ID (9),                  */
678 	0x09, 0x20,         /*      Usage (Stylus),                 */
679 	0xA0,               /*      Collection (Physical),          */
680 	0x75, 0x01,         /*          Report Size (1),            */
681 	0x09, 0x42,         /*          Usage (Tip Switch),         */
682 	0x09, 0x44,         /*          Usage (Barrel Switch),      */
683 	0x09, 0x46,         /*          Usage (Tablet Pick),        */
684 	0x14,               /*          Logical Minimum (0),        */
685 	0x25, 0x01,         /*          Logical Maximum (1),        */
686 	0x95, 0x03,         /*          Report Count (3),           */
687 	0x81, 0x02,         /*          Input (Variable),           */
688 	0x95, 0x05,         /*          Report Count (5),           */
689 	0x81, 0x01,         /*          Input (Constant),           */
690 	0x75, 0x10,         /*          Report Size (16),           */
691 	0x95, 0x01,         /*          Report Count (1),           */
692 	0x14,               /*          Logical Minimum (0),        */
693 	0xA4,               /*          Push,                       */
694 	0x05, 0x01,         /*          Usage Page (Desktop),       */
695 	0x55, 0xFD,         /*          Unit Exponent (-3),         */
696 	0x65, 0x13,         /*          Unit (Inch),                */
697 	0x34,               /*          Physical Minimum (0),       */
698 	0x09, 0x30,         /*          Usage (X),                  */
699 	0x46, 0xE0, 0x2E,   /*          Physical Maximum (12000),   */
700 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
701 	0x81, 0x02,         /*          Input (Variable),           */
702 	0x09, 0x31,         /*          Usage (Y),                  */
703 	0x46, 0x28, 0x23,   /*          Physical Maximum (9000),    */
704 	0x26, 0xFF, 0x7F,   /*          Logical Maximum (32767),    */
705 	0x81, 0x02,         /*          Input (Variable),           */
706 	0xB4,               /*          Pop,                        */
707 	0x09, 0x30,         /*          Usage (Tip Pressure),       */
708 	0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
709 	0x81, 0x02,         /*          Input (Variable),           */
710 	0xC0,               /*      End Collection,                 */
711 	0xC0,               /*  End Collection,                     */
712 	0x05, 0x01,         /*  Usage Page (Desktop),               */
713 	0x09, 0x02,         /*  Usage (Mouse),                      */
714 	0xA1, 0x01,         /*  Collection (Application),           */
715 	0x85, 0x08,         /*      Report ID (8),                  */
716 	0x09, 0x01,         /*      Usage (Pointer),                */
717 	0xA0,               /*      Collection (Physical),          */
718 	0x75, 0x01,         /*          Report Size (1),            */
719 	0x05, 0x09,         /*          Usage Page (Button),        */
720 	0x19, 0x01,         /*          Usage Minimum (01h),        */
721 	0x29, 0x03,         /*          Usage Maximum (03h),        */
722 	0x14,               /*          Logical Minimum (0),        */
723 	0x25, 0x01,         /*          Logical Maximum (1),        */
724 	0x95, 0x03,         /*          Report Count (3),           */
725 	0x81, 0x02,         /*          Input (Variable),           */
726 	0x95, 0x05,         /*          Report Count (5),           */
727 	0x81, 0x01,         /*          Input (Constant),           */
728 	0x05, 0x01,         /*          Usage Page (Desktop),       */
729 	0x75, 0x08,         /*          Report Size (8),            */
730 	0x09, 0x30,         /*          Usage (X),                  */
731 	0x09, 0x31,         /*          Usage (Y),                  */
732 	0x15, 0x81,         /*          Logical Minimum (-127),     */
733 	0x25, 0x7F,         /*          Logical Maximum (127),      */
734 	0x95, 0x02,         /*          Report Count (2),           */
735 	0x81, 0x06,         /*          Input (Variable, Relative), */
736 	0x09, 0x38,         /*          Usage (Wheel),              */
737 	0x15, 0xFF,         /*          Logical Minimum (-1),       */
738 	0x25, 0x01,         /*          Logical Maximum (1),        */
739 	0x95, 0x01,         /*          Report Count (1),           */
740 	0x81, 0x06,         /*          Input (Variable, Relative), */
741 	0x81, 0x01,         /*          Input (Constant),           */
742 	0xC0,               /*      End Collection,                 */
743 	0xC0                /*  End Collection                      */
744 };
745 
uclogic_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * rsize)746 static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
747 					unsigned int *rsize)
748 {
749 	switch (hdev->product) {
750 	case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209:
751 		if (*rsize == PF1209_RDESC_ORIG_SIZE) {
752 			rdesc = pf1209_rdesc_fixed;
753 			*rsize = sizeof(pf1209_rdesc_fixed);
754 		}
755 		break;
756 	case USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U:
757 		if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
758 			rdesc = wp4030u_rdesc_fixed;
759 			*rsize = sizeof(wp4030u_rdesc_fixed);
760 		}
761 		break;
762 	case USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U:
763 		if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
764 			rdesc = wp5540u_rdesc_fixed;
765 			*rsize = sizeof(wp5540u_rdesc_fixed);
766 		}
767 		break;
768 	case USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U:
769 		if (*rsize == WPXXXXU_RDESC_ORIG_SIZE) {
770 			rdesc = wp8060u_rdesc_fixed;
771 			*rsize = sizeof(wp8060u_rdesc_fixed);
772 		}
773 		break;
774 	case USB_DEVICE_ID_UCLOGIC_TABLET_WP1062:
775 		if (*rsize == WP1062_RDESC_ORIG_SIZE) {
776 			rdesc = wp1062_rdesc_fixed;
777 			*rsize = sizeof(wp1062_rdesc_fixed);
778 		}
779 		break;
780 	}
781 
782 	return rdesc;
783 }
784 
785 static const struct hid_device_id uclogic_devices[] = {
786 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
787 				USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
788 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
789 				USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
790 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
791 				USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
792 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
793 				USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
794 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
795 				USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
796 	{ }
797 };
798 MODULE_DEVICE_TABLE(hid, uclogic_devices);
799 
800 static struct hid_driver uclogic_driver = {
801 	.name = "uclogic",
802 	.id_table = uclogic_devices,
803 	.report_fixup = uclogic_report_fixup,
804 };
805 
uclogic_init(void)806 static int __init uclogic_init(void)
807 {
808 	return hid_register_driver(&uclogic_driver);
809 }
810 
uclogic_exit(void)811 static void __exit uclogic_exit(void)
812 {
813 	hid_unregister_driver(&uclogic_driver);
814 }
815 
816 module_init(uclogic_init);
817 module_exit(uclogic_exit);
818 MODULE_LICENSE("GPL");
819