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