blob: 61543c02ea0baf42c58fbfa5518dba229cb22901 [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 Tissoires9b3bb9b82012-11-14 16:59:24 +010056#define MT_QUIRK_HOVERING (1 << 11)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010057
58struct mt_slot {
Benjamin Tissoires349fd6702012-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 Tissoires9b3bb9b82012-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 Tissoires5519cab2011-01-07 23:45:50 +010088 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires4aceed32012-06-19 14:39:52 +020089 __s8 inputmode_index; /* InputMode HID feature index in the report */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010090 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
91 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010092 __u8 num_received; /* how many contacts we received */
93 __u8 num_expected; /* expected last contact index */
94 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010095 __u8 touches_by_report; /* how many touches are present in one report:
96 * 1 means we should use a serial protocol
97 * > 1 means hybrid (multitouch) protocol */
Henrik Rydberg76f59022012-09-01 20:11:34 +020098 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010099 bool curvalid; /* is the current contact valid? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200100 unsigned mt_flags; /* flags to pass to input-mt */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100101};
102
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100103/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200104#define MT_CLS_DEFAULT 0x0001
105
Stephane Chattya062cc52011-09-17 22:27:30 +0200106#define MT_CLS_SERIAL 0x0002
107#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100108#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
109#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
110#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
111#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
112#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800113#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200114
115/* vendor specific classes */
116#define MT_CLS_3M 0x0101
117#define MT_CLS_CYPRESS 0x0102
118#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100119#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100120#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800121#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200122#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200123#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
124#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100125
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100126#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100127#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100128
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200129#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
130#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
131
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100132/*
133 * these device-dependent functions determine what slot corresponds
134 * to a valid contact that was just read.
135 */
136
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100137static int cypress_compute_slot(struct mt_device *td)
138{
139 if (td->curdata.contactid != 0 || td->num_received == 0)
140 return td->curdata.contactid;
141 else
142 return -1;
143}
144
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100145static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100146 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100147 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200148 { .name = MT_CLS_SERIAL,
149 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200150 { .name = MT_CLS_CONFIDENCE,
151 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100152 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
153 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
154 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200155 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
156 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
157 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100158 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100159 .quirks = MT_QUIRK_VALID_IS_INRANGE |
160 MT_QUIRK_SLOT_IS_CONTACTID,
161 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100162 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100163 .quirks = MT_QUIRK_VALID_IS_INRANGE |
164 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
165 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200166 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
167 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
168 MT_QUIRK_SLOT_IS_CONTACTID,
169 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800170 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
171 .quirks = MT_QUIRK_VALID_IS_INRANGE |
172 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200173
174 /*
175 * vendor specific classes
176 */
177 { .name = MT_CLS_3M,
178 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
179 MT_QUIRK_SLOT_IS_CONTACTID,
180 .sn_move = 2048,
181 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200182 .sn_height = 128,
183 .maxcontacts = 60,
184 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100185 { .name = MT_CLS_CYPRESS,
186 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
187 MT_QUIRK_CYPRESS,
188 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100189 { .name = MT_CLS_EGALAX,
190 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100191 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100192 .sn_move = 4096,
193 .sn_pressure = 32,
194 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100195 { .name = MT_CLS_EGALAX_SERIAL,
196 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
197 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100198 .sn_move = 4096,
199 .sn_pressure = 32,
200 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100201 { .name = MT_CLS_TOPSEED,
202 .quirks = MT_QUIRK_ALWAYS_VALID,
203 .is_indirect = true,
204 .maxcontacts = 2,
205 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800206 { .name = MT_CLS_PANASONIC,
207 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
208 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800209 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
210 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
211 MT_QUIRK_VALID_IS_INRANGE |
212 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
213 .maxcontacts = 2
214 },
215 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
216 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Xianhan Yu58ad34b2012-10-29 23:04:37 +0800217 MT_QUIRK_SLOT_IS_CONTACTNUMBER
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800218 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100219
Henrik Rydberg77723e32012-09-07 19:37:40 +0200220 { .name = MT_CLS_FLATFROG,
221 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
222 MT_QUIRK_NO_AREA,
223 .sn_move = 2048,
224 .maxcontacts = 40,
225 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100226 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100227};
228
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100229static ssize_t mt_show_quirks(struct device *dev,
230 struct device_attribute *attr,
231 char *buf)
232{
233 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
234 struct mt_device *td = hid_get_drvdata(hdev);
235
236 return sprintf(buf, "%u\n", td->mtclass.quirks);
237}
238
239static ssize_t mt_set_quirks(struct device *dev,
240 struct device_attribute *attr,
241 const char *buf, size_t count)
242{
243 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
244 struct mt_device *td = hid_get_drvdata(hdev);
245
246 unsigned long val;
247
248 if (kstrtoul(buf, 0, &val))
249 return -EINVAL;
250
251 td->mtclass.quirks = val;
252
253 return count;
254}
255
256static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
257
258static struct attribute *sysfs_attrs[] = {
259 &dev_attr_quirks.attr,
260 NULL
261};
262
263static struct attribute_group mt_attribute_group = {
264 .attrs = sysfs_attrs
265};
266
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100267static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100268 struct hid_field *field, struct hid_usage *usage)
269{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100270 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200271 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100272
273 switch (usage->hid) {
274 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100275 td->inputmode = field->report->id;
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200276 td->inputmode_index = 0; /* has to be updated below */
277
278 for (i=0; i < field->maxusage; i++) {
279 if (field->usage[i].hid == usage->hid) {
280 td->inputmode_index = i;
281 break;
282 }
283 }
284
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100285 break;
286 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100287 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100288 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100289 if (!td->maxcontacts &&
290 field->logical_maximum <= MT_MAX_MAXCONTACT)
291 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100292 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100293 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100294 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100295
296 break;
Benjamin Tissoires1b42fc42012-11-14 16:59:25 +0100297 case 0xff0000c5:
298 if (field->report_count == 256 && field->report_size == 8) {
299 /* Win 8 devices need special quirks */
300 __s32 *quirks = &td->mtclass.quirks;
301 *quirks |= MT_QUIRK_ALWAYS_VALID;
302 *quirks |= MT_QUIRK_IGNORE_DUPLICATES;
303 *quirks |= MT_QUIRK_HOVERING;
304 *quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
305 *quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
306 *quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
307 }
308 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100309 }
310}
311
312static void set_abs(struct input_dev *input, unsigned int code,
313 struct hid_field *field, int snratio)
314{
315 int fmin = field->logical_minimum;
316 int fmax = field->logical_maximum;
317 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
318 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100319 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100320}
321
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200322static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100323 struct hid_input *hi)
324{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200325 struct mt_fields *f = td->fields;
326
327 if (f->length >= HID_MAX_FIELDS)
328 return;
329
330 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100331}
332
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100333static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
334 struct hid_field *field, struct hid_usage *usage,
335 unsigned long **bit, int *max)
336{
337 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100338 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100339 int code;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100340 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100341
Jeff Brown658d4aed592011-08-15 16:44:28 -0700342 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800343 * We need to ignore fields that belong to other collections
344 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700345 if (field->application == HID_DG_TOUCHSCREEN)
Henrik Rydberg76f59022012-09-01 20:11:34 +0200346 td->mt_flags |= INPUT_MT_DIRECT;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100347 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700348 return 0;
349
Henrik Rydberg76f59022012-09-01 20:11:34 +0200350 /*
351 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100352 */
353 if (field->application == HID_DG_TOUCHPAD ||
Henrik Rydberg76f59022012-09-01 20:11:34 +0200354 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
355 td->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100356
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100357 /* eGalax devices provide a Digitizer.Stylus input which overrides
358 * the correct Digitizers.Finger X/Y ranges.
359 * Let's just ignore this input. */
360 if (field->physical == HID_DG_STYLUS)
361 return -1;
362
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100363 if (usage->usage_index)
364 prev_usage = &field->usage[usage->usage_index - 1];
365
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100366 switch (usage->hid & HID_USAGE_PAGE) {
367
368 case HID_UP_GENDESK:
369 switch (usage->hid) {
370 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100371 if (prev_usage && (prev_usage->hid == usage->hid)) {
372 hid_map_usage(hi, usage, bit, max,
373 EV_ABS, ABS_MT_TOOL_X);
374 set_abs(hi->input, ABS_MT_TOOL_X, field,
375 cls->sn_move);
376 } else {
377 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100378 EV_ABS, ABS_MT_POSITION_X);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100379 set_abs(hi->input, ABS_MT_POSITION_X, field,
380 cls->sn_move);
381 }
382
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200383 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100384 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100385 return 1;
386 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100387 if (prev_usage && (prev_usage->hid == usage->hid)) {
388 hid_map_usage(hi, usage, bit, max,
389 EV_ABS, ABS_MT_TOOL_Y);
390 set_abs(hi->input, ABS_MT_TOOL_Y, field,
391 cls->sn_move);
392 } else {
393 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100394 EV_ABS, ABS_MT_POSITION_Y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100395 set_abs(hi->input, ABS_MT_POSITION_Y, field,
396 cls->sn_move);
397 }
398
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200399 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100400 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100401 return 1;
402 }
403 return 0;
404
405 case HID_UP_DIGITIZER:
406 switch (usage->hid) {
407 case HID_DG_INRANGE:
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100408 if (cls->quirks & MT_QUIRK_HOVERING) {
409 hid_map_usage(hi, usage, bit, max,
410 EV_ABS, ABS_MT_DISTANCE);
411 input_set_abs_params(hi->input,
412 ABS_MT_DISTANCE, 0, 1, 0, 0);
413 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200414 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100415 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100416 return 1;
417 case HID_DG_CONFIDENCE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200418 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100419 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100420 return 1;
421 case HID_DG_TIPSWITCH:
422 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
423 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
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_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200428 mt_store_field(usage, td, hi);
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200429 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100430 td->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100431 return 1;
432 case HID_DG_WIDTH:
433 hid_map_usage(hi, usage, bit, max,
434 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200435 if (!(cls->quirks & MT_QUIRK_NO_AREA))
436 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
437 cls->sn_width);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200438 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100439 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100440 return 1;
441 case HID_DG_HEIGHT:
442 hid_map_usage(hi, usage, bit, max,
443 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200444 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
445 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
446 cls->sn_height);
447 input_set_abs_params(hi->input,
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100448 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200449 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200450 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100451 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100452 return 1;
453 case HID_DG_TIPPRESSURE:
454 hid_map_usage(hi, usage, bit, max,
455 EV_ABS, ABS_MT_PRESSURE);
456 set_abs(hi->input, ABS_MT_PRESSURE, field,
457 cls->sn_pressure);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200458 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100459 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100460 return 1;
461 case HID_DG_CONTACTCOUNT:
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_CONTACTMAX:
465 /* we don't set td->last_slot_field as contactcount and
466 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100467 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100468 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100469 case HID_DG_TOUCH:
470 /* Legacy devices use TIPSWITCH and not TOUCH.
471 * Let's just ignore this field. */
472 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100473 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100474 /* let hid-input decide for the others */
475 return 0;
476
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100477 case HID_UP_BUTTON:
478 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
479 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
480 input_set_capability(hi->input, EV_KEY, code);
481 return 1;
482
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100483 case 0xff000000:
484 /* we do not want to map these: no input-oriented meaning */
485 return -1;
486 }
487
488 return 0;
489}
490
491static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
492 struct hid_field *field, struct hid_usage *usage,
493 unsigned long **bit, int *max)
494{
495 if (usage->type == EV_KEY || usage->type == EV_ABS)
496 set_bit(usage->type, hi->input->evbit);
497
498 return -1;
499}
500
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200501static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100502{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100503 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100504
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100505 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
506 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100507
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100508 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100509 return cypress_compute_slot(td);
510
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100511 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
512 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100513
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200514 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
515 return td->curdata.contactid - 1;
516
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200517 return input_mt_get_slot_by_key(input, td->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100518}
519
520/*
521 * this function is called when a whole contact has been processed,
522 * so that it can assign it to a slot and store the data there
523 */
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200524static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100525{
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100526 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200527 int slotnum = mt_compute_slot(td, input);
528 struct mt_slot *s = &td->curdata;
Benjamin Tissoires28728392012-11-14 16:59:23 +0100529 struct input_mt *mt = input->mt;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100530
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200531 if (slotnum < 0 || slotnum >= td->maxcontacts)
532 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100533
Benjamin Tissoires28728392012-11-14 16:59:23 +0100534 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
535 struct input_mt_slot *slot = &mt->slots[slotnum];
536 if (input_mt_is_active(slot) &&
537 input_mt_is_used(mt, slot))
538 return;
539 }
540
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200541 input_mt_slot(input, slotnum);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100542 input_mt_report_slot_state(input, MT_TOOL_FINGER,
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100543 s->touch_state || s->inrange_state);
544 if (s->touch_state || s->inrange_state) {
545 /* this finger is in proximity of the sensor */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100546 int wide = (s->w > s->h);
547 /* divided by two to match visual scale of touch */
548 int major = max(s->w, s->h) >> 1;
549 int minor = min(s->w, s->h) >> 1;
550
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100551 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
552 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100553 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
554 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100555 input_event(input, EV_ABS, ABS_MT_DISTANCE,
556 !s->touch_state);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100557 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100558 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100559 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
560 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100561 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100562 }
563
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200564 td->num_received++;
565}
566
567/*
568 * this function is called when a whole packet has been received and processed,
569 * so that it can decide what to send to the input layer.
570 */
571static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
572{
Henrik Rydberg76f59022012-09-01 20:11:34 +0200573 input_mt_sync_frame(input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100574 input_sync(input);
575 td->num_received = 0;
576}
577
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100578static int mt_event(struct hid_device *hid, struct hid_field *field,
579 struct hid_usage *usage, __s32 value)
580{
581 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100582 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100583
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200584 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100585 switch (usage->hid) {
586 case HID_DG_INRANGE:
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100587 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100588 td->curvalid = value;
Benjamin Tissoires9b3bb9b82012-11-14 16:59:24 +0100589 if (quirks & MT_QUIRK_HOVERING)
590 td->curdata.inrange_state = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100591 break;
592 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100593 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
594 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100595 td->curdata.touch_state = value;
596 break;
597 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100598 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
599 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100600 break;
601 case HID_DG_CONTACTID:
602 td->curdata.contactid = value;
603 break;
604 case HID_DG_TIPPRESSURE:
605 td->curdata.p = value;
606 break;
607 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100608 if (usage->code == ABS_MT_TOOL_X)
609 td->curdata.cx = value;
610 else
611 td->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100612 break;
613 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100614 if (usage->code == ABS_MT_TOOL_Y)
615 td->curdata.cy = value;
616 else
617 td->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100618 break;
619 case HID_DG_WIDTH:
620 td->curdata.w = value;
621 break;
622 case HID_DG_HEIGHT:
623 td->curdata.h = value;
624 break;
625 case HID_DG_CONTACTCOUNT:
626 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100627 * Includes multi-packet support where subsequent
628 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100629 */
630 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100631 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100632 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100633 case HID_DG_TOUCH:
634 /* do nothing */
635 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100636
637 default:
638 /* fallback to the generic hidinput handling */
639 return 0;
640 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100641
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100642 if (usage->usage_index + 1 == field->report_count) {
643 /* we only take into account the last report. */
644 if (usage->hid == td->last_slot_field)
645 mt_complete_slot(td, field->hidinput->input);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100646
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100647 if (field->index == td->last_field_index
648 && td->num_received >= td->num_expected)
649 mt_sync_frame(td, field->hidinput->input);
650 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100651
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100652 }
653
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100654 /* we have handled the hidinput part, now remains hiddev */
655 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
656 hid->hiddev_hid_event(hid, field, usage, value);
657
658 return 1;
659}
660
661static void mt_set_input_mode(struct hid_device *hdev)
662{
663 struct mt_device *td = hid_get_drvdata(hdev);
664 struct hid_report *r;
665 struct hid_report_enum *re;
666
667 if (td->inputmode < 0)
668 return;
669
670 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
671 r = re->report_id_hash[td->inputmode];
672 if (r) {
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200673 r->field[0]->value[td->inputmode_index] = 0x02;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100674 usbhid_submit_report(hdev, r, USB_DIR_OUT);
675 }
676}
677
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100678static void mt_set_maxcontacts(struct hid_device *hdev)
679{
680 struct mt_device *td = hid_get_drvdata(hdev);
681 struct hid_report *r;
682 struct hid_report_enum *re;
683 int fieldmax, max;
684
685 if (td->maxcontact_report_id < 0)
686 return;
687
688 if (!td->mtclass.maxcontacts)
689 return;
690
691 re = &hdev->report_enum[HID_FEATURE_REPORT];
692 r = re->report_id_hash[td->maxcontact_report_id];
693 if (r) {
694 max = td->mtclass.maxcontacts;
695 fieldmax = r->field[0]->logical_maximum;
696 max = min(fieldmax, max);
697 if (r->field[0]->value[0] != max) {
698 r->field[0]->value[0] = max;
699 usbhid_submit_report(hdev, r, USB_DIR_OUT);
700 }
701 }
702}
703
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200704static void mt_post_parse_default_settings(struct mt_device *td)
705{
706 __s32 quirks = td->mtclass.quirks;
707
708 /* unknown serial device needs special quirks */
709 if (td->touches_by_report == 1) {
710 quirks |= MT_QUIRK_ALWAYS_VALID;
711 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
712 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
713 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
714 }
715
716 td->mtclass.quirks = quirks;
717}
718
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200719static void mt_post_parse(struct mt_device *td)
720{
721 struct mt_fields *f = td->fields;
722
723 if (td->touches_by_report > 0) {
724 int field_count_per_touch = f->length / td->touches_by_report;
725 td->last_slot_field = f->usages[field_count_per_touch - 1];
726 }
727}
728
Henrik Rydberg76f59022012-09-01 20:11:34 +0200729static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
730
731{
732 struct mt_device *td = hid_get_drvdata(hdev);
733 struct mt_class *cls = &td->mtclass;
734 struct input_dev *input = hi->input;
735
736 /* Only initialize slots for MT input devices */
737 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
738 return;
739
740 if (!td->maxcontacts)
741 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
742
743 mt_post_parse(td);
744 if (td->serial_maybe)
745 mt_post_parse_default_settings(td);
746
747 if (cls->is_indirect)
748 td->mt_flags |= INPUT_MT_POINTER;
749
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200750 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
751 td->mt_flags |= INPUT_MT_DROP_UNUSED;
752
Henrik Rydberg76f59022012-09-01 20:11:34 +0200753 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
754
755 td->mt_flags = 0;
756}
757
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100758static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
759{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100760 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100761 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100762 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
763
Henrik Rydberg94b5485c2012-08-08 21:45:50 +0200764 for (i = 0; mt_classes[i].name ; i++) {
765 if (id->driver_data == mt_classes[i].name) {
766 mtclass = &(mt_classes[i]);
767 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100768 }
769 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100770
Henrik Rydbergd682bd7f2011-11-01 15:26:31 +0100771 /* This allows the driver to correctly support devices
772 * that emit events over several HID messages.
773 */
774 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100775
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100776 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100777 if (!td) {
778 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
779 return -ENOMEM;
780 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100781 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100782 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100783 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100784 hid_set_drvdata(hdev, td);
785
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200786 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
787 if (!td->fields) {
788 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
789 ret = -ENOMEM;
790 goto fail;
791 }
792
Henrik Rydberg76f59022012-09-01 20:11:34 +0200793 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
794 td->serial_maybe = true;
795
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100796 ret = hid_parse(hdev);
797 if (ret != 0)
798 goto fail;
799
800 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100801 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100802 goto fail;
803
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100804 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
805
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100806 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100807 mt_set_input_mode(hdev);
808
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200809 kfree(td->fields);
810 td->fields = NULL;
811
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100812 return 0;
813
814fail:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200815 kfree(td->fields);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100816 kfree(td);
817 return ret;
818}
819
820#ifdef CONFIG_PM
821static int mt_reset_resume(struct hid_device *hdev)
822{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100823 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100824 mt_set_input_mode(hdev);
825 return 0;
826}
Scott Liudfeefd12012-08-15 17:21:55 +0800827
828static int mt_resume(struct hid_device *hdev)
829{
830 struct usb_interface *intf;
831 struct usb_host_interface *interface;
832 struct usb_device *dev;
833
834 if (hdev->bus != BUS_USB)
835 return 0;
836
837 intf = to_usb_interface(hdev->dev.parent);
838 interface = intf->cur_altsetting;
839 dev = hid_to_usb_dev(hdev);
840
841 /* Some Elan legacy devices require SET_IDLE to be set on resume.
842 * It should be safe to send it to other devices too.
843 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
844
845 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
846 HID_REQ_SET_IDLE,
847 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
848 0, interface->desc.bInterfaceNumber,
849 NULL, 0, USB_CTRL_SET_TIMEOUT);
850
851 return 0;
852}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100853#endif
854
855static void mt_remove(struct hid_device *hdev)
856{
857 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100858 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100859 hid_hw_stop(hdev);
860 kfree(td);
861 hid_set_drvdata(hdev, NULL);
862}
863
864static const struct hid_device_id mt_devices[] = {
865
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100866 /* 3M panels */
867 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200868 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100869 USB_DEVICE_ID_3M1968) },
870 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200871 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100872 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100873 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200874 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100875 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100876
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200877 /* ActionStar panels */
878 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200879 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200880 USB_DEVICE_ID_ACTIONSTAR_1011) },
881
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100882 /* Atmel panels */
883 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200884 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100885 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100886 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200887 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100888 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100889
Jiri Kosina9ed32692012-04-20 12:15:44 +0200890 /* Baanto multitouch devices */
891 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina16b79bb2012-05-05 23:32:54 +0200892 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +0200893 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100894 /* Cando panels */
895 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200896 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100897 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
898 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200899 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100900 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
901 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200902 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100903 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
904 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200905 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100906 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
907
Austin Zhang942fd422011-05-28 02:03:47 +0800908 /* Chunghwa Telecom touch panels */
909 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200910 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +0800911 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
912
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200913 /* CVTouch panels */
914 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200915 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200916 USB_DEVICE_ID_CVTOUCH_SCREEN) },
917
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100918 /* Cypress panel */
919 { .driver_data = MT_CLS_CYPRESS,
920 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
921 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
922
Benjamin Tissoires22408282011-05-20 15:59:34 +0200923 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100924 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200925 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100926 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
927 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200928 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100929 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200930
931 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100932 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200933 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100934 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100935 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200936 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100937 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
938 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200939 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100940 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
941 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200942 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100943 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100944 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200945 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100946 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100947 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200948 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100949 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100950 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200951 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100952 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100953 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200954 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100955 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100956 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200957 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100958 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100959 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200960 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100961 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
962 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200963 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100964 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100965 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200966 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100967 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
968 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200969 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +0200970 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
971 { .driver_data = MT_CLS_EGALAX_SERIAL,
972 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100973 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Jiri Kosina3d771042012-08-15 10:01:01 +0200974 { .driver_data = MT_CLS_EGALAX,
975 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
976 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
977 { .driver_data = MT_CLS_EGALAX,
978 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
979 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
980 { .driver_data = MT_CLS_EGALAX,
981 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
982 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200983
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200984 /* Elo TouchSystems IntelliTouch Plus panel */
985 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200986 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200987 USB_DEVICE_ID_ELO_TS2515) },
988
Henrik Rydberg77723e32012-09-07 19:37:40 +0200989 /* Flatfrog Panels */
990 { .driver_data = MT_CLS_FLATFROG,
991 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
992 USB_DEVICE_ID_MULTITOUCH_3200) },
993
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100994 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800995 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200996 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100997 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800998 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
999 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
1000 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001001
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001002 /* Gametel game controller */
1003 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001004 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +01001005 USB_DEVICE_ID_GAMETEL_MT_MODE) },
1006
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001007 /* GoodTouch panels */
1008 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001009 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001010 USB_DEVICE_ID_GOODTOUCH_000f) },
1011
Benjamin Tissoires54580362011-11-29 13:13:12 +01001012 /* Hanvon panels */
1013 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001014 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001015 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1016
Stephane Chattya062cc52011-09-17 22:27:30 +02001017 /* Ideacom panel */
1018 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001019 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Stephane Chattya062cc52011-09-17 22:27:30 +02001020 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001021 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001022 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001023 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +02001024
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001025 /* Ilitek dual touch panel */
1026 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001027 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001028 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1029
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001030 /* IRTOUCH panels */
1031 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001032 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001033 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1034
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001035 /* LG Display panels */
1036 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001037 MT_USB_DEVICE(USB_VENDOR_ID_LG,
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001038 USB_DEVICE_ID_LG_MULTITOUCH) },
1039
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001040 /* Lumio panels */
1041 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001042 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001043 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001044 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001045 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001046 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001047
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001048 /* MosArt panels */
1049 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001050 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001051 USB_DEVICE_ID_ASUS_T91MT)},
1052 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001053 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001054 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1055 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001056 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001057 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1058
Denis Kovalev2258e862012-02-14 00:50:33 -08001059 /* Panasonic panels */
1060 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001061 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001062 USB_DEVICE_ID_PANABOARD_UBT780) },
1063 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001064 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001065 USB_DEVICE_ID_PANABOARD_UBT880) },
1066
Austin Hendrix4db703e2012-06-04 15:27:51 -07001067 /* Novatek Panel */
1068 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina4380d812012-06-06 16:28:33 +02001069 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001070 USB_DEVICE_ID_NOVATEK_PCT) },
1071
John Sung6ab3a9a2011-04-21 16:21:52 +02001072 /* PenMount panels */
1073 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001074 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
John Sung6ab3a9a2011-04-21 16:21:52 +02001075 USB_DEVICE_ID_PENMOUNT_PCI) },
1076
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001077 /* PixArt optical touch screen */
1078 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001079 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001080 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1081 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001082 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001083 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1084 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001085 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001086 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1087
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001088 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001089 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001090 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001091 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001092 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001093 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001094 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1095
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001096 /* Quanta-based panels */
1097 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001098 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001099 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1100 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001101 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001102 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1103 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001104 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001105 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1106
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001107 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001108 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001109 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001110 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001111 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001112 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001113 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001114 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001115 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001116 USB_DEVICE_ID_MTP_SITRONIX)},
1117
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001118 /* TopSeed panels */
1119 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001120 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001121 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1122
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001123 /* Touch International panels */
1124 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001125 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001126 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1127
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001128 /* Unitec panels */
1129 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001130 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001131 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1132 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001133 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001134 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +08001135 /* XAT */
1136 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001137 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001138 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001139
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001140 /* Xiroku */
1141 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001142 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001143 USB_DEVICE_ID_XIROKU_SPX) },
1144 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001145 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001146 USB_DEVICE_ID_XIROKU_MPX) },
1147 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001148 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001149 USB_DEVICE_ID_XIROKU_CSR) },
1150 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001151 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001152 USB_DEVICE_ID_XIROKU_SPX1) },
1153 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001154 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001155 USB_DEVICE_ID_XIROKU_MPX1) },
1156 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001157 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001158 USB_DEVICE_ID_XIROKU_CSR1) },
1159 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001160 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001161 USB_DEVICE_ID_XIROKU_SPX2) },
1162 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001163 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001164 USB_DEVICE_ID_XIROKU_MPX2) },
1165 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001166 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001167 USB_DEVICE_ID_XIROKU_CSR2) },
1168
Benjamin Tissoires82d06982012-06-19 14:39:54 +02001169 /* Zytronic panels */
1170 { .driver_data = MT_CLS_SERIAL,
1171 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1172 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1173
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001174 /* Generic MT device */
1175 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001176 { }
1177};
1178MODULE_DEVICE_TABLE(hid, mt_devices);
1179
1180static const struct hid_usage_id mt_grabbed_usages[] = {
1181 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1182 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1183};
1184
1185static struct hid_driver mt_driver = {
1186 .name = "hid-multitouch",
1187 .id_table = mt_devices,
1188 .probe = mt_probe,
1189 .remove = mt_remove,
1190 .input_mapping = mt_input_mapping,
1191 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001192 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001193 .feature_mapping = mt_feature_mapping,
1194 .usage_table = mt_grabbed_usages,
1195 .event = mt_event,
1196#ifdef CONFIG_PM
1197 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001198 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001199#endif
1200};
1201
1202static int __init mt_init(void)
1203{
1204 return hid_register_driver(&mt_driver);
1205}
1206
1207static void __exit mt_exit(void)
1208{
1209 hid_unregister_driver(&mt_driver);
1210}
1211
1212module_init(mt_init);
1213module_exit(mt_exit);