Merge branch 'linux-2.6' into for-linus
[linux-2.6] / drivers / usb / input / wacom_wac.c
1 /*
2  * drivers/usb/input/wacom_wac.c
3  *
4  *  USB Wacom Graphire and Wacom Intuos 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, id, pressure;
60
61         if (data[0] != 2) {
62                 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
63                 return 0;
64         }
65
66         prox = data[1] & 0x40;
67
68         id = ERASER_DEVICE_ID;
69         if (prox) {
70
71                 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
72                 if (wacom->features->pressure_max > 255)
73                         pressure = (pressure << 1) | ((data[4] >> 6) & 1);
74                 pressure += (wacom->features->pressure_max + 1) / 2;
75
76                 /*
77                  * if going from out of proximity into proximity select between the eraser
78                  * and the pen based on the state of the stylus2 button, choose eraser if
79                  * pressed else choose pen. if not a proximity change from out to in, send
80                  * an out of proximity for previous tool then a in for new tool.
81                  */
82                 if (!wacom->tool[0]) {
83                         /* Eraser bit set for DTF */
84                         if (data[1] & 0x10)
85                                 wacom->tool[1] = BTN_TOOL_RUBBER;
86                         else
87                                 /* Going into proximity select tool */
88                                 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
89                 } else {
90                         /* was entered with stylus2 pressed */
91                         if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
92                                 /* report out proximity for previous tool */
93                                 wacom_report_key(wcombo, wacom->tool[1], 0);
94                                 wacom_input_sync(wcombo);
95                                 wacom->tool[1] = BTN_TOOL_PEN;
96                                 return 0;
97                         }
98                 }
99                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
100                         /* Unknown tool selected default to pen tool */
101                         wacom->tool[1] = BTN_TOOL_PEN;
102                         id = STYLUS_DEVICE_ID;
103                 }
104                 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */
105                 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
106                 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
107                 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
108                 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
109
110                 wacom_report_key(wcombo, BTN_TOUCH, data[4] & 0x08);
111                 wacom_report_key(wcombo, BTN_STYLUS, data[4] & 0x10);
112                 /* Only allow the stylus2 button to be reported for the pen tool. */
113                 wacom_report_key(wcombo, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
114         } else {
115                 /* report proximity-out of a (valid) tool */
116                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
117                         /* Unknown tool selected default to pen tool */
118                         wacom->tool[1] = BTN_TOOL_PEN;
119                 }
120                 wacom_report_key(wcombo, wacom->tool[1], prox);
121         }
122
123         wacom->tool[0] = prox; /* Save proximity state */
124         return 1;
125 }
126
127 static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
128 {
129         unsigned char *data = wacom->data;
130         int id;
131
132         if (data[0] != 2) {
133                 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
134                 return 0;
135         }
136
137         if (data[1] & 0x04) {
138                 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20);
139                 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08);
140                 id = ERASER_DEVICE_ID;
141         } else {
142                 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20);
143                 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
144                 id = STYLUS_DEVICE_ID;
145         }
146         wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
147         wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
148         wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
149         wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
150         wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
151         wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10);
152         return 1;
153 }
154
155 static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
156 {
157         unsigned char *data = wacom->data;
158         int x, y, id, rw;
159
160         if (data[0] != 2) {
161                 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
162                 return 0;
163         }
164
165         id = STYLUS_DEVICE_ID;
166         if (data[1] & 0x10) { /* in prox */
167
168                 switch ((data[1] >> 5) & 3) {
169
170                         case 0: /* Pen */
171                                 wacom->tool[0] = BTN_TOOL_PEN;
172                                 break;
173
174                         case 1: /* Rubber */
175                                 wacom->tool[0] = BTN_TOOL_RUBBER;
176                                 id = ERASER_DEVICE_ID;
177                                 break;
178
179                         case 2: /* Mouse with wheel */
180                                 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04);
181                                 if (wacom->features->type == WACOM_G4) {
182                                         rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
183                                         wacom_report_rel(wcombo, REL_WHEEL, -rw);
184                                 } else
185                                         wacom_report_rel(wcombo, REL_WHEEL, -(signed char) data[6]);
186                                 /* fall through */
187
188                         case 3: /* Mouse without wheel */
189                                 wacom->tool[0] = BTN_TOOL_MOUSE;
190                                 id = CURSOR_DEVICE_ID;
191                                 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
192                                 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
193                                 if (wacom->features->type == WACOM_G4)
194                                         wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f);
195                                 else
196                                         wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
197                                 break;
198                 }
199         }
200
201         if (data[1] & 0x90) {
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         }
213
214         if (data[1] & 0x10)
215                 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
216         else
217                 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
218         wacom_report_key(wcombo, wacom->tool[0], data[1] & 0x10);
219         wacom_input_sync(wcombo);
220
221         /* send pad data */
222         if (wacom->features->type == WACOM_G4) {
223                 if ( (wacom->serial[1] & 0xc0) != (data[7] & 0xf8) ) {
224                         wacom->id[1] = 1;
225                         wacom->serial[1] = (data[7] & 0xf8);
226                         wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
227                         wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
228                         rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
229                         wacom_report_rel(wcombo, REL_WHEEL, rw);
230                         wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
231                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
232                 } else if (wacom->id[1]) {
233                         wacom->id[1] = 0;
234                         wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
235                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
236                 }
237         }
238         return 1;
239 }
240
241 static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
242 {
243         unsigned char *data = wacom->data;
244         int idx;
245
246         /* tool number */
247         idx = data[1] & 0x01;
248
249         /* Enter report */
250         if ((data[1] & 0xfc) == 0xc0) {
251                 /* serial number of the tool */
252                 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
253                         (data[4] << 20) + (data[5] << 12) +
254                         (data[6] << 4) + (data[7] >> 4);
255
256                 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
257                 switch (wacom->id[idx]) {
258                         case 0x812: /* Inking pen */
259                         case 0x801: /* Intuos3 Inking pen */
260                         case 0x012:
261                                 wacom->tool[idx] = BTN_TOOL_PENCIL;
262                                 break;
263                         case 0x822: /* Pen */
264                         case 0x842:
265                         case 0x852:
266                         case 0x823: /* Intuos3 Grip Pen */
267                         case 0x813: /* Intuos3 Classic Pen */
268                         case 0x885: /* Intuos3 Marker Pen */
269                         case 0x022:
270                                 wacom->tool[idx] = BTN_TOOL_PEN;
271                                 break;
272                         case 0x832: /* Stroke pen */
273                         case 0x032:
274                                 wacom->tool[idx] = BTN_TOOL_BRUSH;
275                                 break;
276                         case 0x007: /* Mouse 4D and 2D */
277                         case 0x09c:
278                         case 0x094:
279                         case 0x017: /* Intuos3 2D Mouse */
280                                 wacom->tool[idx] = BTN_TOOL_MOUSE;
281                                 break;
282                         case 0x096: /* Lens cursor */
283                         case 0x097: /* Intuos3 Lens cursor */
284                                 wacom->tool[idx] = BTN_TOOL_LENS;
285                                 break;
286                         case 0x82a: /* Eraser */
287                         case 0x85a:
288                         case 0x91a:
289                         case 0xd1a:
290                         case 0x0fa:
291                         case 0x82b: /* Intuos3 Grip Pen Eraser */
292                         case 0x81b: /* Intuos3 Classic Pen Eraser */
293                         case 0x91b: /* Intuos3 Airbrush Eraser */
294                                 wacom->tool[idx] = BTN_TOOL_RUBBER;
295                                 break;
296                         case 0xd12:
297                         case 0x912:
298                         case 0x112:
299                         case 0x913: /* Intuos3 Airbrush */
300                                 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
301                                 break;
302                         default: /* Unknown tool */
303                                 wacom->tool[idx] = BTN_TOOL_PEN;
304                 }
305                 /* only large I3 support Lens Cursor */
306                 if(!((wacom->tool[idx] == BTN_TOOL_LENS)
307                                  && ((wacom->features->type == INTUOS3)
308                                  || (wacom->features->type == INTUOS3S)))) {
309                         wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
310                         wacom_report_key(wcombo, wacom->tool[idx], 1);
311                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
312                         return 2;
313                 }
314                 return 1;
315         }
316
317         /* Exit report */
318         if ((data[1] & 0xfe) == 0x80) {
319                 if(!((wacom->tool[idx] == BTN_TOOL_LENS)
320                                  && ((wacom->features->type == INTUOS3)
321                                  || (wacom->features->type == INTUOS3S)))) {
322                         wacom_report_key(wcombo, wacom->tool[idx], 0);
323                         wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
324                         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
325                         return 2;
326                 }
327         }
328         return 0;
329 }
330
331 static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
332 {
333         unsigned char *data = wacom->data;
334         unsigned int t;
335
336         /* general pen packet */
337         if ((data[1] & 0xb8) == 0xa0) {
338                 t = (data[6] << 2) | ((data[7] >> 6) & 3);
339                 wacom_report_abs(wcombo, ABS_PRESSURE, t);
340                 wacom_report_abs(wcombo, ABS_TILT_X,
341                                 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
342                 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
343                 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 2);
344                 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 4);
345                 wacom_report_key(wcombo, BTN_TOUCH, t > 10);
346         }
347
348         /* airbrush second packet */
349         if ((data[1] & 0xbc) == 0xb4) {
350                 wacom_report_abs(wcombo, ABS_WHEEL,
351                                 (data[6] << 2) | ((data[7] >> 6) & 3));
352                 wacom_report_abs(wcombo, ABS_TILT_X,
353                                 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
354                 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
355         }
356         return;
357 }
358
359 static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
360 {
361         unsigned char *data = wacom->data;
362         unsigned int t;
363         int idx, result;
364
365         if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
366                 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
367                 return 0;
368         }
369
370         /* tool number */
371         idx = data[1] & 0x01;
372
373         /* pad packets. Works as a second tool and is always in prox */
374         if (data[0] == 12) {
375                 /* initiate the pad as a device */
376                 if (wacom->tool[1] != BTN_TOOL_FINGER)
377                         wacom->tool[1] = BTN_TOOL_FINGER;
378
379                 wacom_report_key(wcombo, BTN_0, (data[5] & 0x01));
380                 wacom_report_key(wcombo, BTN_1, (data[5] & 0x02));
381                 wacom_report_key(wcombo, BTN_2, (data[5] & 0x04));
382                 wacom_report_key(wcombo, BTN_3, (data[5] & 0x08));
383                 wacom_report_key(wcombo, BTN_4, (data[6] & 0x01));
384                 wacom_report_key(wcombo, BTN_5, (data[6] & 0x02));
385                 wacom_report_key(wcombo, BTN_6, (data[6] & 0x04));
386                 wacom_report_key(wcombo, BTN_7, (data[6] & 0x08));
387                 wacom_report_abs(wcombo, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
388                 wacom_report_abs(wcombo, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
389
390                 if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) |
391                         data[2] | (data[3] & 0x1f) | data[4])
392                         wacom_report_key(wcombo, wacom->tool[1], 1);
393                 else
394                         wacom_report_key(wcombo, wacom->tool[1], 0);
395                 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff);
396                 return 1;
397         }
398
399         /* process in/out prox events */
400         result = wacom_intuos_inout(wacom, wcombo);
401         if (result)
402                 return result-1;
403
404         /* Cintiq doesn't send data when RDY bit isn't set */
405         if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
406                  return 0;
407
408         if (wacom->features->type >= INTUOS3) {
409                 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
410                 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
411                 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
412         } else {
413                 wacom_report_abs(wcombo, ABS_X, wacom_be16_to_cpu(&data[2]));
414                 wacom_report_abs(wcombo, ABS_Y, wacom_be16_to_cpu(&data[4]));
415                 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
416         }
417
418         /* process general packets */
419         wacom_intuos_general(wacom, wcombo);
420
421         /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
422         if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
423
424                 if (data[1] & 0x02) {
425                         /* Rotation packet */
426                         if (wacom->features->type >= INTUOS3) {
427                                 /* I3 marker pen rotation reported as wheel
428                                  * due to valuator limitation
429                                  */
430                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
431                                 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
432                                         ((t-1) / 2 + 450)) : (450 - t / 2) ;
433                                 wacom_report_abs(wcombo, ABS_WHEEL, t);
434                         } else {
435                                 /* 4D mouse rotation packet */
436                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
437                                 wacom_report_abs(wcombo, ABS_RZ, (data[7] & 0x20) ?
438                                         ((t - 1) / 2) : -t / 2);
439                         }
440
441                 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3S) {
442                         /* 4D mouse packet */
443                         wacom_report_key(wcombo, BTN_LEFT,   data[8] & 0x01);
444                         wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
445                         wacom_report_key(wcombo, BTN_RIGHT,  data[8] & 0x04);
446
447                         wacom_report_key(wcombo, BTN_SIDE,   data[8] & 0x20);
448                         wacom_report_key(wcombo, BTN_EXTRA,  data[8] & 0x10);
449                         t = (data[6] << 2) | ((data[7] >> 6) & 3);
450                         wacom_report_abs(wcombo, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
451
452                 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
453                         /* 2D mouse packet */
454                         wacom_report_key(wcombo, BTN_LEFT,   data[8] & 0x04);
455                         wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x08);
456                         wacom_report_key(wcombo, BTN_RIGHT,  data[8] & 0x10);
457                         wacom_report_rel(wcombo, REL_WHEEL, (data[8] & 0x01)
458                                                  - ((data[8] & 0x02) >> 1));
459
460                         /* I3 2D mouse side buttons */
461                         if (wacom->features->type >= INTUOS3S && wacom->features->type <= INTUOS3L) {
462                                 wacom_report_key(wcombo, BTN_SIDE,   data[8] & 0x40);
463                                 wacom_report_key(wcombo, BTN_EXTRA,  data[8] & 0x20);
464                         }
465
466                 } else if (wacom->features->type < INTUOS3S || wacom->features->type == INTUOS3L) {
467                         /* Lens cursor packets */
468                         wacom_report_key(wcombo, BTN_LEFT,   data[8] & 0x01);
469                         wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
470                         wacom_report_key(wcombo, BTN_RIGHT,  data[8] & 0x04);
471                         wacom_report_key(wcombo, BTN_SIDE,   data[8] & 0x10);
472                         wacom_report_key(wcombo, BTN_EXTRA,  data[8] & 0x08);
473                 }
474         }
475
476         wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
477         wacom_report_key(wcombo, wacom->tool[idx], 1);
478         wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
479         return 1;
480 }
481
482 int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo)
483 {
484         switch (wacom_wac->features->type) {
485                 case PENPARTNER:
486                         return (wacom_penpartner_irq(wacom_wac, wcombo));
487                         break;
488                 case PL:
489                         return (wacom_pl_irq(wacom_wac, wcombo));
490                         break;
491                 case WACOM_G4:
492                 case GRAPHIRE:
493                         return (wacom_graphire_irq(wacom_wac, wcombo));
494                         break;
495                 case PTU:
496                         return (wacom_ptu_irq(wacom_wac, wcombo));
497                         break;
498                 case INTUOS:
499                 case INTUOS3S:
500                 case INTUOS3:
501                 case INTUOS3L:
502                 case CINTIQ:
503                         return (wacom_intuos_irq(wacom_wac, wcombo));
504                         break;
505                 default:
506                         return 0;
507         }
508         return 0;
509 }
510
511 void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
512 {
513         switch (wacom_wac->features->type) {
514                 case WACOM_G4:
515                         input_dev_g4(input_dev, wacom_wac);
516                         /* fall through */
517                 case GRAPHIRE:
518                         input_dev_g(input_dev, wacom_wac);
519                         break;
520                 case INTUOS3:
521                 case INTUOS3L:
522                 case CINTIQ:
523                         input_dev_i3(input_dev, wacom_wac);
524                         /* fall through */
525                 case INTUOS3S:
526                         input_dev_i3s(input_dev, wacom_wac);
527                 case INTUOS:
528                         input_dev_i(input_dev, wacom_wac);
529                         break;
530                 case PL:
531                 case PTU:
532                         input_dev_pl(input_dev, wacom_wac);
533                         break;
534                 case PENPARTNER:
535                         input_dev_pt(input_dev, wacom_wac);
536                         break;
537         }
538         return;
539 }
540
541 static struct wacom_features wacom_features[] = {
542         { "Wacom Penpartner",    7,   5040,  3780,  255,  0, PENPARTNER },
543         { "Wacom Graphire",      8,  10206,  7422,  511, 63, GRAPHIRE },
544         { "Wacom Graphire2 4x5", 8,  10206,  7422,  511, 63, GRAPHIRE },
545         { "Wacom Graphire2 5x7", 8,  13918, 10206,  511, 63, GRAPHIRE },
546         { "Wacom Graphire3",     8,  10208,  7424,  511, 63, GRAPHIRE },
547         { "Wacom Graphire3 6x8", 8,  16704, 12064,  511, 63, GRAPHIRE },
548         { "Wacom Graphire4 4x5", 8,  10208,  7424,  511, 63, WACOM_G4 },
549         { "Wacom Graphire4 6x8", 8,  16704, 12064,  511, 63, WACOM_G4 },
550         { "Wacom Volito",        8,   5104,  3712,  511,  0, GRAPHIRE },
551         { "Wacom PenStation2",   8,   3250,  2320,  255,  0, GRAPHIRE },
552         { "Wacom Volito2 4x5",   8,   5104,  3712,  511,  0, GRAPHIRE },
553         { "Wacom Volito2 2x3",   8,   3248,  2320,  511,  0, GRAPHIRE },
554         { "Wacom PenPartner2",   8,   3250,  2320,  255,  0, GRAPHIRE },
555         { "Wacom Intuos 4x5",   10,  12700, 10600, 1023, 63, INTUOS },
556         { "Wacom Intuos 6x8",   10,  20320, 16240, 1023, 63, INTUOS },
557         { "Wacom Intuos 9x12",  10,  30480, 24060, 1023, 63, INTUOS },
558         { "Wacom Intuos 12x12", 10,  30480, 31680, 1023, 63, INTUOS },
559         { "Wacom Intuos 12x18", 10,  45720, 31680, 1023, 63, INTUOS },
560         { "Wacom PL400",         8,   5408,  4056,  255,  0, PL },
561         { "Wacom PL500",         8,   6144,  4608,  255,  0, PL },
562         { "Wacom PL600",         8,   6126,  4604,  255,  0, PL },
563         { "Wacom PL600SX",       8,   6260,  5016,  255,  0, PL },
564         { "Wacom PL550",         8,   6144,  4608,  511,  0, PL },
565         { "Wacom PL800",         8,   7220,  5780,  511,  0, PL },
566         { "Wacom PL700",         8,   6758,  5406,  511,  0, PL },
567         { "Wacom PL510",         8,   6282,  4762,  511,  0, PL },
568         { "Wacom DTU710",        8,  34080, 27660,  511,  0, PL },
569         { "Wacom DTF521",        8,   6282,  4762,  511,  0, PL },
570         { "Wacom DTF720",        8,   6858,  5506,  511,  0, PL },
571         { "Wacom Cintiq Partner",8,  20480, 15360,  511,  0, PTU },
572         { "Wacom Intuos2 4x5",   10, 12700, 10600, 1023, 63, INTUOS },
573         { "Wacom Intuos2 6x8",   10, 20320, 16240, 1023, 63, INTUOS },
574         { "Wacom Intuos2 9x12",  10, 30480, 24060, 1023, 63, INTUOS },
575         { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 63, INTUOS },
576         { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 63, INTUOS },
577         { "Wacom Intuos3 4x5",   10, 25400, 20320, 1023, 63, INTUOS3S },
578         { "Wacom Intuos3 6x8",   10, 40640, 30480, 1023, 63, INTUOS3 },
579         { "Wacom Intuos3 9x12",  10, 60960, 45720, 1023, 63, INTUOS3 },
580         { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 63, INTUOS3L },
581         { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 63, INTUOS3L },
582         { "Wacom Intuos3 6x11",  10, 54204, 31750, 1023, 63, INTUOS3 },
583         { "Wacom Intuos3 4x6",   10, 31496, 19685, 1023, 15, INTUOS3S },
584         { "Wacom Cintiq 21UX",   10, 87200, 65600, 1023, 63, CINTIQ },
585         { "Wacom Intuos2 6x8",   10, 20320, 16240, 1023, 63, INTUOS },
586         { }
587 };
588
589 static struct usb_device_id wacom_ids[] = {
590         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
591         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
592         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
593         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
594         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
595         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
596         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
597         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
598         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
599         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
600         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
601         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
602         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
603         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
604         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
605         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
606         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
607         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
608         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
609         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
610         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
611         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
612         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
613         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
614         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
615         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
616         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
617         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
618         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC4) },
619         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
620         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
621         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
622         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
623         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
624         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
625         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
626         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
627         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
628         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
629         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
630         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
631         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) },
632         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
633         { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
634         { }
635 };
636
637 const struct usb_device_id * get_device_table(void) {
638         const struct usb_device_id * id_table = wacom_ids;
639         return id_table;
640 }
641
642 struct wacom_features * get_wacom_feature(const struct usb_device_id * id) {
643         int index = id - wacom_ids;
644         struct wacom_features *wf = &wacom_features[index];
645         return wf;
646 }
647
648 MODULE_DEVICE_TABLE(usb, wacom_ids);