1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * HID driver for multitouch panels
4 *
5 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
6 * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
7 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
8 * Copyright (c) 2012-2013 Red Hat, Inc
9 *
10 * This code is partly based on hid-egalax.c:
11 *
12 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
13 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
14 * Copyright (c) 2010 Canonical, Ltd.
15 *
16 * This code is partly based on hid-3m-pct.c:
17 *
18 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
19 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
20 * Copyright (c) 2010 Canonical, Ltd.
21 */
22
23 /*
24 */
25
26 /*
27 * This driver is regularly tested thanks to the test suite in hid-tools[1].
28 * Please run these regression tests before patching this module so that
29 * your patch won't break existing known devices.
30 *
31 * [1] https://gitlab.freedesktop.org/libevdev/hid-tools
32 */
33
34 #include <linux/device.h>
35 #include <linux/hid.h>
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/input/mt.h>
39 #include <linux/jiffies.h>
40 #include <linux/string.h>
41 #include <linux/timer.h>
42
43
44 MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
45 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
46 MODULE_DESCRIPTION("HID multitouch panels");
47 MODULE_LICENSE("GPL");
48
49 #include "hid-ids.h"
50
51 /* quirks to control the device */
52 #define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
53 #define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
54 #define MT_QUIRK_CYPRESS BIT(2)
55 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
56 #define MT_QUIRK_ALWAYS_VALID BIT(4)
57 #define MT_QUIRK_VALID_IS_INRANGE BIT(5)
58 #define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
59 #define MT_QUIRK_CONFIDENCE BIT(7)
60 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
61 #define MT_QUIRK_NO_AREA BIT(9)
62 #define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
63 #define MT_QUIRK_HOVERING BIT(11)
64 #define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
65 #define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
66 #define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
67 #define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
68 #define MT_QUIRK_STICKY_FINGERS BIT(16)
69 #define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
70 #define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
71 #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19)
72 #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20)
73 #define MT_QUIRK_DISABLE_WAKEUP BIT(21)
74 #define MT_QUIRK_ORIENTATION_INVERT BIT(22)
75
76 #define MT_INPUTMODE_TOUCHSCREEN 0x02
77 #define MT_INPUTMODE_TOUCHPAD 0x03
78
79 #define MT_BUTTONTYPE_CLICKPAD 0
80
81 enum latency_mode {
82 HID_LATENCY_NORMAL = 0,
83 HID_LATENCY_HIGH = 1,
84 };
85
86 #define MT_IO_FLAGS_RUNNING 0
87 #define MT_IO_FLAGS_ACTIVE_SLOTS 1
88 #define MT_IO_FLAGS_PENDING_SLOTS 2
89
90 static const bool mtrue = true; /* default for true */
91 static const bool mfalse; /* default for false */
92 static const __s32 mzero; /* default for 0 */
93
94 #define DEFAULT_TRUE ((void *)&mtrue)
95 #define DEFAULT_FALSE ((void *)&mfalse)
96 #define DEFAULT_ZERO ((void *)&mzero)
97
98 struct mt_usages {
99 struct list_head list;
100 __s32 *x, *y, *cx, *cy, *p, *w, *h, *a;
101 __s32 *contactid; /* the device ContactID assigned to this slot */
102 bool *tip_state; /* is the touch valid? */
103 bool *inrange_state; /* is the finger in proximity of the sensor? */
104 bool *confidence_state; /* is the touch made by a finger? */
105 };
106
107 struct mt_application {
108 struct list_head list;
109 unsigned int application;
110 unsigned int report_id;
111 struct list_head mt_usages; /* mt usages list */
112
113 __s32 quirks;
114
115 __s32 *scantime; /* scantime reported */
116 __s32 scantime_logical_max; /* max value for raw scantime */
117
118 __s32 *raw_cc; /* contact count in the report */
119 int left_button_state; /* left button state */
120 unsigned int mt_flags; /* flags to pass to input-mt */
121
122 unsigned long *pending_palm_slots; /* slots where we reported palm
123 * and need to release */
124
125 __u8 num_received; /* how many contacts we received */
126 __u8 num_expected; /* expected last contact index */
127 __u8 buttons_count; /* number of physical buttons per touchpad */
128 __u8 touches_by_report; /* how many touches are present in one report:
129 * 1 means we should use a serial protocol
130 * > 1 means hybrid (multitouch) protocol
131 */
132
133 unsigned long jiffies; /* the frame's jiffies */
134 int timestamp; /* the timestamp to be sent */
135 int prev_scantime; /* scantime reported previously */
136
137 bool have_contact_count;
138 };
139
140 struct mt_class {
141 __s32 name; /* MT_CLS */
142 __s32 quirks;
143 __s32 sn_move; /* Signal/noise ratio for move events */
144 __s32 sn_width; /* Signal/noise ratio for width events */
145 __s32 sn_height; /* Signal/noise ratio for height events */
146 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
147 __u8 maxcontacts;
148 bool is_indirect; /* true for touchpads */
149 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
150 };
151
152 struct mt_report_data {
153 struct list_head list;
154 struct hid_report *report;
155 struct mt_application *application;
156 bool is_mt_collection;
157 };
158
159 struct mt_device {
160 struct mt_class mtclass; /* our mt device class */
161 struct timer_list release_timer; /* to release sticky fingers */
162 struct hid_device *hdev; /* hid_device we're attached to */
163 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */
164 __u8 inputmode_value; /* InputMode HID feature value */
165 __u8 maxcontacts;
166 bool is_buttonpad; /* is this device a button pad? */
167 bool serial_maybe; /* need to check for serial protocol */
168
169 struct list_head applications;
170 struct list_head reports;
171 };
172
173 static void mt_post_parse_default_settings(struct mt_device *td,
174 struct mt_application *app);
175 static void mt_post_parse(struct mt_device *td, struct mt_application *app);
176
177 /* classes of device behavior */
178 #define MT_CLS_DEFAULT 0x0001
179
180 #define MT_CLS_SERIAL 0x0002
181 #define MT_CLS_CONFIDENCE 0x0003
182 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
183 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
184 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
185 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
186 /* reserved 0x0008 */
187 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
188 #define MT_CLS_NSMU 0x000a
189 /* reserved 0x0010 */
190 /* reserved 0x0011 */
191 #define MT_CLS_WIN_8 0x0012
192 #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
193 /* reserved 0x0014 */
194 #define MT_CLS_WIN_8_FORCE_MULTI_INPUT 0x0015
195 #define MT_CLS_WIN_8_DISABLE_WAKEUP 0x0016
196 #define MT_CLS_WIN_8_NO_STICKY_FINGERS 0x0017
197 #define MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU 0x0018
198
199 /* vendor specific classes */
200 #define MT_CLS_3M 0x0101
201 /* reserved 0x0102 */
202 #define MT_CLS_EGALAX 0x0103
203 #define MT_CLS_EGALAX_SERIAL 0x0104
204 #define MT_CLS_TOPSEED 0x0105
205 #define MT_CLS_PANASONIC 0x0106
206 #define MT_CLS_FLATFROG 0x0107
207 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
208 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
209 #define MT_CLS_LG 0x010a
210 #define MT_CLS_ASUS 0x010b
211 #define MT_CLS_VTL 0x0110
212 #define MT_CLS_GOOGLE 0x0111
213 #define MT_CLS_RAZER_BLADE_STEALTH 0x0112
214 #define MT_CLS_SMART_TECH 0x0113
215 #define MT_CLS_SIS 0x0457
216
217 #define MT_DEFAULT_MAXCONTACT 10
218 #define MT_MAX_MAXCONTACT 250
219
220 /*
221 * Resync device and local timestamps after that many microseconds without
222 * receiving data.
223 */
224 #define MAX_TIMESTAMP_INTERVAL 1000000
225
226 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
227 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
228
229 /*
230 * these device-dependent functions determine what slot corresponds
231 * to a valid contact that was just read.
232 */
233
cypress_compute_slot(struct mt_application * application,struct mt_usages * slot)234 static int cypress_compute_slot(struct mt_application *application,
235 struct mt_usages *slot)
236 {
237 if (*slot->contactid != 0 || application->num_received == 0)
238 return *slot->contactid;
239 else
240 return -1;
241 }
242
243 static const struct mt_class mt_classes[] = {
244 { .name = MT_CLS_DEFAULT,
245 .quirks = MT_QUIRK_ALWAYS_VALID |
246 MT_QUIRK_CONTACT_CNT_ACCURATE },
247 { .name = MT_CLS_NSMU,
248 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
249 { .name = MT_CLS_SERIAL,
250 .quirks = MT_QUIRK_ALWAYS_VALID},
251 { .name = MT_CLS_CONFIDENCE,
252 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
253 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
254 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
255 MT_QUIRK_SLOT_IS_CONTACTID },
256 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
257 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
258 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
259 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
260 .quirks = MT_QUIRK_VALID_IS_INRANGE |
261 MT_QUIRK_SLOT_IS_CONTACTID,
262 .maxcontacts = 2 },
263 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
264 .quirks = MT_QUIRK_VALID_IS_INRANGE |
265 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
266 .maxcontacts = 2 },
267 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
268 .quirks = MT_QUIRK_VALID_IS_INRANGE |
269 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
270 { .name = MT_CLS_WIN_8,
271 .quirks = MT_QUIRK_ALWAYS_VALID |
272 MT_QUIRK_IGNORE_DUPLICATES |
273 MT_QUIRK_HOVERING |
274 MT_QUIRK_CONTACT_CNT_ACCURATE |
275 MT_QUIRK_STICKY_FINGERS |
276 MT_QUIRK_WIN8_PTP_BUTTONS,
277 .export_all_inputs = true },
278 { .name = MT_CLS_EXPORT_ALL_INPUTS,
279 .quirks = MT_QUIRK_ALWAYS_VALID |
280 MT_QUIRK_CONTACT_CNT_ACCURATE,
281 .export_all_inputs = true },
282 { .name = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
283 .quirks = MT_QUIRK_ALWAYS_VALID |
284 MT_QUIRK_IGNORE_DUPLICATES |
285 MT_QUIRK_HOVERING |
286 MT_QUIRK_CONTACT_CNT_ACCURATE |
287 MT_QUIRK_STICKY_FINGERS |
288 MT_QUIRK_WIN8_PTP_BUTTONS |
289 MT_QUIRK_FORCE_MULTI_INPUT,
290 .export_all_inputs = true },
291 { .name = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
292 .quirks = MT_QUIRK_IGNORE_DUPLICATES |
293 MT_QUIRK_HOVERING |
294 MT_QUIRK_CONTACT_CNT_ACCURATE |
295 MT_QUIRK_STICKY_FINGERS |
296 MT_QUIRK_WIN8_PTP_BUTTONS |
297 MT_QUIRK_FORCE_MULTI_INPUT |
298 MT_QUIRK_NOT_SEEN_MEANS_UP,
299 .export_all_inputs = true },
300 { .name = MT_CLS_WIN_8_DISABLE_WAKEUP,
301 .quirks = MT_QUIRK_ALWAYS_VALID |
302 MT_QUIRK_IGNORE_DUPLICATES |
303 MT_QUIRK_HOVERING |
304 MT_QUIRK_CONTACT_CNT_ACCURATE |
305 MT_QUIRK_STICKY_FINGERS |
306 MT_QUIRK_WIN8_PTP_BUTTONS |
307 MT_QUIRK_DISABLE_WAKEUP,
308 .export_all_inputs = true },
309 { .name = MT_CLS_WIN_8_NO_STICKY_FINGERS,
310 .quirks = MT_QUIRK_ALWAYS_VALID |
311 MT_QUIRK_IGNORE_DUPLICATES |
312 MT_QUIRK_HOVERING |
313 MT_QUIRK_CONTACT_CNT_ACCURATE |
314 MT_QUIRK_WIN8_PTP_BUTTONS,
315 .export_all_inputs = true },
316
317 /*
318 * vendor specific classes
319 */
320 { .name = MT_CLS_3M,
321 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
322 MT_QUIRK_SLOT_IS_CONTACTID |
323 MT_QUIRK_TOUCH_SIZE_SCALING,
324 .sn_move = 2048,
325 .sn_width = 128,
326 .sn_height = 128,
327 .maxcontacts = 60,
328 },
329 { .name = MT_CLS_EGALAX,
330 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
331 MT_QUIRK_VALID_IS_INRANGE,
332 .sn_move = 4096,
333 .sn_pressure = 32,
334 },
335 { .name = MT_CLS_EGALAX_SERIAL,
336 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
337 MT_QUIRK_ALWAYS_VALID,
338 .sn_move = 4096,
339 .sn_pressure = 32,
340 },
341 { .name = MT_CLS_TOPSEED,
342 .quirks = MT_QUIRK_ALWAYS_VALID,
343 .is_indirect = true,
344 .maxcontacts = 2,
345 },
346 { .name = MT_CLS_PANASONIC,
347 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
348 .maxcontacts = 4 },
349 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
350 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
351 MT_QUIRK_VALID_IS_INRANGE |
352 MT_QUIRK_SLOT_IS_CONTACTID,
353 .maxcontacts = 2
354 },
355 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
356 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
357 MT_QUIRK_SLOT_IS_CONTACTID
358 },
359
360 { .name = MT_CLS_FLATFROG,
361 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
362 MT_QUIRK_NO_AREA,
363 .sn_move = 2048,
364 .maxcontacts = 40,
365 },
366 { .name = MT_CLS_LG,
367 .quirks = MT_QUIRK_ALWAYS_VALID |
368 MT_QUIRK_FIX_CONST_CONTACT_ID |
369 MT_QUIRK_IGNORE_DUPLICATES |
370 MT_QUIRK_HOVERING |
371 MT_QUIRK_CONTACT_CNT_ACCURATE },
372 { .name = MT_CLS_ASUS,
373 .quirks = MT_QUIRK_ALWAYS_VALID |
374 MT_QUIRK_CONTACT_CNT_ACCURATE |
375 MT_QUIRK_ASUS_CUSTOM_UP },
376 { .name = MT_CLS_VTL,
377 .quirks = MT_QUIRK_ALWAYS_VALID |
378 MT_QUIRK_CONTACT_CNT_ACCURATE |
379 MT_QUIRK_FORCE_GET_FEATURE,
380 },
381 { .name = MT_CLS_GOOGLE,
382 .quirks = MT_QUIRK_ALWAYS_VALID |
383 MT_QUIRK_CONTACT_CNT_ACCURATE |
384 MT_QUIRK_SLOT_IS_CONTACTID |
385 MT_QUIRK_HOVERING
386 },
387 { .name = MT_CLS_RAZER_BLADE_STEALTH,
388 .quirks = MT_QUIRK_ALWAYS_VALID |
389 MT_QUIRK_IGNORE_DUPLICATES |
390 MT_QUIRK_HOVERING |
391 MT_QUIRK_CONTACT_CNT_ACCURATE |
392 MT_QUIRK_WIN8_PTP_BUTTONS,
393 },
394 { .name = MT_CLS_SMART_TECH,
395 .quirks = MT_QUIRK_ALWAYS_VALID |
396 MT_QUIRK_IGNORE_DUPLICATES |
397 MT_QUIRK_CONTACT_CNT_ACCURATE |
398 MT_QUIRK_SEPARATE_APP_REPORT,
399 },
400 { .name = MT_CLS_SIS,
401 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
402 MT_QUIRK_ALWAYS_VALID |
403 MT_QUIRK_CONTACT_CNT_ACCURATE,
404 },
405 { }
406 };
407
mt_show_quirks(struct device * dev,struct device_attribute * attr,char * buf)408 static ssize_t mt_show_quirks(struct device *dev,
409 struct device_attribute *attr,
410 char *buf)
411 {
412 struct hid_device *hdev = to_hid_device(dev);
413 struct mt_device *td = hid_get_drvdata(hdev);
414
415 return sprintf(buf, "%u\n", td->mtclass.quirks);
416 }
417
mt_set_quirks(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)418 static ssize_t mt_set_quirks(struct device *dev,
419 struct device_attribute *attr,
420 const char *buf, size_t count)
421 {
422 struct hid_device *hdev = to_hid_device(dev);
423 struct mt_device *td = hid_get_drvdata(hdev);
424 struct mt_application *application;
425
426 unsigned long val;
427
428 if (kstrtoul(buf, 0, &val))
429 return -EINVAL;
430
431 td->mtclass.quirks = val;
432
433 list_for_each_entry(application, &td->applications, list) {
434 application->quirks = val;
435 if (!application->have_contact_count)
436 application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
437 }
438
439 return count;
440 }
441
442 static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
443
444 static struct attribute *sysfs_attrs[] = {
445 &dev_attr_quirks.attr,
446 NULL
447 };
448
449 static const struct attribute_group mt_attribute_group = {
450 .attrs = sysfs_attrs
451 };
452
mt_get_feature(struct hid_device * hdev,struct hid_report * report)453 static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
454 {
455 int ret;
456 u32 size = hid_report_len(report);
457 u8 *buf;
458
459 /*
460 * Do not fetch the feature report if the device has been explicitly
461 * marked as non-capable.
462 */
463 if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
464 return;
465
466 buf = hid_alloc_report_buf(report, GFP_KERNEL);
467 if (!buf)
468 return;
469
470 ret = hid_hw_raw_request(hdev, report->id, buf, size,
471 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
472 if (ret < 0) {
473 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
474 report->id);
475 } else {
476 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
477 size, 0);
478 if (ret)
479 dev_warn(&hdev->dev, "failed to report feature\n");
480 }
481
482 kfree(buf);
483 }
484
mt_feature_mapping(struct hid_device * hdev,struct hid_field * field,struct hid_usage * usage)485 static void mt_feature_mapping(struct hid_device *hdev,
486 struct hid_field *field, struct hid_usage *usage)
487 {
488 struct mt_device *td = hid_get_drvdata(hdev);
489
490 switch (usage->hid) {
491 case HID_DG_CONTACTMAX:
492 mt_get_feature(hdev, field->report);
493
494 td->maxcontacts = field->value[0];
495 if (!td->maxcontacts &&
496 field->logical_maximum <= MT_MAX_MAXCONTACT)
497 td->maxcontacts = field->logical_maximum;
498 if (td->mtclass.maxcontacts)
499 /* check if the maxcontacts is given by the class */
500 td->maxcontacts = td->mtclass.maxcontacts;
501
502 break;
503 case HID_DG_BUTTONTYPE:
504 if (usage->usage_index >= field->report_count) {
505 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
506 break;
507 }
508
509 mt_get_feature(hdev, field->report);
510 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
511 td->is_buttonpad = true;
512
513 break;
514 case 0xff0000c5:
515 /* Retrieve the Win8 blob once to enable some devices */
516 if (usage->usage_index == 0)
517 mt_get_feature(hdev, field->report);
518 break;
519 }
520 }
521
set_abs(struct input_dev * input,unsigned int code,struct hid_field * field,int snratio)522 static void set_abs(struct input_dev *input, unsigned int code,
523 struct hid_field *field, int snratio)
524 {
525 int fmin = field->logical_minimum;
526 int fmax = field->logical_maximum;
527 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
528 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
529 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
530 }
531
mt_allocate_usage(struct hid_device * hdev,struct mt_application * application)532 static struct mt_usages *mt_allocate_usage(struct hid_device *hdev,
533 struct mt_application *application)
534 {
535 struct mt_usages *usage;
536
537 usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL);
538 if (!usage)
539 return NULL;
540
541 /* set some defaults so we do not need to check for null pointers */
542 usage->x = DEFAULT_ZERO;
543 usage->y = DEFAULT_ZERO;
544 usage->cx = DEFAULT_ZERO;
545 usage->cy = DEFAULT_ZERO;
546 usage->p = DEFAULT_ZERO;
547 usage->w = DEFAULT_ZERO;
548 usage->h = DEFAULT_ZERO;
549 usage->a = DEFAULT_ZERO;
550 usage->contactid = DEFAULT_ZERO;
551 usage->tip_state = DEFAULT_FALSE;
552 usage->inrange_state = DEFAULT_FALSE;
553 usage->confidence_state = DEFAULT_TRUE;
554
555 list_add_tail(&usage->list, &application->mt_usages);
556
557 return usage;
558 }
559
mt_allocate_application(struct mt_device * td,struct hid_report * report)560 static struct mt_application *mt_allocate_application(struct mt_device *td,
561 struct hid_report *report)
562 {
563 unsigned int application = report->application;
564 struct mt_application *mt_application;
565
566 mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
567 GFP_KERNEL);
568 if (!mt_application)
569 return NULL;
570
571 mt_application->application = application;
572 INIT_LIST_HEAD(&mt_application->mt_usages);
573
574 if (application == HID_DG_TOUCHSCREEN)
575 mt_application->mt_flags |= INPUT_MT_DIRECT;
576
577 /*
578 * Model touchscreens providing buttons as touchpads.
579 */
580 if (application == HID_DG_TOUCHPAD) {
581 mt_application->mt_flags |= INPUT_MT_POINTER;
582 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
583 }
584
585 mt_application->scantime = DEFAULT_ZERO;
586 mt_application->raw_cc = DEFAULT_ZERO;
587 mt_application->quirks = td->mtclass.quirks;
588 mt_application->report_id = report->id;
589
590 list_add_tail(&mt_application->list, &td->applications);
591
592 return mt_application;
593 }
594
mt_find_application(struct mt_device * td,struct hid_report * report)595 static struct mt_application *mt_find_application(struct mt_device *td,
596 struct hid_report *report)
597 {
598 unsigned int application = report->application;
599 struct mt_application *tmp, *mt_application = NULL;
600
601 list_for_each_entry(tmp, &td->applications, list) {
602 if (application == tmp->application) {
603 if (!(td->mtclass.quirks & MT_QUIRK_SEPARATE_APP_REPORT) ||
604 tmp->report_id == report->id) {
605 mt_application = tmp;
606 break;
607 }
608 }
609 }
610
611 if (!mt_application)
612 mt_application = mt_allocate_application(td, report);
613
614 return mt_application;
615 }
616
mt_allocate_report_data(struct mt_device * td,struct hid_report * report)617 static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
618 struct hid_report *report)
619 {
620 struct mt_report_data *rdata;
621 struct hid_field *field;
622 int r, n;
623
624 rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL);
625 if (!rdata)
626 return NULL;
627
628 rdata->report = report;
629 rdata->application = mt_find_application(td, report);
630
631 if (!rdata->application) {
632 devm_kfree(&td->hdev->dev, rdata);
633 return NULL;
634 }
635
636 for (r = 0; r < report->maxfield; r++) {
637 field = report->field[r];
638
639 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
640 continue;
641
642 if (field->logical == HID_DG_FINGER || td->hdev->group != HID_GROUP_MULTITOUCH_WIN_8) {
643 for (n = 0; n < field->report_count; n++) {
644 if (field->usage[n].hid == HID_DG_CONTACTID) {
645 rdata->is_mt_collection = true;
646 break;
647 }
648 }
649 }
650 }
651
652 list_add_tail(&rdata->list, &td->reports);
653
654 return rdata;
655 }
656
mt_find_report_data(struct mt_device * td,struct hid_report * report)657 static struct mt_report_data *mt_find_report_data(struct mt_device *td,
658 struct hid_report *report)
659 {
660 struct mt_report_data *tmp, *rdata = NULL;
661
662 list_for_each_entry(tmp, &td->reports, list) {
663 if (report == tmp->report) {
664 rdata = tmp;
665 break;
666 }
667 }
668
669 if (!rdata)
670 rdata = mt_allocate_report_data(td, report);
671
672 return rdata;
673 }
674
mt_store_field(struct hid_device * hdev,struct mt_application * application,__s32 * value,size_t offset)675 static void mt_store_field(struct hid_device *hdev,
676 struct mt_application *application,
677 __s32 *value,
678 size_t offset)
679 {
680 struct mt_usages *usage;
681 __s32 **target;
682
683 if (list_empty(&application->mt_usages))
684 usage = mt_allocate_usage(hdev, application);
685 else
686 usage = list_last_entry(&application->mt_usages,
687 struct mt_usages,
688 list);
689
690 if (!usage)
691 return;
692
693 target = (__s32 **)((char *)usage + offset);
694
695 /* the value has already been filled, create a new slot */
696 if (*target != DEFAULT_TRUE &&
697 *target != DEFAULT_FALSE &&
698 *target != DEFAULT_ZERO) {
699 if (usage->contactid == DEFAULT_ZERO ||
700 usage->x == DEFAULT_ZERO ||
701 usage->y == DEFAULT_ZERO) {
702 hid_dbg(hdev,
703 "ignoring duplicate usage on incomplete");
704 return;
705 }
706 usage = mt_allocate_usage(hdev, application);
707 if (!usage)
708 return;
709
710 target = (__s32 **)((char *)usage + offset);
711 }
712
713 *target = value;
714 }
715
716 #define MT_STORE_FIELD(__name) \
717 mt_store_field(hdev, app, \
718 &field->value[usage->usage_index], \
719 offsetof(struct mt_usages, __name))
720
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,struct mt_application * app)721 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
722 struct hid_field *field, struct hid_usage *usage,
723 unsigned long **bit, int *max, struct mt_application *app)
724 {
725 struct mt_device *td = hid_get_drvdata(hdev);
726 struct mt_class *cls = &td->mtclass;
727 int code;
728 struct hid_usage *prev_usage = NULL;
729
730 /*
731 * Model touchscreens providing buttons as touchpads.
732 */
733 if (field->application == HID_DG_TOUCHSCREEN &&
734 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
735 app->mt_flags |= INPUT_MT_POINTER;
736 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
737 }
738
739 /* count the buttons on touchpads */
740 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
741 app->buttons_count++;
742
743 if (usage->usage_index)
744 prev_usage = &field->usage[usage->usage_index - 1];
745
746 switch (usage->hid & HID_USAGE_PAGE) {
747
748 case HID_UP_GENDESK:
749 switch (usage->hid) {
750 case HID_GD_X:
751 if (prev_usage && (prev_usage->hid == usage->hid)) {
752 code = ABS_MT_TOOL_X;
753 MT_STORE_FIELD(cx);
754 } else {
755 code = ABS_MT_POSITION_X;
756 MT_STORE_FIELD(x);
757 }
758
759 set_abs(hi->input, code, field, cls->sn_move);
760
761 /*
762 * A system multi-axis that exports X and Y has a high
763 * chance of being used directly on a surface
764 */
765 if (field->application == HID_GD_SYSTEM_MULTIAXIS) {
766 __set_bit(INPUT_PROP_DIRECT,
767 hi->input->propbit);
768 input_set_abs_params(hi->input,
769 ABS_MT_TOOL_TYPE,
770 MT_TOOL_DIAL,
771 MT_TOOL_DIAL, 0, 0);
772 }
773
774 return 1;
775 case HID_GD_Y:
776 if (prev_usage && (prev_usage->hid == usage->hid)) {
777 code = ABS_MT_TOOL_Y;
778 MT_STORE_FIELD(cy);
779 } else {
780 code = ABS_MT_POSITION_Y;
781 MT_STORE_FIELD(y);
782 }
783
784 set_abs(hi->input, code, field, cls->sn_move);
785
786 return 1;
787 }
788 return 0;
789
790 case HID_UP_DIGITIZER:
791 switch (usage->hid) {
792 case HID_DG_INRANGE:
793 if (app->quirks & MT_QUIRK_HOVERING) {
794 input_set_abs_params(hi->input,
795 ABS_MT_DISTANCE, 0, 1, 0, 0);
796 }
797 MT_STORE_FIELD(inrange_state);
798 return 1;
799 case HID_DG_CONFIDENCE:
800 if ((cls->name == MT_CLS_WIN_8 ||
801 cls->name == MT_CLS_WIN_8_FORCE_MULTI_INPUT ||
802 cls->name == MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU ||
803 cls->name == MT_CLS_WIN_8_DISABLE_WAKEUP) &&
804 (field->application == HID_DG_TOUCHPAD ||
805 field->application == HID_DG_TOUCHSCREEN))
806 app->quirks |= MT_QUIRK_CONFIDENCE;
807
808 if (app->quirks & MT_QUIRK_CONFIDENCE)
809 input_set_abs_params(hi->input,
810 ABS_MT_TOOL_TYPE,
811 MT_TOOL_FINGER,
812 MT_TOOL_PALM, 0, 0);
813
814 MT_STORE_FIELD(confidence_state);
815 return 1;
816 case HID_DG_TIPSWITCH:
817 if (field->application != HID_GD_SYSTEM_MULTIAXIS)
818 input_set_capability(hi->input,
819 EV_KEY, BTN_TOUCH);
820 MT_STORE_FIELD(tip_state);
821 return 1;
822 case HID_DG_CONTACTID:
823 MT_STORE_FIELD(contactid);
824 app->touches_by_report++;
825 return 1;
826 case HID_DG_WIDTH:
827 if (!(app->quirks & MT_QUIRK_NO_AREA))
828 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
829 cls->sn_width);
830 MT_STORE_FIELD(w);
831 return 1;
832 case HID_DG_HEIGHT:
833 if (!(app->quirks & MT_QUIRK_NO_AREA)) {
834 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
835 cls->sn_height);
836
837 /*
838 * Only set ABS_MT_ORIENTATION if it is not
839 * already set by the HID_DG_AZIMUTH usage.
840 */
841 if (!test_bit(ABS_MT_ORIENTATION,
842 hi->input->absbit))
843 input_set_abs_params(hi->input,
844 ABS_MT_ORIENTATION, 0, 1, 0, 0);
845 }
846 MT_STORE_FIELD(h);
847 return 1;
848 case HID_DG_TIPPRESSURE:
849 set_abs(hi->input, ABS_MT_PRESSURE, field,
850 cls->sn_pressure);
851 MT_STORE_FIELD(p);
852 return 1;
853 case HID_DG_SCANTIME:
854 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
855 app->scantime = &field->value[usage->usage_index];
856 app->scantime_logical_max = field->logical_maximum;
857 return 1;
858 case HID_DG_CONTACTCOUNT:
859 app->have_contact_count = true;
860 app->raw_cc = &field->value[usage->usage_index];
861 return 1;
862 case HID_DG_AZIMUTH:
863 /*
864 * Azimuth has the range of [0, MAX) representing a full
865 * revolution. Set ABS_MT_ORIENTATION to a quarter of
866 * MAX according the definition of ABS_MT_ORIENTATION
867 */
868 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
869 -field->logical_maximum / 4,
870 field->logical_maximum / 4,
871 cls->sn_move ?
872 field->logical_maximum / cls->sn_move : 0, 0);
873 MT_STORE_FIELD(a);
874 return 1;
875 case HID_DG_CONTACTMAX:
876 /* contact max are global to the report */
877 return -1;
878 case HID_DG_TOUCH:
879 /* Legacy devices use TIPSWITCH and not TOUCH.
880 * Let's just ignore this field. */
881 return -1;
882 }
883 /* let hid-input decide for the others */
884 return 0;
885
886 case HID_UP_BUTTON:
887 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
888 /*
889 * MS PTP spec says that external buttons left and right have
890 * usages 2 and 3.
891 */
892 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
893 field->application == HID_DG_TOUCHPAD &&
894 (usage->hid & HID_USAGE) > 1)
895 code--;
896
897 if (field->application == HID_GD_SYSTEM_MULTIAXIS)
898 code = BTN_0 + ((usage->hid - 1) & HID_USAGE);
899
900 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
901 if (!*bit)
902 return -1;
903 input_set_capability(hi->input, EV_KEY, code);
904 return 1;
905
906 case 0xff000000:
907 /* we do not want to map these: no input-oriented meaning */
908 return -1;
909 }
910
911 return 0;
912 }
913
mt_compute_slot(struct mt_device * td,struct mt_application * app,struct mt_usages * slot,struct input_dev * input)914 static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
915 struct mt_usages *slot,
916 struct input_dev *input)
917 {
918 __s32 quirks = app->quirks;
919
920 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
921 return *slot->contactid;
922
923 if (quirks & MT_QUIRK_CYPRESS)
924 return cypress_compute_slot(app, slot);
925
926 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
927 return app->num_received;
928
929 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
930 return *slot->contactid - 1;
931
932 return input_mt_get_slot_by_key(input, *slot->contactid);
933 }
934
mt_release_pending_palms(struct mt_device * td,struct mt_application * app,struct input_dev * input)935 static void mt_release_pending_palms(struct mt_device *td,
936 struct mt_application *app,
937 struct input_dev *input)
938 {
939 int slotnum;
940 bool need_sync = false;
941
942 for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) {
943 clear_bit(slotnum, app->pending_palm_slots);
944
945 input_mt_slot(input, slotnum);
946 input_mt_report_slot_inactive(input);
947
948 need_sync = true;
949 }
950
951 if (need_sync) {
952 input_mt_sync_frame(input);
953 input_sync(input);
954 }
955 }
956
957 /*
958 * this function is called when a whole packet has been received and processed,
959 * so that it can decide what to send to the input layer.
960 */
mt_sync_frame(struct mt_device * td,struct mt_application * app,struct input_dev * input)961 static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
962 struct input_dev *input)
963 {
964 if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
965 input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
966
967 input_mt_sync_frame(input);
968 input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
969 input_sync(input);
970
971 mt_release_pending_palms(td, app, input);
972
973 app->num_received = 0;
974 app->left_button_state = 0;
975
976 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
977 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
978 else
979 clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
980 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
981 }
982
mt_compute_timestamp(struct mt_application * app,__s32 value)983 static int mt_compute_timestamp(struct mt_application *app, __s32 value)
984 {
985 long delta = value - app->prev_scantime;
986 unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
987
988 app->jiffies = jiffies;
989
990 if (delta < 0)
991 delta += app->scantime_logical_max;
992
993 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */
994 delta *= 100;
995
996 if (jdelta > MAX_TIMESTAMP_INTERVAL)
997 /* No data received for a while, resync the timestamp. */
998 return 0;
999 else
1000 return app->timestamp + delta;
1001 }
1002
mt_touch_event(struct hid_device * hid,struct hid_field * field,struct hid_usage * usage,__s32 value)1003 static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
1004 struct hid_usage *usage, __s32 value)
1005 {
1006 /* we will handle the hidinput part later, now remains hiddev */
1007 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
1008 hid->hiddev_hid_event(hid, field, usage, value);
1009
1010 return 1;
1011 }
1012
mt_process_slot(struct mt_device * td,struct input_dev * input,struct mt_application * app,struct mt_usages * slot)1013 static int mt_process_slot(struct mt_device *td, struct input_dev *input,
1014 struct mt_application *app,
1015 struct mt_usages *slot)
1016 {
1017 struct input_mt *mt = input->mt;
1018 struct hid_device *hdev = td->hdev;
1019 __s32 quirks = app->quirks;
1020 bool valid = true;
1021 bool confidence_state = true;
1022 bool inrange_state = false;
1023 int active;
1024 int slotnum;
1025 int tool = MT_TOOL_FINGER;
1026
1027 if (!slot)
1028 return -EINVAL;
1029
1030 if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
1031 app->num_received >= app->num_expected)
1032 return -EAGAIN;
1033
1034 if (!(quirks & MT_QUIRK_ALWAYS_VALID)) {
1035 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
1036 valid = *slot->inrange_state;
1037 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
1038 valid = *slot->tip_state;
1039 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
1040 valid = *slot->confidence_state;
1041
1042 if (!valid)
1043 return 0;
1044 }
1045
1046 slotnum = mt_compute_slot(td, app, slot, input);
1047 if (slotnum < 0 || slotnum >= td->maxcontacts)
1048 return 0;
1049
1050 if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
1051 struct input_mt_slot *i_slot = &mt->slots[slotnum];
1052
1053 if (input_mt_is_active(i_slot) &&
1054 input_mt_is_used(mt, i_slot))
1055 return -EAGAIN;
1056 }
1057
1058 if (quirks & MT_QUIRK_CONFIDENCE)
1059 confidence_state = *slot->confidence_state;
1060
1061 if (quirks & MT_QUIRK_HOVERING)
1062 inrange_state = *slot->inrange_state;
1063
1064 active = *slot->tip_state || inrange_state;
1065
1066 if (app->application == HID_GD_SYSTEM_MULTIAXIS)
1067 tool = MT_TOOL_DIAL;
1068 else if (unlikely(!confidence_state)) {
1069 tool = MT_TOOL_PALM;
1070 if (!active && mt &&
1071 input_mt_is_active(&mt->slots[slotnum])) {
1072 /*
1073 * The non-confidence was reported for
1074 * previously valid contact that is also no
1075 * longer valid. We can't simply report
1076 * lift-off as userspace will not be aware
1077 * of non-confidence, so we need to split
1078 * it into 2 events: active MT_TOOL_PALM
1079 * and a separate liftoff.
1080 */
1081 active = true;
1082 set_bit(slotnum, app->pending_palm_slots);
1083 }
1084 }
1085
1086 input_mt_slot(input, slotnum);
1087 input_mt_report_slot_state(input, tool, active);
1088 if (active) {
1089 /* this finger is in proximity of the sensor */
1090 int wide = (*slot->w > *slot->h);
1091 int major = max(*slot->w, *slot->h);
1092 int minor = min(*slot->w, *slot->h);
1093 int orientation = wide;
1094 int max_azimuth;
1095 int azimuth;
1096 int x;
1097 int y;
1098 int cx;
1099 int cy;
1100
1101 if (slot->a != DEFAULT_ZERO) {
1102 /*
1103 * Azimuth is counter-clockwise and ranges from [0, MAX)
1104 * (a full revolution). Convert it to clockwise ranging
1105 * [-MAX/2, MAX/2].
1106 *
1107 * Note that ABS_MT_ORIENTATION require us to report
1108 * the limit of [-MAX/4, MAX/4], but the value can go
1109 * out of range to [-MAX/2, MAX/2] to report an upside
1110 * down ellipsis.
1111 */
1112 azimuth = *slot->a;
1113 max_azimuth = input_abs_get_max(input,
1114 ABS_MT_ORIENTATION);
1115 if (azimuth > max_azimuth * 2)
1116 azimuth -= max_azimuth * 4;
1117 orientation = -azimuth;
1118 if (quirks & MT_QUIRK_ORIENTATION_INVERT)
1119 orientation = -orientation;
1120
1121 }
1122
1123 if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
1124 /*
1125 * divided by two to match visual scale of touch
1126 * for devices with this quirk
1127 */
1128 major = major >> 1;
1129 minor = minor >> 1;
1130 }
1131
1132 x = hdev->quirks & HID_QUIRK_X_INVERT ?
1133 input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x :
1134 *slot->x;
1135 y = hdev->quirks & HID_QUIRK_Y_INVERT ?
1136 input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->y :
1137 *slot->y;
1138 cx = hdev->quirks & HID_QUIRK_X_INVERT ?
1139 input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->cx :
1140 *slot->cx;
1141 cy = hdev->quirks & HID_QUIRK_Y_INVERT ?
1142 input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->cy :
1143 *slot->cy;
1144
1145 input_event(input, EV_ABS, ABS_MT_POSITION_X, x);
1146 input_event(input, EV_ABS, ABS_MT_POSITION_Y, y);
1147 input_event(input, EV_ABS, ABS_MT_TOOL_X, cx);
1148 input_event(input, EV_ABS, ABS_MT_TOOL_Y, cy);
1149 input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state);
1150 input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation);
1151 input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p);
1152 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
1153 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
1154
1155 set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
1156 }
1157
1158 return 0;
1159 }
1160
mt_process_mt_event(struct hid_device * hid,struct mt_application * app,struct hid_field * field,struct hid_usage * usage,__s32 value,bool first_packet)1161 static void mt_process_mt_event(struct hid_device *hid,
1162 struct mt_application *app,
1163 struct hid_field *field,
1164 struct hid_usage *usage,
1165 __s32 value,
1166 bool first_packet)
1167 {
1168 __s32 quirks = app->quirks;
1169 struct input_dev *input = field->hidinput->input;
1170
1171 if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT))
1172 return;
1173
1174 if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) {
1175
1176 /*
1177 * For Win8 PTP touchpads we should only look at
1178 * non finger/touch events in the first_packet of a
1179 * (possible) multi-packet frame.
1180 */
1181 if (!first_packet)
1182 return;
1183
1184 /*
1185 * For Win8 PTP touchpads we map both the clickpad click
1186 * and any "external" left buttons to BTN_LEFT if a
1187 * device claims to have both we need to report 1 for
1188 * BTN_LEFT if either is pressed, so we or all values
1189 * together and report the result in mt_sync_frame().
1190 */
1191 if (usage->type == EV_KEY && usage->code == BTN_LEFT) {
1192 app->left_button_state |= value;
1193 return;
1194 }
1195 }
1196
1197 input_event(input, usage->type, usage->code, value);
1198 }
1199
mt_touch_report(struct hid_device * hid,struct mt_report_data * rdata)1200 static void mt_touch_report(struct hid_device *hid,
1201 struct mt_report_data *rdata)
1202 {
1203 struct mt_device *td = hid_get_drvdata(hid);
1204 struct hid_report *report = rdata->report;
1205 struct mt_application *app = rdata->application;
1206 struct hid_field *field;
1207 struct input_dev *input;
1208 struct mt_usages *slot;
1209 bool first_packet;
1210 unsigned count;
1211 int r, n;
1212 int scantime = 0;
1213 int contact_count = -1;
1214
1215 /* sticky fingers release in progress, abort */
1216 if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1217 return;
1218
1219 scantime = *app->scantime;
1220 app->timestamp = mt_compute_timestamp(app, scantime);
1221 if (app->raw_cc != DEFAULT_ZERO)
1222 contact_count = *app->raw_cc;
1223
1224 /*
1225 * Includes multi-packet support where subsequent
1226 * packets are sent with zero contactcount.
1227 */
1228 if (contact_count >= 0) {
1229 /*
1230 * For Win8 PTPs the first packet (td->num_received == 0) may
1231 * have a contactcount of 0 if there only is a button event.
1232 * We double check that this is not a continuation packet
1233 * of a possible multi-packet frame be checking that the
1234 * timestamp has changed.
1235 */
1236 if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
1237 app->num_received == 0 &&
1238 app->prev_scantime != scantime)
1239 app->num_expected = contact_count;
1240 /* A non 0 contact count always indicates a first packet */
1241 else if (contact_count)
1242 app->num_expected = contact_count;
1243 }
1244 app->prev_scantime = scantime;
1245
1246 first_packet = app->num_received == 0;
1247
1248 input = report->field[0]->hidinput->input;
1249
1250 list_for_each_entry(slot, &app->mt_usages, list) {
1251 if (!mt_process_slot(td, input, app, slot))
1252 app->num_received++;
1253 }
1254
1255 for (r = 0; r < report->maxfield; r++) {
1256 field = report->field[r];
1257 count = field->report_count;
1258
1259 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1260 continue;
1261
1262 for (n = 0; n < count; n++)
1263 mt_process_mt_event(hid, app, field,
1264 &field->usage[n], field->value[n],
1265 first_packet);
1266 }
1267
1268 if (app->num_received >= app->num_expected)
1269 mt_sync_frame(td, app, input);
1270
1271 /*
1272 * Windows 8 specs says 2 things:
1273 * - once a contact has been reported, it has to be reported in each
1274 * subsequent report
1275 * - the report rate when fingers are present has to be at least
1276 * the refresh rate of the screen, 60 or 120 Hz
1277 *
1278 * I interprete this that the specification forces a report rate of
1279 * at least 60 Hz for a touchscreen to be certified.
1280 * Which means that if we do not get a report whithin 16 ms, either
1281 * something wrong happens, either the touchscreen forgets to send
1282 * a release. Taking a reasonable margin allows to remove issues
1283 * with USB communication or the load of the machine.
1284 *
1285 * Given that Win 8 devices are forced to send a release, this will
1286 * only affect laggish machines and the ones that have a firmware
1287 * defect.
1288 */
1289 if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
1290 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1291 mod_timer(&td->release_timer,
1292 jiffies + msecs_to_jiffies(100));
1293 else
1294 del_timer(&td->release_timer);
1295 }
1296
1297 clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1298 }
1299
mt_touch_input_configured(struct hid_device * hdev,struct hid_input * hi,struct mt_application * app)1300 static int mt_touch_input_configured(struct hid_device *hdev,
1301 struct hid_input *hi,
1302 struct mt_application *app)
1303 {
1304 struct mt_device *td = hid_get_drvdata(hdev);
1305 struct mt_class *cls = &td->mtclass;
1306 struct input_dev *input = hi->input;
1307 int ret;
1308
1309 if (!td->maxcontacts)
1310 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1311
1312 mt_post_parse(td, app);
1313 if (td->serial_maybe)
1314 mt_post_parse_default_settings(td, app);
1315
1316 if (cls->is_indirect)
1317 app->mt_flags |= INPUT_MT_POINTER;
1318
1319 if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
1320 app->mt_flags |= INPUT_MT_DROP_UNUSED;
1321
1322 /* check for clickpads */
1323 if ((app->mt_flags & INPUT_MT_POINTER) &&
1324 (app->buttons_count == 1))
1325 td->is_buttonpad = true;
1326
1327 if (td->is_buttonpad)
1328 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1329
1330 app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
1331 BITS_TO_LONGS(td->maxcontacts),
1332 sizeof(long),
1333 GFP_KERNEL);
1334 if (!app->pending_palm_slots)
1335 return -ENOMEM;
1336
1337 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
1338 if (ret)
1339 return ret;
1340
1341 app->mt_flags = 0;
1342 return 0;
1343 }
1344
1345 #define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1346 max, EV_KEY, (c))
mt_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)1347 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1348 struct hid_field *field, struct hid_usage *usage,
1349 unsigned long **bit, int *max)
1350 {
1351 struct mt_device *td = hid_get_drvdata(hdev);
1352 struct mt_application *application;
1353 struct mt_report_data *rdata;
1354
1355 rdata = mt_find_report_data(td, field->report);
1356 if (!rdata) {
1357 hid_err(hdev, "failed to allocate data for report\n");
1358 return 0;
1359 }
1360
1361 application = rdata->application;
1362
1363 /*
1364 * If mtclass.export_all_inputs is not set, only map fields from
1365 * TouchScreen or TouchPad collections. We need to ignore fields
1366 * that belong to other collections such as Mouse that might have
1367 * the same GenericDesktop usages.
1368 */
1369 if (!td->mtclass.export_all_inputs &&
1370 field->application != HID_DG_TOUCHSCREEN &&
1371 field->application != HID_DG_PEN &&
1372 field->application != HID_DG_TOUCHPAD &&
1373 field->application != HID_GD_KEYBOARD &&
1374 field->application != HID_GD_SYSTEM_CONTROL &&
1375 field->application != HID_CP_CONSUMER_CONTROL &&
1376 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
1377 field->application != HID_GD_SYSTEM_MULTIAXIS &&
1378 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1379 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
1380 return -1;
1381
1382 /*
1383 * Some Asus keyboard+touchpad devices have the hotkeys defined in the
1384 * touchpad report descriptor. We need to treat these as an array to
1385 * map usages to input keys.
1386 */
1387 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1388 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
1389 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1390 set_bit(EV_REP, hi->input->evbit);
1391 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1392 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1393 switch (usage->hid & HID_USAGE) {
1394 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1395 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1396 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1397 case 0x6b: mt_map_key_clear(KEY_F21); break;
1398 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1399 default:
1400 return -1;
1401 }
1402 return 1;
1403 }
1404
1405 if (rdata->is_mt_collection)
1406 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1407 application);
1408
1409 /*
1410 * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1411 * for the stylus. Overwrite the hid_input application
1412 */
1413 if (field->physical == HID_DG_STYLUS)
1414 hi->application = HID_DG_STYLUS;
1415
1416 /* let hid-core decide for the others */
1417 return 0;
1418 }
1419
mt_input_mapped(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)1420 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1421 struct hid_field *field, struct hid_usage *usage,
1422 unsigned long **bit, int *max)
1423 {
1424 struct mt_device *td = hid_get_drvdata(hdev);
1425 struct mt_report_data *rdata;
1426
1427 rdata = mt_find_report_data(td, field->report);
1428 if (rdata && rdata->is_mt_collection) {
1429 /* We own these mappings, tell hid-input to ignore them */
1430 return -1;
1431 }
1432
1433 /* let hid-core decide for the others */
1434 return 0;
1435 }
1436
mt_event(struct hid_device * hid,struct hid_field * field,struct hid_usage * usage,__s32 value)1437 static int mt_event(struct hid_device *hid, struct hid_field *field,
1438 struct hid_usage *usage, __s32 value)
1439 {
1440 struct mt_device *td = hid_get_drvdata(hid);
1441 struct mt_report_data *rdata;
1442
1443 rdata = mt_find_report_data(td, field->report);
1444 if (rdata && rdata->is_mt_collection)
1445 return mt_touch_event(hid, field, usage, value);
1446
1447 return 0;
1448 }
1449
mt_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * size)1450 static const __u8 *mt_report_fixup(struct hid_device *hdev, __u8 *rdesc,
1451 unsigned int *size)
1452 {
1453 if (hdev->vendor == I2C_VENDOR_ID_GOODIX &&
1454 (hdev->product == I2C_DEVICE_ID_GOODIX_01E8 ||
1455 hdev->product == I2C_DEVICE_ID_GOODIX_01E9)) {
1456 if (*size < 608) {
1457 dev_info(
1458 &hdev->dev,
1459 "GT7868Q fixup: report descriptor is only %u bytes, skipping\n",
1460 *size);
1461 return rdesc;
1462 }
1463
1464 if (rdesc[607] == 0x15) {
1465 rdesc[607] = 0x25;
1466 dev_info(
1467 &hdev->dev,
1468 "GT7868Q report descriptor fixup is applied.\n");
1469 } else {
1470 dev_info(
1471 &hdev->dev,
1472 "The byte is not expected for fixing the report descriptor. \
1473 It's possible that the touchpad firmware is not suitable for applying the fix. \
1474 got: %x\n",
1475 rdesc[607]);
1476 }
1477 }
1478
1479 return rdesc;
1480 }
1481
mt_report(struct hid_device * hid,struct hid_report * report)1482 static void mt_report(struct hid_device *hid, struct hid_report *report)
1483 {
1484 struct mt_device *td = hid_get_drvdata(hid);
1485 struct hid_field *field = report->field[0];
1486 struct mt_report_data *rdata;
1487
1488 if (!(hid->claimed & HID_CLAIMED_INPUT))
1489 return;
1490
1491 rdata = mt_find_report_data(td, report);
1492 if (rdata && rdata->is_mt_collection)
1493 return mt_touch_report(hid, rdata);
1494
1495 if (field && field->hidinput && field->hidinput->input)
1496 input_sync(field->hidinput->input);
1497 }
1498
mt_need_to_apply_feature(struct hid_device * hdev,struct hid_field * field,struct hid_usage * usage,enum latency_mode latency,bool surface_switch,bool button_switch,bool * inputmode_found)1499 static bool mt_need_to_apply_feature(struct hid_device *hdev,
1500 struct hid_field *field,
1501 struct hid_usage *usage,
1502 enum latency_mode latency,
1503 bool surface_switch,
1504 bool button_switch,
1505 bool *inputmode_found)
1506 {
1507 struct mt_device *td = hid_get_drvdata(hdev);
1508 struct mt_class *cls = &td->mtclass;
1509 struct hid_report *report = field->report;
1510 unsigned int index = usage->usage_index;
1511 char *buf;
1512 u32 report_len;
1513 int max;
1514
1515 switch (usage->hid) {
1516 case HID_DG_INPUTMODE:
1517 /*
1518 * Some elan panels wrongly declare 2 input mode features,
1519 * and silently ignore when we set the value in the second
1520 * field. Skip the second feature and hope for the best.
1521 */
1522 if (*inputmode_found)
1523 return false;
1524
1525 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
1526 report_len = hid_report_len(report);
1527 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1528 if (!buf) {
1529 hid_err(hdev,
1530 "failed to allocate buffer for report\n");
1531 return false;
1532 }
1533 hid_hw_raw_request(hdev, report->id, buf, report_len,
1534 HID_FEATURE_REPORT,
1535 HID_REQ_GET_REPORT);
1536 kfree(buf);
1537 }
1538
1539 field->value[index] = td->inputmode_value;
1540 *inputmode_found = true;
1541 return true;
1542
1543 case HID_DG_CONTACTMAX:
1544 if (cls->maxcontacts) {
1545 max = min_t(int, field->logical_maximum,
1546 cls->maxcontacts);
1547 if (field->value[index] != max) {
1548 field->value[index] = max;
1549 return true;
1550 }
1551 }
1552 break;
1553
1554 case HID_DG_LATENCYMODE:
1555 field->value[index] = latency;
1556 return true;
1557
1558 case HID_DG_SURFACESWITCH:
1559 field->value[index] = surface_switch;
1560 return true;
1561
1562 case HID_DG_BUTTONSWITCH:
1563 field->value[index] = button_switch;
1564 return true;
1565 }
1566
1567 return false; /* no need to update the report */
1568 }
1569
mt_set_modes(struct hid_device * hdev,enum latency_mode latency,bool surface_switch,bool button_switch)1570 static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1571 bool surface_switch, bool button_switch)
1572 {
1573 struct hid_report_enum *rep_enum;
1574 struct hid_report *rep;
1575 struct hid_usage *usage;
1576 int i, j;
1577 bool update_report;
1578 bool inputmode_found = false;
1579
1580 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1581 list_for_each_entry(rep, &rep_enum->report_list, list) {
1582 update_report = false;
1583
1584 for (i = 0; i < rep->maxfield; i++) {
1585 /* Ignore if report count is out of bounds. */
1586 if (rep->field[i]->report_count < 1)
1587 continue;
1588
1589 for (j = 0; j < rep->field[i]->maxusage; j++) {
1590 usage = &rep->field[i]->usage[j];
1591
1592 if (mt_need_to_apply_feature(hdev,
1593 rep->field[i],
1594 usage,
1595 latency,
1596 surface_switch,
1597 button_switch,
1598 &inputmode_found))
1599 update_report = true;
1600 }
1601 }
1602
1603 if (update_report)
1604 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
1605 }
1606 }
1607
mt_post_parse_default_settings(struct mt_device * td,struct mt_application * app)1608 static void mt_post_parse_default_settings(struct mt_device *td,
1609 struct mt_application *app)
1610 {
1611 __s32 quirks = app->quirks;
1612
1613 /* unknown serial device needs special quirks */
1614 if (list_is_singular(&app->mt_usages)) {
1615 quirks |= MT_QUIRK_ALWAYS_VALID;
1616 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1617 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1618 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
1619 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1620 }
1621
1622 app->quirks = quirks;
1623 }
1624
mt_post_parse(struct mt_device * td,struct mt_application * app)1625 static void mt_post_parse(struct mt_device *td, struct mt_application *app)
1626 {
1627 if (!app->have_contact_count)
1628 app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1629 }
1630
mt_input_configured(struct hid_device * hdev,struct hid_input * hi)1631 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
1632 {
1633 struct mt_device *td = hid_get_drvdata(hdev);
1634 const char *suffix = NULL;
1635 struct mt_report_data *rdata;
1636 struct mt_application *mt_application = NULL;
1637 struct hid_report *report;
1638 int ret;
1639
1640 list_for_each_entry(report, &hi->reports, hidinput_list) {
1641 rdata = mt_find_report_data(td, report);
1642 if (!rdata) {
1643 hid_err(hdev, "failed to allocate data for report\n");
1644 return -ENOMEM;
1645 }
1646
1647 mt_application = rdata->application;
1648
1649 if (rdata->is_mt_collection) {
1650 ret = mt_touch_input_configured(hdev, hi,
1651 mt_application);
1652 if (ret)
1653 return ret;
1654 }
1655 }
1656
1657 switch (hi->application) {
1658 case HID_GD_KEYBOARD:
1659 case HID_GD_KEYPAD:
1660 case HID_GD_MOUSE:
1661 case HID_DG_TOUCHPAD:
1662 case HID_GD_SYSTEM_CONTROL:
1663 case HID_CP_CONSUMER_CONTROL:
1664 case HID_GD_WIRELESS_RADIO_CTLS:
1665 case HID_GD_SYSTEM_MULTIAXIS:
1666 /* already handled by hid core */
1667 break;
1668 case HID_DG_TOUCHSCREEN:
1669 /* we do not set suffix = "Touchscreen" */
1670 hi->input->name = hdev->name;
1671 break;
1672 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1673 suffix = "Custom Media Keys";
1674 break;
1675 case HID_DG_STYLUS:
1676 /* force BTN_STYLUS to allow tablet matching in udev */
1677 __set_bit(BTN_STYLUS, hi->input->keybit);
1678 break;
1679 default:
1680 suffix = "UNKNOWN";
1681 break;
1682 }
1683
1684 if (suffix) {
1685 hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
1686 "%s %s", hdev->name, suffix);
1687 if (!hi->input->name)
1688 return -ENOMEM;
1689 }
1690
1691 return 0;
1692 }
1693
mt_fix_const_field(struct hid_field * field,unsigned int usage)1694 static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
1695 {
1696 if (field->usage[0].hid != usage ||
1697 !(field->flags & HID_MAIN_ITEM_CONSTANT))
1698 return;
1699
1700 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
1701 field->flags |= HID_MAIN_ITEM_VARIABLE;
1702 }
1703
mt_fix_const_fields(struct hid_device * hdev,unsigned int usage)1704 static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
1705 {
1706 struct hid_report *report;
1707 int i;
1708
1709 list_for_each_entry(report,
1710 &hdev->report_enum[HID_INPUT_REPORT].report_list,
1711 list) {
1712
1713 if (!report->maxfield)
1714 continue;
1715
1716 for (i = 0; i < report->maxfield; i++)
1717 if (report->field[i]->maxusage >= 1)
1718 mt_fix_const_field(report->field[i], usage);
1719 }
1720 }
1721
mt_release_contacts(struct hid_device * hid)1722 static void mt_release_contacts(struct hid_device *hid)
1723 {
1724 struct hid_input *hidinput;
1725 struct mt_application *application;
1726 struct mt_device *td = hid_get_drvdata(hid);
1727
1728 list_for_each_entry(hidinput, &hid->inputs, list) {
1729 struct input_dev *input_dev = hidinput->input;
1730 struct input_mt *mt = input_dev->mt;
1731 int i;
1732
1733 if (mt) {
1734 for (i = 0; i < mt->num_slots; i++) {
1735 input_mt_slot(input_dev, i);
1736 input_mt_report_slot_inactive(input_dev);
1737 }
1738 input_mt_sync_frame(input_dev);
1739 input_sync(input_dev);
1740 }
1741 }
1742
1743 list_for_each_entry(application, &td->applications, list) {
1744 application->num_received = 0;
1745 }
1746 }
1747
mt_expired_timeout(struct timer_list * t)1748 static void mt_expired_timeout(struct timer_list *t)
1749 {
1750 struct mt_device *td = from_timer(td, t, release_timer);
1751 struct hid_device *hdev = td->hdev;
1752
1753 /*
1754 * An input report came in just before we release the sticky fingers,
1755 * it will take care of the sticky fingers.
1756 */
1757 if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
1758 return;
1759 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1760 mt_release_contacts(hdev);
1761 clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1762 }
1763
mt_probe(struct hid_device * hdev,const struct hid_device_id * id)1764 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
1765 {
1766 int ret, i;
1767 struct mt_device *td;
1768 const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
1769
1770 for (i = 0; mt_classes[i].name ; i++) {
1771 if (id->driver_data == mt_classes[i].name) {
1772 mtclass = &(mt_classes[i]);
1773 break;
1774 }
1775 }
1776
1777 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
1778 if (!td) {
1779 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
1780 return -ENOMEM;
1781 }
1782 td->hdev = hdev;
1783 td->mtclass = *mtclass;
1784 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
1785 hid_set_drvdata(hdev, td);
1786
1787 INIT_LIST_HEAD(&td->applications);
1788 INIT_LIST_HEAD(&td->reports);
1789
1790 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
1791 td->serial_maybe = true;
1792
1793
1794 /* Orientation is inverted if the X or Y axes are
1795 * flipped, but normalized if both are inverted.
1796 */
1797 if (hdev->quirks & (HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT) &&
1798 !((hdev->quirks & HID_QUIRK_X_INVERT)
1799 && (hdev->quirks & HID_QUIRK_Y_INVERT)))
1800 td->mtclass.quirks = MT_QUIRK_ORIENTATION_INVERT;
1801
1802 /* This allows the driver to correctly support devices
1803 * that emit events over several HID messages.
1804 */
1805 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
1806
1807 /*
1808 * This allows the driver to handle different input sensors
1809 * that emits events through different applications on the same HID
1810 * device.
1811 */
1812 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1813
1814 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
1815 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1816
1817 if (mtclass->quirks & MT_QUIRK_FORCE_MULTI_INPUT) {
1818 hdev->quirks &= ~HID_QUIRK_INPUT_PER_APP;
1819 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
1820 }
1821
1822 timer_setup(&td->release_timer, mt_expired_timeout, 0);
1823
1824 ret = hid_parse(hdev);
1825 if (ret != 0)
1826 return ret;
1827
1828 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
1829 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
1830
1831 if (hdev->vendor == USB_VENDOR_ID_SIS_TOUCH)
1832 hdev->quirks |= HID_QUIRK_NOGET;
1833
1834 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1835 if (ret)
1836 return ret;
1837
1838 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
1839 if (ret)
1840 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
1841 hdev->name);
1842
1843 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1844
1845 return 0;
1846 }
1847
mt_suspend(struct hid_device * hdev,pm_message_t state)1848 static int mt_suspend(struct hid_device *hdev, pm_message_t state)
1849 {
1850 struct mt_device *td = hid_get_drvdata(hdev);
1851
1852 /* High latency is desirable for power savings during S3/S0ix */
1853 if ((td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP) ||
1854 !hid_hw_may_wakeup(hdev))
1855 mt_set_modes(hdev, HID_LATENCY_HIGH, false, false);
1856 else
1857 mt_set_modes(hdev, HID_LATENCY_HIGH, true, true);
1858
1859 return 0;
1860 }
1861
mt_reset_resume(struct hid_device * hdev)1862 static int mt_reset_resume(struct hid_device *hdev)
1863 {
1864 mt_release_contacts(hdev);
1865 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1866 return 0;
1867 }
1868
mt_resume(struct hid_device * hdev)1869 static int mt_resume(struct hid_device *hdev)
1870 {
1871 /* Some Elan legacy devices require SET_IDLE to be set on resume.
1872 * It should be safe to send it to other devices too.
1873 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
1874
1875 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
1876
1877 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1878
1879 return 0;
1880 }
1881
mt_remove(struct hid_device * hdev)1882 static void mt_remove(struct hid_device *hdev)
1883 {
1884 struct mt_device *td = hid_get_drvdata(hdev);
1885
1886 del_timer_sync(&td->release_timer);
1887
1888 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
1889 hid_hw_stop(hdev);
1890 }
1891
1892 /*
1893 * This list contains only:
1894 * - VID/PID of products not working with the default multitouch handling
1895 * - 2 generic rules.
1896 * So there is no point in adding here any device with MT_CLS_DEFAULT.
1897 */
1898 static const struct hid_device_id mt_devices[] = {
1899
1900 /* 3M panels */
1901 { .driver_data = MT_CLS_3M,
1902 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1903 USB_DEVICE_ID_3M1968) },
1904 { .driver_data = MT_CLS_3M,
1905 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1906 USB_DEVICE_ID_3M2256) },
1907 { .driver_data = MT_CLS_3M,
1908 MT_USB_DEVICE(USB_VENDOR_ID_3M,
1909 USB_DEVICE_ID_3M3266) },
1910
1911 /* Anton devices */
1912 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1913 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
1914 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
1915
1916 /* Asus T101HA */
1917 { .driver_data = MT_CLS_WIN_8_DISABLE_WAKEUP,
1918 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1919 USB_VENDOR_ID_ASUSTEK,
1920 USB_DEVICE_ID_ASUSTEK_T101HA_KEYBOARD) },
1921
1922 /* Asus T304UA */
1923 { .driver_data = MT_CLS_ASUS,
1924 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
1925 USB_VENDOR_ID_ASUSTEK,
1926 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
1927
1928 /* Atmel panels */
1929 { .driver_data = MT_CLS_SERIAL,
1930 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
1931 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
1932
1933 /* Baanto multitouch devices */
1934 { .driver_data = MT_CLS_NSMU,
1935 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
1936 USB_DEVICE_ID_BAANTO_MT_190W2) },
1937
1938 /* Cando panels */
1939 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1940 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1941 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1942 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
1943 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
1944 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1945
1946 /* Chunghwa Telecom touch panels */
1947 { .driver_data = MT_CLS_NSMU,
1948 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
1949 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1950
1951 /* CJTouch panels */
1952 { .driver_data = MT_CLS_NSMU,
1953 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1954 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
1955 { .driver_data = MT_CLS_NSMU,
1956 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
1957 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
1958
1959 /* CVTouch panels */
1960 { .driver_data = MT_CLS_NSMU,
1961 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
1962 USB_DEVICE_ID_CVTOUCH_SCREEN) },
1963
1964 /* eGalax devices (SAW) */
1965 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
1966 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1967 USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER) },
1968
1969 /* eGalax devices (resistive) */
1970 { .driver_data = MT_CLS_EGALAX,
1971 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1972 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1973 { .driver_data = MT_CLS_EGALAX,
1974 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1975 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1976
1977 /* eGalax devices (capacitive) */
1978 { .driver_data = MT_CLS_EGALAX_SERIAL,
1979 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1980 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
1981 { .driver_data = MT_CLS_EGALAX,
1982 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1983 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1984 { .driver_data = MT_CLS_EGALAX_SERIAL,
1985 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1986 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1987 { .driver_data = MT_CLS_EGALAX_SERIAL,
1988 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1989 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
1990 { .driver_data = MT_CLS_EGALAX_SERIAL,
1991 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1992 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
1993 { .driver_data = MT_CLS_EGALAX_SERIAL,
1994 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1995 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
1996 { .driver_data = MT_CLS_EGALAX,
1997 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
1998 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1999 { .driver_data = MT_CLS_EGALAX,
2000 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2001 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
2002 { .driver_data = MT_CLS_EGALAX_SERIAL,
2003 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2004 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
2005 { .driver_data = MT_CLS_EGALAX,
2006 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
2007 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
2008 { .driver_data = MT_CLS_EGALAX,
2009 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
2010 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
2011 { .driver_data = MT_CLS_EGALAX,
2012 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2013 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
2014 { .driver_data = MT_CLS_EGALAX,
2015 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2016 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
2017 { .driver_data = MT_CLS_EGALAX_SERIAL,
2018 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2019 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
2020 { .driver_data = MT_CLS_EGALAX_SERIAL,
2021 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2022 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
2023 { .driver_data = MT_CLS_EGALAX_SERIAL,
2024 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2025 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
2026 { .driver_data = MT_CLS_EGALAX,
2027 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2028 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C002) },
2029
2030 /* Elan devices */
2031 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2032 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2033 USB_VENDOR_ID_ELAN, 0x313a) },
2034
2035 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2036 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2037 USB_VENDOR_ID_ELAN, 0x3148) },
2038
2039 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2040 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2041 USB_VENDOR_ID_ELAN, 0x32ae) },
2042
2043 /* Elitegroup panel */
2044 { .driver_data = MT_CLS_SERIAL,
2045 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
2046 USB_DEVICE_ID_ELITEGROUP_05D8) },
2047
2048 /* Flatfrog Panels */
2049 { .driver_data = MT_CLS_FLATFROG,
2050 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
2051 USB_DEVICE_ID_MULTITOUCH_3200) },
2052
2053 /* FocalTech Panels */
2054 { .driver_data = MT_CLS_SERIAL,
2055 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
2056 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
2057
2058 /* GeneralTouch panel */
2059 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
2060 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2061 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
2062 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2063 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2064 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
2065 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
2066 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2067 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
2068 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2069 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2070 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
2071 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2072 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2073 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
2074 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2075 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2076 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
2077 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2078 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2079 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
2080
2081 /* Gametel game controller */
2082 { .driver_data = MT_CLS_NSMU,
2083 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
2084 USB_DEVICE_ID_GAMETEL_MT_MODE) },
2085
2086 /* Goodix GT7868Q devices */
2087 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2088 HID_DEVICE(BUS_I2C, HID_GROUP_ANY, I2C_VENDOR_ID_GOODIX,
2089 I2C_DEVICE_ID_GOODIX_01E8) },
2090 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2091 HID_DEVICE(BUS_I2C, HID_GROUP_ANY, I2C_VENDOR_ID_GOODIX,
2092 I2C_DEVICE_ID_GOODIX_01E9) },
2093
2094 /* GoodTouch panels */
2095 { .driver_data = MT_CLS_NSMU,
2096 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
2097 USB_DEVICE_ID_GOODTOUCH_000f) },
2098
2099 /* Hanvon panels */
2100 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2101 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
2102 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
2103
2104 /* HONOR GLO-GXXX panel */
2105 { .driver_data = MT_CLS_VTL,
2106 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2107 0x347d, 0x7853) },
2108
2109 /* HONOR MagicBook Art 14 touchpad */
2110 { .driver_data = MT_CLS_VTL,
2111 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2112 0x35cc, 0x0104) },
2113
2114 /* Ilitek dual touch panel */
2115 { .driver_data = MT_CLS_NSMU,
2116 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
2117 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
2118
2119 /* LG Melfas panel */
2120 { .driver_data = MT_CLS_LG,
2121 HID_USB_DEVICE(USB_VENDOR_ID_LG,
2122 USB_DEVICE_ID_LG_MELFAS_MT) },
2123 { .driver_data = MT_CLS_LG,
2124 HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
2125 USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_7010) },
2126
2127 /* Lenovo X1 TAB Gen 1 */
2128 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2129 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2130 USB_VENDOR_ID_LENOVO,
2131 USB_DEVICE_ID_LENOVO_X1_TAB) },
2132
2133 /* Lenovo X1 TAB Gen 2 */
2134 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2135 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2136 USB_VENDOR_ID_LENOVO,
2137 USB_DEVICE_ID_LENOVO_X1_TAB2) },
2138
2139 /* Lenovo X1 TAB Gen 3 */
2140 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2141 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2142 USB_VENDOR_ID_LENOVO,
2143 USB_DEVICE_ID_LENOVO_X1_TAB3) },
2144
2145 /* Lenovo X12 TAB Gen 1 */
2146 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2147 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2148 USB_VENDOR_ID_LENOVO,
2149 USB_DEVICE_ID_LENOVO_X12_TAB) },
2150
2151 /* Lenovo X12 TAB Gen 2 */
2152 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2153 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2154 USB_VENDOR_ID_LENOVO,
2155 USB_DEVICE_ID_LENOVO_X12_TAB2) },
2156
2157 /* Logitech devices */
2158 { .driver_data = MT_CLS_NSMU,
2159 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH_WIN_8,
2160 USB_VENDOR_ID_LOGITECH,
2161 USB_DEVICE_ID_LOGITECH_CASA_TOUCHPAD) },
2162 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2163 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2164 USB_VENDOR_ID_LOGITECH,
2165 USB_DEVICE_ID_LOGITECH_BOLT_RECEIVER) },
2166
2167 /* MosArt panels */
2168 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2169 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2170 USB_DEVICE_ID_ASUS_T91MT)},
2171 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2172 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2173 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
2174 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2175 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
2176 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
2177
2178 /* Novatek Panel */
2179 { .driver_data = MT_CLS_NSMU,
2180 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
2181 USB_DEVICE_ID_NOVATEK_PCT) },
2182
2183 /* Ntrig Panel */
2184 { .driver_data = MT_CLS_NSMU,
2185 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2186 USB_VENDOR_ID_NTRIG, 0x1b05) },
2187
2188 /* Panasonic panels */
2189 { .driver_data = MT_CLS_PANASONIC,
2190 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2191 USB_DEVICE_ID_PANABOARD_UBT780) },
2192 { .driver_data = MT_CLS_PANASONIC,
2193 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2194 USB_DEVICE_ID_PANABOARD_UBT880) },
2195
2196 /* PixArt optical touch screen */
2197 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2198 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2199 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
2200 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2201 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2202 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
2203 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2204 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2205 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
2206
2207 /* PixCir-based panels */
2208 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2209 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
2210 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
2211
2212 /* Quanta-based panels */
2213 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2214 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
2215 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
2216
2217 /* Razer touchpads */
2218 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
2219 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2220 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
2221
2222 /* Smart Tech panels */
2223 { .driver_data = MT_CLS_SMART_TECH,
2224 MT_USB_DEVICE(0x0b8c, 0x0092)},
2225
2226 /* Stantum panels */
2227 { .driver_data = MT_CLS_CONFIDENCE,
2228 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
2229 USB_DEVICE_ID_MTP_STM)},
2230
2231 /* Synaptics devices */
2232 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2233 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2234 USB_VENDOR_ID_SYNAPTICS, 0xcd7e) },
2235
2236 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2237 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2238 USB_VENDOR_ID_SYNAPTICS, 0xcddc) },
2239
2240 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2241 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2242 USB_VENDOR_ID_SYNAPTICS, 0xce08) },
2243
2244 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2245 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2246 USB_VENDOR_ID_SYNAPTICS, 0xce09) },
2247
2248 /* TopSeed panels */
2249 { .driver_data = MT_CLS_TOPSEED,
2250 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
2251 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
2252
2253 /* Touch International panels */
2254 { .driver_data = MT_CLS_NSMU,
2255 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
2256 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
2257
2258 /* Unitec panels */
2259 { .driver_data = MT_CLS_NSMU,
2260 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2261 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
2262 { .driver_data = MT_CLS_NSMU,
2263 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2264 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
2265
2266 /* VTL panels */
2267 { .driver_data = MT_CLS_VTL,
2268 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
2269 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
2270
2271 /* Winbond Electronics Corp. */
2272 { .driver_data = MT_CLS_WIN_8_NO_STICKY_FINGERS,
2273 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2274 USB_VENDOR_ID_WINBOND, USB_DEVICE_ID_TSTP_MTOUCH) },
2275
2276 /* Wistron panels */
2277 { .driver_data = MT_CLS_NSMU,
2278 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
2279 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
2280
2281 /* XAT */
2282 { .driver_data = MT_CLS_NSMU,
2283 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
2284 USB_DEVICE_ID_XAT_CSR) },
2285
2286 /* Xiroku */
2287 { .driver_data = MT_CLS_NSMU,
2288 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2289 USB_DEVICE_ID_XIROKU_SPX) },
2290 { .driver_data = MT_CLS_NSMU,
2291 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2292 USB_DEVICE_ID_XIROKU_MPX) },
2293 { .driver_data = MT_CLS_NSMU,
2294 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2295 USB_DEVICE_ID_XIROKU_CSR) },
2296 { .driver_data = MT_CLS_NSMU,
2297 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2298 USB_DEVICE_ID_XIROKU_SPX1) },
2299 { .driver_data = MT_CLS_NSMU,
2300 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2301 USB_DEVICE_ID_XIROKU_MPX1) },
2302 { .driver_data = MT_CLS_NSMU,
2303 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2304 USB_DEVICE_ID_XIROKU_CSR1) },
2305 { .driver_data = MT_CLS_NSMU,
2306 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2307 USB_DEVICE_ID_XIROKU_SPX2) },
2308 { .driver_data = MT_CLS_NSMU,
2309 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2310 USB_DEVICE_ID_XIROKU_MPX2) },
2311 { .driver_data = MT_CLS_NSMU,
2312 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2313 USB_DEVICE_ID_XIROKU_CSR2) },
2314
2315 /* Google MT devices */
2316 { .driver_data = MT_CLS_GOOGLE,
2317 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
2318 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2319 { .driver_data = MT_CLS_GOOGLE,
2320 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_GOOGLE,
2321 USB_DEVICE_ID_GOOGLE_WHISKERS) },
2322
2323 /* sis */
2324 { .driver_data = MT_CLS_SIS,
2325 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_SIS_TOUCH,
2326 HID_ANY_ID) },
2327
2328 /* Hantick */
2329 { .driver_data = MT_CLS_NSMU,
2330 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2331 I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288) },
2332
2333 /* Generic MT device */
2334 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
2335
2336 /* Generic Win 8 certified MT device */
2337 { .driver_data = MT_CLS_WIN_8,
2338 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2339 HID_ANY_ID, HID_ANY_ID) },
2340 { }
2341 };
2342 MODULE_DEVICE_TABLE(hid, mt_devices);
2343
2344 static const struct hid_usage_id mt_grabbed_usages[] = {
2345 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
2346 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
2347 };
2348
2349 static struct hid_driver mt_driver = {
2350 .name = "hid-multitouch",
2351 .id_table = mt_devices,
2352 .probe = mt_probe,
2353 .remove = mt_remove,
2354 .input_mapping = mt_input_mapping,
2355 .input_mapped = mt_input_mapped,
2356 .input_configured = mt_input_configured,
2357 .feature_mapping = mt_feature_mapping,
2358 .usage_table = mt_grabbed_usages,
2359 .event = mt_event,
2360 .report_fixup = mt_report_fixup,
2361 .report = mt_report,
2362 .suspend = pm_ptr(mt_suspend),
2363 .reset_resume = pm_ptr(mt_reset_resume),
2364 .resume = pm_ptr(mt_resume),
2365 };
2366 module_hid_driver(mt_driver);
2367