blob: 0a04893099052caacd0a14f0a258a13374b61ee5 [file] [log] [blame]
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001/*
2 * HID driver for multitouch panels
3 *
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +01004 * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01007 *
Richard Nauber4875ac12011-03-09 06:20:57 +01008 * This code is partly based on hid-egalax.c:
9 *
10 * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
11 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
12 * Copyright (c) 2010 Canonical, Ltd.
13 *
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010014 * This code is partly based on hid-3m-pct.c:
15 *
16 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
17 * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
18 * Copyright (c) 2010 Canonical, Ltd.
19 *
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010020 */
21
22/*
23 * This program is free software; you can redistribute it and/or modify it
24 * under the terms of the GNU General Public License as published by the Free
25 * Software Foundation; either version 2 of the License, or (at your option)
26 * any later version.
27 */
28
29#include <linux/device.h>
30#include <linux/hid.h>
31#include <linux/module.h>
32#include <linux/slab.h>
33#include <linux/usb.h>
34#include <linux/input/mt.h>
35#include "usbhid/usbhid.h"
36
37
38MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
Benjamin Tissoiresef2fafb2011-01-31 11:28:21 +010039MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010040MODULE_DESCRIPTION("HID multitouch panels");
41MODULE_LICENSE("GPL");
42
43#include "hid-ids.h"
44
45/* quirks to control the device */
46#define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
47#define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
Benjamin Tissoires2d936662011-01-11 16:45:54 +010048#define MT_QUIRK_CYPRESS (1 << 2)
Benjamin Tissoires5572da02011-01-07 23:47:27 +010049#define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
Stephane Chattya062cc52011-09-17 22:27:30 +020050#define MT_QUIRK_ALWAYS_VALID (1 << 4)
51#define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
52#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
Stephane Chattya062cc52011-09-17 22:27:30 +020053#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
Henrik Rydberg77723e32012-09-07 19:37:40 +020054#define MT_QUIRK_NO_AREA (1 << 9)
Benjamin Tissoires28728392012-11-14 16:59:23 +010055#define MT_QUIRK_IGNORE_DUPLICATES (1 << 10)
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +010056#define MT_QUIRK_HOVERING (1 << 11)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010057
58struct mt_slot {
Benjamin Tissoires349fd672012-11-14 16:59:19 +010059 __s32 x, y, cx, cy, p, w, h;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010060 __s32 contactid; /* the device ContactID assigned to this slot */
61 bool touch_state; /* is the touch valid? */
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +010062 bool inrange_state; /* is the finger in proximity of the sensor? */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010063};
64
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010065struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010066 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010067 __s32 quirks;
68 __s32 sn_move; /* Signal/noise ratio for move events */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +010069 __s32 sn_width; /* Signal/noise ratio for width events */
70 __s32 sn_height; /* Signal/noise ratio for height events */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010071 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
72 __u8 maxcontacts;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +010073 bool is_indirect; /* true for touchpads */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010074};
75
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020076struct mt_fields {
77 unsigned usages[HID_MAX_FIELDS];
78 unsigned int length;
79};
80
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010081struct mt_device {
82 struct mt_slot curdata; /* placeholder of incoming data */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +010083 struct mt_class mtclass; /* our mt device class */
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +020084 struct mt_fields *fields; /* temporary placeholder for storing the
85 multitouch fields */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010086 unsigned last_field_index; /* last field index of the report */
87 unsigned last_slot_field; /* the last field of a slot */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010088 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
Benjamin Tissoires4aceed32012-06-19 14:39:52 +020089 __s8 inputmode_index; /* InputMode HID feature index in the report */
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +010090 __s8 maxcontact_report_id; /* Maximum Contact Number HID feature,
91 -1 if non-existent */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010092 __u8 num_received; /* how many contacts we received */
93 __u8 num_expected; /* expected last contact index */
94 __u8 maxcontacts;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +010095 __u8 touches_by_report; /* how many touches are present in one report:
96 * 1 means we should use a serial protocol
97 * > 1 means hybrid (multitouch) protocol */
Henrik Rydberg76f59022012-09-01 20:11:34 +020098 bool serial_maybe; /* need to check for serial protocol */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010099 bool curvalid; /* is the current contact valid? */
Henrik Rydberg76f59022012-09-01 20:11:34 +0200100 unsigned mt_flags; /* flags to pass to input-mt */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100101};
102
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100103/* classes of device behavior */
Benjamin Tissoires22408282011-05-20 15:59:34 +0200104#define MT_CLS_DEFAULT 0x0001
105
Stephane Chattya062cc52011-09-17 22:27:30 +0200106#define MT_CLS_SERIAL 0x0002
107#define MT_CLS_CONFIDENCE 0x0003
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100108#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
109#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
110#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
111#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
112#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800113#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
Benjamin Tissoires22408282011-05-20 15:59:34 +0200114
115/* vendor specific classes */
116#define MT_CLS_3M 0x0101
117#define MT_CLS_CYPRESS 0x0102
118#define MT_CLS_EGALAX 0x0103
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100119#define MT_CLS_EGALAX_SERIAL 0x0104
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100120#define MT_CLS_TOPSEED 0x0105
Denis Kovalev2258e862012-02-14 00:50:33 -0800121#define MT_CLS_PANASONIC 0x0106
Henrik Rydberg77723e32012-09-07 19:37:40 +0200122#define MT_CLS_FLATFROG 0x0107
Jiri Kosinacdcd3ac2012-10-01 14:38:54 +0200123#define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
124#define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100125
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100126#define MT_DEFAULT_MAXCONTACT 10
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100127#define MT_MAX_MAXCONTACT 250
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100128
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200129#define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
130#define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
131
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100132/*
133 * these device-dependent functions determine what slot corresponds
134 * to a valid contact that was just read.
135 */
136
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100137static int cypress_compute_slot(struct mt_device *td)
138{
139 if (td->curdata.contactid != 0 || td->num_received == 0)
140 return td->curdata.contactid;
141 else
142 return -1;
143}
144
Jiri Kosinab3c21d22011-11-22 23:23:37 +0100145static struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100146 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100147 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Stephane Chattya062cc52011-09-17 22:27:30 +0200148 { .name = MT_CLS_SERIAL,
149 .quirks = MT_QUIRK_ALWAYS_VALID},
Benjamin Tissoires22408282011-05-20 15:59:34 +0200150 { .name = MT_CLS_CONFIDENCE,
151 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +0100152 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
153 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
154 MT_QUIRK_SLOT_IS_CONTACTID },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200155 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
156 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
157 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100158 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100159 .quirks = MT_QUIRK_VALID_IS_INRANGE |
160 MT_QUIRK_SLOT_IS_CONTACTID,
161 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100162 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100163 .quirks = MT_QUIRK_VALID_IS_INRANGE |
164 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
165 .maxcontacts = 2 },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200166 { .name = MT_CLS_DUAL_NSMU_CONTACTID,
167 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
168 MT_QUIRK_SLOT_IS_CONTACTID,
169 .maxcontacts = 2 },
Aaron Tianb7ea95f2011-12-15 11:09:06 +0800170 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
171 .quirks = MT_QUIRK_VALID_IS_INRANGE |
172 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200173
174 /*
175 * vendor specific classes
176 */
177 { .name = MT_CLS_3M,
178 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
179 MT_QUIRK_SLOT_IS_CONTACTID,
180 .sn_move = 2048,
181 .sn_width = 128,
Henrik Rydbergc5d40be2012-09-05 16:58:12 +0200182 .sn_height = 128,
183 .maxcontacts = 60,
184 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100185 { .name = MT_CLS_CYPRESS,
186 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
187 MT_QUIRK_CYPRESS,
188 .maxcontacts = 10 },
Richard Nauber4875ac12011-03-09 06:20:57 +0100189 { .name = MT_CLS_EGALAX,
190 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100191 MT_QUIRK_VALID_IS_INRANGE,
Richard Nauber4875ac12011-03-09 06:20:57 +0100192 .sn_move = 4096,
193 .sn_pressure = 32,
194 },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100195 { .name = MT_CLS_EGALAX_SERIAL,
196 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
197 MT_QUIRK_ALWAYS_VALID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100198 .sn_move = 4096,
199 .sn_pressure = 32,
200 },
Benjamin Tissoires847672c2012-02-04 17:08:50 +0100201 { .name = MT_CLS_TOPSEED,
202 .quirks = MT_QUIRK_ALWAYS_VALID,
203 .is_indirect = true,
204 .maxcontacts = 2,
205 },
Denis Kovalev2258e862012-02-14 00:50:33 -0800206 { .name = MT_CLS_PANASONIC,
207 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
208 .maxcontacts = 4 },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800209 { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
210 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
211 MT_QUIRK_VALID_IS_INRANGE |
212 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
213 .maxcontacts = 2
214 },
215 { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
216 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
Xianhan Yu58ad34b2012-10-29 23:04:37 +0800217 MT_QUIRK_SLOT_IS_CONTACTNUMBER
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800218 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100219
Henrik Rydberg77723e32012-09-07 19:37:40 +0200220 { .name = MT_CLS_FLATFROG,
221 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
222 MT_QUIRK_NO_AREA,
223 .sn_move = 2048,
224 .maxcontacts = 40,
225 },
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100226 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100227};
228
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100229static ssize_t mt_show_quirks(struct device *dev,
230 struct device_attribute *attr,
231 char *buf)
232{
233 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
234 struct mt_device *td = hid_get_drvdata(hdev);
235
236 return sprintf(buf, "%u\n", td->mtclass.quirks);
237}
238
239static ssize_t mt_set_quirks(struct device *dev,
240 struct device_attribute *attr,
241 const char *buf, size_t count)
242{
243 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
244 struct mt_device *td = hid_get_drvdata(hdev);
245
246 unsigned long val;
247
248 if (kstrtoul(buf, 0, &val))
249 return -EINVAL;
250
251 td->mtclass.quirks = val;
252
253 return count;
254}
255
256static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
257
258static struct attribute *sysfs_attrs[] = {
259 &dev_attr_quirks.attr,
260 NULL
261};
262
263static struct attribute_group mt_attribute_group = {
264 .attrs = sysfs_attrs
265};
266
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100267static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100268 struct hid_field *field, struct hid_usage *usage)
269{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100270 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200271 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100272
273 switch (usage->hid) {
274 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100275 td->inputmode = field->report->id;
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200276 td->inputmode_index = 0; /* has to be updated below */
277
278 for (i=0; i < field->maxusage; i++) {
279 if (field->usage[i].hid == usage->hid) {
280 td->inputmode_index = i;
281 break;
282 }
283 }
284
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100285 break;
286 case HID_DG_CONTACTMAX:
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100287 td->maxcontact_report_id = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100288 td->maxcontacts = field->value[0];
Benjamin Tissoiresafbcb042012-11-14 16:59:18 +0100289 if (!td->maxcontacts &&
290 field->logical_maximum <= MT_MAX_MAXCONTACT)
291 td->maxcontacts = field->logical_maximum;
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100292 if (td->mtclass.maxcontacts)
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100293 /* check if the maxcontacts is given by the class */
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100294 td->maxcontacts = td->mtclass.maxcontacts;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100295
296 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100297 }
298}
299
300static void set_abs(struct input_dev *input, unsigned int code,
301 struct hid_field *field, int snratio)
302{
303 int fmin = field->logical_minimum;
304 int fmax = field->logical_maximum;
305 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
306 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
Benjamin Tissoires37cf6e62012-11-14 16:59:13 +0100307 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100308}
309
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200310static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100311 struct hid_input *hi)
312{
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200313 struct mt_fields *f = td->fields;
314
315 if (f->length >= HID_MAX_FIELDS)
316 return;
317
318 f->usages[f->length++] = usage->hid;
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100319}
320
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100321static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
322 struct hid_field *field, struct hid_usage *usage,
323 unsigned long **bit, int *max)
324{
325 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100326 struct mt_class *cls = &td->mtclass;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100327 int code;
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100328 struct hid_usage *prev_usage = NULL;
Richard Nauber4875ac12011-03-09 06:20:57 +0100329
Jeff Brown658d4aed592011-08-15 16:44:28 -0700330 /* Only map fields from TouchScreen or TouchPad collections.
Denis Kovalev2258e862012-02-14 00:50:33 -0800331 * We need to ignore fields that belong to other collections
332 * such as Mouse that might have the same GenericDesktop usages. */
Jeff Brown658d4aed592011-08-15 16:44:28 -0700333 if (field->application == HID_DG_TOUCHSCREEN)
Henrik Rydberg76f59022012-09-01 20:11:34 +0200334 td->mt_flags |= INPUT_MT_DIRECT;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100335 else if (field->application != HID_DG_TOUCHPAD)
Jeff Brown658d4aed592011-08-15 16:44:28 -0700336 return 0;
337
Henrik Rydberg76f59022012-09-01 20:11:34 +0200338 /*
339 * Model touchscreens providing buttons as touchpads.
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100340 */
341 if (field->application == HID_DG_TOUCHPAD ||
Henrik Rydberg76f59022012-09-01 20:11:34 +0200342 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
343 td->mt_flags |= INPUT_MT_POINTER;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100344
Benjamin Tissoires2261bb92011-11-23 10:54:29 +0100345 /* eGalax devices provide a Digitizer.Stylus input which overrides
346 * the correct Digitizers.Finger X/Y ranges.
347 * Let's just ignore this input. */
348 if (field->physical == HID_DG_STYLUS)
349 return -1;
350
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100351 if (usage->usage_index)
352 prev_usage = &field->usage[usage->usage_index - 1];
353
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100354 switch (usage->hid & HID_USAGE_PAGE) {
355
356 case HID_UP_GENDESK:
357 switch (usage->hid) {
358 case HID_GD_X:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100359 if (prev_usage && (prev_usage->hid == usage->hid)) {
360 hid_map_usage(hi, usage, bit, max,
361 EV_ABS, ABS_MT_TOOL_X);
362 set_abs(hi->input, ABS_MT_TOOL_X, field,
363 cls->sn_move);
364 } else {
365 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100366 EV_ABS, ABS_MT_POSITION_X);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100367 set_abs(hi->input, ABS_MT_POSITION_X, field,
368 cls->sn_move);
369 }
370
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200371 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100372 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100373 return 1;
374 case HID_GD_Y:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100375 if (prev_usage && (prev_usage->hid == usage->hid)) {
376 hid_map_usage(hi, usage, bit, max,
377 EV_ABS, ABS_MT_TOOL_Y);
378 set_abs(hi->input, ABS_MT_TOOL_Y, field,
379 cls->sn_move);
380 } else {
381 hid_map_usage(hi, usage, bit, max,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100382 EV_ABS, ABS_MT_POSITION_Y);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100383 set_abs(hi->input, ABS_MT_POSITION_Y, field,
384 cls->sn_move);
385 }
386
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200387 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100388 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100389 return 1;
390 }
391 return 0;
392
393 case HID_UP_DIGITIZER:
394 switch (usage->hid) {
395 case HID_DG_INRANGE:
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100396 if (cls->quirks & MT_QUIRK_HOVERING) {
397 hid_map_usage(hi, usage, bit, max,
398 EV_ABS, ABS_MT_DISTANCE);
399 input_set_abs_params(hi->input,
400 ABS_MT_DISTANCE, 0, 1, 0, 0);
401 }
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200402 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100403 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100404 return 1;
405 case HID_DG_CONFIDENCE:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200406 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100407 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100408 return 1;
409 case HID_DG_TIPSWITCH:
410 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
411 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200412 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100413 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100414 return 1;
415 case HID_DG_CONTACTID:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200416 mt_store_field(usage, td, hi);
Benjamin Tissoires2955cae2011-04-21 14:15:59 +0200417 td->last_field_index = field->index;
Benjamin Tissoires9e87f222012-03-06 17:57:06 +0100418 td->touches_by_report++;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100419 return 1;
420 case HID_DG_WIDTH:
421 hid_map_usage(hi, usage, bit, max,
422 EV_ABS, ABS_MT_TOUCH_MAJOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200423 if (!(cls->quirks & MT_QUIRK_NO_AREA))
424 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
425 cls->sn_width);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200426 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100427 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100428 return 1;
429 case HID_DG_HEIGHT:
430 hid_map_usage(hi, usage, bit, max,
431 EV_ABS, ABS_MT_TOUCH_MINOR);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200432 if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
433 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
434 cls->sn_height);
435 input_set_abs_params(hi->input,
Benjamin Tissoires1e648a12011-03-18 14:27:55 +0100436 ABS_MT_ORIENTATION, 0, 1, 0, 0);
Henrik Rydberg77723e32012-09-07 19:37:40 +0200437 }
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_TIPPRESSURE:
442 hid_map_usage(hi, usage, bit, max,
443 EV_ABS, ABS_MT_PRESSURE);
444 set_abs(hi->input, ABS_MT_PRESSURE, field,
445 cls->sn_pressure);
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200446 mt_store_field(usage, td, hi);
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100447 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100448 return 1;
449 case HID_DG_CONTACTCOUNT:
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100450 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100451 return 1;
452 case HID_DG_CONTACTMAX:
453 /* we don't set td->last_slot_field as contactcount and
454 * contact max are global to the report */
Benjamin Tissoiresed9d5c92012-03-06 17:57:03 +0100455 td->last_field_index = field->index;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100456 return -1;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100457 case HID_DG_TOUCH:
458 /* Legacy devices use TIPSWITCH and not TOUCH.
459 * Let's just ignore this field. */
460 return -1;
Alan Cox65b258e2012-10-25 15:35:25 +0100461 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100462 /* let hid-input decide for the others */
463 return 0;
464
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100465 case HID_UP_BUTTON:
466 code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
467 hid_map_usage(hi, usage, bit, max, EV_KEY, code);
468 input_set_capability(hi->input, EV_KEY, code);
469 return 1;
470
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100471 case 0xff000000:
472 /* we do not want to map these: no input-oriented meaning */
473 return -1;
474 }
475
476 return 0;
477}
478
479static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
480 struct hid_field *field, struct hid_usage *usage,
481 unsigned long **bit, int *max)
482{
483 if (usage->type == EV_KEY || usage->type == EV_ABS)
484 set_bit(usage->type, hi->input->evbit);
485
486 return -1;
487}
488
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200489static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100490{
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100491 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100492
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100493 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
494 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100495
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100496 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100497 return cypress_compute_slot(td);
498
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100499 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
500 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100501
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +0200502 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
503 return td->curdata.contactid - 1;
504
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200505 return input_mt_get_slot_by_key(input, td->curdata.contactid);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100506}
507
508/*
509 * this function is called when a whole contact has been processed,
510 * so that it can assign it to a slot and store the data there
511 */
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200512static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100513{
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100514 if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200515 int slotnum = mt_compute_slot(td, input);
516 struct mt_slot *s = &td->curdata;
Benjamin Tissoires28728392012-11-14 16:59:23 +0100517 struct input_mt *mt = input->mt;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100518
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200519 if (slotnum < 0 || slotnum >= td->maxcontacts)
520 return;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100521
Benjamin Tissoires28728392012-11-14 16:59:23 +0100522 if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
523 struct input_mt_slot *slot = &mt->slots[slotnum];
524 if (input_mt_is_active(slot) &&
525 input_mt_is_used(mt, slot))
526 return;
527 }
528
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200529 input_mt_slot(input, slotnum);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100530 input_mt_report_slot_state(input, MT_TOOL_FINGER,
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100531 s->touch_state || s->inrange_state);
532 if (s->touch_state || s->inrange_state) {
533 /* this finger is in proximity of the sensor */
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100534 int wide = (s->w > s->h);
535 /* divided by two to match visual scale of touch */
536 int major = max(s->w, s->h) >> 1;
537 int minor = min(s->w, s->h) >> 1;
538
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100539 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
540 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100541 input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
542 input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100543 input_event(input, EV_ABS, ABS_MT_DISTANCE,
544 !s->touch_state);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100545 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100546 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100547 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
548 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100549 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100550 }
551
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200552 td->num_received++;
553}
554
555/*
556 * this function is called when a whole packet has been received and processed,
557 * so that it can decide what to send to the input layer.
558 */
559static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
560{
Henrik Rydberg76f59022012-09-01 20:11:34 +0200561 input_mt_sync_frame(input);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100562 input_sync(input);
563 td->num_received = 0;
564}
565
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100566static int mt_event(struct hid_device *hid, struct hid_field *field,
567 struct hid_usage *usage, __s32 value)
568{
569 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100570 __s32 quirks = td->mtclass.quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100571
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200572 if (hid->claimed & HID_CLAIMED_INPUT) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100573 switch (usage->hid) {
574 case HID_DG_INRANGE:
Benjamin Tissoires20b60e62012-11-14 16:59:20 +0100575 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100576 td->curvalid = value;
Benjamin Tissoires9b3bb9b2012-11-14 16:59:24 +0100577 if (quirks & MT_QUIRK_HOVERING)
578 td->curdata.inrange_state = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100579 break;
580 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100581 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
582 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100583 td->curdata.touch_state = value;
584 break;
585 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100586 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
587 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100588 break;
589 case HID_DG_CONTACTID:
590 td->curdata.contactid = value;
591 break;
592 case HID_DG_TIPPRESSURE:
593 td->curdata.p = value;
594 break;
595 case HID_GD_X:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100596 if (usage->code == ABS_MT_TOOL_X)
597 td->curdata.cx = value;
598 else
599 td->curdata.x = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100600 break;
601 case HID_GD_Y:
Benjamin Tissoires349fd672012-11-14 16:59:19 +0100602 if (usage->code == ABS_MT_TOOL_Y)
603 td->curdata.cy = value;
604 else
605 td->curdata.y = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100606 break;
607 case HID_DG_WIDTH:
608 td->curdata.w = value;
609 break;
610 case HID_DG_HEIGHT:
611 td->curdata.h = value;
612 break;
613 case HID_DG_CONTACTCOUNT:
614 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100615 * Includes multi-packet support where subsequent
616 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100617 */
618 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100619 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100620 break;
Benjamin Tissoiresc2ef8f22012-02-04 17:08:48 +0100621 case HID_DG_TOUCH:
622 /* do nothing */
623 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100624
625 default:
626 /* fallback to the generic hidinput handling */
627 return 0;
628 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100629
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100630 if (usage->usage_index + 1 == field->report_count) {
631 /* we only take into account the last report. */
632 if (usage->hid == td->last_slot_field)
633 mt_complete_slot(td, field->hidinput->input);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100634
Benjamin Tissoires54f4c0c2012-11-14 16:59:17 +0100635 if (field->index == td->last_field_index
636 && td->num_received >= td->num_expected)
637 mt_sync_frame(td, field->hidinput->input);
638 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100639
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100640 }
641
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100642 /* we have handled the hidinput part, now remains hiddev */
643 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
644 hid->hiddev_hid_event(hid, field, usage, value);
645
646 return 1;
647}
648
649static void mt_set_input_mode(struct hid_device *hdev)
650{
651 struct mt_device *td = hid_get_drvdata(hdev);
652 struct hid_report *r;
653 struct hid_report_enum *re;
654
655 if (td->inputmode < 0)
656 return;
657
658 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
659 r = re->report_id_hash[td->inputmode];
660 if (r) {
Benjamin Tissoires4aceed32012-06-19 14:39:52 +0200661 r->field[0]->value[td->inputmode_index] = 0x02;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100662 usbhid_submit_report(hdev, r, USB_DIR_OUT);
663 }
664}
665
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100666static void mt_set_maxcontacts(struct hid_device *hdev)
667{
668 struct mt_device *td = hid_get_drvdata(hdev);
669 struct hid_report *r;
670 struct hid_report_enum *re;
671 int fieldmax, max;
672
673 if (td->maxcontact_report_id < 0)
674 return;
675
676 if (!td->mtclass.maxcontacts)
677 return;
678
679 re = &hdev->report_enum[HID_FEATURE_REPORT];
680 r = re->report_id_hash[td->maxcontact_report_id];
681 if (r) {
682 max = td->mtclass.maxcontacts;
683 fieldmax = r->field[0]->logical_maximum;
684 max = min(fieldmax, max);
685 if (r->field[0]->value[0] != max) {
686 r->field[0]->value[0] = max;
687 usbhid_submit_report(hdev, r, USB_DIR_OUT);
688 }
689 }
690}
691
Henrik Rydberg4fa3a582012-05-01 08:40:01 +0200692static void mt_post_parse_default_settings(struct mt_device *td)
693{
694 __s32 quirks = td->mtclass.quirks;
695
696 /* unknown serial device needs special quirks */
697 if (td->touches_by_report == 1) {
698 quirks |= MT_QUIRK_ALWAYS_VALID;
699 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
700 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
701 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
702 }
703
704 td->mtclass.quirks = quirks;
705}
706
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200707static void mt_post_parse(struct mt_device *td)
708{
709 struct mt_fields *f = td->fields;
710
711 if (td->touches_by_report > 0) {
712 int field_count_per_touch = f->length / td->touches_by_report;
713 td->last_slot_field = f->usages[field_count_per_touch - 1];
714 }
715}
716
Henrik Rydberg76f59022012-09-01 20:11:34 +0200717static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
718
719{
720 struct mt_device *td = hid_get_drvdata(hdev);
721 struct mt_class *cls = &td->mtclass;
722 struct input_dev *input = hi->input;
723
724 /* Only initialize slots for MT input devices */
725 if (!test_bit(ABS_MT_POSITION_X, input->absbit))
726 return;
727
728 if (!td->maxcontacts)
729 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
730
731 mt_post_parse(td);
732 if (td->serial_maybe)
733 mt_post_parse_default_settings(td);
734
735 if (cls->is_indirect)
736 td->mt_flags |= INPUT_MT_POINTER;
737
Henrik Rydberg3e1b5012012-09-01 19:46:58 +0200738 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
739 td->mt_flags |= INPUT_MT_DROP_UNUSED;
740
Henrik Rydberg76f59022012-09-01 20:11:34 +0200741 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
742
743 td->mt_flags = 0;
744}
745
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100746static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
747{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100748 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100749 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100750 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
751
Henrik Rydberg94b54852012-08-08 21:45:50 +0200752 for (i = 0; mt_classes[i].name ; i++) {
753 if (id->driver_data == mt_classes[i].name) {
754 mtclass = &(mt_classes[i]);
755 break;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100756 }
757 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100758
Henrik Rydbergd682bd72011-11-01 15:26:31 +0100759 /* This allows the driver to correctly support devices
760 * that emit events over several HID messages.
761 */
762 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100763
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100764 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100765 if (!td) {
766 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
767 return -ENOMEM;
768 }
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100769 td->mtclass = *mtclass;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100770 td->inputmode = -1;
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100771 td->maxcontact_report_id = -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100772 hid_set_drvdata(hdev, td);
773
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200774 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL);
775 if (!td->fields) {
776 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
777 ret = -ENOMEM;
778 goto fail;
779 }
780
Henrik Rydberg76f59022012-09-01 20:11:34 +0200781 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
782 td->serial_maybe = true;
783
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100784 ret = hid_parse(hdev);
785 if (ret != 0)
786 goto fail;
787
788 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100789 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100790 goto fail;
791
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100792 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
793
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100794 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100795 mt_set_input_mode(hdev);
796
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200797 kfree(td->fields);
798 td->fields = NULL;
799
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100800 return 0;
801
802fail:
Benjamin Tissoires3ac36d12012-05-04 14:53:46 +0200803 kfree(td->fields);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100804 kfree(td);
805 return ret;
806}
807
808#ifdef CONFIG_PM
809static int mt_reset_resume(struct hid_device *hdev)
810{
Benjamin Tissoires31ae9bd2012-02-04 17:08:49 +0100811 mt_set_maxcontacts(hdev);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100812 mt_set_input_mode(hdev);
813 return 0;
814}
Scott Liudfeefd12012-08-15 17:21:55 +0800815
816static int mt_resume(struct hid_device *hdev)
817{
818 struct usb_interface *intf;
819 struct usb_host_interface *interface;
820 struct usb_device *dev;
821
822 if (hdev->bus != BUS_USB)
823 return 0;
824
825 intf = to_usb_interface(hdev->dev.parent);
826 interface = intf->cur_altsetting;
827 dev = hid_to_usb_dev(hdev);
828
829 /* Some Elan legacy devices require SET_IDLE to be set on resume.
830 * It should be safe to send it to other devices too.
831 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
832
833 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
834 HID_REQ_SET_IDLE,
835 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
836 0, interface->desc.bInterfaceNumber,
837 NULL, 0, USB_CTRL_SET_TIMEOUT);
838
839 return 0;
840}
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100841#endif
842
843static void mt_remove(struct hid_device *hdev)
844{
845 struct mt_device *td = hid_get_drvdata(hdev);
Benjamin Tissoireseec29e32011-11-23 10:54:28 +0100846 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100847 hid_hw_stop(hdev);
848 kfree(td);
849 hid_set_drvdata(hdev, NULL);
850}
851
852static const struct hid_device_id mt_devices[] = {
853
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100854 /* 3M panels */
855 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200856 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100857 USB_DEVICE_ID_3M1968) },
858 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200859 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100860 USB_DEVICE_ID_3M2256) },
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100861 { .driver_data = MT_CLS_3M,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200862 MT_USB_DEVICE(USB_VENDOR_ID_3M,
Benjamin Tissoiresc4fad872011-12-23 15:41:00 +0100863 USB_DEVICE_ID_3M3266) },
Benjamin Tissoiresf786bba2011-03-22 17:34:01 +0100864
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200865 /* ActionStar panels */
866 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200867 MT_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
Benjamin Tissoirese6aac342011-05-19 14:18:13 +0200868 USB_DEVICE_ID_ACTIONSTAR_1011) },
869
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100870 /* Atmel panels */
871 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200872 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100873 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100874 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200875 MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
Benjamin Tissoires841cb152012-03-06 10:53:45 +0100876 USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
Benjamin Tissoiresb1057122011-12-23 15:40:59 +0100877
Jiri Kosina9ed32692012-04-20 12:15:44 +0200878 /* Baanto multitouch devices */
879 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina16b79bb2012-05-05 23:32:54 +0200880 MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
Jiri Kosina9ed32692012-04-20 12:15:44 +0200881 USB_DEVICE_ID_BAANTO_MT_190W2) },
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100882 /* Cando panels */
883 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200884 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100885 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
886 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200887 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100888 USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
889 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200890 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100891 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
892 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200893 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoiresa841b622011-03-18 14:27:54 +0100894 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
895
Austin Zhang942fd422011-05-28 02:03:47 +0800896 /* Chunghwa Telecom touch panels */
897 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200898 MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
Austin Zhang942fd422011-05-28 02:03:47 +0800899 USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
900
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200901 /* CVTouch panels */
902 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200903 MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
Benjamin Tissoires79603dc2011-05-19 14:18:14 +0200904 USB_DEVICE_ID_CVTOUCH_SCREEN) },
905
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100906 /* Cypress panel */
907 { .driver_data = MT_CLS_CYPRESS,
908 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
909 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
910
Benjamin Tissoires22408282011-05-20 15:59:34 +0200911 /* eGalax devices (resistive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100912 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200913 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100914 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
915 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200916 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100917 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200918
919 /* eGalax devices (capacitive) */
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100920 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200921 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100922 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100923 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200924 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100925 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
926 { .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_725E) },
929 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200930 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100931 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100932 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200933 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires2ce09df2012-03-06 17:57:02 +0100934 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
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 Tissoirese36f6902011-11-23 10:54:31 +0100937 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100938 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200939 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100940 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100941 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200942 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100943 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100944 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200945 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100946 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100947 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200948 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoires66f06122011-11-23 10:54:33 +0100949 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
950 { .driver_data = MT_CLS_EGALAX,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200951 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Marek Vasutbb9ff212011-11-23 10:54:32 +0100952 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
Benjamin Tissoires1b723e82011-11-23 10:54:34 +0100953 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200954 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoiresfd1d1522012-03-06 10:53:47 +0100955 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
956 { .driver_data = MT_CLS_EGALAX_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200957 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Thierry Redingae01c9e2012-08-09 08:34:48 +0200958 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
959 { .driver_data = MT_CLS_EGALAX_SERIAL,
960 MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
Benjamin Tissoirese36f6902011-11-23 10:54:31 +0100961 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
Jiri Kosina3d771042012-08-15 10:01:01 +0200962 { .driver_data = MT_CLS_EGALAX,
963 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
964 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
965 { .driver_data = MT_CLS_EGALAX,
966 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
967 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
968 { .driver_data = MT_CLS_EGALAX,
969 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
970 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
Benjamin Tissoires22408282011-05-20 15:59:34 +0200971
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200972 /* Elo TouchSystems IntelliTouch Plus panel */
973 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200974 MT_USB_DEVICE(USB_VENDOR_ID_ELO,
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +0200975 USB_DEVICE_ID_ELO_TS2515) },
976
Henrik Rydberg77723e32012-09-07 19:37:40 +0200977 /* Flatfrog Panels */
978 { .driver_data = MT_CLS_FLATFROG,
979 MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
980 USB_DEVICE_ID_MULTITOUCH_3200) },
981
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100982 /* GeneralTouch panel */
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800983 { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200984 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100985 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Xianhan Yuf5ff4e12012-09-28 10:18:59 +0800986 { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
987 MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
988 USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100989
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100990 /* Gametel game controller */
991 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200992 MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
Andreas Nielsen4d5df5d2012-03-19 15:41:03 +0100993 USB_DEVICE_ID_GAMETEL_MT_MODE) },
994
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200995 /* GoodTouch panels */
996 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +0200997 MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +0200998 USB_DEVICE_ID_GOODTOUCH_000f) },
999
Benjamin Tissoires54580362011-11-29 13:13:12 +01001000 /* Hanvon panels */
1001 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001002 MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
Benjamin Tissoires54580362011-11-29 13:13:12 +01001003 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1004
Stephane Chattya062cc52011-09-17 22:27:30 +02001005 /* Ideacom panel */
1006 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001007 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Stephane Chattya062cc52011-09-17 22:27:30 +02001008 USB_DEVICE_ID_IDEACOM_IDC6650) },
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001009 { .driver_data = MT_CLS_SERIAL,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001010 MT_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
Benjamin Tissoires71078b02012-03-06 10:53:46 +01001011 USB_DEVICE_ID_IDEACOM_IDC6651) },
Stephane Chattya062cc52011-09-17 22:27:30 +02001012
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001013 /* Ilitek dual touch panel */
1014 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001015 MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001016 USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1017
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001018 /* IRTOUCH panels */
1019 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001020 MT_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +01001021 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1022
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001023 /* LG Display panels */
1024 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001025 MT_USB_DEVICE(USB_VENDOR_ID_LG,
Jeff Brownc50bb1a2011-08-15 21:12:09 -07001026 USB_DEVICE_ID_LG_MULTITOUCH) },
1027
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001028 /* Lumio panels */
1029 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001030 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001031 USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001032 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001033 MT_USB_DEVICE(USB_VENDOR_ID_LUMIO,
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001034 USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001035
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001036 /* MosArt panels */
1037 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001038 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001039 USB_DEVICE_ID_ASUS_T91MT)},
1040 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001041 MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001042 USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1043 { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001044 MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
Benjamin Tissoires4a6ee682011-04-22 11:51:48 +02001045 USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1046
Denis Kovalev2258e862012-02-14 00:50:33 -08001047 /* Panasonic panels */
1048 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001049 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001050 USB_DEVICE_ID_PANABOARD_UBT780) },
1051 { .driver_data = MT_CLS_PANASONIC,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001052 MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
Denis Kovalev2258e862012-02-14 00:50:33 -08001053 USB_DEVICE_ID_PANABOARD_UBT880) },
1054
Austin Hendrix4db703e2012-06-04 15:27:51 -07001055 /* Novatek Panel */
1056 { .driver_data = MT_CLS_DEFAULT,
Jiri Kosina4380d812012-06-06 16:28:33 +02001057 MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
Austin Hendrix4db703e2012-06-04 15:27:51 -07001058 USB_DEVICE_ID_NOVATEK_PCT) },
1059
John Sung6ab3a9a2011-04-21 16:21:52 +02001060 /* PenMount panels */
1061 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001062 MT_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
John Sung6ab3a9a2011-04-21 16:21:52 +02001063 USB_DEVICE_ID_PENMOUNT_PCI) },
1064
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001065 /* PixArt optical touch screen */
1066 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001067 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001068 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1069 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001070 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001071 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1072 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001073 MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
Aaron Tianb7ea95f2011-12-15 11:09:06 +08001074 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1075
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001076 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001077 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001078 MT_USB_DEVICE(USB_VENDOR_ID_HANVON,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001079 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +01001080 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001081 MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001082 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1083
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001084 /* Quanta-based panels */
1085 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001086 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001087 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1088 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001089 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001090 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
1091 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001092 MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
Benjamin Tissoires5e7ea112011-11-29 13:13:10 +01001093 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
1094
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001095 /* Stantum panels */
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001096 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001097 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001098 USB_DEVICE_ID_MTP)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001099 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001100 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001101 USB_DEVICE_ID_MTP_STM)},
Benjamin Tissoiresbf5af9b2011-05-19 14:18:18 +02001102 { .driver_data = MT_CLS_CONFIDENCE,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001103 MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
Benjamin Tissoires043b4032011-03-18 14:27:53 +01001104 USB_DEVICE_ID_MTP_SITRONIX)},
1105
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001106 /* TopSeed panels */
1107 { .driver_data = MT_CLS_TOPSEED,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001108 MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
Benjamin Tissoires847672c2012-02-04 17:08:50 +01001109 USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
1110
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001111 /* Touch International panels */
1112 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001113 MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001114 USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1115
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001116 /* Unitec panels */
1117 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001118 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001119 USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1120 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001121 MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001122 USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
ice chienbc8a2a92011-07-15 16:58:06 +08001123 /* XAT */
1124 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001125 MT_USB_DEVICE(USB_VENDOR_ID_XAT,
ice chienbc8a2a92011-07-15 16:58:06 +08001126 USB_DEVICE_ID_XAT_CSR) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001127
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001128 /* Xiroku */
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_SPX) },
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_MPX) },
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_CSR) },
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_SPX1) },
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_MPX1) },
1144 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001145 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001146 USB_DEVICE_ID_XIROKU_CSR1) },
1147 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001148 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001149 USB_DEVICE_ID_XIROKU_SPX2) },
1150 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001151 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001152 USB_DEVICE_ID_XIROKU_MPX2) },
1153 { .driver_data = MT_CLS_DEFAULT,
Henrik Rydberg2c2110e2012-05-04 15:32:04 +02001154 MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
Masatoshi Hoshikawa11576c62012-01-05 11:53:46 +09001155 USB_DEVICE_ID_XIROKU_CSR2) },
1156
Benjamin Tissoires82d06982012-06-19 14:39:54 +02001157 /* Zytronic panels */
1158 { .driver_data = MT_CLS_SERIAL,
1159 MT_USB_DEVICE(USB_VENDOR_ID_ZYTRONIC,
1160 USB_DEVICE_ID_ZYTRONIC_ZXY100) },
1161
Henrik Rydberg4fa3a582012-05-01 08:40:01 +02001162 /* Generic MT device */
1163 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001164 { }
1165};
1166MODULE_DEVICE_TABLE(hid, mt_devices);
1167
1168static const struct hid_usage_id mt_grabbed_usages[] = {
1169 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
1170 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
1171};
1172
1173static struct hid_driver mt_driver = {
1174 .name = "hid-multitouch",
1175 .id_table = mt_devices,
1176 .probe = mt_probe,
1177 .remove = mt_remove,
1178 .input_mapping = mt_input_mapping,
1179 .input_mapped = mt_input_mapped,
Henrik Rydberg76f59022012-09-01 20:11:34 +02001180 .input_configured = mt_input_configured,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001181 .feature_mapping = mt_feature_mapping,
1182 .usage_table = mt_grabbed_usages,
1183 .event = mt_event,
1184#ifdef CONFIG_PM
1185 .reset_resume = mt_reset_resume,
Scott Liudfeefd12012-08-15 17:21:55 +08001186 .resume = mt_resume,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001187#endif
1188};
1189
1190static int __init mt_init(void)
1191{
1192 return hid_register_driver(&mt_driver);
1193}
1194
1195static void __exit mt_exit(void)
1196{
1197 hid_unregister_driver(&mt_driver);
1198}
1199
1200module_init(mt_init);
1201module_exit(mt_exit);