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