Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-4.19/multitouch-multiaxis' into for-linus

Multitouch updates:

- Dial support
- Palm rejection for touchscreens
- a few small assorted fixes

+683 -419
+6 -6
Documentation/input/multi-touch-protocol.rst
··· 310 310 ABS_MT_TOOL_TYPE 311 311 The type of approaching tool. A lot of kernel drivers cannot distinguish 312 312 between different tool types, such as a finger or a pen. In such cases, the 313 - event should be omitted. The protocol currently supports MT_TOOL_FINGER, 314 - MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_. For type B devices, this event is 315 - handled by input core; drivers should instead use 316 - input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may change over 317 - time while still touching the device, because the firmware may not be able 318 - to determine which tool is being used when it first appears. 313 + event should be omitted. The protocol currently mainly supports 314 + MT_TOOL_FINGER, MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_. 315 + For type B devices, this event is handled by input core; drivers should 316 + instead use input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may 317 + change over time while still touching the device, because the firmware may 318 + not be able to determine which tool is being used when it first appears. 319 319 320 320 ABS_MT_BLOB_ID 321 321 The BLOB_ID groups several packets together into one arbitrarily shaped
+14 -3
drivers/hid/hid-core.c
··· 128 128 129 129 usage = parser->local.usage[0]; 130 130 131 - if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { 132 - hid_err(parser->device, "collection stack overflow\n"); 133 - return -EINVAL; 131 + if (parser->collection_stack_ptr == parser->collection_stack_size) { 132 + unsigned int *collection_stack; 133 + unsigned int new_size = parser->collection_stack_size + 134 + HID_COLLECTION_STACK_SIZE; 135 + 136 + collection_stack = krealloc(parser->collection_stack, 137 + new_size * sizeof(unsigned int), 138 + GFP_KERNEL); 139 + if (!collection_stack) 140 + return -ENOMEM; 141 + 142 + parser->collection_stack = collection_stack; 143 + parser->collection_stack_size = new_size; 134 144 } 135 145 136 146 if (parser->device->maxcollection == parser->device->collection_size) { ··· 850 840 break; 851 841 } 852 842 843 + kfree(parser->collection_stack); 853 844 vfree(parser); 854 845 return 0; 855 846 }
+3
drivers/hid/hid-input.c
··· 1550 1550 case HID_GD_WIRELESS_RADIO_CTLS: 1551 1551 suffix = "Wireless Radio Control"; 1552 1552 break; 1553 + case HID_GD_SYSTEM_MULTIAXIS: 1554 + suffix = "System Multi Axis"; 1555 + break; 1553 1556 default: 1554 1557 break; 1555 1558 }
+43 -6
drivers/hid/hid-microsoft.c
··· 22 22 23 23 #include "hid-ids.h" 24 24 25 - #define MS_HIDINPUT 0x01 26 - #define MS_ERGONOMY 0x02 27 - #define MS_PRESENTER 0x04 28 - #define MS_RDESC 0x08 29 - #define MS_NOGET 0x10 30 - #define MS_DUPLICATE_USAGES 0x20 25 + #define MS_HIDINPUT BIT(0) 26 + #define MS_ERGONOMY BIT(1) 27 + #define MS_PRESENTER BIT(2) 28 + #define MS_RDESC BIT(3) 29 + #define MS_NOGET BIT(4) 30 + #define MS_DUPLICATE_USAGES BIT(5) 31 + #define MS_SURFACE_DIAL BIT(6) 31 32 32 33 static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, 33 34 unsigned int *rsize) ··· 131 130 return 1; 132 131 } 133 132 133 + static int ms_surface_dial_quirk(struct hid_input *hi, struct hid_field *field, 134 + struct hid_usage *usage, unsigned long **bit, int *max) 135 + { 136 + switch (usage->hid & HID_USAGE_PAGE) { 137 + case 0xff070000: 138 + /* fall-through */ 139 + case HID_UP_DIGITIZER: 140 + /* ignore those axis */ 141 + return -1; 142 + case HID_UP_GENDESK: 143 + switch (usage->hid) { 144 + case HID_GD_X: 145 + /* fall-through */ 146 + case HID_GD_Y: 147 + /* fall-through */ 148 + case HID_GD_RFKILL_BTN: 149 + /* ignore those axis */ 150 + return -1; 151 + } 152 + } 153 + 154 + return 0; 155 + } 156 + 134 157 static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, 135 158 struct hid_field *field, struct hid_usage *usage, 136 159 unsigned long **bit, int *max) ··· 170 145 if ((quirks & MS_PRESENTER) && 171 146 ms_presenter_8k_quirk(hi, usage, bit, max)) 172 147 return 1; 148 + 149 + if (quirks & MS_SURFACE_DIAL) { 150 + int ret = ms_surface_dial_quirk(hi, field, usage, bit, max); 151 + 152 + if (ret) 153 + return ret; 154 + } 173 155 174 156 return 0; 175 157 } ··· 261 229 if (quirks & MS_NOGET) 262 230 hdev->quirks |= HID_QUIRK_NOGET; 263 231 232 + if (quirks & MS_SURFACE_DIAL) 233 + hdev->quirks |= HID_QUIRK_INPUT_PER_APP; 234 + 264 235 ret = hid_parse(hdev); 265 236 if (ret) { 266 237 hid_err(hdev, "parse failed\n"); ··· 316 281 317 282 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), 318 283 .driver_data = MS_PRESENTER }, 284 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, 0x091B), 285 + .driver_data = MS_SURFACE_DIAL }, 319 286 { } 320 287 }; 321 288 MODULE_DEVICE_TABLE(hid, ms_devices);
+601 -396
drivers/hid/hid-multitouch.c
··· 28 28 */ 29 29 30 30 /* 31 - * This driver is regularly tested thanks to the tool hid-test[1]. 32 - * This tool relies on hid-replay[2] and a database of hid devices[3]. 31 + * This driver is regularly tested thanks to the test suite in hid-tools[1]. 33 32 * Please run these regression tests before patching this module so that 34 33 * your patch won't break existing known devices. 35 34 * 36 - * [1] https://github.com/bentiss/hid-test 37 - * [2] https://github.com/bentiss/hid-replay 38 - * [3] https://github.com/bentiss/hid-devices 35 + * [1] https://gitlab.freedesktop.org/libevdev/hid-tools 39 36 */ 40 37 41 38 #include <linux/device.h> ··· 87 90 #define MT_IO_FLAGS_ACTIVE_SLOTS 1 88 91 #define MT_IO_FLAGS_PENDING_SLOTS 2 89 92 90 - struct mt_slot { 91 - __s32 x, y, cx, cy, p, w, h, a; 92 - __s32 contactid; /* the device ContactID assigned to this slot */ 93 - bool touch_state; /* is the touch valid? */ 94 - bool inrange_state; /* is the finger in proximity of the sensor? */ 95 - bool confidence_state; /* is the touch made by a finger? */ 96 - bool has_azimuth; /* the contact reports azimuth */ 93 + static const bool mtrue = true; /* default for true */ 94 + static const bool mfalse; /* default for false */ 95 + static const __s32 mzero; /* default for 0 */ 96 + 97 + #define DEFAULT_TRUE ((void *)&mtrue) 98 + #define DEFAULT_FALSE ((void *)&mfalse) 99 + #define DEFAULT_ZERO ((void *)&mzero) 100 + 101 + struct mt_usages { 102 + struct list_head list; 103 + __s32 *x, *y, *cx, *cy, *p, *w, *h, *a; 104 + __s32 *contactid; /* the device ContactID assigned to this slot */ 105 + bool *tip_state; /* is the touch valid? */ 106 + bool *inrange_state; /* is the finger in proximity of the sensor? */ 107 + bool *confidence_state; /* is the touch made by a finger? */ 108 + }; 109 + 110 + struct mt_application { 111 + struct list_head list; 112 + unsigned int application; 113 + struct list_head mt_usages; /* mt usages list */ 114 + 115 + __s32 quirks; 116 + 117 + __s32 *scantime; /* scantime reported */ 118 + __s32 scantime_logical_max; /* max value for raw scantime */ 119 + 120 + __s32 *raw_cc; /* contact count in the report */ 121 + int left_button_state; /* left button state */ 122 + unsigned int mt_flags; /* flags to pass to input-mt */ 123 + 124 + unsigned long *pending_palm_slots; /* slots where we reported palm 125 + * and need to release */ 126 + 127 + __u8 num_received; /* how many contacts we received */ 128 + __u8 num_expected; /* expected last contact index */ 129 + __u8 buttons_count; /* number of physical buttons per touchpad */ 130 + __u8 touches_by_report; /* how many touches are present in one report: 131 + * 1 means we should use a serial protocol 132 + * > 1 means hybrid (multitouch) protocol 133 + */ 134 + 135 + __s32 dev_time; /* the scan time provided by the device */ 136 + unsigned long jiffies; /* the frame's jiffies */ 137 + int timestamp; /* the timestamp to be sent */ 138 + int prev_scantime; /* scantime reported previously */ 139 + 140 + bool have_contact_count; 97 141 }; 98 142 99 143 struct mt_class { ··· 149 111 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ 150 112 }; 151 113 152 - struct mt_fields { 153 - unsigned usages[HID_MAX_FIELDS]; 154 - unsigned int length; 114 + struct mt_report_data { 115 + struct list_head list; 116 + struct hid_report *report; 117 + struct mt_application *application; 118 + bool is_mt_collection; 155 119 }; 156 120 157 121 struct mt_device { 158 - struct mt_slot curdata; /* placeholder of incoming data */ 159 122 struct mt_class mtclass; /* our mt device class */ 160 123 struct timer_list release_timer; /* to release sticky fingers */ 161 124 struct hid_device *hdev; /* hid_device we're attached to */ 162 - struct mt_fields *fields; /* temporary placeholder for storing the 163 - multitouch fields */ 164 125 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ 165 - int cc_index; /* contact count field index in the report */ 166 - int cc_value_index; /* contact count value index in the field */ 167 - int scantime_index; /* scantime field index in the report */ 168 - int scantime_val_index; /* scantime value index in the field */ 169 - int prev_scantime; /* scantime reported in the previous packet */ 170 - int left_button_state; /* left button state */ 171 - unsigned last_slot_field; /* the last field of a slot */ 172 - unsigned mt_report_id; /* the report ID of the multitouch device */ 173 126 __u8 inputmode_value; /* InputMode HID feature value */ 174 - __u8 num_received; /* how many contacts we received */ 175 - __u8 num_expected; /* expected last contact index */ 176 127 __u8 maxcontacts; 177 - __u8 touches_by_report; /* how many touches are present in one report: 178 - * 1 means we should use a serial protocol 179 - * > 1 means hybrid (multitouch) protocol */ 180 - __u8 buttons_count; /* number of physical buttons per touchpad */ 181 128 bool is_buttonpad; /* is this device a button pad? */ 182 129 bool serial_maybe; /* need to check for serial protocol */ 183 - bool curvalid; /* is the current contact valid? */ 184 - unsigned mt_flags; /* flags to pass to input-mt */ 185 - __s32 dev_time; /* the scan time provided by the device */ 186 - unsigned long jiffies; /* the frame's jiffies */ 187 - int timestamp; /* the timestamp to be sent */ 130 + 131 + struct list_head applications; 132 + struct list_head reports; 188 133 }; 189 134 190 - static void mt_post_parse_default_settings(struct mt_device *td); 191 - static void mt_post_parse(struct mt_device *td); 135 + static void mt_post_parse_default_settings(struct mt_device *td, 136 + struct mt_application *app); 137 + static void mt_post_parse(struct mt_device *td, struct mt_application *app); 192 138 193 139 /* classes of device behavior */ 194 140 #define MT_CLS_DEFAULT 0x0001 ··· 225 203 * to a valid contact that was just read. 226 204 */ 227 205 228 - static int cypress_compute_slot(struct mt_device *td) 206 + static int cypress_compute_slot(struct mt_application *application, 207 + struct mt_usages *slot) 229 208 { 230 - if (td->curdata.contactid != 0 || td->num_received == 0) 231 - return td->curdata.contactid; 209 + if (*slot->contactid != 0 || application->num_received == 0) 210 + return *slot->contactid; 232 211 else 233 212 return -1; 234 213 } 235 214 236 - static struct mt_class mt_classes[] = { 215 + static const struct mt_class mt_classes[] = { 237 216 { .name = MT_CLS_DEFAULT, 238 217 .quirks = MT_QUIRK_ALWAYS_VALID | 239 218 MT_QUIRK_CONTACT_CNT_ACCURATE }, ··· 376 353 { 377 354 struct hid_device *hdev = to_hid_device(dev); 378 355 struct mt_device *td = hid_get_drvdata(hdev); 356 + struct mt_application *application; 379 357 380 358 unsigned long val; 381 359 ··· 385 361 386 362 td->mtclass.quirks = val; 387 363 388 - if (td->cc_index < 0) 389 - td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 364 + list_for_each_entry(application, &td->applications, list) { 365 + application->quirks = val; 366 + if (!application->have_contact_count) 367 + application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 368 + } 390 369 391 370 return count; 392 371 } ··· 484 457 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code)); 485 458 } 486 459 487 - static void mt_store_field(struct hid_usage *usage, struct mt_device *td, 488 - struct hid_input *hi) 460 + static struct mt_usages *mt_allocate_usage(struct hid_device *hdev, 461 + struct mt_application *application) 489 462 { 490 - struct mt_fields *f = td->fields; 463 + struct mt_usages *usage; 491 464 492 - if (f->length >= HID_MAX_FIELDS) 465 + usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL); 466 + if (!usage) 467 + return NULL; 468 + 469 + /* set some defaults so we do not need to check for null pointers */ 470 + usage->x = DEFAULT_ZERO; 471 + usage->y = DEFAULT_ZERO; 472 + usage->cx = DEFAULT_ZERO; 473 + usage->cy = DEFAULT_ZERO; 474 + usage->p = DEFAULT_ZERO; 475 + usage->w = DEFAULT_ZERO; 476 + usage->h = DEFAULT_ZERO; 477 + usage->a = DEFAULT_ZERO; 478 + usage->contactid = DEFAULT_ZERO; 479 + usage->tip_state = DEFAULT_FALSE; 480 + usage->inrange_state = DEFAULT_FALSE; 481 + usage->confidence_state = DEFAULT_TRUE; 482 + 483 + list_add_tail(&usage->list, &application->mt_usages); 484 + 485 + return usage; 486 + } 487 + 488 + static struct mt_application *mt_allocate_application(struct mt_device *td, 489 + unsigned int application) 490 + { 491 + struct mt_application *mt_application; 492 + 493 + mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application), 494 + GFP_KERNEL); 495 + if (!mt_application) 496 + return NULL; 497 + 498 + mt_application->application = application; 499 + INIT_LIST_HEAD(&mt_application->mt_usages); 500 + 501 + if (application == HID_DG_TOUCHSCREEN) 502 + mt_application->mt_flags |= INPUT_MT_DIRECT; 503 + 504 + /* 505 + * Model touchscreens providing buttons as touchpads. 506 + */ 507 + if (application == HID_DG_TOUCHPAD) { 508 + mt_application->mt_flags |= INPUT_MT_POINTER; 509 + td->inputmode_value = MT_INPUTMODE_TOUCHPAD; 510 + } 511 + 512 + mt_application->scantime = DEFAULT_ZERO; 513 + mt_application->raw_cc = DEFAULT_ZERO; 514 + mt_application->quirks = td->mtclass.quirks; 515 + 516 + list_add_tail(&mt_application->list, &td->applications); 517 + 518 + return mt_application; 519 + } 520 + 521 + static struct mt_application *mt_find_application(struct mt_device *td, 522 + unsigned int application) 523 + { 524 + struct mt_application *tmp, *mt_application = NULL; 525 + 526 + list_for_each_entry(tmp, &td->applications, list) { 527 + if (application == tmp->application) { 528 + mt_application = tmp; 529 + break; 530 + } 531 + } 532 + 533 + if (!mt_application) 534 + mt_application = mt_allocate_application(td, application); 535 + 536 + return mt_application; 537 + } 538 + 539 + static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, 540 + struct hid_report *report) 541 + { 542 + struct mt_report_data *rdata; 543 + struct hid_field *field; 544 + int r, n; 545 + 546 + rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL); 547 + if (!rdata) 548 + return NULL; 549 + 550 + rdata->report = report; 551 + rdata->application = mt_find_application(td, report->application); 552 + 553 + if (!rdata->application) { 554 + devm_kfree(&td->hdev->dev, rdata); 555 + return NULL; 556 + } 557 + 558 + for (r = 0; r < report->maxfield; r++) { 559 + field = report->field[r]; 560 + 561 + if (!(HID_MAIN_ITEM_VARIABLE & field->flags)) 562 + continue; 563 + 564 + for (n = 0; n < field->report_count; n++) { 565 + if (field->usage[n].hid == HID_DG_CONTACTID) 566 + rdata->is_mt_collection = true; 567 + } 568 + } 569 + 570 + list_add_tail(&rdata->list, &td->reports); 571 + 572 + return rdata; 573 + } 574 + 575 + static struct mt_report_data *mt_find_report_data(struct mt_device *td, 576 + struct hid_report *report) 577 + { 578 + struct mt_report_data *tmp, *rdata = NULL; 579 + 580 + list_for_each_entry(tmp, &td->reports, list) { 581 + if (report == tmp->report) { 582 + rdata = tmp; 583 + break; 584 + } 585 + } 586 + 587 + if (!rdata) 588 + rdata = mt_allocate_report_data(td, report); 589 + 590 + return rdata; 591 + } 592 + 593 + static void mt_store_field(struct hid_device *hdev, 594 + struct mt_application *application, 595 + __s32 *value, 596 + size_t offset) 597 + { 598 + struct mt_usages *usage; 599 + __s32 **target; 600 + 601 + if (list_empty(&application->mt_usages)) 602 + usage = mt_allocate_usage(hdev, application); 603 + else 604 + usage = list_last_entry(&application->mt_usages, 605 + struct mt_usages, 606 + list); 607 + 608 + if (!usage) 493 609 return; 494 610 495 - f->usages[f->length++] = usage->hid; 611 + target = (__s32 **)((char *)usage + offset); 612 + 613 + /* the value has already been filled, create a new slot */ 614 + if (*target != DEFAULT_TRUE && 615 + *target != DEFAULT_FALSE && 616 + *target != DEFAULT_ZERO) { 617 + usage = mt_allocate_usage(hdev, application); 618 + if (!usage) 619 + return; 620 + 621 + target = (__s32 **)((char *)usage + offset); 622 + } 623 + 624 + *target = value; 496 625 } 626 + 627 + #define MT_STORE_FIELD(__name) \ 628 + mt_store_field(hdev, app, \ 629 + &field->value[usage->usage_index], \ 630 + offsetof(struct mt_usages, __name)) 497 631 498 632 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, 499 633 struct hid_field *field, struct hid_usage *usage, 500 - unsigned long **bit, int *max) 634 + unsigned long **bit, int *max, struct mt_application *app) 501 635 { 502 636 struct mt_device *td = hid_get_drvdata(hdev); 503 637 struct mt_class *cls = &td->mtclass; 504 638 int code; 505 639 struct hid_usage *prev_usage = NULL; 506 640 507 - if (field->application == HID_DG_TOUCHSCREEN) 508 - td->mt_flags |= INPUT_MT_DIRECT; 509 - 510 641 /* 511 642 * Model touchscreens providing buttons as touchpads. 512 643 */ 513 - if (field->application == HID_DG_TOUCHPAD || 644 + if (field->application == HID_DG_TOUCHSCREEN && 514 645 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { 515 - td->mt_flags |= INPUT_MT_POINTER; 646 + app->mt_flags |= INPUT_MT_POINTER; 516 647 td->inputmode_value = MT_INPUTMODE_TOUCHPAD; 517 648 } 518 649 519 650 /* count the buttons on touchpads */ 520 651 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) 521 - td->buttons_count++; 652 + app->buttons_count++; 522 653 523 654 if (usage->usage_index) 524 655 prev_usage = &field->usage[usage->usage_index - 1]; ··· 687 502 switch (usage->hid) { 688 503 case HID_GD_X: 689 504 if (prev_usage && (prev_usage->hid == usage->hid)) { 690 - hid_map_usage(hi, usage, bit, max, 691 - EV_ABS, ABS_MT_TOOL_X); 692 - set_abs(hi->input, ABS_MT_TOOL_X, field, 693 - cls->sn_move); 505 + code = ABS_MT_TOOL_X; 506 + MT_STORE_FIELD(cx); 694 507 } else { 695 - hid_map_usage(hi, usage, bit, max, 696 - EV_ABS, ABS_MT_POSITION_X); 697 - set_abs(hi->input, ABS_MT_POSITION_X, field, 698 - cls->sn_move); 508 + code = ABS_MT_POSITION_X; 509 + MT_STORE_FIELD(x); 699 510 } 700 511 701 - mt_store_field(usage, td, hi); 512 + set_abs(hi->input, code, field, cls->sn_move); 513 + 514 + /* 515 + * A system multi-axis that exports X and Y has a high 516 + * chance of being used directly on a surface 517 + */ 518 + if (field->application == HID_GD_SYSTEM_MULTIAXIS) { 519 + __set_bit(INPUT_PROP_DIRECT, 520 + hi->input->propbit); 521 + input_set_abs_params(hi->input, 522 + ABS_MT_TOOL_TYPE, 523 + MT_TOOL_DIAL, 524 + MT_TOOL_DIAL, 0, 0); 525 + } 526 + 702 527 return 1; 703 528 case HID_GD_Y: 704 529 if (prev_usage && (prev_usage->hid == usage->hid)) { 705 - hid_map_usage(hi, usage, bit, max, 706 - EV_ABS, ABS_MT_TOOL_Y); 707 - set_abs(hi->input, ABS_MT_TOOL_Y, field, 708 - cls->sn_move); 530 + code = ABS_MT_TOOL_Y; 531 + MT_STORE_FIELD(cy); 709 532 } else { 710 - hid_map_usage(hi, usage, bit, max, 711 - EV_ABS, ABS_MT_POSITION_Y); 712 - set_abs(hi->input, ABS_MT_POSITION_Y, field, 713 - cls->sn_move); 533 + code = ABS_MT_POSITION_Y; 534 + MT_STORE_FIELD(y); 714 535 } 715 536 716 - mt_store_field(usage, td, hi); 537 + set_abs(hi->input, code, field, cls->sn_move); 538 + 717 539 return 1; 718 540 } 719 541 return 0; ··· 728 536 case HID_UP_DIGITIZER: 729 537 switch (usage->hid) { 730 538 case HID_DG_INRANGE: 731 - if (cls->quirks & MT_QUIRK_HOVERING) { 732 - hid_map_usage(hi, usage, bit, max, 733 - EV_ABS, ABS_MT_DISTANCE); 539 + if (app->quirks & MT_QUIRK_HOVERING) { 734 540 input_set_abs_params(hi->input, 735 541 ABS_MT_DISTANCE, 0, 1, 0, 0); 736 542 } 737 - mt_store_field(usage, td, hi); 543 + MT_STORE_FIELD(inrange_state); 738 544 return 1; 739 545 case HID_DG_CONFIDENCE: 740 546 if ((cls->name == MT_CLS_WIN_8 || 741 547 cls->name == MT_CLS_WIN_8_DUAL) && 742 - field->application == HID_DG_TOUCHPAD) 743 - cls->quirks |= MT_QUIRK_CONFIDENCE; 744 - mt_store_field(usage, td, hi); 548 + (field->application == HID_DG_TOUCHPAD || 549 + field->application == HID_DG_TOUCHSCREEN)) 550 + app->quirks |= MT_QUIRK_CONFIDENCE; 551 + 552 + if (app->quirks & MT_QUIRK_CONFIDENCE) 553 + input_set_abs_params(hi->input, 554 + ABS_MT_TOOL_TYPE, 555 + MT_TOOL_FINGER, 556 + MT_TOOL_PALM, 0, 0); 557 + 558 + MT_STORE_FIELD(confidence_state); 745 559 return 1; 746 560 case HID_DG_TIPSWITCH: 747 - hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); 748 - input_set_capability(hi->input, EV_KEY, BTN_TOUCH); 749 - mt_store_field(usage, td, hi); 561 + if (field->application != HID_GD_SYSTEM_MULTIAXIS) 562 + input_set_capability(hi->input, 563 + EV_KEY, BTN_TOUCH); 564 + MT_STORE_FIELD(tip_state); 750 565 return 1; 751 566 case HID_DG_CONTACTID: 752 - mt_store_field(usage, td, hi); 753 - td->touches_by_report++; 754 - td->mt_report_id = field->report->id; 567 + MT_STORE_FIELD(contactid); 568 + app->touches_by_report++; 755 569 return 1; 756 570 case HID_DG_WIDTH: 757 - hid_map_usage(hi, usage, bit, max, 758 - EV_ABS, ABS_MT_TOUCH_MAJOR); 759 - if (!(cls->quirks & MT_QUIRK_NO_AREA)) 571 + if (!(app->quirks & MT_QUIRK_NO_AREA)) 760 572 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, 761 573 cls->sn_width); 762 - mt_store_field(usage, td, hi); 574 + MT_STORE_FIELD(w); 763 575 return 1; 764 576 case HID_DG_HEIGHT: 765 - hid_map_usage(hi, usage, bit, max, 766 - EV_ABS, ABS_MT_TOUCH_MINOR); 767 - if (!(cls->quirks & MT_QUIRK_NO_AREA)) { 577 + if (!(app->quirks & MT_QUIRK_NO_AREA)) { 768 578 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, 769 579 cls->sn_height); 770 580 ··· 779 585 input_set_abs_params(hi->input, 780 586 ABS_MT_ORIENTATION, 0, 1, 0, 0); 781 587 } 782 - mt_store_field(usage, td, hi); 588 + MT_STORE_FIELD(h); 783 589 return 1; 784 590 case HID_DG_TIPPRESSURE: 785 - hid_map_usage(hi, usage, bit, max, 786 - EV_ABS, ABS_MT_PRESSURE); 787 591 set_abs(hi->input, ABS_MT_PRESSURE, field, 788 592 cls->sn_pressure); 789 - mt_store_field(usage, td, hi); 593 + MT_STORE_FIELD(p); 790 594 return 1; 791 595 case HID_DG_SCANTIME: 792 - hid_map_usage(hi, usage, bit, max, 793 - EV_MSC, MSC_TIMESTAMP); 794 596 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); 795 - /* Ignore if indexes are out of bounds. */ 796 - if (field->index >= field->report->maxfield || 797 - usage->usage_index >= field->report_count) 798 - return 1; 799 - td->scantime_index = field->index; 800 - td->scantime_val_index = usage->usage_index; 801 - /* 802 - * We don't set td->last_slot_field as scan time is 803 - * global to the report. 804 - */ 597 + app->scantime = &field->value[usage->usage_index]; 598 + app->scantime_logical_max = field->logical_maximum; 805 599 return 1; 806 600 case HID_DG_CONTACTCOUNT: 807 - /* Ignore if indexes are out of bounds. */ 808 - if (field->index >= field->report->maxfield || 809 - usage->usage_index >= field->report_count) 810 - return 1; 811 - td->cc_index = field->index; 812 - td->cc_value_index = usage->usage_index; 601 + app->have_contact_count = true; 602 + app->raw_cc = &field->value[usage->usage_index]; 813 603 return 1; 814 604 case HID_DG_AZIMUTH: 815 - hid_map_usage(hi, usage, bit, max, 816 - EV_ABS, ABS_MT_ORIENTATION); 817 605 /* 818 606 * Azimuth has the range of [0, MAX) representing a full 819 607 * revolution. Set ABS_MT_ORIENTATION to a quarter of ··· 806 630 field->logical_maximum / 4, 807 631 cls->sn_move ? 808 632 field->logical_maximum / cls->sn_move : 0, 0); 809 - mt_store_field(usage, td, hi); 633 + MT_STORE_FIELD(a); 810 634 return 1; 811 635 case HID_DG_CONTACTMAX: 812 - /* we don't set td->last_slot_field as contactcount and 813 - * contact max are global to the report */ 636 + /* contact max are global to the report */ 814 637 return -1; 815 638 case HID_DG_TOUCH: 816 639 /* Legacy devices use TIPSWITCH and not TOUCH. ··· 825 650 * MS PTP spec says that external buttons left and right have 826 651 * usages 2 and 3. 827 652 */ 828 - if ((cls->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 653 + if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 829 654 field->application == HID_DG_TOUCHPAD && 830 655 (usage->hid & HID_USAGE) > 1) 831 656 code--; 657 + 658 + if (field->application == HID_GD_SYSTEM_MULTIAXIS) 659 + code = BTN_0 + ((usage->hid - 1) & HID_USAGE); 660 + 832 661 hid_map_usage(hi, usage, bit, max, EV_KEY, code); 833 662 input_set_capability(hi->input, EV_KEY, code); 834 663 return 1; ··· 845 666 return 0; 846 667 } 847 668 848 - static int mt_compute_slot(struct mt_device *td, struct input_dev *input) 669 + static int mt_compute_slot(struct mt_device *td, struct mt_application *app, 670 + struct mt_usages *slot, 671 + struct input_dev *input) 849 672 { 850 - __s32 quirks = td->mtclass.quirks; 673 + __s32 quirks = app->quirks; 851 674 852 675 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) 853 - return td->curdata.contactid; 676 + return *slot->contactid; 854 677 855 678 if (quirks & MT_QUIRK_CYPRESS) 856 - return cypress_compute_slot(td); 679 + return cypress_compute_slot(app, slot); 857 680 858 681 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) 859 - return td->num_received; 682 + return app->num_received; 860 683 861 684 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) 862 - return td->curdata.contactid - 1; 685 + return *slot->contactid - 1; 863 686 864 - return input_mt_get_slot_by_key(input, td->curdata.contactid); 687 + return input_mt_get_slot_by_key(input, *slot->contactid); 865 688 } 866 689 867 - /* 868 - * this function is called when a whole contact has been processed, 869 - * so that it can assign it to a slot and store the data there 870 - */ 871 - static void mt_complete_slot(struct mt_device *td, struct input_dev *input) 690 + static void mt_release_pending_palms(struct mt_device *td, 691 + struct mt_application *app, 692 + struct input_dev *input) 872 693 { 873 - if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && 874 - td->num_received >= td->num_expected) 875 - return; 694 + int slotnum; 695 + bool need_sync = false; 876 696 877 - if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) { 878 - int active; 879 - int slotnum = mt_compute_slot(td, input); 880 - struct mt_slot *s = &td->curdata; 881 - struct input_mt *mt = input->mt; 882 - 883 - if (slotnum < 0 || slotnum >= td->maxcontacts) 884 - return; 885 - 886 - if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { 887 - struct input_mt_slot *slot = &mt->slots[slotnum]; 888 - if (input_mt_is_active(slot) && 889 - input_mt_is_used(mt, slot)) 890 - return; 891 - } 892 - 893 - if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE)) 894 - s->confidence_state = true; 895 - active = (s->touch_state || s->inrange_state) && 896 - s->confidence_state; 697 + for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) { 698 + clear_bit(slotnum, app->pending_palm_slots); 897 699 898 700 input_mt_slot(input, slotnum); 899 - input_mt_report_slot_state(input, MT_TOOL_FINGER, active); 900 - if (active) { 901 - /* this finger is in proximity of the sensor */ 902 - int wide = (s->w > s->h); 903 - int major = max(s->w, s->h); 904 - int minor = min(s->w, s->h); 905 - int orientation = wide; 701 + input_mt_report_slot_state(input, MT_TOOL_PALM, false); 906 702 907 - if (s->has_azimuth) 908 - orientation = s->a; 909 - 910 - /* 911 - * divided by two to match visual scale of touch 912 - * for devices with this quirk 913 - */ 914 - if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { 915 - major = major >> 1; 916 - minor = minor >> 1; 917 - } 918 - 919 - input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); 920 - input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); 921 - input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx); 922 - input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy); 923 - input_event(input, EV_ABS, ABS_MT_DISTANCE, 924 - !s->touch_state); 925 - input_event(input, EV_ABS, ABS_MT_ORIENTATION, 926 - orientation); 927 - input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); 928 - input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); 929 - input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); 930 - 931 - set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); 932 - } 703 + need_sync = true; 933 704 } 934 705 935 - td->num_received++; 706 + if (need_sync) { 707 + input_mt_sync_frame(input); 708 + input_sync(input); 709 + } 936 710 } 937 711 938 712 /* 939 713 * this function is called when a whole packet has been received and processed, 940 714 * so that it can decide what to send to the input layer. 941 715 */ 942 - static void mt_sync_frame(struct mt_device *td, struct input_dev *input) 716 + static void mt_sync_frame(struct mt_device *td, struct mt_application *app, 717 + struct input_dev *input) 943 718 { 944 - if (td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) 945 - input_event(input, EV_KEY, BTN_LEFT, td->left_button_state); 719 + if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) 720 + input_event(input, EV_KEY, BTN_LEFT, app->left_button_state); 946 721 947 722 input_mt_sync_frame(input); 948 - input_event(input, EV_MSC, MSC_TIMESTAMP, td->timestamp); 723 + input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp); 949 724 input_sync(input); 950 - td->num_received = 0; 951 - td->left_button_state = 0; 725 + 726 + mt_release_pending_palms(td, app, input); 727 + 728 + app->num_received = 0; 729 + app->left_button_state = 0; 730 + 952 731 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) 953 732 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); 954 733 else ··· 914 777 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); 915 778 } 916 779 917 - static int mt_compute_timestamp(struct mt_device *td, struct hid_field *field, 918 - __s32 value) 780 + static int mt_compute_timestamp(struct mt_application *app, __s32 value) 919 781 { 920 - long delta = value - td->dev_time; 921 - unsigned long jdelta = jiffies_to_usecs(jiffies - td->jiffies); 782 + long delta = value - app->prev_scantime; 783 + unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies); 922 784 923 - td->jiffies = jiffies; 924 - td->dev_time = value; 785 + app->jiffies = jiffies; 925 786 926 787 if (delta < 0) 927 - delta += field->logical_maximum; 788 + delta += app->scantime_logical_max; 928 789 929 790 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */ 930 791 delta *= 100; ··· 931 796 /* No data received for a while, resync the timestamp. */ 932 797 return 0; 933 798 else 934 - return td->timestamp + delta; 799 + return app->timestamp + delta; 935 800 } 936 801 937 802 static int mt_touch_event(struct hid_device *hid, struct hid_field *field, ··· 944 809 return 1; 945 810 } 946 811 947 - static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, 948 - struct hid_usage *usage, __s32 value, 949 - bool first_packet) 812 + static int mt_process_slot(struct mt_device *td, struct input_dev *input, 813 + struct mt_application *app, 814 + struct mt_usages *slot) 950 815 { 951 - struct mt_device *td = hid_get_drvdata(hid); 952 - __s32 quirks = td->mtclass.quirks; 953 - struct input_dev *input = field->hidinput->input; 816 + struct input_mt *mt = input->mt; 817 + __s32 quirks = app->quirks; 818 + bool valid = true; 819 + bool confidence_state = true; 820 + bool inrange_state = false; 821 + int active; 822 + int slotnum; 823 + int tool = MT_TOOL_FINGER; 954 824 955 - if (hid->claimed & HID_CLAIMED_INPUT) { 956 - switch (usage->hid) { 957 - case HID_DG_INRANGE: 958 - if (quirks & MT_QUIRK_VALID_IS_INRANGE) 959 - td->curvalid = value; 960 - if (quirks & MT_QUIRK_HOVERING) 961 - td->curdata.inrange_state = value; 962 - break; 963 - case HID_DG_TIPSWITCH: 964 - if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 965 - td->curvalid = value; 966 - td->curdata.touch_state = value; 967 - break; 968 - case HID_DG_CONFIDENCE: 969 - if (quirks & MT_QUIRK_CONFIDENCE) 970 - td->curdata.confidence_state = value; 971 - if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) 972 - td->curvalid = value; 973 - break; 974 - case HID_DG_CONTACTID: 975 - td->curdata.contactid = value; 976 - break; 977 - case HID_DG_TIPPRESSURE: 978 - td->curdata.p = value; 979 - break; 980 - case HID_GD_X: 981 - if (usage->code == ABS_MT_TOOL_X) 982 - td->curdata.cx = value; 983 - else 984 - td->curdata.x = value; 985 - break; 986 - case HID_GD_Y: 987 - if (usage->code == ABS_MT_TOOL_Y) 988 - td->curdata.cy = value; 989 - else 990 - td->curdata.y = value; 991 - break; 992 - case HID_DG_WIDTH: 993 - td->curdata.w = value; 994 - break; 995 - case HID_DG_HEIGHT: 996 - td->curdata.h = value; 997 - break; 998 - case HID_DG_SCANTIME: 999 - td->timestamp = mt_compute_timestamp(td, field, value); 1000 - break; 1001 - case HID_DG_CONTACTCOUNT: 1002 - break; 1003 - case HID_DG_AZIMUTH: 825 + if (!slot) 826 + return -EINVAL; 827 + 828 + if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && 829 + app->num_received >= app->num_expected) 830 + return -EAGAIN; 831 + 832 + if (!(quirks & MT_QUIRK_ALWAYS_VALID)) { 833 + if (quirks & MT_QUIRK_VALID_IS_INRANGE) 834 + valid = *slot->inrange_state; 835 + if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 836 + valid = *slot->tip_state; 837 + if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) 838 + valid = *slot->confidence_state; 839 + 840 + if (!valid) 841 + return 0; 842 + } 843 + 844 + slotnum = mt_compute_slot(td, app, slot, input); 845 + if (slotnum < 0 || slotnum >= td->maxcontacts) 846 + return 0; 847 + 848 + if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { 849 + struct input_mt_slot *i_slot = &mt->slots[slotnum]; 850 + 851 + if (input_mt_is_active(i_slot) && 852 + input_mt_is_used(mt, i_slot)) 853 + return -EAGAIN; 854 + } 855 + 856 + if (quirks & MT_QUIRK_CONFIDENCE) 857 + confidence_state = *slot->confidence_state; 858 + 859 + if (quirks & MT_QUIRK_HOVERING) 860 + inrange_state = *slot->inrange_state; 861 + 862 + active = *slot->tip_state || inrange_state; 863 + 864 + if (app->application == HID_GD_SYSTEM_MULTIAXIS) 865 + tool = MT_TOOL_DIAL; 866 + else if (unlikely(!confidence_state)) { 867 + tool = MT_TOOL_PALM; 868 + if (!active && 869 + input_mt_is_active(&mt->slots[slotnum])) { 870 + /* 871 + * The non-confidence was reported for 872 + * previously valid contact that is also no 873 + * longer valid. We can't simply report 874 + * lift-off as userspace will not be aware 875 + * of non-confidence, so we need to split 876 + * it into 2 events: active MT_TOOL_PALM 877 + * and a separate liftoff. 878 + */ 879 + active = true; 880 + set_bit(slotnum, app->pending_palm_slots); 881 + } 882 + } 883 + 884 + input_mt_slot(input, slotnum); 885 + input_mt_report_slot_state(input, tool, active); 886 + if (active) { 887 + /* this finger is in proximity of the sensor */ 888 + int wide = (*slot->w > *slot->h); 889 + int major = max(*slot->w, *slot->h); 890 + int minor = min(*slot->w, *slot->h); 891 + int orientation = wide; 892 + int max_azimuth; 893 + int azimuth; 894 + 895 + if (slot->a != DEFAULT_ZERO) { 1004 896 /* 1005 897 * Azimuth is counter-clockwise and ranges from [0, MAX) 1006 898 * (a full revolution). Convert it to clockwise ranging ··· 1038 876 * out of range to [-MAX/2, MAX/2] to report an upside 1039 877 * down ellipsis. 1040 878 */ 1041 - if (value > field->logical_maximum / 2) 1042 - value -= field->logical_maximum; 1043 - td->curdata.a = -value; 1044 - td->curdata.has_azimuth = true; 1045 - break; 1046 - case HID_DG_TOUCH: 1047 - /* do nothing */ 1048 - break; 1049 - 1050 - default: 1051 - /* 1052 - * For Win8 PTP touchpads we should only look at 1053 - * non finger/touch events in the first_packet of 1054 - * a (possible) multi-packet frame. 1055 - */ 1056 - if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 1057 - !first_packet) 1058 - return; 1059 - 1060 - /* 1061 - * For Win8 PTP touchpads we map both the clickpad click 1062 - * and any "external" left buttons to BTN_LEFT if a 1063 - * device claims to have both we need to report 1 for 1064 - * BTN_LEFT if either is pressed, so we or all values 1065 - * together and report the result in mt_sync_frame(). 1066 - */ 1067 - if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 1068 - usage->type == EV_KEY && usage->code == BTN_LEFT) { 1069 - td->left_button_state |= value; 1070 - return; 1071 - } 1072 - 1073 - if (usage->type) 1074 - input_event(input, usage->type, usage->code, 1075 - value); 1076 - return; 879 + azimuth = *slot->a; 880 + max_azimuth = input_abs_get_max(input, 881 + ABS_MT_ORIENTATION); 882 + if (azimuth > max_azimuth * 2) 883 + azimuth -= max_azimuth * 4; 884 + orientation = -azimuth; 1077 885 } 1078 886 1079 - if (usage->usage_index + 1 == field->report_count) { 1080 - /* we only take into account the last report. */ 1081 - if (usage->hid == td->last_slot_field) 1082 - mt_complete_slot(td, field->hidinput->input); 887 + if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { 888 + /* 889 + * divided by two to match visual scale of touch 890 + * for devices with this quirk 891 + */ 892 + major = major >> 1; 893 + minor = minor >> 1; 1083 894 } 1084 895 896 + input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); 897 + input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); 898 + input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); 899 + input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); 900 + input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); 901 + input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); 902 + input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); 903 + input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); 904 + input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); 905 + 906 + set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); 1085 907 } 908 + 909 + return 0; 1086 910 } 1087 911 1088 - static void mt_touch_report(struct hid_device *hid, struct hid_report *report) 912 + static void mt_process_mt_event(struct hid_device *hid, 913 + struct mt_application *app, 914 + struct hid_field *field, 915 + struct hid_usage *usage, 916 + __s32 value, 917 + bool first_packet) 918 + { 919 + __s32 quirks = app->quirks; 920 + struct input_dev *input = field->hidinput->input; 921 + 922 + if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT)) 923 + return; 924 + 925 + if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) { 926 + 927 + /* 928 + * For Win8 PTP touchpads we should only look at 929 + * non finger/touch events in the first_packet of a 930 + * (possible) multi-packet frame. 931 + */ 932 + if (!first_packet) 933 + return; 934 + 935 + /* 936 + * For Win8 PTP touchpads we map both the clickpad click 937 + * and any "external" left buttons to BTN_LEFT if a 938 + * device claims to have both we need to report 1 for 939 + * BTN_LEFT if either is pressed, so we or all values 940 + * together and report the result in mt_sync_frame(). 941 + */ 942 + if (usage->type == EV_KEY && usage->code == BTN_LEFT) { 943 + app->left_button_state |= value; 944 + return; 945 + } 946 + } 947 + 948 + input_event(input, usage->type, usage->code, value); 949 + } 950 + 951 + static void mt_touch_report(struct hid_device *hid, 952 + struct mt_report_data *rdata) 1089 953 { 1090 954 struct mt_device *td = hid_get_drvdata(hid); 955 + struct hid_report *report = rdata->report; 956 + struct mt_application *app = rdata->application; 1091 957 struct hid_field *field; 958 + struct input_dev *input; 959 + struct mt_usages *slot; 1092 960 bool first_packet; 1093 961 unsigned count; 1094 - int r, n, scantime = 0; 962 + int r, n; 963 + int scantime = 0; 964 + int contact_count = -1; 1095 965 1096 966 /* sticky fingers release in progress, abort */ 1097 967 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) 1098 968 return; 1099 969 970 + scantime = *app->scantime; 971 + app->timestamp = mt_compute_timestamp(app, scantime); 972 + if (app->raw_cc != DEFAULT_ZERO) 973 + contact_count = *app->raw_cc; 974 + 1100 975 /* 1101 976 * Includes multi-packet support where subsequent 1102 977 * packets are sent with zero contactcount. 1103 978 */ 1104 - if (td->scantime_index >= 0) { 1105 - field = report->field[td->scantime_index]; 1106 - scantime = field->value[td->scantime_val_index]; 1107 - } 1108 - if (td->cc_index >= 0) { 1109 - struct hid_field *field = report->field[td->cc_index]; 1110 - int value = field->value[td->cc_value_index]; 1111 - 979 + if (contact_count >= 0) { 1112 980 /* 1113 981 * For Win8 PTPs the first packet (td->num_received == 0) may 1114 982 * have a contactcount of 0 if there only is a button event. ··· 1146 954 * of a possible multi-packet frame be checking that the 1147 955 * timestamp has changed. 1148 956 */ 1149 - if ((td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 1150 - td->num_received == 0 && td->prev_scantime != scantime) 1151 - td->num_expected = value; 957 + if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 958 + app->num_received == 0 && 959 + app->prev_scantime != scantime) 960 + app->num_expected = contact_count; 1152 961 /* A non 0 contact count always indicates a first packet */ 1153 - else if (value) 1154 - td->num_expected = value; 962 + else if (contact_count) 963 + app->num_expected = contact_count; 1155 964 } 1156 - td->prev_scantime = scantime; 965 + app->prev_scantime = scantime; 1157 966 1158 - first_packet = td->num_received == 0; 967 + first_packet = app->num_received == 0; 968 + 969 + input = report->field[0]->hidinput->input; 970 + 971 + list_for_each_entry(slot, &app->mt_usages, list) { 972 + if (!mt_process_slot(td, input, app, slot)) 973 + app->num_received++; 974 + } 975 + 1159 976 for (r = 0; r < report->maxfield; r++) { 1160 977 field = report->field[r]; 1161 978 count = field->report_count; ··· 1173 972 continue; 1174 973 1175 974 for (n = 0; n < count; n++) 1176 - mt_process_mt_event(hid, field, &field->usage[n], 1177 - field->value[n], first_packet); 975 + mt_process_mt_event(hid, app, field, 976 + &field->usage[n], field->value[n], 977 + first_packet); 1178 978 } 1179 979 1180 - if (td->num_received >= td->num_expected) 1181 - mt_sync_frame(td, report->field[0]->hidinput->input); 980 + if (app->num_received >= app->num_expected) 981 + mt_sync_frame(td, app, input); 1182 982 1183 983 /* 1184 984 * Windows 8 specs says 2 things: ··· 1199 997 * only affect laggish machines and the ones that have a firmware 1200 998 * defect. 1201 999 */ 1202 - if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) { 1000 + if (app->quirks & MT_QUIRK_STICKY_FINGERS) { 1203 1001 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags)) 1204 1002 mod_timer(&td->release_timer, 1205 1003 jiffies + msecs_to_jiffies(100)); ··· 1211 1009 } 1212 1010 1213 1011 static int mt_touch_input_configured(struct hid_device *hdev, 1214 - struct hid_input *hi) 1012 + struct hid_input *hi, 1013 + struct mt_application *app) 1215 1014 { 1216 1015 struct mt_device *td = hid_get_drvdata(hdev); 1217 1016 struct mt_class *cls = &td->mtclass; ··· 1222 1019 if (!td->maxcontacts) 1223 1020 td->maxcontacts = MT_DEFAULT_MAXCONTACT; 1224 1021 1225 - mt_post_parse(td); 1022 + mt_post_parse(td, app); 1226 1023 if (td->serial_maybe) 1227 - mt_post_parse_default_settings(td); 1024 + mt_post_parse_default_settings(td, app); 1228 1025 1229 1026 if (cls->is_indirect) 1230 - td->mt_flags |= INPUT_MT_POINTER; 1027 + app->mt_flags |= INPUT_MT_POINTER; 1231 1028 1232 - if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 1233 - td->mt_flags |= INPUT_MT_DROP_UNUSED; 1029 + if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 1030 + app->mt_flags |= INPUT_MT_DROP_UNUSED; 1234 1031 1235 1032 /* check for clickpads */ 1236 - if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1)) 1033 + if ((app->mt_flags & INPUT_MT_POINTER) && 1034 + (app->buttons_count == 1)) 1237 1035 td->is_buttonpad = true; 1238 1036 1239 1037 if (td->is_buttonpad) 1240 1038 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); 1241 1039 1242 - ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); 1040 + app->pending_palm_slots = devm_kcalloc(&hi->input->dev, 1041 + BITS_TO_LONGS(td->maxcontacts), 1042 + sizeof(long), 1043 + GFP_KERNEL); 1044 + if (!app->pending_palm_slots) 1045 + return -ENOMEM; 1046 + 1047 + ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags); 1243 1048 if (ret) 1244 1049 return ret; 1245 1050 1246 - td->mt_flags = 0; 1051 + app->mt_flags = 0; 1247 1052 return 0; 1248 1053 } 1249 1054 ··· 1262 1051 unsigned long **bit, int *max) 1263 1052 { 1264 1053 struct mt_device *td = hid_get_drvdata(hdev); 1054 + struct mt_application *application; 1055 + struct mt_report_data *rdata; 1056 + 1057 + rdata = mt_find_report_data(td, field->report); 1058 + if (!rdata) { 1059 + hid_err(hdev, "failed to allocate data for report\n"); 1060 + return 0; 1061 + } 1062 + 1063 + application = rdata->application; 1265 1064 1266 1065 /* 1267 1066 * If mtclass.export_all_inputs is not set, only map fields from ··· 1287 1066 field->application != HID_GD_SYSTEM_CONTROL && 1288 1067 field->application != HID_CP_CONSUMER_CONTROL && 1289 1068 field->application != HID_GD_WIRELESS_RADIO_CTLS && 1069 + field->application != HID_GD_SYSTEM_MULTIAXIS && 1290 1070 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && 1291 - td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP)) 1071 + application->quirks & MT_QUIRK_ASUS_CUSTOM_UP)) 1292 1072 return -1; 1293 1073 1294 1074 /* ··· 1298 1076 * map usages to input keys. 1299 1077 */ 1300 1078 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && 1301 - td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP && 1079 + application->quirks & MT_QUIRK_ASUS_CUSTOM_UP && 1302 1080 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) { 1303 1081 set_bit(EV_REP, hi->input->evbit); 1304 1082 if (field->flags & HID_MAIN_ITEM_VARIABLE) ··· 1315 1093 return 1; 1316 1094 } 1317 1095 1318 - /* 1319 - * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" 1320 - * for the stylus. 1321 - * The check for mt_report_id ensures we don't process 1322 - * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical 1323 - * collection, but within the report ID. 1324 - */ 1325 - if (field->physical == HID_DG_STYLUS) 1326 - return 0; 1327 - else if ((field->physical == 0) && 1328 - (field->report->id != td->mt_report_id) && 1329 - (td->mt_report_id != -1)) 1330 - return 0; 1331 - 1332 - if (field->application == HID_DG_TOUCHSCREEN || 1333 - field->application == HID_DG_TOUCHPAD) 1334 - return mt_touch_input_mapping(hdev, hi, field, usage, bit, max); 1096 + if (rdata->is_mt_collection) 1097 + return mt_touch_input_mapping(hdev, hi, field, usage, bit, max, 1098 + application); 1335 1099 1336 1100 /* let hid-core decide for the others */ 1337 1101 return 0; ··· 1327 1119 struct hid_field *field, struct hid_usage *usage, 1328 1120 unsigned long **bit, int *max) 1329 1121 { 1330 - /* 1331 - * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" 1332 - * for the stylus. 1333 - */ 1334 - if (field->physical == HID_DG_STYLUS) 1335 - return 0; 1122 + struct mt_device *td = hid_get_drvdata(hdev); 1123 + struct mt_report_data *rdata; 1336 1124 1337 - if (field->application == HID_DG_TOUCHSCREEN || 1338 - field->application == HID_DG_TOUCHPAD) { 1125 + rdata = mt_find_report_data(td, field->report); 1126 + if (rdata && rdata->is_mt_collection) { 1339 1127 /* We own these mappings, tell hid-input to ignore them */ 1340 1128 return -1; 1341 1129 } ··· 1344 1140 struct hid_usage *usage, __s32 value) 1345 1141 { 1346 1142 struct mt_device *td = hid_get_drvdata(hid); 1143 + struct mt_report_data *rdata; 1347 1144 1348 - if (field->report->id == td->mt_report_id) 1145 + rdata = mt_find_report_data(td, field->report); 1146 + if (rdata && rdata->is_mt_collection) 1349 1147 return mt_touch_event(hid, field, usage, value); 1350 1148 1351 1149 return 0; ··· 1357 1151 { 1358 1152 struct mt_device *td = hid_get_drvdata(hid); 1359 1153 struct hid_field *field = report->field[0]; 1154 + struct mt_report_data *rdata; 1360 1155 1361 1156 if (!(hid->claimed & HID_CLAIMED_INPUT)) 1362 1157 return; 1363 1158 1364 - if (report->id == td->mt_report_id) 1365 - return mt_touch_report(hid, report); 1159 + rdata = mt_find_report_data(td, report); 1160 + if (rdata && rdata->is_mt_collection) 1161 + return mt_touch_report(hid, rdata); 1366 1162 1367 1163 if (field && field->hidinput && field->hidinput->input) 1368 1164 input_sync(field->hidinput->input); ··· 1405 1197 return true; 1406 1198 1407 1199 case HID_DG_CONTACTMAX: 1408 - if (td->mtclass.maxcontacts) { 1200 + if (cls->maxcontacts) { 1409 1201 max = min_t(int, field->logical_maximum, 1410 - td->mtclass.maxcontacts); 1202 + cls->maxcontacts); 1411 1203 if (field->value[index] != max) { 1412 1204 field->value[index] = max; 1413 1205 return true; ··· 1467 1259 } 1468 1260 } 1469 1261 1470 - static void mt_post_parse_default_settings(struct mt_device *td) 1262 + static void mt_post_parse_default_settings(struct mt_device *td, 1263 + struct mt_application *app) 1471 1264 { 1472 - __s32 quirks = td->mtclass.quirks; 1265 + __s32 quirks = app->quirks; 1473 1266 1474 1267 /* unknown serial device needs special quirks */ 1475 - if (td->touches_by_report == 1) { 1268 + if (list_is_singular(&app->mt_usages)) { 1476 1269 quirks |= MT_QUIRK_ALWAYS_VALID; 1477 1270 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP; 1478 1271 quirks &= ~MT_QUIRK_VALID_IS_INRANGE; ··· 1481 1272 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 1482 1273 } 1483 1274 1484 - td->mtclass.quirks = quirks; 1275 + app->quirks = quirks; 1485 1276 } 1486 1277 1487 - static void mt_post_parse(struct mt_device *td) 1278 + static void mt_post_parse(struct mt_device *td, struct mt_application *app) 1488 1279 { 1489 - struct mt_fields *f = td->fields; 1490 - struct mt_class *cls = &td->mtclass; 1491 - 1492 - if (td->touches_by_report > 0) { 1493 - int field_count_per_touch = f->length / td->touches_by_report; 1494 - td->last_slot_field = f->usages[field_count_per_touch - 1]; 1495 - } 1496 - 1497 - if (td->cc_index < 0) 1498 - cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 1280 + if (!app->have_contact_count) 1281 + app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 1499 1282 } 1500 1283 1501 1284 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) ··· 1496 1295 char *name; 1497 1296 const char *suffix = NULL; 1498 1297 unsigned int application = 0; 1298 + struct mt_report_data *rdata; 1299 + struct mt_application *mt_application = NULL; 1499 1300 struct hid_report *report; 1500 1301 int ret; 1501 1302 1502 1303 list_for_each_entry(report, &hi->reports, hidinput_list) { 1503 1304 application = report->application; 1504 - if (report->id == td->mt_report_id) { 1505 - ret = mt_touch_input_configured(hdev, hi); 1305 + rdata = mt_find_report_data(td, report); 1306 + if (!rdata) { 1307 + hid_err(hdev, "failed to allocate data for report\n"); 1308 + return -ENOMEM; 1309 + } 1310 + 1311 + mt_application = rdata->application; 1312 + 1313 + if (rdata->is_mt_collection) { 1314 + ret = mt_touch_input_configured(hdev, hi, 1315 + mt_application); 1506 1316 if (ret) 1507 1317 return ret; 1508 1318 } ··· 1539 1327 case HID_GD_SYSTEM_CONTROL: 1540 1328 case HID_CP_CONSUMER_CONTROL: 1541 1329 case HID_GD_WIRELESS_RADIO_CTLS: 1330 + case HID_GD_SYSTEM_MULTIAXIS: 1542 1331 /* already handled by hid core */ 1543 1332 break; 1544 1333 case HID_DG_TOUCHSCREEN: ··· 1603 1390 static void mt_release_contacts(struct hid_device *hid) 1604 1391 { 1605 1392 struct hid_input *hidinput; 1393 + struct mt_application *application; 1606 1394 struct mt_device *td = hid_get_drvdata(hid); 1607 1395 1608 1396 list_for_each_entry(hidinput, &hid->inputs, list) { ··· 1623 1409 } 1624 1410 } 1625 1411 1626 - td->num_received = 0; 1412 + list_for_each_entry(application, &td->applications, list) { 1413 + application->num_received = 0; 1414 + } 1627 1415 } 1628 1416 1629 1417 static void mt_expired_timeout(struct timer_list *t) ··· 1648 1432 { 1649 1433 int ret, i; 1650 1434 struct mt_device *td; 1651 - struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 1435 + const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 1652 1436 1653 1437 for (i = 0; mt_classes[i].name ; i++) { 1654 1438 if (id->driver_data == mt_classes[i].name) { ··· 1665 1449 td->hdev = hdev; 1666 1450 td->mtclass = *mtclass; 1667 1451 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; 1668 - td->cc_index = -1; 1669 - td->scantime_index = -1; 1670 - td->mt_report_id = -1; 1671 1452 hid_set_drvdata(hdev, td); 1672 1453 1673 - td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields), 1674 - GFP_KERNEL); 1675 - if (!td->fields) { 1676 - dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); 1677 - return -ENOMEM; 1678 - } 1454 + INIT_LIST_HEAD(&td->applications); 1455 + INIT_LIST_HEAD(&td->reports); 1679 1456 1680 1457 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) 1681 1458 td->serial_maybe = true; ··· 1704 1495 hdev->name); 1705 1496 1706 1497 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); 1707 - 1708 - /* release .fields memory as it is not used anymore */ 1709 - devm_kfree(&hdev->dev, td->fields); 1710 - td->fields = NULL; 1711 1498 1712 1499 return 0; 1713 1500 }
+11 -4
include/linux/hid.h
··· 190 190 * http://www.usb.org/developers/hidpage/HUTRR40RadioHIDUsagesFinal.pdf 191 191 */ 192 192 #define HID_GD_WIRELESS_RADIO_CTLS 0x0001000c 193 + /* 194 + * System Multi-Axis, see: 195 + * http://www.usb.org/developers/hidpage/HUTRR62_-_Generic_Desktop_CA_for_System_Multi-Axis_Controllers.txt 196 + */ 197 + #define HID_GD_SYSTEM_MULTIAXIS 0x0001000e 198 + 193 199 #define HID_GD_X 0x00010030 194 200 #define HID_GD_Y 0x00010031 195 201 #define HID_GD_Z 0x00010032 ··· 644 638 struct hid_parser { 645 639 struct hid_global global; 646 640 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE]; 647 - unsigned global_stack_ptr; 641 + unsigned int global_stack_ptr; 648 642 struct hid_local local; 649 - unsigned collection_stack[HID_COLLECTION_STACK_SIZE]; 650 - unsigned collection_stack_ptr; 643 + unsigned int *collection_stack; 644 + unsigned int collection_stack_ptr; 645 + unsigned int collection_stack_size; 651 646 struct hid_device *device; 652 - unsigned scan_flags; 647 + unsigned int scan_flags; 653 648 }; 654 649 655 650 struct hid_class_descriptor {
+5 -4
include/uapi/linux/input.h
··· 270 270 /* 271 271 * MT_TOOL types 272 272 */ 273 - #define MT_TOOL_FINGER 0 274 - #define MT_TOOL_PEN 1 275 - #define MT_TOOL_PALM 2 276 - #define MT_TOOL_MAX 2 273 + #define MT_TOOL_FINGER 0x00 274 + #define MT_TOOL_PEN 0x01 275 + #define MT_TOOL_PALM 0x02 276 + #define MT_TOOL_DIAL 0x0a 277 + #define MT_TOOL_MAX 0x0f 277 278 278 279 /* 279 280 * Values describing the status of a force-feedback effect