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