mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / hid / hid-multitouch.c
blob0ffc0a4d5182550959dc95de267a8fc8530ec452
1 /*
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)
27 * any later version.
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/usb.h>
46 #include <linux/input/mt.h>
47 #include <linux/string.h>
50 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
51 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
52 MODULE_DESCRIPTION("HID multitouch panels");
53 MODULE_LICENSE("GPL");
55 #include "hid-ids.h"
57 /* quirks to control the device */
58 #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
59 #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
60 #define MT_QUIRK_CYPRESS (1 << 2)
61 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
62 #define MT_QUIRK_ALWAYS_VALID (1 << 4)
63 #define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
64 #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
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)
71 #define MT_INPUTMODE_TOUCHSCREEN 0x02
72 #define MT_INPUTMODE_TOUCHPAD 0x03
74 struct mt_slot {
75 __s32 x, y, cx, cy, p, w, h;
76 __s32 contactid; /* the device ContactID assigned to this slot */
77 bool touch_state; /* is the touch valid? */
78 bool inrange_state; /* is the finger in proximity of the sensor? */
81 struct mt_class {
82 __s32 name; /* MT_CLS */
83 __s32 quirks;
84 __s32 sn_move; /* Signal/noise ratio for move events */
85 __s32 sn_width; /* Signal/noise ratio for width events */
86 __s32 sn_height; /* Signal/noise ratio for height events */
87 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
88 __u8 maxcontacts;
89 bool is_indirect; /* true for touchpads */
92 struct mt_fields {
93 unsigned usages[HID_MAX_FIELDS];
94 unsigned int length;
97 struct mt_device {
98 struct mt_slot curdata; /* placeholder of incoming data */
99 struct mt_class mtclass; /* our mt device class */
100 struct mt_fields *fields; /* temporary placeholder for storing the
101 multitouch fields */
102 int cc_index; /* contact count field index in the report */
103 int cc_value_index; /* contact count value index in the field */
104 unsigned last_slot_field; /* the last field of a slot */
105 unsigned mt_report_id; /* the report ID of the multitouch device */
106 unsigned pen_report_id; /* the report ID of the pen device */
107 __s16 inputmode; /* InputMode HID feature, -1 if non-existent */
108 __s16 inputmode_index; /* InputMode HID feature index in the report */
109 __s16 maxcontact_report_id; /* Maximum Contact Number HID feature,
110 -1 if non-existent */
111 __u8 inputmode_value; /* InputMode HID feature value */
112 __u8 num_received; /* how many contacts we received */
113 __u8 num_expected; /* expected last contact index */
114 __u8 maxcontacts;
115 __u8 touches_by_report; /* how many touches are present in one report:
116 * 1 means we should use a serial protocol
117 * > 1 means hybrid (multitouch) protocol */
118 bool serial_maybe; /* need to check for serial protocol */
119 bool curvalid; /* is the current contact valid? */
120 unsigned mt_flags; /* flags to pass to input-mt */
123 static void mt_post_parse_default_settings(struct mt_device *td);
124 static void mt_post_parse(struct mt_device *td);
126 /* classes of device behavior */
127 #define MT_CLS_DEFAULT 0x0001
129 #define MT_CLS_SERIAL 0x0002
130 #define MT_CLS_CONFIDENCE 0x0003
131 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
132 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
133 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
134 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
135 #define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
136 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
137 #define MT_CLS_NSMU 0x000a
138 #define MT_CLS_DUAL_CONTACT_NUMBER 0x0010
139 #define MT_CLS_DUAL_CONTACT_ID 0x0011
140 #define MT_CLS_WIN_8 0x0012
142 /* vendor specific classes */
143 #define MT_CLS_3M 0x0101
144 #define MT_CLS_CYPRESS 0x0102
145 #define MT_CLS_EGALAX 0x0103
146 #define MT_CLS_EGALAX_SERIAL 0x0104
147 #define MT_CLS_TOPSEED 0x0105
148 #define MT_CLS_PANASONIC 0x0106
149 #define MT_CLS_FLATFROG 0x0107
150 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
151 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
153 #define MT_DEFAULT_MAXCONTACT 10
154 #define MT_MAX_MAXCONTACT 250
156 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
157 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
160 * these device-dependent functions determine what slot corresponds
161 * to a valid contact that was just read.
164 static int cypress_compute_slot(struct mt_device *td)
166 if (td->curdata.contactid != 0 || td->num_received == 0)
167 return td->curdata.contactid;
168 else
169 return -1;
172 static struct mt_class mt_classes[] = {
173 { .name = MT_CLS_DEFAULT,
174 .quirks = MT_QUIRK_ALWAYS_VALID |
175 MT_QUIRK_CONTACT_CNT_ACCURATE },
176 { .name = MT_CLS_NSMU,
177 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
178 { .name = MT_CLS_SERIAL,
179 .quirks = MT_QUIRK_ALWAYS_VALID},
180 { .name = MT_CLS_CONFIDENCE,
181 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
182 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
183 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
184 MT_QUIRK_SLOT_IS_CONTACTID },
185 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
186 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
187 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
188 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
189 .quirks = MT_QUIRK_VALID_IS_INRANGE |
190 MT_QUIRK_SLOT_IS_CONTACTID,
191 .maxcontacts = 2 },
192 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
193 .quirks = MT_QUIRK_VALID_IS_INRANGE |
194 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
195 .maxcontacts = 2 },
196 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
197 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
198 MT_QUIRK_SLOT_IS_CONTACTID,
199 .maxcontacts = 2 },
200 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
201 .quirks = MT_QUIRK_VALID_IS_INRANGE |
202 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
203 { .name = MT_CLS_DUAL_CONTACT_NUMBER,
204 .quirks = MT_QUIRK_ALWAYS_VALID |
205 MT_QUIRK_CONTACT_CNT_ACCURATE |
206 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
207 .maxcontacts = 2 },
208 { .name = MT_CLS_DUAL_CONTACT_ID,
209 .quirks = MT_QUIRK_ALWAYS_VALID |
210 MT_QUIRK_CONTACT_CNT_ACCURATE |
211 MT_QUIRK_SLOT_IS_CONTACTID,
212 .maxcontacts = 2 },
213 { .name = MT_CLS_WIN_8,
214 .quirks = MT_QUIRK_ALWAYS_VALID |
215 MT_QUIRK_IGNORE_DUPLICATES |
216 MT_QUIRK_HOVERING |
217 MT_QUIRK_CONTACT_CNT_ACCURATE },
220 * vendor specific classes
222 { .name = MT_CLS_3M,
223 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
224 MT_QUIRK_SLOT_IS_CONTACTID,
225 .sn_move = 2048,
226 .sn_width = 128,
227 .sn_height = 128,
228 .maxcontacts = 60,
230 { .name = MT_CLS_CYPRESS,
231 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
232 MT_QUIRK_CYPRESS,
233 .maxcontacts = 10 },
234 { .name = MT_CLS_EGALAX,
235 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
236 MT_QUIRK_VALID_IS_INRANGE,
237 .sn_move = 4096,
238 .sn_pressure = 32,
240 { .name = MT_CLS_EGALAX_SERIAL,
241 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
242 MT_QUIRK_ALWAYS_VALID,
243 .sn_move = 4096,
244 .sn_pressure = 32,
246 { .name = MT_CLS_TOPSEED,
247 .quirks = MT_QUIRK_ALWAYS_VALID,
248 .is_indirect = true,
249 .maxcontacts = 2,
251 { .name = MT_CLS_PANASONIC,
252 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
253 .maxcontacts = 4 },
254 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
255 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
256 MT_QUIRK_VALID_IS_INRANGE |
257 MT_QUIRK_SLOT_IS_CONTACTID,
258 .maxcontacts = 2
260 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
261 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
262 MT_QUIRK_SLOT_IS_CONTACTID
265 { .name = MT_CLS_FLATFROG,
266 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
267 MT_QUIRK_NO_AREA,
268 .sn_move = 2048,
269 .maxcontacts = 40,
274 static ssize_t mt_show_quirks(struct device *dev,
275 struct device_attribute *attr,
276 char *buf)
278 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
279 struct mt_device *td = hid_get_drvdata(hdev);
281 return sprintf(buf, "%u\n", td->mtclass.quirks);
284 static ssize_t mt_set_quirks(struct device *dev,
285 struct device_attribute *attr,
286 const char *buf, size_t count)
288 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
289 struct mt_device *td = hid_get_drvdata(hdev);
291 unsigned long val;
293 if (kstrtoul(buf, 0, &val))
294 return -EINVAL;
296 td->mtclass.quirks = val;
298 if (td->cc_index < 0)
299 td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
301 return count;
304 static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
306 static struct attribute *sysfs_attrs[] = {
307 &dev_attr_quirks.attr,
308 NULL
311 static struct attribute_group mt_attribute_group = {
312 .attrs = sysfs_attrs
315 static void mt_feature_mapping(struct hid_device *hdev,
316 struct hid_field *field, struct hid_usage *usage)
318 struct mt_device *td = hid_get_drvdata(hdev);
320 switch (usage->hid) {
321 case HID_DG_INPUTMODE:
322 /* Ignore if value index is out of bounds. */
323 if (usage->usage_index >= field->report_count) {
324 dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
325 break;
328 td->inputmode = field->report->id;
329 td->inputmode_index = usage->usage_index;
331 break;
332 case HID_DG_CONTACTMAX:
333 td->maxcontact_report_id = field->report->id;
334 td->maxcontacts = field->value[0];
335 if (!td->maxcontacts &&
336 field->logical_maximum <= MT_MAX_MAXCONTACT)
337 td->maxcontacts = field->logical_maximum;
338 if (td->mtclass.maxcontacts)
339 /* check if the maxcontacts is given by the class */
340 td->maxcontacts = td->mtclass.maxcontacts;
342 break;
346 static void set_abs(struct input_dev *input, unsigned int code,
347 struct hid_field *field, int snratio)
349 int fmin = field->logical_minimum;
350 int fmax = field->logical_maximum;
351 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
352 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
353 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
356 static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
357 struct hid_input *hi)
359 struct mt_fields *f = td->fields;
361 if (f->length >= HID_MAX_FIELDS)
362 return;
364 f->usages[f->length++] = usage->hid;
367 static int mt_pen_input_mapping(struct hid_device *hdev, struct hid_input *hi,
368 struct hid_field *field, struct hid_usage *usage,
369 unsigned long **bit, int *max)
371 struct mt_device *td = hid_get_drvdata(hdev);
373 td->pen_report_id = field->report->id;
375 return 0;
378 static int mt_pen_input_mapped(struct hid_device *hdev, struct hid_input *hi,
379 struct hid_field *field, struct hid_usage *usage,
380 unsigned long **bit, int *max)
382 return 0;
385 static int mt_pen_event(struct hid_device *hid, struct hid_field *field,
386 struct hid_usage *usage, __s32 value)
388 /* let hid-input handle it */
389 return 0;
392 static void mt_pen_report(struct hid_device *hid, struct hid_report *report)
394 struct hid_field *field = report->field[0];
396 input_sync(field->hidinput->input);
399 static void mt_pen_input_configured(struct hid_device *hdev,
400 struct hid_input *hi)
402 /* force BTN_STYLUS to allow tablet matching in udev */
403 __set_bit(BTN_STYLUS, hi->input->keybit);
406 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
407 struct hid_field *field, struct hid_usage *usage,
408 unsigned long **bit, int *max)
410 struct mt_device *td = hid_get_drvdata(hdev);
411 struct mt_class *cls = &td->mtclass;
412 int code;
413 struct hid_usage *prev_usage = NULL;
415 if (field->application == HID_DG_TOUCHSCREEN)
416 td->mt_flags |= INPUT_MT_DIRECT;
419 * Model touchscreens providing buttons as touchpads.
421 if (field->application == HID_DG_TOUCHPAD ||
422 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
423 td->mt_flags |= INPUT_MT_POINTER;
424 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
427 if (usage->usage_index)
428 prev_usage = &field->usage[usage->usage_index - 1];
430 switch (usage->hid & HID_USAGE_PAGE) {
432 case HID_UP_GENDESK:
433 switch (usage->hid) {
434 case HID_GD_X:
435 if (prev_usage && (prev_usage->hid == usage->hid)) {
436 hid_map_usage(hi, usage, bit, max,
437 EV_ABS, ABS_MT_TOOL_X);
438 set_abs(hi->input, ABS_MT_TOOL_X, field,
439 cls->sn_move);
440 } else {
441 hid_map_usage(hi, usage, bit, max,
442 EV_ABS, ABS_MT_POSITION_X);
443 set_abs(hi->input, ABS_MT_POSITION_X, field,
444 cls->sn_move);
447 mt_store_field(usage, td, hi);
448 return 1;
449 case HID_GD_Y:
450 if (prev_usage && (prev_usage->hid == usage->hid)) {
451 hid_map_usage(hi, usage, bit, max,
452 EV_ABS, ABS_MT_TOOL_Y);
453 set_abs(hi->input, ABS_MT_TOOL_Y, field,
454 cls->sn_move);
455 } else {
456 hid_map_usage(hi, usage, bit, max,
457 EV_ABS, ABS_MT_POSITION_Y);
458 set_abs(hi->input, ABS_MT_POSITION_Y, field,
459 cls->sn_move);
462 mt_store_field(usage, td, hi);
463 return 1;
465 return 0;
467 case HID_UP_DIGITIZER:
468 switch (usage->hid) {
469 case HID_DG_INRANGE:
470 if (cls->quirks & MT_QUIRK_HOVERING) {
471 hid_map_usage(hi, usage, bit, max,
472 EV_ABS, ABS_MT_DISTANCE);
473 input_set_abs_params(hi->input,
474 ABS_MT_DISTANCE, 0, 1, 0, 0);
476 mt_store_field(usage, td, hi);
477 return 1;
478 case HID_DG_CONFIDENCE:
479 mt_store_field(usage, td, hi);
480 return 1;
481 case HID_DG_TIPSWITCH:
482 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
483 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
484 mt_store_field(usage, td, hi);
485 return 1;
486 case HID_DG_CONTACTID:
487 mt_store_field(usage, td, hi);
488 td->touches_by_report++;
489 td->mt_report_id = field->report->id;
490 return 1;
491 case HID_DG_WIDTH:
492 hid_map_usage(hi, usage, bit, max,
493 EV_ABS, ABS_MT_TOUCH_MAJOR);
494 if (!(cls->quirks & MT_QUIRK_NO_AREA))
495 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
496 cls->sn_width);
497 mt_store_field(usage, td, hi);
498 return 1;
499 case HID_DG_HEIGHT:
500 hid_map_usage(hi, usage, bit, max,
501 EV_ABS, ABS_MT_TOUCH_MINOR);
502 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
503 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
504 cls->sn_height);
505 input_set_abs_params(hi->input,
506 ABS_MT_ORIENTATION, 0, 1, 0, 0);
508 mt_store_field(usage, td, hi);
509 return 1;
510 case HID_DG_TIPPRESSURE:
511 hid_map_usage(hi, usage, bit, max,
512 EV_ABS, ABS_MT_PRESSURE);
513 set_abs(hi->input, ABS_MT_PRESSURE, field,
514 cls->sn_pressure);
515 mt_store_field(usage, td, hi);
516 return 1;
517 case HID_DG_CONTACTCOUNT:
518 /* Ignore if indexes are out of bounds. */
519 if (field->index >= field->report->maxfield ||
520 usage->usage_index >= field->report_count)
521 return 1;
522 td->cc_index = field->index;
523 td->cc_value_index = usage->usage_index;
524 return 1;
525 case HID_DG_CONTACTMAX:
526 /* we don't set td->last_slot_field as contactcount and
527 * contact max are global to the report */
528 return -1;
529 case HID_DG_TOUCH:
530 /* Legacy devices use TIPSWITCH and not TOUCH.
531 * Let's just ignore this field. */
532 return -1;
534 /* let hid-input decide for the others */
535 return 0;
537 case HID_UP_BUTTON:
538 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
539 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
540 input_set_capability(hi->input, EV_KEY, code);
541 return 1;
543 case 0xff000000:
544 /* we do not want to map these: no input-oriented meaning */
545 return -1;
548 return 0;
551 static int mt_touch_input_mapped(struct hid_device *hdev, struct hid_input *hi,
552 struct hid_field *field, struct hid_usage *usage,
553 unsigned long **bit, int *max)
555 if (usage->type == EV_KEY || usage->type == EV_ABS)
556 set_bit(usage->type, hi->input->evbit);
558 return -1;
561 static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
563 __s32 quirks = td->mtclass.quirks;
565 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
566 return td->curdata.contactid;
568 if (quirks & MT_QUIRK_CYPRESS)
569 return cypress_compute_slot(td);
571 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
572 return td->num_received;
574 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
575 return td->curdata.contactid - 1;
577 return input_mt_get_slot_by_key(input, td->curdata.contactid);
581 * this function is called when a whole contact has been processed,
582 * so that it can assign it to a slot and store the data there
584 static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
586 if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
587 td->num_received >= td->num_expected)
588 return;
590 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
591 int slotnum = mt_compute_slot(td, input);
592 struct mt_slot *s = &td->curdata;
593 struct input_mt *mt = input->mt;
595 if (slotnum < 0 || slotnum >= td->maxcontacts)
596 return;
598 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
599 struct input_mt_slot *slot = &mt->slots[slotnum];
600 if (input_mt_is_active(slot) &&
601 input_mt_is_used(mt, slot))
602 return;
605 input_mt_slot(input, slotnum);
606 input_mt_report_slot_state(input, MT_TOOL_FINGER,
607 s->touch_state || s->inrange_state);
608 if (s->touch_state || s->inrange_state) {
609 /* this finger is in proximity of the sensor */
610 int wide = (s->w > s->h);
611 /* divided by two to match visual scale of touch */
612 int major = max(s->w, s->h) >> 1;
613 int minor = min(s->w, s->h) >> 1;
615 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
616 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
617 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
618 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
619 input_event(input, EV_ABS, ABS_MT_DISTANCE,
620 !s->touch_state);
621 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
622 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
623 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
624 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
628 td->num_received++;
632 * this function is called when a whole packet has been received and processed,
633 * so that it can decide what to send to the input layer.
635 static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
637 input_mt_sync_frame(input);
638 input_sync(input);
639 td->num_received = 0;
642 static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
643 struct hid_usage *usage, __s32 value)
645 /* we will handle the hidinput part later, now remains hiddev */
646 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
647 hid->hiddev_hid_event(hid, field, usage, value);
649 return 1;
652 static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
653 struct hid_usage *usage, __s32 value)
655 struct mt_device *td = hid_get_drvdata(hid);
656 __s32 quirks = td->mtclass.quirks;
657 struct input_dev *input = field->hidinput->input;
659 if (hid->claimed & HID_CLAIMED_INPUT) {
660 switch (usage->hid) {
661 case HID_DG_INRANGE:
662 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
663 td->curvalid = value;
664 if (quirks & MT_QUIRK_HOVERING)
665 td->curdata.inrange_state = value;
666 break;
667 case HID_DG_TIPSWITCH:
668 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
669 td->curvalid = value;
670 td->curdata.touch_state = value;
671 break;
672 case HID_DG_CONFIDENCE:
673 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
674 td->curvalid = value;
675 break;
676 case HID_DG_CONTACTID:
677 td->curdata.contactid = value;
678 break;
679 case HID_DG_TIPPRESSURE:
680 td->curdata.p = value;
681 break;
682 case HID_GD_X:
683 if (usage->code == ABS_MT_TOOL_X)
684 td->curdata.cx = value;
685 else
686 td->curdata.x = value;
687 break;
688 case HID_GD_Y:
689 if (usage->code == ABS_MT_TOOL_Y)
690 td->curdata.cy = value;
691 else
692 td->curdata.y = value;
693 break;
694 case HID_DG_WIDTH:
695 td->curdata.w = value;
696 break;
697 case HID_DG_HEIGHT:
698 td->curdata.h = value;
699 break;
700 case HID_DG_CONTACTCOUNT:
701 break;
702 case HID_DG_TOUCH:
703 /* do nothing */
704 break;
706 default:
707 if (usage->type)
708 input_event(input, usage->type, usage->code,
709 value);
710 return;
713 if (usage->usage_index + 1 == field->report_count) {
714 /* we only take into account the last report. */
715 if (usage->hid == td->last_slot_field)
716 mt_complete_slot(td, field->hidinput->input);
722 static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
724 struct mt_device *td = hid_get_drvdata(hid);
725 struct hid_field *field;
726 unsigned count;
727 int r, n;
730 * Includes multi-packet support where subsequent
731 * packets are sent with zero contactcount.
733 if (td->cc_index >= 0) {
734 struct hid_field *field = report->field[td->cc_index];
735 int value = field->value[td->cc_value_index];
736 if (value)
737 td->num_expected = value;
740 for (r = 0; r < report->maxfield; r++) {
741 field = report->field[r];
742 count = field->report_count;
744 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
745 continue;
747 for (n = 0; n < count; n++)
748 mt_process_mt_event(hid, field, &field->usage[n],
749 field->value[n]);
752 if (td->num_received >= td->num_expected)
753 mt_sync_frame(td, report->field[0]->hidinput->input);
756 static void mt_touch_input_configured(struct hid_device *hdev,
757 struct hid_input *hi)
759 struct mt_device *td = hid_get_drvdata(hdev);
760 struct mt_class *cls = &td->mtclass;
761 struct input_dev *input = hi->input;
763 if (!td->maxcontacts)
764 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
766 mt_post_parse(td);
767 if (td->serial_maybe)
768 mt_post_parse_default_settings(td);
770 if (cls->is_indirect)
771 td->mt_flags |= INPUT_MT_POINTER;
773 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
774 td->mt_flags |= INPUT_MT_DROP_UNUSED;
776 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
778 td->mt_flags = 0;
781 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
782 struct hid_field *field, struct hid_usage *usage,
783 unsigned long **bit, int *max)
785 /* Only map fields from TouchScreen or TouchPad collections.
786 * We need to ignore fields that belong to other collections
787 * such as Mouse that might have the same GenericDesktop usages. */
788 if (field->application != HID_DG_TOUCHSCREEN &&
789 field->application != HID_DG_PEN &&
790 field->application != HID_DG_TOUCHPAD)
791 return -1;
793 if (field->physical == HID_DG_STYLUS)
794 return mt_pen_input_mapping(hdev, hi, field, usage, bit, max);
796 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max);
799 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
800 struct hid_field *field, struct hid_usage *usage,
801 unsigned long **bit, int *max)
803 if (field->physical == HID_DG_STYLUS)
804 return mt_pen_input_mapped(hdev, hi, field, usage, bit, max);
806 return mt_touch_input_mapped(hdev, hi, field, usage, bit, max);
809 static int mt_event(struct hid_device *hid, struct hid_field *field,
810 struct hid_usage *usage, __s32 value)
812 struct mt_device *td = hid_get_drvdata(hid);
814 if (field->report->id == td->mt_report_id)
815 return mt_touch_event(hid, field, usage, value);
817 if (field->report->id == td->pen_report_id)
818 return mt_pen_event(hid, field, usage, value);
820 /* ignore other reports */
821 return 1;
824 static void mt_report(struct hid_device *hid, struct hid_report *report)
826 struct mt_device *td = hid_get_drvdata(hid);
828 if (!(hid->claimed & HID_CLAIMED_INPUT))
829 return;
831 if (report->id == td->mt_report_id)
832 mt_touch_report(hid, report);
834 if (report->id == td->pen_report_id)
835 mt_pen_report(hid, report);
838 static void mt_set_input_mode(struct hid_device *hdev)
840 struct mt_device *td = hid_get_drvdata(hdev);
841 struct hid_report *r;
842 struct hid_report_enum *re;
844 if (td->inputmode < 0)
845 return;
847 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
848 r = re->report_id_hash[td->inputmode];
849 if (r) {
850 r->field[0]->value[td->inputmode_index] = td->inputmode_value;
851 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
855 static void mt_set_maxcontacts(struct hid_device *hdev)
857 struct mt_device *td = hid_get_drvdata(hdev);
858 struct hid_report *r;
859 struct hid_report_enum *re;
860 int fieldmax, max;
862 if (td->maxcontact_report_id < 0)
863 return;
865 if (!td->mtclass.maxcontacts)
866 return;
868 re = &hdev->report_enum[HID_FEATURE_REPORT];
869 r = re->report_id_hash[td->maxcontact_report_id];
870 if (r) {
871 max = td->mtclass.maxcontacts;
872 fieldmax = r->field[0]->logical_maximum;
873 max = min(fieldmax, max);
874 if (r->field[0]->value[0] != max) {
875 r->field[0]->value[0] = max;
876 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
881 static void mt_post_parse_default_settings(struct mt_device *td)
883 __s32 quirks = td->mtclass.quirks;
885 /* unknown serial device needs special quirks */
886 if (td->touches_by_report == 1) {
887 quirks |= MT_QUIRK_ALWAYS_VALID;
888 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
889 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
890 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
891 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
894 td->mtclass.quirks = quirks;
897 static void mt_post_parse(struct mt_device *td)
899 struct mt_fields *f = td->fields;
900 struct mt_class *cls = &td->mtclass;
902 if (td->touches_by_report > 0) {
903 int field_count_per_touch = f->length / td->touches_by_report;
904 td->last_slot_field = f->usages[field_count_per_touch - 1];
907 if (td->cc_index < 0)
908 cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
911 static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
913 struct mt_device *td = hid_get_drvdata(hdev);
914 char *name;
915 const char *suffix = NULL;
917 if (hi->report->id == td->mt_report_id)
918 mt_touch_input_configured(hdev, hi);
920 if (hi->report->field[0]->physical == HID_DG_STYLUS) {
921 suffix = "Pen";
922 mt_pen_input_configured(hdev, hi);
925 if (suffix) {
926 name = devm_kzalloc(&hi->input->dev,
927 strlen(hdev->name) + strlen(suffix) + 2,
928 GFP_KERNEL);
929 if (name) {
930 sprintf(name, "%s %s", hdev->name, suffix);
931 hi->input->name = name;
936 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
938 int ret, i;
939 struct mt_device *td;
940 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
942 for (i = 0; mt_classes[i].name ; i++) {
943 if (id->driver_data == mt_classes[i].name) {
944 mtclass = &(mt_classes[i]);
945 break;
949 /* This allows the driver to correctly support devices
950 * that emit events over several HID messages.
952 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
955 * This allows the driver to handle different input sensors
956 * that emits events through different reports on the same HID
957 * device.
959 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
960 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
963 * Handle special quirks for Windows 8 certified devices.
965 if (id->group == HID_GROUP_MULTITOUCH_WIN_8)
967 * Some multitouch screens do not like to be polled for input
968 * reports. Fortunately, the Win8 spec says that all touches
969 * should be sent during each report, making the initialization
970 * of input reports unnecessary.
972 hdev->quirks |= HID_QUIRK_NO_INIT_INPUT_REPORTS;
974 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
975 if (!td) {
976 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
977 return -ENOMEM;
979 td->mtclass = *mtclass;
980 td->inputmode = -1;
981 td->maxcontact_report_id = -1;
982 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
983 td->cc_index = -1;
984 td->mt_report_id = -1;
985 td->pen_report_id = -1;
986 hid_set_drvdata(hdev, td);
988 td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
989 GFP_KERNEL);
990 if (!td->fields) {
991 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
992 return -ENOMEM;
995 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
996 td->serial_maybe = true;
998 ret = hid_parse(hdev);
999 if (ret != 0)
1000 return ret;
1002 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1003 if (ret)
1004 return ret;
1006 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
1008 mt_set_maxcontacts(hdev);
1009 mt_set_input_mode(hdev);
1011 /* release .fields memory as it is not used anymore */
1012 devm_kfree(&hdev->dev, td->fields);
1013 td->fields = NULL;
1015 return 0;
1018 #ifdef CONFIG_PM
1019 static int mt_reset_resume(struct hid_device *hdev)
1021 mt_set_maxcontacts(hdev);
1022 mt_set_input_mode(hdev);
1023 return 0;
1026 static int mt_resume(struct hid_device *hdev)
1028 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1029 * It should be safe to send it to other devices too.
1030 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1032 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
1034 return 0;
1036 #endif
1038 static void mt_remove(struct hid_device *hdev)
1040 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
1041 hid_hw_stop(hdev);
1044 static const struct hid_device_id mt_devices[] = {
1046 /* 3M panels */
1047 { .driver_data = MT_CLS_3M,
1048 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1049 USB_DEVICE_ID_3M1968) },
1050 { .driver_data = MT_CLS_3M,
1051 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1052 USB_DEVICE_ID_3M2256) },
1053 { .driver_data = MT_CLS_3M,
1054 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1055 USB_DEVICE_ID_3M3266) },
1057 /* ActionStar panels */
1058 { .driver_data = MT_CLS_NSMU,
1059 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
1060 USB_DEVICE_ID_ACTIONSTAR_1011) },
1062 /* Atmel panels */
1063 { .driver_data = MT_CLS_SERIAL,
1064 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
1065 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
1066 { .driver_data = MT_CLS_SERIAL,
1067 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
1068 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
1070 /* Baanto multitouch devices */
1071 { .driver_data = MT_CLS_NSMU,
1072 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
1073 USB_DEVICE_ID_BAANTO_MT_190W2) },
1074 /* Cando panels */
1075 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1076 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1077 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1078 { .driver_data = MT_CLS_DUAL_CONTACT_NUMBER,
1079 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1080 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
1081 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1082 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1083 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1084 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1085 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1086 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1088 /* Chunghwa Telecom touch panels */
1089 { .driver_data = MT_CLS_NSMU,
1090 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
1091 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1093 /* CVTouch panels */
1094 { .driver_data = MT_CLS_NSMU,
1095 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
1096 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1098 /* Cypress panel */
1099 { .driver_data = MT_CLS_CYPRESS,
1100 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
1101 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
1103 /* Data Modul easyMaxTouch */
1104 { .driver_data = MT_CLS_DEFAULT,
1105 MT_USB_DEVICE(USB_VENDOR_ID_DATA_MODUL,
1106 USB_VENDOR_ID_DATA_MODUL_EASYMAXTOUCH) },
1108 /* eGalax devices (resistive) */
1109 { .driver_data = MT_CLS_EGALAX,
1110 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1111 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1112 { .driver_data = MT_CLS_EGALAX,
1113 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1114 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1116 /* eGalax devices (capacitive) */
1117 { .driver_data = MT_CLS_EGALAX_SERIAL,
1118 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1119 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
1120 { .driver_data = MT_CLS_EGALAX,
1121 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1122 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1123 { .driver_data = MT_CLS_EGALAX_SERIAL,
1124 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1125 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1126 { .driver_data = MT_CLS_EGALAX_SERIAL,
1127 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1128 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
1129 { .driver_data = MT_CLS_EGALAX_SERIAL,
1130 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1131 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
1132 { .driver_data = MT_CLS_EGALAX_SERIAL,
1133 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1134 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
1135 { .driver_data = MT_CLS_EGALAX,
1136 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1137 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1138 { .driver_data = MT_CLS_EGALAX,
1139 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1140 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1141 { .driver_data = MT_CLS_EGALAX_SERIAL,
1142 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1143 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
1144 { .driver_data = MT_CLS_EGALAX,
1145 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1146 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1147 { .driver_data = MT_CLS_EGALAX,
1148 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1149 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1150 { .driver_data = MT_CLS_EGALAX,
1151 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1152 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1153 { .driver_data = MT_CLS_EGALAX,
1154 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1155 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1156 { .driver_data = MT_CLS_EGALAX_SERIAL,
1157 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1158 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1159 { .driver_data = MT_CLS_EGALAX_SERIAL,
1160 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1161 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1162 { .driver_data = MT_CLS_EGALAX_SERIAL,
1163 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1164 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
1166 /* Elitegroup panel */
1167 { .driver_data = MT_CLS_SERIAL,
1168 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1169 USB_DEVICE_ID_ELITEGROUP_05D8) },
1171 /* Elo TouchSystems IntelliTouch Plus panel */
1172 { .driver_data = MT_CLS_DUAL_CONTACT_ID,
1173 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
1174 USB_DEVICE_ID_ELO_TS2515) },
1176 /* Flatfrog Panels */
1177 { .driver_data = MT_CLS_FLATFROG,
1178 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1179 USB_DEVICE_ID_MULTITOUCH_3200) },
1181 /* GeneralTouch panel */
1182 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1183 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1184 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1185 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1186 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1187 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
1188 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1189 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1190 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1191 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1192 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1193 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1194 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1195 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1196 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1197 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1198 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1199 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1200 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1201 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1202 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
1204 /* Gametel game controller */
1205 { .driver_data = MT_CLS_NSMU,
1206 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
1207 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1209 /* GoodTouch panels */
1210 { .driver_data = MT_CLS_NSMU,
1211 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
1212 USB_DEVICE_ID_GOODTOUCH_000f) },
1214 /* Hanvon panels */
1215 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1216 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
1217 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1219 /* Ideacom panel */
1220 { .driver_data = MT_CLS_SERIAL,
1221 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
1222 USB_DEVICE_ID_IDEACOM_IDC6650) },
1223 { .driver_data = MT_CLS_SERIAL,
1224 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
1225 USB_DEVICE_ID_IDEACOM_IDC6651) },
1227 /* Ilitek dual touch panel */
1228 { .driver_data = MT_CLS_NSMU,
1229 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
1230 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1232 /* IRTOUCH panels */
1233 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1234 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
1235 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1237 /* LG Display panels */
1238 { .driver_data = MT_CLS_DEFAULT,
1239 MT_USB_DEVICE(USB_VENDOR_ID_LG,
1240 USB_DEVICE_ID_LG_MULTITOUCH) },
1242 /* Lumio panels */
1243 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1244 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
1245 USB_DEVICE_ID_CRYSTALTOUCH) },
1246 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1247 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
1248 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
1250 /* MosArt panels */
1251 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1252 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
1253 USB_DEVICE_ID_ASUS_T91MT)},
1254 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1255 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
1256 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1257 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1258 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
1259 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1261 /* Nexio panels */
1262 { .driver_data = MT_CLS_DEFAULT,
1263 MT_USB_DEVICE(USB_VENDOR_ID_NEXIO,
1264 USB_DEVICE_ID_NEXIO_MULTITOUCH_420)},
1266 /* Panasonic panels */
1267 { .driver_data = MT_CLS_PANASONIC,
1268 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1269 USB_DEVICE_ID_PANABOARD_UBT780) },
1270 { .driver_data = MT_CLS_PANASONIC,
1271 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1272 USB_DEVICE_ID_PANABOARD_UBT880) },
1274 /* Novatek Panel */
1275 { .driver_data = MT_CLS_NSMU,
1276 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
1277 USB_DEVICE_ID_NOVATEK_PCT) },
1279 /* PenMount panels */
1280 { .driver_data = MT_CLS_CONFIDENCE,
1281 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
1282 USB_DEVICE_ID_PENMOUNT_PCI) },
1284 /* Ntrig Panel */
1285 { .driver_data = MT_CLS_NSMU,
1286 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
1287 USB_VENDOR_ID_NTRIG, 0x1b05) },
1289 /* PixArt optical touch screen */
1290 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
1291 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
1292 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1293 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
1294 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
1295 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1296 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
1297 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
1298 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1300 /* PixCir-based panels */
1301 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1302 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
1303 USB_DEVICE_ID_HANVON_MULTITOUCH) },
1304 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1305 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1306 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1308 /* Quanta-based panels */
1309 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
1310 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
1311 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1312 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
1313 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
1314 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1315 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
1316 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
1317 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1319 /* SiS panels */
1320 { .driver_data = MT_CLS_DEFAULT,
1321 HID_USB_DEVICE(USB_VENDOR_ID_SIS_TOUCH,
1322 USB_DEVICE_ID_SIS9200_TOUCH) },
1323 { .driver_data = MT_CLS_DEFAULT,
1324 HID_USB_DEVICE(USB_VENDOR_ID_SIS_TOUCH,
1325 USB_DEVICE_ID_SIS817_TOUCH) },
1326 { .driver_data = MT_CLS_DEFAULT,
1327 HID_USB_DEVICE(USB_VENDOR_ID_SIS_TOUCH,
1328 USB_DEVICE_ID_SIS1030_TOUCH) },
1330 /* Stantum panels */
1331 { .driver_data = MT_CLS_CONFIDENCE,
1332 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
1333 USB_DEVICE_ID_MTP)},
1334 { .driver_data = MT_CLS_CONFIDENCE,
1335 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
1336 USB_DEVICE_ID_MTP_STM)},
1337 { .driver_data = MT_CLS_DEFAULT,
1338 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
1339 USB_DEVICE_ID_MTP_SITRONIX)},
1341 /* TopSeed panels */
1342 { .driver_data = MT_CLS_TOPSEED,
1343 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
1344 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1346 /* Touch International panels */
1347 { .driver_data = MT_CLS_NSMU,
1348 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
1349 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1351 /* Unitec panels */
1352 { .driver_data = MT_CLS_NSMU,
1353 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
1354 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1355 { .driver_data = MT_CLS_NSMU,
1356 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
1357 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
1359 /* Wistron panels */
1360 { .driver_data = MT_CLS_NSMU,
1361 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
1362 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
1364 /* XAT */
1365 { .driver_data = MT_CLS_NSMU,
1366 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
1367 USB_DEVICE_ID_XAT_CSR) },
1369 /* Xiroku */
1370 { .driver_data = MT_CLS_NSMU,
1371 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1372 USB_DEVICE_ID_XIROKU_SPX) },
1373 { .driver_data = MT_CLS_NSMU,
1374 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1375 USB_DEVICE_ID_XIROKU_MPX) },
1376 { .driver_data = MT_CLS_NSMU,
1377 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1378 USB_DEVICE_ID_XIROKU_CSR) },
1379 { .driver_data = MT_CLS_NSMU,
1380 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1381 USB_DEVICE_ID_XIROKU_SPX1) },
1382 { .driver_data = MT_CLS_NSMU,
1383 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1384 USB_DEVICE_ID_XIROKU_MPX1) },
1385 { .driver_data = MT_CLS_NSMU,
1386 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1387 USB_DEVICE_ID_XIROKU_CSR1) },
1388 { .driver_data = MT_CLS_NSMU,
1389 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1390 USB_DEVICE_ID_XIROKU_SPX2) },
1391 { .driver_data = MT_CLS_NSMU,
1392 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1393 USB_DEVICE_ID_XIROKU_MPX2) },
1394 { .driver_data = MT_CLS_NSMU,
1395 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1396 USB_DEVICE_ID_XIROKU_CSR2) },
1398 /* Zytronic panels */
1399 { .driver_data = MT_CLS_SERIAL,
1400 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1401 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1403 /* Generic MT device */
1404 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
1406 /* Generic Win 8 certified MT device */
1407 { .driver_data = MT_CLS_WIN_8,
1408 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
1409 HID_ANY_ID, HID_ANY_ID) },
1412 MODULE_DEVICE_TABLE(hid, mt_devices);
1414 static const struct hid_usage_id mt_grabbed_usages[] = {
1415 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1416 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1419 static struct hid_driver mt_driver = {
1420 .name = "hid-multitouch",
1421 .id_table = mt_devices,
1422 .probe = mt_probe,
1423 .remove = mt_remove,
1424 .input_mapping = mt_input_mapping,
1425 .input_mapped = mt_input_mapped,
1426 .input_configured = mt_input_configured,
1427 .feature_mapping = mt_feature_mapping,
1428 .usage_table = mt_grabbed_usages,
1429 .event = mt_event,
1430 .report = mt_report,
1431 #ifdef CONFIG_PM
1432 .reset_resume = mt_reset_resume,
1433 .resume = mt_resume,
1434 #endif
1436 module_hid_driver(mt_driver);