]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/hid/wacom_wac.c
Merge branch 'for-4.1/wacom' into for-next
[karo-tx-linux.git] / drivers / hid / 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
19 /* resolution for penabled devices */
20 #define WACOM_PL_RES            20
21 #define WACOM_PENPRTN_RES       40
22 #define WACOM_VOLITO_RES        50
23 #define WACOM_GRAPHIRE_RES      80
24 #define WACOM_INTUOS_RES        100
25 #define WACOM_INTUOS3_RES       200
26
27 /* Newer Cintiq and DTU have an offset between tablet and screen areas */
28 #define WACOM_DTU_OFFSET        200
29 #define WACOM_CINTIQ_OFFSET     400
30
31 /*
32  * Scale factor relating reported contact size to logical contact area.
33  * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
34  */
35 #define WACOM_CONTACT_AREA_SCALE 2607
36
37 /*
38  * Percent of battery capacity for Graphire.
39  * 8th value means AC online and show 100% capacity.
40  */
41 static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
42
43 /*
44  * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
45  */
46 static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
47
48 static void wacom_notify_battery(struct wacom_wac *wacom_wac,
49         int bat_capacity, bool bat_charging, bool ps_connected)
50 {
51         struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
52         bool changed = wacom_wac->battery_capacity != bat_capacity  ||
53                        wacom_wac->bat_charging     != bat_charging  ||
54                        wacom_wac->ps_connected     != ps_connected;
55
56         if (changed) {
57                 wacom_wac->battery_capacity = bat_capacity;
58                 wacom_wac->bat_charging = bat_charging;
59                 wacom_wac->ps_connected = ps_connected;
60
61                 if (wacom->battery.dev)
62                         power_supply_changed(&wacom->battery);
63         }
64 }
65
66 static int wacom_penpartner_irq(struct wacom_wac *wacom)
67 {
68         unsigned char *data = wacom->data;
69         struct input_dev *input = wacom->input;
70
71         switch (data[0]) {
72         case 1:
73                 if (data[5] & 0x80) {
74                         wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
75                         wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
76                         input_report_key(input, wacom->tool[0], 1);
77                         input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
78                         input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
79                         input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
80                         input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
81                         input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
82                         input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
83                 } else {
84                         input_report_key(input, wacom->tool[0], 0);
85                         input_report_abs(input, ABS_MISC, 0); /* report tool id */
86                         input_report_abs(input, ABS_PRESSURE, -1);
87                         input_report_key(input, BTN_TOUCH, 0);
88                 }
89                 break;
90
91         case 2:
92                 input_report_key(input, BTN_TOOL_PEN, 1);
93                 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
94                 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
95                 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
96                 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
97                 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
98                 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
99                 break;
100
101         default:
102                 dev_dbg(input->dev.parent,
103                         "%s: received unknown report #%d\n", __func__, data[0]);
104                 return 0;
105         }
106
107         return 1;
108 }
109
110 static int wacom_pl_irq(struct wacom_wac *wacom)
111 {
112         struct wacom_features *features = &wacom->features;
113         unsigned char *data = wacom->data;
114         struct input_dev *input = wacom->input;
115         int prox, pressure;
116
117         if (data[0] != WACOM_REPORT_PENABLED) {
118                 dev_dbg(input->dev.parent,
119                         "%s: received unknown report #%d\n", __func__, data[0]);
120                 return 0;
121         }
122
123         prox = data[1] & 0x40;
124
125         if (prox) {
126                 wacom->id[0] = ERASER_DEVICE_ID;
127                 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
128                 if (features->pressure_max > 255)
129                         pressure = (pressure << 1) | ((data[4] >> 6) & 1);
130                 pressure += (features->pressure_max + 1) / 2;
131
132                 /*
133                  * if going from out of proximity into proximity select between the eraser
134                  * and the pen based on the state of the stylus2 button, choose eraser if
135                  * pressed else choose pen. if not a proximity change from out to in, send
136                  * an out of proximity for previous tool then a in for new tool.
137                  */
138                 if (!wacom->tool[0]) {
139                         /* Eraser bit set for DTF */
140                         if (data[1] & 0x10)
141                                 wacom->tool[1] = BTN_TOOL_RUBBER;
142                         else
143                                 /* Going into proximity select tool */
144                                 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
145                 } else {
146                         /* was entered with stylus2 pressed */
147                         if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
148                                 /* report out proximity for previous tool */
149                                 input_report_key(input, wacom->tool[1], 0);
150                                 input_sync(input);
151                                 wacom->tool[1] = BTN_TOOL_PEN;
152                                 return 0;
153                         }
154                 }
155                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
156                         /* Unknown tool selected default to pen tool */
157                         wacom->tool[1] = BTN_TOOL_PEN;
158                         wacom->id[0] = STYLUS_DEVICE_ID;
159                 }
160                 input_report_key(input, wacom->tool[1], prox); /* report in proximity for tool */
161                 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
162                 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
163                 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
164                 input_report_abs(input, ABS_PRESSURE, pressure);
165
166                 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
167                 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
168                 /* Only allow the stylus2 button to be reported for the pen tool. */
169                 input_report_key(input, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
170         } else {
171                 /* report proximity-out of a (valid) tool */
172                 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
173                         /* Unknown tool selected default to pen tool */
174                         wacom->tool[1] = BTN_TOOL_PEN;
175                 }
176                 input_report_key(input, wacom->tool[1], prox);
177         }
178
179         wacom->tool[0] = prox; /* Save proximity state */
180         return 1;
181 }
182
183 static int wacom_ptu_irq(struct wacom_wac *wacom)
184 {
185         unsigned char *data = wacom->data;
186         struct input_dev *input = wacom->input;
187
188         if (data[0] != WACOM_REPORT_PENABLED) {
189                 dev_dbg(input->dev.parent,
190                         "%s: received unknown report #%d\n", __func__, data[0]);
191                 return 0;
192         }
193
194         if (data[1] & 0x04) {
195                 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
196                 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
197                 wacom->id[0] = ERASER_DEVICE_ID;
198         } else {
199                 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
200                 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
201                 wacom->id[0] = STYLUS_DEVICE_ID;
202         }
203         input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
204         input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
205         input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
206         input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
207         input_report_key(input, BTN_STYLUS, data[1] & 0x02);
208         input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
209         return 1;
210 }
211
212 static int wacom_dtu_irq(struct wacom_wac *wacom)
213 {
214         unsigned char *data = wacom->data;
215         struct input_dev *input = wacom->input;
216         int prox = data[1] & 0x20;
217
218         dev_dbg(input->dev.parent,
219                 "%s: received report #%d", __func__, data[0]);
220
221         if (prox) {
222                 /* Going into proximity select tool */
223                 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
224                 if (wacom->tool[0] == BTN_TOOL_PEN)
225                         wacom->id[0] = STYLUS_DEVICE_ID;
226                 else
227                         wacom->id[0] = ERASER_DEVICE_ID;
228         }
229         input_report_key(input, BTN_STYLUS, data[1] & 0x02);
230         input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
231         input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
232         input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
233         input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
234         input_report_key(input, BTN_TOUCH, data[1] & 0x05);
235         if (!prox) /* out-prox */
236                 wacom->id[0] = 0;
237         input_report_key(input, wacom->tool[0], prox);
238         input_report_abs(input, ABS_MISC, wacom->id[0]);
239         return 1;
240 }
241
242 static int wacom_dtus_irq(struct wacom_wac *wacom)
243 {
244         char *data = wacom->data;
245         struct input_dev *input = wacom->input;
246         unsigned short prox, pressure = 0;
247
248         if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
249                 dev_dbg(input->dev.parent,
250                         "%s: received unknown report #%d", __func__, data[0]);
251                 return 0;
252         } else if (data[0] == WACOM_REPORT_DTUSPAD) {
253                 input = wacom->pad_input;
254                 input_report_key(input, BTN_0, (data[1] & 0x01));
255                 input_report_key(input, BTN_1, (data[1] & 0x02));
256                 input_report_key(input, BTN_2, (data[1] & 0x04));
257                 input_report_key(input, BTN_3, (data[1] & 0x08));
258                 input_report_abs(input, ABS_MISC,
259                                  data[1] & 0x0f ? PAD_DEVICE_ID : 0);
260                 return 1;
261         } else {
262                 prox = data[1] & 0x80;
263                 if (prox) {
264                         switch ((data[1] >> 3) & 3) {
265                         case 1: /* Rubber */
266                                 wacom->tool[0] = BTN_TOOL_RUBBER;
267                                 wacom->id[0] = ERASER_DEVICE_ID;
268                                 break;
269
270                         case 2: /* Pen */
271                                 wacom->tool[0] = BTN_TOOL_PEN;
272                                 wacom->id[0] = STYLUS_DEVICE_ID;
273                                 break;
274                         }
275                 }
276
277                 input_report_key(input, BTN_STYLUS, data[1] & 0x20);
278                 input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
279                 input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
280                 input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
281                 pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
282                 input_report_abs(input, ABS_PRESSURE, pressure);
283                 input_report_key(input, BTN_TOUCH, pressure > 10);
284
285                 if (!prox) /* out-prox */
286                         wacom->id[0] = 0;
287                 input_report_key(input, wacom->tool[0], prox);
288                 input_report_abs(input, ABS_MISC, wacom->id[0]);
289                 return 1;
290         }
291 }
292
293 static int wacom_graphire_irq(struct wacom_wac *wacom)
294 {
295         struct wacom_features *features = &wacom->features;
296         unsigned char *data = wacom->data;
297         struct input_dev *input = wacom->input;
298         struct input_dev *pad_input = wacom->pad_input;
299         int battery_capacity, ps_connected;
300         int prox;
301         int rw = 0;
302         int retval = 0;
303
304         if (features->type == GRAPHIRE_BT) {
305                 if (data[0] != WACOM_REPORT_PENABLED_BT) {
306                         dev_dbg(input->dev.parent,
307                                 "%s: received unknown report #%d\n", __func__,
308                                 data[0]);
309                         goto exit;
310                 }
311         } else if (data[0] != WACOM_REPORT_PENABLED) {
312                 dev_dbg(input->dev.parent,
313                         "%s: received unknown report #%d\n", __func__, data[0]);
314                 goto exit;
315         }
316
317         prox = data[1] & 0x80;
318         if (prox || wacom->id[0]) {
319                 if (prox) {
320                         switch ((data[1] >> 5) & 3) {
321
322                         case 0: /* Pen */
323                                 wacom->tool[0] = BTN_TOOL_PEN;
324                                 wacom->id[0] = STYLUS_DEVICE_ID;
325                                 break;
326
327                         case 1: /* Rubber */
328                                 wacom->tool[0] = BTN_TOOL_RUBBER;
329                                 wacom->id[0] = ERASER_DEVICE_ID;
330                                 break;
331
332                         case 2: /* Mouse with wheel */
333                                 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
334                                 /* fall through */
335
336                         case 3: /* Mouse without wheel */
337                                 wacom->tool[0] = BTN_TOOL_MOUSE;
338                                 wacom->id[0] = CURSOR_DEVICE_ID;
339                                 break;
340                         }
341                 }
342                 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
343                 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
344                 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
345                         if (features->type == GRAPHIRE_BT)
346                                 input_report_abs(input, ABS_PRESSURE, data[6] |
347                                         (((__u16) (data[1] & 0x08)) << 5));
348                         else
349                                 input_report_abs(input, ABS_PRESSURE, data[6] |
350                                         ((data[7] & 0x03) << 8));
351                         input_report_key(input, BTN_TOUCH, data[1] & 0x01);
352                         input_report_key(input, BTN_STYLUS, data[1] & 0x02);
353                         input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
354                 } else {
355                         input_report_key(input, BTN_LEFT, data[1] & 0x01);
356                         input_report_key(input, BTN_RIGHT, data[1] & 0x02);
357                         if (features->type == WACOM_G4 ||
358                                         features->type == WACOM_MO) {
359                                 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
360                                 rw = (data[7] & 0x04) - (data[7] & 0x03);
361                         } else if (features->type == GRAPHIRE_BT) {
362                                 /* Compute distance between mouse and tablet */
363                                 rw = 44 - (data[6] >> 2);
364                                 rw = clamp_val(rw, 0, 31);
365                                 input_report_abs(input, ABS_DISTANCE, rw);
366                                 if (((data[1] >> 5) & 3) == 2) {
367                                         /* Mouse with wheel */
368                                         input_report_key(input, BTN_MIDDLE,
369                                                         data[1] & 0x04);
370                                         rw = (data[6] & 0x01) ? -1 :
371                                                 (data[6] & 0x02) ? 1 : 0;
372                                 } else {
373                                         rw = 0;
374                                 }
375                         } else {
376                                 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
377                                 rw = -(signed char)data[6];
378                         }
379                         input_report_rel(input, REL_WHEEL, rw);
380                 }
381
382                 if (!prox)
383                         wacom->id[0] = 0;
384                 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
385                 input_report_key(input, wacom->tool[0], prox);
386                 input_sync(input); /* sync last event */
387         }
388
389         /* send pad data */
390         switch (features->type) {
391         case WACOM_G4:
392                 prox = data[7] & 0xf8;
393                 if (prox || wacom->id[1]) {
394                         wacom->id[1] = PAD_DEVICE_ID;
395                         input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
396                         input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
397                         rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
398                         input_report_rel(pad_input, REL_WHEEL, rw);
399                         if (!prox)
400                                 wacom->id[1] = 0;
401                         input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
402                         retval = 1;
403                 }
404                 break;
405
406         case WACOM_MO:
407                 prox = (data[7] & 0xf8) || data[8];
408                 if (prox || wacom->id[1]) {
409                         wacom->id[1] = PAD_DEVICE_ID;
410                         input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
411                         input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
412                         input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
413                         input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
414                         input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
415                         if (!prox)
416                                 wacom->id[1] = 0;
417                         input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
418                         retval = 1;
419                 }
420                 break;
421         case GRAPHIRE_BT:
422                 prox = data[7] & 0x03;
423                 if (prox || wacom->id[1]) {
424                         wacom->id[1] = PAD_DEVICE_ID;
425                         input_report_key(pad_input, BTN_0, (data[7] & 0x02));
426                         input_report_key(pad_input, BTN_1, (data[7] & 0x01));
427                         if (!prox)
428                                 wacom->id[1] = 0;
429                         input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
430                         retval = 1;
431                 }
432                 break;
433         }
434
435         /* Store current battery capacity and power supply state */
436         if (features->type == GRAPHIRE_BT) {
437                 rw = (data[7] >> 2 & 0x07);
438                 battery_capacity = batcap_gr[rw];
439                 ps_connected = rw == 7;
440                 wacom_notify_battery(wacom, battery_capacity, ps_connected,
441                                      ps_connected);
442         }
443 exit:
444         return retval;
445 }
446
447 static int wacom_intuos_inout(struct wacom_wac *wacom)
448 {
449         struct wacom_features *features = &wacom->features;
450         unsigned char *data = wacom->data;
451         struct input_dev *input = wacom->input;
452         int idx = 0;
453
454         /* tool number */
455         if (features->type == INTUOS)
456                 idx = data[1] & 0x01;
457
458         /* Enter report */
459         if ((data[1] & 0xfc) == 0xc0) {
460                 /* serial number of the tool */
461                 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
462                         (data[4] << 20) + (data[5] << 12) +
463                         (data[6] << 4) + (data[7] >> 4);
464
465                 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
466                         ((data[7] & 0x0f) << 20) | ((data[8] & 0xf0) << 12);
467
468                 switch (wacom->id[idx]) {
469                 case 0x812: /* Inking pen */
470                 case 0x801: /* Intuos3 Inking pen */
471                 case 0x120802: /* Intuos4/5 Inking Pen */
472                 case 0x012:
473                         wacom->tool[idx] = BTN_TOOL_PENCIL;
474                         break;
475
476                 case 0x822: /* Pen */
477                 case 0x842:
478                 case 0x852:
479                 case 0x823: /* Intuos3 Grip Pen */
480                 case 0x813: /* Intuos3 Classic Pen */
481                 case 0x885: /* Intuos3 Marker Pen */
482                 case 0x802: /* Intuos4/5 13HD/24HD General Pen */
483                 case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
484                 case 0x022:
485                 case 0x100804: /* Intuos4/5 13HD/24HD Art Pen */
486                 case 0x140802: /* Intuos4/5 13HD/24HD Classic Pen */
487                 case 0x160802: /* Cintiq 13HD Pro Pen */
488                 case 0x180802: /* DTH2242 Pen */
489                 case 0x100802: /* Intuos4/5 13HD/24HD General Pen */
490                         wacom->tool[idx] = BTN_TOOL_PEN;
491                         break;
492
493                 case 0x832: /* Stroke pen */
494                 case 0x032:
495                         wacom->tool[idx] = BTN_TOOL_BRUSH;
496                         break;
497
498                 case 0x007: /* Mouse 4D and 2D */
499                 case 0x09c:
500                 case 0x094:
501                 case 0x017: /* Intuos3 2D Mouse */
502                 case 0x806: /* Intuos4 Mouse */
503                         wacom->tool[idx] = BTN_TOOL_MOUSE;
504                         break;
505
506                 case 0x096: /* Lens cursor */
507                 case 0x097: /* Intuos3 Lens cursor */
508                 case 0x006: /* Intuos4 Lens cursor */
509                         wacom->tool[idx] = BTN_TOOL_LENS;
510                         break;
511
512                 case 0x82a: /* Eraser */
513                 case 0x85a:
514                 case 0x91a:
515                 case 0xd1a:
516                 case 0x0fa:
517                 case 0x82b: /* Intuos3 Grip Pen Eraser */
518                 case 0x81b: /* Intuos3 Classic Pen Eraser */
519                 case 0x91b: /* Intuos3 Airbrush Eraser */
520                 case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
521                 case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
522                 case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
523                 case 0x14080a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
524                 case 0x10090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
525                 case 0x10080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
526                 case 0x16080a: /* Cintiq 13HD Pro Pen Eraser */
527                 case 0x18080a: /* DTH2242 Eraser */
528                 case 0x10080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
529                         wacom->tool[idx] = BTN_TOOL_RUBBER;
530                         break;
531
532                 case 0xd12:
533                 case 0x912:
534                 case 0x112:
535                 case 0x913: /* Intuos3 Airbrush */
536                 case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
537                 case 0x100902: /* Intuos4/5 13HD/24HD Airbrush */
538                         wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
539                         break;
540
541                 default: /* Unknown tool */
542                         wacom->tool[idx] = BTN_TOOL_PEN;
543                         break;
544                 }
545                 return 1;
546         }
547
548         /*
549          * don't report events for invalid data
550          */
551         /* older I4 styli don't work with new Cintiqs */
552         if ((!((wacom->id[idx] >> 20) & 0x01) &&
553                         (features->type == WACOM_21UX2)) ||
554             /* Only large Intuos support Lense Cursor */
555             (wacom->tool[idx] == BTN_TOOL_LENS &&
556                 (features->type == INTUOS3 ||
557                  features->type == INTUOS3S ||
558                  features->type == INTUOS4 ||
559                  features->type == INTUOS4S ||
560                  features->type == INTUOS5 ||
561                  features->type == INTUOS5S ||
562                  features->type == INTUOSPM ||
563                  features->type == INTUOSPS)) ||
564            /* Cintiq doesn't send data when RDY bit isn't set */
565            (features->type == CINTIQ && !(data[1] & 0x40)))
566                 return 1;
567
568         if (features->quirks & WACOM_QUIRK_MULTI_INPUT)
569                 wacom->shared->stylus_in_proximity = true;
570
571         if (wacom->shared->touch_down)
572                 return 1;
573
574         /* in Range while exiting */
575         if (((data[1] & 0xfe) == 0x20) && wacom->reporting_data) {
576                 input_report_key(input, BTN_TOUCH, 0);
577                 input_report_abs(input, ABS_PRESSURE, 0);
578                 input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
579                 return 2;
580         }
581
582         /* Exit report */
583         if ((data[1] & 0xfe) == 0x80) {
584                 if (features->quirks & WACOM_QUIRK_MULTI_INPUT)
585                         wacom->shared->stylus_in_proximity = false;
586                 wacom->reporting_data = false;
587
588                 /* don't report exit if we don't know the ID */
589                 if (!wacom->id[idx])
590                         return 1;
591
592                 /*
593                  * Reset all states otherwise we lose the initial states
594                  * when in-prox next time
595                  */
596                 input_report_abs(input, ABS_X, 0);
597                 input_report_abs(input, ABS_Y, 0);
598                 input_report_abs(input, ABS_DISTANCE, 0);
599                 input_report_abs(input, ABS_TILT_X, 0);
600                 input_report_abs(input, ABS_TILT_Y, 0);
601                 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
602                         input_report_key(input, BTN_LEFT, 0);
603                         input_report_key(input, BTN_MIDDLE, 0);
604                         input_report_key(input, BTN_RIGHT, 0);
605                         input_report_key(input, BTN_SIDE, 0);
606                         input_report_key(input, BTN_EXTRA, 0);
607                         input_report_abs(input, ABS_THROTTLE, 0);
608                         input_report_abs(input, ABS_RZ, 0);
609                 } else {
610                         input_report_abs(input, ABS_PRESSURE, 0);
611                         input_report_key(input, BTN_STYLUS, 0);
612                         input_report_key(input, BTN_STYLUS2, 0);
613                         input_report_key(input, BTN_TOUCH, 0);
614                         input_report_abs(input, ABS_WHEEL, 0);
615                         if (features->type >= INTUOS3S)
616                                 input_report_abs(input, ABS_Z, 0);
617                 }
618                 input_report_key(input, wacom->tool[idx], 0);
619                 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
620                 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
621                 wacom->id[idx] = 0;
622                 return 2;
623         }
624
625         /* don't report other events if we don't know the ID */
626         if (!wacom->id[idx])
627                 return 1;
628
629         return 0;
630 }
631
632 static void wacom_intuos_general(struct wacom_wac *wacom)
633 {
634         struct wacom_features *features = &wacom->features;
635         unsigned char *data = wacom->data;
636         struct input_dev *input = wacom->input;
637         unsigned int t;
638
639         /* general pen packet */
640         if ((data[1] & 0xb8) == 0xa0) {
641                 t = (data[6] << 2) | ((data[7] >> 6) & 3);
642                 if (features->type >= INTUOS4S && features->type <= CINTIQ_HYBRID) {
643                         t = (t << 1) | (data[1] & 1);
644                 }
645                 input_report_abs(input, ABS_PRESSURE, t);
646                 input_report_abs(input, ABS_TILT_X,
647                                  (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
648                 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
649                 input_report_key(input, BTN_STYLUS, data[1] & 2);
650                 input_report_key(input, BTN_STYLUS2, data[1] & 4);
651                 input_report_key(input, BTN_TOUCH, t > 10);
652         }
653
654         /* airbrush second packet */
655         if ((data[1] & 0xbc) == 0xb4) {
656                 input_report_abs(input, ABS_WHEEL,
657                                 (data[6] << 2) | ((data[7] >> 6) & 3));
658                 input_report_abs(input, ABS_TILT_X,
659                                  (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
660                 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
661         }
662 }
663
664 static int wacom_intuos_irq(struct wacom_wac *wacom)
665 {
666         struct wacom_features *features = &wacom->features;
667         unsigned char *data = wacom->data;
668         struct input_dev *input = wacom->input;
669         unsigned int t;
670         int idx = 0, result;
671
672         if (data[0] != WACOM_REPORT_PENABLED &&
673             data[0] != WACOM_REPORT_INTUOSREAD &&
674             data[0] != WACOM_REPORT_INTUOSWRITE &&
675             data[0] != WACOM_REPORT_INTUOSPAD &&
676             data[0] != WACOM_REPORT_CINTIQ &&
677             data[0] != WACOM_REPORT_CINTIQPAD &&
678             data[0] != WACOM_REPORT_INTUOS5PAD) {
679                 dev_dbg(input->dev.parent,
680                         "%s: received unknown report #%d\n", __func__, data[0]);
681                 return 0;
682         }
683
684         /* tool number */
685         if (features->type == INTUOS)
686                 idx = data[1] & 0x01;
687
688         /* pad packets. Works as a second tool and is always in prox */
689         if (data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
690             data[0] == WACOM_REPORT_CINTIQPAD) {
691                 input = wacom->pad_input;
692                 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
693                         input_report_key(input, BTN_0, (data[2] & 0x01));
694                         input_report_key(input, BTN_1, (data[3] & 0x01));
695                         input_report_key(input, BTN_2, (data[3] & 0x02));
696                         input_report_key(input, BTN_3, (data[3] & 0x04));
697                         input_report_key(input, BTN_4, (data[3] & 0x08));
698                         input_report_key(input, BTN_5, (data[3] & 0x10));
699                         input_report_key(input, BTN_6, (data[3] & 0x20));
700                         if (data[1] & 0x80) {
701                                 input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
702                         } else {
703                                 /* Out of proximity, clear wheel value. */
704                                 input_report_abs(input, ABS_WHEEL, 0);
705                         }
706                         if (features->type != INTUOS4S) {
707                                 input_report_key(input, BTN_7, (data[3] & 0x40));
708                                 input_report_key(input, BTN_8, (data[3] & 0x80));
709                         }
710                         if (data[1] | (data[2] & 0x01) | data[3]) {
711                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
712                         } else {
713                                 input_report_abs(input, ABS_MISC, 0);
714                         }
715                 } else if (features->type == DTK) {
716                         input_report_key(input, BTN_0, (data[6] & 0x01));
717                         input_report_key(input, BTN_1, (data[6] & 0x02));
718                         input_report_key(input, BTN_2, (data[6] & 0x04));
719                         input_report_key(input, BTN_3, (data[6] & 0x08));
720                         input_report_key(input, BTN_4, (data[6] & 0x10));
721                         input_report_key(input, BTN_5, (data[6] & 0x20));
722                         if (data[6] & 0x3f) {
723                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
724                         } else {
725                                 input_report_abs(input, ABS_MISC, 0);
726                         }
727                 } else if (features->type == WACOM_13HD) {
728                         input_report_key(input, BTN_0, (data[3] & 0x01));
729                         input_report_key(input, BTN_1, (data[4] & 0x01));
730                         input_report_key(input, BTN_2, (data[4] & 0x02));
731                         input_report_key(input, BTN_3, (data[4] & 0x04));
732                         input_report_key(input, BTN_4, (data[4] & 0x08));
733                         input_report_key(input, BTN_5, (data[4] & 0x10));
734                         input_report_key(input, BTN_6, (data[4] & 0x20));
735                         input_report_key(input, BTN_7, (data[4] & 0x40));
736                         input_report_key(input, BTN_8, (data[4] & 0x80));
737                         if ((data[3] & 0x01) | data[4]) {
738                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
739                         } else {
740                                 input_report_abs(input, ABS_MISC, 0);
741                         }
742                 } else if (features->type == WACOM_24HD) {
743                         input_report_key(input, BTN_0, (data[6] & 0x01));
744                         input_report_key(input, BTN_1, (data[6] & 0x02));
745                         input_report_key(input, BTN_2, (data[6] & 0x04));
746                         input_report_key(input, BTN_3, (data[6] & 0x08));
747                         input_report_key(input, BTN_4, (data[6] & 0x10));
748                         input_report_key(input, BTN_5, (data[6] & 0x20));
749                         input_report_key(input, BTN_6, (data[6] & 0x40));
750                         input_report_key(input, BTN_7, (data[6] & 0x80));
751                         input_report_key(input, BTN_8, (data[8] & 0x01));
752                         input_report_key(input, BTN_9, (data[8] & 0x02));
753                         input_report_key(input, BTN_A, (data[8] & 0x04));
754                         input_report_key(input, BTN_B, (data[8] & 0x08));
755                         input_report_key(input, BTN_C, (data[8] & 0x10));
756                         input_report_key(input, BTN_X, (data[8] & 0x20));
757                         input_report_key(input, BTN_Y, (data[8] & 0x40));
758                         input_report_key(input, BTN_Z, (data[8] & 0x80));
759
760                         /*
761                          * Three "buttons" are available on the 24HD which are
762                          * physically implemented as a touchstrip. Each button
763                          * is approximately 3 bits wide with a 2 bit spacing.
764                          * The raw touchstrip bits are stored at:
765                          *    ((data[3] & 0x1f) << 8) | data[4])
766                          */
767                         input_report_key(input, KEY_PROG1, data[4] & 0x07);
768                         input_report_key(input, KEY_PROG2, data[4] & 0xE0);
769                         input_report_key(input, KEY_PROG3, data[3] & 0x1C);
770
771                         if (data[1] & 0x80) {
772                                 input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
773                         } else {
774                                 /* Out of proximity, clear wheel value. */
775                                 input_report_abs(input, ABS_WHEEL, 0);
776                         }
777
778                         if (data[2] & 0x80) {
779                                 input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
780                         } else {
781                                 /* Out of proximity, clear second wheel value. */
782                                 input_report_abs(input, ABS_THROTTLE, 0);
783                         }
784
785                         if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
786                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
787                         } else {
788                                 input_report_abs(input, ABS_MISC, 0);
789                         }
790                 } else if (features->type == WACOM_27QHD) {
791                         input_report_key(input, KEY_PROG1, data[2] & 0x01);
792                         input_report_key(input, KEY_PROG2, data[2] & 0x02);
793                         input_report_key(input, KEY_PROG3, data[2] & 0x04);
794
795                         input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
796                         input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
797                         input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
798                         if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) {
799                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
800                         } else {
801                                 input_report_abs(input, ABS_MISC, 0);
802                         }
803                 } else if (features->type == CINTIQ_HYBRID) {
804                         /*
805                          * Do not send hardware buttons under Android. They
806                          * are already sent to the system through GPIO (and
807                          * have different meaning).
808                          */
809                         input_report_key(input, BTN_1, (data[4] & 0x01));
810                         input_report_key(input, BTN_2, (data[4] & 0x02));
811                         input_report_key(input, BTN_3, (data[4] & 0x04));
812                         input_report_key(input, BTN_4, (data[4] & 0x08));
813
814                         input_report_key(input, BTN_5, (data[4] & 0x10));  /* Right  */
815                         input_report_key(input, BTN_6, (data[4] & 0x20));  /* Up     */
816                         input_report_key(input, BTN_7, (data[4] & 0x40));  /* Left   */
817                         input_report_key(input, BTN_8, (data[4] & 0x80));  /* Down   */
818                         input_report_key(input, BTN_0, (data[3] & 0x01));  /* Center */
819
820                         if (data[4] | (data[3] & 0x01)) {
821                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
822                         } else {
823                                 input_report_abs(input, ABS_MISC, 0);
824                         }
825                 } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
826                         int i;
827
828                         /* Touch ring mode switch has no capacitive sensor */
829                         input_report_key(input, BTN_0, (data[3] & 0x01));
830
831                         /*
832                          * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
833                          * addition to the mechanical switch. Switch data is
834                          * stored in data[4], capacitive data in data[5].
835                          */
836                         for (i = 0; i < 8; i++)
837                                 input_report_key(input, BTN_1 + i, data[4] & (1 << i));
838
839                         if (data[2] & 0x80) {
840                                 input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
841                         } else {
842                                 /* Out of proximity, clear wheel value. */
843                                 input_report_abs(input, ABS_WHEEL, 0);
844                         }
845
846                         if (data[2] | (data[3] & 0x01) | data[4] | data[5]) {
847                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
848                         } else {
849                                 input_report_abs(input, ABS_MISC, 0);
850                         }
851                 } else {
852                         if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
853                                 input_report_key(input, BTN_0, (data[5] & 0x01));
854                                 input_report_key(input, BTN_1, (data[6] & 0x01));
855                                 input_report_key(input, BTN_2, (data[6] & 0x02));
856                                 input_report_key(input, BTN_3, (data[6] & 0x04));
857                                 input_report_key(input, BTN_4, (data[6] & 0x08));
858                                 input_report_key(input, BTN_5, (data[6] & 0x10));
859                                 input_report_key(input, BTN_6, (data[6] & 0x20));
860                                 input_report_key(input, BTN_7, (data[6] & 0x40));
861                                 input_report_key(input, BTN_8, (data[6] & 0x80));
862                                 input_report_key(input, BTN_9, (data[7] & 0x01));
863                                 input_report_key(input, BTN_A, (data[8] & 0x01));
864                                 input_report_key(input, BTN_B, (data[8] & 0x02));
865                                 input_report_key(input, BTN_C, (data[8] & 0x04));
866                                 input_report_key(input, BTN_X, (data[8] & 0x08));
867                                 input_report_key(input, BTN_Y, (data[8] & 0x10));
868                                 input_report_key(input, BTN_Z, (data[8] & 0x20));
869                                 input_report_key(input, BTN_BASE, (data[8] & 0x40));
870                                 input_report_key(input, BTN_BASE2, (data[8] & 0x80));
871
872                                 if (features->type == WACOM_22HD) {
873                                         input_report_key(input, KEY_PROG1, data[9] & 0x01);
874                                         input_report_key(input, KEY_PROG2, data[9] & 0x02);
875                                         input_report_key(input, KEY_PROG3, data[9] & 0x04);
876                                 }
877                         } else {
878                                 input_report_key(input, BTN_0, (data[5] & 0x01));
879                                 input_report_key(input, BTN_1, (data[5] & 0x02));
880                                 input_report_key(input, BTN_2, (data[5] & 0x04));
881                                 input_report_key(input, BTN_3, (data[5] & 0x08));
882                                 input_report_key(input, BTN_4, (data[6] & 0x01));
883                                 input_report_key(input, BTN_5, (data[6] & 0x02));
884                                 input_report_key(input, BTN_6, (data[6] & 0x04));
885                                 input_report_key(input, BTN_7, (data[6] & 0x08));
886                                 input_report_key(input, BTN_8, (data[5] & 0x10));
887                                 input_report_key(input, BTN_9, (data[6] & 0x10));
888                         }
889                         input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
890                         input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
891
892                         if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
893                                 data[2] | (data[3] & 0x1f) | data[4] | data[8] |
894                                 (data[7] & 0x01)) {
895                                 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
896                         } else {
897                                 input_report_abs(input, ABS_MISC, 0);
898                         }
899                 }
900                 return 1;
901         }
902
903         /* process in/out prox events */
904         result = wacom_intuos_inout(wacom);
905         if (result)
906                 return result - 1;
907
908         if (features->type >= INTUOS3S) {
909                 input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
910                 input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
911                 input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
912         } else {
913                 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
914                 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
915                 input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
916         }
917
918         /* process general packets */
919         wacom_intuos_general(wacom);
920
921         /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
922         if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
923
924                 if (data[1] & 0x02) {
925                         /* Rotation packet */
926                         if (features->type >= INTUOS3S) {
927                                 /* I3 marker pen rotation */
928                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
929                                 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
930                                         ((t-1) / 2 + 450)) : (450 - t / 2) ;
931                                 input_report_abs(input, ABS_Z, t);
932                         } else {
933                                 /* 4D mouse rotation packet */
934                                 t = (data[6] << 3) | ((data[7] >> 5) & 7);
935                                 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
936                                         ((t - 1) / 2) : -t / 2);
937                         }
938
939                 } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
940                         /* 4D mouse packet */
941                         input_report_key(input, BTN_LEFT,   data[8] & 0x01);
942                         input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
943                         input_report_key(input, BTN_RIGHT,  data[8] & 0x04);
944
945                         input_report_key(input, BTN_SIDE,   data[8] & 0x20);
946                         input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
947                         t = (data[6] << 2) | ((data[7] >> 6) & 3);
948                         input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
949
950                 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
951                         /* I4 mouse */
952                         if (features->type >= INTUOS4S && features->type <= INTUOSPL) {
953                                 input_report_key(input, BTN_LEFT,   data[6] & 0x01);
954                                 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
955                                 input_report_key(input, BTN_RIGHT,  data[6] & 0x04);
956                                 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
957                                                  - ((data[7] & 0x40) >> 6));
958                                 input_report_key(input, BTN_SIDE,   data[6] & 0x08);
959                                 input_report_key(input, BTN_EXTRA,  data[6] & 0x10);
960
961                                 input_report_abs(input, ABS_TILT_X,
962                                         (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
963                                 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
964                         } else {
965                                 /* 2D mouse packet */
966                                 input_report_key(input, BTN_LEFT,   data[8] & 0x04);
967                                 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
968                                 input_report_key(input, BTN_RIGHT,  data[8] & 0x10);
969                                 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
970                                                  - ((data[8] & 0x02) >> 1));
971
972                                 /* I3 2D mouse side buttons */
973                                 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
974                                         input_report_key(input, BTN_SIDE,   data[8] & 0x40);
975                                         input_report_key(input, BTN_EXTRA,  data[8] & 0x20);
976                                 }
977                         }
978                 } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
979                                 features->type == INTUOS4L || features->type == INTUOS5L ||
980                                 features->type == INTUOSPL) &&
981                            wacom->tool[idx] == BTN_TOOL_LENS) {
982                         /* Lens cursor packets */
983                         input_report_key(input, BTN_LEFT,   data[8] & 0x01);
984                         input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
985                         input_report_key(input, BTN_RIGHT,  data[8] & 0x04);
986                         input_report_key(input, BTN_SIDE,   data[8] & 0x10);
987                         input_report_key(input, BTN_EXTRA,  data[8] & 0x08);
988                 }
989         }
990
991         input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
992         input_report_key(input, wacom->tool[idx], 1);
993         input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
994         wacom->reporting_data = true;
995         return 1;
996 }
997
998 static int int_dist(int x1, int y1, int x2, int y2)
999 {
1000         int x = x2 - x1;
1001         int y = y2 - y1;
1002
1003         return int_sqrt(x*x + y*y);
1004 }
1005
1006 static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
1007                 unsigned char *data)
1008 {
1009         memcpy(wacom->data, data, 10);
1010         wacom_intuos_irq(wacom);
1011
1012         input_sync(wacom->input);
1013         if (wacom->pad_input)
1014                 input_sync(wacom->pad_input);
1015 }
1016
1017 static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1018 {
1019         unsigned char data[WACOM_PKGLEN_MAX];
1020         int i = 1;
1021         unsigned power_raw, battery_capacity, bat_charging, ps_connected;
1022
1023         memcpy(data, wacom->data, len);
1024
1025         switch (data[0]) {
1026         case 0x04:
1027                 wacom_intuos_bt_process_data(wacom, data + i);
1028                 i += 10;
1029                 /* fall through */
1030         case 0x03:
1031                 wacom_intuos_bt_process_data(wacom, data + i);
1032                 i += 10;
1033                 wacom_intuos_bt_process_data(wacom, data + i);
1034                 i += 10;
1035                 power_raw = data[i];
1036                 bat_charging = (power_raw & 0x08) ? 1 : 0;
1037                 ps_connected = (power_raw & 0x10) ? 1 : 0;
1038                 battery_capacity = batcap_i4[power_raw & 0x07];
1039                 wacom_notify_battery(wacom, battery_capacity, bat_charging,
1040                                      ps_connected);
1041                 break;
1042         default:
1043                 dev_dbg(wacom->input->dev.parent,
1044                                 "Unknown report: %d,%d size:%zu\n",
1045                                 data[0], data[1], len);
1046                 return 0;
1047         }
1048         return 0;
1049 }
1050
1051 static int wacom_24hdt_irq(struct wacom_wac *wacom)
1052 {
1053         struct input_dev *input = wacom->input;
1054         unsigned char *data = wacom->data;
1055         int i;
1056         int current_num_contacts = data[61];
1057         int contacts_to_send = 0;
1058         int num_contacts_left = 4; /* maximum contacts per packet */
1059         int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1060         int y_offset = 2;
1061         static int contact_with_no_pen_down_count = 0;
1062
1063         if (wacom->features.type == WACOM_27QHDT) {
1064                 current_num_contacts = data[63];
1065                 num_contacts_left = 10;
1066                 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1067                 y_offset = 0;
1068         }
1069
1070         /*
1071          * First packet resets the counter since only the first
1072          * packet in series will have non-zero current_num_contacts.
1073          */
1074         if (current_num_contacts) {
1075                 wacom->num_contacts_left = current_num_contacts;
1076                 contact_with_no_pen_down_count = 0;
1077         }
1078
1079         contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1080
1081         for (i = 0; i < contacts_to_send; i++) {
1082                 int offset = (byte_per_packet * i) + 1;
1083                 bool touch = (data[offset] & 0x1) && !wacom->shared->stylus_in_proximity;
1084                 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
1085
1086                 if (slot < 0)
1087                         continue;
1088                 input_mt_slot(input, slot);
1089                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1090
1091                 if (touch) {
1092                         int t_x = get_unaligned_le16(&data[offset + 2]);
1093                         int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
1094
1095                         input_report_abs(input, ABS_MT_POSITION_X, t_x);
1096                         input_report_abs(input, ABS_MT_POSITION_Y, t_y);
1097
1098                         if (wacom->features.type != WACOM_27QHDT) {
1099                                 int c_x = get_unaligned_le16(&data[offset + 4]);
1100                                 int c_y = get_unaligned_le16(&data[offset + 8]);
1101                                 int w = get_unaligned_le16(&data[offset + 10]);
1102                                 int h = get_unaligned_le16(&data[offset + 12]);
1103
1104                                 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1105                                 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1106                                                  min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1107                                 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1108                                 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1109                         }
1110                         contact_with_no_pen_down_count++;
1111                 }
1112         }
1113         input_mt_sync_frame(input);
1114
1115         wacom->num_contacts_left -= contacts_to_send;
1116         if (wacom->num_contacts_left <= 0) {
1117                 wacom->num_contacts_left = 0;
1118                 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
1119         }
1120         return 1;
1121 }
1122
1123 static int wacom_mt_touch(struct wacom_wac *wacom)
1124 {
1125         struct input_dev *input = wacom->input;
1126         unsigned char *data = wacom->data;
1127         int i;
1128         int current_num_contacts = data[2];
1129         int contacts_to_send = 0;
1130         int x_offset = 0;
1131         static int contact_with_no_pen_down_count = 0;
1132
1133         /* MTTPC does not support Height and Width */
1134         if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
1135                 x_offset = -4;
1136
1137         /*
1138          * First packet resets the counter since only the first
1139          * packet in series will have non-zero current_num_contacts.
1140          */
1141         if (current_num_contacts) {
1142                 wacom->num_contacts_left = current_num_contacts;
1143                 contact_with_no_pen_down_count = 0;
1144         }
1145
1146         /* There are at most 5 contacts per packet */
1147         contacts_to_send = min(5, wacom->num_contacts_left);
1148
1149         for (i = 0; i < contacts_to_send; i++) {
1150                 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
1151                 bool touch = (data[offset] & 0x1) && !wacom->shared->stylus_in_proximity;
1152                 int id = get_unaligned_le16(&data[offset + 1]);
1153                 int slot = input_mt_get_slot_by_key(input, id);
1154
1155                 if (slot < 0)
1156                         continue;
1157
1158                 input_mt_slot(input, slot);
1159                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1160                 if (touch) {
1161                         int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1162                         int y = get_unaligned_le16(&data[offset + x_offset + 9]);
1163                         input_report_abs(input, ABS_MT_POSITION_X, x);
1164                         input_report_abs(input, ABS_MT_POSITION_Y, y);
1165                         contact_with_no_pen_down_count++;
1166                 }
1167         }
1168         input_mt_sync_frame(input);
1169
1170         wacom->num_contacts_left -= contacts_to_send;
1171         if (wacom->num_contacts_left <= 0) {
1172                 wacom->num_contacts_left = 0;
1173                 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
1174         }
1175         return 1;
1176 }
1177
1178 static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1179 {
1180         struct input_dev *input = wacom->input;
1181         unsigned char *data = wacom->data;
1182         int contact_with_no_pen_down_count = 0;
1183         int i;
1184
1185         for (i = 0; i < 2; i++) {
1186                 int p = data[1] & (1 << i);
1187                 bool touch = p && !wacom->shared->stylus_in_proximity;
1188
1189                 input_mt_slot(input, i);
1190                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1191                 if (touch) {
1192                         int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1193                         int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1194
1195                         input_report_abs(input, ABS_MT_POSITION_X, x);
1196                         input_report_abs(input, ABS_MT_POSITION_Y, y);
1197                         contact_with_no_pen_down_count++;
1198                 }
1199         }
1200         input_mt_sync_frame(input);
1201
1202         /* keep touch state for pen event */
1203         wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
1204
1205         return 1;
1206 }
1207
1208 static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
1209 {
1210         unsigned char *data = wacom->data;
1211         struct input_dev *input = wacom->input;
1212         bool prox = !wacom->shared->stylus_in_proximity;
1213         int x = 0, y = 0;
1214
1215         if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1216                 return 0;
1217
1218         if (len == WACOM_PKGLEN_TPC1FG) {
1219                 prox = prox && (data[0] & 0x01);
1220                 x = get_unaligned_le16(&data[1]);
1221                 y = get_unaligned_le16(&data[3]);
1222         } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1223                 prox = prox && (data[2] & 0x01);
1224                 x = get_unaligned_le16(&data[3]);
1225                 y = get_unaligned_le16(&data[5]);
1226         } else {
1227                 prox = prox && (data[1] & 0x01);
1228                 x = le16_to_cpup((__le16 *)&data[2]);
1229                 y = le16_to_cpup((__le16 *)&data[4]);
1230         }
1231
1232         if (prox) {
1233                 input_report_abs(input, ABS_X, x);
1234                 input_report_abs(input, ABS_Y, y);
1235         }
1236         input_report_key(input, BTN_TOUCH, prox);
1237
1238         /* keep touch state for pen events */
1239         wacom->shared->touch_down = prox;
1240
1241         return 1;
1242 }
1243
1244 static int wacom_tpc_pen(struct wacom_wac *wacom)
1245 {
1246         unsigned char *data = wacom->data;
1247         struct input_dev *input = wacom->input;
1248         bool prox = data[1] & 0x20;
1249
1250         if (!wacom->shared->stylus_in_proximity) /* first in prox */
1251                 /* Going into proximity select tool */
1252                 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
1253
1254         /* keep pen state for touch events */
1255         wacom->shared->stylus_in_proximity = prox;
1256
1257         /* send pen events only when touch is up or forced out */
1258         if (!wacom->shared->touch_down) {
1259                 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1260                 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1261                 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1262                 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
1263                 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
1264                 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1265                 input_report_key(input, wacom->tool[0], prox);
1266                 return 1;
1267         }
1268
1269         return 0;
1270 }
1271
1272 static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1273 {
1274         unsigned char *data = wacom->data;
1275
1276         dev_dbg(wacom->input->dev.parent,
1277                 "%s: received report #%d\n", __func__, data[0]);
1278
1279         switch (len) {
1280         case WACOM_PKGLEN_TPC1FG:
1281                 return wacom_tpc_single_touch(wacom, len);
1282
1283         case WACOM_PKGLEN_TPC2FG:
1284                 return wacom_tpc_mt_touch(wacom);
1285
1286         case WACOM_PKGLEN_PENABLED:
1287                 return wacom_tpc_pen(wacom);
1288
1289         default:
1290                 switch (data[0]) {
1291                 case WACOM_REPORT_TPC1FG:
1292                 case WACOM_REPORT_TPCHID:
1293                 case WACOM_REPORT_TPCST:
1294                 case WACOM_REPORT_TPC1FGE:
1295                         return wacom_tpc_single_touch(wacom, len);
1296
1297                 case WACOM_REPORT_TPCMT:
1298                 case WACOM_REPORT_TPCMT2:
1299                         return wacom_mt_touch(wacom);
1300
1301                 case WACOM_REPORT_PENABLED:
1302                         return wacom_tpc_pen(wacom);
1303                 }
1304         }
1305
1306         return 0;
1307 }
1308
1309 static void wacom_map_usage(struct wacom *wacom, struct hid_usage *usage,
1310                 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1311 {
1312         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1313         struct input_dev *input = wacom_wac->input;
1314         int fmin = field->logical_minimum;
1315         int fmax = field->logical_maximum;
1316
1317         usage->type = type;
1318         usage->code = code;
1319
1320         set_bit(type, input->evbit);
1321
1322         switch (type) {
1323         case EV_ABS:
1324                 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1325                 input_abs_set_res(input, code,
1326                                   hidinput_calc_abs_res(field, code));
1327                 break;
1328         case EV_KEY:
1329                 input_set_capability(input, EV_KEY, code);
1330                 break;
1331         case EV_MSC:
1332                 input_set_capability(input, EV_MSC, code);
1333                 break;
1334         }
1335 }
1336
1337 static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
1338                 struct hid_field *field, struct hid_usage *usage)
1339 {
1340         struct wacom *wacom = hid_get_drvdata(hdev);
1341
1342         switch (usage->hid) {
1343         case HID_GD_X:
1344                 wacom_map_usage(wacom, usage, field, EV_ABS, ABS_X, 4);
1345                 break;
1346         case HID_GD_Y:
1347                 wacom_map_usage(wacom, usage, field, EV_ABS, ABS_Y, 4);
1348                 break;
1349         case HID_DG_TIPPRESSURE:
1350                 wacom_map_usage(wacom, usage, field, EV_ABS, ABS_PRESSURE, 0);
1351                 break;
1352         case HID_DG_INRANGE:
1353                 wacom_map_usage(wacom, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1354                 break;
1355         case HID_DG_INVERT:
1356                 wacom_map_usage(wacom, usage, field, EV_KEY,
1357                                 BTN_TOOL_RUBBER, 0);
1358                 break;
1359         case HID_DG_ERASER:
1360         case HID_DG_TIPSWITCH:
1361                 wacom_map_usage(wacom, usage, field, EV_KEY, BTN_TOUCH, 0);
1362                 break;
1363         case HID_DG_BARRELSWITCH:
1364                 wacom_map_usage(wacom, usage, field, EV_KEY, BTN_STYLUS, 0);
1365                 break;
1366         case HID_DG_BARRELSWITCH2:
1367                 wacom_map_usage(wacom, usage, field, EV_KEY, BTN_STYLUS2, 0);
1368                 break;
1369         case HID_DG_TOOLSERIALNUMBER:
1370                 wacom_map_usage(wacom, usage, field, EV_MSC, MSC_SERIAL, 0);
1371                 break;
1372         }
1373 }
1374
1375 static int wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
1376                 struct hid_usage *usage, __s32 value)
1377 {
1378         struct wacom *wacom = hid_get_drvdata(hdev);
1379         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1380         struct input_dev *input = wacom_wac->input;
1381
1382         /* checking which Tool / tip switch to send */
1383         switch (usage->hid) {
1384         case HID_DG_INRANGE:
1385                 wacom_wac->hid_data.inrange_state = value;
1386                 return 0;
1387         case HID_DG_INVERT:
1388                 wacom_wac->hid_data.invert_state = value;
1389                 return 0;
1390         case HID_DG_ERASER:
1391         case HID_DG_TIPSWITCH:
1392                 wacom_wac->hid_data.tipswitch |= value;
1393                 return 0;
1394         }
1395
1396         /* send pen events only when touch is up or forced out */
1397         if (!usage->type || wacom_wac->shared->touch_down)
1398                 return 0;
1399
1400         input_event(input, usage->type, usage->code, value);
1401
1402         return 0;
1403 }
1404
1405 static void wacom_wac_pen_report(struct hid_device *hdev,
1406                 struct hid_report *report)
1407 {
1408         struct wacom *wacom = hid_get_drvdata(hdev);
1409         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1410         struct input_dev *input = wacom_wac->input;
1411         bool prox = wacom_wac->hid_data.inrange_state;
1412
1413         if (!wacom_wac->shared->stylus_in_proximity) /* first in prox */
1414                 /* Going into proximity select tool */
1415                 wacom_wac->tool[0] = wacom_wac->hid_data.invert_state ?
1416                                                 BTN_TOOL_RUBBER : BTN_TOOL_PEN;
1417
1418         /* keep pen state for touch events */
1419         wacom_wac->shared->stylus_in_proximity = prox;
1420
1421         /* send pen events only when touch is up or forced out */
1422         if (!wacom_wac->shared->touch_down) {
1423                 input_report_key(input, BTN_TOUCH,
1424                                 wacom_wac->hid_data.tipswitch);
1425                 input_report_key(input, wacom_wac->tool[0], prox);
1426
1427                 wacom_wac->hid_data.tipswitch = false;
1428
1429                 input_sync(input);
1430         }
1431 }
1432
1433 static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
1434                 struct hid_field *field, struct hid_usage *usage)
1435 {
1436         struct wacom *wacom = hid_get_drvdata(hdev);
1437         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1438         struct wacom_features *features = &wacom_wac->features;
1439         unsigned touch_max = wacom_wac->features.touch_max;
1440
1441         switch (usage->hid) {
1442         case HID_GD_X:
1443                 features->last_slot_field = usage->hid;
1444                 if (touch_max == 1)
1445                         wacom_map_usage(wacom, usage, field, EV_ABS, ABS_X, 4);
1446                 else
1447                         wacom_map_usage(wacom, usage, field, EV_ABS,
1448                                         ABS_MT_POSITION_X, 4);
1449                 break;
1450         case HID_GD_Y:
1451                 features->last_slot_field = usage->hid;
1452                 if (touch_max == 1)
1453                         wacom_map_usage(wacom, usage, field, EV_ABS, ABS_Y, 4);
1454                 else
1455                         wacom_map_usage(wacom, usage, field, EV_ABS,
1456                                         ABS_MT_POSITION_Y, 4);
1457                 break;
1458         case HID_DG_CONTACTID:
1459                 features->last_slot_field = usage->hid;
1460                 break;
1461         case HID_DG_INRANGE:
1462                 features->last_slot_field = usage->hid;
1463                 break;
1464         case HID_DG_INVERT:
1465                 features->last_slot_field = usage->hid;
1466                 break;
1467         case HID_DG_TIPSWITCH:
1468                 features->last_slot_field = usage->hid;
1469                 wacom_map_usage(wacom, usage, field, EV_KEY, BTN_TOUCH, 0);
1470                 break;
1471         }
1472 }
1473
1474 static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
1475                 struct input_dev *input)
1476 {
1477         struct hid_data *hid_data = &wacom_wac->hid_data;
1478         bool mt = wacom_wac->features.touch_max > 1;
1479         bool prox = hid_data->tipswitch &&
1480                     !wacom_wac->shared->stylus_in_proximity;
1481
1482         if (mt) {
1483                 int slot;
1484
1485                 slot = input_mt_get_slot_by_key(input, hid_data->id);
1486                 input_mt_slot(input, slot);
1487                 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
1488         }
1489         else {
1490                 input_report_key(input, BTN_TOUCH, prox);
1491         }
1492
1493         if (prox) {
1494                 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
1495                                  hid_data->x);
1496                 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
1497                                  hid_data->y);
1498         }
1499 }
1500
1501 static int wacom_wac_finger_event(struct hid_device *hdev,
1502                 struct hid_field *field, struct hid_usage *usage, __s32 value)
1503 {
1504         struct wacom *wacom = hid_get_drvdata(hdev);
1505         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1506
1507         switch (usage->hid) {
1508         case HID_GD_X:
1509                 wacom_wac->hid_data.x = value;
1510                 break;
1511         case HID_GD_Y:
1512                 wacom_wac->hid_data.y = value;
1513                 break;
1514         case HID_DG_CONTACTID:
1515                 wacom_wac->hid_data.id = value;
1516                 break;
1517         case HID_DG_TIPSWITCH:
1518                 wacom_wac->hid_data.tipswitch = value;
1519                 break;
1520         }
1521
1522
1523         if (usage->usage_index + 1 == field->report_count) {
1524                 if (usage->hid == wacom_wac->features.last_slot_field)
1525                         wacom_wac_finger_slot(wacom_wac, wacom_wac->input);
1526         }
1527
1528         return 0;
1529 }
1530
1531 static int wacom_wac_finger_count_touches(struct hid_device *hdev)
1532 {
1533         struct wacom *wacom = hid_get_drvdata(hdev);
1534         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1535         struct input_dev *input = wacom_wac->input;
1536         unsigned touch_max = wacom_wac->features.touch_max;
1537         int count = 0;
1538         int i;
1539
1540         if (touch_max == 1)
1541                 return wacom_wac->hid_data.tipswitch &&
1542                        !wacom_wac->shared->stylus_in_proximity;
1543
1544         for (i = 0; i < input->mt->num_slots; i++) {
1545                 struct input_mt_slot *ps = &input->mt->slots[i];
1546                 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1547                 if (id >= 0)
1548                         count++;
1549         }
1550
1551         return count;
1552 }
1553
1554 static void wacom_wac_finger_report(struct hid_device *hdev,
1555                 struct hid_report *report)
1556 {
1557         struct wacom *wacom = hid_get_drvdata(hdev);
1558         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1559         struct input_dev *input = wacom_wac->input;
1560         unsigned touch_max = wacom_wac->features.touch_max;
1561
1562         if (touch_max > 1)
1563                 input_mt_sync_frame(input);
1564
1565         input_sync(input);
1566
1567         /* keep touch state for pen event */
1568         wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(hdev);
1569 }
1570
1571 void wacom_wac_usage_mapping(struct hid_device *hdev,
1572                 struct hid_field *field, struct hid_usage *usage)
1573 {
1574         struct wacom *wacom = hid_get_drvdata(hdev);
1575         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1576         struct input_dev *input = wacom_wac->input;
1577
1578         /* currently, only direct devices have proper hid report descriptors */
1579         __set_bit(INPUT_PROP_DIRECT, input->propbit);
1580
1581         if (WACOM_PEN_FIELD(field))
1582                 return wacom_wac_pen_usage_mapping(hdev, field, usage);
1583
1584         if (WACOM_FINGER_FIELD(field))
1585                 return wacom_wac_finger_usage_mapping(hdev, field, usage);
1586 }
1587
1588 int wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
1589                 struct hid_usage *usage, __s32 value)
1590 {
1591         struct wacom *wacom = hid_get_drvdata(hdev);
1592
1593         if (wacom->wacom_wac.features.type != HID_GENERIC)
1594                 return 0;
1595
1596         if (WACOM_PEN_FIELD(field))
1597                 return wacom_wac_pen_event(hdev, field, usage, value);
1598
1599         if (WACOM_FINGER_FIELD(field))
1600                 return wacom_wac_finger_event(hdev, field, usage, value);
1601
1602         return 0;
1603 }
1604
1605 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
1606 {
1607         struct wacom *wacom = hid_get_drvdata(hdev);
1608         struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1609         struct hid_field *field = report->field[0];
1610
1611         if (wacom_wac->features.type != HID_GENERIC)
1612                 return;
1613
1614         if (WACOM_PEN_FIELD(field))
1615                 return wacom_wac_pen_report(hdev, report);
1616
1617         if (WACOM_FINGER_FIELD(field))
1618                 return wacom_wac_finger_report(hdev, report);
1619 }
1620
1621 static int wacom_bpt_touch(struct wacom_wac *wacom)
1622 {
1623         struct wacom_features *features = &wacom->features;
1624         struct input_dev *input = wacom->input;
1625         struct input_dev *pad_input = wacom->pad_input;
1626         unsigned char *data = wacom->data;
1627         int i;
1628         int contact_with_no_pen_down_count = 0;
1629
1630         if (data[0] != 0x02)
1631             return 0;
1632
1633         for (i = 0; i < 2; i++) {
1634                 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
1635                 bool touch = data[offset + 3] & 0x80;
1636
1637                 /*
1638                  * Touch events need to be disabled while stylus is
1639                  * in proximity because user's hand is resting on touchpad
1640                  * and sending unwanted events.  User expects tablet buttons
1641                  * to continue working though.
1642                  */
1643                 touch = touch && !wacom->shared->stylus_in_proximity;
1644
1645                 input_mt_slot(input, i);
1646                 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1647                 if (touch) {
1648                         int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
1649                         int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
1650                         if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
1651                                 x <<= 5;
1652                                 y <<= 5;
1653                         }
1654                         input_report_abs(input, ABS_MT_POSITION_X, x);
1655                         input_report_abs(input, ABS_MT_POSITION_Y, y);
1656                         contact_with_no_pen_down_count++;
1657                 }
1658         }
1659
1660         input_mt_sync_frame(input);
1661
1662         input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
1663         input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
1664         input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
1665         input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
1666         wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
1667
1668         return 1;
1669 }
1670
1671 static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, int last_touch_count)
1672 {
1673         struct wacom_features *features = &wacom->features;
1674         struct input_dev *input = wacom->input;
1675         bool touch = data[1] & 0x80;
1676         int slot = input_mt_get_slot_by_key(input, data[0]);
1677
1678         if (slot < 0)
1679                 return 0;
1680
1681         touch = touch && !wacom->shared->stylus_in_proximity;
1682
1683         input_mt_slot(input, slot);
1684         input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1685
1686         if (touch) {
1687                 int x = (data[2] << 4) | (data[4] >> 4);
1688                 int y = (data[3] << 4) | (data[4] & 0x0f);
1689                 int width, height;
1690
1691                 if (features->type >= INTUOSPS && features->type <= INTUOSPL) {
1692                         width  = data[5] * 100;
1693                         height = data[6] * 100;
1694                 } else {
1695                         /*
1696                          * "a" is a scaled-down area which we assume is
1697                          * roughly circular and which can be described as:
1698                          * a=(pi*r^2)/C.
1699                          */
1700                         int a = data[5];
1701                         int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
1702                         int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
1703                         width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
1704                         height = width * y_res / x_res;
1705                 }
1706
1707                 input_report_abs(input, ABS_MT_POSITION_X, x);
1708                 input_report_abs(input, ABS_MT_POSITION_Y, y);
1709                 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
1710                 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
1711                 last_touch_count++;
1712         }
1713         return last_touch_count;
1714 }
1715
1716 static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
1717 {
1718         struct input_dev *input = wacom->pad_input;
1719         struct wacom_features *features = &wacom->features;
1720
1721         if (features->type == INTUOSHT) {
1722                 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
1723                 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
1724         } else {
1725                 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
1726                 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
1727         }
1728         input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
1729         input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
1730 }
1731
1732 static int wacom_bpt3_touch(struct wacom_wac *wacom)
1733 {
1734         struct input_dev *input = wacom->input;
1735         unsigned char *data = wacom->data;
1736         int count = data[1] & 0x07;
1737         int i;
1738         int contact_with_no_pen_down_count = 0;
1739
1740         if (data[0] != 0x02)
1741             return 0;
1742
1743         /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
1744         for (i = 0; i < count; i++) {
1745                 int offset = (8 * i) + 2;
1746                 int msg_id = data[offset];
1747
1748                 if (msg_id >= 2 && msg_id <= 17)
1749                         contact_with_no_pen_down_count = 
1750                             wacom_bpt3_touch_msg(wacom, data + offset,
1751                                                  contact_with_no_pen_down_count);
1752                 else if (msg_id == 128)
1753                         wacom_bpt3_button_msg(wacom, data + offset);
1754
1755         }
1756         input_mt_sync_frame(input);
1757         wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
1758
1759         return 1;
1760 }
1761
1762 static int wacom_bpt_pen(struct wacom_wac *wacom)
1763 {
1764         struct wacom_features *features = &wacom->features;
1765         struct input_dev *input = wacom->input;
1766         unsigned char *data = wacom->data;
1767         int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
1768
1769         if (data[0] != WACOM_REPORT_PENABLED)
1770             return 0;
1771
1772         prox = (data[1] & 0x20) == 0x20;
1773
1774         /*
1775          * All reports shared between PEN and RUBBER tool must be
1776          * forced to a known starting value (zero) when transitioning to
1777          * out-of-prox.
1778          *
1779          * If not reset then, to userspace, it will look like lost events
1780          * if new tool comes in-prox with same values as previous tool sent.
1781          *
1782          * Hardware does report zero in most out-of-prox cases but not all.
1783          */
1784         if (prox) {
1785                 if (!wacom->shared->stylus_in_proximity) {
1786                         if (data[1] & 0x08) {
1787                                 wacom->tool[0] = BTN_TOOL_RUBBER;
1788                                 wacom->id[0] = ERASER_DEVICE_ID;
1789                         } else {
1790                                 wacom->tool[0] = BTN_TOOL_PEN;
1791                                 wacom->id[0] = STYLUS_DEVICE_ID;
1792                         }
1793                         wacom->shared->stylus_in_proximity = true;
1794                 }
1795                 x = le16_to_cpup((__le16 *)&data[2]);
1796                 y = le16_to_cpup((__le16 *)&data[4]);
1797                 p = le16_to_cpup((__le16 *)&data[6]);
1798                 /*
1799                  * Convert distance from out prox to distance from tablet.
1800                  * distance will be greater than distance_max once
1801                  * touching and applying pressure; do not report negative
1802                  * distance.
1803                  */
1804                 if (data[8] <= features->distance_max)
1805                         d = features->distance_max - data[8];
1806
1807                 pen = data[1] & 0x01;
1808                 btn1 = data[1] & 0x02;
1809                 btn2 = data[1] & 0x04;
1810         }
1811
1812         input_report_key(input, BTN_TOUCH, pen);
1813         input_report_key(input, BTN_STYLUS, btn1);
1814         input_report_key(input, BTN_STYLUS2, btn2);
1815
1816         input_report_abs(input, ABS_X, x);
1817         input_report_abs(input, ABS_Y, y);
1818         input_report_abs(input, ABS_PRESSURE, p);
1819         input_report_abs(input, ABS_DISTANCE, d);
1820
1821         if (!prox) {
1822                 wacom->id[0] = 0;
1823                 wacom->shared->stylus_in_proximity = false;
1824         }
1825
1826         input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
1827         input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
1828
1829         return 1;
1830 }
1831
1832 static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
1833 {
1834         if (len == WACOM_PKGLEN_BBTOUCH)
1835                 return wacom_bpt_touch(wacom);
1836         else if (len == WACOM_PKGLEN_BBTOUCH3)
1837                 return wacom_bpt3_touch(wacom);
1838         else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
1839                 return wacom_bpt_pen(wacom);
1840
1841         return 0;
1842 }
1843
1844 static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
1845                 unsigned char *data)
1846 {
1847         unsigned char prefix;
1848
1849         /*
1850          * We need to reroute the event from the debug interface to the
1851          * pen interface.
1852          * We need to add the report ID to the actual pen report, so we
1853          * temporary overwrite the first byte to prevent having to kzalloc/kfree
1854          * and memcpy the report.
1855          */
1856         prefix = data[0];
1857         data[0] = WACOM_REPORT_BPAD_PEN;
1858
1859         /*
1860          * actually reroute the event.
1861          * No need to check if wacom->shared->pen is valid, hid_input_report()
1862          * will check for us.
1863          */
1864         hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
1865                          WACOM_PKGLEN_PENABLED, 1);
1866
1867         data[0] = prefix;
1868 }
1869
1870 static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
1871                 unsigned char *data)
1872 {
1873         struct input_dev *input = wacom->input;
1874         unsigned char *finger_data, prefix;
1875         unsigned id;
1876         int x, y;
1877         bool valid;
1878
1879         prefix = data[0];
1880
1881         for (id = 0; id < wacom->features.touch_max; id++) {
1882                 valid = !!(prefix & BIT(id)) &&
1883                         !wacom->shared->stylus_in_proximity;
1884
1885                 input_mt_slot(input, id);
1886                 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
1887
1888                 if (!valid)
1889                         continue;
1890
1891                 finger_data = data + 1 + id * 3;
1892                 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
1893                 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
1894
1895                 input_report_abs(input, ABS_MT_POSITION_X, x);
1896                 input_report_abs(input, ABS_MT_POSITION_Y, y);
1897         }
1898
1899         input_mt_sync_frame(input);
1900
1901         input_report_key(input, BTN_LEFT, prefix & 0x40);
1902         input_report_key(input, BTN_RIGHT, prefix & 0x80);
1903
1904         /* keep touch state for pen event */
1905         wacom->shared->touch_down = !!prefix &&
1906                                     !wacom->shared->stylus_in_proximity;
1907
1908         return 1;
1909 }
1910
1911 static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
1912 {
1913         unsigned char *data = wacom->data;
1914
1915         if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
1916               (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
1917             (data[0] != WACOM_REPORT_BPAD_TOUCH))
1918                 return 0;
1919
1920         if (data[1] & 0x01)
1921                 wacom_bamboo_pad_pen_event(wacom, &data[1]);
1922
1923         if (data[1] & 0x02)
1924                 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
1925
1926         return 0;
1927 }
1928
1929 static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1930 {
1931         unsigned char *data = wacom->data;
1932         int connected;
1933
1934         if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
1935                 return 0;
1936
1937         connected = data[1] & 0x01;
1938         if (connected) {
1939                 int pid, battery, charging;
1940
1941                 if ((wacom->shared->type == INTUOSHT) &&
1942                     wacom->shared->touch_input &&
1943                     wacom->shared->touch_max) {
1944                         input_report_switch(wacom->shared->touch_input,
1945                                         SW_MUTE_DEVICE, data[5] & 0x40);
1946                         input_sync(wacom->shared->touch_input);
1947                 }
1948
1949                 pid = get_unaligned_be16(&data[6]);
1950                 battery = (data[5] & 0x3f) * 100 / 31;
1951                 charging = !!(data[5] & 0x80);
1952                 if (wacom->pid != pid) {
1953                         wacom->pid = pid;
1954                         wacom_schedule_work(wacom);
1955                 }
1956
1957                 if (wacom->shared->type)
1958                         wacom_notify_battery(wacom, battery, charging, 0);
1959
1960         } else if (wacom->pid != 0) {
1961                 /* disconnected while previously connected */
1962                 wacom->pid = 0;
1963                 wacom_schedule_work(wacom);
1964                 wacom_notify_battery(wacom, 0, 0, 0);
1965         }
1966
1967         return 0;
1968 }
1969
1970 static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
1971 {
1972         struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1973         struct wacom_features *features = &wacom_wac->features;
1974         unsigned char *data = wacom_wac->data;
1975
1976         if (data[0] != WACOM_REPORT_USB)
1977                 return 0;
1978
1979         if (features->type == INTUOSHT &&
1980             wacom_wac->shared->touch_input &&
1981             features->touch_max) {
1982                 input_report_switch(wacom_wac->shared->touch_input,
1983                                     SW_MUTE_DEVICE, data[8] & 0x40);
1984                 input_sync(wacom_wac->shared->touch_input);
1985         }
1986
1987         if (data[9] & 0x02) { /* wireless module is attached */
1988                 int battery = (data[8] & 0x3f) * 100 / 31;
1989                 bool charging = !!(data[8] & 0x80);
1990
1991                 wacom_notify_battery(wacom_wac, battery, charging,
1992                                      1);
1993
1994                 if (!wacom->battery.dev &&
1995                     !(features->quirks & WACOM_QUIRK_BATTERY)) {
1996                         features->quirks |= WACOM_QUIRK_BATTERY;
1997                         INIT_WORK(&wacom->work, wacom_battery_work);
1998                         wacom_schedule_work(wacom_wac);
1999                 }
2000         }
2001         else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
2002                  wacom->battery.dev) {
2003                 features->quirks &= ~WACOM_QUIRK_BATTERY;
2004                 INIT_WORK(&wacom->work, wacom_battery_work);
2005                 wacom_schedule_work(wacom_wac);
2006                 wacom_notify_battery(wacom_wac, 0, 0, 0);
2007         }
2008         return 0;
2009 }
2010
2011 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
2012 {
2013         bool sync;
2014
2015         switch (wacom_wac->features.type) {
2016         case PENPARTNER:
2017                 sync = wacom_penpartner_irq(wacom_wac);
2018                 break;
2019
2020         case PL:
2021                 sync = wacom_pl_irq(wacom_wac);
2022                 break;
2023
2024         case WACOM_G4:
2025         case GRAPHIRE:
2026         case GRAPHIRE_BT:
2027         case WACOM_MO:
2028                 sync = wacom_graphire_irq(wacom_wac);
2029                 break;
2030
2031         case PTU:
2032                 sync = wacom_ptu_irq(wacom_wac);
2033                 break;
2034
2035         case DTU:
2036                 sync = wacom_dtu_irq(wacom_wac);
2037                 break;
2038
2039         case DTUS:
2040         case DTUSX:
2041                 sync = wacom_dtus_irq(wacom_wac);
2042                 break;
2043
2044         case INTUOS:
2045         case INTUOS3S:
2046         case INTUOS3:
2047         case INTUOS3L:
2048         case INTUOS4S:
2049         case INTUOS4:
2050         case INTUOS4L:
2051         case CINTIQ:
2052         case WACOM_BEE:
2053         case WACOM_13HD:
2054         case WACOM_21UX2:
2055         case WACOM_22HD:
2056         case WACOM_24HD:
2057         case WACOM_27QHD:
2058         case DTK:
2059         case CINTIQ_HYBRID:
2060                 sync = wacom_intuos_irq(wacom_wac);
2061                 break;
2062
2063         case INTUOS4WL:
2064                 sync = wacom_intuos_bt_irq(wacom_wac, len);
2065                 break;
2066
2067         case WACOM_24HDT:
2068         case WACOM_27QHDT:
2069                 sync = wacom_24hdt_irq(wacom_wac);
2070                 break;
2071
2072         case INTUOS5S:
2073         case INTUOS5:
2074         case INTUOS5L:
2075         case INTUOSPS:
2076         case INTUOSPM:
2077         case INTUOSPL:
2078                 if (len == WACOM_PKGLEN_BBTOUCH3)
2079                         sync = wacom_bpt3_touch(wacom_wac);
2080                 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
2081                         sync = wacom_status_irq(wacom_wac, len);
2082                 else
2083                         sync = wacom_intuos_irq(wacom_wac);
2084                 break;
2085
2086         case TABLETPC:
2087         case TABLETPCE:
2088         case TABLETPC2FG:
2089         case MTSCREEN:
2090         case MTTPC:
2091         case MTTPC_B:
2092                 sync = wacom_tpc_irq(wacom_wac, len);
2093                 break;
2094
2095         case BAMBOO_PT:
2096         case INTUOSHT:
2097                 if (wacom_wac->data[0] == WACOM_REPORT_USB)
2098                         sync = wacom_status_irq(wacom_wac, len);
2099                 else
2100                         sync = wacom_bpt_irq(wacom_wac, len);
2101                 break;
2102
2103         case BAMBOO_PAD:
2104                 sync = wacom_bamboo_pad_irq(wacom_wac, len);
2105                 break;
2106
2107         case WIRELESS:
2108                 sync = wacom_wireless_irq(wacom_wac, len);
2109                 break;
2110
2111         default:
2112                 sync = false;
2113                 break;
2114         }
2115
2116         if (sync) {
2117                 input_sync(wacom_wac->input);
2118                 if (wacom_wac->pad_input)
2119                         input_sync(wacom_wac->pad_input);
2120         }
2121 }
2122
2123 static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
2124 {
2125         struct input_dev *input_dev = wacom_wac->input;
2126
2127         input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
2128
2129         __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2130         __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2131         __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
2132         __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
2133         __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
2134         __set_bit(BTN_STYLUS, input_dev->keybit);
2135         __set_bit(BTN_STYLUS2, input_dev->keybit);
2136
2137         input_set_abs_params(input_dev, ABS_DISTANCE,
2138                              0, wacom_wac->features.distance_max, 0, 0);
2139         input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
2140         input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, 0, 0);
2141         input_abs_set_res(input_dev, ABS_TILT_X, 57);
2142         input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, 0, 0);
2143         input_abs_set_res(input_dev, ABS_TILT_Y, 57);
2144 }
2145
2146 static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
2147 {
2148         struct input_dev *input_dev = wacom_wac->input;
2149
2150         input_set_capability(input_dev, EV_REL, REL_WHEEL);
2151
2152         wacom_setup_cintiq(wacom_wac);
2153
2154         __set_bit(BTN_LEFT, input_dev->keybit);
2155         __set_bit(BTN_RIGHT, input_dev->keybit);
2156         __set_bit(BTN_MIDDLE, input_dev->keybit);
2157         __set_bit(BTN_SIDE, input_dev->keybit);
2158         __set_bit(BTN_EXTRA, input_dev->keybit);
2159         __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2160         __set_bit(BTN_TOOL_LENS, input_dev->keybit);
2161
2162         input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
2163         input_abs_set_res(input_dev, ABS_RZ, 287);
2164         input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
2165 }
2166
2167 void wacom_setup_device_quirks(struct wacom_features *features)
2168 {
2169
2170         /* touch device found but size is not defined. use default */
2171         if (features->device_type == BTN_TOOL_FINGER && !features->x_max) {
2172                 features->x_max = 1023;
2173                 features->y_max = 1023;
2174         }
2175
2176         /* these device have multiple inputs */
2177         if (features->type >= WIRELESS ||
2178             (features->type >= INTUOS5S && features->type <= INTUOSHT) ||
2179             (features->oVid && features->oPid))
2180                 features->quirks |= WACOM_QUIRK_MULTI_INPUT;
2181
2182         /* quirk for bamboo touch with 2 low res touches */
2183         if (features->type == BAMBOO_PT &&
2184             features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2185                 features->x_max <<= 5;
2186                 features->y_max <<= 5;
2187                 features->x_fuzz <<= 5;
2188                 features->y_fuzz <<= 5;
2189                 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
2190         }
2191
2192         if (features->type == WIRELESS) {
2193
2194                 /* monitor never has input and pen/touch have delayed create */
2195                 features->quirks |= WACOM_QUIRK_NO_INPUT;
2196
2197                 /* must be monitor interface if no device_type set */
2198                 if (!features->device_type) {
2199                         features->quirks |= WACOM_QUIRK_MONITOR;
2200                         features->quirks |= WACOM_QUIRK_BATTERY;
2201                 }
2202         }
2203 }
2204
2205 static void wacom_abs_set_axis(struct input_dev *input_dev,
2206                                struct wacom_wac *wacom_wac)
2207 {
2208         struct wacom_features *features = &wacom_wac->features;
2209
2210         if (features->device_type == BTN_TOOL_PEN) {
2211                 input_set_abs_params(input_dev, ABS_X, features->x_min,
2212                                      features->x_max, features->x_fuzz, 0);
2213                 input_set_abs_params(input_dev, ABS_Y, features->y_min,
2214                                      features->y_max, features->y_fuzz, 0);
2215                 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
2216                         features->pressure_max, features->pressure_fuzz, 0);
2217
2218                 /* penabled devices have fixed resolution for each model */
2219                 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
2220                 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
2221         } else {
2222                 if (features->touch_max == 1) {
2223                         input_set_abs_params(input_dev, ABS_X, 0,
2224                                 features->x_max, features->x_fuzz, 0);
2225                         input_set_abs_params(input_dev, ABS_Y, 0,
2226                                 features->y_max, features->y_fuzz, 0);
2227                         input_abs_set_res(input_dev, ABS_X,
2228                                           features->x_resolution);
2229                         input_abs_set_res(input_dev, ABS_Y,
2230                                           features->y_resolution);
2231                 }
2232
2233                 if (features->touch_max > 1) {
2234                         input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
2235                                 features->x_max, features->x_fuzz, 0);
2236                         input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
2237                                 features->y_max, features->y_fuzz, 0);
2238                         input_abs_set_res(input_dev, ABS_MT_POSITION_X,
2239                                           features->x_resolution);
2240                         input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
2241                                           features->y_resolution);
2242                 }
2243         }
2244 }
2245
2246 int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
2247                                    struct wacom_wac *wacom_wac)
2248 {
2249         struct wacom_features *features = &wacom_wac->features;
2250
2251         input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
2252
2253         if (features->type == HID_GENERIC)
2254                 /* setup has already been done */
2255                 return 0;
2256
2257         __set_bit(BTN_TOUCH, input_dev->keybit);
2258         __set_bit(ABS_MISC, input_dev->absbit);
2259
2260         wacom_abs_set_axis(input_dev, wacom_wac);
2261
2262         switch (features->type) {
2263         case GRAPHIRE_BT:
2264                 __clear_bit(ABS_MISC, input_dev->absbit);
2265
2266         case WACOM_MO:
2267         case WACOM_G4:
2268                 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2269                                               features->distance_max,
2270                                               0, 0);
2271                 /* fall through */
2272
2273         case GRAPHIRE:
2274                 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2275
2276                 __set_bit(BTN_LEFT, input_dev->keybit);
2277                 __set_bit(BTN_RIGHT, input_dev->keybit);
2278                 __set_bit(BTN_MIDDLE, input_dev->keybit);
2279
2280                 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2281                 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2282                 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2283                 __set_bit(BTN_STYLUS, input_dev->keybit);
2284                 __set_bit(BTN_STYLUS2, input_dev->keybit);
2285
2286                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2287                 break;
2288
2289         case WACOM_27QHD:
2290         case WACOM_24HD:
2291         case DTK:
2292         case WACOM_22HD:
2293         case WACOM_21UX2:
2294         case WACOM_BEE:
2295         case CINTIQ:
2296         case WACOM_13HD:
2297         case CINTIQ_HYBRID:
2298                 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2299                 input_abs_set_res(input_dev, ABS_Z, 287);
2300                 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
2301                 wacom_setup_cintiq(wacom_wac);
2302                 break;
2303
2304         case INTUOS3:
2305         case INTUOS3L:
2306         case INTUOS3S:
2307         case INTUOS4:
2308         case INTUOS4WL:
2309         case INTUOS4L:
2310         case INTUOS4S:
2311                 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2312                 input_abs_set_res(input_dev, ABS_Z, 287);
2313                 /* fall through */
2314
2315         case INTUOS:
2316                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2317
2318                 wacom_setup_intuos(wacom_wac);
2319                 break;
2320
2321         case INTUOS5:
2322         case INTUOS5L:
2323         case INTUOSPM:
2324         case INTUOSPL:
2325         case INTUOS5S:
2326         case INTUOSPS:
2327                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2328
2329                 if (features->device_type == BTN_TOOL_PEN) {
2330                         input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2331                                               features->distance_max,
2332                                               0, 0);
2333
2334                         input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2335                         input_abs_set_res(input_dev, ABS_Z, 287);
2336
2337                         wacom_setup_intuos(wacom_wac);
2338                 } else if (features->device_type == BTN_TOOL_FINGER) {
2339                         __clear_bit(ABS_MISC, input_dev->absbit);
2340
2341                         input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
2342                                              0, features->x_max, 0, 0);
2343                         input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
2344                                              0, features->y_max, 0, 0);
2345                         input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
2346                 }
2347                 break;
2348
2349         case WACOM_24HDT:
2350                 if (features->device_type == BTN_TOOL_FINGER) {
2351                         input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
2352                         input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
2353                         input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
2354                         input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
2355                 }
2356                 /* fall through */
2357
2358         case WACOM_27QHDT:
2359         case MTSCREEN:
2360         case MTTPC:
2361         case MTTPC_B:
2362         case TABLETPC2FG:
2363                 if (features->device_type == BTN_TOOL_FINGER && features->touch_max > 1)
2364                         input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
2365                 /* fall through */
2366
2367         case TABLETPC:
2368         case TABLETPCE:
2369                 __clear_bit(ABS_MISC, input_dev->absbit);
2370
2371                 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
2372
2373                 if (features->device_type != BTN_TOOL_PEN)
2374                         break;  /* no need to process stylus stuff */
2375
2376                 /* fall through */
2377
2378         case DTUS:
2379         case DTUSX:
2380         case PL:
2381         case DTU:
2382                 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2383                 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2384                 __set_bit(BTN_STYLUS, input_dev->keybit);
2385                 __set_bit(BTN_STYLUS2, input_dev->keybit);
2386
2387                 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
2388                 break;
2389
2390         case PTU:
2391                 __set_bit(BTN_STYLUS2, input_dev->keybit);
2392                 /* fall through */
2393
2394         case PENPARTNER:
2395                 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2396                 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2397                 __set_bit(BTN_STYLUS, input_dev->keybit);
2398
2399                 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2400                 break;
2401
2402         case INTUOSHT:
2403                 if (features->touch_max &&
2404                     features->device_type == BTN_TOOL_FINGER) {
2405                         input_dev->evbit[0] |= BIT_MASK(EV_SW);
2406                         __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
2407                 }
2408                 /* fall through */
2409
2410         case BAMBOO_PT:
2411                 __clear_bit(ABS_MISC, input_dev->absbit);
2412
2413                 if (features->device_type == BTN_TOOL_FINGER) {
2414
2415                         if (features->touch_max) {
2416                                 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
2417                                         input_set_abs_params(input_dev,
2418                                                      ABS_MT_TOUCH_MAJOR,
2419                                                      0, features->x_max, 0, 0);
2420                                         input_set_abs_params(input_dev,
2421                                                      ABS_MT_TOUCH_MINOR,
2422                                                      0, features->y_max, 0, 0);
2423                                 }
2424                                 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
2425                         } else {
2426                                 /* buttons/keys only interface */
2427                                 __clear_bit(ABS_X, input_dev->absbit);
2428                                 __clear_bit(ABS_Y, input_dev->absbit);
2429                                 __clear_bit(BTN_TOUCH, input_dev->keybit);
2430
2431                                 /* PAD is setup by wacom_setup_pad_input_capabilities later */
2432                                 return 1;
2433                         }
2434                 } else if (features->device_type == BTN_TOOL_PEN) {
2435                         __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2436                         __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2437                         __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2438                         __set_bit(BTN_STYLUS, input_dev->keybit);
2439                         __set_bit(BTN_STYLUS2, input_dev->keybit);
2440                         input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2441                                               features->distance_max,
2442                                               0, 0);
2443                 }
2444                 break;
2445         case BAMBOO_PAD:
2446                 __clear_bit(ABS_MISC, input_dev->absbit);
2447                 input_mt_init_slots(input_dev, features->touch_max,
2448                                     INPUT_MT_POINTER);
2449                 __set_bit(BTN_LEFT, input_dev->keybit);
2450                 __set_bit(BTN_RIGHT, input_dev->keybit);
2451                 break;
2452         }
2453         return 0;
2454 }
2455
2456 int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
2457                                    struct wacom_wac *wacom_wac)
2458 {
2459         struct wacom_features *features = &wacom_wac->features;
2460         int i;
2461
2462         input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
2463
2464         /* kept for making legacy xf86-input-wacom working with the wheels */
2465         __set_bit(ABS_MISC, input_dev->absbit);
2466
2467         /* kept for making legacy xf86-input-wacom accepting the pad */
2468         input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
2469         input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
2470
2471         /* kept for making udev and libwacom accepting the pad */
2472         __set_bit(BTN_STYLUS, input_dev->keybit);
2473
2474         switch (features->type) {
2475         case GRAPHIRE_BT:
2476                 __set_bit(BTN_0, input_dev->keybit);
2477                 __set_bit(BTN_1, input_dev->keybit);
2478                 break;
2479
2480         case WACOM_MO:
2481                 __set_bit(BTN_BACK, input_dev->keybit);
2482                 __set_bit(BTN_LEFT, input_dev->keybit);
2483                 __set_bit(BTN_FORWARD, input_dev->keybit);
2484                 __set_bit(BTN_RIGHT, input_dev->keybit);
2485                 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
2486                 break;
2487
2488         case WACOM_G4:
2489                 __set_bit(BTN_BACK, input_dev->keybit);
2490                 __set_bit(BTN_FORWARD, input_dev->keybit);
2491                 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2492                 break;
2493
2494         case WACOM_24HD:
2495                 __set_bit(BTN_A, input_dev->keybit);
2496                 __set_bit(BTN_B, input_dev->keybit);
2497                 __set_bit(BTN_C, input_dev->keybit);
2498                 __set_bit(BTN_X, input_dev->keybit);
2499                 __set_bit(BTN_Y, input_dev->keybit);
2500                 __set_bit(BTN_Z, input_dev->keybit);
2501
2502                 for (i = 0; i < 10; i++)
2503                         __set_bit(BTN_0 + i, input_dev->keybit);
2504
2505                 __set_bit(KEY_PROG1, input_dev->keybit);
2506                 __set_bit(KEY_PROG2, input_dev->keybit);
2507                 __set_bit(KEY_PROG3, input_dev->keybit);
2508
2509                 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
2510                 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
2511                 break;
2512
2513         case WACOM_27QHD:
2514                 __set_bit(KEY_PROG1, input_dev->keybit);
2515                 __set_bit(KEY_PROG2, input_dev->keybit);
2516                 __set_bit(KEY_PROG3, input_dev->keybit);
2517                 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
2518                 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
2519                 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
2520                 input_abs_set_res(input_dev, ABS_Y, 1024);
2521                 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
2522                 input_abs_set_res(input_dev, ABS_Z, 1024);
2523                 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
2524                 break;
2525
2526         case DTK:
2527                 for (i = 0; i < 6; i++)
2528                         __set_bit(BTN_0 + i, input_dev->keybit);
2529
2530                 break;
2531
2532         case WACOM_22HD:
2533                 __set_bit(KEY_PROG1, input_dev->keybit);
2534                 __set_bit(KEY_PROG2, input_dev->keybit);
2535                 __set_bit(KEY_PROG3, input_dev->keybit);
2536                 /* fall through */
2537
2538         case WACOM_21UX2:
2539                 __set_bit(BTN_A, input_dev->keybit);
2540                 __set_bit(BTN_B, input_dev->keybit);
2541                 __set_bit(BTN_C, input_dev->keybit);
2542                 __set_bit(BTN_X, input_dev->keybit);
2543                 __set_bit(BTN_Y, input_dev->keybit);
2544                 __set_bit(BTN_Z, input_dev->keybit);
2545                 __set_bit(BTN_BASE, input_dev->keybit);
2546                 __set_bit(BTN_BASE2, input_dev->keybit);
2547                 /* fall through */
2548
2549         case WACOM_BEE:
2550                 __set_bit(BTN_8, input_dev->keybit);
2551                 __set_bit(BTN_9, input_dev->keybit);
2552                 /* fall through */
2553
2554         case CINTIQ:
2555                 for (i = 0; i < 8; i++)
2556                         __set_bit(BTN_0 + i, input_dev->keybit);
2557
2558                 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
2559                 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
2560                 break;
2561
2562         case WACOM_13HD:
2563                 for (i = 0; i < 9; i++)
2564                         __set_bit(BTN_0 + i, input_dev->keybit);
2565
2566                 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
2567                 break;
2568
2569         case INTUOS3:
2570         case INTUOS3L:
2571                 __set_bit(BTN_4, input_dev->keybit);
2572                 __set_bit(BTN_5, input_dev->keybit);
2573                 __set_bit(BTN_6, input_dev->keybit);
2574                 __set_bit(BTN_7, input_dev->keybit);
2575
2576                 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
2577                 /* fall through */
2578
2579         case INTUOS3S:
2580                 __set_bit(BTN_0, input_dev->keybit);
2581                 __set_bit(BTN_1, input_dev->keybit);
2582                 __set_bit(BTN_2, input_dev->keybit);
2583                 __set_bit(BTN_3, input_dev->keybit);
2584
2585                 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
2586                 break;
2587
2588         case INTUOS5:
2589         case INTUOS5L:
2590         case INTUOSPM:
2591         case INTUOSPL:
2592                 __set_bit(BTN_7, input_dev->keybit);
2593                 __set_bit(BTN_8, input_dev->keybit);
2594                 /* fall through */
2595
2596         case INTUOS5S:
2597         case INTUOSPS:
2598                 /* touch interface does not have the pad device */
2599                 if (features->device_type != BTN_TOOL_PEN)
2600                         return -ENODEV;
2601
2602                 for (i = 0; i < 7; i++)
2603                         __set_bit(BTN_0 + i, input_dev->keybit);
2604
2605                 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
2606                 break;
2607
2608         case INTUOS4WL:
2609                 /*
2610                  * For Bluetooth devices, the udev rule does not work correctly
2611                  * for pads unless we add a stylus capability, which forces
2612                  * ID_INPUT_TABLET to be set.
2613                  */
2614                 __set_bit(BTN_STYLUS, input_dev->keybit);
2615                 /* fall through */
2616
2617         case INTUOS4:
2618         case INTUOS4L:
2619                 __set_bit(BTN_7, input_dev->keybit);
2620                 __set_bit(BTN_8, input_dev->keybit);
2621                 /* fall through */
2622
2623         case INTUOS4S:
2624                 for (i = 0; i < 7; i++)
2625                         __set_bit(BTN_0 + i, input_dev->keybit);
2626
2627                 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
2628                 break;
2629
2630         case CINTIQ_HYBRID:
2631                 for (i = 0; i < 9; i++)
2632                         __set_bit(BTN_0 + i, input_dev->keybit);
2633
2634                 break;
2635
2636         case DTUS:
2637                 for (i = 0; i < 4; i++)
2638                         __set_bit(BTN_0 + i, input_dev->keybit);
2639                 break;
2640
2641         case INTUOSHT:
2642         case BAMBOO_PT:
2643                 /* pad device is on the touch interface */
2644                 if ((features->device_type != BTN_TOOL_FINGER) ||
2645                     /* Bamboo Pen only tablet does not have pad */
2646                     ((features->type == BAMBOO_PT) && !features->touch_max))
2647                         return -ENODEV;
2648
2649                 __clear_bit(ABS_MISC, input_dev->absbit);
2650
2651                 __set_bit(BTN_LEFT, input_dev->keybit);
2652                 __set_bit(BTN_FORWARD, input_dev->keybit);
2653                 __set_bit(BTN_BACK, input_dev->keybit);
2654                 __set_bit(BTN_RIGHT, input_dev->keybit);
2655
2656                 break;
2657
2658         default:
2659                 /* no pad supported */
2660                 return -ENODEV;
2661         }
2662         return 0;
2663 }
2664
2665 static const struct wacom_features wacom_features_0x00 =
2666         { "Wacom Penpartner", 5040, 3780, 255, 0,
2667           PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
2668 static const struct wacom_features wacom_features_0x10 =
2669         { "Wacom Graphire", 10206, 7422, 511, 63,
2670           GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2671 static const struct wacom_features wacom_features_0x81 =
2672         { "Wacom Graphire BT", 16704, 12064, 511, 32,
2673           GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2674 static const struct wacom_features wacom_features_0x11 =
2675         { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
2676           GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2677 static const struct wacom_features wacom_features_0x12 =
2678         { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
2679           GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2680 static const struct wacom_features wacom_features_0x13 =
2681         { "Wacom Graphire3", 10208, 7424, 511, 63,
2682           GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2683 static const struct wacom_features wacom_features_0x14 =
2684         { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
2685           GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2686 static const struct wacom_features wacom_features_0x15 =
2687         { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
2688           WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2689 static const struct wacom_features wacom_features_0x16 =
2690         { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
2691           WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2692 static const struct wacom_features wacom_features_0x17 =
2693         { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
2694           WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2695 static const struct wacom_features wacom_features_0x18 =
2696         { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
2697           WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2698 static const struct wacom_features wacom_features_0x19 =
2699         { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
2700           GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
2701 static const struct wacom_features wacom_features_0x60 =
2702         { "Wacom Volito", 5104, 3712, 511, 63,
2703           GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
2704 static const struct wacom_features wacom_features_0x61 =
2705         { "Wacom PenStation2", 3250, 2320, 255, 63,
2706           GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
2707 static const struct wacom_features wacom_features_0x62 =
2708         { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
2709           GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
2710 static const struct wacom_features wacom_features_0x63 =
2711         { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
2712           GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
2713 static const struct wacom_features wacom_features_0x64 =
2714         { "Wacom PenPartner2", 3250, 2320, 511, 63,
2715           GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
2716 static const struct wacom_features wacom_features_0x65 =
2717         { "Wacom Bamboo", 14760, 9225, 511, 63,
2718           WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2719 static const struct wacom_features wacom_features_0x69 =
2720         { "Wacom Bamboo1", 5104, 3712, 511, 63,
2721           GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
2722 static const struct wacom_features wacom_features_0x6A =
2723         { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
2724           GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2725 static const struct wacom_features wacom_features_0x6B =
2726         { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
2727           GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2728 static const struct wacom_features wacom_features_0x20 =
2729         { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
2730           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2731 static const struct wacom_features wacom_features_0x21 =
2732         { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
2733           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2734 static const struct wacom_features wacom_features_0x22 =
2735         { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
2736           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2737 static const struct wacom_features wacom_features_0x23 =
2738         { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
2739           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2740 static const struct wacom_features wacom_features_0x24 =
2741         { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
2742           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2743 static const struct wacom_features wacom_features_0x30 =
2744         { "Wacom PL400", 5408, 4056, 255, 0,
2745           PL, WACOM_PL_RES, WACOM_PL_RES };
2746 static const struct wacom_features wacom_features_0x31 =
2747         { "Wacom PL500", 6144, 4608, 255, 0,
2748           PL, WACOM_PL_RES, WACOM_PL_RES };
2749 static const struct wacom_features wacom_features_0x32 =
2750         { "Wacom PL600", 6126, 4604, 255, 0,
2751           PL, WACOM_PL_RES, WACOM_PL_RES };
2752 static const struct wacom_features wacom_features_0x33 =
2753         { "Wacom PL600SX", 6260, 5016, 255, 0,
2754           PL, WACOM_PL_RES, WACOM_PL_RES };
2755 static const struct wacom_features wacom_features_0x34 =
2756         { "Wacom PL550", 6144, 4608, 511, 0,
2757           PL, WACOM_PL_RES, WACOM_PL_RES };
2758 static const struct wacom_features wacom_features_0x35 =
2759         { "Wacom PL800", 7220, 5780, 511, 0,
2760           PL, WACOM_PL_RES, WACOM_PL_RES };
2761 static const struct wacom_features wacom_features_0x37 =
2762         { "Wacom PL700", 6758, 5406, 511, 0,
2763           PL, WACOM_PL_RES, WACOM_PL_RES };
2764 static const struct wacom_features wacom_features_0x38 =
2765         { "Wacom PL510", 6282, 4762, 511, 0,
2766           PL, WACOM_PL_RES, WACOM_PL_RES };
2767 static const struct wacom_features wacom_features_0x39 =
2768         { "Wacom DTU710", 34080, 27660, 511, 0,
2769           PL, WACOM_PL_RES, WACOM_PL_RES };
2770 static const struct wacom_features wacom_features_0xC4 =
2771         { "Wacom DTF521", 6282, 4762, 511, 0,
2772           PL, WACOM_PL_RES, WACOM_PL_RES };
2773 static const struct wacom_features wacom_features_0xC0 =
2774         { "Wacom DTF720", 6858, 5506, 511, 0,
2775           PL, WACOM_PL_RES, WACOM_PL_RES };
2776 static const struct wacom_features wacom_features_0xC2 =
2777         { "Wacom DTF720a", 6858, 5506, 511, 0,
2778           PL, WACOM_PL_RES, WACOM_PL_RES };
2779 static const struct wacom_features wacom_features_0x03 =
2780         { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
2781           PTU, WACOM_PL_RES, WACOM_PL_RES };
2782 static const struct wacom_features wacom_features_0x41 =
2783         { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
2784           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2785 static const struct wacom_features wacom_features_0x42 =
2786         { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
2787           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2788 static const struct wacom_features wacom_features_0x43 =
2789         { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
2790           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2791 static const struct wacom_features wacom_features_0x44 =
2792         { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
2793           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2794 static const struct wacom_features wacom_features_0x45 =
2795         { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
2796           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2797 static const struct wacom_features wacom_features_0xB0 =
2798         { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
2799           INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2800 static const struct wacom_features wacom_features_0xB1 =
2801         { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
2802           INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2803 static const struct wacom_features wacom_features_0xB2 =
2804         { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
2805           INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2806 static const struct wacom_features wacom_features_0xB3 =
2807         { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
2808           INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2809 static const struct wacom_features wacom_features_0xB4 =
2810         { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
2811           INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2812 static const struct wacom_features wacom_features_0xB5 =
2813         { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
2814           INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2815 static const struct wacom_features wacom_features_0xB7 =
2816         { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
2817           INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2818 static const struct wacom_features wacom_features_0xB8 =
2819         { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
2820           INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2821 static const struct wacom_features wacom_features_0xB9 =
2822         { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
2823           INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2824 static const struct wacom_features wacom_features_0xBA =
2825         { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
2826           INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2827 static const struct wacom_features wacom_features_0xBB =
2828         { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
2829           INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2830 static const struct wacom_features wacom_features_0xBC =
2831         { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
2832           INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2833 static const struct wacom_features wacom_features_0xBD =
2834         { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
2835           INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2836 static const struct wacom_features wacom_features_0x26 =
2837         { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
2838           INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .touch_max = 16 };
2839 static const struct wacom_features wacom_features_0x27 =
2840         { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
2841           INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .touch_max = 16 };
2842 static const struct wacom_features wacom_features_0x28 =
2843         { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
2844           INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .touch_max = 16 };
2845 static const struct wacom_features wacom_features_0x29 =
2846         { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
2847           INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2848 static const struct wacom_features wacom_features_0x2A =
2849         { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
2850           INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2851 static const struct wacom_features wacom_features_0x314 =
2852         { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
2853           INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .touch_max = 16,
2854           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2855 static const struct wacom_features wacom_features_0x315 =
2856         { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
2857           INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .touch_max = 16,
2858           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2859 static const struct wacom_features wacom_features_0x317 =
2860         { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
2861           INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .touch_max = 16,
2862           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2863 static const struct wacom_features wacom_features_0xF4 =
2864         { "Wacom Cintiq 24HD", 104080, 65200, 2047, 63,
2865           WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2866           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2867 static const struct wacom_features wacom_features_0xF8 =
2868         { "Wacom Cintiq 24HD touch", 104080, 65200, 2047, 63, /* Pen */
2869           WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2870           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
2871           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
2872 static const struct wacom_features wacom_features_0xF6 =
2873         { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
2874           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
2875           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2876 static const struct wacom_features wacom_features_0x32A =
2877         { "Wacom Cintiq 27QHD", 119740, 67520, 2047, 63,
2878           WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2879           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2880 static const struct wacom_features wacom_features_0x32B =
2881         { "Wacom Cintiq 27QHD touch", 119740, 67520, 2047, 63,
2882           WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2883           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
2884           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
2885 static const struct wacom_features wacom_features_0x32C =
2886         { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
2887           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
2888 static const struct wacom_features wacom_features_0x3F =
2889         { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
2890           CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2891 static const struct wacom_features wacom_features_0xC5 =
2892         { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
2893           WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2894 static const struct wacom_features wacom_features_0xC6 =
2895         { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
2896           WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
2897 static const struct wacom_features wacom_features_0x304 =
2898         { "Wacom Cintiq 13HD", 59152, 33448, 1023, 63,
2899           WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2900           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2901 static const struct wacom_features wacom_features_0xC7 =
2902         { "Wacom DTU1931", 37832, 30305, 511, 0,
2903           PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2904 static const struct wacom_features wacom_features_0xCE =
2905         { "Wacom DTU2231", 47864, 27011, 511, 0,
2906           DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
2907           .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
2908 static const struct wacom_features wacom_features_0xF0 =
2909         { "Wacom DTU1631", 34623, 19553, 511, 0,
2910           DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2911 static const struct wacom_features wacom_features_0xFB =
2912         { "Wacom DTU1031", 21896, 13760, 511, 0,
2913           DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
2914           WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
2915 static const struct wacom_features wacom_features_0x32F =
2916         { "Wacom DTU1031X", 22472, 12728, 511, 0,
2917           DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
2918           WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
2919 static const struct wacom_features wacom_features_0x57 =
2920         { "Wacom DTK2241", 95640, 54060, 2047, 63,
2921           DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2922           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2923 static const struct wacom_features wacom_features_0x59 = /* Pen */
2924         { "Wacom DTH2242", 95640, 54060, 2047, 63,
2925           DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2926           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
2927           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
2928 static const struct wacom_features wacom_features_0x5D = /* Touch */
2929         { "Wacom DTH2242",       .type = WACOM_24HDT,
2930           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
2931           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2932 static const struct wacom_features wacom_features_0xCC =
2933         { "Wacom Cintiq 21UX2", 86800, 65200, 2047, 63,
2934           WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2935           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2936 static const struct wacom_features wacom_features_0xFA =
2937         { "Wacom Cintiq 22HD", 95440, 53860, 2047, 63,
2938           WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2939           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2940 static const struct wacom_features wacom_features_0x5B =
2941         { "Wacom Cintiq 22HDT", 95440, 53860, 2047, 63,
2942           WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2943           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
2944           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
2945 static const struct wacom_features wacom_features_0x5E =
2946         { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
2947           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
2948           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2949 static const struct wacom_features wacom_features_0x90 =
2950         { "Wacom ISDv4 90", 26202, 16325, 255, 0,
2951           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2952 static const struct wacom_features wacom_features_0x93 =
2953         { "Wacom ISDv4 93", 26202, 16325, 255, 0,
2954           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2955 static const struct wacom_features wacom_features_0x97 =
2956         { "Wacom ISDv4 97", 26202, 16325, 511, 0,
2957           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2958 static const struct wacom_features wacom_features_0x9A =
2959         { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
2960           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2961 static const struct wacom_features wacom_features_0x9F =
2962         { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
2963           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2964 static const struct wacom_features wacom_features_0xE2 =
2965         { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
2966           TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
2967 static const struct wacom_features wacom_features_0xE3 =
2968         { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
2969           TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
2970 static const struct wacom_features wacom_features_0xE5 =
2971         { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
2972           MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2973 static const struct wacom_features wacom_features_0xE6 =
2974         { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
2975           TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
2976 static const struct wacom_features wacom_features_0xEC =
2977         { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
2978           TABLETPC,    WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2979 static const struct wacom_features wacom_features_0xED =
2980         { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
2981           TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2982 static const struct wacom_features wacom_features_0xEF =
2983         { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
2984           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2985 static const struct wacom_features wacom_features_0x100 =
2986         { "Wacom ISDv4 100", 26202, 16325, 255, 0,
2987           MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2988 static const struct wacom_features wacom_features_0x101 =
2989         { "Wacom ISDv4 101", 26202, 16325, 255, 0,
2990           MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2991 static const struct wacom_features wacom_features_0x10D =
2992         { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
2993           MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2994 static const struct wacom_features wacom_features_0x10E =
2995         { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
2996           MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2997 static const struct wacom_features wacom_features_0x10F =
2998         { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
2999           MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3000 static const struct wacom_features wacom_features_0x116 =
3001         { "Wacom ISDv4 116", 26202, 16325, 255, 0,
3002           TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3003 static const struct wacom_features wacom_features_0x12C =
3004         { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
3005           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3006 static const struct wacom_features wacom_features_0x4001 =
3007         { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
3008           MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3009 static const struct wacom_features wacom_features_0x4004 =
3010         { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
3011           MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3012 static const struct wacom_features wacom_features_0x5000 =
3013         { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
3014           MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3015 static const struct wacom_features wacom_features_0x5002 =
3016         { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
3017           MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3018 static const struct wacom_features wacom_features_0x47 =
3019         { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3020           INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3021 static const struct wacom_features wacom_features_0x84 =
3022         { "Wacom Wireless Receiver", 0, 0, 0, 0,
3023           WIRELESS, 0, 0, .touch_max = 16 };
3024 static const struct wacom_features wacom_features_0xD0 =
3025         { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
3026           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3027 static const struct wacom_features wacom_features_0xD1 =
3028         { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
3029           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3030 static const struct wacom_features wacom_features_0xD2 =
3031         { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
3032           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3033 static const struct wacom_features wacom_features_0xD3 =
3034         { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
3035           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3036 static const struct wacom_features wacom_features_0xD4 =
3037         { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
3038           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3039 static const struct wacom_features wacom_features_0xD5 =
3040         { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
3041           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3042 static const struct wacom_features wacom_features_0xD6 =
3043         { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
3044           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3045 static const struct wacom_features wacom_features_0xD7 =
3046         { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
3047           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3048 static const struct wacom_features wacom_features_0xD8 =
3049         { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
3050           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3051 static const struct wacom_features wacom_features_0xDA =
3052         { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
3053           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3054 static const struct wacom_features wacom_features_0xDB =
3055         { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
3056           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3057 static const struct wacom_features wacom_features_0xDD =
3058         { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
3059           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3060 static const struct wacom_features wacom_features_0xDE =
3061         { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
3062           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
3063 static const struct wacom_features wacom_features_0xDF =
3064         { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
3065           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
3066 static const struct wacom_features wacom_features_0x300 =
3067         { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
3068           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3069 static const struct wacom_features wacom_features_0x301 =
3070         { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
3071           BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3072 static const struct wacom_features wacom_features_0x302 =
3073         { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
3074           INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3075           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3076 static const struct wacom_features wacom_features_0x303 =
3077         { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
3078           INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3079           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3080 static const struct wacom_features wacom_features_0x30E =
3081         { "Wacom Intuos S", 15200, 9500, 1023, 31,
3082           INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3083           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3084 static const struct wacom_features wacom_features_0x6004 =
3085         { "ISD-V4", 12800, 8000, 255, 0,
3086           TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3087 static const struct wacom_features wacom_features_0x307 =
3088         { "Wacom ISDv5 307", 59152, 33448, 2047, 63,
3089           CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
3090           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3091           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
3092 static const struct wacom_features wacom_features_0x309 =
3093         { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
3094           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
3095           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3096 static const struct wacom_features wacom_features_0x30A =
3097         { "Wacom ISDv5 30A", 59152, 33448, 2047, 63,
3098           CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
3099           WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3100           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
3101 static const struct wacom_features wacom_features_0x30C =
3102         { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
3103           .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
3104           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3105 static const struct wacom_features wacom_features_0x318 =
3106         { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
3107           .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3108 static const struct wacom_features wacom_features_0x319 =
3109         { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
3110           .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3111 static const struct wacom_features wacom_features_0x323 =
3112         { "Wacom Intuos P M", 21600, 13500, 1023, 31,
3113           INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3114           .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3115
3116 static const struct wacom_features wacom_features_HID_ANY_ID =
3117         { "Wacom HID", .type = HID_GENERIC };
3118
3119 #define USB_DEVICE_WACOM(prod)                                          \
3120         HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3121         .driver_data = (kernel_ulong_t)&wacom_features_##prod
3122
3123 #define BT_DEVICE_WACOM(prod)                                           \
3124         HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3125         .driver_data = (kernel_ulong_t)&wacom_features_##prod
3126
3127 #define I2C_DEVICE_WACOM(prod)                                          \
3128         HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3129         .driver_data = (kernel_ulong_t)&wacom_features_##prod
3130
3131 #define USB_DEVICE_LENOVO(prod)                                 \
3132         HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod),                     \
3133         .driver_data = (kernel_ulong_t)&wacom_features_##prod
3134
3135 const struct hid_device_id wacom_ids[] = {
3136         { USB_DEVICE_WACOM(0x00) },
3137         { USB_DEVICE_WACOM(0x03) },
3138         { USB_DEVICE_WACOM(0x10) },
3139         { USB_DEVICE_WACOM(0x11) },
3140         { USB_DEVICE_WACOM(0x12) },
3141         { USB_DEVICE_WACOM(0x13) },
3142         { USB_DEVICE_WACOM(0x14) },
3143         { USB_DEVICE_WACOM(0x15) },
3144         { USB_DEVICE_WACOM(0x16) },
3145         { USB_DEVICE_WACOM(0x17) },
3146         { USB_DEVICE_WACOM(0x18) },
3147         { USB_DEVICE_WACOM(0x19) },
3148         { USB_DEVICE_WACOM(0x20) },
3149         { USB_DEVICE_WACOM(0x21) },
3150         { USB_DEVICE_WACOM(0x22) },
3151         { USB_DEVICE_WACOM(0x23) },
3152         { USB_DEVICE_WACOM(0x24) },
3153         { USB_DEVICE_WACOM(0x26) },
3154         { USB_DEVICE_WACOM(0x27) },
3155         { USB_DEVICE_WACOM(0x28) },
3156         { USB_DEVICE_WACOM(0x29) },
3157         { USB_DEVICE_WACOM(0x2A) },
3158         { USB_DEVICE_WACOM(0x30) },
3159         { USB_DEVICE_WACOM(0x31) },
3160         { USB_DEVICE_WACOM(0x32) },
3161         { USB_DEVICE_WACOM(0x33) },
3162         { USB_DEVICE_WACOM(0x34) },
3163         { USB_DEVICE_WACOM(0x35) },
3164         { USB_DEVICE_WACOM(0x37) },
3165         { USB_DEVICE_WACOM(0x38) },
3166         { USB_DEVICE_WACOM(0x39) },
3167         { USB_DEVICE_WACOM(0x3F) },
3168         { USB_DEVICE_WACOM(0x41) },
3169         { USB_DEVICE_WACOM(0x42) },
3170         { USB_DEVICE_WACOM(0x43) },
3171         { USB_DEVICE_WACOM(0x44) },
3172         { USB_DEVICE_WACOM(0x45) },
3173         { USB_DEVICE_WACOM(0x47) },
3174         { USB_DEVICE_WACOM(0x57) },
3175         { USB_DEVICE_WACOM(0x59) },
3176         { USB_DEVICE_WACOM(0x5B) },
3177         { USB_DEVICE_WACOM(0x5D) },
3178         { USB_DEVICE_WACOM(0x5E) },
3179         { USB_DEVICE_WACOM(0x60) },
3180         { USB_DEVICE_WACOM(0x61) },
3181         { USB_DEVICE_WACOM(0x62) },
3182         { USB_DEVICE_WACOM(0x63) },
3183         { USB_DEVICE_WACOM(0x64) },
3184         { USB_DEVICE_WACOM(0x65) },
3185         { USB_DEVICE_WACOM(0x69) },
3186         { USB_DEVICE_WACOM(0x6A) },
3187         { USB_DEVICE_WACOM(0x6B) },
3188         { BT_DEVICE_WACOM(0x81) },
3189         { USB_DEVICE_WACOM(0x84) },
3190         { USB_DEVICE_WACOM(0x90) },
3191         { USB_DEVICE_WACOM(0x93) },
3192         { USB_DEVICE_WACOM(0x97) },
3193         { USB_DEVICE_WACOM(0x9A) },
3194         { USB_DEVICE_WACOM(0x9F) },
3195         { USB_DEVICE_WACOM(0xB0) },
3196         { USB_DEVICE_WACOM(0xB1) },
3197         { USB_DEVICE_WACOM(0xB2) },
3198         { USB_DEVICE_WACOM(0xB3) },
3199         { USB_DEVICE_WACOM(0xB4) },
3200         { USB_DEVICE_WACOM(0xB5) },
3201         { USB_DEVICE_WACOM(0xB7) },
3202         { USB_DEVICE_WACOM(0xB8) },
3203         { USB_DEVICE_WACOM(0xB9) },
3204         { USB_DEVICE_WACOM(0xBA) },
3205         { USB_DEVICE_WACOM(0xBB) },
3206         { USB_DEVICE_WACOM(0xBC) },
3207         { BT_DEVICE_WACOM(0xBD) },
3208         { USB_DEVICE_WACOM(0xC0) },
3209         { USB_DEVICE_WACOM(0xC2) },
3210         { USB_DEVICE_WACOM(0xC4) },
3211         { USB_DEVICE_WACOM(0xC5) },
3212         { USB_DEVICE_WACOM(0xC6) },
3213         { USB_DEVICE_WACOM(0xC7) },
3214         { USB_DEVICE_WACOM(0xCC) },
3215         { USB_DEVICE_WACOM(0xCE) },
3216         { USB_DEVICE_WACOM(0xD0) },
3217         { USB_DEVICE_WACOM(0xD1) },
3218         { USB_DEVICE_WACOM(0xD2) },
3219         { USB_DEVICE_WACOM(0xD3) },
3220         { USB_DEVICE_WACOM(0xD4) },
3221         { USB_DEVICE_WACOM(0xD5) },
3222         { USB_DEVICE_WACOM(0xD6) },
3223         { USB_DEVICE_WACOM(0xD7) },
3224         { USB_DEVICE_WACOM(0xD8) },
3225         { USB_DEVICE_WACOM(0xDA) },
3226         { USB_DEVICE_WACOM(0xDB) },
3227         { USB_DEVICE_WACOM(0xDD) },
3228         { USB_DEVICE_WACOM(0xDE) },
3229         { USB_DEVICE_WACOM(0xDF) },
3230         { USB_DEVICE_WACOM(0xE2) },
3231         { USB_DEVICE_WACOM(0xE3) },
3232         { USB_DEVICE_WACOM(0xE5) },
3233         { USB_DEVICE_WACOM(0xE6) },
3234         { USB_DEVICE_WACOM(0xEC) },
3235         { USB_DEVICE_WACOM(0xED) },
3236         { USB_DEVICE_WACOM(0xEF) },
3237         { USB_DEVICE_WACOM(0xF0) },
3238         { USB_DEVICE_WACOM(0xF4) },
3239         { USB_DEVICE_WACOM(0xF6) },
3240         { USB_DEVICE_WACOM(0xF8) },
3241         { USB_DEVICE_WACOM(0xFA) },
3242         { USB_DEVICE_WACOM(0xFB) },
3243         { USB_DEVICE_WACOM(0x100) },
3244         { USB_DEVICE_WACOM(0x101) },
3245         { USB_DEVICE_WACOM(0x10D) },
3246         { USB_DEVICE_WACOM(0x10E) },
3247         { USB_DEVICE_WACOM(0x10F) },
3248         { USB_DEVICE_WACOM(0x116) },
3249         { USB_DEVICE_WACOM(0x12C) },
3250         { USB_DEVICE_WACOM(0x300) },
3251         { USB_DEVICE_WACOM(0x301) },
3252         { USB_DEVICE_WACOM(0x302) },
3253         { USB_DEVICE_WACOM(0x303) },
3254         { USB_DEVICE_WACOM(0x304) },
3255         { USB_DEVICE_WACOM(0x307) },
3256         { USB_DEVICE_WACOM(0x309) },
3257         { USB_DEVICE_WACOM(0x30A) },
3258         { USB_DEVICE_WACOM(0x30C) },
3259         { USB_DEVICE_WACOM(0x30E) },
3260         { USB_DEVICE_WACOM(0x314) },
3261         { USB_DEVICE_WACOM(0x315) },
3262         { USB_DEVICE_WACOM(0x317) },
3263         { USB_DEVICE_WACOM(0x318) },
3264         { USB_DEVICE_WACOM(0x319) },
3265         { USB_DEVICE_WACOM(0x323) },
3266         { USB_DEVICE_WACOM(0x32A) },
3267         { USB_DEVICE_WACOM(0x32B) },
3268         { USB_DEVICE_WACOM(0x32C) },
3269         { USB_DEVICE_WACOM(0x32F) },
3270         { USB_DEVICE_WACOM(0x4001) },
3271         { USB_DEVICE_WACOM(0x4004) },
3272         { USB_DEVICE_WACOM(0x5000) },
3273         { USB_DEVICE_WACOM(0x5002) },
3274         { USB_DEVICE_LENOVO(0x6004) },
3275
3276         { USB_DEVICE_WACOM(HID_ANY_ID) },
3277         { I2C_DEVICE_WACOM(HID_ANY_ID) },
3278         { }
3279 };
3280 MODULE_DEVICE_TABLE(hid, wacom_ids);