]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/hid/wacom_wac.c
HID: multitouch: fix LG Melfas touchscreen
[mirror_ubuntu-artful-kernel.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 static bool touch_arbitration = 1;
38 module_param(touch_arbitration, bool, 0644);
39 MODULE_PARM_DESC(touch_arbitration, " on (Y) off (N)");
40
41 static void wacom_report_numbered_buttons(struct input_dev *input_dev,
42 int button_count, int mask);
43
44 static int wacom_numbered_button_to_key(int n);
45
46 /*
47 * Percent of battery capacity for Graphire.
48 * 8th value means AC online and show 100% capacity.
49 */
50 static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
51
52 /*
53 * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
54 */
55 static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
56
57 static void __wacom_notify_battery(struct wacom_battery *battery,
58 int bat_capacity, bool bat_charging,
59 bool bat_connected, bool ps_connected)
60 {
61 bool changed = battery->battery_capacity != bat_capacity ||
62 battery->bat_charging != bat_charging ||
63 battery->bat_connected != bat_connected ||
64 battery->ps_connected != ps_connected;
65
66 if (changed) {
67 battery->battery_capacity = bat_capacity;
68 battery->bat_charging = bat_charging;
69 battery->bat_connected = bat_connected;
70 battery->ps_connected = ps_connected;
71
72 if (battery->battery)
73 power_supply_changed(battery->battery);
74 }
75 }
76
77 static void wacom_notify_battery(struct wacom_wac *wacom_wac,
78 int bat_capacity, bool bat_charging, bool bat_connected,
79 bool ps_connected)
80 {
81 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
82
83 __wacom_notify_battery(&wacom->battery, bat_capacity, bat_charging,
84 bat_connected, ps_connected);
85 }
86
87 static int wacom_penpartner_irq(struct wacom_wac *wacom)
88 {
89 unsigned char *data = wacom->data;
90 struct input_dev *input = wacom->pen_input;
91
92 switch (data[0]) {
93 case 1:
94 if (data[5] & 0x80) {
95 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
96 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
97 input_report_key(input, wacom->tool[0], 1);
98 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
99 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
100 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
101 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
102 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
103 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
104 } else {
105 input_report_key(input, wacom->tool[0], 0);
106 input_report_abs(input, ABS_MISC, 0); /* report tool id */
107 input_report_abs(input, ABS_PRESSURE, -1);
108 input_report_key(input, BTN_TOUCH, 0);
109 }
110 break;
111
112 case 2:
113 input_report_key(input, BTN_TOOL_PEN, 1);
114 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
115 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
116 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
117 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
118 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
119 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
120 break;
121
122 default:
123 dev_dbg(input->dev.parent,
124 "%s: received unknown report #%d\n", __func__, data[0]);
125 return 0;
126 }
127
128 return 1;
129 }
130
131 static int wacom_pl_irq(struct wacom_wac *wacom)
132 {
133 struct wacom_features *features = &wacom->features;
134 unsigned char *data = wacom->data;
135 struct input_dev *input = wacom->pen_input;
136 int prox, pressure;
137
138 if (data[0] != WACOM_REPORT_PENABLED) {
139 dev_dbg(input->dev.parent,
140 "%s: received unknown report #%d\n", __func__, data[0]);
141 return 0;
142 }
143
144 prox = data[1] & 0x40;
145
146 if (!wacom->id[0]) {
147 if ((data[0] & 0x10) || (data[4] & 0x20)) {
148 wacom->tool[0] = BTN_TOOL_RUBBER;
149 wacom->id[0] = ERASER_DEVICE_ID;
150 }
151 else {
152 wacom->tool[0] = BTN_TOOL_PEN;
153 wacom->id[0] = STYLUS_DEVICE_ID;
154 }
155 }
156
157 /* If the eraser is in prox, STYLUS2 is always set. If we
158 * mis-detected the type and notice that STYLUS2 isn't set
159 * then force the eraser out of prox and let the pen in.
160 */
161 if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
162 input_report_key(input, BTN_TOOL_RUBBER, 0);
163 input_report_abs(input, ABS_MISC, 0);
164 input_sync(input);
165 wacom->tool[0] = BTN_TOOL_PEN;
166 wacom->id[0] = STYLUS_DEVICE_ID;
167 }
168
169 if (prox) {
170 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
171 if (features->pressure_max > 255)
172 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
173 pressure += (features->pressure_max + 1) / 2;
174
175 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
176 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
177 input_report_abs(input, ABS_PRESSURE, pressure);
178
179 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
180 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
181 /* Only allow the stylus2 button to be reported for the pen tool. */
182 input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
183 }
184
185 if (!prox)
186 wacom->id[0] = 0;
187 input_report_key(input, wacom->tool[0], prox);
188 input_report_abs(input, ABS_MISC, wacom->id[0]);
189 return 1;
190 }
191
192 static int wacom_ptu_irq(struct wacom_wac *wacom)
193 {
194 unsigned char *data = wacom->data;
195 struct input_dev *input = wacom->pen_input;
196
197 if (data[0] != WACOM_REPORT_PENABLED) {
198 dev_dbg(input->dev.parent,
199 "%s: received unknown report #%d\n", __func__, data[0]);
200 return 0;
201 }
202
203 if (data[1] & 0x04) {
204 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
205 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
206 wacom->id[0] = ERASER_DEVICE_ID;
207 } else {
208 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
209 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
210 wacom->id[0] = STYLUS_DEVICE_ID;
211 }
212 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
213 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
214 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
215 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
216 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
217 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
218 return 1;
219 }
220
221 static int wacom_dtu_irq(struct wacom_wac *wacom)
222 {
223 unsigned char *data = wacom->data;
224 struct input_dev *input = wacom->pen_input;
225 int prox = data[1] & 0x20;
226
227 dev_dbg(input->dev.parent,
228 "%s: received report #%d", __func__, data[0]);
229
230 if (prox) {
231 /* Going into proximity select tool */
232 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
233 if (wacom->tool[0] == BTN_TOOL_PEN)
234 wacom->id[0] = STYLUS_DEVICE_ID;
235 else
236 wacom->id[0] = ERASER_DEVICE_ID;
237 }
238 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
239 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
240 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
241 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
242 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
243 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
244 if (!prox) /* out-prox */
245 wacom->id[0] = 0;
246 input_report_key(input, wacom->tool[0], prox);
247 input_report_abs(input, ABS_MISC, wacom->id[0]);
248 return 1;
249 }
250
251 static int wacom_dtus_irq(struct wacom_wac *wacom)
252 {
253 char *data = wacom->data;
254 struct input_dev *input = wacom->pen_input;
255 unsigned short prox, pressure = 0;
256
257 if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
258 dev_dbg(input->dev.parent,
259 "%s: received unknown report #%d", __func__, data[0]);
260 return 0;
261 } else if (data[0] == WACOM_REPORT_DTUSPAD) {
262 input = wacom->pad_input;
263 input_report_key(input, BTN_0, (data[1] & 0x01));
264 input_report_key(input, BTN_1, (data[1] & 0x02));
265 input_report_key(input, BTN_2, (data[1] & 0x04));
266 input_report_key(input, BTN_3, (data[1] & 0x08));
267 input_report_abs(input, ABS_MISC,
268 data[1] & 0x0f ? PAD_DEVICE_ID : 0);
269 return 1;
270 } else {
271 prox = data[1] & 0x80;
272 if (prox) {
273 switch ((data[1] >> 3) & 3) {
274 case 1: /* Rubber */
275 wacom->tool[0] = BTN_TOOL_RUBBER;
276 wacom->id[0] = ERASER_DEVICE_ID;
277 break;
278
279 case 2: /* Pen */
280 wacom->tool[0] = BTN_TOOL_PEN;
281 wacom->id[0] = STYLUS_DEVICE_ID;
282 break;
283 }
284 }
285
286 input_report_key(input, BTN_STYLUS, data[1] & 0x20);
287 input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
288 input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
289 input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
290 pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
291 input_report_abs(input, ABS_PRESSURE, pressure);
292 input_report_key(input, BTN_TOUCH, pressure > 10);
293
294 if (!prox) /* out-prox */
295 wacom->id[0] = 0;
296 input_report_key(input, wacom->tool[0], prox);
297 input_report_abs(input, ABS_MISC, wacom->id[0]);
298 return 1;
299 }
300 }
301
302 static int wacom_graphire_irq(struct wacom_wac *wacom)
303 {
304 struct wacom_features *features = &wacom->features;
305 unsigned char *data = wacom->data;
306 struct input_dev *input = wacom->pen_input;
307 struct input_dev *pad_input = wacom->pad_input;
308 int battery_capacity, ps_connected;
309 int prox;
310 int rw = 0;
311 int retval = 0;
312
313 if (features->type == GRAPHIRE_BT) {
314 if (data[0] != WACOM_REPORT_PENABLED_BT) {
315 dev_dbg(input->dev.parent,
316 "%s: received unknown report #%d\n", __func__,
317 data[0]);
318 goto exit;
319 }
320 } else if (data[0] != WACOM_REPORT_PENABLED) {
321 dev_dbg(input->dev.parent,
322 "%s: received unknown report #%d\n", __func__, data[0]);
323 goto exit;
324 }
325
326 prox = data[1] & 0x80;
327 if (prox || wacom->id[0]) {
328 if (prox) {
329 switch ((data[1] >> 5) & 3) {
330
331 case 0: /* Pen */
332 wacom->tool[0] = BTN_TOOL_PEN;
333 wacom->id[0] = STYLUS_DEVICE_ID;
334 break;
335
336 case 1: /* Rubber */
337 wacom->tool[0] = BTN_TOOL_RUBBER;
338 wacom->id[0] = ERASER_DEVICE_ID;
339 break;
340
341 case 2: /* Mouse with wheel */
342 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
343 /* fall through */
344
345 case 3: /* Mouse without wheel */
346 wacom->tool[0] = BTN_TOOL_MOUSE;
347 wacom->id[0] = CURSOR_DEVICE_ID;
348 break;
349 }
350 }
351 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
352 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
353 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
354 if (features->type == GRAPHIRE_BT)
355 input_report_abs(input, ABS_PRESSURE, data[6] |
356 (((__u16) (data[1] & 0x08)) << 5));
357 else
358 input_report_abs(input, ABS_PRESSURE, data[6] |
359 ((data[7] & 0x03) << 8));
360 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
361 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
362 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
363 } else {
364 input_report_key(input, BTN_LEFT, data[1] & 0x01);
365 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
366 if (features->type == WACOM_G4 ||
367 features->type == WACOM_MO) {
368 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
369 rw = (data[7] & 0x04) - (data[7] & 0x03);
370 } else if (features->type == GRAPHIRE_BT) {
371 /* Compute distance between mouse and tablet */
372 rw = 44 - (data[6] >> 2);
373 rw = clamp_val(rw, 0, 31);
374 input_report_abs(input, ABS_DISTANCE, rw);
375 if (((data[1] >> 5) & 3) == 2) {
376 /* Mouse with wheel */
377 input_report_key(input, BTN_MIDDLE,
378 data[1] & 0x04);
379 rw = (data[6] & 0x01) ? -1 :
380 (data[6] & 0x02) ? 1 : 0;
381 } else {
382 rw = 0;
383 }
384 } else {
385 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
386 rw = -(signed char)data[6];
387 }
388 input_report_rel(input, REL_WHEEL, rw);
389 }
390
391 if (!prox)
392 wacom->id[0] = 0;
393 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
394 input_report_key(input, wacom->tool[0], prox);
395 input_sync(input); /* sync last event */
396 }
397
398 /* send pad data */
399 switch (features->type) {
400 case WACOM_G4:
401 prox = data[7] & 0xf8;
402 if (prox || wacom->id[1]) {
403 wacom->id[1] = PAD_DEVICE_ID;
404 input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
405 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
406 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
407 input_report_rel(pad_input, REL_WHEEL, rw);
408 if (!prox)
409 wacom->id[1] = 0;
410 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
411 retval = 1;
412 }
413 break;
414
415 case WACOM_MO:
416 prox = (data[7] & 0xf8) || data[8];
417 if (prox || wacom->id[1]) {
418 wacom->id[1] = PAD_DEVICE_ID;
419 input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
420 input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
421 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
422 input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
423 input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
424 if (!prox)
425 wacom->id[1] = 0;
426 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
427 retval = 1;
428 }
429 break;
430 case GRAPHIRE_BT:
431 prox = data[7] & 0x03;
432 if (prox || wacom->id[1]) {
433 wacom->id[1] = PAD_DEVICE_ID;
434 input_report_key(pad_input, BTN_0, (data[7] & 0x02));
435 input_report_key(pad_input, BTN_1, (data[7] & 0x01));
436 if (!prox)
437 wacom->id[1] = 0;
438 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
439 retval = 1;
440 }
441 break;
442 }
443
444 /* Store current battery capacity and power supply state */
445 if (features->type == GRAPHIRE_BT) {
446 rw = (data[7] >> 2 & 0x07);
447 battery_capacity = batcap_gr[rw];
448 ps_connected = rw == 7;
449 wacom_notify_battery(wacom, battery_capacity, ps_connected,
450 1, ps_connected);
451 }
452 exit:
453 return retval;
454 }
455
456 static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
457 {
458 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
459 struct wacom_features *features = &wacom_wac->features;
460 struct hid_report *r;
461 struct hid_report_enum *re;
462
463 re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
464 if (features->type == INTUOSHT2)
465 r = re->report_id_hash[WACOM_REPORT_INTUOSHT2_ID];
466 else
467 r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1];
468 if (r) {
469 hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
470 }
471 }
472
473 static int wacom_intuos_pad(struct wacom_wac *wacom)
474 {
475 struct wacom_features *features = &wacom->features;
476 unsigned char *data = wacom->data;
477 struct input_dev *input = wacom->pad_input;
478 int i;
479 int buttons = 0, nbuttons = features->numbered_buttons;
480 int keys = 0, nkeys = 0;
481 int ring1 = 0, ring2 = 0;
482 int strip1 = 0, strip2 = 0;
483 bool prox = false;
484
485 /* pad packets. Works as a second tool and is always in prox */
486 if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
487 data[0] == WACOM_REPORT_CINTIQPAD))
488 return 0;
489
490 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
491 buttons = (data[3] << 1) | (data[2] & 0x01);
492 ring1 = data[1];
493 } else if (features->type == DTK) {
494 buttons = data[6];
495 } else if (features->type == WACOM_13HD) {
496 buttons = (data[4] << 1) | (data[3] & 0x01);
497 } else if (features->type == WACOM_24HD) {
498 buttons = (data[8] << 8) | data[6];
499 ring1 = data[1];
500 ring2 = data[2];
501
502 /*
503 * Three "buttons" are available on the 24HD which are
504 * physically implemented as a touchstrip. Each button
505 * is approximately 3 bits wide with a 2 bit spacing.
506 * The raw touchstrip bits are stored at:
507 * ((data[3] & 0x1f) << 8) | data[4])
508 */
509 nkeys = 3;
510 keys = ((data[3] & 0x1C) ? 1<<2 : 0) |
511 ((data[4] & 0xE0) ? 1<<1 : 0) |
512 ((data[4] & 0x07) ? 1<<0 : 0);
513 } else if (features->type == WACOM_27QHD) {
514 nkeys = 3;
515 keys = data[2] & 0x07;
516
517 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
518 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
519 input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
520 } else if (features->type == CINTIQ_HYBRID) {
521 /*
522 * Do not send hardware buttons under Android. They
523 * are already sent to the system through GPIO (and
524 * have different meaning).
525 *
526 * d-pad right -> data[4] & 0x10
527 * d-pad up -> data[4] & 0x20
528 * d-pad left -> data[4] & 0x40
529 * d-pad down -> data[4] & 0x80
530 * d-pad center -> data[3] & 0x01
531 */
532 buttons = (data[4] << 1) | (data[3] & 0x01);
533 } else if (features->type == CINTIQ_COMPANION_2) {
534 /* d-pad right -> data[4] & 0x10
535 * d-pad up -> data[4] & 0x20
536 * d-pad left -> data[4] & 0x40
537 * d-pad down -> data[4] & 0x80
538 * d-pad center -> data[3] & 0x01
539 */
540 buttons = ((data[2] >> 4) << 7) |
541 ((data[1] & 0x04) << 6) |
542 ((data[2] & 0x0F) << 2) |
543 (data[1] & 0x03);
544 } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
545 /*
546 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
547 * addition to the mechanical switch. Switch data is
548 * stored in data[4], capacitive data in data[5].
549 *
550 * Touch ring mode switch (data[3]) has no capacitive sensor
551 */
552 buttons = (data[4] << 1) | (data[3] & 0x01);
553 ring1 = data[2];
554 } else {
555 if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
556 buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) |
557 (data[6] << 1) | (data[5] & 0x01);
558
559 if (features->type == WACOM_22HD) {
560 nkeys = 3;
561 keys = data[9] & 0x07;
562 }
563 } else {
564 buttons = ((data[6] & 0x10) << 10) |
565 ((data[5] & 0x10) << 9) |
566 ((data[6] & 0x0F) << 4) |
567 (data[5] & 0x0F);
568 }
569 strip1 = ((data[1] & 0x1f) << 8) | data[2];
570 strip2 = ((data[3] & 0x1f) << 8) | data[4];
571 }
572
573 prox = (buttons & ~(~0 << nbuttons)) | (keys & ~(~0 << nkeys)) |
574 (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2;
575
576 wacom_report_numbered_buttons(input, nbuttons, buttons);
577
578 for (i = 0; i < nkeys; i++)
579 input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
580
581 input_report_abs(input, ABS_RX, strip1);
582 input_report_abs(input, ABS_RY, strip2);
583
584 input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0);
585 input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0);
586
587 input_report_key(input, wacom->tool[1], prox ? 1 : 0);
588 input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
589
590 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
591
592 return 1;
593 }
594
595 static int wacom_intuos_id_mangle(int tool_id)
596 {
597 return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
598 }
599
600 static int wacom_intuos_get_tool_type(int tool_id)
601 {
602 int tool_type;
603
604 switch (tool_id) {
605 case 0x812: /* Inking pen */
606 case 0x801: /* Intuos3 Inking pen */
607 case 0x12802: /* Intuos4/5 Inking Pen */
608 case 0x012:
609 tool_type = BTN_TOOL_PENCIL;
610 break;
611
612 case 0x822: /* Pen */
613 case 0x842:
614 case 0x852:
615 case 0x823: /* Intuos3 Grip Pen */
616 case 0x813: /* Intuos3 Classic Pen */
617 case 0x885: /* Intuos3 Marker Pen */
618 case 0x802: /* Intuos4/5 13HD/24HD General Pen */
619 case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
620 case 0x8e2: /* IntuosHT2 pen */
621 case 0x022:
622 case 0x10804: /* Intuos4/5 13HD/24HD Art Pen */
623 case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
624 case 0x16802: /* Cintiq 13HD Pro Pen */
625 case 0x18802: /* DTH2242 Pen */
626 case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
627 tool_type = BTN_TOOL_PEN;
628 break;
629
630 case 0x832: /* Stroke pen */
631 case 0x032:
632 tool_type = BTN_TOOL_BRUSH;
633 break;
634
635 case 0x007: /* Mouse 4D and 2D */
636 case 0x09c:
637 case 0x094:
638 case 0x017: /* Intuos3 2D Mouse */
639 case 0x806: /* Intuos4 Mouse */
640 tool_type = BTN_TOOL_MOUSE;
641 break;
642
643 case 0x096: /* Lens cursor */
644 case 0x097: /* Intuos3 Lens cursor */
645 case 0x006: /* Intuos4 Lens cursor */
646 tool_type = BTN_TOOL_LENS;
647 break;
648
649 case 0x82a: /* Eraser */
650 case 0x84a:
651 case 0x85a:
652 case 0x91a:
653 case 0xd1a:
654 case 0x0fa:
655 case 0x82b: /* Intuos3 Grip Pen Eraser */
656 case 0x81b: /* Intuos3 Classic Pen Eraser */
657 case 0x91b: /* Intuos3 Airbrush Eraser */
658 case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
659 case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
660 case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
661 case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
662 case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
663 case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
664 case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
665 case 0x1880a: /* DTH2242 Eraser */
666 case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
667 tool_type = BTN_TOOL_RUBBER;
668 break;
669
670 case 0xd12:
671 case 0x912:
672 case 0x112:
673 case 0x913: /* Intuos3 Airbrush */
674 case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
675 case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
676 tool_type = BTN_TOOL_AIRBRUSH;
677 break;
678
679 default: /* Unknown tool */
680 tool_type = BTN_TOOL_PEN;
681 break;
682 }
683 return tool_type;
684 }
685
686 static int wacom_intuos_inout(struct wacom_wac *wacom)
687 {
688 struct wacom_features *features = &wacom->features;
689 unsigned char *data = wacom->data;
690 struct input_dev *input = wacom->pen_input;
691 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
692
693 if (!(((data[1] & 0xfc) == 0xc0) || /* in prox */
694 ((data[1] & 0xfe) == 0x20) || /* in range */
695 ((data[1] & 0xfe) == 0x80))) /* out prox */
696 return 0;
697
698 /* Enter report */
699 if ((data[1] & 0xfc) == 0xc0) {
700 /* serial number of the tool */
701 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
702 (data[4] << 20) + (data[5] << 12) +
703 (data[6] << 4) + (data[7] >> 4);
704
705 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
706 ((data[7] & 0x0f) << 16) | ((data[8] & 0xf0) << 8);
707
708 wacom->tool[idx] = wacom_intuos_get_tool_type(wacom->id[idx]);
709
710 wacom->shared->stylus_in_proximity = true;
711 return 1;
712 }
713
714 /* in Range */
715 if ((data[1] & 0xfe) == 0x20) {
716 if (features->type != INTUOSHT2)
717 wacom->shared->stylus_in_proximity = true;
718
719 /* in Range while exiting */
720 if (wacom->reporting_data) {
721 input_report_key(input, BTN_TOUCH, 0);
722 input_report_abs(input, ABS_PRESSURE, 0);
723 input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
724 return 2;
725 }
726 return 1;
727 }
728
729 /* Exit report */
730 if ((data[1] & 0xfe) == 0x80) {
731 wacom->shared->stylus_in_proximity = false;
732 wacom->reporting_data = false;
733
734 /* don't report exit if we don't know the ID */
735 if (!wacom->id[idx])
736 return 1;
737
738 /*
739 * Reset all states otherwise we lose the initial states
740 * when in-prox next time
741 */
742 input_report_abs(input, ABS_X, 0);
743 input_report_abs(input, ABS_Y, 0);
744 input_report_abs(input, ABS_DISTANCE, 0);
745 input_report_abs(input, ABS_TILT_X, 0);
746 input_report_abs(input, ABS_TILT_Y, 0);
747 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
748 input_report_key(input, BTN_LEFT, 0);
749 input_report_key(input, BTN_MIDDLE, 0);
750 input_report_key(input, BTN_RIGHT, 0);
751 input_report_key(input, BTN_SIDE, 0);
752 input_report_key(input, BTN_EXTRA, 0);
753 input_report_abs(input, ABS_THROTTLE, 0);
754 input_report_abs(input, ABS_RZ, 0);
755 } else {
756 input_report_abs(input, ABS_PRESSURE, 0);
757 input_report_key(input, BTN_STYLUS, 0);
758 input_report_key(input, BTN_STYLUS2, 0);
759 input_report_key(input, BTN_TOUCH, 0);
760 input_report_abs(input, ABS_WHEEL, 0);
761 if (features->type >= INTUOS3S)
762 input_report_abs(input, ABS_Z, 0);
763 }
764 input_report_key(input, wacom->tool[idx], 0);
765 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
766 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
767 wacom->id[idx] = 0;
768 return 2;
769 }
770
771 return 0;
772 }
773
774 static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
775 {
776 unsigned char *data = wacom_wac->data;
777 struct input_dev *input;
778 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
779 struct wacom_remote *remote = wacom->remote;
780 int bat_charging, bat_percent, touch_ring_mode;
781 __u32 serial;
782 int i, index = -1;
783 unsigned long flags;
784
785 if (data[0] != WACOM_REPORT_REMOTE) {
786 hid_dbg(wacom->hdev, "%s: received unknown report #%d",
787 __func__, data[0]);
788 return 0;
789 }
790
791 serial = data[3] + (data[4] << 8) + (data[5] << 16);
792 wacom_wac->id[0] = PAD_DEVICE_ID;
793
794 spin_lock_irqsave(&remote->remote_lock, flags);
795
796 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
797 if (remote->remotes[i].serial == serial) {
798 index = i;
799 break;
800 }
801 }
802
803 if (index < 0 || !remote->remotes[index].registered)
804 goto out;
805
806 input = remote->remotes[index].input;
807
808 input_report_key(input, BTN_0, (data[9] & 0x01));
809 input_report_key(input, BTN_1, (data[9] & 0x02));
810 input_report_key(input, BTN_2, (data[9] & 0x04));
811 input_report_key(input, BTN_3, (data[9] & 0x08));
812 input_report_key(input, BTN_4, (data[9] & 0x10));
813 input_report_key(input, BTN_5, (data[9] & 0x20));
814 input_report_key(input, BTN_6, (data[9] & 0x40));
815 input_report_key(input, BTN_7, (data[9] & 0x80));
816
817 input_report_key(input, BTN_8, (data[10] & 0x01));
818 input_report_key(input, BTN_9, (data[10] & 0x02));
819 input_report_key(input, BTN_A, (data[10] & 0x04));
820 input_report_key(input, BTN_B, (data[10] & 0x08));
821 input_report_key(input, BTN_C, (data[10] & 0x10));
822 input_report_key(input, BTN_X, (data[10] & 0x20));
823 input_report_key(input, BTN_Y, (data[10] & 0x40));
824 input_report_key(input, BTN_Z, (data[10] & 0x80));
825
826 input_report_key(input, BTN_BASE, (data[11] & 0x01));
827 input_report_key(input, BTN_BASE2, (data[11] & 0x02));
828
829 if (data[12] & 0x80)
830 input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f));
831 else
832 input_report_abs(input, ABS_WHEEL, 0);
833
834 bat_percent = data[7] & 0x7f;
835 bat_charging = !!(data[7] & 0x80);
836
837 if (data[9] | data[10] | (data[11] & 0x03) | data[12])
838 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
839 else
840 input_report_abs(input, ABS_MISC, 0);
841
842 input_event(input, EV_MSC, MSC_SERIAL, serial);
843
844 input_sync(input);
845
846 /*Which mode select (LED light) is currently on?*/
847 touch_ring_mode = (data[11] & 0xC0) >> 6;
848
849 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
850 if (remote->remotes[i].serial == serial)
851 wacom->led.groups[i].select = touch_ring_mode;
852 }
853
854 __wacom_notify_battery(&remote->remotes[index].battery, bat_percent,
855 bat_charging, 1, bat_charging);
856
857 out:
858 spin_unlock_irqrestore(&remote->remote_lock, flags);
859 return 0;
860 }
861
862 static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
863 {
864 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
865 unsigned char *data = wacom_wac->data;
866 struct wacom_remote *remote = wacom->remote;
867 struct wacom_remote_data remote_data;
868 unsigned long flags;
869 int i, ret;
870
871 if (data[0] != WACOM_REPORT_DEVICE_LIST)
872 return;
873
874 memset(&remote_data, 0, sizeof(struct wacom_remote_data));
875
876 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
877 int j = i * 6;
878 int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
879 bool connected = data[j+2];
880
881 remote_data.remote[i].serial = serial;
882 remote_data.remote[i].connected = connected;
883 }
884
885 spin_lock_irqsave(&remote->remote_lock, flags);
886
887 ret = kfifo_in(&remote->remote_fifo, &remote_data, sizeof(remote_data));
888 if (ret != sizeof(remote_data)) {
889 spin_unlock_irqrestore(&remote->remote_lock, flags);
890 hid_err(wacom->hdev, "Can't queue Remote status event.\n");
891 return;
892 }
893
894 spin_unlock_irqrestore(&remote->remote_lock, flags);
895
896 wacom_schedule_work(wacom_wac, WACOM_WORKER_REMOTE);
897 }
898
899 static inline bool report_touch_events(struct wacom_wac *wacom)
900 {
901 return (touch_arbitration ? !wacom->shared->stylus_in_proximity : 1);
902 }
903
904 static inline bool delay_pen_events(struct wacom_wac *wacom)
905 {
906 return (wacom->shared->touch_down && touch_arbitration);
907 }
908
909 static int wacom_intuos_general(struct wacom_wac *wacom)
910 {
911 struct wacom_features *features = &wacom->features;
912 unsigned char *data = wacom->data;
913 struct input_dev *input = wacom->pen_input;
914 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
915 unsigned char type = (data[1] >> 1) & 0x0F;
916 unsigned int x, y, distance, t;
917
918 if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
919 data[0] != WACOM_REPORT_INTUOS_PEN)
920 return 0;
921
922 if (delay_pen_events(wacom))
923 return 1;
924
925 /* don't report events if we don't know the tool ID */
926 if (!wacom->id[idx]) {
927 /* but reschedule a read of the current tool */
928 wacom_intuos_schedule_prox_event(wacom);
929 return 1;
930 }
931
932 /*
933 * don't report events for invalid data
934 */
935 /* older I4 styli don't work with new Cintiqs */
936 if ((!((wacom->id[idx] >> 16) & 0x01) &&
937 (features->type == WACOM_21UX2)) ||
938 /* Only large Intuos support Lense Cursor */
939 (wacom->tool[idx] == BTN_TOOL_LENS &&
940 (features->type == INTUOS3 ||
941 features->type == INTUOS3S ||
942 features->type == INTUOS4 ||
943 features->type == INTUOS4S ||
944 features->type == INTUOS5 ||
945 features->type == INTUOS5S ||
946 features->type == INTUOSPM ||
947 features->type == INTUOSPS)) ||
948 /* Cintiq doesn't send data when RDY bit isn't set */
949 (features->type == CINTIQ && !(data[1] & 0x40)))
950 return 1;
951
952 x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
953 y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
954 distance = data[9] >> 2;
955 if (features->type < INTUOS3S) {
956 x >>= 1;
957 y >>= 1;
958 distance >>= 1;
959 }
960 input_report_abs(input, ABS_X, x);
961 input_report_abs(input, ABS_Y, y);
962 input_report_abs(input, ABS_DISTANCE, distance);
963
964 switch (type) {
965 case 0x00:
966 case 0x01:
967 case 0x02:
968 case 0x03:
969 /* general pen packet */
970 t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
971 if (features->pressure_max < 2047)
972 t >>= 1;
973 input_report_abs(input, ABS_PRESSURE, t);
974 if (features->type != INTUOSHT2) {
975 input_report_abs(input, ABS_TILT_X,
976 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
977 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
978 }
979 input_report_key(input, BTN_STYLUS, data[1] & 2);
980 input_report_key(input, BTN_STYLUS2, data[1] & 4);
981 input_report_key(input, BTN_TOUCH, t > 10);
982 break;
983
984 case 0x0a:
985 /* airbrush second packet */
986 input_report_abs(input, ABS_WHEEL,
987 (data[6] << 2) | ((data[7] >> 6) & 3));
988 input_report_abs(input, ABS_TILT_X,
989 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
990 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
991 break;
992
993 case 0x05:
994 /* Rotation packet */
995 if (features->type >= INTUOS3S) {
996 /* I3 marker pen rotation */
997 t = (data[6] << 3) | ((data[7] >> 5) & 7);
998 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
999 ((t-1) / 2 + 450)) : (450 - t / 2) ;
1000 input_report_abs(input, ABS_Z, t);
1001 } else {
1002 /* 4D mouse 2nd packet */
1003 t = (data[6] << 3) | ((data[7] >> 5) & 7);
1004 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
1005 ((t - 1) / 2) : -t / 2);
1006 }
1007 break;
1008
1009 case 0x04:
1010 /* 4D mouse 1st packet */
1011 input_report_key(input, BTN_LEFT, data[8] & 0x01);
1012 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
1013 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
1014
1015 input_report_key(input, BTN_SIDE, data[8] & 0x20);
1016 input_report_key(input, BTN_EXTRA, data[8] & 0x10);
1017 t = (data[6] << 2) | ((data[7] >> 6) & 3);
1018 input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
1019 break;
1020
1021 case 0x06:
1022 /* I4 mouse */
1023 input_report_key(input, BTN_LEFT, data[6] & 0x01);
1024 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
1025 input_report_key(input, BTN_RIGHT, data[6] & 0x04);
1026 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
1027 - ((data[7] & 0x40) >> 6));
1028 input_report_key(input, BTN_SIDE, data[6] & 0x08);
1029 input_report_key(input, BTN_EXTRA, data[6] & 0x10);
1030
1031 input_report_abs(input, ABS_TILT_X,
1032 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
1033 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
1034 break;
1035
1036 case 0x08:
1037 if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
1038 /* 2D mouse packet */
1039 input_report_key(input, BTN_LEFT, data[8] & 0x04);
1040 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
1041 input_report_key(input, BTN_RIGHT, data[8] & 0x10);
1042 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
1043 - ((data[8] & 0x02) >> 1));
1044
1045 /* I3 2D mouse side buttons */
1046 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
1047 input_report_key(input, BTN_SIDE, data[8] & 0x40);
1048 input_report_key(input, BTN_EXTRA, data[8] & 0x20);
1049 }
1050 }
1051 else if (wacom->tool[idx] == BTN_TOOL_LENS) {
1052 /* Lens cursor packets */
1053 input_report_key(input, BTN_LEFT, data[8] & 0x01);
1054 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
1055 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
1056 input_report_key(input, BTN_SIDE, data[8] & 0x10);
1057 input_report_key(input, BTN_EXTRA, data[8] & 0x08);
1058 }
1059 break;
1060
1061 case 0x07:
1062 case 0x09:
1063 case 0x0b:
1064 case 0x0c:
1065 case 0x0d:
1066 case 0x0e:
1067 case 0x0f:
1068 /* unhandled */
1069 break;
1070 }
1071
1072 input_report_abs(input, ABS_MISC,
1073 wacom_intuos_id_mangle(wacom->id[idx])); /* report tool id */
1074 input_report_key(input, wacom->tool[idx], 1);
1075 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
1076 wacom->reporting_data = true;
1077 return 2;
1078 }
1079
1080 static int wacom_intuos_irq(struct wacom_wac *wacom)
1081 {
1082 unsigned char *data = wacom->data;
1083 struct input_dev *input = wacom->pen_input;
1084 int result;
1085
1086 if (data[0] != WACOM_REPORT_PENABLED &&
1087 data[0] != WACOM_REPORT_INTUOS_ID1 &&
1088 data[0] != WACOM_REPORT_INTUOS_ID2 &&
1089 data[0] != WACOM_REPORT_INTUOSPAD &&
1090 data[0] != WACOM_REPORT_INTUOS_PEN &&
1091 data[0] != WACOM_REPORT_CINTIQ &&
1092 data[0] != WACOM_REPORT_CINTIQPAD &&
1093 data[0] != WACOM_REPORT_INTUOS5PAD) {
1094 dev_dbg(input->dev.parent,
1095 "%s: received unknown report #%d\n", __func__, data[0]);
1096 return 0;
1097 }
1098
1099 /* process pad events */
1100 result = wacom_intuos_pad(wacom);
1101 if (result)
1102 return result;
1103
1104 /* process in/out prox events */
1105 result = wacom_intuos_inout(wacom);
1106 if (result)
1107 return result - 1;
1108
1109 /* process general packets */
1110 result = wacom_intuos_general(wacom);
1111 if (result)
1112 return result - 1;
1113
1114 return 0;
1115 }
1116
1117 static int int_dist(int x1, int y1, int x2, int y2)
1118 {
1119 int x = x2 - x1;
1120 int y = y2 - y1;
1121
1122 return int_sqrt(x*x + y*y);
1123 }
1124
1125 static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
1126 unsigned char *data)
1127 {
1128 memcpy(wacom->data, data, 10);
1129 wacom_intuos_irq(wacom);
1130
1131 input_sync(wacom->pen_input);
1132 if (wacom->pad_input)
1133 input_sync(wacom->pad_input);
1134 }
1135
1136 static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1137 {
1138 unsigned char data[WACOM_PKGLEN_MAX];
1139 int i = 1;
1140 unsigned power_raw, battery_capacity, bat_charging, ps_connected;
1141
1142 memcpy(data, wacom->data, len);
1143
1144 switch (data[0]) {
1145 case 0x04:
1146 wacom_intuos_bt_process_data(wacom, data + i);
1147 i += 10;
1148 /* fall through */
1149 case 0x03:
1150 wacom_intuos_bt_process_data(wacom, data + i);
1151 i += 10;
1152 wacom_intuos_bt_process_data(wacom, data + i);
1153 i += 10;
1154 power_raw = data[i];
1155 bat_charging = (power_raw & 0x08) ? 1 : 0;
1156 ps_connected = (power_raw & 0x10) ? 1 : 0;
1157 battery_capacity = batcap_i4[power_raw & 0x07];
1158 wacom_notify_battery(wacom, battery_capacity, bat_charging,
1159 battery_capacity || bat_charging,
1160 ps_connected);
1161 break;
1162 default:
1163 dev_dbg(wacom->pen_input->dev.parent,
1164 "Unknown report: %d,%d size:%zu\n",
1165 data[0], data[1], len);
1166 return 0;
1167 }
1168 return 0;
1169 }
1170
1171 static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1172 {
1173 struct input_dev *input = wacom->touch_input;
1174 unsigned touch_max = wacom->features.touch_max;
1175 int count = 0;
1176 int i;
1177
1178 if (!touch_max)
1179 return 0;
1180
1181 if (touch_max == 1)
1182 return test_bit(BTN_TOUCH, input->key) &&
1183 report_touch_events(wacom);
1184
1185 for (i = 0; i < input->mt->num_slots; i++) {
1186 struct input_mt_slot *ps = &input->mt->slots[i];
1187 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1188 if (id >= 0)
1189 count++;
1190 }
1191
1192 return count;
1193 }
1194
1195 static int wacom_24hdt_irq(struct wacom_wac *wacom)
1196 {
1197 struct input_dev *input = wacom->touch_input;
1198 unsigned char *data = wacom->data;
1199 int i;
1200 int current_num_contacts = data[61];
1201 int contacts_to_send = 0;
1202 int num_contacts_left = 4; /* maximum contacts per packet */
1203 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1204 int y_offset = 2;
1205
1206 if (wacom->features.type == WACOM_27QHDT) {
1207 current_num_contacts = data[63];
1208 num_contacts_left = 10;
1209 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1210 y_offset = 0;
1211 }
1212
1213 /*
1214 * First packet resets the counter since only the first
1215 * packet in series will have non-zero current_num_contacts.
1216 */
1217 if (current_num_contacts)
1218 wacom->num_contacts_left = current_num_contacts;
1219
1220 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1221
1222 for (i = 0; i < contacts_to_send; i++) {
1223 int offset = (byte_per_packet * i) + 1;
1224 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
1225 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
1226
1227 if (slot < 0)
1228 continue;
1229 input_mt_slot(input, slot);
1230 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1231
1232 if (touch) {
1233 int t_x = get_unaligned_le16(&data[offset + 2]);
1234 int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
1235
1236 input_report_abs(input, ABS_MT_POSITION_X, t_x);
1237 input_report_abs(input, ABS_MT_POSITION_Y, t_y);
1238
1239 if (wacom->features.type != WACOM_27QHDT) {
1240 int c_x = get_unaligned_le16(&data[offset + 4]);
1241 int c_y = get_unaligned_le16(&data[offset + 8]);
1242 int w = get_unaligned_le16(&data[offset + 10]);
1243 int h = get_unaligned_le16(&data[offset + 12]);
1244
1245 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1246 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1247 min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1248 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1249 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1250 }
1251 }
1252 }
1253 input_mt_sync_frame(input);
1254
1255 wacom->num_contacts_left -= contacts_to_send;
1256 if (wacom->num_contacts_left <= 0) {
1257 wacom->num_contacts_left = 0;
1258 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1259 }
1260 return 1;
1261 }
1262
1263 static int wacom_mt_touch(struct wacom_wac *wacom)
1264 {
1265 struct input_dev *input = wacom->touch_input;
1266 unsigned char *data = wacom->data;
1267 int i;
1268 int current_num_contacts = data[2];
1269 int contacts_to_send = 0;
1270 int x_offset = 0;
1271
1272 /* MTTPC does not support Height and Width */
1273 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
1274 x_offset = -4;
1275
1276 /*
1277 * First packet resets the counter since only the first
1278 * packet in series will have non-zero current_num_contacts.
1279 */
1280 if (current_num_contacts)
1281 wacom->num_contacts_left = current_num_contacts;
1282
1283 /* There are at most 5 contacts per packet */
1284 contacts_to_send = min(5, wacom->num_contacts_left);
1285
1286 for (i = 0; i < contacts_to_send; i++) {
1287 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
1288 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
1289 int id = get_unaligned_le16(&data[offset + 1]);
1290 int slot = input_mt_get_slot_by_key(input, id);
1291
1292 if (slot < 0)
1293 continue;
1294
1295 input_mt_slot(input, slot);
1296 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1297 if (touch) {
1298 int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1299 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
1300 input_report_abs(input, ABS_MT_POSITION_X, x);
1301 input_report_abs(input, ABS_MT_POSITION_Y, y);
1302 }
1303 }
1304 input_mt_sync_frame(input);
1305
1306 wacom->num_contacts_left -= contacts_to_send;
1307 if (wacom->num_contacts_left <= 0) {
1308 wacom->num_contacts_left = 0;
1309 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1310 }
1311 return 1;
1312 }
1313
1314 static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1315 {
1316 struct input_dev *input = wacom->touch_input;
1317 unsigned char *data = wacom->data;
1318 int i;
1319
1320 for (i = 0; i < 2; i++) {
1321 int p = data[1] & (1 << i);
1322 bool touch = p && report_touch_events(wacom);
1323
1324 input_mt_slot(input, i);
1325 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1326 if (touch) {
1327 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1328 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1329
1330 input_report_abs(input, ABS_MT_POSITION_X, x);
1331 input_report_abs(input, ABS_MT_POSITION_Y, y);
1332 }
1333 }
1334 input_mt_sync_frame(input);
1335
1336 /* keep touch state for pen event */
1337 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1338
1339 return 1;
1340 }
1341
1342 static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
1343 {
1344 unsigned char *data = wacom->data;
1345 struct input_dev *input = wacom->touch_input;
1346 bool prox = report_touch_events(wacom);
1347 int x = 0, y = 0;
1348
1349 if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1350 return 0;
1351
1352 if (len == WACOM_PKGLEN_TPC1FG) {
1353 prox = prox && (data[0] & 0x01);
1354 x = get_unaligned_le16(&data[1]);
1355 y = get_unaligned_le16(&data[3]);
1356 } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1357 prox = prox && (data[2] & 0x01);
1358 x = get_unaligned_le16(&data[3]);
1359 y = get_unaligned_le16(&data[5]);
1360 } else {
1361 prox = prox && (data[1] & 0x01);
1362 x = le16_to_cpup((__le16 *)&data[2]);
1363 y = le16_to_cpup((__le16 *)&data[4]);
1364 }
1365
1366 if (prox) {
1367 input_report_abs(input, ABS_X, x);
1368 input_report_abs(input, ABS_Y, y);
1369 }
1370 input_report_key(input, BTN_TOUCH, prox);
1371
1372 /* keep touch state for pen events */
1373 wacom->shared->touch_down = prox;
1374
1375 return 1;
1376 }
1377
1378 static int wacom_tpc_pen(struct wacom_wac *wacom)
1379 {
1380 unsigned char *data = wacom->data;
1381 struct input_dev *input = wacom->pen_input;
1382 bool prox = data[1] & 0x20;
1383
1384 if (!wacom->shared->stylus_in_proximity) /* first in prox */
1385 /* Going into proximity select tool */
1386 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
1387
1388 /* keep pen state for touch events */
1389 wacom->shared->stylus_in_proximity = prox;
1390
1391 /* send pen events only when touch is up or forced out
1392 * or touch arbitration is off
1393 */
1394 if (!delay_pen_events(wacom)) {
1395 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1396 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1397 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1398 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
1399 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
1400 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1401 input_report_key(input, wacom->tool[0], prox);
1402 return 1;
1403 }
1404
1405 return 0;
1406 }
1407
1408 static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1409 {
1410 unsigned char *data = wacom->data;
1411
1412 if (wacom->pen_input)
1413 dev_dbg(wacom->pen_input->dev.parent,
1414 "%s: received report #%d\n", __func__, data[0]);
1415 else if (wacom->touch_input)
1416 dev_dbg(wacom->touch_input->dev.parent,
1417 "%s: received report #%d\n", __func__, data[0]);
1418
1419 switch (len) {
1420 case WACOM_PKGLEN_TPC1FG:
1421 return wacom_tpc_single_touch(wacom, len);
1422
1423 case WACOM_PKGLEN_TPC2FG:
1424 return wacom_tpc_mt_touch(wacom);
1425
1426 case WACOM_PKGLEN_PENABLED:
1427 return wacom_tpc_pen(wacom);
1428
1429 default:
1430 switch (data[0]) {
1431 case WACOM_REPORT_TPC1FG:
1432 case WACOM_REPORT_TPCHID:
1433 case WACOM_REPORT_TPCST:
1434 case WACOM_REPORT_TPC1FGE:
1435 return wacom_tpc_single_touch(wacom, len);
1436
1437 case WACOM_REPORT_TPCMT:
1438 case WACOM_REPORT_TPCMT2:
1439 return wacom_mt_touch(wacom);
1440
1441 case WACOM_REPORT_PENABLED:
1442 return wacom_tpc_pen(wacom);
1443 }
1444 }
1445
1446 return 0;
1447 }
1448
1449 static int wacom_equivalent_usage(int usage)
1450 {
1451 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1452 int subpage = (usage & 0xFF00) << 8;
1453 int subusage = (usage & 0xFF);
1454
1455 if (subpage == WACOM_HID_SP_PAD ||
1456 subpage == WACOM_HID_SP_BUTTON ||
1457 subpage == WACOM_HID_SP_DIGITIZER ||
1458 subpage == WACOM_HID_SP_DIGITIZERINFO ||
1459 usage == WACOM_HID_WD_SENSE ||
1460 usage == WACOM_HID_WD_SERIALHI ||
1461 usage == WACOM_HID_WD_TOOLTYPE ||
1462 usage == WACOM_HID_WD_DISTANCE ||
1463 usage == WACOM_HID_WD_TOUCHSTRIP ||
1464 usage == WACOM_HID_WD_TOUCHSTRIP2 ||
1465 usage == WACOM_HID_WD_TOUCHRING ||
1466 usage == WACOM_HID_WD_TOUCHRINGSTATUS) {
1467 return usage;
1468 }
1469
1470 if (subpage == HID_UP_UNDEFINED)
1471 subpage = HID_UP_DIGITIZER;
1472
1473 return subpage | subusage;
1474 }
1475
1476 return usage;
1477 }
1478
1479 static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
1480 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1481 {
1482 struct wacom *wacom = input_get_drvdata(input);
1483 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1484 struct wacom_features *features = &wacom_wac->features;
1485 int fmin = field->logical_minimum;
1486 int fmax = field->logical_maximum;
1487 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
1488 int resolution_code = code;
1489
1490 if (equivalent_usage == HID_DG_TWIST) {
1491 resolution_code = ABS_RZ;
1492 }
1493
1494 if (equivalent_usage == HID_GD_X) {
1495 fmin += features->offset_left;
1496 fmax -= features->offset_right;
1497 }
1498 if (equivalent_usage == HID_GD_Y) {
1499 fmin += features->offset_top;
1500 fmax -= features->offset_bottom;
1501 }
1502
1503 usage->type = type;
1504 usage->code = code;
1505
1506 set_bit(type, input->evbit);
1507
1508 switch (type) {
1509 case EV_ABS:
1510 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1511 input_abs_set_res(input, code,
1512 hidinput_calc_abs_res(field, resolution_code));
1513 break;
1514 case EV_KEY:
1515 input_set_capability(input, EV_KEY, code);
1516 break;
1517 case EV_MSC:
1518 input_set_capability(input, EV_MSC, code);
1519 break;
1520 case EV_SW:
1521 input_set_capability(input, EV_SW, code);
1522 break;
1523 }
1524 }
1525
1526 static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1527 struct hid_field *field, struct hid_usage *usage)
1528 {
1529 struct wacom *wacom = hid_get_drvdata(hdev);
1530 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1531 struct wacom_features *features = &wacom_wac->features;
1532 struct input_dev *input = wacom_wac->pad_input;
1533 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1534
1535 switch (equivalent_usage) {
1536 case WACOM_HID_WD_BATTERY_LEVEL:
1537 case WACOM_HID_WD_BATTERY_CHARGING:
1538 features->quirks |= WACOM_QUIRK_BATTERY;
1539 break;
1540 case WACOM_HID_WD_ACCELEROMETER_X:
1541 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1542 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
1543 features->device_type |= WACOM_DEVICETYPE_PAD;
1544 break;
1545 case WACOM_HID_WD_ACCELEROMETER_Y:
1546 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1547 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
1548 features->device_type |= WACOM_DEVICETYPE_PAD;
1549 break;
1550 case WACOM_HID_WD_ACCELEROMETER_Z:
1551 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1552 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1553 features->device_type |= WACOM_DEVICETYPE_PAD;
1554 break;
1555 case WACOM_HID_WD_BUTTONHOME:
1556 case WACOM_HID_WD_BUTTONUP:
1557 case WACOM_HID_WD_BUTTONDOWN:
1558 case WACOM_HID_WD_BUTTONLEFT:
1559 case WACOM_HID_WD_BUTTONRIGHT:
1560 case WACOM_HID_WD_BUTTONCENTER:
1561 wacom_map_usage(input, usage, field, EV_KEY,
1562 wacom_numbered_button_to_key(features->numbered_buttons),
1563 0);
1564 features->numbered_buttons++;
1565 features->device_type |= WACOM_DEVICETYPE_PAD;
1566 break;
1567 case WACOM_HID_WD_TOUCHONOFF:
1568 wacom_map_usage(input, usage, field, EV_SW, SW_MUTE_DEVICE, 0);
1569 features->device_type |= WACOM_DEVICETYPE_PAD;
1570 break;
1571 case WACOM_HID_WD_TOUCHSTRIP:
1572 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
1573 features->device_type |= WACOM_DEVICETYPE_PAD;
1574 break;
1575 case WACOM_HID_WD_TOUCHSTRIP2:
1576 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
1577 features->device_type |= WACOM_DEVICETYPE_PAD;
1578 break;
1579 case WACOM_HID_WD_TOUCHRING:
1580 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1581 features->device_type |= WACOM_DEVICETYPE_PAD;
1582 break;
1583 }
1584
1585 switch (equivalent_usage & 0xfffffff0) {
1586 case WACOM_HID_WD_EXPRESSKEY00:
1587 wacom_map_usage(input, usage, field, EV_KEY,
1588 wacom_numbered_button_to_key(features->numbered_buttons),
1589 0);
1590 features->numbered_buttons++;
1591 features->device_type |= WACOM_DEVICETYPE_PAD;
1592 break;
1593 }
1594 }
1595
1596 static void wacom_wac_pad_battery_event(struct hid_device *hdev, struct hid_field *field,
1597 struct hid_usage *usage, __s32 value)
1598 {
1599 struct wacom *wacom = hid_get_drvdata(hdev);
1600 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1601 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1602
1603 switch (equivalent_usage) {
1604 case WACOM_HID_WD_BATTERY_LEVEL:
1605 wacom_wac->hid_data.battery_capacity = value;
1606 wacom_wac->hid_data.bat_connected = 1;
1607 break;
1608
1609 case WACOM_HID_WD_BATTERY_CHARGING:
1610 wacom_wac->hid_data.bat_charging = value;
1611 wacom_wac->hid_data.ps_connected = value;
1612 wacom_wac->hid_data.bat_connected = 1;
1613 break;
1614 }
1615 }
1616
1617 static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
1618 struct hid_usage *usage, __s32 value)
1619 {
1620 struct wacom *wacom = hid_get_drvdata(hdev);
1621 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1622 struct input_dev *input = wacom_wac->pad_input;
1623 struct wacom_features *features = &wacom_wac->features;
1624 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1625
1626 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
1627 wacom_wac->hid_data.inrange_state |= value;
1628 }
1629
1630 switch (equivalent_usage) {
1631 case WACOM_HID_WD_TOUCHRINGSTATUS:
1632 break;
1633
1634 default:
1635 features->input_event_flag = true;
1636 input_event(input, usage->type, usage->code, value);
1637 break;
1638 }
1639 }
1640
1641 static void wacom_wac_pad_pre_report(struct hid_device *hdev,
1642 struct hid_report *report)
1643 {
1644 struct wacom *wacom = hid_get_drvdata(hdev);
1645 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1646
1647 wacom_wac->hid_data.inrange_state = 0;
1648 }
1649
1650 static void wacom_wac_pad_battery_report(struct hid_device *hdev,
1651 struct hid_report *report)
1652 {
1653 struct wacom *wacom = hid_get_drvdata(hdev);
1654 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1655 struct wacom_features *features = &wacom_wac->features;
1656
1657 if (features->quirks & WACOM_QUIRK_BATTERY) {
1658 int capacity = wacom_wac->hid_data.battery_capacity;
1659 bool charging = wacom_wac->hid_data.bat_charging;
1660 bool connected = wacom_wac->hid_data.bat_connected;
1661 bool powered = wacom_wac->hid_data.ps_connected;
1662
1663 wacom_notify_battery(wacom_wac, capacity, charging,
1664 connected, powered);
1665 }
1666 }
1667
1668 static void wacom_wac_pad_report(struct hid_device *hdev,
1669 struct hid_report *report)
1670 {
1671 struct wacom *wacom = hid_get_drvdata(hdev);
1672 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1673 struct wacom_features *features = &wacom_wac->features;
1674 struct input_dev *input = wacom_wac->pad_input;
1675 bool active = wacom_wac->hid_data.inrange_state != 0;
1676
1677 /* report prox for expresskey events */
1678 if (wacom_equivalent_usage(report->field[0]->physical) == HID_DG_TABLETFUNCTIONKEY) {
1679 features->input_event_flag = true;
1680 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
1681 }
1682
1683 if (features->input_event_flag) {
1684 features->input_event_flag = false;
1685 input_sync(input);
1686 }
1687 }
1688
1689 static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
1690 struct hid_field *field, struct hid_usage *usage)
1691 {
1692 struct wacom *wacom = hid_get_drvdata(hdev);
1693 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1694 struct wacom_features *features = &wacom_wac->features;
1695 struct input_dev *input = wacom_wac->pen_input;
1696 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1697
1698 switch (equivalent_usage) {
1699 case HID_GD_X:
1700 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
1701 break;
1702 case HID_GD_Y:
1703 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
1704 break;
1705 case WACOM_HID_WD_DISTANCE:
1706 case HID_GD_Z:
1707 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
1708 break;
1709 case HID_DG_TIPPRESSURE:
1710 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
1711 break;
1712 case HID_DG_INRANGE:
1713 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1714 break;
1715 case HID_DG_BATTERYSTRENGTH:
1716 features->quirks |= WACOM_QUIRK_BATTERY;
1717 break;
1718 case HID_DG_INVERT:
1719 wacom_map_usage(input, usage, field, EV_KEY,
1720 BTN_TOOL_RUBBER, 0);
1721 break;
1722 case HID_DG_TILT_X:
1723 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
1724 break;
1725 case HID_DG_TILT_Y:
1726 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
1727 break;
1728 case HID_DG_TWIST:
1729 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1730 break;
1731 case HID_DG_ERASER:
1732 case HID_DG_TIPSWITCH:
1733 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
1734 break;
1735 case HID_DG_BARRELSWITCH:
1736 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
1737 break;
1738 case HID_DG_BARRELSWITCH2:
1739 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
1740 break;
1741 case HID_DG_TOOLSERIALNUMBER:
1742 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
1743 break;
1744 case WACOM_HID_WD_SENSE:
1745 features->quirks |= WACOM_QUIRK_SENSE;
1746 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1747 break;
1748 case WACOM_HID_WD_SERIALHI:
1749 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
1750 set_bit(EV_KEY, input->evbit);
1751 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
1752 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
1753 input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
1754 input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
1755 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
1756 input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
1757 input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
1758 break;
1759 case WACOM_HID_WD_FINGERWHEEL:
1760 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1761 break;
1762 }
1763 }
1764
1765 static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
1766 struct hid_usage *usage, __s32 value)
1767 {
1768 struct wacom *wacom = hid_get_drvdata(hdev);
1769 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1770 struct wacom_features *features = &wacom_wac->features;
1771 struct input_dev *input = wacom_wac->pen_input;
1772 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1773
1774 switch (equivalent_usage) {
1775 case HID_GD_Z:
1776 /*
1777 * HID_GD_Z "should increase as the control's position is
1778 * moved from high to low", while ABS_DISTANCE instead
1779 * increases in value as the tool moves from low to high.
1780 */
1781 value = field->logical_maximum - value;
1782 break;
1783 case HID_DG_INRANGE:
1784 wacom_wac->hid_data.inrange_state = value;
1785 if (!(features->quirks & WACOM_QUIRK_SENSE))
1786 wacom_wac->hid_data.sense_state = value;
1787 return;
1788 case HID_DG_BATTERYSTRENGTH:
1789 wacom_wac->hid_data.battery_capacity = value;
1790 wacom_wac->hid_data.bat_connected = 1;
1791 break;
1792 case HID_DG_INVERT:
1793 wacom_wac->hid_data.invert_state = value;
1794 return;
1795 case HID_DG_ERASER:
1796 case HID_DG_TIPSWITCH:
1797 wacom_wac->hid_data.tipswitch |= value;
1798 return;
1799 case HID_DG_TOOLSERIALNUMBER:
1800 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
1801 wacom_wac->serial[0] |= value;
1802 return;
1803 case WACOM_HID_WD_SENSE:
1804 wacom_wac->hid_data.sense_state = value;
1805 return;
1806 case WACOM_HID_WD_SERIALHI:
1807 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
1808 wacom_wac->serial[0] |= ((__u64)value) << 32;
1809 /*
1810 * Non-USI EMR devices may contain additional tool type
1811 * information here. See WACOM_HID_WD_TOOLTYPE case for
1812 * more details.
1813 */
1814 if (value >> 20 == 1) {
1815 wacom_wac->id[0] |= value & 0xFFFFF;
1816 }
1817 return;
1818 case WACOM_HID_WD_TOOLTYPE:
1819 /*
1820 * Some devices (MobileStudio Pro, and possibly later
1821 * devices as well) do not return the complete tool
1822 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
1823 * bitwise OR so the complete value can be built
1824 * up over time :(
1825 */
1826 wacom_wac->id[0] |= value;
1827 return;
1828 case WACOM_HID_WD_OFFSETLEFT:
1829 if (features->offset_left && value != features->offset_left)
1830 hid_warn(hdev, "%s: overriding exising left offset "
1831 "%d -> %d\n", __func__, value,
1832 features->offset_left);
1833 features->offset_left = value;
1834 return;
1835 case WACOM_HID_WD_OFFSETRIGHT:
1836 if (features->offset_right && value != features->offset_right)
1837 hid_warn(hdev, "%s: overriding exising right offset "
1838 "%d -> %d\n", __func__, value,
1839 features->offset_right);
1840 features->offset_right = value;
1841 return;
1842 case WACOM_HID_WD_OFFSETTOP:
1843 if (features->offset_top && value != features->offset_top)
1844 hid_warn(hdev, "%s: overriding exising top offset "
1845 "%d -> %d\n", __func__, value,
1846 features->offset_top);
1847 features->offset_top = value;
1848 return;
1849 case WACOM_HID_WD_OFFSETBOTTOM:
1850 if (features->offset_bottom && value != features->offset_bottom)
1851 hid_warn(hdev, "%s: overriding exising bottom offset "
1852 "%d -> %d\n", __func__, value,
1853 features->offset_bottom);
1854 features->offset_bottom = value;
1855 return;
1856 }
1857
1858 /* send pen events only when touch is up or forced out
1859 * or touch arbitration is off
1860 */
1861 if (!usage->type || delay_pen_events(wacom_wac))
1862 return;
1863
1864 /* send pen events only when the pen is in/entering/leaving proximity */
1865 if (!wacom_wac->hid_data.inrange_state && !wacom_wac->tool[0])
1866 return;
1867
1868 input_event(input, usage->type, usage->code, value);
1869 }
1870
1871 static void wacom_wac_pen_pre_report(struct hid_device *hdev,
1872 struct hid_report *report)
1873 {
1874 return;
1875 }
1876
1877 static void wacom_wac_pen_report(struct hid_device *hdev,
1878 struct hid_report *report)
1879 {
1880 struct wacom *wacom = hid_get_drvdata(hdev);
1881 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1882 struct input_dev *input = wacom_wac->pen_input;
1883 bool prox = wacom_wac->hid_data.inrange_state;
1884 bool range = wacom_wac->hid_data.sense_state;
1885
1886 if (!wacom_wac->tool[0] && prox) { /* first in prox */
1887 /* Going into proximity select tool */
1888 if (wacom_wac->hid_data.invert_state)
1889 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
1890 else if (wacom_wac->id[0])
1891 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
1892 else
1893 wacom_wac->tool[0] = BTN_TOOL_PEN;
1894 }
1895
1896 /* keep pen state for touch events */
1897 wacom_wac->shared->stylus_in_proximity = range;
1898
1899 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
1900 int id = wacom_wac->id[0];
1901
1902 /*
1903 * Non-USI EMR tools should have their IDs mangled to
1904 * match the legacy behavior of wacom_intuos_general
1905 */
1906 if (wacom_wac->serial[0] >> 52 == 1)
1907 id = wacom_intuos_id_mangle(id);
1908
1909 /*
1910 * To ensure compatibility with xf86-input-wacom, we should
1911 * report the BTN_TOOL_* event prior to the ABS_MISC or
1912 * MSC_SERIAL events.
1913 */
1914 input_report_key(input, BTN_TOUCH,
1915 wacom_wac->hid_data.tipswitch);
1916 input_report_key(input, wacom_wac->tool[0], prox);
1917 if (wacom_wac->serial[0]) {
1918 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
1919 input_report_abs(input, ABS_MISC, id);
1920 }
1921
1922 wacom_wac->hid_data.tipswitch = false;
1923
1924 input_sync(input);
1925 }
1926
1927 if (!prox) {
1928 wacom_wac->tool[0] = 0;
1929 wacom_wac->id[0] = 0;
1930 }
1931 }
1932
1933 static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
1934 struct hid_field *field, struct hid_usage *usage)
1935 {
1936 struct wacom *wacom = hid_get_drvdata(hdev);
1937 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1938 struct input_dev *input = wacom_wac->touch_input;
1939 unsigned touch_max = wacom_wac->features.touch_max;
1940 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1941
1942 switch (equivalent_usage) {
1943 case HID_GD_X:
1944 if (touch_max == 1)
1945 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
1946 else
1947 wacom_map_usage(input, usage, field, EV_ABS,
1948 ABS_MT_POSITION_X, 4);
1949 break;
1950 case HID_GD_Y:
1951 if (touch_max == 1)
1952 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
1953 else
1954 wacom_map_usage(input, usage, field, EV_ABS,
1955 ABS_MT_POSITION_Y, 4);
1956 break;
1957 case HID_DG_WIDTH:
1958 case HID_DG_HEIGHT:
1959 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
1960 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
1961 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
1962 break;
1963 case HID_DG_TIPSWITCH:
1964 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
1965 break;
1966 case HID_DG_CONTACTCOUNT:
1967 wacom_wac->hid_data.cc_report = field->report->id;
1968 wacom_wac->hid_data.cc_index = field->index;
1969 wacom_wac->hid_data.cc_value_index = usage->usage_index;
1970 break;
1971 }
1972 }
1973
1974 static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
1975 struct input_dev *input)
1976 {
1977 struct hid_data *hid_data = &wacom_wac->hid_data;
1978 bool mt = wacom_wac->features.touch_max > 1;
1979 bool prox = hid_data->tipswitch &&
1980 report_touch_events(wacom_wac);
1981
1982 wacom_wac->hid_data.num_received++;
1983 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
1984 return;
1985
1986 if (mt) {
1987 int slot;
1988
1989 slot = input_mt_get_slot_by_key(input, hid_data->id);
1990 input_mt_slot(input, slot);
1991 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
1992 }
1993 else {
1994 input_report_key(input, BTN_TOUCH, prox);
1995 }
1996
1997 if (prox) {
1998 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
1999 hid_data->x);
2000 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
2001 hid_data->y);
2002
2003 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
2004 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
2005 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
2006 if (hid_data->width != hid_data->height)
2007 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
2008 }
2009 }
2010 }
2011
2012 static void wacom_wac_finger_event(struct hid_device *hdev,
2013 struct hid_field *field, struct hid_usage *usage, __s32 value)
2014 {
2015 struct wacom *wacom = hid_get_drvdata(hdev);
2016 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2017 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
2018
2019 switch (equivalent_usage) {
2020 case HID_GD_X:
2021 wacom_wac->hid_data.x = value;
2022 break;
2023 case HID_GD_Y:
2024 wacom_wac->hid_data.y = value;
2025 break;
2026 case HID_DG_WIDTH:
2027 wacom_wac->hid_data.width = value;
2028 break;
2029 case HID_DG_HEIGHT:
2030 wacom_wac->hid_data.height = value;
2031 break;
2032 case HID_DG_CONTACTID:
2033 wacom_wac->hid_data.id = value;
2034 break;
2035 case HID_DG_TIPSWITCH:
2036 wacom_wac->hid_data.tipswitch = value;
2037 break;
2038 }
2039
2040
2041 if (usage->usage_index + 1 == field->report_count) {
2042 if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
2043 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
2044 }
2045 }
2046
2047 static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2048 struct hid_report *report)
2049 {
2050 struct wacom *wacom = hid_get_drvdata(hdev);
2051 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2052 struct hid_data* hid_data = &wacom_wac->hid_data;
2053 int i;
2054
2055 for (i = 0; i < report->maxfield; i++) {
2056 struct hid_field *field = report->field[i];
2057 int j;
2058
2059 for (j = 0; j < field->maxusage; j++) {
2060 struct hid_usage *usage = &field->usage[j];
2061
2062 switch (usage->hid) {
2063 case HID_GD_X:
2064 case HID_GD_Y:
2065 case HID_DG_WIDTH:
2066 case HID_DG_HEIGHT:
2067 case HID_DG_CONTACTID:
2068 case HID_DG_INRANGE:
2069 case HID_DG_INVERT:
2070 case HID_DG_TIPSWITCH:
2071 hid_data->last_slot_field = usage->hid;
2072 break;
2073 case HID_DG_CONTACTCOUNT:
2074 hid_data->cc_report = report->id;
2075 hid_data->cc_index = i;
2076 hid_data->cc_value_index = j;
2077 break;
2078 }
2079 }
2080 }
2081
2082 if (hid_data->cc_report != 0 &&
2083 hid_data->cc_index >= 0) {
2084 struct hid_field *field = report->field[hid_data->cc_index];
2085 int value = field->value[hid_data->cc_value_index];
2086 if (value)
2087 hid_data->num_expected = value;
2088 }
2089 else {
2090 hid_data->num_expected = wacom_wac->features.touch_max;
2091 }
2092 }
2093
2094 static void wacom_wac_finger_report(struct hid_device *hdev,
2095 struct hid_report *report)
2096 {
2097 struct wacom *wacom = hid_get_drvdata(hdev);
2098 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2099 struct input_dev *input = wacom_wac->touch_input;
2100 unsigned touch_max = wacom_wac->features.touch_max;
2101
2102 /* If more packets of data are expected, give us a chance to
2103 * process them rather than immediately syncing a partial
2104 * update.
2105 */
2106 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2107 return;
2108
2109 if (touch_max > 1)
2110 input_mt_sync_frame(input);
2111
2112 input_sync(input);
2113 wacom_wac->hid_data.num_received = 0;
2114
2115 /* keep touch state for pen event */
2116 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
2117 }
2118
2119 void wacom_wac_usage_mapping(struct hid_device *hdev,
2120 struct hid_field *field, struct hid_usage *usage)
2121 {
2122 struct wacom *wacom = hid_get_drvdata(hdev);
2123 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2124 struct wacom_features *features = &wacom_wac->features;
2125
2126 /* currently, only direct devices have proper hid report descriptors */
2127 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2128
2129 if (WACOM_PAD_FIELD(field))
2130 wacom_wac_pad_usage_mapping(hdev, field, usage);
2131 else if (WACOM_PEN_FIELD(field))
2132 wacom_wac_pen_usage_mapping(hdev, field, usage);
2133 else if (WACOM_FINGER_FIELD(field))
2134 wacom_wac_finger_usage_mapping(hdev, field, usage);
2135 }
2136
2137 void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
2138 struct hid_usage *usage, __s32 value)
2139 {
2140 struct wacom *wacom = hid_get_drvdata(hdev);
2141
2142 if (wacom->wacom_wac.features.type != HID_GENERIC)
2143 return;
2144
2145 if (WACOM_PAD_FIELD(field)) {
2146 wacom_wac_pad_battery_event(hdev, field, usage, value);
2147 if (wacom->wacom_wac.pad_input)
2148 wacom_wac_pad_event(hdev, field, usage, value);
2149 } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2150 wacom_wac_pen_event(hdev, field, usage, value);
2151 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2152 wacom_wac_finger_event(hdev, field, usage, value);
2153 }
2154
2155 static void wacom_report_events(struct hid_device *hdev, struct hid_report *report)
2156 {
2157 int r;
2158
2159 for (r = 0; r < report->maxfield; r++) {
2160 struct hid_field *field;
2161 unsigned count, n;
2162
2163 field = report->field[r];
2164 count = field->report_count;
2165
2166 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2167 continue;
2168
2169 for (n = 0; n < count; n++)
2170 wacom_wac_event(hdev, field, &field->usage[n], field->value[n]);
2171 }
2172 }
2173
2174 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2175 {
2176 struct wacom *wacom = hid_get_drvdata(hdev);
2177 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2178 struct hid_field *field = report->field[0];
2179
2180 if (wacom_wac->features.type != HID_GENERIC)
2181 return;
2182
2183 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2184 wacom_wac_pad_pre_report(hdev, report);
2185 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2186 wacom_wac_pen_pre_report(hdev, report);
2187 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2188 wacom_wac_finger_pre_report(hdev, report);
2189
2190 wacom_report_events(hdev, report);
2191
2192 /*
2193 * Non-input reports may be sent prior to the device being
2194 * completely initialized. Since only their events need
2195 * to be processed, exit after 'wacom_report_events' has
2196 * been called to prevent potential crashes in the report-
2197 * processing functions.
2198 */
2199 if (report->type != HID_INPUT_REPORT)
2200 return;
2201
2202 if (WACOM_PAD_FIELD(field)) {
2203 wacom_wac_pad_battery_report(hdev, report);
2204 if (wacom->wacom_wac.pad_input)
2205 wacom_wac_pad_report(hdev, report);
2206 } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2207 wacom_wac_pen_report(hdev, report);
2208 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2209 wacom_wac_finger_report(hdev, report);
2210 }
2211
2212 static int wacom_bpt_touch(struct wacom_wac *wacom)
2213 {
2214 struct wacom_features *features = &wacom->features;
2215 struct input_dev *input = wacom->touch_input;
2216 struct input_dev *pad_input = wacom->pad_input;
2217 unsigned char *data = wacom->data;
2218 int i;
2219
2220 if (data[0] != 0x02)
2221 return 0;
2222
2223 for (i = 0; i < 2; i++) {
2224 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
2225 bool touch = report_touch_events(wacom)
2226 && (data[offset + 3] & 0x80);
2227
2228 input_mt_slot(input, i);
2229 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2230 if (touch) {
2231 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2232 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
2233 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2234 x <<= 5;
2235 y <<= 5;
2236 }
2237 input_report_abs(input, ABS_MT_POSITION_X, x);
2238 input_report_abs(input, ABS_MT_POSITION_Y, y);
2239 }
2240 }
2241
2242 input_mt_sync_frame(input);
2243
2244 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2245 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2246 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2247 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
2248 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2249
2250 return 1;
2251 }
2252
2253 static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
2254 {
2255 struct wacom_features *features = &wacom->features;
2256 struct input_dev *input = wacom->touch_input;
2257 bool touch = data[1] & 0x80;
2258 int slot = input_mt_get_slot_by_key(input, data[0]);
2259
2260 if (slot < 0)
2261 return;
2262
2263 touch = touch && report_touch_events(wacom);
2264
2265 input_mt_slot(input, slot);
2266 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2267
2268 if (touch) {
2269 int x = (data[2] << 4) | (data[4] >> 4);
2270 int y = (data[3] << 4) | (data[4] & 0x0f);
2271 int width, height;
2272
2273 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
2274 width = data[5] * 100;
2275 height = data[6] * 100;
2276 } else {
2277 /*
2278 * "a" is a scaled-down area which we assume is
2279 * roughly circular and which can be described as:
2280 * a=(pi*r^2)/C.
2281 */
2282 int a = data[5];
2283 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2284 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2285 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
2286 height = width * y_res / x_res;
2287 }
2288
2289 input_report_abs(input, ABS_MT_POSITION_X, x);
2290 input_report_abs(input, ABS_MT_POSITION_Y, y);
2291 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2292 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
2293 }
2294 }
2295
2296 static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2297 {
2298 struct input_dev *input = wacom->pad_input;
2299 struct wacom_features *features = &wacom->features;
2300
2301 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
2302 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
2303 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
2304 } else {
2305 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
2306 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
2307 }
2308 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
2309 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
2310 }
2311
2312 static int wacom_bpt3_touch(struct wacom_wac *wacom)
2313 {
2314 unsigned char *data = wacom->data;
2315 int count = data[1] & 0x07;
2316 int touch_changed = 0, i;
2317
2318 if (data[0] != 0x02)
2319 return 0;
2320
2321 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
2322 for (i = 0; i < count; i++) {
2323 int offset = (8 * i) + 2;
2324 int msg_id = data[offset];
2325
2326 if (msg_id >= 2 && msg_id <= 17) {
2327 wacom_bpt3_touch_msg(wacom, data + offset);
2328 touch_changed++;
2329 } else if (msg_id == 128)
2330 wacom_bpt3_button_msg(wacom, data + offset);
2331
2332 }
2333
2334 /* only update touch if we actually have a touchpad and touch data changed */
2335 if (wacom->touch_input && touch_changed) {
2336 input_mt_sync_frame(wacom->touch_input);
2337 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2338 }
2339
2340 return 1;
2341 }
2342
2343 static int wacom_bpt_pen(struct wacom_wac *wacom)
2344 {
2345 struct wacom_features *features = &wacom->features;
2346 struct input_dev *input = wacom->pen_input;
2347 unsigned char *data = wacom->data;
2348 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
2349
2350 if (data[0] != WACOM_REPORT_PENABLED)
2351 return 0;
2352
2353 prox = (data[1] & 0x20) == 0x20;
2354
2355 /*
2356 * All reports shared between PEN and RUBBER tool must be
2357 * forced to a known starting value (zero) when transitioning to
2358 * out-of-prox.
2359 *
2360 * If not reset then, to userspace, it will look like lost events
2361 * if new tool comes in-prox with same values as previous tool sent.
2362 *
2363 * Hardware does report zero in most out-of-prox cases but not all.
2364 */
2365 if (!wacom->shared->stylus_in_proximity) {
2366 if (data[1] & 0x08) {
2367 wacom->tool[0] = BTN_TOOL_RUBBER;
2368 wacom->id[0] = ERASER_DEVICE_ID;
2369 } else {
2370 wacom->tool[0] = BTN_TOOL_PEN;
2371 wacom->id[0] = STYLUS_DEVICE_ID;
2372 }
2373 }
2374
2375 wacom->shared->stylus_in_proximity = prox;
2376 if (delay_pen_events(wacom))
2377 return 0;
2378
2379 if (prox) {
2380 x = le16_to_cpup((__le16 *)&data[2]);
2381 y = le16_to_cpup((__le16 *)&data[4]);
2382 p = le16_to_cpup((__le16 *)&data[6]);
2383 /*
2384 * Convert distance from out prox to distance from tablet.
2385 * distance will be greater than distance_max once
2386 * touching and applying pressure; do not report negative
2387 * distance.
2388 */
2389 if (data[8] <= features->distance_max)
2390 d = features->distance_max - data[8];
2391
2392 pen = data[1] & 0x01;
2393 btn1 = data[1] & 0x02;
2394 btn2 = data[1] & 0x04;
2395 } else {
2396 wacom->id[0] = 0;
2397 }
2398
2399 input_report_key(input, BTN_TOUCH, pen);
2400 input_report_key(input, BTN_STYLUS, btn1);
2401 input_report_key(input, BTN_STYLUS2, btn2);
2402
2403 input_report_abs(input, ABS_X, x);
2404 input_report_abs(input, ABS_Y, y);
2405 input_report_abs(input, ABS_PRESSURE, p);
2406 input_report_abs(input, ABS_DISTANCE, d);
2407
2408 input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
2409 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
2410
2411 return 1;
2412 }
2413
2414 static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
2415 {
2416 struct wacom_features *features = &wacom->features;
2417
2418 if ((features->type == INTUOSHT2) &&
2419 (features->device_type & WACOM_DEVICETYPE_PEN))
2420 return wacom_intuos_irq(wacom);
2421 else if (len == WACOM_PKGLEN_BBTOUCH)
2422 return wacom_bpt_touch(wacom);
2423 else if (len == WACOM_PKGLEN_BBTOUCH3)
2424 return wacom_bpt3_touch(wacom);
2425 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
2426 return wacom_bpt_pen(wacom);
2427
2428 return 0;
2429 }
2430
2431 static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
2432 unsigned char *data)
2433 {
2434 unsigned char prefix;
2435
2436 /*
2437 * We need to reroute the event from the debug interface to the
2438 * pen interface.
2439 * We need to add the report ID to the actual pen report, so we
2440 * temporary overwrite the first byte to prevent having to kzalloc/kfree
2441 * and memcpy the report.
2442 */
2443 prefix = data[0];
2444 data[0] = WACOM_REPORT_BPAD_PEN;
2445
2446 /*
2447 * actually reroute the event.
2448 * No need to check if wacom->shared->pen is valid, hid_input_report()
2449 * will check for us.
2450 */
2451 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
2452 WACOM_PKGLEN_PENABLED, 1);
2453
2454 data[0] = prefix;
2455 }
2456
2457 static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
2458 unsigned char *data)
2459 {
2460 struct input_dev *input = wacom->touch_input;
2461 unsigned char *finger_data, prefix;
2462 unsigned id;
2463 int x, y;
2464 bool valid;
2465
2466 prefix = data[0];
2467
2468 for (id = 0; id < wacom->features.touch_max; id++) {
2469 valid = !!(prefix & BIT(id)) &&
2470 report_touch_events(wacom);
2471
2472 input_mt_slot(input, id);
2473 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
2474
2475 if (!valid)
2476 continue;
2477
2478 finger_data = data + 1 + id * 3;
2479 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
2480 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
2481
2482 input_report_abs(input, ABS_MT_POSITION_X, x);
2483 input_report_abs(input, ABS_MT_POSITION_Y, y);
2484 }
2485
2486 input_mt_sync_frame(input);
2487
2488 input_report_key(input, BTN_LEFT, prefix & 0x40);
2489 input_report_key(input, BTN_RIGHT, prefix & 0x80);
2490
2491 /* keep touch state for pen event */
2492 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
2493
2494 return 1;
2495 }
2496
2497 static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
2498 {
2499 unsigned char *data = wacom->data;
2500
2501 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
2502 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
2503 (data[0] != WACOM_REPORT_BPAD_TOUCH))
2504 return 0;
2505
2506 if (data[1] & 0x01)
2507 wacom_bamboo_pad_pen_event(wacom, &data[1]);
2508
2509 if (data[1] & 0x02)
2510 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
2511
2512 return 0;
2513 }
2514
2515 static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
2516 {
2517 unsigned char *data = wacom->data;
2518 int connected;
2519
2520 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
2521 return 0;
2522
2523 connected = data[1] & 0x01;
2524 if (connected) {
2525 int pid, battery, charging;
2526
2527 if ((wacom->shared->type == INTUOSHT ||
2528 wacom->shared->type == INTUOSHT2) &&
2529 wacom->shared->touch_input &&
2530 wacom->shared->touch_max) {
2531 input_report_switch(wacom->shared->touch_input,
2532 SW_MUTE_DEVICE, data[5] & 0x40);
2533 input_sync(wacom->shared->touch_input);
2534 }
2535
2536 pid = get_unaligned_be16(&data[6]);
2537 battery = (data[5] & 0x3f) * 100 / 31;
2538 charging = !!(data[5] & 0x80);
2539 if (wacom->pid != pid) {
2540 wacom->pid = pid;
2541 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
2542 }
2543
2544 wacom_notify_battery(wacom, battery, charging, 1, 0);
2545
2546 } else if (wacom->pid != 0) {
2547 /* disconnected while previously connected */
2548 wacom->pid = 0;
2549 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
2550 wacom_notify_battery(wacom, 0, 0, 0, 0);
2551 }
2552
2553 return 0;
2554 }
2555
2556 static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
2557 {
2558 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
2559 struct wacom_features *features = &wacom_wac->features;
2560 unsigned char *data = wacom_wac->data;
2561
2562 if (data[0] != WACOM_REPORT_USB)
2563 return 0;
2564
2565 if ((features->type == INTUOSHT ||
2566 features->type == INTUOSHT2) &&
2567 wacom_wac->shared->touch_input &&
2568 features->touch_max) {
2569 input_report_switch(wacom_wac->shared->touch_input,
2570 SW_MUTE_DEVICE, data[8] & 0x40);
2571 input_sync(wacom_wac->shared->touch_input);
2572 }
2573
2574 if (data[9] & 0x02) { /* wireless module is attached */
2575 int battery = (data[8] & 0x3f) * 100 / 31;
2576 bool charging = !!(data[8] & 0x80);
2577
2578 wacom_notify_battery(wacom_wac, battery, charging,
2579 battery || charging, 1);
2580
2581 if (!wacom->battery.battery &&
2582 !(features->quirks & WACOM_QUIRK_BATTERY)) {
2583 features->quirks |= WACOM_QUIRK_BATTERY;
2584 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
2585 }
2586 }
2587 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
2588 wacom->battery.battery) {
2589 features->quirks &= ~WACOM_QUIRK_BATTERY;
2590 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
2591 wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
2592 }
2593 return 0;
2594 }
2595
2596 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
2597 {
2598 bool sync;
2599
2600 switch (wacom_wac->features.type) {
2601 case PENPARTNER:
2602 sync = wacom_penpartner_irq(wacom_wac);
2603 break;
2604
2605 case PL:
2606 sync = wacom_pl_irq(wacom_wac);
2607 break;
2608
2609 case WACOM_G4:
2610 case GRAPHIRE:
2611 case GRAPHIRE_BT:
2612 case WACOM_MO:
2613 sync = wacom_graphire_irq(wacom_wac);
2614 break;
2615
2616 case PTU:
2617 sync = wacom_ptu_irq(wacom_wac);
2618 break;
2619
2620 case DTU:
2621 sync = wacom_dtu_irq(wacom_wac);
2622 break;
2623
2624 case DTUS:
2625 case DTUSX:
2626 sync = wacom_dtus_irq(wacom_wac);
2627 break;
2628
2629 case INTUOS:
2630 case INTUOS3S:
2631 case INTUOS3:
2632 case INTUOS3L:
2633 case INTUOS4S:
2634 case INTUOS4:
2635 case INTUOS4L:
2636 case CINTIQ:
2637 case WACOM_BEE:
2638 case WACOM_13HD:
2639 case WACOM_21UX2:
2640 case WACOM_22HD:
2641 case WACOM_24HD:
2642 case WACOM_27QHD:
2643 case DTK:
2644 case CINTIQ_HYBRID:
2645 case CINTIQ_COMPANION_2:
2646 sync = wacom_intuos_irq(wacom_wac);
2647 break;
2648
2649 case INTUOS4WL:
2650 sync = wacom_intuos_bt_irq(wacom_wac, len);
2651 break;
2652
2653 case WACOM_24HDT:
2654 case WACOM_27QHDT:
2655 sync = wacom_24hdt_irq(wacom_wac);
2656 break;
2657
2658 case INTUOS5S:
2659 case INTUOS5:
2660 case INTUOS5L:
2661 case INTUOSPS:
2662 case INTUOSPM:
2663 case INTUOSPL:
2664 if (len == WACOM_PKGLEN_BBTOUCH3)
2665 sync = wacom_bpt3_touch(wacom_wac);
2666 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
2667 sync = wacom_status_irq(wacom_wac, len);
2668 else
2669 sync = wacom_intuos_irq(wacom_wac);
2670 break;
2671
2672 case TABLETPC:
2673 case TABLETPCE:
2674 case TABLETPC2FG:
2675 case MTSCREEN:
2676 case MTTPC:
2677 case MTTPC_B:
2678 sync = wacom_tpc_irq(wacom_wac, len);
2679 break;
2680
2681 case BAMBOO_PT:
2682 case BAMBOO_PEN:
2683 case BAMBOO_TOUCH:
2684 case INTUOSHT:
2685 case INTUOSHT2:
2686 if (wacom_wac->data[0] == WACOM_REPORT_USB)
2687 sync = wacom_status_irq(wacom_wac, len);
2688 else
2689 sync = wacom_bpt_irq(wacom_wac, len);
2690 break;
2691
2692 case BAMBOO_PAD:
2693 sync = wacom_bamboo_pad_irq(wacom_wac, len);
2694 break;
2695
2696 case WIRELESS:
2697 sync = wacom_wireless_irq(wacom_wac, len);
2698 break;
2699
2700 case REMOTE:
2701 sync = false;
2702 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
2703 wacom_remote_status_irq(wacom_wac, len);
2704 else
2705 sync = wacom_remote_irq(wacom_wac, len);
2706 break;
2707
2708 default:
2709 sync = false;
2710 break;
2711 }
2712
2713 if (sync) {
2714 if (wacom_wac->pen_input)
2715 input_sync(wacom_wac->pen_input);
2716 if (wacom_wac->touch_input)
2717 input_sync(wacom_wac->touch_input);
2718 if (wacom_wac->pad_input)
2719 input_sync(wacom_wac->pad_input);
2720 }
2721 }
2722
2723 static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
2724 {
2725 struct input_dev *input_dev = wacom_wac->pen_input;
2726
2727 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
2728
2729 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2730 __set_bit(BTN_STYLUS, input_dev->keybit);
2731 __set_bit(BTN_STYLUS2, input_dev->keybit);
2732
2733 input_set_abs_params(input_dev, ABS_DISTANCE,
2734 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
2735 }
2736
2737 static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
2738 {
2739 struct input_dev *input_dev = wacom_wac->pen_input;
2740 struct wacom_features *features = &wacom_wac->features;
2741
2742 wacom_setup_basic_pro_pen(wacom_wac);
2743
2744 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2745 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
2746 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
2747 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
2748
2749 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
2750 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
2751 input_abs_set_res(input_dev, ABS_TILT_X, 57);
2752 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
2753 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
2754 }
2755
2756 static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
2757 {
2758 struct input_dev *input_dev = wacom_wac->pen_input;
2759
2760 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2761
2762 wacom_setup_cintiq(wacom_wac);
2763
2764 __set_bit(BTN_LEFT, input_dev->keybit);
2765 __set_bit(BTN_RIGHT, input_dev->keybit);
2766 __set_bit(BTN_MIDDLE, input_dev->keybit);
2767 __set_bit(BTN_SIDE, input_dev->keybit);
2768 __set_bit(BTN_EXTRA, input_dev->keybit);
2769 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2770 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
2771
2772 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
2773 input_abs_set_res(input_dev, ABS_RZ, 287);
2774 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
2775 }
2776
2777 void wacom_setup_device_quirks(struct wacom *wacom)
2778 {
2779 struct wacom_features *features = &wacom->wacom_wac.features;
2780
2781 /* The pen and pad share the same interface on most devices */
2782 if (features->numbered_buttons > 0)
2783 features->device_type |= WACOM_DEVICETYPE_PAD;
2784 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
2785 features->type == DTUS ||
2786 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
2787 if (features->device_type & WACOM_DEVICETYPE_PEN)
2788 features->device_type |= WACOM_DEVICETYPE_PAD;
2789 }
2790
2791 /* touch device found but size is not defined. use default */
2792 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
2793 features->x_max = 1023;
2794 features->y_max = 1023;
2795 }
2796
2797 /*
2798 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
2799 * touch interface in its HID descriptor. If this is the touch
2800 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
2801 * tablet values.
2802 */
2803 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
2804 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
2805 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
2806 if (features->touch_max)
2807 features->device_type |= WACOM_DEVICETYPE_TOUCH;
2808 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
2809 features->device_type |= WACOM_DEVICETYPE_PAD;
2810
2811 features->x_max = 4096;
2812 features->y_max = 4096;
2813 }
2814 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2815 features->device_type |= WACOM_DEVICETYPE_PAD;
2816 }
2817 }
2818
2819 /*
2820 * Hack for the Bamboo One:
2821 * the device presents a PAD/Touch interface as most Bamboos and even
2822 * sends ghosts PAD data on it. However, later, we must disable this
2823 * ghost interface, and we can not detect it unless we set it here
2824 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
2825 */
2826 if (features->type == BAMBOO_PEN &&
2827 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
2828 features->device_type |= WACOM_DEVICETYPE_PAD;
2829
2830 /*
2831 * Raw Wacom-mode pen and touch events both come from interface
2832 * 0, whose HID descriptor has an application usage of 0xFF0D
2833 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
2834 * out through the HID_GENERIC device created for interface 1,
2835 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
2836 */
2837 if (features->type == BAMBOO_PAD)
2838 features->device_type = WACOM_DEVICETYPE_TOUCH;
2839
2840 if (features->type == REMOTE)
2841 features->device_type = WACOM_DEVICETYPE_PAD;
2842
2843 switch (features->type) {
2844 case PL:
2845 case DTU:
2846 case DTUS:
2847 case DTUSX:
2848 case WACOM_21UX2:
2849 case WACOM_22HD:
2850 case DTK:
2851 case WACOM_24HD:
2852 case WACOM_27QHD:
2853 case CINTIQ_HYBRID:
2854 case CINTIQ_COMPANION_2:
2855 case CINTIQ:
2856 case WACOM_BEE:
2857 case WACOM_13HD:
2858 case WACOM_24HDT:
2859 case WACOM_27QHDT:
2860 case TABLETPC:
2861 case TABLETPCE:
2862 case TABLETPC2FG:
2863 case MTSCREEN:
2864 case MTTPC:
2865 case MTTPC_B:
2866 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2867 break;
2868 }
2869
2870 if (wacom->hdev->bus == BUS_BLUETOOTH)
2871 features->quirks |= WACOM_QUIRK_BATTERY;
2872
2873 /* quirk for bamboo touch with 2 low res touches */
2874 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
2875 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2876 features->x_max <<= 5;
2877 features->y_max <<= 5;
2878 features->x_fuzz <<= 5;
2879 features->y_fuzz <<= 5;
2880 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
2881 }
2882
2883 if (features->type == WIRELESS) {
2884 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
2885 features->quirks |= WACOM_QUIRK_BATTERY;
2886 }
2887 }
2888
2889 if (features->type == REMOTE)
2890 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
2891 }
2892
2893 int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
2894 struct wacom_wac *wacom_wac)
2895 {
2896 struct wacom_features *features = &wacom_wac->features;
2897
2898 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
2899
2900 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
2901 return -ENODEV;
2902
2903 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
2904 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
2905 else
2906 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2907
2908 if (features->type == HID_GENERIC)
2909 /* setup has already been done */
2910 return 0;
2911
2912 __set_bit(BTN_TOUCH, input_dev->keybit);
2913 __set_bit(ABS_MISC, input_dev->absbit);
2914
2915 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
2916 features->x_max - features->offset_right,
2917 features->x_fuzz, 0);
2918 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
2919 features->y_max - features->offset_bottom,
2920 features->y_fuzz, 0);
2921 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
2922 features->pressure_max, features->pressure_fuzz, 0);
2923
2924 /* penabled devices have fixed resolution for each model */
2925 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
2926 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
2927
2928 switch (features->type) {
2929 case GRAPHIRE_BT:
2930 __clear_bit(ABS_MISC, input_dev->absbit);
2931
2932 case WACOM_MO:
2933 case WACOM_G4:
2934 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2935 features->distance_max,
2936 features->distance_fuzz, 0);
2937 /* fall through */
2938
2939 case GRAPHIRE:
2940 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2941
2942 __set_bit(BTN_LEFT, input_dev->keybit);
2943 __set_bit(BTN_RIGHT, input_dev->keybit);
2944 __set_bit(BTN_MIDDLE, input_dev->keybit);
2945
2946 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2947 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2948 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2949 __set_bit(BTN_STYLUS, input_dev->keybit);
2950 __set_bit(BTN_STYLUS2, input_dev->keybit);
2951 break;
2952
2953 case WACOM_27QHD:
2954 case WACOM_24HD:
2955 case DTK:
2956 case WACOM_22HD:
2957 case WACOM_21UX2:
2958 case WACOM_BEE:
2959 case CINTIQ:
2960 case WACOM_13HD:
2961 case CINTIQ_HYBRID:
2962 case CINTIQ_COMPANION_2:
2963 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2964 input_abs_set_res(input_dev, ABS_Z, 287);
2965 wacom_setup_cintiq(wacom_wac);
2966 break;
2967
2968 case INTUOS3:
2969 case INTUOS3L:
2970 case INTUOS3S:
2971 case INTUOS4:
2972 case INTUOS4WL:
2973 case INTUOS4L:
2974 case INTUOS4S:
2975 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2976 input_abs_set_res(input_dev, ABS_Z, 287);
2977 /* fall through */
2978
2979 case INTUOS:
2980 wacom_setup_intuos(wacom_wac);
2981 break;
2982
2983 case INTUOS5:
2984 case INTUOS5L:
2985 case INTUOSPM:
2986 case INTUOSPL:
2987 case INTUOS5S:
2988 case INTUOSPS:
2989 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2990 features->distance_max,
2991 features->distance_fuzz, 0);
2992
2993 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2994 input_abs_set_res(input_dev, ABS_Z, 287);
2995
2996 wacom_setup_intuos(wacom_wac);
2997 break;
2998
2999 case WACOM_24HDT:
3000 case WACOM_27QHDT:
3001 case MTSCREEN:
3002 case MTTPC:
3003 case MTTPC_B:
3004 case TABLETPC2FG:
3005 case TABLETPC:
3006 case TABLETPCE:
3007 __clear_bit(ABS_MISC, input_dev->absbit);
3008 /* fall through */
3009
3010 case DTUS:
3011 case DTUSX:
3012 case PL:
3013 case DTU:
3014 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3015 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3016 __set_bit(BTN_STYLUS, input_dev->keybit);
3017 __set_bit(BTN_STYLUS2, input_dev->keybit);
3018 break;
3019
3020 case PTU:
3021 __set_bit(BTN_STYLUS2, input_dev->keybit);
3022 /* fall through */
3023
3024 case PENPARTNER:
3025 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3026 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3027 __set_bit(BTN_STYLUS, input_dev->keybit);
3028 break;
3029
3030 case INTUOSHT:
3031 case BAMBOO_PT:
3032 case BAMBOO_PEN:
3033 case INTUOSHT2:
3034 if (features->type == INTUOSHT2) {
3035 wacom_setup_basic_pro_pen(wacom_wac);
3036 } else {
3037 __clear_bit(ABS_MISC, input_dev->absbit);
3038 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3039 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3040 __set_bit(BTN_STYLUS, input_dev->keybit);
3041 __set_bit(BTN_STYLUS2, input_dev->keybit);
3042 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3043 features->distance_max,
3044 features->distance_fuzz, 0);
3045 }
3046 break;
3047 case BAMBOO_PAD:
3048 __clear_bit(ABS_MISC, input_dev->absbit);
3049 break;
3050 }
3051 return 0;
3052 }
3053
3054 int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3055 struct wacom_wac *wacom_wac)
3056 {
3057 struct wacom_features *features = &wacom_wac->features;
3058
3059 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3060
3061 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3062 return -ENODEV;
3063
3064 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3065 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3066 else
3067 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3068
3069 if (features->type == HID_GENERIC)
3070 /* setup has already been done */
3071 return 0;
3072
3073 __set_bit(BTN_TOUCH, input_dev->keybit);
3074
3075 if (features->touch_max == 1) {
3076 input_set_abs_params(input_dev, ABS_X, 0,
3077 features->x_max, features->x_fuzz, 0);
3078 input_set_abs_params(input_dev, ABS_Y, 0,
3079 features->y_max, features->y_fuzz, 0);
3080 input_abs_set_res(input_dev, ABS_X,
3081 features->x_resolution);
3082 input_abs_set_res(input_dev, ABS_Y,
3083 features->y_resolution);
3084 }
3085 else if (features->touch_max > 1) {
3086 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3087 features->x_max, features->x_fuzz, 0);
3088 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3089 features->y_max, features->y_fuzz, 0);
3090 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3091 features->x_resolution);
3092 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3093 features->y_resolution);
3094 }
3095
3096 switch (features->type) {
3097 case INTUOS5:
3098 case INTUOS5L:
3099 case INTUOSPM:
3100 case INTUOSPL:
3101 case INTUOS5S:
3102 case INTUOSPS:
3103 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3104 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3105 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3106 break;
3107
3108 case WACOM_24HDT:
3109 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3110 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3111 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3112 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
3113 /* fall through */
3114
3115 case WACOM_27QHDT:
3116 case MTSCREEN:
3117 case MTTPC:
3118 case MTTPC_B:
3119 case TABLETPC2FG:
3120 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
3121 /*fall through */
3122
3123 case TABLETPC:
3124 case TABLETPCE:
3125 break;
3126
3127 case INTUOSHT:
3128 case INTUOSHT2:
3129 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3130 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3131 /* fall through */
3132
3133 case BAMBOO_PT:
3134 case BAMBOO_TOUCH:
3135 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3136 input_set_abs_params(input_dev,
3137 ABS_MT_TOUCH_MAJOR,
3138 0, features->x_max, 0, 0);
3139 input_set_abs_params(input_dev,
3140 ABS_MT_TOUCH_MINOR,
3141 0, features->y_max, 0, 0);
3142 }
3143 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3144 break;
3145
3146 case BAMBOO_PAD:
3147 input_mt_init_slots(input_dev, features->touch_max,
3148 INPUT_MT_POINTER);
3149 __set_bit(BTN_LEFT, input_dev->keybit);
3150 __set_bit(BTN_RIGHT, input_dev->keybit);
3151 break;
3152 }
3153 return 0;
3154 }
3155
3156 static int wacom_numbered_button_to_key(int n)
3157 {
3158 if (n < 10)
3159 return BTN_0 + n;
3160 else if (n < 16)
3161 return BTN_A + (n-10);
3162 else if (n < 18)
3163 return BTN_BASE + (n-16);
3164 else
3165 return 0;
3166 }
3167
3168 static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
3169 int button_count)
3170 {
3171 int i;
3172
3173 for (i = 0; i < button_count; i++) {
3174 int key = wacom_numbered_button_to_key(i);
3175
3176 if (key)
3177 __set_bit(key, input_dev->keybit);
3178 }
3179 }
3180
3181 static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3182 {
3183 struct wacom_led *led;
3184 int i;
3185 bool updated = false;
3186
3187 /*
3188 * 24HD has LED group 1 to the left and LED group 0 to the right.
3189 * So group 0 matches the second half of the buttons and thus the mask
3190 * needs to be shifted.
3191 */
3192 if (group == 0)
3193 mask >>= 8;
3194
3195 for (i = 0; i < 3; i++) {
3196 led = wacom_led_find(wacom, group, i);
3197 if (!led) {
3198 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3199 i, group);
3200 continue;
3201 }
3202 if (!updated && mask & BIT(i)) {
3203 led->held = true;
3204 led_trigger_event(&led->trigger, LED_FULL);
3205 } else {
3206 led->held = false;
3207 }
3208 }
3209 }
3210
3211 static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
3212 int mask, int group)
3213 {
3214 int button_per_group;
3215
3216 /*
3217 * 21UX2 has LED group 1 to the left and LED group 0
3218 * to the right. We need to reverse the group to match this
3219 * historical behavior.
3220 */
3221 if (wacom->wacom_wac.features.type == WACOM_21UX2)
3222 group = 1 - group;
3223
3224 button_per_group = button_count/wacom->led.count;
3225
3226 return mask & (1 << (group * button_per_group));
3227 }
3228
3229 static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
3230 int group)
3231 {
3232 struct wacom_led *led, *next_led;
3233 int cur;
3234 bool pressed;
3235
3236 if (wacom->wacom_wac.features.type == WACOM_24HD)
3237 return wacom_24hd_update_leds(wacom, mask, group);
3238
3239 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
3240 cur = wacom->led.groups[group].select;
3241
3242 led = wacom_led_find(wacom, group, cur);
3243 if (!led) {
3244 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
3245 cur, group);
3246 return;
3247 }
3248
3249 if (!pressed) {
3250 led->held = false;
3251 return;
3252 }
3253
3254 if (led->held && pressed)
3255 return;
3256
3257 next_led = wacom_led_next(wacom, led);
3258 if (!next_led) {
3259 hid_err(wacom->hdev, "can't find next LED in group %d\n",
3260 group);
3261 return;
3262 }
3263 if (next_led == led)
3264 return;
3265
3266 next_led->held = true;
3267 led_trigger_event(&next_led->trigger,
3268 wacom_leds_brightness_get(next_led));
3269 }
3270
3271 static void wacom_report_numbered_buttons(struct input_dev *input_dev,
3272 int button_count, int mask)
3273 {
3274 struct wacom *wacom = input_get_drvdata(input_dev);
3275 int i;
3276
3277 for (i = 0; i < wacom->led.count; i++)
3278 wacom_update_led(wacom, button_count, mask, i);
3279
3280 for (i = 0; i < button_count; i++) {
3281 int key = wacom_numbered_button_to_key(i);
3282
3283 if (key)
3284 input_report_key(input_dev, key, mask & (1 << i));
3285 }
3286 }
3287
3288 int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3289 struct wacom_wac *wacom_wac)
3290 {
3291 struct wacom_features *features = &wacom_wac->features;
3292
3293 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
3294 return -ENODEV;
3295
3296 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
3297 return -ENODEV;
3298
3299 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3300
3301 /* kept for making legacy xf86-input-wacom working with the wheels */
3302 __set_bit(ABS_MISC, input_dev->absbit);
3303
3304 /* kept for making legacy xf86-input-wacom accepting the pad */
3305 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
3306 input_dev->absinfo[ABS_X].maximum)))
3307 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
3308 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
3309 input_dev->absinfo[ABS_Y].maximum)))
3310 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
3311
3312 /* kept for making udev and libwacom accepting the pad */
3313 __set_bit(BTN_STYLUS, input_dev->keybit);
3314
3315 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
3316
3317 switch (features->type) {
3318
3319 case CINTIQ_HYBRID:
3320 case CINTIQ_COMPANION_2:
3321 case DTK:
3322 case DTUS:
3323 case GRAPHIRE_BT:
3324 break;
3325
3326 case WACOM_MO:
3327 __set_bit(BTN_BACK, input_dev->keybit);
3328 __set_bit(BTN_LEFT, input_dev->keybit);
3329 __set_bit(BTN_FORWARD, input_dev->keybit);
3330 __set_bit(BTN_RIGHT, input_dev->keybit);
3331 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3332 break;
3333
3334 case WACOM_G4:
3335 __set_bit(BTN_BACK, input_dev->keybit);
3336 __set_bit(BTN_FORWARD, input_dev->keybit);
3337 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3338 break;
3339
3340 case WACOM_24HD:
3341 __set_bit(KEY_PROG1, input_dev->keybit);
3342 __set_bit(KEY_PROG2, input_dev->keybit);
3343 __set_bit(KEY_PROG3, input_dev->keybit);
3344
3345 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3346 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
3347 break;
3348
3349 case WACOM_27QHD:
3350 __set_bit(KEY_PROG1, input_dev->keybit);
3351 __set_bit(KEY_PROG2, input_dev->keybit);
3352 __set_bit(KEY_PROG3, input_dev->keybit);
3353 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
3354 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
3355 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
3356 input_abs_set_res(input_dev, ABS_Y, 1024);
3357 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
3358 input_abs_set_res(input_dev, ABS_Z, 1024);
3359 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
3360 break;
3361
3362 case WACOM_22HD:
3363 __set_bit(KEY_PROG1, input_dev->keybit);
3364 __set_bit(KEY_PROG2, input_dev->keybit);
3365 __set_bit(KEY_PROG3, input_dev->keybit);
3366 /* fall through */
3367
3368 case WACOM_21UX2:
3369 case WACOM_BEE:
3370 case CINTIQ:
3371 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3372 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3373 break;
3374
3375 case WACOM_13HD:
3376 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3377 break;
3378
3379 case INTUOS3:
3380 case INTUOS3L:
3381 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3382 /* fall through */
3383
3384 case INTUOS3S:
3385 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3386 break;
3387
3388 case INTUOS5:
3389 case INTUOS5L:
3390 case INTUOSPM:
3391 case INTUOSPL:
3392 case INTUOS5S:
3393 case INTUOSPS:
3394 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3395 break;
3396
3397 case INTUOS4WL:
3398 /*
3399 * For Bluetooth devices, the udev rule does not work correctly
3400 * for pads unless we add a stylus capability, which forces
3401 * ID_INPUT_TABLET to be set.
3402 */
3403 __set_bit(BTN_STYLUS, input_dev->keybit);
3404 /* fall through */
3405
3406 case INTUOS4:
3407 case INTUOS4L:
3408 case INTUOS4S:
3409 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3410 break;
3411
3412 case INTUOSHT:
3413 case BAMBOO_PT:
3414 case BAMBOO_TOUCH:
3415 case INTUOSHT2:
3416 __clear_bit(ABS_MISC, input_dev->absbit);
3417
3418 __set_bit(BTN_LEFT, input_dev->keybit);
3419 __set_bit(BTN_FORWARD, input_dev->keybit);
3420 __set_bit(BTN_BACK, input_dev->keybit);
3421 __set_bit(BTN_RIGHT, input_dev->keybit);
3422
3423 break;
3424
3425 case REMOTE:
3426 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
3427 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3428 break;
3429
3430 case HID_GENERIC:
3431 break;
3432
3433 default:
3434 /* no pad supported */
3435 return -ENODEV;
3436 }
3437 return 0;
3438 }
3439
3440 static const struct wacom_features wacom_features_0x00 =
3441 { "Wacom Penpartner", 5040, 3780, 255, 0,
3442 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
3443 static const struct wacom_features wacom_features_0x10 =
3444 { "Wacom Graphire", 10206, 7422, 511, 63,
3445 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3446 static const struct wacom_features wacom_features_0x81 =
3447 { "Wacom Graphire BT", 16704, 12064, 511, 32,
3448 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
3449 static const struct wacom_features wacom_features_0x11 =
3450 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
3451 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3452 static const struct wacom_features wacom_features_0x12 =
3453 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
3454 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3455 static const struct wacom_features wacom_features_0x13 =
3456 { "Wacom Graphire3", 10208, 7424, 511, 63,
3457 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3458 static const struct wacom_features wacom_features_0x14 =
3459 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
3460 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3461 static const struct wacom_features wacom_features_0x15 =
3462 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
3463 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3464 static const struct wacom_features wacom_features_0x16 =
3465 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
3466 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3467 static const struct wacom_features wacom_features_0x17 =
3468 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
3469 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3470 static const struct wacom_features wacom_features_0x18 =
3471 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
3472 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3473 static const struct wacom_features wacom_features_0x19 =
3474 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
3475 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3476 static const struct wacom_features wacom_features_0x60 =
3477 { "Wacom Volito", 5104, 3712, 511, 63,
3478 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3479 static const struct wacom_features wacom_features_0x61 =
3480 { "Wacom PenStation2", 3250, 2320, 255, 63,
3481 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3482 static const struct wacom_features wacom_features_0x62 =
3483 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
3484 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3485 static const struct wacom_features wacom_features_0x63 =
3486 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
3487 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3488 static const struct wacom_features wacom_features_0x64 =
3489 { "Wacom PenPartner2", 3250, 2320, 511, 63,
3490 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3491 static const struct wacom_features wacom_features_0x65 =
3492 { "Wacom Bamboo", 14760, 9225, 511, 63,
3493 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3494 static const struct wacom_features wacom_features_0x69 =
3495 { "Wacom Bamboo1", 5104, 3712, 511, 63,
3496 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
3497 static const struct wacom_features wacom_features_0x6A =
3498 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
3499 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3500 static const struct wacom_features wacom_features_0x6B =
3501 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
3502 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3503 static const struct wacom_features wacom_features_0x20 =
3504 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
3505 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3506 static const struct wacom_features wacom_features_0x21 =
3507 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
3508 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3509 static const struct wacom_features wacom_features_0x22 =
3510 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
3511 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3512 static const struct wacom_features wacom_features_0x23 =
3513 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
3514 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3515 static const struct wacom_features wacom_features_0x24 =
3516 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
3517 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3518 static const struct wacom_features wacom_features_0x30 =
3519 { "Wacom PL400", 5408, 4056, 255, 0,
3520 PL, WACOM_PL_RES, WACOM_PL_RES };
3521 static const struct wacom_features wacom_features_0x31 =
3522 { "Wacom PL500", 6144, 4608, 255, 0,
3523 PL, WACOM_PL_RES, WACOM_PL_RES };
3524 static const struct wacom_features wacom_features_0x32 =
3525 { "Wacom PL600", 6126, 4604, 255, 0,
3526 PL, WACOM_PL_RES, WACOM_PL_RES };
3527 static const struct wacom_features wacom_features_0x33 =
3528 { "Wacom PL600SX", 6260, 5016, 255, 0,
3529 PL, WACOM_PL_RES, WACOM_PL_RES };
3530 static const struct wacom_features wacom_features_0x34 =
3531 { "Wacom PL550", 6144, 4608, 511, 0,
3532 PL, WACOM_PL_RES, WACOM_PL_RES };
3533 static const struct wacom_features wacom_features_0x35 =
3534 { "Wacom PL800", 7220, 5780, 511, 0,
3535 PL, WACOM_PL_RES, WACOM_PL_RES };
3536 static const struct wacom_features wacom_features_0x37 =
3537 { "Wacom PL700", 6758, 5406, 511, 0,
3538 PL, WACOM_PL_RES, WACOM_PL_RES };
3539 static const struct wacom_features wacom_features_0x38 =
3540 { "Wacom PL510", 6282, 4762, 511, 0,
3541 PL, WACOM_PL_RES, WACOM_PL_RES };
3542 static const struct wacom_features wacom_features_0x39 =
3543 { "Wacom DTU710", 34080, 27660, 511, 0,
3544 PL, WACOM_PL_RES, WACOM_PL_RES };
3545 static const struct wacom_features wacom_features_0xC4 =
3546 { "Wacom DTF521", 6282, 4762, 511, 0,
3547 PL, WACOM_PL_RES, WACOM_PL_RES };
3548 static const struct wacom_features wacom_features_0xC0 =
3549 { "Wacom DTF720", 6858, 5506, 511, 0,
3550 PL, WACOM_PL_RES, WACOM_PL_RES };
3551 static const struct wacom_features wacom_features_0xC2 =
3552 { "Wacom DTF720a", 6858, 5506, 511, 0,
3553 PL, WACOM_PL_RES, WACOM_PL_RES };
3554 static const struct wacom_features wacom_features_0x03 =
3555 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
3556 PTU, WACOM_PL_RES, WACOM_PL_RES };
3557 static const struct wacom_features wacom_features_0x41 =
3558 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
3559 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3560 static const struct wacom_features wacom_features_0x42 =
3561 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3562 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3563 static const struct wacom_features wacom_features_0x43 =
3564 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
3565 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3566 static const struct wacom_features wacom_features_0x44 =
3567 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
3568 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3569 static const struct wacom_features wacom_features_0x45 =
3570 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
3571 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3572 static const struct wacom_features wacom_features_0xB0 =
3573 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
3574 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
3575 static const struct wacom_features wacom_features_0xB1 =
3576 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
3577 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3578 static const struct wacom_features wacom_features_0xB2 =
3579 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
3580 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3581 static const struct wacom_features wacom_features_0xB3 =
3582 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
3583 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3584 static const struct wacom_features wacom_features_0xB4 =
3585 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
3586 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3587 static const struct wacom_features wacom_features_0xB5 =
3588 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
3589 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3590 static const struct wacom_features wacom_features_0xB7 =
3591 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
3592 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
3593 static const struct wacom_features wacom_features_0xB8 =
3594 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
3595 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
3596 static const struct wacom_features wacom_features_0xB9 =
3597 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
3598 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3599 static const struct wacom_features wacom_features_0xBA =
3600 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
3601 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3602 static const struct wacom_features wacom_features_0xBB =
3603 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
3604 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3605 static const struct wacom_features wacom_features_0xBC =
3606 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
3607 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3608 static const struct wacom_features wacom_features_0xBD =
3609 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
3610 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3611 static const struct wacom_features wacom_features_0x26 =
3612 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
3613 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
3614 static const struct wacom_features wacom_features_0x27 =
3615 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
3616 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
3617 static const struct wacom_features wacom_features_0x28 =
3618 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
3619 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
3620 static const struct wacom_features wacom_features_0x29 =
3621 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
3622 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
3623 static const struct wacom_features wacom_features_0x2A =
3624 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
3625 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3626 static const struct wacom_features wacom_features_0x314 =
3627 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
3628 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
3629 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3630 static const struct wacom_features wacom_features_0x315 =
3631 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
3632 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
3633 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3634 static const struct wacom_features wacom_features_0x317 =
3635 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
3636 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
3637 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3638 static const struct wacom_features wacom_features_0xF4 =
3639 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
3640 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
3641 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3642 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3643 static const struct wacom_features wacom_features_0xF8 =
3644 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
3645 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
3646 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3647 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3648 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
3649 static const struct wacom_features wacom_features_0xF6 =
3650 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
3651 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
3652 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3653 static const struct wacom_features wacom_features_0x32A =
3654 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
3655 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
3656 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3657 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3658 static const struct wacom_features wacom_features_0x32B =
3659 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
3660 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
3661 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3662 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3663 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
3664 static const struct wacom_features wacom_features_0x32C =
3665 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
3666 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
3667 static const struct wacom_features wacom_features_0x3F =
3668 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
3669 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3670 static const struct wacom_features wacom_features_0xC5 =
3671 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
3672 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
3673 static const struct wacom_features wacom_features_0xC6 =
3674 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
3675 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
3676 static const struct wacom_features wacom_features_0x304 =
3677 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
3678 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3679 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3680 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3681 static const struct wacom_features wacom_features_0x333 =
3682 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
3683 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3684 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3685 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3686 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
3687 static const struct wacom_features wacom_features_0x335 =
3688 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
3689 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
3690 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3691 static const struct wacom_features wacom_features_0xC7 =
3692 { "Wacom DTU1931", 37832, 30305, 511, 0,
3693 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3694 static const struct wacom_features wacom_features_0xCE =
3695 { "Wacom DTU2231", 47864, 27011, 511, 0,
3696 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3697 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
3698 static const struct wacom_features wacom_features_0xF0 =
3699 { "Wacom DTU1631", 34623, 19553, 511, 0,
3700 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3701 static const struct wacom_features wacom_features_0xFB =
3702 { "Wacom DTU1031", 22096, 13960, 511, 0,
3703 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3704 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3705 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3706 static const struct wacom_features wacom_features_0x32F =
3707 { "Wacom DTU1031X", 22672, 12928, 511, 0,
3708 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
3709 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3710 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3711 static const struct wacom_features wacom_features_0x336 =
3712 { "Wacom DTU1141", 23672, 13403, 1023, 0,
3713 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3714 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3715 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3716 static const struct wacom_features wacom_features_0x57 =
3717 { "Wacom DTK2241", 95840, 54260, 2047, 63,
3718 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
3719 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3720 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3721 static const struct wacom_features wacom_features_0x59 = /* Pen */
3722 { "Wacom DTH2242", 95840, 54260, 2047, 63,
3723 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
3724 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3725 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3726 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
3727 static const struct wacom_features wacom_features_0x5D = /* Touch */
3728 { "Wacom DTH2242", .type = WACOM_24HDT,
3729 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
3730 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3731 static const struct wacom_features wacom_features_0xCC =
3732 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
3733 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
3734 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3735 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3736 static const struct wacom_features wacom_features_0xFA =
3737 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
3738 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
3739 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3740 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3741 static const struct wacom_features wacom_features_0x5B =
3742 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
3743 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
3744 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3745 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3746 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
3747 static const struct wacom_features wacom_features_0x5E =
3748 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
3749 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
3750 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3751 static const struct wacom_features wacom_features_0x90 =
3752 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
3753 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3754 static const struct wacom_features wacom_features_0x93 =
3755 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
3756 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3757 static const struct wacom_features wacom_features_0x97 =
3758 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
3759 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3760 static const struct wacom_features wacom_features_0x9A =
3761 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
3762 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3763 static const struct wacom_features wacom_features_0x9F =
3764 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
3765 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3766 static const struct wacom_features wacom_features_0xE2 =
3767 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
3768 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3769 static const struct wacom_features wacom_features_0xE3 =
3770 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
3771 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3772 static const struct wacom_features wacom_features_0xE5 =
3773 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
3774 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3775 static const struct wacom_features wacom_features_0xE6 =
3776 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
3777 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3778 static const struct wacom_features wacom_features_0xEC =
3779 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
3780 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3781 static const struct wacom_features wacom_features_0xED =
3782 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
3783 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3784 static const struct wacom_features wacom_features_0xEF =
3785 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
3786 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3787 static const struct wacom_features wacom_features_0x100 =
3788 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
3789 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3790 static const struct wacom_features wacom_features_0x101 =
3791 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
3792 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3793 static const struct wacom_features wacom_features_0x10D =
3794 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
3795 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3796 static const struct wacom_features wacom_features_0x10E =
3797 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
3798 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3799 static const struct wacom_features wacom_features_0x10F =
3800 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
3801 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3802 static const struct wacom_features wacom_features_0x116 =
3803 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
3804 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3805 static const struct wacom_features wacom_features_0x12C =
3806 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
3807 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3808 static const struct wacom_features wacom_features_0x4001 =
3809 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
3810 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3811 static const struct wacom_features wacom_features_0x4004 =
3812 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
3813 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3814 static const struct wacom_features wacom_features_0x5000 =
3815 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
3816 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3817 static const struct wacom_features wacom_features_0x5002 =
3818 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
3819 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3820 static const struct wacom_features wacom_features_0x47 =
3821 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3822 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3823 static const struct wacom_features wacom_features_0x84 =
3824 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
3825 static const struct wacom_features wacom_features_0xD0 =
3826 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
3827 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3828 static const struct wacom_features wacom_features_0xD1 =
3829 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
3830 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3831 static const struct wacom_features wacom_features_0xD2 =
3832 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
3833 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3834 static const struct wacom_features wacom_features_0xD3 =
3835 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
3836 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3837 static const struct wacom_features wacom_features_0xD4 =
3838 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
3839 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3840 static const struct wacom_features wacom_features_0xD5 =
3841 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
3842 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3843 static const struct wacom_features wacom_features_0xD6 =
3844 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
3845 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3846 static const struct wacom_features wacom_features_0xD7 =
3847 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
3848 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3849 static const struct wacom_features wacom_features_0xD8 =
3850 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
3851 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3852 static const struct wacom_features wacom_features_0xDA =
3853 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
3854 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3855 static const struct wacom_features wacom_features_0xDB =
3856 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
3857 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3858 static const struct wacom_features wacom_features_0xDD =
3859 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
3860 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3861 static const struct wacom_features wacom_features_0xDE =
3862 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
3863 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
3864 static const struct wacom_features wacom_features_0xDF =
3865 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
3866 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
3867 static const struct wacom_features wacom_features_0x300 =
3868 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
3869 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3870 static const struct wacom_features wacom_features_0x301 =
3871 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
3872 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3873 static const struct wacom_features wacom_features_0x302 =
3874 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
3875 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3876 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3877 static const struct wacom_features wacom_features_0x303 =
3878 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
3879 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3880 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3881 static const struct wacom_features wacom_features_0x30E =
3882 { "Wacom Intuos S", 15200, 9500, 1023, 31,
3883 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3884 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3885 static const struct wacom_features wacom_features_0x6004 =
3886 { "ISD-V4", 12800, 8000, 255, 0,
3887 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3888 static const struct wacom_features wacom_features_0x307 =
3889 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
3890 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3891 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3892 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3893 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
3894 static const struct wacom_features wacom_features_0x309 =
3895 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
3896 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
3897 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3898 static const struct wacom_features wacom_features_0x30A =
3899 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
3900 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3901 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3902 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3903 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
3904 static const struct wacom_features wacom_features_0x30C =
3905 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
3906 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
3907 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3908 static const struct wacom_features wacom_features_0x318 =
3909 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
3910 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3911 static const struct wacom_features wacom_features_0x319 =
3912 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
3913 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3914 static const struct wacom_features wacom_features_0x325 =
3915 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
3916 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
3917 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3918 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3919 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
3920 static const struct wacom_features wacom_features_0x326 = /* Touch */
3921 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
3922 .oPid = 0x325 };
3923 static const struct wacom_features wacom_features_0x323 =
3924 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
3925 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3926 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3927 static const struct wacom_features wacom_features_0x331 =
3928 { "Wacom Express Key Remote", .type = REMOTE,
3929 .numbered_buttons = 18, .check_for_hid_type = true,
3930 .hid_type = HID_TYPE_USBNONE };
3931 static const struct wacom_features wacom_features_0x33B =
3932 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
3933 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3934 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3935 static const struct wacom_features wacom_features_0x33C =
3936 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
3937 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3938 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3939 static const struct wacom_features wacom_features_0x33D =
3940 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
3941 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3942 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3943 static const struct wacom_features wacom_features_0x33E =
3944 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
3945 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3946 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3947 static const struct wacom_features wacom_features_0x343 =
3948 { "Wacom DTK1651", 34816, 19759, 1023, 0,
3949 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3950 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3951 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3952
3953 static const struct wacom_features wacom_features_HID_ANY_ID =
3954 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
3955
3956 #define USB_DEVICE_WACOM(prod) \
3957 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3958 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3959
3960 #define BT_DEVICE_WACOM(prod) \
3961 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3962 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3963
3964 #define I2C_DEVICE_WACOM(prod) \
3965 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3966 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3967
3968 #define USB_DEVICE_LENOVO(prod) \
3969 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
3970 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3971
3972 const struct hid_device_id wacom_ids[] = {
3973 { USB_DEVICE_WACOM(0x00) },
3974 { USB_DEVICE_WACOM(0x03) },
3975 { USB_DEVICE_WACOM(0x10) },
3976 { USB_DEVICE_WACOM(0x11) },
3977 { USB_DEVICE_WACOM(0x12) },
3978 { USB_DEVICE_WACOM(0x13) },
3979 { USB_DEVICE_WACOM(0x14) },
3980 { USB_DEVICE_WACOM(0x15) },
3981 { USB_DEVICE_WACOM(0x16) },
3982 { USB_DEVICE_WACOM(0x17) },
3983 { USB_DEVICE_WACOM(0x18) },
3984 { USB_DEVICE_WACOM(0x19) },
3985 { USB_DEVICE_WACOM(0x20) },
3986 { USB_DEVICE_WACOM(0x21) },
3987 { USB_DEVICE_WACOM(0x22) },
3988 { USB_DEVICE_WACOM(0x23) },
3989 { USB_DEVICE_WACOM(0x24) },
3990 { USB_DEVICE_WACOM(0x26) },
3991 { USB_DEVICE_WACOM(0x27) },
3992 { USB_DEVICE_WACOM(0x28) },
3993 { USB_DEVICE_WACOM(0x29) },
3994 { USB_DEVICE_WACOM(0x2A) },
3995 { USB_DEVICE_WACOM(0x30) },
3996 { USB_DEVICE_WACOM(0x31) },
3997 { USB_DEVICE_WACOM(0x32) },
3998 { USB_DEVICE_WACOM(0x33) },
3999 { USB_DEVICE_WACOM(0x34) },
4000 { USB_DEVICE_WACOM(0x35) },
4001 { USB_DEVICE_WACOM(0x37) },
4002 { USB_DEVICE_WACOM(0x38) },
4003 { USB_DEVICE_WACOM(0x39) },
4004 { USB_DEVICE_WACOM(0x3F) },
4005 { USB_DEVICE_WACOM(0x41) },
4006 { USB_DEVICE_WACOM(0x42) },
4007 { USB_DEVICE_WACOM(0x43) },
4008 { USB_DEVICE_WACOM(0x44) },
4009 { USB_DEVICE_WACOM(0x45) },
4010 { USB_DEVICE_WACOM(0x47) },
4011 { USB_DEVICE_WACOM(0x57) },
4012 { USB_DEVICE_WACOM(0x59) },
4013 { USB_DEVICE_WACOM(0x5B) },
4014 { USB_DEVICE_WACOM(0x5D) },
4015 { USB_DEVICE_WACOM(0x5E) },
4016 { USB_DEVICE_WACOM(0x60) },
4017 { USB_DEVICE_WACOM(0x61) },
4018 { USB_DEVICE_WACOM(0x62) },
4019 { USB_DEVICE_WACOM(0x63) },
4020 { USB_DEVICE_WACOM(0x64) },
4021 { USB_DEVICE_WACOM(0x65) },
4022 { USB_DEVICE_WACOM(0x69) },
4023 { USB_DEVICE_WACOM(0x6A) },
4024 { USB_DEVICE_WACOM(0x6B) },
4025 { BT_DEVICE_WACOM(0x81) },
4026 { USB_DEVICE_WACOM(0x84) },
4027 { USB_DEVICE_WACOM(0x90) },
4028 { USB_DEVICE_WACOM(0x93) },
4029 { USB_DEVICE_WACOM(0x97) },
4030 { USB_DEVICE_WACOM(0x9A) },
4031 { USB_DEVICE_WACOM(0x9F) },
4032 { USB_DEVICE_WACOM(0xB0) },
4033 { USB_DEVICE_WACOM(0xB1) },
4034 { USB_DEVICE_WACOM(0xB2) },
4035 { USB_DEVICE_WACOM(0xB3) },
4036 { USB_DEVICE_WACOM(0xB4) },
4037 { USB_DEVICE_WACOM(0xB5) },
4038 { USB_DEVICE_WACOM(0xB7) },
4039 { USB_DEVICE_WACOM(0xB8) },
4040 { USB_DEVICE_WACOM(0xB9) },
4041 { USB_DEVICE_WACOM(0xBA) },
4042 { USB_DEVICE_WACOM(0xBB) },
4043 { USB_DEVICE_WACOM(0xBC) },
4044 { BT_DEVICE_WACOM(0xBD) },
4045 { USB_DEVICE_WACOM(0xC0) },
4046 { USB_DEVICE_WACOM(0xC2) },
4047 { USB_DEVICE_WACOM(0xC4) },
4048 { USB_DEVICE_WACOM(0xC5) },
4049 { USB_DEVICE_WACOM(0xC6) },
4050 { USB_DEVICE_WACOM(0xC7) },
4051 { USB_DEVICE_WACOM(0xCC) },
4052 { USB_DEVICE_WACOM(0xCE) },
4053 { USB_DEVICE_WACOM(0xD0) },
4054 { USB_DEVICE_WACOM(0xD1) },
4055 { USB_DEVICE_WACOM(0xD2) },
4056 { USB_DEVICE_WACOM(0xD3) },
4057 { USB_DEVICE_WACOM(0xD4) },
4058 { USB_DEVICE_WACOM(0xD5) },
4059 { USB_DEVICE_WACOM(0xD6) },
4060 { USB_DEVICE_WACOM(0xD7) },
4061 { USB_DEVICE_WACOM(0xD8) },
4062 { USB_DEVICE_WACOM(0xDA) },
4063 { USB_DEVICE_WACOM(0xDB) },
4064 { USB_DEVICE_WACOM(0xDD) },
4065 { USB_DEVICE_WACOM(0xDE) },
4066 { USB_DEVICE_WACOM(0xDF) },
4067 { USB_DEVICE_WACOM(0xE2) },
4068 { USB_DEVICE_WACOM(0xE3) },
4069 { USB_DEVICE_WACOM(0xE5) },
4070 { USB_DEVICE_WACOM(0xE6) },
4071 { USB_DEVICE_WACOM(0xEC) },
4072 { USB_DEVICE_WACOM(0xED) },
4073 { USB_DEVICE_WACOM(0xEF) },
4074 { USB_DEVICE_WACOM(0xF0) },
4075 { USB_DEVICE_WACOM(0xF4) },
4076 { USB_DEVICE_WACOM(0xF6) },
4077 { USB_DEVICE_WACOM(0xF8) },
4078 { USB_DEVICE_WACOM(0xFA) },
4079 { USB_DEVICE_WACOM(0xFB) },
4080 { USB_DEVICE_WACOM(0x100) },
4081 { USB_DEVICE_WACOM(0x101) },
4082 { USB_DEVICE_WACOM(0x10D) },
4083 { USB_DEVICE_WACOM(0x10E) },
4084 { USB_DEVICE_WACOM(0x10F) },
4085 { USB_DEVICE_WACOM(0x116) },
4086 { USB_DEVICE_WACOM(0x12C) },
4087 { USB_DEVICE_WACOM(0x300) },
4088 { USB_DEVICE_WACOM(0x301) },
4089 { USB_DEVICE_WACOM(0x302) },
4090 { USB_DEVICE_WACOM(0x303) },
4091 { USB_DEVICE_WACOM(0x304) },
4092 { USB_DEVICE_WACOM(0x307) },
4093 { USB_DEVICE_WACOM(0x309) },
4094 { USB_DEVICE_WACOM(0x30A) },
4095 { USB_DEVICE_WACOM(0x30C) },
4096 { USB_DEVICE_WACOM(0x30E) },
4097 { USB_DEVICE_WACOM(0x314) },
4098 { USB_DEVICE_WACOM(0x315) },
4099 { USB_DEVICE_WACOM(0x317) },
4100 { USB_DEVICE_WACOM(0x318) },
4101 { USB_DEVICE_WACOM(0x319) },
4102 { USB_DEVICE_WACOM(0x323) },
4103 { USB_DEVICE_WACOM(0x325) },
4104 { USB_DEVICE_WACOM(0x326) },
4105 { USB_DEVICE_WACOM(0x32A) },
4106 { USB_DEVICE_WACOM(0x32B) },
4107 { USB_DEVICE_WACOM(0x32C) },
4108 { USB_DEVICE_WACOM(0x32F) },
4109 { USB_DEVICE_WACOM(0x331) },
4110 { USB_DEVICE_WACOM(0x333) },
4111 { USB_DEVICE_WACOM(0x335) },
4112 { USB_DEVICE_WACOM(0x336) },
4113 { USB_DEVICE_WACOM(0x33B) },
4114 { USB_DEVICE_WACOM(0x33C) },
4115 { USB_DEVICE_WACOM(0x33D) },
4116 { USB_DEVICE_WACOM(0x33E) },
4117 { USB_DEVICE_WACOM(0x343) },
4118 { USB_DEVICE_WACOM(0x4001) },
4119 { USB_DEVICE_WACOM(0x4004) },
4120 { USB_DEVICE_WACOM(0x5000) },
4121 { USB_DEVICE_WACOM(0x5002) },
4122 { USB_DEVICE_LENOVO(0x6004) },
4123
4124 { USB_DEVICE_WACOM(HID_ANY_ID) },
4125 { I2C_DEVICE_WACOM(HID_ANY_ID) },
4126 { }
4127 };
4128 MODULE_DEVICE_TABLE(hid, wacom_ids);