]>
Commit | Line | Data |
---|---|---|
5519cab4 BT |
1 | /* |
2 | * HID driver for multitouch panels | |
3 | * | |
4 | * Copyright (c) 2010-2011 Stephane Chatty <chatty@enac.fr> | |
5 | * Copyright (c) 2010-2011 Benjamin Tissoires <benjamin.tissoires@gmail.com> | |
6 | * Copyright (c) 2010-2011 Ecole Nationale de l'Aviation Civile, France | |
7 | * | |
4875ac11 RN |
8 | * This code is partly based on hid-egalax.c: |
9 | * | |
10 | * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr> | |
11 | * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se> | |
12 | * Copyright (c) 2010 Canonical, Ltd. | |
13 | * | |
f786bba4 BT |
14 | * This code is partly based on hid-3m-pct.c: |
15 | * | |
16 | * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr> | |
17 | * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se> | |
18 | * Copyright (c) 2010 Canonical, Ltd. | |
19 | * | |
5519cab4 BT |
20 | */ |
21 | ||
22 | /* | |
23 | * This program is free software; you can redistribute it and/or modify it | |
24 | * under the terms of the GNU General Public License as published by the Free | |
25 | * Software Foundation; either version 2 of the License, or (at your option) | |
26 | * any later version. | |
27 | */ | |
28 | ||
29 | #include <linux/device.h> | |
30 | #include <linux/hid.h> | |
31 | #include <linux/module.h> | |
32 | #include <linux/slab.h> | |
33 | #include <linux/usb.h> | |
34 | #include <linux/input/mt.h> | |
35 | #include "usbhid/usbhid.h" | |
36 | ||
37 | ||
38 | MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>"); | |
ef2fafb3 | 39 | MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); |
5519cab4 BT |
40 | MODULE_DESCRIPTION("HID multitouch panels"); |
41 | MODULE_LICENSE("GPL"); | |
42 | ||
43 | #include "hid-ids.h" | |
44 | ||
45 | /* quirks to control the device */ | |
46 | #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0) | |
47 | #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1) | |
2d93666e | 48 | #define MT_QUIRK_CYPRESS (1 << 2) |
5572da08 | 49 | #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3) |
a062cc5a SC |
50 | #define MT_QUIRK_ALWAYS_VALID (1 << 4) |
51 | #define MT_QUIRK_VALID_IS_INRANGE (1 << 5) | |
52 | #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6) | |
a062cc5a | 53 | #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8) |
5519cab4 BT |
54 | |
55 | struct mt_slot { | |
56 | __s32 x, y, p, w, h; | |
57 | __s32 contactid; /* the device ContactID assigned to this slot */ | |
58 | bool touch_state; /* is the touch valid? */ | |
59 | bool seen_in_this_frame;/* has this slot been updated */ | |
60 | }; | |
61 | ||
eec29e3d BT |
62 | struct mt_class { |
63 | __s32 name; /* MT_CLS */ | |
64 | __s32 quirks; | |
65 | __s32 sn_move; /* Signal/noise ratio for move events */ | |
66 | __s32 sn_width; /* Signal/noise ratio for width events */ | |
67 | __s32 sn_height; /* Signal/noise ratio for height events */ | |
68 | __s32 sn_pressure; /* Signal/noise ratio for pressure events */ | |
69 | __u8 maxcontacts; | |
70 | }; | |
71 | ||
5519cab4 BT |
72 | struct mt_device { |
73 | struct mt_slot curdata; /* placeholder of incoming data */ | |
eec29e3d | 74 | struct mt_class mtclass; /* our mt device class */ |
5519cab4 BT |
75 | unsigned last_field_index; /* last field index of the report */ |
76 | unsigned last_slot_field; /* the last field of a slot */ | |
b84bd27f | 77 | int last_mt_collection; /* last known mt-related collection */ |
5519cab4 BT |
78 | __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ |
79 | __u8 num_received; /* how many contacts we received */ | |
80 | __u8 num_expected; /* expected last contact index */ | |
9498f954 | 81 | __u8 maxcontacts; |
5519cab4 | 82 | bool curvalid; /* is the current contact valid? */ |
9498f954 | 83 | struct mt_slot *slots; |
5519cab4 BT |
84 | }; |
85 | ||
5519cab4 | 86 | /* classes of device behavior */ |
22408283 BT |
87 | #define MT_CLS_DEFAULT 0x0001 |
88 | ||
a062cc5a SC |
89 | #define MT_CLS_SERIAL 0x0002 |
90 | #define MT_CLS_CONFIDENCE 0x0003 | |
91 | #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0004 | |
92 | #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0005 | |
93 | #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0006 | |
94 | #define MT_CLS_DUAL_NSMU_CONTACTID 0x0007 | |
22408283 BT |
95 | |
96 | /* vendor specific classes */ | |
97 | #define MT_CLS_3M 0x0101 | |
98 | #define MT_CLS_CYPRESS 0x0102 | |
99 | #define MT_CLS_EGALAX 0x0103 | |
5519cab4 | 100 | |
9498f954 BT |
101 | #define MT_DEFAULT_MAXCONTACT 10 |
102 | ||
5519cab4 BT |
103 | /* |
104 | * these device-dependent functions determine what slot corresponds | |
105 | * to a valid contact that was just read. | |
106 | */ | |
107 | ||
a3b5e577 BT |
108 | static int cypress_compute_slot(struct mt_device *td) |
109 | { | |
110 | if (td->curdata.contactid != 0 || td->num_received == 0) | |
111 | return td->curdata.contactid; | |
112 | else | |
113 | return -1; | |
114 | } | |
115 | ||
5519cab4 BT |
116 | static int find_slot_from_contactid(struct mt_device *td) |
117 | { | |
118 | int i; | |
9498f954 | 119 | for (i = 0; i < td->maxcontacts; ++i) { |
5519cab4 BT |
120 | if (td->slots[i].contactid == td->curdata.contactid && |
121 | td->slots[i].touch_state) | |
122 | return i; | |
123 | } | |
9498f954 | 124 | for (i = 0; i < td->maxcontacts; ++i) { |
5519cab4 BT |
125 | if (!td->slots[i].seen_in_this_frame && |
126 | !td->slots[i].touch_state) | |
127 | return i; | |
128 | } | |
5519cab4 BT |
129 | /* should not occurs. If this happens that means |
130 | * that the device sent more touches that it says | |
131 | * in the report descriptor. It is ignored then. */ | |
2d93666e | 132 | return -1; |
5519cab4 BT |
133 | } |
134 | ||
135 | struct mt_class mt_classes[] = { | |
2d93666e | 136 | { .name = MT_CLS_DEFAULT, |
9498f954 | 137 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP }, |
a062cc5a SC |
138 | { .name = MT_CLS_SERIAL, |
139 | .quirks = MT_QUIRK_ALWAYS_VALID}, | |
22408283 BT |
140 | { .name = MT_CLS_CONFIDENCE, |
141 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE }, | |
142 | { .name = MT_CLS_CONFIDENCE_MINUS_ONE, | |
143 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | | |
144 | MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE }, | |
1e9cf35b | 145 | { .name = MT_CLS_DUAL_INRANGE_CONTACTID, |
2d93666e BT |
146 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
147 | MT_QUIRK_SLOT_IS_CONTACTID, | |
148 | .maxcontacts = 2 }, | |
1e9cf35b | 149 | { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
2d93666e BT |
150 | .quirks = MT_QUIRK_VALID_IS_INRANGE | |
151 | MT_QUIRK_SLOT_IS_CONTACTNUMBER, | |
152 | .maxcontacts = 2 }, | |
22408283 BT |
153 | { .name = MT_CLS_DUAL_NSMU_CONTACTID, |
154 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | | |
155 | MT_QUIRK_SLOT_IS_CONTACTID, | |
156 | .maxcontacts = 2 }, | |
157 | ||
158 | /* | |
159 | * vendor specific classes | |
160 | */ | |
161 | { .name = MT_CLS_3M, | |
162 | .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | | |
163 | MT_QUIRK_SLOT_IS_CONTACTID, | |
164 | .sn_move = 2048, | |
165 | .sn_width = 128, | |
166 | .sn_height = 128 }, | |
2d93666e BT |
167 | { .name = MT_CLS_CYPRESS, |
168 | .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | | |
169 | MT_QUIRK_CYPRESS, | |
170 | .maxcontacts = 10 }, | |
4875ac11 RN |
171 | { .name = MT_CLS_EGALAX, |
172 | .quirks = MT_QUIRK_SLOT_IS_CONTACTID | | |
2261bb9f | 173 | MT_QUIRK_VALID_IS_INRANGE, |
4875ac11 RN |
174 | .sn_move = 4096, |
175 | .sn_pressure = 32, | |
176 | }, | |
043b403a | 177 | |
2d93666e | 178 | { } |
5519cab4 BT |
179 | }; |
180 | ||
eec29e3d BT |
181 | static ssize_t mt_show_quirks(struct device *dev, |
182 | struct device_attribute *attr, | |
183 | char *buf) | |
184 | { | |
185 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | |
186 | struct mt_device *td = hid_get_drvdata(hdev); | |
187 | ||
188 | return sprintf(buf, "%u\n", td->mtclass.quirks); | |
189 | } | |
190 | ||
191 | static ssize_t mt_set_quirks(struct device *dev, | |
192 | struct device_attribute *attr, | |
193 | const char *buf, size_t count) | |
194 | { | |
195 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | |
196 | struct mt_device *td = hid_get_drvdata(hdev); | |
197 | ||
198 | unsigned long val; | |
199 | ||
200 | if (kstrtoul(buf, 0, &val)) | |
201 | return -EINVAL; | |
202 | ||
203 | td->mtclass.quirks = val; | |
204 | ||
205 | return count; | |
206 | } | |
207 | ||
208 | static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks); | |
209 | ||
210 | static struct attribute *sysfs_attrs[] = { | |
211 | &dev_attr_quirks.attr, | |
212 | NULL | |
213 | }; | |
214 | ||
215 | static struct attribute_group mt_attribute_group = { | |
216 | .attrs = sysfs_attrs | |
217 | }; | |
218 | ||
f635bd11 | 219 | static void mt_feature_mapping(struct hid_device *hdev, |
5519cab4 BT |
220 | struct hid_field *field, struct hid_usage *usage) |
221 | { | |
9498f954 BT |
222 | struct mt_device *td = hid_get_drvdata(hdev); |
223 | ||
224 | switch (usage->hid) { | |
225 | case HID_DG_INPUTMODE: | |
5519cab4 | 226 | td->inputmode = field->report->id; |
9498f954 BT |
227 | break; |
228 | case HID_DG_CONTACTMAX: | |
229 | td->maxcontacts = field->value[0]; | |
eec29e3d | 230 | if (td->mtclass.maxcontacts) |
9498f954 | 231 | /* check if the maxcontacts is given by the class */ |
eec29e3d | 232 | td->maxcontacts = td->mtclass.maxcontacts; |
9498f954 BT |
233 | |
234 | break; | |
5519cab4 BT |
235 | } |
236 | } | |
237 | ||
238 | static void set_abs(struct input_dev *input, unsigned int code, | |
239 | struct hid_field *field, int snratio) | |
240 | { | |
241 | int fmin = field->logical_minimum; | |
242 | int fmax = field->logical_maximum; | |
243 | int fuzz = snratio ? (fmax - fmin) / snratio : 0; | |
244 | input_set_abs_params(input, code, fmin, fmax, fuzz, 0); | |
245 | } | |
246 | ||
247 | static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |
248 | struct hid_field *field, struct hid_usage *usage, | |
249 | unsigned long **bit, int *max) | |
250 | { | |
251 | struct mt_device *td = hid_get_drvdata(hdev); | |
eec29e3d | 252 | struct mt_class *cls = &td->mtclass; |
4875ac11 | 253 | |
658d4aed JB |
254 | /* Only map fields from TouchScreen or TouchPad collections. |
255 | * We need to ignore fields that belong to other collections | |
256 | * such as Mouse that might have the same GenericDesktop usages. */ | |
257 | if (field->application == HID_DG_TOUCHSCREEN) | |
258 | set_bit(INPUT_PROP_DIRECT, hi->input->propbit); | |
259 | else if (field->application == HID_DG_TOUCHPAD) | |
260 | set_bit(INPUT_PROP_POINTER, hi->input->propbit); | |
261 | else | |
262 | return 0; | |
263 | ||
2261bb9f BT |
264 | /* eGalax devices provide a Digitizer.Stylus input which overrides |
265 | * the correct Digitizers.Finger X/Y ranges. | |
266 | * Let's just ignore this input. */ | |
267 | if (field->physical == HID_DG_STYLUS) | |
268 | return -1; | |
269 | ||
5519cab4 BT |
270 | switch (usage->hid & HID_USAGE_PAGE) { |
271 | ||
272 | case HID_UP_GENDESK: | |
273 | switch (usage->hid) { | |
274 | case HID_GD_X: | |
275 | hid_map_usage(hi, usage, bit, max, | |
276 | EV_ABS, ABS_MT_POSITION_X); | |
277 | set_abs(hi->input, ABS_MT_POSITION_X, field, | |
278 | cls->sn_move); | |
279 | /* touchscreen emulation */ | |
280 | set_abs(hi->input, ABS_X, field, cls->sn_move); | |
b84bd27f BT |
281 | if (td->last_mt_collection == usage->collection_index) { |
282 | td->last_slot_field = usage->hid; | |
283 | td->last_field_index = field->index; | |
284 | } | |
5519cab4 BT |
285 | return 1; |
286 | case HID_GD_Y: | |
287 | hid_map_usage(hi, usage, bit, max, | |
288 | EV_ABS, ABS_MT_POSITION_Y); | |
289 | set_abs(hi->input, ABS_MT_POSITION_Y, field, | |
290 | cls->sn_move); | |
291 | /* touchscreen emulation */ | |
292 | set_abs(hi->input, ABS_Y, field, cls->sn_move); | |
b84bd27f BT |
293 | if (td->last_mt_collection == usage->collection_index) { |
294 | td->last_slot_field = usage->hid; | |
295 | td->last_field_index = field->index; | |
296 | } | |
5519cab4 BT |
297 | return 1; |
298 | } | |
299 | return 0; | |
300 | ||
301 | case HID_UP_DIGITIZER: | |
302 | switch (usage->hid) { | |
303 | case HID_DG_INRANGE: | |
b84bd27f BT |
304 | if (td->last_mt_collection == usage->collection_index) { |
305 | td->last_slot_field = usage->hid; | |
306 | td->last_field_index = field->index; | |
307 | } | |
5519cab4 BT |
308 | return 1; |
309 | case HID_DG_CONFIDENCE: | |
b84bd27f BT |
310 | if (td->last_mt_collection == usage->collection_index) { |
311 | td->last_slot_field = usage->hid; | |
312 | td->last_field_index = field->index; | |
313 | } | |
5519cab4 BT |
314 | return 1; |
315 | case HID_DG_TIPSWITCH: | |
316 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); | |
317 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); | |
b84bd27f BT |
318 | if (td->last_mt_collection == usage->collection_index) { |
319 | td->last_slot_field = usage->hid; | |
320 | td->last_field_index = field->index; | |
321 | } | |
5519cab4 BT |
322 | return 1; |
323 | case HID_DG_CONTACTID: | |
50bc03ab BT |
324 | if (!td->maxcontacts) |
325 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; | |
9498f954 | 326 | input_mt_init_slots(hi->input, td->maxcontacts); |
5519cab4 | 327 | td->last_slot_field = usage->hid; |
2955caed | 328 | td->last_field_index = field->index; |
b84bd27f | 329 | td->last_mt_collection = usage->collection_index; |
5519cab4 BT |
330 | return 1; |
331 | case HID_DG_WIDTH: | |
332 | hid_map_usage(hi, usage, bit, max, | |
333 | EV_ABS, ABS_MT_TOUCH_MAJOR); | |
f786bba4 BT |
334 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, |
335 | cls->sn_width); | |
b84bd27f BT |
336 | if (td->last_mt_collection == usage->collection_index) { |
337 | td->last_slot_field = usage->hid; | |
338 | td->last_field_index = field->index; | |
339 | } | |
5519cab4 BT |
340 | return 1; |
341 | case HID_DG_HEIGHT: | |
342 | hid_map_usage(hi, usage, bit, max, | |
343 | EV_ABS, ABS_MT_TOUCH_MINOR); | |
f786bba4 BT |
344 | set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, |
345 | cls->sn_height); | |
1e648a13 BT |
346 | input_set_abs_params(hi->input, |
347 | ABS_MT_ORIENTATION, 0, 1, 0, 0); | |
b84bd27f BT |
348 | if (td->last_mt_collection == usage->collection_index) { |
349 | td->last_slot_field = usage->hid; | |
350 | td->last_field_index = field->index; | |
351 | } | |
5519cab4 BT |
352 | return 1; |
353 | case HID_DG_TIPPRESSURE: | |
354 | hid_map_usage(hi, usage, bit, max, | |
355 | EV_ABS, ABS_MT_PRESSURE); | |
356 | set_abs(hi->input, ABS_MT_PRESSURE, field, | |
357 | cls->sn_pressure); | |
358 | /* touchscreen emulation */ | |
359 | set_abs(hi->input, ABS_PRESSURE, field, | |
360 | cls->sn_pressure); | |
b84bd27f BT |
361 | if (td->last_mt_collection == usage->collection_index) { |
362 | td->last_slot_field = usage->hid; | |
363 | td->last_field_index = field->index; | |
364 | } | |
5519cab4 BT |
365 | return 1; |
366 | case HID_DG_CONTACTCOUNT: | |
b84bd27f BT |
367 | if (td->last_mt_collection == usage->collection_index) |
368 | td->last_field_index = field->index; | |
5519cab4 BT |
369 | return 1; |
370 | case HID_DG_CONTACTMAX: | |
371 | /* we don't set td->last_slot_field as contactcount and | |
372 | * contact max are global to the report */ | |
b84bd27f BT |
373 | if (td->last_mt_collection == usage->collection_index) |
374 | td->last_field_index = field->index; | |
5519cab4 BT |
375 | return -1; |
376 | } | |
377 | /* let hid-input decide for the others */ | |
378 | return 0; | |
379 | ||
380 | case 0xff000000: | |
381 | /* we do not want to map these: no input-oriented meaning */ | |
382 | return -1; | |
383 | } | |
384 | ||
385 | return 0; | |
386 | } | |
387 | ||
388 | static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi, | |
389 | struct hid_field *field, struct hid_usage *usage, | |
390 | unsigned long **bit, int *max) | |
391 | { | |
392 | if (usage->type == EV_KEY || usage->type == EV_ABS) | |
393 | set_bit(usage->type, hi->input->evbit); | |
394 | ||
395 | return -1; | |
396 | } | |
397 | ||
398 | static int mt_compute_slot(struct mt_device *td) | |
399 | { | |
eec29e3d | 400 | __s32 quirks = td->mtclass.quirks; |
5519cab4 | 401 | |
2d93666e BT |
402 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) |
403 | return td->curdata.contactid; | |
5519cab4 | 404 | |
2d93666e | 405 | if (quirks & MT_QUIRK_CYPRESS) |
a3b5e577 BT |
406 | return cypress_compute_slot(td); |
407 | ||
2d93666e BT |
408 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) |
409 | return td->num_received; | |
5572da08 | 410 | |
4a6ee685 BT |
411 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) |
412 | return td->curdata.contactid - 1; | |
413 | ||
5519cab4 BT |
414 | return find_slot_from_contactid(td); |
415 | } | |
416 | ||
417 | /* | |
418 | * this function is called when a whole contact has been processed, | |
419 | * so that it can assign it to a slot and store the data there | |
420 | */ | |
421 | static void mt_complete_slot(struct mt_device *td) | |
422 | { | |
2d93666e | 423 | td->curdata.seen_in_this_frame = true; |
5519cab4 | 424 | if (td->curvalid) { |
5519cab4 BT |
425 | int slotnum = mt_compute_slot(td); |
426 | ||
9498f954 | 427 | if (slotnum >= 0 && slotnum < td->maxcontacts) |
2d93666e | 428 | td->slots[slotnum] = td->curdata; |
5519cab4 BT |
429 | } |
430 | td->num_received++; | |
431 | } | |
432 | ||
433 | ||
434 | /* | |
435 | * this function is called when a whole packet has been received and processed, | |
436 | * so that it can decide what to send to the input layer. | |
437 | */ | |
438 | static void mt_emit_event(struct mt_device *td, struct input_dev *input) | |
439 | { | |
440 | int i; | |
441 | ||
9498f954 | 442 | for (i = 0; i < td->maxcontacts; ++i) { |
5519cab4 | 443 | struct mt_slot *s = &(td->slots[i]); |
eec29e3d | 444 | if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) && |
5519cab4 | 445 | !s->seen_in_this_frame) { |
5519cab4 BT |
446 | s->touch_state = false; |
447 | } | |
448 | ||
449 | input_mt_slot(input, i); | |
450 | input_mt_report_slot_state(input, MT_TOOL_FINGER, | |
451 | s->touch_state); | |
2d93666e | 452 | if (s->touch_state) { |
f786bba4 BT |
453 | /* this finger is on the screen */ |
454 | int wide = (s->w > s->h); | |
455 | /* divided by two to match visual scale of touch */ | |
456 | int major = max(s->w, s->h) >> 1; | |
457 | int minor = min(s->w, s->h) >> 1; | |
458 | ||
2d93666e BT |
459 | input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); |
460 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); | |
f786bba4 | 461 | input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); |
2d93666e | 462 | input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); |
f786bba4 BT |
463 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); |
464 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); | |
2d93666e | 465 | } |
5519cab4 BT |
466 | s->seen_in_this_frame = false; |
467 | ||
468 | } | |
469 | ||
470 | input_mt_report_pointer_emulation(input, true); | |
471 | input_sync(input); | |
472 | td->num_received = 0; | |
473 | } | |
474 | ||
475 | ||
476 | ||
477 | static int mt_event(struct hid_device *hid, struct hid_field *field, | |
478 | struct hid_usage *usage, __s32 value) | |
479 | { | |
480 | struct mt_device *td = hid_get_drvdata(hid); | |
eec29e3d | 481 | __s32 quirks = td->mtclass.quirks; |
5519cab4 | 482 | |
9498f954 | 483 | if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { |
5519cab4 BT |
484 | switch (usage->hid) { |
485 | case HID_DG_INRANGE: | |
a062cc5a SC |
486 | if (quirks & MT_QUIRK_ALWAYS_VALID) |
487 | td->curvalid = true; | |
488 | else if (quirks & MT_QUIRK_VALID_IS_INRANGE) | |
2d93666e | 489 | td->curvalid = value; |
5519cab4 BT |
490 | break; |
491 | case HID_DG_TIPSWITCH: | |
2d93666e BT |
492 | if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) |
493 | td->curvalid = value; | |
5519cab4 BT |
494 | td->curdata.touch_state = value; |
495 | break; | |
496 | case HID_DG_CONFIDENCE: | |
2d93666e BT |
497 | if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) |
498 | td->curvalid = value; | |
5519cab4 BT |
499 | break; |
500 | case HID_DG_CONTACTID: | |
501 | td->curdata.contactid = value; | |
502 | break; | |
503 | case HID_DG_TIPPRESSURE: | |
504 | td->curdata.p = value; | |
505 | break; | |
506 | case HID_GD_X: | |
507 | td->curdata.x = value; | |
508 | break; | |
509 | case HID_GD_Y: | |
510 | td->curdata.y = value; | |
511 | break; | |
512 | case HID_DG_WIDTH: | |
513 | td->curdata.w = value; | |
514 | break; | |
515 | case HID_DG_HEIGHT: | |
516 | td->curdata.h = value; | |
517 | break; | |
518 | case HID_DG_CONTACTCOUNT: | |
519 | /* | |
2d93666e BT |
520 | * Includes multi-packet support where subsequent |
521 | * packets are sent with zero contactcount. | |
5519cab4 BT |
522 | */ |
523 | if (value) | |
2d93666e | 524 | td->num_expected = value; |
5519cab4 BT |
525 | break; |
526 | ||
527 | default: | |
528 | /* fallback to the generic hidinput handling */ | |
529 | return 0; | |
530 | } | |
5519cab4 | 531 | |
f153fc39 | 532 | if (usage->hid == td->last_slot_field) { |
2d93666e | 533 | mt_complete_slot(td); |
f153fc39 | 534 | } |
2d93666e BT |
535 | |
536 | if (field->index == td->last_field_index | |
537 | && td->num_received >= td->num_expected) | |
538 | mt_emit_event(td, field->hidinput->input); | |
5519cab4 | 539 | |
2d93666e | 540 | } |
5519cab4 BT |
541 | |
542 | /* we have handled the hidinput part, now remains hiddev */ | |
543 | if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) | |
544 | hid->hiddev_hid_event(hid, field, usage, value); | |
545 | ||
546 | return 1; | |
547 | } | |
548 | ||
549 | static void mt_set_input_mode(struct hid_device *hdev) | |
550 | { | |
551 | struct mt_device *td = hid_get_drvdata(hdev); | |
552 | struct hid_report *r; | |
553 | struct hid_report_enum *re; | |
554 | ||
555 | if (td->inputmode < 0) | |
556 | return; | |
557 | ||
558 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); | |
559 | r = re->report_id_hash[td->inputmode]; | |
560 | if (r) { | |
561 | r->field[0]->value[0] = 0x02; | |
562 | usbhid_submit_report(hdev, r, USB_DIR_OUT); | |
563 | } | |
564 | } | |
565 | ||
566 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |
567 | { | |
2d93666e | 568 | int ret, i; |
5519cab4 | 569 | struct mt_device *td; |
2d93666e BT |
570 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
571 | ||
572 | for (i = 0; mt_classes[i].name ; i++) { | |
573 | if (id->driver_data == mt_classes[i].name) { | |
574 | mtclass = &(mt_classes[i]); | |
575 | break; | |
576 | } | |
577 | } | |
5519cab4 | 578 | |
d682bd7f HR |
579 | /* This allows the driver to correctly support devices |
580 | * that emit events over several HID messages. | |
581 | */ | |
582 | hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC; | |
5519cab4 | 583 | |
9498f954 | 584 | td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); |
5519cab4 BT |
585 | if (!td) { |
586 | dev_err(&hdev->dev, "cannot allocate multitouch data\n"); | |
587 | return -ENOMEM; | |
588 | } | |
eec29e3d | 589 | td->mtclass = *mtclass; |
5519cab4 | 590 | td->inputmode = -1; |
b84bd27f | 591 | td->last_mt_collection = -1; |
5519cab4 BT |
592 | hid_set_drvdata(hdev, td); |
593 | ||
594 | ret = hid_parse(hdev); | |
595 | if (ret != 0) | |
596 | goto fail; | |
597 | ||
598 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | |
2d93666e | 599 | if (ret) |
5519cab4 BT |
600 | goto fail; |
601 | ||
9498f954 BT |
602 | td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot), |
603 | GFP_KERNEL); | |
604 | if (!td->slots) { | |
605 | dev_err(&hdev->dev, "cannot allocate multitouch slots\n"); | |
606 | hid_hw_stop(hdev); | |
607 | ret = -ENOMEM; | |
608 | goto fail; | |
609 | } | |
610 | ||
eec29e3d BT |
611 | ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); |
612 | ||
5519cab4 BT |
613 | mt_set_input_mode(hdev); |
614 | ||
615 | return 0; | |
616 | ||
617 | fail: | |
618 | kfree(td); | |
619 | return ret; | |
620 | } | |
621 | ||
622 | #ifdef CONFIG_PM | |
623 | static int mt_reset_resume(struct hid_device *hdev) | |
624 | { | |
625 | mt_set_input_mode(hdev); | |
626 | return 0; | |
627 | } | |
628 | #endif | |
629 | ||
630 | static void mt_remove(struct hid_device *hdev) | |
631 | { | |
632 | struct mt_device *td = hid_get_drvdata(hdev); | |
eec29e3d | 633 | sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); |
5519cab4 | 634 | hid_hw_stop(hdev); |
9498f954 | 635 | kfree(td->slots); |
5519cab4 BT |
636 | kfree(td); |
637 | hid_set_drvdata(hdev, NULL); | |
638 | } | |
639 | ||
640 | static const struct hid_device_id mt_devices[] = { | |
641 | ||
f786bba4 BT |
642 | /* 3M panels */ |
643 | { .driver_data = MT_CLS_3M, | |
644 | HID_USB_DEVICE(USB_VENDOR_ID_3M, | |
645 | USB_DEVICE_ID_3M1968) }, | |
646 | { .driver_data = MT_CLS_3M, | |
647 | HID_USB_DEVICE(USB_VENDOR_ID_3M, | |
648 | USB_DEVICE_ID_3M2256) }, | |
649 | ||
e6aac342 BT |
650 | /* ActionStar panels */ |
651 | { .driver_data = MT_CLS_DEFAULT, | |
652 | HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, | |
653 | USB_DEVICE_ID_ACTIONSTAR_1011) }, | |
654 | ||
a841b62c BT |
655 | /* Cando panels */ |
656 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, | |
657 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, | |
658 | USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, | |
659 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, | |
660 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, | |
661 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) }, | |
662 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, | |
663 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, | |
664 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, | |
665 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, | |
666 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, | |
667 | USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) }, | |
668 | ||
942fd422 AZ |
669 | /* Chunghwa Telecom touch panels */ |
670 | { .driver_data = MT_CLS_DEFAULT, | |
671 | HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, | |
672 | USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) }, | |
673 | ||
79603dc9 BT |
674 | /* CVTouch panels */ |
675 | { .driver_data = MT_CLS_DEFAULT, | |
676 | HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, | |
677 | USB_DEVICE_ID_CVTOUCH_SCREEN) }, | |
678 | ||
a3b5e577 BT |
679 | /* Cypress panel */ |
680 | { .driver_data = MT_CLS_CYPRESS, | |
681 | HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, | |
682 | USB_DEVICE_ID_CYPRESS_TRUETOUCH) }, | |
683 | ||
22408283 | 684 | /* eGalax devices (resistive) */ |
e36f690b | 685 | { .driver_data = MT_CLS_EGALAX, |
22408283 | 686 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b BT |
687 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) }, |
688 | { .driver_data = MT_CLS_EGALAX, | |
22408283 | 689 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b | 690 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) }, |
22408283 BT |
691 | |
692 | /* eGalax devices (capacitive) */ | |
e36f690b | 693 | { .driver_data = MT_CLS_EGALAX, |
22408283 | 694 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b BT |
695 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) }, |
696 | { .driver_data = MT_CLS_EGALAX, | |
22408283 | 697 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b BT |
698 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) }, |
699 | { .driver_data = MT_CLS_EGALAX, | |
22408283 | 700 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b | 701 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) }, |
66f06127 BT |
702 | { .driver_data = MT_CLS_EGALAX, |
703 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, | |
704 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) }, | |
bb9ff210 MV |
705 | { .driver_data = MT_CLS_EGALAX, |
706 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, | |
707 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) }, | |
e36f690b | 708 | { .driver_data = MT_CLS_EGALAX, |
1fd8f047 | 709 | HID_USB_DEVICE(USB_VENDOR_ID_DWAV, |
e36f690b | 710 | USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) }, |
22408283 | 711 | |
c04abeef BT |
712 | /* Elo TouchSystems IntelliTouch Plus panel */ |
713 | { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID, | |
714 | HID_USB_DEVICE(USB_VENDOR_ID_ELO, | |
715 | USB_DEVICE_ID_ELO_TS2515) }, | |
716 | ||
5572da08 | 717 | /* GeneralTouch panel */ |
1e9cf35b | 718 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, |
5572da08 BT |
719 | HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, |
720 | USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) }, | |
721 | ||
ee0fbd14 BT |
722 | /* GoodTouch panels */ |
723 | { .driver_data = MT_CLS_DEFAULT, | |
724 | HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, | |
725 | USB_DEVICE_ID_GOODTOUCH_000f) }, | |
726 | ||
a062cc5a SC |
727 | /* Ideacom panel */ |
728 | { .driver_data = MT_CLS_SERIAL, | |
729 | HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, | |
730 | USB_DEVICE_ID_IDEACOM_IDC6650) }, | |
731 | ||
4e61f0d7 AZ |
732 | /* Ilitek dual touch panel */ |
733 | { .driver_data = MT_CLS_DEFAULT, | |
734 | HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, | |
735 | USB_DEVICE_ID_ILITEK_MULTITOUCH) }, | |
736 | ||
4dfcced8 BT |
737 | /* IRTOUCH panels */ |
738 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, | |
739 | HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, | |
740 | USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, | |
741 | ||
c50bb1a4 JB |
742 | /* LG Display panels */ |
743 | { .driver_data = MT_CLS_DEFAULT, | |
744 | HID_USB_DEVICE(USB_VENDOR_ID_LG, | |
745 | USB_DEVICE_ID_LG_MULTITOUCH) }, | |
746 | ||
df167c4a BT |
747 | /* Lumio panels */ |
748 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
749 | HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, | |
750 | USB_DEVICE_ID_CRYSTALTOUCH) }, | |
c3ead6de BT |
751 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, |
752 | HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, | |
753 | USB_DEVICE_ID_CRYSTALTOUCH_DUAL) }, | |
df167c4a | 754 | |
4a6ee685 BT |
755 | /* MosArt panels */ |
756 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
757 | HID_USB_DEVICE(USB_VENDOR_ID_ASUS, | |
758 | USB_DEVICE_ID_ASUS_T91MT)}, | |
759 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
760 | HID_USB_DEVICE(USB_VENDOR_ID_ASUS, | |
761 | USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) }, | |
762 | { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, | |
763 | HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, | |
764 | USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) }, | |
765 | ||
6ab3a9a6 JS |
766 | /* PenMount panels */ |
767 | { .driver_data = MT_CLS_CONFIDENCE, | |
768 | HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, | |
769 | USB_DEVICE_ID_PENMOUNT_PCI) }, | |
770 | ||
5519cab4 | 771 | /* PixCir-based panels */ |
1e9cf35b | 772 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
5519cab4 BT |
773 | HID_USB_DEVICE(USB_VENDOR_ID_HANVON, |
774 | USB_DEVICE_ID_HANVON_MULTITOUCH) }, | |
1e9cf35b | 775 | { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, |
5519cab4 BT |
776 | HID_USB_DEVICE(USB_VENDOR_ID_CANDO, |
777 | USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) }, | |
778 | ||
043b403a | 779 | /* Stantum panels */ |
bf5af9b5 | 780 | { .driver_data = MT_CLS_CONFIDENCE, |
043b403a BT |
781 | HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, |
782 | USB_DEVICE_ID_MTP)}, | |
bf5af9b5 | 783 | { .driver_data = MT_CLS_CONFIDENCE, |
85a60082 | 784 | HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, |
043b403a | 785 | USB_DEVICE_ID_MTP_STM)}, |
bf5af9b5 | 786 | { .driver_data = MT_CLS_CONFIDENCE, |
85a60082 | 787 | HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, |
043b403a BT |
788 | USB_DEVICE_ID_MTP_SITRONIX)}, |
789 | ||
5e74e56d BT |
790 | /* Touch International panels */ |
791 | { .driver_data = MT_CLS_DEFAULT, | |
792 | HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, | |
793 | USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) }, | |
794 | ||
617b64f9 BT |
795 | /* Unitec panels */ |
796 | { .driver_data = MT_CLS_DEFAULT, | |
797 | HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, | |
798 | USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) }, | |
799 | { .driver_data = MT_CLS_DEFAULT, | |
800 | HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, | |
801 | USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) }, | |
bc8a2a9b | 802 | /* XAT */ |
803 | { .driver_data = MT_CLS_DEFAULT, | |
804 | HID_USB_DEVICE(USB_VENDOR_ID_XAT, | |
805 | USB_DEVICE_ID_XAT_CSR) }, | |
617b64f9 | 806 | |
5519cab4 BT |
807 | { } |
808 | }; | |
809 | MODULE_DEVICE_TABLE(hid, mt_devices); | |
810 | ||
811 | static const struct hid_usage_id mt_grabbed_usages[] = { | |
812 | { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, | |
813 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} | |
814 | }; | |
815 | ||
816 | static struct hid_driver mt_driver = { | |
817 | .name = "hid-multitouch", | |
818 | .id_table = mt_devices, | |
819 | .probe = mt_probe, | |
820 | .remove = mt_remove, | |
821 | .input_mapping = mt_input_mapping, | |
822 | .input_mapped = mt_input_mapped, | |
823 | .feature_mapping = mt_feature_mapping, | |
824 | .usage_table = mt_grabbed_usages, | |
825 | .event = mt_event, | |
826 | #ifdef CONFIG_PM | |
827 | .reset_resume = mt_reset_resume, | |
828 | #endif | |
829 | }; | |
830 | ||
831 | static int __init mt_init(void) | |
832 | { | |
833 | return hid_register_driver(&mt_driver); | |
834 | } | |
835 | ||
836 | static void __exit mt_exit(void) | |
837 | { | |
838 | hid_unregister_driver(&mt_driver); | |
839 | } | |
840 | ||
841 | module_init(mt_init); | |
842 | module_exit(mt_exit); |