This source file includes following definitions.
- cypress_compute_slot
- mt_show_quirks
- mt_set_quirks
- mt_get_feature
- mt_feature_mapping
- set_abs
- mt_allocate_usage
- mt_allocate_application
- mt_find_application
- mt_allocate_report_data
- mt_find_report_data
- mt_store_field
- mt_touch_input_mapping
- mt_compute_slot
- mt_release_pending_palms
- mt_sync_frame
- mt_compute_timestamp
- mt_touch_event
- mt_process_slot
- mt_process_mt_event
- mt_touch_report
- mt_touch_input_configured
- mt_input_mapping
- mt_input_mapped
- mt_event
- mt_report
- mt_need_to_apply_feature
- mt_set_modes
- mt_post_parse_default_settings
- mt_post_parse
- mt_input_configured
- mt_fix_const_field
- mt_fix_const_fields
- mt_release_contacts
- mt_expired_timeout
- mt_probe
- mt_reset_resume
- mt_resume
- mt_remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <linux/device.h>
35 #include <linux/hid.h>
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/input/mt.h>
39 #include <linux/jiffies.h>
40 #include <linux/string.h>
41 #include <linux/timer.h>
42
43
44 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
45 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
46 MODULE_DESCRIPTION("HID multitouch panels");
47 MODULE_LICENSE("GPL");
48
49 #include "hid-ids.h"
50
51
52 #define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
53 #define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
54 #define MT_QUIRK_CYPRESS BIT(2)
55 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
56 #define MT_QUIRK_ALWAYS_VALID BIT(4)
57 #define MT_QUIRK_VALID_IS_INRANGE BIT(5)
58 #define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
59 #define MT_QUIRK_CONFIDENCE BIT(7)
60 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
61 #define MT_QUIRK_NO_AREA BIT(9)
62 #define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
63 #define MT_QUIRK_HOVERING BIT(11)
64 #define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
65 #define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
66 #define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
67 #define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
68 #define MT_QUIRK_STICKY_FINGERS BIT(16)
69 #define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
70 #define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
71 #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19)
72 #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20)
73
74 #define MT_INPUTMODE_TOUCHSCREEN 0x02
75 #define MT_INPUTMODE_TOUCHPAD 0x03
76
77 #define MT_BUTTONTYPE_CLICKPAD 0
78
79 enum latency_mode {
80 HID_LATENCY_NORMAL = 0,
81 HID_LATENCY_HIGH = 1,
82 };
83
84 #define MT_IO_FLAGS_RUNNING 0
85 #define MT_IO_FLAGS_ACTIVE_SLOTS 1
86 #define MT_IO_FLAGS_PENDING_SLOTS 2
87
88 static const bool mtrue = true;
89 static const bool mfalse;
90 static const __s32 mzero;
91
92 #define DEFAULT_TRUE ((void *)&mtrue)
93 #define DEFAULT_FALSE ((void *)&mfalse)
94 #define DEFAULT_ZERO ((void *)&mzero)
95
96 struct mt_usages {
97 struct list_head list;
98 __s32 *x, *y, *cx, *cy, *p, *w, *h, *a;
99 __s32 *contactid;
100 bool *tip_state;
101 bool *inrange_state;
102 bool *confidence_state;
103 };
104
105 struct mt_application {
106 struct list_head list;
107 unsigned int application;
108 unsigned int report_id;
109 struct list_head mt_usages;
110
111 __s32 quirks;
112
113 __s32 *scantime;
114 __s32 scantime_logical_max;
115
116 __s32 *raw_cc;
117 int left_button_state;
118 unsigned int mt_flags;
119
120 unsigned long *pending_palm_slots;
121
122
123 __u8 num_received;
124 __u8 num_expected;
125 __u8 buttons_count;
126 __u8 touches_by_report;
127
128
129
130
131 __s32 dev_time;
132 unsigned long jiffies;
133 int timestamp;
134 int prev_scantime;
135
136 bool have_contact_count;
137 };
138
139 struct mt_class {
140 __s32 name;
141 __s32 quirks;
142 __s32 sn_move;
143 __s32 sn_width;
144 __s32 sn_height;
145 __s32 sn_pressure;
146 __u8 maxcontacts;
147 bool is_indirect;
148 bool export_all_inputs;
149 };
150
151 struct mt_report_data {
152 struct list_head list;
153 struct hid_report *report;
154 struct mt_application *application;
155 bool is_mt_collection;
156 };
157
158 struct mt_device {
159 struct mt_class mtclass;
160 struct timer_list release_timer;
161 struct hid_device *hdev;
162 unsigned long mt_io_flags;
163 __u8 inputmode_value;
164 __u8 maxcontacts;
165 bool is_buttonpad;
166 bool serial_maybe;
167
168 struct list_head applications;
169 struct list_head reports;
170 };
171
172 static void mt_post_parse_default_settings(struct mt_device *td,
173 struct mt_application *app);
174 static void mt_post_parse(struct mt_device *td, struct mt_application *app);
175
176
177 #define MT_CLS_DEFAULT 0x0001
178
179 #define MT_CLS_SERIAL 0x0002
180 #define MT_CLS_CONFIDENCE 0x0003
181 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
182 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
183 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
184 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
185
186 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
187 #define MT_CLS_NSMU 0x000a
188
189
190 #define MT_CLS_WIN_8 0x0012
191 #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
192 #define MT_CLS_WIN_8_DUAL 0x0014
193 #define MT_CLS_WIN_8_FORCE_MULTI_INPUT 0x0015
194
195
196 #define MT_CLS_3M 0x0101
197
198 #define MT_CLS_EGALAX 0x0103
199 #define MT_CLS_EGALAX_SERIAL 0x0104
200 #define MT_CLS_TOPSEED 0x0105
201 #define MT_CLS_PANASONIC 0x0106
202 #define MT_CLS_FLATFROG 0x0107
203 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
204 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
205 #define MT_CLS_LG 0x010a
206 #define MT_CLS_ASUS 0x010b
207 #define MT_CLS_VTL 0x0110
208 #define MT_CLS_GOOGLE 0x0111
209 #define MT_CLS_RAZER_BLADE_STEALTH 0x0112
210 #define MT_CLS_SMART_TECH 0x0113
211
212 #define MT_DEFAULT_MAXCONTACT 10
213 #define MT_MAX_MAXCONTACT 250
214
215
216
217
218
219 #define MAX_TIMESTAMP_INTERVAL 1000000
220
221 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
222 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
223
224
225
226
227
228
229 static int cypress_compute_slot(struct mt_application *application,
230 struct mt_usages *slot)
231 {
232 if (*slot->contactid != 0 || application->num_received == 0)
233 return *slot->contactid;
234 else
235 return -1;
236 }
237
238 static const struct mt_class mt_classes[] = {
239 { .name = MT_CLS_DEFAULT,
240 .quirks = MT_QUIRK_ALWAYS_VALID |
241 MT_QUIRK_CONTACT_CNT_ACCURATE },
242 { .name = MT_CLS_NSMU,
243 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
244 { .name = MT_CLS_SERIAL,
245 .quirks = MT_QUIRK_ALWAYS_VALID},
246 { .name = MT_CLS_CONFIDENCE,
247 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
248 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
249 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
250 MT_QUIRK_SLOT_IS_CONTACTID },
251 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
252 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
253 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
254 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
255 .quirks = MT_QUIRK_VALID_IS_INRANGE |
256 MT_QUIRK_SLOT_IS_CONTACTID,
257 .maxcontacts = 2 },
258 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
259 .quirks = MT_QUIRK_VALID_IS_INRANGE |
260 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
261 .maxcontacts = 2 },
262 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
263 .quirks = MT_QUIRK_VALID_IS_INRANGE |
264 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
265 { .name = MT_CLS_WIN_8,
266 .quirks = MT_QUIRK_ALWAYS_VALID |
267 MT_QUIRK_IGNORE_DUPLICATES |
268 MT_QUIRK_HOVERING |
269 MT_QUIRK_CONTACT_CNT_ACCURATE |
270 MT_QUIRK_STICKY_FINGERS |
271 MT_QUIRK_WIN8_PTP_BUTTONS,
272 .export_all_inputs = true },
273 { .name = MT_CLS_EXPORT_ALL_INPUTS,
274 .quirks = MT_QUIRK_ALWAYS_VALID |
275 MT_QUIRK_CONTACT_CNT_ACCURATE,
276 .export_all_inputs = true },
277 { .name = MT_CLS_WIN_8_DUAL,
278 .quirks = MT_QUIRK_ALWAYS_VALID |
279 MT_QUIRK_IGNORE_DUPLICATES |
280 MT_QUIRK_HOVERING |
281 MT_QUIRK_CONTACT_CNT_ACCURATE |
282 MT_QUIRK_WIN8_PTP_BUTTONS,
283 .export_all_inputs = true },
284 { .name = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
285 .quirks = MT_QUIRK_ALWAYS_VALID |
286 MT_QUIRK_IGNORE_DUPLICATES |
287 MT_QUIRK_HOVERING |
288 MT_QUIRK_CONTACT_CNT_ACCURATE |
289 MT_QUIRK_STICKY_FINGERS |
290 MT_QUIRK_WIN8_PTP_BUTTONS |
291 MT_QUIRK_FORCE_MULTI_INPUT,
292 .export_all_inputs = true },
293
294
295
296
297 { .name = MT_CLS_3M,
298 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
299 MT_QUIRK_SLOT_IS_CONTACTID |
300 MT_QUIRK_TOUCH_SIZE_SCALING,
301 .sn_move = 2048,
302 .sn_width = 128,
303 .sn_height = 128,
304 .maxcontacts = 60,
305 },
306 { .name = MT_CLS_EGALAX,
307 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
308 MT_QUIRK_VALID_IS_INRANGE,
309 .sn_move = 4096,
310 .sn_pressure = 32,
311 },
312 { .name = MT_CLS_EGALAX_SERIAL,
313 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
314 MT_QUIRK_ALWAYS_VALID,
315 .sn_move = 4096,
316 .sn_pressure = 32,
317 },
318 { .name = MT_CLS_TOPSEED,
319 .quirks = MT_QUIRK_ALWAYS_VALID,
320 .is_indirect = true,
321 .maxcontacts = 2,
322 },
323 { .name = MT_CLS_PANASONIC,
324 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
325 .maxcontacts = 4 },
326 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
327 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
328 MT_QUIRK_VALID_IS_INRANGE |
329 MT_QUIRK_SLOT_IS_CONTACTID,
330 .maxcontacts = 2
331 },
332 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
333 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
334 MT_QUIRK_SLOT_IS_CONTACTID
335 },
336
337 { .name = MT_CLS_FLATFROG,
338 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
339 MT_QUIRK_NO_AREA,
340 .sn_move = 2048,
341 .maxcontacts = 40,
342 },
343 { .name = MT_CLS_LG,
344 .quirks = MT_QUIRK_ALWAYS_VALID |
345 MT_QUIRK_FIX_CONST_CONTACT_ID |
346 MT_QUIRK_IGNORE_DUPLICATES |
347 MT_QUIRK_HOVERING |
348 MT_QUIRK_CONTACT_CNT_ACCURATE },
349 { .name = MT_CLS_ASUS,
350 .quirks = MT_QUIRK_ALWAYS_VALID |
351 MT_QUIRK_CONTACT_CNT_ACCURATE |
352 MT_QUIRK_ASUS_CUSTOM_UP },
353 { .name = MT_CLS_VTL,
354 .quirks = MT_QUIRK_ALWAYS_VALID |
355 MT_QUIRK_CONTACT_CNT_ACCURATE |
356 MT_QUIRK_FORCE_GET_FEATURE,
357 },
358 { .name = MT_CLS_GOOGLE,
359 .quirks = MT_QUIRK_ALWAYS_VALID |
360 MT_QUIRK_CONTACT_CNT_ACCURATE |
361 MT_QUIRK_SLOT_IS_CONTACTID |
362 MT_QUIRK_HOVERING
363 },
364 { .name = MT_CLS_RAZER_BLADE_STEALTH,
365 .quirks = MT_QUIRK_ALWAYS_VALID |
366 MT_QUIRK_IGNORE_DUPLICATES |
367 MT_QUIRK_HOVERING |
368 MT_QUIRK_CONTACT_CNT_ACCURATE |
369 MT_QUIRK_WIN8_PTP_BUTTONS,
370 },
371 { .name = MT_CLS_SMART_TECH,
372 .quirks = MT_QUIRK_ALWAYS_VALID |
373 MT_QUIRK_IGNORE_DUPLICATES |
374 MT_QUIRK_CONTACT_CNT_ACCURATE |
375 MT_QUIRK_SEPARATE_APP_REPORT,
376 },
377 { }
378 };
379
380 static ssize_t mt_show_quirks(struct device *dev,
381 struct device_attribute *attr,
382 char *buf)
383 {
384 struct hid_device *hdev = to_hid_device(dev);
385 struct mt_device *td = hid_get_drvdata(hdev);
386
387 return sprintf(buf, "%u\n", td->mtclass.quirks);
388 }
389
390 static ssize_t mt_set_quirks(struct device *dev,
391 struct device_attribute *attr,
392 const char *buf, size_t count)
393 {
394 struct hid_device *hdev = to_hid_device(dev);
395 struct mt_device *td = hid_get_drvdata(hdev);
396 struct mt_application *application;
397
398 unsigned long val;
399
400 if (kstrtoul(buf, 0, &val))
401 return -EINVAL;
402
403 td->mtclass.quirks = val;
404
405 list_for_each_entry(application, &td->applications, list) {
406 application->quirks = val;
407 if (!application->have_contact_count)
408 application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
409 }
410
411 return count;
412 }
413
414 static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
415
416 static struct attribute *sysfs_attrs[] = {
417 &dev_attr_quirks.attr,
418 NULL
419 };
420
421 static const struct attribute_group mt_attribute_group = {
422 .attrs = sysfs_attrs
423 };
424
425 static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
426 {
427 int ret;
428 u32 size = hid_report_len(report);
429 u8 *buf;
430
431
432
433
434
435 if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
436 return;
437
438 buf = hid_alloc_report_buf(report, GFP_KERNEL);
439 if (!buf)
440 return;
441
442 ret = hid_hw_raw_request(hdev, report->id, buf, size,
443 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
444 if (ret < 0) {
445 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
446 report->id);
447 } else {
448 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
449 size, 0);
450 if (ret)
451 dev_warn(&hdev->dev, "failed to report feature\n");
452 }
453
454 kfree(buf);
455 }
456
457 static void mt_feature_mapping(struct hid_device *hdev,
458 struct hid_field *field, struct hid_usage *usage)
459 {
460 struct mt_device *td = hid_get_drvdata(hdev);
461
462 switch (usage->hid) {
463 case HID_DG_CONTACTMAX:
464 mt_get_feature(hdev, field->report);
465
466 td->maxcontacts = field->value[0];
467 if (!td->maxcontacts &&
468 field->logical_maximum <= MT_MAX_MAXCONTACT)
469 td->maxcontacts = field->logical_maximum;
470 if (td->mtclass.maxcontacts)
471
472 td->maxcontacts = td->mtclass.maxcontacts;
473
474 break;
475 case HID_DG_BUTTONTYPE:
476 if (usage->usage_index >= field->report_count) {
477 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
478 break;
479 }
480
481 mt_get_feature(hdev, field->report);
482 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
483 td->is_buttonpad = true;
484
485 break;
486 case 0xff0000c5:
487
488 if (usage->usage_index == 0)
489 mt_get_feature(hdev, field->report);
490 break;
491 }
492 }
493
494 static void set_abs(struct input_dev *input, unsigned int code,
495 struct hid_field *field, int snratio)
496 {
497 int fmin = field->logical_minimum;
498 int fmax = field->logical_maximum;
499 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
500 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
501 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
502 }
503
504 static struct mt_usages *mt_allocate_usage(struct hid_device *hdev,
505 struct mt_application *application)
506 {
507 struct mt_usages *usage;
508
509 usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL);
510 if (!usage)
511 return NULL;
512
513
514 usage->x = DEFAULT_ZERO;
515 usage->y = DEFAULT_ZERO;
516 usage->cx = DEFAULT_ZERO;
517 usage->cy = DEFAULT_ZERO;
518 usage->p = DEFAULT_ZERO;
519 usage->w = DEFAULT_ZERO;
520 usage->h = DEFAULT_ZERO;
521 usage->a = DEFAULT_ZERO;
522 usage->contactid = DEFAULT_ZERO;
523 usage->tip_state = DEFAULT_FALSE;
524 usage->inrange_state = DEFAULT_FALSE;
525 usage->confidence_state = DEFAULT_TRUE;
526
527 list_add_tail(&usage->list, &application->mt_usages);
528
529 return usage;
530 }
531
532 static struct mt_application *mt_allocate_application(struct mt_device *td,
533 struct hid_report *report)
534 {
535 unsigned int application = report->application;
536 struct mt_application *mt_application;
537
538 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
539 GFP_KERNEL);
540 if (!mt_application)
541 return NULL;
542
543 mt_application->application = application;
544 INIT_LIST_HEAD(&mt_application->mt_usages);
545
546 if (application == HID_DG_TOUCHSCREEN)
547 mt_application->mt_flags |= INPUT_MT_DIRECT;
548
549
550
551
552 if (application == HID_DG_TOUCHPAD) {
553 mt_application->mt_flags |= INPUT_MT_POINTER;
554 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
555 }
556
557 mt_application->scantime = DEFAULT_ZERO;
558 mt_application->raw_cc = DEFAULT_ZERO;
559 mt_application->quirks = td->mtclass.quirks;
560 mt_application->report_id = report->id;
561
562 list_add_tail(&mt_application->list, &td->applications);
563
564 return mt_application;
565 }
566
567 static struct mt_application *mt_find_application(struct mt_device *td,
568 struct hid_report *report)
569 {
570 unsigned int application = report->application;
571 struct mt_application *tmp, *mt_application = NULL;
572
573 list_for_each_entry(tmp, &td->applications, list) {
574 if (application == tmp->application) {
575 if (!(td->mtclass.quirks & MT_QUIRK_SEPARATE_APP_REPORT) ||
576 tmp->report_id == report->id) {
577 mt_application = tmp;
578 break;
579 }
580 }
581 }
582
583 if (!mt_application)
584 mt_application = mt_allocate_application(td, report);
585
586 return mt_application;
587 }
588
589 static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
590 struct hid_report *report)
591 {
592 struct mt_report_data *rdata;
593 struct hid_field *field;
594 int r, n;
595
596 rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL);
597 if (!rdata)
598 return NULL;
599
600 rdata->report = report;
601 rdata->application = mt_find_application(td, report);
602
603 if (!rdata->application) {
604 devm_kfree(&td->hdev->dev, rdata);
605 return NULL;
606 }
607
608 for (r = 0; r < report->maxfield; r++) {
609 field = report->field[r];
610
611 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
612 continue;
613
614 for (n = 0; n < field->report_count; n++) {
615 if (field->usage[n].hid == HID_DG_CONTACTID)
616 rdata->is_mt_collection = true;
617 }
618 }
619
620 list_add_tail(&rdata->list, &td->reports);
621
622 return rdata;
623 }
624
625 static struct mt_report_data *mt_find_report_data(struct mt_device *td,
626 struct hid_report *report)
627 {
628 struct mt_report_data *tmp, *rdata = NULL;
629
630 list_for_each_entry(tmp, &td->reports, list) {
631 if (report == tmp->report) {
632 rdata = tmp;
633 break;
634 }
635 }
636
637 if (!rdata)
638 rdata = mt_allocate_report_data(td, report);
639
640 return rdata;
641 }
642
643 static void mt_store_field(struct hid_device *hdev,
644 struct mt_application *application,
645 __s32 *value,
646 size_t offset)
647 {
648 struct mt_usages *usage;
649 __s32 **target;
650
651 if (list_empty(&application->mt_usages))
652 usage = mt_allocate_usage(hdev, application);
653 else
654 usage = list_last_entry(&application->mt_usages,
655 struct mt_usages,
656 list);
657
658 if (!usage)
659 return;
660
661 target = (__s32 **)((char *)usage + offset);
662
663
664 if (*target != DEFAULT_TRUE &&
665 *target != DEFAULT_FALSE &&
666 *target != DEFAULT_ZERO) {
667 if (usage->contactid == DEFAULT_ZERO ||
668 usage->x == DEFAULT_ZERO ||
669 usage->y == DEFAULT_ZERO) {
670 hid_dbg(hdev,
671 "ignoring duplicate usage on incomplete");
672 return;
673 }
674 usage = mt_allocate_usage(hdev, application);
675 if (!usage)
676 return;
677
678 target = (__s32 **)((char *)usage + offset);
679 }
680
681 *target = value;
682 }
683
684 #define MT_STORE_FIELD(__name) \
685 mt_store_field(hdev, app, \
686 &field->value[usage->usage_index], \
687 offsetof(struct mt_usages, __name))
688
689 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
690 struct hid_field *field, struct hid_usage *usage,
691 unsigned long **bit, int *max, struct mt_application *app)
692 {
693 struct mt_device *td = hid_get_drvdata(hdev);
694 struct mt_class *cls = &td->mtclass;
695 int code;
696 struct hid_usage *prev_usage = NULL;
697
698
699
700
701 if (field->application == HID_DG_TOUCHSCREEN &&
702 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
703 app->mt_flags |= INPUT_MT_POINTER;
704 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
705 }
706
707
708 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
709 app->buttons_count++;
710
711 if (usage->usage_index)
712 prev_usage = &field->usage[usage->usage_index - 1];
713
714 switch (usage->hid & HID_USAGE_PAGE) {
715
716 case HID_UP_GENDESK:
717 switch (usage->hid) {
718 case HID_GD_X:
719 if (prev_usage && (prev_usage->hid == usage->hid)) {
720 code = ABS_MT_TOOL_X;
721 MT_STORE_FIELD(cx);
722 } else {
723 code = ABS_MT_POSITION_X;
724 MT_STORE_FIELD(x);
725 }
726
727 set_abs(hi->input, code, field, cls->sn_move);
728
729
730
731
732
733 if (field->application == HID_GD_SYSTEM_MULTIAXIS) {
734 __set_bit(INPUT_PROP_DIRECT,
735 hi->input->propbit);
736 input_set_abs_params(hi->input,
737 ABS_MT_TOOL_TYPE,
738 MT_TOOL_DIAL,
739 MT_TOOL_DIAL, 0, 0);
740 }
741
742 return 1;
743 case HID_GD_Y:
744 if (prev_usage && (prev_usage->hid == usage->hid)) {
745 code = ABS_MT_TOOL_Y;
746 MT_STORE_FIELD(cy);
747 } else {
748 code = ABS_MT_POSITION_Y;
749 MT_STORE_FIELD(y);
750 }
751
752 set_abs(hi->input, code, field, cls->sn_move);
753
754 return 1;
755 }
756 return 0;
757
758 case HID_UP_DIGITIZER:
759 switch (usage->hid) {
760 case HID_DG_INRANGE:
761 if (app->quirks & MT_QUIRK_HOVERING) {
762 input_set_abs_params(hi->input,
763 ABS_MT_DISTANCE, 0, 1, 0, 0);
764 }
765 MT_STORE_FIELD(inrange_state);
766 return 1;
767 case HID_DG_CONFIDENCE:
768 if ((cls->name == MT_CLS_WIN_8 ||
769 cls->name == MT_CLS_WIN_8_DUAL) &&
770 (field->application == HID_DG_TOUCHPAD ||
771 field->application == HID_DG_TOUCHSCREEN))
772 app->quirks |= MT_QUIRK_CONFIDENCE;
773
774 if (app->quirks & MT_QUIRK_CONFIDENCE)
775 input_set_abs_params(hi->input,
776 ABS_MT_TOOL_TYPE,
777 MT_TOOL_FINGER,
778 MT_TOOL_PALM, 0, 0);
779
780 MT_STORE_FIELD(confidence_state);
781 return 1;
782 case HID_DG_TIPSWITCH:
783 if (field->application != HID_GD_SYSTEM_MULTIAXIS)
784 input_set_capability(hi->input,
785 EV_KEY, BTN_TOUCH);
786 MT_STORE_FIELD(tip_state);
787 return 1;
788 case HID_DG_CONTACTID:
789 MT_STORE_FIELD(contactid);
790 app->touches_by_report++;
791 return 1;
792 case HID_DG_WIDTH:
793 if (!(app->quirks & MT_QUIRK_NO_AREA))
794 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
795 cls->sn_width);
796 MT_STORE_FIELD(w);
797 return 1;
798 case HID_DG_HEIGHT:
799 if (!(app->quirks & MT_QUIRK_NO_AREA)) {
800 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
801 cls->sn_height);
802
803
804
805
806
807 if (!test_bit(ABS_MT_ORIENTATION,
808 hi->input->absbit))
809 input_set_abs_params(hi->input,
810 ABS_MT_ORIENTATION, 0, 1, 0, 0);
811 }
812 MT_STORE_FIELD(h);
813 return 1;
814 case HID_DG_TIPPRESSURE:
815 set_abs(hi->input, ABS_MT_PRESSURE, field,
816 cls->sn_pressure);
817 MT_STORE_FIELD(p);
818 return 1;
819 case HID_DG_SCANTIME:
820 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
821 app->scantime = &field->value[usage->usage_index];
822 app->scantime_logical_max = field->logical_maximum;
823 return 1;
824 case HID_DG_CONTACTCOUNT:
825 app->have_contact_count = true;
826 app->raw_cc = &field->value[usage->usage_index];
827 return 1;
828 case HID_DG_AZIMUTH:
829
830
831
832
833
834 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
835 -field->logical_maximum / 4,
836 field->logical_maximum / 4,
837 cls->sn_move ?
838 field->logical_maximum / cls->sn_move : 0, 0);
839 MT_STORE_FIELD(a);
840 return 1;
841 case HID_DG_CONTACTMAX:
842
843 return -1;
844 case HID_DG_TOUCH:
845
846
847 return -1;
848 }
849
850 return 0;
851
852 case HID_UP_BUTTON:
853 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
854
855
856
857
858 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
859 field->application == HID_DG_TOUCHPAD &&
860 (usage->hid & HID_USAGE) > 1)
861 code--;
862
863 if (field->application == HID_GD_SYSTEM_MULTIAXIS)
864 code = BTN_0 + ((usage->hid - 1) & HID_USAGE);
865
866 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
867 input_set_capability(hi->input, EV_KEY, code);
868 return 1;
869
870 case 0xff000000:
871
872 return -1;
873 }
874
875 return 0;
876 }
877
878 static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
879 struct mt_usages *slot,
880 struct input_dev *input)
881 {
882 __s32 quirks = app->quirks;
883
884 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
885 return *slot->contactid;
886
887 if (quirks & MT_QUIRK_CYPRESS)
888 return cypress_compute_slot(app, slot);
889
890 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
891 return app->num_received;
892
893 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
894 return *slot->contactid - 1;
895
896 return input_mt_get_slot_by_key(input, *slot->contactid);
897 }
898
899 static void mt_release_pending_palms(struct mt_device *td,
900 struct mt_application *app,
901 struct input_dev *input)
902 {
903 int slotnum;
904 bool need_sync = false;
905
906 for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) {
907 clear_bit(slotnum, app->pending_palm_slots);
908
909 input_mt_slot(input, slotnum);
910 input_mt_report_slot_state(input, MT_TOOL_PALM, false);
911
912 need_sync = true;
913 }
914
915 if (need_sync) {
916 input_mt_sync_frame(input);
917 input_sync(input);
918 }
919 }
920
921
922
923
924
925 static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
926 struct input_dev *input)
927 {
928 if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
929 input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
930
931 input_mt_sync_frame(input);
932 input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
933 input_sync(input);
934
935 mt_release_pending_palms(td, app, input);
936
937 app->num_received = 0;
938 app->left_button_state = 0;
939
940 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
941 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
942 else
943 clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
944 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
945 }
946
947 static int mt_compute_timestamp(struct mt_application *app, __s32 value)
948 {
949 long delta = value - app->prev_scantime;
950 unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
951
952 app->jiffies = jiffies;
953
954 if (delta < 0)
955 delta += app->scantime_logical_max;
956
957
958 delta *= 100;
959
960 if (jdelta > MAX_TIMESTAMP_INTERVAL)
961
962 return 0;
963 else
964 return app->timestamp + delta;
965 }
966
967 static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
968 struct hid_usage *usage, __s32 value)
969 {
970
971 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
972 hid->hiddev_hid_event(hid, field, usage, value);
973
974 return 1;
975 }
976
977 static int mt_process_slot(struct mt_device *td, struct input_dev *input,
978 struct mt_application *app,
979 struct mt_usages *slot)
980 {
981 struct input_mt *mt = input->mt;
982 __s32 quirks = app->quirks;
983 bool valid = true;
984 bool confidence_state = true;
985 bool inrange_state = false;
986 int active;
987 int slotnum;
988 int tool = MT_TOOL_FINGER;
989
990 if (!slot)
991 return -EINVAL;
992
993 if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
994 app->num_received >= app->num_expected)
995 return -EAGAIN;
996
997 if (!(quirks & MT_QUIRK_ALWAYS_VALID)) {
998 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
999 valid = *slot->inrange_state;
1000 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
1001 valid = *slot->tip_state;
1002 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
1003 valid = *slot->confidence_state;
1004
1005 if (!valid)
1006 return 0;
1007 }
1008
1009 slotnum = mt_compute_slot(td, app, slot, input);
1010 if (slotnum < 0 || slotnum >= td->maxcontacts)
1011 return 0;
1012
1013 if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
1014 struct input_mt_slot *i_slot = &mt->slots[slotnum];
1015
1016 if (input_mt_is_active(i_slot) &&
1017 input_mt_is_used(mt, i_slot))
1018 return -EAGAIN;
1019 }
1020
1021 if (quirks & MT_QUIRK_CONFIDENCE)
1022 confidence_state = *slot->confidence_state;
1023
1024 if (quirks & MT_QUIRK_HOVERING)
1025 inrange_state = *slot->inrange_state;
1026
1027 active = *slot->tip_state || inrange_state;
1028
1029 if (app->application == HID_GD_SYSTEM_MULTIAXIS)
1030 tool = MT_TOOL_DIAL;
1031 else if (unlikely(!confidence_state)) {
1032 tool = MT_TOOL_PALM;
1033 if (!active && mt &&
1034 input_mt_is_active(&mt->slots[slotnum])) {
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044 active = true;
1045 set_bit(slotnum, app->pending_palm_slots);
1046 }
1047 }
1048
1049 input_mt_slot(input, slotnum);
1050 input_mt_report_slot_state(input, tool, active);
1051 if (active) {
1052
1053 int wide = (*slot->w > *slot->h);
1054 int major = max(*slot->w, *slot->h);
1055 int minor = min(*slot->w, *slot->h);
1056 int orientation = wide;
1057 int max_azimuth;
1058 int azimuth;
1059
1060 if (slot->a != DEFAULT_ZERO) {
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071 azimuth = *slot->a;
1072 max_azimuth = input_abs_get_max(input,
1073 ABS_MT_ORIENTATION);
1074 if (azimuth > max_azimuth * 2)
1075 azimuth -= max_azimuth * 4;
1076 orientation = -azimuth;
1077 }
1078
1079 if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
1080
1081
1082
1083
1084 major = major >> 1;
1085 minor = minor >> 1;
1086 }
1087
1088 input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x);
1089 input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y);
1090 input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx);
1091 input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy);
1092 input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state);
1093 input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation);
1094 input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p);
1095 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
1096 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
1097
1098 set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
1099 }
1100
1101 return 0;
1102 }
1103
1104 static void mt_process_mt_event(struct hid_device *hid,
1105 struct mt_application *app,
1106 struct hid_field *field,
1107 struct hid_usage *usage,
1108 __s32 value,
1109 bool first_packet)
1110 {
1111 __s32 quirks = app->quirks;
1112 struct input_dev *input = field->hidinput->input;
1113
1114 if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT))
1115 return;
1116
1117 if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) {
1118
1119
1120
1121
1122
1123
1124 if (!first_packet)
1125 return;
1126
1127
1128
1129
1130
1131
1132
1133
1134 if (usage->type == EV_KEY && usage->code == BTN_LEFT) {
1135 app->left_button_state |= value;
1136 return;
1137 }
1138 }
1139
1140 input_event(input, usage->type, usage->code, value);
1141 }
1142
1143 static void mt_touch_report(struct hid_device *hid,
1144 struct mt_report_data *rdata)
1145 {
1146 struct mt_device *td = hid_get_drvdata(hid);
1147 struct hid_report *report = rdata->report;
1148 struct mt_application *app = rdata->application;
1149 struct hid_field *field;
1150 struct input_dev *input;
1151 struct mt_usages *slot;
1152 bool first_packet;
1153 unsigned count;
1154 int r, n;
1155 int scantime = 0;
1156 int contact_count = -1;
1157
1158
1159 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1160 return;
1161
1162 scantime = *app->scantime;
1163 app->timestamp = mt_compute_timestamp(app, scantime);
1164 if (app->raw_cc != DEFAULT_ZERO)
1165 contact_count = *app->raw_cc;
1166
1167
1168
1169
1170
1171 if (contact_count >= 0) {
1172
1173
1174
1175
1176
1177
1178
1179 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
1180 app->num_received == 0 &&
1181 app->prev_scantime != scantime)
1182 app->num_expected = contact_count;
1183
1184 else if (contact_count)
1185 app->num_expected = contact_count;
1186 }
1187 app->prev_scantime = scantime;
1188
1189 first_packet = app->num_received == 0;
1190
1191 input = report->field[0]->hidinput->input;
1192
1193 list_for_each_entry(slot, &app->mt_usages, list) {
1194 if (!mt_process_slot(td, input, app, slot))
1195 app->num_received++;
1196 }
1197
1198 for (r = 0; r < report->maxfield; r++) {
1199 field = report->field[r];
1200 count = field->report_count;
1201
1202 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1203 continue;
1204
1205 for (n = 0; n < count; n++)
1206 mt_process_mt_event(hid, app, field,
1207 &field->usage[n], field->value[n],
1208 first_packet);
1209 }
1210
1211 if (app->num_received >= app->num_expected)
1212 mt_sync_frame(td, app, input);
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232 if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
1233 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1234 mod_timer(&td->release_timer,
1235 jiffies + msecs_to_jiffies(100));
1236 else
1237 del_timer(&td->release_timer);
1238 }
1239
1240 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1241 }
1242
1243 static int mt_touch_input_configured(struct hid_device *hdev,
1244 struct hid_input *hi,
1245 struct mt_application *app)
1246 {
1247 struct mt_device *td = hid_get_drvdata(hdev);
1248 struct mt_class *cls = &td->mtclass;
1249 struct input_dev *input = hi->input;
1250 int ret;
1251
1252 if (!td->maxcontacts)
1253 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1254
1255 mt_post_parse(td, app);
1256 if (td->serial_maybe)
1257 mt_post_parse_default_settings(td, app);
1258
1259 if (cls->is_indirect)
1260 app->mt_flags |= INPUT_MT_POINTER;
1261
1262 if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
1263 app->mt_flags |= INPUT_MT_DROP_UNUSED;
1264
1265
1266 if ((app->mt_flags & INPUT_MT_POINTER) &&
1267 (app->buttons_count == 1))
1268 td->is_buttonpad = true;
1269
1270 if (td->is_buttonpad)
1271 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1272
1273 app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
1274 BITS_TO_LONGS(td->maxcontacts),
1275 sizeof(long),
1276 GFP_KERNEL);
1277 if (!app->pending_palm_slots)
1278 return -ENOMEM;
1279
1280 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
1281 if (ret)
1282 return ret;
1283
1284 app->mt_flags = 0;
1285 return 0;
1286 }
1287
1288 #define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1289 max, EV_KEY, (c))
1290 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1291 struct hid_field *field, struct hid_usage *usage,
1292 unsigned long **bit, int *max)
1293 {
1294 struct mt_device *td = hid_get_drvdata(hdev);
1295 struct mt_application *application;
1296 struct mt_report_data *rdata;
1297
1298 rdata = mt_find_report_data(td, field->report);
1299 if (!rdata) {
1300 hid_err(hdev, "failed to allocate data for report\n");
1301 return 0;
1302 }
1303
1304 application = rdata->application;
1305
1306
1307
1308
1309
1310
1311
1312 if (!td->mtclass.export_all_inputs &&
1313 field->application != HID_DG_TOUCHSCREEN &&
1314 field->application != HID_DG_PEN &&
1315 field->application != HID_DG_TOUCHPAD &&
1316 field->application != HID_GD_KEYBOARD &&
1317 field->application != HID_GD_SYSTEM_CONTROL &&
1318 field->application != HID_CP_CONSUMER_CONTROL &&
1319 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
1320 field->application != HID_GD_SYSTEM_MULTIAXIS &&
1321 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1322 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
1323 return -1;
1324
1325
1326
1327
1328
1329
1330 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1331 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
1332 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1333 set_bit(EV_REP, hi->input->evbit);
1334 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1335 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1336 switch (usage->hid & HID_USAGE) {
1337 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1338 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1339 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1340 case 0x6b: mt_map_key_clear(KEY_F21); break;
1341 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1342 default:
1343 return -1;
1344 }
1345 return 1;
1346 }
1347
1348 if (rdata->is_mt_collection)
1349 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1350 application);
1351
1352
1353
1354
1355
1356 if (field->physical == HID_DG_STYLUS)
1357 hi->application = HID_DG_STYLUS;
1358
1359
1360 return 0;
1361 }
1362
1363 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1364 struct hid_field *field, struct hid_usage *usage,
1365 unsigned long **bit, int *max)
1366 {
1367 struct mt_device *td = hid_get_drvdata(hdev);
1368 struct mt_report_data *rdata;
1369
1370 rdata = mt_find_report_data(td, field->report);
1371 if (rdata && rdata->is_mt_collection) {
1372
1373 return -1;
1374 }
1375
1376
1377 return 0;
1378 }
1379
1380 static int mt_event(struct hid_device *hid, struct hid_field *field,
1381 struct hid_usage *usage, __s32 value)
1382 {
1383 struct mt_device *td = hid_get_drvdata(hid);
1384 struct mt_report_data *rdata;
1385
1386 rdata = mt_find_report_data(td, field->report);
1387 if (rdata && rdata->is_mt_collection)
1388 return mt_touch_event(hid, field, usage, value);
1389
1390 return 0;
1391 }
1392
1393 static void mt_report(struct hid_device *hid, struct hid_report *report)
1394 {
1395 struct mt_device *td = hid_get_drvdata(hid);
1396 struct hid_field *field = report->field[0];
1397 struct mt_report_data *rdata;
1398
1399 if (!(hid->claimed & HID_CLAIMED_INPUT))
1400 return;
1401
1402 rdata = mt_find_report_data(td, report);
1403 if (rdata && rdata->is_mt_collection)
1404 return mt_touch_report(hid, rdata);
1405
1406 if (field && field->hidinput && field->hidinput->input)
1407 input_sync(field->hidinput->input);
1408 }
1409
1410 static bool mt_need_to_apply_feature(struct hid_device *hdev,
1411 struct hid_field *field,
1412 struct hid_usage *usage,
1413 enum latency_mode latency,
1414 bool surface_switch,
1415 bool button_switch,
1416 bool *inputmode_found)
1417 {
1418 struct mt_device *td = hid_get_drvdata(hdev);
1419 struct mt_class *cls = &td->mtclass;
1420 struct hid_report *report = field->report;
1421 unsigned int index = usage->usage_index;
1422 char *buf;
1423 u32 report_len;
1424 int max;
1425
1426 switch (usage->hid) {
1427 case HID_DG_INPUTMODE:
1428
1429
1430
1431
1432
1433 if (*inputmode_found)
1434 return false;
1435
1436 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
1437 report_len = hid_report_len(report);
1438 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1439 if (!buf) {
1440 hid_err(hdev,
1441 "failed to allocate buffer for report\n");
1442 return false;
1443 }
1444 hid_hw_raw_request(hdev, report->id, buf, report_len,
1445 HID_FEATURE_REPORT,
1446 HID_REQ_GET_REPORT);
1447 kfree(buf);
1448 }
1449
1450 field->value[index] = td->inputmode_value;
1451 *inputmode_found = true;
1452 return true;
1453
1454 case HID_DG_CONTACTMAX:
1455 if (cls->maxcontacts) {
1456 max = min_t(int, field->logical_maximum,
1457 cls->maxcontacts);
1458 if (field->value[index] != max) {
1459 field->value[index] = max;
1460 return true;
1461 }
1462 }
1463 break;
1464
1465 case HID_DG_LATENCYMODE:
1466 field->value[index] = latency;
1467 return true;
1468
1469 case HID_DG_SURFACESWITCH:
1470 field->value[index] = surface_switch;
1471 return true;
1472
1473 case HID_DG_BUTTONSWITCH:
1474 field->value[index] = button_switch;
1475 return true;
1476 }
1477
1478 return false;
1479 }
1480
1481 static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1482 bool surface_switch, bool button_switch)
1483 {
1484 struct hid_report_enum *rep_enum;
1485 struct hid_report *rep;
1486 struct hid_usage *usage;
1487 int i, j;
1488 bool update_report;
1489 bool inputmode_found = false;
1490
1491 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1492 list_for_each_entry(rep, &rep_enum->report_list, list) {
1493 update_report = false;
1494
1495 for (i = 0; i < rep->maxfield; i++) {
1496
1497 if (rep->field[i]->report_count < 1)
1498 continue;
1499
1500 for (j = 0; j < rep->field[i]->maxusage; j++) {
1501 usage = &rep->field[i]->usage[j];
1502
1503 if (mt_need_to_apply_feature(hdev,
1504 rep->field[i],
1505 usage,
1506 latency,
1507 surface_switch,
1508 button_switch,
1509 &inputmode_found))
1510 update_report = true;
1511 }
1512 }
1513
1514 if (update_report)
1515 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
1516 }
1517 }
1518
1519 static void mt_post_parse_default_settings(struct mt_device *td,
1520 struct mt_application *app)
1521 {
1522 __s32 quirks = app->quirks;
1523
1524
1525 if (list_is_singular(&app->mt_usages)) {
1526 quirks |= MT_QUIRK_ALWAYS_VALID;
1527 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1528 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1529 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
1530 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1531 }
1532
1533 app->quirks = quirks;
1534 }
1535
1536 static void mt_post_parse(struct mt_device *td, struct mt_application *app)
1537 {
1538 if (!app->have_contact_count)
1539 app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1540 }
1541
1542 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
1543 {
1544 struct mt_device *td = hid_get_drvdata(hdev);
1545 char *name;
1546 const char *suffix = NULL;
1547 struct mt_report_data *rdata;
1548 struct mt_application *mt_application = NULL;
1549 struct hid_report *report;
1550 int ret;
1551
1552 list_for_each_entry(report, &hi->reports, hidinput_list) {
1553 rdata = mt_find_report_data(td, report);
1554 if (!rdata) {
1555 hid_err(hdev, "failed to allocate data for report\n");
1556 return -ENOMEM;
1557 }
1558
1559 mt_application = rdata->application;
1560
1561 if (rdata->is_mt_collection) {
1562 ret = mt_touch_input_configured(hdev, hi,
1563 mt_application);
1564 if (ret)
1565 return ret;
1566 }
1567 }
1568
1569 switch (hi->application) {
1570 case HID_GD_KEYBOARD:
1571 case HID_GD_KEYPAD:
1572 case HID_GD_MOUSE:
1573 case HID_DG_TOUCHPAD:
1574 case HID_GD_SYSTEM_CONTROL:
1575 case HID_CP_CONSUMER_CONTROL:
1576 case HID_GD_WIRELESS_RADIO_CTLS:
1577 case HID_GD_SYSTEM_MULTIAXIS:
1578
1579 break;
1580 case HID_DG_TOUCHSCREEN:
1581
1582 hi->input->name = hdev->name;
1583 break;
1584 case HID_DG_STYLUS:
1585
1586 __set_bit(BTN_STYLUS, hi->input->keybit);
1587 break;
1588 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1589 suffix = "Custom Media Keys";
1590 break;
1591 case HID_DG_PEN:
1592 suffix = "Stylus";
1593 break;
1594 default:
1595 suffix = "UNKNOWN";
1596 break;
1597 }
1598
1599 if (suffix) {
1600 name = devm_kzalloc(&hi->input->dev,
1601 strlen(hdev->name) + strlen(suffix) + 2,
1602 GFP_KERNEL);
1603 if (name) {
1604 sprintf(name, "%s %s", hdev->name, suffix);
1605 hi->input->name = name;
1606 }
1607 }
1608
1609 return 0;
1610 }
1611
1612 static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1613 {
1614 if (field->usage[0].hid != usage ||
1615 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1616 return;
1617
1618 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1619 field->flags |= HID_MAIN_ITEM_VARIABLE;
1620 }
1621
1622 static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1623 {
1624 struct hid_report *report;
1625 int i;
1626
1627 list_for_each_entry(report,
1628 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1629 list) {
1630
1631 if (!report->maxfield)
1632 continue;
1633
1634 for (i = 0; i < report->maxfield; i++)
1635 if (report->field[i]->maxusage >= 1)
1636 mt_fix_const_field(report->field[i], usage);
1637 }
1638 }
1639
1640 static void mt_release_contacts(struct hid_device *hid)
1641 {
1642 struct hid_input *hidinput;
1643 struct mt_application *application;
1644 struct mt_device *td = hid_get_drvdata(hid);
1645
1646 list_for_each_entry(hidinput, &hid->inputs, list) {
1647 struct input_dev *input_dev = hidinput->input;
1648 struct input_mt *mt = input_dev->mt;
1649 int i;
1650
1651 if (mt) {
1652 for (i = 0; i < mt->num_slots; i++) {
1653 input_mt_slot(input_dev, i);
1654 input_mt_report_slot_state(input_dev,
1655 MT_TOOL_FINGER,
1656 false);
1657 }
1658 input_mt_sync_frame(input_dev);
1659 input_sync(input_dev);
1660 }
1661 }
1662
1663 list_for_each_entry(application, &td->applications, list) {
1664 application->num_received = 0;
1665 }
1666 }
1667
1668 static void mt_expired_timeout(struct timer_list *t)
1669 {
1670 struct mt_device *td = from_timer(td, t, release_timer);
1671 struct hid_device *hdev = td->hdev;
1672
1673
1674
1675
1676
1677 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1678 return;
1679 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1680 mt_release_contacts(hdev);
1681 clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1682 }
1683
1684 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1685 {
1686 int ret, i;
1687 struct mt_device *td;
1688 const struct mt_class *mtclass = mt_classes;
1689
1690 for (i = 0; mt_classes[i].name ; i++) {
1691 if (id->driver_data == mt_classes[i].name) {
1692 mtclass = &(mt_classes[i]);
1693 break;
1694 }
1695 }
1696
1697 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
1698 if (!td) {
1699 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1700 return -ENOMEM;
1701 }
1702 td->hdev = hdev;
1703 td->mtclass = *mtclass;
1704 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
1705 hid_set_drvdata(hdev, td);
1706
1707 INIT_LIST_HEAD(&td->applications);
1708 INIT_LIST_HEAD(&td->reports);
1709
1710 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1711 td->serial_maybe = true;
1712
1713
1714
1715
1716 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1717
1718
1719
1720
1721
1722
1723 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1724
1725 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
1726 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1727
1728 if (mtclass->quirks & MT_QUIRK_FORCE_MULTI_INPUT) {
1729 hdev->quirks &= ~HID_QUIRK_INPUT_PER_APP;
1730 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1731 }
1732
1733 timer_setup(&td->release_timer, mt_expired_timeout, 0);
1734
1735 ret = hid_parse(hdev);
1736 if (ret != 0)
1737 return ret;
1738
1739 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1740 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1741
1742 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1743 if (ret)
1744 return ret;
1745
1746 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
1747 if (ret)
1748 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
1749 hdev->name);
1750
1751 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1752
1753 return 0;
1754 }
1755
1756 #ifdef CONFIG_PM
1757 static int mt_reset_resume(struct hid_device *hdev)
1758 {
1759 mt_release_contacts(hdev);
1760 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1761 return 0;
1762 }
1763
1764 static int mt_resume(struct hid_device *hdev)
1765 {
1766
1767
1768
1769
1770 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
1771
1772 return 0;
1773 }
1774 #endif
1775
1776 static void mt_remove(struct hid_device *hdev)
1777 {
1778 struct mt_device *td = hid_get_drvdata(hdev);
1779
1780 del_timer_sync(&td->release_timer);
1781
1782 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
1783 hid_hw_stop(hdev);
1784 }
1785
1786
1787
1788
1789
1790
1791
1792 static const struct hid_device_id mt_devices[] = {
1793
1794
1795 { .driver_data = MT_CLS_3M,
1796 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1797 USB_DEVICE_ID_3M1968) },
1798 { .driver_data = MT_CLS_3M,
1799 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1800 USB_DEVICE_ID_3M2256) },
1801 { .driver_data = MT_CLS_3M,
1802 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1803 USB_DEVICE_ID_3M3266) },
1804
1805
1806 { .driver_data = MT_CLS_WIN_8_DUAL,
1807 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1808 USB_VENDOR_ID_ALPS_JP,
1809 HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
1810 { .driver_data = MT_CLS_WIN_8_DUAL,
1811 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1812 USB_VENDOR_ID_ALPS_JP,
1813 HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
1814 { .driver_data = MT_CLS_WIN_8_DUAL,
1815 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1816 USB_VENDOR_ID_ALPS_JP,
1817 HID_DEVICE_ID_ALPS_1222) },
1818
1819
1820 { .driver_data = MT_CLS_WIN_8_DUAL,
1821 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1822 USB_VENDOR_ID_LENOVO,
1823 USB_DEVICE_ID_LENOVO_X1_TAB) },
1824
1825
1826 { .driver_data = MT_CLS_WIN_8_DUAL,
1827 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1828 USB_VENDOR_ID_LENOVO,
1829 USB_DEVICE_ID_LENOVO_X1_TAB3) },
1830
1831
1832 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1833 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1834 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
1835
1836
1837 { .driver_data = MT_CLS_ASUS,
1838 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1839 USB_VENDOR_ID_ASUSTEK,
1840 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
1841
1842
1843 { .driver_data = MT_CLS_SERIAL,
1844 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
1845 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
1846
1847
1848 { .driver_data = MT_CLS_NSMU,
1849 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
1850 USB_DEVICE_ID_BAANTO_MT_190W2) },
1851
1852
1853 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1854 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1855 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1856 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1857 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1858 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1859
1860
1861 { .driver_data = MT_CLS_NSMU,
1862 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
1863 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1864
1865
1866 { .driver_data = MT_CLS_WIN_8_DUAL,
1867 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1868 I2C_VENDOR_ID_CIRQUE,
1869 I2C_PRODUCT_ID_CIRQUE_121F) },
1870
1871
1872 { .driver_data = MT_CLS_NSMU,
1873 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1874 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
1875 { .driver_data = MT_CLS_NSMU,
1876 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1877 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
1878
1879
1880 { .driver_data = MT_CLS_NSMU,
1881 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
1882 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1883
1884
1885 { .driver_data = MT_CLS_EGALAX,
1886 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1887 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1888 { .driver_data = MT_CLS_EGALAX,
1889 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1890 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1891
1892
1893 { .driver_data = MT_CLS_EGALAX_SERIAL,
1894 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1895 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
1896 { .driver_data = MT_CLS_EGALAX,
1897 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1898 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1899 { .driver_data = MT_CLS_EGALAX_SERIAL,
1900 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1901 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1902 { .driver_data = MT_CLS_EGALAX_SERIAL,
1903 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1904 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
1905 { .driver_data = MT_CLS_EGALAX_SERIAL,
1906 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1907 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
1908 { .driver_data = MT_CLS_EGALAX_SERIAL,
1909 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1910 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
1911 { .driver_data = MT_CLS_EGALAX,
1912 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1913 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1914 { .driver_data = MT_CLS_EGALAX,
1915 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1916 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1917 { .driver_data = MT_CLS_EGALAX_SERIAL,
1918 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1919 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
1920 { .driver_data = MT_CLS_EGALAX,
1921 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1922 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1923 { .driver_data = MT_CLS_EGALAX,
1924 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1925 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1926 { .driver_data = MT_CLS_EGALAX,
1927 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1928 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1929 { .driver_data = MT_CLS_EGALAX,
1930 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1931 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1932 { .driver_data = MT_CLS_EGALAX_SERIAL,
1933 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1934 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1935 { .driver_data = MT_CLS_EGALAX_SERIAL,
1936 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1937 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1938 { .driver_data = MT_CLS_EGALAX_SERIAL,
1939 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1940 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
1941 { .driver_data = MT_CLS_EGALAX,
1942 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1943 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C002) },
1944
1945
1946 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
1947 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1948 USB_VENDOR_ID_ELAN, 0x313a) },
1949
1950
1951 { .driver_data = MT_CLS_SERIAL,
1952 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1953 USB_DEVICE_ID_ELITEGROUP_05D8) },
1954
1955
1956 { .driver_data = MT_CLS_FLATFROG,
1957 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1958 USB_DEVICE_ID_MULTITOUCH_3200) },
1959
1960
1961 { .driver_data = MT_CLS_SERIAL,
1962 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1963 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1964
1965
1966 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1967 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1968 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1969 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1970 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1971 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
1972 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1973 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1974 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1975 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1976 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1977 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1978 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1979 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1980 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1981 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1982 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1983 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1984 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1985 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1986 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
1987
1988
1989 { .driver_data = MT_CLS_NSMU,
1990 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
1991 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1992
1993
1994 { .driver_data = MT_CLS_NSMU,
1995 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
1996 USB_DEVICE_ID_GOODTOUCH_000f) },
1997
1998
1999 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2000 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
2001 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
2002
2003
2004 { .driver_data = MT_CLS_NSMU,
2005 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
2006 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
2007
2008
2009 { .driver_data = MT_CLS_LG,
2010 HID_USB_DEVICE(USB_VENDOR_ID_LG,
2011 USB_DEVICE_ID_LG_MELFAS_MT) },
2012 { .driver_data = MT_CLS_LG,
2013 HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
2014 USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_7010) },
2015
2016
2017 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2018 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2019 USB_DEVICE_ID_ASUS_T91MT)},
2020 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2021 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2022 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
2023 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2024 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
2025 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
2026
2027
2028 { .driver_data = MT_CLS_NSMU,
2029 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
2030 USB_DEVICE_ID_NOVATEK_PCT) },
2031
2032
2033 { .driver_data = MT_CLS_NSMU,
2034 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2035 USB_VENDOR_ID_NTRIG, 0x1b05) },
2036
2037
2038 { .driver_data = MT_CLS_PANASONIC,
2039 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2040 USB_DEVICE_ID_PANABOARD_UBT780) },
2041 { .driver_data = MT_CLS_PANASONIC,
2042 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2043 USB_DEVICE_ID_PANABOARD_UBT880) },
2044
2045
2046 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2047 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2048 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
2049 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2050 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2051 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
2052 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2053 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2054 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
2055
2056
2057 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2058 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
2059 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
2060
2061
2062 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2063 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
2064 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
2065
2066
2067 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
2068 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2069 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
2070
2071
2072 { .driver_data = MT_CLS_SMART_TECH,
2073 MT_USB_DEVICE(0x0b8c, 0x0092)},
2074
2075
2076 { .driver_data = MT_CLS_CONFIDENCE,
2077 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
2078 USB_DEVICE_ID_MTP_STM)},
2079
2080
2081 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2082 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2083 USB_VENDOR_ID_SYNAPTICS, 0xce08) },
2084
2085
2086 { .driver_data = MT_CLS_TOPSEED,
2087 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
2088 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
2089
2090
2091 { .driver_data = MT_CLS_NSMU,
2092 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
2093 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
2094
2095
2096 { .driver_data = MT_CLS_NSMU,
2097 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2098 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
2099 { .driver_data = MT_CLS_NSMU,
2100 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2101 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
2102
2103
2104 { .driver_data = MT_CLS_VTL,
2105 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
2106 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
2107
2108
2109 { .driver_data = MT_CLS_NSMU,
2110 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
2111 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
2112
2113
2114 { .driver_data = MT_CLS_NSMU,
2115 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
2116 USB_DEVICE_ID_XAT_CSR) },
2117
2118
2119 { .driver_data = MT_CLS_NSMU,
2120 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2121 USB_DEVICE_ID_XIROKU_SPX) },
2122 { .driver_data = MT_CLS_NSMU,
2123 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2124 USB_DEVICE_ID_XIROKU_MPX) },
2125 { .driver_data = MT_CLS_NSMU,
2126 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2127 USB_DEVICE_ID_XIROKU_CSR) },
2128 { .driver_data = MT_CLS_NSMU,
2129 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2130 USB_DEVICE_ID_XIROKU_SPX1) },
2131 { .driver_data = MT_CLS_NSMU,
2132 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2133 USB_DEVICE_ID_XIROKU_MPX1) },
2134 { .driver_data = MT_CLS_NSMU,
2135 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2136 USB_DEVICE_ID_XIROKU_CSR1) },
2137 { .driver_data = MT_CLS_NSMU,
2138 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2139 USB_DEVICE_ID_XIROKU_SPX2) },
2140 { .driver_data = MT_CLS_NSMU,
2141 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2142 USB_DEVICE_ID_XIROKU_MPX2) },
2143 { .driver_data = MT_CLS_NSMU,
2144 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2145 USB_DEVICE_ID_XIROKU_CSR2) },
2146
2147
2148 { .driver_data = MT_CLS_GOOGLE,
2149 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
2150 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2151
2152
2153 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
2154
2155
2156 { .driver_data = MT_CLS_WIN_8,
2157 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2158 HID_ANY_ID, HID_ANY_ID) },
2159 { }
2160 };
2161 MODULE_DEVICE_TABLE(hid, mt_devices);
2162
2163 static const struct hid_usage_id mt_grabbed_usages[] = {
2164 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
2165 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
2166 };
2167
2168 static struct hid_driver mt_driver = {
2169 .name = "hid-multitouch",
2170 .id_table = mt_devices,
2171 .probe = mt_probe,
2172 .remove = mt_remove,
2173 .input_mapping = mt_input_mapping,
2174 .input_mapped = mt_input_mapped,
2175 .input_configured = mt_input_configured,
2176 .feature_mapping = mt_feature_mapping,
2177 .usage_table = mt_grabbed_usages,
2178 .event = mt_event,
2179 .report = mt_report,
2180 #ifdef CONFIG_PM
2181 .reset_resume = mt_reset_resume,
2182 .resume = mt_resume,
2183 #endif
2184 };
2185 module_hid_driver(mt_driver);