blob: ea465f1ceae9320f4f555827ee56252c42be26de [file] [log] [blame]
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001/*
2 * HID driver for multitouch panels
3 *
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01004 * 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
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01007 *
Richard Nauber4875ac12011-03-09 06:20:57 +01008 * 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 *
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010014 * 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 *
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010020 */
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>");
Benjamin Tissoiresef2fafb2011-01-31 11:28:21 +010039MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010040MODULE_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)
Benjamin Tissoires2d936662011-01-11 16:45:54 +010048#define MT_QUIRK_CYPRESS (1 << 2)
Benjamin Tissoires5572da02011-01-07 23:47:27 +010049#define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
Stephane Chattya062cc52011-09-17 22:27:30 +020050#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)
Stephane Chattya062cc52011-09-17 22:27:30 +020053#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010054
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
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010062struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010063 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010064 __s32 quirks;
65 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010066 __s32 sn_width; /* Signal/noise ratio for width events */
67 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010068 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
69 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +010070 bool is_indirect; /* true for touchpads */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010071};
72
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010073struct mt_device {
74 struct mt_slot curdata; /* placeholder of incoming data */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +010075 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010076 unsigned last_field_index; /* last field index of the report */
77 unsigned last_slot_field; /* the last field of a slot */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010078 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010079 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
80 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010081 __u8 num_received; /* how many contacts we received */
82 __u8 num_expected; /* expected last contact index */
83 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010084 __u8 touches_by_report; /* how many touches are present in one report:
85 * 1 means we should use a serial protocol
86 * > 1 means hybrid (multitouch) protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010087 bool curvalid; /* is the current contact valid? */
88 struct mt_slot *slots;
89};
90
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010091/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +020092#define MT_CLS_DEFAULT 0x0001
93
Stephane Chattya062cc52011-09-17 22:27:30 +020094#define MT_CLS_SERIAL 0x0002
95#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +010096#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
97#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
98#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
99#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
100#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800101#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200102
103/* vendor specific classes */
104#define MT_CLS_3M 0x0101
105#define MT_CLS_CYPRESS 0x0102
106#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100107#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100108#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800109#define MT_CLS_PANASONIC 0x0106
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100110
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100111#define MT_DEFAULT_MAXCONTACT 10
112
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100113/*
114 * these device-dependent functions determine what slot corresponds
115 * to a valid contact that was just read.
116 */
117
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100118static int cypress_compute_slot(struct mt_device *td)
119{
120 if (td->curdata.contactid != 0 || td->num_received == 0)
121 return td->curdata.contactid;
122 else
123 return -1;
124}
125
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100126static int find_slot_from_contactid(struct mt_device *td)
127{
128 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100129 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100130 if (td->slots[i].contactid == td->curdata.contactid &&
131 td->slots[i].touch_state)
132 return i;
133 }
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100134 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100135 if (!td->slots[i].seen_in_this_frame &&
136 !td->slots[i].touch_state)
137 return i;
138 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100139 /* should not occurs. If this happens that means
140 * that the device sent more touches that it says
141 * in the report descriptor. It is ignored then. */
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100142 return -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100143}
144
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100145static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100146 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100147 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200148 { .name = MT_CLS_SERIAL,
149 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200150 { .name = MT_CLS_CONFIDENCE,
151 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100152 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
153 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
154 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200155 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
156 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
157 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100158 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100159 .quirks = MT_QUIRK_VALID_IS_INRANGE |
160 MT_QUIRK_SLOT_IS_CONTACTID,
161 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100162 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100163 .quirks = MT_QUIRK_VALID_IS_INRANGE |
164 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
165 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200166 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
167 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
168 MT_QUIRK_SLOT_IS_CONTACTID,
169 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800170 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
171 .quirks = MT_QUIRK_VALID_IS_INRANGE |
172 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200173
174 /*
175 * vendor specific classes
176 */
177 { .name = MT_CLS_3M,
178 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
179 MT_QUIRK_SLOT_IS_CONTACTID,
180 .sn_move = 2048,
181 .sn_width = 128,
182 .sn_height = 128 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100183 { .name = MT_CLS_CYPRESS,
184 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
185 MT_QUIRK_CYPRESS,
186 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100187 { .name = MT_CLS_EGALAX,
188 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100189 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100190 .sn_move = 4096,
191 .sn_pressure = 32,
192 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100193 { .name = MT_CLS_EGALAX_SERIAL,
194 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
195 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100196 .sn_move = 4096,
197 .sn_pressure = 32,
198 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100199 { .name = MT_CLS_TOPSEED,
200 .quirks = MT_QUIRK_ALWAYS_VALID,
201 .is_indirect = true,
202 .maxcontacts = 2,
203 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800204 { .name = MT_CLS_PANASONIC,
205 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
206 .maxcontacts = 4 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100207
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100208 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100209};
210
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100211static ssize_t mt_show_quirks(struct device *dev,
212 struct device_attribute *attr,
213 char *buf)
214{
215 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
216 struct mt_device *td = hid_get_drvdata(hdev);
217
218 return sprintf(buf, "%u\n", td->mtclass.quirks);
219}
220
221static ssize_t mt_set_quirks(struct device *dev,
222 struct device_attribute *attr,
223 const char *buf, size_t count)
224{
225 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
226 struct mt_device *td = hid_get_drvdata(hdev);
227
228 unsigned long val;
229
230 if (kstrtoul(buf, 0, &val))
231 return -EINVAL;
232
233 td->mtclass.quirks = val;
234
235 return count;
236}
237
238static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
239
240static struct attribute *sysfs_attrs[] = {
241 &dev_attr_quirks.attr,
242 NULL
243};
244
245static struct attribute_group mt_attribute_group = {
246 .attrs = sysfs_attrs
247};
248
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100249static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100250 struct hid_field *field, struct hid_usage *usage)
251{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100252 struct mt_device *td = hid_get_drvdata(hdev);
253
254 switch (usage->hid) {
255 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100256 td->inputmode = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100257 break;
258 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100259 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100260 td->maxcontacts = field->value[0];
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100261 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100262 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100263 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100264
265 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100266 }
267}
268
269static void set_abs(struct input_dev *input, unsigned int code,
270 struct hid_field *field, int snratio)
271{
272 int fmin = field->logical_minimum;
273 int fmax = field->logical_maximum;
274 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
275 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
276}
277
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100278static void set_last_slot_field(struct hid_usage *usage, struct mt_device *td,
279 struct hid_input *hi)
280{
281 if (!test_bit(usage->hid, hi->input->absbit))
282 td->last_slot_field = usage->hid;
283}
284
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100285static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
286 struct hid_field *field, struct hid_usage *usage,
287 unsigned long **bit, int *max)
288{
289 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100290 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100291 int code;
Richard Nauber4875ac12011-03-09 06:20:57 +0100292
Jeff Brown658d4aed592011-08-15 16:44:28 -0700293 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800294 * We need to ignore fields that belong to other collections
295 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700296 if (field->application == HID_DG_TOUCHSCREEN)
297 set_bit(INPUT_PROP_DIRECT, hi->input->propbit);
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100298 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700299 return 0;
300
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100301 /* In case of an indirect device (touchpad), we need to add
302 * specific BTN_TOOL_* to be handled by the synaptics xorg
303 * driver.
304 * We also consider that touchscreens providing buttons are touchpads.
305 */
306 if (field->application == HID_DG_TOUCHPAD ||
307 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON ||
308 cls->is_indirect) {
309 set_bit(INPUT_PROP_POINTER, hi->input->propbit);
310 set_bit(BTN_TOOL_FINGER, hi->input->keybit);
311 set_bit(BTN_TOOL_DOUBLETAP, hi->input->keybit);
312 set_bit(BTN_TOOL_TRIPLETAP, hi->input->keybit);
313 set_bit(BTN_TOOL_QUADTAP, hi->input->keybit);
314 }
315
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100316 /* eGalax devices provide a Digitizer.Stylus input which overrides
317 * the correct Digitizers.Finger X/Y ranges.
318 * Let's just ignore this input. */
319 if (field->physical == HID_DG_STYLUS)
320 return -1;
321
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100322 switch (usage->hid & HID_USAGE_PAGE) {
323
324 case HID_UP_GENDESK:
325 switch (usage->hid) {
326 case HID_GD_X:
327 hid_map_usage(hi, usage, bit, max,
328 EV_ABS, ABS_MT_POSITION_X);
329 set_abs(hi->input, ABS_MT_POSITION_X, field,
330 cls->sn_move);
331 /* touchscreen emulation */
332 set_abs(hi->input, ABS_X, field, cls->sn_move);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100333 set_last_slot_field(usage, td, hi);
334 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100335 return 1;
336 case HID_GD_Y:
337 hid_map_usage(hi, usage, bit, max,
338 EV_ABS, ABS_MT_POSITION_Y);
339 set_abs(hi->input, ABS_MT_POSITION_Y, field,
340 cls->sn_move);
341 /* touchscreen emulation */
342 set_abs(hi->input, ABS_Y, field, cls->sn_move);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100343 set_last_slot_field(usage, td, hi);
344 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100345 return 1;
346 }
347 return 0;
348
349 case HID_UP_DIGITIZER:
350 switch (usage->hid) {
351 case HID_DG_INRANGE:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100352 set_last_slot_field(usage, td, hi);
353 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100354 return 1;
355 case HID_DG_CONFIDENCE:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100356 set_last_slot_field(usage, td, hi);
357 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100358 return 1;
359 case HID_DG_TIPSWITCH:
360 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
361 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100362 set_last_slot_field(usage, td, hi);
363 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100364 return 1;
365 case HID_DG_CONTACTID:
Benjamin Tissoires50bc03a2011-06-21 15:01:53 +0200366 if (!td->maxcontacts)
367 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100368 input_mt_init_slots(hi->input, td->maxcontacts);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100369 td->last_slot_field = usage->hid;
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200370 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100371 td->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100372 return 1;
373 case HID_DG_WIDTH:
374 hid_map_usage(hi, usage, bit, max,
375 EV_ABS, ABS_MT_TOUCH_MAJOR);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100376 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
377 cls->sn_width);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100378 set_last_slot_field(usage, td, hi);
379 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100380 return 1;
381 case HID_DG_HEIGHT:
382 hid_map_usage(hi, usage, bit, max,
383 EV_ABS, ABS_MT_TOUCH_MINOR);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100384 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
385 cls->sn_height);
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100386 input_set_abs_params(hi->input,
387 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100388 set_last_slot_field(usage, td, hi);
389 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100390 return 1;
391 case HID_DG_TIPPRESSURE:
392 hid_map_usage(hi, usage, bit, max,
393 EV_ABS, ABS_MT_PRESSURE);
394 set_abs(hi->input, ABS_MT_PRESSURE, field,
395 cls->sn_pressure);
396 /* touchscreen emulation */
397 set_abs(hi->input, ABS_PRESSURE, field,
398 cls->sn_pressure);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100399 set_last_slot_field(usage, td, hi);
400 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100401 return 1;
402 case HID_DG_CONTACTCOUNT:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100403 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100404 return 1;
405 case HID_DG_CONTACTMAX:
406 /* we don't set td->last_slot_field as contactcount and
407 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100408 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100409 return -1;
410 }
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100411 case HID_DG_TOUCH:
412 /* Legacy devices use TIPSWITCH and not TOUCH.
413 * Let's just ignore this field. */
414 return -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100415 /* let hid-input decide for the others */
416 return 0;
417
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100418 case HID_UP_BUTTON:
419 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
420 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
421 input_set_capability(hi->input, EV_KEY, code);
422 return 1;
423
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100424 case 0xff000000:
425 /* we do not want to map these: no input-oriented meaning */
426 return -1;
427 }
428
429 return 0;
430}
431
432static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
433 struct hid_field *field, struct hid_usage *usage,
434 unsigned long **bit, int *max)
435{
436 if (usage->type == EV_KEY || usage->type == EV_ABS)
437 set_bit(usage->type, hi->input->evbit);
438
439 return -1;
440}
441
442static int mt_compute_slot(struct mt_device *td)
443{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100444 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100445
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100446 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
447 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100448
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100449 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100450 return cypress_compute_slot(td);
451
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100452 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
453 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100454
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200455 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
456 return td->curdata.contactid - 1;
457
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100458 return find_slot_from_contactid(td);
459}
460
461/*
462 * this function is called when a whole contact has been processed,
463 * so that it can assign it to a slot and store the data there
464 */
465static void mt_complete_slot(struct mt_device *td)
466{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100467 td->curdata.seen_in_this_frame = true;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100468 if (td->curvalid) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100469 int slotnum = mt_compute_slot(td);
470
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100471 if (slotnum >= 0 && slotnum < td->maxcontacts)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100472 td->slots[slotnum] = td->curdata;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100473 }
474 td->num_received++;
475}
476
477
478/*
479 * this function is called when a whole packet has been received and processed,
480 * so that it can decide what to send to the input layer.
481 */
482static void mt_emit_event(struct mt_device *td, struct input_dev *input)
483{
484 int i;
485
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100486 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100487 struct mt_slot *s = &(td->slots[i]);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100488 if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100489 !s->seen_in_this_frame) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100490 s->touch_state = false;
491 }
492
493 input_mt_slot(input, i);
494 input_mt_report_slot_state(input, MT_TOOL_FINGER,
495 s->touch_state);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100496 if (s->touch_state) {
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100497 /* this finger is on the screen */
498 int wide = (s->w > s->h);
499 /* divided by two to match visual scale of touch */
500 int major = max(s->w, s->h) >> 1;
501 int minor = min(s->w, s->h) >> 1;
502
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100503 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
504 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100505 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100506 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100507 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
508 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100509 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100510 s->seen_in_this_frame = false;
511
512 }
513
514 input_mt_report_pointer_emulation(input, true);
515 input_sync(input);
516 td->num_received = 0;
517}
518
519
520
521static int mt_event(struct hid_device *hid, struct hid_field *field,
522 struct hid_usage *usage, __s32 value)
523{
524 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100525 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100526
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100527 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100528 switch (usage->hid) {
529 case HID_DG_INRANGE:
Stephane Chattya062cc52011-09-17 22:27:30 +0200530 if (quirks & MT_QUIRK_ALWAYS_VALID)
531 td->curvalid = true;
532 else if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100533 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100534 break;
535 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100536 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
537 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100538 td->curdata.touch_state = value;
539 break;
540 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100541 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
542 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100543 break;
544 case HID_DG_CONTACTID:
545 td->curdata.contactid = value;
546 break;
547 case HID_DG_TIPPRESSURE:
548 td->curdata.p = value;
549 break;
550 case HID_GD_X:
551 td->curdata.x = value;
552 break;
553 case HID_GD_Y:
554 td->curdata.y = value;
555 break;
556 case HID_DG_WIDTH:
557 td->curdata.w = value;
558 break;
559 case HID_DG_HEIGHT:
560 td->curdata.h = value;
561 break;
562 case HID_DG_CONTACTCOUNT:
563 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100564 * Includes multi-packet support where subsequent
565 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100566 */
567 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100568 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100569 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100570 case HID_DG_TOUCH:
571 /* do nothing */
572 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100573
574 default:
575 /* fallback to the generic hidinput handling */
576 return 0;
577 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100578
Denis Kovalev2258e862012-02-14 00:50:33 -0800579 if (usage->hid == td->last_slot_field)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100580 mt_complete_slot(td);
581
582 if (field->index == td->last_field_index
583 && td->num_received >= td->num_expected)
584 mt_emit_event(td, field->hidinput->input);
585
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100586 }
587
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100588 /* we have handled the hidinput part, now remains hiddev */
589 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
590 hid->hiddev_hid_event(hid, field, usage, value);
591
592 return 1;
593}
594
595static void mt_set_input_mode(struct hid_device *hdev)
596{
597 struct mt_device *td = hid_get_drvdata(hdev);
598 struct hid_report *r;
599 struct hid_report_enum *re;
600
601 if (td->inputmode < 0)
602 return;
603
604 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
605 r = re->report_id_hash[td->inputmode];
606 if (r) {
607 r->field[0]->value[0] = 0x02;
608 usbhid_submit_report(hdev, r, USB_DIR_OUT);
609 }
610}
611
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100612static void mt_set_maxcontacts(struct hid_device *hdev)
613{
614 struct mt_device *td = hid_get_drvdata(hdev);
615 struct hid_report *r;
616 struct hid_report_enum *re;
617 int fieldmax, max;
618
619 if (td->maxcontact_report_id < 0)
620 return;
621
622 if (!td->mtclass.maxcontacts)
623 return;
624
625 re = &hdev->report_enum[HID_FEATURE_REPORT];
626 r = re->report_id_hash[td->maxcontact_report_id];
627 if (r) {
628 max = td->mtclass.maxcontacts;
629 fieldmax = r->field[0]->logical_maximum;
630 max = min(fieldmax, max);
631 if (r->field[0]->value[0] != max) {
632 r->field[0]->value[0] = max;
633 usbhid_submit_report(hdev, r, USB_DIR_OUT);
634 }
635 }
636}
637
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200638static void mt_post_parse_default_settings(struct mt_device *td)
639{
640 __s32 quirks = td->mtclass.quirks;
641
642 /* unknown serial device needs special quirks */
643 if (td->touches_by_report == 1) {
644 quirks |= MT_QUIRK_ALWAYS_VALID;
645 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
646 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
647 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
648 }
649
650 td->mtclass.quirks = quirks;
651}
652
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100653static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
654{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100655 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100656 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100657 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
658
Benjamin Tissoires8d179a92012-03-06 17:57:04 +0100659 if (id) {
660 for (i = 0; mt_classes[i].name ; i++) {
661 if (id->driver_data == mt_classes[i].name) {
662 mtclass = &(mt_classes[i]);
663 break;
664 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100665 }
666 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100667
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100668 /* This allows the driver to correctly support devices
669 * that emit events over several HID messages.
670 */
671 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100672
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100673 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100674 if (!td) {
675 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
676 return -ENOMEM;
677 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100678 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100679 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100680 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100681 hid_set_drvdata(hdev, td);
682
683 ret = hid_parse(hdev);
684 if (ret != 0)
685 goto fail;
686
687 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100688 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100689 goto fail;
690
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200691 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
692 mt_post_parse_default_settings(td);
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100693
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100694 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
695 GFP_KERNEL);
696 if (!td->slots) {
697 dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
698 hid_hw_stop(hdev);
699 ret = -ENOMEM;
700 goto fail;
701 }
702
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100703 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
704
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100705 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100706 mt_set_input_mode(hdev);
707
708 return 0;
709
710fail:
711 kfree(td);
712 return ret;
713}
714
715#ifdef CONFIG_PM
716static int mt_reset_resume(struct hid_device *hdev)
717{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100718 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100719 mt_set_input_mode(hdev);
720 return 0;
721}
722#endif
723
724static void mt_remove(struct hid_device *hdev)
725{
726 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100727 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100728 hid_hw_stop(hdev);
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100729 kfree(td->slots);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100730 kfree(td);
731 hid_set_drvdata(hdev, NULL);
732}
733
734static const struct hid_device_id mt_devices[] = {
735
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100736 /* 3M panels */
737 { .driver_data = MT_CLS_3M,
738 HID_USB_DEVICE(USB_VENDOR_ID_3M,
739 USB_DEVICE_ID_3M1968) },
740 { .driver_data = MT_CLS_3M,
741 HID_USB_DEVICE(USB_VENDOR_ID_3M,
742 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100743 { .driver_data = MT_CLS_3M,
744 HID_USB_DEVICE(USB_VENDOR_ID_3M,
745 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100746
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200747 /* ActionStar panels */
748 { .driver_data = MT_CLS_DEFAULT,
749 HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
750 USB_DEVICE_ID_ACTIONSTAR_1011) },
751
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100752 /* Atmel panels */
753 { .driver_data = MT_CLS_SERIAL,
754 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL,
755 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100756 { .driver_data = MT_CLS_SERIAL,
757 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL,
758 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100759
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100760 /* Cando panels */
761 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
762 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
763 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
764 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
765 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
766 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
767 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
768 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
769 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
770 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
771 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
772 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
773
Austin Zhang942fd422011-05-28 02:03:47 +0800774 /* Chunghwa Telecom touch panels */
775 { .driver_data = MT_CLS_DEFAULT,
776 HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
777 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
778
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200779 /* CVTouch panels */
780 { .driver_data = MT_CLS_DEFAULT,
781 HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
782 USB_DEVICE_ID_CVTOUCH_SCREEN) },
783
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100784 /* Cypress panel */
785 { .driver_data = MT_CLS_CYPRESS,
786 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
787 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
788
Benjamin Tissoires22408282011-05-20 15:59:34 +0200789 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100790 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200791 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100792 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
793 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200794 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100795 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200796
797 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100798 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200799 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100800 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100801 { .driver_data = MT_CLS_EGALAX_SERIAL,
802 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
803 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
804 { .driver_data = MT_CLS_EGALAX_SERIAL,
805 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
806 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
807 { .driver_data = MT_CLS_EGALAX_SERIAL,
808 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
809 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100810 { .driver_data = MT_CLS_EGALAX_SERIAL,
811 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
812 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100813 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200814 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100815 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100816 { .driver_data = MT_CLS_EGALAX_SERIAL,
817 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
818 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100819 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200820 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100821 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100822 { .driver_data = MT_CLS_EGALAX_SERIAL,
823 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
824 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100825 { .driver_data = MT_CLS_EGALAX,
Chris Bagwell1fd8f042011-11-23 10:54:27 +0100826 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100827 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
828 { .driver_data = MT_CLS_EGALAX,
829 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100830 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100831 { .driver_data = MT_CLS_EGALAX_SERIAL,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100832 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100833 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
834 { .driver_data = MT_CLS_EGALAX_SERIAL,
835 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100836 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200837
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200838 /* Elo TouchSystems IntelliTouch Plus panel */
839 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
840 HID_USB_DEVICE(USB_VENDOR_ID_ELO,
841 USB_DEVICE_ID_ELO_TS2515) },
842
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100843 /* GeneralTouch panel */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100844 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100845 HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
846 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
847
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100848 /* Gametel game controller */
849 { .driver_data = MT_CLS_DEFAULT,
850 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_FRUCTEL,
851 USB_DEVICE_ID_GAMETEL_MT_MODE) },
852
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200853 /* GoodTouch panels */
854 { .driver_data = MT_CLS_DEFAULT,
855 HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
856 USB_DEVICE_ID_GOODTOUCH_000f) },
857
Benjamin Tissoires54580362011-11-29 13:13:12 +0100858 /* Hanvon panels */
859 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
860 HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
861 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
862
Stephane Chattya062cc52011-09-17 22:27:30 +0200863 /* Ideacom panel */
864 { .driver_data = MT_CLS_SERIAL,
865 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
866 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +0100867 { .driver_data = MT_CLS_SERIAL,
868 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
869 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +0200870
Austin Zhang4e61f0d2011-05-09 23:54:14 +0800871 /* Ilitek dual touch panel */
872 { .driver_data = MT_CLS_DEFAULT,
873 HID_USB_DEVICE(USB_VENDOR_ID_ILITEK,
874 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
875
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +0100876 /* IRTOUCH panels */
877 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
878 HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
879 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
880
Jeff Brownc50bb1a2011-08-15 21:12:09 -0700881 /* LG Display panels */
882 { .driver_data = MT_CLS_DEFAULT,
883 HID_USB_DEVICE(USB_VENDOR_ID_LG,
884 USB_DEVICE_ID_LG_MULTITOUCH) },
885
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +0200886 /* Lumio panels */
887 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
888 HID_USB_DEVICE(USB_VENDOR_ID_LUMIO,
889 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +0200890 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
891 HID_USB_DEVICE(USB_VENDOR_ID_LUMIO,
892 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +0200893
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200894 /* MosArt panels */
895 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
896 HID_USB_DEVICE(USB_VENDOR_ID_ASUS,
897 USB_DEVICE_ID_ASUS_T91MT)},
898 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
899 HID_USB_DEVICE(USB_VENDOR_ID_ASUS,
900 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
901 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
902 HID_USB_DEVICE(USB_VENDOR_ID_TURBOX,
903 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
904
Denis Kovalev2258e862012-02-14 00:50:33 -0800905 /* Panasonic panels */
906 { .driver_data = MT_CLS_PANASONIC,
907 HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
908 USB_DEVICE_ID_PANABOARD_UBT780) },
909 { .driver_data = MT_CLS_PANASONIC,
910 HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
911 USB_DEVICE_ID_PANABOARD_UBT880) },
912
John Sung6ab3a9a2011-04-21 16:21:52 +0200913 /* PenMount panels */
914 { .driver_data = MT_CLS_CONFIDENCE,
915 HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
916 USB_DEVICE_ID_PENMOUNT_PCI) },
917
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800918 /* PixArt optical touch screen */
919 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
920 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
921 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
922 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
923 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
924 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
925 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
926 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
927 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
928
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100929 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100930 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100931 HID_USB_DEVICE(USB_VENDOR_ID_HANVON,
932 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100933 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100934 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
935 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
936
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100937 /* Quanta-based panels */
938 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
939 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
940 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
941 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
942 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
943 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
944 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
945 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
946 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
947
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100948 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +0200949 { .driver_data = MT_CLS_CONFIDENCE,
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100950 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
951 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +0200952 { .driver_data = MT_CLS_CONFIDENCE,
Benjamin Tissoires85a60082011-06-21 15:01:54 +0200953 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100954 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +0200955 { .driver_data = MT_CLS_CONFIDENCE,
Benjamin Tissoires85a60082011-06-21 15:01:54 +0200956 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100957 USB_DEVICE_ID_MTP_SITRONIX)},
958
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100959 /* TopSeed panels */
960 { .driver_data = MT_CLS_TOPSEED,
961 HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
962 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
963
Benjamin Tissoires5e74e562011-05-19 14:18:16 +0200964 /* Touch International panels */
965 { .driver_data = MT_CLS_DEFAULT,
966 HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
967 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
968
Benjamin Tissoires617b64f2011-05-19 14:18:17 +0200969 /* Unitec panels */
970 { .driver_data = MT_CLS_DEFAULT,
971 HID_USB_DEVICE(USB_VENDOR_ID_UNITEC,
972 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
973 { .driver_data = MT_CLS_DEFAULT,
974 HID_USB_DEVICE(USB_VENDOR_ID_UNITEC,
975 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +0800976 /* XAT */
977 { .driver_data = MT_CLS_DEFAULT,
978 HID_USB_DEVICE(USB_VENDOR_ID_XAT,
979 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +0200980
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +0900981 /* Xiroku */
982 { .driver_data = MT_CLS_DEFAULT,
983 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
984 USB_DEVICE_ID_XIROKU_SPX) },
985 { .driver_data = MT_CLS_DEFAULT,
986 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
987 USB_DEVICE_ID_XIROKU_MPX) },
988 { .driver_data = MT_CLS_DEFAULT,
989 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
990 USB_DEVICE_ID_XIROKU_CSR) },
991 { .driver_data = MT_CLS_DEFAULT,
992 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
993 USB_DEVICE_ID_XIROKU_SPX1) },
994 { .driver_data = MT_CLS_DEFAULT,
995 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
996 USB_DEVICE_ID_XIROKU_MPX1) },
997 { .driver_data = MT_CLS_DEFAULT,
998 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
999 USB_DEVICE_ID_XIROKU_CSR1) },
1000 { .driver_data = MT_CLS_DEFAULT,
1001 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1002 USB_DEVICE_ID_XIROKU_SPX2) },
1003 { .driver_data = MT_CLS_DEFAULT,
1004 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1005 USB_DEVICE_ID_XIROKU_MPX2) },
1006 { .driver_data = MT_CLS_DEFAULT,
1007 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
1008 USB_DEVICE_ID_XIROKU_CSR2) },
1009
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001010 /* Generic MT device */
1011 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001012 { }
1013};
1014MODULE_DEVICE_TABLE(hid, mt_devices);
1015
1016static const struct hid_usage_id mt_grabbed_usages[] = {
1017 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1018 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1019};
1020
1021static struct hid_driver mt_driver = {
1022 .name = "hid-multitouch",
1023 .id_table = mt_devices,
1024 .probe = mt_probe,
1025 .remove = mt_remove,
1026 .input_mapping = mt_input_mapping,
1027 .input_mapped = mt_input_mapped,
1028 .feature_mapping = mt_feature_mapping,
1029 .usage_table = mt_grabbed_usages,
1030 .event = mt_event,
1031#ifdef CONFIG_PM
1032 .reset_resume = mt_reset_resume,
1033#endif
1034};
1035
1036static int __init mt_init(void)
1037{
1038 return hid_register_driver(&mt_driver);
1039}
1040
1041static void __exit mt_exit(void)
1042{
1043 hid_unregister_driver(&mt_driver);
1044}
1045
1046module_init(mt_init);
1047module_exit(mt_exit);