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