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