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