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