]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/hid/wacom_wac.c
HID: wacom: generic: Send data only when the interface is defined
[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 break;
1542 case WACOM_HID_WD_ACCELEROMETER_Y:
1543 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1544 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
1545 break;
1546 case WACOM_HID_WD_ACCELEROMETER_Z:
1547 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1548 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1549 break;
1550 case WACOM_HID_WD_BUTTONHOME:
1551 case WACOM_HID_WD_BUTTONUP:
1552 case WACOM_HID_WD_BUTTONDOWN:
1553 case WACOM_HID_WD_BUTTONLEFT:
1554 case WACOM_HID_WD_BUTTONRIGHT:
1555 case WACOM_HID_WD_BUTTONCENTER:
1556 wacom_map_usage(input, usage, field, EV_KEY,
1557 wacom_numbered_button_to_key(features->numbered_buttons),
1558 0);
1559 features->numbered_buttons++;
1560 break;
1561 case WACOM_HID_WD_TOUCHONOFF:
1562 wacom_map_usage(input, usage, field, EV_SW, SW_MUTE_DEVICE, 0);
1563 break;
1564 case WACOM_HID_WD_TOUCHSTRIP:
1565 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
1566 break;
1567 case WACOM_HID_WD_TOUCHSTRIP2:
1568 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
1569 break;
1570 case WACOM_HID_WD_TOUCHRING:
1571 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1572 break;
1573 }
1574
1575 switch (equivalent_usage & 0xfffffff0) {
1576 case WACOM_HID_WD_EXPRESSKEY00:
1577 wacom_map_usage(input, usage, field, EV_KEY,
1578 wacom_numbered_button_to_key(features->numbered_buttons),
1579 0);
1580 features->numbered_buttons++;
1581 break;
1582 }
1583 }
1584
1585 static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
1586 struct hid_usage *usage, __s32 value)
1587 {
1588 struct wacom *wacom = hid_get_drvdata(hdev);
1589 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1590 struct input_dev *input = wacom_wac->pad_input;
1591 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1592
1593 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
1594 wacom_wac->hid_data.inrange_state |= value;
1595 }
1596
1597 switch (equivalent_usage) {
1598 case WACOM_HID_WD_BATTERY_LEVEL:
1599 wacom_wac->hid_data.battery_capacity = value;
1600 wacom_wac->hid_data.bat_connected = 1;
1601 break;
1602
1603 case WACOM_HID_WD_BATTERY_CHARGING:
1604 wacom_wac->hid_data.bat_charging = value;
1605 wacom_wac->hid_data.ps_connected = value;
1606 wacom_wac->hid_data.bat_connected = 1;
1607 break;
1608
1609 case WACOM_HID_WD_TOUCHRINGSTATUS:
1610 break;
1611
1612 default:
1613 input_event(input, usage->type, usage->code, value);
1614 break;
1615 }
1616 }
1617
1618 static void wacom_wac_pad_pre_report(struct hid_device *hdev,
1619 struct hid_report *report)
1620 {
1621 struct wacom *wacom = hid_get_drvdata(hdev);
1622 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1623
1624 wacom_wac->hid_data.inrange_state = 0;
1625 }
1626
1627 static void wacom_wac_pad_report(struct hid_device *hdev,
1628 struct hid_report *report)
1629 {
1630 struct wacom *wacom = hid_get_drvdata(hdev);
1631 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1632 struct wacom_features *features = &wacom_wac->features;
1633 struct input_dev *input = wacom_wac->pad_input;
1634 bool active = wacom_wac->hid_data.inrange_state != 0;
1635
1636 /*
1637 * don't report prox for events like accelerometer
1638 * or battery status
1639 */
1640 if (wacom_equivalent_usage(report->field[0]->physical) == HID_DG_TABLETFUNCTIONKEY)
1641 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
1642
1643 if (features->quirks & WACOM_QUIRK_BATTERY) {
1644 int capacity = wacom_wac->hid_data.battery_capacity;
1645 bool charging = wacom_wac->hid_data.bat_charging;
1646 bool connected = wacom_wac->hid_data.bat_connected;
1647 bool powered = wacom_wac->hid_data.ps_connected;
1648
1649 wacom_notify_battery(wacom_wac, capacity, charging,
1650 connected, powered);
1651 }
1652
1653 input_sync(input);
1654 }
1655
1656 static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
1657 struct hid_field *field, struct hid_usage *usage)
1658 {
1659 struct wacom *wacom = hid_get_drvdata(hdev);
1660 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1661 struct wacom_features *features = &wacom_wac->features;
1662 struct input_dev *input = wacom_wac->pen_input;
1663 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1664
1665 switch (equivalent_usage) {
1666 case HID_GD_X:
1667 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
1668 break;
1669 case HID_GD_Y:
1670 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
1671 break;
1672 case WACOM_HID_WD_DISTANCE:
1673 case HID_GD_Z:
1674 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
1675 break;
1676 case HID_DG_TIPPRESSURE:
1677 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
1678 break;
1679 case HID_DG_INRANGE:
1680 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1681 break;
1682 case HID_DG_BATTERYSTRENGTH:
1683 features->quirks |= WACOM_QUIRK_BATTERY;
1684 break;
1685 case HID_DG_INVERT:
1686 wacom_map_usage(input, usage, field, EV_KEY,
1687 BTN_TOOL_RUBBER, 0);
1688 break;
1689 case HID_DG_TILT_X:
1690 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
1691 break;
1692 case HID_DG_TILT_Y:
1693 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
1694 break;
1695 case HID_DG_TWIST:
1696 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1697 break;
1698 case HID_DG_ERASER:
1699 case HID_DG_TIPSWITCH:
1700 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
1701 break;
1702 case HID_DG_BARRELSWITCH:
1703 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
1704 break;
1705 case HID_DG_BARRELSWITCH2:
1706 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
1707 break;
1708 case HID_DG_TOOLSERIALNUMBER:
1709 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
1710 break;
1711 case WACOM_HID_WD_SENSE:
1712 features->quirks |= WACOM_QUIRK_SENSE;
1713 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1714 break;
1715 case WACOM_HID_WD_SERIALHI:
1716 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
1717 set_bit(EV_KEY, input->evbit);
1718 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
1719 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
1720 input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
1721 input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
1722 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
1723 input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
1724 input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
1725 break;
1726 case WACOM_HID_WD_FINGERWHEEL:
1727 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1728 break;
1729 }
1730 }
1731
1732 static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
1733 struct hid_usage *usage, __s32 value)
1734 {
1735 struct wacom *wacom = hid_get_drvdata(hdev);
1736 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1737 struct wacom_features *features = &wacom_wac->features;
1738 struct input_dev *input = wacom_wac->pen_input;
1739 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1740
1741 switch (equivalent_usage) {
1742 case HID_GD_Z:
1743 /*
1744 * HID_GD_Z "should increase as the control's position is
1745 * moved from high to low", while ABS_DISTANCE instead
1746 * increases in value as the tool moves from low to high.
1747 */
1748 value = field->logical_maximum - value;
1749 break;
1750 case HID_DG_INRANGE:
1751 wacom_wac->hid_data.inrange_state = value;
1752 if (!(features->quirks & WACOM_QUIRK_SENSE))
1753 wacom_wac->hid_data.sense_state = value;
1754 return;
1755 case HID_DG_BATTERYSTRENGTH:
1756 wacom_wac->hid_data.battery_capacity = value;
1757 wacom_wac->hid_data.bat_connected = 1;
1758 break;
1759 case HID_DG_INVERT:
1760 wacom_wac->hid_data.invert_state = value;
1761 return;
1762 case HID_DG_ERASER:
1763 case HID_DG_TIPSWITCH:
1764 wacom_wac->hid_data.tipswitch |= value;
1765 return;
1766 case HID_DG_TOOLSERIALNUMBER:
1767 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
1768 wacom_wac->serial[0] |= value;
1769 return;
1770 case WACOM_HID_WD_SENSE:
1771 wacom_wac->hid_data.sense_state = value;
1772 return;
1773 case WACOM_HID_WD_SERIALHI:
1774 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
1775 wacom_wac->serial[0] |= ((__u64)value) << 32;
1776 /*
1777 * Non-USI EMR devices may contain additional tool type
1778 * information here. See WACOM_HID_WD_TOOLTYPE case for
1779 * more details.
1780 */
1781 if (value >> 20 == 1) {
1782 wacom_wac->id[0] |= value & 0xFFFFF;
1783 }
1784 return;
1785 case WACOM_HID_WD_TOOLTYPE:
1786 /*
1787 * Some devices (MobileStudio Pro, and possibly later
1788 * devices as well) do not return the complete tool
1789 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
1790 * bitwise OR so the complete value can be built
1791 * up over time :(
1792 */
1793 wacom_wac->id[0] |= value;
1794 return;
1795 case WACOM_HID_WD_OFFSETLEFT:
1796 if (features->offset_left && value != features->offset_left)
1797 hid_warn(hdev, "%s: overriding exising left offset "
1798 "%d -> %d\n", __func__, value,
1799 features->offset_left);
1800 features->offset_left = value;
1801 return;
1802 case WACOM_HID_WD_OFFSETRIGHT:
1803 if (features->offset_right && value != features->offset_right)
1804 hid_warn(hdev, "%s: overriding exising right offset "
1805 "%d -> %d\n", __func__, value,
1806 features->offset_right);
1807 features->offset_right = value;
1808 return;
1809 case WACOM_HID_WD_OFFSETTOP:
1810 if (features->offset_top && value != features->offset_top)
1811 hid_warn(hdev, "%s: overriding exising top offset "
1812 "%d -> %d\n", __func__, value,
1813 features->offset_top);
1814 features->offset_top = value;
1815 return;
1816 case WACOM_HID_WD_OFFSETBOTTOM:
1817 if (features->offset_bottom && value != features->offset_bottom)
1818 hid_warn(hdev, "%s: overriding exising bottom offset "
1819 "%d -> %d\n", __func__, value,
1820 features->offset_bottom);
1821 features->offset_bottom = value;
1822 return;
1823 }
1824
1825 /* send pen events only when touch is up or forced out
1826 * or touch arbitration is off
1827 */
1828 if (!usage->type || delay_pen_events(wacom_wac))
1829 return;
1830
1831 /* send pen events only when the pen is in/entering/leaving proximity */
1832 if (!wacom_wac->hid_data.inrange_state && !wacom_wac->tool[0])
1833 return;
1834
1835 input_event(input, usage->type, usage->code, value);
1836 }
1837
1838 static void wacom_wac_pen_pre_report(struct hid_device *hdev,
1839 struct hid_report *report)
1840 {
1841 return;
1842 }
1843
1844 static void wacom_wac_pen_report(struct hid_device *hdev,
1845 struct hid_report *report)
1846 {
1847 struct wacom *wacom = hid_get_drvdata(hdev);
1848 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1849 struct input_dev *input = wacom_wac->pen_input;
1850 bool prox = wacom_wac->hid_data.inrange_state;
1851 bool range = wacom_wac->hid_data.sense_state;
1852
1853 if (!wacom_wac->tool[0] && prox) { /* first in prox */
1854 /* Going into proximity select tool */
1855 if (wacom_wac->hid_data.invert_state)
1856 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
1857 else if (wacom_wac->id[0])
1858 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
1859 else
1860 wacom_wac->tool[0] = BTN_TOOL_PEN;
1861 }
1862
1863 /* keep pen state for touch events */
1864 wacom_wac->shared->stylus_in_proximity = range;
1865
1866 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
1867 int id = wacom_wac->id[0];
1868
1869 /*
1870 * Non-USI EMR tools should have their IDs mangled to
1871 * match the legacy behavior of wacom_intuos_general
1872 */
1873 if (wacom_wac->serial[0] >> 52 == 1)
1874 id = wacom_intuos_id_mangle(id);
1875
1876 /*
1877 * To ensure compatibility with xf86-input-wacom, we should
1878 * report the BTN_TOOL_* event prior to the ABS_MISC or
1879 * MSC_SERIAL events.
1880 */
1881 input_report_key(input, BTN_TOUCH,
1882 wacom_wac->hid_data.tipswitch);
1883 input_report_key(input, wacom_wac->tool[0], prox);
1884 if (wacom_wac->serial[0]) {
1885 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
1886 input_report_abs(input, ABS_MISC, id);
1887 }
1888
1889 wacom_wac->hid_data.tipswitch = false;
1890
1891 input_sync(input);
1892 }
1893
1894 if (!prox) {
1895 wacom_wac->tool[0] = 0;
1896 wacom_wac->id[0] = 0;
1897 }
1898 }
1899
1900 static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
1901 struct hid_field *field, struct hid_usage *usage)
1902 {
1903 struct wacom *wacom = hid_get_drvdata(hdev);
1904 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1905 struct input_dev *input = wacom_wac->touch_input;
1906 unsigned touch_max = wacom_wac->features.touch_max;
1907 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1908
1909 switch (equivalent_usage) {
1910 case HID_GD_X:
1911 if (touch_max == 1)
1912 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
1913 else
1914 wacom_map_usage(input, usage, field, EV_ABS,
1915 ABS_MT_POSITION_X, 4);
1916 break;
1917 case HID_GD_Y:
1918 if (touch_max == 1)
1919 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
1920 else
1921 wacom_map_usage(input, usage, field, EV_ABS,
1922 ABS_MT_POSITION_Y, 4);
1923 break;
1924 case HID_DG_WIDTH:
1925 case HID_DG_HEIGHT:
1926 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
1927 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
1928 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
1929 break;
1930 case HID_DG_TIPSWITCH:
1931 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
1932 break;
1933 case HID_DG_CONTACTCOUNT:
1934 wacom_wac->hid_data.cc_report = field->report->id;
1935 wacom_wac->hid_data.cc_index = field->index;
1936 wacom_wac->hid_data.cc_value_index = usage->usage_index;
1937 break;
1938 }
1939 }
1940
1941 static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
1942 struct input_dev *input)
1943 {
1944 struct hid_data *hid_data = &wacom_wac->hid_data;
1945 bool mt = wacom_wac->features.touch_max > 1;
1946 bool prox = hid_data->tipswitch &&
1947 report_touch_events(wacom_wac);
1948
1949 wacom_wac->hid_data.num_received++;
1950 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
1951 return;
1952
1953 if (mt) {
1954 int slot;
1955
1956 slot = input_mt_get_slot_by_key(input, hid_data->id);
1957 input_mt_slot(input, slot);
1958 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
1959 }
1960 else {
1961 input_report_key(input, BTN_TOUCH, prox);
1962 }
1963
1964 if (prox) {
1965 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
1966 hid_data->x);
1967 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
1968 hid_data->y);
1969
1970 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
1971 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
1972 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
1973 if (hid_data->width != hid_data->height)
1974 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
1975 }
1976 }
1977 }
1978
1979 static void wacom_wac_finger_event(struct hid_device *hdev,
1980 struct hid_field *field, struct hid_usage *usage, __s32 value)
1981 {
1982 struct wacom *wacom = hid_get_drvdata(hdev);
1983 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1984 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1985
1986 switch (equivalent_usage) {
1987 case HID_GD_X:
1988 wacom_wac->hid_data.x = value;
1989 break;
1990 case HID_GD_Y:
1991 wacom_wac->hid_data.y = value;
1992 break;
1993 case HID_DG_WIDTH:
1994 wacom_wac->hid_data.width = value;
1995 break;
1996 case HID_DG_HEIGHT:
1997 wacom_wac->hid_data.height = value;
1998 break;
1999 case HID_DG_CONTACTID:
2000 wacom_wac->hid_data.id = value;
2001 break;
2002 case HID_DG_TIPSWITCH:
2003 wacom_wac->hid_data.tipswitch = value;
2004 break;
2005 }
2006
2007
2008 if (usage->usage_index + 1 == field->report_count) {
2009 if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
2010 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
2011 }
2012 }
2013
2014 static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2015 struct hid_report *report)
2016 {
2017 struct wacom *wacom = hid_get_drvdata(hdev);
2018 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2019 struct hid_data* hid_data = &wacom_wac->hid_data;
2020 int i;
2021
2022 for (i = 0; i < report->maxfield; i++) {
2023 struct hid_field *field = report->field[i];
2024 int j;
2025
2026 for (j = 0; j < field->maxusage; j++) {
2027 struct hid_usage *usage = &field->usage[j];
2028
2029 switch (usage->hid) {
2030 case HID_GD_X:
2031 case HID_GD_Y:
2032 case HID_DG_WIDTH:
2033 case HID_DG_HEIGHT:
2034 case HID_DG_CONTACTID:
2035 case HID_DG_INRANGE:
2036 case HID_DG_INVERT:
2037 case HID_DG_TIPSWITCH:
2038 hid_data->last_slot_field = usage->hid;
2039 break;
2040 case HID_DG_CONTACTCOUNT:
2041 hid_data->cc_report = report->id;
2042 hid_data->cc_index = i;
2043 hid_data->cc_value_index = j;
2044 break;
2045 }
2046 }
2047 }
2048
2049 if (hid_data->cc_report != 0 &&
2050 hid_data->cc_index >= 0) {
2051 struct hid_field *field = report->field[hid_data->cc_index];
2052 int value = field->value[hid_data->cc_value_index];
2053 if (value)
2054 hid_data->num_expected = value;
2055 }
2056 else {
2057 hid_data->num_expected = wacom_wac->features.touch_max;
2058 }
2059 }
2060
2061 static void wacom_wac_finger_report(struct hid_device *hdev,
2062 struct hid_report *report)
2063 {
2064 struct wacom *wacom = hid_get_drvdata(hdev);
2065 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2066 struct input_dev *input = wacom_wac->touch_input;
2067 unsigned touch_max = wacom_wac->features.touch_max;
2068
2069 /* If more packets of data are expected, give us a chance to
2070 * process them rather than immediately syncing a partial
2071 * update.
2072 */
2073 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2074 return;
2075
2076 if (touch_max > 1)
2077 input_mt_sync_frame(input);
2078
2079 input_sync(input);
2080 wacom_wac->hid_data.num_received = 0;
2081
2082 /* keep touch state for pen event */
2083 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
2084 }
2085
2086 void wacom_wac_usage_mapping(struct hid_device *hdev,
2087 struct hid_field *field, struct hid_usage *usage)
2088 {
2089 struct wacom *wacom = hid_get_drvdata(hdev);
2090 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2091 struct wacom_features *features = &wacom_wac->features;
2092
2093 /* currently, only direct devices have proper hid report descriptors */
2094 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2095
2096 if (WACOM_PAD_FIELD(field))
2097 wacom_wac_pad_usage_mapping(hdev, field, usage);
2098 else if (WACOM_PEN_FIELD(field))
2099 wacom_wac_pen_usage_mapping(hdev, field, usage);
2100 else if (WACOM_FINGER_FIELD(field))
2101 wacom_wac_finger_usage_mapping(hdev, field, usage);
2102 }
2103
2104 void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
2105 struct hid_usage *usage, __s32 value)
2106 {
2107 struct wacom *wacom = hid_get_drvdata(hdev);
2108
2109 if (wacom->wacom_wac.features.type != HID_GENERIC)
2110 return;
2111
2112 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2113 wacom_wac_pad_event(hdev, field, usage, value);
2114 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2115 wacom_wac_pen_event(hdev, field, usage, value);
2116 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2117 wacom_wac_finger_event(hdev, field, usage, value);
2118 }
2119
2120 static void wacom_report_events(struct hid_device *hdev, struct hid_report *report)
2121 {
2122 int r;
2123
2124 for (r = 0; r < report->maxfield; r++) {
2125 struct hid_field *field;
2126 unsigned count, n;
2127
2128 field = report->field[r];
2129 count = field->report_count;
2130
2131 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2132 continue;
2133
2134 for (n = 0; n < count; n++)
2135 wacom_wac_event(hdev, field, &field->usage[n], field->value[n]);
2136 }
2137 }
2138
2139 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2140 {
2141 struct wacom *wacom = hid_get_drvdata(hdev);
2142 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2143 struct hid_field *field = report->field[0];
2144
2145 if (wacom_wac->features.type != HID_GENERIC)
2146 return;
2147
2148 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2149 wacom_wac_pad_pre_report(hdev, report);
2150 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2151 wacom_wac_pen_pre_report(hdev, report);
2152 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2153 wacom_wac_finger_pre_report(hdev, report);
2154
2155 wacom_report_events(hdev, report);
2156
2157 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2158 return wacom_wac_pad_report(hdev, report);
2159 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2160 return wacom_wac_pen_report(hdev, report);
2161 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2162 return wacom_wac_finger_report(hdev, report);
2163 }
2164
2165 static int wacom_bpt_touch(struct wacom_wac *wacom)
2166 {
2167 struct wacom_features *features = &wacom->features;
2168 struct input_dev *input = wacom->touch_input;
2169 struct input_dev *pad_input = wacom->pad_input;
2170 unsigned char *data = wacom->data;
2171 int i;
2172
2173 if (data[0] != 0x02)
2174 return 0;
2175
2176 for (i = 0; i < 2; i++) {
2177 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
2178 bool touch = report_touch_events(wacom)
2179 && (data[offset + 3] & 0x80);
2180
2181 input_mt_slot(input, i);
2182 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2183 if (touch) {
2184 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2185 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
2186 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2187 x <<= 5;
2188 y <<= 5;
2189 }
2190 input_report_abs(input, ABS_MT_POSITION_X, x);
2191 input_report_abs(input, ABS_MT_POSITION_Y, y);
2192 }
2193 }
2194
2195 input_mt_sync_frame(input);
2196
2197 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2198 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2199 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2200 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
2201 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2202
2203 return 1;
2204 }
2205
2206 static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
2207 {
2208 struct wacom_features *features = &wacom->features;
2209 struct input_dev *input = wacom->touch_input;
2210 bool touch = data[1] & 0x80;
2211 int slot = input_mt_get_slot_by_key(input, data[0]);
2212
2213 if (slot < 0)
2214 return;
2215
2216 touch = touch && report_touch_events(wacom);
2217
2218 input_mt_slot(input, slot);
2219 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2220
2221 if (touch) {
2222 int x = (data[2] << 4) | (data[4] >> 4);
2223 int y = (data[3] << 4) | (data[4] & 0x0f);
2224 int width, height;
2225
2226 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
2227 width = data[5] * 100;
2228 height = data[6] * 100;
2229 } else {
2230 /*
2231 * "a" is a scaled-down area which we assume is
2232 * roughly circular and which can be described as:
2233 * a=(pi*r^2)/C.
2234 */
2235 int a = data[5];
2236 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2237 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2238 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
2239 height = width * y_res / x_res;
2240 }
2241
2242 input_report_abs(input, ABS_MT_POSITION_X, x);
2243 input_report_abs(input, ABS_MT_POSITION_Y, y);
2244 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2245 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
2246 }
2247 }
2248
2249 static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2250 {
2251 struct input_dev *input = wacom->pad_input;
2252 struct wacom_features *features = &wacom->features;
2253
2254 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
2255 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
2256 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
2257 } else {
2258 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
2259 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
2260 }
2261 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
2262 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
2263 }
2264
2265 static int wacom_bpt3_touch(struct wacom_wac *wacom)
2266 {
2267 unsigned char *data = wacom->data;
2268 int count = data[1] & 0x07;
2269 int touch_changed = 0, i;
2270
2271 if (data[0] != 0x02)
2272 return 0;
2273
2274 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
2275 for (i = 0; i < count; i++) {
2276 int offset = (8 * i) + 2;
2277 int msg_id = data[offset];
2278
2279 if (msg_id >= 2 && msg_id <= 17) {
2280 wacom_bpt3_touch_msg(wacom, data + offset);
2281 touch_changed++;
2282 } else if (msg_id == 128)
2283 wacom_bpt3_button_msg(wacom, data + offset);
2284
2285 }
2286
2287 /* only update touch if we actually have a touchpad and touch data changed */
2288 if (wacom->touch_input && touch_changed) {
2289 input_mt_sync_frame(wacom->touch_input);
2290 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2291 }
2292
2293 return 1;
2294 }
2295
2296 static int wacom_bpt_pen(struct wacom_wac *wacom)
2297 {
2298 struct wacom_features *features = &wacom->features;
2299 struct input_dev *input = wacom->pen_input;
2300 unsigned char *data = wacom->data;
2301 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
2302
2303 if (data[0] != WACOM_REPORT_PENABLED)
2304 return 0;
2305
2306 prox = (data[1] & 0x20) == 0x20;
2307
2308 /*
2309 * All reports shared between PEN and RUBBER tool must be
2310 * forced to a known starting value (zero) when transitioning to
2311 * out-of-prox.
2312 *
2313 * If not reset then, to userspace, it will look like lost events
2314 * if new tool comes in-prox with same values as previous tool sent.
2315 *
2316 * Hardware does report zero in most out-of-prox cases but not all.
2317 */
2318 if (!wacom->shared->stylus_in_proximity) {
2319 if (data[1] & 0x08) {
2320 wacom->tool[0] = BTN_TOOL_RUBBER;
2321 wacom->id[0] = ERASER_DEVICE_ID;
2322 } else {
2323 wacom->tool[0] = BTN_TOOL_PEN;
2324 wacom->id[0] = STYLUS_DEVICE_ID;
2325 }
2326 }
2327
2328 wacom->shared->stylus_in_proximity = prox;
2329 if (delay_pen_events(wacom))
2330 return 0;
2331
2332 if (prox) {
2333 x = le16_to_cpup((__le16 *)&data[2]);
2334 y = le16_to_cpup((__le16 *)&data[4]);
2335 p = le16_to_cpup((__le16 *)&data[6]);
2336 /*
2337 * Convert distance from out prox to distance from tablet.
2338 * distance will be greater than distance_max once
2339 * touching and applying pressure; do not report negative
2340 * distance.
2341 */
2342 if (data[8] <= features->distance_max)
2343 d = features->distance_max - data[8];
2344
2345 pen = data[1] & 0x01;
2346 btn1 = data[1] & 0x02;
2347 btn2 = data[1] & 0x04;
2348 } else {
2349 wacom->id[0] = 0;
2350 }
2351
2352 input_report_key(input, BTN_TOUCH, pen);
2353 input_report_key(input, BTN_STYLUS, btn1);
2354 input_report_key(input, BTN_STYLUS2, btn2);
2355
2356 input_report_abs(input, ABS_X, x);
2357 input_report_abs(input, ABS_Y, y);
2358 input_report_abs(input, ABS_PRESSURE, p);
2359 input_report_abs(input, ABS_DISTANCE, d);
2360
2361 input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
2362 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
2363
2364 return 1;
2365 }
2366
2367 static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
2368 {
2369 struct wacom_features *features = &wacom->features;
2370
2371 if ((features->type == INTUOSHT2) &&
2372 (features->device_type & WACOM_DEVICETYPE_PEN))
2373 return wacom_intuos_irq(wacom);
2374 else if (len == WACOM_PKGLEN_BBTOUCH)
2375 return wacom_bpt_touch(wacom);
2376 else if (len == WACOM_PKGLEN_BBTOUCH3)
2377 return wacom_bpt3_touch(wacom);
2378 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
2379 return wacom_bpt_pen(wacom);
2380
2381 return 0;
2382 }
2383
2384 static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
2385 unsigned char *data)
2386 {
2387 unsigned char prefix;
2388
2389 /*
2390 * We need to reroute the event from the debug interface to the
2391 * pen interface.
2392 * We need to add the report ID to the actual pen report, so we
2393 * temporary overwrite the first byte to prevent having to kzalloc/kfree
2394 * and memcpy the report.
2395 */
2396 prefix = data[0];
2397 data[0] = WACOM_REPORT_BPAD_PEN;
2398
2399 /*
2400 * actually reroute the event.
2401 * No need to check if wacom->shared->pen is valid, hid_input_report()
2402 * will check for us.
2403 */
2404 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
2405 WACOM_PKGLEN_PENABLED, 1);
2406
2407 data[0] = prefix;
2408 }
2409
2410 static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
2411 unsigned char *data)
2412 {
2413 struct input_dev *input = wacom->touch_input;
2414 unsigned char *finger_data, prefix;
2415 unsigned id;
2416 int x, y;
2417 bool valid;
2418
2419 prefix = data[0];
2420
2421 for (id = 0; id < wacom->features.touch_max; id++) {
2422 valid = !!(prefix & BIT(id)) &&
2423 report_touch_events(wacom);
2424
2425 input_mt_slot(input, id);
2426 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
2427
2428 if (!valid)
2429 continue;
2430
2431 finger_data = data + 1 + id * 3;
2432 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
2433 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
2434
2435 input_report_abs(input, ABS_MT_POSITION_X, x);
2436 input_report_abs(input, ABS_MT_POSITION_Y, y);
2437 }
2438
2439 input_mt_sync_frame(input);
2440
2441 input_report_key(input, BTN_LEFT, prefix & 0x40);
2442 input_report_key(input, BTN_RIGHT, prefix & 0x80);
2443
2444 /* keep touch state for pen event */
2445 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
2446
2447 return 1;
2448 }
2449
2450 static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
2451 {
2452 unsigned char *data = wacom->data;
2453
2454 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
2455 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
2456 (data[0] != WACOM_REPORT_BPAD_TOUCH))
2457 return 0;
2458
2459 if (data[1] & 0x01)
2460 wacom_bamboo_pad_pen_event(wacom, &data[1]);
2461
2462 if (data[1] & 0x02)
2463 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
2464
2465 return 0;
2466 }
2467
2468 static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
2469 {
2470 unsigned char *data = wacom->data;
2471 int connected;
2472
2473 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
2474 return 0;
2475
2476 connected = data[1] & 0x01;
2477 if (connected) {
2478 int pid, battery, charging;
2479
2480 if ((wacom->shared->type == INTUOSHT ||
2481 wacom->shared->type == INTUOSHT2) &&
2482 wacom->shared->touch_input &&
2483 wacom->shared->touch_max) {
2484 input_report_switch(wacom->shared->touch_input,
2485 SW_MUTE_DEVICE, data[5] & 0x40);
2486 input_sync(wacom->shared->touch_input);
2487 }
2488
2489 pid = get_unaligned_be16(&data[6]);
2490 battery = (data[5] & 0x3f) * 100 / 31;
2491 charging = !!(data[5] & 0x80);
2492 if (wacom->pid != pid) {
2493 wacom->pid = pid;
2494 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
2495 }
2496
2497 wacom_notify_battery(wacom, battery, charging, 1, 0);
2498
2499 } else if (wacom->pid != 0) {
2500 /* disconnected while previously connected */
2501 wacom->pid = 0;
2502 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
2503 wacom_notify_battery(wacom, 0, 0, 0, 0);
2504 }
2505
2506 return 0;
2507 }
2508
2509 static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
2510 {
2511 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
2512 struct wacom_features *features = &wacom_wac->features;
2513 unsigned char *data = wacom_wac->data;
2514
2515 if (data[0] != WACOM_REPORT_USB)
2516 return 0;
2517
2518 if ((features->type == INTUOSHT ||
2519 features->type == INTUOSHT2) &&
2520 wacom_wac->shared->touch_input &&
2521 features->touch_max) {
2522 input_report_switch(wacom_wac->shared->touch_input,
2523 SW_MUTE_DEVICE, data[8] & 0x40);
2524 input_sync(wacom_wac->shared->touch_input);
2525 }
2526
2527 if (data[9] & 0x02) { /* wireless module is attached */
2528 int battery = (data[8] & 0x3f) * 100 / 31;
2529 bool charging = !!(data[8] & 0x80);
2530
2531 wacom_notify_battery(wacom_wac, battery, charging,
2532 battery || charging, 1);
2533
2534 if (!wacom->battery.battery &&
2535 !(features->quirks & WACOM_QUIRK_BATTERY)) {
2536 features->quirks |= WACOM_QUIRK_BATTERY;
2537 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
2538 }
2539 }
2540 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
2541 wacom->battery.battery) {
2542 features->quirks &= ~WACOM_QUIRK_BATTERY;
2543 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
2544 wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
2545 }
2546 return 0;
2547 }
2548
2549 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
2550 {
2551 bool sync;
2552
2553 switch (wacom_wac->features.type) {
2554 case PENPARTNER:
2555 sync = wacom_penpartner_irq(wacom_wac);
2556 break;
2557
2558 case PL:
2559 sync = wacom_pl_irq(wacom_wac);
2560 break;
2561
2562 case WACOM_G4:
2563 case GRAPHIRE:
2564 case GRAPHIRE_BT:
2565 case WACOM_MO:
2566 sync = wacom_graphire_irq(wacom_wac);
2567 break;
2568
2569 case PTU:
2570 sync = wacom_ptu_irq(wacom_wac);
2571 break;
2572
2573 case DTU:
2574 sync = wacom_dtu_irq(wacom_wac);
2575 break;
2576
2577 case DTUS:
2578 case DTUSX:
2579 sync = wacom_dtus_irq(wacom_wac);
2580 break;
2581
2582 case INTUOS:
2583 case INTUOS3S:
2584 case INTUOS3:
2585 case INTUOS3L:
2586 case INTUOS4S:
2587 case INTUOS4:
2588 case INTUOS4L:
2589 case CINTIQ:
2590 case WACOM_BEE:
2591 case WACOM_13HD:
2592 case WACOM_21UX2:
2593 case WACOM_22HD:
2594 case WACOM_24HD:
2595 case WACOM_27QHD:
2596 case DTK:
2597 case CINTIQ_HYBRID:
2598 case CINTIQ_COMPANION_2:
2599 sync = wacom_intuos_irq(wacom_wac);
2600 break;
2601
2602 case INTUOS4WL:
2603 sync = wacom_intuos_bt_irq(wacom_wac, len);
2604 break;
2605
2606 case WACOM_24HDT:
2607 case WACOM_27QHDT:
2608 sync = wacom_24hdt_irq(wacom_wac);
2609 break;
2610
2611 case INTUOS5S:
2612 case INTUOS5:
2613 case INTUOS5L:
2614 case INTUOSPS:
2615 case INTUOSPM:
2616 case INTUOSPL:
2617 if (len == WACOM_PKGLEN_BBTOUCH3)
2618 sync = wacom_bpt3_touch(wacom_wac);
2619 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
2620 sync = wacom_status_irq(wacom_wac, len);
2621 else
2622 sync = wacom_intuos_irq(wacom_wac);
2623 break;
2624
2625 case TABLETPC:
2626 case TABLETPCE:
2627 case TABLETPC2FG:
2628 case MTSCREEN:
2629 case MTTPC:
2630 case MTTPC_B:
2631 sync = wacom_tpc_irq(wacom_wac, len);
2632 break;
2633
2634 case BAMBOO_PT:
2635 case BAMBOO_PEN:
2636 case BAMBOO_TOUCH:
2637 case INTUOSHT:
2638 case INTUOSHT2:
2639 if (wacom_wac->data[0] == WACOM_REPORT_USB)
2640 sync = wacom_status_irq(wacom_wac, len);
2641 else
2642 sync = wacom_bpt_irq(wacom_wac, len);
2643 break;
2644
2645 case BAMBOO_PAD:
2646 sync = wacom_bamboo_pad_irq(wacom_wac, len);
2647 break;
2648
2649 case WIRELESS:
2650 sync = wacom_wireless_irq(wacom_wac, len);
2651 break;
2652
2653 case REMOTE:
2654 sync = false;
2655 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
2656 wacom_remote_status_irq(wacom_wac, len);
2657 else
2658 sync = wacom_remote_irq(wacom_wac, len);
2659 break;
2660
2661 default:
2662 sync = false;
2663 break;
2664 }
2665
2666 if (sync) {
2667 if (wacom_wac->pen_input)
2668 input_sync(wacom_wac->pen_input);
2669 if (wacom_wac->touch_input)
2670 input_sync(wacom_wac->touch_input);
2671 if (wacom_wac->pad_input)
2672 input_sync(wacom_wac->pad_input);
2673 }
2674 }
2675
2676 static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
2677 {
2678 struct input_dev *input_dev = wacom_wac->pen_input;
2679
2680 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
2681
2682 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2683 __set_bit(BTN_STYLUS, input_dev->keybit);
2684 __set_bit(BTN_STYLUS2, input_dev->keybit);
2685
2686 input_set_abs_params(input_dev, ABS_DISTANCE,
2687 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
2688 }
2689
2690 static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
2691 {
2692 struct input_dev *input_dev = wacom_wac->pen_input;
2693 struct wacom_features *features = &wacom_wac->features;
2694
2695 wacom_setup_basic_pro_pen(wacom_wac);
2696
2697 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2698 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
2699 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
2700 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
2701
2702 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
2703 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
2704 input_abs_set_res(input_dev, ABS_TILT_X, 57);
2705 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
2706 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
2707 }
2708
2709 static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
2710 {
2711 struct input_dev *input_dev = wacom_wac->pen_input;
2712
2713 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2714
2715 wacom_setup_cintiq(wacom_wac);
2716
2717 __set_bit(BTN_LEFT, input_dev->keybit);
2718 __set_bit(BTN_RIGHT, input_dev->keybit);
2719 __set_bit(BTN_MIDDLE, input_dev->keybit);
2720 __set_bit(BTN_SIDE, input_dev->keybit);
2721 __set_bit(BTN_EXTRA, input_dev->keybit);
2722 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2723 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
2724
2725 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
2726 input_abs_set_res(input_dev, ABS_RZ, 287);
2727 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
2728 }
2729
2730 void wacom_setup_device_quirks(struct wacom *wacom)
2731 {
2732 struct wacom_features *features = &wacom->wacom_wac.features;
2733
2734 /* The pen and pad share the same interface on most devices */
2735 if (features->numbered_buttons > 0)
2736 features->device_type |= WACOM_DEVICETYPE_PAD;
2737 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
2738 features->type == DTUS ||
2739 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
2740 if (features->device_type & WACOM_DEVICETYPE_PEN)
2741 features->device_type |= WACOM_DEVICETYPE_PAD;
2742 }
2743
2744 /* touch device found but size is not defined. use default */
2745 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
2746 features->x_max = 1023;
2747 features->y_max = 1023;
2748 }
2749
2750 /*
2751 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
2752 * touch interface in its HID descriptor. If this is the touch
2753 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
2754 * tablet values.
2755 */
2756 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
2757 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
2758 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
2759 if (features->touch_max)
2760 features->device_type |= WACOM_DEVICETYPE_TOUCH;
2761 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
2762 features->device_type |= WACOM_DEVICETYPE_PAD;
2763
2764 features->x_max = 4096;
2765 features->y_max = 4096;
2766 }
2767 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2768 features->device_type |= WACOM_DEVICETYPE_PAD;
2769 }
2770 }
2771
2772 /*
2773 * Hack for the Bamboo One:
2774 * the device presents a PAD/Touch interface as most Bamboos and even
2775 * sends ghosts PAD data on it. However, later, we must disable this
2776 * ghost interface, and we can not detect it unless we set it here
2777 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
2778 */
2779 if (features->type == BAMBOO_PEN &&
2780 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
2781 features->device_type |= WACOM_DEVICETYPE_PAD;
2782
2783 /*
2784 * Raw Wacom-mode pen and touch events both come from interface
2785 * 0, whose HID descriptor has an application usage of 0xFF0D
2786 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
2787 * out through the HID_GENERIC device created for interface 1,
2788 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
2789 */
2790 if (features->type == BAMBOO_PAD)
2791 features->device_type = WACOM_DEVICETYPE_TOUCH;
2792
2793 if (features->type == REMOTE)
2794 features->device_type = WACOM_DEVICETYPE_PAD;
2795
2796 switch (features->type) {
2797 case PL:
2798 case DTU:
2799 case DTUS:
2800 case DTUSX:
2801 case WACOM_21UX2:
2802 case WACOM_22HD:
2803 case DTK:
2804 case WACOM_24HD:
2805 case WACOM_27QHD:
2806 case CINTIQ_HYBRID:
2807 case CINTIQ_COMPANION_2:
2808 case CINTIQ:
2809 case WACOM_BEE:
2810 case WACOM_13HD:
2811 case WACOM_24HDT:
2812 case WACOM_27QHDT:
2813 case TABLETPC:
2814 case TABLETPCE:
2815 case TABLETPC2FG:
2816 case MTSCREEN:
2817 case MTTPC:
2818 case MTTPC_B:
2819 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2820 break;
2821 }
2822
2823 if (wacom->hdev->bus == BUS_BLUETOOTH)
2824 features->quirks |= WACOM_QUIRK_BATTERY;
2825
2826 /* quirk for bamboo touch with 2 low res touches */
2827 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
2828 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2829 features->x_max <<= 5;
2830 features->y_max <<= 5;
2831 features->x_fuzz <<= 5;
2832 features->y_fuzz <<= 5;
2833 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
2834 }
2835
2836 if (features->type == WIRELESS) {
2837 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
2838 features->quirks |= WACOM_QUIRK_BATTERY;
2839 }
2840 }
2841
2842 if (features->type == REMOTE)
2843 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
2844 }
2845
2846 int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
2847 struct wacom_wac *wacom_wac)
2848 {
2849 struct wacom_features *features = &wacom_wac->features;
2850
2851 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
2852
2853 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
2854 return -ENODEV;
2855
2856 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
2857 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
2858 else
2859 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2860
2861 if (features->type == HID_GENERIC)
2862 /* setup has already been done */
2863 return 0;
2864
2865 __set_bit(BTN_TOUCH, input_dev->keybit);
2866 __set_bit(ABS_MISC, input_dev->absbit);
2867
2868 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
2869 features->x_max - features->offset_right,
2870 features->x_fuzz, 0);
2871 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
2872 features->y_max - features->offset_bottom,
2873 features->y_fuzz, 0);
2874 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
2875 features->pressure_max, features->pressure_fuzz, 0);
2876
2877 /* penabled devices have fixed resolution for each model */
2878 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
2879 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
2880
2881 switch (features->type) {
2882 case GRAPHIRE_BT:
2883 __clear_bit(ABS_MISC, input_dev->absbit);
2884
2885 case WACOM_MO:
2886 case WACOM_G4:
2887 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2888 features->distance_max,
2889 features->distance_fuzz, 0);
2890 /* fall through */
2891
2892 case GRAPHIRE:
2893 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2894
2895 __set_bit(BTN_LEFT, input_dev->keybit);
2896 __set_bit(BTN_RIGHT, input_dev->keybit);
2897 __set_bit(BTN_MIDDLE, input_dev->keybit);
2898
2899 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2900 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2901 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2902 __set_bit(BTN_STYLUS, input_dev->keybit);
2903 __set_bit(BTN_STYLUS2, input_dev->keybit);
2904 break;
2905
2906 case WACOM_27QHD:
2907 case WACOM_24HD:
2908 case DTK:
2909 case WACOM_22HD:
2910 case WACOM_21UX2:
2911 case WACOM_BEE:
2912 case CINTIQ:
2913 case WACOM_13HD:
2914 case CINTIQ_HYBRID:
2915 case CINTIQ_COMPANION_2:
2916 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2917 input_abs_set_res(input_dev, ABS_Z, 287);
2918 wacom_setup_cintiq(wacom_wac);
2919 break;
2920
2921 case INTUOS3:
2922 case INTUOS3L:
2923 case INTUOS3S:
2924 case INTUOS4:
2925 case INTUOS4WL:
2926 case INTUOS4L:
2927 case INTUOS4S:
2928 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2929 input_abs_set_res(input_dev, ABS_Z, 287);
2930 /* fall through */
2931
2932 case INTUOS:
2933 wacom_setup_intuos(wacom_wac);
2934 break;
2935
2936 case INTUOS5:
2937 case INTUOS5L:
2938 case INTUOSPM:
2939 case INTUOSPL:
2940 case INTUOS5S:
2941 case INTUOSPS:
2942 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2943 features->distance_max,
2944 features->distance_fuzz, 0);
2945
2946 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2947 input_abs_set_res(input_dev, ABS_Z, 287);
2948
2949 wacom_setup_intuos(wacom_wac);
2950 break;
2951
2952 case WACOM_24HDT:
2953 case WACOM_27QHDT:
2954 case MTSCREEN:
2955 case MTTPC:
2956 case MTTPC_B:
2957 case TABLETPC2FG:
2958 case TABLETPC:
2959 case TABLETPCE:
2960 __clear_bit(ABS_MISC, input_dev->absbit);
2961 /* fall through */
2962
2963 case DTUS:
2964 case DTUSX:
2965 case PL:
2966 case DTU:
2967 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2968 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2969 __set_bit(BTN_STYLUS, input_dev->keybit);
2970 __set_bit(BTN_STYLUS2, input_dev->keybit);
2971 break;
2972
2973 case PTU:
2974 __set_bit(BTN_STYLUS2, input_dev->keybit);
2975 /* fall through */
2976
2977 case PENPARTNER:
2978 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2979 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2980 __set_bit(BTN_STYLUS, input_dev->keybit);
2981 break;
2982
2983 case INTUOSHT:
2984 case BAMBOO_PT:
2985 case BAMBOO_PEN:
2986 case INTUOSHT2:
2987 if (features->type == INTUOSHT2) {
2988 wacom_setup_basic_pro_pen(wacom_wac);
2989 } else {
2990 __clear_bit(ABS_MISC, input_dev->absbit);
2991 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2992 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2993 __set_bit(BTN_STYLUS, input_dev->keybit);
2994 __set_bit(BTN_STYLUS2, input_dev->keybit);
2995 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2996 features->distance_max,
2997 features->distance_fuzz, 0);
2998 }
2999 break;
3000 case BAMBOO_PAD:
3001 __clear_bit(ABS_MISC, input_dev->absbit);
3002 break;
3003 }
3004 return 0;
3005 }
3006
3007 int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3008 struct wacom_wac *wacom_wac)
3009 {
3010 struct wacom_features *features = &wacom_wac->features;
3011
3012 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3013
3014 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3015 return -ENODEV;
3016
3017 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3018 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3019 else
3020 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3021
3022 if (features->type == HID_GENERIC)
3023 /* setup has already been done */
3024 return 0;
3025
3026 __set_bit(BTN_TOUCH, input_dev->keybit);
3027
3028 if (features->touch_max == 1) {
3029 input_set_abs_params(input_dev, ABS_X, 0,
3030 features->x_max, features->x_fuzz, 0);
3031 input_set_abs_params(input_dev, ABS_Y, 0,
3032 features->y_max, features->y_fuzz, 0);
3033 input_abs_set_res(input_dev, ABS_X,
3034 features->x_resolution);
3035 input_abs_set_res(input_dev, ABS_Y,
3036 features->y_resolution);
3037 }
3038 else if (features->touch_max > 1) {
3039 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3040 features->x_max, features->x_fuzz, 0);
3041 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3042 features->y_max, features->y_fuzz, 0);
3043 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3044 features->x_resolution);
3045 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3046 features->y_resolution);
3047 }
3048
3049 switch (features->type) {
3050 case INTUOS5:
3051 case INTUOS5L:
3052 case INTUOSPM:
3053 case INTUOSPL:
3054 case INTUOS5S:
3055 case INTUOSPS:
3056 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3057 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3058 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3059 break;
3060
3061 case WACOM_24HDT:
3062 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3063 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3064 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3065 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
3066 /* fall through */
3067
3068 case WACOM_27QHDT:
3069 case MTSCREEN:
3070 case MTTPC:
3071 case MTTPC_B:
3072 case TABLETPC2FG:
3073 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
3074 /*fall through */
3075
3076 case TABLETPC:
3077 case TABLETPCE:
3078 break;
3079
3080 case INTUOSHT:
3081 case INTUOSHT2:
3082 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3083 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3084 /* fall through */
3085
3086 case BAMBOO_PT:
3087 case BAMBOO_TOUCH:
3088 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3089 input_set_abs_params(input_dev,
3090 ABS_MT_TOUCH_MAJOR,
3091 0, features->x_max, 0, 0);
3092 input_set_abs_params(input_dev,
3093 ABS_MT_TOUCH_MINOR,
3094 0, features->y_max, 0, 0);
3095 }
3096 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3097 break;
3098
3099 case BAMBOO_PAD:
3100 input_mt_init_slots(input_dev, features->touch_max,
3101 INPUT_MT_POINTER);
3102 __set_bit(BTN_LEFT, input_dev->keybit);
3103 __set_bit(BTN_RIGHT, input_dev->keybit);
3104 break;
3105 }
3106 return 0;
3107 }
3108
3109 static int wacom_numbered_button_to_key(int n)
3110 {
3111 if (n < 10)
3112 return BTN_0 + n;
3113 else if (n < 16)
3114 return BTN_A + (n-10);
3115 else if (n < 18)
3116 return BTN_BASE + (n-16);
3117 else
3118 return 0;
3119 }
3120
3121 static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
3122 int button_count)
3123 {
3124 int i;
3125
3126 for (i = 0; i < button_count; i++) {
3127 int key = wacom_numbered_button_to_key(i);
3128
3129 if (key)
3130 __set_bit(key, input_dev->keybit);
3131 }
3132 }
3133
3134 static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3135 {
3136 struct wacom_led *led;
3137 int i;
3138 bool updated = false;
3139
3140 /*
3141 * 24HD has LED group 1 to the left and LED group 0 to the right.
3142 * So group 0 matches the second half of the buttons and thus the mask
3143 * needs to be shifted.
3144 */
3145 if (group == 0)
3146 mask >>= 8;
3147
3148 for (i = 0; i < 3; i++) {
3149 led = wacom_led_find(wacom, group, i);
3150 if (!led) {
3151 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3152 i, group);
3153 continue;
3154 }
3155 if (!updated && mask & BIT(i)) {
3156 led->held = true;
3157 led_trigger_event(&led->trigger, LED_FULL);
3158 } else {
3159 led->held = false;
3160 }
3161 }
3162 }
3163
3164 static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
3165 int mask, int group)
3166 {
3167 int button_per_group;
3168
3169 /*
3170 * 21UX2 has LED group 1 to the left and LED group 0
3171 * to the right. We need to reverse the group to match this
3172 * historical behavior.
3173 */
3174 if (wacom->wacom_wac.features.type == WACOM_21UX2)
3175 group = 1 - group;
3176
3177 button_per_group = button_count/wacom->led.count;
3178
3179 return mask & (1 << (group * button_per_group));
3180 }
3181
3182 static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
3183 int group)
3184 {
3185 struct wacom_led *led, *next_led;
3186 int cur;
3187 bool pressed;
3188
3189 if (wacom->wacom_wac.features.type == WACOM_24HD)
3190 return wacom_24hd_update_leds(wacom, mask, group);
3191
3192 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
3193 cur = wacom->led.groups[group].select;
3194
3195 led = wacom_led_find(wacom, group, cur);
3196 if (!led) {
3197 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
3198 cur, group);
3199 return;
3200 }
3201
3202 if (!pressed) {
3203 led->held = false;
3204 return;
3205 }
3206
3207 if (led->held && pressed)
3208 return;
3209
3210 next_led = wacom_led_next(wacom, led);
3211 if (!next_led) {
3212 hid_err(wacom->hdev, "can't find next LED in group %d\n",
3213 group);
3214 return;
3215 }
3216 if (next_led == led)
3217 return;
3218
3219 next_led->held = true;
3220 led_trigger_event(&next_led->trigger,
3221 wacom_leds_brightness_get(next_led));
3222 }
3223
3224 static void wacom_report_numbered_buttons(struct input_dev *input_dev,
3225 int button_count, int mask)
3226 {
3227 struct wacom *wacom = input_get_drvdata(input_dev);
3228 int i;
3229
3230 for (i = 0; i < wacom->led.count; i++)
3231 wacom_update_led(wacom, button_count, mask, i);
3232
3233 for (i = 0; i < button_count; i++) {
3234 int key = wacom_numbered_button_to_key(i);
3235
3236 if (key)
3237 input_report_key(input_dev, key, mask & (1 << i));
3238 }
3239 }
3240
3241 int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3242 struct wacom_wac *wacom_wac)
3243 {
3244 struct wacom_features *features = &wacom_wac->features;
3245
3246 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
3247 return -ENODEV;
3248
3249 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
3250 return -ENODEV;
3251
3252 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3253
3254 /* kept for making legacy xf86-input-wacom working with the wheels */
3255 __set_bit(ABS_MISC, input_dev->absbit);
3256
3257 /* kept for making legacy xf86-input-wacom accepting the pad */
3258 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
3259 input_dev->absinfo[ABS_X].maximum)))
3260 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
3261 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
3262 input_dev->absinfo[ABS_Y].maximum)))
3263 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
3264
3265 /* kept for making udev and libwacom accepting the pad */
3266 __set_bit(BTN_STYLUS, input_dev->keybit);
3267
3268 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
3269
3270 switch (features->type) {
3271
3272 case CINTIQ_HYBRID:
3273 case CINTIQ_COMPANION_2:
3274 case DTK:
3275 case DTUS:
3276 case GRAPHIRE_BT:
3277 break;
3278
3279 case WACOM_MO:
3280 __set_bit(BTN_BACK, input_dev->keybit);
3281 __set_bit(BTN_LEFT, input_dev->keybit);
3282 __set_bit(BTN_FORWARD, input_dev->keybit);
3283 __set_bit(BTN_RIGHT, input_dev->keybit);
3284 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3285 break;
3286
3287 case WACOM_G4:
3288 __set_bit(BTN_BACK, input_dev->keybit);
3289 __set_bit(BTN_FORWARD, input_dev->keybit);
3290 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3291 break;
3292
3293 case WACOM_24HD:
3294 __set_bit(KEY_PROG1, input_dev->keybit);
3295 __set_bit(KEY_PROG2, input_dev->keybit);
3296 __set_bit(KEY_PROG3, input_dev->keybit);
3297
3298 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3299 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
3300 break;
3301
3302 case WACOM_27QHD:
3303 __set_bit(KEY_PROG1, input_dev->keybit);
3304 __set_bit(KEY_PROG2, input_dev->keybit);
3305 __set_bit(KEY_PROG3, input_dev->keybit);
3306 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
3307 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
3308 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
3309 input_abs_set_res(input_dev, ABS_Y, 1024);
3310 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
3311 input_abs_set_res(input_dev, ABS_Z, 1024);
3312 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
3313 break;
3314
3315 case WACOM_22HD:
3316 __set_bit(KEY_PROG1, input_dev->keybit);
3317 __set_bit(KEY_PROG2, input_dev->keybit);
3318 __set_bit(KEY_PROG3, input_dev->keybit);
3319 /* fall through */
3320
3321 case WACOM_21UX2:
3322 case WACOM_BEE:
3323 case CINTIQ:
3324 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3325 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3326 break;
3327
3328 case WACOM_13HD:
3329 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3330 break;
3331
3332 case INTUOS3:
3333 case INTUOS3L:
3334 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3335 /* fall through */
3336
3337 case INTUOS3S:
3338 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3339 break;
3340
3341 case INTUOS5:
3342 case INTUOS5L:
3343 case INTUOSPM:
3344 case INTUOSPL:
3345 case INTUOS5S:
3346 case INTUOSPS:
3347 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3348 break;
3349
3350 case INTUOS4WL:
3351 /*
3352 * For Bluetooth devices, the udev rule does not work correctly
3353 * for pads unless we add a stylus capability, which forces
3354 * ID_INPUT_TABLET to be set.
3355 */
3356 __set_bit(BTN_STYLUS, input_dev->keybit);
3357 /* fall through */
3358
3359 case INTUOS4:
3360 case INTUOS4L:
3361 case INTUOS4S:
3362 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3363 break;
3364
3365 case INTUOSHT:
3366 case BAMBOO_PT:
3367 case BAMBOO_TOUCH:
3368 case INTUOSHT2:
3369 __clear_bit(ABS_MISC, input_dev->absbit);
3370
3371 __set_bit(BTN_LEFT, input_dev->keybit);
3372 __set_bit(BTN_FORWARD, input_dev->keybit);
3373 __set_bit(BTN_BACK, input_dev->keybit);
3374 __set_bit(BTN_RIGHT, input_dev->keybit);
3375
3376 break;
3377
3378 case REMOTE:
3379 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
3380 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3381 break;
3382
3383 case HID_GENERIC:
3384 break;
3385
3386 default:
3387 /* no pad supported */
3388 return -ENODEV;
3389 }
3390 return 0;
3391 }
3392
3393 static const struct wacom_features wacom_features_0x00 =
3394 { "Wacom Penpartner", 5040, 3780, 255, 0,
3395 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
3396 static const struct wacom_features wacom_features_0x10 =
3397 { "Wacom Graphire", 10206, 7422, 511, 63,
3398 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3399 static const struct wacom_features wacom_features_0x81 =
3400 { "Wacom Graphire BT", 16704, 12064, 511, 32,
3401 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
3402 static const struct wacom_features wacom_features_0x11 =
3403 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
3404 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3405 static const struct wacom_features wacom_features_0x12 =
3406 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
3407 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3408 static const struct wacom_features wacom_features_0x13 =
3409 { "Wacom Graphire3", 10208, 7424, 511, 63,
3410 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3411 static const struct wacom_features wacom_features_0x14 =
3412 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
3413 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3414 static const struct wacom_features wacom_features_0x15 =
3415 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
3416 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3417 static const struct wacom_features wacom_features_0x16 =
3418 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
3419 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3420 static const struct wacom_features wacom_features_0x17 =
3421 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
3422 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3423 static const struct wacom_features wacom_features_0x18 =
3424 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
3425 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3426 static const struct wacom_features wacom_features_0x19 =
3427 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
3428 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
3429 static const struct wacom_features wacom_features_0x60 =
3430 { "Wacom Volito", 5104, 3712, 511, 63,
3431 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3432 static const struct wacom_features wacom_features_0x61 =
3433 { "Wacom PenStation2", 3250, 2320, 255, 63,
3434 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3435 static const struct wacom_features wacom_features_0x62 =
3436 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
3437 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3438 static const struct wacom_features wacom_features_0x63 =
3439 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
3440 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3441 static const struct wacom_features wacom_features_0x64 =
3442 { "Wacom PenPartner2", 3250, 2320, 511, 63,
3443 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
3444 static const struct wacom_features wacom_features_0x65 =
3445 { "Wacom Bamboo", 14760, 9225, 511, 63,
3446 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3447 static const struct wacom_features wacom_features_0x69 =
3448 { "Wacom Bamboo1", 5104, 3712, 511, 63,
3449 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
3450 static const struct wacom_features wacom_features_0x6A =
3451 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
3452 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3453 static const struct wacom_features wacom_features_0x6B =
3454 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
3455 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3456 static const struct wacom_features wacom_features_0x20 =
3457 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
3458 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3459 static const struct wacom_features wacom_features_0x21 =
3460 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
3461 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3462 static const struct wacom_features wacom_features_0x22 =
3463 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
3464 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3465 static const struct wacom_features wacom_features_0x23 =
3466 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
3467 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3468 static const struct wacom_features wacom_features_0x24 =
3469 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
3470 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3471 static const struct wacom_features wacom_features_0x30 =
3472 { "Wacom PL400", 5408, 4056, 255, 0,
3473 PL, WACOM_PL_RES, WACOM_PL_RES };
3474 static const struct wacom_features wacom_features_0x31 =
3475 { "Wacom PL500", 6144, 4608, 255, 0,
3476 PL, WACOM_PL_RES, WACOM_PL_RES };
3477 static const struct wacom_features wacom_features_0x32 =
3478 { "Wacom PL600", 6126, 4604, 255, 0,
3479 PL, WACOM_PL_RES, WACOM_PL_RES };
3480 static const struct wacom_features wacom_features_0x33 =
3481 { "Wacom PL600SX", 6260, 5016, 255, 0,
3482 PL, WACOM_PL_RES, WACOM_PL_RES };
3483 static const struct wacom_features wacom_features_0x34 =
3484 { "Wacom PL550", 6144, 4608, 511, 0,
3485 PL, WACOM_PL_RES, WACOM_PL_RES };
3486 static const struct wacom_features wacom_features_0x35 =
3487 { "Wacom PL800", 7220, 5780, 511, 0,
3488 PL, WACOM_PL_RES, WACOM_PL_RES };
3489 static const struct wacom_features wacom_features_0x37 =
3490 { "Wacom PL700", 6758, 5406, 511, 0,
3491 PL, WACOM_PL_RES, WACOM_PL_RES };
3492 static const struct wacom_features wacom_features_0x38 =
3493 { "Wacom PL510", 6282, 4762, 511, 0,
3494 PL, WACOM_PL_RES, WACOM_PL_RES };
3495 static const struct wacom_features wacom_features_0x39 =
3496 { "Wacom DTU710", 34080, 27660, 511, 0,
3497 PL, WACOM_PL_RES, WACOM_PL_RES };
3498 static const struct wacom_features wacom_features_0xC4 =
3499 { "Wacom DTF521", 6282, 4762, 511, 0,
3500 PL, WACOM_PL_RES, WACOM_PL_RES };
3501 static const struct wacom_features wacom_features_0xC0 =
3502 { "Wacom DTF720", 6858, 5506, 511, 0,
3503 PL, WACOM_PL_RES, WACOM_PL_RES };
3504 static const struct wacom_features wacom_features_0xC2 =
3505 { "Wacom DTF720a", 6858, 5506, 511, 0,
3506 PL, WACOM_PL_RES, WACOM_PL_RES };
3507 static const struct wacom_features wacom_features_0x03 =
3508 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
3509 PTU, WACOM_PL_RES, WACOM_PL_RES };
3510 static const struct wacom_features wacom_features_0x41 =
3511 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
3512 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3513 static const struct wacom_features wacom_features_0x42 =
3514 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3515 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3516 static const struct wacom_features wacom_features_0x43 =
3517 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
3518 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3519 static const struct wacom_features wacom_features_0x44 =
3520 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
3521 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3522 static const struct wacom_features wacom_features_0x45 =
3523 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
3524 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3525 static const struct wacom_features wacom_features_0xB0 =
3526 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
3527 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
3528 static const struct wacom_features wacom_features_0xB1 =
3529 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
3530 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3531 static const struct wacom_features wacom_features_0xB2 =
3532 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
3533 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3534 static const struct wacom_features wacom_features_0xB3 =
3535 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
3536 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3537 static const struct wacom_features wacom_features_0xB4 =
3538 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
3539 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3540 static const struct wacom_features wacom_features_0xB5 =
3541 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
3542 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3543 static const struct wacom_features wacom_features_0xB7 =
3544 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
3545 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
3546 static const struct wacom_features wacom_features_0xB8 =
3547 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
3548 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
3549 static const struct wacom_features wacom_features_0xB9 =
3550 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
3551 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3552 static const struct wacom_features wacom_features_0xBA =
3553 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
3554 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3555 static const struct wacom_features wacom_features_0xBB =
3556 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
3557 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3558 static const struct wacom_features wacom_features_0xBC =
3559 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
3560 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3561 static const struct wacom_features wacom_features_0xBD =
3562 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
3563 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3564 static const struct wacom_features wacom_features_0x26 =
3565 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
3566 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
3567 static const struct wacom_features wacom_features_0x27 =
3568 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
3569 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
3570 static const struct wacom_features wacom_features_0x28 =
3571 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
3572 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
3573 static const struct wacom_features wacom_features_0x29 =
3574 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
3575 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
3576 static const struct wacom_features wacom_features_0x2A =
3577 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
3578 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
3579 static const struct wacom_features wacom_features_0x314 =
3580 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
3581 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
3582 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3583 static const struct wacom_features wacom_features_0x315 =
3584 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
3585 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
3586 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3587 static const struct wacom_features wacom_features_0x317 =
3588 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
3589 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
3590 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3591 static const struct wacom_features wacom_features_0xF4 =
3592 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
3593 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
3594 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3595 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3596 static const struct wacom_features wacom_features_0xF8 =
3597 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
3598 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
3599 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3600 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3601 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
3602 static const struct wacom_features wacom_features_0xF6 =
3603 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
3604 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
3605 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3606 static const struct wacom_features wacom_features_0x32A =
3607 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
3608 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
3609 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3610 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3611 static const struct wacom_features wacom_features_0x32B =
3612 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
3613 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
3614 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3615 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3616 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
3617 static const struct wacom_features wacom_features_0x32C =
3618 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
3619 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
3620 static const struct wacom_features wacom_features_0x3F =
3621 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
3622 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
3623 static const struct wacom_features wacom_features_0xC5 =
3624 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
3625 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
3626 static const struct wacom_features wacom_features_0xC6 =
3627 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
3628 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
3629 static const struct wacom_features wacom_features_0x304 =
3630 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
3631 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3632 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3633 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3634 static const struct wacom_features wacom_features_0x333 =
3635 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
3636 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3637 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3638 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3639 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
3640 static const struct wacom_features wacom_features_0x335 =
3641 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
3642 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
3643 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3644 static const struct wacom_features wacom_features_0xC7 =
3645 { "Wacom DTU1931", 37832, 30305, 511, 0,
3646 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3647 static const struct wacom_features wacom_features_0xCE =
3648 { "Wacom DTU2231", 47864, 27011, 511, 0,
3649 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3650 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
3651 static const struct wacom_features wacom_features_0xF0 =
3652 { "Wacom DTU1631", 34623, 19553, 511, 0,
3653 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3654 static const struct wacom_features wacom_features_0xFB =
3655 { "Wacom DTU1031", 22096, 13960, 511, 0,
3656 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3657 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3658 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3659 static const struct wacom_features wacom_features_0x32F =
3660 { "Wacom DTU1031X", 22672, 12928, 511, 0,
3661 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
3662 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3663 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3664 static const struct wacom_features wacom_features_0x336 =
3665 { "Wacom DTU1141", 23672, 13403, 1023, 0,
3666 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3667 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3668 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3669 static const struct wacom_features wacom_features_0x57 =
3670 { "Wacom DTK2241", 95840, 54260, 2047, 63,
3671 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
3672 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3673 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3674 static const struct wacom_features wacom_features_0x59 = /* Pen */
3675 { "Wacom DTH2242", 95840, 54260, 2047, 63,
3676 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
3677 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3678 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3679 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
3680 static const struct wacom_features wacom_features_0x5D = /* Touch */
3681 { "Wacom DTH2242", .type = WACOM_24HDT,
3682 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
3683 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3684 static const struct wacom_features wacom_features_0xCC =
3685 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
3686 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
3687 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3688 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3689 static const struct wacom_features wacom_features_0xFA =
3690 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
3691 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
3692 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3693 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
3694 static const struct wacom_features wacom_features_0x5B =
3695 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
3696 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
3697 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3698 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3699 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
3700 static const struct wacom_features wacom_features_0x5E =
3701 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
3702 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
3703 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3704 static const struct wacom_features wacom_features_0x90 =
3705 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
3706 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3707 static const struct wacom_features wacom_features_0x93 =
3708 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
3709 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3710 static const struct wacom_features wacom_features_0x97 =
3711 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
3712 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3713 static const struct wacom_features wacom_features_0x9A =
3714 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
3715 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3716 static const struct wacom_features wacom_features_0x9F =
3717 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
3718 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3719 static const struct wacom_features wacom_features_0xE2 =
3720 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
3721 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3722 static const struct wacom_features wacom_features_0xE3 =
3723 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
3724 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3725 static const struct wacom_features wacom_features_0xE5 =
3726 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
3727 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3728 static const struct wacom_features wacom_features_0xE6 =
3729 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
3730 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3731 static const struct wacom_features wacom_features_0xEC =
3732 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
3733 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3734 static const struct wacom_features wacom_features_0xED =
3735 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
3736 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3737 static const struct wacom_features wacom_features_0xEF =
3738 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
3739 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3740 static const struct wacom_features wacom_features_0x100 =
3741 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
3742 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3743 static const struct wacom_features wacom_features_0x101 =
3744 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
3745 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3746 static const struct wacom_features wacom_features_0x10D =
3747 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
3748 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3749 static const struct wacom_features wacom_features_0x10E =
3750 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
3751 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3752 static const struct wacom_features wacom_features_0x10F =
3753 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
3754 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3755 static const struct wacom_features wacom_features_0x116 =
3756 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
3757 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3758 static const struct wacom_features wacom_features_0x12C =
3759 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
3760 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3761 static const struct wacom_features wacom_features_0x4001 =
3762 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
3763 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3764 static const struct wacom_features wacom_features_0x4004 =
3765 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
3766 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3767 static const struct wacom_features wacom_features_0x5000 =
3768 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
3769 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3770 static const struct wacom_features wacom_features_0x5002 =
3771 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
3772 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3773 static const struct wacom_features wacom_features_0x47 =
3774 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3775 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3776 static const struct wacom_features wacom_features_0x84 =
3777 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
3778 static const struct wacom_features wacom_features_0xD0 =
3779 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
3780 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3781 static const struct wacom_features wacom_features_0xD1 =
3782 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
3783 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3784 static const struct wacom_features wacom_features_0xD2 =
3785 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
3786 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3787 static const struct wacom_features wacom_features_0xD3 =
3788 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
3789 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3790 static const struct wacom_features wacom_features_0xD4 =
3791 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
3792 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3793 static const struct wacom_features wacom_features_0xD5 =
3794 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
3795 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3796 static const struct wacom_features wacom_features_0xD6 =
3797 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
3798 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3799 static const struct wacom_features wacom_features_0xD7 =
3800 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
3801 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3802 static const struct wacom_features wacom_features_0xD8 =
3803 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
3804 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3805 static const struct wacom_features wacom_features_0xDA =
3806 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
3807 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3808 static const struct wacom_features wacom_features_0xDB =
3809 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
3810 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
3811 static const struct wacom_features wacom_features_0xDD =
3812 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
3813 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3814 static const struct wacom_features wacom_features_0xDE =
3815 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
3816 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
3817 static const struct wacom_features wacom_features_0xDF =
3818 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
3819 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
3820 static const struct wacom_features wacom_features_0x300 =
3821 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
3822 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3823 static const struct wacom_features wacom_features_0x301 =
3824 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
3825 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3826 static const struct wacom_features wacom_features_0x302 =
3827 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
3828 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3829 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3830 static const struct wacom_features wacom_features_0x303 =
3831 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
3832 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3833 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3834 static const struct wacom_features wacom_features_0x30E =
3835 { "Wacom Intuos S", 15200, 9500, 1023, 31,
3836 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3837 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3838 static const struct wacom_features wacom_features_0x6004 =
3839 { "ISD-V4", 12800, 8000, 255, 0,
3840 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
3841 static const struct wacom_features wacom_features_0x307 =
3842 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
3843 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3844 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3845 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3846 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
3847 static const struct wacom_features wacom_features_0x309 =
3848 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
3849 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
3850 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3851 static const struct wacom_features wacom_features_0x30A =
3852 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
3853 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
3854 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3855 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3856 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
3857 static const struct wacom_features wacom_features_0x30C =
3858 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
3859 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
3860 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3861 static const struct wacom_features wacom_features_0x318 =
3862 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
3863 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3864 static const struct wacom_features wacom_features_0x319 =
3865 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
3866 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3867 static const struct wacom_features wacom_features_0x325 =
3868 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
3869 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
3870 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3871 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
3872 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
3873 static const struct wacom_features wacom_features_0x326 = /* Touch */
3874 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
3875 .oPid = 0x325 };
3876 static const struct wacom_features wacom_features_0x323 =
3877 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
3878 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3879 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3880 static const struct wacom_features wacom_features_0x331 =
3881 { "Wacom Express Key Remote", .type = REMOTE,
3882 .numbered_buttons = 18, .check_for_hid_type = true,
3883 .hid_type = HID_TYPE_USBNONE };
3884 static const struct wacom_features wacom_features_0x33B =
3885 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
3886 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3887 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3888 static const struct wacom_features wacom_features_0x33C =
3889 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
3890 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3891 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3892 static const struct wacom_features wacom_features_0x33D =
3893 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
3894 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3895 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3896 static const struct wacom_features wacom_features_0x33E =
3897 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
3898 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3899 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3900 static const struct wacom_features wacom_features_0x343 =
3901 { "Wacom DTK1651", 34816, 19759, 1023, 0,
3902 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
3903 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
3904 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
3905
3906 static const struct wacom_features wacom_features_HID_ANY_ID =
3907 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
3908
3909 #define USB_DEVICE_WACOM(prod) \
3910 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3911 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3912
3913 #define BT_DEVICE_WACOM(prod) \
3914 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3915 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3916
3917 #define I2C_DEVICE_WACOM(prod) \
3918 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3919 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3920
3921 #define USB_DEVICE_LENOVO(prod) \
3922 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
3923 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3924
3925 const struct hid_device_id wacom_ids[] = {
3926 { USB_DEVICE_WACOM(0x00) },
3927 { USB_DEVICE_WACOM(0x03) },
3928 { USB_DEVICE_WACOM(0x10) },
3929 { USB_DEVICE_WACOM(0x11) },
3930 { USB_DEVICE_WACOM(0x12) },
3931 { USB_DEVICE_WACOM(0x13) },
3932 { USB_DEVICE_WACOM(0x14) },
3933 { USB_DEVICE_WACOM(0x15) },
3934 { USB_DEVICE_WACOM(0x16) },
3935 { USB_DEVICE_WACOM(0x17) },
3936 { USB_DEVICE_WACOM(0x18) },
3937 { USB_DEVICE_WACOM(0x19) },
3938 { USB_DEVICE_WACOM(0x20) },
3939 { USB_DEVICE_WACOM(0x21) },
3940 { USB_DEVICE_WACOM(0x22) },
3941 { USB_DEVICE_WACOM(0x23) },
3942 { USB_DEVICE_WACOM(0x24) },
3943 { USB_DEVICE_WACOM(0x26) },
3944 { USB_DEVICE_WACOM(0x27) },
3945 { USB_DEVICE_WACOM(0x28) },
3946 { USB_DEVICE_WACOM(0x29) },
3947 { USB_DEVICE_WACOM(0x2A) },
3948 { USB_DEVICE_WACOM(0x30) },
3949 { USB_DEVICE_WACOM(0x31) },
3950 { USB_DEVICE_WACOM(0x32) },
3951 { USB_DEVICE_WACOM(0x33) },
3952 { USB_DEVICE_WACOM(0x34) },
3953 { USB_DEVICE_WACOM(0x35) },
3954 { USB_DEVICE_WACOM(0x37) },
3955 { USB_DEVICE_WACOM(0x38) },
3956 { USB_DEVICE_WACOM(0x39) },
3957 { USB_DEVICE_WACOM(0x3F) },
3958 { USB_DEVICE_WACOM(0x41) },
3959 { USB_DEVICE_WACOM(0x42) },
3960 { USB_DEVICE_WACOM(0x43) },
3961 { USB_DEVICE_WACOM(0x44) },
3962 { USB_DEVICE_WACOM(0x45) },
3963 { USB_DEVICE_WACOM(0x47) },
3964 { USB_DEVICE_WACOM(0x57) },
3965 { USB_DEVICE_WACOM(0x59) },
3966 { USB_DEVICE_WACOM(0x5B) },
3967 { USB_DEVICE_WACOM(0x5D) },
3968 { USB_DEVICE_WACOM(0x5E) },
3969 { USB_DEVICE_WACOM(0x60) },
3970 { USB_DEVICE_WACOM(0x61) },
3971 { USB_DEVICE_WACOM(0x62) },
3972 { USB_DEVICE_WACOM(0x63) },
3973 { USB_DEVICE_WACOM(0x64) },
3974 { USB_DEVICE_WACOM(0x65) },
3975 { USB_DEVICE_WACOM(0x69) },
3976 { USB_DEVICE_WACOM(0x6A) },
3977 { USB_DEVICE_WACOM(0x6B) },
3978 { BT_DEVICE_WACOM(0x81) },
3979 { USB_DEVICE_WACOM(0x84) },
3980 { USB_DEVICE_WACOM(0x90) },
3981 { USB_DEVICE_WACOM(0x93) },
3982 { USB_DEVICE_WACOM(0x97) },
3983 { USB_DEVICE_WACOM(0x9A) },
3984 { USB_DEVICE_WACOM(0x9F) },
3985 { USB_DEVICE_WACOM(0xB0) },
3986 { USB_DEVICE_WACOM(0xB1) },
3987 { USB_DEVICE_WACOM(0xB2) },
3988 { USB_DEVICE_WACOM(0xB3) },
3989 { USB_DEVICE_WACOM(0xB4) },
3990 { USB_DEVICE_WACOM(0xB5) },
3991 { USB_DEVICE_WACOM(0xB7) },
3992 { USB_DEVICE_WACOM(0xB8) },
3993 { USB_DEVICE_WACOM(0xB9) },
3994 { USB_DEVICE_WACOM(0xBA) },
3995 { USB_DEVICE_WACOM(0xBB) },
3996 { USB_DEVICE_WACOM(0xBC) },
3997 { BT_DEVICE_WACOM(0xBD) },
3998 { USB_DEVICE_WACOM(0xC0) },
3999 { USB_DEVICE_WACOM(0xC2) },
4000 { USB_DEVICE_WACOM(0xC4) },
4001 { USB_DEVICE_WACOM(0xC5) },
4002 { USB_DEVICE_WACOM(0xC6) },
4003 { USB_DEVICE_WACOM(0xC7) },
4004 { USB_DEVICE_WACOM(0xCC) },
4005 { USB_DEVICE_WACOM(0xCE) },
4006 { USB_DEVICE_WACOM(0xD0) },
4007 { USB_DEVICE_WACOM(0xD1) },
4008 { USB_DEVICE_WACOM(0xD2) },
4009 { USB_DEVICE_WACOM(0xD3) },
4010 { USB_DEVICE_WACOM(0xD4) },
4011 { USB_DEVICE_WACOM(0xD5) },
4012 { USB_DEVICE_WACOM(0xD6) },
4013 { USB_DEVICE_WACOM(0xD7) },
4014 { USB_DEVICE_WACOM(0xD8) },
4015 { USB_DEVICE_WACOM(0xDA) },
4016 { USB_DEVICE_WACOM(0xDB) },
4017 { USB_DEVICE_WACOM(0xDD) },
4018 { USB_DEVICE_WACOM(0xDE) },
4019 { USB_DEVICE_WACOM(0xDF) },
4020 { USB_DEVICE_WACOM(0xE2) },
4021 { USB_DEVICE_WACOM(0xE3) },
4022 { USB_DEVICE_WACOM(0xE5) },
4023 { USB_DEVICE_WACOM(0xE6) },
4024 { USB_DEVICE_WACOM(0xEC) },
4025 { USB_DEVICE_WACOM(0xED) },
4026 { USB_DEVICE_WACOM(0xEF) },
4027 { USB_DEVICE_WACOM(0xF0) },
4028 { USB_DEVICE_WACOM(0xF4) },
4029 { USB_DEVICE_WACOM(0xF6) },
4030 { USB_DEVICE_WACOM(0xF8) },
4031 { USB_DEVICE_WACOM(0xFA) },
4032 { USB_DEVICE_WACOM(0xFB) },
4033 { USB_DEVICE_WACOM(0x100) },
4034 { USB_DEVICE_WACOM(0x101) },
4035 { USB_DEVICE_WACOM(0x10D) },
4036 { USB_DEVICE_WACOM(0x10E) },
4037 { USB_DEVICE_WACOM(0x10F) },
4038 { USB_DEVICE_WACOM(0x116) },
4039 { USB_DEVICE_WACOM(0x12C) },
4040 { USB_DEVICE_WACOM(0x300) },
4041 { USB_DEVICE_WACOM(0x301) },
4042 { USB_DEVICE_WACOM(0x302) },
4043 { USB_DEVICE_WACOM(0x303) },
4044 { USB_DEVICE_WACOM(0x304) },
4045 { USB_DEVICE_WACOM(0x307) },
4046 { USB_DEVICE_WACOM(0x309) },
4047 { USB_DEVICE_WACOM(0x30A) },
4048 { USB_DEVICE_WACOM(0x30C) },
4049 { USB_DEVICE_WACOM(0x30E) },
4050 { USB_DEVICE_WACOM(0x314) },
4051 { USB_DEVICE_WACOM(0x315) },
4052 { USB_DEVICE_WACOM(0x317) },
4053 { USB_DEVICE_WACOM(0x318) },
4054 { USB_DEVICE_WACOM(0x319) },
4055 { USB_DEVICE_WACOM(0x323) },
4056 { USB_DEVICE_WACOM(0x325) },
4057 { USB_DEVICE_WACOM(0x326) },
4058 { USB_DEVICE_WACOM(0x32A) },
4059 { USB_DEVICE_WACOM(0x32B) },
4060 { USB_DEVICE_WACOM(0x32C) },
4061 { USB_DEVICE_WACOM(0x32F) },
4062 { USB_DEVICE_WACOM(0x331) },
4063 { USB_DEVICE_WACOM(0x333) },
4064 { USB_DEVICE_WACOM(0x335) },
4065 { USB_DEVICE_WACOM(0x336) },
4066 { USB_DEVICE_WACOM(0x33B) },
4067 { USB_DEVICE_WACOM(0x33C) },
4068 { USB_DEVICE_WACOM(0x33D) },
4069 { USB_DEVICE_WACOM(0x33E) },
4070 { USB_DEVICE_WACOM(0x343) },
4071 { USB_DEVICE_WACOM(0x4001) },
4072 { USB_DEVICE_WACOM(0x4004) },
4073 { USB_DEVICE_WACOM(0x5000) },
4074 { USB_DEVICE_WACOM(0x5002) },
4075 { USB_DEVICE_LENOVO(0x6004) },
4076
4077 { USB_DEVICE_WACOM(HID_ANY_ID) },
4078 { I2C_DEVICE_WACOM(HID_ANY_ID) },
4079 { }
4080 };
4081 MODULE_DEVICE_TABLE(hid, wacom_ids);