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