blob: 0eda37f03c302b1544949910424678e31dffefd7 [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 */
78 int last_mt_collection; /* last known mt-related collection */
79 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010080 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
81 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010082 __u8 num_received; /* how many contacts we received */
83 __u8 num_expected; /* expected last contact index */
84 __u8 maxcontacts;
85 bool curvalid; /* is the current contact valid? */
86 struct mt_slot *slots;
87};
88
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010089/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +020090#define MT_CLS_DEFAULT 0x0001
91
Stephane Chattya062cc52011-09-17 22:27:30 +020092#define MT_CLS_SERIAL 0x0002
93#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +010094#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
95#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
96#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
97#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
98#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +080099#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200100
101/* vendor specific classes */
102#define MT_CLS_3M 0x0101
103#define MT_CLS_CYPRESS 0x0102
104#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100105#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100106#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800107#define MT_CLS_PANASONIC 0x0106
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100108
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100109#define MT_DEFAULT_MAXCONTACT 10
110
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100111/*
112 * these device-dependent functions determine what slot corresponds
113 * to a valid contact that was just read.
114 */
115
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100116static int cypress_compute_slot(struct mt_device *td)
117{
118 if (td->curdata.contactid != 0 || td->num_received == 0)
119 return td->curdata.contactid;
120 else
121 return -1;
122}
123
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100124static int find_slot_from_contactid(struct mt_device *td)
125{
126 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100127 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100128 if (td->slots[i].contactid == td->curdata.contactid &&
129 td->slots[i].touch_state)
130 return i;
131 }
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100132 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100133 if (!td->slots[i].seen_in_this_frame &&
134 !td->slots[i].touch_state)
135 return i;
136 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100137 /* should not occurs. If this happens that means
138 * that the device sent more touches that it says
139 * in the report descriptor. It is ignored then. */
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100140 return -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100141}
142
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100143static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100144 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100145 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200146 { .name = MT_CLS_SERIAL,
147 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200148 { .name = MT_CLS_CONFIDENCE,
149 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100150 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
151 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
152 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200153 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
154 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
155 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100156 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100157 .quirks = MT_QUIRK_VALID_IS_INRANGE |
158 MT_QUIRK_SLOT_IS_CONTACTID,
159 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100160 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100161 .quirks = MT_QUIRK_VALID_IS_INRANGE |
162 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
163 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200164 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
165 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
166 MT_QUIRK_SLOT_IS_CONTACTID,
167 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800168 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
169 .quirks = MT_QUIRK_VALID_IS_INRANGE |
170 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200171
172 /*
173 * vendor specific classes
174 */
175 { .name = MT_CLS_3M,
176 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
177 MT_QUIRK_SLOT_IS_CONTACTID,
178 .sn_move = 2048,
179 .sn_width = 128,
180 .sn_height = 128 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100181 { .name = MT_CLS_CYPRESS,
182 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
183 MT_QUIRK_CYPRESS,
184 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100185 { .name = MT_CLS_EGALAX,
186 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100187 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100188 .sn_move = 4096,
189 .sn_pressure = 32,
190 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100191 { .name = MT_CLS_EGALAX_SERIAL,
192 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
193 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100194 .sn_move = 4096,
195 .sn_pressure = 32,
196 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100197 { .name = MT_CLS_TOPSEED,
198 .quirks = MT_QUIRK_ALWAYS_VALID,
199 .is_indirect = true,
200 .maxcontacts = 2,
201 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800202 { .name = MT_CLS_PANASONIC,
203 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
204 .maxcontacts = 4 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100205
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100206 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100207};
208
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100209static ssize_t mt_show_quirks(struct device *dev,
210 struct device_attribute *attr,
211 char *buf)
212{
213 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
214 struct mt_device *td = hid_get_drvdata(hdev);
215
216 return sprintf(buf, "%u\n", td->mtclass.quirks);
217}
218
219static ssize_t mt_set_quirks(struct device *dev,
220 struct device_attribute *attr,
221 const char *buf, size_t count)
222{
223 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
224 struct mt_device *td = hid_get_drvdata(hdev);
225
226 unsigned long val;
227
228 if (kstrtoul(buf, 0, &val))
229 return -EINVAL;
230
231 td->mtclass.quirks = val;
232
233 return count;
234}
235
236static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
237
238static struct attribute *sysfs_attrs[] = {
239 &dev_attr_quirks.attr,
240 NULL
241};
242
243static struct attribute_group mt_attribute_group = {
244 .attrs = sysfs_attrs
245};
246
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100247static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100248 struct hid_field *field, struct hid_usage *usage)
249{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100250 struct mt_device *td = hid_get_drvdata(hdev);
251
252 switch (usage->hid) {
253 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100254 td->inputmode = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100255 break;
256 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100257 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100258 td->maxcontacts = field->value[0];
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100259 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100260 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100261 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100262
263 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100264 }
265}
266
267static void set_abs(struct input_dev *input, unsigned int code,
268 struct hid_field *field, int snratio)
269{
270 int fmin = field->logical_minimum;
271 int fmax = field->logical_maximum;
272 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
273 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
274}
275
276static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
277 struct hid_field *field, struct hid_usage *usage,
278 unsigned long **bit, int *max)
279{
280 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100281 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100282 int code;
Richard Nauber4875ac12011-03-09 06:20:57 +0100283
Jeff Brown658d4aed592011-08-15 16:44:28 -0700284 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800285 * We need to ignore fields that belong to other collections
286 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700287 if (field->application == HID_DG_TOUCHSCREEN)
288 set_bit(INPUT_PROP_DIRECT, hi->input->propbit);
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100289 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700290 return 0;
291
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100292 /* In case of an indirect device (touchpad), we need to add
293 * specific BTN_TOOL_* to be handled by the synaptics xorg
294 * driver.
295 * We also consider that touchscreens providing buttons are touchpads.
296 */
297 if (field->application == HID_DG_TOUCHPAD ||
298 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON ||
299 cls->is_indirect) {
300 set_bit(INPUT_PROP_POINTER, hi->input->propbit);
301 set_bit(BTN_TOOL_FINGER, hi->input->keybit);
302 set_bit(BTN_TOOL_DOUBLETAP, hi->input->keybit);
303 set_bit(BTN_TOOL_TRIPLETAP, hi->input->keybit);
304 set_bit(BTN_TOOL_QUADTAP, hi->input->keybit);
305 }
306
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100307 /* eGalax devices provide a Digitizer.Stylus input which overrides
308 * the correct Digitizers.Finger X/Y ranges.
309 * Let's just ignore this input. */
310 if (field->physical == HID_DG_STYLUS)
311 return -1;
312
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100313 switch (usage->hid & HID_USAGE_PAGE) {
314
315 case HID_UP_GENDESK:
316 switch (usage->hid) {
317 case HID_GD_X:
318 hid_map_usage(hi, usage, bit, max,
319 EV_ABS, ABS_MT_POSITION_X);
320 set_abs(hi->input, ABS_MT_POSITION_X, field,
321 cls->sn_move);
322 /* touchscreen emulation */
323 set_abs(hi->input, ABS_X, field, cls->sn_move);
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200324 if (td->last_mt_collection == usage->collection_index) {
325 td->last_slot_field = usage->hid;
326 td->last_field_index = field->index;
327 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100328 return 1;
329 case HID_GD_Y:
330 hid_map_usage(hi, usage, bit, max,
331 EV_ABS, ABS_MT_POSITION_Y);
332 set_abs(hi->input, ABS_MT_POSITION_Y, field,
333 cls->sn_move);
334 /* touchscreen emulation */
335 set_abs(hi->input, ABS_Y, field, cls->sn_move);
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200336 if (td->last_mt_collection == usage->collection_index) {
337 td->last_slot_field = usage->hid;
338 td->last_field_index = field->index;
339 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100340 return 1;
341 }
342 return 0;
343
344 case HID_UP_DIGITIZER:
345 switch (usage->hid) {
346 case HID_DG_INRANGE:
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200347 if (td->last_mt_collection == usage->collection_index) {
348 td->last_slot_field = usage->hid;
349 td->last_field_index = field->index;
350 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100351 return 1;
352 case HID_DG_CONFIDENCE:
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200353 if (td->last_mt_collection == usage->collection_index) {
354 td->last_slot_field = usage->hid;
355 td->last_field_index = field->index;
356 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100357 return 1;
358 case HID_DG_TIPSWITCH:
359 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
360 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200361 if (td->last_mt_collection == usage->collection_index) {
362 td->last_slot_field = usage->hid;
363 td->last_field_index = field->index;
364 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100365 return 1;
366 case HID_DG_CONTACTID:
Benjamin Tissoires50bc03a2011-06-21 15:01:53 +0200367 if (!td->maxcontacts)
368 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100369 input_mt_init_slots(hi->input, td->maxcontacts);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100370 td->last_slot_field = usage->hid;
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200371 td->last_field_index = field->index;
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200372 td->last_mt_collection = usage->collection_index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100373 return 1;
374 case HID_DG_WIDTH:
375 hid_map_usage(hi, usage, bit, max,
376 EV_ABS, ABS_MT_TOUCH_MAJOR);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100377 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
378 cls->sn_width);
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200379 if (td->last_mt_collection == usage->collection_index) {
380 td->last_slot_field = usage->hid;
381 td->last_field_index = field->index;
382 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100383 return 1;
384 case HID_DG_HEIGHT:
385 hid_map_usage(hi, usage, bit, max,
386 EV_ABS, ABS_MT_TOUCH_MINOR);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100387 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
388 cls->sn_height);
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100389 input_set_abs_params(hi->input,
390 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200391 if (td->last_mt_collection == usage->collection_index) {
392 td->last_slot_field = usage->hid;
393 td->last_field_index = field->index;
394 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100395 return 1;
396 case HID_DG_TIPPRESSURE:
397 hid_map_usage(hi, usage, bit, max,
398 EV_ABS, ABS_MT_PRESSURE);
399 set_abs(hi->input, ABS_MT_PRESSURE, field,
400 cls->sn_pressure);
401 /* touchscreen emulation */
402 set_abs(hi->input, ABS_PRESSURE, field,
403 cls->sn_pressure);
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200404 if (td->last_mt_collection == usage->collection_index) {
405 td->last_slot_field = usage->hid;
406 td->last_field_index = field->index;
407 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100408 return 1;
409 case HID_DG_CONTACTCOUNT:
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200410 if (td->last_mt_collection == usage->collection_index)
411 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100412 return 1;
413 case HID_DG_CONTACTMAX:
414 /* we don't set td->last_slot_field as contactcount and
415 * contact max are global to the report */
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200416 if (td->last_mt_collection == usage->collection_index)
417 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100418 return -1;
419 }
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100420 case HID_DG_TOUCH:
421 /* Legacy devices use TIPSWITCH and not TOUCH.
422 * Let's just ignore this field. */
423 return -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100424 /* let hid-input decide for the others */
425 return 0;
426
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100427 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
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100433 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{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100453 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100454
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100455 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
456 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100457
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100458 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100459 return cypress_compute_slot(td);
460
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100461 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
462 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100463
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200464 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
465 return td->curdata.contactid - 1;
466
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100467 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{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100476 td->curdata.seen_in_this_frame = true;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100477 if (td->curvalid) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100478 int slotnum = mt_compute_slot(td);
479
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100480 if (slotnum >= 0 && slotnum < td->maxcontacts)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100481 td->slots[slotnum] = td->curdata;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100482 }
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
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100495 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100496 struct mt_slot *s = &(td->slots[i]);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100497 if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100498 !s->seen_in_this_frame) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100499 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);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100505 if (s->touch_state) {
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100506 /* 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
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100512 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
513 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100514 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100515 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100516 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
517 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100518 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100519 s->seen_in_this_frame = false;
520
521 }
522
523 input_mt_report_pointer_emulation(input, true);
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);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100534 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100535
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100536 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100537 switch (usage->hid) {
538 case HID_DG_INRANGE:
Stephane Chattya062cc52011-09-17 22:27:30 +0200539 if (quirks & MT_QUIRK_ALWAYS_VALID)
540 td->curvalid = true;
541 else if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100542 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100543 break;
544 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100545 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
546 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100547 td->curdata.touch_state = value;
548 break;
549 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100550 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
551 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100552 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 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100573 * Includes multi-packet support where subsequent
574 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100575 */
576 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100577 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100578 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100579 case HID_DG_TOUCH:
580 /* do nothing */
581 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100582
583 default:
584 /* fallback to the generic hidinput handling */
585 return 0;
586 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100587
Denis Kovalev2258e862012-02-14 00:50:33 -0800588 if (usage->hid == td->last_slot_field)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100589 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);
594
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100595 }
596
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100597 /* 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) {
616 r->field[0]->value[0] = 0x02;
617 usbhid_submit_report(hdev, r, USB_DIR_OUT);
618 }
619}
620
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100621static 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
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100647static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
648{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100649 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100650 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100651 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
652
653 for (i = 0; mt_classes[i].name ; i++) {
654 if (id->driver_data == mt_classes[i].name) {
655 mtclass = &(mt_classes[i]);
656 break;
657 }
658 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100659
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100660 /* This allows the driver to correctly support devices
661 * that emit events over several HID messages.
662 */
663 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100664
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100665 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100666 if (!td) {
667 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
668 return -ENOMEM;
669 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100670 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100671 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100672 td->maxcontact_report_id = -1;
Benjamin Tissoiresb84bd272011-06-12 08:22:08 +0200673 td->last_mt_collection = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100674 hid_set_drvdata(hdev, td);
675
676 ret = hid_parse(hdev);
677 if (ret != 0)
678 goto fail;
679
680 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100681 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100682 goto fail;
683
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100684 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
685 GFP_KERNEL);
686 if (!td->slots) {
687 dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
688 hid_hw_stop(hdev);
689 ret = -ENOMEM;
690 goto fail;
691 }
692
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100693 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
694
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100695 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100696 mt_set_input_mode(hdev);
697
698 return 0;
699
700fail:
701 kfree(td);
702 return ret;
703}
704
705#ifdef CONFIG_PM
706static int mt_reset_resume(struct hid_device *hdev)
707{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100708 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100709 mt_set_input_mode(hdev);
710 return 0;
711}
712#endif
713
714static void mt_remove(struct hid_device *hdev)
715{
716 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100717 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100718 hid_hw_stop(hdev);
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100719 kfree(td->slots);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100720 kfree(td);
721 hid_set_drvdata(hdev, NULL);
722}
723
724static const struct hid_device_id mt_devices[] = {
725
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100726 /* 3M panels */
727 { .driver_data = MT_CLS_3M,
728 HID_USB_DEVICE(USB_VENDOR_ID_3M,
729 USB_DEVICE_ID_3M1968) },
730 { .driver_data = MT_CLS_3M,
731 HID_USB_DEVICE(USB_VENDOR_ID_3M,
732 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100733 { .driver_data = MT_CLS_3M,
734 HID_USB_DEVICE(USB_VENDOR_ID_3M,
735 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100736
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200737 /* ActionStar panels */
738 { .driver_data = MT_CLS_DEFAULT,
739 HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
740 USB_DEVICE_ID_ACTIONSTAR_1011) },
741
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100742 /* Atmel panels */
743 { .driver_data = MT_CLS_SERIAL,
744 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL,
745 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100746 { .driver_data = MT_CLS_SERIAL,
747 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL,
748 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100749
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100750 /* Cando panels */
751 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
752 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
753 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
754 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
755 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
756 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
757 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
758 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
759 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
760 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
761 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
762 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
763
Austin Zhang942fd422011-05-28 02:03:47 +0800764 /* Chunghwa Telecom touch panels */
765 { .driver_data = MT_CLS_DEFAULT,
766 HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
767 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
768
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200769 /* CVTouch panels */
770 { .driver_data = MT_CLS_DEFAULT,
771 HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
772 USB_DEVICE_ID_CVTOUCH_SCREEN) },
773
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100774 /* Cypress panel */
775 { .driver_data = MT_CLS_CYPRESS,
776 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
777 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
778
Benjamin Tissoires22408282011-05-20 15:59:34 +0200779 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100780 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200781 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100782 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
783 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200784 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100785 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200786
787 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100788 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200789 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100790 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100791 { .driver_data = MT_CLS_EGALAX_SERIAL,
792 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
793 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
794 { .driver_data = MT_CLS_EGALAX_SERIAL,
795 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
796 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
797 { .driver_data = MT_CLS_EGALAX_SERIAL,
798 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
799 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100800 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200801 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100802 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100803 { .driver_data = MT_CLS_EGALAX_SERIAL,
804 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
805 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100806 { .driver_data = MT_CLS_EGALAX,
Benjamin Tissoires22408282011-05-20 15:59:34 +0200807 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100808 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100809 { .driver_data = MT_CLS_EGALAX_SERIAL,
810 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
811 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100812 { .driver_data = MT_CLS_EGALAX,
Chris Bagwell1fd8f042011-11-23 10:54:27 +0100813 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100814 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
815 { .driver_data = MT_CLS_EGALAX,
816 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100817 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100818 { .driver_data = MT_CLS_EGALAX_SERIAL,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100819 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100820 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
821 { .driver_data = MT_CLS_EGALAX_SERIAL,
822 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100823 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200824
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200825 /* Elo TouchSystems IntelliTouch Plus panel */
826 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
827 HID_USB_DEVICE(USB_VENDOR_ID_ELO,
828 USB_DEVICE_ID_ELO_TS2515) },
829
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100830 /* GeneralTouch panel */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100831 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100832 HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
833 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
834
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200835 /* GoodTouch panels */
836 { .driver_data = MT_CLS_DEFAULT,
837 HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
838 USB_DEVICE_ID_GOODTOUCH_000f) },
839
Benjamin Tissoires54580362011-11-29 13:13:12 +0100840 /* Hanvon panels */
841 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
842 HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
843 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
844
Stephane Chattya062cc52011-09-17 22:27:30 +0200845 /* Ideacom panel */
846 { .driver_data = MT_CLS_SERIAL,
847 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
848 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +0100849 { .driver_data = MT_CLS_SERIAL,
850 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
851 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +0200852
Austin Zhang4e61f0d2011-05-09 23:54:14 +0800853 /* Ilitek dual touch panel */
854 { .driver_data = MT_CLS_DEFAULT,
855 HID_USB_DEVICE(USB_VENDOR_ID_ILITEK,
856 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
857
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +0100858 /* IRTOUCH panels */
859 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
860 HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
861 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
862
Jeff Brownc50bb1a2011-08-15 21:12:09 -0700863 /* LG Display panels */
864 { .driver_data = MT_CLS_DEFAULT,
865 HID_USB_DEVICE(USB_VENDOR_ID_LG,
866 USB_DEVICE_ID_LG_MULTITOUCH) },
867
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +0200868 /* Lumio panels */
869 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
870 HID_USB_DEVICE(USB_VENDOR_ID_LUMIO,
871 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +0200872 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
873 HID_USB_DEVICE(USB_VENDOR_ID_LUMIO,
874 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +0200875
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200876 /* MosArt panels */
877 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
878 HID_USB_DEVICE(USB_VENDOR_ID_ASUS,
879 USB_DEVICE_ID_ASUS_T91MT)},
880 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
881 HID_USB_DEVICE(USB_VENDOR_ID_ASUS,
882 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
883 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
884 HID_USB_DEVICE(USB_VENDOR_ID_TURBOX,
885 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
886
Denis Kovalev2258e862012-02-14 00:50:33 -0800887 /* Panasonic panels */
888 { .driver_data = MT_CLS_PANASONIC,
889 HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
890 USB_DEVICE_ID_PANABOARD_UBT780) },
891 { .driver_data = MT_CLS_PANASONIC,
892 HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
893 USB_DEVICE_ID_PANABOARD_UBT880) },
894
John Sung6ab3a9a2011-04-21 16:21:52 +0200895 /* PenMount panels */
896 { .driver_data = MT_CLS_CONFIDENCE,
897 HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
898 USB_DEVICE_ID_PENMOUNT_PCI) },
899
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800900 /* PixArt optical touch screen */
901 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
902 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
903 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
904 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
905 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
906 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
907 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
908 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
909 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
910
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100911 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100912 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100913 HID_USB_DEVICE(USB_VENDOR_ID_HANVON,
914 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100915 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100916 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
917 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
918
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100919 /* Quanta-based panels */
920 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
921 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
922 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
923 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
924 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
925 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
926 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
927 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
928 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
929
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100930 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +0200931 { .driver_data = MT_CLS_CONFIDENCE,
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100932 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
933 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +0200934 { .driver_data = MT_CLS_CONFIDENCE,
Benjamin Tissoires85a60082011-06-21 15:01:54 +0200935 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100936 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +0200937 { .driver_data = MT_CLS_CONFIDENCE,
Benjamin Tissoires85a60082011-06-21 15:01:54 +0200938 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100939 USB_DEVICE_ID_MTP_SITRONIX)},
940
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100941 /* TopSeed panels */
942 { .driver_data = MT_CLS_TOPSEED,
943 HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
944 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
945
Benjamin Tissoires5e74e562011-05-19 14:18:16 +0200946 /* Touch International panels */
947 { .driver_data = MT_CLS_DEFAULT,
948 HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
949 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
950
Benjamin Tissoires617b64f2011-05-19 14:18:17 +0200951 /* Unitec panels */
952 { .driver_data = MT_CLS_DEFAULT,
953 HID_USB_DEVICE(USB_VENDOR_ID_UNITEC,
954 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
955 { .driver_data = MT_CLS_DEFAULT,
956 HID_USB_DEVICE(USB_VENDOR_ID_UNITEC,
957 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +0800958 /* XAT */
959 { .driver_data = MT_CLS_DEFAULT,
960 HID_USB_DEVICE(USB_VENDOR_ID_XAT,
961 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +0200962
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +0900963 /* Xiroku */
964 { .driver_data = MT_CLS_DEFAULT,
965 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
966 USB_DEVICE_ID_XIROKU_SPX) },
967 { .driver_data = MT_CLS_DEFAULT,
968 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
969 USB_DEVICE_ID_XIROKU_MPX) },
970 { .driver_data = MT_CLS_DEFAULT,
971 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
972 USB_DEVICE_ID_XIROKU_CSR) },
973 { .driver_data = MT_CLS_DEFAULT,
974 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
975 USB_DEVICE_ID_XIROKU_SPX1) },
976 { .driver_data = MT_CLS_DEFAULT,
977 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
978 USB_DEVICE_ID_XIROKU_MPX1) },
979 { .driver_data = MT_CLS_DEFAULT,
980 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
981 USB_DEVICE_ID_XIROKU_CSR1) },
982 { .driver_data = MT_CLS_DEFAULT,
983 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
984 USB_DEVICE_ID_XIROKU_SPX2) },
985 { .driver_data = MT_CLS_DEFAULT,
986 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
987 USB_DEVICE_ID_XIROKU_MPX2) },
988 { .driver_data = MT_CLS_DEFAULT,
989 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
990 USB_DEVICE_ID_XIROKU_CSR2) },
991
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100992 { }
993};
994MODULE_DEVICE_TABLE(hid, mt_devices);
995
996static const struct hid_usage_id mt_grabbed_usages[] = {
997 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
998 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
999};
1000
1001static struct hid_driver mt_driver = {
1002 .name = "hid-multitouch",
1003 .id_table = mt_devices,
1004 .probe = mt_probe,
1005 .remove = mt_remove,
1006 .input_mapping = mt_input_mapping,
1007 .input_mapped = mt_input_mapped,
1008 .feature_mapping = mt_feature_mapping,
1009 .usage_table = mt_grabbed_usages,
1010 .event = mt_event,
1011#ifdef CONFIG_PM
1012 .reset_resume = mt_reset_resume,
1013#endif
1014};
1015
1016static int __init mt_init(void)
1017{
1018 return hid_register_driver(&mt_driver);
1019}
1020
1021static void __exit mt_exit(void)
1022{
1023 hid_unregister_driver(&mt_driver);
1024}
1025
1026module_init(mt_init);
1027module_exit(mt_exit);