1 /*
2 * HID driver for multitouch panels
3 *
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
8 *
9 * This code is partly based on hid-egalax.c:
10 *
11 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
12 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
13 * Copyright (c) 2010 Canonical, Ltd.
14 *
15 * This code is partly based on hid-3m-pct.c:
16 *
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.
20 *
21 */
22
23 /*
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.
28 */
29
30 /*
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.
35 *
36 * [1] https://github.com/bentiss/hid-test
37 * [2] https://github.com/bentiss/hid-replay
38 * [3] https://github.com/bentiss/hid-devices
39 */
40
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>
47
48
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");
53
54 #include "hid-ids.h"
55
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_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
65 #define MT_QUIRK_NO_AREA (1 << 9)
66 #define MT_QUIRK_IGNORE_DUPLICATES (1 << 10)
67 #define MT_QUIRK_HOVERING (1 << 11)
68 #define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12)
69 #define MT_QUIRK_FORCE_GET_FEATURE (1 << 13)
70
71 #define MT_INPUTMODE_TOUCHSCREEN 0x02
72 #define MT_INPUTMODE_TOUCHPAD 0x03
73
74 #define MT_BUTTONTYPE_CLICKPAD 0
75
76 struct mt_slot {
77 __s32 x, y, cx, cy, p, w, h;
78 __s32 contactid; /* the device ContactID assigned to this slot */
79 bool touch_state; /* is the touch valid? */
80 bool inrange_state; /* is the finger in proximity of the sensor? */
81 };
82
83 struct mt_class {
84 __s32 name; /* MT_CLS */
85 __s32 quirks;
86 __s32 sn_move; /* Signal/noise ratio for move events */
87 __s32 sn_width; /* Signal/noise ratio for width events */
88 __s32 sn_height; /* Signal/noise ratio for height events */
89 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
90 __u8 maxcontacts;
91 bool is_indirect; /* true for touchpads */
92 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
93 };
94
95 struct mt_fields {
96 unsigned usages[HID_MAX_FIELDS];
97 unsigned int length;
98 };
99
100 struct mt_device {
101 struct mt_slot curdata; /* placeholder of incoming data */
102 struct mt_class mtclass; /* our mt device class */
103 struct mt_fields *fields; /* temporary placeholder for storing the
104 multitouch fields */
105 int cc_index; /* contact count field index in the report */
106 int cc_value_index; /* contact count value index in the field */
107 unsigned last_slot_field; /* the last field of a slot */
108 unsigned mt_report_id; /* the report ID of the multitouch device */
109 __s16 inputmode; /* InputMode HID feature, -1 if non-existent */
110 __s16 inputmode_index; /* InputMode HID feature index in the report */
111 __s16 maxcontact_report_id; /* Maximum Contact Number HID feature,
112 -1 if non-existent */
113 __u8 inputmode_value; /* InputMode HID feature value */
114 __u8 num_received; /* how many contacts we received */
115 __u8 num_expected; /* expected last contact index */
116 __u8 maxcontacts;
117 __u8 touches_by_report; /* how many touches are present in one report:
118 * 1 means we should use a serial protocol
119 * > 1 means hybrid (multitouch) protocol */
120 __u8 buttons_count; /* number of physical buttons per touchpad */
121 bool is_buttonpad; /* is this device a button pad? */
122 bool serial_maybe; /* need to check for serial protocol */
123 bool curvalid; /* is the current contact valid? */
124 unsigned mt_flags; /* flags to pass to input-mt */
125 };
126
127 static void mt_post_parse_default_settings(struct mt_device *td);
128 static void mt_post_parse(struct mt_device *td);
129
130 /* classes of device behavior */
131 #define MT_CLS_DEFAULT 0x0001
132
133 #define MT_CLS_SERIAL 0x0002
134 #define MT_CLS_CONFIDENCE 0x0003
135 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
136 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
137 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
138 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
139 /* reserved 0x0008 */
140 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
141 #define MT_CLS_NSMU 0x000a
142 /* reserved 0x0010 */
143 /* reserved 0x0011 */
144 #define MT_CLS_WIN_8 0x0012
145 #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
146
147 /* vendor specific classes */
148 #define MT_CLS_3M 0x0101
149 /* reserved 0x0102 */
150 #define MT_CLS_EGALAX 0x0103
151 #define MT_CLS_EGALAX_SERIAL 0x0104
152 #define MT_CLS_TOPSEED 0x0105
153 #define MT_CLS_PANASONIC 0x0106
154 #define MT_CLS_FLATFROG 0x0107
155 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
156 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
157 #define MT_CLS_VTL 0x0110
158
159 #define MT_DEFAULT_MAXCONTACT 10
160 #define MT_MAX_MAXCONTACT 250
161
162 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
163 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
164
165 /*
166 * these device-dependent functions determine what slot corresponds
167 * to a valid contact that was just read.
168 */
169
cypress_compute_slot(struct mt_device * td)170 static int cypress_compute_slot(struct mt_device *td)
171 {
172 if (td->curdata.contactid != 0 || td->num_received == 0)
173 return td->curdata.contactid;
174 else
175 return -1;
176 }
177
178 static struct mt_class mt_classes[] = {
179 { .name = MT_CLS_DEFAULT,
180 .quirks = MT_QUIRK_ALWAYS_VALID |
181 MT_QUIRK_CONTACT_CNT_ACCURATE },
182 { .name = MT_CLS_NSMU,
183 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
184 { .name = MT_CLS_SERIAL,
185 .quirks = MT_QUIRK_ALWAYS_VALID},
186 { .name = MT_CLS_CONFIDENCE,
187 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
188 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
189 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
190 MT_QUIRK_SLOT_IS_CONTACTID },
191 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
192 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
193 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
194 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
195 .quirks = MT_QUIRK_VALID_IS_INRANGE |
196 MT_QUIRK_SLOT_IS_CONTACTID,
197 .maxcontacts = 2 },
198 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
199 .quirks = MT_QUIRK_VALID_IS_INRANGE |
200 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
201 .maxcontacts = 2 },
202 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
203 .quirks = MT_QUIRK_VALID_IS_INRANGE |
204 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
205 { .name = MT_CLS_WIN_8,
206 .quirks = MT_QUIRK_ALWAYS_VALID |
207 MT_QUIRK_IGNORE_DUPLICATES |
208 MT_QUIRK_HOVERING |
209 MT_QUIRK_CONTACT_CNT_ACCURATE },
210 { .name = MT_CLS_EXPORT_ALL_INPUTS,
211 .quirks = MT_QUIRK_ALWAYS_VALID |
212 MT_QUIRK_CONTACT_CNT_ACCURATE,
213 .export_all_inputs = true },
214
215 /*
216 * vendor specific classes
217 */
218 { .name = MT_CLS_3M,
219 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
220 MT_QUIRK_SLOT_IS_CONTACTID,
221 .sn_move = 2048,
222 .sn_width = 128,
223 .sn_height = 128,
224 .maxcontacts = 60,
225 },
226 { .name = MT_CLS_EGALAX,
227 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
228 MT_QUIRK_VALID_IS_INRANGE,
229 .sn_move = 4096,
230 .sn_pressure = 32,
231 },
232 { .name = MT_CLS_EGALAX_SERIAL,
233 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
234 MT_QUIRK_ALWAYS_VALID,
235 .sn_move = 4096,
236 .sn_pressure = 32,
237 },
238 { .name = MT_CLS_TOPSEED,
239 .quirks = MT_QUIRK_ALWAYS_VALID,
240 .is_indirect = true,
241 .maxcontacts = 2,
242 },
243 { .name = MT_CLS_PANASONIC,
244 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
245 .maxcontacts = 4 },
246 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
247 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
248 MT_QUIRK_VALID_IS_INRANGE |
249 MT_QUIRK_SLOT_IS_CONTACTID,
250 .maxcontacts = 2
251 },
252 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
253 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
254 MT_QUIRK_SLOT_IS_CONTACTID
255 },
256
257 { .name = MT_CLS_FLATFROG,
258 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
259 MT_QUIRK_NO_AREA,
260 .sn_move = 2048,
261 .maxcontacts = 40,
262 },
263 { .name = MT_CLS_VTL,
264 .quirks = MT_QUIRK_ALWAYS_VALID |
265 MT_QUIRK_CONTACT_CNT_ACCURATE |
266 MT_QUIRK_FORCE_GET_FEATURE,
267 },
268 { }
269 };
270
mt_show_quirks(struct device * dev,struct device_attribute * attr,char * buf)271 static ssize_t mt_show_quirks(struct device *dev,
272 struct device_attribute *attr,
273 char *buf)
274 {
275 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
276 struct mt_device *td = hid_get_drvdata(hdev);
277
278 return sprintf(buf, "%u\n", td->mtclass.quirks);
279 }
280
mt_set_quirks(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)281 static ssize_t mt_set_quirks(struct device *dev,
282 struct device_attribute *attr,
283 const char *buf, size_t count)
284 {
285 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
286 struct mt_device *td = hid_get_drvdata(hdev);
287
288 unsigned long val;
289
290 if (kstrtoul(buf, 0, &val))
291 return -EINVAL;
292
293 td->mtclass.quirks = val;
294
295 if (td->cc_index < 0)
296 td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
297
298 return count;
299 }
300
301 static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
302
303 static struct attribute *sysfs_attrs[] = {
304 &dev_attr_quirks.attr,
305 NULL
306 };
307
308 static struct attribute_group mt_attribute_group = {
309 .attrs = sysfs_attrs
310 };
311
mt_feature_mapping(struct hid_device * hdev,struct hid_field * field,struct hid_usage * usage)312 static void mt_feature_mapping(struct hid_device *hdev,
313 struct hid_field *field, struct hid_usage *usage)
314 {
315 struct mt_device *td = hid_get_drvdata(hdev);
316
317 switch (usage->hid) {
318 case HID_DG_INPUTMODE:
319 /* Ignore if value index is out of bounds. */
320 if (usage->usage_index >= field->report_count) {
321 dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
322 break;
323 }
324
325 if (td->inputmode < 0) {
326 td->inputmode = field->report->id;
327 td->inputmode_index = usage->usage_index;
328 } else {
329 /*
330 * Some elan panels wrongly declare 2 input mode
331 * features, and silently ignore when we set the
332 * value in the second field. Skip the second feature
333 * and hope for the best.
334 */
335 dev_info(&hdev->dev,
336 "Ignoring the extra HID_DG_INPUTMODE\n");
337 }
338
339 break;
340 case HID_DG_CONTACTMAX:
341 td->maxcontact_report_id = field->report->id;
342 td->maxcontacts = field->value[0];
343 if (!td->maxcontacts &&
344 field->logical_maximum <= MT_MAX_MAXCONTACT)
345 td->maxcontacts = field->logical_maximum;
346 if (td->mtclass.maxcontacts)
347 /* check if the maxcontacts is given by the class */
348 td->maxcontacts = td->mtclass.maxcontacts;
349
350 break;
351 case HID_DG_BUTTONTYPE:
352 if (usage->usage_index >= field->report_count) {
353 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
354 break;
355 }
356
357 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
358 td->is_buttonpad = true;
359
360 break;
361 }
362 }
363
set_abs(struct input_dev * input,unsigned int code,struct hid_field * field,int snratio)364 static void set_abs(struct input_dev *input, unsigned int code,
365 struct hid_field *field, int snratio)
366 {
367 int fmin = field->logical_minimum;
368 int fmax = field->logical_maximum;
369 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
370 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
371 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
372 }
373
mt_store_field(struct hid_usage * usage,struct mt_device * td,struct hid_input * hi)374 static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
375 struct hid_input *hi)
376 {
377 struct mt_fields *f = td->fields;
378
379 if (f->length >= HID_MAX_FIELDS)
380 return;
381
382 f->usages[f->length++] = usage->hid;
383 }
384
mt_touch_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)385 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
386 struct hid_field *field, struct hid_usage *usage,
387 unsigned long **bit, int *max)
388 {
389 struct mt_device *td = hid_get_drvdata(hdev);
390 struct mt_class *cls = &td->mtclass;
391 int code;
392 struct hid_usage *prev_usage = NULL;
393
394 if (field->application == HID_DG_TOUCHSCREEN)
395 td->mt_flags |= INPUT_MT_DIRECT;
396
397 /*
398 * Model touchscreens providing buttons as touchpads.
399 */
400 if (field->application == HID_DG_TOUCHPAD ||
401 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
402 td->mt_flags |= INPUT_MT_POINTER;
403 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
404 }
405
406 /* count the buttons on touchpads */
407 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
408 td->buttons_count++;
409
410 if (usage->usage_index)
411 prev_usage = &field->usage[usage->usage_index - 1];
412
413 switch (usage->hid & HID_USAGE_PAGE) {
414
415 case HID_UP_GENDESK:
416 switch (usage->hid) {
417 case HID_GD_X:
418 if (prev_usage && (prev_usage->hid == usage->hid)) {
419 hid_map_usage(hi, usage, bit, max,
420 EV_ABS, ABS_MT_TOOL_X);
421 set_abs(hi->input, ABS_MT_TOOL_X, field,
422 cls->sn_move);
423 } else {
424 hid_map_usage(hi, usage, bit, max,
425 EV_ABS, ABS_MT_POSITION_X);
426 set_abs(hi->input, ABS_MT_POSITION_X, field,
427 cls->sn_move);
428 }
429
430 mt_store_field(usage, td, hi);
431 return 1;
432 case HID_GD_Y:
433 if (prev_usage && (prev_usage->hid == usage->hid)) {
434 hid_map_usage(hi, usage, bit, max,
435 EV_ABS, ABS_MT_TOOL_Y);
436 set_abs(hi->input, ABS_MT_TOOL_Y, field,
437 cls->sn_move);
438 } else {
439 hid_map_usage(hi, usage, bit, max,
440 EV_ABS, ABS_MT_POSITION_Y);
441 set_abs(hi->input, ABS_MT_POSITION_Y, field,
442 cls->sn_move);
443 }
444
445 mt_store_field(usage, td, hi);
446 return 1;
447 }
448 return 0;
449
450 case HID_UP_DIGITIZER:
451 switch (usage->hid) {
452 case HID_DG_INRANGE:
453 if (cls->quirks & MT_QUIRK_HOVERING) {
454 hid_map_usage(hi, usage, bit, max,
455 EV_ABS, ABS_MT_DISTANCE);
456 input_set_abs_params(hi->input,
457 ABS_MT_DISTANCE, 0, 1, 0, 0);
458 }
459 mt_store_field(usage, td, hi);
460 return 1;
461 case HID_DG_CONFIDENCE:
462 mt_store_field(usage, td, hi);
463 return 1;
464 case HID_DG_TIPSWITCH:
465 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
466 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
467 mt_store_field(usage, td, hi);
468 return 1;
469 case HID_DG_CONTACTID:
470 mt_store_field(usage, td, hi);
471 td->touches_by_report++;
472 td->mt_report_id = field->report->id;
473 return 1;
474 case HID_DG_WIDTH:
475 hid_map_usage(hi, usage, bit, max,
476 EV_ABS, ABS_MT_TOUCH_MAJOR);
477 if (!(cls->quirks & MT_QUIRK_NO_AREA))
478 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
479 cls->sn_width);
480 mt_store_field(usage, td, hi);
481 return 1;
482 case HID_DG_HEIGHT:
483 hid_map_usage(hi, usage, bit, max,
484 EV_ABS, ABS_MT_TOUCH_MINOR);
485 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
486 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
487 cls->sn_height);
488 input_set_abs_params(hi->input,
489 ABS_MT_ORIENTATION, 0, 1, 0, 0);
490 }
491 mt_store_field(usage, td, hi);
492 return 1;
493 case HID_DG_TIPPRESSURE:
494 hid_map_usage(hi, usage, bit, max,
495 EV_ABS, ABS_MT_PRESSURE);
496 set_abs(hi->input, ABS_MT_PRESSURE, field,
497 cls->sn_pressure);
498 mt_store_field(usage, td, hi);
499 return 1;
500 case HID_DG_CONTACTCOUNT:
501 /* Ignore if indexes are out of bounds. */
502 if (field->index >= field->report->maxfield ||
503 usage->usage_index >= field->report_count)
504 return 1;
505 td->cc_index = field->index;
506 td->cc_value_index = usage->usage_index;
507 return 1;
508 case HID_DG_CONTACTMAX:
509 /* we don't set td->last_slot_field as contactcount and
510 * contact max are global to the report */
511 return -1;
512 case HID_DG_TOUCH:
513 /* Legacy devices use TIPSWITCH and not TOUCH.
514 * Let's just ignore this field. */
515 return -1;
516 }
517 /* let hid-input decide for the others */
518 return 0;
519
520 case HID_UP_BUTTON:
521 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
522 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
523 input_set_capability(hi->input, EV_KEY, code);
524 return 1;
525
526 case 0xff000000:
527 /* we do not want to map these: no input-oriented meaning */
528 return -1;
529 }
530
531 return 0;
532 }
533
mt_touch_input_mapped(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)534 static int mt_touch_input_mapped(struct hid_device *hdev, struct hid_input *hi,
535 struct hid_field *field, struct hid_usage *usage,
536 unsigned long **bit, int *max)
537 {
538 if (usage->type == EV_KEY || usage->type == EV_ABS)
539 set_bit(usage->type, hi->input->evbit);
540
541 return -1;
542 }
543
mt_compute_slot(struct mt_device * td,struct input_dev * input)544 static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
545 {
546 __s32 quirks = td->mtclass.quirks;
547
548 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
549 return td->curdata.contactid;
550
551 if (quirks & MT_QUIRK_CYPRESS)
552 return cypress_compute_slot(td);
553
554 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
555 return td->num_received;
556
557 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
558 return td->curdata.contactid - 1;
559
560 return input_mt_get_slot_by_key(input, td->curdata.contactid);
561 }
562
563 /*
564 * this function is called when a whole contact has been processed,
565 * so that it can assign it to a slot and store the data there
566 */
mt_complete_slot(struct mt_device * td,struct input_dev * input)567 static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
568 {
569 if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
570 td->num_received >= td->num_expected)
571 return;
572
573 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
574 int slotnum = mt_compute_slot(td, input);
575 struct mt_slot *s = &td->curdata;
576 struct input_mt *mt = input->mt;
577
578 if (slotnum < 0 || slotnum >= td->maxcontacts)
579 return;
580
581 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
582 struct input_mt_slot *slot = &mt->slots[slotnum];
583 if (input_mt_is_active(slot) &&
584 input_mt_is_used(mt, slot))
585 return;
586 }
587
588 input_mt_slot(input, slotnum);
589 input_mt_report_slot_state(input, MT_TOOL_FINGER,
590 s->touch_state || s->inrange_state);
591 if (s->touch_state || s->inrange_state) {
592 /* this finger is in proximity of the sensor */
593 int wide = (s->w > s->h);
594 /* divided by two to match visual scale of touch */
595 int major = max(s->w, s->h) >> 1;
596 int minor = min(s->w, s->h) >> 1;
597
598 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
599 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
600 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
601 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
602 input_event(input, EV_ABS, ABS_MT_DISTANCE,
603 !s->touch_state);
604 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
605 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
606 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
607 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
608 }
609 }
610
611 td->num_received++;
612 }
613
614 /*
615 * this function is called when a whole packet has been received and processed,
616 * so that it can decide what to send to the input layer.
617 */
mt_sync_frame(struct mt_device * td,struct input_dev * input)618 static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
619 {
620 input_mt_sync_frame(input);
621 input_sync(input);
622 td->num_received = 0;
623 }
624
mt_touch_event(struct hid_device * hid,struct hid_field * field,struct hid_usage * usage,__s32 value)625 static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
626 struct hid_usage *usage, __s32 value)
627 {
628 /* we will handle the hidinput part later, now remains hiddev */
629 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
630 hid->hiddev_hid_event(hid, field, usage, value);
631
632 return 1;
633 }
634
mt_process_mt_event(struct hid_device * hid,struct hid_field * field,struct hid_usage * usage,__s32 value)635 static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
636 struct hid_usage *usage, __s32 value)
637 {
638 struct mt_device *td = hid_get_drvdata(hid);
639 __s32 quirks = td->mtclass.quirks;
640 struct input_dev *input = field->hidinput->input;
641
642 if (hid->claimed & HID_CLAIMED_INPUT) {
643 switch (usage->hid) {
644 case HID_DG_INRANGE:
645 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
646 td->curvalid = value;
647 if (quirks & MT_QUIRK_HOVERING)
648 td->curdata.inrange_state = value;
649 break;
650 case HID_DG_TIPSWITCH:
651 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
652 td->curvalid = value;
653 td->curdata.touch_state = value;
654 break;
655 case HID_DG_CONFIDENCE:
656 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
657 td->curvalid = value;
658 break;
659 case HID_DG_CONTACTID:
660 td->curdata.contactid = value;
661 break;
662 case HID_DG_TIPPRESSURE:
663 td->curdata.p = value;
664 break;
665 case HID_GD_X:
666 if (usage->code == ABS_MT_TOOL_X)
667 td->curdata.cx = value;
668 else
669 td->curdata.x = value;
670 break;
671 case HID_GD_Y:
672 if (usage->code == ABS_MT_TOOL_Y)
673 td->curdata.cy = value;
674 else
675 td->curdata.y = value;
676 break;
677 case HID_DG_WIDTH:
678 td->curdata.w = value;
679 break;
680 case HID_DG_HEIGHT:
681 td->curdata.h = value;
682 break;
683 case HID_DG_CONTACTCOUNT:
684 break;
685 case HID_DG_TOUCH:
686 /* do nothing */
687 break;
688
689 default:
690 if (usage->type)
691 input_event(input, usage->type, usage->code,
692 value);
693 return;
694 }
695
696 if (usage->usage_index + 1 == field->report_count) {
697 /* we only take into account the last report. */
698 if (usage->hid == td->last_slot_field)
699 mt_complete_slot(td, field->hidinput->input);
700 }
701
702 }
703 }
704
mt_touch_report(struct hid_device * hid,struct hid_report * report)705 static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
706 {
707 struct mt_device *td = hid_get_drvdata(hid);
708 struct hid_field *field;
709 unsigned count;
710 int r, n;
711
712 /*
713 * Includes multi-packet support where subsequent
714 * packets are sent with zero contactcount.
715 */
716 if (td->cc_index >= 0) {
717 struct hid_field *field = report->field[td->cc_index];
718 int value = field->value[td->cc_value_index];
719 if (value)
720 td->num_expected = value;
721 }
722
723 for (r = 0; r < report->maxfield; r++) {
724 field = report->field[r];
725 count = field->report_count;
726
727 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
728 continue;
729
730 for (n = 0; n < count; n++)
731 mt_process_mt_event(hid, field, &field->usage[n],
732 field->value[n]);
733 }
734
735 if (td->num_received >= td->num_expected)
736 mt_sync_frame(td, report->field[0]->hidinput->input);
737 }
738
mt_touch_input_configured(struct hid_device * hdev,struct hid_input * hi)739 static void mt_touch_input_configured(struct hid_device *hdev,
740 struct hid_input *hi)
741 {
742 struct mt_device *td = hid_get_drvdata(hdev);
743 struct mt_class *cls = &td->mtclass;
744 struct input_dev *input = hi->input;
745
746 if (!td->maxcontacts)
747 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
748
749 mt_post_parse(td);
750 if (td->serial_maybe)
751 mt_post_parse_default_settings(td);
752
753 if (cls->is_indirect)
754 td->mt_flags |= INPUT_MT_POINTER;
755
756 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
757 td->mt_flags |= INPUT_MT_DROP_UNUSED;
758
759 /* check for clickpads */
760 if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1))
761 td->is_buttonpad = true;
762
763 if (td->is_buttonpad)
764 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
765
766 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
767
768 td->mt_flags = 0;
769 }
770
mt_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)771 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
772 struct hid_field *field, struct hid_usage *usage,
773 unsigned long **bit, int *max)
774 {
775 struct mt_device *td = hid_get_drvdata(hdev);
776
777 /*
778 * If mtclass.export_all_inputs is not set, only map fields from
779 * TouchScreen or TouchPad collections. We need to ignore fields
780 * that belong to other collections such as Mouse that might have
781 * the same GenericDesktop usages.
782 */
783 if (!td->mtclass.export_all_inputs &&
784 field->application != HID_DG_TOUCHSCREEN &&
785 field->application != HID_DG_PEN &&
786 field->application != HID_DG_TOUCHPAD)
787 return -1;
788
789 /*
790 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
791 * for the stylus.
792 */
793 if (field->physical == HID_DG_STYLUS)
794 return 0;
795
796 if (field->application == HID_DG_TOUCHSCREEN ||
797 field->application == HID_DG_TOUCHPAD)
798 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max);
799
800 /* let hid-core decide for the others */
801 return 0;
802 }
803
mt_input_mapped(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)804 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
805 struct hid_field *field, struct hid_usage *usage,
806 unsigned long **bit, int *max)
807 {
808 /*
809 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
810 * for the stylus.
811 */
812 if (field->physical == HID_DG_STYLUS)
813 return 0;
814
815 if (field->application == HID_DG_TOUCHSCREEN ||
816 field->application == HID_DG_TOUCHPAD)
817 return mt_touch_input_mapped(hdev, hi, field, usage, bit, max);
818
819 /* let hid-core decide for the others */
820 return 0;
821 }
822
mt_event(struct hid_device * hid,struct hid_field * field,struct hid_usage * usage,__s32 value)823 static int mt_event(struct hid_device *hid, struct hid_field *field,
824 struct hid_usage *usage, __s32 value)
825 {
826 struct mt_device *td = hid_get_drvdata(hid);
827
828 if (field->report->id == td->mt_report_id)
829 return mt_touch_event(hid, field, usage, value);
830
831 return 0;
832 }
833
mt_report(struct hid_device * hid,struct hid_report * report)834 static void mt_report(struct hid_device *hid, struct hid_report *report)
835 {
836 struct mt_device *td = hid_get_drvdata(hid);
837 struct hid_field *field = report->field[0];
838
839 if (!(hid->claimed & HID_CLAIMED_INPUT))
840 return;
841
842 if (report->id == td->mt_report_id)
843 return mt_touch_report(hid, report);
844
845 if (field && field->hidinput && field->hidinput->input)
846 input_sync(field->hidinput->input);
847 }
848
mt_set_input_mode(struct hid_device * hdev)849 static void mt_set_input_mode(struct hid_device *hdev)
850 {
851 struct mt_device *td = hid_get_drvdata(hdev);
852 struct hid_report *r;
853 struct hid_report_enum *re;
854 struct mt_class *cls = &td->mtclass;
855 char *buf;
856 int report_len;
857
858 if (td->inputmode < 0)
859 return;
860
861 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
862 r = re->report_id_hash[td->inputmode];
863 if (r) {
864 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
865 report_len = hid_report_len(r);
866 buf = hid_alloc_report_buf(r, GFP_KERNEL);
867 if (!buf) {
868 hid_err(hdev, "failed to allocate buffer for report\n");
869 return;
870 }
871 hid_hw_raw_request(hdev, r->id, buf, report_len,
872 HID_FEATURE_REPORT,
873 HID_REQ_GET_REPORT);
874 kfree(buf);
875 }
876 r->field[0]->value[td->inputmode_index] = td->inputmode_value;
877 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
878 }
879 }
880
mt_set_maxcontacts(struct hid_device * hdev)881 static void mt_set_maxcontacts(struct hid_device *hdev)
882 {
883 struct mt_device *td = hid_get_drvdata(hdev);
884 struct hid_report *r;
885 struct hid_report_enum *re;
886 int fieldmax, max;
887
888 if (td->maxcontact_report_id < 0)
889 return;
890
891 if (!td->mtclass.maxcontacts)
892 return;
893
894 re = &hdev->report_enum[HID_FEATURE_REPORT];
895 r = re->report_id_hash[td->maxcontact_report_id];
896 if (r) {
897 max = td->mtclass.maxcontacts;
898 fieldmax = r->field[0]->logical_maximum;
899 max = min(fieldmax, max);
900 if (r->field[0]->value[0] != max) {
901 r->field[0]->value[0] = max;
902 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
903 }
904 }
905 }
906
mt_post_parse_default_settings(struct mt_device * td)907 static void mt_post_parse_default_settings(struct mt_device *td)
908 {
909 __s32 quirks = td->mtclass.quirks;
910
911 /* unknown serial device needs special quirks */
912 if (td->touches_by_report == 1) {
913 quirks |= MT_QUIRK_ALWAYS_VALID;
914 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
915 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
916 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
917 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
918 }
919
920 td->mtclass.quirks = quirks;
921 }
922
mt_post_parse(struct mt_device * td)923 static void mt_post_parse(struct mt_device *td)
924 {
925 struct mt_fields *f = td->fields;
926 struct mt_class *cls = &td->mtclass;
927
928 if (td->touches_by_report > 0) {
929 int field_count_per_touch = f->length / td->touches_by_report;
930 td->last_slot_field = f->usages[field_count_per_touch - 1];
931 }
932
933 if (td->cc_index < 0)
934 cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
935 }
936
mt_input_configured(struct hid_device * hdev,struct hid_input * hi)937 static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
938 {
939 struct mt_device *td = hid_get_drvdata(hdev);
940 char *name;
941 const char *suffix = NULL;
942 struct hid_field *field = hi->report->field[0];
943
944 if (hi->report->id == td->mt_report_id)
945 mt_touch_input_configured(hdev, hi);
946
947 /*
948 * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
949 * for the stylus. Check this first, and then rely on the application
950 * field.
951 */
952 if (hi->report->field[0]->physical == HID_DG_STYLUS) {
953 suffix = "Pen";
954 /* force BTN_STYLUS to allow tablet matching in udev */
955 __set_bit(BTN_STYLUS, hi->input->keybit);
956 } else {
957 switch (field->application) {
958 case HID_GD_KEYBOARD:
959 suffix = "Keyboard";
960 break;
961 case HID_GD_KEYPAD:
962 suffix = "Keypad";
963 break;
964 case HID_GD_MOUSE:
965 suffix = "Mouse";
966 break;
967 case HID_DG_STYLUS:
968 suffix = "Pen";
969 /* force BTN_STYLUS to allow tablet matching in udev */
970 __set_bit(BTN_STYLUS, hi->input->keybit);
971 break;
972 case HID_DG_TOUCHSCREEN:
973 /* we do not set suffix = "Touchscreen" */
974 break;
975 case HID_GD_SYSTEM_CONTROL:
976 suffix = "System Control";
977 break;
978 case HID_CP_CONSUMER_CONTROL:
979 suffix = "Consumer Control";
980 break;
981 default:
982 suffix = "UNKNOWN";
983 break;
984 }
985 }
986
987 if (suffix) {
988 name = devm_kzalloc(&hi->input->dev,
989 strlen(hdev->name) + strlen(suffix) + 2,
990 GFP_KERNEL);
991 if (name) {
992 sprintf(name, "%s %s", hdev->name, suffix);
993 hi->input->name = name;
994 }
995 }
996 }
997
mt_probe(struct hid_device * hdev,const struct hid_device_id * id)998 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
999 {
1000 int ret, i;
1001 struct mt_device *td;
1002 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
1003
1004 for (i = 0; mt_classes[i].name ; i++) {
1005 if (id->driver_data == mt_classes[i].name) {
1006 mtclass = &(mt_classes[i]);
1007 break;
1008 }
1009 }
1010
1011 /* This allows the driver to correctly support devices
1012 * that emit events over several HID messages.
1013 */
1014 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1015
1016 /*
1017 * This allows the driver to handle different input sensors
1018 * that emits events through different reports on the same HID
1019 * device.
1020 */
1021 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1022 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
1023
1024 /*
1025 * Handle special quirks for Windows 8 certified devices.
1026 */
1027 if (id->group == HID_GROUP_MULTITOUCH_WIN_8)
1028 /*
1029 * Some multitouch screens do not like to be polled for input
1030 * reports. Fortunately, the Win8 spec says that all touches
1031 * should be sent during each report, making the initialization
1032 * of input reports unnecessary.
1033 */
1034 hdev->quirks |= HID_QUIRK_NO_INIT_INPUT_REPORTS;
1035
1036 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
1037 if (!td) {
1038 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1039 return -ENOMEM;
1040 }
1041 td->mtclass = *mtclass;
1042 td->inputmode = -1;
1043 td->maxcontact_report_id = -1;
1044 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
1045 td->cc_index = -1;
1046 td->mt_report_id = -1;
1047 hid_set_drvdata(hdev, td);
1048
1049 td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
1050 GFP_KERNEL);
1051 if (!td->fields) {
1052 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
1053 return -ENOMEM;
1054 }
1055
1056 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1057 td->serial_maybe = true;
1058
1059 ret = hid_parse(hdev);
1060 if (ret != 0)
1061 return ret;
1062
1063 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1064 if (ret)
1065 return ret;
1066
1067 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
1068
1069 mt_set_maxcontacts(hdev);
1070 mt_set_input_mode(hdev);
1071
1072 /* release .fields memory as it is not used anymore */
1073 devm_kfree(&hdev->dev, td->fields);
1074 td->fields = NULL;
1075
1076 return 0;
1077 }
1078
1079 #ifdef CONFIG_PM
mt_reset_resume(struct hid_device * hdev)1080 static int mt_reset_resume(struct hid_device *hdev)
1081 {
1082 mt_set_maxcontacts(hdev);
1083 mt_set_input_mode(hdev);
1084 return 0;
1085 }
1086
mt_resume(struct hid_device * hdev)1087 static int mt_resume(struct hid_device *hdev)
1088 {
1089 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1090 * It should be safe to send it to other devices too.
1091 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1092
1093 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
1094
1095 return 0;
1096 }
1097 #endif
1098
mt_remove(struct hid_device * hdev)1099 static void mt_remove(struct hid_device *hdev)
1100 {
1101 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
1102 hid_hw_stop(hdev);
1103 }
1104
1105 /*
1106 * This list contains only:
1107 * - VID/PID of products not working with the default multitouch handling
1108 * - 2 generic rules.
1109 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1110 */
1111 static const struct hid_device_id mt_devices[] = {
1112
1113 /* 3M panels */
1114 { .driver_data = MT_CLS_3M,
1115 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1116 USB_DEVICE_ID_3M1968) },
1117 { .driver_data = MT_CLS_3M,
1118 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1119 USB_DEVICE_ID_3M2256) },
1120 { .driver_data = MT_CLS_3M,
1121 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1122 USB_DEVICE_ID_3M3266) },
1123
1124 /* Anton devices */
1125 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1126 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1127 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
1128
1129 /* Atmel panels */
1130 { .driver_data = MT_CLS_SERIAL,
1131 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
1132 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
1133
1134 /* Baanto multitouch devices */
1135 { .driver_data = MT_CLS_NSMU,
1136 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
1137 USB_DEVICE_ID_BAANTO_MT_190W2) },
1138
1139 /* Cando panels */
1140 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1141 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1142 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1143 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1144 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1145 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1146
1147 /* Chunghwa Telecom touch panels */
1148 { .driver_data = MT_CLS_NSMU,
1149 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
1150 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1151
1152 /* CVTouch panels */
1153 { .driver_data = MT_CLS_NSMU,
1154 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
1155 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1156
1157 /* eGalax devices (resistive) */
1158 { .driver_data = MT_CLS_EGALAX,
1159 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1160 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1161 { .driver_data = MT_CLS_EGALAX,
1162 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1163 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1164
1165 /* eGalax devices (capacitive) */
1166 { .driver_data = MT_CLS_EGALAX_SERIAL,
1167 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1168 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
1169 { .driver_data = MT_CLS_EGALAX,
1170 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1171 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1172 { .driver_data = MT_CLS_EGALAX_SERIAL,
1173 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1174 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1175 { .driver_data = MT_CLS_EGALAX_SERIAL,
1176 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1177 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
1178 { .driver_data = MT_CLS_EGALAX_SERIAL,
1179 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1180 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
1181 { .driver_data = MT_CLS_EGALAX_SERIAL,
1182 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1183 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
1184 { .driver_data = MT_CLS_EGALAX,
1185 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1186 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1187 { .driver_data = MT_CLS_EGALAX,
1188 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1189 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1190 { .driver_data = MT_CLS_EGALAX_SERIAL,
1191 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1192 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
1193 { .driver_data = MT_CLS_EGALAX,
1194 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1195 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
1196 { .driver_data = MT_CLS_EGALAX,
1197 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1198 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1199 { .driver_data = MT_CLS_EGALAX,
1200 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1201 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1202 { .driver_data = MT_CLS_EGALAX,
1203 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1204 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1205 { .driver_data = MT_CLS_EGALAX_SERIAL,
1206 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1207 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1208 { .driver_data = MT_CLS_EGALAX_SERIAL,
1209 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1210 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1211 { .driver_data = MT_CLS_EGALAX_SERIAL,
1212 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1213 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
1214
1215 /* Elitegroup panel */
1216 { .driver_data = MT_CLS_SERIAL,
1217 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
1218 USB_DEVICE_ID_ELITEGROUP_05D8) },
1219
1220 /* Flatfrog Panels */
1221 { .driver_data = MT_CLS_FLATFROG,
1222 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1223 USB_DEVICE_ID_MULTITOUCH_3200) },
1224
1225 /* FocalTech Panels */
1226 { .driver_data = MT_CLS_SERIAL,
1227 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
1228 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
1229
1230 /* GeneralTouch panel */
1231 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1232 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1233 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1234 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1235 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1236 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
1237 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
1238 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1239 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
1240 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1241 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1242 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
1243 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1244 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1245 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
1246 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1247 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1248 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
1249 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1250 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1251 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
1252
1253 /* Gametel game controller */
1254 { .driver_data = MT_CLS_NSMU,
1255 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
1256 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1257
1258 /* GoodTouch panels */
1259 { .driver_data = MT_CLS_NSMU,
1260 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
1261 USB_DEVICE_ID_GOODTOUCH_000f) },
1262
1263 /* Hanvon panels */
1264 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1265 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
1266 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1267
1268 /* Ilitek dual touch panel */
1269 { .driver_data = MT_CLS_NSMU,
1270 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
1271 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1272
1273 /* MosArt panels */
1274 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1275 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
1276 USB_DEVICE_ID_ASUS_T91MT)},
1277 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1278 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
1279 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1280 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
1281 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
1282 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1283
1284 /* Panasonic panels */
1285 { .driver_data = MT_CLS_PANASONIC,
1286 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1287 USB_DEVICE_ID_PANABOARD_UBT780) },
1288 { .driver_data = MT_CLS_PANASONIC,
1289 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
1290 USB_DEVICE_ID_PANABOARD_UBT880) },
1291
1292 /* Novatek Panel */
1293 { .driver_data = MT_CLS_NSMU,
1294 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
1295 USB_DEVICE_ID_NOVATEK_PCT) },
1296
1297 /* PixArt optical touch screen */
1298 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
1299 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
1300 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1301 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
1302 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
1303 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1304 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
1305 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
1306 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1307
1308 /* PixCir-based panels */
1309 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
1310 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1311 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1312
1313 /* Quanta-based panels */
1314 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
1315 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
1316 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1317
1318 /* Stantum panels */
1319 { .driver_data = MT_CLS_CONFIDENCE,
1320 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
1321 USB_DEVICE_ID_MTP_STM)},
1322
1323 /* TopSeed panels */
1324 { .driver_data = MT_CLS_TOPSEED,
1325 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
1326 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1327
1328 /* Touch International panels */
1329 { .driver_data = MT_CLS_NSMU,
1330 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
1331 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1332
1333 /* Unitec panels */
1334 { .driver_data = MT_CLS_NSMU,
1335 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
1336 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1337 { .driver_data = MT_CLS_NSMU,
1338 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
1339 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
1340
1341 /* VTL panels */
1342 { .driver_data = MT_CLS_VTL,
1343 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
1344 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
1345
1346 /* Wistron panels */
1347 { .driver_data = MT_CLS_NSMU,
1348 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
1349 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
1350
1351 /* XAT */
1352 { .driver_data = MT_CLS_NSMU,
1353 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
1354 USB_DEVICE_ID_XAT_CSR) },
1355
1356 /* Xiroku */
1357 { .driver_data = MT_CLS_NSMU,
1358 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1359 USB_DEVICE_ID_XIROKU_SPX) },
1360 { .driver_data = MT_CLS_NSMU,
1361 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1362 USB_DEVICE_ID_XIROKU_MPX) },
1363 { .driver_data = MT_CLS_NSMU,
1364 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1365 USB_DEVICE_ID_XIROKU_CSR) },
1366 { .driver_data = MT_CLS_NSMU,
1367 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1368 USB_DEVICE_ID_XIROKU_SPX1) },
1369 { .driver_data = MT_CLS_NSMU,
1370 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1371 USB_DEVICE_ID_XIROKU_MPX1) },
1372 { .driver_data = MT_CLS_NSMU,
1373 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1374 USB_DEVICE_ID_XIROKU_CSR1) },
1375 { .driver_data = MT_CLS_NSMU,
1376 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1377 USB_DEVICE_ID_XIROKU_SPX2) },
1378 { .driver_data = MT_CLS_NSMU,
1379 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1380 USB_DEVICE_ID_XIROKU_MPX2) },
1381 { .driver_data = MT_CLS_NSMU,
1382 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1383 USB_DEVICE_ID_XIROKU_CSR2) },
1384
1385 /* Generic MT device */
1386 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
1387
1388 /* Generic Win 8 certified MT device */
1389 { .driver_data = MT_CLS_WIN_8,
1390 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
1391 HID_ANY_ID, HID_ANY_ID) },
1392 { }
1393 };
1394 MODULE_DEVICE_TABLE(hid, mt_devices);
1395
1396 static const struct hid_usage_id mt_grabbed_usages[] = {
1397 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1398 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1399 };
1400
1401 static struct hid_driver mt_driver = {
1402 .name = "hid-multitouch",
1403 .id_table = mt_devices,
1404 .probe = mt_probe,
1405 .remove = mt_remove,
1406 .input_mapping = mt_input_mapping,
1407 .input_mapped = mt_input_mapped,
1408 .input_configured = mt_input_configured,
1409 .feature_mapping = mt_feature_mapping,
1410 .usage_table = mt_grabbed_usages,
1411 .event = mt_event,
1412 .report = mt_report,
1413 #ifdef CONFIG_PM
1414 .reset_resume = mt_reset_resume,
1415 .resume = mt_resume,
1416 #endif
1417 };
1418 module_hid_driver(mt_driver);
1419