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