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