blob: e86fbf4be63977bb6430901dbb0511fe2055cf27 [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 Tissoires5519cab2011-01-07 23:45:50 +010056
57struct mt_slot {
Benjamin Tissoires349fd6702012-11-14 16:59:19 +010058 __s32 x, y, cx, cy, p, w, h;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010059 __s32 contactid; /* the device ContactID assigned to this slot */
60 bool touch_state; /* is the touch valid? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010061};
62
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010063struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010064 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010065 __s32 quirks;
66 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010067 __s32 sn_width; /* Signal/noise ratio for width events */
68 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010069 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
70 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +010071 bool is_indirect; /* true for touchpads */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010072};
73
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020074struct mt_fields {
75 unsigned usages[HID_MAX_FIELDS];
76 unsigned int length;
77};
78
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010079struct mt_device {
80 struct mt_slot curdata; /* placeholder of incoming data */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +010081 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020082 struct mt_fields *fields; /* temporary placeholder for storing the
83 multitouch fields */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010084 unsigned last_field_index; /* last field index of the report */
85 unsigned last_slot_field; /* the last field of a slot */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010086 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires4aceed32012-06-19 14:39:52 +020087 __s8 inputmode_index; /* InputMode HID feature index in the report */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010088 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
89 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010090 __u8 num_received; /* how many contacts we received */
91 __u8 num_expected; /* expected last contact index */
92 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010093 __u8 touches_by_report; /* how many touches are present in one report:
94 * 1 means we should use a serial protocol
95 * > 1 means hybrid (multitouch) protocol */
Henrik Rydberg76f59022012-09-01 20:11:34 +020096 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010097 bool curvalid; /* is the current contact valid? */
Henrik Rydberg76f59022012-09-01 20:11:34 +020098 unsigned mt_flags; /* flags to pass to input-mt */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010099};
100
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100101/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200102#define MT_CLS_DEFAULT 0x0001
103
Stephane Chattya062cc52011-09-17 22:27:30 +0200104#define MT_CLS_SERIAL 0x0002
105#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100106#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
107#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
108#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
109#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
110#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800111#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200112
113/* vendor specific classes */
114#define MT_CLS_3M 0x0101
115#define MT_CLS_CYPRESS 0x0102
116#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100117#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100118#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800119#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200120#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200121#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
122#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100123
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100124#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100125#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100126
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200127#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
128#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
129
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100130/*
131 * these device-dependent functions determine what slot corresponds
132 * to a valid contact that was just read.
133 */
134
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100135static int cypress_compute_slot(struct mt_device *td)
136{
137 if (td->curdata.contactid != 0 || td->num_received == 0)
138 return td->curdata.contactid;
139 else
140 return -1;
141}
142
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100143static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100144 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100145 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200146 { .name = MT_CLS_SERIAL,
147 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200148 { .name = MT_CLS_CONFIDENCE,
149 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100150 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
151 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
152 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200153 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
154 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
155 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100156 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100157 .quirks = MT_QUIRK_VALID_IS_INRANGE |
158 MT_QUIRK_SLOT_IS_CONTACTID,
159 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100160 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100161 .quirks = MT_QUIRK_VALID_IS_INRANGE |
162 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
163 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200164 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
165 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
166 MT_QUIRK_SLOT_IS_CONTACTID,
167 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800168 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
169 .quirks = MT_QUIRK_VALID_IS_INRANGE |
170 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200171
172 /*
173 * vendor specific classes
174 */
175 { .name = MT_CLS_3M,
176 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
177 MT_QUIRK_SLOT_IS_CONTACTID,
178 .sn_move = 2048,
179 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200180 .sn_height = 128,
181 .maxcontacts = 60,
182 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100183 { .name = MT_CLS_CYPRESS,
184 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
185 MT_QUIRK_CYPRESS,
186 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100187 { .name = MT_CLS_EGALAX,
188 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100189 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100190 .sn_move = 4096,
191 .sn_pressure = 32,
192 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100193 { .name = MT_CLS_EGALAX_SERIAL,
194 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
195 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100196 .sn_move = 4096,
197 .sn_pressure = 32,
198 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100199 { .name = MT_CLS_TOPSEED,
200 .quirks = MT_QUIRK_ALWAYS_VALID,
201 .is_indirect = true,
202 .maxcontacts = 2,
203 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800204 { .name = MT_CLS_PANASONIC,
205 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
206 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800207 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
208 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
209 MT_QUIRK_VALID_IS_INRANGE |
210 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
211 .maxcontacts = 2
212 },
213 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
214 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Xianhan Yu58ad34b2012-10-29 23:04:37 +0800215 MT_QUIRK_SLOT_IS_CONTACTNUMBER
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800216 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100217
Henrik Rydberg77723e32012-09-07 19:37:40 +0200218 { .name = MT_CLS_FLATFROG,
219 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
220 MT_QUIRK_NO_AREA,
221 .sn_move = 2048,
222 .maxcontacts = 40,
223 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100224 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100225};
226
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100227static ssize_t mt_show_quirks(struct device *dev,
228 struct device_attribute *attr,
229 char *buf)
230{
231 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
232 struct mt_device *td = hid_get_drvdata(hdev);
233
234 return sprintf(buf, "%u\n", td->mtclass.quirks);
235}
236
237static ssize_t mt_set_quirks(struct device *dev,
238 struct device_attribute *attr,
239 const char *buf, size_t count)
240{
241 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
242 struct mt_device *td = hid_get_drvdata(hdev);
243
244 unsigned long val;
245
246 if (kstrtoul(buf, 0, &val))
247 return -EINVAL;
248
249 td->mtclass.quirks = val;
250
251 return count;
252}
253
254static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
255
256static struct attribute *sysfs_attrs[] = {
257 &dev_attr_quirks.attr,
258 NULL
259};
260
261static struct attribute_group mt_attribute_group = {
262 .attrs = sysfs_attrs
263};
264
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100265static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100266 struct hid_field *field, struct hid_usage *usage)
267{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100268 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200269 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100270
271 switch (usage->hid) {
272 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100273 td->inputmode = field->report->id;
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200274 td->inputmode_index = 0; /* has to be updated below */
275
276 for (i=0; i < field->maxusage; i++) {
277 if (field->usage[i].hid == usage->hid) {
278 td->inputmode_index = i;
279 break;
280 }
281 }
282
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100283 break;
284 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100285 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100286 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100287 if (!td->maxcontacts &&
288 field->logical_maximum <= MT_MAX_MAXCONTACT)
289 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100290 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100291 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100292 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100293
294 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100295 }
296}
297
298static void set_abs(struct input_dev *input, unsigned int code,
299 struct hid_field *field, int snratio)
300{
301 int fmin = field->logical_minimum;
302 int fmax = field->logical_maximum;
303 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
304 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100305 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100306}
307
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200308static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100309 struct hid_input *hi)
310{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200311 struct mt_fields *f = td->fields;
312
313 if (f->length >= HID_MAX_FIELDS)
314 return;
315
316 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100317}
318
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100319static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
320 struct hid_field *field, struct hid_usage *usage,
321 unsigned long **bit, int *max)
322{
323 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100324 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100325 int code;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100326 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100327
Jeff Brown658d4aed592011-08-15 16:44:28 -0700328 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800329 * We need to ignore fields that belong to other collections
330 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700331 if (field->application == HID_DG_TOUCHSCREEN)
Henrik Rydberg76f59022012-09-01 20:11:34 +0200332 td->mt_flags |= INPUT_MT_DIRECT;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100333 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700334 return 0;
335
Henrik Rydberg76f59022012-09-01 20:11:34 +0200336 /*
337 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100338 */
339 if (field->application == HID_DG_TOUCHPAD ||
Henrik Rydberg76f59022012-09-01 20:11:34 +0200340 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
341 td->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100342
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100343 /* eGalax devices provide a Digitizer.Stylus input which overrides
344 * the correct Digitizers.Finger X/Y ranges.
345 * Let's just ignore this input. */
346 if (field->physical == HID_DG_STYLUS)
347 return -1;
348
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100349 if (usage->usage_index)
350 prev_usage = &field->usage[usage->usage_index - 1];
351
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100352 switch (usage->hid & HID_USAGE_PAGE) {
353
354 case HID_UP_GENDESK:
355 switch (usage->hid) {
356 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100357 if (prev_usage && (prev_usage->hid == usage->hid)) {
358 hid_map_usage(hi, usage, bit, max,
359 EV_ABS, ABS_MT_TOOL_X);
360 set_abs(hi->input, ABS_MT_TOOL_X, field,
361 cls->sn_move);
362 } else {
363 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100364 EV_ABS, ABS_MT_POSITION_X);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100365 set_abs(hi->input, ABS_MT_POSITION_X, field,
366 cls->sn_move);
367 }
368
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200369 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100370 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100371 return 1;
372 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100373 if (prev_usage && (prev_usage->hid == usage->hid)) {
374 hid_map_usage(hi, usage, bit, max,
375 EV_ABS, ABS_MT_TOOL_Y);
376 set_abs(hi->input, ABS_MT_TOOL_Y, field,
377 cls->sn_move);
378 } else {
379 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100380 EV_ABS, ABS_MT_POSITION_Y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100381 set_abs(hi->input, ABS_MT_POSITION_Y, field,
382 cls->sn_move);
383 }
384
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200385 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100386 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100387 return 1;
388 }
389 return 0;
390
391 case HID_UP_DIGITIZER:
392 switch (usage->hid) {
393 case HID_DG_INRANGE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200394 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100395 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100396 return 1;
397 case HID_DG_CONFIDENCE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200398 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100399 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100400 return 1;
401 case HID_DG_TIPSWITCH:
402 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
403 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200404 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100405 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100406 return 1;
407 case HID_DG_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200408 mt_store_field(usage, td, hi);
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200409 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100410 td->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100411 return 1;
412 case HID_DG_WIDTH:
413 hid_map_usage(hi, usage, bit, max,
414 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200415 if (!(cls->quirks & MT_QUIRK_NO_AREA))
416 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
417 cls->sn_width);
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_HEIGHT:
422 hid_map_usage(hi, usage, bit, max,
423 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200424 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
425 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
426 cls->sn_height);
427 input_set_abs_params(hi->input,
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100428 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200429 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200430 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100431 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100432 return 1;
433 case HID_DG_TIPPRESSURE:
434 hid_map_usage(hi, usage, bit, max,
435 EV_ABS, ABS_MT_PRESSURE);
436 set_abs(hi->input, ABS_MT_PRESSURE, field,
437 cls->sn_pressure);
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_CONTACTCOUNT:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100442 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100443 return 1;
444 case HID_DG_CONTACTMAX:
445 /* we don't set td->last_slot_field as contactcount and
446 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100447 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100448 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100449 case HID_DG_TOUCH:
450 /* Legacy devices use TIPSWITCH and not TOUCH.
451 * Let's just ignore this field. */
452 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100453 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100454 /* let hid-input decide for the others */
455 return 0;
456
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100457 case HID_UP_BUTTON:
458 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
459 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
460 input_set_capability(hi->input, EV_KEY, code);
461 return 1;
462
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100463 case 0xff000000:
464 /* we do not want to map these: no input-oriented meaning */
465 return -1;
466 }
467
468 return 0;
469}
470
471static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
472 struct hid_field *field, struct hid_usage *usage,
473 unsigned long **bit, int *max)
474{
475 if (usage->type == EV_KEY || usage->type == EV_ABS)
476 set_bit(usage->type, hi->input->evbit);
477
478 return -1;
479}
480
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200481static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100482{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100483 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100484
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100485 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
486 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100487
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100488 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100489 return cypress_compute_slot(td);
490
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100491 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
492 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100493
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200494 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
495 return td->curdata.contactid - 1;
496
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200497 return input_mt_get_slot_by_key(input, td->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100498}
499
500/*
501 * this function is called when a whole contact has been processed,
502 * so that it can assign it to a slot and store the data there
503 */
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200504static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100505{
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100506 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200507 int slotnum = mt_compute_slot(td, input);
508 struct mt_slot *s = &td->curdata;
Benjamin Tissoires28728392012-11-14 16:59:23 +0100509 struct input_mt *mt = input->mt;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100510
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200511 if (slotnum < 0 || slotnum >= td->maxcontacts)
512 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100513
Benjamin Tissoires28728392012-11-14 16:59:23 +0100514 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
515 struct input_mt_slot *slot = &mt->slots[slotnum];
516 if (input_mt_is_active(slot) &&
517 input_mt_is_used(mt, slot))
518 return;
519 }
520
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200521 input_mt_slot(input, slotnum);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100522 input_mt_report_slot_state(input, MT_TOOL_FINGER,
523 s->touch_state);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100524 if (s->touch_state) {
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100525 /* this finger is on the screen */
526 int wide = (s->w > s->h);
527 /* divided by two to match visual scale of touch */
528 int major = max(s->w, s->h) >> 1;
529 int minor = min(s->w, s->h) >> 1;
530
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100531 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
532 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100533 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
534 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100535 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100536 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100537 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
538 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100539 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100540 }
541
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200542 td->num_received++;
543}
544
545/*
546 * this function is called when a whole packet has been received and processed,
547 * so that it can decide what to send to the input layer.
548 */
549static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
550{
Henrik Rydberg76f59022012-09-01 20:11:34 +0200551 input_mt_sync_frame(input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100552 input_sync(input);
553 td->num_received = 0;
554}
555
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100556static int mt_event(struct hid_device *hid, struct hid_field *field,
557 struct hid_usage *usage, __s32 value)
558{
559 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100560 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100561
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200562 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100563 switch (usage->hid) {
564 case HID_DG_INRANGE:
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100565 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100566 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100567 break;
568 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100569 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
570 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100571 td->curdata.touch_state = value;
572 break;
573 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100574 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
575 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100576 break;
577 case HID_DG_CONTACTID:
578 td->curdata.contactid = value;
579 break;
580 case HID_DG_TIPPRESSURE:
581 td->curdata.p = value;
582 break;
583 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100584 if (usage->code == ABS_MT_TOOL_X)
585 td->curdata.cx = value;
586 else
587 td->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100588 break;
589 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100590 if (usage->code == ABS_MT_TOOL_Y)
591 td->curdata.cy = value;
592 else
593 td->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100594 break;
595 case HID_DG_WIDTH:
596 td->curdata.w = value;
597 break;
598 case HID_DG_HEIGHT:
599 td->curdata.h = value;
600 break;
601 case HID_DG_CONTACTCOUNT:
602 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100603 * Includes multi-packet support where subsequent
604 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100605 */
606 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100607 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100608 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100609 case HID_DG_TOUCH:
610 /* do nothing */
611 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100612
613 default:
614 /* fallback to the generic hidinput handling */
615 return 0;
616 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100617
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100618 if (usage->usage_index + 1 == field->report_count) {
619 /* we only take into account the last report. */
620 if (usage->hid == td->last_slot_field)
621 mt_complete_slot(td, field->hidinput->input);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100622
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100623 if (field->index == td->last_field_index
624 && td->num_received >= td->num_expected)
625 mt_sync_frame(td, field->hidinput->input);
626 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100627
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100628 }
629
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100630 /* we have handled the hidinput part, now remains hiddev */
631 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
632 hid->hiddev_hid_event(hid, field, usage, value);
633
634 return 1;
635}
636
637static void mt_set_input_mode(struct hid_device *hdev)
638{
639 struct mt_device *td = hid_get_drvdata(hdev);
640 struct hid_report *r;
641 struct hid_report_enum *re;
642
643 if (td->inputmode < 0)
644 return;
645
646 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
647 r = re->report_id_hash[td->inputmode];
648 if (r) {
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200649 r->field[0]->value[td->inputmode_index] = 0x02;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100650 usbhid_submit_report(hdev, r, USB_DIR_OUT);
651 }
652}
653
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100654static void mt_set_maxcontacts(struct hid_device *hdev)
655{
656 struct mt_device *td = hid_get_drvdata(hdev);
657 struct hid_report *r;
658 struct hid_report_enum *re;
659 int fieldmax, max;
660
661 if (td->maxcontact_report_id < 0)
662 return;
663
664 if (!td->mtclass.maxcontacts)
665 return;
666
667 re = &hdev->report_enum[HID_FEATURE_REPORT];
668 r = re->report_id_hash[td->maxcontact_report_id];
669 if (r) {
670 max = td->mtclass.maxcontacts;
671 fieldmax = r->field[0]->logical_maximum;
672 max = min(fieldmax, max);
673 if (r->field[0]->value[0] != max) {
674 r->field[0]->value[0] = max;
675 usbhid_submit_report(hdev, r, USB_DIR_OUT);
676 }
677 }
678}
679
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200680static void mt_post_parse_default_settings(struct mt_device *td)
681{
682 __s32 quirks = td->mtclass.quirks;
683
684 /* unknown serial device needs special quirks */
685 if (td->touches_by_report == 1) {
686 quirks |= MT_QUIRK_ALWAYS_VALID;
687 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
688 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
689 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
690 }
691
692 td->mtclass.quirks = quirks;
693}
694
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200695static void mt_post_parse(struct mt_device *td)
696{
697 struct mt_fields *f = td->fields;
698
699 if (td->touches_by_report > 0) {
700 int field_count_per_touch = f->length / td->touches_by_report;
701 td->last_slot_field = f->usages[field_count_per_touch - 1];
702 }
703}
704
Henrik Rydberg76f59022012-09-01 20:11:34 +0200705static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
706
707{
708 struct mt_device *td = hid_get_drvdata(hdev);
709 struct mt_class *cls = &td->mtclass;
710 struct input_dev *input = hi->input;
711
712 /* Only initialize slots for MT input devices */
713 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
714 return;
715
716 if (!td->maxcontacts)
717 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
718
719 mt_post_parse(td);
720 if (td->serial_maybe)
721 mt_post_parse_default_settings(td);
722
723 if (cls->is_indirect)
724 td->mt_flags |= INPUT_MT_POINTER;
725
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200726 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
727 td->mt_flags |= INPUT_MT_DROP_UNUSED;
728
Henrik Rydberg76f59022012-09-01 20:11:34 +0200729 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
730
731 td->mt_flags = 0;
732}
733
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100734static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
735{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100736 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100737 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100738 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
739
Henrik Rydberg94b5485c2012-08-08 21:45:50 +0200740 for (i = 0; mt_classes[i].name ; i++) {
741 if (id->driver_data == mt_classes[i].name) {
742 mtclass = &(mt_classes[i]);
743 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100744 }
745 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100746
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100747 /* This allows the driver to correctly support devices
748 * that emit events over several HID messages.
749 */
750 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100751
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100752 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100753 if (!td) {
754 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
755 return -ENOMEM;
756 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100757 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100758 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100759 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100760 hid_set_drvdata(hdev, td);
761
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200762 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
763 if (!td->fields) {
764 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
765 ret = -ENOMEM;
766 goto fail;
767 }
768
Henrik Rydberg76f59022012-09-01 20:11:34 +0200769 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
770 td->serial_maybe = true;
771
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100772 ret = hid_parse(hdev);
773 if (ret != 0)
774 goto fail;
775
776 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100777 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100778 goto fail;
779
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100780 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
781
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100782 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100783 mt_set_input_mode(hdev);
784
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200785 kfree(td->fields);
786 td->fields = NULL;
787
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100788 return 0;
789
790fail:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200791 kfree(td->fields);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100792 kfree(td);
793 return ret;
794}
795
796#ifdef CONFIG_PM
797static int mt_reset_resume(struct hid_device *hdev)
798{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100799 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100800 mt_set_input_mode(hdev);
801 return 0;
802}
Scott Liudfeefd12012-08-15 17:21:55 +0800803
804static int mt_resume(struct hid_device *hdev)
805{
806 struct usb_interface *intf;
807 struct usb_host_interface *interface;
808 struct usb_device *dev;
809
810 if (hdev->bus != BUS_USB)
811 return 0;
812
813 intf = to_usb_interface(hdev->dev.parent);
814 interface = intf->cur_altsetting;
815 dev = hid_to_usb_dev(hdev);
816
817 /* Some Elan legacy devices require SET_IDLE to be set on resume.
818 * It should be safe to send it to other devices too.
819 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
820
821 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
822 HID_REQ_SET_IDLE,
823 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
824 0, interface->desc.bInterfaceNumber,
825 NULL, 0, USB_CTRL_SET_TIMEOUT);
826
827 return 0;
828}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100829#endif
830
831static void mt_remove(struct hid_device *hdev)
832{
833 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100834 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100835 hid_hw_stop(hdev);
836 kfree(td);
837 hid_set_drvdata(hdev, NULL);
838}
839
840static const struct hid_device_id mt_devices[] = {
841
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100842 /* 3M panels */
843 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200844 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100845 USB_DEVICE_ID_3M1968) },
846 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200847 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100848 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100849 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200850 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100851 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100852
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200853 /* ActionStar panels */
854 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200855 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200856 USB_DEVICE_ID_ACTIONSTAR_1011) },
857
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100858 /* Atmel panels */
859 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200860 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100861 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100862 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200863 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100864 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100865
Jiri Kosina9ed32692012-04-20 12:15:44 +0200866 /* Baanto multitouch devices */
867 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina16b79bb2012-05-05 23:32:54 +0200868 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +0200869 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100870 /* Cando panels */
871 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200872 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100873 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
874 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200875 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100876 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
877 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200878 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100879 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
880 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200881 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100882 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
883
Austin Zhang942fd422011-05-28 02:03:47 +0800884 /* Chunghwa Telecom touch panels */
885 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200886 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +0800887 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
888
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200889 /* CVTouch panels */
890 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200891 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200892 USB_DEVICE_ID_CVTOUCH_SCREEN) },
893
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100894 /* Cypress panel */
895 { .driver_data = MT_CLS_CYPRESS,
896 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
897 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
898
Benjamin Tissoires22408282011-05-20 15:59:34 +0200899 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100900 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200901 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100902 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
903 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200904 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100905 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200906
907 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100908 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200909 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100910 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100911 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200912 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100913 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
914 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200915 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100916 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
917 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200918 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100919 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100920 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200921 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100922 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100923 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200924 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100925 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100926 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200927 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100928 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100929 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200930 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100931 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100932 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200933 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100934 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100935 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200936 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100937 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
938 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200939 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100940 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100941 { .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_7349) },
944 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200945 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +0200946 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
947 { .driver_data = MT_CLS_EGALAX_SERIAL,
948 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100949 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Jiri Kosina3d771042012-08-15 10:01:01 +0200950 { .driver_data = MT_CLS_EGALAX,
951 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
952 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
953 { .driver_data = MT_CLS_EGALAX,
954 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
955 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
956 { .driver_data = MT_CLS_EGALAX,
957 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
958 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200959
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200960 /* Elo TouchSystems IntelliTouch Plus panel */
961 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200962 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200963 USB_DEVICE_ID_ELO_TS2515) },
964
Henrik Rydberg77723e32012-09-07 19:37:40 +0200965 /* Flatfrog Panels */
966 { .driver_data = MT_CLS_FLATFROG,
967 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
968 USB_DEVICE_ID_MULTITOUCH_3200) },
969
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100970 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800971 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200972 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100973 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800974 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
975 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
976 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100977
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100978 /* Gametel game controller */
979 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200980 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100981 USB_DEVICE_ID_GAMETEL_MT_MODE) },
982
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200983 /* GoodTouch panels */
984 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200985 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200986 USB_DEVICE_ID_GOODTOUCH_000f) },
987
Benjamin Tissoires54580362011-11-29 13:13:12 +0100988 /* Hanvon panels */
989 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200990 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +0100991 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
992
Stephane Chattya062cc52011-09-17 22:27:30 +0200993 /* Ideacom panel */
994 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200995 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Stephane Chattya062cc52011-09-17 22:27:30 +0200996 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +0100997 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200998 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Benjamin Tissoires71078b02012-03-06 10:53:46 +0100999 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +02001000
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001001 /* Ilitek dual touch panel */
1002 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001003 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001004 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1005
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001006 /* IRTOUCH panels */
1007 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001008 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001009 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1010
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001011 /* LG Display panels */
1012 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001013 MT_USB_DEVICE(USB_VENDOR_ID_LG,
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001014 USB_DEVICE_ID_LG_MULTITOUCH) },
1015
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001016 /* Lumio panels */
1017 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001018 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001019 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001020 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001021 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001022 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001023
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001024 /* MosArt panels */
1025 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001026 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001027 USB_DEVICE_ID_ASUS_T91MT)},
1028 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001029 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001030 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1031 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001032 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001033 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1034
Denis Kovalev2258e862012-02-14 00:50:33 -08001035 /* Panasonic panels */
1036 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001037 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001038 USB_DEVICE_ID_PANABOARD_UBT780) },
1039 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001040 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001041 USB_DEVICE_ID_PANABOARD_UBT880) },
1042
Austin Hendrix4db703e2012-06-04 15:27:51 -07001043 /* Novatek Panel */
1044 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina4380d812012-06-06 16:28:33 +02001045 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001046 USB_DEVICE_ID_NOVATEK_PCT) },
1047
John Sung6ab3a9a2011-04-21 16:21:52 +02001048 /* PenMount panels */
1049 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001050 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
John Sung6ab3a9a2011-04-21 16:21:52 +02001051 USB_DEVICE_ID_PENMOUNT_PCI) },
1052
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001053 /* PixArt optical touch screen */
1054 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001055 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001056 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1057 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001058 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001059 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1060 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001061 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001062 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1063
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001064 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001065 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001066 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001067 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001068 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001069 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001070 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1071
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001072 /* Quanta-based panels */
1073 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001074 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001075 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1076 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001077 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001078 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1079 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001080 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001081 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1082
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001083 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001084 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001085 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001086 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001087 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001088 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001089 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001090 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001091 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001092 USB_DEVICE_ID_MTP_SITRONIX)},
1093
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001094 /* TopSeed panels */
1095 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001096 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001097 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1098
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001099 /* Touch International panels */
1100 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001101 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001102 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1103
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001104 /* Unitec panels */
1105 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001106 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001107 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1108 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001109 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001110 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +08001111 /* XAT */
1112 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001113 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001114 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001115
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001116 /* Xiroku */
1117 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001118 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001119 USB_DEVICE_ID_XIROKU_SPX) },
1120 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001121 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001122 USB_DEVICE_ID_XIROKU_MPX) },
1123 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001124 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001125 USB_DEVICE_ID_XIROKU_CSR) },
1126 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001127 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001128 USB_DEVICE_ID_XIROKU_SPX1) },
1129 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001130 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001131 USB_DEVICE_ID_XIROKU_MPX1) },
1132 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001133 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001134 USB_DEVICE_ID_XIROKU_CSR1) },
1135 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001136 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001137 USB_DEVICE_ID_XIROKU_SPX2) },
1138 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001139 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001140 USB_DEVICE_ID_XIROKU_MPX2) },
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_CSR2) },
1144
Benjamin Tissoires82d06982012-06-19 14:39:54 +02001145 /* Zytronic panels */
1146 { .driver_data = MT_CLS_SERIAL,
1147 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1148 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1149
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001150 /* Generic MT device */
1151 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001152 { }
1153};
1154MODULE_DEVICE_TABLE(hid, mt_devices);
1155
1156static const struct hid_usage_id mt_grabbed_usages[] = {
1157 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1158 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1159};
1160
1161static struct hid_driver mt_driver = {
1162 .name = "hid-multitouch",
1163 .id_table = mt_devices,
1164 .probe = mt_probe,
1165 .remove = mt_remove,
1166 .input_mapping = mt_input_mapping,
1167 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001168 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001169 .feature_mapping = mt_feature_mapping,
1170 .usage_table = mt_grabbed_usages,
1171 .event = mt_event,
1172#ifdef CONFIG_PM
1173 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001174 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001175#endif
1176};
1177
1178static int __init mt_init(void)
1179{
1180 return hid_register_driver(&mt_driver);
1181}
1182
1183static void __exit mt_exit(void)
1184{
1185 hid_unregister_driver(&mt_driver);
1186}
1187
1188module_init(mt_init);
1189module_exit(mt_exit);