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