]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/hid/hid-multitouch.c
HID: hid-multitouch: Simplify setup and frame synchronization
[mirror_ubuntu-artful-kernel.git] / drivers / hid / hid-multitouch.c
CommitLineData
5519cab4
BT
1/*
2 * HID driver for multitouch panels
3 *
c2ef8f21
BT
4 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
5519cab4 7 *
4875ac11
RN
8 * This code is partly based on hid-egalax.c:
9 *
10 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
11 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
12 * Copyright (c) 2010 Canonical, Ltd.
13 *
f786bba4
BT
14 * This code is partly based on hid-3m-pct.c:
15 *
16 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
17 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
18 * Copyright (c) 2010 Canonical, Ltd.
19 *
5519cab4
BT
20 */
21
22/*
23 * This program is free software; you can redistribute it and/or modify it
24 * under the terms of the GNU General Public License as published by the Free
25 * Software Foundation; either version 2 of the License, or (at your option)
26 * any later version.
27 */
28
29#include <linux/device.h>
30#include <linux/hid.h>
31#include <linux/module.h>
32#include <linux/slab.h>
33#include <linux/usb.h>
34#include <linux/input/mt.h>
35#include "usbhid/usbhid.h"
36
37
38MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
ef2fafb3 39MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
5519cab4
BT
40MODULE_DESCRIPTION("HID multitouch panels");
41MODULE_LICENSE("GPL");
42
43#include "hid-ids.h"
44
45/* quirks to control the device */
46#define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
47#define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
2d93666e 48#define MT_QUIRK_CYPRESS (1 << 2)
5572da08 49#define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
a062cc5a
SC
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)
a062cc5a 53#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
5519cab4
BT
54
55struct mt_slot {
56 __s32 x, y, p, w, h;
57 __s32 contactid; /* the device ContactID assigned to this slot */
58 bool touch_state; /* is the touch valid? */
59 bool seen_in_this_frame;/* has this slot been updated */
60};
61
eec29e3d
BT
62struct mt_class {
63 __s32 name; /* MT_CLS */
64 __s32 quirks;
65 __s32 sn_move; /* Signal/noise ratio for move events */
66 __s32 sn_width; /* Signal/noise ratio for width events */
67 __s32 sn_height; /* Signal/noise ratio for height events */
68 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
69 __u8 maxcontacts;
c2ef8f21 70 bool is_indirect; /* true for touchpads */
eec29e3d
BT
71};
72
3ac36d15
BT
73struct mt_fields {
74 unsigned usages[HID_MAX_FIELDS];
75 unsigned int length;
76};
77
5519cab4
BT
78struct mt_device {
79 struct mt_slot curdata; /* placeholder of incoming data */
eec29e3d 80 struct mt_class mtclass; /* our mt device class */
3ac36d15
BT
81 struct mt_fields *fields; /* temporary placeholder for storing the
82 multitouch fields */
5519cab4
BT
83 unsigned last_field_index; /* last field index of the report */
84 unsigned last_slot_field; /* the last field of a slot */
85 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
4aceed37 86 __s8 inputmode_index; /* InputMode HID feature index in the report */
31ae9bdd
BT
87 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
88 -1 if non-existent */
5519cab4
BT
89 __u8 num_received; /* how many contacts we received */
90 __u8 num_expected; /* expected last contact index */
9498f954 91 __u8 maxcontacts;
9e87f22a
BT
92 __u8 touches_by_report; /* how many touches are present in one report:
93 * 1 means we should use a serial protocol
94 * > 1 means hybrid (multitouch) protocol */
76f5902a 95 bool serial_maybe; /* need to check for serial protocol */
5519cab4 96 bool curvalid; /* is the current contact valid? */
9498f954 97 struct mt_slot *slots;
76f5902a 98 unsigned mt_flags; /* flags to pass to input-mt */
5519cab4
BT
99};
100
5519cab4 101/* classes of device behavior */
22408283
BT
102#define MT_CLS_DEFAULT 0x0001
103
a062cc5a
SC
104#define MT_CLS_SERIAL 0x0002
105#define MT_CLS_CONFIDENCE 0x0003
5e7ea11f
BT
106#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
107#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
108#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
109#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
110#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
b7ea95ff 111#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
22408283
BT
112
113/* vendor specific classes */
114#define MT_CLS_3M 0x0101
115#define MT_CLS_CYPRESS 0x0102
116#define MT_CLS_EGALAX 0x0103
1b723e8d 117#define MT_CLS_EGALAX_SERIAL 0x0104
847672cd 118#define MT_CLS_TOPSEED 0x0105
2258e863 119#define MT_CLS_PANASONIC 0x0106
5519cab4 120
9498f954
BT
121#define MT_DEFAULT_MAXCONTACT 10
122
2c2110e9
HR
123#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
124#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
125
5519cab4
BT
126/*
127 * these device-dependent functions determine what slot corresponds
128 * to a valid contact that was just read.
129 */
130
a3b5e577
BT
131static int cypress_compute_slot(struct mt_device *td)
132{
133 if (td->curdata.contactid != 0 || td->num_received == 0)
134 return td->curdata.contactid;
135 else
136 return -1;
137}
138
5519cab4
BT
139static int find_slot_from_contactid(struct mt_device *td)
140{
141 int i;
9498f954 142 for (i = 0; i < td->maxcontacts; ++i) {
5519cab4
BT
143 if (td->slots[i].contactid == td->curdata.contactid &&
144 td->slots[i].touch_state)
145 return i;
146 }
9498f954 147 for (i = 0; i < td->maxcontacts; ++i) {
5519cab4
BT
148 if (!td->slots[i].seen_in_this_frame &&
149 !td->slots[i].touch_state)
150 return i;
151 }
5519cab4
BT
152 /* should not occurs. If this happens that means
153 * that the device sent more touches that it says
154 * in the report descriptor. It is ignored then. */
2d93666e 155 return -1;
5519cab4
BT
156}
157
b3c21d2c 158static struct mt_class mt_classes[] = {
2d93666e 159 { .name = MT_CLS_DEFAULT,
9498f954 160 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
a062cc5a
SC
161 { .name = MT_CLS_SERIAL,
162 .quirks = MT_QUIRK_ALWAYS_VALID},
22408283
BT
163 { .name = MT_CLS_CONFIDENCE,
164 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
5e7ea11f
BT
165 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
166 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
167 MT_QUIRK_SLOT_IS_CONTACTID },
22408283
BT
168 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
169 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
170 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
1e9cf35b 171 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
2d93666e
BT
172 .quirks = MT_QUIRK_VALID_IS_INRANGE |
173 MT_QUIRK_SLOT_IS_CONTACTID,
174 .maxcontacts = 2 },
1e9cf35b 175 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2d93666e
BT
176 .quirks = MT_QUIRK_VALID_IS_INRANGE |
177 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
178 .maxcontacts = 2 },
22408283
BT
179 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
180 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
181 MT_QUIRK_SLOT_IS_CONTACTID,
182 .maxcontacts = 2 },
b7ea95ff
AT
183 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
184 .quirks = MT_QUIRK_VALID_IS_INRANGE |
185 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
22408283
BT
186
187 /*
188 * vendor specific classes
189 */
190 { .name = MT_CLS_3M,
191 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
192 MT_QUIRK_SLOT_IS_CONTACTID,
193 .sn_move = 2048,
194 .sn_width = 128,
195 .sn_height = 128 },
2d93666e
BT
196 { .name = MT_CLS_CYPRESS,
197 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
198 MT_QUIRK_CYPRESS,
199 .maxcontacts = 10 },
4875ac11
RN
200 { .name = MT_CLS_EGALAX,
201 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
2261bb9f 202 MT_QUIRK_VALID_IS_INRANGE,
4875ac11
RN
203 .sn_move = 4096,
204 .sn_pressure = 32,
205 },
1b723e8d
BT
206 { .name = MT_CLS_EGALAX_SERIAL,
207 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
208 MT_QUIRK_ALWAYS_VALID,
4875ac11
RN
209 .sn_move = 4096,
210 .sn_pressure = 32,
211 },
847672cd
BT
212 { .name = MT_CLS_TOPSEED,
213 .quirks = MT_QUIRK_ALWAYS_VALID,
214 .is_indirect = true,
215 .maxcontacts = 2,
216 },
2258e863
DK
217 { .name = MT_CLS_PANASONIC,
218 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
219 .maxcontacts = 4 },
043b403a 220
2d93666e 221 { }
5519cab4
BT
222};
223
eec29e3d
BT
224static ssize_t mt_show_quirks(struct device *dev,
225 struct device_attribute *attr,
226 char *buf)
227{
228 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
229 struct mt_device *td = hid_get_drvdata(hdev);
230
231 return sprintf(buf, "%u\n", td->mtclass.quirks);
232}
233
234static ssize_t mt_set_quirks(struct device *dev,
235 struct device_attribute *attr,
236 const char *buf, size_t count)
237{
238 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
239 struct mt_device *td = hid_get_drvdata(hdev);
240
241 unsigned long val;
242
243 if (kstrtoul(buf, 0, &val))
244 return -EINVAL;
245
246 td->mtclass.quirks = val;
247
248 return count;
249}
250
251static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
252
253static struct attribute *sysfs_attrs[] = {
254 &dev_attr_quirks.attr,
255 NULL
256};
257
258static struct attribute_group mt_attribute_group = {
259 .attrs = sysfs_attrs
260};
261
f635bd11 262static void mt_feature_mapping(struct hid_device *hdev,
5519cab4
BT
263 struct hid_field *field, struct hid_usage *usage)
264{
9498f954 265 struct mt_device *td = hid_get_drvdata(hdev);
4aceed37 266 int i;
9498f954
BT
267
268 switch (usage->hid) {
269 case HID_DG_INPUTMODE:
5519cab4 270 td->inputmode = field->report->id;
4aceed37
BT
271 td->inputmode_index = 0; /* has to be updated below */
272
273 for (i=0; i < field->maxusage; i++) {
274 if (field->usage[i].hid == usage->hid) {
275 td->inputmode_index = i;
276 break;
277 }
278 }
279
9498f954
BT
280 break;
281 case HID_DG_CONTACTMAX:
31ae9bdd 282 td->maxcontact_report_id = field->report->id;
9498f954 283 td->maxcontacts = field->value[0];
eec29e3d 284 if (td->mtclass.maxcontacts)
9498f954 285 /* check if the maxcontacts is given by the class */
eec29e3d 286 td->maxcontacts = td->mtclass.maxcontacts;
9498f954
BT
287
288 break;
5519cab4
BT
289 }
290}
291
292static void set_abs(struct input_dev *input, unsigned int code,
293 struct hid_field *field, int snratio)
294{
295 int fmin = field->logical_minimum;
296 int fmax = field->logical_maximum;
297 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
298 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
299}
300
3ac36d15 301static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
ed9d5c96
BT
302 struct hid_input *hi)
303{
3ac36d15
BT
304 struct mt_fields *f = td->fields;
305
306 if (f->length >= HID_MAX_FIELDS)
307 return;
308
309 f->usages[f->length++] = usage->hid;
ed9d5c96
BT
310}
311
5519cab4
BT
312static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
313 struct hid_field *field, struct hid_usage *usage,
314 unsigned long **bit, int *max)
315{
316 struct mt_device *td = hid_get_drvdata(hdev);
eec29e3d 317 struct mt_class *cls = &td->mtclass;
c2ef8f21 318 int code;
4875ac11 319
658d4aed 320 /* Only map fields from TouchScreen or TouchPad collections.
2258e863
DK
321 * We need to ignore fields that belong to other collections
322 * such as Mouse that might have the same GenericDesktop usages. */
658d4aed 323 if (field->application == HID_DG_TOUCHSCREEN)
76f5902a 324 td->mt_flags |= INPUT_MT_DIRECT;
c2ef8f21 325 else if (field->application != HID_DG_TOUCHPAD)
658d4aed
JB
326 return 0;
327
76f5902a
HR
328 /*
329 * Model touchscreens providing buttons as touchpads.
c2ef8f21
BT
330 */
331 if (field->application == HID_DG_TOUCHPAD ||
76f5902a
HR
332 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
333 td->mt_flags |= INPUT_MT_POINTER;
c2ef8f21 334
2261bb9f
BT
335 /* eGalax devices provide a Digitizer.Stylus input which overrides
336 * the correct Digitizers.Finger X/Y ranges.
337 * Let's just ignore this input. */
338 if (field->physical == HID_DG_STYLUS)
339 return -1;
340
5519cab4
BT
341 switch (usage->hid & HID_USAGE_PAGE) {
342
343 case HID_UP_GENDESK:
344 switch (usage->hid) {
345 case HID_GD_X:
346 hid_map_usage(hi, usage, bit, max,
347 EV_ABS, ABS_MT_POSITION_X);
348 set_abs(hi->input, ABS_MT_POSITION_X, field,
349 cls->sn_move);
3ac36d15 350 mt_store_field(usage, td, hi);
ed9d5c96 351 td->last_field_index = field->index;
5519cab4
BT
352 return 1;
353 case HID_GD_Y:
354 hid_map_usage(hi, usage, bit, max,
355 EV_ABS, ABS_MT_POSITION_Y);
356 set_abs(hi->input, ABS_MT_POSITION_Y, field,
357 cls->sn_move);
3ac36d15 358 mt_store_field(usage, td, hi);
ed9d5c96 359 td->last_field_index = field->index;
5519cab4
BT
360 return 1;
361 }
362 return 0;
363
364 case HID_UP_DIGITIZER:
365 switch (usage->hid) {
366 case HID_DG_INRANGE:
3ac36d15 367 mt_store_field(usage, td, hi);
ed9d5c96 368 td->last_field_index = field->index;
5519cab4
BT
369 return 1;
370 case HID_DG_CONFIDENCE:
3ac36d15 371 mt_store_field(usage, td, hi);
ed9d5c96 372 td->last_field_index = field->index;
5519cab4
BT
373 return 1;
374 case HID_DG_TIPSWITCH:
375 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
376 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
3ac36d15 377 mt_store_field(usage, td, hi);
ed9d5c96 378 td->last_field_index = field->index;
5519cab4
BT
379 return 1;
380 case HID_DG_CONTACTID:
3ac36d15 381 mt_store_field(usage, td, hi);
2955caed 382 td->last_field_index = field->index;
9e87f22a 383 td->touches_by_report++;
5519cab4
BT
384 return 1;
385 case HID_DG_WIDTH:
386 hid_map_usage(hi, usage, bit, max,
387 EV_ABS, ABS_MT_TOUCH_MAJOR);
f786bba4
BT
388 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
389 cls->sn_width);
3ac36d15 390 mt_store_field(usage, td, hi);
ed9d5c96 391 td->last_field_index = field->index;
5519cab4
BT
392 return 1;
393 case HID_DG_HEIGHT:
394 hid_map_usage(hi, usage, bit, max,
395 EV_ABS, ABS_MT_TOUCH_MINOR);
f786bba4
BT
396 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
397 cls->sn_height);
1e648a13
BT
398 input_set_abs_params(hi->input,
399 ABS_MT_ORIENTATION, 0, 1, 0, 0);
3ac36d15 400 mt_store_field(usage, td, hi);
ed9d5c96 401 td->last_field_index = field->index;
5519cab4
BT
402 return 1;
403 case HID_DG_TIPPRESSURE:
404 hid_map_usage(hi, usage, bit, max,
405 EV_ABS, ABS_MT_PRESSURE);
406 set_abs(hi->input, ABS_MT_PRESSURE, field,
407 cls->sn_pressure);
3ac36d15 408 mt_store_field(usage, td, hi);
ed9d5c96 409 td->last_field_index = field->index;
5519cab4
BT
410 return 1;
411 case HID_DG_CONTACTCOUNT:
ed9d5c96 412 td->last_field_index = field->index;
5519cab4
BT
413 return 1;
414 case HID_DG_CONTACTMAX:
415 /* we don't set td->last_slot_field as contactcount and
416 * contact max are global to the report */
ed9d5c96 417 td->last_field_index = field->index;
5519cab4
BT
418 return -1;
419 }
c2ef8f21
BT
420 case HID_DG_TOUCH:
421 /* Legacy devices use TIPSWITCH and not TOUCH.
422 * Let's just ignore this field. */
423 return -1;
5519cab4
BT
424 /* let hid-input decide for the others */
425 return 0;
426
c2ef8f21
BT
427 case HID_UP_BUTTON:
428 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
429 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
430 input_set_capability(hi->input, EV_KEY, code);
431 return 1;
432
5519cab4
BT
433 case 0xff000000:
434 /* we do not want to map these: no input-oriented meaning */
435 return -1;
436 }
437
438 return 0;
439}
440
441static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
442 struct hid_field *field, struct hid_usage *usage,
443 unsigned long **bit, int *max)
444{
445 if (usage->type == EV_KEY || usage->type == EV_ABS)
446 set_bit(usage->type, hi->input->evbit);
447
448 return -1;
449}
450
451static int mt_compute_slot(struct mt_device *td)
452{
eec29e3d 453 __s32 quirks = td->mtclass.quirks;
5519cab4 454
2d93666e
BT
455 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
456 return td->curdata.contactid;
5519cab4 457
2d93666e 458 if (quirks & MT_QUIRK_CYPRESS)
a3b5e577
BT
459 return cypress_compute_slot(td);
460
2d93666e
BT
461 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
462 return td->num_received;
5572da08 463
4a6ee685
BT
464 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
465 return td->curdata.contactid - 1;
466
5519cab4
BT
467 return find_slot_from_contactid(td);
468}
469
470/*
471 * this function is called when a whole contact has been processed,
472 * so that it can assign it to a slot and store the data there
473 */
474static void mt_complete_slot(struct mt_device *td)
475{
2d93666e 476 td->curdata.seen_in_this_frame = true;
5519cab4 477 if (td->curvalid) {
5519cab4
BT
478 int slotnum = mt_compute_slot(td);
479
9498f954 480 if (slotnum >= 0 && slotnum < td->maxcontacts)
2d93666e 481 td->slots[slotnum] = td->curdata;
5519cab4
BT
482 }
483 td->num_received++;
484}
485
486
487/*
488 * this function is called when a whole packet has been received and processed,
489 * so that it can decide what to send to the input layer.
490 */
491static void mt_emit_event(struct mt_device *td, struct input_dev *input)
492{
493 int i;
494
9498f954 495 for (i = 0; i < td->maxcontacts; ++i) {
5519cab4 496 struct mt_slot *s = &(td->slots[i]);
eec29e3d 497 if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
5519cab4 498 !s->seen_in_this_frame) {
5519cab4
BT
499 s->touch_state = false;
500 }
501
502 input_mt_slot(input, i);
503 input_mt_report_slot_state(input, MT_TOOL_FINGER,
504 s->touch_state);
2d93666e 505 if (s->touch_state) {
f786bba4
BT
506 /* this finger is on the screen */
507 int wide = (s->w > s->h);
508 /* divided by two to match visual scale of touch */
509 int major = max(s->w, s->h) >> 1;
510 int minor = min(s->w, s->h) >> 1;
511
2d93666e
BT
512 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
513 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
f786bba4 514 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
2d93666e 515 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
f786bba4
BT
516 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
517 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
2d93666e 518 }
5519cab4
BT
519 s->seen_in_this_frame = false;
520
521 }
522
76f5902a 523 input_mt_sync_frame(input);
5519cab4
BT
524 input_sync(input);
525 td->num_received = 0;
526}
527
528
529
530static int mt_event(struct hid_device *hid, struct hid_field *field,
531 struct hid_usage *usage, __s32 value)
532{
533 struct mt_device *td = hid_get_drvdata(hid);
eec29e3d 534 __s32 quirks = td->mtclass.quirks;
5519cab4 535
9498f954 536 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
5519cab4
BT
537 switch (usage->hid) {
538 case HID_DG_INRANGE:
a062cc5a
SC
539 if (quirks & MT_QUIRK_ALWAYS_VALID)
540 td->curvalid = true;
541 else if (quirks & MT_QUIRK_VALID_IS_INRANGE)
2d93666e 542 td->curvalid = value;
5519cab4
BT
543 break;
544 case HID_DG_TIPSWITCH:
2d93666e
BT
545 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
546 td->curvalid = value;
5519cab4
BT
547 td->curdata.touch_state = value;
548 break;
549 case HID_DG_CONFIDENCE:
2d93666e
BT
550 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
551 td->curvalid = value;
5519cab4
BT
552 break;
553 case HID_DG_CONTACTID:
554 td->curdata.contactid = value;
555 break;
556 case HID_DG_TIPPRESSURE:
557 td->curdata.p = value;
558 break;
559 case HID_GD_X:
560 td->curdata.x = value;
561 break;
562 case HID_GD_Y:
563 td->curdata.y = value;
564 break;
565 case HID_DG_WIDTH:
566 td->curdata.w = value;
567 break;
568 case HID_DG_HEIGHT:
569 td->curdata.h = value;
570 break;
571 case HID_DG_CONTACTCOUNT:
572 /*
2d93666e
BT
573 * Includes multi-packet support where subsequent
574 * packets are sent with zero contactcount.
5519cab4
BT
575 */
576 if (value)
2d93666e 577 td->num_expected = value;
5519cab4 578 break;
c2ef8f21
BT
579 case HID_DG_TOUCH:
580 /* do nothing */
581 break;
5519cab4
BT
582
583 default:
584 /* fallback to the generic hidinput handling */
585 return 0;
586 }
5519cab4 587
2258e863 588 if (usage->hid == td->last_slot_field)
2d93666e
BT
589 mt_complete_slot(td);
590
591 if (field->index == td->last_field_index
592 && td->num_received >= td->num_expected)
593 mt_emit_event(td, field->hidinput->input);
5519cab4 594
2d93666e 595 }
5519cab4
BT
596
597 /* we have handled the hidinput part, now remains hiddev */
598 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
599 hid->hiddev_hid_event(hid, field, usage, value);
600
601 return 1;
602}
603
604static void mt_set_input_mode(struct hid_device *hdev)
605{
606 struct mt_device *td = hid_get_drvdata(hdev);
607 struct hid_report *r;
608 struct hid_report_enum *re;
609
610 if (td->inputmode < 0)
611 return;
612
613 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
614 r = re->report_id_hash[td->inputmode];
615 if (r) {
4aceed37 616 r->field[0]->value[td->inputmode_index] = 0x02;
5519cab4
BT
617 usbhid_submit_report(hdev, r, USB_DIR_OUT);
618 }
619}
620
31ae9bdd
BT
621static void mt_set_maxcontacts(struct hid_device *hdev)
622{
623 struct mt_device *td = hid_get_drvdata(hdev);
624 struct hid_report *r;
625 struct hid_report_enum *re;
626 int fieldmax, max;
627
628 if (td->maxcontact_report_id < 0)
629 return;
630
631 if (!td->mtclass.maxcontacts)
632 return;
633
634 re = &hdev->report_enum[HID_FEATURE_REPORT];
635 r = re->report_id_hash[td->maxcontact_report_id];
636 if (r) {
637 max = td->mtclass.maxcontacts;
638 fieldmax = r->field[0]->logical_maximum;
639 max = min(fieldmax, max);
640 if (r->field[0]->value[0] != max) {
641 r->field[0]->value[0] = max;
642 usbhid_submit_report(hdev, r, USB_DIR_OUT);
643 }
644 }
645}
646
4fa3a583
HR
647static void mt_post_parse_default_settings(struct mt_device *td)
648{
649 __s32 quirks = td->mtclass.quirks;
650
651 /* unknown serial device needs special quirks */
652 if (td->touches_by_report == 1) {
653 quirks |= MT_QUIRK_ALWAYS_VALID;
654 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
655 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
656 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
657 }
658
659 td->mtclass.quirks = quirks;
660}
661
3ac36d15
BT
662static void mt_post_parse(struct mt_device *td)
663{
664 struct mt_fields *f = td->fields;
665
666 if (td->touches_by_report > 0) {
667 int field_count_per_touch = f->length / td->touches_by_report;
668 td->last_slot_field = f->usages[field_count_per_touch - 1];
669 }
670}
671
76f5902a
HR
672static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
673
674{
675 struct mt_device *td = hid_get_drvdata(hdev);
676 struct mt_class *cls = &td->mtclass;
677 struct input_dev *input = hi->input;
678
679 /* Only initialize slots for MT input devices */
680 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
681 return;
682
683 if (!td->maxcontacts)
684 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
685
686 mt_post_parse(td);
687 if (td->serial_maybe)
688 mt_post_parse_default_settings(td);
689
690 if (cls->is_indirect)
691 td->mt_flags |= INPUT_MT_POINTER;
692
693 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
694
695 td->mt_flags = 0;
696}
697
5519cab4
BT
698static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
699{
2d93666e 700 int ret, i;
5519cab4 701 struct mt_device *td;
2d93666e
BT
702 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
703
8d179a9e
BT
704 if (id) {
705 for (i = 0; mt_classes[i].name ; i++) {
706 if (id->driver_data == mt_classes[i].name) {
707 mtclass = &(mt_classes[i]);
708 break;
709 }
2d93666e
BT
710 }
711 }
5519cab4 712
d682bd7f
HR
713 /* This allows the driver to correctly support devices
714 * that emit events over several HID messages.
715 */
716 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
5519cab4 717
9498f954 718 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
5519cab4
BT
719 if (!td) {
720 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
721 return -ENOMEM;
722 }
eec29e3d 723 td->mtclass = *mtclass;
5519cab4 724 td->inputmode = -1;
31ae9bdd 725 td->maxcontact_report_id = -1;
5519cab4
BT
726 hid_set_drvdata(hdev, td);
727
3ac36d15
BT
728 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
729 if (!td->fields) {
730 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
731 ret = -ENOMEM;
732 goto fail;
733 }
734
76f5902a
HR
735 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
736 td->serial_maybe = true;
737
5519cab4
BT
738 ret = hid_parse(hdev);
739 if (ret != 0)
740 goto fail;
741
742 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
2d93666e 743 if (ret)
5519cab4
BT
744 goto fail;
745
9498f954
BT
746 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
747 GFP_KERNEL);
748 if (!td->slots) {
749 dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
750 hid_hw_stop(hdev);
751 ret = -ENOMEM;
752 goto fail;
753 }
754
eec29e3d
BT
755 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
756
31ae9bdd 757 mt_set_maxcontacts(hdev);
5519cab4
BT
758 mt_set_input_mode(hdev);
759
3ac36d15
BT
760 kfree(td->fields);
761 td->fields = NULL;
762
5519cab4
BT
763 return 0;
764
765fail:
3ac36d15 766 kfree(td->fields);
5519cab4
BT
767 kfree(td);
768 return ret;
769}
770
771#ifdef CONFIG_PM
772static int mt_reset_resume(struct hid_device *hdev)
773{
31ae9bdd 774 mt_set_maxcontacts(hdev);
5519cab4
BT
775 mt_set_input_mode(hdev);
776 return 0;
777}
778#endif
779
780static void mt_remove(struct hid_device *hdev)
781{
782 struct mt_device *td = hid_get_drvdata(hdev);
eec29e3d 783 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
5519cab4 784 hid_hw_stop(hdev);
9498f954 785 kfree(td->slots);
5519cab4
BT
786 kfree(td);
787 hid_set_drvdata(hdev, NULL);
788}
789
790static const struct hid_device_id mt_devices[] = {
791
f786bba4
BT
792 /* 3M panels */
793 { .driver_data = MT_CLS_3M,
2c2110e9 794 MT_USB_DEVICE(USB_VENDOR_ID_3M,
f786bba4
BT
795 USB_DEVICE_ID_3M1968) },
796 { .driver_data = MT_CLS_3M,
2c2110e9 797 MT_USB_DEVICE(USB_VENDOR_ID_3M,
f786bba4 798 USB_DEVICE_ID_3M2256) },
c4fad877 799 { .driver_data = MT_CLS_3M,
2c2110e9 800 MT_USB_DEVICE(USB_VENDOR_ID_3M,
c4fad877 801 USB_DEVICE_ID_3M3266) },
f786bba4 802
e6aac342
BT
803 /* ActionStar panels */
804 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 805 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
e6aac342
BT
806 USB_DEVICE_ID_ACTIONSTAR_1011) },
807
b1057124
BT
808 /* Atmel panels */
809 { .driver_data = MT_CLS_SERIAL,
2c2110e9 810 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
b1057124 811 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
841cb157 812 { .driver_data = MT_CLS_SERIAL,
2c2110e9 813 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
841cb157 814 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
b1057124 815
9ed32695
JK
816 /* Baanto multitouch devices */
817 { .driver_data = MT_CLS_DEFAULT,
16b79bb8 818 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
9ed32695 819 USB_DEVICE_ID_BAANTO_MT_190W2) },
a841b62c
BT
820 /* Cando panels */
821 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2c2110e9 822 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
a841b62c
BT
823 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
824 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2c2110e9 825 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
a841b62c
BT
826 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
827 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2c2110e9 828 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
a841b62c
BT
829 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
830 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2c2110e9 831 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
a841b62c
BT
832 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
833
942fd422
AZ
834 /* Chunghwa Telecom touch panels */
835 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 836 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
942fd422
AZ
837 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
838
79603dc9
BT
839 /* CVTouch panels */
840 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 841 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
79603dc9
BT
842 USB_DEVICE_ID_CVTOUCH_SCREEN) },
843
a3b5e577
BT
844 /* Cypress panel */
845 { .driver_data = MT_CLS_CYPRESS,
846 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
847 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
848
22408283 849 /* eGalax devices (resistive) */
e36f690b 850 { .driver_data = MT_CLS_EGALAX,
2c2110e9 851 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
e36f690b
BT
852 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
853 { .driver_data = MT_CLS_EGALAX,
2c2110e9 854 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
e36f690b 855 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
22408283
BT
856
857 /* eGalax devices (capacitive) */
e36f690b 858 { .driver_data = MT_CLS_EGALAX,
2c2110e9 859 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
e36f690b 860 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
fd1d1525 861 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 862 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
fd1d1525
BT
863 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
864 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 865 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
fd1d1525
BT
866 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
867 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 868 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
fd1d1525 869 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
2ce09df4 870 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 871 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
2ce09df4 872 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
e36f690b 873 { .driver_data = MT_CLS_EGALAX,
2c2110e9 874 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
e36f690b 875 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
fd1d1525 876 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 877 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
fd1d1525 878 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
e36f690b 879 { .driver_data = MT_CLS_EGALAX,
2c2110e9 880 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
e36f690b 881 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
fd1d1525 882 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 883 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
fd1d1525 884 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
66f06127 885 { .driver_data = MT_CLS_EGALAX,
2c2110e9 886 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
66f06127 887 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
bb9ff210 888 { .driver_data = MT_CLS_EGALAX,
2c2110e9 889 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
bb9ff210 890 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
fd1d1525 891 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 892 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
fd1d1525 893 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1b723e8d 894 { .driver_data = MT_CLS_EGALAX_SERIAL,
2c2110e9 895 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
e36f690b 896 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
22408283 897
c04abeef
BT
898 /* Elo TouchSystems IntelliTouch Plus panel */
899 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
2c2110e9 900 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
c04abeef
BT
901 USB_DEVICE_ID_ELO_TS2515) },
902
5572da08 903 /* GeneralTouch panel */
1e9cf35b 904 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
2c2110e9 905 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
5572da08
BT
906 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
907
4d5df5d1
AN
908 /* Gametel game controller */
909 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 910 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
4d5df5d1
AN
911 USB_DEVICE_ID_GAMETEL_MT_MODE) },
912
ee0fbd14
BT
913 /* GoodTouch panels */
914 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 915 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
ee0fbd14
BT
916 USB_DEVICE_ID_GOODTOUCH_000f) },
917
54580365
BT
918 /* Hanvon panels */
919 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2c2110e9 920 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
54580365
BT
921 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
922
a062cc5a
SC
923 /* Ideacom panel */
924 { .driver_data = MT_CLS_SERIAL,
2c2110e9 925 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
a062cc5a 926 USB_DEVICE_ID_IDEACOM_IDC6650) },
71078b0d 927 { .driver_data = MT_CLS_SERIAL,
2c2110e9 928 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
71078b0d 929 USB_DEVICE_ID_IDEACOM_IDC6651) },
a062cc5a 930
4e61f0d7
AZ
931 /* Ilitek dual touch panel */
932 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 933 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
4e61f0d7
AZ
934 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
935
4dfcced8
BT
936 /* IRTOUCH panels */
937 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2c2110e9 938 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
4dfcced8
BT
939 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
940
c50bb1a4
JB
941 /* LG Display panels */
942 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 943 MT_USB_DEVICE(USB_VENDOR_ID_LG,
c50bb1a4
JB
944 USB_DEVICE_ID_LG_MULTITOUCH) },
945
df167c4a
BT
946 /* Lumio panels */
947 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2c2110e9 948 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
df167c4a 949 USB_DEVICE_ID_CRYSTALTOUCH) },
c3ead6de 950 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2c2110e9 951 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
c3ead6de 952 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
df167c4a 953
4a6ee685
BT
954 /* MosArt panels */
955 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2c2110e9 956 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
4a6ee685
BT
957 USB_DEVICE_ID_ASUS_T91MT)},
958 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2c2110e9 959 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
4a6ee685
BT
960 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
961 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
2c2110e9 962 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
4a6ee685
BT
963 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
964
2258e863
DK
965 /* Panasonic panels */
966 { .driver_data = MT_CLS_PANASONIC,
2c2110e9 967 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2258e863
DK
968 USB_DEVICE_ID_PANABOARD_UBT780) },
969 { .driver_data = MT_CLS_PANASONIC,
2c2110e9 970 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
2258e863
DK
971 USB_DEVICE_ID_PANABOARD_UBT880) },
972
4db703ea
AH
973 /* Novatek Panel */
974 { .driver_data = MT_CLS_DEFAULT,
4380d819 975 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
4db703ea
AH
976 USB_DEVICE_ID_NOVATEK_PCT) },
977
6ab3a9a6
JS
978 /* PenMount panels */
979 { .driver_data = MT_CLS_CONFIDENCE,
2c2110e9 980 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
6ab3a9a6
JS
981 USB_DEVICE_ID_PENMOUNT_PCI) },
982
b7ea95ff
AT
983 /* PixArt optical touch screen */
984 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2c2110e9 985 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
b7ea95ff
AT
986 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
987 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2c2110e9 988 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
b7ea95ff
AT
989 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
990 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
2c2110e9 991 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
b7ea95ff
AT
992 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
993
5519cab4 994 /* PixCir-based panels */
1e9cf35b 995 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2c2110e9 996 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
5519cab4 997 USB_DEVICE_ID_HANVON_MULTITOUCH) },
1e9cf35b 998 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
2c2110e9 999 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
5519cab4
BT
1000 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1001
5e7ea11f
BT
1002 /* Quanta-based panels */
1003 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2c2110e9 1004 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
5e7ea11f
BT
1005 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1006 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2c2110e9 1007 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
5e7ea11f
BT
1008 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1009 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
2c2110e9 1010 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
5e7ea11f
BT
1011 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1012
043b403a 1013 /* Stantum panels */
bf5af9b5 1014 { .driver_data = MT_CLS_CONFIDENCE,
2c2110e9 1015 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
043b403a 1016 USB_DEVICE_ID_MTP)},
bf5af9b5 1017 { .driver_data = MT_CLS_CONFIDENCE,
2c2110e9 1018 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
043b403a 1019 USB_DEVICE_ID_MTP_STM)},
bf5af9b5 1020 { .driver_data = MT_CLS_CONFIDENCE,
2c2110e9 1021 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
043b403a
BT
1022 USB_DEVICE_ID_MTP_SITRONIX)},
1023
847672cd
BT
1024 /* TopSeed panels */
1025 { .driver_data = MT_CLS_TOPSEED,
2c2110e9 1026 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
847672cd
BT
1027 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1028
5e74e56d
BT
1029 /* Touch International panels */
1030 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1031 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
5e74e56d
BT
1032 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1033
617b64f9
BT
1034 /* Unitec panels */
1035 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1036 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
617b64f9
BT
1037 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1038 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1039 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
617b64f9 1040 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
bc8a2a9b 1041 /* XAT */
1042 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1043 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
bc8a2a9b 1044 USB_DEVICE_ID_XAT_CSR) },
617b64f9 1045
11576c61
MH
1046 /* Xiroku */
1047 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1048 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1049 USB_DEVICE_ID_XIROKU_SPX) },
1050 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1051 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1052 USB_DEVICE_ID_XIROKU_MPX) },
1053 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1054 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1055 USB_DEVICE_ID_XIROKU_CSR) },
1056 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1057 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1058 USB_DEVICE_ID_XIROKU_SPX1) },
1059 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1060 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1061 USB_DEVICE_ID_XIROKU_MPX1) },
1062 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1063 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1064 USB_DEVICE_ID_XIROKU_CSR1) },
1065 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1066 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1067 USB_DEVICE_ID_XIROKU_SPX2) },
1068 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1069 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1070 USB_DEVICE_ID_XIROKU_MPX2) },
1071 { .driver_data = MT_CLS_DEFAULT,
2c2110e9 1072 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
11576c61
MH
1073 USB_DEVICE_ID_XIROKU_CSR2) },
1074
82d06982
BT
1075 /* Zytronic panels */
1076 { .driver_data = MT_CLS_SERIAL,
1077 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1078 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1079
4fa3a583
HR
1080 /* Generic MT device */
1081 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
5519cab4
BT
1082 { }
1083};
1084MODULE_DEVICE_TABLE(hid, mt_devices);
1085
1086static const struct hid_usage_id mt_grabbed_usages[] = {
1087 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1088 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1089};
1090
1091static struct hid_driver mt_driver = {
1092 .name = "hid-multitouch",
1093 .id_table = mt_devices,
1094 .probe = mt_probe,
1095 .remove = mt_remove,
1096 .input_mapping = mt_input_mapping,
1097 .input_mapped = mt_input_mapped,
76f5902a 1098 .input_configured = mt_input_configured,
5519cab4
BT
1099 .feature_mapping = mt_feature_mapping,
1100 .usage_table = mt_grabbed_usages,
1101 .event = mt_event,
1102#ifdef CONFIG_PM
1103 .reset_resume = mt_reset_resume,
1104#endif
1105};
1106
1107static int __init mt_init(void)
1108{
1109 return hid_register_driver(&mt_driver);
1110}
1111
1112static void __exit mt_exit(void)
1113{
1114 hid_unregister_driver(&mt_driver);
1115}
1116
1117module_init(mt_init);
1118module_exit(mt_exit);