Merge branch 'acpica' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[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 #include "wacom.h"
15 #include "wacom_wac.h"
16
17 static int wacom_penpartner_irq(struct wacom_wac *wacom, void *wcombo)
18 {
19         unsigned char *data = wacom->data;
20
21         switch (data[0]) {
22                 case 1:
23                         if (data[5] & 0x80) {
24                                 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
25                                 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
26                                 wacom_report_key(wcombo, wacom->tool[0], 1);
27                                 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
28                                 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
29                                 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
30                                 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127);
31                                 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -127));
32                                 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40));
33                         } else {
34                                 wacom_report_key(wcombo, wacom->tool[0], 0);
35                                 wacom_report_abs(wcombo, ABS_MISC, 0); /* report tool id */
36                                 wacom_report_abs(wcombo, ABS_PRESSURE, -1);
37                                 wacom_report_key(wcombo, BTN_TOUCH, 0);
38                         }
39                         break;
40                 case 2:
41                         wacom_report_key(wcombo, BTN_TOOL_PEN, 1);
42                         wacom_report_abs(wcombo, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
43                         wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
44                         wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
45                         wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127);
46                         wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
47                         wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40));
48                         break;
49                 default:
50                         printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
51                         return 0;
52         }
53         return 1;
54 }
55
56 static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
57 {
58         unsigned char *data = wacom->data;
59         int prox, pressure;
60
61         if (data[0] != WACOM_REPORT_PENABLED) {
62                 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
63                 return 0;
64         }
65
66         prox = data[1] & 0x40;
67
68         if (prox) {
69                 wacom->id[0] = ERASER_DEVICE_ID;
70                 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
71                 if (wacom->features->pressure_max > 255)
72                         pressure = (pressure << 1) | ((data[4] >> 6) & 1);
73                 pressure += (wacom->features->pressure_max + 1) / 2;
74
75                 /*
76                  * if going from out of proximity into proximity select between the eraser
77                  * and the pen based on the state of the stylus2 button, choose eraser if
78                  * pressed else choose pen. if not a proximity change from out to in, send
79                  * an out of proximity for previous tool then a in for new tool.
80                  */
81                 if (!wacom->tool[0]) {
82                         /* Eraser bit set for DTF */
83                         if (data[1] & 0x10)
84                                 wacom->tool[1] = BTN_TOOL_RUBBER;
85                         else
86                                 /* Going into proximity select tool */
87                                 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
88                 } else {
89                         /* was entered with stylus2 pressed */
90                         if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
91                                 /* report out proximity for previous tool */
92                                 wacom_report_key(wcombo, wacom->tool[1], 0);
93                                 wacom_input_sync(wcombo);
94                                 wacom->tool[1] = BTN_TOOL_PEN;
95                                 return 0;
96                         }
97                 }
98                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
99                         /* Unknown tool selected default to pen tool */
100                         wacom->tool[1] = BTN_TOOL_PEN;
101                         wacom->id[0] = STYLUS_DEVICE_ID;
102                 }
103                 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */
104                 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
105                 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
106                 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
107                 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
108
109                 wacom_report_key(wcombo, BTN_TOUCH, data[4] & 0x08);
110                 wacom_report_key(wcombo, BTN_STYLUS, data[4] & 0x10);
111                 /* Only allow the stylus2 button to be reported for the pen tool. */
112                 wacom_report_key(wcombo, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
113         } else {
114                 /* report proximity-out of a (valid) tool */
115                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
116                         /* Unknown tool selected default to pen tool */
117                         wacom->tool[1] = BTN_TOOL_PEN;
118                 }
119                 wacom_report_key(wcombo, wacom->tool[1], prox);
120         }
121
122         wacom->tool[0] = prox; /* Save proximity state */
123         return 1;
124 }
125
126 static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
127 {
128         unsigned char *data = wacom->data;
129
130         if (data[0] != WACOM_REPORT_PENABLED) {
131                 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
132                 return 0;
133         }
134
135         if (data[1] & 0x04) {
136                 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20);
137                 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08);
138                 wacom->id[0] = ERASER_DEVICE_ID;
139         } else {
140                 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20);
141                 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
142                 wacom->id[0] = STYLUS_DEVICE_ID;
143         }
144         wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
145         wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
146         wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
147         wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
148         wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
149         wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10);
150         return 1;
151 }
152
153 static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
154 {
155         unsigned char *data = wacom->data;
156         int x, y, rw;
157         static int penData = 0;
158
159         if (data[0] != WACOM_REPORT_PENABLED) {
160                 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
161                 return 0;
162         }
163
164         if (data[1] & 0x80) {
165                 /* in prox and not a pad data */
166                 penData = 1;
167
168                 switch ((data[1] >> 5) & 3) {
169
170                         case 0: /* Pen */
171                                 wacom->tool[0] = BTN_TOOL_PEN;
172                                 wacom->id[0] = STYLUS_DEVICE_ID;
173                                 break;
174
175                         case 1: /* Rubber */
176                                 wacom->tool[0] = BTN_TOOL_RUBBER;
177                                 wacom->id[0] = ERASER_DEVICE_ID;
178                                 break;
179
180                         case 2: /* Mouse with wheel */
181                                 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04);
182                                 if (wacom->features->type == WACOM_G4 ||
183                                                 wacom->features->type == WACOM_MO) {
184                                         rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
185                                         wacom_report_rel(wcombo, REL_WHEEL, -rw);
186                                 } else
187                                         wacom_report_rel(wcombo, REL_WHEEL, -(signed char) data[6]);
188                                 /* fall through */
189
190                         case 3: /* Mouse without wheel */
191                                 wacom->tool[0] = BTN_TOOL_MOUSE;
192                                 wacom->id[0] = CURSOR_DEVICE_ID;
193                                 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
194                                 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
195                                 if (wacom->features->type == WACOM_G4 ||
196                                                 wacom->features->type == WACOM_MO)
197                                         wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f);
198                                 else
199                                         wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
200                                 break;
201                 }
202                 x = wacom_le16_to_cpu(&data[2]);
203                 y = wacom_le16_to_cpu(&data[4]);
204                 wacom_report_abs(wcombo, ABS_X, x);
205                 wacom_report_abs(wcombo, ABS_Y, y);
206                 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
207                         wacom_report_abs(wcombo, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
208                         wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
209                         wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
210                         wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
211                 }
212                 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
213                 wacom_report_key(wcombo, wacom->tool[0], 1);
214         } else if (wacom->id[0]) {
215                 wacom_report_abs(wcombo, ABS_X, 0);
216                 wacom_report_abs(wcombo, ABS_Y, 0);
217                 if (wacom->tool[0] == BTN_TOOL_MOUSE) {
218                         wacom_report_key(wcombo, BTN_LEFT, 0);
219                         wacom_report_key(wcombo, BTN_RIGHT, 0);
220                         wacom_report_abs(wcombo, ABS_DISTANCE, 0);
221                 } else {
222                         wacom_report_abs(wcombo, ABS_PRESSURE, 0);
223                         wacom_report_key(wcombo, BTN_TOUCH, 0);
224                         wacom_report_key(wcombo, BTN_STYLUS, 0);
225                         wacom_report_key(wcombo, BTN_STYLUS2, 0);
226                 }
227                 wacom->id[0] = 0;
228                 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
229                 wacom_report_key(wcombo, wacom->tool[0], 0);
230         }
231
232         /* send pad data */
233         switch (wacom->features->type) {
234             case WACOM_G4:
235                 if (data[7] & 0xf8) {
236                         if (penData) {
237                                 wacom_input_sync(wcombo); /* sync last event */
238                                 if (!wacom->id[0])
239                                         penData = 0;
240                         }
241                         wacom->id[1] = PAD_DEVICE_ID;
242                         wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
243                         wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
244                         rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
245                         wacom_report_rel(wcombo, REL_WHEEL, rw);
246                         wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
247                         wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
248                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
249                 } else if (wacom->id[1]) {
250                         if (penData) {
251                                 wacom_input_sync(wcombo); /* sync last event */
252                                 if (!wacom->id[0])
253                                         penData = 0;
254                         }
255                         wacom->id[1] = 0;
256                         wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
257                         wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
258                         wacom_report_rel(wcombo, REL_WHEEL, 0);
259                         wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
260                         wacom_report_abs(wcombo, ABS_MISC, 0);
261                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
262                 }
263                 break;
264             case WACOM_MO:
265                 if ((data[7] & 0xf8) || (data[8] & 0xff)) {
266                         if (penData) {
267                                 wacom_input_sync(wcombo); /* sync last event */
268                                 if (!wacom->id[0])
269                                         penData = 0;
270                         }
271                         wacom->id[1] = PAD_DEVICE_ID;
272                         wacom_report_key(wcombo, BTN_0, (data[7] & 0x08));
273                         wacom_report_key(wcombo, BTN_1, (data[7] & 0x20));
274                         wacom_report_key(wcombo, BTN_4, (data[7] & 0x10));
275                         wacom_report_key(wcombo, BTN_5, (data[7] & 0x40));
276                         wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f));
277                         wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
278                         wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
279                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
280                 } else if (wacom->id[1]) {
281                         if (penData) {
282                                 wacom_input_sync(wcombo); /* sync last event */
283                                 if (!wacom->id[0])
284                                         penData = 0;
285                         }
286                         wacom->id[1] = 0;
287                         wacom_report_key(wcombo, BTN_0, (data[7] & 0x08));
288                         wacom_report_key(wcombo, BTN_1, (data[7] & 0x20));
289                         wacom_report_key(wcombo, BTN_4, (data[7] & 0x10));
290                         wacom_report_key(wcombo, BTN_5, (data[7] & 0x40));
291                         wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f));
292                         wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
293                         wacom_report_abs(wcombo, ABS_MISC, 0);
294                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
295                 }
296                 break;
297         }
298         return 1;
299 }
300
301 static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
302 {
303         unsigned char *data = wacom->data;
304         int idx = 0;
305
306         /* tool number */
307         if (wacom->features->type == INTUOS)
308                 idx = data[1] & 0x01;
309
310         /* Enter report */
311         if ((data[1] & 0xfc) == 0xc0) {
312                 /* serial number of the tool */
313                 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
314                         (data[4] << 20) + (data[5] << 12) +
315                         (data[6] << 4) + (data[7] >> 4);
316
317                 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
318                 switch (wacom->id[idx]) {
319                         case 0x812: /* Inking pen */
320                         case 0x801: /* Intuos3 Inking pen */
321                         case 0x20802: /* Intuos4 Classic Pen */
322                         case 0x012:
323                                 wacom->tool[idx] = BTN_TOOL_PENCIL;
324                                 break;
325                         case 0x822: /* Pen */
326                         case 0x842:
327                         case 0x852:
328                         case 0x823: /* Intuos3 Grip Pen */
329                         case 0x813: /* Intuos3 Classic Pen */
330                         case 0x885: /* Intuos3 Marker Pen */
331                         case 0x802: /* Intuos4 Grip Pen Eraser */
332                         case 0x804: /* Intuos4 Marker Pen */
333                         case 0x40802: /* Intuos4 Classic Pen */
334                         case 0x022:
335                                 wacom->tool[idx] = BTN_TOOL_PEN;
336                                 break;
337                         case 0x832: /* Stroke pen */
338                         case 0x032:
339                                 wacom->tool[idx] = BTN_TOOL_BRUSH;
340                                 break;
341                         case 0x007: /* Mouse 4D and 2D */
342                         case 0x09c:
343                         case 0x094:
344                         case 0x017: /* Intuos3 2D Mouse */
345                         case 0x806: /* Intuos4 Mouse */
346                                 wacom->tool[idx] = BTN_TOOL_MOUSE;
347                                 break;
348                         case 0x096: /* Lens cursor */
349                         case 0x097: /* Intuos3 Lens cursor */
350                         case 0x006: /* Intuos4 Lens cursor */
351                                 wacom->tool[idx] = BTN_TOOL_LENS;
352                                 break;
353                         case 0x82a: /* Eraser */
354                         case 0x85a:
355                         case 0x91a:
356                         case 0xd1a:
357                         case 0x0fa:
358                         case 0x82b: /* Intuos3 Grip Pen Eraser */
359                         case 0x81b: /* Intuos3 Classic Pen Eraser */
360                         case 0x91b: /* Intuos3 Airbrush Eraser */
361                         case 0x80c: /* Intuos4 Marker Pen Eraser */
362                         case 0x80a: /* Intuos4 Grip Pen Eraser */
363                         case 0x4080a: /* Intuos4 Classic Pen Eraser */
364                         case 0x90a: /* Intuos4 Airbrush Eraser */
365                                 wacom->tool[idx] = BTN_TOOL_RUBBER;
366                                 break;
367                         case 0xd12:
368                         case 0x912:
369                         case 0x112:
370                         case 0x913: /* Intuos3 Airbrush */
371                         case 0x902: /* Intuos4 Airbrush */
372                                 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
373                                 break;
374                         default: /* Unknown tool */
375                                 wacom->tool[idx] = BTN_TOOL_PEN;
376                 }
377                 return 1;
378         }
379
380         /* Exit report */
381         if ((data[1] & 0xfe) == 0x80) {
382                 /*
383                  * Reset all states otherwise we lose the initial states
384                  * when in-prox next time
385                  */
386                 wacom_report_abs(wcombo, ABS_X, 0);
387                 wacom_report_abs(wcombo, ABS_Y, 0);
388                 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
389                 wacom_report_abs(wcombo, ABS_TILT_X, 0);
390                 wacom_report_abs(wcombo, ABS_TILT_Y, 0);
391                 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
392                         wacom_report_key(wcombo, BTN_LEFT, 0);
393                         wacom_report_key(wcombo, BTN_MIDDLE, 0);
394                         wacom_report_key(wcombo, BTN_RIGHT, 0);
395                         wacom_report_key(wcombo, BTN_SIDE, 0);
396                         wacom_report_key(wcombo, BTN_EXTRA, 0);
397                         wacom_report_abs(wcombo, ABS_THROTTLE, 0);
398                         wacom_report_abs(wcombo, ABS_RZ, 0);
399                 } else {
400                         wacom_report_abs(wcombo, ABS_PRESSURE, 0);
401                         wacom_report_key(wcombo, BTN_STYLUS, 0);
402                         wacom_report_key(wcombo, BTN_STYLUS2, 0);
403                         wacom_report_key(wcombo, BTN_TOUCH, 0);
404                         wacom_report_abs(wcombo, ABS_WHEEL, 0);
405                         if (wacom->features->type >= INTUOS3S)
406                                 wacom_report_abs(wcombo, ABS_Z, 0);
407                 }
408                 wacom_report_key(wcombo, wacom->tool[idx], 0);
409                 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
410                 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
411                 wacom->id[idx] = 0;
412                 return 2;
413         }
414         return 0;
415 }
416
417 static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
418 {
419         unsigned char *data = wacom->data;
420         unsigned int t;
421
422         /* general pen packet */
423         if ((data[1] & 0xb8) == 0xa0) {
424                 t = (data[6] << 2) | ((data[7] >> 6) & 3);
425                 if (wacom->features->type >= INTUOS4S && wacom->features->type <= INTUOS4L)
426                         t = (t << 1) | (data[1] & 1);
427                 wacom_report_abs(wcombo, ABS_PRESSURE, t);
428                 wacom_report_abs(wcombo, ABS_TILT_X,
429                                 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
430                 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
431                 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 2);
432                 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 4);
433                 wacom_report_key(wcombo, BTN_TOUCH, t > 10);
434         }
435
436         /* airbrush second packet */
437         if ((data[1] & 0xbc) == 0xb4) {
438                 wacom_report_abs(wcombo, ABS_WHEEL,
439                                 (data[6] << 2) | ((data[7] >> 6) & 3));
440                 wacom_report_abs(wcombo, ABS_TILT_X,
441                                 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
442                 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
443         }
444         return;
445 }
446
447 static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
448 {
449         unsigned char *data = wacom->data;
450         unsigned int t;
451         int idx = 0, result;
452
453         if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_INTUOSREAD
454                 && data[0] != WACOM_REPORT_INTUOSWRITE && data[0] != WACOM_REPORT_INTUOSPAD) {
455                 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
456                 return 0;
457         }
458
459         /* tool number */
460         if (wacom->features->type == INTUOS)
461                 idx = data[1] & 0x01;
462
463         /* pad packets. Works as a second tool and is always in prox */
464         if (data[0] == WACOM_REPORT_INTUOSPAD) {
465                 /* initiate the pad as a device */
466                 if (wacom->tool[1] != BTN_TOOL_FINGER)
467                         wacom->tool[1] = BTN_TOOL_FINGER;
468
469                 if (wacom->features->type >= INTUOS4S && wacom->features->type <= INTUOS4L) {
470                         wacom_report_key(wcombo, BTN_0, (data[2] & 0x01));
471                         wacom_report_key(wcombo, BTN_1, (data[3] & 0x01));
472                         wacom_report_key(wcombo, BTN_2, (data[3] & 0x02));
473                         wacom_report_key(wcombo, BTN_3, (data[3] & 0x04));
474                         wacom_report_key(wcombo, BTN_4, (data[3] & 0x08));
475                         wacom_report_key(wcombo, BTN_5, (data[3] & 0x10));
476                         wacom_report_key(wcombo, BTN_6, (data[3] & 0x20));
477                         if (data[1] & 0x80) {
478                                 wacom_report_abs(wcombo, ABS_WHEEL, (data[1] & 0x7f));
479                         } else {
480                                 /* Out of proximity, clear wheel value. */
481                                 wacom_report_abs(wcombo, ABS_WHEEL, 0);
482                         }
483                         if (wacom->features->type != INTUOS4S) {
484                                 wacom_report_key(wcombo, BTN_7, (data[3] & 0x40));
485                                 wacom_report_key(wcombo, BTN_8, (data[3] & 0x80));
486                         }
487                         if (data[1] | (data[2] & 0x01) | data[3]) {
488                                 wacom_report_key(wcombo, wacom->tool[1], 1);
489                                 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
490                         } else {
491                                 wacom_report_key(wcombo, wacom->tool[1], 0);
492                                 wacom_report_abs(wcombo, ABS_MISC, 0);
493                         }
494                 } else {
495                         wacom_report_key(wcombo, BTN_0, (data[5] & 0x01));
496                         wacom_report_key(wcombo, BTN_1, (data[5] & 0x02));
497                         wacom_report_key(wcombo, BTN_2, (data[5] & 0x04));
498                         wacom_report_key(wcombo, BTN_3, (data[5] & 0x08));
499                         wacom_report_key(wcombo, BTN_4, (data[6] & 0x01));
500                         wacom_report_key(wcombo, BTN_5, (data[6] & 0x02));
501                         wacom_report_key(wcombo, BTN_6, (data[6] & 0x04));
502                         wacom_report_key(wcombo, BTN_7, (data[6] & 0x08));
503                         wacom_report_key(wcombo, BTN_8, (data[5] & 0x10));
504                         wacom_report_key(wcombo, BTN_9, (data[6] & 0x10));
505                         wacom_report_abs(wcombo, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
506                         wacom_report_abs(wcombo, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
507
508                         if ((data[5] & 0x1f) | (data[6] & 0x1f) | (data[1] & 0x1f) |
509                                 data[2] | (data[3] & 0x1f) | data[4]) {
510                                 wacom_report_key(wcombo, wacom->tool[1], 1);
511                                 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
512                         } else {
513                                 wacom_report_key(wcombo, wacom->tool[1], 0);
514                                 wacom_report_abs(wcombo, ABS_MISC, 0);
515                         }
516                 }
517                 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff);
518                 return 1;
519         }
520
521         /* process in/out prox events */
522         result = wacom_intuos_inout(wacom, wcombo);
523         if (result)
524                 return result-1;
525
526         /* don't proceed if we don't know the ID */
527         if (!wacom->id[idx])
528                 return 0;
529
530         /* Only large Intuos support Lense Cursor */
531         if ((wacom->tool[idx] == BTN_TOOL_LENS)
532                         && ((wacom->features->type == INTUOS3)
533                         || (wacom->features->type == INTUOS3S)
534                         || (wacom->features->type == INTUOS4)
535                         || (wacom->features->type == INTUOS4S)))
536                 return 0;
537
538         /* Cintiq doesn't send data when RDY bit isn't set */
539         if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
540                  return 0;
541
542         if (wacom->features->type >= INTUOS3S) {
543                 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
544                 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
545                 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
546         } else {
547                 wacom_report_abs(wcombo, ABS_X, wacom_be16_to_cpu(&data[2]));
548                 wacom_report_abs(wcombo, ABS_Y, wacom_be16_to_cpu(&data[4]));
549                 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
550         }
551
552         /* process general packets */
553         wacom_intuos_general(wacom, wcombo);
554
555         /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
556         if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
557
558                 if (data[1] & 0x02) {
559                         /* Rotation packet */
560                         if (wacom->features->type >= INTUOS3S) {
561                                 /* I3 marker pen rotation */
562                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
563                                 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
564                                         ((t-1) / 2 + 450)) : (450 - t / 2) ;
565                                 wacom_report_abs(wcombo, ABS_Z, t);
566                         } else {
567                                 /* 4D mouse rotation packet */
568                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
569                                 wacom_report_abs(wcombo, ABS_RZ, (data[7] & 0x20) ?
570                                         ((t - 1) / 2) : -t / 2);
571                         }
572
573                 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3S) {
574                         /* 4D mouse packet */
575                         wacom_report_key(wcombo, BTN_LEFT,   data[8] & 0x01);
576                         wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
577                         wacom_report_key(wcombo, BTN_RIGHT,  data[8] & 0x04);
578
579                         wacom_report_key(wcombo, BTN_SIDE,   data[8] & 0x20);
580                         wacom_report_key(wcombo, BTN_EXTRA,  data[8] & 0x10);
581                         t = (data[6] << 2) | ((data[7] >> 6) & 3);
582                         wacom_report_abs(wcombo, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
583
584                 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
585                         /* I4 mouse */
586                         if (wacom->features->type >= INTUOS4S && wacom->features->type <= INTUOS4L) {
587                                 wacom_report_key(wcombo, BTN_LEFT,   data[6] & 0x01);
588                                 wacom_report_key(wcombo, BTN_MIDDLE, data[6] & 0x02);
589                                 wacom_report_key(wcombo, BTN_RIGHT,  data[6] & 0x04);
590                                 wacom_report_rel(wcombo, REL_WHEEL, ((data[7] & 0x80) >> 7)
591                                                  - ((data[7] & 0x40) >> 6));
592                                 wacom_report_key(wcombo, BTN_SIDE,   data[6] & 0x08);
593                                 wacom_report_key(wcombo, BTN_EXTRA,  data[6] & 0x10);
594
595                                 wacom_report_abs(wcombo, ABS_TILT_X,
596                                         ((data[7] << 1) & 0x7e) | (data[8] >> 7));
597                                 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
598                         } else {
599                                 /* 2D mouse packet */
600                                 wacom_report_key(wcombo, BTN_LEFT,   data[8] & 0x04);
601                                 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x08);
602                                 wacom_report_key(wcombo, BTN_RIGHT,  data[8] & 0x10);
603                                 wacom_report_rel(wcombo, REL_WHEEL, (data[8] & 0x01)
604                                                  - ((data[8] & 0x02) >> 1));
605
606                                 /* I3 2D mouse side buttons */
607                                 if (wacom->features->type >= INTUOS3S && wacom->features->type <= INTUOS3L) {
608                                         wacom_report_key(wcombo, BTN_SIDE,   data[8] & 0x40);
609                                         wacom_report_key(wcombo, BTN_EXTRA,  data[8] & 0x20);
610                                 }
611                         }
612                 } else if ((wacom->features->type < INTUOS3S || wacom->features->type == INTUOS3L ||
613                                 wacom->features->type == INTUOS4L) &&
614                            wacom->tool[idx] == BTN_TOOL_LENS) {
615                         /* Lens cursor packets */
616                         wacom_report_key(wcombo, BTN_LEFT,   data[8] & 0x01);
617                         wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
618                         wacom_report_key(wcombo, BTN_RIGHT,  data[8] & 0x04);
619                         wacom_report_key(wcombo, BTN_SIDE,   data[8] & 0x10);
620                         wacom_report_key(wcombo, BTN_EXTRA,  data[8] & 0x08);
621                 }
622         }
623
624         wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
625         wacom_report_key(wcombo, wacom->tool[idx], 1);
626         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
627         return 1;
628 }
629
630
631 static void wacom_tpc_finger_in(struct wacom_wac *wacom, void *wcombo, char *data, int idx)
632 {
633         wacom_report_abs(wcombo, ABS_X,
634                 (data[2 + idx * 2] & 0xff) | ((data[3 + idx * 2] & 0x7f) << 8));
635         wacom_report_abs(wcombo, ABS_Y,
636                 (data[6 + idx * 2] & 0xff) | ((data[7 + idx * 2] & 0x7f) << 8));
637         wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]);
638         wacom_report_key(wcombo, wacom->tool[idx], 1);
639         if (idx)
640                 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
641         else
642                 wacom_report_key(wcombo, BTN_TOUCH, 1);
643 }
644
645 static void wacom_tpc_touch_out(struct wacom_wac *wacom, void *wcombo, int idx)
646 {
647         wacom_report_abs(wcombo, ABS_X, 0);
648         wacom_report_abs(wcombo, ABS_Y, 0);
649         wacom_report_abs(wcombo, ABS_MISC, 0);
650         wacom_report_key(wcombo, wacom->tool[idx], 0);
651         if (idx)
652                 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
653         else
654                 wacom_report_key(wcombo, BTN_TOUCH, 0);
655         return;
656 }
657
658 static void wacom_tpc_touch_in(struct wacom_wac *wacom, void *wcombo)
659 {
660         char *data = wacom->data;
661         struct urb *urb = ((struct wacom_combo *)wcombo)->urb;
662         static int firstFinger = 0;
663         static int secondFinger = 0;
664
665         wacom->tool[0] = BTN_TOOL_DOUBLETAP;
666         wacom->id[0] = TOUCH_DEVICE_ID;
667         wacom->tool[1] = BTN_TOOL_TRIPLETAP;
668
669         if (urb->actual_length != WACOM_PKGLEN_TPC1FG) {
670                 switch (data[0]) {
671                         case WACOM_REPORT_TPC1FG:
672                                 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
673                                 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
674                                 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
675                                 wacom_report_key(wcombo, BTN_TOUCH, wacom_le16_to_cpu(&data[6]));
676                                 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]);
677                                 wacom_report_key(wcombo, wacom->tool[0], 1);
678                                 break;
679                         case WACOM_REPORT_TPC2FG:
680                                 /* keep this byte to send proper out-prox event */
681                                 wacom->id[1] = data[1] & 0x03;
682
683                                 if (data[1] & 0x01) {
684                                         wacom_tpc_finger_in(wacom, wcombo, data, 0);
685                                         firstFinger = 1;
686                                 } else if (firstFinger) {
687                                         wacom_tpc_touch_out(wacom, wcombo, 0);
688                                 }
689
690                                 if (data[1] & 0x02) {
691                                         /* sync first finger data */
692                                         if (firstFinger)
693                                                 wacom_input_sync(wcombo);
694
695                                         wacom_tpc_finger_in(wacom, wcombo, data, 1);
696                                         secondFinger = 1;
697                                 } else if (secondFinger) {
698                                         /* sync first finger data */
699                                         if (firstFinger)
700                                                 wacom_input_sync(wcombo);
701
702                                         wacom_tpc_touch_out(wacom, wcombo, 1);
703                                         secondFinger = 0;
704                                 }
705                                 if (!(data[1] & 0x01))
706                                         firstFinger = 0;
707                                 break;
708                 }
709         } else {
710                 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
711                 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
712                 wacom_report_key(wcombo, BTN_TOUCH, 1);
713                 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]);
714                 wacom_report_key(wcombo, wacom->tool[0], 1);
715         }
716         return;
717 }
718
719 static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo)
720 {
721         char *data = wacom->data;
722         int prox = 0, pressure, idx = -1;
723         static int stylusInProx, touchInProx = 1, touchOut;
724         struct urb *urb = ((struct wacom_combo *)wcombo)->urb;
725
726         dbg("wacom_tpc_irq: received report #%d", data[0]);
727
728         if (urb->actual_length == WACOM_PKGLEN_TPC1FG || /* single touch */
729             data[0] == WACOM_REPORT_TPC1FG ||            /* single touch */
730             data[0] == WACOM_REPORT_TPC2FG) {            /* 2FG touch */
731                 if (urb->actual_length == WACOM_PKGLEN_TPC1FG) {  /* with touch */
732                         prox = data[0] & 0x01;
733                 } else {  /* with capacity */
734                         if (data[0] == WACOM_REPORT_TPC1FG)
735                                 /* single touch */
736                                 prox = data[1] & 0x01;
737                         else
738                                 /* 2FG touch data */
739                                 prox = data[1] & 0x03;
740                 }
741
742                 if (!stylusInProx) { /* stylus not in prox */
743                         if (prox) {
744                                 if (touchInProx) {
745                                         wacom_tpc_touch_in(wacom, wcombo);
746                                         touchOut = 1;
747                                         return 1;
748                                 }
749                         } else {
750                                 /* 2FGT out-prox */
751                                 if (data[0] == WACOM_REPORT_TPC2FG) {
752                                         idx = (wacom->id[1] & 0x01) - 1;
753                                         if (idx == 0) {
754                                                 wacom_tpc_touch_out(wacom, wcombo, idx);
755                                                 /* sync first finger event */
756                                                 if (wacom->id[1] & 0x02)
757                                                         wacom_input_sync(wcombo);
758                                         }
759                                         idx = (wacom->id[1] & 0x02) - 1;
760                                         if (idx == 1)
761                                                 wacom_tpc_touch_out(wacom, wcombo, idx);
762                                 } else /* one finger touch */
763                                         wacom_tpc_touch_out(wacom, wcombo, 0);
764                                 touchOut = 0;
765                                 touchInProx = 1;
766                                 return 1;
767                         }
768                 } else if (touchOut || !prox) { /* force touch out-prox */
769                         wacom_tpc_touch_out(wacom, wcombo, 0);
770                         touchOut = 0;
771                         touchInProx = 1;
772                         return 1;
773                 }
774         } else if (data[0] == WACOM_REPORT_PENABLED) { /* Penabled */
775                 prox = data[1] & 0x20;
776
777                 touchInProx = 0;
778
779                 if (prox) { /* in prox */
780                         if (!wacom->id[0]) {
781                                 /* Going into proximity select tool */
782                                 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
783                                 if (wacom->tool[0] == BTN_TOOL_PEN)
784                                         wacom->id[0] = STYLUS_DEVICE_ID;
785                                 else
786                                         wacom->id[0] = ERASER_DEVICE_ID;
787                         }
788                         wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
789                         wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10);
790                         wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
791                         wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
792                         pressure = ((data[7] & 0x01) << 8) | data[6];
793                         if (pressure < 0)
794                                 pressure = wacom->features->pressure_max + pressure + 1;
795                         wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
796                         wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x05);
797                 } else {
798                         wacom_report_abs(wcombo, ABS_X, 0);
799                         wacom_report_abs(wcombo, ABS_Y, 0);
800                         wacom_report_abs(wcombo, ABS_PRESSURE, 0);
801                         wacom_report_key(wcombo, BTN_STYLUS, 0);
802                         wacom_report_key(wcombo, BTN_STYLUS2, 0);
803                         wacom_report_key(wcombo, BTN_TOUCH, 0);
804                         wacom->id[0] = 0;
805                         /* pen is out so touch can be enabled now */
806                         touchInProx = 1;
807                 }
808                 wacom_report_key(wcombo, wacom->tool[0], prox);
809                 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]);
810                 stylusInProx = prox;
811                 return 1;
812         }
813         return 0;
814 }
815
816 int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo)
817 {
818         switch (wacom_wac->features->type) {
819                 case PENPARTNER:
820                         return wacom_penpartner_irq(wacom_wac, wcombo);
821
822                 case PL:
823                         return wacom_pl_irq(wacom_wac, wcombo);
824
825                 case WACOM_G4:
826                 case GRAPHIRE:
827                 case WACOM_MO:
828                         return wacom_graphire_irq(wacom_wac, wcombo);
829
830                 case PTU:
831                         return wacom_ptu_irq(wacom_wac, wcombo);
832
833                 case INTUOS:
834                 case INTUOS3S:
835                 case INTUOS3:
836                 case INTUOS3L:
837                 case INTUOS4S:
838                 case INTUOS4:
839                 case INTUOS4L:
840                 case CINTIQ:
841                 case WACOM_BEE:
842                         return wacom_intuos_irq(wacom_wac, wcombo);
843
844                 case TABLETPC:
845                 case TABLETPC2FG:
846                         return wacom_tpc_irq(wacom_wac, wcombo);
847
848                 default:
849                         return 0;
850         }
851         return 0;
852 }
853
854 void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
855 {
856         switch (wacom_wac->features->type) {
857                 case WACOM_MO:
858                         input_dev_mo(input_dev, wacom_wac);
859                 case WACOM_G4:
860                         input_dev_g4(input_dev, wacom_wac);
861                         /* fall through */
862                 case GRAPHIRE:
863                         input_dev_g(input_dev, wacom_wac);
864                         break;
865                 case WACOM_BEE:
866                         input_dev_bee(input_dev, wacom_wac);
867                 case INTUOS3:
868                 case INTUOS3L:
869                 case CINTIQ:
870                         input_dev_i3(input_dev, wacom_wac);
871                         /* fall through */
872                 case INTUOS3S:
873                         input_dev_i3s(input_dev, wacom_wac);
874                         /* fall through */
875                 case INTUOS:
876                         input_dev_i(input_dev, wacom_wac);
877                         break;
878                 case INTUOS4:
879                 case INTUOS4L:
880                         input_dev_i4(input_dev, wacom_wac);
881                         /* fall through */
882                 case INTUOS4S:
883                         input_dev_i4s(input_dev, wacom_wac);
884                         input_dev_i(input_dev, wacom_wac);
885                         break;
886                 case TABLETPC2FG:
887                         input_dev_tpc2fg(input_dev, wacom_wac);
888                         /* fall through */
889                 case TABLETPC:
890                         input_dev_tpc(input_dev, wacom_wac);
891                         if (wacom_wac->features->device_type != BTN_TOOL_PEN)
892                                 break;  /* no need to process stylus stuff */
893
894                         /* fall through */
895                 case PL:
896                 case PTU:
897                         input_dev_pl(input_dev, wacom_wac);
898                         /* fall through */
899                 case PENPARTNER:
900                         input_dev_pt(input_dev, wacom_wac);
901                         break;
902         }
903         return;
904 }
905
906 static struct wacom_features wacom_features[] = {
907         { "Wacom Penpartner",     WACOM_PKGLEN_PENPRTN,    5040,  3780,  255,  0, PENPARTNER },
908         { "Wacom Graphire",       WACOM_PKGLEN_GRAPHIRE,  10206,  7422,  511, 63, GRAPHIRE },
909         { "Wacom Graphire2 4x5",  WACOM_PKGLEN_GRAPHIRE,  10206,  7422,  511, 63, GRAPHIRE },
910         { "Wacom Graphire2 5x7",  WACOM_PKGLEN_GRAPHIRE,  13918, 10206,  511, 63, GRAPHIRE },
911         { "Wacom Graphire3",      WACOM_PKGLEN_GRAPHIRE,  10208,  7424,  511, 63, GRAPHIRE },
912         { "Wacom Graphire3 6x8",  WACOM_PKGLEN_GRAPHIRE,  16704, 12064,  511, 63, GRAPHIRE },
913         { "Wacom Graphire4 4x5",  WACOM_PKGLEN_GRAPHIRE,  10208,  7424,  511, 63, WACOM_G4 },
914         { "Wacom Graphire4 6x8",  WACOM_PKGLEN_GRAPHIRE,  16704, 12064,  511, 63, WACOM_G4 },
915         { "Wacom BambooFun 4x5",  WACOM_PKGLEN_BBFUN,     14760,  9225,  511, 63, WACOM_MO },
916         { "Wacom BambooFun 6x8",  WACOM_PKGLEN_BBFUN,     21648, 13530,  511, 63, WACOM_MO },
917         { "Wacom Bamboo1 Medium", WACOM_PKGLEN_GRAPHIRE,  16704, 12064,  511, 63, GRAPHIRE },
918         { "Wacom Volito",         WACOM_PKGLEN_GRAPHIRE,   5104,  3712,  511, 63, GRAPHIRE },
919         { "Wacom PenStation2",    WACOM_PKGLEN_GRAPHIRE,   3250,  2320,  255, 63, GRAPHIRE },
920         { "Wacom Volito2 4x5",    WACOM_PKGLEN_GRAPHIRE,   5104,  3712,  511, 63, GRAPHIRE },
921         { "Wacom Volito2 2x3",    WACOM_PKGLEN_GRAPHIRE,   3248,  2320,  511, 63, GRAPHIRE },
922         { "Wacom PenPartner2",    WACOM_PKGLEN_GRAPHIRE,   3250,  2320,  511, 63, GRAPHIRE },
923         { "Wacom Bamboo",         WACOM_PKGLEN_BBFUN,     14760,  9225,  511, 63, WACOM_MO },
924         { "Wacom Bamboo1",        WACOM_PKGLEN_GRAPHIRE,   5104,  3712,  511, 63, GRAPHIRE },
925         { "Wacom Intuos 4x5",     WACOM_PKGLEN_INTUOS,    12700, 10600, 1023, 31, INTUOS },
926         { "Wacom Intuos 6x8",     WACOM_PKGLEN_INTUOS,    20320, 16240, 1023, 31, INTUOS },
927         { "Wacom Intuos 9x12",    WACOM_PKGLEN_INTUOS,    30480, 24060, 1023, 31, INTUOS },
928         { "Wacom Intuos 12x12",   WACOM_PKGLEN_INTUOS,    30480, 31680, 1023, 31, INTUOS },
929         { "Wacom Intuos 12x18",   WACOM_PKGLEN_INTUOS,    45720, 31680, 1023, 31, INTUOS },
930         { "Wacom PL400",          WACOM_PKGLEN_GRAPHIRE,   5408,  4056,  255,  0, PL },
931         { "Wacom PL500",          WACOM_PKGLEN_GRAPHIRE,   6144,  4608,  255,  0, PL },
932         { "Wacom PL600",          WACOM_PKGLEN_GRAPHIRE,   6126,  4604,  255,  0, PL },
933         { "Wacom PL600SX",        WACOM_PKGLEN_GRAPHIRE,   6260,  5016,  255,  0, PL },
934         { "Wacom PL550",          WACOM_PKGLEN_GRAPHIRE,   6144,  4608,  511,  0, PL },
935         { "Wacom PL800",          WACOM_PKGLEN_GRAPHIRE,   7220,  5780,  511,  0, PL },
936         { "Wacom PL700",          WACOM_PKGLEN_GRAPHIRE,   6758,  5406,  511,  0, PL },
937         { "Wacom PL510",          WACOM_PKGLEN_GRAPHIRE,   6282,  4762,  511,  0, PL },
938         { "Wacom DTU710",         WACOM_PKGLEN_GRAPHIRE,  34080, 27660,  511,  0, PL },
939         { "Wacom DTF521",         WACOM_PKGLEN_GRAPHIRE,   6282,  4762,  511,  0, PL },
940         { "Wacom DTF720",         WACOM_PKGLEN_GRAPHIRE,   6858,  5506,  511,  0, PL },
941         { "Wacom DTF720a",        WACOM_PKGLEN_GRAPHIRE,   6858,  5506,  511,  0, PL },
942         { "Wacom Cintiq Partner", WACOM_PKGLEN_GRAPHIRE,  20480, 15360,  511,  0, PTU },
943         { "Wacom Intuos2 4x5",    WACOM_PKGLEN_INTUOS,    12700, 10600, 1023, 31, INTUOS },
944         { "Wacom Intuos2 6x8",    WACOM_PKGLEN_INTUOS,    20320, 16240, 1023, 31, INTUOS },
945         { "Wacom Intuos2 9x12",   WACOM_PKGLEN_INTUOS,    30480, 24060, 1023, 31, INTUOS },
946         { "Wacom Intuos2 12x12",  WACOM_PKGLEN_INTUOS,    30480, 31680, 1023, 31, INTUOS },
947         { "Wacom Intuos2 12x18",  WACOM_PKGLEN_INTUOS,    45720, 31680, 1023, 31, INTUOS },
948         { "Wacom Intuos3 4x5",    WACOM_PKGLEN_INTUOS,    25400, 20320, 1023, 63, INTUOS3S },
949         { "Wacom Intuos3 6x8",    WACOM_PKGLEN_INTUOS,    40640, 30480, 1023, 63, INTUOS3 },
950         { "Wacom Intuos3 9x12",   WACOM_PKGLEN_INTUOS,    60960, 45720, 1023, 63, INTUOS3 },
951         { "Wacom Intuos3 12x12",  WACOM_PKGLEN_INTUOS,    60960, 60960, 1023, 63, INTUOS3L },
952         { "Wacom Intuos3 12x19",  WACOM_PKGLEN_INTUOS,    97536, 60960, 1023, 63, INTUOS3L },
953         { "Wacom Intuos3 6x11",   WACOM_PKGLEN_INTUOS,    54204, 31750, 1023, 63, INTUOS3 },
954         { "Wacom Intuos3 4x6",    WACOM_PKGLEN_INTUOS,    31496, 19685, 1023, 63, INTUOS3S },
955         { "Wacom Intuos4 4x6",    WACOM_PKGLEN_INTUOS,    31496, 19685, 2047, 63, INTUOS4S },
956         { "Wacom Intuos4 6x9",    WACOM_PKGLEN_INTUOS,    44704, 27940, 2047, 63, INTUOS4 },
957         { "Wacom Intuos4 8x13",   WACOM_PKGLEN_INTUOS,    65024, 40640, 2047, 63, INTUOS4L },
958         { "Wacom Intuos4 12x19",  WACOM_PKGLEN_INTUOS,    97536, 60960, 2047, 63, INTUOS4L },
959         { "Wacom Cintiq 21UX",    WACOM_PKGLEN_INTUOS,    87200, 65600, 1023, 63, CINTIQ },
960         { "Wacom Cintiq 20WSX",   WACOM_PKGLEN_INTUOS,    86680, 54180, 1023, 63, WACOM_BEE },
961         { "Wacom Cintiq 12WX",    WACOM_PKGLEN_INTUOS,    53020, 33440, 1023, 63, WACOM_BEE },
962         { "Wacom DTU1931",        WACOM_PKGLEN_GRAPHIRE,  37832, 30305,  511,  0, PL },
963         { "Wacom ISDv4 90",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,  0, TABLETPC },
964         { "Wacom ISDv4 93",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,  0, TABLETPC },
965         { "Wacom ISDv4 9A",       WACOM_PKGLEN_GRAPHIRE,  26202, 16325,  255,  0, TABLETPC },
966         { "Wacom ISDv4 9F",       WACOM_PKGLEN_PENABLED,  26202, 16325,  255,  0, TABLETPC },
967         { "Wacom ISDv4 E2",       WACOM_PKGLEN_TPC2FG,    26202, 16325,  255,  0, TABLETPC2FG },
968         { "Wacom ISDv4 E3",       WACOM_PKGLEN_TPC2FG,    26202, 16325,  255,  0, TABLETPC2FG },
969         { "Wacom Intuos2 6x8",    WACOM_PKGLEN_INTUOS,    20320, 16240, 1023, 31, INTUOS },
970         { }
971 };
972
973 static struct usb_device_id wacom_ids[] = {
974         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
975         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
976         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
977         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
978         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
979         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
980         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
981         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
982         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x17) },
983         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x18) },
984         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x19) },
985         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
986         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
987         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
988         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
989         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
990         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x65) },
991         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x69) },
992         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
993         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
994         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
995         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
996         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
997         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
998         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
999         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
1000         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
1001         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
1002         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
1003         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
1004         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
1005         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
1006         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC4) },
1007         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
1008         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC2) },
1009         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
1010         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
1011         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
1012         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
1013         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
1014         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
1015         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
1016         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
1017         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
1018         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
1019         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
1020         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
1021         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) },
1022         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB8) },
1023         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB9) },
1024         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xBA) },
1025         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xBB) },
1026         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
1027         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC5) },
1028         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6) },
1029         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC7) },
1030         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x90) },
1031         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x93) },
1032         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x9A) },
1033         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x9F) },
1034         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xE2) },
1035         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xE3) },
1036         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
1037         { }
1038 };
1039
1040 const struct usb_device_id *get_device_table(void)
1041 {
1042         const struct usb_device_id *id_table = wacom_ids;
1043
1044         return id_table;
1045 }
1046
1047 struct wacom_features * get_wacom_feature(const struct usb_device_id *id)
1048 {
1049         int index = id - wacom_ids;
1050         struct wacom_features *wf = &wacom_features[index];
1051
1052         return wf;
1053 }
1054
1055 MODULE_DEVICE_TABLE(usb, wacom_ids);