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 tool hid-test[1].
32 * This tool relies on hid-replay[2] and a database of hid devices[3].
33 * Please run these regression tests before patching this module so that
34 * your patch won't break existing known devices.
36 * [1] https://github.com/bentiss/hid-test
37 * [2] https://github.com/bentiss/hid-replay
38 * [3] https://github.com/bentiss/hid-devices
41 #include <linux/device.h>
42 #include <linux/hid.h>
43 #include <linux/module.h>
44 #include <linux/slab.h>
45 #include <linux/input/mt.h>
46 #include <linux/string.h>
49 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
50 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
51 MODULE_DESCRIPTION("HID multitouch panels");
52 MODULE_LICENSE("GPL");
56 /* quirks to control the device */
57 #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
58 #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
59 #define MT_QUIRK_CYPRESS (1 << 2)
60 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
61 #define MT_QUIRK_ALWAYS_VALID (1 << 4)
62 #define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
63 #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
64 #define MT_QUIRK_CONFIDENCE (1 << 7)
65 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
66 #define MT_QUIRK_NO_AREA (1 << 9)
67 #define MT_QUIRK_IGNORE_DUPLICATES (1 << 10)
68 #define MT_QUIRK_HOVERING (1 << 11)
69 #define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12)
70 #define MT_QUIRK_FORCE_GET_FEATURE (1 << 13)
71 #define MT_QUIRK_FIX_CONST_CONTACT_ID (1 << 14)
72 #define MT_QUIRK_TOUCH_SIZE_SCALING (1 << 15)
74 #define MT_INPUTMODE_TOUCHSCREEN 0x02
75 #define MT_INPUTMODE_TOUCHPAD 0x03
77 #define MT_BUTTONTYPE_CLICKPAD 0
80 __s32 x
, y
, cx
, cy
, p
, w
, h
;
81 __s32 contactid
; /* the device ContactID assigned to this slot */
82 bool touch_state
; /* is the touch valid? */
83 bool inrange_state
; /* is the finger in proximity of the sensor? */
84 bool confidence_state
; /* is the touch made by a finger? */
88 __s32 name
; /* MT_CLS */
90 __s32 sn_move
; /* Signal/noise ratio for move events */
91 __s32 sn_width
; /* Signal/noise ratio for width events */
92 __s32 sn_height
; /* Signal/noise ratio for height events */
93 __s32 sn_pressure
; /* Signal/noise ratio for pressure events */
95 bool is_indirect
; /* true for touchpads */
96 bool export_all_inputs
; /* do not ignore mouse, keyboards, etc... */
100 unsigned usages
[HID_MAX_FIELDS
];
105 struct mt_slot curdata
; /* placeholder of incoming data */
106 struct mt_class mtclass
; /* our mt device class */
107 struct mt_fields
*fields
; /* temporary placeholder for storing the
109 int cc_index
; /* contact count field index in the report */
110 int cc_value_index
; /* contact count value index in the field */
111 unsigned last_slot_field
; /* the last field of a slot */
112 unsigned mt_report_id
; /* the report ID of the multitouch device */
113 unsigned long initial_quirks
; /* initial quirks state */
114 __s16 inputmode
; /* InputMode HID feature, -1 if non-existent */
115 __s16 inputmode_index
; /* InputMode HID feature index in the report */
116 __s16 maxcontact_report_id
; /* Maximum Contact Number HID feature,
117 -1 if non-existent */
118 __u8 inputmode_value
; /* InputMode HID feature value */
119 __u8 num_received
; /* how many contacts we received */
120 __u8 num_expected
; /* expected last contact index */
122 __u8 touches_by_report
; /* how many touches are present in one report:
123 * 1 means we should use a serial protocol
124 * > 1 means hybrid (multitouch) protocol */
125 __u8 buttons_count
; /* number of physical buttons per touchpad */
126 bool is_buttonpad
; /* is this device a button pad? */
127 bool serial_maybe
; /* need to check for serial protocol */
128 bool curvalid
; /* is the current contact valid? */
129 unsigned mt_flags
; /* flags to pass to input-mt */
132 static void mt_post_parse_default_settings(struct mt_device
*td
);
133 static void mt_post_parse(struct mt_device
*td
);
135 /* classes of device behavior */
136 #define MT_CLS_DEFAULT 0x0001
138 #define MT_CLS_SERIAL 0x0002
139 #define MT_CLS_CONFIDENCE 0x0003
140 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
141 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
142 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
143 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
144 /* reserved 0x0008 */
145 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
146 #define MT_CLS_NSMU 0x000a
147 /* reserved 0x0010 */
148 /* reserved 0x0011 */
149 #define MT_CLS_WIN_8 0x0012
150 #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
151 #define MT_CLS_WIN_8_DUAL 0x0014
153 /* vendor specific classes */
154 #define MT_CLS_3M 0x0101
155 /* reserved 0x0102 */
156 #define MT_CLS_EGALAX 0x0103
157 #define MT_CLS_EGALAX_SERIAL 0x0104
158 #define MT_CLS_TOPSEED 0x0105
159 #define MT_CLS_PANASONIC 0x0106
160 #define MT_CLS_FLATFROG 0x0107
161 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
162 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
163 #define MT_CLS_LG 0x010a
164 #define MT_CLS_VTL 0x0110
166 #define MT_DEFAULT_MAXCONTACT 10
167 #define MT_MAX_MAXCONTACT 250
169 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
170 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
173 * these device-dependent functions determine what slot corresponds
174 * to a valid contact that was just read.
177 static int cypress_compute_slot(struct mt_device
*td
)
179 if (td
->curdata
.contactid
!= 0 || td
->num_received
== 0)
180 return td
->curdata
.contactid
;
185 static struct mt_class mt_classes
[] = {
186 { .name
= MT_CLS_DEFAULT
,
187 .quirks
= MT_QUIRK_ALWAYS_VALID
|
188 MT_QUIRK_CONTACT_CNT_ACCURATE
},
189 { .name
= MT_CLS_NSMU
,
190 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
},
191 { .name
= MT_CLS_SERIAL
,
192 .quirks
= MT_QUIRK_ALWAYS_VALID
},
193 { .name
= MT_CLS_CONFIDENCE
,
194 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
},
195 { .name
= MT_CLS_CONFIDENCE_CONTACT_ID
,
196 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
|
197 MT_QUIRK_SLOT_IS_CONTACTID
},
198 { .name
= MT_CLS_CONFIDENCE_MINUS_ONE
,
199 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
|
200 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE
},
201 { .name
= MT_CLS_DUAL_INRANGE_CONTACTID
,
202 .quirks
= MT_QUIRK_VALID_IS_INRANGE
|
203 MT_QUIRK_SLOT_IS_CONTACTID
,
205 { .name
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
206 .quirks
= MT_QUIRK_VALID_IS_INRANGE
|
207 MT_QUIRK_SLOT_IS_CONTACTNUMBER
,
209 { .name
= MT_CLS_INRANGE_CONTACTNUMBER
,
210 .quirks
= MT_QUIRK_VALID_IS_INRANGE
|
211 MT_QUIRK_SLOT_IS_CONTACTNUMBER
},
212 { .name
= MT_CLS_WIN_8
,
213 .quirks
= MT_QUIRK_ALWAYS_VALID
|
214 MT_QUIRK_IGNORE_DUPLICATES
|
216 MT_QUIRK_CONTACT_CNT_ACCURATE
},
217 { .name
= MT_CLS_EXPORT_ALL_INPUTS
,
218 .quirks
= MT_QUIRK_ALWAYS_VALID
|
219 MT_QUIRK_CONTACT_CNT_ACCURATE
,
220 .export_all_inputs
= true },
221 { .name
= MT_CLS_WIN_8_DUAL
,
222 .quirks
= MT_QUIRK_ALWAYS_VALID
|
223 MT_QUIRK_IGNORE_DUPLICATES
|
225 MT_QUIRK_CONTACT_CNT_ACCURATE
,
226 .export_all_inputs
= true },
229 * vendor specific classes
232 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
|
233 MT_QUIRK_SLOT_IS_CONTACTID
|
234 MT_QUIRK_TOUCH_SIZE_SCALING
,
240 { .name
= MT_CLS_EGALAX
,
241 .quirks
= MT_QUIRK_SLOT_IS_CONTACTID
|
242 MT_QUIRK_VALID_IS_INRANGE
,
246 { .name
= MT_CLS_EGALAX_SERIAL
,
247 .quirks
= MT_QUIRK_SLOT_IS_CONTACTID
|
248 MT_QUIRK_ALWAYS_VALID
,
252 { .name
= MT_CLS_TOPSEED
,
253 .quirks
= MT_QUIRK_ALWAYS_VALID
,
257 { .name
= MT_CLS_PANASONIC
,
258 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
,
260 { .name
= MT_CLS_GENERALTOUCH_TWOFINGERS
,
261 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
|
262 MT_QUIRK_VALID_IS_INRANGE
|
263 MT_QUIRK_SLOT_IS_CONTACTID
,
266 { .name
= MT_CLS_GENERALTOUCH_PWT_TENFINGERS
,
267 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
|
268 MT_QUIRK_SLOT_IS_CONTACTID
271 { .name
= MT_CLS_FLATFROG
,
272 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
|
278 .quirks
= MT_QUIRK_ALWAYS_VALID
|
279 MT_QUIRK_FIX_CONST_CONTACT_ID
|
280 MT_QUIRK_IGNORE_DUPLICATES
|
282 MT_QUIRK_CONTACT_CNT_ACCURATE
},
283 { .name
= MT_CLS_VTL
,
284 .quirks
= MT_QUIRK_ALWAYS_VALID
|
285 MT_QUIRK_CONTACT_CNT_ACCURATE
|
286 MT_QUIRK_FORCE_GET_FEATURE
,
291 static ssize_t
mt_show_quirks(struct device
*dev
,
292 struct device_attribute
*attr
,
295 struct hid_device
*hdev
= to_hid_device(dev
);
296 struct mt_device
*td
= hid_get_drvdata(hdev
);
298 return sprintf(buf
, "%u\n", td
->mtclass
.quirks
);
301 static ssize_t
mt_set_quirks(struct device
*dev
,
302 struct device_attribute
*attr
,
303 const char *buf
, size_t count
)
305 struct hid_device
*hdev
= to_hid_device(dev
);
306 struct mt_device
*td
= hid_get_drvdata(hdev
);
310 if (kstrtoul(buf
, 0, &val
))
313 td
->mtclass
.quirks
= val
;
315 if (td
->cc_index
< 0)
316 td
->mtclass
.quirks
&= ~MT_QUIRK_CONTACT_CNT_ACCURATE
;
321 static DEVICE_ATTR(quirks
, S_IWUSR
| S_IRUGO
, mt_show_quirks
, mt_set_quirks
);
323 static struct attribute
*sysfs_attrs
[] = {
324 &dev_attr_quirks
.attr
,
328 static struct attribute_group mt_attribute_group
= {
332 static void mt_get_feature(struct hid_device
*hdev
, struct hid_report
*report
)
334 struct mt_device
*td
= hid_get_drvdata(hdev
);
335 int ret
, size
= hid_report_len(report
);
339 * Do not fetch the feature report if the device has been explicitly
340 * marked as non-capable.
342 if (td
->initial_quirks
& HID_QUIRK_NO_INIT_REPORTS
)
345 buf
= hid_alloc_report_buf(report
, GFP_KERNEL
);
349 ret
= hid_hw_raw_request(hdev
, report
->id
, buf
, size
,
350 HID_FEATURE_REPORT
, HID_REQ_GET_REPORT
);
352 dev_warn(&hdev
->dev
, "failed to fetch feature %d\n",
355 ret
= hid_report_raw_event(hdev
, HID_FEATURE_REPORT
, buf
,
358 dev_warn(&hdev
->dev
, "failed to report feature\n");
364 static void mt_feature_mapping(struct hid_device
*hdev
,
365 struct hid_field
*field
, struct hid_usage
*usage
)
367 struct mt_device
*td
= hid_get_drvdata(hdev
);
369 switch (usage
->hid
) {
370 case HID_DG_INPUTMODE
:
371 /* Ignore if value index is out of bounds. */
372 if (usage
->usage_index
>= field
->report_count
) {
373 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
377 if (td
->inputmode
< 0) {
378 td
->inputmode
= field
->report
->id
;
379 td
->inputmode_index
= usage
->usage_index
;
382 * Some elan panels wrongly declare 2 input mode
383 * features, and silently ignore when we set the
384 * value in the second field. Skip the second feature
385 * and hope for the best.
388 "Ignoring the extra HID_DG_INPUTMODE\n");
392 case HID_DG_CONTACTMAX
:
393 mt_get_feature(hdev
, field
->report
);
395 td
->maxcontact_report_id
= field
->report
->id
;
396 td
->maxcontacts
= field
->value
[0];
397 if (!td
->maxcontacts
&&
398 field
->logical_maximum
<= MT_MAX_MAXCONTACT
)
399 td
->maxcontacts
= field
->logical_maximum
;
400 if (td
->mtclass
.maxcontacts
)
401 /* check if the maxcontacts is given by the class */
402 td
->maxcontacts
= td
->mtclass
.maxcontacts
;
405 case HID_DG_BUTTONTYPE
:
406 if (usage
->usage_index
>= field
->report_count
) {
407 dev_err(&hdev
->dev
, "HID_DG_BUTTONTYPE out of range\n");
411 mt_get_feature(hdev
, field
->report
);
412 if (field
->value
[usage
->usage_index
] == MT_BUTTONTYPE_CLICKPAD
)
413 td
->is_buttonpad
= true;
417 /* Retrieve the Win8 blob once to enable some devices */
418 if (usage
->usage_index
== 0)
419 mt_get_feature(hdev
, field
->report
);
424 static void set_abs(struct input_dev
*input
, unsigned int code
,
425 struct hid_field
*field
, int snratio
)
427 int fmin
= field
->logical_minimum
;
428 int fmax
= field
->logical_maximum
;
429 int fuzz
= snratio
? (fmax
- fmin
) / snratio
: 0;
430 input_set_abs_params(input
, code
, fmin
, fmax
, fuzz
, 0);
431 input_abs_set_res(input
, code
, hidinput_calc_abs_res(field
, code
));
434 static void mt_store_field(struct hid_usage
*usage
, struct mt_device
*td
,
435 struct hid_input
*hi
)
437 struct mt_fields
*f
= td
->fields
;
439 if (f
->length
>= HID_MAX_FIELDS
)
442 f
->usages
[f
->length
++] = usage
->hid
;
445 static int mt_touch_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
446 struct hid_field
*field
, struct hid_usage
*usage
,
447 unsigned long **bit
, int *max
)
449 struct mt_device
*td
= hid_get_drvdata(hdev
);
450 struct mt_class
*cls
= &td
->mtclass
;
452 struct hid_usage
*prev_usage
= NULL
;
454 if (field
->application
== HID_DG_TOUCHSCREEN
)
455 td
->mt_flags
|= INPUT_MT_DIRECT
;
458 * Model touchscreens providing buttons as touchpads.
460 if (field
->application
== HID_DG_TOUCHPAD
||
461 (usage
->hid
& HID_USAGE_PAGE
) == HID_UP_BUTTON
) {
462 td
->mt_flags
|= INPUT_MT_POINTER
;
463 td
->inputmode_value
= MT_INPUTMODE_TOUCHPAD
;
466 /* count the buttons on touchpads */
467 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_BUTTON
)
470 if (usage
->usage_index
)
471 prev_usage
= &field
->usage
[usage
->usage_index
- 1];
473 switch (usage
->hid
& HID_USAGE_PAGE
) {
476 switch (usage
->hid
) {
478 if (prev_usage
&& (prev_usage
->hid
== usage
->hid
)) {
479 hid_map_usage(hi
, usage
, bit
, max
,
480 EV_ABS
, ABS_MT_TOOL_X
);
481 set_abs(hi
->input
, ABS_MT_TOOL_X
, field
,
484 hid_map_usage(hi
, usage
, bit
, max
,
485 EV_ABS
, ABS_MT_POSITION_X
);
486 set_abs(hi
->input
, ABS_MT_POSITION_X
, field
,
490 mt_store_field(usage
, td
, hi
);
493 if (prev_usage
&& (prev_usage
->hid
== usage
->hid
)) {
494 hid_map_usage(hi
, usage
, bit
, max
,
495 EV_ABS
, ABS_MT_TOOL_Y
);
496 set_abs(hi
->input
, ABS_MT_TOOL_Y
, field
,
499 hid_map_usage(hi
, usage
, bit
, max
,
500 EV_ABS
, ABS_MT_POSITION_Y
);
501 set_abs(hi
->input
, ABS_MT_POSITION_Y
, field
,
505 mt_store_field(usage
, td
, hi
);
510 case HID_UP_DIGITIZER
:
511 switch (usage
->hid
) {
513 if (cls
->quirks
& MT_QUIRK_HOVERING
) {
514 hid_map_usage(hi
, usage
, bit
, max
,
515 EV_ABS
, ABS_MT_DISTANCE
);
516 input_set_abs_params(hi
->input
,
517 ABS_MT_DISTANCE
, 0, 1, 0, 0);
519 mt_store_field(usage
, td
, hi
);
521 case HID_DG_CONFIDENCE
:
522 if ((cls
->name
== MT_CLS_WIN_8
||
523 cls
->name
== MT_CLS_WIN_8_DUAL
) &&
524 field
->application
== HID_DG_TOUCHPAD
)
525 cls
->quirks
|= MT_QUIRK_CONFIDENCE
;
526 mt_store_field(usage
, td
, hi
);
528 case HID_DG_TIPSWITCH
:
529 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
530 input_set_capability(hi
->input
, EV_KEY
, BTN_TOUCH
);
531 mt_store_field(usage
, td
, hi
);
533 case HID_DG_CONTACTID
:
534 mt_store_field(usage
, td
, hi
);
535 td
->touches_by_report
++;
536 td
->mt_report_id
= field
->report
->id
;
539 hid_map_usage(hi
, usage
, bit
, max
,
540 EV_ABS
, ABS_MT_TOUCH_MAJOR
);
541 if (!(cls
->quirks
& MT_QUIRK_NO_AREA
))
542 set_abs(hi
->input
, ABS_MT_TOUCH_MAJOR
, field
,
544 mt_store_field(usage
, td
, hi
);
547 hid_map_usage(hi
, usage
, bit
, max
,
548 EV_ABS
, ABS_MT_TOUCH_MINOR
);
549 if (!(cls
->quirks
& MT_QUIRK_NO_AREA
)) {
550 set_abs(hi
->input
, ABS_MT_TOUCH_MINOR
, field
,
552 input_set_abs_params(hi
->input
,
553 ABS_MT_ORIENTATION
, 0, 1, 0, 0);
555 mt_store_field(usage
, td
, hi
);
557 case HID_DG_TIPPRESSURE
:
558 hid_map_usage(hi
, usage
, bit
, max
,
559 EV_ABS
, ABS_MT_PRESSURE
);
560 set_abs(hi
->input
, ABS_MT_PRESSURE
, field
,
562 mt_store_field(usage
, td
, hi
);
564 case HID_DG_CONTACTCOUNT
:
565 /* Ignore if indexes are out of bounds. */
566 if (field
->index
>= field
->report
->maxfield
||
567 usage
->usage_index
>= field
->report_count
)
569 td
->cc_index
= field
->index
;
570 td
->cc_value_index
= usage
->usage_index
;
572 case HID_DG_CONTACTMAX
:
573 /* we don't set td->last_slot_field as contactcount and
574 * contact max are global to the report */
577 /* Legacy devices use TIPSWITCH and not TOUCH.
578 * Let's just ignore this field. */
581 /* let hid-input decide for the others */
585 code
= BTN_MOUSE
+ ((usage
->hid
- 1) & HID_USAGE
);
587 * MS PTP spec says that external buttons left and right have
590 if ((cls
->name
== MT_CLS_WIN_8
||
591 cls
->name
== MT_CLS_WIN_8_DUAL
) &&
592 field
->application
== HID_DG_TOUCHPAD
&&
593 (usage
->hid
& HID_USAGE
) > 1)
595 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, code
);
596 input_set_capability(hi
->input
, EV_KEY
, code
);
600 /* we do not want to map these: no input-oriented meaning */
607 static int mt_touch_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
608 struct hid_field
*field
, struct hid_usage
*usage
,
609 unsigned long **bit
, int *max
)
611 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
612 set_bit(usage
->type
, hi
->input
->evbit
);
617 static int mt_compute_slot(struct mt_device
*td
, struct input_dev
*input
)
619 __s32 quirks
= td
->mtclass
.quirks
;
621 if (quirks
& MT_QUIRK_SLOT_IS_CONTACTID
)
622 return td
->curdata
.contactid
;
624 if (quirks
& MT_QUIRK_CYPRESS
)
625 return cypress_compute_slot(td
);
627 if (quirks
& MT_QUIRK_SLOT_IS_CONTACTNUMBER
)
628 return td
->num_received
;
630 if (quirks
& MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE
)
631 return td
->curdata
.contactid
- 1;
633 return input_mt_get_slot_by_key(input
, td
->curdata
.contactid
);
637 * this function is called when a whole contact has been processed,
638 * so that it can assign it to a slot and store the data there
640 static void mt_complete_slot(struct mt_device
*td
, struct input_dev
*input
)
642 if ((td
->mtclass
.quirks
& MT_QUIRK_CONTACT_CNT_ACCURATE
) &&
643 td
->num_received
>= td
->num_expected
)
646 if (td
->curvalid
|| (td
->mtclass
.quirks
& MT_QUIRK_ALWAYS_VALID
)) {
648 int slotnum
= mt_compute_slot(td
, input
);
649 struct mt_slot
*s
= &td
->curdata
;
650 struct input_mt
*mt
= input
->mt
;
652 if (slotnum
< 0 || slotnum
>= td
->maxcontacts
)
655 if ((td
->mtclass
.quirks
& MT_QUIRK_IGNORE_DUPLICATES
) && mt
) {
656 struct input_mt_slot
*slot
= &mt
->slots
[slotnum
];
657 if (input_mt_is_active(slot
) &&
658 input_mt_is_used(mt
, slot
))
662 if (!(td
->mtclass
.quirks
& MT_QUIRK_CONFIDENCE
))
663 s
->confidence_state
= 1;
664 active
= (s
->touch_state
|| s
->inrange_state
) &&
667 input_mt_slot(input
, slotnum
);
668 input_mt_report_slot_state(input
, MT_TOOL_FINGER
, active
);
670 /* this finger is in proximity of the sensor */
671 int wide
= (s
->w
> s
->h
);
672 int major
= max(s
->w
, s
->h
);
673 int minor
= min(s
->w
, s
->h
);
676 * divided by two to match visual scale of touch
677 * for devices with this quirk
679 if (td
->mtclass
.quirks
& MT_QUIRK_TOUCH_SIZE_SCALING
) {
684 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, s
->x
);
685 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, s
->y
);
686 input_event(input
, EV_ABS
, ABS_MT_TOOL_X
, s
->cx
);
687 input_event(input
, EV_ABS
, ABS_MT_TOOL_Y
, s
->cy
);
688 input_event(input
, EV_ABS
, ABS_MT_DISTANCE
,
690 input_event(input
, EV_ABS
, ABS_MT_ORIENTATION
, wide
);
691 input_event(input
, EV_ABS
, ABS_MT_PRESSURE
, s
->p
);
692 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MAJOR
, major
);
693 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MINOR
, minor
);
701 * this function is called when a whole packet has been received and processed,
702 * so that it can decide what to send to the input layer.
704 static void mt_sync_frame(struct mt_device
*td
, struct input_dev
*input
)
706 input_mt_sync_frame(input
);
708 td
->num_received
= 0;
711 static int mt_touch_event(struct hid_device
*hid
, struct hid_field
*field
,
712 struct hid_usage
*usage
, __s32 value
)
714 /* we will handle the hidinput part later, now remains hiddev */
715 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
716 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
721 static void mt_process_mt_event(struct hid_device
*hid
, struct hid_field
*field
,
722 struct hid_usage
*usage
, __s32 value
)
724 struct mt_device
*td
= hid_get_drvdata(hid
);
725 __s32 quirks
= td
->mtclass
.quirks
;
726 struct input_dev
*input
= field
->hidinput
->input
;
728 if (hid
->claimed
& HID_CLAIMED_INPUT
) {
729 switch (usage
->hid
) {
731 if (quirks
& MT_QUIRK_VALID_IS_INRANGE
)
732 td
->curvalid
= value
;
733 if (quirks
& MT_QUIRK_HOVERING
)
734 td
->curdata
.inrange_state
= value
;
736 case HID_DG_TIPSWITCH
:
737 if (quirks
& MT_QUIRK_NOT_SEEN_MEANS_UP
)
738 td
->curvalid
= value
;
739 td
->curdata
.touch_state
= value
;
741 case HID_DG_CONFIDENCE
:
742 if (quirks
& MT_QUIRK_CONFIDENCE
)
743 td
->curdata
.confidence_state
= value
;
744 if (quirks
& MT_QUIRK_VALID_IS_CONFIDENCE
)
745 td
->curvalid
= value
;
747 case HID_DG_CONTACTID
:
748 td
->curdata
.contactid
= value
;
750 case HID_DG_TIPPRESSURE
:
751 td
->curdata
.p
= value
;
754 if (usage
->code
== ABS_MT_TOOL_X
)
755 td
->curdata
.cx
= value
;
757 td
->curdata
.x
= value
;
760 if (usage
->code
== ABS_MT_TOOL_Y
)
761 td
->curdata
.cy
= value
;
763 td
->curdata
.y
= value
;
766 td
->curdata
.w
= value
;
769 td
->curdata
.h
= value
;
771 case HID_DG_CONTACTCOUNT
:
779 input_event(input
, usage
->type
, usage
->code
,
784 if (usage
->usage_index
+ 1 == field
->report_count
) {
785 /* we only take into account the last report. */
786 if (usage
->hid
== td
->last_slot_field
)
787 mt_complete_slot(td
, field
->hidinput
->input
);
793 static void mt_touch_report(struct hid_device
*hid
, struct hid_report
*report
)
795 struct mt_device
*td
= hid_get_drvdata(hid
);
796 struct hid_field
*field
;
801 * Includes multi-packet support where subsequent
802 * packets are sent with zero contactcount.
804 if (td
->cc_index
>= 0) {
805 struct hid_field
*field
= report
->field
[td
->cc_index
];
806 int value
= field
->value
[td
->cc_value_index
];
808 td
->num_expected
= value
;
811 for (r
= 0; r
< report
->maxfield
; r
++) {
812 field
= report
->field
[r
];
813 count
= field
->report_count
;
815 if (!(HID_MAIN_ITEM_VARIABLE
& field
->flags
))
818 for (n
= 0; n
< count
; n
++)
819 mt_process_mt_event(hid
, field
, &field
->usage
[n
],
823 if (td
->num_received
>= td
->num_expected
)
824 mt_sync_frame(td
, report
->field
[0]->hidinput
->input
);
827 static int mt_touch_input_configured(struct hid_device
*hdev
,
828 struct hid_input
*hi
)
830 struct mt_device
*td
= hid_get_drvdata(hdev
);
831 struct mt_class
*cls
= &td
->mtclass
;
832 struct input_dev
*input
= hi
->input
;
835 if (!td
->maxcontacts
)
836 td
->maxcontacts
= MT_DEFAULT_MAXCONTACT
;
839 if (td
->serial_maybe
)
840 mt_post_parse_default_settings(td
);
842 if (cls
->is_indirect
)
843 td
->mt_flags
|= INPUT_MT_POINTER
;
845 if (cls
->quirks
& MT_QUIRK_NOT_SEEN_MEANS_UP
)
846 td
->mt_flags
|= INPUT_MT_DROP_UNUSED
;
848 /* check for clickpads */
849 if ((td
->mt_flags
& INPUT_MT_POINTER
) && (td
->buttons_count
== 1))
850 td
->is_buttonpad
= true;
852 if (td
->is_buttonpad
)
853 __set_bit(INPUT_PROP_BUTTONPAD
, input
->propbit
);
855 ret
= input_mt_init_slots(input
, td
->maxcontacts
, td
->mt_flags
);
863 static int mt_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
864 struct hid_field
*field
, struct hid_usage
*usage
,
865 unsigned long **bit
, int *max
)
867 struct mt_device
*td
= hid_get_drvdata(hdev
);
870 * If mtclass.export_all_inputs is not set, only map fields from
871 * TouchScreen or TouchPad collections. We need to ignore fields
872 * that belong to other collections such as Mouse that might have
873 * the same GenericDesktop usages.
875 if (!td
->mtclass
.export_all_inputs
&&
876 field
->application
!= HID_DG_TOUCHSCREEN
&&
877 field
->application
!= HID_DG_PEN
&&
878 field
->application
!= HID_DG_TOUCHPAD
&&
879 field
->application
!= HID_GD_KEYBOARD
&&
880 field
->application
!= HID_CP_CONSUMER_CONTROL
)
884 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
886 * The check for mt_report_id ensures we don't process
887 * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical
888 * collection, but within the report ID.
890 if (field
->physical
== HID_DG_STYLUS
)
892 else if ((field
->physical
== 0) &&
893 (field
->report
->id
!= td
->mt_report_id
) &&
894 (td
->mt_report_id
!= -1))
897 if (field
->application
== HID_DG_TOUCHSCREEN
||
898 field
->application
== HID_DG_TOUCHPAD
)
899 return mt_touch_input_mapping(hdev
, hi
, field
, usage
, bit
, max
);
901 /* let hid-core decide for the others */
905 static int mt_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
906 struct hid_field
*field
, struct hid_usage
*usage
,
907 unsigned long **bit
, int *max
)
910 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
913 if (field
->physical
== HID_DG_STYLUS
)
916 if (field
->application
== HID_DG_TOUCHSCREEN
||
917 field
->application
== HID_DG_TOUCHPAD
)
918 return mt_touch_input_mapped(hdev
, hi
, field
, usage
, bit
, max
);
920 /* let hid-core decide for the others */
924 static int mt_event(struct hid_device
*hid
, struct hid_field
*field
,
925 struct hid_usage
*usage
, __s32 value
)
927 struct mt_device
*td
= hid_get_drvdata(hid
);
929 if (field
->report
->id
== td
->mt_report_id
)
930 return mt_touch_event(hid
, field
, usage
, value
);
935 static void mt_report(struct hid_device
*hid
, struct hid_report
*report
)
937 struct mt_device
*td
= hid_get_drvdata(hid
);
938 struct hid_field
*field
= report
->field
[0];
940 if (!(hid
->claimed
& HID_CLAIMED_INPUT
))
943 if (report
->id
== td
->mt_report_id
)
944 return mt_touch_report(hid
, report
);
946 if (field
&& field
->hidinput
&& field
->hidinput
->input
)
947 input_sync(field
->hidinput
->input
);
950 static void mt_set_input_mode(struct hid_device
*hdev
)
952 struct mt_device
*td
= hid_get_drvdata(hdev
);
953 struct hid_report
*r
;
954 struct hid_report_enum
*re
;
955 struct mt_class
*cls
= &td
->mtclass
;
959 if (td
->inputmode
< 0)
962 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
963 r
= re
->report_id_hash
[td
->inputmode
];
965 if (cls
->quirks
& MT_QUIRK_FORCE_GET_FEATURE
) {
966 report_len
= hid_report_len(r
);
967 buf
= hid_alloc_report_buf(r
, GFP_KERNEL
);
969 hid_err(hdev
, "failed to allocate buffer for report\n");
972 hid_hw_raw_request(hdev
, r
->id
, buf
, report_len
,
977 r
->field
[0]->value
[td
->inputmode_index
] = td
->inputmode_value
;
978 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
982 static void mt_set_maxcontacts(struct hid_device
*hdev
)
984 struct mt_device
*td
= hid_get_drvdata(hdev
);
985 struct hid_report
*r
;
986 struct hid_report_enum
*re
;
989 if (td
->maxcontact_report_id
< 0)
992 if (!td
->mtclass
.maxcontacts
)
995 re
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
996 r
= re
->report_id_hash
[td
->maxcontact_report_id
];
998 max
= td
->mtclass
.maxcontacts
;
999 fieldmax
= r
->field
[0]->logical_maximum
;
1000 max
= min(fieldmax
, max
);
1001 if (r
->field
[0]->value
[0] != max
) {
1002 r
->field
[0]->value
[0] = max
;
1003 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
1008 static void mt_post_parse_default_settings(struct mt_device
*td
)
1010 __s32 quirks
= td
->mtclass
.quirks
;
1012 /* unknown serial device needs special quirks */
1013 if (td
->touches_by_report
== 1) {
1014 quirks
|= MT_QUIRK_ALWAYS_VALID
;
1015 quirks
&= ~MT_QUIRK_NOT_SEEN_MEANS_UP
;
1016 quirks
&= ~MT_QUIRK_VALID_IS_INRANGE
;
1017 quirks
&= ~MT_QUIRK_VALID_IS_CONFIDENCE
;
1018 quirks
&= ~MT_QUIRK_CONTACT_CNT_ACCURATE
;
1021 td
->mtclass
.quirks
= quirks
;
1024 static void mt_post_parse(struct mt_device
*td
)
1026 struct mt_fields
*f
= td
->fields
;
1027 struct mt_class
*cls
= &td
->mtclass
;
1029 if (td
->touches_by_report
> 0) {
1030 int field_count_per_touch
= f
->length
/ td
->touches_by_report
;
1031 td
->last_slot_field
= f
->usages
[field_count_per_touch
- 1];
1034 if (td
->cc_index
< 0)
1035 cls
->quirks
&= ~MT_QUIRK_CONTACT_CNT_ACCURATE
;
1038 static int mt_input_configured(struct hid_device
*hdev
, struct hid_input
*hi
)
1040 struct mt_device
*td
= hid_get_drvdata(hdev
);
1042 const char *suffix
= NULL
;
1043 struct hid_field
*field
= hi
->report
->field
[0];
1046 if (hi
->report
->id
== td
->mt_report_id
) {
1047 ret
= mt_touch_input_configured(hdev
, hi
);
1053 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
1054 * for the stylus. Check this first, and then rely on the application
1057 if (hi
->report
->field
[0]->physical
== HID_DG_STYLUS
) {
1059 /* force BTN_STYLUS to allow tablet matching in udev */
1060 __set_bit(BTN_STYLUS
, hi
->input
->keybit
);
1062 switch (field
->application
) {
1063 case HID_GD_KEYBOARD
:
1064 suffix
= "Keyboard";
1074 /* force BTN_STYLUS to allow tablet matching in udev */
1075 __set_bit(BTN_STYLUS
, hi
->input
->keybit
);
1077 case HID_DG_TOUCHSCREEN
:
1078 /* we do not set suffix = "Touchscreen" */
1080 case HID_DG_TOUCHPAD
:
1081 suffix
= "Touchpad";
1083 case HID_GD_SYSTEM_CONTROL
:
1084 suffix
= "System Control";
1086 case HID_CP_CONSUMER_CONTROL
:
1087 suffix
= "Consumer Control";
1096 name
= devm_kzalloc(&hi
->input
->dev
,
1097 strlen(hdev
->name
) + strlen(suffix
) + 2,
1100 sprintf(name
, "%s %s", hdev
->name
, suffix
);
1101 hi
->input
->name
= name
;
1108 static void mt_fix_const_field(struct hid_field
*field
, unsigned int usage
)
1110 if (field
->usage
[0].hid
!= usage
||
1111 !(field
->flags
& HID_MAIN_ITEM_CONSTANT
))
1114 field
->flags
&= ~HID_MAIN_ITEM_CONSTANT
;
1115 field
->flags
|= HID_MAIN_ITEM_VARIABLE
;
1118 static void mt_fix_const_fields(struct hid_device
*hdev
, unsigned int usage
)
1120 struct hid_report
*report
;
1123 list_for_each_entry(report
,
1124 &hdev
->report_enum
[HID_INPUT_REPORT
].report_list
,
1127 if (!report
->maxfield
)
1130 for (i
= 0; i
< report
->maxfield
; i
++)
1131 if (report
->field
[i
]->maxusage
>= 1)
1132 mt_fix_const_field(report
->field
[i
], usage
);
1136 static int mt_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
1139 struct mt_device
*td
;
1140 struct mt_class
*mtclass
= mt_classes
; /* MT_CLS_DEFAULT */
1142 for (i
= 0; mt_classes
[i
].name
; i
++) {
1143 if (id
->driver_data
== mt_classes
[i
].name
) {
1144 mtclass
= &(mt_classes
[i
]);
1149 td
= devm_kzalloc(&hdev
->dev
, sizeof(struct mt_device
), GFP_KERNEL
);
1151 dev_err(&hdev
->dev
, "cannot allocate multitouch data\n");
1154 td
->mtclass
= *mtclass
;
1156 td
->maxcontact_report_id
= -1;
1157 td
->inputmode_value
= MT_INPUTMODE_TOUCHSCREEN
;
1159 td
->mt_report_id
= -1;
1160 hid_set_drvdata(hdev
, td
);
1162 td
->fields
= devm_kzalloc(&hdev
->dev
, sizeof(struct mt_fields
),
1165 dev_err(&hdev
->dev
, "cannot allocate multitouch fields data\n");
1169 if (id
->vendor
== HID_ANY_ID
&& id
->product
== HID_ANY_ID
)
1170 td
->serial_maybe
= true;
1173 * Store the initial quirk state
1175 td
->initial_quirks
= hdev
->quirks
;
1177 /* This allows the driver to correctly support devices
1178 * that emit events over several HID messages.
1180 hdev
->quirks
|= HID_QUIRK_NO_INPUT_SYNC
;
1183 * This allows the driver to handle different input sensors
1184 * that emits events through different reports on the same HID
1187 hdev
->quirks
|= HID_QUIRK_MULTI_INPUT
;
1188 hdev
->quirks
|= HID_QUIRK_NO_EMPTY_INPUT
;
1191 * Some multitouch screens do not like to be polled for input
1192 * reports. Fortunately, the Win8 spec says that all touches
1193 * should be sent during each report, making the initialization
1194 * of input reports unnecessary. For Win7 devices, well, let's hope
1195 * they will still be happy (this is only be a problem if a touch
1196 * was already there while probing the device).
1198 * In addition some touchpads do not behave well if we read
1199 * all feature reports from them. Instead we prevent
1200 * initial report fetching and then selectively fetch each
1201 * report we are interested in.
1203 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
1205 ret
= hid_parse(hdev
);
1209 if (mtclass
->quirks
& MT_QUIRK_FIX_CONST_CONTACT_ID
)
1210 mt_fix_const_fields(hdev
, HID_DG_CONTACTID
);
1212 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
1216 ret
= sysfs_create_group(&hdev
->dev
.kobj
, &mt_attribute_group
);
1218 dev_warn(&hdev
->dev
, "Cannot allocate sysfs group for %s\n",
1221 mt_set_maxcontacts(hdev
);
1222 mt_set_input_mode(hdev
);
1224 /* release .fields memory as it is not used anymore */
1225 devm_kfree(&hdev
->dev
, td
->fields
);
1232 static void mt_release_contacts(struct hid_device
*hid
)
1234 struct hid_input
*hidinput
;
1236 list_for_each_entry(hidinput
, &hid
->inputs
, list
) {
1237 struct input_dev
*input_dev
= hidinput
->input
;
1238 struct input_mt
*mt
= input_dev
->mt
;
1242 for (i
= 0; i
< mt
->num_slots
; i
++) {
1243 input_mt_slot(input_dev
, i
);
1244 input_mt_report_slot_state(input_dev
,
1248 input_mt_sync_frame(input_dev
);
1249 input_sync(input_dev
);
1254 static int mt_reset_resume(struct hid_device
*hdev
)
1256 mt_release_contacts(hdev
);
1257 mt_set_maxcontacts(hdev
);
1258 mt_set_input_mode(hdev
);
1262 static int mt_resume(struct hid_device
*hdev
)
1264 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1265 * It should be safe to send it to other devices too.
1266 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1268 hid_hw_idle(hdev
, 0, 0, HID_REQ_SET_IDLE
);
1274 static void mt_remove(struct hid_device
*hdev
)
1276 struct mt_device
*td
= hid_get_drvdata(hdev
);
1278 sysfs_remove_group(&hdev
->dev
.kobj
, &mt_attribute_group
);
1280 hdev
->quirks
= td
->initial_quirks
;
1284 * This list contains only:
1285 * - VID/PID of products not working with the default multitouch handling
1286 * - 2 generic rules.
1287 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1289 static const struct hid_device_id mt_devices
[] = {
1292 { .driver_data
= MT_CLS_3M
,
1293 MT_USB_DEVICE(USB_VENDOR_ID_3M
,
1294 USB_DEVICE_ID_3M1968
) },
1295 { .driver_data
= MT_CLS_3M
,
1296 MT_USB_DEVICE(USB_VENDOR_ID_3M
,
1297 USB_DEVICE_ID_3M2256
) },
1298 { .driver_data
= MT_CLS_3M
,
1299 MT_USB_DEVICE(USB_VENDOR_ID_3M
,
1300 USB_DEVICE_ID_3M3266
) },
1303 { .driver_data
= MT_CLS_WIN_8_DUAL
,
1304 HID_DEVICE(BUS_I2C
, HID_GROUP_MULTITOUCH_WIN_8
,
1305 USB_VENDOR_ID_ALPS_JP
,
1306 HID_DEVICE_ID_ALPS_U1_DUAL_PTP
) },
1307 { .driver_data
= MT_CLS_WIN_8_DUAL
,
1308 HID_DEVICE(BUS_I2C
, HID_GROUP_MULTITOUCH_WIN_8
,
1309 USB_VENDOR_ID_ALPS_JP
,
1310 HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP
) },
1313 { .driver_data
= MT_CLS_EXPORT_ALL_INPUTS
,
1314 MT_USB_DEVICE(USB_VENDOR_ID_ANTON
,
1315 USB_DEVICE_ID_ANTON_TOUCH_PAD
) },
1318 { .driver_data
= MT_CLS_SERIAL
,
1319 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL
,
1320 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER
) },
1322 /* Baanto multitouch devices */
1323 { .driver_data
= MT_CLS_NSMU
,
1324 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO
,
1325 USB_DEVICE_ID_BAANTO_MT_190W2
) },
1328 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
1329 MT_USB_DEVICE(USB_VENDOR_ID_CANDO
,
1330 USB_DEVICE_ID_CANDO_MULTI_TOUCH
) },
1331 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
1332 MT_USB_DEVICE(USB_VENDOR_ID_CANDO
,
1333 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6
) },
1335 /* Chunghwa Telecom touch panels */
1336 { .driver_data
= MT_CLS_NSMU
,
1337 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT
,
1338 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH
) },
1340 /* CJTouch panels */
1341 { .driver_data
= MT_CLS_NSMU
,
1342 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH
,
1343 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020
) },
1344 { .driver_data
= MT_CLS_NSMU
,
1345 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH
,
1346 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040
) },
1348 /* CVTouch panels */
1349 { .driver_data
= MT_CLS_NSMU
,
1350 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH
,
1351 USB_DEVICE_ID_CVTOUCH_SCREEN
) },
1353 /* eGalax devices (resistive) */
1354 { .driver_data
= MT_CLS_EGALAX
,
1355 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1356 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D
) },
1357 { .driver_data
= MT_CLS_EGALAX
,
1358 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1359 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E
) },
1361 /* eGalax devices (capacitive) */
1362 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1363 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1364 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207
) },
1365 { .driver_data
= MT_CLS_EGALAX
,
1366 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1367 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C
) },
1368 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1369 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1370 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224
) },
1371 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1372 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1373 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A
) },
1374 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1375 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1376 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E
) },
1377 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1378 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1379 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262
) },
1380 { .driver_data
= MT_CLS_EGALAX
,
1381 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1382 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B
) },
1383 { .driver_data
= MT_CLS_EGALAX
,
1384 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1385 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1
) },
1386 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1387 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1388 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA
) },
1389 { .driver_data
= MT_CLS_EGALAX
,
1390 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1391 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4
) },
1392 { .driver_data
= MT_CLS_EGALAX
,
1393 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1394 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0
) },
1395 { .driver_data
= MT_CLS_EGALAX
,
1396 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1397 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA
) },
1398 { .driver_data
= MT_CLS_EGALAX
,
1399 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1400 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302
) },
1401 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1402 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1403 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349
) },
1404 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1405 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1406 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7
) },
1407 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
1408 MT_USB_DEVICE(USB_VENDOR_ID_DWAV
,
1409 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001
) },
1411 /* Elitegroup panel */
1412 { .driver_data
= MT_CLS_SERIAL
,
1413 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP
,
1414 USB_DEVICE_ID_ELITEGROUP_05D8
) },
1416 /* Flatfrog Panels */
1417 { .driver_data
= MT_CLS_FLATFROG
,
1418 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG
,
1419 USB_DEVICE_ID_MULTITOUCH_3200
) },
1421 /* FocalTech Panels */
1422 { .driver_data
= MT_CLS_SERIAL
,
1423 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL
,
1424 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH
) },
1426 /* GeneralTouch panel */
1427 { .driver_data
= MT_CLS_GENERALTOUCH_TWOFINGERS
,
1428 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1429 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS
) },
1430 { .driver_data
= MT_CLS_GENERALTOUCH_PWT_TENFINGERS
,
1431 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1432 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS
) },
1433 { .driver_data
= MT_CLS_GENERALTOUCH_TWOFINGERS
,
1434 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1435 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101
) },
1436 { .driver_data
= MT_CLS_GENERALTOUCH_PWT_TENFINGERS
,
1437 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1438 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102
) },
1439 { .driver_data
= MT_CLS_GENERALTOUCH_PWT_TENFINGERS
,
1440 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1441 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106
) },
1442 { .driver_data
= MT_CLS_GENERALTOUCH_PWT_TENFINGERS
,
1443 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1444 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A
) },
1445 { .driver_data
= MT_CLS_GENERALTOUCH_PWT_TENFINGERS
,
1446 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
1447 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100
) },
1449 /* Gametel game controller */
1450 { .driver_data
= MT_CLS_NSMU
,
1451 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL
,
1452 USB_DEVICE_ID_GAMETEL_MT_MODE
) },
1454 /* GoodTouch panels */
1455 { .driver_data
= MT_CLS_NSMU
,
1456 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH
,
1457 USB_DEVICE_ID_GOODTOUCH_000f
) },
1460 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTID
,
1461 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT
,
1462 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH
) },
1464 /* Ilitek dual touch panel */
1465 { .driver_data
= MT_CLS_NSMU
,
1466 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK
,
1467 USB_DEVICE_ID_ILITEK_MULTITOUCH
) },
1469 /* LG Melfas panel */
1470 { .driver_data
= MT_CLS_LG
,
1471 HID_USB_DEVICE(USB_VENDOR_ID_LG
,
1472 USB_DEVICE_ID_LG_MELFAS_MT
) },
1475 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
1476 MT_USB_DEVICE(USB_VENDOR_ID_ASUS
,
1477 USB_DEVICE_ID_ASUS_T91MT
)},
1478 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
1479 MT_USB_DEVICE(USB_VENDOR_ID_ASUS
,
1480 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO
) },
1481 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
1482 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX
,
1483 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART
) },
1485 /* Panasonic panels */
1486 { .driver_data
= MT_CLS_PANASONIC
,
1487 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC
,
1488 USB_DEVICE_ID_PANABOARD_UBT780
) },
1489 { .driver_data
= MT_CLS_PANASONIC
,
1490 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC
,
1491 USB_DEVICE_ID_PANABOARD_UBT880
) },
1494 { .driver_data
= MT_CLS_NSMU
,
1495 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK
,
1496 USB_DEVICE_ID_NOVATEK_PCT
) },
1499 { .driver_data
= MT_CLS_NSMU
,
1500 HID_DEVICE(BUS_I2C
, HID_GROUP_MULTITOUCH_WIN_8
,
1501 USB_VENDOR_ID_NTRIG
, 0x1b05) },
1503 /* PixArt optical touch screen */
1504 { .driver_data
= MT_CLS_INRANGE_CONTACTNUMBER
,
1505 MT_USB_DEVICE(USB_VENDOR_ID_PIXART
,
1506 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN
) },
1507 { .driver_data
= MT_CLS_INRANGE_CONTACTNUMBER
,
1508 MT_USB_DEVICE(USB_VENDOR_ID_PIXART
,
1509 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1
) },
1510 { .driver_data
= MT_CLS_INRANGE_CONTACTNUMBER
,
1511 MT_USB_DEVICE(USB_VENDOR_ID_PIXART
,
1512 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2
) },
1514 /* PixCir-based panels */
1515 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTID
,
1516 MT_USB_DEVICE(USB_VENDOR_ID_CANDO
,
1517 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH
) },
1519 /* Quanta-based panels */
1520 { .driver_data
= MT_CLS_CONFIDENCE_CONTACT_ID
,
1521 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA
,
1522 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001
) },
1524 /* Stantum panels */
1525 { .driver_data
= MT_CLS_CONFIDENCE
,
1526 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM
,
1527 USB_DEVICE_ID_MTP_STM
)},
1529 /* TopSeed panels */
1530 { .driver_data
= MT_CLS_TOPSEED
,
1531 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2
,
1532 USB_DEVICE_ID_TOPSEED2_PERIPAD_701
) },
1534 /* Touch International panels */
1535 { .driver_data
= MT_CLS_NSMU
,
1536 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL
,
1537 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH
) },
1540 { .driver_data
= MT_CLS_NSMU
,
1541 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC
,
1542 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709
) },
1543 { .driver_data
= MT_CLS_NSMU
,
1544 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC
,
1545 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19
) },
1548 { .driver_data
= MT_CLS_VTL
,
1549 MT_USB_DEVICE(USB_VENDOR_ID_VTL
,
1550 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F
) },
1552 /* Wistron panels */
1553 { .driver_data
= MT_CLS_NSMU
,
1554 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON
,
1555 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH
) },
1558 { .driver_data
= MT_CLS_NSMU
,
1559 MT_USB_DEVICE(USB_VENDOR_ID_XAT
,
1560 USB_DEVICE_ID_XAT_CSR
) },
1563 { .driver_data
= MT_CLS_NSMU
,
1564 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1565 USB_DEVICE_ID_XIROKU_SPX
) },
1566 { .driver_data
= MT_CLS_NSMU
,
1567 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1568 USB_DEVICE_ID_XIROKU_MPX
) },
1569 { .driver_data
= MT_CLS_NSMU
,
1570 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1571 USB_DEVICE_ID_XIROKU_CSR
) },
1572 { .driver_data
= MT_CLS_NSMU
,
1573 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1574 USB_DEVICE_ID_XIROKU_SPX1
) },
1575 { .driver_data
= MT_CLS_NSMU
,
1576 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1577 USB_DEVICE_ID_XIROKU_MPX1
) },
1578 { .driver_data
= MT_CLS_NSMU
,
1579 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1580 USB_DEVICE_ID_XIROKU_CSR1
) },
1581 { .driver_data
= MT_CLS_NSMU
,
1582 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1583 USB_DEVICE_ID_XIROKU_SPX2
) },
1584 { .driver_data
= MT_CLS_NSMU
,
1585 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1586 USB_DEVICE_ID_XIROKU_MPX2
) },
1587 { .driver_data
= MT_CLS_NSMU
,
1588 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1589 USB_DEVICE_ID_XIROKU_CSR2
) },
1591 /* Generic MT device */
1592 { HID_DEVICE(HID_BUS_ANY
, HID_GROUP_MULTITOUCH
, HID_ANY_ID
, HID_ANY_ID
) },
1594 /* Generic Win 8 certified MT device */
1595 { .driver_data
= MT_CLS_WIN_8
,
1596 HID_DEVICE(HID_BUS_ANY
, HID_GROUP_MULTITOUCH_WIN_8
,
1597 HID_ANY_ID
, HID_ANY_ID
) },
1600 MODULE_DEVICE_TABLE(hid
, mt_devices
);
1602 static const struct hid_usage_id mt_grabbed_usages
[] = {
1603 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
1604 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
1607 static struct hid_driver mt_driver
= {
1608 .name
= "hid-multitouch",
1609 .id_table
= mt_devices
,
1611 .remove
= mt_remove
,
1612 .input_mapping
= mt_input_mapping
,
1613 .input_mapped
= mt_input_mapped
,
1614 .input_configured
= mt_input_configured
,
1615 .feature_mapping
= mt_feature_mapping
,
1616 .usage_table
= mt_grabbed_usages
,
1618 .report
= mt_report
,
1620 .reset_resume
= mt_reset_resume
,
1621 .resume
= mt_resume
,
1624 module_hid_driver(mt_driver
);