blob: 13b94619b5d001f58804b6c4596fec74e8448ff5 [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)
Henrik Rydberg77723e32012-09-07 19:37:40 +020054#define MT_QUIRK_NO_AREA (1 << 9)
Benjamin Tissoires28728392012-11-14 16:59:23 +010055#define MT_QUIRK_IGNORE_DUPLICATES (1 << 10)
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +010056#define MT_QUIRK_HOVERING (1 << 11)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010057
58struct mt_slot {
Benjamin Tissoires349fd672012-11-14 16:59:19 +010059 __s32 x, y, cx, cy, p, w, h;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010060 __s32 contactid; /* the device ContactID assigned to this slot */
61 bool touch_state; /* is the touch valid? */
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +010062 bool inrange_state; /* is the finger in proximity of the sensor? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010063};
64
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010065struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010066 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010067 __s32 quirks;
68 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010069 __s32 sn_width; /* Signal/noise ratio for width events */
70 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010071 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
72 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +010073 bool is_indirect; /* true for touchpads */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010074};
75
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020076struct mt_fields {
77 unsigned usages[HID_MAX_FIELDS];
78 unsigned int length;
79};
80
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010081struct mt_device {
82 struct mt_slot curdata; /* placeholder of incoming data */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +010083 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020084 struct mt_fields *fields; /* temporary placeholder for storing the
85 multitouch fields */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010086 unsigned last_field_index; /* last field index of the report */
87 unsigned last_slot_field; /* the last field of a slot */
Benjamin Tissoires55978fa2013-01-31 17:22:24 +010088 unsigned mt_report_id; /* the report ID of the multitouch device */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010089 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires4aceed32012-06-19 14:39:52 +020090 __s8 inputmode_index; /* InputMode HID feature index in the report */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010091 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
92 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010093 __u8 num_received; /* how many contacts we received */
94 __u8 num_expected; /* expected last contact index */
95 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010096 __u8 touches_by_report; /* how many touches are present in one report:
97 * 1 means we should use a serial protocol
98 * > 1 means hybrid (multitouch) protocol */
Henrik Rydberg76f59022012-09-01 20:11:34 +020099 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100100 bool curvalid; /* is the current contact valid? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200101 unsigned mt_flags; /* flags to pass to input-mt */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100102};
103
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100104/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200105#define MT_CLS_DEFAULT 0x0001
106
Stephane Chattya062cc52011-09-17 22:27:30 +0200107#define MT_CLS_SERIAL 0x0002
108#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100109#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
110#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
111#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
112#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
113#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800114#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200115
116/* vendor specific classes */
117#define MT_CLS_3M 0x0101
118#define MT_CLS_CYPRESS 0x0102
119#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100120#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100121#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800122#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200123#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200124#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
125#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100126
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100127#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100128#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100129
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200130#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
131#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
132
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100133/*
134 * these device-dependent functions determine what slot corresponds
135 * to a valid contact that was just read.
136 */
137
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100138static int cypress_compute_slot(struct mt_device *td)
139{
140 if (td->curdata.contactid != 0 || td->num_received == 0)
141 return td->curdata.contactid;
142 else
143 return -1;
144}
145
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100146static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100147 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100148 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200149 { .name = MT_CLS_SERIAL,
150 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200151 { .name = MT_CLS_CONFIDENCE,
152 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100153 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
154 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
155 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200156 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
157 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
158 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100159 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100160 .quirks = MT_QUIRK_VALID_IS_INRANGE |
161 MT_QUIRK_SLOT_IS_CONTACTID,
162 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100163 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100164 .quirks = MT_QUIRK_VALID_IS_INRANGE |
165 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
166 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200167 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
168 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
169 MT_QUIRK_SLOT_IS_CONTACTID,
170 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800171 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
172 .quirks = MT_QUIRK_VALID_IS_INRANGE |
173 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200174
175 /*
176 * vendor specific classes
177 */
178 { .name = MT_CLS_3M,
179 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
180 MT_QUIRK_SLOT_IS_CONTACTID,
181 .sn_move = 2048,
182 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200183 .sn_height = 128,
184 .maxcontacts = 60,
185 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100186 { .name = MT_CLS_CYPRESS,
187 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
188 MT_QUIRK_CYPRESS,
189 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100190 { .name = MT_CLS_EGALAX,
191 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100192 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100193 .sn_move = 4096,
194 .sn_pressure = 32,
195 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100196 { .name = MT_CLS_EGALAX_SERIAL,
197 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
198 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100199 .sn_move = 4096,
200 .sn_pressure = 32,
201 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100202 { .name = MT_CLS_TOPSEED,
203 .quirks = MT_QUIRK_ALWAYS_VALID,
204 .is_indirect = true,
205 .maxcontacts = 2,
206 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800207 { .name = MT_CLS_PANASONIC,
208 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
209 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800210 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
211 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
212 MT_QUIRK_VALID_IS_INRANGE |
213 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
214 .maxcontacts = 2
215 },
216 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
217 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Xianhan Yu58ad34b2012-10-29 23:04:37 +0800218 MT_QUIRK_SLOT_IS_CONTACTNUMBER
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800219 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100220
Henrik Rydberg77723e32012-09-07 19:37:40 +0200221 { .name = MT_CLS_FLATFROG,
222 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
223 MT_QUIRK_NO_AREA,
224 .sn_move = 2048,
225 .maxcontacts = 40,
226 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100227 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100228};
229
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100230static ssize_t mt_show_quirks(struct device *dev,
231 struct device_attribute *attr,
232 char *buf)
233{
234 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
235 struct mt_device *td = hid_get_drvdata(hdev);
236
237 return sprintf(buf, "%u\n", td->mtclass.quirks);
238}
239
240static ssize_t mt_set_quirks(struct device *dev,
241 struct device_attribute *attr,
242 const char *buf, size_t count)
243{
244 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
245 struct mt_device *td = hid_get_drvdata(hdev);
246
247 unsigned long val;
248
249 if (kstrtoul(buf, 0, &val))
250 return -EINVAL;
251
252 td->mtclass.quirks = val;
253
254 return count;
255}
256
257static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
258
259static struct attribute *sysfs_attrs[] = {
260 &dev_attr_quirks.attr,
261 NULL
262};
263
264static struct attribute_group mt_attribute_group = {
265 .attrs = sysfs_attrs
266};
267
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100268static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100269 struct hid_field *field, struct hid_usage *usage)
270{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100271 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200272 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100273
274 switch (usage->hid) {
275 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100276 td->inputmode = field->report->id;
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200277 td->inputmode_index = 0; /* has to be updated below */
278
279 for (i=0; i < field->maxusage; i++) {
280 if (field->usage[i].hid == usage->hid) {
281 td->inputmode_index = i;
282 break;
283 }
284 }
285
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100286 break;
287 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100288 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100289 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100290 if (!td->maxcontacts &&
291 field->logical_maximum <= MT_MAX_MAXCONTACT)
292 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100293 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100294 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100295 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100296
297 break;
Benjamin Tissoires1b42fc42012-11-14 16:59:25 +0100298 case 0xff0000c5:
299 if (field->report_count == 256 && field->report_size == 8) {
300 /* Win 8 devices need special quirks */
301 __s32 *quirks = &td->mtclass.quirks;
302 *quirks |= MT_QUIRK_ALWAYS_VALID;
303 *quirks |= MT_QUIRK_IGNORE_DUPLICATES;
304 *quirks |= MT_QUIRK_HOVERING;
305 *quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
306 *quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
307 *quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
308 }
309 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100310 }
311}
312
313static void set_abs(struct input_dev *input, unsigned int code,
314 struct hid_field *field, int snratio)
315{
316 int fmin = field->logical_minimum;
317 int fmax = field->logical_maximum;
318 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
319 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100320 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100321}
322
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200323static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100324 struct hid_input *hi)
325{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200326 struct mt_fields *f = td->fields;
327
328 if (f->length >= HID_MAX_FIELDS)
329 return;
330
331 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100332}
333
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100334static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
335 struct hid_field *field, struct hid_usage *usage,
336 unsigned long **bit, int *max)
337{
338 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100339 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100340 int code;
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100341 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100342
Jeff Brown658d4aed592011-08-15 16:44:28 -0700343 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800344 * We need to ignore fields that belong to other collections
345 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700346 if (field->application == HID_DG_TOUCHSCREEN)
Henrik Rydberg76f59022012-09-01 20:11:34 +0200347 td->mt_flags |= INPUT_MT_DIRECT;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100348 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700349 return 0;
350
Henrik Rydberg76f59022012-09-01 20:11:34 +0200351 /*
352 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100353 */
354 if (field->application == HID_DG_TOUCHPAD ||
Henrik Rydberg76f59022012-09-01 20:11:34 +0200355 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
356 td->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100357
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100358 /* eGalax devices provide a Digitizer.Stylus input which overrides
359 * the correct Digitizers.Finger X/Y ranges.
360 * Let's just ignore this input. */
361 if (field->physical == HID_DG_STYLUS)
362 return -1;
363
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100364 if (usage->usage_index)
365 prev_usage = &field->usage[usage->usage_index - 1];
366
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100367 switch (usage->hid & HID_USAGE_PAGE) {
368
369 case HID_UP_GENDESK:
370 switch (usage->hid) {
371 case HID_GD_X:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100372 if (prev_usage && (prev_usage->hid == usage->hid)) {
373 hid_map_usage(hi, usage, bit, max,
374 EV_ABS, ABS_MT_TOOL_X);
375 set_abs(hi->input, ABS_MT_TOOL_X, field,
376 cls->sn_move);
377 } else {
378 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100379 EV_ABS, ABS_MT_POSITION_X);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100380 set_abs(hi->input, ABS_MT_POSITION_X, field,
381 cls->sn_move);
382 }
383
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200384 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100385 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100386 return 1;
387 case HID_GD_Y:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100388 if (prev_usage && (prev_usage->hid == usage->hid)) {
389 hid_map_usage(hi, usage, bit, max,
390 EV_ABS, ABS_MT_TOOL_Y);
391 set_abs(hi->input, ABS_MT_TOOL_Y, field,
392 cls->sn_move);
393 } else {
394 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100395 EV_ABS, ABS_MT_POSITION_Y);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100396 set_abs(hi->input, ABS_MT_POSITION_Y, field,
397 cls->sn_move);
398 }
399
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200400 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100401 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100402 return 1;
403 }
404 return 0;
405
406 case HID_UP_DIGITIZER:
407 switch (usage->hid) {
408 case HID_DG_INRANGE:
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100409 if (cls->quirks & MT_QUIRK_HOVERING) {
410 hid_map_usage(hi, usage, bit, max,
411 EV_ABS, ABS_MT_DISTANCE);
412 input_set_abs_params(hi->input,
413 ABS_MT_DISTANCE, 0, 1, 0, 0);
414 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200415 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100416 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100417 return 1;
418 case HID_DG_CONFIDENCE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200419 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100420 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100421 return 1;
422 case HID_DG_TIPSWITCH:
423 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
424 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200425 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100426 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100427 return 1;
428 case HID_DG_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200429 mt_store_field(usage, td, hi);
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200430 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100431 td->touches_by_report++;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100432 td->mt_report_id = field->report->id;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100433 return 1;
434 case HID_DG_WIDTH:
435 hid_map_usage(hi, usage, bit, max,
436 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200437 if (!(cls->quirks & MT_QUIRK_NO_AREA))
438 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
439 cls->sn_width);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200440 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100441 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100442 return 1;
443 case HID_DG_HEIGHT:
444 hid_map_usage(hi, usage, bit, max,
445 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200446 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
447 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
448 cls->sn_height);
449 input_set_abs_params(hi->input,
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100450 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200451 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200452 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100453 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100454 return 1;
455 case HID_DG_TIPPRESSURE:
456 hid_map_usage(hi, usage, bit, max,
457 EV_ABS, ABS_MT_PRESSURE);
458 set_abs(hi->input, ABS_MT_PRESSURE, field,
459 cls->sn_pressure);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200460 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100461 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100462 return 1;
463 case HID_DG_CONTACTCOUNT:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100464 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100465 return 1;
466 case HID_DG_CONTACTMAX:
467 /* we don't set td->last_slot_field as contactcount and
468 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100469 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100470 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100471 case HID_DG_TOUCH:
472 /* Legacy devices use TIPSWITCH and not TOUCH.
473 * Let's just ignore this field. */
474 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100475 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100476 /* let hid-input decide for the others */
477 return 0;
478
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100479 case HID_UP_BUTTON:
480 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
481 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
482 input_set_capability(hi->input, EV_KEY, code);
483 return 1;
484
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100485 case 0xff000000:
486 /* we do not want to map these: no input-oriented meaning */
487 return -1;
488 }
489
490 return 0;
491}
492
493static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
494 struct hid_field *field, struct hid_usage *usage,
495 unsigned long **bit, int *max)
496{
497 if (usage->type == EV_KEY || usage->type == EV_ABS)
498 set_bit(usage->type, hi->input->evbit);
499
500 return -1;
501}
502
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200503static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100504{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100505 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100506
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100507 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
508 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100509
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100510 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100511 return cypress_compute_slot(td);
512
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100513 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
514 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100515
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200516 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
517 return td->curdata.contactid - 1;
518
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200519 return input_mt_get_slot_by_key(input, td->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100520}
521
522/*
523 * this function is called when a whole contact has been processed,
524 * so that it can assign it to a slot and store the data there
525 */
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200526static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100527{
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100528 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200529 int slotnum = mt_compute_slot(td, input);
530 struct mt_slot *s = &td->curdata;
Benjamin Tissoires28728392012-11-14 16:59:23 +0100531 struct input_mt *mt = input->mt;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100532
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200533 if (slotnum < 0 || slotnum >= td->maxcontacts)
534 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100535
Benjamin Tissoires28728392012-11-14 16:59:23 +0100536 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
537 struct input_mt_slot *slot = &mt->slots[slotnum];
538 if (input_mt_is_active(slot) &&
539 input_mt_is_used(mt, slot))
540 return;
541 }
542
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200543 input_mt_slot(input, slotnum);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100544 input_mt_report_slot_state(input, MT_TOOL_FINGER,
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100545 s->touch_state || s->inrange_state);
546 if (s->touch_state || s->inrange_state) {
547 /* this finger is in proximity of the sensor */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100548 int wide = (s->w > s->h);
549 /* divided by two to match visual scale of touch */
550 int major = max(s->w, s->h) >> 1;
551 int minor = min(s->w, s->h) >> 1;
552
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100553 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
554 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100555 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
556 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100557 input_event(input, EV_ABS, ABS_MT_DISTANCE,
558 !s->touch_state);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100559 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100560 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100561 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
562 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100563 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100564 }
565
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200566 td->num_received++;
567}
568
569/*
570 * this function is called when a whole packet has been received and processed,
571 * so that it can decide what to send to the input layer.
572 */
573static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
574{
Henrik Rydberg76f59022012-09-01 20:11:34 +0200575 input_mt_sync_frame(input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100576 input_sync(input);
577 td->num_received = 0;
578}
579
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100580static int mt_event(struct hid_device *hid, struct hid_field *field,
581 struct hid_usage *usage, __s32 value)
582{
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100583 /* we will handle the hidinput part later, now remains hiddev */
584 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
585 hid->hiddev_hid_event(hid, field, usage, value);
586
587 return 1;
588}
589
590static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
591 struct hid_usage *usage, __s32 value)
592{
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100593 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100594 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100595
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200596 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100597 switch (usage->hid) {
598 case HID_DG_INRANGE:
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100599 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100600 td->curvalid = value;
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100601 if (quirks & MT_QUIRK_HOVERING)
602 td->curdata.inrange_state = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100603 break;
604 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100605 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
606 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100607 td->curdata.touch_state = value;
608 break;
609 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100610 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
611 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100612 break;
613 case HID_DG_CONTACTID:
614 td->curdata.contactid = value;
615 break;
616 case HID_DG_TIPPRESSURE:
617 td->curdata.p = value;
618 break;
619 case HID_GD_X:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100620 if (usage->code == ABS_MT_TOOL_X)
621 td->curdata.cx = value;
622 else
623 td->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100624 break;
625 case HID_GD_Y:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100626 if (usage->code == ABS_MT_TOOL_Y)
627 td->curdata.cy = value;
628 else
629 td->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100630 break;
631 case HID_DG_WIDTH:
632 td->curdata.w = value;
633 break;
634 case HID_DG_HEIGHT:
635 td->curdata.h = value;
636 break;
637 case HID_DG_CONTACTCOUNT:
638 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100639 * Includes multi-packet support where subsequent
640 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100641 */
642 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100643 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100644 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100645 case HID_DG_TOUCH:
646 /* do nothing */
647 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100648
649 default:
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100650 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100651 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100652
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100653 if (usage->usage_index + 1 == field->report_count) {
654 /* we only take into account the last report. */
655 if (usage->hid == td->last_slot_field)
656 mt_complete_slot(td, field->hidinput->input);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100657
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100658 if (field->index == td->last_field_index
659 && td->num_received >= td->num_expected)
660 mt_sync_frame(td, field->hidinput->input);
661 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100662
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100663 }
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100664}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100665
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100666static void mt_report(struct hid_device *hid, struct hid_report *report)
667{
668 struct mt_device *td = hid_get_drvdata(hid);
669 struct hid_field *field;
670 unsigned count;
671 int r, n;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100672
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100673 if (report->id != td->mt_report_id)
674 return;
675
676 if (!(hid->claimed & HID_CLAIMED_INPUT))
677 return;
678
679 for (r = 0; r < report->maxfield; r++) {
680 field = report->field[r];
681 count = field->report_count;
682
683 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
684 continue;
685
686 for (n = 0; n < count; n++)
687 mt_process_mt_event(hid, field, &field->usage[n],
688 field->value[n]);
689 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100690}
691
692static void mt_set_input_mode(struct hid_device *hdev)
693{
694 struct mt_device *td = hid_get_drvdata(hdev);
695 struct hid_report *r;
696 struct hid_report_enum *re;
697
698 if (td->inputmode < 0)
699 return;
700
701 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
702 r = re->report_id_hash[td->inputmode];
703 if (r) {
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200704 r->field[0]->value[td->inputmode_index] = 0x02;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100705 usbhid_submit_report(hdev, r, USB_DIR_OUT);
706 }
707}
708
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100709static void mt_set_maxcontacts(struct hid_device *hdev)
710{
711 struct mt_device *td = hid_get_drvdata(hdev);
712 struct hid_report *r;
713 struct hid_report_enum *re;
714 int fieldmax, max;
715
716 if (td->maxcontact_report_id < 0)
717 return;
718
719 if (!td->mtclass.maxcontacts)
720 return;
721
722 re = &hdev->report_enum[HID_FEATURE_REPORT];
723 r = re->report_id_hash[td->maxcontact_report_id];
724 if (r) {
725 max = td->mtclass.maxcontacts;
726 fieldmax = r->field[0]->logical_maximum;
727 max = min(fieldmax, max);
728 if (r->field[0]->value[0] != max) {
729 r->field[0]->value[0] = max;
730 usbhid_submit_report(hdev, r, USB_DIR_OUT);
731 }
732 }
733}
734
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200735static void mt_post_parse_default_settings(struct mt_device *td)
736{
737 __s32 quirks = td->mtclass.quirks;
738
739 /* unknown serial device needs special quirks */
740 if (td->touches_by_report == 1) {
741 quirks |= MT_QUIRK_ALWAYS_VALID;
742 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
743 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
744 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
745 }
746
747 td->mtclass.quirks = quirks;
748}
749
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200750static void mt_post_parse(struct mt_device *td)
751{
752 struct mt_fields *f = td->fields;
753
754 if (td->touches_by_report > 0) {
755 int field_count_per_touch = f->length / td->touches_by_report;
756 td->last_slot_field = f->usages[field_count_per_touch - 1];
757 }
758}
759
Henrik Rydberg76f59022012-09-01 20:11:34 +0200760static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
761
762{
763 struct mt_device *td = hid_get_drvdata(hdev);
764 struct mt_class *cls = &td->mtclass;
765 struct input_dev *input = hi->input;
766
767 /* Only initialize slots for MT input devices */
768 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
769 return;
770
771 if (!td->maxcontacts)
772 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
773
774 mt_post_parse(td);
775 if (td->serial_maybe)
776 mt_post_parse_default_settings(td);
777
778 if (cls->is_indirect)
779 td->mt_flags |= INPUT_MT_POINTER;
780
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200781 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
782 td->mt_flags |= INPUT_MT_DROP_UNUSED;
783
Henrik Rydberg76f59022012-09-01 20:11:34 +0200784 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
785
786 td->mt_flags = 0;
787}
788
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100789static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
790{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100791 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100792 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100793 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
794
Henrik Rydberg94b54852012-08-08 21:45:50 +0200795 for (i = 0; mt_classes[i].name ; i++) {
796 if (id->driver_data == mt_classes[i].name) {
797 mtclass = &(mt_classes[i]);
798 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100799 }
800 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100801
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100802 /* This allows the driver to correctly support devices
803 * that emit events over several HID messages.
804 */
805 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100806
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100807 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100808 if (!td) {
809 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
810 return -ENOMEM;
811 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100812 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100813 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100814 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100815 hid_set_drvdata(hdev, td);
816
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200817 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
818 if (!td->fields) {
819 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
820 ret = -ENOMEM;
821 goto fail;
822 }
823
Henrik Rydberg76f59022012-09-01 20:11:34 +0200824 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
825 td->serial_maybe = true;
826
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100827 ret = hid_parse(hdev);
828 if (ret != 0)
829 goto fail;
830
831 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100832 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100833 goto fail;
834
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100835 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
836
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100837 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100838 mt_set_input_mode(hdev);
839
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200840 kfree(td->fields);
841 td->fields = NULL;
842
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100843 return 0;
844
845fail:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200846 kfree(td->fields);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100847 kfree(td);
848 return ret;
849}
850
851#ifdef CONFIG_PM
852static int mt_reset_resume(struct hid_device *hdev)
853{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100854 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100855 mt_set_input_mode(hdev);
856 return 0;
857}
Scott Liudfeefd12012-08-15 17:21:55 +0800858
859static int mt_resume(struct hid_device *hdev)
860{
861 struct usb_interface *intf;
862 struct usb_host_interface *interface;
863 struct usb_device *dev;
864
865 if (hdev->bus != BUS_USB)
866 return 0;
867
868 intf = to_usb_interface(hdev->dev.parent);
869 interface = intf->cur_altsetting;
870 dev = hid_to_usb_dev(hdev);
871
872 /* Some Elan legacy devices require SET_IDLE to be set on resume.
873 * It should be safe to send it to other devices too.
874 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
875
876 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
877 HID_REQ_SET_IDLE,
878 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
879 0, interface->desc.bInterfaceNumber,
880 NULL, 0, USB_CTRL_SET_TIMEOUT);
881
882 return 0;
883}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100884#endif
885
886static void mt_remove(struct hid_device *hdev)
887{
888 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100889 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100890 hid_hw_stop(hdev);
891 kfree(td);
892 hid_set_drvdata(hdev, NULL);
893}
894
895static const struct hid_device_id mt_devices[] = {
896
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100897 /* 3M panels */
898 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200899 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100900 USB_DEVICE_ID_3M1968) },
901 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200902 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100903 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100904 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200905 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100906 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100907
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200908 /* ActionStar panels */
909 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200910 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200911 USB_DEVICE_ID_ACTIONSTAR_1011) },
912
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100913 /* Atmel panels */
914 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200915 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100916 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100917 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200918 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100919 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100920
Jiri Kosina9ed32692012-04-20 12:15:44 +0200921 /* Baanto multitouch devices */
922 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina16b79bb2012-05-05 23:32:54 +0200923 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +0200924 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100925 /* Cando panels */
926 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200927 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100928 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
929 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200930 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100931 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
932 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200933 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100934 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
935 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200936 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100937 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
938
Austin Zhang942fd422011-05-28 02:03:47 +0800939 /* Chunghwa Telecom touch panels */
940 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200941 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +0800942 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
943
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200944 /* CVTouch panels */
945 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200946 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200947 USB_DEVICE_ID_CVTOUCH_SCREEN) },
948
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100949 /* Cypress panel */
950 { .driver_data = MT_CLS_CYPRESS,
951 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
952 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
953
Benjamin Tissoires22408282011-05-20 15:59:34 +0200954 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100955 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200956 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100957 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
958 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200959 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100960 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200961
962 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100963 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200964 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100965 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100966 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200967 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100968 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
969 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200970 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100971 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
972 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200973 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100974 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100975 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200976 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100977 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100978 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200979 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100980 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100981 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200982 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100983 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100984 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200985 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100986 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100987 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200988 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100989 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100990 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200991 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100992 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
993 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200994 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100995 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100996 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200997 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100998 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
999 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001000 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +02001001 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1002 { .driver_data = MT_CLS_EGALAX_SERIAL,
1003 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001004 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Jiri Kosina3d771042012-08-15 10:01:01 +02001005 { .driver_data = MT_CLS_EGALAX,
1006 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1007 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1008 { .driver_data = MT_CLS_EGALAX,
1009 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1010 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1011 { .driver_data = MT_CLS_EGALAX,
1012 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1013 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001014
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +02001015 /* Elo TouchSystems IntelliTouch Plus panel */
1016 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001017 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +02001018 USB_DEVICE_ID_ELO_TS2515) },
1019
Henrik Rydberg77723e32012-09-07 19:37:40 +02001020 /* Flatfrog Panels */
1021 { .driver_data = MT_CLS_FLATFROG,
1022 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1023 USB_DEVICE_ID_MULTITOUCH_3200) },
1024
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001025 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001026 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001027 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001028 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001029 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1030 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1031 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001032
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001033 /* Gametel game controller */
1034 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001035 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001036 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1037
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001038 /* GoodTouch panels */
1039 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001040 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001041 USB_DEVICE_ID_GOODTOUCH_000f) },
1042
Benjamin Tissoires54580362011-11-29 13:13:12 +01001043 /* Hanvon panels */
1044 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001045 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001046 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1047
Stephane Chattya062cc52011-09-17 22:27:30 +02001048 /* Ideacom panel */
1049 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001050 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Stephane Chattya062cc52011-09-17 22:27:30 +02001051 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001052 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001053 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001054 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +02001055
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001056 /* Ilitek dual touch panel */
1057 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001058 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001059 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1060
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001061 /* IRTOUCH panels */
1062 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001063 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001064 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1065
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001066 /* LG Display panels */
1067 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001068 MT_USB_DEVICE(USB_VENDOR_ID_LG,
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001069 USB_DEVICE_ID_LG_MULTITOUCH) },
1070
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001071 /* Lumio panels */
1072 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001073 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001074 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001075 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001076 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001077 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001078
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001079 /* MosArt panels */
1080 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001081 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001082 USB_DEVICE_ID_ASUS_T91MT)},
1083 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001084 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001085 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1086 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001087 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001088 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1089
Denis Kovalev2258e862012-02-14 00:50:33 -08001090 /* Panasonic panels */
1091 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001092 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001093 USB_DEVICE_ID_PANABOARD_UBT780) },
1094 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001095 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001096 USB_DEVICE_ID_PANABOARD_UBT880) },
1097
Austin Hendrix4db703e2012-06-04 15:27:51 -07001098 /* Novatek Panel */
1099 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina4380d812012-06-06 16:28:33 +02001100 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001101 USB_DEVICE_ID_NOVATEK_PCT) },
1102
John Sung6ab3a9a2011-04-21 16:21:52 +02001103 /* PenMount panels */
1104 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001105 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
John Sung6ab3a9a2011-04-21 16:21:52 +02001106 USB_DEVICE_ID_PENMOUNT_PCI) },
1107
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001108 /* PixArt optical touch screen */
1109 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001110 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001111 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1112 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001113 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001114 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1115 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001116 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001117 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1118
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001119 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001120 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001121 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001122 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001123 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001124 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001125 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1126
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001127 /* Quanta-based panels */
1128 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001129 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001130 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1131 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001132 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001133 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1134 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001135 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001136 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1137
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001138 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001139 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001140 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001141 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001142 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001143 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001144 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001145 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001146 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001147 USB_DEVICE_ID_MTP_SITRONIX)},
1148
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001149 /* TopSeed panels */
1150 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001151 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001152 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1153
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001154 /* Touch International panels */
1155 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001156 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001157 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1158
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001159 /* Unitec panels */
1160 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001161 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001162 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1163 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001164 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001165 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +08001166 /* XAT */
1167 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001168 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001169 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001170
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001171 /* Xiroku */
1172 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001173 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001174 USB_DEVICE_ID_XIROKU_SPX) },
1175 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001176 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001177 USB_DEVICE_ID_XIROKU_MPX) },
1178 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001179 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001180 USB_DEVICE_ID_XIROKU_CSR) },
1181 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001182 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001183 USB_DEVICE_ID_XIROKU_SPX1) },
1184 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001185 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001186 USB_DEVICE_ID_XIROKU_MPX1) },
1187 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001188 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001189 USB_DEVICE_ID_XIROKU_CSR1) },
1190 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001191 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001192 USB_DEVICE_ID_XIROKU_SPX2) },
1193 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001194 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001195 USB_DEVICE_ID_XIROKU_MPX2) },
1196 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001197 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001198 USB_DEVICE_ID_XIROKU_CSR2) },
1199
Benjamin Tissoires82d06982012-06-19 14:39:54 +02001200 /* Zytronic panels */
1201 { .driver_data = MT_CLS_SERIAL,
1202 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1203 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1204
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001205 /* Generic MT device */
1206 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001207 { }
1208};
1209MODULE_DEVICE_TABLE(hid, mt_devices);
1210
1211static const struct hid_usage_id mt_grabbed_usages[] = {
1212 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1213 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1214};
1215
1216static struct hid_driver mt_driver = {
1217 .name = "hid-multitouch",
1218 .id_table = mt_devices,
1219 .probe = mt_probe,
1220 .remove = mt_remove,
1221 .input_mapping = mt_input_mapping,
1222 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001223 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001224 .feature_mapping = mt_feature_mapping,
1225 .usage_table = mt_grabbed_usages,
1226 .event = mt_event,
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001227 .report = mt_report,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001228#ifdef CONFIG_PM
1229 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001230 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001231#endif
1232};
1233
1234static int __init mt_init(void)
1235{
1236 return hid_register_driver(&mt_driver);
1237}
1238
1239static void __exit mt_exit(void)
1240{
1241 hid_unregister_driver(&mt_driver);
1242}
1243
1244module_init(mt_init);
1245module_exit(mt_exit);