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