blob: a2963b238fde1d25fd9f10b3cd00974992ff900d [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 Tissoires5519cab2011-01-07 23:45:50 +010055
56struct mt_slot {
Benjamin Tissoires349fd6702012-11-14 16:59:19 +010057 __s32 x, y, cx, cy, p, w, h;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010058 __s32 contactid; /* the device ContactID assigned to this slot */
59 bool touch_state; /* is the touch valid? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010060};
61
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010062struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010063 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010064 __s32 quirks;
65 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010066 __s32 sn_width; /* Signal/noise ratio for width events */
67 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010068 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
69 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +010070 bool is_indirect; /* true for touchpads */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010071};
72
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020073struct mt_fields {
74 unsigned usages[HID_MAX_FIELDS];
75 unsigned int length;
76};
77
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010078struct mt_device {
79 struct mt_slot curdata; /* placeholder of incoming data */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +010080 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020081 struct mt_fields *fields; /* temporary placeholder for storing the
82 multitouch fields */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010083 unsigned last_field_index; /* last field index of the report */
84 unsigned last_slot_field; /* the last field of a slot */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010085 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires4aceed32012-06-19 14:39:52 +020086 __s8 inputmode_index; /* InputMode HID feature index in the report */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010087 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
88 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010089 __u8 num_received; /* how many contacts we received */
90 __u8 num_expected; /* expected last contact index */
91 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010092 __u8 touches_by_report; /* how many touches are present in one report:
93 * 1 means we should use a serial protocol
94 * > 1 means hybrid (multitouch) protocol */
Henrik Rydberg76f59022012-09-01 20:11:34 +020095 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010096 bool curvalid; /* is the current contact valid? */
Henrik Rydberg76f59022012-09-01 20:11:34 +020097 unsigned mt_flags; /* flags to pass to input-mt */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010098};
99
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100100/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200101#define MT_CLS_DEFAULT 0x0001
102
Stephane Chattya062cc52011-09-17 22:27:30 +0200103#define MT_CLS_SERIAL 0x0002
104#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100105#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
106#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
107#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
108#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
109#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800110#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200111
112/* vendor specific classes */
113#define MT_CLS_3M 0x0101
114#define MT_CLS_CYPRESS 0x0102
115#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100116#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100117#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800118#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200119#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200120#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
121#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100122
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100123#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100124#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100125
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200126#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
127#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
128
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100129/*
130 * these device-dependent functions determine what slot corresponds
131 * to a valid contact that was just read.
132 */
133
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100134static int cypress_compute_slot(struct mt_device *td)
135{
136 if (td->curdata.contactid != 0 || td->num_received == 0)
137 return td->curdata.contactid;
138 else
139 return -1;
140}
141
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100142static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100143 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100144 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200145 { .name = MT_CLS_SERIAL,
146 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200147 { .name = MT_CLS_CONFIDENCE,
148 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100149 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
150 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
151 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200152 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
153 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
154 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100155 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100156 .quirks = MT_QUIRK_VALID_IS_INRANGE |
157 MT_QUIRK_SLOT_IS_CONTACTID,
158 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100159 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100160 .quirks = MT_QUIRK_VALID_IS_INRANGE |
161 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
162 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200163 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
164 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
165 MT_QUIRK_SLOT_IS_CONTACTID,
166 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800167 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
168 .quirks = MT_QUIRK_VALID_IS_INRANGE |
169 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200170
171 /*
172 * vendor specific classes
173 */
174 { .name = MT_CLS_3M,
175 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
176 MT_QUIRK_SLOT_IS_CONTACTID,
177 .sn_move = 2048,
178 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200179 .sn_height = 128,
180 .maxcontacts = 60,
181 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100182 { .name = MT_CLS_CYPRESS,
183 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
184 MT_QUIRK_CYPRESS,
185 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100186 { .name = MT_CLS_EGALAX,
187 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100188 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100189 .sn_move = 4096,
190 .sn_pressure = 32,
191 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100192 { .name = MT_CLS_EGALAX_SERIAL,
193 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
194 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100195 .sn_move = 4096,
196 .sn_pressure = 32,
197 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100198 { .name = MT_CLS_TOPSEED,
199 .quirks = MT_QUIRK_ALWAYS_VALID,
200 .is_indirect = true,
201 .maxcontacts = 2,
202 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800203 { .name = MT_CLS_PANASONIC,
204 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
205 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800206 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
207 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
208 MT_QUIRK_VALID_IS_INRANGE |
209 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
210 .maxcontacts = 2
211 },
212 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
213 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Xianhan Yu58ad34b2012-10-29 23:04:37 +0800214 MT_QUIRK_SLOT_IS_CONTACTNUMBER
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800215 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100216
Henrik Rydberg77723e32012-09-07 19:37:40 +0200217 { .name = MT_CLS_FLATFROG,
218 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
219 MT_QUIRK_NO_AREA,
220 .sn_move = 2048,
221 .maxcontacts = 40,
222 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100223 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100224};
225
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100226static ssize_t mt_show_quirks(struct device *dev,
227 struct device_attribute *attr,
228 char *buf)
229{
230 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
231 struct mt_device *td = hid_get_drvdata(hdev);
232
233 return sprintf(buf, "%u\n", td->mtclass.quirks);
234}
235
236static ssize_t mt_set_quirks(struct device *dev,
237 struct device_attribute *attr,
238 const char *buf, size_t count)
239{
240 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
241 struct mt_device *td = hid_get_drvdata(hdev);
242
243 unsigned long val;
244
245 if (kstrtoul(buf, 0, &val))
246 return -EINVAL;
247
248 td->mtclass.quirks = val;
249
250 return count;
251}
252
253static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
254
255static struct attribute *sysfs_attrs[] = {
256 &dev_attr_quirks.attr,
257 NULL
258};
259
260static struct attribute_group mt_attribute_group = {
261 .attrs = sysfs_attrs
262};
263
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100264static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100265 struct hid_field *field, struct hid_usage *usage)
266{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100267 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200268 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100269
270 switch (usage->hid) {
271 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100272 td->inputmode = field->report->id;
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200273 td->inputmode_index = 0; /* has to be updated below */
274
275 for (i=0; i < field->maxusage; i++) {
276 if (field->usage[i].hid == usage->hid) {
277 td->inputmode_index = i;
278 break;
279 }
280 }
281
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100282 break;
283 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100284 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100285 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100286 if (!td->maxcontacts &&
287 field->logical_maximum <= MT_MAX_MAXCONTACT)
288 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100289 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100290 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100291 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100292
293 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100294 }
295}
296
297static void set_abs(struct input_dev *input, unsigned int code,
298 struct hid_field *field, int snratio)
299{
300 int fmin = field->logical_minimum;
301 int fmax = field->logical_maximum;
302 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
303 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100304 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100305}
306
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200307static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100308 struct hid_input *hi)
309{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200310 struct mt_fields *f = td->fields;
311
312 if (f->length >= HID_MAX_FIELDS)
313 return;
314
315 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100316}
317
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100318static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
319 struct hid_field *field, struct hid_usage *usage,
320 unsigned long **bit, int *max)
321{
322 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100323 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100324 int code;
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100325 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100326
Jeff Brown658d4aed592011-08-15 16:44:28 -0700327 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800328 * We need to ignore fields that belong to other collections
329 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700330 if (field->application == HID_DG_TOUCHSCREEN)
Henrik Rydberg76f59022012-09-01 20:11:34 +0200331 td->mt_flags |= INPUT_MT_DIRECT;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100332 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700333 return 0;
334
Henrik Rydberg76f59022012-09-01 20:11:34 +0200335 /*
336 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100337 */
338 if (field->application == HID_DG_TOUCHPAD ||
Henrik Rydberg76f59022012-09-01 20:11:34 +0200339 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
340 td->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100341
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100342 /* eGalax devices provide a Digitizer.Stylus input which overrides
343 * the correct Digitizers.Finger X/Y ranges.
344 * Let's just ignore this input. */
345 if (field->physical == HID_DG_STYLUS)
346 return -1;
347
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100348 if (usage->usage_index)
349 prev_usage = &field->usage[usage->usage_index - 1];
350
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100351 switch (usage->hid & HID_USAGE_PAGE) {
352
353 case HID_UP_GENDESK:
354 switch (usage->hid) {
355 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100356 if (prev_usage && (prev_usage->hid == usage->hid)) {
357 hid_map_usage(hi, usage, bit, max,
358 EV_ABS, ABS_MT_TOOL_X);
359 set_abs(hi->input, ABS_MT_TOOL_X, field,
360 cls->sn_move);
361 } else {
362 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100363 EV_ABS, ABS_MT_POSITION_X);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100364 set_abs(hi->input, ABS_MT_POSITION_X, field,
365 cls->sn_move);
366 }
367
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200368 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100369 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100370 return 1;
371 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100372 if (prev_usage && (prev_usage->hid == usage->hid)) {
373 hid_map_usage(hi, usage, bit, max,
374 EV_ABS, ABS_MT_TOOL_Y);
375 set_abs(hi->input, ABS_MT_TOOL_Y, field,
376 cls->sn_move);
377 } else {
378 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100379 EV_ABS, ABS_MT_POSITION_Y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100380 set_abs(hi->input, ABS_MT_POSITION_Y, field,
381 cls->sn_move);
382 }
383
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200384 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100385 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100386 return 1;
387 }
388 return 0;
389
390 case HID_UP_DIGITIZER:
391 switch (usage->hid) {
392 case HID_DG_INRANGE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200393 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100394 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100395 return 1;
396 case HID_DG_CONFIDENCE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200397 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100398 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100399 return 1;
400 case HID_DG_TIPSWITCH:
401 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
402 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200403 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100404 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100405 return 1;
406 case HID_DG_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200407 mt_store_field(usage, td, hi);
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200408 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100409 td->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100410 return 1;
411 case HID_DG_WIDTH:
412 hid_map_usage(hi, usage, bit, max,
413 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200414 if (!(cls->quirks & MT_QUIRK_NO_AREA))
415 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
416 cls->sn_width);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200417 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100418 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100419 return 1;
420 case HID_DG_HEIGHT:
421 hid_map_usage(hi, usage, bit, max,
422 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200423 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
424 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
425 cls->sn_height);
426 input_set_abs_params(hi->input,
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100427 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200428 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200429 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100430 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100431 return 1;
432 case HID_DG_TIPPRESSURE:
433 hid_map_usage(hi, usage, bit, max,
434 EV_ABS, ABS_MT_PRESSURE);
435 set_abs(hi->input, ABS_MT_PRESSURE, field,
436 cls->sn_pressure);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200437 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100438 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100439 return 1;
440 case HID_DG_CONTACTCOUNT:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100441 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100442 return 1;
443 case HID_DG_CONTACTMAX:
444 /* we don't set td->last_slot_field as contactcount and
445 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100446 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100447 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100448 case HID_DG_TOUCH:
449 /* Legacy devices use TIPSWITCH and not TOUCH.
450 * Let's just ignore this field. */
451 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100452 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100453 /* let hid-input decide for the others */
454 return 0;
455
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100456 case HID_UP_BUTTON:
457 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
458 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
459 input_set_capability(hi->input, EV_KEY, code);
460 return 1;
461
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100462 case 0xff000000:
463 /* we do not want to map these: no input-oriented meaning */
464 return -1;
465 }
466
467 return 0;
468}
469
470static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
471 struct hid_field *field, struct hid_usage *usage,
472 unsigned long **bit, int *max)
473{
474 if (usage->type == EV_KEY || usage->type == EV_ABS)
475 set_bit(usage->type, hi->input->evbit);
476
477 return -1;
478}
479
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200480static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100481{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100482 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100483
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100484 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
485 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100486
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100487 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100488 return cypress_compute_slot(td);
489
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100490 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
491 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100492
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200493 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
494 return td->curdata.contactid - 1;
495
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200496 return input_mt_get_slot_by_key(input, td->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100497}
498
499/*
500 * this function is called when a whole contact has been processed,
501 * so that it can assign it to a slot and store the data there
502 */
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200503static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100504{
505 if (td->curvalid) {
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200506 int slotnum = mt_compute_slot(td, input);
507 struct mt_slot *s = &td->curdata;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100508
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200509 if (slotnum < 0 || slotnum >= td->maxcontacts)
510 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100511
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200512 input_mt_slot(input, slotnum);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100513 input_mt_report_slot_state(input, MT_TOOL_FINGER,
514 s->touch_state);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100515 if (s->touch_state) {
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100516 /* this finger is on the screen */
517 int wide = (s->w > s->h);
518 /* divided by two to match visual scale of touch */
519 int major = max(s->w, s->h) >> 1;
520 int minor = min(s->w, s->h) >> 1;
521
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100522 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
523 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100524 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
525 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100526 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100527 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100528 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
529 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100530 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100531 }
532
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200533 td->num_received++;
534}
535
536/*
537 * this function is called when a whole packet has been received and processed,
538 * so that it can decide what to send to the input layer.
539 */
540static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
541{
Henrik Rydberg76f59022012-09-01 20:11:34 +0200542 input_mt_sync_frame(input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100543 input_sync(input);
544 td->num_received = 0;
545}
546
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100547static int mt_event(struct hid_device *hid, struct hid_field *field,
548 struct hid_usage *usage, __s32 value)
549{
550 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100551 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100552
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200553 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100554 switch (usage->hid) {
555 case HID_DG_INRANGE:
Stephane Chattya062cc52011-09-17 22:27:30 +0200556 if (quirks & MT_QUIRK_ALWAYS_VALID)
557 td->curvalid = true;
558 else if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100559 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100560 break;
561 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100562 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
563 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100564 td->curdata.touch_state = value;
565 break;
566 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100567 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
568 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100569 break;
570 case HID_DG_CONTACTID:
571 td->curdata.contactid = value;
572 break;
573 case HID_DG_TIPPRESSURE:
574 td->curdata.p = value;
575 break;
576 case HID_GD_X:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100577 if (usage->code == ABS_MT_TOOL_X)
578 td->curdata.cx = value;
579 else
580 td->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100581 break;
582 case HID_GD_Y:
Benjamin Tissoires349fd6702012-11-14 16:59:19 +0100583 if (usage->code == ABS_MT_TOOL_Y)
584 td->curdata.cy = value;
585 else
586 td->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100587 break;
588 case HID_DG_WIDTH:
589 td->curdata.w = value;
590 break;
591 case HID_DG_HEIGHT:
592 td->curdata.h = value;
593 break;
594 case HID_DG_CONTACTCOUNT:
595 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100596 * Includes multi-packet support where subsequent
597 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100598 */
599 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100600 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100601 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100602 case HID_DG_TOUCH:
603 /* do nothing */
604 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100605
606 default:
607 /* fallback to the generic hidinput handling */
608 return 0;
609 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100610
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100611 if (usage->usage_index + 1 == field->report_count) {
612 /* we only take into account the last report. */
613 if (usage->hid == td->last_slot_field)
614 mt_complete_slot(td, field->hidinput->input);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100615
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100616 if (field->index == td->last_field_index
617 && td->num_received >= td->num_expected)
618 mt_sync_frame(td, field->hidinput->input);
619 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100620
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100621 }
622
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100623 /* we have handled the hidinput part, now remains hiddev */
624 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
625 hid->hiddev_hid_event(hid, field, usage, value);
626
627 return 1;
628}
629
630static void mt_set_input_mode(struct hid_device *hdev)
631{
632 struct mt_device *td = hid_get_drvdata(hdev);
633 struct hid_report *r;
634 struct hid_report_enum *re;
635
636 if (td->inputmode < 0)
637 return;
638
639 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
640 r = re->report_id_hash[td->inputmode];
641 if (r) {
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200642 r->field[0]->value[td->inputmode_index] = 0x02;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100643 usbhid_submit_report(hdev, r, USB_DIR_OUT);
644 }
645}
646
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100647static void mt_set_maxcontacts(struct hid_device *hdev)
648{
649 struct mt_device *td = hid_get_drvdata(hdev);
650 struct hid_report *r;
651 struct hid_report_enum *re;
652 int fieldmax, max;
653
654 if (td->maxcontact_report_id < 0)
655 return;
656
657 if (!td->mtclass.maxcontacts)
658 return;
659
660 re = &hdev->report_enum[HID_FEATURE_REPORT];
661 r = re->report_id_hash[td->maxcontact_report_id];
662 if (r) {
663 max = td->mtclass.maxcontacts;
664 fieldmax = r->field[0]->logical_maximum;
665 max = min(fieldmax, max);
666 if (r->field[0]->value[0] != max) {
667 r->field[0]->value[0] = max;
668 usbhid_submit_report(hdev, r, USB_DIR_OUT);
669 }
670 }
671}
672
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200673static void mt_post_parse_default_settings(struct mt_device *td)
674{
675 __s32 quirks = td->mtclass.quirks;
676
677 /* unknown serial device needs special quirks */
678 if (td->touches_by_report == 1) {
679 quirks |= MT_QUIRK_ALWAYS_VALID;
680 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
681 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
682 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
683 }
684
685 td->mtclass.quirks = quirks;
686}
687
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200688static void mt_post_parse(struct mt_device *td)
689{
690 struct mt_fields *f = td->fields;
691
692 if (td->touches_by_report > 0) {
693 int field_count_per_touch = f->length / td->touches_by_report;
694 td->last_slot_field = f->usages[field_count_per_touch - 1];
695 }
696}
697
Henrik Rydberg76f59022012-09-01 20:11:34 +0200698static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
699
700{
701 struct mt_device *td = hid_get_drvdata(hdev);
702 struct mt_class *cls = &td->mtclass;
703 struct input_dev *input = hi->input;
704
705 /* Only initialize slots for MT input devices */
706 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
707 return;
708
709 if (!td->maxcontacts)
710 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
711
712 mt_post_parse(td);
713 if (td->serial_maybe)
714 mt_post_parse_default_settings(td);
715
716 if (cls->is_indirect)
717 td->mt_flags |= INPUT_MT_POINTER;
718
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200719 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
720 td->mt_flags |= INPUT_MT_DROP_UNUSED;
721
Henrik Rydberg76f59022012-09-01 20:11:34 +0200722 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
723
724 td->mt_flags = 0;
725}
726
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100727static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
728{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100729 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100730 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100731 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
732
Henrik Rydberg94b5485c2012-08-08 21:45:50 +0200733 for (i = 0; mt_classes[i].name ; i++) {
734 if (id->driver_data == mt_classes[i].name) {
735 mtclass = &(mt_classes[i]);
736 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100737 }
738 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100739
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100740 /* This allows the driver to correctly support devices
741 * that emit events over several HID messages.
742 */
743 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100744
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100745 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100746 if (!td) {
747 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
748 return -ENOMEM;
749 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100750 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100751 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100752 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100753 hid_set_drvdata(hdev, td);
754
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200755 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
756 if (!td->fields) {
757 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
758 ret = -ENOMEM;
759 goto fail;
760 }
761
Henrik Rydberg76f59022012-09-01 20:11:34 +0200762 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
763 td->serial_maybe = true;
764
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100765 ret = hid_parse(hdev);
766 if (ret != 0)
767 goto fail;
768
769 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100770 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100771 goto fail;
772
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100773 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
774
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100775 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100776 mt_set_input_mode(hdev);
777
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200778 kfree(td->fields);
779 td->fields = NULL;
780
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100781 return 0;
782
783fail:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200784 kfree(td->fields);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100785 kfree(td);
786 return ret;
787}
788
789#ifdef CONFIG_PM
790static int mt_reset_resume(struct hid_device *hdev)
791{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100792 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100793 mt_set_input_mode(hdev);
794 return 0;
795}
Scott Liudfeefd12012-08-15 17:21:55 +0800796
797static int mt_resume(struct hid_device *hdev)
798{
799 struct usb_interface *intf;
800 struct usb_host_interface *interface;
801 struct usb_device *dev;
802
803 if (hdev->bus != BUS_USB)
804 return 0;
805
806 intf = to_usb_interface(hdev->dev.parent);
807 interface = intf->cur_altsetting;
808 dev = hid_to_usb_dev(hdev);
809
810 /* Some Elan legacy devices require SET_IDLE to be set on resume.
811 * It should be safe to send it to other devices too.
812 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
813
814 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
815 HID_REQ_SET_IDLE,
816 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
817 0, interface->desc.bInterfaceNumber,
818 NULL, 0, USB_CTRL_SET_TIMEOUT);
819
820 return 0;
821}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100822#endif
823
824static void mt_remove(struct hid_device *hdev)
825{
826 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100827 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100828 hid_hw_stop(hdev);
829 kfree(td);
830 hid_set_drvdata(hdev, NULL);
831}
832
833static const struct hid_device_id mt_devices[] = {
834
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100835 /* 3M panels */
836 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200837 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100838 USB_DEVICE_ID_3M1968) },
839 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200840 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100841 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100842 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200843 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100844 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100845
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200846 /* ActionStar panels */
847 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200848 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200849 USB_DEVICE_ID_ACTIONSTAR_1011) },
850
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100851 /* Atmel panels */
852 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200853 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100854 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100855 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200856 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100857 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100858
Jiri Kosina9ed32692012-04-20 12:15:44 +0200859 /* Baanto multitouch devices */
860 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina16b79bb2012-05-05 23:32:54 +0200861 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +0200862 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100863 /* Cando panels */
864 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200865 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100866 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
867 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200868 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100869 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
870 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200871 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100872 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
873 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200874 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100875 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
876
Austin Zhang942fd422011-05-28 02:03:47 +0800877 /* Chunghwa Telecom touch panels */
878 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200879 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +0800880 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
881
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200882 /* CVTouch panels */
883 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200884 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200885 USB_DEVICE_ID_CVTOUCH_SCREEN) },
886
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100887 /* Cypress panel */
888 { .driver_data = MT_CLS_CYPRESS,
889 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
890 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
891
Benjamin Tissoires22408282011-05-20 15:59:34 +0200892 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100893 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200894 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100895 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
896 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200897 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100898 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200899
900 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100901 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200902 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100903 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100904 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200905 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100906 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
907 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200908 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100909 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
910 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200911 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100912 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100913 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200914 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100915 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100916 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200917 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100918 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100919 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200920 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100921 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100922 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200923 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100924 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100925 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200926 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100927 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100928 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200929 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100930 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
931 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200932 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100933 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100934 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200935 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100936 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
937 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200938 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +0200939 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
940 { .driver_data = MT_CLS_EGALAX_SERIAL,
941 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100942 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Jiri Kosina3d771042012-08-15 10:01:01 +0200943 { .driver_data = MT_CLS_EGALAX,
944 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
945 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
946 { .driver_data = MT_CLS_EGALAX,
947 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
948 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
949 { .driver_data = MT_CLS_EGALAX,
950 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
951 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200952
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200953 /* Elo TouchSystems IntelliTouch Plus panel */
954 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200955 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200956 USB_DEVICE_ID_ELO_TS2515) },
957
Henrik Rydberg77723e32012-09-07 19:37:40 +0200958 /* Flatfrog Panels */
959 { .driver_data = MT_CLS_FLATFROG,
960 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
961 USB_DEVICE_ID_MULTITOUCH_3200) },
962
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100963 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800964 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200965 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100966 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800967 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
968 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
969 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100970
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100971 /* Gametel game controller */
972 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200973 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100974 USB_DEVICE_ID_GAMETEL_MT_MODE) },
975
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200976 /* GoodTouch panels */
977 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200978 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200979 USB_DEVICE_ID_GOODTOUCH_000f) },
980
Benjamin Tissoires54580362011-11-29 13:13:12 +0100981 /* Hanvon panels */
982 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200983 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +0100984 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
985
Stephane Chattya062cc52011-09-17 22:27:30 +0200986 /* Ideacom panel */
987 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200988 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Stephane Chattya062cc52011-09-17 22:27:30 +0200989 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +0100990 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200991 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Benjamin Tissoires71078b02012-03-06 10:53:46 +0100992 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +0200993
Austin Zhang4e61f0d2011-05-09 23:54:14 +0800994 /* Ilitek dual touch panel */
995 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200996 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +0800997 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
998
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +0100999 /* IRTOUCH panels */
1000 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001001 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001002 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1003
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001004 /* LG Display panels */
1005 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001006 MT_USB_DEVICE(USB_VENDOR_ID_LG,
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001007 USB_DEVICE_ID_LG_MULTITOUCH) },
1008
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001009 /* Lumio panels */
1010 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001011 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001012 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001013 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001014 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001015 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001016
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001017 /* MosArt panels */
1018 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001019 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001020 USB_DEVICE_ID_ASUS_T91MT)},
1021 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001022 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001023 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1024 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001025 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001026 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1027
Denis Kovalev2258e862012-02-14 00:50:33 -08001028 /* Panasonic panels */
1029 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001030 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001031 USB_DEVICE_ID_PANABOARD_UBT780) },
1032 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001033 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001034 USB_DEVICE_ID_PANABOARD_UBT880) },
1035
Austin Hendrix4db703e2012-06-04 15:27:51 -07001036 /* Novatek Panel */
1037 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina4380d812012-06-06 16:28:33 +02001038 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001039 USB_DEVICE_ID_NOVATEK_PCT) },
1040
John Sung6ab3a9a2011-04-21 16:21:52 +02001041 /* PenMount panels */
1042 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001043 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
John Sung6ab3a9a2011-04-21 16:21:52 +02001044 USB_DEVICE_ID_PENMOUNT_PCI) },
1045
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001046 /* PixArt optical touch screen */
1047 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001048 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001049 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1050 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001051 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001052 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1053 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001054 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001055 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1056
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001057 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001058 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001059 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001060 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001061 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001062 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001063 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1064
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001065 /* Quanta-based panels */
1066 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001067 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001068 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1069 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001070 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001071 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1072 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001073 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001074 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1075
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001076 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001077 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001078 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001079 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001080 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001081 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001082 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001083 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001084 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001085 USB_DEVICE_ID_MTP_SITRONIX)},
1086
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001087 /* TopSeed panels */
1088 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001089 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001090 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1091
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001092 /* Touch International panels */
1093 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001094 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001095 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1096
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001097 /* Unitec panels */
1098 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001099 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001100 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1101 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001102 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001103 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +08001104 /* XAT */
1105 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001106 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001107 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001108
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001109 /* Xiroku */
1110 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001111 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001112 USB_DEVICE_ID_XIROKU_SPX) },
1113 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001114 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001115 USB_DEVICE_ID_XIROKU_MPX) },
1116 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001117 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001118 USB_DEVICE_ID_XIROKU_CSR) },
1119 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001120 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001121 USB_DEVICE_ID_XIROKU_SPX1) },
1122 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001123 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001124 USB_DEVICE_ID_XIROKU_MPX1) },
1125 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001126 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001127 USB_DEVICE_ID_XIROKU_CSR1) },
1128 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001129 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001130 USB_DEVICE_ID_XIROKU_SPX2) },
1131 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001132 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001133 USB_DEVICE_ID_XIROKU_MPX2) },
1134 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001135 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001136 USB_DEVICE_ID_XIROKU_CSR2) },
1137
Benjamin Tissoires82d06982012-06-19 14:39:54 +02001138 /* Zytronic panels */
1139 { .driver_data = MT_CLS_SERIAL,
1140 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1141 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1142
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001143 /* Generic MT device */
1144 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001145 { }
1146};
1147MODULE_DEVICE_TABLE(hid, mt_devices);
1148
1149static const struct hid_usage_id mt_grabbed_usages[] = {
1150 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1151 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1152};
1153
1154static struct hid_driver mt_driver = {
1155 .name = "hid-multitouch",
1156 .id_table = mt_devices,
1157 .probe = mt_probe,
1158 .remove = mt_remove,
1159 .input_mapping = mt_input_mapping,
1160 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001161 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001162 .feature_mapping = mt_feature_mapping,
1163 .usage_table = mt_grabbed_usages,
1164 .event = mt_event,
1165#ifdef CONFIG_PM
1166 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001167 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001168#endif
1169};
1170
1171static int __init mt_init(void)
1172{
1173 return hid_register_driver(&mt_driver);
1174}
1175
1176static void __exit mt_exit(void)
1177{
1178 hid_unregister_driver(&mt_driver);
1179}
1180
1181module_init(mt_init);
1182module_exit(mt_exit);