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