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