OSDN Git Service

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