Linux 5.1.15
[linux/fpc-iii.git] / drivers / hid / wacom_wac.c
blob09b8e4aac82f498c3574f62e34430cd3c0526485
1 /*
2 * drivers/input/tablet/wacom_wac.c
4 * USB Wacom tablet support - Wacom specific code
6 */
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.
15 #include "wacom_wac.h"
16 #include "wacom.h"
17 #include <linux/input/mt.h>
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
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
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
35 #define WACOM_CONTACT_AREA_SCALE 2607
37 static bool touch_arbitration = 1;
38 module_param(touch_arbitration, bool, 0644);
39 MODULE_PARM_DESC(touch_arbitration, " on (Y) off (N)");
41 static void wacom_report_numbered_buttons(struct input_dev *input_dev,
42 int button_count, int mask);
44 static int wacom_numbered_button_to_key(int n);
46 static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
47 int group);
49 * Percent of battery capacity for Graphire.
50 * 8th value means AC online and show 100% capacity.
52 static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
55 * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
57 static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
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)
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;
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;
77 if (battery->battery)
78 power_supply_changed(battery->battery);
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)
86 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
88 __wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
89 bat_charging, bat_connected, ps_connected);
92 static int wacom_penpartner_irq(struct wacom_wac *wacom)
94 unsigned char *data = wacom->data;
95 struct input_dev *input = wacom->pen_input;
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);
115 break;
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;
127 default:
128 dev_dbg(input->dev.parent,
129 "%s: received unknown report #%d\n", __func__, data[0]);
130 return 0;
133 return 1;
136 static int wacom_pl_irq(struct wacom_wac *wacom)
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;
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;
149 prox = data[1] & 0x40;
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;
156 else {
157 wacom->tool[0] = BTN_TOOL_PEN;
158 wacom->id[0] = STYLUS_DEVICE_ID;
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.
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;
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;
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);
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));
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;
197 static int wacom_ptu_irq(struct wacom_wac *wacom)
199 unsigned char *data = wacom->data;
200 struct input_dev *input = wacom->pen_input;
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;
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;
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;
226 static int wacom_dtu_irq(struct wacom_wac *wacom)
228 unsigned char *data = wacom->data;
229 struct input_dev *input = wacom->pen_input;
230 int prox = data[1] & 0x20;
232 dev_dbg(input->dev.parent,
233 "%s: received report #%d", __func__, data[0]);
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;
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;
256 static int wacom_dtus_irq(struct wacom_wac *wacom)
258 char *data = wacom->data;
259 struct input_dev *input = wacom->pen_input;
260 unsigned short prox, pressure = 0;
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;
284 case 2: /* Pen */
285 wacom->tool[0] = BTN_TOOL_PEN;
286 wacom->id[0] = STYLUS_DEVICE_ID;
287 break;
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);
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;
307 static int wacom_graphire_irq(struct wacom_wac *wacom)
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;
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;
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;
331 prox = data[1] & 0x80;
332 if (prox || wacom->id[0]) {
333 if (prox) {
334 switch ((data[1] >> 5) & 3) {
336 case 0: /* Pen */
337 wacom->tool[0] = BTN_TOOL_PEN;
338 wacom->id[0] = STYLUS_DEVICE_ID;
339 break;
341 case 1: /* Rubber */
342 wacom->tool[0] = BTN_TOOL_RUBBER;
343 wacom->id[0] = ERASER_DEVICE_ID;
344 break;
346 case 2: /* Mouse with wheel */
347 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
348 /* fall through */
350 case 3: /* Mouse without wheel */
351 wacom->tool[0] = BTN_TOOL_MOUSE;
352 wacom->id[0] = CURSOR_DEVICE_ID;
353 break;
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;
389 } else {
390 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
391 rw = -(signed char)data[6];
393 input_report_rel(input, REL_WHEEL, rw);
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 */
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;
418 break;
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;
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;
446 break;
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);
458 exit:
459 return retval;
462 static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
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;
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);
479 static int wacom_intuos_pad(struct wacom_wac *wacom)
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;
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;
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];
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])
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;
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) {
528 * Do not send hardware buttons under Android. They
529 * are already sent to the system through GPIO (and
530 * have different meaning).
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
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
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) {
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].
556 * Touch ring mode switch (data[3]) has no capacitive sensor
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);
565 if (features->type == WACOM_22HD) {
566 nkeys = 3;
567 keys = data[9] & 0x07;
569 } else {
570 buttons = ((data[6] & 0x10) << 5) |
571 ((data[5] & 0x10) << 4) |
572 ((data[6] & 0x0F) << 4) |
573 (data[5] & 0x0F);
575 strip1 = ((data[1] & 0x1f) << 8) | data[2];
576 strip2 = ((data[3] & 0x1f) << 8) | data[4];
579 prox = (buttons & ~(~0 << nbuttons)) | (keys & ~(~0 << nkeys)) |
580 (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2;
582 wacom_report_numbered_buttons(input, nbuttons, buttons);
584 for (i = 0; i < nkeys; i++)
585 input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
587 input_report_abs(input, ABS_RX, strip1);
588 input_report_abs(input, ABS_RY, strip2);
590 input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0);
591 input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0);
593 input_report_key(input, wacom->tool[1], prox ? 1 : 0);
594 input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
596 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
598 return 1;
601 static int wacom_intuos_id_mangle(int tool_id)
603 return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
606 static int wacom_intuos_get_tool_type(int tool_id)
608 int tool_type;
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;
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 0x10842: /* MobileStudio Pro Pro Pen slim */
630 case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
631 case 0x16802: /* Cintiq 13HD Pro Pen */
632 case 0x18802: /* DTH2242 Pen */
633 case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
634 tool_type = BTN_TOOL_PEN;
635 break;
637 case 0x832: /* Stroke pen */
638 case 0x032:
639 tool_type = BTN_TOOL_BRUSH;
640 break;
642 case 0x007: /* Mouse 4D and 2D */
643 case 0x09c:
644 case 0x094:
645 case 0x017: /* Intuos3 2D Mouse */
646 case 0x806: /* Intuos4 Mouse */
647 tool_type = BTN_TOOL_MOUSE;
648 break;
650 case 0x096: /* Lens cursor */
651 case 0x097: /* Intuos3 Lens cursor */
652 case 0x006: /* Intuos4 Lens cursor */
653 tool_type = BTN_TOOL_LENS;
654 break;
656 case 0x82a: /* Eraser */
657 case 0x84a:
658 case 0x85a:
659 case 0x91a:
660 case 0xd1a:
661 case 0x0fa:
662 case 0x82b: /* Intuos3 Grip Pen Eraser */
663 case 0x81b: /* Intuos3 Classic Pen Eraser */
664 case 0x91b: /* Intuos3 Airbrush Eraser */
665 case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
666 case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
667 case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
668 case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
669 case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
670 case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
671 case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
672 case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
673 case 0x1880a: /* DTH2242 Eraser */
674 case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
675 tool_type = BTN_TOOL_RUBBER;
676 break;
678 case 0xd12:
679 case 0x912:
680 case 0x112:
681 case 0x913: /* Intuos3 Airbrush */
682 case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
683 case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
684 tool_type = BTN_TOOL_AIRBRUSH;
685 break;
687 default: /* Unknown tool */
688 tool_type = BTN_TOOL_PEN;
689 break;
691 return tool_type;
694 static void wacom_exit_report(struct wacom_wac *wacom)
696 struct input_dev *input = wacom->pen_input;
697 struct wacom_features *features = &wacom->features;
698 unsigned char *data = wacom->data;
699 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
702 * Reset all states otherwise we lose the initial states
703 * when in-prox next time
705 input_report_abs(input, ABS_X, 0);
706 input_report_abs(input, ABS_Y, 0);
707 input_report_abs(input, ABS_DISTANCE, 0);
708 input_report_abs(input, ABS_TILT_X, 0);
709 input_report_abs(input, ABS_TILT_Y, 0);
710 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
711 input_report_key(input, BTN_LEFT, 0);
712 input_report_key(input, BTN_MIDDLE, 0);
713 input_report_key(input, BTN_RIGHT, 0);
714 input_report_key(input, BTN_SIDE, 0);
715 input_report_key(input, BTN_EXTRA, 0);
716 input_report_abs(input, ABS_THROTTLE, 0);
717 input_report_abs(input, ABS_RZ, 0);
718 } else {
719 input_report_abs(input, ABS_PRESSURE, 0);
720 input_report_key(input, BTN_STYLUS, 0);
721 input_report_key(input, BTN_STYLUS2, 0);
722 input_report_key(input, BTN_TOUCH, 0);
723 input_report_abs(input, ABS_WHEEL, 0);
724 if (features->type >= INTUOS3S)
725 input_report_abs(input, ABS_Z, 0);
727 input_report_key(input, wacom->tool[idx], 0);
728 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
729 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
730 wacom->id[idx] = 0;
733 static int wacom_intuos_inout(struct wacom_wac *wacom)
735 struct wacom_features *features = &wacom->features;
736 unsigned char *data = wacom->data;
737 struct input_dev *input = wacom->pen_input;
738 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
740 if (!(((data[1] & 0xfc) == 0xc0) || /* in prox */
741 ((data[1] & 0xfe) == 0x20) || /* in range */
742 ((data[1] & 0xfe) == 0x80))) /* out prox */
743 return 0;
745 /* Enter report */
746 if ((data[1] & 0xfc) == 0xc0) {
747 /* serial number of the tool */
748 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
749 (data[4] << 20) + (data[5] << 12) +
750 (data[6] << 4) + (data[7] >> 4);
752 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
753 ((data[7] & 0x0f) << 16) | ((data[8] & 0xf0) << 8);
755 wacom->tool[idx] = wacom_intuos_get_tool_type(wacom->id[idx]);
757 wacom->shared->stylus_in_proximity = true;
758 return 1;
761 /* in Range */
762 if ((data[1] & 0xfe) == 0x20) {
763 if (features->type != INTUOSHT2)
764 wacom->shared->stylus_in_proximity = true;
766 /* in Range while exiting */
767 if (wacom->reporting_data) {
768 input_report_key(input, BTN_TOUCH, 0);
769 input_report_abs(input, ABS_PRESSURE, 0);
770 input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
771 return 2;
773 return 1;
776 /* Exit report */
777 if ((data[1] & 0xfe) == 0x80) {
778 wacom->shared->stylus_in_proximity = false;
779 wacom->reporting_data = false;
781 /* don't report exit if we don't know the ID */
782 if (!wacom->id[idx])
783 return 1;
785 wacom_exit_report(wacom);
786 return 2;
789 return 0;
792 static inline bool report_touch_events(struct wacom_wac *wacom)
794 return (touch_arbitration ? !wacom->shared->stylus_in_proximity : 1);
797 static inline bool delay_pen_events(struct wacom_wac *wacom)
799 return (wacom->shared->touch_down && touch_arbitration);
802 static int wacom_intuos_general(struct wacom_wac *wacom)
804 struct wacom_features *features = &wacom->features;
805 unsigned char *data = wacom->data;
806 struct input_dev *input = wacom->pen_input;
807 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
808 unsigned char type = (data[1] >> 1) & 0x0F;
809 unsigned int x, y, distance, t;
811 if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
812 data[0] != WACOM_REPORT_INTUOS_PEN)
813 return 0;
815 if (delay_pen_events(wacom))
816 return 1;
818 /* don't report events if we don't know the tool ID */
819 if (!wacom->id[idx]) {
820 /* but reschedule a read of the current tool */
821 wacom_intuos_schedule_prox_event(wacom);
822 return 1;
826 * don't report events for invalid data
828 /* older I4 styli don't work with new Cintiqs */
829 if ((!((wacom->id[idx] >> 16) & 0x01) &&
830 (features->type == WACOM_21UX2)) ||
831 /* Only large Intuos support Lense Cursor */
832 (wacom->tool[idx] == BTN_TOOL_LENS &&
833 (features->type == INTUOS3 ||
834 features->type == INTUOS3S ||
835 features->type == INTUOS4 ||
836 features->type == INTUOS4S ||
837 features->type == INTUOS5 ||
838 features->type == INTUOS5S ||
839 features->type == INTUOSPM ||
840 features->type == INTUOSPS)) ||
841 /* Cintiq doesn't send data when RDY bit isn't set */
842 (features->type == CINTIQ && !(data[1] & 0x40)))
843 return 1;
845 x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
846 y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
847 distance = data[9] >> 2;
848 if (features->type < INTUOS3S) {
849 x >>= 1;
850 y >>= 1;
851 distance >>= 1;
853 input_report_abs(input, ABS_X, x);
854 input_report_abs(input, ABS_Y, y);
855 input_report_abs(input, ABS_DISTANCE, distance);
857 switch (type) {
858 case 0x00:
859 case 0x01:
860 case 0x02:
861 case 0x03:
862 /* general pen packet */
863 t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
864 if (features->pressure_max < 2047)
865 t >>= 1;
866 input_report_abs(input, ABS_PRESSURE, t);
867 if (features->type != INTUOSHT2) {
868 input_report_abs(input, ABS_TILT_X,
869 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
870 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
872 input_report_key(input, BTN_STYLUS, data[1] & 2);
873 input_report_key(input, BTN_STYLUS2, data[1] & 4);
874 input_report_key(input, BTN_TOUCH, t > 10);
875 break;
877 case 0x0a:
878 /* airbrush second packet */
879 input_report_abs(input, ABS_WHEEL,
880 (data[6] << 2) | ((data[7] >> 6) & 3));
881 input_report_abs(input, ABS_TILT_X,
882 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
883 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
884 break;
886 case 0x05:
887 /* Rotation packet */
888 if (features->type >= INTUOS3S) {
889 /* I3 marker pen rotation */
890 t = (data[6] << 3) | ((data[7] >> 5) & 7);
891 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
892 ((t-1) / 2 + 450)) : (450 - t / 2) ;
893 input_report_abs(input, ABS_Z, t);
894 } else {
895 /* 4D mouse 2nd packet */
896 t = (data[6] << 3) | ((data[7] >> 5) & 7);
897 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
898 ((t - 1) / 2) : -t / 2);
900 break;
902 case 0x04:
903 /* 4D mouse 1st packet */
904 input_report_key(input, BTN_LEFT, data[8] & 0x01);
905 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
906 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
908 input_report_key(input, BTN_SIDE, data[8] & 0x20);
909 input_report_key(input, BTN_EXTRA, data[8] & 0x10);
910 t = (data[6] << 2) | ((data[7] >> 6) & 3);
911 input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
912 break;
914 case 0x06:
915 /* I4 mouse */
916 input_report_key(input, BTN_LEFT, data[6] & 0x01);
917 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
918 input_report_key(input, BTN_RIGHT, data[6] & 0x04);
919 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
920 - ((data[7] & 0x40) >> 6));
921 input_report_key(input, BTN_SIDE, data[6] & 0x08);
922 input_report_key(input, BTN_EXTRA, data[6] & 0x10);
924 input_report_abs(input, ABS_TILT_X,
925 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
926 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
927 break;
929 case 0x08:
930 if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
931 /* 2D mouse packet */
932 input_report_key(input, BTN_LEFT, data[8] & 0x04);
933 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
934 input_report_key(input, BTN_RIGHT, data[8] & 0x10);
935 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
936 - ((data[8] & 0x02) >> 1));
938 /* I3 2D mouse side buttons */
939 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
940 input_report_key(input, BTN_SIDE, data[8] & 0x40);
941 input_report_key(input, BTN_EXTRA, data[8] & 0x20);
944 else if (wacom->tool[idx] == BTN_TOOL_LENS) {
945 /* Lens cursor packets */
946 input_report_key(input, BTN_LEFT, data[8] & 0x01);
947 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
948 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
949 input_report_key(input, BTN_SIDE, data[8] & 0x10);
950 input_report_key(input, BTN_EXTRA, data[8] & 0x08);
952 break;
954 case 0x07:
955 case 0x09:
956 case 0x0b:
957 case 0x0c:
958 case 0x0d:
959 case 0x0e:
960 case 0x0f:
961 /* unhandled */
962 break;
965 input_report_abs(input, ABS_MISC,
966 wacom_intuos_id_mangle(wacom->id[idx])); /* report tool id */
967 input_report_key(input, wacom->tool[idx], 1);
968 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
969 wacom->reporting_data = true;
970 return 2;
973 static int wacom_intuos_irq(struct wacom_wac *wacom)
975 unsigned char *data = wacom->data;
976 struct input_dev *input = wacom->pen_input;
977 int result;
979 if (data[0] != WACOM_REPORT_PENABLED &&
980 data[0] != WACOM_REPORT_INTUOS_ID1 &&
981 data[0] != WACOM_REPORT_INTUOS_ID2 &&
982 data[0] != WACOM_REPORT_INTUOSPAD &&
983 data[0] != WACOM_REPORT_INTUOS_PEN &&
984 data[0] != WACOM_REPORT_CINTIQ &&
985 data[0] != WACOM_REPORT_CINTIQPAD &&
986 data[0] != WACOM_REPORT_INTUOS5PAD) {
987 dev_dbg(input->dev.parent,
988 "%s: received unknown report #%d\n", __func__, data[0]);
989 return 0;
992 /* process pad events */
993 result = wacom_intuos_pad(wacom);
994 if (result)
995 return result;
997 /* process in/out prox events */
998 result = wacom_intuos_inout(wacom);
999 if (result)
1000 return result - 1;
1002 /* process general packets */
1003 result = wacom_intuos_general(wacom);
1004 if (result)
1005 return result - 1;
1007 return 0;
1010 static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
1012 unsigned char *data = wacom_wac->data;
1013 struct input_dev *input;
1014 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1015 struct wacom_remote *remote = wacom->remote;
1016 int bat_charging, bat_percent, touch_ring_mode;
1017 __u32 serial;
1018 int i, index = -1;
1019 unsigned long flags;
1021 if (data[0] != WACOM_REPORT_REMOTE) {
1022 hid_dbg(wacom->hdev, "%s: received unknown report #%d",
1023 __func__, data[0]);
1024 return 0;
1027 serial = data[3] + (data[4] << 8) + (data[5] << 16);
1028 wacom_wac->id[0] = PAD_DEVICE_ID;
1030 spin_lock_irqsave(&remote->remote_lock, flags);
1032 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1033 if (remote->remotes[i].serial == serial) {
1034 index = i;
1035 break;
1039 if (index < 0 || !remote->remotes[index].registered)
1040 goto out;
1042 input = remote->remotes[index].input;
1044 input_report_key(input, BTN_0, (data[9] & 0x01));
1045 input_report_key(input, BTN_1, (data[9] & 0x02));
1046 input_report_key(input, BTN_2, (data[9] & 0x04));
1047 input_report_key(input, BTN_3, (data[9] & 0x08));
1048 input_report_key(input, BTN_4, (data[9] & 0x10));
1049 input_report_key(input, BTN_5, (data[9] & 0x20));
1050 input_report_key(input, BTN_6, (data[9] & 0x40));
1051 input_report_key(input, BTN_7, (data[9] & 0x80));
1053 input_report_key(input, BTN_8, (data[10] & 0x01));
1054 input_report_key(input, BTN_9, (data[10] & 0x02));
1055 input_report_key(input, BTN_A, (data[10] & 0x04));
1056 input_report_key(input, BTN_B, (data[10] & 0x08));
1057 input_report_key(input, BTN_C, (data[10] & 0x10));
1058 input_report_key(input, BTN_X, (data[10] & 0x20));
1059 input_report_key(input, BTN_Y, (data[10] & 0x40));
1060 input_report_key(input, BTN_Z, (data[10] & 0x80));
1062 input_report_key(input, BTN_BASE, (data[11] & 0x01));
1063 input_report_key(input, BTN_BASE2, (data[11] & 0x02));
1065 if (data[12] & 0x80)
1066 input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f));
1067 else
1068 input_report_abs(input, ABS_WHEEL, 0);
1070 bat_percent = data[7] & 0x7f;
1071 bat_charging = !!(data[7] & 0x80);
1073 if (data[9] | data[10] | (data[11] & 0x03) | data[12])
1074 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
1075 else
1076 input_report_abs(input, ABS_MISC, 0);
1078 input_event(input, EV_MSC, MSC_SERIAL, serial);
1080 input_sync(input);
1082 /*Which mode select (LED light) is currently on?*/
1083 touch_ring_mode = (data[11] & 0xC0) >> 6;
1085 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1086 if (remote->remotes[i].serial == serial)
1087 wacom->led.groups[i].select = touch_ring_mode;
1090 __wacom_notify_battery(&remote->remotes[index].battery,
1091 WACOM_POWER_SUPPLY_STATUS_AUTO, bat_percent,
1092 bat_charging, 1, bat_charging);
1094 out:
1095 spin_unlock_irqrestore(&remote->remote_lock, flags);
1096 return 0;
1099 static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
1101 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1102 unsigned char *data = wacom_wac->data;
1103 struct wacom_remote *remote = wacom->remote;
1104 struct wacom_remote_data remote_data;
1105 unsigned long flags;
1106 int i, ret;
1108 if (data[0] != WACOM_REPORT_DEVICE_LIST)
1109 return;
1111 memset(&remote_data, 0, sizeof(struct wacom_remote_data));
1113 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1114 int j = i * 6;
1115 int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
1116 bool connected = data[j+2];
1118 remote_data.remote[i].serial = serial;
1119 remote_data.remote[i].connected = connected;
1122 spin_lock_irqsave(&remote->remote_lock, flags);
1124 ret = kfifo_in(&remote->remote_fifo, &remote_data, sizeof(remote_data));
1125 if (ret != sizeof(remote_data)) {
1126 spin_unlock_irqrestore(&remote->remote_lock, flags);
1127 hid_err(wacom->hdev, "Can't queue Remote status event.\n");
1128 return;
1131 spin_unlock_irqrestore(&remote->remote_lock, flags);
1133 wacom_schedule_work(wacom_wac, WACOM_WORKER_REMOTE);
1136 static int int_dist(int x1, int y1, int x2, int y2)
1138 int x = x2 - x1;
1139 int y = y2 - y1;
1141 return int_sqrt(x*x + y*y);
1144 static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
1145 unsigned char *data)
1147 memcpy(wacom->data, data, 10);
1148 wacom_intuos_irq(wacom);
1150 input_sync(wacom->pen_input);
1151 if (wacom->pad_input)
1152 input_sync(wacom->pad_input);
1155 static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1157 unsigned char data[WACOM_PKGLEN_MAX];
1158 int i = 1;
1159 unsigned power_raw, battery_capacity, bat_charging, ps_connected;
1161 memcpy(data, wacom->data, len);
1163 switch (data[0]) {
1164 case 0x04:
1165 wacom_intuos_bt_process_data(wacom, data + i);
1166 i += 10;
1167 /* fall through */
1168 case 0x03:
1169 wacom_intuos_bt_process_data(wacom, data + i);
1170 i += 10;
1171 wacom_intuos_bt_process_data(wacom, data + i);
1172 i += 10;
1173 power_raw = data[i];
1174 bat_charging = (power_raw & 0x08) ? 1 : 0;
1175 ps_connected = (power_raw & 0x10) ? 1 : 0;
1176 battery_capacity = batcap_i4[power_raw & 0x07];
1177 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1178 battery_capacity, bat_charging,
1179 battery_capacity || bat_charging,
1180 ps_connected);
1181 break;
1182 default:
1183 dev_dbg(wacom->pen_input->dev.parent,
1184 "Unknown report: %d,%d size:%zu\n",
1185 data[0], data[1], len);
1186 return 0;
1188 return 0;
1191 static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1193 struct input_dev *input = wacom->touch_input;
1194 unsigned touch_max = wacom->features.touch_max;
1195 int count = 0;
1196 int i;
1198 if (!touch_max)
1199 return 0;
1201 if (touch_max == 1)
1202 return test_bit(BTN_TOUCH, input->key) &&
1203 report_touch_events(wacom);
1205 for (i = 0; i < input->mt->num_slots; i++) {
1206 struct input_mt_slot *ps = &input->mt->slots[i];
1207 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1208 if (id >= 0)
1209 count++;
1212 return count;
1215 static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1217 int pen_frame_len, pen_frames;
1219 struct input_dev *pen_input = wacom->pen_input;
1220 unsigned char *data = wacom->data;
1221 int i;
1223 if (wacom->features.type == INTUOSP2_BT) {
1224 wacom->serial[0] = get_unaligned_le64(&data[99]);
1225 wacom->id[0] = get_unaligned_le16(&data[107]);
1226 pen_frame_len = 14;
1227 pen_frames = 7;
1228 } else {
1229 wacom->serial[0] = get_unaligned_le64(&data[33]);
1230 wacom->id[0] = get_unaligned_le16(&data[41]);
1231 pen_frame_len = 8;
1232 pen_frames = 4;
1235 if (wacom->serial[0] >> 52 == 1) {
1236 /* Add back in missing bits of ID for non-USI pens */
1237 wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
1240 for (i = 0; i < pen_frames; i++) {
1241 unsigned char *frame = &data[i*pen_frame_len + 1];
1242 bool valid = frame[0] & 0x80;
1243 bool prox = frame[0] & 0x40;
1244 bool range = frame[0] & 0x20;
1245 bool invert = frame[0] & 0x10;
1247 if (!valid)
1248 continue;
1250 if (!prox) {
1251 wacom->shared->stylus_in_proximity = false;
1252 wacom_exit_report(wacom);
1253 input_sync(pen_input);
1255 wacom->tool[0] = 0;
1256 wacom->id[0] = 0;
1257 wacom->serial[0] = 0;
1258 return;
1261 if (range) {
1262 if (!wacom->tool[0]) { /* first in range */
1263 /* Going into range select tool */
1264 if (invert)
1265 wacom->tool[0] = BTN_TOOL_RUBBER;
1266 else if (wacom->id[0])
1267 wacom->tool[0] = wacom_intuos_get_tool_type(wacom->id[0]);
1268 else
1269 wacom->tool[0] = BTN_TOOL_PEN;
1272 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
1273 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
1275 if (wacom->features.type == INTUOSP2_BT) {
1276 /* Fix rotation alignment: userspace expects zero at left */
1277 int16_t rotation =
1278 (int16_t)get_unaligned_le16(&frame[9]);
1279 rotation += 1800/4;
1281 if (rotation > 899)
1282 rotation -= 1800;
1284 input_report_abs(pen_input, ABS_TILT_X,
1285 (char)frame[7]);
1286 input_report_abs(pen_input, ABS_TILT_Y,
1287 (char)frame[8]);
1288 input_report_abs(pen_input, ABS_Z, rotation);
1289 input_report_abs(pen_input, ABS_WHEEL,
1290 get_unaligned_le16(&frame[11]));
1294 if (wacom->tool[0]) {
1295 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
1296 if (wacom->features.type == INTUOSP2_BT) {
1297 input_report_abs(pen_input, ABS_DISTANCE,
1298 range ? frame[13] : wacom->features.distance_max);
1299 } else {
1300 input_report_abs(pen_input, ABS_DISTANCE,
1301 range ? frame[7] : wacom->features.distance_max);
1304 input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x09);
1305 input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02);
1306 input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04);
1308 input_report_key(pen_input, wacom->tool[0], prox);
1309 input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]);
1310 input_report_abs(pen_input, ABS_MISC,
1311 wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */
1314 wacom->shared->stylus_in_proximity = prox;
1316 input_sync(pen_input);
1320 static void wacom_intuos_pro2_bt_touch(struct wacom_wac *wacom)
1322 const int finger_touch_len = 8;
1323 const int finger_frames = 4;
1324 const int finger_frame_len = 43;
1326 struct input_dev *touch_input = wacom->touch_input;
1327 unsigned char *data = wacom->data;
1328 int num_contacts_left = 5;
1329 int i, j;
1331 for (i = 0; i < finger_frames; i++) {
1332 unsigned char *frame = &data[i*finger_frame_len + 109];
1333 int current_num_contacts = frame[0] & 0x7F;
1334 int contacts_to_send;
1336 if (!(frame[0] & 0x80))
1337 continue;
1340 * First packet resets the counter since only the first
1341 * packet in series will have non-zero current_num_contacts.
1343 if (current_num_contacts)
1344 wacom->num_contacts_left = current_num_contacts;
1346 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1348 for (j = 0; j < contacts_to_send; j++) {
1349 unsigned char *touch = &frame[j*finger_touch_len + 1];
1350 int slot = input_mt_get_slot_by_key(touch_input, touch[0]);
1351 int x = get_unaligned_le16(&touch[2]);
1352 int y = get_unaligned_le16(&touch[4]);
1353 int w = touch[6] * input_abs_get_res(touch_input, ABS_MT_POSITION_X);
1354 int h = touch[7] * input_abs_get_res(touch_input, ABS_MT_POSITION_Y);
1356 if (slot < 0)
1357 continue;
1359 input_mt_slot(touch_input, slot);
1360 input_mt_report_slot_state(touch_input, MT_TOOL_FINGER, touch[1] & 0x01);
1361 input_report_abs(touch_input, ABS_MT_POSITION_X, x);
1362 input_report_abs(touch_input, ABS_MT_POSITION_Y, y);
1363 input_report_abs(touch_input, ABS_MT_TOUCH_MAJOR, max(w, h));
1364 input_report_abs(touch_input, ABS_MT_TOUCH_MINOR, min(w, h));
1365 input_report_abs(touch_input, ABS_MT_ORIENTATION, w > h);
1368 input_mt_sync_frame(touch_input);
1370 wacom->num_contacts_left -= contacts_to_send;
1371 if (wacom->num_contacts_left <= 0) {
1372 wacom->num_contacts_left = 0;
1373 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1374 input_sync(touch_input);
1378 if (wacom->num_contacts_left == 0) {
1379 // Be careful that we don't accidentally call input_sync with
1380 // only a partial set of fingers of processed
1381 input_report_switch(touch_input, SW_MUTE_DEVICE, !(data[281] >> 7));
1382 input_sync(touch_input);
1387 static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
1389 struct input_dev *pad_input = wacom->pad_input;
1390 unsigned char *data = wacom->data;
1392 int buttons = data[282] | ((data[281] & 0x40) << 2);
1393 int ring = data[285] & 0x7F;
1394 bool ringstatus = data[285] & 0x80;
1395 bool prox = buttons || ringstatus;
1397 /* Fix touchring data: userspace expects 0 at left and increasing clockwise */
1398 ring = 71 - ring;
1399 ring += 3*72/16;
1400 if (ring > 71)
1401 ring -= 72;
1403 wacom_report_numbered_buttons(pad_input, 9, buttons);
1405 input_report_abs(pad_input, ABS_WHEEL, ringstatus ? ring : 0);
1407 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
1408 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
1409 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1411 input_sync(pad_input);
1414 static void wacom_intuos_pro2_bt_battery(struct wacom_wac *wacom)
1416 unsigned char *data = wacom->data;
1418 bool chg = data[284] & 0x80;
1419 int battery_status = data[284] & 0x7F;
1421 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1422 battery_status, chg, 1, chg);
1425 static void wacom_intuos_gen3_bt_pad(struct wacom_wac *wacom)
1427 struct input_dev *pad_input = wacom->pad_input;
1428 unsigned char *data = wacom->data;
1430 int buttons = data[44];
1432 wacom_report_numbered_buttons(pad_input, 4, buttons);
1434 input_report_key(pad_input, wacom->tool[1], buttons ? 1 : 0);
1435 input_report_abs(pad_input, ABS_MISC, buttons ? PAD_DEVICE_ID : 0);
1436 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1438 input_sync(pad_input);
1441 static void wacom_intuos_gen3_bt_battery(struct wacom_wac *wacom)
1443 unsigned char *data = wacom->data;
1445 bool chg = data[45] & 0x80;
1446 int battery_status = data[45] & 0x7F;
1448 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1449 battery_status, chg, 1, chg);
1452 static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
1454 unsigned char *data = wacom->data;
1456 if (data[0] != 0x80 && data[0] != 0x81) {
1457 dev_dbg(wacom->pen_input->dev.parent,
1458 "%s: received unknown report #%d\n", __func__, data[0]);
1459 return 0;
1462 wacom_intuos_pro2_bt_pen(wacom);
1463 if (wacom->features.type == INTUOSP2_BT) {
1464 wacom_intuos_pro2_bt_touch(wacom);
1465 wacom_intuos_pro2_bt_pad(wacom);
1466 wacom_intuos_pro2_bt_battery(wacom);
1467 } else {
1468 wacom_intuos_gen3_bt_pad(wacom);
1469 wacom_intuos_gen3_bt_battery(wacom);
1471 return 0;
1474 static int wacom_24hdt_irq(struct wacom_wac *wacom)
1476 struct input_dev *input = wacom->touch_input;
1477 unsigned char *data = wacom->data;
1478 int i;
1479 int current_num_contacts = data[61];
1480 int contacts_to_send = 0;
1481 int num_contacts_left = 4; /* maximum contacts per packet */
1482 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1483 int y_offset = 2;
1485 if (wacom->features.type == WACOM_27QHDT) {
1486 current_num_contacts = data[63];
1487 num_contacts_left = 10;
1488 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1489 y_offset = 0;
1493 * First packet resets the counter since only the first
1494 * packet in series will have non-zero current_num_contacts.
1496 if (current_num_contacts)
1497 wacom->num_contacts_left = current_num_contacts;
1499 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1501 for (i = 0; i < contacts_to_send; i++) {
1502 int offset = (byte_per_packet * i) + 1;
1503 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
1504 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
1506 if (slot < 0)
1507 continue;
1508 input_mt_slot(input, slot);
1509 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1511 if (touch) {
1512 int t_x = get_unaligned_le16(&data[offset + 2]);
1513 int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
1515 input_report_abs(input, ABS_MT_POSITION_X, t_x);
1516 input_report_abs(input, ABS_MT_POSITION_Y, t_y);
1518 if (wacom->features.type != WACOM_27QHDT) {
1519 int c_x = get_unaligned_le16(&data[offset + 4]);
1520 int c_y = get_unaligned_le16(&data[offset + 8]);
1521 int w = get_unaligned_le16(&data[offset + 10]);
1522 int h = get_unaligned_le16(&data[offset + 12]);
1524 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1525 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1526 min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1527 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1528 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1532 input_mt_sync_frame(input);
1534 wacom->num_contacts_left -= contacts_to_send;
1535 if (wacom->num_contacts_left <= 0) {
1536 wacom->num_contacts_left = 0;
1537 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1539 return 1;
1542 static int wacom_mt_touch(struct wacom_wac *wacom)
1544 struct input_dev *input = wacom->touch_input;
1545 unsigned char *data = wacom->data;
1546 int i;
1547 int current_num_contacts = data[2];
1548 int contacts_to_send = 0;
1549 int x_offset = 0;
1551 /* MTTPC does not support Height and Width */
1552 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
1553 x_offset = -4;
1556 * First packet resets the counter since only the first
1557 * packet in series will have non-zero current_num_contacts.
1559 if (current_num_contacts)
1560 wacom->num_contacts_left = current_num_contacts;
1562 /* There are at most 5 contacts per packet */
1563 contacts_to_send = min(5, wacom->num_contacts_left);
1565 for (i = 0; i < contacts_to_send; i++) {
1566 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
1567 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
1568 int id = get_unaligned_le16(&data[offset + 1]);
1569 int slot = input_mt_get_slot_by_key(input, id);
1571 if (slot < 0)
1572 continue;
1574 input_mt_slot(input, slot);
1575 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1576 if (touch) {
1577 int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1578 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
1579 input_report_abs(input, ABS_MT_POSITION_X, x);
1580 input_report_abs(input, ABS_MT_POSITION_Y, y);
1583 input_mt_sync_frame(input);
1585 wacom->num_contacts_left -= contacts_to_send;
1586 if (wacom->num_contacts_left <= 0) {
1587 wacom->num_contacts_left = 0;
1588 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1590 return 1;
1593 static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1595 struct input_dev *input = wacom->touch_input;
1596 unsigned char *data = wacom->data;
1597 int i;
1599 for (i = 0; i < 2; i++) {
1600 int p = data[1] & (1 << i);
1601 bool touch = p && report_touch_events(wacom);
1603 input_mt_slot(input, i);
1604 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1605 if (touch) {
1606 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1607 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1609 input_report_abs(input, ABS_MT_POSITION_X, x);
1610 input_report_abs(input, ABS_MT_POSITION_Y, y);
1613 input_mt_sync_frame(input);
1615 /* keep touch state for pen event */
1616 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1618 return 1;
1621 static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
1623 unsigned char *data = wacom->data;
1624 struct input_dev *input = wacom->touch_input;
1625 bool prox = report_touch_events(wacom);
1626 int x = 0, y = 0;
1628 if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1629 return 0;
1631 if (len == WACOM_PKGLEN_TPC1FG) {
1632 prox = prox && (data[0] & 0x01);
1633 x = get_unaligned_le16(&data[1]);
1634 y = get_unaligned_le16(&data[3]);
1635 } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1636 prox = prox && (data[2] & 0x01);
1637 x = get_unaligned_le16(&data[3]);
1638 y = get_unaligned_le16(&data[5]);
1639 } else {
1640 prox = prox && (data[1] & 0x01);
1641 x = le16_to_cpup((__le16 *)&data[2]);
1642 y = le16_to_cpup((__le16 *)&data[4]);
1645 if (prox) {
1646 input_report_abs(input, ABS_X, x);
1647 input_report_abs(input, ABS_Y, y);
1649 input_report_key(input, BTN_TOUCH, prox);
1651 /* keep touch state for pen events */
1652 wacom->shared->touch_down = prox;
1654 return 1;
1657 static int wacom_tpc_pen(struct wacom_wac *wacom)
1659 unsigned char *data = wacom->data;
1660 struct input_dev *input = wacom->pen_input;
1661 bool prox = data[1] & 0x20;
1663 if (!wacom->shared->stylus_in_proximity) /* first in prox */
1664 /* Going into proximity select tool */
1665 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
1667 /* keep pen state for touch events */
1668 wacom->shared->stylus_in_proximity = prox;
1670 /* send pen events only when touch is up or forced out
1671 * or touch arbitration is off
1673 if (!delay_pen_events(wacom)) {
1674 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1675 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1676 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1677 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
1678 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
1679 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1680 input_report_key(input, wacom->tool[0], prox);
1681 return 1;
1684 return 0;
1687 static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1689 unsigned char *data = wacom->data;
1691 if (wacom->pen_input) {
1692 dev_dbg(wacom->pen_input->dev.parent,
1693 "%s: received report #%d\n", __func__, data[0]);
1695 if (len == WACOM_PKGLEN_PENABLED ||
1696 data[0] == WACOM_REPORT_PENABLED)
1697 return wacom_tpc_pen(wacom);
1699 else if (wacom->touch_input) {
1700 dev_dbg(wacom->touch_input->dev.parent,
1701 "%s: received report #%d\n", __func__, data[0]);
1703 switch (len) {
1704 case WACOM_PKGLEN_TPC1FG:
1705 return wacom_tpc_single_touch(wacom, len);
1707 case WACOM_PKGLEN_TPC2FG:
1708 return wacom_tpc_mt_touch(wacom);
1710 default:
1711 switch (data[0]) {
1712 case WACOM_REPORT_TPC1FG:
1713 case WACOM_REPORT_TPCHID:
1714 case WACOM_REPORT_TPCST:
1715 case WACOM_REPORT_TPC1FGE:
1716 return wacom_tpc_single_touch(wacom, len);
1718 case WACOM_REPORT_TPCMT:
1719 case WACOM_REPORT_TPCMT2:
1720 return wacom_mt_touch(wacom);
1726 return 0;
1729 static int wacom_offset_rotation(struct input_dev *input, struct hid_usage *usage,
1730 int value, int num, int denom)
1732 struct input_absinfo *abs = &input->absinfo[usage->code];
1733 int range = (abs->maximum - abs->minimum + 1);
1735 value += num*range/denom;
1736 if (value > abs->maximum)
1737 value -= range;
1738 else if (value < abs->minimum)
1739 value += range;
1740 return value;
1743 int wacom_equivalent_usage(int usage)
1745 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1746 int subpage = (usage & 0xFF00) << 8;
1747 int subusage = (usage & 0xFF);
1749 if (subpage == WACOM_HID_SP_PAD ||
1750 subpage == WACOM_HID_SP_BUTTON ||
1751 subpage == WACOM_HID_SP_DIGITIZER ||
1752 subpage == WACOM_HID_SP_DIGITIZERINFO ||
1753 usage == WACOM_HID_WD_SENSE ||
1754 usage == WACOM_HID_WD_SERIALHI ||
1755 usage == WACOM_HID_WD_TOOLTYPE ||
1756 usage == WACOM_HID_WD_DISTANCE ||
1757 usage == WACOM_HID_WD_TOUCHSTRIP ||
1758 usage == WACOM_HID_WD_TOUCHSTRIP2 ||
1759 usage == WACOM_HID_WD_TOUCHRING ||
1760 usage == WACOM_HID_WD_TOUCHRINGSTATUS ||
1761 usage == WACOM_HID_WD_REPORT_VALID) {
1762 return usage;
1765 if (subpage == HID_UP_UNDEFINED)
1766 subpage = HID_UP_DIGITIZER;
1768 return subpage | subusage;
1771 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMTOUCH) {
1772 int subpage = (usage & 0xFF00) << 8;
1773 int subusage = (usage & 0xFF);
1775 if (subpage == HID_UP_UNDEFINED)
1776 subpage = WACOM_HID_SP_DIGITIZER;
1778 return subpage | subusage;
1781 return usage;
1784 static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
1785 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1787 struct wacom *wacom = input_get_drvdata(input);
1788 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1789 struct wacom_features *features = &wacom_wac->features;
1790 int fmin = field->logical_minimum;
1791 int fmax = field->logical_maximum;
1792 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
1793 int resolution_code = code;
1795 if (equivalent_usage == HID_DG_TWIST) {
1796 resolution_code = ABS_RZ;
1799 if (equivalent_usage == HID_GD_X) {
1800 fmin += features->offset_left;
1801 fmax -= features->offset_right;
1803 if (equivalent_usage == HID_GD_Y) {
1804 fmin += features->offset_top;
1805 fmax -= features->offset_bottom;
1808 usage->type = type;
1809 usage->code = code;
1811 set_bit(type, input->evbit);
1813 switch (type) {
1814 case EV_ABS:
1815 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1816 input_abs_set_res(input, code,
1817 hidinput_calc_abs_res(field, resolution_code));
1818 break;
1819 case EV_KEY:
1820 input_set_capability(input, EV_KEY, code);
1821 break;
1822 case EV_MSC:
1823 input_set_capability(input, EV_MSC, code);
1824 break;
1825 case EV_SW:
1826 input_set_capability(input, EV_SW, code);
1827 break;
1831 static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
1832 struct hid_field *field, struct hid_usage *usage)
1834 struct wacom *wacom = hid_get_drvdata(hdev);
1835 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1836 struct wacom_features *features = &wacom_wac->features;
1837 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1839 switch (equivalent_usage) {
1840 case HID_DG_BATTERYSTRENGTH:
1841 case WACOM_HID_WD_BATTERY_LEVEL:
1842 case WACOM_HID_WD_BATTERY_CHARGING:
1843 features->quirks |= WACOM_QUIRK_BATTERY;
1844 break;
1848 static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
1849 struct hid_usage *usage, __s32 value)
1851 struct wacom *wacom = hid_get_drvdata(hdev);
1852 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1853 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1855 switch (equivalent_usage) {
1856 case HID_DG_BATTERYSTRENGTH:
1857 if (value == 0) {
1858 wacom_wac->hid_data.bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
1860 else {
1861 value = value * 100 / (field->logical_maximum - field->logical_minimum);
1862 wacom_wac->hid_data.battery_capacity = value;
1863 wacom_wac->hid_data.bat_connected = 1;
1864 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1866 break;
1867 case WACOM_HID_WD_BATTERY_LEVEL:
1868 value = value * 100 / (field->logical_maximum - field->logical_minimum);
1869 wacom_wac->hid_data.battery_capacity = value;
1870 wacom_wac->hid_data.bat_connected = 1;
1871 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1872 break;
1873 case WACOM_HID_WD_BATTERY_CHARGING:
1874 wacom_wac->hid_data.bat_charging = value;
1875 wacom_wac->hid_data.ps_connected = value;
1876 wacom_wac->hid_data.bat_connected = 1;
1877 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1878 break;
1882 static void wacom_wac_battery_pre_report(struct hid_device *hdev,
1883 struct hid_report *report)
1885 return;
1888 static void wacom_wac_battery_report(struct hid_device *hdev,
1889 struct hid_report *report)
1891 struct wacom *wacom = hid_get_drvdata(hdev);
1892 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1893 struct wacom_features *features = &wacom_wac->features;
1895 if (features->quirks & WACOM_QUIRK_BATTERY) {
1896 int status = wacom_wac->hid_data.bat_status;
1897 int capacity = wacom_wac->hid_data.battery_capacity;
1898 bool charging = wacom_wac->hid_data.bat_charging;
1899 bool connected = wacom_wac->hid_data.bat_connected;
1900 bool powered = wacom_wac->hid_data.ps_connected;
1902 wacom_notify_battery(wacom_wac, status, capacity, charging,
1903 connected, powered);
1907 static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1908 struct hid_field *field, struct hid_usage *usage)
1910 struct wacom *wacom = hid_get_drvdata(hdev);
1911 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1912 struct wacom_features *features = &wacom_wac->features;
1913 struct input_dev *input = wacom_wac->pad_input;
1914 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1916 switch (equivalent_usage) {
1917 case WACOM_HID_WD_ACCELEROMETER_X:
1918 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1919 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
1920 features->device_type |= WACOM_DEVICETYPE_PAD;
1921 break;
1922 case WACOM_HID_WD_ACCELEROMETER_Y:
1923 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1924 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
1925 features->device_type |= WACOM_DEVICETYPE_PAD;
1926 break;
1927 case WACOM_HID_WD_ACCELEROMETER_Z:
1928 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1929 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1930 features->device_type |= WACOM_DEVICETYPE_PAD;
1931 break;
1932 case WACOM_HID_WD_BUTTONCENTER:
1933 wacom->generic_has_leds = true;
1934 /* fall through */
1935 case WACOM_HID_WD_BUTTONHOME:
1936 case WACOM_HID_WD_BUTTONUP:
1937 case WACOM_HID_WD_BUTTONDOWN:
1938 case WACOM_HID_WD_BUTTONLEFT:
1939 case WACOM_HID_WD_BUTTONRIGHT:
1940 wacom_map_usage(input, usage, field, EV_KEY,
1941 wacom_numbered_button_to_key(features->numbered_buttons),
1943 features->numbered_buttons++;
1944 features->device_type |= WACOM_DEVICETYPE_PAD;
1945 break;
1946 case WACOM_HID_WD_TOUCHONOFF:
1947 case WACOM_HID_WD_MUTE_DEVICE:
1949 * This usage, which is used to mute touch events, comes
1950 * from the pad packet, but is reported on the touch
1951 * interface. Because the touch interface may not have
1952 * been created yet, we cannot call wacom_map_usage(). In
1953 * order to process this usage when we receive it, we set
1954 * the usage type and code directly.
1956 wacom_wac->has_mute_touch_switch = true;
1957 usage->type = EV_SW;
1958 usage->code = SW_MUTE_DEVICE;
1959 features->device_type |= WACOM_DEVICETYPE_PAD;
1960 break;
1961 case WACOM_HID_WD_TOUCHSTRIP:
1962 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
1963 features->device_type |= WACOM_DEVICETYPE_PAD;
1964 break;
1965 case WACOM_HID_WD_TOUCHSTRIP2:
1966 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
1967 features->device_type |= WACOM_DEVICETYPE_PAD;
1968 break;
1969 case WACOM_HID_WD_TOUCHRING:
1970 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1971 features->device_type |= WACOM_DEVICETYPE_PAD;
1972 break;
1973 case WACOM_HID_WD_TOUCHRINGSTATUS:
1975 * Only set up type/code association. Completely mapping
1976 * this usage may overwrite the axis resolution and range.
1978 usage->type = EV_ABS;
1979 usage->code = ABS_WHEEL;
1980 set_bit(EV_ABS, input->evbit);
1981 features->device_type |= WACOM_DEVICETYPE_PAD;
1982 break;
1983 case WACOM_HID_WD_BUTTONCONFIG:
1984 wacom_map_usage(input, usage, field, EV_KEY, KEY_BUTTONCONFIG, 0);
1985 features->device_type |= WACOM_DEVICETYPE_PAD;
1986 break;
1987 case WACOM_HID_WD_ONSCREEN_KEYBOARD:
1988 wacom_map_usage(input, usage, field, EV_KEY, KEY_ONSCREEN_KEYBOARD, 0);
1989 features->device_type |= WACOM_DEVICETYPE_PAD;
1990 break;
1991 case WACOM_HID_WD_CONTROLPANEL:
1992 wacom_map_usage(input, usage, field, EV_KEY, KEY_CONTROLPANEL, 0);
1993 features->device_type |= WACOM_DEVICETYPE_PAD;
1994 break;
1995 case WACOM_HID_WD_MODE_CHANGE:
1996 /* do not overwrite previous data */
1997 if (!wacom_wac->has_mode_change) {
1998 wacom_wac->has_mode_change = true;
1999 wacom_wac->is_direct_mode = true;
2001 features->device_type |= WACOM_DEVICETYPE_PAD;
2002 break;
2005 switch (equivalent_usage & 0xfffffff0) {
2006 case WACOM_HID_WD_EXPRESSKEY00:
2007 wacom_map_usage(input, usage, field, EV_KEY,
2008 wacom_numbered_button_to_key(features->numbered_buttons),
2010 features->numbered_buttons++;
2011 features->device_type |= WACOM_DEVICETYPE_PAD;
2012 break;
2016 static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
2017 struct hid_usage *usage, __s32 value)
2019 struct wacom *wacom = hid_get_drvdata(hdev);
2020 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2021 struct input_dev *input = wacom_wac->pad_input;
2022 struct wacom_features *features = &wacom_wac->features;
2023 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
2024 int i;
2025 bool do_report = false;
2028 * Avoid reporting this event and setting inrange_state if this usage
2029 * hasn't been mapped.
2031 if (!usage->type && equivalent_usage != WACOM_HID_WD_MODE_CHANGE)
2032 return;
2034 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
2035 if (usage->hid != WACOM_HID_WD_TOUCHRING)
2036 wacom_wac->hid_data.inrange_state |= value;
2039 switch (equivalent_usage) {
2040 case WACOM_HID_WD_TOUCHRING:
2042 * Userspace expects touchrings to increase in value with
2043 * clockwise gestures and have their zero point at the
2044 * tablet's left. HID events "should" be clockwise-
2045 * increasing and zero at top, though the MobileStudio
2046 * Pro and 2nd-gen Intuos Pro don't do this...
2048 if (hdev->vendor == 0x56a &&
2049 (hdev->product == 0x34d || hdev->product == 0x34e || /* MobileStudio Pro */
2050 hdev->product == 0x357 || hdev->product == 0x358)) { /* Intuos Pro 2 */
2051 value = (field->logical_maximum - value);
2053 if (hdev->product == 0x357 || hdev->product == 0x358)
2054 value = wacom_offset_rotation(input, usage, value, 3, 16);
2055 else if (hdev->product == 0x34d || hdev->product == 0x34e)
2056 value = wacom_offset_rotation(input, usage, value, 1, 2);
2058 else {
2059 value = wacom_offset_rotation(input, usage, value, 1, 4);
2061 do_report = true;
2062 break;
2063 case WACOM_HID_WD_TOUCHRINGSTATUS:
2064 if (!value)
2065 input_event(input, usage->type, usage->code, 0);
2066 break;
2068 case WACOM_HID_WD_MUTE_DEVICE:
2069 case WACOM_HID_WD_TOUCHONOFF:
2070 if (wacom_wac->shared->touch_input) {
2071 bool *is_touch_on = &wacom_wac->shared->is_touch_on;
2073 if (equivalent_usage == WACOM_HID_WD_MUTE_DEVICE && value)
2074 *is_touch_on = !(*is_touch_on);
2075 else if (equivalent_usage == WACOM_HID_WD_TOUCHONOFF)
2076 *is_touch_on = value;
2078 input_report_switch(wacom_wac->shared->touch_input,
2079 SW_MUTE_DEVICE, !(*is_touch_on));
2080 input_sync(wacom_wac->shared->touch_input);
2082 break;
2084 case WACOM_HID_WD_MODE_CHANGE:
2085 if (wacom_wac->is_direct_mode != value) {
2086 wacom_wac->is_direct_mode = value;
2087 wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_MODE_CHANGE);
2089 break;
2091 case WACOM_HID_WD_BUTTONCENTER:
2092 for (i = 0; i < wacom->led.count; i++)
2093 wacom_update_led(wacom, features->numbered_buttons,
2094 value, i);
2095 /* fall through*/
2096 default:
2097 do_report = true;
2098 break;
2101 if (do_report) {
2102 input_event(input, usage->type, usage->code, value);
2103 if (value)
2104 wacom_wac->hid_data.pad_input_event_flag = true;
2108 static void wacom_wac_pad_pre_report(struct hid_device *hdev,
2109 struct hid_report *report)
2111 struct wacom *wacom = hid_get_drvdata(hdev);
2112 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2114 wacom_wac->hid_data.inrange_state = 0;
2117 static void wacom_wac_pad_report(struct hid_device *hdev,
2118 struct hid_report *report, struct hid_field *field)
2120 struct wacom *wacom = hid_get_drvdata(hdev);
2121 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2122 struct input_dev *input = wacom_wac->pad_input;
2123 bool active = wacom_wac->hid_data.inrange_state != 0;
2125 /* report prox for expresskey events */
2126 if ((wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) &&
2127 wacom_wac->hid_data.pad_input_event_flag) {
2128 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
2129 input_sync(input);
2130 if (!active)
2131 wacom_wac->hid_data.pad_input_event_flag = false;
2136 static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
2137 struct hid_field *field, struct hid_usage *usage)
2139 struct wacom *wacom = hid_get_drvdata(hdev);
2140 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2141 struct wacom_features *features = &wacom_wac->features;
2142 struct input_dev *input = wacom_wac->pen_input;
2143 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
2145 switch (equivalent_usage) {
2146 case HID_GD_X:
2147 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
2148 break;
2149 case HID_GD_Y:
2150 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
2151 break;
2152 case WACOM_HID_WD_DISTANCE:
2153 case HID_GD_Z:
2154 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
2155 break;
2156 case HID_DG_TIPPRESSURE:
2157 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
2158 break;
2159 case HID_DG_INRANGE:
2160 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
2161 break;
2162 case HID_DG_INVERT:
2163 wacom_map_usage(input, usage, field, EV_KEY,
2164 BTN_TOOL_RUBBER, 0);
2165 break;
2166 case HID_DG_TILT_X:
2167 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
2168 break;
2169 case HID_DG_TILT_Y:
2170 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
2171 break;
2172 case HID_DG_TWIST:
2173 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
2174 break;
2175 case HID_DG_ERASER:
2176 case HID_DG_TIPSWITCH:
2177 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
2178 break;
2179 case HID_DG_BARRELSWITCH:
2180 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
2181 break;
2182 case HID_DG_BARRELSWITCH2:
2183 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
2184 break;
2185 case HID_DG_TOOLSERIALNUMBER:
2186 features->quirks |= WACOM_QUIRK_TOOLSERIAL;
2187 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
2188 break;
2189 case WACOM_HID_WD_SENSE:
2190 features->quirks |= WACOM_QUIRK_SENSE;
2191 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
2192 break;
2193 case WACOM_HID_WD_SERIALHI:
2194 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
2196 if (!(features->quirks & WACOM_QUIRK_AESPEN)) {
2197 set_bit(EV_KEY, input->evbit);
2198 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
2199 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
2200 input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
2201 input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
2202 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
2203 if (!(features->device_type & WACOM_DEVICETYPE_DIRECT)) {
2204 input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
2205 input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
2208 break;
2209 case WACOM_HID_WD_FINGERWHEEL:
2210 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2211 break;
2215 static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
2216 struct hid_usage *usage, __s32 value)
2218 struct wacom *wacom = hid_get_drvdata(hdev);
2219 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2220 struct wacom_features *features = &wacom_wac->features;
2221 struct input_dev *input = wacom_wac->pen_input;
2222 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
2224 if (wacom_wac->is_invalid_bt_frame)
2225 return;
2227 switch (equivalent_usage) {
2228 case HID_GD_Z:
2230 * HID_GD_Z "should increase as the control's position is
2231 * moved from high to low", while ABS_DISTANCE instead
2232 * increases in value as the tool moves from low to high.
2234 value = field->logical_maximum - value;
2235 break;
2236 case HID_DG_INRANGE:
2237 wacom_wac->hid_data.inrange_state = value;
2238 if (!(features->quirks & WACOM_QUIRK_SENSE))
2239 wacom_wac->hid_data.sense_state = value;
2240 return;
2241 case HID_DG_INVERT:
2242 wacom_wac->hid_data.invert_state = value;
2243 return;
2244 case HID_DG_ERASER:
2245 case HID_DG_TIPSWITCH:
2246 wacom_wac->hid_data.tipswitch |= value;
2247 return;
2248 case HID_DG_BARRELSWITCH:
2249 wacom_wac->hid_data.barrelswitch = value;
2250 return;
2251 case HID_DG_BARRELSWITCH2:
2252 wacom_wac->hid_data.barrelswitch2 = value;
2253 return;
2254 case HID_DG_TOOLSERIALNUMBER:
2255 if (value) {
2256 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
2257 wacom_wac->serial[0] |= (__u32)value;
2259 return;
2260 case HID_DG_TWIST:
2262 * Userspace expects pen twist to have its zero point when
2263 * the buttons/finger is on the tablet's left. HID values
2264 * are zero when buttons are toward the top.
2266 value = wacom_offset_rotation(input, usage, value, 1, 4);
2267 break;
2268 case WACOM_HID_WD_SENSE:
2269 wacom_wac->hid_data.sense_state = value;
2270 return;
2271 case WACOM_HID_WD_SERIALHI:
2272 if (value) {
2273 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
2274 wacom_wac->serial[0] |= ((__u64)value) << 32;
2276 * Non-USI EMR devices may contain additional tool type
2277 * information here. See WACOM_HID_WD_TOOLTYPE case for
2278 * more details.
2280 if (value >> 20 == 1) {
2281 wacom_wac->id[0] |= value & 0xFFFFF;
2284 return;
2285 case WACOM_HID_WD_TOOLTYPE:
2287 * Some devices (MobileStudio Pro, and possibly later
2288 * devices as well) do not return the complete tool
2289 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
2290 * bitwise OR so the complete value can be built
2291 * up over time :(
2293 wacom_wac->id[0] |= value;
2294 return;
2295 case WACOM_HID_WD_OFFSETLEFT:
2296 if (features->offset_left && value != features->offset_left)
2297 hid_warn(hdev, "%s: overriding existing left offset "
2298 "%d -> %d\n", __func__, value,
2299 features->offset_left);
2300 features->offset_left = value;
2301 return;
2302 case WACOM_HID_WD_OFFSETRIGHT:
2303 if (features->offset_right && value != features->offset_right)
2304 hid_warn(hdev, "%s: overriding existing right offset "
2305 "%d -> %d\n", __func__, value,
2306 features->offset_right);
2307 features->offset_right = value;
2308 return;
2309 case WACOM_HID_WD_OFFSETTOP:
2310 if (features->offset_top && value != features->offset_top)
2311 hid_warn(hdev, "%s: overriding existing top offset "
2312 "%d -> %d\n", __func__, value,
2313 features->offset_top);
2314 features->offset_top = value;
2315 return;
2316 case WACOM_HID_WD_OFFSETBOTTOM:
2317 if (features->offset_bottom && value != features->offset_bottom)
2318 hid_warn(hdev, "%s: overriding existing bottom offset "
2319 "%d -> %d\n", __func__, value,
2320 features->offset_bottom);
2321 features->offset_bottom = value;
2322 return;
2323 case WACOM_HID_WD_REPORT_VALID:
2324 wacom_wac->is_invalid_bt_frame = !value;
2325 return;
2328 /* send pen events only when touch is up or forced out
2329 * or touch arbitration is off
2331 if (!usage->type || delay_pen_events(wacom_wac))
2332 return;
2334 /* send pen events only when the pen is in range */
2335 if (wacom_wac->hid_data.inrange_state)
2336 input_event(input, usage->type, usage->code, value);
2337 else if (wacom_wac->shared->stylus_in_proximity && !wacom_wac->hid_data.sense_state)
2338 input_event(input, usage->type, usage->code, 0);
2341 static void wacom_wac_pen_pre_report(struct hid_device *hdev,
2342 struct hid_report *report)
2344 struct wacom *wacom = hid_get_drvdata(hdev);
2345 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2347 wacom_wac->is_invalid_bt_frame = false;
2348 return;
2351 static void wacom_wac_pen_report(struct hid_device *hdev,
2352 struct hid_report *report)
2354 struct wacom *wacom = hid_get_drvdata(hdev);
2355 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2356 struct input_dev *input = wacom_wac->pen_input;
2357 bool range = wacom_wac->hid_data.inrange_state;
2358 bool sense = wacom_wac->hid_data.sense_state;
2360 if (wacom_wac->is_invalid_bt_frame)
2361 return;
2363 if (!wacom_wac->tool[0] && range) { /* first in range */
2364 /* Going into range select tool */
2365 if (wacom_wac->hid_data.invert_state)
2366 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
2367 else if (wacom_wac->id[0])
2368 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
2369 else
2370 wacom_wac->tool[0] = BTN_TOOL_PEN;
2373 /* keep pen state for touch events */
2374 wacom_wac->shared->stylus_in_proximity = sense;
2376 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
2377 int id = wacom_wac->id[0];
2378 int sw_state = wacom_wac->hid_data.barrelswitch |
2379 (wacom_wac->hid_data.barrelswitch2 << 1);
2381 input_report_key(input, BTN_STYLUS, sw_state == 1);
2382 input_report_key(input, BTN_STYLUS2, sw_state == 2);
2383 input_report_key(input, BTN_STYLUS3, sw_state == 3);
2386 * Non-USI EMR tools should have their IDs mangled to
2387 * match the legacy behavior of wacom_intuos_general
2389 if (wacom_wac->serial[0] >> 52 == 1)
2390 id = wacom_intuos_id_mangle(id);
2393 * To ensure compatibility with xf86-input-wacom, we should
2394 * report the BTN_TOOL_* event prior to the ABS_MISC or
2395 * MSC_SERIAL events.
2397 input_report_key(input, BTN_TOUCH,
2398 wacom_wac->hid_data.tipswitch);
2399 input_report_key(input, wacom_wac->tool[0], sense);
2400 if (wacom_wac->serial[0]) {
2401 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
2402 input_report_abs(input, ABS_MISC, sense ? id : 0);
2405 wacom_wac->hid_data.tipswitch = false;
2407 input_sync(input);
2410 if (!sense) {
2411 wacom_wac->tool[0] = 0;
2412 wacom_wac->id[0] = 0;
2413 wacom_wac->serial[0] = 0;
2417 static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
2418 struct hid_field *field, struct hid_usage *usage)
2420 struct wacom *wacom = hid_get_drvdata(hdev);
2421 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2422 struct input_dev *input = wacom_wac->touch_input;
2423 unsigned touch_max = wacom_wac->features.touch_max;
2424 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
2426 switch (equivalent_usage) {
2427 case HID_GD_X:
2428 if (touch_max == 1)
2429 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
2430 else
2431 wacom_map_usage(input, usage, field, EV_ABS,
2432 ABS_MT_POSITION_X, 4);
2433 break;
2434 case HID_GD_Y:
2435 if (touch_max == 1)
2436 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
2437 else
2438 wacom_map_usage(input, usage, field, EV_ABS,
2439 ABS_MT_POSITION_Y, 4);
2440 break;
2441 case HID_DG_WIDTH:
2442 case HID_DG_HEIGHT:
2443 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
2444 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
2445 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
2446 break;
2447 case HID_DG_TIPSWITCH:
2448 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
2449 break;
2450 case HID_DG_CONTACTCOUNT:
2451 wacom_wac->hid_data.cc_report = field->report->id;
2452 wacom_wac->hid_data.cc_index = field->index;
2453 wacom_wac->hid_data.cc_value_index = usage->usage_index;
2454 break;
2455 case HID_DG_CONTACTID:
2456 if ((field->logical_maximum - field->logical_minimum) < touch_max) {
2458 * The HID descriptor for G11 sensors leaves logical
2459 * maximum set to '1' despite it being a multitouch
2460 * device. Override to a sensible number.
2462 field->logical_maximum = 255;
2464 break;
2468 static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
2469 struct input_dev *input)
2471 struct hid_data *hid_data = &wacom_wac->hid_data;
2472 bool mt = wacom_wac->features.touch_max > 1;
2473 bool prox = hid_data->tipswitch &&
2474 report_touch_events(wacom_wac);
2476 if (wacom_wac->shared->has_mute_touch_switch &&
2477 !wacom_wac->shared->is_touch_on) {
2478 if (!wacom_wac->shared->touch_down)
2479 return;
2480 prox = 0;
2483 wacom_wac->hid_data.num_received++;
2484 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
2485 return;
2487 if (mt) {
2488 int slot;
2490 slot = input_mt_get_slot_by_key(input, hid_data->id);
2491 input_mt_slot(input, slot);
2492 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
2494 else {
2495 input_report_key(input, BTN_TOUCH, prox);
2498 if (prox) {
2499 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
2500 hid_data->x);
2501 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
2502 hid_data->y);
2504 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
2505 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
2506 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
2507 if (hid_data->width != hid_data->height)
2508 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
2513 static void wacom_wac_finger_event(struct hid_device *hdev,
2514 struct hid_field *field, struct hid_usage *usage, __s32 value)
2516 struct wacom *wacom = hid_get_drvdata(hdev);
2517 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2518 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
2520 switch (equivalent_usage) {
2521 case HID_GD_X:
2522 wacom_wac->hid_data.x = value;
2523 break;
2524 case HID_GD_Y:
2525 wacom_wac->hid_data.y = value;
2526 break;
2527 case HID_DG_WIDTH:
2528 wacom_wac->hid_data.width = value;
2529 break;
2530 case HID_DG_HEIGHT:
2531 wacom_wac->hid_data.height = value;
2532 break;
2533 case HID_DG_CONTACTID:
2534 wacom_wac->hid_data.id = value;
2535 break;
2536 case HID_DG_TIPSWITCH:
2537 wacom_wac->hid_data.tipswitch = value;
2538 break;
2542 if (usage->usage_index + 1 == field->report_count) {
2543 if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
2544 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
2548 static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2549 struct hid_report *report)
2551 struct wacom *wacom = hid_get_drvdata(hdev);
2552 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2553 struct hid_data* hid_data = &wacom_wac->hid_data;
2554 int i;
2556 for (i = 0; i < report->maxfield; i++) {
2557 struct hid_field *field = report->field[i];
2558 int j;
2560 for (j = 0; j < field->maxusage; j++) {
2561 struct hid_usage *usage = &field->usage[j];
2562 unsigned int equivalent_usage =
2563 wacom_equivalent_usage(usage->hid);
2565 switch (equivalent_usage) {
2566 case HID_GD_X:
2567 case HID_GD_Y:
2568 case HID_DG_WIDTH:
2569 case HID_DG_HEIGHT:
2570 case HID_DG_CONTACTID:
2571 case HID_DG_INRANGE:
2572 case HID_DG_INVERT:
2573 case HID_DG_TIPSWITCH:
2574 hid_data->last_slot_field = equivalent_usage;
2575 break;
2576 case HID_DG_CONTACTCOUNT:
2577 hid_data->cc_report = report->id;
2578 hid_data->cc_index = i;
2579 hid_data->cc_value_index = j;
2580 break;
2585 if (hid_data->cc_report != 0 &&
2586 hid_data->cc_index >= 0) {
2587 struct hid_field *field = report->field[hid_data->cc_index];
2588 int value = field->value[hid_data->cc_value_index];
2589 if (value)
2590 hid_data->num_expected = value;
2592 else {
2593 hid_data->num_expected = wacom_wac->features.touch_max;
2597 static void wacom_wac_finger_report(struct hid_device *hdev,
2598 struct hid_report *report)
2600 struct wacom *wacom = hid_get_drvdata(hdev);
2601 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2602 struct input_dev *input = wacom_wac->touch_input;
2603 unsigned touch_max = wacom_wac->features.touch_max;
2605 /* If more packets of data are expected, give us a chance to
2606 * process them rather than immediately syncing a partial
2607 * update.
2609 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2610 return;
2612 if (touch_max > 1)
2613 input_mt_sync_frame(input);
2615 input_sync(input);
2616 wacom_wac->hid_data.num_received = 0;
2618 /* keep touch state for pen event */
2619 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
2622 void wacom_wac_usage_mapping(struct hid_device *hdev,
2623 struct hid_field *field, struct hid_usage *usage)
2625 struct wacom *wacom = hid_get_drvdata(hdev);
2626 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2627 struct wacom_features *features = &wacom_wac->features;
2629 if (WACOM_DIRECT_DEVICE(field))
2630 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2632 /* usage tests must precede field tests */
2633 if (WACOM_BATTERY_USAGE(usage))
2634 wacom_wac_battery_usage_mapping(hdev, field, usage);
2635 else if (WACOM_PAD_FIELD(field))
2636 wacom_wac_pad_usage_mapping(hdev, field, usage);
2637 else if (WACOM_PEN_FIELD(field))
2638 wacom_wac_pen_usage_mapping(hdev, field, usage);
2639 else if (WACOM_FINGER_FIELD(field))
2640 wacom_wac_finger_usage_mapping(hdev, field, usage);
2643 void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
2644 struct hid_usage *usage, __s32 value)
2646 struct wacom *wacom = hid_get_drvdata(hdev);
2648 if (wacom->wacom_wac.features.type != HID_GENERIC)
2649 return;
2651 if (value > field->logical_maximum || value < field->logical_minimum)
2652 return;
2654 /* usage tests must precede field tests */
2655 if (WACOM_BATTERY_USAGE(usage))
2656 wacom_wac_battery_event(hdev, field, usage, value);
2657 else if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2658 wacom_wac_pad_event(hdev, field, usage, value);
2659 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2660 wacom_wac_pen_event(hdev, field, usage, value);
2661 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2662 wacom_wac_finger_event(hdev, field, usage, value);
2665 static void wacom_report_events(struct hid_device *hdev,
2666 struct hid_report *report, int collection_index,
2667 int field_index)
2669 int r;
2671 for (r = field_index; r < report->maxfield; r++) {
2672 struct hid_field *field;
2673 unsigned count, n;
2675 field = report->field[r];
2676 count = field->report_count;
2678 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2679 continue;
2681 for (n = 0 ; n < count; n++) {
2682 if (field->usage[n].collection_index == collection_index)
2683 wacom_wac_event(hdev, field, &field->usage[n],
2684 field->value[n]);
2685 else
2686 return;
2691 static int wacom_wac_collection(struct hid_device *hdev, struct hid_report *report,
2692 int collection_index, struct hid_field *field,
2693 int field_index)
2695 struct wacom *wacom = hid_get_drvdata(hdev);
2697 wacom_report_events(hdev, report, collection_index, field_index);
2700 * Non-input reports may be sent prior to the device being
2701 * completely initialized. Since only their events need
2702 * to be processed, exit after 'wacom_report_events' has
2703 * been called to prevent potential crashes in the report-
2704 * processing functions.
2706 if (report->type != HID_INPUT_REPORT)
2707 return -1;
2709 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2710 wacom_wac_pad_report(hdev, report, field);
2711 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2712 wacom_wac_pen_report(hdev, report);
2713 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
2714 wacom_wac_finger_report(hdev, report);
2716 return 0;
2719 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2721 struct wacom *wacom = hid_get_drvdata(hdev);
2722 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2723 struct hid_field *field;
2724 bool pad_in_hid_field = false, pen_in_hid_field = false,
2725 finger_in_hid_field = false;
2726 int r;
2727 int prev_collection = -1;
2729 if (wacom_wac->features.type != HID_GENERIC)
2730 return;
2732 for (r = 0; r < report->maxfield; r++) {
2733 field = report->field[r];
2735 if (WACOM_PAD_FIELD(field))
2736 pad_in_hid_field = true;
2737 if (WACOM_PEN_FIELD(field))
2738 pen_in_hid_field = true;
2739 if (WACOM_FINGER_FIELD(field))
2740 finger_in_hid_field = true;
2743 wacom_wac_battery_pre_report(hdev, report);
2745 if (pad_in_hid_field && wacom->wacom_wac.pad_input)
2746 wacom_wac_pad_pre_report(hdev, report);
2747 if (pen_in_hid_field && wacom->wacom_wac.pen_input)
2748 wacom_wac_pen_pre_report(hdev, report);
2749 if (finger_in_hid_field && wacom->wacom_wac.touch_input)
2750 wacom_wac_finger_pre_report(hdev, report);
2752 for (r = 0; r < report->maxfield; r++) {
2753 field = report->field[r];
2755 if (field->usage[0].collection_index != prev_collection) {
2756 if (wacom_wac_collection(hdev, report,
2757 field->usage[0].collection_index, field, r) < 0)
2758 return;
2759 prev_collection = field->usage[0].collection_index;
2763 wacom_wac_battery_report(hdev, report);
2766 static int wacom_bpt_touch(struct wacom_wac *wacom)
2768 struct wacom_features *features = &wacom->features;
2769 struct input_dev *input = wacom->touch_input;
2770 struct input_dev *pad_input = wacom->pad_input;
2771 unsigned char *data = wacom->data;
2772 int i;
2774 if (data[0] != 0x02)
2775 return 0;
2777 for (i = 0; i < 2; i++) {
2778 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
2779 bool touch = report_touch_events(wacom)
2780 && (data[offset + 3] & 0x80);
2782 input_mt_slot(input, i);
2783 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2784 if (touch) {
2785 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2786 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
2787 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2788 x <<= 5;
2789 y <<= 5;
2791 input_report_abs(input, ABS_MT_POSITION_X, x);
2792 input_report_abs(input, ABS_MT_POSITION_Y, y);
2796 input_mt_sync_frame(input);
2798 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2799 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2800 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2801 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
2802 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2804 return 1;
2807 static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
2809 struct wacom_features *features = &wacom->features;
2810 struct input_dev *input = wacom->touch_input;
2811 bool touch = data[1] & 0x80;
2812 int slot = input_mt_get_slot_by_key(input, data[0]);
2814 if (slot < 0)
2815 return;
2817 touch = touch && report_touch_events(wacom);
2819 input_mt_slot(input, slot);
2820 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2822 if (touch) {
2823 int x = (data[2] << 4) | (data[4] >> 4);
2824 int y = (data[3] << 4) | (data[4] & 0x0f);
2825 int width, height;
2827 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
2828 width = data[5] * 100;
2829 height = data[6] * 100;
2830 } else {
2832 * "a" is a scaled-down area which we assume is
2833 * roughly circular and which can be described as:
2834 * a=(pi*r^2)/C.
2836 int a = data[5];
2837 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2838 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2839 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
2840 height = width * y_res / x_res;
2843 input_report_abs(input, ABS_MT_POSITION_X, x);
2844 input_report_abs(input, ABS_MT_POSITION_Y, y);
2845 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2846 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
2850 static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2852 struct input_dev *input = wacom->pad_input;
2853 struct wacom_features *features = &wacom->features;
2855 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
2856 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
2857 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
2858 } else {
2859 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
2860 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
2862 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
2863 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
2866 static int wacom_bpt3_touch(struct wacom_wac *wacom)
2868 unsigned char *data = wacom->data;
2869 int count = data[1] & 0x07;
2870 int touch_changed = 0, i;
2872 if (data[0] != 0x02)
2873 return 0;
2875 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
2876 for (i = 0; i < count; i++) {
2877 int offset = (8 * i) + 2;
2878 int msg_id = data[offset];
2880 if (msg_id >= 2 && msg_id <= 17) {
2881 wacom_bpt3_touch_msg(wacom, data + offset);
2882 touch_changed++;
2883 } else if (msg_id == 128)
2884 wacom_bpt3_button_msg(wacom, data + offset);
2888 /* only update touch if we actually have a touchpad and touch data changed */
2889 if (wacom->touch_input && touch_changed) {
2890 input_mt_sync_frame(wacom->touch_input);
2891 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2894 return 1;
2897 static int wacom_bpt_pen(struct wacom_wac *wacom)
2899 struct wacom_features *features = &wacom->features;
2900 struct input_dev *input = wacom->pen_input;
2901 unsigned char *data = wacom->data;
2902 int x = 0, y = 0, p = 0, d = 0;
2903 bool pen = false, btn1 = false, btn2 = false;
2904 bool range, prox, rdy;
2906 if (data[0] != WACOM_REPORT_PENABLED)
2907 return 0;
2909 range = (data[1] & 0x80) == 0x80;
2910 prox = (data[1] & 0x40) == 0x40;
2911 rdy = (data[1] & 0x20) == 0x20;
2913 wacom->shared->stylus_in_proximity = range;
2914 if (delay_pen_events(wacom))
2915 return 0;
2917 if (rdy) {
2918 p = le16_to_cpup((__le16 *)&data[6]);
2919 pen = data[1] & 0x01;
2920 btn1 = data[1] & 0x02;
2921 btn2 = data[1] & 0x04;
2923 if (prox) {
2924 x = le16_to_cpup((__le16 *)&data[2]);
2925 y = le16_to_cpup((__le16 *)&data[4]);
2927 if (data[1] & 0x08) {
2928 wacom->tool[0] = BTN_TOOL_RUBBER;
2929 wacom->id[0] = ERASER_DEVICE_ID;
2930 } else {
2931 wacom->tool[0] = BTN_TOOL_PEN;
2932 wacom->id[0] = STYLUS_DEVICE_ID;
2934 wacom->reporting_data = true;
2936 if (range) {
2938 * Convert distance from out prox to distance from tablet.
2939 * distance will be greater than distance_max once
2940 * touching and applying pressure; do not report negative
2941 * distance.
2943 if (data[8] <= features->distance_max)
2944 d = features->distance_max - data[8];
2945 } else {
2946 wacom->id[0] = 0;
2949 if (wacom->reporting_data) {
2950 input_report_key(input, BTN_TOUCH, pen);
2951 input_report_key(input, BTN_STYLUS, btn1);
2952 input_report_key(input, BTN_STYLUS2, btn2);
2954 if (prox || !range) {
2955 input_report_abs(input, ABS_X, x);
2956 input_report_abs(input, ABS_Y, y);
2958 input_report_abs(input, ABS_PRESSURE, p);
2959 input_report_abs(input, ABS_DISTANCE, d);
2961 input_report_key(input, wacom->tool[0], range); /* PEN or RUBBER */
2962 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
2965 if (!range) {
2966 wacom->reporting_data = false;
2969 return 1;
2972 static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
2974 struct wacom_features *features = &wacom->features;
2976 if ((features->type == INTUOSHT2) &&
2977 (features->device_type & WACOM_DEVICETYPE_PEN))
2978 return wacom_intuos_irq(wacom);
2979 else if (len == WACOM_PKGLEN_BBTOUCH)
2980 return wacom_bpt_touch(wacom);
2981 else if (len == WACOM_PKGLEN_BBTOUCH3)
2982 return wacom_bpt3_touch(wacom);
2983 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
2984 return wacom_bpt_pen(wacom);
2986 return 0;
2989 static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
2990 unsigned char *data)
2992 unsigned char prefix;
2995 * We need to reroute the event from the debug interface to the
2996 * pen interface.
2997 * We need to add the report ID to the actual pen report, so we
2998 * temporary overwrite the first byte to prevent having to kzalloc/kfree
2999 * and memcpy the report.
3001 prefix = data[0];
3002 data[0] = WACOM_REPORT_BPAD_PEN;
3005 * actually reroute the event.
3006 * No need to check if wacom->shared->pen is valid, hid_input_report()
3007 * will check for us.
3009 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
3010 WACOM_PKGLEN_PENABLED, 1);
3012 data[0] = prefix;
3015 static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
3016 unsigned char *data)
3018 struct input_dev *input = wacom->touch_input;
3019 unsigned char *finger_data, prefix;
3020 unsigned id;
3021 int x, y;
3022 bool valid;
3024 prefix = data[0];
3026 for (id = 0; id < wacom->features.touch_max; id++) {
3027 valid = !!(prefix & BIT(id)) &&
3028 report_touch_events(wacom);
3030 input_mt_slot(input, id);
3031 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
3033 if (!valid)
3034 continue;
3036 finger_data = data + 1 + id * 3;
3037 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
3038 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
3040 input_report_abs(input, ABS_MT_POSITION_X, x);
3041 input_report_abs(input, ABS_MT_POSITION_Y, y);
3044 input_mt_sync_frame(input);
3046 input_report_key(input, BTN_LEFT, prefix & 0x40);
3047 input_report_key(input, BTN_RIGHT, prefix & 0x80);
3049 /* keep touch state for pen event */
3050 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
3052 return 1;
3055 static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
3057 unsigned char *data = wacom->data;
3059 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
3060 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
3061 (data[0] != WACOM_REPORT_BPAD_TOUCH))
3062 return 0;
3064 if (data[1] & 0x01)
3065 wacom_bamboo_pad_pen_event(wacom, &data[1]);
3067 if (data[1] & 0x02)
3068 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
3070 return 0;
3073 static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
3075 unsigned char *data = wacom->data;
3076 int connected;
3078 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
3079 return 0;
3081 connected = data[1] & 0x01;
3082 if (connected) {
3083 int pid, battery, charging;
3085 if ((wacom->shared->type == INTUOSHT ||
3086 wacom->shared->type == INTUOSHT2) &&
3087 wacom->shared->touch_input &&
3088 wacom->shared->touch_max) {
3089 input_report_switch(wacom->shared->touch_input,
3090 SW_MUTE_DEVICE, data[5] & 0x40);
3091 input_sync(wacom->shared->touch_input);
3094 pid = get_unaligned_be16(&data[6]);
3095 battery = (data[5] & 0x3f) * 100 / 31;
3096 charging = !!(data[5] & 0x80);
3097 if (wacom->pid != pid) {
3098 wacom->pid = pid;
3099 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
3102 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
3103 battery, charging, 1, 0);
3105 } else if (wacom->pid != 0) {
3106 /* disconnected while previously connected */
3107 wacom->pid = 0;
3108 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
3109 wacom_notify_battery(wacom, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
3112 return 0;
3115 static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
3117 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
3118 struct wacom_features *features = &wacom_wac->features;
3119 unsigned char *data = wacom_wac->data;
3121 if (data[0] != WACOM_REPORT_USB)
3122 return 0;
3124 if ((features->type == INTUOSHT ||
3125 features->type == INTUOSHT2) &&
3126 wacom_wac->shared->touch_input &&
3127 features->touch_max) {
3128 input_report_switch(wacom_wac->shared->touch_input,
3129 SW_MUTE_DEVICE, data[8] & 0x40);
3130 input_sync(wacom_wac->shared->touch_input);
3133 if (data[9] & 0x02) { /* wireless module is attached */
3134 int battery = (data[8] & 0x3f) * 100 / 31;
3135 bool charging = !!(data[8] & 0x80);
3137 wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
3138 battery, charging, battery || charging, 1);
3140 if (!wacom->battery.battery &&
3141 !(features->quirks & WACOM_QUIRK_BATTERY)) {
3142 features->quirks |= WACOM_QUIRK_BATTERY;
3143 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
3146 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
3147 wacom->battery.battery) {
3148 features->quirks &= ~WACOM_QUIRK_BATTERY;
3149 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
3150 wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
3152 return 0;
3155 void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
3157 bool sync;
3159 switch (wacom_wac->features.type) {
3160 case PENPARTNER:
3161 sync = wacom_penpartner_irq(wacom_wac);
3162 break;
3164 case PL:
3165 sync = wacom_pl_irq(wacom_wac);
3166 break;
3168 case WACOM_G4:
3169 case GRAPHIRE:
3170 case GRAPHIRE_BT:
3171 case WACOM_MO:
3172 sync = wacom_graphire_irq(wacom_wac);
3173 break;
3175 case PTU:
3176 sync = wacom_ptu_irq(wacom_wac);
3177 break;
3179 case DTU:
3180 sync = wacom_dtu_irq(wacom_wac);
3181 break;
3183 case DTUS:
3184 case DTUSX:
3185 sync = wacom_dtus_irq(wacom_wac);
3186 break;
3188 case INTUOS:
3189 case INTUOS3S:
3190 case INTUOS3:
3191 case INTUOS3L:
3192 case INTUOS4S:
3193 case INTUOS4:
3194 case INTUOS4L:
3195 case CINTIQ:
3196 case WACOM_BEE:
3197 case WACOM_13HD:
3198 case WACOM_21UX2:
3199 case WACOM_22HD:
3200 case WACOM_24HD:
3201 case WACOM_27QHD:
3202 case DTK:
3203 case CINTIQ_HYBRID:
3204 case CINTIQ_COMPANION_2:
3205 sync = wacom_intuos_irq(wacom_wac);
3206 break;
3208 case INTUOS4WL:
3209 sync = wacom_intuos_bt_irq(wacom_wac, len);
3210 break;
3212 case WACOM_24HDT:
3213 case WACOM_27QHDT:
3214 sync = wacom_24hdt_irq(wacom_wac);
3215 break;
3217 case INTUOS5S:
3218 case INTUOS5:
3219 case INTUOS5L:
3220 case INTUOSPS:
3221 case INTUOSPM:
3222 case INTUOSPL:
3223 if (len == WACOM_PKGLEN_BBTOUCH3)
3224 sync = wacom_bpt3_touch(wacom_wac);
3225 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
3226 sync = wacom_status_irq(wacom_wac, len);
3227 else
3228 sync = wacom_intuos_irq(wacom_wac);
3229 break;
3231 case INTUOSP2_BT:
3232 case INTUOSHT3_BT:
3233 sync = wacom_intuos_pro2_bt_irq(wacom_wac, len);
3234 break;
3236 case TABLETPC:
3237 case TABLETPCE:
3238 case TABLETPC2FG:
3239 case MTSCREEN:
3240 case MTTPC:
3241 case MTTPC_B:
3242 sync = wacom_tpc_irq(wacom_wac, len);
3243 break;
3245 case BAMBOO_PT:
3246 case BAMBOO_PEN:
3247 case BAMBOO_TOUCH:
3248 case INTUOSHT:
3249 case INTUOSHT2:
3250 if (wacom_wac->data[0] == WACOM_REPORT_USB)
3251 sync = wacom_status_irq(wacom_wac, len);
3252 else
3253 sync = wacom_bpt_irq(wacom_wac, len);
3254 break;
3256 case BAMBOO_PAD:
3257 sync = wacom_bamboo_pad_irq(wacom_wac, len);
3258 break;
3260 case WIRELESS:
3261 sync = wacom_wireless_irq(wacom_wac, len);
3262 break;
3264 case REMOTE:
3265 sync = false;
3266 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
3267 wacom_remote_status_irq(wacom_wac, len);
3268 else
3269 sync = wacom_remote_irq(wacom_wac, len);
3270 break;
3272 default:
3273 sync = false;
3274 break;
3277 if (sync) {
3278 if (wacom_wac->pen_input)
3279 input_sync(wacom_wac->pen_input);
3280 if (wacom_wac->touch_input)
3281 input_sync(wacom_wac->touch_input);
3282 if (wacom_wac->pad_input)
3283 input_sync(wacom_wac->pad_input);
3287 static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
3289 struct input_dev *input_dev = wacom_wac->pen_input;
3291 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
3293 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3294 __set_bit(BTN_STYLUS, input_dev->keybit);
3295 __set_bit(BTN_STYLUS2, input_dev->keybit);
3297 input_set_abs_params(input_dev, ABS_DISTANCE,
3298 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
3301 static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
3303 struct input_dev *input_dev = wacom_wac->pen_input;
3304 struct wacom_features *features = &wacom_wac->features;
3306 wacom_setup_basic_pro_pen(wacom_wac);
3308 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3309 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
3310 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
3311 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
3313 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
3314 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
3315 input_abs_set_res(input_dev, ABS_TILT_X, 57);
3316 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
3317 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
3320 static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
3322 struct input_dev *input_dev = wacom_wac->pen_input;
3324 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3326 wacom_setup_cintiq(wacom_wac);
3328 __set_bit(BTN_LEFT, input_dev->keybit);
3329 __set_bit(BTN_RIGHT, input_dev->keybit);
3330 __set_bit(BTN_MIDDLE, input_dev->keybit);
3331 __set_bit(BTN_SIDE, input_dev->keybit);
3332 __set_bit(BTN_EXTRA, input_dev->keybit);
3333 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3334 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
3336 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
3337 input_abs_set_res(input_dev, ABS_RZ, 287);
3338 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
3341 void wacom_setup_device_quirks(struct wacom *wacom)
3343 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
3344 struct wacom_features *features = &wacom->wacom_wac.features;
3346 /* The pen and pad share the same interface on most devices */
3347 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
3348 features->type == DTUS ||
3349 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
3350 if (features->device_type & WACOM_DEVICETYPE_PEN)
3351 features->device_type |= WACOM_DEVICETYPE_PAD;
3354 /* touch device found but size is not defined. use default */
3355 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
3356 features->x_max = 1023;
3357 features->y_max = 1023;
3361 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
3362 * touch interface in its HID descriptor. If this is the touch
3363 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
3364 * tablet values.
3366 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
3367 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
3368 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3369 if (features->touch_max)
3370 features->device_type |= WACOM_DEVICETYPE_TOUCH;
3371 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
3372 features->device_type |= WACOM_DEVICETYPE_PAD;
3374 if (features->type == INTUOSHT2) {
3375 features->x_max = features->x_max / 10;
3376 features->y_max = features->y_max / 10;
3378 else {
3379 features->x_max = 4096;
3380 features->y_max = 4096;
3383 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
3384 features->device_type |= WACOM_DEVICETYPE_PAD;
3389 * Hack for the Bamboo One:
3390 * the device presents a PAD/Touch interface as most Bamboos and even
3391 * sends ghosts PAD data on it. However, later, we must disable this
3392 * ghost interface, and we can not detect it unless we set it here
3393 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
3395 if (features->type == BAMBOO_PEN &&
3396 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
3397 features->device_type |= WACOM_DEVICETYPE_PAD;
3400 * Raw Wacom-mode pen and touch events both come from interface
3401 * 0, whose HID descriptor has an application usage of 0xFF0D
3402 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
3403 * out through the HID_GENERIC device created for interface 1,
3404 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
3406 if (features->type == BAMBOO_PAD)
3407 features->device_type = WACOM_DEVICETYPE_TOUCH;
3409 if (features->type == REMOTE)
3410 features->device_type = WACOM_DEVICETYPE_PAD;
3412 if (features->type == INTUOSP2_BT) {
3413 features->device_type |= WACOM_DEVICETYPE_PEN |
3414 WACOM_DEVICETYPE_PAD |
3415 WACOM_DEVICETYPE_TOUCH;
3416 features->quirks |= WACOM_QUIRK_BATTERY;
3419 if (features->type == INTUOSHT3_BT) {
3420 features->device_type |= WACOM_DEVICETYPE_PEN |
3421 WACOM_DEVICETYPE_PAD;
3422 features->quirks |= WACOM_QUIRK_BATTERY;
3425 switch (features->type) {
3426 case PL:
3427 case DTU:
3428 case DTUS:
3429 case DTUSX:
3430 case WACOM_21UX2:
3431 case WACOM_22HD:
3432 case DTK:
3433 case WACOM_24HD:
3434 case WACOM_27QHD:
3435 case CINTIQ_HYBRID:
3436 case CINTIQ_COMPANION_2:
3437 case CINTIQ:
3438 case WACOM_BEE:
3439 case WACOM_13HD:
3440 case WACOM_24HDT:
3441 case WACOM_27QHDT:
3442 case TABLETPC:
3443 case TABLETPCE:
3444 case TABLETPC2FG:
3445 case MTSCREEN:
3446 case MTTPC:
3447 case MTTPC_B:
3448 features->device_type |= WACOM_DEVICETYPE_DIRECT;
3449 break;
3452 if (wacom->hdev->bus == BUS_BLUETOOTH)
3453 features->quirks |= WACOM_QUIRK_BATTERY;
3455 /* quirk for bamboo touch with 2 low res touches */
3456 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
3457 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
3458 features->x_max <<= 5;
3459 features->y_max <<= 5;
3460 features->x_fuzz <<= 5;
3461 features->y_fuzz <<= 5;
3462 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
3465 if (features->type == WIRELESS) {
3466 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
3467 features->quirks |= WACOM_QUIRK_BATTERY;
3471 if (features->type == REMOTE)
3472 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
3474 /* HID descriptor for DTK-2451 / DTH-2452 claims to report lots
3475 * of things it shouldn't. Lets fix up the damage...
3477 if (wacom->hdev->product == 0x382 || wacom->hdev->product == 0x37d) {
3478 features->quirks &= ~WACOM_QUIRK_TOOLSERIAL;
3479 __clear_bit(BTN_TOOL_BRUSH, wacom_wac->pen_input->keybit);
3480 __clear_bit(BTN_TOOL_PENCIL, wacom_wac->pen_input->keybit);
3481 __clear_bit(BTN_TOOL_AIRBRUSH, wacom_wac->pen_input->keybit);
3482 __clear_bit(ABS_Z, wacom_wac->pen_input->absbit);
3483 __clear_bit(ABS_DISTANCE, wacom_wac->pen_input->absbit);
3484 __clear_bit(ABS_TILT_X, wacom_wac->pen_input->absbit);
3485 __clear_bit(ABS_TILT_Y, wacom_wac->pen_input->absbit);
3486 __clear_bit(ABS_WHEEL, wacom_wac->pen_input->absbit);
3487 __clear_bit(ABS_MISC, wacom_wac->pen_input->absbit);
3488 __clear_bit(MSC_SERIAL, wacom_wac->pen_input->mscbit);
3489 __clear_bit(EV_MSC, wacom_wac->pen_input->evbit);
3493 int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
3494 struct wacom_wac *wacom_wac)
3496 struct wacom_features *features = &wacom_wac->features;
3498 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3500 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
3501 return -ENODEV;
3503 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3504 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3505 else
3506 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3508 if (features->type == HID_GENERIC) {
3509 /* setup has already been done; apply otherwise-undetectible quirks */
3510 input_set_capability(input_dev, EV_KEY, BTN_STYLUS3);
3511 return 0;
3514 __set_bit(BTN_TOUCH, input_dev->keybit);
3515 __set_bit(ABS_MISC, input_dev->absbit);
3517 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
3518 features->x_max - features->offset_right,
3519 features->x_fuzz, 0);
3520 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
3521 features->y_max - features->offset_bottom,
3522 features->y_fuzz, 0);
3523 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
3524 features->pressure_max, features->pressure_fuzz, 0);
3526 /* penabled devices have fixed resolution for each model */
3527 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
3528 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
3530 switch (features->type) {
3531 case GRAPHIRE_BT:
3532 __clear_bit(ABS_MISC, input_dev->absbit);
3533 /* fall through */
3535 case WACOM_MO:
3536 case WACOM_G4:
3537 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3538 features->distance_max,
3539 features->distance_fuzz, 0);
3540 /* fall through */
3542 case GRAPHIRE:
3543 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3545 __set_bit(BTN_LEFT, input_dev->keybit);
3546 __set_bit(BTN_RIGHT, input_dev->keybit);
3547 __set_bit(BTN_MIDDLE, input_dev->keybit);
3549 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3550 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3551 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3552 __set_bit(BTN_STYLUS, input_dev->keybit);
3553 __set_bit(BTN_STYLUS2, input_dev->keybit);
3554 break;
3556 case WACOM_27QHD:
3557 case WACOM_24HD:
3558 case DTK:
3559 case WACOM_22HD:
3560 case WACOM_21UX2:
3561 case WACOM_BEE:
3562 case CINTIQ:
3563 case WACOM_13HD:
3564 case CINTIQ_HYBRID:
3565 case CINTIQ_COMPANION_2:
3566 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
3567 input_abs_set_res(input_dev, ABS_Z, 287);
3568 wacom_setup_cintiq(wacom_wac);
3569 break;
3571 case INTUOS3:
3572 case INTUOS3L:
3573 case INTUOS3S:
3574 case INTUOS4:
3575 case INTUOS4WL:
3576 case INTUOS4L:
3577 case INTUOS4S:
3578 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
3579 input_abs_set_res(input_dev, ABS_Z, 287);
3580 /* fall through */
3582 case INTUOS:
3583 wacom_setup_intuos(wacom_wac);
3584 break;
3586 case INTUOS5:
3587 case INTUOS5L:
3588 case INTUOSPM:
3589 case INTUOSPL:
3590 case INTUOS5S:
3591 case INTUOSPS:
3592 case INTUOSP2_BT:
3593 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3594 features->distance_max,
3595 features->distance_fuzz, 0);
3597 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
3598 input_abs_set_res(input_dev, ABS_Z, 287);
3600 wacom_setup_intuos(wacom_wac);
3601 break;
3603 case WACOM_24HDT:
3604 case WACOM_27QHDT:
3605 case MTSCREEN:
3606 case MTTPC:
3607 case MTTPC_B:
3608 case TABLETPC2FG:
3609 case TABLETPC:
3610 case TABLETPCE:
3611 __clear_bit(ABS_MISC, input_dev->absbit);
3612 /* fall through */
3614 case DTUS:
3615 case DTUSX:
3616 case PL:
3617 case DTU:
3618 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3619 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3620 __set_bit(BTN_STYLUS, input_dev->keybit);
3621 __set_bit(BTN_STYLUS2, input_dev->keybit);
3622 break;
3624 case PTU:
3625 __set_bit(BTN_STYLUS2, input_dev->keybit);
3626 /* fall through */
3628 case PENPARTNER:
3629 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3630 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3631 __set_bit(BTN_STYLUS, input_dev->keybit);
3632 break;
3634 case INTUOSHT:
3635 case BAMBOO_PT:
3636 case BAMBOO_PEN:
3637 case INTUOSHT2:
3638 case INTUOSHT3_BT:
3639 if (features->type == INTUOSHT2 ||
3640 features->type == INTUOSHT3_BT) {
3641 wacom_setup_basic_pro_pen(wacom_wac);
3642 } else {
3643 __clear_bit(ABS_MISC, input_dev->absbit);
3644 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3645 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3646 __set_bit(BTN_STYLUS, input_dev->keybit);
3647 __set_bit(BTN_STYLUS2, input_dev->keybit);
3648 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3649 features->distance_max,
3650 features->distance_fuzz, 0);
3652 break;
3653 case BAMBOO_PAD:
3654 __clear_bit(ABS_MISC, input_dev->absbit);
3655 break;
3657 return 0;
3660 int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3661 struct wacom_wac *wacom_wac)
3663 struct wacom_features *features = &wacom_wac->features;
3665 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3667 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3668 return -ENODEV;
3670 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3671 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3672 else
3673 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3675 if (features->type == HID_GENERIC)
3676 /* setup has already been done */
3677 return 0;
3679 __set_bit(BTN_TOUCH, input_dev->keybit);
3681 if (features->touch_max == 1) {
3682 input_set_abs_params(input_dev, ABS_X, 0,
3683 features->x_max, features->x_fuzz, 0);
3684 input_set_abs_params(input_dev, ABS_Y, 0,
3685 features->y_max, features->y_fuzz, 0);
3686 input_abs_set_res(input_dev, ABS_X,
3687 features->x_resolution);
3688 input_abs_set_res(input_dev, ABS_Y,
3689 features->y_resolution);
3691 else if (features->touch_max > 1) {
3692 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3693 features->x_max, features->x_fuzz, 0);
3694 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3695 features->y_max, features->y_fuzz, 0);
3696 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3697 features->x_resolution);
3698 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3699 features->y_resolution);
3702 switch (features->type) {
3703 case INTUOSP2_BT:
3704 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3705 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3707 if (wacom_wac->shared->touch->product == 0x361) {
3708 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3709 0, 12440, 4, 0);
3710 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3711 0, 8640, 4, 0);
3713 else if (wacom_wac->shared->touch->product == 0x360) {
3714 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3715 0, 8960, 4, 0);
3716 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3717 0, 5920, 4, 0);
3719 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
3720 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
3722 /* fall through */
3724 case INTUOS5:
3725 case INTUOS5L:
3726 case INTUOSPM:
3727 case INTUOSPL:
3728 case INTUOS5S:
3729 case INTUOSPS:
3730 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3731 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3732 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3733 break;
3735 case WACOM_24HDT:
3736 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3737 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3738 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3739 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
3740 /* fall through */
3742 case WACOM_27QHDT:
3743 case MTSCREEN:
3744 case MTTPC:
3745 case MTTPC_B:
3746 case TABLETPC2FG:
3747 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
3748 /*fall through */
3750 case TABLETPC:
3751 case TABLETPCE:
3752 break;
3754 case INTUOSHT:
3755 case INTUOSHT2:
3756 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3757 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3758 /* fall through */
3760 case BAMBOO_PT:
3761 case BAMBOO_TOUCH:
3762 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3763 input_set_abs_params(input_dev,
3764 ABS_MT_TOUCH_MAJOR,
3765 0, features->x_max, 0, 0);
3766 input_set_abs_params(input_dev,
3767 ABS_MT_TOUCH_MINOR,
3768 0, features->y_max, 0, 0);
3770 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3771 break;
3773 case BAMBOO_PAD:
3774 input_mt_init_slots(input_dev, features->touch_max,
3775 INPUT_MT_POINTER);
3776 __set_bit(BTN_LEFT, input_dev->keybit);
3777 __set_bit(BTN_RIGHT, input_dev->keybit);
3778 break;
3780 return 0;
3783 static int wacom_numbered_button_to_key(int n)
3785 if (n < 10)
3786 return BTN_0 + n;
3787 else if (n < 16)
3788 return BTN_A + (n-10);
3789 else if (n < 18)
3790 return BTN_BASE + (n-16);
3791 else
3792 return 0;
3795 static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
3796 int button_count)
3798 int i;
3800 for (i = 0; i < button_count; i++) {
3801 int key = wacom_numbered_button_to_key(i);
3803 if (key)
3804 __set_bit(key, input_dev->keybit);
3808 static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3810 struct wacom_led *led;
3811 int i;
3812 bool updated = false;
3815 * 24HD has LED group 1 to the left and LED group 0 to the right.
3816 * So group 0 matches the second half of the buttons and thus the mask
3817 * needs to be shifted.
3819 if (group == 0)
3820 mask >>= 8;
3822 for (i = 0; i < 3; i++) {
3823 led = wacom_led_find(wacom, group, i);
3824 if (!led) {
3825 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3826 i, group);
3827 continue;
3829 if (!updated && mask & BIT(i)) {
3830 led->held = true;
3831 led_trigger_event(&led->trigger, LED_FULL);
3832 } else {
3833 led->held = false;
3838 static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
3839 int mask, int group)
3841 int group_button;
3844 * 21UX2 has LED group 1 to the left and LED group 0
3845 * to the right. We need to reverse the group to match this
3846 * historical behavior.
3848 if (wacom->wacom_wac.features.type == WACOM_21UX2)
3849 group = 1 - group;
3851 group_button = group * (button_count/wacom->led.count);
3853 if (wacom->wacom_wac.features.type == INTUOSP2_BT)
3854 group_button = 8;
3856 return mask & (1 << group_button);
3859 static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
3860 int group)
3862 struct wacom_led *led, *next_led;
3863 int cur;
3864 bool pressed;
3866 if (wacom->wacom_wac.features.type == WACOM_24HD)
3867 return wacom_24hd_update_leds(wacom, mask, group);
3869 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
3870 cur = wacom->led.groups[group].select;
3872 led = wacom_led_find(wacom, group, cur);
3873 if (!led) {
3874 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
3875 cur, group);
3876 return;
3879 if (!pressed) {
3880 led->held = false;
3881 return;
3884 if (led->held && pressed)
3885 return;
3887 next_led = wacom_led_next(wacom, led);
3888 if (!next_led) {
3889 hid_err(wacom->hdev, "can't find next LED in group %d\n",
3890 group);
3891 return;
3893 if (next_led == led)
3894 return;
3896 next_led->held = true;
3897 led_trigger_event(&next_led->trigger,
3898 wacom_leds_brightness_get(next_led));
3901 static void wacom_report_numbered_buttons(struct input_dev *input_dev,
3902 int button_count, int mask)
3904 struct wacom *wacom = input_get_drvdata(input_dev);
3905 int i;
3907 for (i = 0; i < wacom->led.count; i++)
3908 wacom_update_led(wacom, button_count, mask, i);
3910 for (i = 0; i < button_count; i++) {
3911 int key = wacom_numbered_button_to_key(i);
3913 if (key)
3914 input_report_key(input_dev, key, mask & (1 << i));
3918 int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3919 struct wacom_wac *wacom_wac)
3921 struct wacom_features *features = &wacom_wac->features;
3923 if ((features->type == HID_GENERIC) && features->numbered_buttons > 0)
3924 features->device_type |= WACOM_DEVICETYPE_PAD;
3926 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
3927 return -ENODEV;
3929 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
3930 return -ENODEV;
3932 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3934 /* kept for making legacy xf86-input-wacom working with the wheels */
3935 __set_bit(ABS_MISC, input_dev->absbit);
3937 /* kept for making legacy xf86-input-wacom accepting the pad */
3938 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
3939 input_dev->absinfo[ABS_X].maximum)))
3940 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
3941 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
3942 input_dev->absinfo[ABS_Y].maximum)))
3943 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
3945 /* kept for making udev and libwacom accepting the pad */
3946 __set_bit(BTN_STYLUS, input_dev->keybit);
3948 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
3950 switch (features->type) {
3952 case CINTIQ_HYBRID:
3953 case CINTIQ_COMPANION_2:
3954 case DTK:
3955 case DTUS:
3956 case GRAPHIRE_BT:
3957 break;
3959 case WACOM_MO:
3960 __set_bit(BTN_BACK, input_dev->keybit);
3961 __set_bit(BTN_LEFT, input_dev->keybit);
3962 __set_bit(BTN_FORWARD, input_dev->keybit);
3963 __set_bit(BTN_RIGHT, input_dev->keybit);
3964 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3965 break;
3967 case WACOM_G4:
3968 __set_bit(BTN_BACK, input_dev->keybit);
3969 __set_bit(BTN_FORWARD, input_dev->keybit);
3970 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3971 break;
3973 case WACOM_24HD:
3974 __set_bit(KEY_PROG1, input_dev->keybit);
3975 __set_bit(KEY_PROG2, input_dev->keybit);
3976 __set_bit(KEY_PROG3, input_dev->keybit);
3978 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3979 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
3980 break;
3982 case WACOM_27QHD:
3983 __set_bit(KEY_PROG1, input_dev->keybit);
3984 __set_bit(KEY_PROG2, input_dev->keybit);
3985 __set_bit(KEY_PROG3, input_dev->keybit);
3986 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
3987 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
3988 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
3989 input_abs_set_res(input_dev, ABS_Y, 1024);
3990 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
3991 input_abs_set_res(input_dev, ABS_Z, 1024);
3992 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
3993 break;
3995 case WACOM_22HD:
3996 __set_bit(KEY_PROG1, input_dev->keybit);
3997 __set_bit(KEY_PROG2, input_dev->keybit);
3998 __set_bit(KEY_PROG3, input_dev->keybit);
3999 /* fall through */
4001 case WACOM_21UX2:
4002 case WACOM_BEE:
4003 case CINTIQ:
4004 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
4005 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
4006 break;
4008 case WACOM_13HD:
4009 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4010 break;
4012 case INTUOS3:
4013 case INTUOS3L:
4014 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
4015 /* fall through */
4017 case INTUOS3S:
4018 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
4019 break;
4021 case INTUOS5:
4022 case INTUOS5L:
4023 case INTUOSPM:
4024 case INTUOSPL:
4025 case INTUOS5S:
4026 case INTUOSPS:
4027 case INTUOSP2_BT:
4028 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4029 break;
4031 case INTUOS4WL:
4033 * For Bluetooth devices, the udev rule does not work correctly
4034 * for pads unless we add a stylus capability, which forces
4035 * ID_INPUT_TABLET to be set.
4037 __set_bit(BTN_STYLUS, input_dev->keybit);
4038 /* fall through */
4040 case INTUOS4:
4041 case INTUOS4L:
4042 case INTUOS4S:
4043 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4044 break;
4046 case INTUOSHT:
4047 case BAMBOO_PT:
4048 case BAMBOO_TOUCH:
4049 case INTUOSHT2:
4050 __clear_bit(ABS_MISC, input_dev->absbit);
4052 __set_bit(BTN_LEFT, input_dev->keybit);
4053 __set_bit(BTN_FORWARD, input_dev->keybit);
4054 __set_bit(BTN_BACK, input_dev->keybit);
4055 __set_bit(BTN_RIGHT, input_dev->keybit);
4057 break;
4059 case REMOTE:
4060 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
4061 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4062 break;
4064 case INTUOSHT3_BT:
4065 case HID_GENERIC:
4066 break;
4068 default:
4069 /* no pad supported */
4070 return -ENODEV;
4072 return 0;
4075 static const struct wacom_features wacom_features_0x00 =
4076 { "Wacom Penpartner", 5040, 3780, 255, 0,
4077 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
4078 static const struct wacom_features wacom_features_0x10 =
4079 { "Wacom Graphire", 10206, 7422, 511, 63,
4080 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4081 static const struct wacom_features wacom_features_0x81 =
4082 { "Wacom Graphire BT", 16704, 12064, 511, 32,
4083 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
4084 static const struct wacom_features wacom_features_0x11 =
4085 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
4086 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4087 static const struct wacom_features wacom_features_0x12 =
4088 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
4089 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4090 static const struct wacom_features wacom_features_0x13 =
4091 { "Wacom Graphire3", 10208, 7424, 511, 63,
4092 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4093 static const struct wacom_features wacom_features_0x14 =
4094 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
4095 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4096 static const struct wacom_features wacom_features_0x15 =
4097 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
4098 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4099 static const struct wacom_features wacom_features_0x16 =
4100 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
4101 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4102 static const struct wacom_features wacom_features_0x17 =
4103 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
4104 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4105 static const struct wacom_features wacom_features_0x18 =
4106 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
4107 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4108 static const struct wacom_features wacom_features_0x19 =
4109 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
4110 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
4111 static const struct wacom_features wacom_features_0x60 =
4112 { "Wacom Volito", 5104, 3712, 511, 63,
4113 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
4114 static const struct wacom_features wacom_features_0x61 =
4115 { "Wacom PenStation2", 3250, 2320, 255, 63,
4116 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
4117 static const struct wacom_features wacom_features_0x62 =
4118 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
4119 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
4120 static const struct wacom_features wacom_features_0x63 =
4121 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
4122 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
4123 static const struct wacom_features wacom_features_0x64 =
4124 { "Wacom PenPartner2", 3250, 2320, 511, 63,
4125 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
4126 static const struct wacom_features wacom_features_0x65 =
4127 { "Wacom Bamboo", 14760, 9225, 511, 63,
4128 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4129 static const struct wacom_features wacom_features_0x69 =
4130 { "Wacom Bamboo1", 5104, 3712, 511, 63,
4131 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
4132 static const struct wacom_features wacom_features_0x6A =
4133 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
4134 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4135 static const struct wacom_features wacom_features_0x6B =
4136 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
4137 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4138 static const struct wacom_features wacom_features_0x20 =
4139 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
4140 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4141 static const struct wacom_features wacom_features_0x21 =
4142 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
4143 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4144 static const struct wacom_features wacom_features_0x22 =
4145 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
4146 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4147 static const struct wacom_features wacom_features_0x23 =
4148 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
4149 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4150 static const struct wacom_features wacom_features_0x24 =
4151 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
4152 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4153 static const struct wacom_features wacom_features_0x30 =
4154 { "Wacom PL400", 5408, 4056, 255, 0,
4155 PL, WACOM_PL_RES, WACOM_PL_RES };
4156 static const struct wacom_features wacom_features_0x31 =
4157 { "Wacom PL500", 6144, 4608, 255, 0,
4158 PL, WACOM_PL_RES, WACOM_PL_RES };
4159 static const struct wacom_features wacom_features_0x32 =
4160 { "Wacom PL600", 6126, 4604, 255, 0,
4161 PL, WACOM_PL_RES, WACOM_PL_RES };
4162 static const struct wacom_features wacom_features_0x33 =
4163 { "Wacom PL600SX", 6260, 5016, 255, 0,
4164 PL, WACOM_PL_RES, WACOM_PL_RES };
4165 static const struct wacom_features wacom_features_0x34 =
4166 { "Wacom PL550", 6144, 4608, 511, 0,
4167 PL, WACOM_PL_RES, WACOM_PL_RES };
4168 static const struct wacom_features wacom_features_0x35 =
4169 { "Wacom PL800", 7220, 5780, 511, 0,
4170 PL, WACOM_PL_RES, WACOM_PL_RES };
4171 static const struct wacom_features wacom_features_0x37 =
4172 { "Wacom PL700", 6758, 5406, 511, 0,
4173 PL, WACOM_PL_RES, WACOM_PL_RES };
4174 static const struct wacom_features wacom_features_0x38 =
4175 { "Wacom PL510", 6282, 4762, 511, 0,
4176 PL, WACOM_PL_RES, WACOM_PL_RES };
4177 static const struct wacom_features wacom_features_0x39 =
4178 { "Wacom DTU710", 34080, 27660, 511, 0,
4179 PL, WACOM_PL_RES, WACOM_PL_RES };
4180 static const struct wacom_features wacom_features_0xC4 =
4181 { "Wacom DTF521", 6282, 4762, 511, 0,
4182 PL, WACOM_PL_RES, WACOM_PL_RES };
4183 static const struct wacom_features wacom_features_0xC0 =
4184 { "Wacom DTF720", 6858, 5506, 511, 0,
4185 PL, WACOM_PL_RES, WACOM_PL_RES };
4186 static const struct wacom_features wacom_features_0xC2 =
4187 { "Wacom DTF720a", 6858, 5506, 511, 0,
4188 PL, WACOM_PL_RES, WACOM_PL_RES };
4189 static const struct wacom_features wacom_features_0x03 =
4190 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
4191 PTU, WACOM_PL_RES, WACOM_PL_RES };
4192 static const struct wacom_features wacom_features_0x41 =
4193 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
4194 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4195 static const struct wacom_features wacom_features_0x42 =
4196 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4197 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4198 static const struct wacom_features wacom_features_0x43 =
4199 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
4200 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4201 static const struct wacom_features wacom_features_0x44 =
4202 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
4203 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4204 static const struct wacom_features wacom_features_0x45 =
4205 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
4206 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4207 static const struct wacom_features wacom_features_0xB0 =
4208 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
4209 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
4210 static const struct wacom_features wacom_features_0xB1 =
4211 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
4212 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
4213 static const struct wacom_features wacom_features_0xB2 =
4214 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
4215 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
4216 static const struct wacom_features wacom_features_0xB3 =
4217 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
4218 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
4219 static const struct wacom_features wacom_features_0xB4 =
4220 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
4221 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
4222 static const struct wacom_features wacom_features_0xB5 =
4223 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
4224 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
4225 static const struct wacom_features wacom_features_0xB7 =
4226 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
4227 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
4228 static const struct wacom_features wacom_features_0xB8 =
4229 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
4230 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
4231 static const struct wacom_features wacom_features_0xB9 =
4232 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
4233 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
4234 static const struct wacom_features wacom_features_0xBA =
4235 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
4236 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
4237 static const struct wacom_features wacom_features_0xBB =
4238 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
4239 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
4240 static const struct wacom_features wacom_features_0xBC =
4241 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
4242 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
4243 static const struct wacom_features wacom_features_0xBD =
4244 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
4245 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
4246 static const struct wacom_features wacom_features_0x26 =
4247 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
4248 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
4249 static const struct wacom_features wacom_features_0x27 =
4250 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
4251 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
4252 static const struct wacom_features wacom_features_0x28 =
4253 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
4254 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
4255 static const struct wacom_features wacom_features_0x29 =
4256 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
4257 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
4258 static const struct wacom_features wacom_features_0x2A =
4259 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
4260 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
4261 static const struct wacom_features wacom_features_0x314 =
4262 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
4263 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
4264 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4265 static const struct wacom_features wacom_features_0x315 =
4266 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
4267 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
4268 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4269 static const struct wacom_features wacom_features_0x317 =
4270 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
4271 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
4272 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4273 static const struct wacom_features wacom_features_0xF4 =
4274 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
4275 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
4276 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4277 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
4278 static const struct wacom_features wacom_features_0xF8 =
4279 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
4280 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
4281 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4282 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4283 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
4284 static const struct wacom_features wacom_features_0xF6 =
4285 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
4286 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
4287 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4288 static const struct wacom_features wacom_features_0x32A =
4289 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
4290 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
4291 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4292 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
4293 static const struct wacom_features wacom_features_0x32B =
4294 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
4295 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
4296 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4297 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4298 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
4299 static const struct wacom_features wacom_features_0x32C =
4300 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
4301 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
4302 static const struct wacom_features wacom_features_0x3F =
4303 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
4304 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
4305 static const struct wacom_features wacom_features_0xC5 =
4306 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
4307 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
4308 static const struct wacom_features wacom_features_0xC6 =
4309 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
4310 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
4311 static const struct wacom_features wacom_features_0x304 =
4312 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
4313 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
4314 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4315 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
4316 static const struct wacom_features wacom_features_0x333 =
4317 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
4318 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
4319 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4320 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4321 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
4322 static const struct wacom_features wacom_features_0x335 =
4323 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
4324 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
4325 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4326 static const struct wacom_features wacom_features_0xC7 =
4327 { "Wacom DTU1931", 37832, 30305, 511, 0,
4328 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4329 static const struct wacom_features wacom_features_0xCE =
4330 { "Wacom DTU2231", 47864, 27011, 511, 0,
4331 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4332 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
4333 static const struct wacom_features wacom_features_0xF0 =
4334 { "Wacom DTU1631", 34623, 19553, 511, 0,
4335 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4336 static const struct wacom_features wacom_features_0xFB =
4337 { "Wacom DTU1031", 22096, 13960, 511, 0,
4338 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
4339 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
4340 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
4341 static const struct wacom_features wacom_features_0x32F =
4342 { "Wacom DTU1031X", 22672, 12928, 511, 0,
4343 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
4344 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
4345 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
4346 static const struct wacom_features wacom_features_0x336 =
4347 { "Wacom DTU1141", 23672, 13403, 1023, 0,
4348 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
4349 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
4350 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
4351 static const struct wacom_features wacom_features_0x57 =
4352 { "Wacom DTK2241", 95840, 54260, 2047, 63,
4353 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
4354 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4355 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
4356 static const struct wacom_features wacom_features_0x59 = /* Pen */
4357 { "Wacom DTH2242", 95840, 54260, 2047, 63,
4358 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
4359 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4360 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4361 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
4362 static const struct wacom_features wacom_features_0x5D = /* Touch */
4363 { "Wacom DTH2242", .type = WACOM_24HDT,
4364 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
4365 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4366 static const struct wacom_features wacom_features_0xCC =
4367 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
4368 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
4369 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4370 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
4371 static const struct wacom_features wacom_features_0xFA =
4372 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
4373 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
4374 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4375 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
4376 static const struct wacom_features wacom_features_0x5B =
4377 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
4378 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
4379 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4380 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4381 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
4382 static const struct wacom_features wacom_features_0x5E =
4383 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
4384 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
4385 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4386 static const struct wacom_features wacom_features_0x90 =
4387 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
4388 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
4389 static const struct wacom_features wacom_features_0x93 =
4390 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
4391 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
4392 static const struct wacom_features wacom_features_0x97 =
4393 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
4394 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
4395 static const struct wacom_features wacom_features_0x9A =
4396 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
4397 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
4398 static const struct wacom_features wacom_features_0x9F =
4399 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
4400 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
4401 static const struct wacom_features wacom_features_0xE2 =
4402 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
4403 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4404 static const struct wacom_features wacom_features_0xE3 =
4405 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
4406 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4407 static const struct wacom_features wacom_features_0xE5 =
4408 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
4409 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4410 static const struct wacom_features wacom_features_0xE6 =
4411 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
4412 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4413 static const struct wacom_features wacom_features_0xEC =
4414 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
4415 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
4416 static const struct wacom_features wacom_features_0xED =
4417 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
4418 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
4419 static const struct wacom_features wacom_features_0xEF =
4420 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
4421 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
4422 static const struct wacom_features wacom_features_0x100 =
4423 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
4424 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4425 static const struct wacom_features wacom_features_0x101 =
4426 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
4427 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4428 static const struct wacom_features wacom_features_0x10D =
4429 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
4430 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4431 static const struct wacom_features wacom_features_0x10E =
4432 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
4433 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4434 static const struct wacom_features wacom_features_0x10F =
4435 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
4436 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4437 static const struct wacom_features wacom_features_0x116 =
4438 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
4439 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
4440 static const struct wacom_features wacom_features_0x12C =
4441 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
4442 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
4443 static const struct wacom_features wacom_features_0x4001 =
4444 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
4445 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4446 static const struct wacom_features wacom_features_0x4004 =
4447 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
4448 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4449 static const struct wacom_features wacom_features_0x5000 =
4450 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
4451 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4452 static const struct wacom_features wacom_features_0x5002 =
4453 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
4454 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4455 static const struct wacom_features wacom_features_0x47 =
4456 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4457 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4458 static const struct wacom_features wacom_features_0x84 =
4459 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
4460 static const struct wacom_features wacom_features_0xD0 =
4461 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
4462 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4463 static const struct wacom_features wacom_features_0xD1 =
4464 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
4465 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4466 static const struct wacom_features wacom_features_0xD2 =
4467 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
4468 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4469 static const struct wacom_features wacom_features_0xD3 =
4470 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
4471 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4472 static const struct wacom_features wacom_features_0xD4 =
4473 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
4474 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4475 static const struct wacom_features wacom_features_0xD5 =
4476 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
4477 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4478 static const struct wacom_features wacom_features_0xD6 =
4479 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
4480 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4481 static const struct wacom_features wacom_features_0xD7 =
4482 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
4483 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4484 static const struct wacom_features wacom_features_0xD8 =
4485 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
4486 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4487 static const struct wacom_features wacom_features_0xDA =
4488 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
4489 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4490 static const struct wacom_features wacom_features_0xDB =
4491 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
4492 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
4493 static const struct wacom_features wacom_features_0xDD =
4494 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
4495 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4496 static const struct wacom_features wacom_features_0xDE =
4497 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
4498 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
4499 static const struct wacom_features wacom_features_0xDF =
4500 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
4501 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
4502 static const struct wacom_features wacom_features_0x300 =
4503 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
4504 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4505 static const struct wacom_features wacom_features_0x301 =
4506 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
4507 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4508 static const struct wacom_features wacom_features_0x302 =
4509 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
4510 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4511 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4512 static const struct wacom_features wacom_features_0x303 =
4513 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
4514 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4515 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4516 static const struct wacom_features wacom_features_0x30E =
4517 { "Wacom Intuos S", 15200, 9500, 1023, 31,
4518 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4519 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4520 static const struct wacom_features wacom_features_0x6004 =
4521 { "ISD-V4", 12800, 8000, 255, 0,
4522 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4523 static const struct wacom_features wacom_features_0x307 =
4524 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
4525 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
4526 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4527 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4528 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
4529 static const struct wacom_features wacom_features_0x309 =
4530 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
4531 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
4532 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4533 static const struct wacom_features wacom_features_0x30A =
4534 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
4535 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
4536 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4537 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4538 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
4539 static const struct wacom_features wacom_features_0x30C =
4540 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
4541 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
4542 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4543 static const struct wacom_features wacom_features_0x318 =
4544 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
4545 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
4546 static const struct wacom_features wacom_features_0x319 =
4547 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
4548 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
4549 static const struct wacom_features wacom_features_0x325 =
4550 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
4551 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
4552 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4553 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
4554 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
4555 static const struct wacom_features wacom_features_0x326 = /* Touch */
4556 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
4557 .oPid = 0x325 };
4558 static const struct wacom_features wacom_features_0x323 =
4559 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
4560 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4561 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4562 static const struct wacom_features wacom_features_0x331 =
4563 { "Wacom Express Key Remote", .type = REMOTE,
4564 .numbered_buttons = 18, .check_for_hid_type = true,
4565 .hid_type = HID_TYPE_USBNONE };
4566 static const struct wacom_features wacom_features_0x33B =
4567 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
4568 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4569 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4570 static const struct wacom_features wacom_features_0x33C =
4571 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
4572 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4573 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4574 static const struct wacom_features wacom_features_0x33D =
4575 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
4576 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4577 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4578 static const struct wacom_features wacom_features_0x33E =
4579 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
4580 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4581 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4582 static const struct wacom_features wacom_features_0x343 =
4583 { "Wacom DTK1651", 34816, 19759, 1023, 0,
4584 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
4585 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
4586 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
4587 static const struct wacom_features wacom_features_0x360 =
4588 { "Wacom Intuos Pro M", 44800, 29600, 8191, 63,
4589 INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
4590 static const struct wacom_features wacom_features_0x361 =
4591 { "Wacom Intuos Pro L", 62200, 43200, 8191, 63,
4592 INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
4593 static const struct wacom_features wacom_features_0x377 =
4594 { "Wacom Intuos BT S", 15200, 9500, 4095, 63,
4595 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
4596 static const struct wacom_features wacom_features_0x379 =
4597 { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
4598 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
4599 static const struct wacom_features wacom_features_0x37A =
4600 { "Wacom One by Wacom S", 15200, 9500, 2047, 63,
4601 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4602 static const struct wacom_features wacom_features_0x37B =
4603 { "Wacom One by Wacom M", 21600, 13500, 2047, 63,
4604 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4606 static const struct wacom_features wacom_features_HID_ANY_ID =
4607 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
4609 #define USB_DEVICE_WACOM(prod) \
4610 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4611 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4613 #define BT_DEVICE_WACOM(prod) \
4614 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4615 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4617 #define I2C_DEVICE_WACOM(prod) \
4618 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4619 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4621 #define USB_DEVICE_LENOVO(prod) \
4622 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
4623 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4625 const struct hid_device_id wacom_ids[] = {
4626 { USB_DEVICE_WACOM(0x00) },
4627 { USB_DEVICE_WACOM(0x03) },
4628 { USB_DEVICE_WACOM(0x10) },
4629 { USB_DEVICE_WACOM(0x11) },
4630 { USB_DEVICE_WACOM(0x12) },
4631 { USB_DEVICE_WACOM(0x13) },
4632 { USB_DEVICE_WACOM(0x14) },
4633 { USB_DEVICE_WACOM(0x15) },
4634 { USB_DEVICE_WACOM(0x16) },
4635 { USB_DEVICE_WACOM(0x17) },
4636 { USB_DEVICE_WACOM(0x18) },
4637 { USB_DEVICE_WACOM(0x19) },
4638 { USB_DEVICE_WACOM(0x20) },
4639 { USB_DEVICE_WACOM(0x21) },
4640 { USB_DEVICE_WACOM(0x22) },
4641 { USB_DEVICE_WACOM(0x23) },
4642 { USB_DEVICE_WACOM(0x24) },
4643 { USB_DEVICE_WACOM(0x26) },
4644 { USB_DEVICE_WACOM(0x27) },
4645 { USB_DEVICE_WACOM(0x28) },
4646 { USB_DEVICE_WACOM(0x29) },
4647 { USB_DEVICE_WACOM(0x2A) },
4648 { USB_DEVICE_WACOM(0x30) },
4649 { USB_DEVICE_WACOM(0x31) },
4650 { USB_DEVICE_WACOM(0x32) },
4651 { USB_DEVICE_WACOM(0x33) },
4652 { USB_DEVICE_WACOM(0x34) },
4653 { USB_DEVICE_WACOM(0x35) },
4654 { USB_DEVICE_WACOM(0x37) },
4655 { USB_DEVICE_WACOM(0x38) },
4656 { USB_DEVICE_WACOM(0x39) },
4657 { USB_DEVICE_WACOM(0x3F) },
4658 { USB_DEVICE_WACOM(0x41) },
4659 { USB_DEVICE_WACOM(0x42) },
4660 { USB_DEVICE_WACOM(0x43) },
4661 { USB_DEVICE_WACOM(0x44) },
4662 { USB_DEVICE_WACOM(0x45) },
4663 { USB_DEVICE_WACOM(0x47) },
4664 { USB_DEVICE_WACOM(0x57) },
4665 { USB_DEVICE_WACOM(0x59) },
4666 { USB_DEVICE_WACOM(0x5B) },
4667 { USB_DEVICE_WACOM(0x5D) },
4668 { USB_DEVICE_WACOM(0x5E) },
4669 { USB_DEVICE_WACOM(0x60) },
4670 { USB_DEVICE_WACOM(0x61) },
4671 { USB_DEVICE_WACOM(0x62) },
4672 { USB_DEVICE_WACOM(0x63) },
4673 { USB_DEVICE_WACOM(0x64) },
4674 { USB_DEVICE_WACOM(0x65) },
4675 { USB_DEVICE_WACOM(0x69) },
4676 { USB_DEVICE_WACOM(0x6A) },
4677 { USB_DEVICE_WACOM(0x6B) },
4678 { BT_DEVICE_WACOM(0x81) },
4679 { USB_DEVICE_WACOM(0x84) },
4680 { USB_DEVICE_WACOM(0x90) },
4681 { USB_DEVICE_WACOM(0x93) },
4682 { USB_DEVICE_WACOM(0x97) },
4683 { USB_DEVICE_WACOM(0x9A) },
4684 { USB_DEVICE_WACOM(0x9F) },
4685 { USB_DEVICE_WACOM(0xB0) },
4686 { USB_DEVICE_WACOM(0xB1) },
4687 { USB_DEVICE_WACOM(0xB2) },
4688 { USB_DEVICE_WACOM(0xB3) },
4689 { USB_DEVICE_WACOM(0xB4) },
4690 { USB_DEVICE_WACOM(0xB5) },
4691 { USB_DEVICE_WACOM(0xB7) },
4692 { USB_DEVICE_WACOM(0xB8) },
4693 { USB_DEVICE_WACOM(0xB9) },
4694 { USB_DEVICE_WACOM(0xBA) },
4695 { USB_DEVICE_WACOM(0xBB) },
4696 { USB_DEVICE_WACOM(0xBC) },
4697 { BT_DEVICE_WACOM(0xBD) },
4698 { USB_DEVICE_WACOM(0xC0) },
4699 { USB_DEVICE_WACOM(0xC2) },
4700 { USB_DEVICE_WACOM(0xC4) },
4701 { USB_DEVICE_WACOM(0xC5) },
4702 { USB_DEVICE_WACOM(0xC6) },
4703 { USB_DEVICE_WACOM(0xC7) },
4704 { USB_DEVICE_WACOM(0xCC) },
4705 { USB_DEVICE_WACOM(0xCE) },
4706 { USB_DEVICE_WACOM(0xD0) },
4707 { USB_DEVICE_WACOM(0xD1) },
4708 { USB_DEVICE_WACOM(0xD2) },
4709 { USB_DEVICE_WACOM(0xD3) },
4710 { USB_DEVICE_WACOM(0xD4) },
4711 { USB_DEVICE_WACOM(0xD5) },
4712 { USB_DEVICE_WACOM(0xD6) },
4713 { USB_DEVICE_WACOM(0xD7) },
4714 { USB_DEVICE_WACOM(0xD8) },
4715 { USB_DEVICE_WACOM(0xDA) },
4716 { USB_DEVICE_WACOM(0xDB) },
4717 { USB_DEVICE_WACOM(0xDD) },
4718 { USB_DEVICE_WACOM(0xDE) },
4719 { USB_DEVICE_WACOM(0xDF) },
4720 { USB_DEVICE_WACOM(0xE2) },
4721 { USB_DEVICE_WACOM(0xE3) },
4722 { USB_DEVICE_WACOM(0xE5) },
4723 { USB_DEVICE_WACOM(0xE6) },
4724 { USB_DEVICE_WACOM(0xEC) },
4725 { USB_DEVICE_WACOM(0xED) },
4726 { USB_DEVICE_WACOM(0xEF) },
4727 { USB_DEVICE_WACOM(0xF0) },
4728 { USB_DEVICE_WACOM(0xF4) },
4729 { USB_DEVICE_WACOM(0xF6) },
4730 { USB_DEVICE_WACOM(0xF8) },
4731 { USB_DEVICE_WACOM(0xFA) },
4732 { USB_DEVICE_WACOM(0xFB) },
4733 { USB_DEVICE_WACOM(0x100) },
4734 { USB_DEVICE_WACOM(0x101) },
4735 { USB_DEVICE_WACOM(0x10D) },
4736 { USB_DEVICE_WACOM(0x10E) },
4737 { USB_DEVICE_WACOM(0x10F) },
4738 { USB_DEVICE_WACOM(0x116) },
4739 { USB_DEVICE_WACOM(0x12C) },
4740 { USB_DEVICE_WACOM(0x300) },
4741 { USB_DEVICE_WACOM(0x301) },
4742 { USB_DEVICE_WACOM(0x302) },
4743 { USB_DEVICE_WACOM(0x303) },
4744 { USB_DEVICE_WACOM(0x304) },
4745 { USB_DEVICE_WACOM(0x307) },
4746 { USB_DEVICE_WACOM(0x309) },
4747 { USB_DEVICE_WACOM(0x30A) },
4748 { USB_DEVICE_WACOM(0x30C) },
4749 { USB_DEVICE_WACOM(0x30E) },
4750 { USB_DEVICE_WACOM(0x314) },
4751 { USB_DEVICE_WACOM(0x315) },
4752 { USB_DEVICE_WACOM(0x317) },
4753 { USB_DEVICE_WACOM(0x318) },
4754 { USB_DEVICE_WACOM(0x319) },
4755 { USB_DEVICE_WACOM(0x323) },
4756 { USB_DEVICE_WACOM(0x325) },
4757 { USB_DEVICE_WACOM(0x326) },
4758 { USB_DEVICE_WACOM(0x32A) },
4759 { USB_DEVICE_WACOM(0x32B) },
4760 { USB_DEVICE_WACOM(0x32C) },
4761 { USB_DEVICE_WACOM(0x32F) },
4762 { USB_DEVICE_WACOM(0x331) },
4763 { USB_DEVICE_WACOM(0x333) },
4764 { USB_DEVICE_WACOM(0x335) },
4765 { USB_DEVICE_WACOM(0x336) },
4766 { USB_DEVICE_WACOM(0x33B) },
4767 { USB_DEVICE_WACOM(0x33C) },
4768 { USB_DEVICE_WACOM(0x33D) },
4769 { USB_DEVICE_WACOM(0x33E) },
4770 { USB_DEVICE_WACOM(0x343) },
4771 { BT_DEVICE_WACOM(0x360) },
4772 { BT_DEVICE_WACOM(0x361) },
4773 { BT_DEVICE_WACOM(0x377) },
4774 { BT_DEVICE_WACOM(0x379) },
4775 { USB_DEVICE_WACOM(0x37A) },
4776 { USB_DEVICE_WACOM(0x37B) },
4777 { USB_DEVICE_WACOM(0x4001) },
4778 { USB_DEVICE_WACOM(0x4004) },
4779 { USB_DEVICE_WACOM(0x5000) },
4780 { USB_DEVICE_WACOM(0x5002) },
4781 { USB_DEVICE_LENOVO(0x6004) },
4783 { USB_DEVICE_WACOM(HID_ANY_ID) },
4784 { I2C_DEVICE_WACOM(HID_ANY_ID) },
4785 { BT_DEVICE_WACOM(HID_ANY_ID) },
4788 MODULE_DEVICE_TABLE(hid, wacom_ids);