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