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