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