]>
Commit | Line | Data |
---|---|---|
5519cab4 BT |
1 | /* |
2 | * HID driver for multitouch panels | |
3 | * | |
c2ef8f21 | 4 | * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr> |
b0a78681 | 5 | * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com> |
c2ef8f21 | 6 | * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France |
b0a78681 | 7 | * Copyright (c) 2012-2013 Red Hat, Inc |
5519cab4 | 8 | * |
4875ac11 RN |
9 | * This code is partly based on hid-egalax.c: |
10 | * | |
11 | * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr> | |
12 | * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se> | |
13 | * Copyright (c) 2010 Canonical, Ltd. | |
14 | * | |
f786bba4 BT |
15 | * This code is partly based on hid-3m-pct.c: |
16 | * | |
17 | * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr> | |
18 | * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se> | |
19 | * Copyright (c) 2010 Canonical, Ltd. | |
20 | * | |
5519cab4 BT |
21 | */ |
22 | ||
23 | /* | |
24 | * This program is free software; you can redistribute it and/or modify it | |
25 | * under the terms of the GNU General Public License as published by the Free | |
26 | * Software Foundation; either version 2 of the License, or (at your option) | |
27 | * any later version. | |
28 | */ | |
29 | ||
b0a78681 BT |
30 | /* |
31 | * This driver is regularly tested thanks to the tool hid-test[1]. | |
32 | * This tool relies on hid-replay[2] and a database of hid devices[3]. | |
33 | * Please run these regression tests before patching this module so that | |
34 | * your patch won't break existing known devices. | |
35 | * | |
36 | * [1] https://github.com/bentiss/hid-test | |
37 | * [2] https://github.com/bentiss/hid-replay | |
38 | * [3] https://github.com/bentiss/hid-devices | |
39 | */ | |
40 | ||
5519cab4 BT |
41 | #include <linux/device.h> |
42 | #include <linux/hid.h> | |
43 | #include <linux/module.h> | |
44 | #include <linux/slab.h> | |
5519cab4 | 45 | #include <linux/input/mt.h> |
29cc309d | 46 | #include <linux/jiffies.h> |
49a5a827 | 47 | #include <linux/string.h> |
4f4001bc | 48 | #include <linux/timer.h> |
5519cab4 BT |
49 | |
50 | ||
51 | MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); | |
ef2fafb3 | 52 | MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); |
5519cab4 BT |
53 | MODULE_DESCRIPTION("HID multitouch panels"); |
54 | MODULE_LICENSE("GPL"); | |
55 | ||
56 | #include "hid-ids.h" | |
57 | ||
58 | /* quirks to control the device */ | |
fd911896 BT |
59 | #define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0) |
60 | #define MT_QUIRK_SLOT_IS_CONTACTID BIT(1) | |
61 | #define MT_QUIRK_CYPRESS BIT(2) | |
62 | #define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3) | |
63 | #define MT_QUIRK_ALWAYS_VALID BIT(4) | |
64 | #define MT_QUIRK_VALID_IS_INRANGE BIT(5) | |
65 | #define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6) | |
66 | #define MT_QUIRK_CONFIDENCE BIT(7) | |
67 | #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8) | |
68 | #define MT_QUIRK_NO_AREA BIT(9) | |
69 | #define MT_QUIRK_IGNORE_DUPLICATES BIT(10) | |
70 | #define MT_QUIRK_HOVERING BIT(11) | |
71 | #define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12) | |
72 | #define MT_QUIRK_FORCE_GET_FEATURE BIT(13) | |
73 | #define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14) | |
74 | #define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15) | |
4f4001bc | 75 | #define MT_QUIRK_STICKY_FINGERS BIT(16) |
957b8dff | 76 | #define MT_QUIRK_ASUS_CUSTOM_UP BIT(17) |
5519cab4 | 77 | |
9abebedb AD |
78 | #define MT_INPUTMODE_TOUCHSCREEN 0x02 |
79 | #define MT_INPUTMODE_TOUCHPAD 0x03 | |
80 | ||
2c6e0277 SF |
81 | #define MT_BUTTONTYPE_CLICKPAD 0 |
82 | ||
4f4001bc | 83 | #define MT_IO_FLAGS_RUNNING 0 |
96098274 BT |
84 | #define MT_IO_FLAGS_ACTIVE_SLOTS 1 |
85 | #define MT_IO_FLAGS_PENDING_SLOTS 2 | |
4f4001bc | 86 | |
5519cab4 | 87 | struct mt_slot { |
349fd670 | 88 | __s32 x, y, cx, cy, p, w, h; |
5519cab4 BT |
89 | __s32 contactid; /* the device ContactID assigned to this slot */ |
90 | bool touch_state; /* is the touch valid? */ | |
9b3bb9b8 | 91 | bool inrange_state; /* is the finger in proximity of the sensor? */ |
6dd2e27a | 92 | bool confidence_state; /* is the touch made by a finger? */ |
5519cab4 BT |
93 | }; |
94 | ||
eec29e3d BT |
95 | struct mt_class { |
96 | __s32 name; /* MT_CLS */ | |
97 | __s32 quirks; | |
98 | __s32 sn_move; /* Signal/noise ratio for move events */ | |
99 | __s32 sn_width; /* Signal/noise ratio for width events */ | |
100 | __s32 sn_height; /* Signal/noise ratio for height events */ | |
101 | __s32 sn_pressure; /* Signal/noise ratio for pressure events */ | |
102 | __u8 maxcontacts; | |
c2ef8f21 | 103 | bool is_indirect; /* true for touchpads */ |
6aef704e | 104 | bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ |
eec29e3d BT |
105 | }; |
106 | ||
3ac36d15 BT |
107 | struct mt_fields { |
108 | unsigned usages[HID_MAX_FIELDS]; | |
109 | unsigned int length; | |
110 | }; | |
111 | ||
5519cab4 BT |
112 | struct mt_device { |
113 | struct mt_slot curdata; /* placeholder of incoming data */ | |
eec29e3d | 114 | struct mt_class mtclass; /* our mt device class */ |
4f4001bc | 115 | struct timer_list release_timer; /* to release sticky fingers */ |
0ee32774 | 116 | struct hid_device *hdev; /* hid_device we're attached to */ |
3ac36d15 BT |
117 | struct mt_fields *fields; /* temporary placeholder for storing the |
118 | multitouch fields */ | |
4f4001bc | 119 | unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ |
7e3cc447 BT |
120 | int cc_index; /* contact count field index in the report */ |
121 | int cc_value_index; /* contact count value index in the field */ | |
af8dc4d0 HG |
122 | int scantime_index; /* scantime field index in the report */ |
123 | int scantime_val_index; /* scantime value index in the field */ | |
124 | int prev_scantime; /* scantime reported in the previous packet */ | |
127e71bd | 125 | int left_button_state; /* left button state */ |
5519cab4 | 126 | unsigned last_slot_field; /* the last field of a slot */ |
55978fa9 | 127 | unsigned mt_report_id; /* the report ID of the multitouch device */ |
b897f6db | 128 | unsigned long initial_quirks; /* initial quirks state */ |
8821f5dc BT |
129 | __s16 inputmode; /* InputMode HID feature, -1 if non-existent */ |
130 | __s16 inputmode_index; /* InputMode HID feature index in the report */ | |
131 | __s16 maxcontact_report_id; /* Maximum Contact Number HID feature, | |
31ae9bdd | 132 | -1 if non-existent */ |
9abebedb | 133 | __u8 inputmode_value; /* InputMode HID feature value */ |
5519cab4 BT |
134 | __u8 num_received; /* how many contacts we received */ |
135 | __u8 num_expected; /* expected last contact index */ | |
9498f954 | 136 | __u8 maxcontacts; |
9e87f22a BT |
137 | __u8 touches_by_report; /* how many touches are present in one report: |
138 | * 1 means we should use a serial protocol | |
139 | * > 1 means hybrid (multitouch) protocol */ | |
015fdaa9 | 140 | __u8 buttons_count; /* number of physical buttons per touchpad */ |
2c6e0277 | 141 | bool is_buttonpad; /* is this device a button pad? */ |
76f5902a | 142 | bool serial_maybe; /* need to check for serial protocol */ |
5519cab4 | 143 | bool curvalid; /* is the current contact valid? */ |
76f5902a | 144 | unsigned mt_flags; /* flags to pass to input-mt */ |
29cc309d NB |
145 | __s32 dev_time; /* the scan time provided by the device */ |
146 | unsigned long jiffies; /* the frame's jiffies */ | |
147 | int timestamp; /* the timestamp to be sent */ | |
5519cab4 BT |
148 | }; |
149 | ||
a69c5f8b BT |
150 | static void mt_post_parse_default_settings(struct mt_device *td); |
151 | static void mt_post_parse(struct mt_device *td); | |
152 | ||
5519cab4 | 153 | /* classes of device behavior */ |
22408283 BT |
154 | #define MT_CLS_DEFAULT 0x0001 |
155 | ||
a062cc5a SC |
156 | #define MT_CLS_SERIAL 0x0002 |
157 | #define MT_CLS_CONFIDENCE 0x0003 | |
5e7ea11f BT |
158 | #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004 |
159 | #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005 | |
160 | #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006 | |
161 | #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007 | |
0fa9c616 | 162 | /* reserved 0x0008 */ |
b7ea95ff | 163 | #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009 |
dc3e1d80 | 164 | #define MT_CLS_NSMU 0x000a |
0fa9c616 BT |
165 | /* reserved 0x0010 */ |
166 | /* reserved 0x0011 */ | |
f961bd35 | 167 | #define MT_CLS_WIN_8 0x0012 |
6aef704e | 168 | #define MT_CLS_EXPORT_ALL_INPUTS 0x0013 |
504c932c | 169 | #define MT_CLS_WIN_8_DUAL 0x0014 |
22408283 BT |
170 | |
171 | /* vendor specific classes */ | |
172 | #define MT_CLS_3M 0x0101 | |
0fa9c616 | 173 | /* reserved 0x0102 */ |
22408283 | 174 | #define MT_CLS_EGALAX 0x0103 |
1b723e8d | 175 | #define MT_CLS_EGALAX_SERIAL 0x0104 |
847672cd | 176 | #define MT_CLS_TOPSEED 0x0105 |
2258e863 | 177 | #define MT_CLS_PANASONIC 0x0106 |
77723e3b | 178 | #define MT_CLS_FLATFROG 0x0107 |
cdcd3ac4 JK |
179 | #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108 |
180 | #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109 | |
f3287a99 | 181 | #define MT_CLS_LG 0x010a |
957b8dff | 182 | #define MT_CLS_ASUS 0x010b |
da10bc25 | 183 | #define MT_CLS_VTL 0x0110 |
0e82232c | 184 | #define MT_CLS_GOOGLE 0x0111 |
5519cab4 | 185 | |
9498f954 | 186 | #define MT_DEFAULT_MAXCONTACT 10 |
afbcb04c | 187 | #define MT_MAX_MAXCONTACT 250 |
9498f954 | 188 | |
29cc309d NB |
189 | /* |
190 | * Resync device and local timestamps after that many microseconds without | |
191 | * receiving data. | |
192 | */ | |
193 | #define MAX_TIMESTAMP_INTERVAL 1000000 | |
194 | ||
2c2110e9 HR |
195 | #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p) |
196 | #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p) | |
197 | ||
5519cab4 BT |
198 | /* |
199 | * these device-dependent functions determine what slot corresponds | |
200 | * to a valid contact that was just read. | |
201 | */ | |
202 | ||
a3b5e577 BT |
203 | static int cypress_compute_slot(struct mt_device *td) |
204 | { | |
205 | if (td->curdata.contactid != 0 || td->num_received == 0) | |
206 | return td->curdata.contactid; | |
207 | else | |
208 | return -1; | |
209 | } | |
210 | ||
b3c21d2c | 211 | static struct mt_class mt_classes[] = { |
2d93666e | 212 | { .name = MT_CLS_DEFAULT, |
dc3e1d80 BT |
213 | .quirks = MT_QUIRK_ALWAYS_VALID | |
214 | MT_QUIRK_CONTACT_CNT_ACCURATE }, | |
215 | { .name = MT_CLS_NSMU, | |
9498f954 | 216 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, |
a062cc5a SC |
217 | { .name = MT_CLS_SERIAL, |
218 | .quirks = MT_QUIRK_ALWAYS_VALID}, | |
22408283 BT |
219 | { .name = MT_CLS_CONFIDENCE, |
220 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE }, | |
5e7ea11f BT |
221 | { .name = MT_CLS_CONFIDENCE_CONTACT_ID, |
222 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | | |
223 | MT_QUIRK_SLOT_IS_CONTACTID }, | |
22408283 BT |
224 | { .name = MT_CLS_CONFIDENCE_MINUS_ONE, |
225 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | | |
226 | MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE }, | |
1e9cf35b | 227 | { .name = MT_CLS_DUAL_INRANGE_CONTACTID, |
2d93666e BT |
228 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
229 | MT_QUIRK_SLOT_IS_CONTACTID, | |
230 | .maxcontacts = 2 }, | |
1e9cf35b | 231 | { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
2d93666e BT |
232 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
233 | MT_QUIRK_SLOT_IS_CONTACTNUMBER, | |
234 | .maxcontacts = 2 }, | |
b7ea95ff AT |
235 | { .name = MT_CLS_INRANGE_CONTACTNUMBER, |
236 | .quirks = MT_QUIRK_VALID_IS_INRANGE | | |
237 | MT_QUIRK_SLOT_IS_CONTACTNUMBER }, | |
f961bd35 BT |
238 | { .name = MT_CLS_WIN_8, |
239 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
240 | MT_QUIRK_IGNORE_DUPLICATES | | |
241 | MT_QUIRK_HOVERING | | |
4f4001bc BT |
242 | MT_QUIRK_CONTACT_CNT_ACCURATE | |
243 | MT_QUIRK_STICKY_FINGERS }, | |
6aef704e BT |
244 | { .name = MT_CLS_EXPORT_ALL_INPUTS, |
245 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
246 | MT_QUIRK_CONTACT_CNT_ACCURATE, | |
247 | .export_all_inputs = true }, | |
504c932c MO |
248 | { .name = MT_CLS_WIN_8_DUAL, |
249 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
250 | MT_QUIRK_IGNORE_DUPLICATES | | |
251 | MT_QUIRK_HOVERING | | |
252 | MT_QUIRK_CONTACT_CNT_ACCURATE, | |
253 | .export_all_inputs = true }, | |
22408283 BT |
254 | |
255 | /* | |
256 | * vendor specific classes | |
257 | */ | |
258 | { .name = MT_CLS_3M, | |
259 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | | |
e9d0a26d HC |
260 | MT_QUIRK_SLOT_IS_CONTACTID | |
261 | MT_QUIRK_TOUCH_SIZE_SCALING, | |
22408283 BT |
262 | .sn_move = 2048, |
263 | .sn_width = 128, | |
c5d40be5 HR |
264 | .sn_height = 128, |
265 | .maxcontacts = 60, | |
266 | }, | |
4875ac11 RN |
267 | { .name = MT_CLS_EGALAX, |
268 | .quirks = MT_QUIRK_SLOT_IS_CONTACTID | | |
2261bb9f | 269 | MT_QUIRK_VALID_IS_INRANGE, |
4875ac11 RN |
270 | .sn_move = 4096, |
271 | .sn_pressure = 32, | |
272 | }, | |
1b723e8d BT |
273 | { .name = MT_CLS_EGALAX_SERIAL, |
274 | .quirks = MT_QUIRK_SLOT_IS_CONTACTID | | |
275 | MT_QUIRK_ALWAYS_VALID, | |
4875ac11 RN |
276 | .sn_move = 4096, |
277 | .sn_pressure = 32, | |
278 | }, | |
847672cd BT |
279 | { .name = MT_CLS_TOPSEED, |
280 | .quirks = MT_QUIRK_ALWAYS_VALID, | |
281 | .is_indirect = true, | |
282 | .maxcontacts = 2, | |
283 | }, | |
2258e863 DK |
284 | { .name = MT_CLS_PANASONIC, |
285 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP, | |
286 | .maxcontacts = 4 }, | |
f5ff4e1e XY |
287 | { .name = MT_CLS_GENERALTOUCH_TWOFINGERS, |
288 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | | |
289 | MT_QUIRK_VALID_IS_INRANGE | | |
7b226292 | 290 | MT_QUIRK_SLOT_IS_CONTACTID, |
f5ff4e1e XY |
291 | .maxcontacts = 2 |
292 | }, | |
293 | { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS, | |
294 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | | |
7b226292 | 295 | MT_QUIRK_SLOT_IS_CONTACTID |
f5ff4e1e | 296 | }, |
043b403a | 297 | |
77723e3b HR |
298 | { .name = MT_CLS_FLATFROG, |
299 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | | |
300 | MT_QUIRK_NO_AREA, | |
301 | .sn_move = 2048, | |
302 | .maxcontacts = 40, | |
303 | }, | |
f3287a99 BT |
304 | { .name = MT_CLS_LG, |
305 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
306 | MT_QUIRK_FIX_CONST_CONTACT_ID | | |
307 | MT_QUIRK_IGNORE_DUPLICATES | | |
308 | MT_QUIRK_HOVERING | | |
309 | MT_QUIRK_CONTACT_CNT_ACCURATE }, | |
957b8dff JPRV |
310 | { .name = MT_CLS_ASUS, |
311 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
312 | MT_QUIRK_CONTACT_CNT_ACCURATE | | |
313 | MT_QUIRK_ASUS_CUSTOM_UP }, | |
da10bc25 MM |
314 | { .name = MT_CLS_VTL, |
315 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
316 | MT_QUIRK_CONTACT_CNT_ACCURATE | | |
317 | MT_QUIRK_FORCE_GET_FEATURE, | |
318 | }, | |
0e82232c WNH |
319 | { .name = MT_CLS_GOOGLE, |
320 | .quirks = MT_QUIRK_ALWAYS_VALID | | |
321 | MT_QUIRK_CONTACT_CNT_ACCURATE | | |
322 | MT_QUIRK_SLOT_IS_CONTACTID | | |
323 | MT_QUIRK_HOVERING | |
324 | }, | |
2d93666e | 325 | { } |
5519cab4 BT |
326 | }; |
327 | ||
eec29e3d BT |
328 | static ssize_t mt_show_quirks(struct device *dev, |
329 | struct device_attribute *attr, | |
330 | char *buf) | |
331 | { | |
ee79a8f8 | 332 | struct hid_device *hdev = to_hid_device(dev); |
eec29e3d BT |
333 | struct mt_device *td = hid_get_drvdata(hdev); |
334 | ||
335 | return sprintf(buf, "%u\n", td->mtclass.quirks); | |
336 | } | |
337 | ||
338 | static ssize_t mt_set_quirks(struct device *dev, | |
339 | struct device_attribute *attr, | |
340 | const char *buf, size_t count) | |
341 | { | |
ee79a8f8 | 342 | struct hid_device *hdev = to_hid_device(dev); |
eec29e3d BT |
343 | struct mt_device *td = hid_get_drvdata(hdev); |
344 | ||
345 | unsigned long val; | |
346 | ||
347 | if (kstrtoul(buf, 0, &val)) | |
348 | return -EINVAL; | |
349 | ||
350 | td->mtclass.quirks = val; | |
351 | ||
7e3cc447 | 352 | if (td->cc_index < 0) |
c2517f62 BT |
353 | td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; |
354 | ||
eec29e3d BT |
355 | return count; |
356 | } | |
357 | ||
358 | static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks); | |
359 | ||
360 | static struct attribute *sysfs_attrs[] = { | |
361 | &dev_attr_quirks.attr, | |
362 | NULL | |
363 | }; | |
364 | ||
9182fb98 | 365 | static const struct attribute_group mt_attribute_group = { |
eec29e3d BT |
366 | .attrs = sysfs_attrs |
367 | }; | |
368 | ||
6d4f5440 MW |
369 | static void mt_get_feature(struct hid_device *hdev, struct hid_report *report) |
370 | { | |
371 | struct mt_device *td = hid_get_drvdata(hdev); | |
372 | int ret, size = hid_report_len(report); | |
373 | u8 *buf; | |
374 | ||
375 | /* | |
b897f6db BT |
376 | * Do not fetch the feature report if the device has been explicitly |
377 | * marked as non-capable. | |
6d4f5440 | 378 | */ |
b897f6db | 379 | if (td->initial_quirks & HID_QUIRK_NO_INIT_REPORTS) |
6d4f5440 MW |
380 | return; |
381 | ||
382 | buf = hid_alloc_report_buf(report, GFP_KERNEL); | |
383 | if (!buf) | |
384 | return; | |
385 | ||
386 | ret = hid_hw_raw_request(hdev, report->id, buf, size, | |
387 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | |
388 | if (ret < 0) { | |
389 | dev_warn(&hdev->dev, "failed to fetch feature %d\n", | |
390 | report->id); | |
391 | } else { | |
392 | ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf, | |
393 | size, 0); | |
394 | if (ret) | |
395 | dev_warn(&hdev->dev, "failed to report feature\n"); | |
396 | } | |
397 | ||
398 | kfree(buf); | |
399 | } | |
400 | ||
f635bd11 | 401 | static void mt_feature_mapping(struct hid_device *hdev, |
5519cab4 BT |
402 | struct hid_field *field, struct hid_usage *usage) |
403 | { | |
9498f954 BT |
404 | struct mt_device *td = hid_get_drvdata(hdev); |
405 | ||
406 | switch (usage->hid) { | |
407 | case HID_DG_INPUTMODE: | |
8821f5dc BT |
408 | /* Ignore if value index is out of bounds. */ |
409 | if (usage->usage_index >= field->report_count) { | |
410 | dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n"); | |
411 | break; | |
4aceed37 BT |
412 | } |
413 | ||
73e7d63e BT |
414 | if (td->inputmode < 0) { |
415 | td->inputmode = field->report->id; | |
416 | td->inputmode_index = usage->usage_index; | |
417 | } else { | |
418 | /* | |
419 | * Some elan panels wrongly declare 2 input mode | |
420 | * features, and silently ignore when we set the | |
421 | * value in the second field. Skip the second feature | |
422 | * and hope for the best. | |
423 | */ | |
424 | dev_info(&hdev->dev, | |
425 | "Ignoring the extra HID_DG_INPUTMODE\n"); | |
426 | } | |
8821f5dc | 427 | |
9498f954 BT |
428 | break; |
429 | case HID_DG_CONTACTMAX: | |
6d4f5440 MW |
430 | mt_get_feature(hdev, field->report); |
431 | ||
31ae9bdd | 432 | td->maxcontact_report_id = field->report->id; |
9498f954 | 433 | td->maxcontacts = field->value[0]; |
afbcb04c BT |
434 | if (!td->maxcontacts && |
435 | field->logical_maximum <= MT_MAX_MAXCONTACT) | |
436 | td->maxcontacts = field->logical_maximum; | |
eec29e3d | 437 | if (td->mtclass.maxcontacts) |
9498f954 | 438 | /* check if the maxcontacts is given by the class */ |
eec29e3d | 439 | td->maxcontacts = td->mtclass.maxcontacts; |
9498f954 | 440 | |
2c6e0277 SF |
441 | break; |
442 | case HID_DG_BUTTONTYPE: | |
443 | if (usage->usage_index >= field->report_count) { | |
444 | dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n"); | |
445 | break; | |
446 | } | |
447 | ||
6d4f5440 | 448 | mt_get_feature(hdev, field->report); |
2c6e0277 SF |
449 | if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD) |
450 | td->is_buttonpad = true; | |
451 | ||
9498f954 | 452 | break; |
45c5c682 BT |
453 | case 0xff0000c5: |
454 | /* Retrieve the Win8 blob once to enable some devices */ | |
455 | if (usage->usage_index == 0) | |
456 | mt_get_feature(hdev, field->report); | |
457 | break; | |
5519cab4 BT |
458 | } |
459 | } | |
460 | ||
461 | static void set_abs(struct input_dev *input, unsigned int code, | |
462 | struct hid_field *field, int snratio) | |
463 | { | |
464 | int fmin = field->logical_minimum; | |
465 | int fmax = field->logical_maximum; | |
466 | int fuzz = snratio ? (fmax - fmin) / snratio : 0; | |
467 | input_set_abs_params(input, code, fmin, fmax, fuzz, 0); | |
37cf6e6f | 468 | input_abs_set_res(input, code, hidinput_calc_abs_res(field, code)); |
5519cab4 BT |
469 | } |
470 | ||
3ac36d15 | 471 | static void mt_store_field(struct hid_usage *usage, struct mt_device *td, |
ed9d5c96 BT |
472 | struct hid_input *hi) |
473 | { | |
3ac36d15 BT |
474 | struct mt_fields *f = td->fields; |
475 | ||
476 | if (f->length >= HID_MAX_FIELDS) | |
477 | return; | |
478 | ||
479 | f->usages[f->length++] = usage->hid; | |
ed9d5c96 BT |
480 | } |
481 | ||
a69c5f8b | 482 | static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
5519cab4 BT |
483 | struct hid_field *field, struct hid_usage *usage, |
484 | unsigned long **bit, int *max) | |
485 | { | |
486 | struct mt_device *td = hid_get_drvdata(hdev); | |
eec29e3d | 487 | struct mt_class *cls = &td->mtclass; |
c2ef8f21 | 488 | int code; |
349fd670 | 489 | struct hid_usage *prev_usage = NULL; |
4875ac11 | 490 | |
658d4aed | 491 | if (field->application == HID_DG_TOUCHSCREEN) |
76f5902a | 492 | td->mt_flags |= INPUT_MT_DIRECT; |
658d4aed | 493 | |
76f5902a HR |
494 | /* |
495 | * Model touchscreens providing buttons as touchpads. | |
c2ef8f21 BT |
496 | */ |
497 | if (field->application == HID_DG_TOUCHPAD || | |
9abebedb | 498 | (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { |
76f5902a | 499 | td->mt_flags |= INPUT_MT_POINTER; |
9abebedb AD |
500 | td->inputmode_value = MT_INPUTMODE_TOUCHPAD; |
501 | } | |
c2ef8f21 | 502 | |
015fdaa9 BT |
503 | /* count the buttons on touchpads */ |
504 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) | |
505 | td->buttons_count++; | |
506 | ||
349fd670 BT |
507 | if (usage->usage_index) |
508 | prev_usage = &field->usage[usage->usage_index - 1]; | |
509 | ||
5519cab4 BT |
510 | switch (usage->hid & HID_USAGE_PAGE) { |
511 | ||
512 | case HID_UP_GENDESK: | |
513 | switch (usage->hid) { | |
514 | case HID_GD_X: | |
349fd670 BT |
515 | if (prev_usage && (prev_usage->hid == usage->hid)) { |
516 | hid_map_usage(hi, usage, bit, max, | |
517 | EV_ABS, ABS_MT_TOOL_X); | |
518 | set_abs(hi->input, ABS_MT_TOOL_X, field, | |
519 | cls->sn_move); | |
520 | } else { | |
521 | hid_map_usage(hi, usage, bit, max, | |
5519cab4 | 522 | EV_ABS, ABS_MT_POSITION_X); |
349fd670 BT |
523 | set_abs(hi->input, ABS_MT_POSITION_X, field, |
524 | cls->sn_move); | |
525 | } | |
526 | ||
3ac36d15 | 527 | mt_store_field(usage, td, hi); |
5519cab4 BT |
528 | return 1; |
529 | case HID_GD_Y: | |
349fd670 BT |
530 | if (prev_usage && (prev_usage->hid == usage->hid)) { |
531 | hid_map_usage(hi, usage, bit, max, | |
532 | EV_ABS, ABS_MT_TOOL_Y); | |
533 | set_abs(hi->input, ABS_MT_TOOL_Y, field, | |
534 | cls->sn_move); | |
535 | } else { | |
536 | hid_map_usage(hi, usage, bit, max, | |
5519cab4 | 537 | EV_ABS, ABS_MT_POSITION_Y); |
349fd670 BT |
538 | set_abs(hi->input, ABS_MT_POSITION_Y, field, |
539 | cls->sn_move); | |
540 | } | |
541 | ||
3ac36d15 | 542 | mt_store_field(usage, td, hi); |
5519cab4 BT |
543 | return 1; |
544 | } | |
545 | return 0; | |
546 | ||
547 | case HID_UP_DIGITIZER: | |
548 | switch (usage->hid) { | |
549 | case HID_DG_INRANGE: | |
9b3bb9b8 BT |
550 | if (cls->quirks & MT_QUIRK_HOVERING) { |
551 | hid_map_usage(hi, usage, bit, max, | |
552 | EV_ABS, ABS_MT_DISTANCE); | |
553 | input_set_abs_params(hi->input, | |
554 | ABS_MT_DISTANCE, 0, 1, 0, 0); | |
555 | } | |
3ac36d15 | 556 | mt_store_field(usage, td, hi); |
5519cab4 BT |
557 | return 1; |
558 | case HID_DG_CONFIDENCE: | |
504c932c MO |
559 | if ((cls->name == MT_CLS_WIN_8 || |
560 | cls->name == MT_CLS_WIN_8_DUAL) && | |
6dd2e27a AH |
561 | field->application == HID_DG_TOUCHPAD) |
562 | cls->quirks |= MT_QUIRK_CONFIDENCE; | |
3ac36d15 | 563 | mt_store_field(usage, td, hi); |
5519cab4 BT |
564 | return 1; |
565 | case HID_DG_TIPSWITCH: | |
566 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); | |
567 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); | |
3ac36d15 | 568 | mt_store_field(usage, td, hi); |
5519cab4 BT |
569 | return 1; |
570 | case HID_DG_CONTACTID: | |
3ac36d15 | 571 | mt_store_field(usage, td, hi); |
9e87f22a | 572 | td->touches_by_report++; |
55978fa9 | 573 | td->mt_report_id = field->report->id; |
5519cab4 BT |
574 | return 1; |
575 | case HID_DG_WIDTH: | |
576 | hid_map_usage(hi, usage, bit, max, | |
577 | EV_ABS, ABS_MT_TOUCH_MAJOR); | |
77723e3b HR |
578 | if (!(cls->quirks & MT_QUIRK_NO_AREA)) |
579 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, | |
580 | cls->sn_width); | |
3ac36d15 | 581 | mt_store_field(usage, td, hi); |
5519cab4 BT |
582 | return 1; |
583 | case HID_DG_HEIGHT: | |
584 | hid_map_usage(hi, usage, bit, max, | |
585 | EV_ABS, ABS_MT_TOUCH_MINOR); | |
77723e3b HR |
586 | if (!(cls->quirks & MT_QUIRK_NO_AREA)) { |
587 | set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, | |
588 | cls->sn_height); | |
589 | input_set_abs_params(hi->input, | |
1e648a13 | 590 | ABS_MT_ORIENTATION, 0, 1, 0, 0); |
77723e3b | 591 | } |
3ac36d15 | 592 | mt_store_field(usage, td, hi); |
5519cab4 BT |
593 | return 1; |
594 | case HID_DG_TIPPRESSURE: | |
595 | hid_map_usage(hi, usage, bit, max, | |
596 | EV_ABS, ABS_MT_PRESSURE); | |
597 | set_abs(hi->input, ABS_MT_PRESSURE, field, | |
598 | cls->sn_pressure); | |
3ac36d15 | 599 | mt_store_field(usage, td, hi); |
5519cab4 | 600 | return 1; |
29cc309d NB |
601 | case HID_DG_SCANTIME: |
602 | hid_map_usage(hi, usage, bit, max, | |
603 | EV_MSC, MSC_TIMESTAMP); | |
604 | input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); | |
605 | mt_store_field(usage, td, hi); | |
af8dc4d0 HG |
606 | /* Ignore if indexes are out of bounds. */ |
607 | if (field->index >= field->report->maxfield || | |
608 | usage->usage_index >= field->report_count) | |
609 | return 1; | |
610 | td->scantime_index = field->index; | |
611 | td->scantime_val_index = usage->usage_index; | |
29cc309d | 612 | return 1; |
5519cab4 | 613 | case HID_DG_CONTACTCOUNT: |
8821f5dc BT |
614 | /* Ignore if indexes are out of bounds. */ |
615 | if (field->index >= field->report->maxfield || | |
616 | usage->usage_index >= field->report_count) | |
617 | return 1; | |
7e3cc447 BT |
618 | td->cc_index = field->index; |
619 | td->cc_value_index = usage->usage_index; | |
5519cab4 BT |
620 | return 1; |
621 | case HID_DG_CONTACTMAX: | |
622 | /* we don't set td->last_slot_field as contactcount and | |
623 | * contact max are global to the report */ | |
624 | return -1; | |
c2ef8f21 BT |
625 | case HID_DG_TOUCH: |
626 | /* Legacy devices use TIPSWITCH and not TOUCH. | |
627 | * Let's just ignore this field. */ | |
628 | return -1; | |
65b258e9 | 629 | } |
5519cab4 BT |
630 | /* let hid-input decide for the others */ |
631 | return 0; | |
632 | ||
c2ef8f21 BT |
633 | case HID_UP_BUTTON: |
634 | code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE); | |
594312b8 BT |
635 | /* |
636 | * MS PTP spec says that external buttons left and right have | |
637 | * usages 2 and 3. | |
638 | */ | |
504c932c MO |
639 | if ((cls->name == MT_CLS_WIN_8 || |
640 | cls->name == MT_CLS_WIN_8_DUAL) && | |
594312b8 BT |
641 | field->application == HID_DG_TOUCHPAD && |
642 | (usage->hid & HID_USAGE) > 1) | |
643 | code--; | |
c2ef8f21 BT |
644 | hid_map_usage(hi, usage, bit, max, EV_KEY, code); |
645 | input_set_capability(hi->input, EV_KEY, code); | |
646 | return 1; | |
647 | ||
5519cab4 BT |
648 | case 0xff000000: |
649 | /* we do not want to map these: no input-oriented meaning */ | |
650 | return -1; | |
651 | } | |
652 | ||
653 | return 0; | |
654 | } | |
655 | ||
3e1b5015 | 656 | static int mt_compute_slot(struct mt_device *td, struct input_dev *input) |
5519cab4 | 657 | { |
eec29e3d | 658 | __s32 quirks = td->mtclass.quirks; |
5519cab4 | 659 | |
2d93666e BT |
660 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) |
661 | return td->curdata.contactid; | |
5519cab4 | 662 | |
2d93666e | 663 | if (quirks & MT_QUIRK_CYPRESS) |
a3b5e577 BT |
664 | return cypress_compute_slot(td); |
665 | ||
2d93666e BT |
666 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) |
667 | return td->num_received; | |
5572da08 | 668 | |
4a6ee685 BT |
669 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) |
670 | return td->curdata.contactid - 1; | |
671 | ||
3e1b5015 | 672 | return input_mt_get_slot_by_key(input, td->curdata.contactid); |
5519cab4 BT |
673 | } |
674 | ||
675 | /* | |
676 | * this function is called when a whole contact has been processed, | |
677 | * so that it can assign it to a slot and store the data there | |
678 | */ | |
3e1b5015 | 679 | static void mt_complete_slot(struct mt_device *td, struct input_dev *input) |
5519cab4 | 680 | { |
c2517f62 BT |
681 | if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && |
682 | td->num_received >= td->num_expected) | |
683 | return; | |
684 | ||
20b60e6d | 685 | if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) { |
6dd2e27a | 686 | int active; |
3e1b5015 HR |
687 | int slotnum = mt_compute_slot(td, input); |
688 | struct mt_slot *s = &td->curdata; | |
28728399 | 689 | struct input_mt *mt = input->mt; |
5519cab4 | 690 | |
3e1b5015 HR |
691 | if (slotnum < 0 || slotnum >= td->maxcontacts) |
692 | return; | |
5519cab4 | 693 | |
28728399 BT |
694 | if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { |
695 | struct input_mt_slot *slot = &mt->slots[slotnum]; | |
696 | if (input_mt_is_active(slot) && | |
697 | input_mt_is_used(mt, slot)) | |
698 | return; | |
699 | } | |
700 | ||
6dd2e27a AH |
701 | if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE)) |
702 | s->confidence_state = 1; | |
703 | active = (s->touch_state || s->inrange_state) && | |
704 | s->confidence_state; | |
705 | ||
3e1b5015 | 706 | input_mt_slot(input, slotnum); |
6dd2e27a AH |
707 | input_mt_report_slot_state(input, MT_TOOL_FINGER, active); |
708 | if (active) { | |
9b3bb9b8 | 709 | /* this finger is in proximity of the sensor */ |
f786bba4 | 710 | int wide = (s->w > s->h); |
e9d0a26d HC |
711 | int major = max(s->w, s->h); |
712 | int minor = min(s->w, s->h); | |
713 | ||
714 | /* | |
715 | * divided by two to match visual scale of touch | |
716 | * for devices with this quirk | |
717 | */ | |
718 | if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { | |
719 | major = major >> 1; | |
720 | minor = minor >> 1; | |
721 | } | |
f786bba4 | 722 | |
2d93666e BT |
723 | input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); |
724 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); | |
349fd670 BT |
725 | input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx); |
726 | input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy); | |
9b3bb9b8 BT |
727 | input_event(input, EV_ABS, ABS_MT_DISTANCE, |
728 | !s->touch_state); | |
f786bba4 | 729 | input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); |
2d93666e | 730 | input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); |
f786bba4 BT |
731 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); |
732 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); | |
96098274 BT |
733 | |
734 | set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); | |
2d93666e | 735 | } |
5519cab4 BT |
736 | } |
737 | ||
3e1b5015 HR |
738 | td->num_received++; |
739 | } | |
740 | ||
741 | /* | |
742 | * this function is called when a whole packet has been received and processed, | |
743 | * so that it can decide what to send to the input layer. | |
744 | */ | |
745 | static void mt_sync_frame(struct mt_device *td, struct input_dev *input) | |
746 | { | |
127e71bd HG |
747 | __s32 cls = td->mtclass.name; |
748 | ||
749 | if (cls == MT_CLS_WIN_8 || cls == MT_CLS_WIN_8_DUAL) | |
750 | input_event(input, EV_KEY, BTN_LEFT, td->left_button_state); | |
751 | ||
76f5902a | 752 | input_mt_sync_frame(input); |
29cc309d | 753 | input_event(input, EV_MSC, MSC_TIMESTAMP, td->timestamp); |
5519cab4 BT |
754 | input_sync(input); |
755 | td->num_received = 0; | |
127e71bd | 756 | td->left_button_state = 0; |
96098274 BT |
757 | if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) |
758 | set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); | |
759 | else | |
760 | clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); | |
761 | clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); | |
5519cab4 BT |
762 | } |
763 | ||
29cc309d NB |
764 | static int mt_compute_timestamp(struct mt_device *td, struct hid_field *field, |
765 | __s32 value) | |
766 | { | |
767 | long delta = value - td->dev_time; | |
768 | unsigned long jdelta = jiffies_to_usecs(jiffies - td->jiffies); | |
769 | ||
770 | td->jiffies = jiffies; | |
771 | td->dev_time = value; | |
772 | ||
773 | if (delta < 0) | |
774 | delta += field->logical_maximum; | |
775 | ||
776 | /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */ | |
777 | delta *= 100; | |
778 | ||
779 | if (jdelta > MAX_TIMESTAMP_INTERVAL) | |
780 | /* No data received for a while, resync the timestamp. */ | |
781 | return 0; | |
782 | else | |
783 | return td->timestamp + delta; | |
784 | } | |
785 | ||
a69c5f8b | 786 | static int mt_touch_event(struct hid_device *hid, struct hid_field *field, |
5519cab4 | 787 | struct hid_usage *usage, __s32 value) |
55978fa9 BT |
788 | { |
789 | /* we will handle the hidinput part later, now remains hiddev */ | |
790 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) | |
791 | hid->hiddev_hid_event(hid, field, usage, value); | |
792 | ||
793 | return 1; | |
794 | } | |
795 | ||
796 | static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, | |
55746d28 HG |
797 | struct hid_usage *usage, __s32 value, |
798 | bool first_packet) | |
5519cab4 BT |
799 | { |
800 | struct mt_device *td = hid_get_drvdata(hid); | |
55746d28 | 801 | __s32 cls = td->mtclass.name; |
eec29e3d | 802 | __s32 quirks = td->mtclass.quirks; |
4c437555 | 803 | struct input_dev *input = field->hidinput->input; |
5519cab4 | 804 | |
3e1b5015 | 805 | if (hid->claimed & HID_CLAIMED_INPUT) { |
5519cab4 BT |
806 | switch (usage->hid) { |
807 | case HID_DG_INRANGE: | |
20b60e6d | 808 | if (quirks & MT_QUIRK_VALID_IS_INRANGE) |
2d93666e | 809 | td->curvalid = value; |
9b3bb9b8 BT |
810 | if (quirks & MT_QUIRK_HOVERING) |
811 | td->curdata.inrange_state = value; | |
5519cab4 BT |
812 | break; |
813 | case HID_DG_TIPSWITCH: | |
2d93666e BT |
814 | if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) |
815 | td->curvalid = value; | |
5519cab4 BT |
816 | td->curdata.touch_state = value; |
817 | break; | |
818 | case HID_DG_CONFIDENCE: | |
6dd2e27a AH |
819 | if (quirks & MT_QUIRK_CONFIDENCE) |
820 | td->curdata.confidence_state = value; | |
2d93666e BT |
821 | if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) |
822 | td->curvalid = value; | |
5519cab4 BT |
823 | break; |
824 | case HID_DG_CONTACTID: | |
825 | td->curdata.contactid = value; | |
826 | break; | |
827 | case HID_DG_TIPPRESSURE: | |
828 | td->curdata.p = value; | |
829 | break; | |
830 | case HID_GD_X: | |
349fd670 BT |
831 | if (usage->code == ABS_MT_TOOL_X) |
832 | td->curdata.cx = value; | |
833 | else | |
834 | td->curdata.x = value; | |
5519cab4 BT |
835 | break; |
836 | case HID_GD_Y: | |
349fd670 BT |
837 | if (usage->code == ABS_MT_TOOL_Y) |
838 | td->curdata.cy = value; | |
839 | else | |
840 | td->curdata.y = value; | |
5519cab4 BT |
841 | break; |
842 | case HID_DG_WIDTH: | |
843 | td->curdata.w = value; | |
844 | break; | |
845 | case HID_DG_HEIGHT: | |
846 | td->curdata.h = value; | |
847 | break; | |
29cc309d NB |
848 | case HID_DG_SCANTIME: |
849 | td->timestamp = mt_compute_timestamp(td, field, value); | |
850 | break; | |
5519cab4 | 851 | case HID_DG_CONTACTCOUNT: |
5519cab4 | 852 | break; |
c2ef8f21 BT |
853 | case HID_DG_TOUCH: |
854 | /* do nothing */ | |
855 | break; | |
5519cab4 BT |
856 | |
857 | default: | |
55746d28 HG |
858 | /* |
859 | * For Win8 PTP touchpads we should only look at | |
860 | * non finger/touch events in the first_packet of | |
861 | * a (possible) multi-packet frame. | |
862 | */ | |
863 | if ((cls == MT_CLS_WIN_8 || cls == MT_CLS_WIN_8_DUAL) && | |
864 | !first_packet) | |
865 | return; | |
866 | ||
127e71bd HG |
867 | /* |
868 | * For Win8 PTP touchpads we map both the clickpad click | |
869 | * and any "external" left buttons to BTN_LEFT if a | |
870 | * device claims to have both we need to report 1 for | |
871 | * BTN_LEFT if either is pressed, so we or all values | |
872 | * together and report the result in mt_sync_frame(). | |
873 | */ | |
874 | if ((cls == MT_CLS_WIN_8 || cls == MT_CLS_WIN_8_DUAL) && | |
875 | usage->type == EV_KEY && usage->code == BTN_LEFT) { | |
876 | td->left_button_state |= value; | |
877 | return; | |
878 | } | |
879 | ||
4c437555 BT |
880 | if (usage->type) |
881 | input_event(input, usage->type, usage->code, | |
882 | value); | |
55978fa9 | 883 | return; |
5519cab4 | 884 | } |
5519cab4 | 885 | |
54f4c0c3 BT |
886 | if (usage->usage_index + 1 == field->report_count) { |
887 | /* we only take into account the last report. */ | |
888 | if (usage->hid == td->last_slot_field) | |
889 | mt_complete_slot(td, field->hidinput->input); | |
54f4c0c3 | 890 | } |
5519cab4 | 891 | |
2d93666e | 892 | } |
55978fa9 | 893 | } |
5519cab4 | 894 | |
a69c5f8b | 895 | static void mt_touch_report(struct hid_device *hid, struct hid_report *report) |
55978fa9 BT |
896 | { |
897 | struct mt_device *td = hid_get_drvdata(hid); | |
af8dc4d0 | 898 | __s32 cls = td->mtclass.name; |
55978fa9 | 899 | struct hid_field *field; |
55746d28 | 900 | bool first_packet; |
55978fa9 | 901 | unsigned count; |
af8dc4d0 | 902 | int r, n, scantime = 0; |
5519cab4 | 903 | |
4f4001bc BT |
904 | /* sticky fingers release in progress, abort */ |
905 | if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) | |
906 | return; | |
907 | ||
c2517f62 BT |
908 | /* |
909 | * Includes multi-packet support where subsequent | |
910 | * packets are sent with zero contactcount. | |
911 | */ | |
af8dc4d0 HG |
912 | if (td->scantime_index >= 0) { |
913 | field = report->field[td->scantime_index]; | |
914 | scantime = field->value[td->scantime_val_index]; | |
915 | } | |
7e3cc447 BT |
916 | if (td->cc_index >= 0) { |
917 | struct hid_field *field = report->field[td->cc_index]; | |
918 | int value = field->value[td->cc_value_index]; | |
af8dc4d0 HG |
919 | |
920 | /* | |
921 | * For Win8 PTPs the first packet (td->num_received == 0) may | |
922 | * have a contactcount of 0 if there only is a button event. | |
923 | * We double check that this is not a continuation packet | |
924 | * of a possible multi-packet frame be checking that the | |
925 | * timestamp has changed. | |
926 | */ | |
927 | if ((cls == MT_CLS_WIN_8 || cls == MT_CLS_WIN_8_DUAL) && | |
928 | td->num_received == 0 && td->prev_scantime != scantime) | |
929 | td->num_expected = value; | |
930 | /* A non 0 contact count always indicates a first packet */ | |
931 | else if (value) | |
7e3cc447 BT |
932 | td->num_expected = value; |
933 | } | |
af8dc4d0 | 934 | td->prev_scantime = scantime; |
c2517f62 | 935 | |
55746d28 | 936 | first_packet = td->num_received == 0; |
55978fa9 BT |
937 | for (r = 0; r < report->maxfield; r++) { |
938 | field = report->field[r]; | |
939 | count = field->report_count; | |
940 | ||
941 | if (!(HID_MAIN_ITEM_VARIABLE & field->flags)) | |
942 | continue; | |
943 | ||
944 | for (n = 0; n < count; n++) | |
945 | mt_process_mt_event(hid, field, &field->usage[n], | |
55746d28 | 946 | field->value[n], first_packet); |
55978fa9 | 947 | } |
5b62efd8 BT |
948 | |
949 | if (td->num_received >= td->num_expected) | |
950 | mt_sync_frame(td, report->field[0]->hidinput->input); | |
4f4001bc BT |
951 | |
952 | /* | |
953 | * Windows 8 specs says 2 things: | |
954 | * - once a contact has been reported, it has to be reported in each | |
955 | * subsequent report | |
956 | * - the report rate when fingers are present has to be at least | |
957 | * the refresh rate of the screen, 60 or 120 Hz | |
958 | * | |
959 | * I interprete this that the specification forces a report rate of | |
960 | * at least 60 Hz for a touchscreen to be certified. | |
961 | * Which means that if we do not get a report whithin 16 ms, either | |
962 | * something wrong happens, either the touchscreen forgets to send | |
963 | * a release. Taking a reasonable margin allows to remove issues | |
964 | * with USB communication or the load of the machine. | |
965 | * | |
966 | * Given that Win 8 devices are forced to send a release, this will | |
967 | * only affect laggish machines and the ones that have a firmware | |
968 | * defect. | |
969 | */ | |
96098274 BT |
970 | if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) { |
971 | if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags)) | |
972 | mod_timer(&td->release_timer, | |
973 | jiffies + msecs_to_jiffies(100)); | |
974 | else | |
975 | del_timer(&td->release_timer); | |
976 | } | |
4f4001bc BT |
977 | |
978 | clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags); | |
5519cab4 BT |
979 | } |
980 | ||
b2c68a2f | 981 | static int mt_touch_input_configured(struct hid_device *hdev, |
a69c5f8b BT |
982 | struct hid_input *hi) |
983 | { | |
984 | struct mt_device *td = hid_get_drvdata(hdev); | |
985 | struct mt_class *cls = &td->mtclass; | |
986 | struct input_dev *input = hi->input; | |
b2c68a2f | 987 | int ret; |
a69c5f8b BT |
988 | |
989 | if (!td->maxcontacts) | |
990 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; | |
991 | ||
992 | mt_post_parse(td); | |
993 | if (td->serial_maybe) | |
994 | mt_post_parse_default_settings(td); | |
995 | ||
996 | if (cls->is_indirect) | |
997 | td->mt_flags |= INPUT_MT_POINTER; | |
998 | ||
999 | if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) | |
1000 | td->mt_flags |= INPUT_MT_DROP_UNUSED; | |
1001 | ||
015fdaa9 BT |
1002 | /* check for clickpads */ |
1003 | if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1)) | |
2c6e0277 SF |
1004 | td->is_buttonpad = true; |
1005 | ||
1006 | if (td->is_buttonpad) | |
015fdaa9 BT |
1007 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
1008 | ||
b2c68a2f DT |
1009 | ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); |
1010 | if (ret) | |
1011 | return ret; | |
a69c5f8b BT |
1012 | |
1013 | td->mt_flags = 0; | |
b2c68a2f | 1014 | return 0; |
a69c5f8b BT |
1015 | } |
1016 | ||
957b8dff JPRV |
1017 | #define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \ |
1018 | max, EV_KEY, (c)) | |
a69c5f8b BT |
1019 | static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
1020 | struct hid_field *field, struct hid_usage *usage, | |
1021 | unsigned long **bit, int *max) | |
1022 | { | |
6aef704e BT |
1023 | struct mt_device *td = hid_get_drvdata(hdev); |
1024 | ||
1025 | /* | |
1026 | * If mtclass.export_all_inputs is not set, only map fields from | |
1027 | * TouchScreen or TouchPad collections. We need to ignore fields | |
1028 | * that belong to other collections such as Mouse that might have | |
1029 | * the same GenericDesktop usages. | |
1030 | */ | |
1031 | if (!td->mtclass.export_all_inputs && | |
1032 | field->application != HID_DG_TOUCHSCREEN && | |
fa11aa72 | 1033 | field->application != HID_DG_PEN && |
8fe89ef0 BT |
1034 | field->application != HID_DG_TOUCHPAD && |
1035 | field->application != HID_GD_KEYBOARD && | |
e57f4e67 | 1036 | field->application != HID_GD_SYSTEM_CONTROL && |
1fbf74ef | 1037 | field->application != HID_CP_CONSUMER_CONTROL && |
957b8dff JPRV |
1038 | field->application != HID_GD_WIRELESS_RADIO_CTLS && |
1039 | !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && | |
1040 | td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP)) | |
6f492f28 | 1041 | return -1; |
a69c5f8b | 1042 | |
957b8dff JPRV |
1043 | /* |
1044 | * Some Asus keyboard+touchpad devices have the hotkeys defined in the | |
1045 | * touchpad report descriptor. We need to treat these as an array to | |
1046 | * map usages to input keys. | |
1047 | */ | |
39bbf402 | 1048 | if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && |
957b8dff JPRV |
1049 | td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP && |
1050 | (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) { | |
1051 | set_bit(EV_REP, hi->input->evbit); | |
1052 | if (field->flags & HID_MAIN_ITEM_VARIABLE) | |
1053 | field->flags &= ~HID_MAIN_ITEM_VARIABLE; | |
1054 | switch (usage->hid & HID_USAGE) { | |
1055 | case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break; | |
1056 | case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break; | |
1057 | case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break; | |
1058 | case 0x6b: mt_map_key_clear(KEY_F21); break; | |
1059 | case 0x6c: mt_map_key_clear(KEY_SLEEP); break; | |
1060 | default: | |
1061 | return -1; | |
1062 | } | |
1063 | return 1; | |
1064 | } | |
1065 | ||
6aef704e BT |
1066 | /* |
1067 | * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" | |
1068 | * for the stylus. | |
1cc1cc92 BA |
1069 | * The check for mt_report_id ensures we don't process |
1070 | * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical | |
1071 | * collection, but within the report ID. | |
6aef704e | 1072 | */ |
a69c5f8b | 1073 | if (field->physical == HID_DG_STYLUS) |
e55f6200 | 1074 | return 0; |
1cc1cc92 BA |
1075 | else if ((field->physical == 0) && |
1076 | (field->report->id != td->mt_report_id) && | |
1077 | (td->mt_report_id != -1)) | |
1078 | return 0; | |
a69c5f8b | 1079 | |
6aef704e BT |
1080 | if (field->application == HID_DG_TOUCHSCREEN || |
1081 | field->application == HID_DG_TOUCHPAD) | |
1082 | return mt_touch_input_mapping(hdev, hi, field, usage, bit, max); | |
1083 | ||
1084 | /* let hid-core decide for the others */ | |
1085 | return 0; | |
a69c5f8b BT |
1086 | } |
1087 | ||
1088 | static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi, | |
1089 | struct hid_field *field, struct hid_usage *usage, | |
1090 | unsigned long **bit, int *max) | |
1091 | { | |
6aef704e BT |
1092 | /* |
1093 | * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" | |
1094 | * for the stylus. | |
1095 | */ | |
fa11aa72 | 1096 | if (field->physical == HID_DG_STYLUS) |
e55f6200 | 1097 | return 0; |
fa11aa72 | 1098 | |
6aef704e | 1099 | if (field->application == HID_DG_TOUCHSCREEN || |
4cf56a89 DT |
1100 | field->application == HID_DG_TOUCHPAD) { |
1101 | /* We own these mappings, tell hid-input to ignore them */ | |
1102 | return -1; | |
1103 | } | |
6aef704e BT |
1104 | |
1105 | /* let hid-core decide for the others */ | |
1106 | return 0; | |
a69c5f8b BT |
1107 | } |
1108 | ||
1109 | static int mt_event(struct hid_device *hid, struct hid_field *field, | |
1110 | struct hid_usage *usage, __s32 value) | |
1111 | { | |
1112 | struct mt_device *td = hid_get_drvdata(hid); | |
1113 | ||
1114 | if (field->report->id == td->mt_report_id) | |
1115 | return mt_touch_event(hid, field, usage, value); | |
1116 | ||
e55f6200 | 1117 | return 0; |
a69c5f8b BT |
1118 | } |
1119 | ||
1120 | static void mt_report(struct hid_device *hid, struct hid_report *report) | |
1121 | { | |
1122 | struct mt_device *td = hid_get_drvdata(hid); | |
e55f6200 | 1123 | struct hid_field *field = report->field[0]; |
a69c5f8b BT |
1124 | |
1125 | if (!(hid->claimed & HID_CLAIMED_INPUT)) | |
1126 | return; | |
1127 | ||
1128 | if (report->id == td->mt_report_id) | |
e55f6200 | 1129 | return mt_touch_report(hid, report); |
fa11aa72 | 1130 | |
e55f6200 BT |
1131 | if (field && field->hidinput && field->hidinput->input) |
1132 | input_sync(field->hidinput->input); | |
5519cab4 BT |
1133 | } |
1134 | ||
1135 | static void mt_set_input_mode(struct hid_device *hdev) | |
1136 | { | |
1137 | struct mt_device *td = hid_get_drvdata(hdev); | |
1138 | struct hid_report *r; | |
1139 | struct hid_report_enum *re; | |
da10bc25 MM |
1140 | struct mt_class *cls = &td->mtclass; |
1141 | char *buf; | |
1142 | int report_len; | |
5519cab4 BT |
1143 | |
1144 | if (td->inputmode < 0) | |
1145 | return; | |
1146 | ||
1147 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); | |
1148 | r = re->report_id_hash[td->inputmode]; | |
1149 | if (r) { | |
da10bc25 | 1150 | if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) { |
dabb05c6 | 1151 | report_len = hid_report_len(r); |
da10bc25 MM |
1152 | buf = hid_alloc_report_buf(r, GFP_KERNEL); |
1153 | if (!buf) { | |
1154 | hid_err(hdev, "failed to allocate buffer for report\n"); | |
1155 | return; | |
1156 | } | |
1157 | hid_hw_raw_request(hdev, r->id, buf, report_len, | |
1158 | HID_FEATURE_REPORT, | |
1159 | HID_REQ_GET_REPORT); | |
1160 | kfree(buf); | |
1161 | } | |
9abebedb | 1162 | r->field[0]->value[td->inputmode_index] = td->inputmode_value; |
d8814272 | 1163 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); |
5519cab4 BT |
1164 | } |
1165 | } | |
1166 | ||
31ae9bdd BT |
1167 | static void mt_set_maxcontacts(struct hid_device *hdev) |
1168 | { | |
1169 | struct mt_device *td = hid_get_drvdata(hdev); | |
1170 | struct hid_report *r; | |
1171 | struct hid_report_enum *re; | |
1172 | int fieldmax, max; | |
1173 | ||
1174 | if (td->maxcontact_report_id < 0) | |
1175 | return; | |
1176 | ||
1177 | if (!td->mtclass.maxcontacts) | |
1178 | return; | |
1179 | ||
1180 | re = &hdev->report_enum[HID_FEATURE_REPORT]; | |
1181 | r = re->report_id_hash[td->maxcontact_report_id]; | |
1182 | if (r) { | |
1183 | max = td->mtclass.maxcontacts; | |
1184 | fieldmax = r->field[0]->logical_maximum; | |
1185 | max = min(fieldmax, max); | |
1186 | if (r->field[0]->value[0] != max) { | |
1187 | r->field[0]->value[0] = max; | |
d8814272 | 1188 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); |
31ae9bdd BT |
1189 | } |
1190 | } | |
1191 | } | |
1192 | ||
4fa3a583 HR |
1193 | static void mt_post_parse_default_settings(struct mt_device *td) |
1194 | { | |
1195 | __s32 quirks = td->mtclass.quirks; | |
1196 | ||
1197 | /* unknown serial device needs special quirks */ | |
1198 | if (td->touches_by_report == 1) { | |
1199 | quirks |= MT_QUIRK_ALWAYS_VALID; | |
1200 | quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP; | |
1201 | quirks &= ~MT_QUIRK_VALID_IS_INRANGE; | |
1202 | quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE; | |
e0bb8f9a | 1203 | quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; |
4fa3a583 HR |
1204 | } |
1205 | ||
1206 | td->mtclass.quirks = quirks; | |
1207 | } | |
1208 | ||
3ac36d15 BT |
1209 | static void mt_post_parse(struct mt_device *td) |
1210 | { | |
1211 | struct mt_fields *f = td->fields; | |
c2517f62 | 1212 | struct mt_class *cls = &td->mtclass; |
3ac36d15 BT |
1213 | |
1214 | if (td->touches_by_report > 0) { | |
1215 | int field_count_per_touch = f->length / td->touches_by_report; | |
1216 | td->last_slot_field = f->usages[field_count_per_touch - 1]; | |
1217 | } | |
c2517f62 | 1218 | |
7e3cc447 | 1219 | if (td->cc_index < 0) |
c2517f62 | 1220 | cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; |
3ac36d15 BT |
1221 | } |
1222 | ||
b2c68a2f | 1223 | static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) |
76f5902a HR |
1224 | { |
1225 | struct mt_device *td = hid_get_drvdata(hdev); | |
c08d46aa BT |
1226 | char *name; |
1227 | const char *suffix = NULL; | |
6aef704e | 1228 | struct hid_field *field = hi->report->field[0]; |
b2c68a2f | 1229 | int ret; |
76f5902a | 1230 | |
b2c68a2f DT |
1231 | if (hi->report->id == td->mt_report_id) { |
1232 | ret = mt_touch_input_configured(hdev, hi); | |
1233 | if (ret) | |
1234 | return ret; | |
1235 | } | |
76f5902a | 1236 | |
6aef704e BT |
1237 | /* |
1238 | * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" | |
1239 | * for the stylus. Check this first, and then rely on the application | |
1240 | * field. | |
1241 | */ | |
c08d46aa BT |
1242 | if (hi->report->field[0]->physical == HID_DG_STYLUS) { |
1243 | suffix = "Pen"; | |
e55f6200 BT |
1244 | /* force BTN_STYLUS to allow tablet matching in udev */ |
1245 | __set_bit(BTN_STYLUS, hi->input->keybit); | |
6aef704e BT |
1246 | } else { |
1247 | switch (field->application) { | |
1248 | case HID_GD_KEYBOARD: | |
1249 | suffix = "Keyboard"; | |
1250 | break; | |
1251 | case HID_GD_KEYPAD: | |
1252 | suffix = "Keypad"; | |
1253 | break; | |
1254 | case HID_GD_MOUSE: | |
1255 | suffix = "Mouse"; | |
1256 | break; | |
1257 | case HID_DG_STYLUS: | |
1258 | suffix = "Pen"; | |
1259 | /* force BTN_STYLUS to allow tablet matching in udev */ | |
1260 | __set_bit(BTN_STYLUS, hi->input->keybit); | |
1261 | break; | |
1262 | case HID_DG_TOUCHSCREEN: | |
1263 | /* we do not set suffix = "Touchscreen" */ | |
1264 | break; | |
dc425a1c MW |
1265 | case HID_DG_TOUCHPAD: |
1266 | suffix = "Touchpad"; | |
1267 | break; | |
6aef704e BT |
1268 | case HID_GD_SYSTEM_CONTROL: |
1269 | suffix = "System Control"; | |
1270 | break; | |
1271 | case HID_CP_CONSUMER_CONTROL: | |
1272 | suffix = "Consumer Control"; | |
1273 | break; | |
1fbf74ef JPRV |
1274 | case HID_GD_WIRELESS_RADIO_CTLS: |
1275 | suffix = "Wireless Radio Control"; | |
1276 | break; | |
957b8dff JPRV |
1277 | case HID_VD_ASUS_CUSTOM_MEDIA_KEYS: |
1278 | suffix = "Custom Media Keys"; | |
1279 | break; | |
6aef704e BT |
1280 | default: |
1281 | suffix = "UNKNOWN"; | |
1282 | break; | |
1283 | } | |
c08d46aa BT |
1284 | } |
1285 | ||
1286 | if (suffix) { | |
1287 | name = devm_kzalloc(&hi->input->dev, | |
1288 | strlen(hdev->name) + strlen(suffix) + 2, | |
1289 | GFP_KERNEL); | |
1290 | if (name) { | |
1291 | sprintf(name, "%s %s", hdev->name, suffix); | |
1292 | hi->input->name = name; | |
1293 | } | |
1294 | } | |
b2c68a2f DT |
1295 | |
1296 | return 0; | |
76f5902a HR |
1297 | } |
1298 | ||
f3287a99 BT |
1299 | static void mt_fix_const_field(struct hid_field *field, unsigned int usage) |
1300 | { | |
1301 | if (field->usage[0].hid != usage || | |
1302 | !(field->flags & HID_MAIN_ITEM_CONSTANT)) | |
1303 | return; | |
1304 | ||
1305 | field->flags &= ~HID_MAIN_ITEM_CONSTANT; | |
1306 | field->flags |= HID_MAIN_ITEM_VARIABLE; | |
1307 | } | |
1308 | ||
1309 | static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage) | |
1310 | { | |
1311 | struct hid_report *report; | |
1312 | int i; | |
1313 | ||
1314 | list_for_each_entry(report, | |
1315 | &hdev->report_enum[HID_INPUT_REPORT].report_list, | |
1316 | list) { | |
1317 | ||
1318 | if (!report->maxfield) | |
1319 | continue; | |
1320 | ||
1321 | for (i = 0; i < report->maxfield; i++) | |
1322 | if (report->field[i]->maxusage >= 1) | |
1323 | mt_fix_const_field(report->field[i], usage); | |
1324 | } | |
1325 | } | |
1326 | ||
4f4001bc BT |
1327 | static void mt_release_contacts(struct hid_device *hid) |
1328 | { | |
1329 | struct hid_input *hidinput; | |
1330 | struct mt_device *td = hid_get_drvdata(hid); | |
1331 | ||
1332 | list_for_each_entry(hidinput, &hid->inputs, list) { | |
1333 | struct input_dev *input_dev = hidinput->input; | |
1334 | struct input_mt *mt = input_dev->mt; | |
1335 | int i; | |
1336 | ||
1337 | if (mt) { | |
1338 | for (i = 0; i < mt->num_slots; i++) { | |
1339 | input_mt_slot(input_dev, i); | |
1340 | input_mt_report_slot_state(input_dev, | |
1341 | MT_TOOL_FINGER, | |
1342 | false); | |
1343 | } | |
1344 | input_mt_sync_frame(input_dev); | |
1345 | input_sync(input_dev); | |
1346 | } | |
1347 | } | |
1348 | ||
1349 | td->num_received = 0; | |
1350 | } | |
1351 | ||
0ee32774 | 1352 | static void mt_expired_timeout(struct timer_list *t) |
4f4001bc | 1353 | { |
0ee32774 KC |
1354 | struct mt_device *td = from_timer(td, t, release_timer); |
1355 | struct hid_device *hdev = td->hdev; | |
4f4001bc BT |
1356 | |
1357 | /* | |
1358 | * An input report came in just before we release the sticky fingers, | |
1359 | * it will take care of the sticky fingers. | |
1360 | */ | |
1361 | if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) | |
1362 | return; | |
96098274 BT |
1363 | if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags)) |
1364 | mt_release_contacts(hdev); | |
4f4001bc BT |
1365 | clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags); |
1366 | } | |
1367 | ||
5519cab4 BT |
1368 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
1369 | { | |
2d93666e | 1370 | int ret, i; |
5519cab4 | 1371 | struct mt_device *td; |
2d93666e BT |
1372 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
1373 | ||
94b5485c HR |
1374 | for (i = 0; mt_classes[i].name ; i++) { |
1375 | if (id->driver_data == mt_classes[i].name) { | |
1376 | mtclass = &(mt_classes[i]); | |
1377 | break; | |
2d93666e BT |
1378 | } |
1379 | } | |
5519cab4 | 1380 | |
c08d46aa | 1381 | td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL); |
5519cab4 BT |
1382 | if (!td) { |
1383 | dev_err(&hdev->dev, "cannot allocate multitouch data\n"); | |
1384 | return -ENOMEM; | |
1385 | } | |
0ee32774 | 1386 | td->hdev = hdev; |
eec29e3d | 1387 | td->mtclass = *mtclass; |
5519cab4 | 1388 | td->inputmode = -1; |
31ae9bdd | 1389 | td->maxcontact_report_id = -1; |
9abebedb | 1390 | td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; |
7e3cc447 | 1391 | td->cc_index = -1; |
af8dc4d0 | 1392 | td->scantime_index = -1; |
fa11aa72 | 1393 | td->mt_report_id = -1; |
5519cab4 BT |
1394 | hid_set_drvdata(hdev, td); |
1395 | ||
c08d46aa BT |
1396 | td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields), |
1397 | GFP_KERNEL); | |
3ac36d15 BT |
1398 | if (!td->fields) { |
1399 | dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); | |
c08d46aa | 1400 | return -ENOMEM; |
3ac36d15 BT |
1401 | } |
1402 | ||
76f5902a HR |
1403 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) |
1404 | td->serial_maybe = true; | |
1405 | ||
b897f6db BT |
1406 | /* |
1407 | * Store the initial quirk state | |
1408 | */ | |
1409 | td->initial_quirks = hdev->quirks; | |
1410 | ||
1411 | /* This allows the driver to correctly support devices | |
1412 | * that emit events over several HID messages. | |
1413 | */ | |
1414 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; | |
1415 | ||
1416 | /* | |
1417 | * This allows the driver to handle different input sensors | |
1418 | * that emits events through different reports on the same HID | |
1419 | * device. | |
1420 | */ | |
1421 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | |
1422 | hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT; | |
1423 | ||
1424 | /* | |
1425 | * Some multitouch screens do not like to be polled for input | |
1426 | * reports. Fortunately, the Win8 spec says that all touches | |
1427 | * should be sent during each report, making the initialization | |
1428 | * of input reports unnecessary. For Win7 devices, well, let's hope | |
1429 | * they will still be happy (this is only be a problem if a touch | |
1430 | * was already there while probing the device). | |
1431 | * | |
1432 | * In addition some touchpads do not behave well if we read | |
1433 | * all feature reports from them. Instead we prevent | |
1434 | * initial report fetching and then selectively fetch each | |
1435 | * report we are interested in. | |
1436 | */ | |
1437 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; | |
1438 | ||
0ee32774 | 1439 | timer_setup(&td->release_timer, mt_expired_timeout, 0); |
4f4001bc | 1440 | |
5519cab4 BT |
1441 | ret = hid_parse(hdev); |
1442 | if (ret != 0) | |
c08d46aa | 1443 | return ret; |
5519cab4 | 1444 | |
f3287a99 BT |
1445 | if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID) |
1446 | mt_fix_const_fields(hdev, HID_DG_CONTACTID); | |
1447 | ||
5519cab4 | 1448 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
2d93666e | 1449 | if (ret) |
c08d46aa | 1450 | return ret; |
5519cab4 | 1451 | |
eec29e3d | 1452 | ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); |
0c4b3c63 NK |
1453 | if (ret) |
1454 | dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n", | |
1455 | hdev->name); | |
eec29e3d | 1456 | |
31ae9bdd | 1457 | mt_set_maxcontacts(hdev); |
5519cab4 BT |
1458 | mt_set_input_mode(hdev); |
1459 | ||
c08d46aa BT |
1460 | /* release .fields memory as it is not used anymore */ |
1461 | devm_kfree(&hdev->dev, td->fields); | |
3ac36d15 BT |
1462 | td->fields = NULL; |
1463 | ||
5519cab4 | 1464 | return 0; |
5519cab4 BT |
1465 | } |
1466 | ||
1467 | #ifdef CONFIG_PM | |
1468 | static int mt_reset_resume(struct hid_device *hdev) | |
1469 | { | |
d3e69b9a | 1470 | mt_release_contacts(hdev); |
31ae9bdd | 1471 | mt_set_maxcontacts(hdev); |
5519cab4 BT |
1472 | mt_set_input_mode(hdev); |
1473 | return 0; | |
1474 | } | |
dfeefd10 SL |
1475 | |
1476 | static int mt_resume(struct hid_device *hdev) | |
1477 | { | |
dfeefd10 SL |
1478 | /* Some Elan legacy devices require SET_IDLE to be set on resume. |
1479 | * It should be safe to send it to other devices too. | |
1480 | * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */ | |
1481 | ||
4ba25d3f | 1482 | hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE); |
dfeefd10 SL |
1483 | |
1484 | return 0; | |
1485 | } | |
5519cab4 BT |
1486 | #endif |
1487 | ||
1488 | static void mt_remove(struct hid_device *hdev) | |
1489 | { | |
b897f6db BT |
1490 | struct mt_device *td = hid_get_drvdata(hdev); |
1491 | ||
4f4001bc BT |
1492 | del_timer_sync(&td->release_timer); |
1493 | ||
eec29e3d | 1494 | sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); |
5939212d | 1495 | hid_hw_stop(hdev); |
b897f6db | 1496 | hdev->quirks = td->initial_quirks; |
5519cab4 BT |
1497 | } |
1498 | ||
0fa9c616 BT |
1499 | /* |
1500 | * This list contains only: | |
1501 | * - VID/PID of products not working with the default multitouch handling | |
1502 | * - 2 generic rules. | |
1503 | * So there is no point in adding here any device with MT_CLS_DEFAULT. | |
1504 | */ | |
5519cab4 BT |
1505 | static const struct hid_device_id mt_devices[] = { |
1506 | ||
f786bba4 BT |
1507 | /* 3M panels */ |
1508 | { .driver_data = MT_CLS_3M, | |
2c2110e9 | 1509 | MT_USB_DEVICE(USB_VENDOR_ID_3M, |
f786bba4 BT |
1510 | USB_DEVICE_ID_3M1968) }, |
1511 | { .driver_data = MT_CLS_3M, | |
2c2110e9 | 1512 | MT_USB_DEVICE(USB_VENDOR_ID_3M, |
f786bba4 | 1513 | USB_DEVICE_ID_3M2256) }, |
c4fad877 | 1514 | { .driver_data = MT_CLS_3M, |
2c2110e9 | 1515 | MT_USB_DEVICE(USB_VENDOR_ID_3M, |
c4fad877 | 1516 | USB_DEVICE_ID_3M3266) }, |
f786bba4 | 1517 | |
504c932c MO |
1518 | /* Alps devices */ |
1519 | { .driver_data = MT_CLS_WIN_8_DUAL, | |
1520 | HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, | |
1521 | USB_VENDOR_ID_ALPS_JP, | |
1522 | HID_DEVICE_ID_ALPS_U1_DUAL_PTP) }, | |
1523 | { .driver_data = MT_CLS_WIN_8_DUAL, | |
1524 | HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, | |
1525 | USB_VENDOR_ID_ALPS_JP, | |
1526 | HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) }, | |
1527 | ||
56d859e1 PT |
1528 | /* Lenovo X1 TAB Gen 2 */ |
1529 | { .driver_data = MT_CLS_WIN_8_DUAL, | |
1530 | HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, | |
1531 | USB_VENDOR_ID_LENOVO, | |
1532 | USB_DEVICE_ID_LENOVO_X1_TAB) }, | |
1533 | ||
6aef704e BT |
1534 | /* Anton devices */ |
1535 | { .driver_data = MT_CLS_EXPORT_ALL_INPUTS, | |
1536 | MT_USB_DEVICE(USB_VENDOR_ID_ANTON, | |
1537 | USB_DEVICE_ID_ANTON_TOUCH_PAD) }, | |
e6aac342 | 1538 | |
957b8dff JPRV |
1539 | /* Asus T304UA */ |
1540 | { .driver_data = MT_CLS_ASUS, | |
1541 | HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, | |
1542 | USB_VENDOR_ID_ASUSTEK, | |
1543 | USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) }, | |
1544 | ||
b1057124 | 1545 | /* Atmel panels */ |
841cb157 | 1546 | { .driver_data = MT_CLS_SERIAL, |
2c2110e9 | 1547 | MT_USB_DEVICE(USB_VENDOR_ID_ATMEL, |
841cb157 | 1548 | USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) }, |
b1057124 | 1549 | |
9ed32695 | 1550 | /* Baanto multitouch devices */ |
dc3e1d80 | 1551 | { .driver_data = MT_CLS_NSMU, |
16b79bb8 | 1552 | MT_USB_DEVICE(USB_VENDOR_ID_BAANTO, |
9ed32695 | 1553 | USB_DEVICE_ID_BAANTO_MT_190W2) }, |
0fa9c616 | 1554 | |
a841b62c BT |
1555 | /* Cando panels */ |
1556 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, | |
2c2110e9 | 1557 | MT_USB_DEVICE(USB_VENDOR_ID_CANDO, |
a841b62c | 1558 | USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, |
a841b62c | 1559 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
2c2110e9 | 1560 | MT_USB_DEVICE(USB_VENDOR_ID_CANDO, |
a841b62c BT |
1561 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) }, |
1562 | ||
942fd422 | 1563 | /* Chunghwa Telecom touch panels */ |
dc3e1d80 | 1564 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1565 | MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, |
942fd422 AZ |
1566 | USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) }, |
1567 | ||
070f63b4 YB |
1568 | /* CJTouch panels */ |
1569 | { .driver_data = MT_CLS_NSMU, | |
1570 | MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH, | |
1571 | USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) }, | |
1572 | { .driver_data = MT_CLS_NSMU, | |
1573 | MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH, | |
1574 | USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) }, | |
1575 | ||
79603dc9 | 1576 | /* CVTouch panels */ |
dc3e1d80 | 1577 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1578 | MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, |
79603dc9 BT |
1579 | USB_DEVICE_ID_CVTOUCH_SCREEN) }, |
1580 | ||
22408283 | 1581 | /* eGalax devices (resistive) */ |
e36f690b | 1582 | { .driver_data = MT_CLS_EGALAX, |
2c2110e9 | 1583 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b BT |
1584 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) }, |
1585 | { .driver_data = MT_CLS_EGALAX, | |
2c2110e9 | 1586 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b | 1587 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) }, |
22408283 BT |
1588 | |
1589 | /* eGalax devices (capacitive) */ | |
fd1d1525 | 1590 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1591 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
fd1d1525 | 1592 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) }, |
aa672da1 | 1593 | { .driver_data = MT_CLS_EGALAX, |
2c2110e9 | 1594 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
aa672da1 | 1595 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) }, |
fd1d1525 | 1596 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1597 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
fd1d1525 | 1598 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) }, |
2ce09df4 | 1599 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1600 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
2ce09df4 | 1601 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) }, |
aa672da1 | 1602 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1603 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
aa672da1 | 1604 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) }, |
fd1d1525 | 1605 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1606 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
fd1d1525 | 1607 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) }, |
aa672da1 AS |
1608 | { .driver_data = MT_CLS_EGALAX, |
1609 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, | |
1610 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) }, | |
e36f690b | 1611 | { .driver_data = MT_CLS_EGALAX, |
2c2110e9 | 1612 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b | 1613 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) }, |
fd1d1525 | 1614 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1615 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
fd1d1525 | 1616 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) }, |
aa672da1 AS |
1617 | { .driver_data = MT_CLS_EGALAX, |
1618 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, | |
1619 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) }, | |
1620 | { .driver_data = MT_CLS_EGALAX, | |
1621 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, | |
1622 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) }, | |
66f06127 | 1623 | { .driver_data = MT_CLS_EGALAX, |
2c2110e9 | 1624 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
66f06127 | 1625 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) }, |
bb9ff210 | 1626 | { .driver_data = MT_CLS_EGALAX, |
2c2110e9 | 1627 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
bb9ff210 | 1628 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) }, |
fd1d1525 | 1629 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1630 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
fd1d1525 | 1631 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) }, |
1b723e8d | 1632 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
ae01c9e5 TR |
1633 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
1634 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) }, | |
1b723e8d | 1635 | { .driver_data = MT_CLS_EGALAX_SERIAL, |
2c2110e9 | 1636 | MT_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b | 1637 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) }, |
22408283 | 1638 | |
7c7606a2 TS |
1639 | /* Elitegroup panel */ |
1640 | { .driver_data = MT_CLS_SERIAL, | |
1641 | MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP, | |
1642 | USB_DEVICE_ID_ELITEGROUP_05D8) }, | |
1643 | ||
77723e3b HR |
1644 | /* Flatfrog Panels */ |
1645 | { .driver_data = MT_CLS_FLATFROG, | |
1646 | MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG, | |
1647 | USB_DEVICE_ID_MULTITOUCH_3200) }, | |
1648 | ||
3db187e7 BT |
1649 | /* FocalTech Panels */ |
1650 | { .driver_data = MT_CLS_SERIAL, | |
1651 | MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL, | |
1652 | USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) }, | |
1653 | ||
5572da08 | 1654 | /* GeneralTouch panel */ |
f5ff4e1e | 1655 | { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS, |
2c2110e9 | 1656 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, |
5572da08 | 1657 | USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) }, |
f5ff4e1e XY |
1658 | { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS, |
1659 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | |
1660 | USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) }, | |
7b226292 L |
1661 | { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS, |
1662 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | |
1663 | USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) }, | |
1664 | { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS, | |
1665 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | |
1666 | USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) }, | |
1667 | { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS, | |
1668 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | |
1669 | USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) }, | |
1670 | { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS, | |
1671 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | |
1672 | USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) }, | |
1673 | { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS, | |
1674 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | |
1675 | USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) }, | |
5572da08 | 1676 | |
4d5df5d1 | 1677 | /* Gametel game controller */ |
dc3e1d80 | 1678 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1679 | MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL, |
4d5df5d1 AN |
1680 | USB_DEVICE_ID_GAMETEL_MT_MODE) }, |
1681 | ||
ee0fbd14 | 1682 | /* GoodTouch panels */ |
dc3e1d80 | 1683 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1684 | MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, |
ee0fbd14 BT |
1685 | USB_DEVICE_ID_GOODTOUCH_000f) }, |
1686 | ||
54580365 BT |
1687 | /* Hanvon panels */ |
1688 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, | |
2c2110e9 | 1689 | MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT, |
54580365 BT |
1690 | USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) }, |
1691 | ||
4e61f0d7 | 1692 | /* Ilitek dual touch panel */ |
dc3e1d80 | 1693 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1694 | MT_USB_DEVICE(USB_VENDOR_ID_ILITEK, |
4e61f0d7 AZ |
1695 | USB_DEVICE_ID_ILITEK_MULTITOUCH) }, |
1696 | ||
f3287a99 BT |
1697 | /* LG Melfas panel */ |
1698 | { .driver_data = MT_CLS_LG, | |
1699 | HID_USB_DEVICE(USB_VENDOR_ID_LG, | |
1700 | USB_DEVICE_ID_LG_MELFAS_MT) }, | |
1701 | ||
4a6ee685 BT |
1702 | /* MosArt panels */ |
1703 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
2c2110e9 | 1704 | MT_USB_DEVICE(USB_VENDOR_ID_ASUS, |
4a6ee685 BT |
1705 | USB_DEVICE_ID_ASUS_T91MT)}, |
1706 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
2c2110e9 | 1707 | MT_USB_DEVICE(USB_VENDOR_ID_ASUS, |
4a6ee685 BT |
1708 | USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) }, |
1709 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
2c2110e9 | 1710 | MT_USB_DEVICE(USB_VENDOR_ID_TURBOX, |
4a6ee685 BT |
1711 | USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) }, |
1712 | ||
4db703ea | 1713 | /* Novatek Panel */ |
dc3e1d80 | 1714 | { .driver_data = MT_CLS_NSMU, |
4380d819 | 1715 | MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK, |
4db703ea AH |
1716 | USB_DEVICE_ID_NOVATEK_PCT) }, |
1717 | ||
a80e803a BT |
1718 | /* Ntrig Panel */ |
1719 | { .driver_data = MT_CLS_NSMU, | |
1720 | HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, | |
1721 | USB_VENDOR_ID_NTRIG, 0x1b05) }, | |
1722 | ||
fb55b402 HG |
1723 | /* Panasonic panels */ |
1724 | { .driver_data = MT_CLS_PANASONIC, | |
1725 | MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC, | |
1726 | USB_DEVICE_ID_PANABOARD_UBT780) }, | |
1727 | { .driver_data = MT_CLS_PANASONIC, | |
1728 | MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC, | |
1729 | USB_DEVICE_ID_PANABOARD_UBT880) }, | |
1730 | ||
b7ea95ff AT |
1731 | /* PixArt optical touch screen */ |
1732 | { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER, | |
2c2110e9 | 1733 | MT_USB_DEVICE(USB_VENDOR_ID_PIXART, |
b7ea95ff AT |
1734 | USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) }, |
1735 | { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER, | |
2c2110e9 | 1736 | MT_USB_DEVICE(USB_VENDOR_ID_PIXART, |
b7ea95ff AT |
1737 | USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) }, |
1738 | { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER, | |
2c2110e9 | 1739 | MT_USB_DEVICE(USB_VENDOR_ID_PIXART, |
b7ea95ff AT |
1740 | USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) }, |
1741 | ||
5519cab4 | 1742 | /* PixCir-based panels */ |
1e9cf35b | 1743 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
2c2110e9 | 1744 | MT_USB_DEVICE(USB_VENDOR_ID_CANDO, |
5519cab4 BT |
1745 | USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) }, |
1746 | ||
5e7ea11f | 1747 | /* Quanta-based panels */ |
5e7ea11f | 1748 | { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID, |
2c2110e9 | 1749 | MT_USB_DEVICE(USB_VENDOR_ID_QUANTA, |
5e7ea11f | 1750 | USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) }, |
a6802e00 | 1751 | |
043b403a | 1752 | /* Stantum panels */ |
bf5af9b5 | 1753 | { .driver_data = MT_CLS_CONFIDENCE, |
2c2110e9 | 1754 | MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, |
043b403a | 1755 | USB_DEVICE_ID_MTP_STM)}, |
043b403a | 1756 | |
847672cd BT |
1757 | /* TopSeed panels */ |
1758 | { .driver_data = MT_CLS_TOPSEED, | |
2c2110e9 | 1759 | MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, |
847672cd BT |
1760 | USB_DEVICE_ID_TOPSEED2_PERIPAD_701) }, |
1761 | ||
5e74e56d | 1762 | /* Touch International panels */ |
dc3e1d80 | 1763 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1764 | MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, |
5e74e56d BT |
1765 | USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) }, |
1766 | ||
617b64f9 | 1767 | /* Unitec panels */ |
dc3e1d80 | 1768 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1769 | MT_USB_DEVICE(USB_VENDOR_ID_UNITEC, |
617b64f9 | 1770 | USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) }, |
dc3e1d80 | 1771 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1772 | MT_USB_DEVICE(USB_VENDOR_ID_UNITEC, |
617b64f9 | 1773 | USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) }, |
bf9d121e | 1774 | |
da10bc25 MM |
1775 | /* VTL panels */ |
1776 | { .driver_data = MT_CLS_VTL, | |
1777 | MT_USB_DEVICE(USB_VENDOR_ID_VTL, | |
1778 | USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) }, | |
1779 | ||
bf9d121e KC |
1780 | /* Wistron panels */ |
1781 | { .driver_data = MT_CLS_NSMU, | |
1782 | MT_USB_DEVICE(USB_VENDOR_ID_WISTRON, | |
1783 | USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) }, | |
1784 | ||
bc8a2a9b | 1785 | /* XAT */ |
dc3e1d80 | 1786 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1787 | MT_USB_DEVICE(USB_VENDOR_ID_XAT, |
bc8a2a9b | 1788 | USB_DEVICE_ID_XAT_CSR) }, |
617b64f9 | 1789 | |
11576c61 | 1790 | /* Xiroku */ |
dc3e1d80 | 1791 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1792 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1793 | USB_DEVICE_ID_XIROKU_SPX) }, |
dc3e1d80 | 1794 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1795 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1796 | USB_DEVICE_ID_XIROKU_MPX) }, |
dc3e1d80 | 1797 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1798 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1799 | USB_DEVICE_ID_XIROKU_CSR) }, |
dc3e1d80 | 1800 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1801 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1802 | USB_DEVICE_ID_XIROKU_SPX1) }, |
dc3e1d80 | 1803 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1804 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1805 | USB_DEVICE_ID_XIROKU_MPX1) }, |
dc3e1d80 | 1806 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1807 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1808 | USB_DEVICE_ID_XIROKU_CSR1) }, |
dc3e1d80 | 1809 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1810 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1811 | USB_DEVICE_ID_XIROKU_SPX2) }, |
dc3e1d80 | 1812 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1813 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 | 1814 | USB_DEVICE_ID_XIROKU_MPX2) }, |
dc3e1d80 | 1815 | { .driver_data = MT_CLS_NSMU, |
2c2110e9 | 1816 | MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, |
11576c61 MH |
1817 | USB_DEVICE_ID_XIROKU_CSR2) }, |
1818 | ||
0e82232c WNH |
1819 | /* Google MT devices */ |
1820 | { .driver_data = MT_CLS_GOOGLE, | |
1821 | HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE, | |
1822 | USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) }, | |
1823 | ||
4fa3a583 HR |
1824 | /* Generic MT device */ |
1825 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) }, | |
f961bd35 BT |
1826 | |
1827 | /* Generic Win 8 certified MT device */ | |
1828 | { .driver_data = MT_CLS_WIN_8, | |
1829 | HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8, | |
1830 | HID_ANY_ID, HID_ANY_ID) }, | |
5519cab4 BT |
1831 | { } |
1832 | }; | |
1833 | MODULE_DEVICE_TABLE(hid, mt_devices); | |
1834 | ||
1835 | static const struct hid_usage_id mt_grabbed_usages[] = { | |
1836 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, | |
1837 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} | |
1838 | }; | |
1839 | ||
1840 | static struct hid_driver mt_driver = { | |
1841 | .name = "hid-multitouch", | |
1842 | .id_table = mt_devices, | |
1843 | .probe = mt_probe, | |
1844 | .remove = mt_remove, | |
1845 | .input_mapping = mt_input_mapping, | |
1846 | .input_mapped = mt_input_mapped, | |
76f5902a | 1847 | .input_configured = mt_input_configured, |
5519cab4 BT |
1848 | .feature_mapping = mt_feature_mapping, |
1849 | .usage_table = mt_grabbed_usages, | |
1850 | .event = mt_event, | |
55978fa9 | 1851 | .report = mt_report, |
5519cab4 BT |
1852 | #ifdef CONFIG_PM |
1853 | .reset_resume = mt_reset_resume, | |
dfeefd10 | 1854 | .resume = mt_resume, |
5519cab4 BT |
1855 | #endif |
1856 | }; | |
f425458e | 1857 | module_hid_driver(mt_driver); |