aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-multitouch.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/hid-multitouch.c')
-rw-r--r--drivers/hid/hid-multitouch.c273
1 files changed, 193 insertions, 80 deletions
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 82e9211b3ca9..dc3ae5c56f56 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -2,8 +2,9 @@
2 * HID driver for multitouch panels 2 * HID driver for multitouch panels
3 * 3 *
4 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr> 4 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2012 Benjamin Tissoires <benjamin.tissoires@gmail.com> 5 * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France 6 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
7 * Copyright (c) 2012-2013 Red Hat, Inc
7 * 8 *
8 * This code is partly based on hid-egalax.c: 9 * This code is partly based on hid-egalax.c:
9 * 10 *
@@ -26,13 +27,24 @@
26 * any later version. 27 * any later version.
27 */ 28 */
28 29
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].
33 * Please run these regression tests before patching this module so that
34 * your patch won't break existing known devices.
35 *
36 * [1] https://github.com/bentiss/hid-test
37 * [2] https://github.com/bentiss/hid-replay
38 * [3] https://github.com/bentiss/hid-devices
39 */
40
29#include <linux/device.h> 41#include <linux/device.h>
30#include <linux/hid.h> 42#include <linux/hid.h>
31#include <linux/module.h> 43#include <linux/module.h>
32#include <linux/slab.h> 44#include <linux/slab.h>
33#include <linux/usb.h> 45#include <linux/usb.h>
34#include <linux/input/mt.h> 46#include <linux/input/mt.h>
35#include "usbhid/usbhid.h" 47#include <linux/string.h>
36 48
37 49
38MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); 50MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
@@ -86,9 +98,9 @@ struct mt_device {
86 multitouch fields */ 98 multitouch fields */
87 int cc_index; /* contact count field index in the report */ 99 int cc_index; /* contact count field index in the report */
88 int cc_value_index; /* contact count value index in the field */ 100 int cc_value_index; /* contact count value index in the field */
89 unsigned last_field_index; /* last field index of the report */
90 unsigned last_slot_field; /* the last field of a slot */ 101 unsigned last_slot_field; /* the last field of a slot */
91 unsigned mt_report_id; /* the report ID of the multitouch device */ 102 unsigned mt_report_id; /* the report ID of the multitouch device */
103 unsigned pen_report_id; /* the report ID of the pen device */
92 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ 104 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
93 __s8 inputmode_index; /* InputMode HID feature index in the report */ 105 __s8 inputmode_index; /* InputMode HID feature index in the report */
94 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature, 106 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
@@ -104,6 +116,9 @@ struct mt_device {
104 unsigned mt_flags; /* flags to pass to input-mt */ 116 unsigned mt_flags; /* flags to pass to input-mt */
105}; 117};
106 118
119static void mt_post_parse_default_settings(struct mt_device *td);
120static void mt_post_parse(struct mt_device *td);
121
107/* classes of device behavior */ 122/* classes of device behavior */
108#define MT_CLS_DEFAULT 0x0001 123#define MT_CLS_DEFAULT 0x0001
109 124
@@ -246,6 +261,14 @@ static struct mt_class mt_classes[] = {
246 { } 261 { }
247}; 262};
248 263
264static void mt_free_input_name(struct hid_input *hi)
265{
266 struct hid_device *hdev = hi->report->device;
267
268 if (hi->input->name != hdev->name)
269 kfree(hi->input->name);
270}
271
249static ssize_t mt_show_quirks(struct device *dev, 272static ssize_t mt_show_quirks(struct device *dev,
250 struct device_attribute *attr, 273 struct device_attribute *attr,
251 char *buf) 274 char *buf)
@@ -354,7 +377,53 @@ static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
354 f->usages[f->length++] = usage->hid; 377 f->usages[f->length++] = usage->hid;
355} 378}
356 379
357static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, 380static int mt_pen_input_mapping(struct hid_device *hdev, struct hid_input *hi,
381 struct hid_field *field, struct hid_usage *usage,
382 unsigned long **bit, int *max)
383{
384 struct mt_device *td = hid_get_drvdata(hdev);
385
386 td->pen_report_id = field->report->id;
387
388 return 0;
389}
390
391static int mt_pen_input_mapped(struct hid_device *hdev, struct hid_input *hi,
392 struct hid_field *field, struct hid_usage *usage,
393 unsigned long **bit, int *max)
394{
395 return 0;
396}
397
398static int mt_pen_event(struct hid_device *hid, struct hid_field *field,
399 struct hid_usage *usage, __s32 value)
400{
401 /* let hid-input handle it */
402 return 0;
403}
404
405static void mt_pen_report(struct hid_device *hid, struct hid_report *report)
406{
407 struct hid_field *field = report->field[0];
408
409 input_sync(field->hidinput->input);
410}
411
412static void mt_pen_input_configured(struct hid_device *hdev,
413 struct hid_input *hi)
414{
415 char *name = kzalloc(strlen(hi->input->name) + 5, GFP_KERNEL);
416 if (name) {
417 sprintf(name, "%s Pen", hi->input->name);
418 mt_free_input_name(hi);
419 hi->input->name = name;
420 }
421
422 /* force BTN_STYLUS to allow tablet matching in udev */
423 __set_bit(BTN_STYLUS, hi->input->keybit);
424}
425
426static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
358 struct hid_field *field, struct hid_usage *usage, 427 struct hid_field *field, struct hid_usage *usage,
359 unsigned long **bit, int *max) 428 unsigned long **bit, int *max)
360{ 429{
@@ -363,13 +432,8 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
363 int code; 432 int code;
364 struct hid_usage *prev_usage = NULL; 433 struct hid_usage *prev_usage = NULL;
365 434
366 /* Only map fields from TouchScreen or TouchPad collections.
367 * We need to ignore fields that belong to other collections
368 * such as Mouse that might have the same GenericDesktop usages. */
369 if (field->application == HID_DG_TOUCHSCREEN) 435 if (field->application == HID_DG_TOUCHSCREEN)
370 td->mt_flags |= INPUT_MT_DIRECT; 436 td->mt_flags |= INPUT_MT_DIRECT;
371 else if (field->application != HID_DG_TOUCHPAD)
372 return 0;
373 437
374 /* 438 /*
375 * Model touchscreens providing buttons as touchpads. 439 * Model touchscreens providing buttons as touchpads.
@@ -378,12 +442,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
378 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) 442 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
379 td->mt_flags |= INPUT_MT_POINTER; 443 td->mt_flags |= INPUT_MT_POINTER;
380 444
381 /* eGalax devices provide a Digitizer.Stylus input which overrides
382 * the correct Digitizers.Finger X/Y ranges.
383 * Let's just ignore this input. */
384 if (field->physical == HID_DG_STYLUS)
385 return -1;
386
387 if (usage->usage_index) 445 if (usage->usage_index)
388 prev_usage = &field->usage[usage->usage_index - 1]; 446 prev_usage = &field->usage[usage->usage_index - 1];
389 447
@@ -405,7 +463,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
405 } 463 }
406 464
407 mt_store_field(usage, td, hi); 465 mt_store_field(usage, td, hi);
408 td->last_field_index = field->index;
409 return 1; 466 return 1;
410 case HID_GD_Y: 467 case HID_GD_Y:
411 if (prev_usage && (prev_usage->hid == usage->hid)) { 468 if (prev_usage && (prev_usage->hid == usage->hid)) {
@@ -421,7 +478,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
421 } 478 }
422 479
423 mt_store_field(usage, td, hi); 480 mt_store_field(usage, td, hi);
424 td->last_field_index = field->index;
425 return 1; 481 return 1;
426 } 482 }
427 return 0; 483 return 0;
@@ -436,21 +492,17 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
436 ABS_MT_DISTANCE, 0, 1, 0, 0); 492 ABS_MT_DISTANCE, 0, 1, 0, 0);
437 } 493 }
438 mt_store_field(usage, td, hi); 494 mt_store_field(usage, td, hi);
439 td->last_field_index = field->index;
440 return 1; 495 return 1;
441 case HID_DG_CONFIDENCE: 496 case HID_DG_CONFIDENCE:
442 mt_store_field(usage, td, hi); 497 mt_store_field(usage, td, hi);
443 td->last_field_index = field->index;
444 return 1; 498 return 1;
445 case HID_DG_TIPSWITCH: 499 case HID_DG_TIPSWITCH:
446 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); 500 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
447 input_set_capability(hi->input, EV_KEY, BTN_TOUCH); 501 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
448 mt_store_field(usage, td, hi); 502 mt_store_field(usage, td, hi);
449 td->last_field_index = field->index;
450 return 1; 503 return 1;
451 case HID_DG_CONTACTID: 504 case HID_DG_CONTACTID:
452 mt_store_field(usage, td, hi); 505 mt_store_field(usage, td, hi);
453 td->last_field_index = field->index;
454 td->touches_by_report++; 506 td->touches_by_report++;
455 td->mt_report_id = field->report->id; 507 td->mt_report_id = field->report->id;
456 return 1; 508 return 1;
@@ -461,7 +513,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
461 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, 513 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
462 cls->sn_width); 514 cls->sn_width);
463 mt_store_field(usage, td, hi); 515 mt_store_field(usage, td, hi);
464 td->last_field_index = field->index;
465 return 1; 516 return 1;
466 case HID_DG_HEIGHT: 517 case HID_DG_HEIGHT:
467 hid_map_usage(hi, usage, bit, max, 518 hid_map_usage(hi, usage, bit, max,
@@ -473,7 +524,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
473 ABS_MT_ORIENTATION, 0, 1, 0, 0); 524 ABS_MT_ORIENTATION, 0, 1, 0, 0);
474 } 525 }
475 mt_store_field(usage, td, hi); 526 mt_store_field(usage, td, hi);
476 td->last_field_index = field->index;
477 return 1; 527 return 1;
478 case HID_DG_TIPPRESSURE: 528 case HID_DG_TIPPRESSURE:
479 hid_map_usage(hi, usage, bit, max, 529 hid_map_usage(hi, usage, bit, max,
@@ -481,17 +531,14 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
481 set_abs(hi->input, ABS_MT_PRESSURE, field, 531 set_abs(hi->input, ABS_MT_PRESSURE, field,
482 cls->sn_pressure); 532 cls->sn_pressure);
483 mt_store_field(usage, td, hi); 533 mt_store_field(usage, td, hi);
484 td->last_field_index = field->index;
485 return 1; 534 return 1;
486 case HID_DG_CONTACTCOUNT: 535 case HID_DG_CONTACTCOUNT:
487 td->cc_index = field->index; 536 td->cc_index = field->index;
488 td->cc_value_index = usage->usage_index; 537 td->cc_value_index = usage->usage_index;
489 td->last_field_index = field->index;
490 return 1; 538 return 1;
491 case HID_DG_CONTACTMAX: 539 case HID_DG_CONTACTMAX:
492 /* we don't set td->last_slot_field as contactcount and 540 /* we don't set td->last_slot_field as contactcount and
493 * contact max are global to the report */ 541 * contact max are global to the report */
494 td->last_field_index = field->index;
495 return -1; 542 return -1;
496 case HID_DG_TOUCH: 543 case HID_DG_TOUCH:
497 /* Legacy devices use TIPSWITCH and not TOUCH. 544 /* Legacy devices use TIPSWITCH and not TOUCH.
@@ -515,7 +562,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
515 return 0; 562 return 0;
516} 563}
517 564
518static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi, 565static int mt_touch_input_mapped(struct hid_device *hdev, struct hid_input *hi,
519 struct hid_field *field, struct hid_usage *usage, 566 struct hid_field *field, struct hid_usage *usage,
520 unsigned long **bit, int *max) 567 unsigned long **bit, int *max)
521{ 568{
@@ -606,7 +653,7 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
606 td->num_received = 0; 653 td->num_received = 0;
607} 654}
608 655
609static int mt_event(struct hid_device *hid, struct hid_field *field, 656static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
610 struct hid_usage *usage, __s32 value) 657 struct hid_usage *usage, __s32 value)
611{ 658{
612 /* we will handle the hidinput part later, now remains hiddev */ 659 /* we will handle the hidinput part later, now remains hiddev */
@@ -680,29 +727,19 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
680 if (usage->usage_index + 1 == field->report_count) { 727 if (usage->usage_index + 1 == field->report_count) {
681 /* we only take into account the last report. */ 728 /* we only take into account the last report. */
682 if (usage->hid == td->last_slot_field) 729 if (usage->hid == td->last_slot_field)
683 mt_complete_slot(td, input); 730 mt_complete_slot(td, field->hidinput->input);
684
685 if (field->index == td->last_field_index
686 && td->num_received >= td->num_expected)
687 mt_sync_frame(td, field->hidinput->input);
688 } 731 }
689 732
690 } 733 }
691} 734}
692 735
693static void mt_report(struct hid_device *hid, struct hid_report *report) 736static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
694{ 737{
695 struct mt_device *td = hid_get_drvdata(hid); 738 struct mt_device *td = hid_get_drvdata(hid);
696 struct hid_field *field; 739 struct hid_field *field;
697 unsigned count; 740 unsigned count;
698 int r, n; 741 int r, n;
699 742
700 if (report->id != td->mt_report_id)
701 return;
702
703 if (!(hid->claimed & HID_CLAIMED_INPUT))
704 return;
705
706 /* 743 /*
707 * Includes multi-packet support where subsequent 744 * Includes multi-packet support where subsequent
708 * packets are sent with zero contactcount. 745 * packets are sent with zero contactcount.
@@ -725,6 +762,91 @@ static void mt_report(struct hid_device *hid, struct hid_report *report)
725 mt_process_mt_event(hid, field, &field->usage[n], 762 mt_process_mt_event(hid, field, &field->usage[n],
726 field->value[n]); 763 field->value[n]);
727 } 764 }
765
766 if (td->num_received >= td->num_expected)
767 mt_sync_frame(td, report->field[0]->hidinput->input);
768}
769
770static void mt_touch_input_configured(struct hid_device *hdev,
771 struct hid_input *hi)
772{
773 struct mt_device *td = hid_get_drvdata(hdev);
774 struct mt_class *cls = &td->mtclass;
775 struct input_dev *input = hi->input;
776
777 if (!td->maxcontacts)
778 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
779
780 mt_post_parse(td);
781 if (td->serial_maybe)
782 mt_post_parse_default_settings(td);
783
784 if (cls->is_indirect)
785 td->mt_flags |= INPUT_MT_POINTER;
786
787 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
788 td->mt_flags |= INPUT_MT_DROP_UNUSED;
789
790 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
791
792 td->mt_flags = 0;
793}
794
795static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
796 struct hid_field *field, struct hid_usage *usage,
797 unsigned long **bit, int *max)
798{
799 /* Only map fields from TouchScreen or TouchPad collections.
800 * We need to ignore fields that belong to other collections
801 * such as Mouse that might have the same GenericDesktop usages. */
802 if (field->application != HID_DG_TOUCHSCREEN &&
803 field->application != HID_DG_PEN &&
804 field->application != HID_DG_TOUCHPAD)
805 return -1;
806
807 if (field->physical == HID_DG_STYLUS)
808 return mt_pen_input_mapping(hdev, hi, field, usage, bit, max);
809
810 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max);
811}
812
813static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
814 struct hid_field *field, struct hid_usage *usage,
815 unsigned long **bit, int *max)
816{
817 if (field->physical == HID_DG_STYLUS)
818 return mt_pen_input_mapped(hdev, hi, field, usage, bit, max);
819
820 return mt_touch_input_mapped(hdev, hi, field, usage, bit, max);
821}
822
823static int mt_event(struct hid_device *hid, struct hid_field *field,
824 struct hid_usage *usage, __s32 value)
825{
826 struct mt_device *td = hid_get_drvdata(hid);
827
828 if (field->report->id == td->mt_report_id)
829 return mt_touch_event(hid, field, usage, value);
830
831 if (field->report->id == td->pen_report_id)
832 return mt_pen_event(hid, field, usage, value);
833
834 /* ignore other reports */
835 return 1;
836}
837
838static void mt_report(struct hid_device *hid, struct hid_report *report)
839{
840 struct mt_device *td = hid_get_drvdata(hid);
841
842 if (!(hid->claimed & HID_CLAIMED_INPUT))
843 return;
844
845 if (report->id == td->mt_report_id)
846 mt_touch_report(hid, report);
847
848 if (report->id == td->pen_report_id)
849 mt_pen_report(hid, report);
728} 850}
729 851
730static void mt_set_input_mode(struct hid_device *hdev) 852static void mt_set_input_mode(struct hid_device *hdev)
@@ -740,7 +862,7 @@ static void mt_set_input_mode(struct hid_device *hdev)
740 r = re->report_id_hash[td->inputmode]; 862 r = re->report_id_hash[td->inputmode];
741 if (r) { 863 if (r) {
742 r->field[0]->value[td->inputmode_index] = 0x02; 864 r->field[0]->value[td->inputmode_index] = 0x02;
743 usbhid_submit_report(hdev, r, USB_DIR_OUT); 865 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
744 } 866 }
745} 867}
746 868
@@ -765,7 +887,7 @@ static void mt_set_maxcontacts(struct hid_device *hdev)
765 max = min(fieldmax, max); 887 max = min(fieldmax, max);
766 if (r->field[0]->value[0] != max) { 888 if (r->field[0]->value[0] != max) {
767 r->field[0]->value[0] = max; 889 r->field[0]->value[0] = max;
768 usbhid_submit_report(hdev, r, USB_DIR_OUT); 890 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
769 } 891 }
770 } 892 }
771} 893}
@@ -801,32 +923,18 @@ static void mt_post_parse(struct mt_device *td)
801} 923}
802 924
803static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi) 925static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
804
805{ 926{
806 struct mt_device *td = hid_get_drvdata(hdev); 927 struct mt_device *td = hid_get_drvdata(hdev);
807 struct mt_class *cls = &td->mtclass; 928 char *name = kstrdup(hdev->name, GFP_KERNEL);
808 struct input_dev *input = hi->input;
809 929
810 /* Only initialize slots for MT input devices */ 930 if (name)
811 if (!test_bit(ABS_MT_POSITION_X, input->absbit)) 931 hi->input->name = name;
812 return;
813 932
814 if (!td->maxcontacts) 933 if (hi->report->id == td->mt_report_id)
815 td->maxcontacts = MT_DEFAULT_MAXCONTACT; 934 mt_touch_input_configured(hdev, hi);
816 935
817 mt_post_parse(td); 936 if (hi->report->id == td->pen_report_id)
818 if (td->serial_maybe) 937 mt_pen_input_configured(hdev, hi);
819 mt_post_parse_default_settings(td);
820
821 if (cls->is_indirect)
822 td->mt_flags |= INPUT_MT_POINTER;
823
824 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
825 td->mt_flags |= INPUT_MT_DROP_UNUSED;
826
827 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
828
829 td->mt_flags = 0;
830} 938}
831 939
832static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) 940static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
@@ -834,6 +942,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
834 int ret, i; 942 int ret, i;
835 struct mt_device *td; 943 struct mt_device *td;
836 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 944 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
945 struct hid_input *hi;
837 946
838 for (i = 0; mt_classes[i].name ; i++) { 947 for (i = 0; mt_classes[i].name ; i++) {
839 if (id->driver_data == mt_classes[i].name) { 948 if (id->driver_data == mt_classes[i].name) {
@@ -847,6 +956,14 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
847 */ 956 */
848 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; 957 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
849 958
959 /*
960 * This allows the driver to handle different input sensors
961 * that emits events through different reports on the same HID
962 * device.
963 */
964 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
965 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
966
850 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); 967 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
851 if (!td) { 968 if (!td) {
852 dev_err(&hdev->dev, "cannot allocate multitouch data\n"); 969 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
@@ -856,6 +973,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
856 td->inputmode = -1; 973 td->inputmode = -1;
857 td->maxcontact_report_id = -1; 974 td->maxcontact_report_id = -1;
858 td->cc_index = -1; 975 td->cc_index = -1;
976 td->mt_report_id = -1;
977 td->pen_report_id = -1;
859 hid_set_drvdata(hdev, td); 978 hid_set_drvdata(hdev, td);
860 979
861 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL); 980 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
@@ -874,7 +993,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
874 993
875 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 994 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
876 if (ret) 995 if (ret)
877 goto fail; 996 goto hid_fail;
878 997
879 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); 998 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
880 999
@@ -886,6 +1005,9 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
886 1005
887 return 0; 1006 return 0;
888 1007
1008hid_fail:
1009 list_for_each_entry(hi, &hdev->inputs, list)
1010 mt_free_input_name(hi);
889fail: 1011fail:
890 kfree(td->fields); 1012 kfree(td->fields);
891 kfree(td); 1013 kfree(td);
@@ -902,26 +1024,11 @@ static int mt_reset_resume(struct hid_device *hdev)
902 1024
903static int mt_resume(struct hid_device *hdev) 1025static int mt_resume(struct hid_device *hdev)
904{ 1026{
905 struct usb_interface *intf;
906 struct usb_host_interface *interface;
907 struct usb_device *dev;
908
909 if (hdev->bus != BUS_USB)
910 return 0;
911
912 intf = to_usb_interface(hdev->dev.parent);
913 interface = intf->cur_altsetting;
914 dev = hid_to_usb_dev(hdev);
915
916 /* Some Elan legacy devices require SET_IDLE to be set on resume. 1027 /* Some Elan legacy devices require SET_IDLE to be set on resume.
917 * It should be safe to send it to other devices too. 1028 * It should be safe to send it to other devices too.
918 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */ 1029 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
919 1030
920 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1031 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
921 HID_REQ_SET_IDLE,
922 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
923 0, interface->desc.bInterfaceNumber,
924 NULL, 0, USB_CTRL_SET_TIMEOUT);
925 1032
926 return 0; 1033 return 0;
927} 1034}
@@ -930,8 +1037,14 @@ static int mt_resume(struct hid_device *hdev)
930static void mt_remove(struct hid_device *hdev) 1037static void mt_remove(struct hid_device *hdev)
931{ 1038{
932 struct mt_device *td = hid_get_drvdata(hdev); 1039 struct mt_device *td = hid_get_drvdata(hdev);
1040 struct hid_input *hi;
1041
933 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); 1042 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
934 hid_hw_stop(hdev); 1043 hid_hw_stop(hdev);
1044
1045 list_for_each_entry(hi, &hdev->inputs, list)
1046 mt_free_input_name(hi);
1047
935 kfree(td); 1048 kfree(td);
936 hid_set_drvdata(hdev, NULL); 1049 hid_set_drvdata(hdev, NULL);
937} 1050}