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