blob: 5983e5559e8105422f6722c1617bda33603f70e9 [file] [log] [blame]
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001/*
2 * HID driver for multitouch panels
3 *
4 * Copyright (c) 2010-2011 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010-2011 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 * Copyright (c) 2010-2011 Ecole Nationale de l'Aviation Civile, France
7 *
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 Tissoires5519cab2011-01-07 23:45:50 +010014 */
15
16/*
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the Free
19 * Software Foundation; either version 2 of the License, or (at your option)
20 * any later version.
21 */
22
23#include <linux/device.h>
24#include <linux/hid.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27#include <linux/usb.h>
28#include <linux/input/mt.h>
29#include "usbhid/usbhid.h"
30
31
32MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
Benjamin Tissoiresef2fafb2011-01-31 11:28:21 +010033MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010034MODULE_DESCRIPTION("HID multitouch panels");
35MODULE_LICENSE("GPL");
36
37#include "hid-ids.h"
38
39/* quirks to control the device */
40#define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
41#define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
Benjamin Tissoires2d936662011-01-11 16:45:54 +010042#define MT_QUIRK_CYPRESS (1 << 2)
Benjamin Tissoires5572da02011-01-07 23:47:27 +010043#define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
Benjamin Tissoires2d936662011-01-11 16:45:54 +010044#define MT_QUIRK_VALID_IS_INRANGE (1 << 4)
45#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 5)
Richard Nauber4875ac12011-03-09 06:20:57 +010046#define MT_QUIRK_EGALAX_XYZ_FIXUP (1 << 6)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010047
48struct mt_slot {
49 __s32 x, y, p, w, h;
50 __s32 contactid; /* the device ContactID assigned to this slot */
51 bool touch_state; /* is the touch valid? */
52 bool seen_in_this_frame;/* has this slot been updated */
53};
54
55struct mt_device {
56 struct mt_slot curdata; /* placeholder of incoming data */
57 struct mt_class *mtclass; /* our mt device class */
58 unsigned last_field_index; /* last field index of the report */
59 unsigned last_slot_field; /* the last field of a slot */
60 __s8 inputmode; /* InputMode HID feature, -1 if non-existent */
61 __u8 num_received; /* how many contacts we received */
62 __u8 num_expected; /* expected last contact index */
Benjamin Tissoires9498f952011-03-18 14:27:52 +010063 __u8 maxcontacts;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010064 bool curvalid; /* is the current contact valid? */
Benjamin Tissoires9498f952011-03-18 14:27:52 +010065 struct mt_slot *slots;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010066};
67
68struct mt_class {
Benjamin Tissoires2d936662011-01-11 16:45:54 +010069 __s32 name; /* MT_CLS */
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010070 __s32 quirks;
71 __s32 sn_move; /* Signal/noise ratio for move events */
72 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
73 __u8 maxcontacts;
74};
75
76/* classes of device behavior */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +010077#define MT_CLS_DEFAULT 1
78#define MT_CLS_DUAL_INRANGE_CONTACTID 2
79#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 3
80#define MT_CLS_CYPRESS 4
Richard Nauber4875ac12011-03-09 06:20:57 +010081#define MT_CLS_EGALAX 5
Benjamin Tissoires043b4032011-03-18 14:27:53 +010082#define MT_CLS_STANTUM 6
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010083
Benjamin Tissoires9498f952011-03-18 14:27:52 +010084#define MT_DEFAULT_MAXCONTACT 10
85
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010086/*
87 * these device-dependent functions determine what slot corresponds
88 * to a valid contact that was just read.
89 */
90
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +010091static int cypress_compute_slot(struct mt_device *td)
92{
93 if (td->curdata.contactid != 0 || td->num_received == 0)
94 return td->curdata.contactid;
95 else
96 return -1;
97}
98
Benjamin Tissoires5519cab2011-01-07 23:45:50 +010099static int find_slot_from_contactid(struct mt_device *td)
100{
101 int i;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100102 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100103 if (td->slots[i].contactid == td->curdata.contactid &&
104 td->slots[i].touch_state)
105 return i;
106 }
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100107 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100108 if (!td->slots[i].seen_in_this_frame &&
109 !td->slots[i].touch_state)
110 return i;
111 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100112 /* should not occurs. If this happens that means
113 * that the device sent more touches that it says
114 * in the report descriptor. It is ignored then. */
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100115 return -1;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100116}
117
118struct mt_class mt_classes[] = {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100119 { .name = MT_CLS_DEFAULT,
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100120 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100121 { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100122 .quirks = MT_QUIRK_VALID_IS_INRANGE |
123 MT_QUIRK_SLOT_IS_CONTACTID,
124 .maxcontacts = 2 },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100125 { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100126 .quirks = MT_QUIRK_VALID_IS_INRANGE |
127 MT_QUIRK_SLOT_IS_CONTACTNUMBER,
128 .maxcontacts = 2 },
129 { .name = MT_CLS_CYPRESS,
130 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
131 MT_QUIRK_CYPRESS,
132 .maxcontacts = 10 },
133
Richard Nauber4875ac12011-03-09 06:20:57 +0100134 { .name = MT_CLS_EGALAX,
135 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
136 MT_QUIRK_VALID_IS_INRANGE |
137 MT_QUIRK_EGALAX_XYZ_FIXUP,
138 .maxcontacts = 2,
139 .sn_move = 4096,
140 .sn_pressure = 32,
141 },
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100142 { .name = MT_CLS_STANTUM,
143 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
144
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100145 { }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100146};
147
Henrik Rydbergf635bd12011-02-24 19:30:59 +0100148static void mt_feature_mapping(struct hid_device *hdev,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100149 struct hid_field *field, struct hid_usage *usage)
150{
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100151 struct mt_device *td = hid_get_drvdata(hdev);
152
153 switch (usage->hid) {
154 case HID_DG_INPUTMODE:
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100155 td->inputmode = field->report->id;
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100156 break;
157 case HID_DG_CONTACTMAX:
158 td->maxcontacts = field->value[0];
159 if (td->mtclass->maxcontacts)
160 /* check if the maxcontacts is given by the class */
161 td->maxcontacts = td->mtclass->maxcontacts;
162
163 break;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100164 }
165}
166
167static void set_abs(struct input_dev *input, unsigned int code,
168 struct hid_field *field, int snratio)
169{
170 int fmin = field->logical_minimum;
171 int fmax = field->logical_maximum;
172 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
173 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
174}
175
176static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
177 struct hid_field *field, struct hid_usage *usage,
178 unsigned long **bit, int *max)
179{
180 struct mt_device *td = hid_get_drvdata(hdev);
181 struct mt_class *cls = td->mtclass;
Richard Nauber4875ac12011-03-09 06:20:57 +0100182 __s32 quirks = cls->quirks;
183
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100184 switch (usage->hid & HID_USAGE_PAGE) {
185
186 case HID_UP_GENDESK:
187 switch (usage->hid) {
188 case HID_GD_X:
Richard Nauber4875ac12011-03-09 06:20:57 +0100189 if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
190 field->logical_maximum = 32760;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100191 hid_map_usage(hi, usage, bit, max,
192 EV_ABS, ABS_MT_POSITION_X);
193 set_abs(hi->input, ABS_MT_POSITION_X, field,
194 cls->sn_move);
195 /* touchscreen emulation */
196 set_abs(hi->input, ABS_X, field, cls->sn_move);
197 td->last_slot_field = usage->hid;
198 return 1;
199 case HID_GD_Y:
Richard Nauber4875ac12011-03-09 06:20:57 +0100200 if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
201 field->logical_maximum = 32760;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100202 hid_map_usage(hi, usage, bit, max,
203 EV_ABS, ABS_MT_POSITION_Y);
204 set_abs(hi->input, ABS_MT_POSITION_Y, field,
205 cls->sn_move);
206 /* touchscreen emulation */
207 set_abs(hi->input, ABS_Y, field, cls->sn_move);
208 td->last_slot_field = usage->hid;
209 return 1;
210 }
211 return 0;
212
213 case HID_UP_DIGITIZER:
214 switch (usage->hid) {
215 case HID_DG_INRANGE:
216 td->last_slot_field = usage->hid;
217 return 1;
218 case HID_DG_CONFIDENCE:
219 td->last_slot_field = usage->hid;
220 return 1;
221 case HID_DG_TIPSWITCH:
222 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
223 input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
224 td->last_slot_field = usage->hid;
225 return 1;
226 case HID_DG_CONTACTID:
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100227 input_mt_init_slots(hi->input, td->maxcontacts);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100228 td->last_slot_field = usage->hid;
229 return 1;
230 case HID_DG_WIDTH:
231 hid_map_usage(hi, usage, bit, max,
232 EV_ABS, ABS_MT_TOUCH_MAJOR);
233 td->last_slot_field = usage->hid;
234 return 1;
235 case HID_DG_HEIGHT:
236 hid_map_usage(hi, usage, bit, max,
237 EV_ABS, ABS_MT_TOUCH_MINOR);
238 field->logical_maximum = 1;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100239 field->logical_minimum = 0;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100240 set_abs(hi->input, ABS_MT_ORIENTATION, field, 0);
241 td->last_slot_field = usage->hid;
242 return 1;
243 case HID_DG_TIPPRESSURE:
Richard Nauber4875ac12011-03-09 06:20:57 +0100244 if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
245 field->logical_minimum = 0;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100246 hid_map_usage(hi, usage, bit, max,
247 EV_ABS, ABS_MT_PRESSURE);
248 set_abs(hi->input, ABS_MT_PRESSURE, field,
249 cls->sn_pressure);
250 /* touchscreen emulation */
251 set_abs(hi->input, ABS_PRESSURE, field,
252 cls->sn_pressure);
253 td->last_slot_field = usage->hid;
254 return 1;
255 case HID_DG_CONTACTCOUNT:
256 td->last_field_index = field->report->maxfield - 1;
257 return 1;
258 case HID_DG_CONTACTMAX:
259 /* we don't set td->last_slot_field as contactcount and
260 * contact max are global to the report */
261 return -1;
262 }
263 /* let hid-input decide for the others */
264 return 0;
265
266 case 0xff000000:
267 /* we do not want to map these: no input-oriented meaning */
268 return -1;
269 }
270
271 return 0;
272}
273
274static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
275 struct hid_field *field, struct hid_usage *usage,
276 unsigned long **bit, int *max)
277{
278 if (usage->type == EV_KEY || usage->type == EV_ABS)
279 set_bit(usage->type, hi->input->evbit);
280
281 return -1;
282}
283
284static int mt_compute_slot(struct mt_device *td)
285{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100286 __s32 quirks = td->mtclass->quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100287
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100288 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
289 return td->curdata.contactid;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100290
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100291 if (quirks & MT_QUIRK_CYPRESS)
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100292 return cypress_compute_slot(td);
293
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100294 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
295 return td->num_received;
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100296
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100297 return find_slot_from_contactid(td);
298}
299
300/*
301 * this function is called when a whole contact has been processed,
302 * so that it can assign it to a slot and store the data there
303 */
304static void mt_complete_slot(struct mt_device *td)
305{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100306 td->curdata.seen_in_this_frame = true;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100307 if (td->curvalid) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100308 int slotnum = mt_compute_slot(td);
309
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100310 if (slotnum >= 0 && slotnum < td->maxcontacts)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100311 td->slots[slotnum] = td->curdata;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100312 }
313 td->num_received++;
314}
315
316
317/*
318 * this function is called when a whole packet has been received and processed,
319 * so that it can decide what to send to the input layer.
320 */
321static void mt_emit_event(struct mt_device *td, struct input_dev *input)
322{
323 int i;
324
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100325 for (i = 0; i < td->maxcontacts; ++i) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100326 struct mt_slot *s = &(td->slots[i]);
327 if ((td->mtclass->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
328 !s->seen_in_this_frame) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100329 s->touch_state = false;
330 }
331
332 input_mt_slot(input, i);
333 input_mt_report_slot_state(input, MT_TOOL_FINGER,
334 s->touch_state);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100335 if (s->touch_state) {
336 input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
337 input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
338 input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
339 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, s->w);
340 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, s->h);
341 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100342 s->seen_in_this_frame = false;
343
344 }
345
346 input_mt_report_pointer_emulation(input, true);
347 input_sync(input);
348 td->num_received = 0;
349}
350
351
352
353static int mt_event(struct hid_device *hid, struct hid_field *field,
354 struct hid_usage *usage, __s32 value)
355{
356 struct mt_device *td = hid_get_drvdata(hid);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100357 __s32 quirks = td->mtclass->quirks;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100358
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100359 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100360 switch (usage->hid) {
361 case HID_DG_INRANGE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100362 if (quirks & MT_QUIRK_VALID_IS_INRANGE)
363 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100364 break;
365 case HID_DG_TIPSWITCH:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100366 if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
367 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100368 td->curdata.touch_state = value;
369 break;
370 case HID_DG_CONFIDENCE:
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100371 if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
372 td->curvalid = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100373 break;
374 case HID_DG_CONTACTID:
375 td->curdata.contactid = value;
376 break;
377 case HID_DG_TIPPRESSURE:
378 td->curdata.p = value;
379 break;
380 case HID_GD_X:
381 td->curdata.x = value;
382 break;
383 case HID_GD_Y:
384 td->curdata.y = value;
385 break;
386 case HID_DG_WIDTH:
387 td->curdata.w = value;
388 break;
389 case HID_DG_HEIGHT:
390 td->curdata.h = value;
391 break;
392 case HID_DG_CONTACTCOUNT:
393 /*
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100394 * Includes multi-packet support where subsequent
395 * packets are sent with zero contactcount.
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100396 */
397 if (value)
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100398 td->num_expected = value;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100399 break;
400
401 default:
402 /* fallback to the generic hidinput handling */
403 return 0;
404 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100405
Henrik Rydbergf153fc32011-03-09 06:35:25 +0100406 if (usage->hid == td->last_slot_field) {
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100407 mt_complete_slot(td);
Henrik Rydbergf153fc32011-03-09 06:35:25 +0100408 if (!td->last_field_index)
409 mt_emit_event(td, field->hidinput->input);
410 }
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100411
412 if (field->index == td->last_field_index
413 && td->num_received >= td->num_expected)
414 mt_emit_event(td, field->hidinput->input);
415
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100416 }
417
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100418 /* we have handled the hidinput part, now remains hiddev */
419 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
420 hid->hiddev_hid_event(hid, field, usage, value);
421
422 return 1;
423}
424
425static void mt_set_input_mode(struct hid_device *hdev)
426{
427 struct mt_device *td = hid_get_drvdata(hdev);
428 struct hid_report *r;
429 struct hid_report_enum *re;
430
431 if (td->inputmode < 0)
432 return;
433
434 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
435 r = re->report_id_hash[td->inputmode];
436 if (r) {
437 r->field[0]->value[0] = 0x02;
438 usbhid_submit_report(hdev, r, USB_DIR_OUT);
439 }
440}
441
442static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
443{
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100444 int ret, i;
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100445 struct mt_device *td;
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100446 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
447
448 for (i = 0; mt_classes[i].name ; i++) {
449 if (id->driver_data == mt_classes[i].name) {
450 mtclass = &(mt_classes[i]);
451 break;
452 }
453 }
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100454
455 /* This allows the driver to correctly support devices
456 * that emit events over several HID messages.
457 */
458 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
459
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100460 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100461 if (!td) {
462 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
463 return -ENOMEM;
464 }
465 td->mtclass = mtclass;
466 td->inputmode = -1;
467 hid_set_drvdata(hdev, td);
468
469 ret = hid_parse(hdev);
470 if (ret != 0)
471 goto fail;
472
473 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Benjamin Tissoires2d936662011-01-11 16:45:54 +0100474 if (ret)
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100475 goto fail;
476
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100477 if (!td->maxcontacts)
478 td->maxcontacts = MT_DEFAULT_MAXCONTACT;
479
480 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
481 GFP_KERNEL);
482 if (!td->slots) {
483 dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
484 hid_hw_stop(hdev);
485 ret = -ENOMEM;
486 goto fail;
487 }
488
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100489 mt_set_input_mode(hdev);
490
491 return 0;
492
493fail:
494 kfree(td);
495 return ret;
496}
497
498#ifdef CONFIG_PM
499static int mt_reset_resume(struct hid_device *hdev)
500{
501 mt_set_input_mode(hdev);
502 return 0;
503}
504#endif
505
506static void mt_remove(struct hid_device *hdev)
507{
508 struct mt_device *td = hid_get_drvdata(hdev);
509 hid_hw_stop(hdev);
Benjamin Tissoires9498f952011-03-18 14:27:52 +0100510 kfree(td->slots);
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100511 kfree(td);
512 hid_set_drvdata(hdev, NULL);
513}
514
515static const struct hid_device_id mt_devices[] = {
516
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +0100517 /* Cypress panel */
518 { .driver_data = MT_CLS_CYPRESS,
519 HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
520 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
521
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100522 /* GeneralTouch panel */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100523 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
Benjamin Tissoires5572da02011-01-07 23:47:27 +0100524 HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
525 USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
526
Benjamin Tissoires4dfcced2011-01-31 11:28:22 +0100527 /* IRTOUCH panels */
528 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
529 HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
530 USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
531
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100532 /* PixCir-based panels */
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100533 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100534 HID_USB_DEVICE(USB_VENDOR_ID_HANVON,
535 USB_DEVICE_ID_HANVON_MULTITOUCH) },
Benjamin Tissoires1e9cf352011-01-31 11:28:20 +0100536 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100537 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
538 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
539
Richard Nauber4875ac12011-03-09 06:20:57 +0100540 /* Resistive eGalax devices */
541 { .driver_data = MT_CLS_EGALAX,
542 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
543 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
544 { .driver_data = MT_CLS_EGALAX,
545 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
546 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) },
547
548 /* Capacitive eGalax devices */
549 { .driver_data = MT_CLS_EGALAX,
550 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
551 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
552 { .driver_data = MT_CLS_EGALAX,
553 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
554 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) },
555 { .driver_data = MT_CLS_EGALAX,
556 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
557 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) },
558
Benjamin Tissoires043b4032011-03-18 14:27:53 +0100559 /* Stantum panels */
560 { .driver_data = MT_CLS_STANTUM,
561 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
562 USB_DEVICE_ID_MTP)},
563 { .driver_data = MT_CLS_STANTUM,
564 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
565 USB_DEVICE_ID_MTP_STM)},
566 { .driver_data = MT_CLS_STANTUM,
567 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
568 USB_DEVICE_ID_MTP_SITRONIX)},
569
Benjamin Tissoires5519cab2011-01-07 23:45:50 +0100570 { }
571};
572MODULE_DEVICE_TABLE(hid, mt_devices);
573
574static const struct hid_usage_id mt_grabbed_usages[] = {
575 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
576 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
577};
578
579static struct hid_driver mt_driver = {
580 .name = "hid-multitouch",
581 .id_table = mt_devices,
582 .probe = mt_probe,
583 .remove = mt_remove,
584 .input_mapping = mt_input_mapping,
585 .input_mapped = mt_input_mapped,
586 .feature_mapping = mt_feature_mapping,
587 .usage_table = mt_grabbed_usages,
588 .event = mt_event,
589#ifdef CONFIG_PM
590 .reset_resume = mt_reset_resume,
591#endif
592};
593
594static int __init mt_init(void)
595{
596 return hid_register_driver(&mt_driver);
597}
598
599static void __exit mt_exit(void)
600{
601 hid_unregister_driver(&mt_driver);
602}
603
604module_init(mt_init);
605module_exit(mt_exit);