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