2 * HID driver for multitouch panels
4 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
7 * Copyright (c) 2012-2013 Red Hat, Inc
9 * This code is partly based on hid-egalax.c:
11 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
12 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
13 * Copyright (c) 2010 Canonical, Ltd.
15 * This code is partly based on hid-3m-pct.c:
17 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
18 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
19 * Copyright (c) 2010 Canonical, Ltd.
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the Free
26 * Software Foundation; either version 2 of the License, or (at your option)
31 * This driver is regularly tested thanks to the test suite in hid-tools[1].
32 * Please run these regression tests before patching this module so that
33 * your patch won't break existing known devices.
35 * [1] https://gitlab.freedesktop.org/libevdev/hid-tools
38 #include <linux/device.h>
39 #include <linux/hid.h>
40 #include <linux/module.h>
41 #include <linux/slab.h>
42 #include <linux/input/mt.h>
43 #include <linux/jiffies.h>
44 #include <linux/string.h>
45 #include <linux/timer.h>
48 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
49 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
50 MODULE_DESCRIPTION("HID multitouch panels");
51 MODULE_LICENSE("GPL");
55 /* quirks to control the device */
56 #define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
57 #define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
58 #define MT_QUIRK_CYPRESS BIT(2)
59 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
60 #define MT_QUIRK_ALWAYS_VALID BIT(4)
61 #define MT_QUIRK_VALID_IS_INRANGE BIT(5)
62 #define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
63 #define MT_QUIRK_CONFIDENCE BIT(7)
64 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
65 #define MT_QUIRK_NO_AREA BIT(9)
66 #define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
67 #define MT_QUIRK_HOVERING BIT(11)
68 #define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
69 #define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
70 #define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
71 #define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
72 #define MT_QUIRK_STICKY_FINGERS BIT(16)
73 #define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
74 #define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
75 #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19)
77 #define MT_INPUTMODE_TOUCHSCREEN 0x02
78 #define MT_INPUTMODE_TOUCHPAD 0x03
80 #define MT_BUTTONTYPE_CLICKPAD 0
83 HID_LATENCY_NORMAL = 0,
87 #define MT_IO_FLAGS_RUNNING 0
88 #define MT_IO_FLAGS_ACTIVE_SLOTS 1
89 #define MT_IO_FLAGS_PENDING_SLOTS 2
91 static const bool mtrue = true; /* default for true */
92 static const bool mfalse; /* default for false */
93 static const __s32 mzero; /* default for 0 */
95 #define DEFAULT_TRUE ((void *)&mtrue)
96 #define DEFAULT_FALSE ((void *)&mfalse)
97 #define DEFAULT_ZERO ((void *)&mzero)
100 struct list_head list;
101 __s32 *x, *y, *cx, *cy, *p, *w, *h, *a;
102 __s32 *contactid; /* the device ContactID assigned to this slot */
103 bool *tip_state; /* is the touch valid? */
104 bool *inrange_state; /* is the finger in proximity of the sensor? */
105 bool *confidence_state; /* is the touch made by a finger? */
108 struct mt_application {
109 struct list_head list;
110 unsigned int application;
111 unsigned int report_id;
112 struct list_head mt_usages; /* mt usages list */
116 __s32 *scantime; /* scantime reported */
117 __s32 scantime_logical_max; /* max value for raw scantime */
119 __s32 *raw_cc; /* contact count in the report */
120 int left_button_state; /* left button state */
121 unsigned int mt_flags; /* flags to pass to input-mt */
123 unsigned long *pending_palm_slots; /* slots where we reported palm
124 * and need to release */
126 __u8 num_received; /* how many contacts we received */
127 __u8 num_expected; /* expected last contact index */
128 __u8 buttons_count; /* number of physical buttons per touchpad */
129 __u8 touches_by_report; /* how many touches are present in one report:
130 * 1 means we should use a serial protocol
131 * > 1 means hybrid (multitouch) protocol
134 __s32 dev_time; /* the scan time provided by the device */
135 unsigned long jiffies; /* the frame's jiffies */
136 int timestamp; /* the timestamp to be sent */
137 int prev_scantime; /* scantime reported previously */
139 bool have_contact_count;
143 __s32 name; /* MT_CLS */
145 __s32 sn_move; /* Signal/noise ratio for move events */
146 __s32 sn_width; /* Signal/noise ratio for width events */
147 __s32 sn_height; /* Signal/noise ratio for height events */
148 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
150 bool is_indirect; /* true for touchpads */
151 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
154 struct mt_report_data {
155 struct list_head list;
156 struct hid_report *report;
157 struct mt_application *application;
158 bool is_mt_collection;
162 struct mt_class mtclass; /* our mt device class */
163 struct timer_list release_timer; /* to release sticky fingers */
164 struct hid_device *hdev; /* hid_device we're attached to */
165 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */
166 __u8 inputmode_value; /* InputMode HID feature value */
168 bool is_buttonpad; /* is this device a button pad? */
169 bool serial_maybe; /* need to check for serial protocol */
171 struct list_head applications;
172 struct list_head reports;
175 static void mt_post_parse_default_settings(struct mt_device *td,
176 struct mt_application *app);
177 static void mt_post_parse(struct mt_device *td, struct mt_application *app);
179 /* classes of device behavior */
180 #define MT_CLS_DEFAULT 0x0001
182 #define MT_CLS_SERIAL 0x0002
183 #define MT_CLS_CONFIDENCE 0x0003
184 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
185 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
186 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
187 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
188 /* reserved 0x0008 */
189 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
190 #define MT_CLS_NSMU 0x000a
191 /* reserved 0x0010 */
192 /* reserved 0x0011 */
193 #define MT_CLS_WIN_8 0x0012
194 #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
195 #define MT_CLS_WIN_8_DUAL 0x0014
197 /* vendor specific classes */
198 #define MT_CLS_3M 0x0101
199 /* reserved 0x0102 */
200 #define MT_CLS_EGALAX 0x0103
201 #define MT_CLS_EGALAX_SERIAL 0x0104
202 #define MT_CLS_TOPSEED 0x0105
203 #define MT_CLS_PANASONIC 0x0106
204 #define MT_CLS_FLATFROG 0x0107
205 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
206 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
207 #define MT_CLS_LG 0x010a
208 #define MT_CLS_ASUS 0x010b
209 #define MT_CLS_VTL 0x0110
210 #define MT_CLS_GOOGLE 0x0111
211 #define MT_CLS_RAZER_BLADE_STEALTH 0x0112
212 #define MT_CLS_SMART_TECH 0x0113
214 #define MT_DEFAULT_MAXCONTACT 10
215 #define MT_MAX_MAXCONTACT 250
218 * Resync device and local timestamps after that many microseconds without
221 #define MAX_TIMESTAMP_INTERVAL 1000000
223 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
224 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
227 * these device-dependent functions determine what slot corresponds
228 * to a valid contact that was just read.
231 static int cypress_compute_slot(struct mt_application *application,
232 struct mt_usages *slot)
234 if (*slot->contactid != 0 || application->num_received == 0)
235 return *slot->contactid;
240 static const struct mt_class mt_classes[] = {
241 { .name = MT_CLS_DEFAULT,
242 .quirks = MT_QUIRK_ALWAYS_VALID |
243 MT_QUIRK_CONTACT_CNT_ACCURATE },
244 { .name = MT_CLS_NSMU,
245 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
246 { .name = MT_CLS_SERIAL,
247 .quirks = MT_QUIRK_ALWAYS_VALID},
248 { .name = MT_CLS_CONFIDENCE,
249 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
250 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
251 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
252 MT_QUIRK_SLOT_IS_CONTACTID },
253 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
254 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
255 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
256 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
257 .quirks = MT_QUIRK_VALID_IS_INRANGE |
258 MT_QUIRK_SLOT_IS_CONTACTID,
260 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
261 .quirks = MT_QUIRK_VALID_IS_INRANGE |
262 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
264 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
265 .quirks = MT_QUIRK_VALID_IS_INRANGE |
266 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
267 { .name = MT_CLS_WIN_8,
268 .quirks = MT_QUIRK_ALWAYS_VALID |
269 MT_QUIRK_IGNORE_DUPLICATES |
271 MT_QUIRK_CONTACT_CNT_ACCURATE |
272 MT_QUIRK_STICKY_FINGERS |
273 MT_QUIRK_WIN8_PTP_BUTTONS },
274 { .name = MT_CLS_EXPORT_ALL_INPUTS,
275 .quirks = MT_QUIRK_ALWAYS_VALID |
276 MT_QUIRK_CONTACT_CNT_ACCURATE,
277 .export_all_inputs = true },
278 { .name = MT_CLS_WIN_8_DUAL,
279 .quirks = MT_QUIRK_ALWAYS_VALID |
280 MT_QUIRK_IGNORE_DUPLICATES |
282 MT_QUIRK_CONTACT_CNT_ACCURATE |
283 MT_QUIRK_WIN8_PTP_BUTTONS,
284 .export_all_inputs = true },
287 * vendor specific classes
290 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
291 MT_QUIRK_SLOT_IS_CONTACTID |
292 MT_QUIRK_TOUCH_SIZE_SCALING,
298 { .name = MT_CLS_EGALAX,
299 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
300 MT_QUIRK_VALID_IS_INRANGE,
304 { .name = MT_CLS_EGALAX_SERIAL,
305 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
306 MT_QUIRK_ALWAYS_VALID,
310 { .name = MT_CLS_TOPSEED,
311 .quirks = MT_QUIRK_ALWAYS_VALID,
315 { .name = MT_CLS_PANASONIC,
316 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
318 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
319 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
320 MT_QUIRK_VALID_IS_INRANGE |
321 MT_QUIRK_SLOT_IS_CONTACTID,
324 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
325 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
326 MT_QUIRK_SLOT_IS_CONTACTID
329 { .name = MT_CLS_FLATFROG,
330 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
336 .quirks = MT_QUIRK_ALWAYS_VALID |
337 MT_QUIRK_FIX_CONST_CONTACT_ID |
338 MT_QUIRK_IGNORE_DUPLICATES |
340 MT_QUIRK_CONTACT_CNT_ACCURATE },
341 { .name = MT_CLS_ASUS,
342 .quirks = MT_QUIRK_ALWAYS_VALID |
343 MT_QUIRK_CONTACT_CNT_ACCURATE |
344 MT_QUIRK_ASUS_CUSTOM_UP },
345 { .name = MT_CLS_VTL,
346 .quirks = MT_QUIRK_ALWAYS_VALID |
347 MT_QUIRK_CONTACT_CNT_ACCURATE |
348 MT_QUIRK_FORCE_GET_FEATURE,
350 { .name = MT_CLS_GOOGLE,
351 .quirks = MT_QUIRK_ALWAYS_VALID |
352 MT_QUIRK_CONTACT_CNT_ACCURATE |
353 MT_QUIRK_SLOT_IS_CONTACTID |
356 { .name = MT_CLS_RAZER_BLADE_STEALTH,
357 .quirks = MT_QUIRK_ALWAYS_VALID |
358 MT_QUIRK_IGNORE_DUPLICATES |
360 MT_QUIRK_CONTACT_CNT_ACCURATE |
361 MT_QUIRK_WIN8_PTP_BUTTONS,
363 { .name = MT_CLS_SMART_TECH,
364 .quirks = MT_QUIRK_ALWAYS_VALID |
365 MT_QUIRK_IGNORE_DUPLICATES |
366 MT_QUIRK_CONTACT_CNT_ACCURATE |
367 MT_QUIRK_SEPARATE_APP_REPORT,
372 static ssize_t mt_show_quirks(struct device *dev,
373 struct device_attribute *attr,
376 struct hid_device *hdev = to_hid_device(dev);
377 struct mt_device *td = hid_get_drvdata(hdev);
379 return sprintf(buf, "%u\n", td->mtclass.quirks);
382 static ssize_t mt_set_quirks(struct device *dev,
383 struct device_attribute *attr,
384 const char *buf, size_t count)
386 struct hid_device *hdev = to_hid_device(dev);
387 struct mt_device *td = hid_get_drvdata(hdev);
388 struct mt_application *application;
392 if (kstrtoul(buf, 0, &val))
395 td->mtclass.quirks = val;
397 list_for_each_entry(application, &td->applications, list) {
398 application->quirks = val;
399 if (!application->have_contact_count)
400 application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
406 static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
408 static struct attribute *sysfs_attrs[] = {
409 &dev_attr_quirks.attr,
413 static const struct attribute_group mt_attribute_group = {
417 static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
420 u32 size = hid_report_len(report);
424 * Do not fetch the feature report if the device has been explicitly
425 * marked as non-capable.
427 if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
430 buf = hid_alloc_report_buf(report, GFP_KERNEL);
434 ret = hid_hw_raw_request(hdev, report->id, buf, size,
435 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
437 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
440 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
443 dev_warn(&hdev->dev, "failed to report feature\n");
449 static void mt_feature_mapping(struct hid_device *hdev,
450 struct hid_field *field, struct hid_usage *usage)
452 struct mt_device *td = hid_get_drvdata(hdev);
454 switch (usage->hid) {
455 case HID_DG_CONTACTMAX:
456 mt_get_feature(hdev, field->report);
458 td->maxcontacts = field->value[0];
459 if (!td->maxcontacts &&
460 field->logical_maximum <= MT_MAX_MAXCONTACT)
461 td->maxcontacts = field->logical_maximum;
462 if (td->mtclass.maxcontacts)
463 /* check if the maxcontacts is given by the class */
464 td->maxcontacts = td->mtclass.maxcontacts;
467 case HID_DG_BUTTONTYPE:
468 if (usage->usage_index >= field->report_count) {
469 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
473 mt_get_feature(hdev, field->report);
474 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
475 td->is_buttonpad = true;
479 /* Retrieve the Win8 blob once to enable some devices */
480 if (usage->usage_index == 0)
481 mt_get_feature(hdev, field->report);
486 static void set_abs(struct input_dev *input, unsigned int code,
487 struct hid_field *field, int snratio)
489 int fmin = field->logical_minimum;
490 int fmax = field->logical_maximum;
491 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
492 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
493 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
496 static struct mt_usages *mt_allocate_usage(struct hid_device *hdev,
497 struct mt_application *application)
499 struct mt_usages *usage;
501 usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL);
505 /* set some defaults so we do not need to check for null pointers */
506 usage->x = DEFAULT_ZERO;
507 usage->y = DEFAULT_ZERO;
508 usage->cx = DEFAULT_ZERO;
509 usage->cy = DEFAULT_ZERO;
510 usage->p = DEFAULT_ZERO;
511 usage->w = DEFAULT_ZERO;
512 usage->h = DEFAULT_ZERO;
513 usage->a = DEFAULT_ZERO;
514 usage->contactid = DEFAULT_ZERO;
515 usage->tip_state = DEFAULT_FALSE;
516 usage->inrange_state = DEFAULT_FALSE;
517 usage->confidence_state = DEFAULT_TRUE;
519 list_add_tail(&usage->list, &application->mt_usages);
524 static struct mt_application *mt_allocate_application(struct mt_device *td,
525 struct hid_report *report)
527 unsigned int application = report->application;
528 struct mt_application *mt_application;
530 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
535 mt_application->application = application;
536 INIT_LIST_HEAD(&mt_application->mt_usages);
538 if (application == HID_DG_TOUCHSCREEN)
539 mt_application->mt_flags |= INPUT_MT_DIRECT;
542 * Model touchscreens providing buttons as touchpads.
544 if (application == HID_DG_TOUCHPAD) {
545 mt_application->mt_flags |= INPUT_MT_POINTER;
546 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
549 mt_application->scantime = DEFAULT_ZERO;
550 mt_application->raw_cc = DEFAULT_ZERO;
551 mt_application->quirks = td->mtclass.quirks;
552 mt_application->report_id = report->id;
554 list_add_tail(&mt_application->list, &td->applications);
556 return mt_application;
559 static struct mt_application *mt_find_application(struct mt_device *td,
560 struct hid_report *report)
562 unsigned int application = report->application;
563 struct mt_application *tmp, *mt_application = NULL;
565 list_for_each_entry(tmp, &td->applications, list) {
566 if (application == tmp->application) {
567 if (!(td->mtclass.quirks & MT_QUIRK_SEPARATE_APP_REPORT) ||
568 tmp->report_id == report->id) {
569 mt_application = tmp;
576 mt_application = mt_allocate_application(td, report);
578 return mt_application;
581 static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
582 struct hid_report *report)
584 struct mt_report_data *rdata;
585 struct hid_field *field;
588 rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL);
592 rdata->report = report;
593 rdata->application = mt_find_application(td, report);
595 if (!rdata->application) {
596 devm_kfree(&td->hdev->dev, rdata);
600 for (r = 0; r < report->maxfield; r++) {
601 field = report->field[r];
603 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
606 if (field->logical == HID_DG_FINGER || td->hdev->group != HID_GROUP_MULTITOUCH_WIN_8) {
607 for (n = 0; n < field->report_count; n++) {
608 if (field->usage[n].hid == HID_DG_CONTACTID) {
609 rdata->is_mt_collection = true;
616 list_add_tail(&rdata->list, &td->reports);
621 static struct mt_report_data *mt_find_report_data(struct mt_device *td,
622 struct hid_report *report)
624 struct mt_report_data *tmp, *rdata = NULL;
626 list_for_each_entry(tmp, &td->reports, list) {
627 if (report == tmp->report) {
634 rdata = mt_allocate_report_data(td, report);
639 static void mt_store_field(struct hid_device *hdev,
640 struct mt_application *application,
644 struct mt_usages *usage;
647 if (list_empty(&application->mt_usages))
648 usage = mt_allocate_usage(hdev, application);
650 usage = list_last_entry(&application->mt_usages,
657 target = (__s32 **)((char *)usage + offset);
659 /* the value has already been filled, create a new slot */
660 if (*target != DEFAULT_TRUE &&
661 *target != DEFAULT_FALSE &&
662 *target != DEFAULT_ZERO) {
663 if (usage->contactid == DEFAULT_ZERO ||
664 usage->x == DEFAULT_ZERO ||
665 usage->y == DEFAULT_ZERO) {
667 "ignoring duplicate usage on incomplete");
670 usage = mt_allocate_usage(hdev, application);
674 target = (__s32 **)((char *)usage + offset);
680 #define MT_STORE_FIELD(__name) \
681 mt_store_field(hdev, app, \
682 &field->value[usage->usage_index], \
683 offsetof(struct mt_usages, __name))
685 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
686 struct hid_field *field, struct hid_usage *usage,
687 unsigned long **bit, int *max, struct mt_application *app)
689 struct mt_device *td = hid_get_drvdata(hdev);
690 struct mt_class *cls = &td->mtclass;
692 struct hid_usage *prev_usage = NULL;
695 * Model touchscreens providing buttons as touchpads.
697 if (field->application == HID_DG_TOUCHSCREEN &&
698 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
699 app->mt_flags |= INPUT_MT_POINTER;
700 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
703 /* count the buttons on touchpads */
704 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
705 app->buttons_count++;
707 if (usage->usage_index)
708 prev_usage = &field->usage[usage->usage_index - 1];
710 switch (usage->hid & HID_USAGE_PAGE) {
713 switch (usage->hid) {
715 if (prev_usage && (prev_usage->hid == usage->hid)) {
716 code = ABS_MT_TOOL_X;
719 code = ABS_MT_POSITION_X;
723 set_abs(hi->input, code, field, cls->sn_move);
726 * A system multi-axis that exports X and Y has a high
727 * chance of being used directly on a surface
729 if (field->application == HID_GD_SYSTEM_MULTIAXIS) {
730 __set_bit(INPUT_PROP_DIRECT,
732 input_set_abs_params(hi->input,
740 if (prev_usage && (prev_usage->hid == usage->hid)) {
741 code = ABS_MT_TOOL_Y;
744 code = ABS_MT_POSITION_Y;
748 set_abs(hi->input, code, field, cls->sn_move);
754 case HID_UP_DIGITIZER:
755 switch (usage->hid) {
757 if (app->quirks & MT_QUIRK_HOVERING) {
758 input_set_abs_params(hi->input,
759 ABS_MT_DISTANCE, 0, 1, 0, 0);
761 MT_STORE_FIELD(inrange_state);
763 case HID_DG_CONFIDENCE:
764 if ((cls->name == MT_CLS_WIN_8 ||
765 cls->name == MT_CLS_WIN_8_DUAL) &&
766 (field->application == HID_DG_TOUCHPAD ||
767 field->application == HID_DG_TOUCHSCREEN))
768 app->quirks |= MT_QUIRK_CONFIDENCE;
770 if (app->quirks & MT_QUIRK_CONFIDENCE)
771 input_set_abs_params(hi->input,
776 MT_STORE_FIELD(confidence_state);
778 case HID_DG_TIPSWITCH:
779 if (field->application != HID_GD_SYSTEM_MULTIAXIS)
780 input_set_capability(hi->input,
782 MT_STORE_FIELD(tip_state);
784 case HID_DG_CONTACTID:
785 MT_STORE_FIELD(contactid);
786 app->touches_by_report++;
789 if (!(app->quirks & MT_QUIRK_NO_AREA))
790 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
795 if (!(app->quirks & MT_QUIRK_NO_AREA)) {
796 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
800 * Only set ABS_MT_ORIENTATION if it is not
801 * already set by the HID_DG_AZIMUTH usage.
803 if (!test_bit(ABS_MT_ORIENTATION,
805 input_set_abs_params(hi->input,
806 ABS_MT_ORIENTATION, 0, 1, 0, 0);
810 case HID_DG_TIPPRESSURE:
811 set_abs(hi->input, ABS_MT_PRESSURE, field,
815 case HID_DG_SCANTIME:
816 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
817 app->scantime = &field->value[usage->usage_index];
818 app->scantime_logical_max = field->logical_maximum;
820 case HID_DG_CONTACTCOUNT:
821 app->have_contact_count = true;
822 app->raw_cc = &field->value[usage->usage_index];
826 * Azimuth has the range of [0, MAX) representing a full
827 * revolution. Set ABS_MT_ORIENTATION to a quarter of
828 * MAX according the definition of ABS_MT_ORIENTATION
830 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
831 -field->logical_maximum / 4,
832 field->logical_maximum / 4,
834 field->logical_maximum / cls->sn_move : 0, 0);
837 case HID_DG_CONTACTMAX:
838 /* contact max are global to the report */
841 /* Legacy devices use TIPSWITCH and not TOUCH.
842 * Let's just ignore this field. */
845 /* let hid-input decide for the others */
849 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
851 * MS PTP spec says that external buttons left and right have
854 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
855 field->application == HID_DG_TOUCHPAD &&
856 (usage->hid & HID_USAGE) > 1)
859 if (field->application == HID_GD_SYSTEM_MULTIAXIS)
860 code = BTN_0 + ((usage->hid - 1) & HID_USAGE);
862 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
865 input_set_capability(hi->input, EV_KEY, code);
869 /* we do not want to map these: no input-oriented meaning */
876 static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
877 struct mt_usages *slot,
878 struct input_dev *input)
880 __s32 quirks = app->quirks;
882 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
883 return *slot->contactid;
885 if (quirks & MT_QUIRK_CYPRESS)
886 return cypress_compute_slot(app, slot);
888 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
889 return app->num_received;
891 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
892 return *slot->contactid - 1;
894 return input_mt_get_slot_by_key(input, *slot->contactid);
897 static void mt_release_pending_palms(struct mt_device *td,
898 struct mt_application *app,
899 struct input_dev *input)
902 bool need_sync = false;
904 for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) {
905 clear_bit(slotnum, app->pending_palm_slots);
907 input_mt_slot(input, slotnum);
908 input_mt_report_slot_state(input, MT_TOOL_PALM, false);
914 input_mt_sync_frame(input);
920 * this function is called when a whole packet has been received and processed,
921 * so that it can decide what to send to the input layer.
923 static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
924 struct input_dev *input)
926 if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
927 input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
929 input_mt_sync_frame(input);
930 input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
933 mt_release_pending_palms(td, app, input);
935 app->num_received = 0;
936 app->left_button_state = 0;
938 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
939 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
941 clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
942 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
945 static int mt_compute_timestamp(struct mt_application *app, __s32 value)
947 long delta = value - app->prev_scantime;
948 unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
950 app->jiffies = jiffies;
953 delta += app->scantime_logical_max;
955 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */
958 if (jdelta > MAX_TIMESTAMP_INTERVAL)
959 /* No data received for a while, resync the timestamp. */
962 return app->timestamp + delta;
965 static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
966 struct hid_usage *usage, __s32 value)
968 /* we will handle the hidinput part later, now remains hiddev */
969 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
970 hid->hiddev_hid_event(hid, field, usage, value);
975 static int mt_process_slot(struct mt_device *td, struct input_dev *input,
976 struct mt_application *app,
977 struct mt_usages *slot)
979 struct input_mt *mt = input->mt;
980 __s32 quirks = app->quirks;
982 bool confidence_state = true;
983 bool inrange_state = false;
986 int tool = MT_TOOL_FINGER;
991 if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
992 app->num_received >= app->num_expected)
995 if (!(quirks & MT_QUIRK_ALWAYS_VALID)) {
996 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
997 valid = *slot->inrange_state;
998 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
999 valid = *slot->tip_state;
1000 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
1001 valid = *slot->confidence_state;
1007 slotnum = mt_compute_slot(td, app, slot, input);
1008 if (slotnum < 0 || slotnum >= td->maxcontacts)
1011 if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
1012 struct input_mt_slot *i_slot = &mt->slots[slotnum];
1014 if (input_mt_is_active(i_slot) &&
1015 input_mt_is_used(mt, i_slot))
1019 if (quirks & MT_QUIRK_CONFIDENCE)
1020 confidence_state = *slot->confidence_state;
1022 if (quirks & MT_QUIRK_HOVERING)
1023 inrange_state = *slot->inrange_state;
1025 active = *slot->tip_state || inrange_state;
1027 if (app->application == HID_GD_SYSTEM_MULTIAXIS)
1028 tool = MT_TOOL_DIAL;
1029 else if (unlikely(!confidence_state)) {
1030 tool = MT_TOOL_PALM;
1031 if (!active && mt &&
1032 input_mt_is_active(&mt->slots[slotnum])) {
1034 * The non-confidence was reported for
1035 * previously valid contact that is also no
1036 * longer valid. We can't simply report
1037 * lift-off as userspace will not be aware
1038 * of non-confidence, so we need to split
1039 * it into 2 events: active MT_TOOL_PALM
1040 * and a separate liftoff.
1043 set_bit(slotnum, app->pending_palm_slots);
1047 input_mt_slot(input, slotnum);
1048 input_mt_report_slot_state(input, tool, active);
1050 /* this finger is in proximity of the sensor */
1051 int wide = (*slot->w > *slot->h);
1052 int major = max(*slot->w, *slot->h);
1053 int minor = min(*slot->w, *slot->h);
1054 int orientation = wide;
1058 if (slot->a != DEFAULT_ZERO) {
1060 * Azimuth is counter-clockwise and ranges from [0, MAX)
1061 * (a full revolution). Convert it to clockwise ranging
1064 * Note that ABS_MT_ORIENTATION require us to report
1065 * the limit of [-MAX/4, MAX/4], but the value can go
1066 * out of range to [-MAX/2, MAX/2] to report an upside
1070 max_azimuth = input_abs_get_max(input,
1071 ABS_MT_ORIENTATION);
1072 if (azimuth > max_azimuth * 2)
1073 azimuth -= max_azimuth * 4;
1074 orientation = -azimuth;
1077 if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
1079 * divided by two to match visual scale of touch
1080 * for devices with this quirk
1086 input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x);
1087 input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y);
1088 input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx);
1089 input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy);
1090 input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state);
1091 input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation);
1092 input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p);
1093 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
1094 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
1096 set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
1102 static void mt_process_mt_event(struct hid_device *hid,
1103 struct mt_application *app,
1104 struct hid_field *field,
1105 struct hid_usage *usage,
1109 __s32 quirks = app->quirks;
1110 struct input_dev *input = field->hidinput->input;
1112 if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT))
1115 if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) {
1118 * For Win8 PTP touchpads we should only look at
1119 * non finger/touch events in the first_packet of a
1120 * (possible) multi-packet frame.
1126 * For Win8 PTP touchpads we map both the clickpad click
1127 * and any "external" left buttons to BTN_LEFT if a
1128 * device claims to have both we need to report 1 for
1129 * BTN_LEFT if either is pressed, so we or all values
1130 * together and report the result in mt_sync_frame().
1132 if (usage->type == EV_KEY && usage->code == BTN_LEFT) {
1133 app->left_button_state |= value;
1138 input_event(input, usage->type, usage->code, value);
1141 static void mt_touch_report(struct hid_device *hid,
1142 struct mt_report_data *rdata)
1144 struct mt_device *td = hid_get_drvdata(hid);
1145 struct hid_report *report = rdata->report;
1146 struct mt_application *app = rdata->application;
1147 struct hid_field *field;
1148 struct input_dev *input;
1149 struct mt_usages *slot;
1154 int contact_count = -1;
1156 /* sticky fingers release in progress, abort */
1157 if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1160 scantime = *app->scantime;
1161 app->timestamp = mt_compute_timestamp(app, scantime);
1162 if (app->raw_cc != DEFAULT_ZERO)
1163 contact_count = *app->raw_cc;
1166 * Includes multi-packet support where subsequent
1167 * packets are sent with zero contactcount.
1169 if (contact_count >= 0) {
1171 * For Win8 PTPs the first packet (td->num_received == 0) may
1172 * have a contactcount of 0 if there only is a button event.
1173 * We double check that this is not a continuation packet
1174 * of a possible multi-packet frame be checking that the
1175 * timestamp has changed.
1177 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
1178 app->num_received == 0 &&
1179 app->prev_scantime != scantime)
1180 app->num_expected = contact_count;
1181 /* A non 0 contact count always indicates a first packet */
1182 else if (contact_count)
1183 app->num_expected = contact_count;
1185 app->prev_scantime = scantime;
1187 first_packet = app->num_received == 0;
1189 input = report->field[0]->hidinput->input;
1191 list_for_each_entry(slot, &app->mt_usages, list) {
1192 if (!mt_process_slot(td, input, app, slot))
1193 app->num_received++;
1196 for (r = 0; r < report->maxfield; r++) {
1197 field = report->field[r];
1198 count = field->report_count;
1200 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1203 for (n = 0; n < count; n++)
1204 mt_process_mt_event(hid, app, field,
1205 &field->usage[n], field->value[n],
1209 if (app->num_received >= app->num_expected)
1210 mt_sync_frame(td, app, input);
1213 * Windows 8 specs says 2 things:
1214 * - once a contact has been reported, it has to be reported in each
1216 * - the report rate when fingers are present has to be at least
1217 * the refresh rate of the screen, 60 or 120 Hz
1219 * I interprete this that the specification forces a report rate of
1220 * at least 60 Hz for a touchscreen to be certified.
1221 * Which means that if we do not get a report whithin 16 ms, either
1222 * something wrong happens, either the touchscreen forgets to send
1223 * a release. Taking a reasonable margin allows to remove issues
1224 * with USB communication or the load of the machine.
1226 * Given that Win 8 devices are forced to send a release, this will
1227 * only affect laggish machines and the ones that have a firmware
1230 if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
1231 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1232 mod_timer(&td->release_timer,
1233 jiffies + msecs_to_jiffies(100));
1235 del_timer(&td->release_timer);
1238 clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1241 static int mt_touch_input_configured(struct hid_device *hdev,
1242 struct hid_input *hi,
1243 struct mt_application *app)
1245 struct mt_device *td = hid_get_drvdata(hdev);
1246 struct mt_class *cls = &td->mtclass;
1247 struct input_dev *input = hi->input;
1250 if (!td->maxcontacts)
1251 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1253 mt_post_parse(td, app);
1254 if (td->serial_maybe)
1255 mt_post_parse_default_settings(td, app);
1257 if (cls->is_indirect)
1258 app->mt_flags |= INPUT_MT_POINTER;
1260 if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
1261 app->mt_flags |= INPUT_MT_DROP_UNUSED;
1263 /* check for clickpads */
1264 if ((app->mt_flags & INPUT_MT_POINTER) &&
1265 (app->buttons_count == 1))
1266 td->is_buttonpad = true;
1268 if (td->is_buttonpad)
1269 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1271 app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
1272 BITS_TO_LONGS(td->maxcontacts),
1275 if (!app->pending_palm_slots)
1278 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
1286 #define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1288 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1289 struct hid_field *field, struct hid_usage *usage,
1290 unsigned long **bit, int *max)
1292 struct mt_device *td = hid_get_drvdata(hdev);
1293 struct mt_application *application;
1294 struct mt_report_data *rdata;
1296 rdata = mt_find_report_data(td, field->report);
1298 hid_err(hdev, "failed to allocate data for report\n");
1302 application = rdata->application;
1305 * If mtclass.export_all_inputs is not set, only map fields from
1306 * TouchScreen or TouchPad collections. We need to ignore fields
1307 * that belong to other collections such as Mouse that might have
1308 * the same GenericDesktop usages.
1310 if (!td->mtclass.export_all_inputs &&
1311 field->application != HID_DG_TOUCHSCREEN &&
1312 field->application != HID_DG_PEN &&
1313 field->application != HID_DG_TOUCHPAD &&
1314 field->application != HID_GD_KEYBOARD &&
1315 field->application != HID_GD_SYSTEM_CONTROL &&
1316 field->application != HID_CP_CONSUMER_CONTROL &&
1317 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
1318 field->application != HID_GD_SYSTEM_MULTIAXIS &&
1319 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1320 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
1324 * Some Asus keyboard+touchpad devices have the hotkeys defined in the
1325 * touchpad report descriptor. We need to treat these as an array to
1326 * map usages to input keys.
1328 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1329 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
1330 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1331 set_bit(EV_REP, hi->input->evbit);
1332 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1333 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1334 switch (usage->hid & HID_USAGE) {
1335 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1336 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1337 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1338 case 0x6b: mt_map_key_clear(KEY_F21); break;
1339 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1346 if (rdata->is_mt_collection)
1347 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1351 * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1352 * for the stylus. Overwrite the hid_input application
1354 if (field->physical == HID_DG_STYLUS)
1355 hi->application = HID_DG_STYLUS;
1357 /* let hid-core decide for the others */
1361 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1362 struct hid_field *field, struct hid_usage *usage,
1363 unsigned long **bit, int *max)
1365 struct mt_device *td = hid_get_drvdata(hdev);
1366 struct mt_report_data *rdata;
1368 rdata = mt_find_report_data(td, field->report);
1369 if (rdata && rdata->is_mt_collection) {
1370 /* We own these mappings, tell hid-input to ignore them */
1374 /* let hid-core decide for the others */
1378 static int mt_event(struct hid_device *hid, struct hid_field *field,
1379 struct hid_usage *usage, __s32 value)
1381 struct mt_device *td = hid_get_drvdata(hid);
1382 struct mt_report_data *rdata;
1384 rdata = mt_find_report_data(td, field->report);
1385 if (rdata && rdata->is_mt_collection)
1386 return mt_touch_event(hid, field, usage, value);
1391 static void mt_report(struct hid_device *hid, struct hid_report *report)
1393 struct mt_device *td = hid_get_drvdata(hid);
1394 struct hid_field *field = report->field[0];
1395 struct mt_report_data *rdata;
1397 if (!(hid->claimed & HID_CLAIMED_INPUT))
1400 rdata = mt_find_report_data(td, report);
1401 if (rdata && rdata->is_mt_collection)
1402 return mt_touch_report(hid, rdata);
1404 if (field && field->hidinput && field->hidinput->input)
1405 input_sync(field->hidinput->input);
1408 static bool mt_need_to_apply_feature(struct hid_device *hdev,
1409 struct hid_field *field,
1410 struct hid_usage *usage,
1411 enum latency_mode latency,
1412 bool surface_switch,
1414 bool *inputmode_found)
1416 struct mt_device *td = hid_get_drvdata(hdev);
1417 struct mt_class *cls = &td->mtclass;
1418 struct hid_report *report = field->report;
1419 unsigned int index = usage->usage_index;
1424 switch (usage->hid) {
1425 case HID_DG_INPUTMODE:
1427 * Some elan panels wrongly declare 2 input mode features,
1428 * and silently ignore when we set the value in the second
1429 * field. Skip the second feature and hope for the best.
1431 if (*inputmode_found)
1434 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
1435 report_len = hid_report_len(report);
1436 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1439 "failed to allocate buffer for report\n");
1442 hid_hw_raw_request(hdev, report->id, buf, report_len,
1444 HID_REQ_GET_REPORT);
1448 field->value[index] = td->inputmode_value;
1449 *inputmode_found = true;
1452 case HID_DG_CONTACTMAX:
1453 if (cls->maxcontacts) {
1454 max = min_t(int, field->logical_maximum,
1456 if (field->value[index] != max) {
1457 field->value[index] = max;
1463 case HID_DG_LATENCYMODE:
1464 field->value[index] = latency;
1467 case HID_DG_SURFACESWITCH:
1468 field->value[index] = surface_switch;
1471 case HID_DG_BUTTONSWITCH:
1472 field->value[index] = button_switch;
1476 return false; /* no need to update the report */
1479 static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1480 bool surface_switch, bool button_switch)
1482 struct hid_report_enum *rep_enum;
1483 struct hid_report *rep;
1484 struct hid_usage *usage;
1487 bool inputmode_found = false;
1489 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1490 list_for_each_entry(rep, &rep_enum->report_list, list) {
1491 update_report = false;
1493 for (i = 0; i < rep->maxfield; i++) {
1494 /* Ignore if report count is out of bounds. */
1495 if (rep->field[i]->report_count < 1)
1498 for (j = 0; j < rep->field[i]->maxusage; j++) {
1499 usage = &rep->field[i]->usage[j];
1501 if (mt_need_to_apply_feature(hdev,
1508 update_report = true;
1513 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
1517 static void mt_post_parse_default_settings(struct mt_device *td,
1518 struct mt_application *app)
1520 __s32 quirks = app->quirks;
1522 /* unknown serial device needs special quirks */
1523 if (list_is_singular(&app->mt_usages)) {
1524 quirks |= MT_QUIRK_ALWAYS_VALID;
1525 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1526 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1527 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
1528 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1531 app->quirks = quirks;
1534 static void mt_post_parse(struct mt_device *td, struct mt_application *app)
1536 if (!app->have_contact_count)
1537 app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1540 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
1542 struct mt_device *td = hid_get_drvdata(hdev);
1544 const char *suffix = NULL;
1545 struct mt_report_data *rdata;
1546 struct mt_application *mt_application = NULL;
1547 struct hid_report *report;
1550 list_for_each_entry(report, &hi->reports, hidinput_list) {
1551 rdata = mt_find_report_data(td, report);
1553 hid_err(hdev, "failed to allocate data for report\n");
1557 mt_application = rdata->application;
1559 if (rdata->is_mt_collection) {
1560 ret = mt_touch_input_configured(hdev, hi,
1567 switch (hi->application) {
1568 case HID_GD_KEYBOARD:
1571 case HID_DG_TOUCHPAD:
1572 case HID_GD_SYSTEM_CONTROL:
1573 case HID_CP_CONSUMER_CONTROL:
1574 case HID_GD_WIRELESS_RADIO_CTLS:
1575 case HID_GD_SYSTEM_MULTIAXIS:
1576 /* already handled by hid core */
1578 case HID_DG_TOUCHSCREEN:
1579 /* we do not set suffix = "Touchscreen" */
1580 hi->input->name = hdev->name;
1583 /* force BTN_STYLUS to allow tablet matching in udev */
1584 __set_bit(BTN_STYLUS, hi->input->keybit);
1586 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1587 suffix = "Custom Media Keys";
1598 name = devm_kzalloc(&hi->input->dev,
1599 strlen(hdev->name) + strlen(suffix) + 2,
1602 sprintf(name, "%s %s", hdev->name, suffix);
1603 hi->input->name = name;
1610 static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1612 if (field->usage[0].hid != usage ||
1613 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1616 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1617 field->flags |= HID_MAIN_ITEM_VARIABLE;
1620 static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1622 struct hid_report *report;
1625 list_for_each_entry(report,
1626 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1629 if (!report->maxfield)
1632 for (i = 0; i < report->maxfield; i++)
1633 if (report->field[i]->maxusage >= 1)
1634 mt_fix_const_field(report->field[i], usage);
1638 static void mt_release_contacts(struct hid_device *hid)
1640 struct hid_input *hidinput;
1641 struct mt_application *application;
1642 struct mt_device *td = hid_get_drvdata(hid);
1644 list_for_each_entry(hidinput, &hid->inputs, list) {
1645 struct input_dev *input_dev = hidinput->input;
1646 struct input_mt *mt = input_dev->mt;
1650 for (i = 0; i < mt->num_slots; i++) {
1651 input_mt_slot(input_dev, i);
1652 input_mt_report_slot_state(input_dev,
1656 input_mt_sync_frame(input_dev);
1657 input_sync(input_dev);
1661 list_for_each_entry(application, &td->applications, list) {
1662 application->num_received = 0;
1666 static void mt_expired_timeout(struct timer_list *t)
1668 struct mt_device *td = from_timer(td, t, release_timer);
1669 struct hid_device *hdev = td->hdev;
1672 * An input report came in just before we release the sticky fingers,
1673 * it will take care of the sticky fingers.
1675 if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1677 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1678 mt_release_contacts(hdev);
1679 clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1682 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1685 struct mt_device *td;
1686 const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
1688 for (i = 0; mt_classes[i].name ; i++) {
1689 if (id->driver_data == mt_classes[i].name) {
1690 mtclass = &(mt_classes[i]);
1695 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
1697 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1701 td->mtclass = *mtclass;
1702 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
1703 hid_set_drvdata(hdev, td);
1705 INIT_LIST_HEAD(&td->applications);
1706 INIT_LIST_HEAD(&td->reports);
1708 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1709 td->serial_maybe = true;
1711 /* This allows the driver to correctly support devices
1712 * that emit events over several HID messages.
1714 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1717 * This allows the driver to handle different input sensors
1718 * that emits events through different applications on the same HID
1721 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1723 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
1724 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1726 timer_setup(&td->release_timer, mt_expired_timeout, 0);
1728 ret = hid_parse(hdev);
1732 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1733 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1735 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1739 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
1741 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
1744 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1750 static int mt_reset_resume(struct hid_device *hdev)
1752 mt_release_contacts(hdev);
1753 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1757 static int mt_resume(struct hid_device *hdev)
1759 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1760 * It should be safe to send it to other devices too.
1761 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1763 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
1769 static void mt_remove(struct hid_device *hdev)
1771 struct mt_device *td = hid_get_drvdata(hdev);
1773 del_timer_sync(&td->release_timer);
1775 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
1780 * This list contains only:
1781 * - VID/PID of products not working with the default multitouch handling
1782 * - 2 generic rules.
1783 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1785 static const struct hid_device_id mt_devices[] = {
1788 { .driver_data = MT_CLS_3M,
1789 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1790 USB_DEVICE_ID_3M1968) },
1791 { .driver_data = MT_CLS_3M,
1792 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1793 USB_DEVICE_ID_3M2256) },
1794 { .driver_data = MT_CLS_3M,
1795 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1796 USB_DEVICE_ID_3M3266) },
1799 { .driver_data = MT_CLS_WIN_8_DUAL,
1800 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1801 USB_VENDOR_ID_ALPS_JP,
1802 HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
1803 { .driver_data = MT_CLS_WIN_8_DUAL,
1804 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1805 USB_VENDOR_ID_ALPS_JP,
1806 HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
1807 { .driver_data = MT_CLS_WIN_8_DUAL,
1808 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1809 USB_VENDOR_ID_ALPS_JP,
1810 HID_DEVICE_ID_ALPS_1222) },
1812 /* Lenovo X1 TAB Gen 2 */
1813 { .driver_data = MT_CLS_WIN_8_DUAL,
1814 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1815 USB_VENDOR_ID_LENOVO,
1816 USB_DEVICE_ID_LENOVO_X1_TAB) },
1818 /* Lenovo X1 TAB Gen 3 */
1819 { .driver_data = MT_CLS_WIN_8_DUAL,
1820 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1821 USB_VENDOR_ID_LENOVO,
1822 USB_DEVICE_ID_LENOVO_X1_TAB3) },
1825 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1826 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1827 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
1830 { .driver_data = MT_CLS_ASUS,
1831 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1832 USB_VENDOR_ID_ASUSTEK,
1833 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
1836 { .driver_data = MT_CLS_SERIAL,
1837 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
1838 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
1840 /* Baanto multitouch devices */
1841 { .driver_data = MT_CLS_NSMU,
1842 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
1843 USB_DEVICE_ID_BAANTO_MT_190W2) },
1846 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1847 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1848 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1849 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1850 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1851 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1853 /* Chunghwa Telecom touch panels */
1854 { .driver_data = MT_CLS_NSMU,
1855 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
1856 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1858 /* Cirque devices */
1859 { .driver_data = MT_CLS_WIN_8_DUAL,
1860 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1861 I2C_VENDOR_ID_CIRQUE,
1862 I2C_PRODUCT_ID_CIRQUE_121F) },
1864 /* CJTouch panels */
1865 { .driver_data = MT_CLS_NSMU,
1866 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1867 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
1868 { .driver_data = MT_CLS_NSMU,
1869 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1870 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
1872 /* CVTouch panels */
1873 { .driver_data = MT_CLS_NSMU,
1874 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
1875 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1877 /* eGalax devices (resistive) */
1878 { .driver_data = MT_CLS_EGALAX,
1879 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1880 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1881 { .driver_data = MT_CLS_EGALAX,
1882 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1883 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1885 /* eGalax devices (capacitive) */
1886 { .driver_data = MT_CLS_EGALAX_SERIAL,
1887 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1888 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
1889 { .driver_data = MT_CLS_EGALAX,
1890 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1891 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1892 { .driver_data = MT_CLS_EGALAX_SERIAL,
1893 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1894 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1895 { .driver_data = MT_CLS_EGALAX_SERIAL,
1896 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1897 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
1898 { .driver_data = MT_CLS_EGALAX_SERIAL,
1899 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1900 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
1901 { .driver_data = MT_CLS_EGALAX_SERIAL,
1902 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1903 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
1904 { .driver_data = MT_CLS_EGALAX,
1905 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1906 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1907 { .driver_data = MT_CLS_EGALAX,
1908 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1909 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1910 { .driver_data = MT_CLS_EGALAX_SERIAL,
1911 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1912 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
1913 { .driver_data = MT_CLS_EGALAX,
1914 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1915 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1916 { .driver_data = MT_CLS_EGALAX,
1917 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1918 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1919 { .driver_data = MT_CLS_EGALAX,
1920 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1921 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1922 { .driver_data = MT_CLS_EGALAX,
1923 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1924 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1925 { .driver_data = MT_CLS_EGALAX_SERIAL,
1926 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1927 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1928 { .driver_data = MT_CLS_EGALAX_SERIAL,
1929 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1930 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1931 { .driver_data = MT_CLS_EGALAX_SERIAL,
1932 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1933 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
1934 { .driver_data = MT_CLS_EGALAX,
1935 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1936 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C002) },
1938 /* Elitegroup panel */
1939 { .driver_data = MT_CLS_SERIAL,
1940 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1941 USB_DEVICE_ID_ELITEGROUP_05D8) },
1943 /* Flatfrog Panels */
1944 { .driver_data = MT_CLS_FLATFROG,
1945 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1946 USB_DEVICE_ID_MULTITOUCH_3200) },
1948 /* FocalTech Panels */
1949 { .driver_data = MT_CLS_SERIAL,
1950 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1951 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1953 /* GeneralTouch panel */
1954 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1955 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1956 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1957 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1958 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1959 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
1960 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1961 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1962 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1963 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1964 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1965 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1966 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1967 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1968 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1969 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1970 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1971 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1972 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1973 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1974 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
1976 /* Gametel game controller */
1977 { .driver_data = MT_CLS_NSMU,
1978 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
1979 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1981 /* GoodTouch panels */
1982 { .driver_data = MT_CLS_NSMU,
1983 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
1984 USB_DEVICE_ID_GOODTOUCH_000f) },
1987 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1988 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
1989 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1991 /* Ilitek dual touch panel */
1992 { .driver_data = MT_CLS_NSMU,
1993 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
1994 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1996 /* LG Melfas panel */
1997 { .driver_data = MT_CLS_LG,
1998 HID_USB_DEVICE(USB_VENDOR_ID_LG,
1999 USB_DEVICE_ID_LG_MELFAS_MT) },
2000 { .driver_data = MT_CLS_LG,
2001 HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
2002 USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_7010) },
2005 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2006 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2007 USB_DEVICE_ID_ASUS_T91MT)},
2008 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2009 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2010 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
2011 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2012 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
2013 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
2016 { .driver_data = MT_CLS_NSMU,
2017 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
2018 USB_DEVICE_ID_NOVATEK_PCT) },
2021 { .driver_data = MT_CLS_NSMU,
2022 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2023 USB_VENDOR_ID_NTRIG, 0x1b05) },
2025 /* Panasonic panels */
2026 { .driver_data = MT_CLS_PANASONIC,
2027 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2028 USB_DEVICE_ID_PANABOARD_UBT780) },
2029 { .driver_data = MT_CLS_PANASONIC,
2030 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2031 USB_DEVICE_ID_PANABOARD_UBT880) },
2033 /* PixArt optical touch screen */
2034 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2035 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2036 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
2037 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2038 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2039 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
2040 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2041 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2042 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
2044 /* PixCir-based panels */
2045 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2046 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
2047 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
2049 /* Quanta-based panels */
2050 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2051 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
2052 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
2054 /* Razer touchpads */
2055 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
2056 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2057 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
2059 /* Smart Tech panels */
2060 { .driver_data = MT_CLS_SMART_TECH,
2061 MT_USB_DEVICE(0x0b8c, 0x0092)},
2063 /* Stantum panels */
2064 { .driver_data = MT_CLS_CONFIDENCE,
2065 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
2066 USB_DEVICE_ID_MTP_STM)},
2068 /* TopSeed panels */
2069 { .driver_data = MT_CLS_TOPSEED,
2070 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
2071 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
2073 /* Touch International panels */
2074 { .driver_data = MT_CLS_NSMU,
2075 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
2076 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
2079 { .driver_data = MT_CLS_NSMU,
2080 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2081 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
2082 { .driver_data = MT_CLS_NSMU,
2083 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2084 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
2087 { .driver_data = MT_CLS_VTL,
2088 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
2089 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
2091 /* Wistron panels */
2092 { .driver_data = MT_CLS_NSMU,
2093 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
2094 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
2097 { .driver_data = MT_CLS_NSMU,
2098 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
2099 USB_DEVICE_ID_XAT_CSR) },
2102 { .driver_data = MT_CLS_NSMU,
2103 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2104 USB_DEVICE_ID_XIROKU_SPX) },
2105 { .driver_data = MT_CLS_NSMU,
2106 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2107 USB_DEVICE_ID_XIROKU_MPX) },
2108 { .driver_data = MT_CLS_NSMU,
2109 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2110 USB_DEVICE_ID_XIROKU_CSR) },
2111 { .driver_data = MT_CLS_NSMU,
2112 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2113 USB_DEVICE_ID_XIROKU_SPX1) },
2114 { .driver_data = MT_CLS_NSMU,
2115 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2116 USB_DEVICE_ID_XIROKU_MPX1) },
2117 { .driver_data = MT_CLS_NSMU,
2118 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2119 USB_DEVICE_ID_XIROKU_CSR1) },
2120 { .driver_data = MT_CLS_NSMU,
2121 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2122 USB_DEVICE_ID_XIROKU_SPX2) },
2123 { .driver_data = MT_CLS_NSMU,
2124 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2125 USB_DEVICE_ID_XIROKU_MPX2) },
2126 { .driver_data = MT_CLS_NSMU,
2127 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2128 USB_DEVICE_ID_XIROKU_CSR2) },
2130 /* Google MT devices */
2131 { .driver_data = MT_CLS_GOOGLE,
2132 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
2133 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2134 { .driver_data = MT_CLS_GOOGLE,
2135 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_GOOGLE,
2136 USB_DEVICE_ID_GOOGLE_WHISKERS) },
2138 /* Generic MT device */
2139 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
2141 /* Generic Win 8 certified MT device */
2142 { .driver_data = MT_CLS_WIN_8,
2143 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2144 HID_ANY_ID, HID_ANY_ID) },
2147 MODULE_DEVICE_TABLE(hid, mt_devices);
2149 static const struct hid_usage_id mt_grabbed_usages[] = {
2150 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
2151 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
2154 static struct hid_driver mt_driver = {
2155 .name = "hid-multitouch",
2156 .id_table = mt_devices,
2158 .remove = mt_remove,
2159 .input_mapping = mt_input_mapping,
2160 .input_mapped = mt_input_mapped,
2161 .input_configured = mt_input_configured,
2162 .feature_mapping = mt_feature_mapping,
2163 .usage_table = mt_grabbed_usages,
2165 .report = mt_report,
2167 .reset_resume = mt_reset_resume,
2168 .resume = mt_resume,
2171 module_hid_driver(mt_driver);