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