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