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