blob: b9d49e4a392d78896aa36997af336efe3fda5d5a [file] [log] [blame]
Nikolai Kondrashov72a46342010-08-20 19:21:11 +04001/*
2 * HID driver for Waltop 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 * Original Slim Tablet 5.8 inch report descriptor.
22 *
23 * All the reports except the report with ID 16 (the stylus) are unused,
24 * possibly because the tablet is not configured to, or because they were
25 * just copied from a more capable model. The purpose of features described
26 * for report ID 2 is unknown.
27 *
28 * The stylus buttons are described as three bit fields, whereas actually
29 * it's an "array", i.e. they're reported as button numbers (1, 2 and 3).
30 * The "eraser" field is not used. There is also a "push" without a "pop" in
31 * the stylus description.
32 *
33 * Usage Page (Desktop), ; Generic desktop controls (01h)
34 * Usage (Mouse), ; Mouse (02h, application collection)
35 * Collection (Application),
36 * Report ID (1),
37 * Usage (Pointer), ; Pointer (01h, physical collection)
38 * Collection (Physical),
39 * Usage Page (Button), ; Button (09h)
40 * Usage Minimum (01h),
41 * Usage Maximum (05h),
42 * Logical Minimum (0),
43 * Logical Maximum (1),
44 * Report Size (1),
45 * Report Count (5),
46 * Input (Variable),
47 * Report Size (3),
48 * Report Count (1),
49 * Input (Constant, Variable),
50 * Usage Page (Desktop), ; Generic desktop controls (01h)
51 * Usage (X), ; X (30h, dynamic value)
52 * Usage (Y), ; Y (31h, dynamic value)
53 * Usage (Wheel), ; Wheel (38h, dynamic value)
54 * Logical Minimum (-127),
55 * Logical Maximum (127),
56 * Report Size (8),
57 * Report Count (3),
58 * Input (Variable, Relative),
59 * End Collection,
60 * End Collection,
61 * Usage Page (Digitizer), ; Digitizer (0Dh)
62 * Usage (Pen), ; Pen (02h, application collection)
63 * Collection (Application),
64 * Report ID (2),
65 * Usage (Stylus), ; Stylus (20h, logical collection)
66 * Collection (Physical),
67 * Usage (00h),
68 * Logical Minimum (0),
69 * Logical Maximum (255),
70 * Report Size (8),
71 * Report Count (7),
72 * Input (Variable),
73 * Usage (Azimuth), ; Azimuth (3Fh, dynamic value)
74 * Usage (Altitude), ; Altitude (40h, dynamic value)
75 * Logical Minimum (0),
76 * Logical Maximum (255),
77 * Report Size (8),
78 * Report Count (2),
79 * Feature (Variable),
80 * End Collection,
81 * Report ID (5),
82 * Usage Page (Digitizer), ; Digitizer (0Dh)
83 * Usage (Stylus), ; Stylus (20h, logical collection)
84 * Collection (Physical),
85 * Usage (00h),
86 * Logical Minimum (0),
87 * Logical Maximum (255),
88 * Report Size (8),
89 * Report Count (7),
90 * Input (Variable),
91 * End Collection,
92 * Report ID (10),
93 * Usage Page (Digitizer), ; Digitizer (0Dh)
94 * Usage (Stylus), ; Stylus (20h, logical collection)
95 * Collection (Physical),
96 * Usage (00h),
97 * Logical Minimum (0),
98 * Logical Maximum (255),
99 * Report Size (8),
100 * Report Count (3),
101 * Input (Variable),
102 * End Collection,
103 * Report ID (16),
104 * Usage (Stylus), ; Stylus (20h, logical collection)
105 * Collection (Physical),
106 * Usage (Tip Switch), ; Tip switch (42h, momentary control)
107 * Usage (Barrel Switch), ; Barrel switch (44h, momentary control)
108 * Usage (Invert), ; Invert (3Ch, momentary control)
109 * Usage (Eraser), ; Eraser (45h, momentary control)
110 * Usage (In Range), ; In range (32h, momentary control)
111 * Logical Minimum (0),
112 * Logical Maximum (1),
113 * Report Size (1),
114 * Report Count (5),
115 * Input (Variable),
116 * Report Count (3),
117 * Input (Constant, Variable),
118 * Usage Page (Desktop), ; Generic desktop controls (01h)
119 * Usage (X), ; X (30h, dynamic value)
120 * Report Size (16),
121 * Report Count (1),
122 * Push,
123 * Unit Exponent (13),
124 * Unit (Inch^3),
125 * Logical Minimum (0),
126 * Logical Maximum (10000),
127 * Physical Minimum (0),
128 * Physical Maximum (10000),
129 * Input (Variable),
130 * Usage (Y), ; Y (31h, dynamic value)
131 * Logical Maximum (6000),
132 * Physical Maximum (6000),
133 * Input (Variable),
134 * Usage Page (Digitizer), ; Digitizer (0Dh)
135 * Usage (Tip Pressure), ; Tip pressure (30h, dynamic value)
136 * Logical Minimum (0),
137 * Logical Maximum (1023),
138 * Physical Minimum (0),
139 * Physical Maximum (1023),
140 * Input (Variable),
141 * End Collection,
142 * End Collection
143 */
144
145/* Size of the original report descriptor of Slim Tablet 5.8 inch */
146#define SLIM_TABLET_5_8_INCH_RDESC_ORIG_SIZE 222
147
148/*
149 * Fixed Slim Tablet 5.8 inch descriptor.
150 *
151 * All the reports except the stylus report (ID 16) were removed as unused.
152 * The stylus buttons description was fixed.
153 */
154static __u8 slim_tablet_5_8_inch_rdesc_fixed[] = {
155 0x05, 0x0D, /* Usage Page (Digitizer), */
156 0x09, 0x02, /* Usage (Pen), */
157 0xA1, 0x01, /* Collection (Application), */
158 0x85, 0x10, /* Report ID (16), */
159 0x09, 0x20, /* Usage (Stylus), */
160 0xA0, /* Collection (Physical), */
161 0x09, 0x42, /* Usage (Tip Switch), */
162 0x09, 0x44, /* Usage (Barrel Switch), */
163 0x09, 0x46, /* Usage (Tablet Pick), */
164 0x15, 0x01, /* Logical Minimum (1), */
165 0x25, 0x03, /* Logical Maximum (3), */
166 0x75, 0x04, /* Report Size (4), */
167 0x95, 0x01, /* Report Count (1), */
168 0x80, /* Input, */
169 0x09, 0x32, /* Usage (In Range), */
170 0x14, /* Logical Minimum (0), */
171 0x25, 0x01, /* Logical Maximum (1), */
172 0x75, 0x01, /* Report Size (1), */
173 0x95, 0x01, /* Report Count (1), */
174 0x81, 0x02, /* Input (Variable), */
175 0x95, 0x03, /* Report Count (3), */
176 0x81, 0x03, /* Input (Constant, Variable), */
177 0x75, 0x10, /* Report Size (16), */
178 0x95, 0x01, /* Report Count (1), */
179 0x14, /* Logical Minimum (0), */
180 0xA4, /* Push, */
181 0x05, 0x01, /* Usage Page (Desktop), */
182 0x65, 0x13, /* Unit (Inch), */
183 0x55, 0xFD, /* Unit Exponent (-3), */
184 0x34, /* Physical Minimum (0), */
185 0x09, 0x30, /* Usage (X), */
186 0x46, 0x88, 0x13, /* Physical Maximum (5000), */
187 0x26, 0x10, 0x27, /* Logical Maximum (10000), */
188 0x81, 0x02, /* Input (Variable), */
189 0x09, 0x31, /* Usage (Y), */
190 0x46, 0xB8, 0x0B, /* Physical Maximum (3000), */
191 0x26, 0x70, 0x17, /* Logical Maximum (6000), */
192 0x81, 0x02, /* Input (Variable), */
193 0xB4, /* Pop, */
194 0x09, 0x30, /* Usage (Tip Pressure), */
195 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
196 0x81, 0x02, /* Input (Variable), */
197 0xC0, /* End Collection, */
198 0xC0 /* End Collection */
199};
200
201/*
202 * Original Media Tablet 10.6 inch report descriptor.
203 *
204 * There are at least two versions of this model in the wild. They are
205 * represented by Genius G-Pen M609 (older version) and Genius G-Pen M609X
206 * (newer version).
207 *
208 * Both versions have the usual pen with two barrel buttons and two
209 * identical wheels with center buttons in the top corners of the tablet
210 * base. They also have buttons on the top, between the wheels, for
211 * selecting the wheels' functions and wide/standard mode. In the wide mode
212 * the whole working surface is sensed, in the standard mode a narrower area
213 * is sensed, but the logical report extents remain the same. These modes
214 * correspond roughly to 16:9 and 4:3 aspect ratios respectively.
215 *
216 * The older version has three wheel function buttons ("scroll", "zoom" and
217 * "volume") and two separate buttons for wide and standard mode. The newer
218 * version has four wheel function buttons (plus "brush") and only one
219 * button is used for selecting wide/standard mode. So, the total number of
220 * buttons remains the same, but one of the mode buttons is repurposed as a
221 * wheels' function button in the newer version.
222 *
223 * The wheel functions are:
Nikolai Kondrashov4b5b45752010-08-30 14:06:35 +0400224 * scroll - the wheels act as scroll wheels, the center buttons switch
225 * between vertical and horizontal scrolling;
226 * zoom - the wheels zoom in/out, the buttons supposedly reset to 100%;
227 * volume - the wheels control the sound volume, the buttons mute;
Nikolai Kondrashov72a46342010-08-20 19:21:11 +0400228 * brush - the wheels are supposed to control brush width in a graphics
229 * editor, the buttons do nothing.
230 *
231 * Below is the newer version's report descriptor. It may very well be that
232 * the older version's descriptor is different and thus it won't be
233 * supported.
234 *
235 * The mouse report (ID 1) only uses the wheel field for reporting the tablet
236 * wheels' scroll mode. The keyboard report (ID 13) is used to report the
237 * wheels' zoom and brush control functions as key presses. The report ID 12
238 * is used to report the wheels' volume control functions. The stylus report
239 * (ID 16) has the same problems as the Slim Tablet 5.8 inch report has.
240 *
241 * The rest of the reports are unused, at least in the default configuration.
242 * The purpose of the features is unknown.
243 *
244 * Usage Page (Desktop),
245 * Usage (Mouse),
246 * Collection (Application),
247 * Report ID (1),
248 * Usage (Pointer),
249 * Collection (Physical),
250 * Usage Page (Button),
251 * Usage Minimum (01h),
252 * Usage Maximum (05h),
253 * Logical Minimum (0),
254 * Logical Maximum (1),
255 * Report Size (1),
256 * Report Count (5),
257 * Input (Variable),
258 * Report Size (3),
259 * Report Count (1),
260 * Input (Constant, Variable),
261 * Usage Page (Desktop),
262 * Usage (X),
263 * Usage (Y),
264 * Usage (Wheel),
265 * Logical Minimum (-127),
266 * Logical Maximum (127),
267 * Report Size (8),
268 * Report Count (3),
269 * Input (Variable, Relative),
270 * End Collection,
271 * End Collection,
272 * Usage Page (Digitizer),
273 * Usage (Pen),
274 * Collection (Application),
275 * Report ID (2),
276 * Usage (Stylus),
277 * Collection (Physical),
278 * Usage (00h),
279 * Logical Minimum (0),
280 * Logical Maximum (255),
281 * Report Size (8),
282 * Report Count (7),
283 * Input (Variable),
284 * Usage (Azimuth),
285 * Usage (Altitude),
286 * Logical Minimum (0),
287 * Logical Maximum (255),
288 * Report Size (8),
289 * Report Count (2),
290 * Feature (Variable),
291 * End Collection,
292 * Report ID (5),
293 * Usage Page (Digitizer),
294 * Usage (Stylus),
295 * Collection (Physical),
296 * Usage (00h),
297 * Logical Minimum (0),
298 * Logical Maximum (255),
299 * Report Size (8),
300 * Report Count (7),
301 * Input (Variable),
302 * End Collection,
303 * Report ID (10),
304 * Usage Page (Digitizer),
305 * Usage (Stylus),
306 * Collection (Physical),
307 * Usage (00h),
308 * Logical Minimum (0),
309 * Logical Maximum (255),
310 * Report Size (8),
311 * Report Count (7),
312 * Input (Variable),
313 * End Collection,
314 * Report ID (16),
315 * Usage (Stylus),
316 * Collection (Physical),
317 * Usage (Tip Switch),
318 * Usage (Barrel Switch),
319 * Usage (Invert),
320 * Usage (Eraser),
321 * Usage (In Range),
322 * Logical Minimum (0),
323 * Logical Maximum (1),
324 * Report Size (1),
325 * Report Count (5),
326 * Input (Variable),
327 * Report Count (3),
328 * Input (Constant, Variable),
329 * Usage Page (Desktop),
330 * Usage (X),
331 * Report Size (16),
332 * Report Count (1),
333 * Push,
334 * Unit Exponent (13),
335 * Unit (Inch^3),
336 * Logical Minimum (0),
337 * Logical Maximum (18000),
338 * Physical Minimum (0),
339 * Physical Maximum (18000),
340 * Input (Variable),
341 * Usage (Y),
342 * Logical Maximum (11000),
343 * Physical Maximum (11000),
344 * Input (Variable),
345 * Usage Page (Digitizer),
346 * Usage (Tip Pressure),
347 * Logical Minimum (0),
348 * Logical Maximum (1023),
349 * Physical Minimum (0),
350 * Physical Maximum (1023),
351 * Input (Variable),
352 * End Collection,
353 * End Collection,
354 * Usage Page (Desktop),
355 * Usage (Keyboard),
356 * Collection (Application),
357 * Report ID (13),
358 * Usage Page (Keyboard),
359 * Usage Minimum (KB Leftcontrol),
360 * Usage Maximum (KB Right GUI),
361 * Logical Minimum (0),
362 * Logical Maximum (1),
363 * Report Size (1),
364 * Report Count (8),
365 * Input (Variable),
366 * Report Size (8),
367 * Report Count (1),
368 * Input (Constant),
369 * Usage Page (Keyboard),
370 * Usage Minimum (None),
371 * Usage Maximum (KB Application),
372 * Logical Minimum (0),
373 * Logical Maximum (101),
374 * Report Size (8),
375 * Report Count (5),
376 * Input,
377 * End Collection,
378 * Usage Page (Consumer),
379 * Usage (Consumer Control),
380 * Collection (Application),
381 * Report ID (12),
382 * Usage (Volume Inc),
383 * Usage (Volume Dec),
384 * Usage (Mute),
385 * Logical Minimum (0),
386 * Logical Maximum (1),
387 * Report Size (1),
388 * Report Count (3),
389 * Input (Variable, Relative),
390 * Report Size (5),
391 * Report Count (1),
392 * Input (Constant, Variable, Relative),
393 * End Collection
394 */
395
396/* Size of the original report descriptor of Media Tablet 10.6 inch */
397#define MEDIA_TABLET_10_6_INCH_RDESC_ORIG_SIZE 300
398
399/*
400 * Fixed Media Tablet 10.6 inch descriptor.
401 *
402 * The descriptions of reports unused in the default configuration are
403 * removed. The stylus report (ID 16) is fixed similarly to Slim Tablet 5.8
404 * inch. The unused mouse report (ID 1) fields are replaced with constant
405 * padding.
406 *
407 * The keyboard report (ID 13) is hacked to instead have an "array" field
408 * reporting consumer page controls, and all the unused bits are masked out
409 * with constant padding. The "brush" wheels' function is represented as "Scan
410 * Previous/Next Track" controls due to the lack of brush controls in the
411 * usage tables specification.
412 */
413static __u8 media_tablet_10_6_inch_rdesc_fixed[] = {
414 0x05, 0x0D, /* Usage Page (Digitizer), */
415 0x09, 0x02, /* Usage (Pen), */
416 0xA1, 0x01, /* Collection (Application), */
417 0x85, 0x10, /* Report ID (16), */
418 0x09, 0x20, /* Usage (Stylus), */
419 0xA0, /* Collection (Physical), */
420 0x09, 0x42, /* Usage (Tip Switch), */
421 0x09, 0x44, /* Usage (Barrel Switch), */
422 0x09, 0x46, /* Usage (Tablet Pick), */
423 0x15, 0x01, /* Logical Minimum (1), */
424 0x25, 0x03, /* Logical Maximum (3), */
425 0x75, 0x04, /* Report Size (4), */
426 0x95, 0x01, /* Report Count (1), */
427 0x80, /* Input, */
428 0x75, 0x01, /* Report Size (1), */
429 0x09, 0x32, /* Usage (In Range), */
430 0x14, /* Logical Minimum (0), */
431 0x25, 0x01, /* Logical Maximum (1), */
432 0x95, 0x01, /* Report Count (1), */
433 0x81, 0x02, /* Input (Variable), */
434 0x95, 0x03, /* Report Count (3), */
435 0x81, 0x03, /* Input (Constant, Variable), */
436 0x75, 0x10, /* Report Size (16), */
437 0x95, 0x01, /* Report Count (1), */
438 0x14, /* Logical Minimum (0), */
439 0xA4, /* Push, */
440 0x05, 0x01, /* Usage Page (Desktop), */
441 0x65, 0x13, /* Unit (Inch), */
442 0x55, 0xFD, /* Unit Exponent (-3), */
443 0x34, /* Physical Minimum (0), */
444 0x09, 0x30, /* Usage (X), */
445 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
446 0x26, 0x50, 0x46, /* Logical Maximum (18000), */
447 0x81, 0x02, /* Input (Variable), */
448 0x09, 0x31, /* Usage (Y), */
449 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
450 0x26, 0xF8, 0x2A, /* Logical Maximum (11000), */
451 0x81, 0x02, /* Input (Variable), */
452 0xB4, /* Pop, */
453 0x09, 0x30, /* Usage (Tip Pressure), */
454 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
455 0x81, 0x02, /* Input (Variable), */
456 0xC0, /* End Collection, */
457 0xC0, /* End Collection, */
458 0x05, 0x01, /* Usage Page (Desktop), */
459 0x09, 0x02, /* Usage (Mouse), */
460 0xA1, 0x01, /* Collection (Application), */
461 0x85, 0x01, /* Report ID (1), */
462 0x09, 0x01, /* Usage (Pointer), */
463 0xA0, /* Collection (Physical), */
Nikolai Kondrashov4b5b45752010-08-30 14:06:35 +0400464 0x75, 0x08, /* Report Size (8), */
465 0x95, 0x03, /* Report Count (3), */
Nikolai Kondrashov72a46342010-08-20 19:21:11 +0400466 0x81, 0x03, /* Input (Constant, Variable), */
Nikolai Kondrashov4b5b45752010-08-30 14:06:35 +0400467 0x95, 0x02, /* Report Count (2), */
Nikolai Kondrashov72a46342010-08-20 19:21:11 +0400468 0x15, 0xFF, /* Logical Minimum (-1), */
469 0x25, 0x01, /* Logical Maximum (1), */
Nikolai Kondrashov4b5b45752010-08-30 14:06:35 +0400470 0x09, 0x38, /* Usage (Wheel), */
471 0x0B, 0x38, 0x02, /* Usage (Consumer AC Pan), */
472 0x0C, 0x00,
Nikolai Kondrashov72a46342010-08-20 19:21:11 +0400473 0x81, 0x06, /* Input (Variable, Relative), */
Nikolai Kondrashov4b5b45752010-08-30 14:06:35 +0400474 0x95, 0x02, /* Report Count (2), */
Nikolai Kondrashov72a46342010-08-20 19:21:11 +0400475 0x81, 0x03, /* Input (Constant, Variable), */
476 0xC0, /* End Collection, */
477 0xC0, /* End Collection, */
478 0x05, 0x0C, /* Usage Page (Consumer), */
479 0x09, 0x01, /* Usage (Consumer Control), */
480 0xA1, 0x01, /* Collection (Application), */
481 0x85, 0x0D, /* Report ID (13), */
482 0x95, 0x01, /* Report Count (1), */
483 0x75, 0x10, /* Report Size (16), */
484 0x81, 0x03, /* Input (Constant, Variable), */
485 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
486 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
487 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
488 0x09, 0xB6, /* Usage (Scan Previous Track), */
489 0x09, 0xB5, /* Usage (Scan Next Track), */
490 0x15, 0x2C, /* Logical Minimum (44), */
491 0x25, 0x30, /* Logical Maximum (48), */
492 0x75, 0x08, /* Report Size (8), */
493 0x80, /* Input, */
494 0x75, 0x20, /* Report Size (32), */
495 0x81, 0x03, /* Input (Constant, Variable), */
496 0xC0, /* End Collection, */
497 0x09, 0x01, /* Usage (Consumer Control), */
498 0xA1, 0x01, /* Collection (Application), */
499 0x85, 0x0C, /* Report ID (12), */
500 0x75, 0x01, /* Report Size (1), */
501 0x09, 0xE9, /* Usage (Volume Inc), */
502 0x09, 0xEA, /* Usage (Volume Dec), */
503 0x09, 0xE2, /* Usage (Mute), */
504 0x14, /* Logical Minimum (0), */
505 0x25, 0x01, /* Logical Maximum (1), */
506 0x95, 0x03, /* Report Count (3), */
507 0x81, 0x06, /* Input (Variable, Relative), */
508 0x95, 0x35, /* Report Count (53), */
509 0x81, 0x03, /* Input (Constant, Variable), */
510 0xC0 /* End Collection */
511};
512
513static __u8 *waltop_report_fixup(struct hid_device *hdev, __u8 *rdesc,
514 unsigned int *rsize)
515{
516 switch (hdev->product) {
517 case USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH:
518 if (*rsize == SLIM_TABLET_5_8_INCH_RDESC_ORIG_SIZE) {
519 rdesc = slim_tablet_5_8_inch_rdesc_fixed;
520 *rsize = sizeof(slim_tablet_5_8_inch_rdesc_fixed);
521 }
522 break;
523 case USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH:
524 if (*rsize == MEDIA_TABLET_10_6_INCH_RDESC_ORIG_SIZE) {
525 rdesc = media_tablet_10_6_inch_rdesc_fixed;
526 *rsize = sizeof(media_tablet_10_6_inch_rdesc_fixed);
527 }
528 break;
529 }
530 return rdesc;
531}
532
533static const struct hid_device_id waltop_devices[] = {
534 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
535 USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
536 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP,
537 USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
538 { }
539};
540MODULE_DEVICE_TABLE(hid, waltop_devices);
541
542static struct hid_driver waltop_driver = {
543 .name = "waltop",
544 .id_table = waltop_devices,
545 .report_fixup = waltop_report_fixup,
546};
547
548static int __init waltop_init(void)
549{
550 return hid_register_driver(&waltop_driver);
551}
552
553static void __exit waltop_exit(void)
554{
555 hid_unregister_driver(&waltop_driver);
556}
557
558module_init(waltop_init);
559module_exit(waltop_exit);
560MODULE_LICENSE("GPL");