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