2 * HID driver for multitouch panels
4 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
8 * This code is partly based on hid-egalax.c:
10 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
11 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
12 * Copyright (c) 2010 Canonical, Ltd.
14 * This code is partly based on hid-3m-pct.c:
16 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
17 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
18 * Copyright (c) 2010 Canonical, Ltd.
23 * This program is free software; you can redistribute it and/or modify it
24 * under the terms of the GNU General Public License as published by the Free
25 * Software Foundation; either version 2 of the License, or (at your option)
29 #include <linux/device.h>
30 #include <linux/hid.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/usb.h>
34 #include <linux/input/mt.h>
35 #include "usbhid/usbhid.h"
38 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
39 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
40 MODULE_DESCRIPTION("HID multitouch panels");
41 MODULE_LICENSE("GPL");
45 /* quirks to control the device */
46 #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
47 #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
48 #define MT_QUIRK_CYPRESS (1 << 2)
49 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
50 #define MT_QUIRK_ALWAYS_VALID (1 << 4)
51 #define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
52 #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
53 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
57 __s32 contactid
; /* the device ContactID assigned to this slot */
58 bool touch_state
; /* is the touch valid? */
59 bool seen_in_this_frame
;/* has this slot been updated */
63 __s32 name
; /* MT_CLS */
65 __s32 sn_move
; /* Signal/noise ratio for move events */
66 __s32 sn_width
; /* Signal/noise ratio for width events */
67 __s32 sn_height
; /* Signal/noise ratio for height events */
68 __s32 sn_pressure
; /* Signal/noise ratio for pressure events */
70 bool is_indirect
; /* true for touchpads */
74 struct mt_slot curdata
; /* placeholder of incoming data */
75 struct mt_class mtclass
; /* our mt device class */
76 unsigned last_field_index
; /* last field index of the report */
77 unsigned last_slot_field
; /* the last field of a slot */
78 __s8 inputmode
; /* InputMode HID feature, -1 if non-existent */
79 __s8 maxcontact_report_id
; /* Maximum Contact Number HID feature,
81 __u8 num_received
; /* how many contacts we received */
82 __u8 num_expected
; /* expected last contact index */
84 __u8 touches_by_report
; /* how many touches are present in one report:
85 * 1 means we should use a serial protocol
86 * > 1 means hybrid (multitouch) protocol */
87 bool curvalid
; /* is the current contact valid? */
88 struct mt_slot
*slots
;
91 /* classes of device behavior */
92 #define MT_CLS_DEFAULT 0x0001
94 #define MT_CLS_SERIAL 0x0002
95 #define MT_CLS_CONFIDENCE 0x0003
96 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
97 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
98 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
99 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
100 #define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
101 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
103 /* vendor specific classes */
104 #define MT_CLS_3M 0x0101
105 #define MT_CLS_CYPRESS 0x0102
106 #define MT_CLS_EGALAX 0x0103
107 #define MT_CLS_EGALAX_SERIAL 0x0104
108 #define MT_CLS_TOPSEED 0x0105
109 #define MT_CLS_PANASONIC 0x0106
111 #define MT_DEFAULT_MAXCONTACT 10
114 * these device-dependent functions determine what slot corresponds
115 * to a valid contact that was just read.
118 static int cypress_compute_slot(struct mt_device
*td
)
120 if (td
->curdata
.contactid
!= 0 || td
->num_received
== 0)
121 return td
->curdata
.contactid
;
126 static int find_slot_from_contactid(struct mt_device
*td
)
129 for (i
= 0; i
< td
->maxcontacts
; ++i
) {
130 if (td
->slots
[i
].contactid
== td
->curdata
.contactid
&&
131 td
->slots
[i
].touch_state
)
134 for (i
= 0; i
< td
->maxcontacts
; ++i
) {
135 if (!td
->slots
[i
].seen_in_this_frame
&&
136 !td
->slots
[i
].touch_state
)
139 /* should not occurs. If this happens that means
140 * that the device sent more touches that it says
141 * in the report descriptor. It is ignored then. */
145 static struct mt_class mt_classes
[] = {
146 { .name
= MT_CLS_DEFAULT
,
147 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
},
148 { .name
= MT_CLS_SERIAL
,
149 .quirks
= MT_QUIRK_ALWAYS_VALID
},
150 { .name
= MT_CLS_CONFIDENCE
,
151 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
},
152 { .name
= MT_CLS_CONFIDENCE_CONTACT_ID
,
153 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
|
154 MT_QUIRK_SLOT_IS_CONTACTID
},
155 { .name
= MT_CLS_CONFIDENCE_MINUS_ONE
,
156 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
|
157 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE
},
158 { .name
= MT_CLS_DUAL_INRANGE_CONTACTID
,
159 .quirks
= MT_QUIRK_VALID_IS_INRANGE
|
160 MT_QUIRK_SLOT_IS_CONTACTID
,
162 { .name
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
163 .quirks
= MT_QUIRK_VALID_IS_INRANGE
|
164 MT_QUIRK_SLOT_IS_CONTACTNUMBER
,
166 { .name
= MT_CLS_DUAL_NSMU_CONTACTID
,
167 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
|
168 MT_QUIRK_SLOT_IS_CONTACTID
,
170 { .name
= MT_CLS_INRANGE_CONTACTNUMBER
,
171 .quirks
= MT_QUIRK_VALID_IS_INRANGE
|
172 MT_QUIRK_SLOT_IS_CONTACTNUMBER
},
175 * vendor specific classes
178 .quirks
= MT_QUIRK_VALID_IS_CONFIDENCE
|
179 MT_QUIRK_SLOT_IS_CONTACTID
,
183 { .name
= MT_CLS_CYPRESS
,
184 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
|
187 { .name
= MT_CLS_EGALAX
,
188 .quirks
= MT_QUIRK_SLOT_IS_CONTACTID
|
189 MT_QUIRK_VALID_IS_INRANGE
,
193 { .name
= MT_CLS_EGALAX_SERIAL
,
194 .quirks
= MT_QUIRK_SLOT_IS_CONTACTID
|
195 MT_QUIRK_ALWAYS_VALID
,
199 { .name
= MT_CLS_TOPSEED
,
200 .quirks
= MT_QUIRK_ALWAYS_VALID
,
204 { .name
= MT_CLS_PANASONIC
,
205 .quirks
= MT_QUIRK_NOT_SEEN_MEANS_UP
,
211 static ssize_t
mt_show_quirks(struct device
*dev
,
212 struct device_attribute
*attr
,
215 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
216 struct mt_device
*td
= hid_get_drvdata(hdev
);
218 return sprintf(buf
, "%u\n", td
->mtclass
.quirks
);
221 static ssize_t
mt_set_quirks(struct device
*dev
,
222 struct device_attribute
*attr
,
223 const char *buf
, size_t count
)
225 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
226 struct mt_device
*td
= hid_get_drvdata(hdev
);
230 if (kstrtoul(buf
, 0, &val
))
233 td
->mtclass
.quirks
= val
;
238 static DEVICE_ATTR(quirks
, S_IWUSR
| S_IRUGO
, mt_show_quirks
, mt_set_quirks
);
240 static struct attribute
*sysfs_attrs
[] = {
241 &dev_attr_quirks
.attr
,
245 static struct attribute_group mt_attribute_group
= {
249 static void mt_feature_mapping(struct hid_device
*hdev
,
250 struct hid_field
*field
, struct hid_usage
*usage
)
252 struct mt_device
*td
= hid_get_drvdata(hdev
);
254 switch (usage
->hid
) {
255 case HID_DG_INPUTMODE
:
256 td
->inputmode
= field
->report
->id
;
258 case HID_DG_CONTACTMAX
:
259 td
->maxcontact_report_id
= field
->report
->id
;
260 td
->maxcontacts
= field
->value
[0];
261 if (td
->mtclass
.maxcontacts
)
262 /* check if the maxcontacts is given by the class */
263 td
->maxcontacts
= td
->mtclass
.maxcontacts
;
269 static void set_abs(struct input_dev
*input
, unsigned int code
,
270 struct hid_field
*field
, int snratio
)
272 int fmin
= field
->logical_minimum
;
273 int fmax
= field
->logical_maximum
;
274 int fuzz
= snratio
? (fmax
- fmin
) / snratio
: 0;
275 input_set_abs_params(input
, code
, fmin
, fmax
, fuzz
, 0);
278 static void set_last_slot_field(struct hid_usage
*usage
, struct mt_device
*td
,
279 struct hid_input
*hi
)
281 if (!test_bit(usage
->hid
, hi
->input
->absbit
))
282 td
->last_slot_field
= usage
->hid
;
285 static int mt_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
286 struct hid_field
*field
, struct hid_usage
*usage
,
287 unsigned long **bit
, int *max
)
289 struct mt_device
*td
= hid_get_drvdata(hdev
);
290 struct mt_class
*cls
= &td
->mtclass
;
293 /* Only map fields from TouchScreen or TouchPad collections.
294 * We need to ignore fields that belong to other collections
295 * such as Mouse that might have the same GenericDesktop usages. */
296 if (field
->application
== HID_DG_TOUCHSCREEN
)
297 set_bit(INPUT_PROP_DIRECT
, hi
->input
->propbit
);
298 else if (field
->application
!= HID_DG_TOUCHPAD
)
301 /* In case of an indirect device (touchpad), we need to add
302 * specific BTN_TOOL_* to be handled by the synaptics xorg
304 * We also consider that touchscreens providing buttons are touchpads.
306 if (field
->application
== HID_DG_TOUCHPAD
||
307 (usage
->hid
& HID_USAGE_PAGE
) == HID_UP_BUTTON
||
309 set_bit(INPUT_PROP_POINTER
, hi
->input
->propbit
);
310 set_bit(BTN_TOOL_FINGER
, hi
->input
->keybit
);
311 set_bit(BTN_TOOL_DOUBLETAP
, hi
->input
->keybit
);
312 set_bit(BTN_TOOL_TRIPLETAP
, hi
->input
->keybit
);
313 set_bit(BTN_TOOL_QUADTAP
, hi
->input
->keybit
);
316 /* eGalax devices provide a Digitizer.Stylus input which overrides
317 * the correct Digitizers.Finger X/Y ranges.
318 * Let's just ignore this input. */
319 if (field
->physical
== HID_DG_STYLUS
)
322 switch (usage
->hid
& HID_USAGE_PAGE
) {
325 switch (usage
->hid
) {
327 hid_map_usage(hi
, usage
, bit
, max
,
328 EV_ABS
, ABS_MT_POSITION_X
);
329 set_abs(hi
->input
, ABS_MT_POSITION_X
, field
,
331 /* touchscreen emulation */
332 set_abs(hi
->input
, ABS_X
, field
, cls
->sn_move
);
333 set_last_slot_field(usage
, td
, hi
);
334 td
->last_field_index
= field
->index
;
337 hid_map_usage(hi
, usage
, bit
, max
,
338 EV_ABS
, ABS_MT_POSITION_Y
);
339 set_abs(hi
->input
, ABS_MT_POSITION_Y
, field
,
341 /* touchscreen emulation */
342 set_abs(hi
->input
, ABS_Y
, field
, cls
->sn_move
);
343 set_last_slot_field(usage
, td
, hi
);
344 td
->last_field_index
= field
->index
;
349 case HID_UP_DIGITIZER
:
350 switch (usage
->hid
) {
352 set_last_slot_field(usage
, td
, hi
);
353 td
->last_field_index
= field
->index
;
355 case HID_DG_CONFIDENCE
:
356 set_last_slot_field(usage
, td
, hi
);
357 td
->last_field_index
= field
->index
;
359 case HID_DG_TIPSWITCH
:
360 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, BTN_TOUCH
);
361 input_set_capability(hi
->input
, EV_KEY
, BTN_TOUCH
);
362 set_last_slot_field(usage
, td
, hi
);
363 td
->last_field_index
= field
->index
;
365 case HID_DG_CONTACTID
:
366 if (!td
->maxcontacts
)
367 td
->maxcontacts
= MT_DEFAULT_MAXCONTACT
;
368 input_mt_init_slots(hi
->input
, td
->maxcontacts
);
369 td
->last_slot_field
= usage
->hid
;
370 td
->last_field_index
= field
->index
;
371 td
->touches_by_report
++;
374 hid_map_usage(hi
, usage
, bit
, max
,
375 EV_ABS
, ABS_MT_TOUCH_MAJOR
);
376 set_abs(hi
->input
, ABS_MT_TOUCH_MAJOR
, field
,
378 set_last_slot_field(usage
, td
, hi
);
379 td
->last_field_index
= field
->index
;
382 hid_map_usage(hi
, usage
, bit
, max
,
383 EV_ABS
, ABS_MT_TOUCH_MINOR
);
384 set_abs(hi
->input
, ABS_MT_TOUCH_MINOR
, field
,
386 input_set_abs_params(hi
->input
,
387 ABS_MT_ORIENTATION
, 0, 1, 0, 0);
388 set_last_slot_field(usage
, td
, hi
);
389 td
->last_field_index
= field
->index
;
391 case HID_DG_TIPPRESSURE
:
392 hid_map_usage(hi
, usage
, bit
, max
,
393 EV_ABS
, ABS_MT_PRESSURE
);
394 set_abs(hi
->input
, ABS_MT_PRESSURE
, field
,
396 /* touchscreen emulation */
397 set_abs(hi
->input
, ABS_PRESSURE
, field
,
399 set_last_slot_field(usage
, td
, hi
);
400 td
->last_field_index
= field
->index
;
402 case HID_DG_CONTACTCOUNT
:
403 td
->last_field_index
= field
->index
;
405 case HID_DG_CONTACTMAX
:
406 /* we don't set td->last_slot_field as contactcount and
407 * contact max are global to the report */
408 td
->last_field_index
= field
->index
;
412 /* Legacy devices use TIPSWITCH and not TOUCH.
413 * Let's just ignore this field. */
415 /* let hid-input decide for the others */
419 code
= BTN_MOUSE
+ ((usage
->hid
- 1) & HID_USAGE
);
420 hid_map_usage(hi
, usage
, bit
, max
, EV_KEY
, code
);
421 input_set_capability(hi
->input
, EV_KEY
, code
);
425 /* we do not want to map these: no input-oriented meaning */
432 static int mt_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
433 struct hid_field
*field
, struct hid_usage
*usage
,
434 unsigned long **bit
, int *max
)
436 if (usage
->type
== EV_KEY
|| usage
->type
== EV_ABS
)
437 set_bit(usage
->type
, hi
->input
->evbit
);
442 static int mt_compute_slot(struct mt_device
*td
)
444 __s32 quirks
= td
->mtclass
.quirks
;
446 if (quirks
& MT_QUIRK_SLOT_IS_CONTACTID
)
447 return td
->curdata
.contactid
;
449 if (quirks
& MT_QUIRK_CYPRESS
)
450 return cypress_compute_slot(td
);
452 if (quirks
& MT_QUIRK_SLOT_IS_CONTACTNUMBER
)
453 return td
->num_received
;
455 if (quirks
& MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE
)
456 return td
->curdata
.contactid
- 1;
458 return find_slot_from_contactid(td
);
462 * this function is called when a whole contact has been processed,
463 * so that it can assign it to a slot and store the data there
465 static void mt_complete_slot(struct mt_device
*td
)
467 td
->curdata
.seen_in_this_frame
= true;
469 int slotnum
= mt_compute_slot(td
);
471 if (slotnum
>= 0 && slotnum
< td
->maxcontacts
)
472 td
->slots
[slotnum
] = td
->curdata
;
479 * this function is called when a whole packet has been received and processed,
480 * so that it can decide what to send to the input layer.
482 static void mt_emit_event(struct mt_device
*td
, struct input_dev
*input
)
486 for (i
= 0; i
< td
->maxcontacts
; ++i
) {
487 struct mt_slot
*s
= &(td
->slots
[i
]);
488 if ((td
->mtclass
.quirks
& MT_QUIRK_NOT_SEEN_MEANS_UP
) &&
489 !s
->seen_in_this_frame
) {
490 s
->touch_state
= false;
493 input_mt_slot(input
, i
);
494 input_mt_report_slot_state(input
, MT_TOOL_FINGER
,
496 if (s
->touch_state
) {
497 /* this finger is on the screen */
498 int wide
= (s
->w
> s
->h
);
499 /* divided by two to match visual scale of touch */
500 int major
= max(s
->w
, s
->h
) >> 1;
501 int minor
= min(s
->w
, s
->h
) >> 1;
503 input_event(input
, EV_ABS
, ABS_MT_POSITION_X
, s
->x
);
504 input_event(input
, EV_ABS
, ABS_MT_POSITION_Y
, s
->y
);
505 input_event(input
, EV_ABS
, ABS_MT_ORIENTATION
, wide
);
506 input_event(input
, EV_ABS
, ABS_MT_PRESSURE
, s
->p
);
507 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MAJOR
, major
);
508 input_event(input
, EV_ABS
, ABS_MT_TOUCH_MINOR
, minor
);
510 s
->seen_in_this_frame
= false;
514 input_mt_report_pointer_emulation(input
, true);
516 td
->num_received
= 0;
521 static int mt_event(struct hid_device
*hid
, struct hid_field
*field
,
522 struct hid_usage
*usage
, __s32 value
)
524 struct mt_device
*td
= hid_get_drvdata(hid
);
525 __s32 quirks
= td
->mtclass
.quirks
;
527 if (hid
->claimed
& HID_CLAIMED_INPUT
&& td
->slots
) {
528 switch (usage
->hid
) {
530 if (quirks
& MT_QUIRK_ALWAYS_VALID
)
532 else if (quirks
& MT_QUIRK_VALID_IS_INRANGE
)
533 td
->curvalid
= value
;
535 case HID_DG_TIPSWITCH
:
536 if (quirks
& MT_QUIRK_NOT_SEEN_MEANS_UP
)
537 td
->curvalid
= value
;
538 td
->curdata
.touch_state
= value
;
540 case HID_DG_CONFIDENCE
:
541 if (quirks
& MT_QUIRK_VALID_IS_CONFIDENCE
)
542 td
->curvalid
= value
;
544 case HID_DG_CONTACTID
:
545 td
->curdata
.contactid
= value
;
547 case HID_DG_TIPPRESSURE
:
548 td
->curdata
.p
= value
;
551 td
->curdata
.x
= value
;
554 td
->curdata
.y
= value
;
557 td
->curdata
.w
= value
;
560 td
->curdata
.h
= value
;
562 case HID_DG_CONTACTCOUNT
:
564 * Includes multi-packet support where subsequent
565 * packets are sent with zero contactcount.
568 td
->num_expected
= value
;
575 /* fallback to the generic hidinput handling */
579 if (usage
->hid
== td
->last_slot_field
)
580 mt_complete_slot(td
);
582 if (field
->index
== td
->last_field_index
583 && td
->num_received
>= td
->num_expected
)
584 mt_emit_event(td
, field
->hidinput
->input
);
588 /* we have handled the hidinput part, now remains hiddev */
589 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& hid
->hiddev_hid_event
)
590 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
595 static void mt_set_input_mode(struct hid_device
*hdev
)
597 struct mt_device
*td
= hid_get_drvdata(hdev
);
598 struct hid_report
*r
;
599 struct hid_report_enum
*re
;
601 if (td
->inputmode
< 0)
604 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
605 r
= re
->report_id_hash
[td
->inputmode
];
607 r
->field
[0]->value
[0] = 0x02;
608 usbhid_submit_report(hdev
, r
, USB_DIR_OUT
);
612 static void mt_set_maxcontacts(struct hid_device
*hdev
)
614 struct mt_device
*td
= hid_get_drvdata(hdev
);
615 struct hid_report
*r
;
616 struct hid_report_enum
*re
;
619 if (td
->maxcontact_report_id
< 0)
622 if (!td
->mtclass
.maxcontacts
)
625 re
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
626 r
= re
->report_id_hash
[td
->maxcontact_report_id
];
628 max
= td
->mtclass
.maxcontacts
;
629 fieldmax
= r
->field
[0]->logical_maximum
;
630 max
= min(fieldmax
, max
);
631 if (r
->field
[0]->value
[0] != max
) {
632 r
->field
[0]->value
[0] = max
;
633 usbhid_submit_report(hdev
, r
, USB_DIR_OUT
);
638 static int mt_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
641 struct mt_device
*td
;
642 struct mt_class
*mtclass
= mt_classes
; /* MT_CLS_DEFAULT */
645 for (i
= 0; mt_classes
[i
].name
; i
++) {
646 if (id
->driver_data
== mt_classes
[i
].name
) {
647 mtclass
= &(mt_classes
[i
]);
653 /* This allows the driver to correctly support devices
654 * that emit events over several HID messages.
656 hdev
->quirks
|= HID_QUIRK_NO_INPUT_SYNC
;
657 hdev
->quirks
&= ~HID_QUIRK_MULTITOUCH
;
659 td
= kzalloc(sizeof(struct mt_device
), GFP_KERNEL
);
661 dev_err(&hdev
->dev
, "cannot allocate multitouch data\n");
664 td
->mtclass
= *mtclass
;
666 td
->maxcontact_report_id
= -1;
667 hid_set_drvdata(hdev
, td
);
669 ret
= hid_parse(hdev
);
673 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
677 if (!id
&& td
->touches_by_report
== 1) {
678 /* the device has been sent by hid-generic */
679 mtclass
= &td
->mtclass
;
680 mtclass
->quirks
|= MT_QUIRK_ALWAYS_VALID
;
681 mtclass
->quirks
&= ~MT_QUIRK_NOT_SEEN_MEANS_UP
;
682 mtclass
->quirks
&= ~MT_QUIRK_VALID_IS_INRANGE
;
683 mtclass
->quirks
&= ~MT_QUIRK_VALID_IS_CONFIDENCE
;
686 td
->slots
= kzalloc(td
->maxcontacts
* sizeof(struct mt_slot
),
689 dev_err(&hdev
->dev
, "cannot allocate multitouch slots\n");
695 ret
= sysfs_create_group(&hdev
->dev
.kobj
, &mt_attribute_group
);
697 mt_set_maxcontacts(hdev
);
698 mt_set_input_mode(hdev
);
708 static int mt_reset_resume(struct hid_device
*hdev
)
710 mt_set_maxcontacts(hdev
);
711 mt_set_input_mode(hdev
);
716 static void mt_remove(struct hid_device
*hdev
)
718 struct mt_device
*td
= hid_get_drvdata(hdev
);
719 sysfs_remove_group(&hdev
->dev
.kobj
, &mt_attribute_group
);
723 hid_set_drvdata(hdev
, NULL
);
726 static const struct hid_device_id mt_devices
[] = {
729 { .driver_data
= MT_CLS_3M
,
730 HID_USB_DEVICE(USB_VENDOR_ID_3M
,
731 USB_DEVICE_ID_3M1968
) },
732 { .driver_data
= MT_CLS_3M
,
733 HID_USB_DEVICE(USB_VENDOR_ID_3M
,
734 USB_DEVICE_ID_3M2256
) },
735 { .driver_data
= MT_CLS_3M
,
736 HID_USB_DEVICE(USB_VENDOR_ID_3M
,
737 USB_DEVICE_ID_3M3266
) },
739 /* ActionStar panels */
740 { .driver_data
= MT_CLS_DEFAULT
,
741 HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR
,
742 USB_DEVICE_ID_ACTIONSTAR_1011
) },
745 { .driver_data
= MT_CLS_SERIAL
,
746 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL
,
747 USB_DEVICE_ID_ATMEL_MULTITOUCH
) },
748 { .driver_data
= MT_CLS_SERIAL
,
749 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL
,
750 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER
) },
753 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
754 HID_USB_DEVICE(USB_VENDOR_ID_CANDO
,
755 USB_DEVICE_ID_CANDO_MULTI_TOUCH
) },
756 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
757 HID_USB_DEVICE(USB_VENDOR_ID_CANDO
,
758 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1
) },
759 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
760 HID_USB_DEVICE(USB_VENDOR_ID_CANDO
,
761 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6
) },
762 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
763 HID_USB_DEVICE(USB_VENDOR_ID_CANDO
,
764 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6
) },
766 /* Chunghwa Telecom touch panels */
767 { .driver_data
= MT_CLS_DEFAULT
,
768 HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT
,
769 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH
) },
772 { .driver_data
= MT_CLS_DEFAULT
,
773 HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH
,
774 USB_DEVICE_ID_CVTOUCH_SCREEN
) },
777 { .driver_data
= MT_CLS_CYPRESS
,
778 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
,
779 USB_DEVICE_ID_CYPRESS_TRUETOUCH
) },
781 /* eGalax devices (resistive) */
782 { .driver_data
= MT_CLS_EGALAX
,
783 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
784 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D
) },
785 { .driver_data
= MT_CLS_EGALAX
,
786 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
787 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E
) },
789 /* eGalax devices (capacitive) */
790 { .driver_data
= MT_CLS_EGALAX
,
791 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
792 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C
) },
793 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
794 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
795 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207
) },
796 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
797 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
798 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E
) },
799 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
800 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
801 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224
) },
802 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
803 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
804 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A
) },
805 { .driver_data
= MT_CLS_EGALAX
,
806 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
807 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B
) },
808 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
809 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
810 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262
) },
811 { .driver_data
= MT_CLS_EGALAX
,
812 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
813 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1
) },
814 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
815 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
816 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA
) },
817 { .driver_data
= MT_CLS_EGALAX
,
818 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
819 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA
) },
820 { .driver_data
= MT_CLS_EGALAX
,
821 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
822 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302
) },
823 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
824 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
825 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349
) },
826 { .driver_data
= MT_CLS_EGALAX_SERIAL
,
827 HID_USB_DEVICE(USB_VENDOR_ID_DWAV
,
828 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001
) },
830 /* Elo TouchSystems IntelliTouch Plus panel */
831 { .driver_data
= MT_CLS_DUAL_NSMU_CONTACTID
,
832 HID_USB_DEVICE(USB_VENDOR_ID_ELO
,
833 USB_DEVICE_ID_ELO_TS2515
) },
835 /* GeneralTouch panel */
836 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTNUMBER
,
837 HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
,
838 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS
) },
840 /* Gametel game controller */
841 { .driver_data
= MT_CLS_DEFAULT
,
842 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_FRUCTEL
,
843 USB_DEVICE_ID_GAMETEL_MT_MODE
) },
845 /* GoodTouch panels */
846 { .driver_data
= MT_CLS_DEFAULT
,
847 HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH
,
848 USB_DEVICE_ID_GOODTOUCH_000f
) },
851 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTID
,
852 HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT
,
853 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH
) },
856 { .driver_data
= MT_CLS_SERIAL
,
857 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM
,
858 USB_DEVICE_ID_IDEACOM_IDC6650
) },
859 { .driver_data
= MT_CLS_SERIAL
,
860 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM
,
861 USB_DEVICE_ID_IDEACOM_IDC6651
) },
863 /* Ilitek dual touch panel */
864 { .driver_data
= MT_CLS_DEFAULT
,
865 HID_USB_DEVICE(USB_VENDOR_ID_ILITEK
,
866 USB_DEVICE_ID_ILITEK_MULTITOUCH
) },
869 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTID
,
870 HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS
,
871 USB_DEVICE_ID_IRTOUCH_INFRARED_USB
) },
873 /* LG Display panels */
874 { .driver_data
= MT_CLS_DEFAULT
,
875 HID_USB_DEVICE(USB_VENDOR_ID_LG
,
876 USB_DEVICE_ID_LG_MULTITOUCH
) },
879 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
880 HID_USB_DEVICE(USB_VENDOR_ID_LUMIO
,
881 USB_DEVICE_ID_CRYSTALTOUCH
) },
882 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
883 HID_USB_DEVICE(USB_VENDOR_ID_LUMIO
,
884 USB_DEVICE_ID_CRYSTALTOUCH_DUAL
) },
887 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
888 HID_USB_DEVICE(USB_VENDOR_ID_ASUS
,
889 USB_DEVICE_ID_ASUS_T91MT
)},
890 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
891 HID_USB_DEVICE(USB_VENDOR_ID_ASUS
,
892 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO
) },
893 { .driver_data
= MT_CLS_CONFIDENCE_MINUS_ONE
,
894 HID_USB_DEVICE(USB_VENDOR_ID_TURBOX
,
895 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART
) },
897 /* Panasonic panels */
898 { .driver_data
= MT_CLS_PANASONIC
,
899 HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC
,
900 USB_DEVICE_ID_PANABOARD_UBT780
) },
901 { .driver_data
= MT_CLS_PANASONIC
,
902 HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC
,
903 USB_DEVICE_ID_PANABOARD_UBT880
) },
905 /* PenMount panels */
906 { .driver_data
= MT_CLS_CONFIDENCE
,
907 HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT
,
908 USB_DEVICE_ID_PENMOUNT_PCI
) },
910 /* PixArt optical touch screen */
911 { .driver_data
= MT_CLS_INRANGE_CONTACTNUMBER
,
912 HID_USB_DEVICE(USB_VENDOR_ID_PIXART
,
913 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN
) },
914 { .driver_data
= MT_CLS_INRANGE_CONTACTNUMBER
,
915 HID_USB_DEVICE(USB_VENDOR_ID_PIXART
,
916 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1
) },
917 { .driver_data
= MT_CLS_INRANGE_CONTACTNUMBER
,
918 HID_USB_DEVICE(USB_VENDOR_ID_PIXART
,
919 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2
) },
921 /* PixCir-based panels */
922 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTID
,
923 HID_USB_DEVICE(USB_VENDOR_ID_HANVON
,
924 USB_DEVICE_ID_HANVON_MULTITOUCH
) },
925 { .driver_data
= MT_CLS_DUAL_INRANGE_CONTACTID
,
926 HID_USB_DEVICE(USB_VENDOR_ID_CANDO
,
927 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH
) },
929 /* Quanta-based panels */
930 { .driver_data
= MT_CLS_CONFIDENCE_CONTACT_ID
,
931 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA
,
932 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH
) },
933 { .driver_data
= MT_CLS_CONFIDENCE_CONTACT_ID
,
934 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA
,
935 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001
) },
936 { .driver_data
= MT_CLS_CONFIDENCE_CONTACT_ID
,
937 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA
,
938 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008
) },
941 { .driver_data
= MT_CLS_CONFIDENCE
,
942 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM
,
944 { .driver_data
= MT_CLS_CONFIDENCE
,
945 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM
,
946 USB_DEVICE_ID_MTP_STM
)},
947 { .driver_data
= MT_CLS_CONFIDENCE
,
948 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX
,
949 USB_DEVICE_ID_MTP_SITRONIX
)},
952 { .driver_data
= MT_CLS_TOPSEED
,
953 HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2
,
954 USB_DEVICE_ID_TOPSEED2_PERIPAD_701
) },
956 /* Touch International panels */
957 { .driver_data
= MT_CLS_DEFAULT
,
958 HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL
,
959 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH
) },
962 { .driver_data
= MT_CLS_DEFAULT
,
963 HID_USB_DEVICE(USB_VENDOR_ID_UNITEC
,
964 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709
) },
965 { .driver_data
= MT_CLS_DEFAULT
,
966 HID_USB_DEVICE(USB_VENDOR_ID_UNITEC
,
967 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19
) },
969 { .driver_data
= MT_CLS_DEFAULT
,
970 HID_USB_DEVICE(USB_VENDOR_ID_XAT
,
971 USB_DEVICE_ID_XAT_CSR
) },
974 { .driver_data
= MT_CLS_DEFAULT
,
975 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
976 USB_DEVICE_ID_XIROKU_SPX
) },
977 { .driver_data
= MT_CLS_DEFAULT
,
978 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
979 USB_DEVICE_ID_XIROKU_MPX
) },
980 { .driver_data
= MT_CLS_DEFAULT
,
981 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
982 USB_DEVICE_ID_XIROKU_CSR
) },
983 { .driver_data
= MT_CLS_DEFAULT
,
984 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
985 USB_DEVICE_ID_XIROKU_SPX1
) },
986 { .driver_data
= MT_CLS_DEFAULT
,
987 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
988 USB_DEVICE_ID_XIROKU_MPX1
) },
989 { .driver_data
= MT_CLS_DEFAULT
,
990 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
991 USB_DEVICE_ID_XIROKU_CSR1
) },
992 { .driver_data
= MT_CLS_DEFAULT
,
993 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
994 USB_DEVICE_ID_XIROKU_SPX2
) },
995 { .driver_data
= MT_CLS_DEFAULT
,
996 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
997 USB_DEVICE_ID_XIROKU_MPX2
) },
998 { .driver_data
= MT_CLS_DEFAULT
,
999 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU
,
1000 USB_DEVICE_ID_XIROKU_CSR2
) },
1004 MODULE_DEVICE_TABLE(hid
, mt_devices
);
1006 static const struct hid_usage_id mt_grabbed_usages
[] = {
1007 { HID_ANY_ID
, HID_ANY_ID
, HID_ANY_ID
},
1008 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
1011 static struct hid_driver mt_driver
= {
1012 .name
= "hid-multitouch",
1013 .id_table
= mt_devices
,
1015 .remove
= mt_remove
,
1016 .input_mapping
= mt_input_mapping
,
1017 .input_mapped
= mt_input_mapped
,
1018 .feature_mapping
= mt_feature_mapping
,
1019 .usage_table
= mt_grabbed_usages
,
1022 .reset_resume
= mt_reset_resume
,
1026 static int __init
mt_init(void)
1028 return hid_register_driver(&mt_driver
);
1031 static void __exit
mt_exit(void)
1033 hid_unregister_driver(&mt_driver
);
1036 module_init(mt_init
);
1037 module_exit(mt_exit
);