Input: wacom - Bamboo One 1024 pressure fix
[firefly-linux-kernel-4.4.55.git] / drivers / input / tablet / wacom_wac.c
1 /*
2  * drivers/input/tablet/wacom_wac.c
3  *
4  *  USB Wacom tablet support - Wacom specific code
5  *
6  */
7
8 /*
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  */
14
15 #include "wacom_wac.h"
16 #include "wacom.h"
17 #include <linux/input/mt.h>
18 #include <linux/hid.h>
19
20 /* resolution for penabled devices */
21 #define WACOM_PL_RES            20
22 #define WACOM_PENPRTN_RES       40
23 #define WACOM_VOLITO_RES        50
24 #define WACOM_GRAPHIRE_RES      80
25 #define WACOM_INTUOS_RES        100
26 #define WACOM_INTUOS3_RES       200
27
28 static int wacom_penpartner_irq(struct wacom_wac *wacom)
29 {
30         unsigned char *data = wacom->data;
31         struct input_dev *input = wacom->input;
32
33         switch (data[0]) {
34         case 1:
35                 if (data[5] & 0x80) {
36                         wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
37                         wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
38                         input_report_key(input, wacom->tool[0], 1);
39                         input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
40                         input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
41                         input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
42                         input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
43                         input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
44                         input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
45                 } else {
46                         input_report_key(input, wacom->tool[0], 0);
47                         input_report_abs(input, ABS_MISC, 0); /* report tool id */
48                         input_report_abs(input, ABS_PRESSURE, -1);
49                         input_report_key(input, BTN_TOUCH, 0);
50                 }
51                 break;
52
53         case 2:
54                 input_report_key(input, BTN_TOOL_PEN, 1);
55                 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
56                 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
57                 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
58                 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
59                 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
60                 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
61                 break;
62
63         default:
64                 dev_dbg(input->dev.parent,
65                         "%s: received unknown report #%d\n", __func__, data[0]);
66                 return 0;
67         }
68
69         return 1;
70 }
71
72 static int wacom_pl_irq(struct wacom_wac *wacom)
73 {
74         struct wacom_features *features = &wacom->features;
75         unsigned char *data = wacom->data;
76         struct input_dev *input = wacom->input;
77         int prox, pressure;
78
79         if (data[0] != WACOM_REPORT_PENABLED) {
80                 dev_dbg(input->dev.parent,
81                         "%s: received unknown report #%d\n", __func__, data[0]);
82                 return 0;
83         }
84
85         prox = data[1] & 0x40;
86
87         if (prox) {
88                 wacom->id[0] = ERASER_DEVICE_ID;
89                 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
90                 if (features->pressure_max > 255)
91                         pressure = (pressure << 1) | ((data[4] >> 6) & 1);
92                 pressure += (features->pressure_max + 1) / 2;
93
94                 /*
95                  * if going from out of proximity into proximity select between the eraser
96                  * and the pen based on the state of the stylus2 button, choose eraser if
97                  * pressed else choose pen. if not a proximity change from out to in, send
98                  * an out of proximity for previous tool then a in for new tool.
99                  */
100                 if (!wacom->tool[0]) {
101                         /* Eraser bit set for DTF */
102                         if (data[1] & 0x10)
103                                 wacom->tool[1] = BTN_TOOL_RUBBER;
104                         else
105                                 /* Going into proximity select tool */
106                                 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
107                 } else {
108                         /* was entered with stylus2 pressed */
109                         if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
110                                 /* report out proximity for previous tool */
111                                 input_report_key(input, wacom->tool[1], 0);
112                                 input_sync(input);
113                                 wacom->tool[1] = BTN_TOOL_PEN;
114                                 return 0;
115                         }
116                 }
117                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
118                         /* Unknown tool selected default to pen tool */
119                         wacom->tool[1] = BTN_TOOL_PEN;
120                         wacom->id[0] = STYLUS_DEVICE_ID;
121                 }
122                 input_report_key(input, wacom->tool[1], prox); /* report in proximity for tool */
123                 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
124                 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
125                 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
126                 input_report_abs(input, ABS_PRESSURE, pressure);
127
128                 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
129                 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
130                 /* Only allow the stylus2 button to be reported for the pen tool. */
131                 input_report_key(input, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
132         } else {
133                 /* report proximity-out of a (valid) tool */
134                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
135                         /* Unknown tool selected default to pen tool */
136                         wacom->tool[1] = BTN_TOOL_PEN;
137                 }
138                 input_report_key(input, wacom->tool[1], prox);
139         }
140
141         wacom->tool[0] = prox; /* Save proximity state */
142         return 1;
143 }
144
145 static int wacom_ptu_irq(struct wacom_wac *wacom)
146 {
147         unsigned char *data = wacom->data;
148         struct input_dev *input = wacom->input;
149
150         if (data[0] != WACOM_REPORT_PENABLED) {
151                 dev_dbg(input->dev.parent,
152                         "%s: received unknown report #%d\n", __func__, data[0]);
153                 return 0;
154         }
155
156         if (data[1] & 0x04) {
157                 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
158                 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
159                 wacom->id[0] = ERASER_DEVICE_ID;
160         } else {
161                 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
162                 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
163                 wacom->id[0] = STYLUS_DEVICE_ID;
164         }
165         input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
166         input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
167         input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
168         input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
169         input_report_key(input, BTN_STYLUS, data[1] & 0x02);
170         input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
171         return 1;
172 }
173
174 static int wacom_dtu_irq(struct wacom_wac *wacom)
175 {
176         struct wacom_features *features = &wacom->features;
177         char *data = wacom->data;
178         struct input_dev *input = wacom->input;
179         int prox = data[1] & 0x20, pressure;
180
181         dev_dbg(input->dev.parent,
182                 "%s: received report #%d", __func__, data[0]);
183
184         if (prox) {
185                 /* Going into proximity select tool */
186                 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
187                 if (wacom->tool[0] == BTN_TOOL_PEN)
188                         wacom->id[0] = STYLUS_DEVICE_ID;
189                 else
190                         wacom->id[0] = ERASER_DEVICE_ID;
191         }
192         input_report_key(input, BTN_STYLUS, data[1] & 0x02);
193         input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
194         input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
195         input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
196         pressure = ((data[7] & 0x01) << 8) | data[6];
197         if (pressure < 0)
198                 pressure = features->pressure_max + pressure + 1;
199         input_report_abs(input, ABS_PRESSURE, pressure);
200         input_report_key(input, BTN_TOUCH, data[1] & 0x05);
201         if (!prox) /* out-prox */
202                 wacom->id[0] = 0;
203         input_report_key(input, wacom->tool[0], prox);
204         input_report_abs(input, ABS_MISC, wacom->id[0]);
205         return 1;
206 }
207
208 static int wacom_graphire_irq(struct wacom_wac *wacom)
209 {
210         struct wacom_features *features = &wacom->features;
211         unsigned char *data = wacom->data;
212         struct input_dev *input = wacom->input;
213         int prox;
214         int rw = 0;
215         int retval = 0;
216
217         if (data[0] != WACOM_REPORT_PENABLED) {
218                 dev_dbg(input->dev.parent,
219                         "%s: received unknown report #%d\n", __func__, data[0]);
220                 goto exit;
221         }
222
223         prox = data[1] & 0x80;
224         if (prox || wacom->id[0]) {
225                 if (prox) {
226                         switch ((data[1] >> 5) & 3) {
227
228                         case 0: /* Pen */
229                                 wacom->tool[0] = BTN_TOOL_PEN;
230                                 wacom->id[0] = STYLUS_DEVICE_ID;
231                                 break;
232
233                         case 1: /* Rubber */
234                                 wacom->tool[0] = BTN_TOOL_RUBBER;
235                                 wacom->id[0] = ERASER_DEVICE_ID;
236                                 break;
237
238                         case 2: /* Mouse with wheel */
239                                 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
240                                 /* fall through */
241
242                         case 3: /* Mouse without wheel */
243                                 wacom->tool[0] = BTN_TOOL_MOUSE;
244                                 wacom->id[0] = CURSOR_DEVICE_ID;
245                                 break;
246                         }
247                 }
248                 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
249                 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
250                 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
251                         input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x03) << 8));
252                         input_report_key(input, BTN_TOUCH, data[1] & 0x01);
253                         input_report_key(input, BTN_STYLUS, data[1] & 0x02);
254                         input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
255                 } else {
256                         input_report_key(input, BTN_LEFT, data[1] & 0x01);
257                         input_report_key(input, BTN_RIGHT, data[1] & 0x02);
258                         if (features->type == WACOM_G4 ||
259                                         features->type == WACOM_MO) {
260                                 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
261                                 rw = (data[7] & 0x04) - (data[7] & 0x03);
262                         } else {
263                                 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
264                                 rw = -(signed char)data[6];
265                         }
266                         input_report_rel(input, REL_WHEEL, rw);
267                 }
268
269                 if (!prox)
270                         wacom->id[0] = 0;
271                 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
272                 input_report_key(input, wacom->tool[0], prox);
273                 input_event(input, EV_MSC, MSC_SERIAL, 1);
274                 input_sync(input); /* sync last event */
275         }
276
277         /* send pad data */
278         switch (features->type) {
279         case WACOM_G4:
280                 prox = data[7] & 0xf8;
281                 if (prox || wacom->id[1]) {
282                         wacom->id[1] = PAD_DEVICE_ID;
283                         input_report_key(input, BTN_BACK, (data[7] & 0x40));
284                         input_report_key(input, BTN_FORWARD, (data[7] & 0x80));
285                         rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
286                         input_report_rel(input, REL_WHEEL, rw);
287                         if (!prox)
288                                 wacom->id[1] = 0;
289                         input_report_abs(input, ABS_MISC, wacom->id[1]);
290                         input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
291                         retval = 1;
292                 }
293                 break;
294
295         case WACOM_MO:
296                 prox = (data[7] & 0xf8) || data[8];
297                 if (prox || wacom->id[1]) {
298                         wacom->id[1] = PAD_DEVICE_ID;
299                         input_report_key(input, BTN_BACK, (data[7] & 0x08));
300                         input_report_key(input, BTN_LEFT, (data[7] & 0x20));
301                         input_report_key(input, BTN_FORWARD, (data[7] & 0x10));
302                         input_report_key(input, BTN_RIGHT, (data[7] & 0x40));
303                         input_report_abs(input, ABS_WHEEL, (data[8] & 0x7f));
304                         if (!prox)
305                                 wacom->id[1] = 0;
306                         input_report_abs(input, ABS_MISC, wacom->id[1]);
307                         input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
308                         retval = 1;
309                 }
310                 break;
311         }
312 exit:
313         return retval;
314 }
315
316 static int wacom_intuos_inout(struct wacom_wac *wacom)
317 {
318         struct wacom_features *features = &wacom->features;
319         unsigned char *data = wacom->data;
320         struct input_dev *input = wacom->input;
321         int idx = 0;
322
323         /* tool number */
324         if (features->type == INTUOS)
325                 idx = data[1] & 0x01;
326
327         /* Enter report */
328         if ((data[1] & 0xfc) == 0xc0) {
329                 if (features->type >= INTUOS5S && features->type <= INTUOS5L)
330                         wacom->shared->stylus_in_proximity = true;
331
332                 /* serial number of the tool */
333                 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
334                         (data[4] << 20) + (data[5] << 12) +
335                         (data[6] << 4) + (data[7] >> 4);
336
337                 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
338                         ((data[7] & 0x0f) << 20) | ((data[8] & 0xf0) << 12);
339
340                 switch (wacom->id[idx] & 0xfffff) {
341                 case 0x812: /* Inking pen */
342                 case 0x801: /* Intuos3 Inking pen */
343                 case 0x20802: /* Intuos4 Inking Pen */
344                 case 0x012:
345                         wacom->tool[idx] = BTN_TOOL_PENCIL;
346                         break;
347
348                 case 0x822: /* Pen */
349                 case 0x842:
350                 case 0x852:
351                 case 0x823: /* Intuos3 Grip Pen */
352                 case 0x813: /* Intuos3 Classic Pen */
353                 case 0x885: /* Intuos3 Marker Pen */
354                 case 0x802: /* Intuos4 General Pen */
355                 case 0x804: /* Intuos4 Marker Pen */
356                 case 0x40802: /* Intuos4 Classic Pen */
357                 case 0x022:
358                         wacom->tool[idx] = BTN_TOOL_PEN;
359                         break;
360
361                 case 0x832: /* Stroke pen */
362                 case 0x032:
363                         wacom->tool[idx] = BTN_TOOL_BRUSH;
364                         break;
365
366                 case 0x007: /* Mouse 4D and 2D */
367                 case 0x09c:
368                 case 0x094:
369                 case 0x017: /* Intuos3 2D Mouse */
370                 case 0x806: /* Intuos4 Mouse */
371                         wacom->tool[idx] = BTN_TOOL_MOUSE;
372                         break;
373
374                 case 0x096: /* Lens cursor */
375                 case 0x097: /* Intuos3 Lens cursor */
376                 case 0x006: /* Intuos4 Lens cursor */
377                         wacom->tool[idx] = BTN_TOOL_LENS;
378                         break;
379
380                 case 0x82a: /* Eraser */
381                 case 0x85a:
382                 case 0x91a:
383                 case 0xd1a:
384                 case 0x0fa:
385                 case 0x82b: /* Intuos3 Grip Pen Eraser */
386                 case 0x81b: /* Intuos3 Classic Pen Eraser */
387                 case 0x91b: /* Intuos3 Airbrush Eraser */
388                 case 0x80c: /* Intuos4 Marker Pen Eraser */
389                 case 0x80a: /* Intuos4 General Pen Eraser */
390                 case 0x4080a: /* Intuos4 Classic Pen Eraser */
391                 case 0x90a: /* Intuos4 Airbrush Eraser */
392                         wacom->tool[idx] = BTN_TOOL_RUBBER;
393                         break;
394
395                 case 0xd12:
396                 case 0x912:
397                 case 0x112:
398                 case 0x913: /* Intuos3 Airbrush */
399                 case 0x902: /* Intuos4 Airbrush */
400                         wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
401                         break;
402
403                 default: /* Unknown tool */
404                         wacom->tool[idx] = BTN_TOOL_PEN;
405                         break;
406                 }
407                 return 1;
408         }
409
410         /* older I4 styli don't work with new Cintiqs */
411         if (!((wacom->id[idx] >> 20) & 0x01) &&
412                         (features->type == WACOM_21UX2))
413                 return 1;
414
415         /* Exit report */
416         if ((data[1] & 0xfe) == 0x80) {
417                 if (features->type >= INTUOS5S && features->type <= INTUOS5L)
418                         wacom->shared->stylus_in_proximity = false;
419
420                 /*
421                  * Reset all states otherwise we lose the initial states
422                  * when in-prox next time
423                  */
424                 input_report_abs(input, ABS_X, 0);
425                 input_report_abs(input, ABS_Y, 0);
426                 input_report_abs(input, ABS_DISTANCE, 0);
427                 input_report_abs(input, ABS_TILT_X, 0);
428                 input_report_abs(input, ABS_TILT_Y, 0);
429                 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
430                         input_report_key(input, BTN_LEFT, 0);
431                         input_report_key(input, BTN_MIDDLE, 0);
432                         input_report_key(input, BTN_RIGHT, 0);
433                         input_report_key(input, BTN_SIDE, 0);
434                         input_report_key(input, BTN_EXTRA, 0);
435                         input_report_abs(input, ABS_THROTTLE, 0);
436                         input_report_abs(input, ABS_RZ, 0);
437                 } else {
438                         input_report_abs(input, ABS_PRESSURE, 0);
439                         input_report_key(input, BTN_STYLUS, 0);
440                         input_report_key(input, BTN_STYLUS2, 0);
441                         input_report_key(input, BTN_TOUCH, 0);
442                         input_report_abs(input, ABS_WHEEL, 0);
443                         if (features->type >= INTUOS3S)
444                                 input_report_abs(input, ABS_Z, 0);
445                 }
446                 input_report_key(input, wacom->tool[idx], 0);
447                 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
448                 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
449                 wacom->id[idx] = 0;
450                 return 2;
451         }
452         return 0;
453 }
454
455 static void wacom_intuos_general(struct wacom_wac *wacom)
456 {
457         struct wacom_features *features = &wacom->features;
458         unsigned char *data = wacom->data;
459         struct input_dev *input = wacom->input;
460         unsigned int t;
461
462         /* general pen packet */
463         if ((data[1] & 0xb8) == 0xa0) {
464                 t = (data[6] << 2) | ((data[7] >> 6) & 3);
465                 if ((features->type >= INTUOS4S && features->type <= INTUOS4L) ||
466                     (features->type >= INTUOS5S && features->type <= INTUOS5L) ||
467                     features->type == WACOM_21UX2 || features->type == WACOM_24HD) {
468                         t = (t << 1) | (data[1] & 1);
469                 }
470                 input_report_abs(input, ABS_PRESSURE, t);
471                 input_report_abs(input, ABS_TILT_X,
472                                 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
473                 input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
474                 input_report_key(input, BTN_STYLUS, data[1] & 2);
475                 input_report_key(input, BTN_STYLUS2, data[1] & 4);
476                 input_report_key(input, BTN_TOUCH, t > 10);
477         }
478
479         /* airbrush second packet */
480         if ((data[1] & 0xbc) == 0xb4) {
481                 input_report_abs(input, ABS_WHEEL,
482                                 (data[6] << 2) | ((data[7] >> 6) & 3));
483                 input_report_abs(input, ABS_TILT_X,
484                                 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
485                 input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
486         }
487 }
488
489 static int wacom_intuos_irq(struct wacom_wac *wacom)
490 {
491         struct wacom_features *features = &wacom->features;
492         unsigned char *data = wacom->data;
493         struct input_dev *input = wacom->input;
494         unsigned int t;
495         int idx = 0, result;
496
497         if (data[0] != WACOM_REPORT_PENABLED &&
498             data[0] != WACOM_REPORT_INTUOSREAD &&
499             data[0] != WACOM_REPORT_INTUOSWRITE &&
500             data[0] != WACOM_REPORT_INTUOSPAD &&
501             data[0] != WACOM_REPORT_INTUOS5PAD) {
502                 dev_dbg(input->dev.parent,
503                         "%s: received unknown report #%d\n", __func__, data[0]);
504                 return 0;
505         }
506
507         /* tool number */
508         if (features->type == INTUOS)
509                 idx = data[1] & 0x01;
510
511         /* pad packets. Works as a second tool and is always in prox */
512         if (data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD) {
513                 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
514                         input_report_key(input, BTN_0, (data[2] & 0x01));
515                         input_report_key(input, BTN_1, (data[3] & 0x01));
516                         input_report_key(input, BTN_2, (data[3] & 0x02));
517                         input_report_key(input, BTN_3, (data[3] & 0x04));
518                         input_report_key(input, BTN_4, (data[3] & 0x08));
519                         input_report_key(input, BTN_5, (data[3] & 0x10));
520                         input_report_key(input, BTN_6, (data[3] & 0x20));
521                         if (data[1] & 0x80) {
522                                 input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
523                         } else {
524                                 /* Out of proximity, clear wheel value. */
525                                 input_report_abs(input, ABS_WHEEL, 0);
526                         }
527                         if (features->type != INTUOS4S) {
528                                 input_report_key(input, BTN_7, (data[3] & 0x40));
529                                 input_report_key(input, BTN_8, (data[3] & 0x80));
530                         }
531                         if (data[1] | (data[2] & 0x01) | data[3]) {
532                                 input_report_key(input, wacom->tool[1], 1);
533                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
534                         } else {
535                                 input_report_key(input, wacom->tool[1], 0);
536                                 input_report_abs(input, ABS_MISC, 0);
537                         }
538                 } else if (features->type == WACOM_24HD) {
539                         input_report_key(input, BTN_0, (data[6] & 0x01));
540                         input_report_key(input, BTN_1, (data[6] & 0x02));
541                         input_report_key(input, BTN_2, (data[6] & 0x04));
542                         input_report_key(input, BTN_3, (data[6] & 0x08));
543                         input_report_key(input, BTN_4, (data[6] & 0x10));
544                         input_report_key(input, BTN_5, (data[6] & 0x20));
545                         input_report_key(input, BTN_6, (data[6] & 0x40));
546                         input_report_key(input, BTN_7, (data[6] & 0x80));
547                         input_report_key(input, BTN_8, (data[8] & 0x01));
548                         input_report_key(input, BTN_9, (data[8] & 0x02));
549                         input_report_key(input, BTN_A, (data[8] & 0x04));
550                         input_report_key(input, BTN_B, (data[8] & 0x08));
551                         input_report_key(input, BTN_C, (data[8] & 0x10));
552                         input_report_key(input, BTN_X, (data[8] & 0x20));
553                         input_report_key(input, BTN_Y, (data[8] & 0x40));
554                         input_report_key(input, BTN_Z, (data[8] & 0x80));
555
556                         /*
557                          * Three "buttons" are available on the 24HD which are
558                          * physically implemented as a touchstrip. Each button
559                          * is approximately 3 bits wide with a 2 bit spacing.
560                          * The raw touchstrip bits are stored at:
561                          *    ((data[3] & 0x1f) << 8) | data[4])
562                          */
563                         input_report_key(input, KEY_PROG1, data[4] & 0x07);
564                         input_report_key(input, KEY_PROG2, data[4] & 0xE0);
565                         input_report_key(input, KEY_PROG3, data[3] & 0x1C);
566
567                         if (data[1] & 0x80) {
568                                 input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
569                         } else {
570                                 /* Out of proximity, clear wheel value. */
571                                 input_report_abs(input, ABS_WHEEL, 0);
572                         }
573
574                         if (data[2] & 0x80) {
575                                 input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
576                         } else {
577                                 /* Out of proximity, clear second wheel value. */
578                                 input_report_abs(input, ABS_THROTTLE, 0);
579                         }
580
581                         if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
582                                 input_report_key(input, wacom->tool[1], 1);
583                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
584                         } else {
585                                 input_report_key(input, wacom->tool[1], 0);
586                                 input_report_abs(input, ABS_MISC, 0);
587                         }
588                 } else if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
589                         int i;
590
591                         /* Touch ring mode switch has no capacitive sensor */
592                         input_report_key(input, BTN_0, (data[3] & 0x01));
593
594                         /*
595                          * ExpressKeys on Intuos5 have a capacitive sensor in
596                          * addition to the mechanical switch. Switch data is
597                          * stored in data[4], capacitive data in data[5].
598                          */
599                         for (i = 0; i < 8; i++)
600                                 input_report_key(input, BTN_1 + i, data[4] & (1 << i));
601
602                         if (data[2] & 0x80) {
603                                 input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
604                         } else {
605                                 /* Out of proximity, clear wheel value. */
606                                 input_report_abs(input, ABS_WHEEL, 0);
607                         }
608
609                         if (data[2] | (data[3] & 0x01) | data[4]) {
610                                 input_report_key(input, wacom->tool[1], 1);
611                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
612                         } else {
613                                 input_report_key(input, wacom->tool[1], 0);
614                                 input_report_abs(input, ABS_MISC, 0);
615                         }
616                 } else {
617                         if (features->type == WACOM_21UX2) {
618                                 input_report_key(input, BTN_0, (data[5] & 0x01));
619                                 input_report_key(input, BTN_1, (data[6] & 0x01));
620                                 input_report_key(input, BTN_2, (data[6] & 0x02));
621                                 input_report_key(input, BTN_3, (data[6] & 0x04));
622                                 input_report_key(input, BTN_4, (data[6] & 0x08));
623                                 input_report_key(input, BTN_5, (data[6] & 0x10));
624                                 input_report_key(input, BTN_6, (data[6] & 0x20));
625                                 input_report_key(input, BTN_7, (data[6] & 0x40));
626                                 input_report_key(input, BTN_8, (data[6] & 0x80));
627                                 input_report_key(input, BTN_9, (data[7] & 0x01));
628                                 input_report_key(input, BTN_A, (data[8] & 0x01));
629                                 input_report_key(input, BTN_B, (data[8] & 0x02));
630                                 input_report_key(input, BTN_C, (data[8] & 0x04));
631                                 input_report_key(input, BTN_X, (data[8] & 0x08));
632                                 input_report_key(input, BTN_Y, (data[8] & 0x10));
633                                 input_report_key(input, BTN_Z, (data[8] & 0x20));
634                                 input_report_key(input, BTN_BASE, (data[8] & 0x40));
635                                 input_report_key(input, BTN_BASE2, (data[8] & 0x80));
636                         } else {
637                                 input_report_key(input, BTN_0, (data[5] & 0x01));
638                                 input_report_key(input, BTN_1, (data[5] & 0x02));
639                                 input_report_key(input, BTN_2, (data[5] & 0x04));
640                                 input_report_key(input, BTN_3, (data[5] & 0x08));
641                                 input_report_key(input, BTN_4, (data[6] & 0x01));
642                                 input_report_key(input, BTN_5, (data[6] & 0x02));
643                                 input_report_key(input, BTN_6, (data[6] & 0x04));
644                                 input_report_key(input, BTN_7, (data[6] & 0x08));
645                                 input_report_key(input, BTN_8, (data[5] & 0x10));
646                                 input_report_key(input, BTN_9, (data[6] & 0x10));
647                         }
648                         input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
649                         input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
650
651                         if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
652                                 data[2] | (data[3] & 0x1f) | data[4] | data[8] |
653                                 (data[7] & 0x01)) {
654                                 input_report_key(input, wacom->tool[1], 1);
655                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
656                         } else {
657                                 input_report_key(input, wacom->tool[1], 0);
658                                 input_report_abs(input, ABS_MISC, 0);
659                         }
660                 }
661                 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
662                 return 1;
663         }
664
665         /* process in/out prox events */
666         result = wacom_intuos_inout(wacom);
667         if (result)
668                 return result - 1;
669
670         /* don't proceed if we don't know the ID */
671         if (!wacom->id[idx])
672                 return 0;
673
674         /* Only large Intuos support Lense Cursor */
675         if (wacom->tool[idx] == BTN_TOOL_LENS &&
676             (features->type == INTUOS3 ||
677              features->type == INTUOS3S ||
678              features->type == INTUOS4 ||
679              features->type == INTUOS4S ||
680              features->type == INTUOS5 ||
681              features->type == INTUOS5S)) {
682
683                 return 0;
684         }
685
686         /* Cintiq doesn't send data when RDY bit isn't set */
687         if (features->type == CINTIQ && !(data[1] & 0x40))
688                  return 0;
689
690         if (features->type >= INTUOS3S) {
691                 input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
692                 input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
693                 input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
694         } else {
695                 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
696                 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
697                 input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
698         }
699
700         /* process general packets */
701         wacom_intuos_general(wacom);
702
703         /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
704         if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
705
706                 if (data[1] & 0x02) {
707                         /* Rotation packet */
708                         if (features->type >= INTUOS3S) {
709                                 /* I3 marker pen rotation */
710                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
711                                 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
712                                         ((t-1) / 2 + 450)) : (450 - t / 2) ;
713                                 input_report_abs(input, ABS_Z, t);
714                         } else {
715                                 /* 4D mouse rotation packet */
716                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
717                                 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
718                                         ((t - 1) / 2) : -t / 2);
719                         }
720
721                 } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
722                         /* 4D mouse packet */
723                         input_report_key(input, BTN_LEFT,   data[8] & 0x01);
724                         input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
725                         input_report_key(input, BTN_RIGHT,  data[8] & 0x04);
726
727                         input_report_key(input, BTN_SIDE,   data[8] & 0x20);
728                         input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
729                         t = (data[6] << 2) | ((data[7] >> 6) & 3);
730                         input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
731
732                 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
733                         /* I4 mouse */
734                         if ((features->type >= INTUOS4S && features->type <= INTUOS4L) ||
735                             (features->type >= INTUOS5S && features->type <= INTUOS5L)) {
736                                 input_report_key(input, BTN_LEFT,   data[6] & 0x01);
737                                 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
738                                 input_report_key(input, BTN_RIGHT,  data[6] & 0x04);
739                                 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
740                                                  - ((data[7] & 0x40) >> 6));
741                                 input_report_key(input, BTN_SIDE,   data[6] & 0x08);
742                                 input_report_key(input, BTN_EXTRA,  data[6] & 0x10);
743
744                                 input_report_abs(input, ABS_TILT_X,
745                                         ((data[7] << 1) & 0x7e) | (data[8] >> 7));
746                                 input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
747                         } else {
748                                 /* 2D mouse packet */
749                                 input_report_key(input, BTN_LEFT,   data[8] & 0x04);
750                                 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
751                                 input_report_key(input, BTN_RIGHT,  data[8] & 0x10);
752                                 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
753                                                  - ((data[8] & 0x02) >> 1));
754
755                                 /* I3 2D mouse side buttons */
756                                 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
757                                         input_report_key(input, BTN_SIDE,   data[8] & 0x40);
758                                         input_report_key(input, BTN_EXTRA,  data[8] & 0x20);
759                                 }
760                         }
761                 } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
762                                 features->type == INTUOS4L || features->type == INTUOS5L) &&
763                            wacom->tool[idx] == BTN_TOOL_LENS) {
764                         /* Lens cursor packets */
765                         input_report_key(input, BTN_LEFT,   data[8] & 0x01);
766                         input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
767                         input_report_key(input, BTN_RIGHT,  data[8] & 0x04);
768                         input_report_key(input, BTN_SIDE,   data[8] & 0x10);
769                         input_report_key(input, BTN_EXTRA,  data[8] & 0x08);
770                 }
771         }
772
773         input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
774         input_report_key(input, wacom->tool[idx], 1);
775         input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
776         return 1;
777 }
778
779 static int find_slot_from_contactid(struct wacom_wac *wacom, int contactid)
780 {
781         int touch_max = wacom->features.touch_max;
782         int i;
783
784         if (!wacom->slots)
785                 return -1;
786
787         for (i = 0; i < touch_max; ++i) {
788                 if (wacom->slots[i] == contactid)
789                         return i;
790         }
791         for (i = 0; i < touch_max; ++i) {
792                 if (wacom->slots[i] == -1)
793                         return i;
794         }
795         return -1;
796 }
797
798 static int wacom_mt_touch(struct wacom_wac *wacom)
799 {
800         struct input_dev *input = wacom->input;
801         char *data = wacom->data;
802         int i;
803         int current_num_contacts = data[2];
804         int contacts_to_send = 0;
805
806         /*
807          * First packet resets the counter since only the first
808          * packet in series will have non-zero current_num_contacts.
809          */
810         if (current_num_contacts)
811                 wacom->num_contacts_left = current_num_contacts;
812
813         /* There are at most 5 contacts per packet */
814         contacts_to_send = min(5, wacom->num_contacts_left);
815
816         for (i = 0; i < contacts_to_send; i++) {
817                 int offset = (WACOM_BYTES_PER_MT_PACKET * i) + 3;
818                 bool touch = data[offset] & 0x1;
819                 int id = le16_to_cpup((__le16 *)&data[offset + 1]);
820                 int slot = find_slot_from_contactid(wacom, id);
821
822                 if (slot < 0)
823                         continue;
824
825                 input_mt_slot(input, slot);
826                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
827                 if (touch) {
828                         int x = le16_to_cpup((__le16 *)&data[offset + 7]);
829                         int y = le16_to_cpup((__le16 *)&data[offset + 9]);
830                         input_report_abs(input, ABS_MT_POSITION_X, x);
831                         input_report_abs(input, ABS_MT_POSITION_Y, y);
832                 }
833                 wacom->slots[slot] = touch ? id : -1;
834         }
835
836         input_mt_report_pointer_emulation(input, true);
837
838         wacom->num_contacts_left -= contacts_to_send;
839         if (wacom->num_contacts_left < 0)
840                 wacom->num_contacts_left = 0;
841
842         return 1;
843 }
844
845 static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
846 {
847         struct input_dev *input = wacom->input;
848         unsigned char *data = wacom->data;
849         int contact_with_no_pen_down_count = 0;
850         int i;
851
852         for (i = 0; i < 2; i++) {
853                 int p = data[1] & (1 << i);
854                 bool touch = p && !wacom->shared->stylus_in_proximity;
855
856                 input_mt_slot(input, i);
857                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
858                 if (touch) {
859                         int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
860                         int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
861
862                         input_report_abs(input, ABS_MT_POSITION_X, x);
863                         input_report_abs(input, ABS_MT_POSITION_Y, y);
864                         contact_with_no_pen_down_count++;
865                 }
866         }
867
868         /* keep touch state for pen event */
869         wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
870
871         input_mt_report_pointer_emulation(input, true);
872
873         return 1;
874 }
875
876 static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
877 {
878         char *data = wacom->data;
879         struct input_dev *input = wacom->input;
880         bool prox;
881         int x = 0, y = 0;
882
883         if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
884                 return 0;
885
886         if (!wacom->shared->stylus_in_proximity) {
887                 if (len == WACOM_PKGLEN_TPC1FG) {
888                         prox = data[0] & 0x01;
889                         x = get_unaligned_le16(&data[1]);
890                         y = get_unaligned_le16(&data[3]);
891                 } else {
892                         prox = data[1] & 0x01;
893                         x = le16_to_cpup((__le16 *)&data[2]);
894                         y = le16_to_cpup((__le16 *)&data[4]);
895                 }
896         } else
897                 /* force touch out when pen is in prox */
898                 prox = 0;
899
900         if (prox) {
901                 input_report_abs(input, ABS_X, x);
902                 input_report_abs(input, ABS_Y, y);
903         }
904         input_report_key(input, BTN_TOUCH, prox);
905
906         /* keep touch state for pen events */
907         wacom->shared->touch_down = prox;
908
909         return 1;
910 }
911
912 static int wacom_tpc_pen(struct wacom_wac *wacom)
913 {
914         struct wacom_features *features = &wacom->features;
915         char *data = wacom->data;
916         struct input_dev *input = wacom->input;
917         int pressure;
918         bool prox = data[1] & 0x20;
919
920         if (!wacom->shared->stylus_in_proximity) /* first in prox */
921                 /* Going into proximity select tool */
922                 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
923
924         /* keep pen state for touch events */
925         wacom->shared->stylus_in_proximity = prox;
926
927         /* send pen events only when touch is up or forced out */
928         if (!wacom->shared->touch_down) {
929                 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
930                 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
931                 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
932                 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
933                 pressure = ((data[7] & 0x01) << 8) | data[6];
934                 if (pressure < 0)
935                         pressure = features->pressure_max + pressure + 1;
936                 input_report_abs(input, ABS_PRESSURE, pressure);
937                 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
938                 input_report_key(input, wacom->tool[0], prox);
939                 return 1;
940         }
941
942         return 0;
943 }
944
945 static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
946 {
947         char *data = wacom->data;
948
949         dev_dbg(wacom->input->dev.parent,
950                 "%s: received report #%d\n", __func__, data[0]);
951
952         switch (len) {
953         case WACOM_PKGLEN_TPC1FG:
954                 return wacom_tpc_single_touch(wacom, len);
955
956         case WACOM_PKGLEN_TPC2FG:
957                 return wacom_tpc_mt_touch(wacom);
958
959         default:
960                 switch (data[0]) {
961                 case WACOM_REPORT_TPC1FG:
962                 case WACOM_REPORT_TPCHID:
963                 case WACOM_REPORT_TPCST:
964                 case WACOM_REPORT_TPC1FGE:
965                         return wacom_tpc_single_touch(wacom, len);
966
967                 case WACOM_REPORT_TPCMT:
968                         return wacom_mt_touch(wacom);
969
970                 case WACOM_REPORT_PENABLED:
971                         return wacom_tpc_pen(wacom);
972                 }
973         }
974
975         return 0;
976 }
977
978 static int wacom_bpt_touch(struct wacom_wac *wacom)
979 {
980         struct wacom_features *features = &wacom->features;
981         struct input_dev *input = wacom->input;
982         unsigned char *data = wacom->data;
983         int i;
984
985         if (data[0] != 0x02)
986             return 0;
987
988         for (i = 0; i < 2; i++) {
989                 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
990                 bool touch = data[offset + 3] & 0x80;
991
992                 /*
993                  * Touch events need to be disabled while stylus is
994                  * in proximity because user's hand is resting on touchpad
995                  * and sending unwanted events.  User expects tablet buttons
996                  * to continue working though.
997                  */
998                 touch = touch && !wacom->shared->stylus_in_proximity;
999
1000                 input_mt_slot(input, i);
1001                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1002                 if (touch) {
1003                         int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
1004                         int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
1005                         if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
1006                                 x <<= 5;
1007                                 y <<= 5;
1008                         }
1009                         input_report_abs(input, ABS_MT_POSITION_X, x);
1010                         input_report_abs(input, ABS_MT_POSITION_Y, y);
1011                 }
1012         }
1013
1014         input_mt_report_pointer_emulation(input, true);
1015
1016         input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
1017         input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
1018         input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
1019         input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
1020
1021         input_sync(input);
1022
1023         return 0;
1024 }
1025
1026 static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
1027 {
1028         struct input_dev *input = wacom->input;
1029         int slot_id = data[0] - 2;  /* data[0] is between 2 and 17 */
1030         bool touch = data[1] & 0x80;
1031
1032         touch = touch && !wacom->shared->stylus_in_proximity;
1033
1034         input_mt_slot(input, slot_id);
1035         input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1036
1037         if (touch) {
1038                 int x = (data[2] << 4) | (data[4] >> 4);
1039                 int y = (data[3] << 4) | (data[4] & 0x0f);
1040                 int w = data[6];
1041
1042                 input_report_abs(input, ABS_MT_POSITION_X, x);
1043                 input_report_abs(input, ABS_MT_POSITION_Y, y);
1044                 input_report_abs(input, ABS_MT_TOUCH_MAJOR, w);
1045         }
1046 }
1047
1048 static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
1049 {
1050         struct input_dev *input = wacom->input;
1051
1052         input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
1053         input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
1054         input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
1055         input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
1056 }
1057
1058 static int wacom_bpt3_touch(struct wacom_wac *wacom)
1059 {
1060         struct input_dev *input = wacom->input;
1061         unsigned char *data = wacom->data;
1062         int count = data[1] & 0x07;
1063         int i;
1064
1065         if (data[0] != 0x02)
1066             return 0;
1067
1068         /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
1069         for (i = 0; i < count; i++) {
1070                 int offset = (8 * i) + 2;
1071                 int msg_id = data[offset];
1072
1073                 if (msg_id >= 2 && msg_id <= 17)
1074                         wacom_bpt3_touch_msg(wacom, data + offset);
1075                 else if (msg_id == 128)
1076                         wacom_bpt3_button_msg(wacom, data + offset);
1077
1078         }
1079
1080         input_mt_report_pointer_emulation(input, true);
1081
1082         input_sync(input);
1083
1084         return 0;
1085 }
1086
1087 static int wacom_bpt_pen(struct wacom_wac *wacom)
1088 {
1089         struct input_dev *input = wacom->input;
1090         unsigned char *data = wacom->data;
1091         int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
1092
1093         if (data[0] != 0x02)
1094             return 0;
1095
1096         prox = (data[1] & 0x20) == 0x20;
1097
1098         /*
1099          * All reports shared between PEN and RUBBER tool must be
1100          * forced to a known starting value (zero) when transitioning to
1101          * out-of-prox.
1102          *
1103          * If not reset then, to userspace, it will look like lost events
1104          * if new tool comes in-prox with same values as previous tool sent.
1105          *
1106          * Hardware does report zero in most out-of-prox cases but not all.
1107          */
1108         if (prox) {
1109                 if (!wacom->shared->stylus_in_proximity) {
1110                         if (data[1] & 0x08) {
1111                                 wacom->tool[0] = BTN_TOOL_RUBBER;
1112                                 wacom->id[0] = ERASER_DEVICE_ID;
1113                         } else {
1114                                 wacom->tool[0] = BTN_TOOL_PEN;
1115                                 wacom->id[0] = STYLUS_DEVICE_ID;
1116                         }
1117                         wacom->shared->stylus_in_proximity = true;
1118                 }
1119                 x = le16_to_cpup((__le16 *)&data[2]);
1120                 y = le16_to_cpup((__le16 *)&data[4]);
1121                 p = le16_to_cpup((__le16 *)&data[6]);
1122                 /*
1123                  * Convert distance from out prox to distance from tablet.
1124                  * distance will be greater than distance_max once
1125                  * touching and applying pressure; do not report negative
1126                  * distance.
1127                  */
1128                 if (data[8] <= wacom->features.distance_max)
1129                         d = wacom->features.distance_max - data[8];
1130
1131                 pen = data[1] & 0x01;
1132                 btn1 = data[1] & 0x02;
1133                 btn2 = data[1] & 0x04;
1134         }
1135
1136         input_report_key(input, BTN_TOUCH, pen);
1137         input_report_key(input, BTN_STYLUS, btn1);
1138         input_report_key(input, BTN_STYLUS2, btn2);
1139
1140         input_report_abs(input, ABS_X, x);
1141         input_report_abs(input, ABS_Y, y);
1142         input_report_abs(input, ABS_PRESSURE, p);
1143         input_report_abs(input, ABS_DISTANCE, d);
1144
1145         if (!prox) {
1146                 wacom->id[0] = 0;
1147                 wacom->shared->stylus_in_proximity = false;
1148         }
1149
1150         input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
1151         input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
1152
1153         return 1;
1154 }
1155
1156 static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
1157 {
1158         if (len == WACOM_PKGLEN_BBTOUCH)
1159                 return wacom_bpt_touch(wacom);
1160         else if (len == WACOM_PKGLEN_BBTOUCH3)
1161                 return wacom_bpt3_touch(wacom);
1162         else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
1163                 return wacom_bpt_pen(wacom);
1164
1165         return 0;
1166 }
1167
1168 static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1169 {
1170         unsigned char *data = wacom->data;
1171         int connected;
1172
1173         if (len != WACOM_PKGLEN_WIRELESS || data[0] != 0x80)
1174                 return 0;
1175
1176         connected = data[1] & 0x01;
1177         if (connected) {
1178                 int pid, battery;
1179
1180                 pid = get_unaligned_be16(&data[6]);
1181                 battery = data[5] & 0x3f;
1182                 if (wacom->pid != pid) {
1183                         wacom->pid = pid;
1184                         wacom_schedule_work(wacom);
1185                 }
1186                 wacom->battery_capacity = battery;
1187         } else if (wacom->pid != 0) {
1188                 /* disconnected while previously connected */
1189                 wacom->pid = 0;
1190                 wacom_schedule_work(wacom);
1191                 wacom->battery_capacity = 0;
1192         }
1193
1194         return 0;
1195 }
1196
1197 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
1198 {
1199         bool sync;
1200
1201         switch (wacom_wac->features.type) {
1202         case PENPARTNER:
1203                 sync = wacom_penpartner_irq(wacom_wac);
1204                 break;
1205
1206         case PL:
1207                 sync = wacom_pl_irq(wacom_wac);
1208                 break;
1209
1210         case WACOM_G4:
1211         case GRAPHIRE:
1212         case WACOM_MO:
1213                 sync = wacom_graphire_irq(wacom_wac);
1214                 break;
1215
1216         case PTU:
1217                 sync = wacom_ptu_irq(wacom_wac);
1218                 break;
1219
1220         case DTU:
1221                 sync = wacom_dtu_irq(wacom_wac);
1222                 break;
1223
1224         case INTUOS:
1225         case INTUOS3S:
1226         case INTUOS3:
1227         case INTUOS3L:
1228         case INTUOS4S:
1229         case INTUOS4:
1230         case INTUOS4L:
1231         case CINTIQ:
1232         case WACOM_BEE:
1233         case WACOM_21UX2:
1234         case WACOM_24HD:
1235                 sync = wacom_intuos_irq(wacom_wac);
1236                 break;
1237
1238         case INTUOS5S:
1239         case INTUOS5:
1240         case INTUOS5L:
1241                 if (len == WACOM_PKGLEN_BBTOUCH3)
1242                         sync = wacom_bpt3_touch(wacom_wac);
1243                 else
1244                         sync = wacom_intuos_irq(wacom_wac);
1245                 break;
1246
1247         case TABLETPC:
1248         case TABLETPCE:
1249         case TABLETPC2FG:
1250         case MTSCREEN:
1251                 sync = wacom_tpc_irq(wacom_wac, len);
1252                 break;
1253
1254         case BAMBOO_PT:
1255                 sync = wacom_bpt_irq(wacom_wac, len);
1256                 break;
1257
1258         case WIRELESS:
1259                 sync = wacom_wireless_irq(wacom_wac, len);
1260                 break;
1261
1262         default:
1263                 sync = false;
1264                 break;
1265         }
1266
1267         if (sync)
1268                 input_sync(wacom_wac->input);
1269 }
1270
1271 static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
1272 {
1273         struct input_dev *input_dev = wacom_wac->input;
1274
1275         input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
1276
1277         __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
1278         __set_bit(BTN_TOOL_PEN, input_dev->keybit);
1279         __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
1280         __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
1281         __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
1282         __set_bit(BTN_STYLUS, input_dev->keybit);
1283         __set_bit(BTN_STYLUS2, input_dev->keybit);
1284
1285         input_set_abs_params(input_dev, ABS_DISTANCE,
1286                              0, wacom_wac->features.distance_max, 0, 0);
1287         input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
1288         input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
1289         input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
1290 }
1291
1292 static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
1293 {
1294         struct input_dev *input_dev = wacom_wac->input;
1295
1296         input_set_capability(input_dev, EV_REL, REL_WHEEL);
1297
1298         wacom_setup_cintiq(wacom_wac);
1299
1300         __set_bit(BTN_LEFT, input_dev->keybit);
1301         __set_bit(BTN_RIGHT, input_dev->keybit);
1302         __set_bit(BTN_MIDDLE, input_dev->keybit);
1303         __set_bit(BTN_SIDE, input_dev->keybit);
1304         __set_bit(BTN_EXTRA, input_dev->keybit);
1305         __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
1306         __set_bit(BTN_TOOL_LENS, input_dev->keybit);
1307
1308         input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
1309         input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
1310 }
1311
1312 void wacom_setup_device_quirks(struct wacom_features *features)
1313 {
1314
1315         /* touch device found but size is not defined. use default */
1316         if (features->device_type == BTN_TOOL_FINGER && !features->x_max) {
1317                 features->x_max = 1023;
1318                 features->y_max = 1023;
1319         }
1320
1321         /* these device have multiple inputs */
1322         if (features->type >= WIRELESS ||
1323             (features->type >= INTUOS5S && features->type <= INTUOS5L))
1324                 features->quirks |= WACOM_QUIRK_MULTI_INPUT;
1325
1326         /* quirk for bamboo touch with 2 low res touches */
1327         if (features->type == BAMBOO_PT &&
1328             features->pktlen == WACOM_PKGLEN_BBTOUCH) {
1329                 features->x_max <<= 5;
1330                 features->y_max <<= 5;
1331                 features->x_fuzz <<= 5;
1332                 features->y_fuzz <<= 5;
1333                 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
1334         }
1335
1336         if (features->type == WIRELESS) {
1337
1338                 /* monitor never has input and pen/touch have delayed create */
1339                 features->quirks |= WACOM_QUIRK_NO_INPUT;
1340
1341                 /* must be monitor interface if no device_type set */
1342                 if (!features->device_type)
1343                         features->quirks |= WACOM_QUIRK_MONITOR;
1344         }
1345 }
1346
1347 static unsigned int wacom_calculate_touch_res(unsigned int logical_max,
1348                                               unsigned int physical_max)
1349 {
1350        /* Touch physical dimensions are in 100th of mm */
1351        return (logical_max * 100) / physical_max;
1352 }
1353
1354 int wacom_setup_input_capabilities(struct input_dev *input_dev,
1355                                    struct wacom_wac *wacom_wac)
1356 {
1357         struct wacom_features *features = &wacom_wac->features;
1358         int i;
1359
1360         input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1361
1362         __set_bit(BTN_TOUCH, input_dev->keybit);
1363
1364         input_set_abs_params(input_dev, ABS_X, 0, features->x_max,
1365                              features->x_fuzz, 0);
1366         input_set_abs_params(input_dev, ABS_Y, 0, features->y_max,
1367                              features->y_fuzz, 0);
1368
1369         if (features->device_type == BTN_TOOL_PEN) {
1370                 input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max,
1371                              features->pressure_fuzz, 0);
1372
1373                 /* penabled devices have fixed resolution for each model */
1374                 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
1375                 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
1376         } else {
1377                 input_abs_set_res(input_dev, ABS_X,
1378                         wacom_calculate_touch_res(features->x_max,
1379                                                 features->x_phy));
1380                 input_abs_set_res(input_dev, ABS_Y,
1381                         wacom_calculate_touch_res(features->y_max,
1382                                                 features->y_phy));
1383         }
1384
1385         __set_bit(ABS_MISC, input_dev->absbit);
1386
1387         switch (wacom_wac->features.type) {
1388         case WACOM_MO:
1389                 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
1390                 /* fall through */
1391
1392         case WACOM_G4:
1393                 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
1394
1395                 __set_bit(BTN_BACK, input_dev->keybit);
1396                 __set_bit(BTN_FORWARD, input_dev->keybit);
1397                 /* fall through */
1398
1399         case GRAPHIRE:
1400                 input_set_capability(input_dev, EV_REL, REL_WHEEL);
1401
1402                 __set_bit(BTN_LEFT, input_dev->keybit);
1403                 __set_bit(BTN_RIGHT, input_dev->keybit);
1404                 __set_bit(BTN_MIDDLE, input_dev->keybit);
1405
1406                 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
1407                 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
1408                 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
1409                 __set_bit(BTN_STYLUS, input_dev->keybit);
1410                 __set_bit(BTN_STYLUS2, input_dev->keybit);
1411
1412                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1413                 break;
1414
1415         case WACOM_24HD:
1416                 __set_bit(BTN_A, input_dev->keybit);
1417                 __set_bit(BTN_B, input_dev->keybit);
1418                 __set_bit(BTN_C, input_dev->keybit);
1419                 __set_bit(BTN_X, input_dev->keybit);
1420                 __set_bit(BTN_Y, input_dev->keybit);
1421                 __set_bit(BTN_Z, input_dev->keybit);
1422
1423                 for (i = 0; i < 10; i++)
1424                         __set_bit(BTN_0 + i, input_dev->keybit);
1425
1426                 __set_bit(KEY_PROG1, input_dev->keybit);
1427                 __set_bit(KEY_PROG2, input_dev->keybit);
1428                 __set_bit(KEY_PROG3, input_dev->keybit);
1429
1430                 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
1431                 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
1432                 wacom_setup_cintiq(wacom_wac);
1433                 break;
1434
1435         case WACOM_21UX2:
1436                 __set_bit(BTN_A, input_dev->keybit);
1437                 __set_bit(BTN_B, input_dev->keybit);
1438                 __set_bit(BTN_C, input_dev->keybit);
1439                 __set_bit(BTN_X, input_dev->keybit);
1440                 __set_bit(BTN_Y, input_dev->keybit);
1441                 __set_bit(BTN_Z, input_dev->keybit);
1442                 __set_bit(BTN_BASE, input_dev->keybit);
1443                 __set_bit(BTN_BASE2, input_dev->keybit);
1444                 /* fall through */
1445
1446         case WACOM_BEE:
1447                 __set_bit(BTN_8, input_dev->keybit);
1448                 __set_bit(BTN_9, input_dev->keybit);
1449                 /* fall through */
1450
1451         case CINTIQ:
1452                 for (i = 0; i < 8; i++)
1453                         __set_bit(BTN_0 + i, input_dev->keybit);
1454
1455                 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
1456                 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
1457                 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
1458
1459                 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
1460
1461                 wacom_setup_cintiq(wacom_wac);
1462                 break;
1463
1464         case INTUOS3:
1465         case INTUOS3L:
1466                 __set_bit(BTN_4, input_dev->keybit);
1467                 __set_bit(BTN_5, input_dev->keybit);
1468                 __set_bit(BTN_6, input_dev->keybit);
1469                 __set_bit(BTN_7, input_dev->keybit);
1470
1471                 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
1472                 /* fall through */
1473
1474         case INTUOS3S:
1475                 __set_bit(BTN_0, input_dev->keybit);
1476                 __set_bit(BTN_1, input_dev->keybit);
1477                 __set_bit(BTN_2, input_dev->keybit);
1478                 __set_bit(BTN_3, input_dev->keybit);
1479
1480                 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
1481                 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
1482                 /* fall through */
1483
1484         case INTUOS:
1485                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1486
1487                 wacom_setup_intuos(wacom_wac);
1488                 break;
1489
1490         case INTUOS5:
1491         case INTUOS5L:
1492                 if (features->device_type == BTN_TOOL_PEN) {
1493                         __set_bit(BTN_7, input_dev->keybit);
1494                         __set_bit(BTN_8, input_dev->keybit);
1495                 }
1496                 /* fall through */
1497
1498         case INTUOS5S:
1499                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1500
1501                 if (features->device_type == BTN_TOOL_PEN) {
1502                         for (i = 0; i < 7; i++)
1503                                 __set_bit(BTN_0 + i, input_dev->keybit);
1504
1505                         input_set_abs_params(input_dev, ABS_DISTANCE, 0,
1506                                               features->distance_max,
1507                                               0, 0);
1508
1509                         input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
1510
1511                         wacom_setup_intuos(wacom_wac);
1512                 } else if (features->device_type == BTN_TOOL_FINGER) {
1513                         __clear_bit(ABS_MISC, input_dev->absbit);
1514
1515                         __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
1516                         __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
1517                         __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
1518                         __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
1519
1520                         input_mt_init_slots(input_dev, features->touch_max);
1521
1522                         input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1523                                              0, 255, 0, 0);
1524
1525                         input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1526                                              0, features->x_max,
1527                                              features->x_fuzz, 0);
1528                         input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1529                                              0, features->y_max,
1530                                              features->y_fuzz, 0);
1531                 }
1532                 break;
1533
1534         case INTUOS4:
1535         case INTUOS4L:
1536                 __set_bit(BTN_7, input_dev->keybit);
1537                 __set_bit(BTN_8, input_dev->keybit);
1538                 /* fall through */
1539
1540         case INTUOS4S:
1541                 for (i = 0; i < 7; i++)
1542                         __set_bit(BTN_0 + i, input_dev->keybit);
1543
1544                 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
1545                 wacom_setup_intuos(wacom_wac);
1546
1547                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1548                 break;
1549
1550         case TABLETPC2FG:
1551         case MTSCREEN:
1552                 if (features->device_type == BTN_TOOL_FINGER) {
1553
1554                         wacom_wac->slots = kmalloc(features->touch_max *
1555                                                         sizeof(int),
1556                                                    GFP_KERNEL);
1557                         if (!wacom_wac->slots)
1558                                 return -ENOMEM;
1559
1560                         for (i = 0; i < features->touch_max; i++)
1561                                 wacom_wac->slots[i] = -1;
1562
1563                         input_mt_init_slots(input_dev, features->touch_max);
1564                         input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
1565                                         0, MT_TOOL_MAX, 0, 0);
1566                         input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1567                                         0, features->x_max, 0, 0);
1568                         input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1569                                         0, features->y_max, 0, 0);
1570                 }
1571                 /* fall through */
1572
1573         case TABLETPC:
1574         case TABLETPCE:
1575                 __clear_bit(ABS_MISC, input_dev->absbit);
1576
1577                 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
1578
1579                 if (features->device_type != BTN_TOOL_PEN)
1580                         break;  /* no need to process stylus stuff */
1581
1582                 /* fall through */
1583
1584         case PL:
1585         case DTU:
1586                 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
1587                 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
1588                 __set_bit(BTN_STYLUS, input_dev->keybit);
1589                 __set_bit(BTN_STYLUS2, input_dev->keybit);
1590
1591                 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
1592                 break;
1593
1594         case PTU:
1595                 __set_bit(BTN_STYLUS2, input_dev->keybit);
1596                 /* fall through */
1597
1598         case PENPARTNER:
1599                 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
1600                 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
1601                 __set_bit(BTN_STYLUS, input_dev->keybit);
1602
1603                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1604                 break;
1605
1606         case BAMBOO_PT:
1607                 __clear_bit(ABS_MISC, input_dev->absbit);
1608
1609                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1610
1611                 if (features->device_type == BTN_TOOL_FINGER) {
1612                         __set_bit(BTN_LEFT, input_dev->keybit);
1613                         __set_bit(BTN_FORWARD, input_dev->keybit);
1614                         __set_bit(BTN_BACK, input_dev->keybit);
1615                         __set_bit(BTN_RIGHT, input_dev->keybit);
1616
1617                         __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
1618                         __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
1619                         input_mt_init_slots(input_dev, features->touch_max);
1620
1621                         if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
1622                                 __set_bit(BTN_TOOL_TRIPLETAP,
1623                                           input_dev->keybit);
1624                                 __set_bit(BTN_TOOL_QUADTAP,
1625                                           input_dev->keybit);
1626
1627                                 input_set_abs_params(input_dev,
1628                                                      ABS_MT_TOUCH_MAJOR,
1629                                                      0, 255, 0, 0);
1630                         }
1631
1632                         input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1633                                              0, features->x_max,
1634                                              features->x_fuzz, 0);
1635                         input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
1636                                              0, features->y_max,
1637                                              features->y_fuzz, 0);
1638                 } else if (features->device_type == BTN_TOOL_PEN) {
1639                         __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
1640                         __set_bit(BTN_TOOL_PEN, input_dev->keybit);
1641                         __set_bit(BTN_STYLUS, input_dev->keybit);
1642                         __set_bit(BTN_STYLUS2, input_dev->keybit);
1643                         input_set_abs_params(input_dev, ABS_DISTANCE, 0,
1644                                               features->distance_max,
1645                                               0, 0);
1646                 }
1647                 break;
1648         }
1649         return 0;
1650 }
1651
1652 static const struct wacom_features wacom_features_0x00 =
1653         { "Wacom Penpartner",     WACOM_PKGLEN_PENPRTN,    5040,  3780,  255,
1654           0, PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
1655 static const struct wacom_features wacom_features_0x10 =
1656         { "Wacom Graphire",       WACOM_PKGLEN_GRAPHIRE,  10206,  7422,  511,
1657           63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1658 static const struct wacom_features wacom_features_0x11 =
1659         { "Wacom Graphire2 4x5",  WACOM_PKGLEN_GRAPHIRE,  10206,  7422,  511,
1660           63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1661 static const struct wacom_features wacom_features_0x12 =
1662         { "Wacom Graphire2 5x7",  WACOM_PKGLEN_GRAPHIRE,  13918, 10206,  511,
1663           63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1664 static const struct wacom_features wacom_features_0x13 =
1665         { "Wacom Graphire3",      WACOM_PKGLEN_GRAPHIRE,  10208,  7424,  511,
1666           63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1667 static const struct wacom_features wacom_features_0x14 =
1668         { "Wacom Graphire3 6x8",  WACOM_PKGLEN_GRAPHIRE,  16704, 12064,  511,
1669           63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1670 static const struct wacom_features wacom_features_0x15 =
1671         { "Wacom Graphire4 4x5",  WACOM_PKGLEN_GRAPHIRE,  10208,  7424,  511,
1672           63, WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1673 static const struct wacom_features wacom_features_0x16 =
1674         { "Wacom Graphire4 6x8",  WACOM_PKGLEN_GRAPHIRE,  16704, 12064,  511,
1675           63, WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1676 static const struct wacom_features wacom_features_0x17 =
1677         { "Wacom BambooFun 4x5",  WACOM_PKGLEN_BBFUN,     14760,  9225,  511,
1678           63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1679 static const struct wacom_features wacom_features_0x18 =
1680         { "Wacom BambooFun 6x8",  WACOM_PKGLEN_BBFUN,     21648, 13530,  511,
1681           63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1682 static const struct wacom_features wacom_features_0x19 =
1683         { "Wacom Bamboo1 Medium", WACOM_PKGLEN_GRAPHIRE,  16704, 12064,  511,
1684           63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
1685 static const struct wacom_features wacom_features_0x60 =
1686         { "Wacom Volito",         WACOM_PKGLEN_GRAPHIRE,   5104,  3712,  511,
1687           63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
1688 static const struct wacom_features wacom_features_0x61 =
1689         { "Wacom PenStation2",    WACOM_PKGLEN_GRAPHIRE,   3250,  2320,  255,
1690           63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
1691 static const struct wacom_features wacom_features_0x62 =
1692         { "Wacom Volito2 4x5",    WACOM_PKGLEN_GRAPHIRE,   5104,  3712,  511,
1693           63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
1694 static const struct wacom_features wacom_features_0x63 =
1695         { "Wacom Volito2 2x3",    WACOM_PKGLEN_GRAPHIRE,   3248,  2320,  511,
1696           63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
1697 static const struct wacom_features wacom_features_0x64 =
1698         { "Wacom PenPartner2",    WACOM_PKGLEN_GRAPHIRE,   3250,  2320,  511,
1699           63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
1700 static const struct wacom_features wacom_features_0x65 =
1701         { "Wacom Bamboo",         WACOM_PKGLEN_BBFUN,     14760,  9225,  511,
1702           63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1703 static const struct wacom_features wacom_features_0x69 =
1704         { "Wacom Bamboo1",        WACOM_PKGLEN_GRAPHIRE,   5104,  3712,  511,
1705           63, GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
1706 static const struct wacom_features wacom_features_0x6A =
1707         { "Wacom Bamboo1 4x6",    WACOM_PKGLEN_GRAPHIRE,  14760,  9225, 1023,
1708           63, GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1709 static const struct wacom_features wacom_features_0x6B =
1710         { "Wacom Bamboo1 5x8",    WACOM_PKGLEN_GRAPHIRE,  21648, 13530, 1023,
1711           63, GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1712 static const struct wacom_features wacom_features_0x20 =
1713         { "Wacom Intuos 4x5",     WACOM_PKGLEN_INTUOS,    12700, 10600, 1023,
1714           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1715 static const struct wacom_features wacom_features_0x21 =
1716         { "Wacom Intuos 6x8",     WACOM_PKGLEN_INTUOS,    20320, 16240, 1023,
1717           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1718 static const struct wacom_features wacom_features_0x22 =
1719         { "Wacom Intuos 9x12",    WACOM_PKGLEN_INTUOS,    30480, 24060, 1023,
1720           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1721 static const struct wacom_features wacom_features_0x23 =
1722         { "Wacom Intuos 12x12",   WACOM_PKGLEN_INTUOS,    30480, 31680, 1023,
1723           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1724 static const struct wacom_features wacom_features_0x24 =
1725         { "Wacom Intuos 12x18",   WACOM_PKGLEN_INTUOS,    45720, 31680, 1023,
1726           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1727 static const struct wacom_features wacom_features_0x30 =
1728         { "Wacom PL400",          WACOM_PKGLEN_GRAPHIRE,   5408,  4056,  255,
1729           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1730 static const struct wacom_features wacom_features_0x31 =
1731         { "Wacom PL500",          WACOM_PKGLEN_GRAPHIRE,   6144,  4608,  255,
1732           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1733 static const struct wacom_features wacom_features_0x32 =
1734         { "Wacom PL600",          WACOM_PKGLEN_GRAPHIRE,   6126,  4604,  255,
1735           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1736 static const struct wacom_features wacom_features_0x33 =
1737         { "Wacom PL600SX",        WACOM_PKGLEN_GRAPHIRE,   6260,  5016,  255,
1738           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1739 static const struct wacom_features wacom_features_0x34 =
1740         { "Wacom PL550",          WACOM_PKGLEN_GRAPHIRE,   6144,  4608,  511,
1741           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1742 static const struct wacom_features wacom_features_0x35 =
1743         { "Wacom PL800",          WACOM_PKGLEN_GRAPHIRE,   7220,  5780,  511,
1744           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1745 static const struct wacom_features wacom_features_0x37 =
1746         { "Wacom PL700",          WACOM_PKGLEN_GRAPHIRE,   6758,  5406,  511,
1747           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1748 static const struct wacom_features wacom_features_0x38 =
1749         { "Wacom PL510",          WACOM_PKGLEN_GRAPHIRE,   6282,  4762,  511,
1750           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1751 static const struct wacom_features wacom_features_0x39 =
1752         { "Wacom DTU710",         WACOM_PKGLEN_GRAPHIRE,  34080, 27660,  511,
1753           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1754 static const struct wacom_features wacom_features_0xC4 =
1755         { "Wacom DTF521",         WACOM_PKGLEN_GRAPHIRE,   6282,  4762,  511,
1756           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1757 static const struct wacom_features wacom_features_0xC0 =
1758         { "Wacom DTF720",         WACOM_PKGLEN_GRAPHIRE,   6858,  5506,  511,
1759           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1760 static const struct wacom_features wacom_features_0xC2 =
1761         { "Wacom DTF720a",        WACOM_PKGLEN_GRAPHIRE,   6858,  5506,  511,
1762           0, PL, WACOM_PL_RES, WACOM_PL_RES };
1763 static const struct wacom_features wacom_features_0x03 =
1764         { "Wacom Cintiq Partner", WACOM_PKGLEN_GRAPHIRE,  20480, 15360,  511,
1765           0, PTU, WACOM_PL_RES, WACOM_PL_RES };
1766 static const struct wacom_features wacom_features_0x41 =
1767         { "Wacom Intuos2 4x5",    WACOM_PKGLEN_INTUOS,    12700, 10600, 1023,
1768           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1769 static const struct wacom_features wacom_features_0x42 =
1770         { "Wacom Intuos2 6x8",    WACOM_PKGLEN_INTUOS,    20320, 16240, 1023,
1771           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1772 static const struct wacom_features wacom_features_0x43 =
1773         { "Wacom Intuos2 9x12",   WACOM_PKGLEN_INTUOS,    30480, 24060, 1023,
1774           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1775 static const struct wacom_features wacom_features_0x44 =
1776         { "Wacom Intuos2 12x12",  WACOM_PKGLEN_INTUOS,    30480, 31680, 1023,
1777           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1778 static const struct wacom_features wacom_features_0x45 =
1779         { "Wacom Intuos2 12x18",  WACOM_PKGLEN_INTUOS,    45720, 31680, 1023,
1780           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1781 static const struct wacom_features wacom_features_0xB0 =
1782         { "Wacom Intuos3 4x5",    WACOM_PKGLEN_INTUOS,    25400, 20320, 1023,
1783           63, INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1784 static const struct wacom_features wacom_features_0xB1 =
1785         { "Wacom Intuos3 6x8",    WACOM_PKGLEN_INTUOS,    40640, 30480, 1023,
1786           63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1787 static const struct wacom_features wacom_features_0xB2 =
1788         { "Wacom Intuos3 9x12",   WACOM_PKGLEN_INTUOS,    60960, 45720, 1023,
1789           63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1790 static const struct wacom_features wacom_features_0xB3 =
1791         { "Wacom Intuos3 12x12",  WACOM_PKGLEN_INTUOS,    60960, 60960, 1023,
1792           63, INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1793 static const struct wacom_features wacom_features_0xB4 =
1794         { "Wacom Intuos3 12x19",  WACOM_PKGLEN_INTUOS,    97536, 60960, 1023,
1795           63, INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1796 static const struct wacom_features wacom_features_0xB5 =
1797         { "Wacom Intuos3 6x11",   WACOM_PKGLEN_INTUOS,    54204, 31750, 1023,
1798           63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1799 static const struct wacom_features wacom_features_0xB7 =
1800         { "Wacom Intuos3 4x6",    WACOM_PKGLEN_INTUOS,    31496, 19685, 1023,
1801           63, INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1802 static const struct wacom_features wacom_features_0xB8 =
1803         { "Wacom Intuos4 4x6",    WACOM_PKGLEN_INTUOS,    31496, 19685, 2047,
1804           63, INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1805 static const struct wacom_features wacom_features_0xB9 =
1806         { "Wacom Intuos4 6x9",    WACOM_PKGLEN_INTUOS,    44704, 27940, 2047,
1807           63, INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1808 static const struct wacom_features wacom_features_0xBA =
1809         { "Wacom Intuos4 8x13",   WACOM_PKGLEN_INTUOS,    65024, 40640, 2047,
1810           63, INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1811 static const struct wacom_features wacom_features_0xBB =
1812         { "Wacom Intuos4 12x19",  WACOM_PKGLEN_INTUOS,    97536, 60960, 2047,
1813           63, INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1814 static const struct wacom_features wacom_features_0xBC =
1815         { "Wacom Intuos4 WL",     WACOM_PKGLEN_INTUOS,    40840, 25400, 2047,
1816           63, INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1817 static const struct wacom_features wacom_features_0x26 =
1818         { "Wacom Intuos5 touch S", WACOM_PKGLEN_INTUOS,  31496, 19685, 2047,
1819           63, INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
1820           .touch_max = 16 };
1821 static const struct wacom_features wacom_features_0x27 =
1822         { "Wacom Intuos5 touch M", WACOM_PKGLEN_INTUOS,  44704, 27940, 2047,
1823           63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
1824           .touch_max = 16 };
1825 static const struct wacom_features wacom_features_0x28 =
1826         { "Wacom Intuos5 touch L", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047,
1827           63, INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
1828           .touch_max = 16 };
1829 static const struct wacom_features wacom_features_0x29 =
1830         { "Wacom Intuos5 S", WACOM_PKGLEN_INTUOS,  31496, 19685, 2047,
1831           63, INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1832 static const struct wacom_features wacom_features_0x2A =
1833         { "Wacom Intuos5 M", WACOM_PKGLEN_INTUOS,  44704, 27940, 2047,
1834           63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1835 static const struct wacom_features wacom_features_0xF4 =
1836         { "Wacom Cintiq 24HD",    WACOM_PKGLEN_INTUOS,   104480, 65600, 2047,
1837           63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1838 static const struct wacom_features wacom_features_0x3F =
1839         { "Wacom Cintiq 21UX",    WACOM_PKGLEN_INTUOS,    87200, 65600, 1023,
1840           63, CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1841 static const struct wacom_features wacom_features_0xC5 =
1842         { "Wacom Cintiq 20WSX",   WACOM_PKGLEN_INTUOS,    86680, 54180, 1023,
1843           63, WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1844 static const struct wacom_features wacom_features_0xC6 =
1845         { "Wacom Cintiq 12WX",    WACOM_PKGLEN_INTUOS,    53020, 33440, 1023,
1846           63, WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1847 static const struct wacom_features wacom_features_0xC7 =
1848         { "Wacom DTU1931",        WACOM_PKGLEN_GRAPHIRE,  37832, 30305,  511,
1849           0, PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1850 static const struct wacom_features wacom_features_0xCE =
1851         { "Wacom DTU2231",        WACOM_PKGLEN_GRAPHIRE,  47864, 27011,  511,
1852           0, DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1853 static const struct wacom_features wacom_features_0xF0 =
1854         { "Wacom DTU1631",        WACOM_PKGLEN_GRAPHIRE,  34623, 19553,  511,
1855           0, DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1856 static const struct wacom_features wacom_features_0xCC =
1857         { "Wacom Cintiq 21UX2",   WACOM_PKGLEN_INTUOS,    87200, 65600, 2047,
1858           63, WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
1859 static const struct wacom_features wacom_features_0x90 =
1860         { "Wacom ISDv4 90",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,
1861           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1862 static const struct wacom_features wacom_features_0x93 =
1863         { "Wacom ISDv4 93",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,
1864           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1865 static const struct wacom_features wacom_features_0x97 =
1866         { "Wacom ISDv4 97",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  511,
1867           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1868 static const struct wacom_features wacom_features_0x9A =
1869         { "Wacom ISDv4 9A",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,
1870           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1871 static const struct wacom_features wacom_features_0x9F =
1872         { "Wacom ISDv4 9F",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,
1873           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1874 static const struct wacom_features wacom_features_0xE2 =
1875         { "Wacom ISDv4 E2",       WACOM_PKGLEN_TPC2FG,    26202, 16325,  255,
1876           0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1877           .touch_max = 2 };
1878 static const struct wacom_features wacom_features_0xE3 =
1879         { "Wacom ISDv4 E3",       WACOM_PKGLEN_TPC2FG,    26202, 16325,  255,
1880           0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1881           .touch_max = 2 };
1882 static const struct wacom_features wacom_features_0xE5 =
1883         { "Wacom ISDv4 E5",       WACOM_PKGLEN_MTOUCH,    26202, 16325,  255,
1884           0, MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1885 static const struct wacom_features wacom_features_0xE6 =
1886         { "Wacom ISDv4 E6",       WACOM_PKGLEN_TPC2FG,    27760, 15694,  255,
1887           0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1888         .touch_max = 2 };
1889 static const struct wacom_features wacom_features_0xEC =
1890         { "Wacom ISDv4 EC",       WACOM_PKGLEN_GRAPHIRE,  25710, 14500,  255,
1891           0, TABLETPC,    WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1892 static const struct wacom_features wacom_features_0xED =
1893         { "Wacom ISDv4 ED",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,
1894           0, TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1895 static const struct wacom_features wacom_features_0xEF =
1896         { "Wacom ISDv4 EF",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,
1897           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1898 static const struct wacom_features wacom_features_0x47 =
1899         { "Wacom Intuos2 6x8",    WACOM_PKGLEN_INTUOS,    20320, 16240, 1023,
1900           31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1901 static const struct wacom_features wacom_features_0x84 =
1902         { "Wacom Wireless Receiver", WACOM_PKGLEN_WIRELESS, 0, 0, 0,
1903           0, WIRELESS, 0, 0, .touch_max = 16 };
1904 static const struct wacom_features wacom_features_0xD0 =
1905         { "Wacom Bamboo 2FG",     WACOM_PKGLEN_BBFUN,     14720,  9200, 1023,
1906           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1907           .touch_max = 2 };
1908 static const struct wacom_features wacom_features_0xD1 =
1909         { "Wacom Bamboo 2FG 4x5", WACOM_PKGLEN_BBFUN,     14720,  9200, 1023,
1910           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1911           .touch_max = 2 };
1912 static const struct wacom_features wacom_features_0xD2 =
1913         { "Wacom Bamboo Craft",   WACOM_PKGLEN_BBFUN,     14720,  9200, 1023,
1914           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1915 static const struct wacom_features wacom_features_0xD3 =
1916         { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN,     21648, 13700, 1023,
1917           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1918           .touch_max = 2 };
1919 static const struct wacom_features wacom_features_0xD4 =
1920         { "Wacom Bamboo Pen",     WACOM_PKGLEN_BBFUN,     14720,  9200, 1023,
1921           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1922 static const struct wacom_features wacom_features_0xD5 =
1923         { "Wacom Bamboo Pen 6x8",     WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
1924           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1925 static const struct wacom_features wacom_features_0xD6 =
1926         { "Wacom BambooPT 2FG 4x5", WACOM_PKGLEN_BBFUN,   14720,  9200, 1023,
1927           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1928           .touch_max = 2 };
1929 static const struct wacom_features wacom_features_0xD7 =
1930         { "Wacom BambooPT 2FG Small", WACOM_PKGLEN_BBFUN, 14720,  9200, 1023,
1931           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1932           .touch_max = 2 };
1933 static const struct wacom_features wacom_features_0xD8 =
1934         { "Wacom Bamboo Comic 2FG", WACOM_PKGLEN_BBFUN,   21648, 13700, 1023,
1935           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1936           .touch_max = 2 };
1937 static const struct wacom_features wacom_features_0xDA =
1938         { "Wacom Bamboo 2FG 4x5 SE", WACOM_PKGLEN_BBFUN,  14720,  9200, 1023,
1939           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1940           .touch_max = 2 };
1941 static struct wacom_features wacom_features_0xDB =
1942         { "Wacom Bamboo 2FG 6x8 SE", WACOM_PKGLEN_BBFUN,  21648, 13700, 1023,
1943           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1944           .touch_max = 2 };
1945 static const struct wacom_features wacom_features_0xDD =
1946         { "Wacom Bamboo Connect", WACOM_PKGLEN_BBPEN,     14720,  9200, 1023,
1947           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1948 static const struct wacom_features wacom_features_0xDE =
1949         { "Wacom Bamboo 16FG 4x5", WACOM_PKGLEN_BBPEN,    14720,  9200, 1023,
1950           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1951           .touch_max = 16 };
1952 static const struct wacom_features wacom_features_0xDF =
1953         { "Wacom Bamboo 16FG 6x8", WACOM_PKGLEN_BBPEN,    21648, 13700, 1023,
1954           31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
1955           .touch_max = 16 };
1956 static const struct wacom_features wacom_features_0x6004 =
1957         { "ISD-V4",               WACOM_PKGLEN_GRAPHIRE,  12800,  8000,  255,
1958           0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1959
1960 #define USB_DEVICE_WACOM(prod)                                  \
1961         USB_DEVICE(USB_VENDOR_ID_WACOM, prod),                  \
1962         .driver_info = (kernel_ulong_t)&wacom_features_##prod
1963
1964 #define USB_DEVICE_DETAILED(prod, class, sub, proto)                    \
1965         USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_WACOM, prod, class, \
1966                                       sub, proto),                      \
1967         .driver_info = (kernel_ulong_t)&wacom_features_##prod
1968
1969 #define USB_DEVICE_LENOVO(prod)                                 \
1970         USB_DEVICE(USB_VENDOR_ID_LENOVO, prod),                 \
1971         .driver_info = (kernel_ulong_t)&wacom_features_##prod
1972
1973 const struct usb_device_id wacom_ids[] = {
1974         { USB_DEVICE_WACOM(0x00) },
1975         { USB_DEVICE_WACOM(0x10) },
1976         { USB_DEVICE_WACOM(0x11) },
1977         { USB_DEVICE_WACOM(0x12) },
1978         { USB_DEVICE_WACOM(0x13) },
1979         { USB_DEVICE_WACOM(0x14) },
1980         { USB_DEVICE_WACOM(0x15) },
1981         { USB_DEVICE_WACOM(0x16) },
1982         { USB_DEVICE_WACOM(0x17) },
1983         { USB_DEVICE_WACOM(0x18) },
1984         { USB_DEVICE_WACOM(0x19) },
1985         { USB_DEVICE_WACOM(0x60) },
1986         { USB_DEVICE_WACOM(0x61) },
1987         { USB_DEVICE_WACOM(0x62) },
1988         { USB_DEVICE_WACOM(0x63) },
1989         { USB_DEVICE_WACOM(0x64) },
1990         { USB_DEVICE_WACOM(0x65) },
1991         { USB_DEVICE_WACOM(0x69) },
1992         { USB_DEVICE_WACOM(0x6A) },
1993         { USB_DEVICE_WACOM(0x6B) },
1994         { USB_DEVICE_WACOM(0x20) },
1995         { USB_DEVICE_WACOM(0x21) },
1996         { USB_DEVICE_WACOM(0x22) },
1997         { USB_DEVICE_WACOM(0x23) },
1998         { USB_DEVICE_WACOM(0x24) },
1999         { USB_DEVICE_WACOM(0x30) },
2000         { USB_DEVICE_WACOM(0x31) },
2001         { USB_DEVICE_WACOM(0x32) },
2002         { USB_DEVICE_WACOM(0x33) },
2003         { USB_DEVICE_WACOM(0x34) },
2004         { USB_DEVICE_WACOM(0x35) },
2005         { USB_DEVICE_WACOM(0x37) },
2006         { USB_DEVICE_WACOM(0x38) },
2007         { USB_DEVICE_WACOM(0x39) },
2008         { USB_DEVICE_WACOM(0xC4) },
2009         { USB_DEVICE_WACOM(0xC0) },
2010         { USB_DEVICE_WACOM(0xC2) },
2011         { USB_DEVICE_WACOM(0x03) },
2012         { USB_DEVICE_WACOM(0x41) },
2013         { USB_DEVICE_WACOM(0x42) },
2014         { USB_DEVICE_WACOM(0x43) },
2015         { USB_DEVICE_WACOM(0x44) },
2016         { USB_DEVICE_WACOM(0x45) },
2017         { USB_DEVICE_WACOM(0xB0) },
2018         { USB_DEVICE_WACOM(0xB1) },
2019         { USB_DEVICE_WACOM(0xB2) },
2020         { USB_DEVICE_WACOM(0xB3) },
2021         { USB_DEVICE_WACOM(0xB4) },
2022         { USB_DEVICE_WACOM(0xB5) },
2023         { USB_DEVICE_WACOM(0xB7) },
2024         { USB_DEVICE_WACOM(0xB8) },
2025         { USB_DEVICE_WACOM(0xB9) },
2026         { USB_DEVICE_WACOM(0xBA) },
2027         { USB_DEVICE_WACOM(0xBB) },
2028         { USB_DEVICE_WACOM(0xBC) },
2029         { USB_DEVICE_WACOM(0x26) },
2030         { USB_DEVICE_WACOM(0x27) },
2031         { USB_DEVICE_WACOM(0x28) },
2032         { USB_DEVICE_WACOM(0x29) },
2033         { USB_DEVICE_WACOM(0x2A) },
2034         { USB_DEVICE_WACOM(0x3F) },
2035         { USB_DEVICE_WACOM(0xC5) },
2036         { USB_DEVICE_WACOM(0xC6) },
2037         { USB_DEVICE_WACOM(0xC7) },
2038         /*
2039          * DTU-2231 has two interfaces on the same configuration,
2040          * only one is used.
2041          */
2042         { USB_DEVICE_DETAILED(0xCE, USB_CLASS_HID,
2043                               USB_INTERFACE_SUBCLASS_BOOT,
2044                               USB_INTERFACE_PROTOCOL_MOUSE) },
2045         { USB_DEVICE_WACOM(0x84) },
2046         { USB_DEVICE_WACOM(0xD0) },
2047         { USB_DEVICE_WACOM(0xD1) },
2048         { USB_DEVICE_WACOM(0xD2) },
2049         { USB_DEVICE_WACOM(0xD3) },
2050         { USB_DEVICE_WACOM(0xD4) },
2051         { USB_DEVICE_WACOM(0xD5) },
2052         { USB_DEVICE_WACOM(0xD6) },
2053         { USB_DEVICE_WACOM(0xD7) },
2054         { USB_DEVICE_WACOM(0xD8) },
2055         { USB_DEVICE_WACOM(0xDA) },
2056         { USB_DEVICE_WACOM(0xDB) },
2057         { USB_DEVICE_WACOM(0xDD) },
2058         { USB_DEVICE_WACOM(0xDE) },
2059         { USB_DEVICE_WACOM(0xDF) },
2060         { USB_DEVICE_WACOM(0xF0) },
2061         { USB_DEVICE_WACOM(0xCC) },
2062         { USB_DEVICE_WACOM(0x90) },
2063         { USB_DEVICE_WACOM(0x93) },
2064         { USB_DEVICE_WACOM(0x97) },
2065         { USB_DEVICE_WACOM(0x9A) },
2066         { USB_DEVICE_WACOM(0x9F) },
2067         { USB_DEVICE_WACOM(0xE2) },
2068         { USB_DEVICE_WACOM(0xE3) },
2069         { USB_DEVICE_WACOM(0xE5) },
2070         { USB_DEVICE_WACOM(0xE6) },
2071         { USB_DEVICE_WACOM(0xEC) },
2072         { USB_DEVICE_WACOM(0xED) },
2073         { USB_DEVICE_WACOM(0xEF) },
2074         { USB_DEVICE_WACOM(0x47) },
2075         { USB_DEVICE_WACOM(0xF4) },
2076         { USB_DEVICE_LENOVO(0x6004) },
2077         { }
2078 };
2079 MODULE_DEVICE_TABLE(usb, wacom_ids);