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