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