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 app->num_expected = contact_count;
1326 else if (app->num_received == 0 && app->prev_scantime != scantime) {
1327 /*
1328 * New multi-report frame:
1329 *
1330 * For Win8 PTPs the first packet (td->num_received == 0) may
1331 * have a contactcount of 0 if there only is a button event.
1332 *
1333 * Some other devices use a sentinel frame with 0 to release all contacts
1334 */
1335 app->num_expected = 0;
1336 }
1337 app->prev_scantime = scantime;
1338
1339 first_packet = app->num_received == 0;
1340
1341 input = report->field[0]->hidinput->input;
1342
1343 list_for_each_entry(slot, &app->mt_usages, list) {
1344 if (!mt_process_slot(td, input, app, slot))
1345 app->num_received++;
1346 }
1347
1348 for (r = 0; r < report->maxfield; r++) {
1349 field = report->field[r];
1350 count = field->report_count;
1351
1352 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
1353 continue;
1354
1355 for (n = 0; n < count; n++)
1356 mt_process_mt_event(hid, app, field,
1357 &field->usage[n], field->value[n],
1358 first_packet);
1359 }
1360
1361 if (app->num_received >= app->num_expected)
1362 mt_sync_frame(td, app, input);
1363
1364 /*
1365 * Windows 8 specs says 2 things:
1366 * - once a contact has been reported, it has to be reported in each
1367 * subsequent report
1368 * - the report rate when fingers are present has to be at least
1369 * the refresh rate of the screen, 60 or 120 Hz
1370 *
1371 * I interprete this that the specification forces a report rate of
1372 * at least 60 Hz for a touchscreen to be certified.
1373 * Which means that if we do not get a report whithin 16 ms, either
1374 * something wrong happens, either the touchscreen forgets to send
1375 * a release. Taking a reasonable margin allows to remove issues
1376 * with USB communication or the load of the machine.
1377 *
1378 * Given that Win 8 devices are forced to send a release, this will
1379 * only affect laggish machines and the ones that have a firmware
1380 * defect.
1381 */
1382 if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
1383 if (!bitmap_empty(td->active_slots, td->maxcontacts))
1384 mod_timer(&td->release_timer,
1385 jiffies + msecs_to_jiffies(100));
1386 else
1387 timer_delete(&td->release_timer);
1388 }
1389
1390 clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
1391 }
1392
mt_touch_input_configured(struct hid_device * hdev,struct hid_input * hi,struct mt_application * app)1393 static int mt_touch_input_configured(struct hid_device *hdev,
1394 struct hid_input *hi,
1395 struct mt_application *app)
1396 {
1397 struct mt_device *td = hid_get_drvdata(hdev);
1398 struct mt_class *cls = &td->mtclass;
1399 struct input_dev *input = hi->input;
1400 int ret;
1401
1402 /*
1403 * HID_DG_CONTACTMAX field is not present on Apple Touch Bars,
1404 * but the maximum contact count is greater than the default.
1405 */
1406 if (cls->quirks & MT_QUIRK_APPLE_TOUCHBAR && cls->maxcontacts)
1407 td->maxcontacts = cls->maxcontacts;
1408
1409 if (!td->maxcontacts)
1410 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
1411
1412 mt_post_parse(td, app);
1413 if (td->serial_maybe)
1414 mt_post_parse_default_settings(td, app);
1415
1416 /*
1417 * The application for Apple Touch Bars is HID_DG_TOUCHPAD,
1418 * but these devices are direct.
1419 */
1420 if (cls->quirks & MT_QUIRK_APPLE_TOUCHBAR)
1421 app->mt_flags |= INPUT_MT_DIRECT;
1422
1423 if (cls->is_indirect)
1424 app->mt_flags |= INPUT_MT_POINTER;
1425
1426 if (td->is_haptic_touchpad)
1427 app->mt_flags |= INPUT_MT_TOTAL_FORCE;
1428
1429 if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
1430 app->mt_flags |= INPUT_MT_DROP_UNUSED;
1431
1432 /* check for clickpads */
1433 if ((app->mt_flags & INPUT_MT_POINTER) &&
1434 (app->buttons_count == 1))
1435 td->is_buttonpad = true;
1436
1437 if (td->is_buttonpad)
1438 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
1439 if (td->is_pressurepad)
1440 __set_bit(INPUT_PROP_PRESSUREPAD, input->propbit);
1441
1442 if (!td->active_slots) {
1443 td->active_slots = devm_kcalloc(&td->hdev->dev,
1444 BITS_TO_LONGS(td->maxcontacts),
1445 sizeof(long),
1446 GFP_KERNEL);
1447 if (!td->active_slots)
1448 return -ENOMEM;
1449 }
1450
1451 app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
1452 BITS_TO_LONGS(td->maxcontacts),
1453 sizeof(long),
1454 GFP_KERNEL);
1455 if (!app->pending_palm_slots)
1456 return -ENOMEM;
1457
1458 ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
1459 if (ret)
1460 return ret;
1461
1462 app->mt_flags = 0;
1463 return 0;
1464 }
1465
1466 #define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
1467 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)1468 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1469 struct hid_field *field, struct hid_usage *usage,
1470 unsigned long **bit, int *max)
1471 {
1472 struct mt_device *td = hid_get_drvdata(hdev);
1473 struct mt_application *application;
1474 struct mt_report_data *rdata;
1475 int ret;
1476
1477 rdata = mt_find_report_data(td, field->report);
1478 if (!rdata) {
1479 hid_err(hdev, "failed to allocate data for report\n");
1480 return 0;
1481 }
1482
1483 application = rdata->application;
1484
1485 /*
1486 * If mtclass.export_all_inputs is not set, only map fields from
1487 * TouchScreen or TouchPad collections. We need to ignore fields
1488 * that belong to other collections such as Mouse that might have
1489 * the same GenericDesktop usages.
1490 */
1491 if (!td->mtclass.export_all_inputs &&
1492 field->application != HID_DG_TOUCHSCREEN &&
1493 field->application != HID_DG_PEN &&
1494 field->application != HID_DG_TOUCHPAD &&
1495 field->application != HID_GD_KEYBOARD &&
1496 field->application != HID_GD_SYSTEM_CONTROL &&
1497 field->application != HID_CP_CONSUMER_CONTROL &&
1498 field->application != HID_GD_WIRELESS_RADIO_CTLS &&
1499 field->application != HID_GD_SYSTEM_MULTIAXIS &&
1500 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1501 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
1502 return -1;
1503
1504 /*
1505 * Some Asus keyboard+touchpad devices have the hotkeys defined in the
1506 * touchpad report descriptor. We need to treat these as an array to
1507 * map usages to input keys.
1508 */
1509 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
1510 application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
1511 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
1512 set_bit(EV_REP, hi->input->evbit);
1513 if (field->flags & HID_MAIN_ITEM_VARIABLE)
1514 field->flags &= ~HID_MAIN_ITEM_VARIABLE;
1515 switch (usage->hid & HID_USAGE) {
1516 case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
1517 case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
1518 case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
1519 case 0x6b: mt_map_key_clear(KEY_F21); break;
1520 case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
1521 default:
1522 return -1;
1523 }
1524 return 1;
1525 }
1526
1527 if (rdata->is_mt_collection)
1528 return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
1529 application);
1530
1531 /*
1532 * some egalax touchscreens have "application == DG_TOUCHSCREEN"
1533 * for the stylus. Overwrite the hid_input application
1534 */
1535 if (field->physical == HID_DG_STYLUS)
1536 hi->application = HID_DG_STYLUS;
1537
1538 ret = hid_haptic_input_mapping(hdev, td->haptic, hi, field, usage, bit,
1539 max);
1540 if (ret != 0)
1541 return ret;
1542
1543 /* let hid-core decide for the others */
1544 return 0;
1545 }
1546
mt_input_mapped(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)1547 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
1548 struct hid_field *field, struct hid_usage *usage,
1549 unsigned long **bit, int *max)
1550 {
1551 struct mt_device *td = hid_get_drvdata(hdev);
1552 struct mt_report_data *rdata;
1553
1554 rdata = mt_find_report_data(td, field->report);
1555 if (rdata && rdata->is_mt_collection) {
1556 /* We own these mappings, tell hid-input to ignore them */
1557 return -1;
1558 }
1559
1560 /* let hid-core decide for the others */
1561 return 0;
1562 }
1563
mt_event(struct hid_device * hid,struct hid_field * field,struct hid_usage * usage,__s32 value)1564 static int mt_event(struct hid_device *hid, struct hid_field *field,
1565 struct hid_usage *usage, __s32 value)
1566 {
1567 struct mt_device *td = hid_get_drvdata(hid);
1568 struct mt_report_data *rdata;
1569
1570 rdata = mt_find_report_data(td, field->report);
1571 if (rdata && rdata->is_mt_collection)
1572 return mt_touch_event(hid, field, usage, value);
1573
1574 return 0;
1575 }
1576
1577 /*
1578 * Yoga Book 9 14IAH10 descriptor fixup.
1579 *
1580 * The device includes a HID_DG_TOUCHPAD application collection designed for
1581 * the Windows inbox HID driver's Win8 PTP touchpad mode. On Linux we want
1582 * only the HID_DG_TOUCHSCREEN collections. The touchpad collection (and the
1583 * HID_DG_BUTTONTYPE and Win8 compliance blob features it contains) must be
1584 * removed so hid-multitouch does not misclassify the touchscreen nodes as
1585 * indirect buttonpads.
1586 *
1587 * The firmware also resets if any USB control request is received while the
1588 * CDC-ACM interface is initialising (~1.18 s after enumeration). Dropping
1589 * the Win8 blob and Contact Count Max feature reports prevents the
1590 * GET_REPORT calls that hid-multitouch issues at probe.
1591 */
mt_yogabook9_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * size)1592 static void mt_yogabook9_fixup(struct hid_device *hdev, __u8 *rdesc,
1593 unsigned int *size)
1594 {
1595 /* Usage Page (Digitizer), Usage (Touch Pad), Collection (Application) */
1596 static const __u8 tp_app_hdr[] = { 0x05, 0x0d, 0x09, 0x05, 0xa1, 0x01 };
1597 /* Vendor Usage Page 0xff00 (Win8 compliance blob header) */
1598 static const __u8 win8_page[] = { 0x06, 0x00, 0xff };
1599 /* Usage (Contact Count Max = 0x55) */
1600 static const __u8 ccmax_usage[] = { 0x09, 0x55 };
1601 unsigned int i;
1602
1603 /*
1604 * Step 1: find and remove the Touch Pad application collection.
1605 * Walk HID short items from the collection header to its matching
1606 * End Collection, then close the gap with memmove.
1607 */
1608 for (i = 0; i + sizeof(tp_app_hdr) <= *size; i++) {
1609 if (memcmp(rdesc + i, tp_app_hdr, sizeof(tp_app_hdr)) == 0) {
1610 __u8 *start = rdesc + i;
1611 __u8 *coll_end = NULL;
1612 __u8 *p = start;
1613 unsigned int drop;
1614 int depth = 0;
1615
1616 while (p < rdesc + *size) {
1617 __u8 b = *p;
1618 int ds = b & 3;
1619 int item_len;
1620
1621 if (b == 0xfe) { /* long item */
1622 if (p + 2 >= rdesc + *size)
1623 break;
1624 item_len = p[1] + 3;
1625 } else {
1626 item_len = (ds == 3) ? 5 : ds + 1;
1627 }
1628 if (p + item_len > rdesc + *size)
1629 break;
1630
1631 if ((b & 0xfc) == 0xa0)
1632 depth++; /* Collection */
1633 else if (b == 0xc0) {
1634 depth--; /* End Collection */
1635 if (depth == 0) {
1636 coll_end = p;
1637 break;
1638 }
1639 }
1640 p += item_len;
1641 }
1642
1643 if (!coll_end) {
1644 hid_err(hdev,
1645 "Yoga Book 9: Touch Pad End Collection not found\n");
1646 break;
1647 }
1648
1649 drop = coll_end - start + 1;
1650 memmove(start, coll_end + 1, rdesc + *size - coll_end - 1);
1651 *size -= drop;
1652 hid_dbg(hdev,
1653 "Yoga Book 9: dropped Touch Pad collection (%u bytes)\n",
1654 drop);
1655 break;
1656 }
1657 }
1658
1659 /*
1660 * Step 2: neutralize Win8 compliance blob feature reports remaining
1661 * in the touchscreen collections. Change Usage Page 0xff00 to 0x0f00
1662 * so the case 0xff0000c5 branch in mt_feature_mapping() is not reached
1663 * and no GET_REPORT is issued.
1664 */
1665 for (i = 0; i + sizeof(win8_page) <= *size; i++) {
1666 if (memcmp(rdesc + i, win8_page, sizeof(win8_page)) == 0) {
1667 rdesc[i + 2] = 0x0f; /* 0xff00 -> 0x0f00 */
1668 hid_dbg(hdev,
1669 "Yoga Book 9: neutralized Win8 blob at offset %u\n",
1670 i);
1671 }
1672 }
1673
1674 /*
1675 * Step 3: neutralize Contact Count Max feature reports. Change usage
1676 * 0x55 (HID_DG_CONTACTMAX) to 0x00 so mt_feature_mapping() does not
1677 * issue GET_REPORT. The class maxcontacts field provides the value.
1678 */
1679 for (i = 0; i + sizeof(ccmax_usage) <= *size; i++) {
1680 if (memcmp(rdesc + i, ccmax_usage, sizeof(ccmax_usage)) == 0) {
1681 rdesc[i + 1] = 0x00;
1682 hid_dbg(hdev,
1683 "Yoga Book 9: neutralized ContactMax at offset %u\n",
1684 i);
1685 }
1686 }
1687
1688 /*
1689 * Step 4: neutralize Surface Switch (0x57) and Button Switch (0x58)
1690 * feature report usages in the Device Configuration collection.
1691 * mt_set_modes() issues HID_REQ_SET_REPORT for these on every
1692 * input-device open/close; those repeated control requests hit the
1693 * firmware's CDC-ACM init window and trigger resets.
1694 *
1695 * Input Mode (0x52) is intentionally left intact. mt_set_modes()
1696 * sends it once at probe to set the device into touchscreen mode,
1697 * which flushes the firmware's contact buffer and clears a persistent
1698 * ghost contact (cid 2, fixed coordinates) that otherwise appears on
1699 * every enumeration. By probe time cdc_acm has already satisfied the
1700 * CDC-ACM init watchdog (~130 ms), so the single SET_REPORT for Input
1701 * Mode arrives safely after the reset window has closed.
1702 */
1703 for (i = 0; i + 2 <= *size; i++) {
1704 if (rdesc[i] == 0x09 &&
1705 (rdesc[i + 1] == 0x57 ||
1706 rdesc[i + 1] == 0x58)) {
1707 hid_dbg(hdev,
1708 "Yoga Book 9: neutralized set-modes usage 0x%02x at offset %u\n",
1709 rdesc[i + 1], i);
1710 rdesc[i + 1] = 0x00;
1711 }
1712 }
1713 }
1714
mt_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * size)1715 static const __u8 *mt_report_fixup(struct hid_device *hdev, __u8 *rdesc,
1716 unsigned int *size)
1717 {
1718 if (hdev->vendor == I2C_VENDOR_ID_GOODIX &&
1719 (hdev->product == I2C_DEVICE_ID_GOODIX_01E8 ||
1720 hdev->product == I2C_DEVICE_ID_GOODIX_01E9)) {
1721 if (*size < 608) {
1722 dev_info(
1723 &hdev->dev,
1724 "GT7868Q fixup: report descriptor is only %u bytes, skipping\n",
1725 *size);
1726 return rdesc;
1727 }
1728
1729 if (rdesc[607] == 0x15) {
1730 rdesc[607] = 0x25;
1731 dev_info(
1732 &hdev->dev,
1733 "GT7868Q report descriptor fixup is applied.\n");
1734 } else {
1735 dev_info(
1736 &hdev->dev,
1737 "The byte is not expected for fixing the report descriptor. \
1738 It's possible that the touchpad firmware is not suitable for applying the fix. \
1739 got: %x\n",
1740 rdesc[607]);
1741 }
1742 }
1743
1744 if (hdev->vendor == USB_VENDOR_ID_LENOVO &&
1745 hdev->product == USB_DEVICE_ID_LENOVO_YOGABOOK9I)
1746 mt_yogabook9_fixup(hdev, rdesc, size);
1747
1748 return rdesc;
1749 }
1750
mt_report(struct hid_device * hid,struct hid_report * report)1751 static void mt_report(struct hid_device *hid, struct hid_report *report)
1752 {
1753 struct mt_device *td = hid_get_drvdata(hid);
1754 struct hid_field *field = report->field[0];
1755 struct mt_report_data *rdata;
1756
1757 if (!(hid->claimed & HID_CLAIMED_INPUT))
1758 return;
1759
1760 rdata = mt_find_report_data(td, report);
1761 if (rdata && rdata->is_mt_collection)
1762 return mt_touch_report(hid, rdata);
1763
1764 /* Lenovo Yoga Book 9i requires consuming and dropping certain bogus reports */
1765 if (rdata && rdata->application &&
1766 (rdata->application->quirks & MT_QUIRK_YOGABOOK9I)) {
1767
1768 bool all_zero_report = true;
1769
1770 for (int f = 0; f < report->maxfield && all_zero_report; f++) {
1771 struct hid_field *fld = report->field[f];
1772
1773 for (int i = 0; i < fld->report_count; i++) {
1774 unsigned int usage = fld->usage[i].hid;
1775
1776 if (usage == HID_DG_INRANGE ||
1777 usage == HID_DG_TIPSWITCH ||
1778 usage == HID_DG_BARRELSWITCH ||
1779 usage == HID_DG_BARRELSWITCH2 ||
1780 usage == HID_DG_CONTACTID ||
1781 usage == HID_DG_TILT_X ||
1782 usage == HID_DG_TILT_Y) {
1783
1784 if (fld->value[i] != 0) {
1785 all_zero_report = false;
1786 break;
1787 }
1788 }
1789 }
1790 }
1791
1792 if (all_zero_report)
1793 return;
1794 }
1795
1796 if (field && field->hidinput && field->hidinput->input)
1797 input_sync(field->hidinput->input);
1798 }
1799
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)1800 static bool mt_need_to_apply_feature(struct hid_device *hdev,
1801 struct hid_field *field,
1802 struct hid_usage *usage,
1803 enum latency_mode latency,
1804 enum report_mode report_mode,
1805 bool *inputmode_found)
1806 {
1807 struct mt_device *td = hid_get_drvdata(hdev);
1808 struct mt_class *cls = &td->mtclass;
1809 struct hid_report *report = field->report;
1810 unsigned int index = usage->usage_index;
1811 char *buf;
1812 u32 report_len;
1813 int max;
1814
1815 switch (usage->hid) {
1816 case HID_DG_INPUTMODE:
1817 /*
1818 * Some elan panels wrongly declare 2 input mode features,
1819 * and silently ignore when we set the value in the second
1820 * field. Skip the second feature and hope for the best.
1821 */
1822 if (*inputmode_found)
1823 return false;
1824
1825 if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
1826 report_len = hid_report_len(report);
1827 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1828 if (!buf) {
1829 hid_err(hdev,
1830 "failed to allocate buffer for report\n");
1831 return false;
1832 }
1833 hid_hw_raw_request(hdev, report->id, buf, report_len,
1834 HID_FEATURE_REPORT,
1835 HID_REQ_GET_REPORT);
1836 kfree(buf);
1837 }
1838
1839 field->value[index] = td->inputmode_value;
1840 *inputmode_found = true;
1841 return true;
1842
1843 case HID_DG_CONTACTMAX:
1844 if (cls->maxcontacts) {
1845 max = min_t(int, field->logical_maximum,
1846 cls->maxcontacts);
1847 if (field->value[index] != max) {
1848 field->value[index] = max;
1849 return true;
1850 }
1851 }
1852 break;
1853
1854 case HID_DG_LATENCYMODE:
1855 field->value[index] = latency;
1856 return true;
1857
1858 case HID_DG_SURFACESWITCH:
1859 field->value[index] = !!(report_mode & TOUCHPAD_REPORT_CONTACTS);
1860 return true;
1861
1862 case HID_DG_BUTTONSWITCH:
1863 field->value[index] = !!(report_mode & TOUCHPAD_REPORT_BUTTONS);
1864 return true;
1865 }
1866
1867 return false; /* no need to update the report */
1868 }
1869
mt_set_modes(struct hid_device * hdev,enum latency_mode latency,enum report_mode report_mode)1870 static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1871 enum report_mode report_mode)
1872 {
1873 struct hid_report_enum *rep_enum;
1874 struct hid_report *rep;
1875 struct hid_usage *usage;
1876 int i, j;
1877 bool update_report;
1878 bool inputmode_found = false;
1879
1880 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
1881 list_for_each_entry(rep, &rep_enum->report_list, list) {
1882 update_report = false;
1883
1884 for (i = 0; i < rep->maxfield; i++) {
1885 /* Ignore if report count is out of bounds. */
1886 if (rep->field[i]->report_count < 1)
1887 continue;
1888
1889 for (j = 0; j < rep->field[i]->maxusage; j++) {
1890 usage = &rep->field[i]->usage[j];
1891
1892 if (mt_need_to_apply_feature(hdev,
1893 rep->field[i],
1894 usage,
1895 latency,
1896 report_mode,
1897 &inputmode_found))
1898 update_report = true;
1899 }
1900 }
1901
1902 if (update_report)
1903 hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
1904 }
1905 }
1906
mt_post_parse_default_settings(struct mt_device * td,struct mt_application * app)1907 static void mt_post_parse_default_settings(struct mt_device *td,
1908 struct mt_application *app)
1909 {
1910 __s32 quirks = app->quirks;
1911
1912 /* unknown serial device needs special quirks */
1913 if (list_is_singular(&app->mt_usages)) {
1914 quirks |= MT_QUIRK_ALWAYS_VALID;
1915 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
1916 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
1917 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
1918 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1919 }
1920
1921 app->quirks = quirks;
1922 }
1923
mt_post_parse(struct mt_device * td,struct mt_application * app)1924 static void mt_post_parse(struct mt_device *td, struct mt_application *app)
1925 {
1926 if (!app->have_contact_count)
1927 app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
1928 }
1929
mt_input_configured(struct hid_device * hdev,struct hid_input * hi)1930 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
1931 {
1932 struct mt_device *td = hid_get_drvdata(hdev);
1933 const char *suffix = NULL;
1934 struct mt_report_data *rdata;
1935 struct mt_application *mt_application = NULL;
1936 struct hid_report *report;
1937 int ret;
1938
1939 if (td->is_haptic_touchpad && (td->mtclass.name == MT_CLS_WIN_8 ||
1940 td->mtclass.name == MT_CLS_WIN_8_FORCE_MULTI_INPUT ||
1941 td->mtclass.name == MT_CLS_WIN_8_KEEP_LATENCY_ON_CLOSE)) {
1942 if (hid_haptic_input_configured(hdev, td->haptic, hi) == 0)
1943 td->is_haptic_touchpad = false;
1944 } else {
1945 td->is_haptic_touchpad = false;
1946 }
1947
1948 list_for_each_entry(report, &hi->reports, hidinput_list) {
1949 rdata = mt_find_report_data(td, report);
1950 if (!rdata) {
1951 hid_err(hdev, "failed to allocate data for report\n");
1952 return -ENOMEM;
1953 }
1954
1955 mt_application = rdata->application;
1956
1957 if (rdata->is_mt_collection) {
1958 ret = mt_touch_input_configured(hdev, hi,
1959 mt_application);
1960 if (ret)
1961 return ret;
1962 }
1963 }
1964
1965 switch (hi->application) {
1966 case HID_GD_KEYBOARD:
1967 case HID_GD_KEYPAD:
1968 case HID_GD_MOUSE:
1969 case HID_DG_TOUCHPAD:
1970 case HID_GD_SYSTEM_CONTROL:
1971 case HID_CP_CONSUMER_CONTROL:
1972 case HID_GD_WIRELESS_RADIO_CTLS:
1973 case HID_GD_SYSTEM_MULTIAXIS:
1974 case HID_DG_PEN:
1975 /* already handled by hid core */
1976 break;
1977 case HID_DG_TOUCHSCREEN:
1978 /* we do not set suffix = "Touchscreen" */
1979 hi->input->name = hdev->name;
1980 break;
1981 case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
1982 suffix = "Custom Media Keys";
1983 break;
1984 case HID_DG_STYLUS:
1985 /* force BTN_STYLUS to allow tablet matching in udev */
1986 __set_bit(BTN_STYLUS, hi->input->keybit);
1987 break;
1988 default:
1989 suffix = "UNKNOWN";
1990 break;
1991 }
1992
1993 /* Lenovo Yoga Book 9i requires custom naming to allow differentiation in udev */
1994 if (hi->report && td->mtclass.quirks & MT_QUIRK_YOGABOOK9I) {
1995 switch (hi->report->id) {
1996 case 48:
1997 suffix = "Touchscreen Top";
1998 break;
1999 case 56:
2000 suffix = "Touchscreen Bottom";
2001 break;
2002 case 20:
2003 suffix = "Stylus Top";
2004 break;
2005 case 40:
2006 suffix = "Stylus Bottom";
2007 break;
2008 case 80:
2009 suffix = "Emulated Touchpad";
2010 break;
2011 default:
2012 suffix = "";
2013 break;
2014 }
2015 }
2016
2017 if (suffix) {
2018 hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
2019 "%s %s", hdev->name, suffix);
2020 if (!hi->input->name)
2021 return -ENOMEM;
2022 }
2023
2024 return 0;
2025 }
2026
mt_fix_const_field(struct hid_field * field,unsigned int usage)2027 static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
2028 {
2029 if (field->usage[0].hid != usage ||
2030 !(field->flags & HID_MAIN_ITEM_CONSTANT))
2031 return;
2032
2033 field->flags &= ~HID_MAIN_ITEM_CONSTANT;
2034 field->flags |= HID_MAIN_ITEM_VARIABLE;
2035 }
2036
mt_fix_const_fields(struct hid_device * hdev,unsigned int usage)2037 static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
2038 {
2039 struct hid_report *report;
2040 int i;
2041
2042 list_for_each_entry(report,
2043 &hdev->report_enum[HID_INPUT_REPORT].report_list,
2044 list) {
2045
2046 if (!report->maxfield)
2047 continue;
2048
2049 for (i = 0; i < report->maxfield; i++)
2050 if (report->field[i]->maxusage >= 1)
2051 mt_fix_const_field(report->field[i], usage);
2052 }
2053 }
2054
mt_release_contacts(struct hid_device * hid)2055 static void mt_release_contacts(struct hid_device *hid)
2056 {
2057 struct hid_input *hidinput;
2058 struct mt_application *application;
2059 struct mt_device *td = hid_get_drvdata(hid);
2060
2061 list_for_each_entry(hidinput, &hid->inputs, list) {
2062 struct input_dev *input_dev = hidinput->input;
2063 struct input_mt *mt = input_dev->mt;
2064 int i;
2065
2066 if (mt) {
2067 for (i = 0; i < mt->num_slots; i++) {
2068 input_mt_slot(input_dev, i);
2069 input_mt_report_slot_inactive(input_dev);
2070 clear_bit(i, td->active_slots);
2071 }
2072 input_mt_sync_frame(input_dev);
2073 input_sync(input_dev);
2074 }
2075 }
2076
2077 list_for_each_entry(application, &td->applications, list) {
2078 application->num_received = 0;
2079 }
2080 }
2081
mt_expired_timeout(struct timer_list * t)2082 static void mt_expired_timeout(struct timer_list *t)
2083 {
2084 struct mt_device *td = timer_container_of(td, t, release_timer);
2085 struct hid_device *hdev = td->hdev;
2086
2087 /*
2088 * An input report came in just before we release the sticky fingers,
2089 * it will take care of the sticky fingers.
2090 */
2091 if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
2092 return;
2093 if (!bitmap_empty(td->active_slots, td->maxcontacts))
2094 mt_release_contacts(hdev);
2095 clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
2096 }
2097
mt_probe(struct hid_device * hdev,const struct hid_device_id * id)2098 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
2099 {
2100 int ret, i;
2101 struct mt_device *td;
2102 const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
2103
2104 for (i = 0; mt_classes[i].name ; i++) {
2105 if (id->driver_data == mt_classes[i].name) {
2106 mtclass = &(mt_classes[i]);
2107 break;
2108 }
2109 }
2110
2111 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
2112 if (!td) {
2113 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
2114 return -ENOMEM;
2115 }
2116 td->haptic = devm_kzalloc(&hdev->dev, sizeof(*(td->haptic)), GFP_KERNEL);
2117 if (!td->haptic)
2118 return -ENOMEM;
2119
2120 td->haptic->hdev = hdev;
2121 td->hdev = hdev;
2122 td->mtclass = *mtclass;
2123 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
2124 hid_set_drvdata(hdev, td);
2125
2126 INIT_LIST_HEAD(&td->applications);
2127 INIT_LIST_HEAD(&td->reports);
2128
2129 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
2130 td->serial_maybe = true;
2131
2132
2133 /* Orientation is inverted if the X or Y axes are
2134 * flipped, but normalized if both are inverted.
2135 */
2136 if (hdev->quirks & (HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT) &&
2137 !((hdev->quirks & HID_QUIRK_X_INVERT)
2138 && (hdev->quirks & HID_QUIRK_Y_INVERT)))
2139 td->mtclass.quirks = MT_QUIRK_ORIENTATION_INVERT;
2140
2141 /* This allows the driver to correctly support devices
2142 * that emit events over several HID messages.
2143 */
2144 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
2145
2146 /*
2147 * This allows the driver to handle different input sensors
2148 * that emits events through different applications on the same HID
2149 * device.
2150 */
2151 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
2152
2153 if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
2154 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
2155
2156 if (mtclass->quirks & MT_QUIRK_FORCE_MULTI_INPUT) {
2157 hdev->quirks &= ~HID_QUIRK_INPUT_PER_APP;
2158 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
2159 }
2160
2161 timer_setup(&td->release_timer, mt_expired_timeout, 0);
2162
2163 ret = hid_parse(hdev);
2164 if (ret != 0)
2165 return ret;
2166
2167 if (mtclass->name == MT_CLS_APPLE_TOUCHBAR &&
2168 !hid_find_field(hdev, HID_INPUT_REPORT,
2169 HID_DG_TOUCHPAD, HID_DG_TRANSDUCER_INDEX))
2170 return -ENODEV;
2171
2172 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
2173 mt_fix_const_fields(hdev, HID_DG_CONTACTID);
2174
2175 if (hdev->vendor == USB_VENDOR_ID_SIS_TOUCH)
2176 hdev->quirks |= HID_QUIRK_NOGET;
2177
2178 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
2179 if (ret)
2180 return ret;
2181
2182 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
2183 if (ret)
2184 dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
2185 hdev->name);
2186
2187 mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
2188
2189 if (!td->is_haptic_touchpad)
2190 devm_kfree(&hdev->dev, td->haptic);
2191
2192 return 0;
2193 }
2194
mt_suspend(struct hid_device * hdev,pm_message_t state)2195 static int mt_suspend(struct hid_device *hdev, pm_message_t state)
2196 {
2197 struct mt_device *td = hid_get_drvdata(hdev);
2198
2199 /* High latency is desirable for power savings during S3/S0ix */
2200 if ((td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP) ||
2201 !hid_hw_may_wakeup(hdev))
2202 mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE);
2203 else
2204 mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_ALL);
2205
2206 return 0;
2207 }
2208
mt_reset_resume(struct hid_device * hdev)2209 static int mt_reset_resume(struct hid_device *hdev)
2210 {
2211 mt_release_contacts(hdev);
2212 mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
2213 return 0;
2214 }
2215
mt_resume(struct hid_device * hdev)2216 static int mt_resume(struct hid_device *hdev)
2217 {
2218 /* Some Elan legacy devices require SET_IDLE to be set on resume.
2219 * It should be safe to send it to other devices too.
2220 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
2221
2222 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
2223
2224 mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
2225
2226 return 0;
2227 }
2228
mt_remove(struct hid_device * hdev)2229 static void mt_remove(struct hid_device *hdev)
2230 {
2231 struct mt_device *td = hid_get_drvdata(hdev);
2232
2233 timer_delete_sync(&td->release_timer);
2234
2235 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
2236 hid_hw_stop(hdev);
2237 }
2238
mt_on_hid_hw_open(struct hid_device * hdev)2239 static void mt_on_hid_hw_open(struct hid_device *hdev)
2240 {
2241 mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
2242 }
2243
mt_on_hid_hw_close(struct hid_device * hdev)2244 static void mt_on_hid_hw_close(struct hid_device *hdev)
2245 {
2246 struct mt_device *td = hid_get_drvdata(hdev);
2247
2248 if (td->mtclass.quirks & MT_QUIRK_KEEP_LATENCY_ON_CLOSE)
2249 mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_NONE);
2250 else
2251 mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE);
2252 }
2253
2254 /*
2255 * This list contains only:
2256 * - VID/PID of products not working with the default multitouch handling
2257 * - 2 generic rules.
2258 * So there is no point in adding here any device with MT_CLS_DEFAULT.
2259 */
2260 static const struct hid_device_id mt_devices[] = {
2261
2262 /* 3M panels */
2263 { .driver_data = MT_CLS_3M,
2264 MT_USB_DEVICE(USB_VENDOR_ID_3M,
2265 USB_DEVICE_ID_3M1968) },
2266 { .driver_data = MT_CLS_3M,
2267 MT_USB_DEVICE(USB_VENDOR_ID_3M,
2268 USB_DEVICE_ID_3M2256) },
2269 { .driver_data = MT_CLS_3M,
2270 MT_USB_DEVICE(USB_VENDOR_ID_3M,
2271 USB_DEVICE_ID_3M3266) },
2272
2273 /* Anton devices */
2274 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
2275 MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
2276 USB_DEVICE_ID_ANTON_TOUCH_PAD) },
2277
2278 /* Asus T101HA */
2279 { .driver_data = MT_CLS_WIN_8_DISABLE_WAKEUP,
2280 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2281 USB_VENDOR_ID_ASUSTEK,
2282 USB_DEVICE_ID_ASUSTEK_T101HA_KEYBOARD) },
2283
2284 /* Asus T304UA */
2285 { .driver_data = MT_CLS_ASUS,
2286 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2287 USB_VENDOR_ID_ASUSTEK,
2288 USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
2289
2290 /* Atmel panels */
2291 { .driver_data = MT_CLS_SERIAL,
2292 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
2293 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
2294
2295 /* Baanto multitouch devices */
2296 { .driver_data = MT_CLS_NSMU,
2297 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
2298 USB_DEVICE_ID_BAANTO_MT_190W2) },
2299
2300 /* Cando panels */
2301 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2302 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
2303 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
2304 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2305 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
2306 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
2307
2308 /* Chunghwa Telecom touch panels */
2309 { .driver_data = MT_CLS_NSMU,
2310 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
2311 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
2312
2313 /* CJTouch panels */
2314 { .driver_data = MT_CLS_NSMU,
2315 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
2316 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
2317 { .driver_data = MT_CLS_NSMU,
2318 MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
2319 USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
2320
2321 /* CVTouch panels */
2322 { .driver_data = MT_CLS_NSMU,
2323 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
2324 USB_DEVICE_ID_CVTOUCH_SCREEN) },
2325
2326 /* eGalax devices (SAW) */
2327 { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
2328 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2329 USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER) },
2330
2331 /* eGalax devices (resistive) */
2332 { .driver_data = MT_CLS_EGALAX,
2333 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2334 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
2335 { .driver_data = MT_CLS_EGALAX,
2336 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2337 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
2338
2339 /* eGalax devices (capacitive) */
2340 { .driver_data = MT_CLS_EGALAX_SERIAL,
2341 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2342 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
2343 { .driver_data = MT_CLS_EGALAX,
2344 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2345 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
2346 { .driver_data = MT_CLS_EGALAX_SERIAL,
2347 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2348 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
2349 { .driver_data = MT_CLS_EGALAX_SERIAL,
2350 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2351 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
2352 { .driver_data = MT_CLS_EGALAX_SERIAL,
2353 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2354 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
2355 { .driver_data = MT_CLS_EGALAX_SERIAL,
2356 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2357 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
2358 { .driver_data = MT_CLS_EGALAX,
2359 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2360 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
2361 { .driver_data = MT_CLS_EGALAX,
2362 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2363 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
2364 { .driver_data = MT_CLS_EGALAX_SERIAL,
2365 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2366 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
2367 { .driver_data = MT_CLS_EGALAX,
2368 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
2369 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
2370 { .driver_data = MT_CLS_EGALAX,
2371 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
2372 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
2373 { .driver_data = MT_CLS_EGALAX,
2374 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2375 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
2376 { .driver_data = MT_CLS_EGALAX,
2377 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2378 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
2379 { .driver_data = MT_CLS_EGALAX_SERIAL,
2380 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2381 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
2382 { .driver_data = MT_CLS_EGALAX_SERIAL,
2383 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2384 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
2385 { .driver_data = MT_CLS_EGALAX_SERIAL,
2386 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2387 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
2388 { .driver_data = MT_CLS_EGALAX_SERIAL,
2389 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2390 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C000) },
2391 { .driver_data = MT_CLS_EGALAX_P80H84,
2392 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2393 USB_VENDOR_ID_DWAV,
2394 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C002) },
2395
2396 /* Elan devices */
2397 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2398 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2399 USB_VENDOR_ID_ELAN, 0x313a) },
2400
2401 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2402 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2403 USB_VENDOR_ID_ELAN, 0x3148) },
2404
2405 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2406 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2407 USB_VENDOR_ID_ELAN, 0x32ae) },
2408
2409 /* Elitegroup panel */
2410 { .driver_data = MT_CLS_SERIAL,
2411 MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
2412 USB_DEVICE_ID_ELITEGROUP_05D8) },
2413
2414 /* Flatfrog Panels */
2415 { .driver_data = MT_CLS_FLATFROG,
2416 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
2417 USB_DEVICE_ID_MULTITOUCH_3200) },
2418
2419 /* FocalTech Panels */
2420 { .driver_data = MT_CLS_SERIAL,
2421 MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
2422 USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
2423
2424 /* GeneralTouch panel */
2425 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
2426 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2427 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
2428 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2429 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2430 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
2431 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
2432 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2433 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
2434 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
2435 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
2436 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
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_0106) },
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_010A) },
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_E100) },
2446
2447 /* Gametel game controller */
2448 { .driver_data = MT_CLS_NSMU,
2449 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
2450 USB_DEVICE_ID_GAMETEL_MT_MODE) },
2451
2452 /* Goodix GT7868Q devices */
2453 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2454 HID_DEVICE(BUS_I2C, HID_GROUP_ANY, I2C_VENDOR_ID_GOODIX,
2455 I2C_DEVICE_ID_GOODIX_01E8) },
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_01E9) },
2459
2460 /* GoodTouch panels */
2461 { .driver_data = MT_CLS_NSMU,
2462 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
2463 USB_DEVICE_ID_GOODTOUCH_000f) },
2464
2465 /* Hanvon panels */
2466 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2467 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
2468 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
2469
2470 /* HONOR GLO-GXXX panel */
2471 { .driver_data = MT_CLS_VTL,
2472 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2473 0x347d, 0x7853) },
2474
2475 /* HONOR MagicBook Art 14 touchpad */
2476 { .driver_data = MT_CLS_VTL,
2477 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2478 0x35cc, 0x0104) },
2479
2480 /* Ilitek dual touch panel */
2481 { .driver_data = MT_CLS_NSMU,
2482 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
2483 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
2484
2485 /* LG Melfas panel */
2486 { .driver_data = MT_CLS_LG,
2487 HID_USB_DEVICE(USB_VENDOR_ID_LG,
2488 USB_DEVICE_ID_LG_MELFAS_MT) },
2489 { .driver_data = MT_CLS_LG,
2490 HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
2491 USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_7010) },
2492
2493 /* Lenovo X1 TAB Gen 1 */
2494 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2495 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2496 USB_VENDOR_ID_LENOVO,
2497 USB_DEVICE_ID_LENOVO_X1_TAB) },
2498
2499 /* Lenovo X1 TAB Gen 2 */
2500 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2501 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2502 USB_VENDOR_ID_LENOVO,
2503 USB_DEVICE_ID_LENOVO_X1_TAB2) },
2504
2505 /* Lenovo X1 TAB Gen 3 */
2506 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2507 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2508 USB_VENDOR_ID_LENOVO,
2509 USB_DEVICE_ID_LENOVO_X1_TAB3) },
2510
2511 /* Lenovo X12 TAB Gen 1 */
2512 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2513 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2514 USB_VENDOR_ID_LENOVO,
2515 USB_DEVICE_ID_LENOVO_X12_TAB) },
2516
2517 /* Lenovo X12 TAB Gen 2 */
2518 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2519 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2520 USB_VENDOR_ID_LENOVO,
2521 USB_DEVICE_ID_LENOVO_X12_TAB2) },
2522
2523 /* Lenovo Yoga Book 9i */
2524 { .driver_data = MT_CLS_YOGABOOK9I,
2525 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2526 USB_VENDOR_ID_LENOVO,
2527 USB_DEVICE_ID_LENOVO_YOGABOOK9I) },
2528
2529 /* Logitech devices */
2530 { .driver_data = MT_CLS_NSMU,
2531 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH_WIN_8,
2532 USB_VENDOR_ID_LOGITECH,
2533 USB_DEVICE_ID_LOGITECH_CASA_TOUCHPAD) },
2534 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2535 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
2536 USB_VENDOR_ID_LOGITECH,
2537 USB_DEVICE_ID_LOGITECH_BOLT_RECEIVER) },
2538
2539 /* MosArt panels */
2540 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2541 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2542 USB_DEVICE_ID_ASUS_T91MT)},
2543 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2544 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
2545 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
2546 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2547 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
2548 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
2549
2550 /* Novatek Panel */
2551 { .driver_data = MT_CLS_NSMU,
2552 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
2553 USB_DEVICE_ID_NOVATEK_PCT) },
2554
2555 /* Ntrig Panel */
2556 { .driver_data = MT_CLS_NSMU,
2557 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2558 USB_VENDOR_ID_NTRIG, 0x1b05) },
2559
2560 /* Panasonic panels */
2561 { .driver_data = MT_CLS_PANASONIC,
2562 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2563 USB_DEVICE_ID_PANABOARD_UBT780) },
2564 { .driver_data = MT_CLS_PANASONIC,
2565 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2566 USB_DEVICE_ID_PANABOARD_UBT880) },
2567
2568 /* PixArt optical touch screen */
2569 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2570 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2571 USB_DEVICE_ID_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_SCREEN1) },
2575 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2576 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
2577 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
2578
2579 /* PixCir-based panels */
2580 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2581 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
2582 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
2583
2584 /* Quanta-based panels */
2585 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2586 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
2587 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
2588
2589 /* Razer touchpads */
2590 { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
2591 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2592 USB_VENDOR_ID_SYNAPTICS, 0x8323) },
2593
2594 /* Smart Tech panels */
2595 { .driver_data = MT_CLS_SMART_TECH,
2596 MT_USB_DEVICE(0x0b8c, 0x0092)},
2597
2598 /* Stantum panels */
2599 { .driver_data = MT_CLS_CONFIDENCE,
2600 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
2601 USB_DEVICE_ID_MTP_STM)},
2602
2603 /* Synaptics devices */
2604 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2605 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2606 USB_VENDOR_ID_SYNAPTICS, 0xcd7e) },
2607
2608 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2609 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2610 USB_VENDOR_ID_SYNAPTICS, 0xcddc) },
2611
2612 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2613 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2614 USB_VENDOR_ID_SYNAPTICS, 0xce08) },
2615
2616 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT,
2617 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2618 USB_VENDOR_ID_SYNAPTICS, 0xce09) },
2619
2620 /* TopSeed panels */
2621 { .driver_data = MT_CLS_TOPSEED,
2622 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
2623 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
2624
2625 /* Touch International panels */
2626 { .driver_data = MT_CLS_NSMU,
2627 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
2628 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
2629
2630 /* Unitec panels */
2631 { .driver_data = MT_CLS_NSMU,
2632 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2633 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
2634 { .driver_data = MT_CLS_NSMU,
2635 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
2636 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
2637
2638 /* Uniwill touchpads */
2639 { .driver_data = MT_CLS_WIN_8_KEEP_LATENCY_ON_CLOSE,
2640 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2641 USB_VENDOR_ID_PIXART, 0x0255) },
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, 0x0274) },
2645
2646 /* VTL panels */
2647 { .driver_data = MT_CLS_VTL,
2648 MT_USB_DEVICE(USB_VENDOR_ID_VTL,
2649 USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
2650
2651 /* Winbond Electronics Corp. */
2652 { .driver_data = MT_CLS_WIN_8_NO_STICKY_FINGERS,
2653 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2654 USB_VENDOR_ID_WINBOND, USB_DEVICE_ID_TSTP_MTOUCH) },
2655
2656 /* Wistron panels */
2657 { .driver_data = MT_CLS_NSMU,
2658 MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
2659 USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
2660
2661 /* XAT */
2662 { .driver_data = MT_CLS_NSMU,
2663 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
2664 USB_DEVICE_ID_XAT_CSR) },
2665
2666 /* Xiroku */
2667 { .driver_data = MT_CLS_NSMU,
2668 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2669 USB_DEVICE_ID_XIROKU_SPX) },
2670 { .driver_data = MT_CLS_NSMU,
2671 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2672 USB_DEVICE_ID_XIROKU_MPX) },
2673 { .driver_data = MT_CLS_NSMU,
2674 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2675 USB_DEVICE_ID_XIROKU_CSR) },
2676 { .driver_data = MT_CLS_NSMU,
2677 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2678 USB_DEVICE_ID_XIROKU_SPX1) },
2679 { .driver_data = MT_CLS_NSMU,
2680 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2681 USB_DEVICE_ID_XIROKU_MPX1) },
2682 { .driver_data = MT_CLS_NSMU,
2683 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2684 USB_DEVICE_ID_XIROKU_CSR1) },
2685 { .driver_data = MT_CLS_NSMU,
2686 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2687 USB_DEVICE_ID_XIROKU_SPX2) },
2688 { .driver_data = MT_CLS_NSMU,
2689 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2690 USB_DEVICE_ID_XIROKU_MPX2) },
2691 { .driver_data = MT_CLS_NSMU,
2692 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
2693 USB_DEVICE_ID_XIROKU_CSR2) },
2694
2695 /* Apple Touch Bar */
2696 { .driver_data = MT_CLS_APPLE_TOUCHBAR,
2697 HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
2698 USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) },
2699
2700 /* Google MT devices */
2701 { .driver_data = MT_CLS_GOOGLE,
2702 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
2703 USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
2704 { .driver_data = MT_CLS_GOOGLE,
2705 HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_GOOGLE,
2706 USB_DEVICE_ID_GOOGLE_WHISKERS) },
2707
2708 /* sis */
2709 { .driver_data = MT_CLS_SIS,
2710 HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_SIS_TOUCH,
2711 HID_ANY_ID) },
2712
2713 /* Hantick */
2714 { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT_NSMU,
2715 HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
2716 I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288) },
2717
2718 /* Generic MT device */
2719 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
2720
2721 /* Generic Win 8 certified MT device */
2722 { .driver_data = MT_CLS_WIN_8,
2723 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
2724 HID_ANY_ID, HID_ANY_ID) },
2725 { }
2726 };
2727 MODULE_DEVICE_TABLE(hid, mt_devices);
2728
2729 static const struct hid_usage_id mt_grabbed_usages[] = {
2730 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
2731 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
2732 };
2733
2734 static struct hid_driver mt_driver = {
2735 .name = "hid-multitouch",
2736 .id_table = mt_devices,
2737 .probe = mt_probe,
2738 .remove = mt_remove,
2739 .input_mapping = mt_input_mapping,
2740 .input_mapped = mt_input_mapped,
2741 .input_configured = mt_input_configured,
2742 .feature_mapping = mt_feature_mapping,
2743 .usage_table = mt_grabbed_usages,
2744 .event = mt_event,
2745 .report_fixup = mt_report_fixup,
2746 .report = mt_report,
2747 .suspend = pm_ptr(mt_suspend),
2748 .reset_resume = pm_ptr(mt_reset_resume),
2749 .resume = pm_ptr(mt_resume),
2750 .on_hid_hw_open = mt_on_hid_hw_open,
2751 .on_hid_hw_close = mt_on_hid_hw_close,
2752 };
2753 module_hid_driver(mt_driver);
2754