blob: 87690e2726ac3318963e65b3bf65066ef4c25543 [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 Tissoiresc2517f62013-01-31 17:22:25 +010057#define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010058
59struct mt_slot {
Benjamin Tissoires349fd672012-11-14 16:59:19 +010060 __s32 x, y, cx, cy, p, w, h;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010061 __s32 contactid; /* the device ContactID assigned to this slot */
62 bool touch_state; /* is the touch valid? */
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +010063 bool inrange_state; /* is the finger in proximity of the sensor? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010064};
65
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010066struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010067 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010068 __s32 quirks;
69 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010070 __s32 sn_width; /* Signal/noise ratio for width events */
71 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010072 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
73 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +010074 bool is_indirect; /* true for touchpads */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010075};
76
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020077struct mt_fields {
78 unsigned usages[HID_MAX_FIELDS];
79 unsigned int length;
80};
81
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010082struct mt_device {
83 struct mt_slot curdata; /* placeholder of incoming data */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +010084 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020085 struct mt_fields *fields; /* temporary placeholder for storing the
86 multitouch fields */
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +010087 __s32 *contactcount; /* contact count value in the report */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010088 unsigned last_field_index; /* last field index of the report */
89 unsigned last_slot_field; /* the last field of a slot */
Benjamin Tissoires55978fa2013-01-31 17:22:24 +010090 unsigned mt_report_id; /* the report ID of the multitouch device */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010091 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires4aceed32012-06-19 14:39:52 +020092 __s8 inputmode_index; /* InputMode HID feature index in the report */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010093 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
94 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010095 __u8 num_received; /* how many contacts we received */
96 __u8 num_expected; /* expected last contact index */
97 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010098 __u8 touches_by_report; /* how many touches are present in one report:
99 * 1 means we should use a serial protocol
100 * > 1 means hybrid (multitouch) protocol */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200101 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100102 bool curvalid; /* is the current contact valid? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200103 unsigned mt_flags; /* flags to pass to input-mt */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100104};
105
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100106/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200107#define MT_CLS_DEFAULT 0x0001
108
Stephane Chattya062cc52011-09-17 22:27:30 +0200109#define MT_CLS_SERIAL 0x0002
110#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100111#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
112#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
113#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
114#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
115#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800116#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100117#define MT_CLS_ALWAYS_TRUE 0x000a
Benjamin Tissoires22408282011-05-20 15:59:34 +0200118
119/* vendor specific classes */
120#define MT_CLS_3M 0x0101
121#define MT_CLS_CYPRESS 0x0102
122#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100123#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100124#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800125#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200126#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200127#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
128#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100129
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100130#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100131#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100132
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200133#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
134#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
135
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100136/*
137 * these device-dependent functions determine what slot corresponds
138 * to a valid contact that was just read.
139 */
140
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100141static int cypress_compute_slot(struct mt_device *td)
142{
143 if (td->curdata.contactid != 0 || td->num_received == 0)
144 return td->curdata.contactid;
145 else
146 return -1;
147}
148
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100149static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100150 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100151 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200152 { .name = MT_CLS_SERIAL,
153 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200154 { .name = MT_CLS_CONFIDENCE,
155 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100156 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
157 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
158 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200159 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
160 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
161 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100162 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100163 .quirks = MT_QUIRK_VALID_IS_INRANGE |
164 MT_QUIRK_SLOT_IS_CONTACTID,
165 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100166 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100167 .quirks = MT_QUIRK_VALID_IS_INRANGE |
168 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
169 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200170 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
171 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
172 MT_QUIRK_SLOT_IS_CONTACTID,
173 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800174 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
175 .quirks = MT_QUIRK_VALID_IS_INRANGE |
176 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100177 { .name = MT_CLS_ALWAYS_TRUE,
178 .quirks = MT_QUIRK_ALWAYS_VALID |
179 MT_QUIRK_CONTACT_CNT_ACCURATE },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200180
181 /*
182 * vendor specific classes
183 */
184 { .name = MT_CLS_3M,
185 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
186 MT_QUIRK_SLOT_IS_CONTACTID,
187 .sn_move = 2048,
188 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200189 .sn_height = 128,
190 .maxcontacts = 60,
191 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100192 { .name = MT_CLS_CYPRESS,
193 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
194 MT_QUIRK_CYPRESS,
195 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100196 { .name = MT_CLS_EGALAX,
197 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100198 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100199 .sn_move = 4096,
200 .sn_pressure = 32,
201 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100202 { .name = MT_CLS_EGALAX_SERIAL,
203 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
204 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100205 .sn_move = 4096,
206 .sn_pressure = 32,
207 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100208 { .name = MT_CLS_TOPSEED,
209 .quirks = MT_QUIRK_ALWAYS_VALID,
210 .is_indirect = true,
211 .maxcontacts = 2,
212 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800213 { .name = MT_CLS_PANASONIC,
214 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
215 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800216 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
217 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
218 MT_QUIRK_VALID_IS_INRANGE |
219 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
220 .maxcontacts = 2
221 },
222 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
223 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Xianhan Yu58ad34b2012-10-29 23:04:37 +0800224 MT_QUIRK_SLOT_IS_CONTACTNUMBER
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800225 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100226
Henrik Rydberg77723e32012-09-07 19:37:40 +0200227 { .name = MT_CLS_FLATFROG,
228 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
229 MT_QUIRK_NO_AREA,
230 .sn_move = 2048,
231 .maxcontacts = 40,
232 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100233 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100234};
235
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100236static ssize_t mt_show_quirks(struct device *dev,
237 struct device_attribute *attr,
238 char *buf)
239{
240 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
241 struct mt_device *td = hid_get_drvdata(hdev);
242
243 return sprintf(buf, "%u\n", td->mtclass.quirks);
244}
245
246static ssize_t mt_set_quirks(struct device *dev,
247 struct device_attribute *attr,
248 const char *buf, size_t count)
249{
250 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
251 struct mt_device *td = hid_get_drvdata(hdev);
252
253 unsigned long val;
254
255 if (kstrtoul(buf, 0, &val))
256 return -EINVAL;
257
258 td->mtclass.quirks = val;
259
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100260 if (!td->contactcount)
261 td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
262
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100263 return count;
264}
265
266static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
267
268static struct attribute *sysfs_attrs[] = {
269 &dev_attr_quirks.attr,
270 NULL
271};
272
273static struct attribute_group mt_attribute_group = {
274 .attrs = sysfs_attrs
275};
276
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100277static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100278 struct hid_field *field, struct hid_usage *usage)
279{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100280 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200281 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100282
283 switch (usage->hid) {
284 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100285 td->inputmode = field->report->id;
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200286 td->inputmode_index = 0; /* has to be updated below */
287
288 for (i=0; i < field->maxusage; i++) {
289 if (field->usage[i].hid == usage->hid) {
290 td->inputmode_index = i;
291 break;
292 }
293 }
294
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100295 break;
296 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100297 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100298 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100299 if (!td->maxcontacts &&
300 field->logical_maximum <= MT_MAX_MAXCONTACT)
301 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100302 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100303 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100304 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100305
306 break;
Benjamin Tissoires1b42fc42012-11-14 16:59:25 +0100307 case 0xff0000c5:
308 if (field->report_count == 256 && field->report_size == 8) {
309 /* Win 8 devices need special quirks */
310 __s32 *quirks = &td->mtclass.quirks;
311 *quirks |= MT_QUIRK_ALWAYS_VALID;
312 *quirks |= MT_QUIRK_IGNORE_DUPLICATES;
313 *quirks |= MT_QUIRK_HOVERING;
314 *quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
315 *quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
316 *quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
317 }
318 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100319 }
320}
321
322static void set_abs(struct input_dev *input, unsigned int code,
323 struct hid_field *field, int snratio)
324{
325 int fmin = field->logical_minimum;
326 int fmax = field->logical_maximum;
327 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
328 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100329 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100330}
331
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200332static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100333 struct hid_input *hi)
334{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200335 struct mt_fields *f = td->fields;
336
337 if (f->length >= HID_MAX_FIELDS)
338 return;
339
340 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100341}
342
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100343static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
344 struct hid_field *field, struct hid_usage *usage,
345 unsigned long **bit, int *max)
346{
347 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100348 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100349 int code;
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100350 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100351
Jeff Brown658d4aed592011-08-15 16:44:28 -0700352 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800353 * We need to ignore fields that belong to other collections
354 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700355 if (field->application == HID_DG_TOUCHSCREEN)
Henrik Rydberg76f59022012-09-01 20:11:34 +0200356 td->mt_flags |= INPUT_MT_DIRECT;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100357 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700358 return 0;
359
Henrik Rydberg76f59022012-09-01 20:11:34 +0200360 /*
361 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100362 */
363 if (field->application == HID_DG_TOUCHPAD ||
Henrik Rydberg76f59022012-09-01 20:11:34 +0200364 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
365 td->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100366
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100367 /* eGalax devices provide a Digitizer.Stylus input which overrides
368 * the correct Digitizers.Finger X/Y ranges.
369 * Let's just ignore this input. */
370 if (field->physical == HID_DG_STYLUS)
371 return -1;
372
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100373 if (usage->usage_index)
374 prev_usage = &field->usage[usage->usage_index - 1];
375
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100376 switch (usage->hid & HID_USAGE_PAGE) {
377
378 case HID_UP_GENDESK:
379 switch (usage->hid) {
380 case HID_GD_X:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100381 if (prev_usage && (prev_usage->hid == usage->hid)) {
382 hid_map_usage(hi, usage, bit, max,
383 EV_ABS, ABS_MT_TOOL_X);
384 set_abs(hi->input, ABS_MT_TOOL_X, field,
385 cls->sn_move);
386 } else {
387 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100388 EV_ABS, ABS_MT_POSITION_X);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100389 set_abs(hi->input, ABS_MT_POSITION_X, field,
390 cls->sn_move);
391 }
392
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200393 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100394 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100395 return 1;
396 case HID_GD_Y:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100397 if (prev_usage && (prev_usage->hid == usage->hid)) {
398 hid_map_usage(hi, usage, bit, max,
399 EV_ABS, ABS_MT_TOOL_Y);
400 set_abs(hi->input, ABS_MT_TOOL_Y, field,
401 cls->sn_move);
402 } else {
403 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100404 EV_ABS, ABS_MT_POSITION_Y);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100405 set_abs(hi->input, ABS_MT_POSITION_Y, field,
406 cls->sn_move);
407 }
408
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200409 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100410 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100411 return 1;
412 }
413 return 0;
414
415 case HID_UP_DIGITIZER:
416 switch (usage->hid) {
417 case HID_DG_INRANGE:
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100418 if (cls->quirks & MT_QUIRK_HOVERING) {
419 hid_map_usage(hi, usage, bit, max,
420 EV_ABS, ABS_MT_DISTANCE);
421 input_set_abs_params(hi->input,
422 ABS_MT_DISTANCE, 0, 1, 0, 0);
423 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200424 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100425 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100426 return 1;
427 case HID_DG_CONFIDENCE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200428 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100429 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100430 return 1;
431 case HID_DG_TIPSWITCH:
432 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
433 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200434 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100435 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100436 return 1;
437 case HID_DG_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200438 mt_store_field(usage, td, hi);
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200439 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100440 td->touches_by_report++;
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100441 td->mt_report_id = field->report->id;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100442 return 1;
443 case HID_DG_WIDTH:
444 hid_map_usage(hi, usage, bit, max,
445 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200446 if (!(cls->quirks & MT_QUIRK_NO_AREA))
447 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
448 cls->sn_width);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200449 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100450 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100451 return 1;
452 case HID_DG_HEIGHT:
453 hid_map_usage(hi, usage, bit, max,
454 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200455 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
456 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
457 cls->sn_height);
458 input_set_abs_params(hi->input,
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100459 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200460 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200461 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100462 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100463 return 1;
464 case HID_DG_TIPPRESSURE:
465 hid_map_usage(hi, usage, bit, max,
466 EV_ABS, ABS_MT_PRESSURE);
467 set_abs(hi->input, ABS_MT_PRESSURE, field,
468 cls->sn_pressure);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200469 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100470 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100471 return 1;
472 case HID_DG_CONTACTCOUNT:
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100473 td->contactcount = field->value + usage->usage_index;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100474 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100475 return 1;
476 case HID_DG_CONTACTMAX:
477 /* we don't set td->last_slot_field as contactcount and
478 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100479 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100480 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100481 case HID_DG_TOUCH:
482 /* Legacy devices use TIPSWITCH and not TOUCH.
483 * Let's just ignore this field. */
484 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100485 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100486 /* let hid-input decide for the others */
487 return 0;
488
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100489 case HID_UP_BUTTON:
490 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
491 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
492 input_set_capability(hi->input, EV_KEY, code);
493 return 1;
494
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100495 case 0xff000000:
496 /* we do not want to map these: no input-oriented meaning */
497 return -1;
498 }
499
500 return 0;
501}
502
503static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
504 struct hid_field *field, struct hid_usage *usage,
505 unsigned long **bit, int *max)
506{
507 if (usage->type == EV_KEY || usage->type == EV_ABS)
508 set_bit(usage->type, hi->input->evbit);
509
510 return -1;
511}
512
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200513static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100514{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100515 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100516
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100517 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
518 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100519
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100520 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100521 return cypress_compute_slot(td);
522
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100523 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
524 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100525
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200526 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
527 return td->curdata.contactid - 1;
528
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200529 return input_mt_get_slot_by_key(input, td->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100530}
531
532/*
533 * this function is called when a whole contact has been processed,
534 * so that it can assign it to a slot and store the data there
535 */
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200536static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100537{
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100538 if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
539 td->num_received >= td->num_expected)
540 return;
541
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100542 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200543 int slotnum = mt_compute_slot(td, input);
544 struct mt_slot *s = &td->curdata;
Benjamin Tissoires28728392012-11-14 16:59:23 +0100545 struct input_mt *mt = input->mt;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100546
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200547 if (slotnum < 0 || slotnum >= td->maxcontacts)
548 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100549
Benjamin Tissoires28728392012-11-14 16:59:23 +0100550 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
551 struct input_mt_slot *slot = &mt->slots[slotnum];
552 if (input_mt_is_active(slot) &&
553 input_mt_is_used(mt, slot))
554 return;
555 }
556
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200557 input_mt_slot(input, slotnum);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100558 input_mt_report_slot_state(input, MT_TOOL_FINGER,
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100559 s->touch_state || s->inrange_state);
560 if (s->touch_state || s->inrange_state) {
561 /* this finger is in proximity of the sensor */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100562 int wide = (s->w > s->h);
563 /* divided by two to match visual scale of touch */
564 int major = max(s->w, s->h) >> 1;
565 int minor = min(s->w, s->h) >> 1;
566
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100567 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
568 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100569 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
570 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100571 input_event(input, EV_ABS, ABS_MT_DISTANCE,
572 !s->touch_state);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100573 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100574 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100575 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
576 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100577 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100578 }
579
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200580 td->num_received++;
581}
582
583/*
584 * this function is called when a whole packet has been received and processed,
585 * so that it can decide what to send to the input layer.
586 */
587static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
588{
Henrik Rydberg76f59022012-09-01 20:11:34 +0200589 input_mt_sync_frame(input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100590 input_sync(input);
591 td->num_received = 0;
592}
593
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100594static int mt_event(struct hid_device *hid, struct hid_field *field,
595 struct hid_usage *usage, __s32 value)
596{
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100597 /* we will handle the hidinput part later, 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_process_mt_event(struct hid_device *hid, struct hid_field *field,
605 struct hid_usage *usage, __s32 value)
606{
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100607 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100608 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100609
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200610 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100611 switch (usage->hid) {
612 case HID_DG_INRANGE:
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100613 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100614 td->curvalid = value;
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100615 if (quirks & MT_QUIRK_HOVERING)
616 td->curdata.inrange_state = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100617 break;
618 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100619 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
620 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100621 td->curdata.touch_state = value;
622 break;
623 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100624 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
625 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100626 break;
627 case HID_DG_CONTACTID:
628 td->curdata.contactid = value;
629 break;
630 case HID_DG_TIPPRESSURE:
631 td->curdata.p = value;
632 break;
633 case HID_GD_X:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100634 if (usage->code == ABS_MT_TOOL_X)
635 td->curdata.cx = value;
636 else
637 td->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100638 break;
639 case HID_GD_Y:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100640 if (usage->code == ABS_MT_TOOL_Y)
641 td->curdata.cy = value;
642 else
643 td->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100644 break;
645 case HID_DG_WIDTH:
646 td->curdata.w = value;
647 break;
648 case HID_DG_HEIGHT:
649 td->curdata.h = value;
650 break;
651 case HID_DG_CONTACTCOUNT:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100652 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100653 case HID_DG_TOUCH:
654 /* do nothing */
655 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100656
657 default:
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100658 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100659 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100660
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100661 if (usage->usage_index + 1 == field->report_count) {
662 /* we only take into account the last report. */
663 if (usage->hid == td->last_slot_field)
664 mt_complete_slot(td, field->hidinput->input);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100665
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100666 if (field->index == td->last_field_index
667 && td->num_received >= td->num_expected)
668 mt_sync_frame(td, field->hidinput->input);
669 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100670
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100671 }
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100672}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100673
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100674static void mt_report(struct hid_device *hid, struct hid_report *report)
675{
676 struct mt_device *td = hid_get_drvdata(hid);
677 struct hid_field *field;
678 unsigned count;
679 int r, n;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100680
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100681 if (report->id != td->mt_report_id)
682 return;
683
684 if (!(hid->claimed & HID_CLAIMED_INPUT))
685 return;
686
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100687 /*
688 * Includes multi-packet support where subsequent
689 * packets are sent with zero contactcount.
690 */
691 if (td->contactcount && *td->contactcount)
692 td->num_expected = *td->contactcount;
693
Benjamin Tissoires55978fa2013-01-31 17:22:24 +0100694 for (r = 0; r < report->maxfield; r++) {
695 field = report->field[r];
696 count = field->report_count;
697
698 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
699 continue;
700
701 for (n = 0; n < count; n++)
702 mt_process_mt_event(hid, field, &field->usage[n],
703 field->value[n]);
704 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100705}
706
707static void mt_set_input_mode(struct hid_device *hdev)
708{
709 struct mt_device *td = hid_get_drvdata(hdev);
710 struct hid_report *r;
711 struct hid_report_enum *re;
712
713 if (td->inputmode < 0)
714 return;
715
716 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
717 r = re->report_id_hash[td->inputmode];
718 if (r) {
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200719 r->field[0]->value[td->inputmode_index] = 0x02;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100720 usbhid_submit_report(hdev, r, USB_DIR_OUT);
721 }
722}
723
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100724static void mt_set_maxcontacts(struct hid_device *hdev)
725{
726 struct mt_device *td = hid_get_drvdata(hdev);
727 struct hid_report *r;
728 struct hid_report_enum *re;
729 int fieldmax, max;
730
731 if (td->maxcontact_report_id < 0)
732 return;
733
734 if (!td->mtclass.maxcontacts)
735 return;
736
737 re = &hdev->report_enum[HID_FEATURE_REPORT];
738 r = re->report_id_hash[td->maxcontact_report_id];
739 if (r) {
740 max = td->mtclass.maxcontacts;
741 fieldmax = r->field[0]->logical_maximum;
742 max = min(fieldmax, max);
743 if (r->field[0]->value[0] != max) {
744 r->field[0]->value[0] = max;
745 usbhid_submit_report(hdev, r, USB_DIR_OUT);
746 }
747 }
748}
749
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200750static void mt_post_parse_default_settings(struct mt_device *td)
751{
752 __s32 quirks = td->mtclass.quirks;
753
754 /* unknown serial device needs special quirks */
755 if (td->touches_by_report == 1) {
756 quirks |= MT_QUIRK_ALWAYS_VALID;
757 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
758 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
759 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
760 }
761
762 td->mtclass.quirks = quirks;
763}
764
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200765static void mt_post_parse(struct mt_device *td)
766{
767 struct mt_fields *f = td->fields;
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100768 struct mt_class *cls = &td->mtclass;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200769
770 if (td->touches_by_report > 0) {
771 int field_count_per_touch = f->length / td->touches_by_report;
772 td->last_slot_field = f->usages[field_count_per_touch - 1];
773 }
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +0100774
775 if (!td->contactcount)
776 cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200777}
778
Henrik Rydberg76f59022012-09-01 20:11:34 +0200779static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
780
781{
782 struct mt_device *td = hid_get_drvdata(hdev);
783 struct mt_class *cls = &td->mtclass;
784 struct input_dev *input = hi->input;
785
786 /* Only initialize slots for MT input devices */
787 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
788 return;
789
790 if (!td->maxcontacts)
791 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
792
793 mt_post_parse(td);
794 if (td->serial_maybe)
795 mt_post_parse_default_settings(td);
796
797 if (cls->is_indirect)
798 td->mt_flags |= INPUT_MT_POINTER;
799
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200800 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
801 td->mt_flags |= INPUT_MT_DROP_UNUSED;
802
Henrik Rydberg76f59022012-09-01 20:11:34 +0200803 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
804
805 td->mt_flags = 0;
806}
807
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100808static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
809{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100810 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100811 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100812 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
813
Henrik Rydberg94b54852012-08-08 21:45:50 +0200814 for (i = 0; mt_classes[i].name ; i++) {
815 if (id->driver_data == mt_classes[i].name) {
816 mtclass = &(mt_classes[i]);
817 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100818 }
819 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100820
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100821 /* This allows the driver to correctly support devices
822 * that emit events over several HID messages.
823 */
824 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100825
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100826 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100827 if (!td) {
828 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
829 return -ENOMEM;
830 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100831 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100832 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100833 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100834 hid_set_drvdata(hdev, td);
835
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200836 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
837 if (!td->fields) {
838 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
839 ret = -ENOMEM;
840 goto fail;
841 }
842
Henrik Rydberg76f59022012-09-01 20:11:34 +0200843 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
844 td->serial_maybe = true;
845
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100846 ret = hid_parse(hdev);
847 if (ret != 0)
848 goto fail;
849
850 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100851 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100852 goto fail;
853
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100854 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
855
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100856 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100857 mt_set_input_mode(hdev);
858
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200859 kfree(td->fields);
860 td->fields = NULL;
861
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100862 return 0;
863
864fail:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200865 kfree(td->fields);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100866 kfree(td);
867 return ret;
868}
869
870#ifdef CONFIG_PM
871static int mt_reset_resume(struct hid_device *hdev)
872{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100873 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100874 mt_set_input_mode(hdev);
875 return 0;
876}
Scott Liudfeefd12012-08-15 17:21:55 +0800877
878static int mt_resume(struct hid_device *hdev)
879{
880 struct usb_interface *intf;
881 struct usb_host_interface *interface;
882 struct usb_device *dev;
883
884 if (hdev->bus != BUS_USB)
885 return 0;
886
887 intf = to_usb_interface(hdev->dev.parent);
888 interface = intf->cur_altsetting;
889 dev = hid_to_usb_dev(hdev);
890
891 /* Some Elan legacy devices require SET_IDLE to be set on resume.
892 * It should be safe to send it to other devices too.
893 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
894
895 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
896 HID_REQ_SET_IDLE,
897 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
898 0, interface->desc.bInterfaceNumber,
899 NULL, 0, USB_CTRL_SET_TIMEOUT);
900
901 return 0;
902}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100903#endif
904
905static void mt_remove(struct hid_device *hdev)
906{
907 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100908 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100909 hid_hw_stop(hdev);
910 kfree(td);
911 hid_set_drvdata(hdev, NULL);
912}
913
914static const struct hid_device_id mt_devices[] = {
915
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100916 /* 3M panels */
917 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200918 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100919 USB_DEVICE_ID_3M1968) },
920 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200921 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100922 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100923 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200924 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100925 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100926
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200927 /* ActionStar panels */
928 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200929 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200930 USB_DEVICE_ID_ACTIONSTAR_1011) },
931
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100932 /* Atmel panels */
933 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200934 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100935 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100936 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200937 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100938 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100939
Jiri Kosina9ed32692012-04-20 12:15:44 +0200940 /* Baanto multitouch devices */
941 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina16b79bb2012-05-05 23:32:54 +0200942 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +0200943 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100944 /* Cando panels */
945 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200946 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100947 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
948 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200949 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100950 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
951 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200952 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100953 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
954 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200955 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100956 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
957
Austin Zhang942fd422011-05-28 02:03:47 +0800958 /* Chunghwa Telecom touch panels */
959 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200960 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +0800961 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
962
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200963 /* CVTouch panels */
964 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200965 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200966 USB_DEVICE_ID_CVTOUCH_SCREEN) },
967
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100968 /* Cypress panel */
969 { .driver_data = MT_CLS_CYPRESS,
970 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
971 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
972
Benjamin Tissoires22408282011-05-20 15:59:34 +0200973 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100974 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200975 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100976 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
977 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200978 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100979 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200980
981 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100982 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200983 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100984 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100985 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200986 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100987 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
988 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200989 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100990 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
991 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200992 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100993 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100994 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200995 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100996 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100997 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200998 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100999 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001000 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001001 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001002 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001003 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001004 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001005 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001006 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001007 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001008 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001009 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001010 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +01001011 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
1012 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001013 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +01001014 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +01001015 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001016 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +01001017 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
1018 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001019 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +02001020 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
1021 { .driver_data = MT_CLS_EGALAX_SERIAL,
1022 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +01001023 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Jiri Kosina3d771042012-08-15 10:01:01 +02001024 { .driver_data = MT_CLS_EGALAX,
1025 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1026 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1027 { .driver_data = MT_CLS_EGALAX,
1028 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1029 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
1030 { .driver_data = MT_CLS_EGALAX,
1031 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
1032 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
Benjamin Tissoires22408282011-05-20 15:59:34 +02001033
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +02001034 /* Elo TouchSystems IntelliTouch Plus panel */
1035 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001036 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +02001037 USB_DEVICE_ID_ELO_TS2515) },
1038
Henrik Rydberg77723e32012-09-07 19:37:40 +02001039 /* Flatfrog Panels */
1040 { .driver_data = MT_CLS_FLATFROG,
1041 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
1042 USB_DEVICE_ID_MULTITOUCH_3200) },
1043
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001044 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001045 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001046 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001047 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +08001048 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
1049 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1050 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001051
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001052 /* Gametel game controller */
1053 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001054 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001055 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1056
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001057 /* GoodTouch panels */
1058 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001059 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001060 USB_DEVICE_ID_GOODTOUCH_000f) },
1061
Benjamin Tissoires54580362011-11-29 13:13:12 +01001062 /* Hanvon panels */
1063 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001064 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001065 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1066
Stephane Chattya062cc52011-09-17 22:27:30 +02001067 /* Ideacom panel */
1068 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001069 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Stephane Chattya062cc52011-09-17 22:27:30 +02001070 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001071 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001072 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001073 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +02001074
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001075 /* Ilitek dual touch panel */
1076 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001077 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001078 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1079
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001080 /* IRTOUCH panels */
1081 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001082 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001083 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1084
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001085 /* LG Display panels */
1086 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001087 MT_USB_DEVICE(USB_VENDOR_ID_LG,
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001088 USB_DEVICE_ID_LG_MULTITOUCH) },
1089
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001090 /* Lumio panels */
1091 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001092 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001093 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001094 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001095 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001096 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001097
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001098 /* MosArt panels */
1099 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001100 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001101 USB_DEVICE_ID_ASUS_T91MT)},
1102 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001103 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001104 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1105 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001106 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001107 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1108
Benjamin Tissoiresc2517f62013-01-31 17:22:25 +01001109 /* Nexio panels */
1110 { .driver_data = MT_CLS_ALWAYS_TRUE,
1111 MT_USB_DEVICE(USB_VENDOR_ID_NEXIO,
1112 USB_DEVICE_ID_NEXIO_MULTITOUCH_420)},
1113
Denis Kovalev2258e862012-02-14 00:50:33 -08001114 /* Panasonic panels */
1115 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001116 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001117 USB_DEVICE_ID_PANABOARD_UBT780) },
1118 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001119 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001120 USB_DEVICE_ID_PANABOARD_UBT880) },
1121
Austin Hendrix4db703e2012-06-04 15:27:51 -07001122 /* Novatek Panel */
1123 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina4380d812012-06-06 16:28:33 +02001124 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001125 USB_DEVICE_ID_NOVATEK_PCT) },
1126
John Sung6ab3a9a2011-04-21 16:21:52 +02001127 /* PenMount panels */
1128 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001129 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
John Sung6ab3a9a2011-04-21 16:21:52 +02001130 USB_DEVICE_ID_PENMOUNT_PCI) },
1131
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001132 /* PixArt optical touch screen */
1133 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001134 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001135 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1136 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001137 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001138 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1139 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001140 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001141 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1142
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001143 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001144 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001145 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001146 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001147 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001148 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001149 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1150
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001151 /* Quanta-based panels */
1152 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001153 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001154 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1155 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001156 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001157 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1158 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001159 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001160 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1161
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001162 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001163 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001164 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001165 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001166 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001167 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001168 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001169 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001170 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001171 USB_DEVICE_ID_MTP_SITRONIX)},
1172
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001173 /* TopSeed panels */
1174 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001175 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001176 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1177
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001178 /* Touch International panels */
1179 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001180 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001181 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1182
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001183 /* Unitec panels */
1184 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001185 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001186 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1187 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001188 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001189 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +08001190 /* XAT */
1191 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001192 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001193 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001194
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001195 /* Xiroku */
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_SPX) },
1199 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001200 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001201 USB_DEVICE_ID_XIROKU_MPX) },
1202 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001203 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001204 USB_DEVICE_ID_XIROKU_CSR) },
1205 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001206 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001207 USB_DEVICE_ID_XIROKU_SPX1) },
1208 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001209 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001210 USB_DEVICE_ID_XIROKU_MPX1) },
1211 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001212 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001213 USB_DEVICE_ID_XIROKU_CSR1) },
1214 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001215 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001216 USB_DEVICE_ID_XIROKU_SPX2) },
1217 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001218 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001219 USB_DEVICE_ID_XIROKU_MPX2) },
1220 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001221 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001222 USB_DEVICE_ID_XIROKU_CSR2) },
1223
Benjamin Tissoires82d06982012-06-19 14:39:54 +02001224 /* Zytronic panels */
1225 { .driver_data = MT_CLS_SERIAL,
1226 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1227 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1228
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001229 /* Generic MT device */
1230 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001231 { }
1232};
1233MODULE_DEVICE_TABLE(hid, mt_devices);
1234
1235static const struct hid_usage_id mt_grabbed_usages[] = {
1236 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1237 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1238};
1239
1240static struct hid_driver mt_driver = {
1241 .name = "hid-multitouch",
1242 .id_table = mt_devices,
1243 .probe = mt_probe,
1244 .remove = mt_remove,
1245 .input_mapping = mt_input_mapping,
1246 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001247 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001248 .feature_mapping = mt_feature_mapping,
1249 .usage_table = mt_grabbed_usages,
1250 .event = mt_event,
Benjamin Tissoires55978fa2013-01-31 17:22:24 +01001251 .report = mt_report,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001252#ifdef CONFIG_PM
1253 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001254 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001255#endif
1256};
1257
1258static int __init mt_init(void)
1259{
1260 return hid_register_driver(&mt_driver);
1261}
1262
1263static void __exit mt_exit(void)
1264{
1265 hid_unregister_driver(&mt_driver);
1266}
1267
1268module_init(mt_init);
1269module_exit(mt_exit);