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