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