hid-multitouch.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /*
  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. *
  8. * 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. *
  14. * 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. *
  20. */
  21. /*
  22. * This program is free software; you can redistribute it and/or modify it
  23. * under the terms of the GNU General Public License as published by the Free
  24. * Software Foundation; either version 2 of the License, or (at your option)
  25. * any later version.
  26. */
  27. #include <linux/device.h>
  28. #include <linux/hid.h>
  29. #include <linux/module.h>
  30. #include <linux/slab.h>
  31. #include <linux/usb.h>
  32. #include <linux/input/mt.h>
  33. #include "usbhid/usbhid.h"
  34. MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
  35. MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
  36. MODULE_DESCRIPTION("HID multitouch panels");
  37. MODULE_LICENSE("GPL");
  38. #include "hid-ids.h"
  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)
  42. #define MT_QUIRK_CYPRESS (1 << 2)
  43. #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
  44. #define MT_QUIRK_VALID_IS_INRANGE (1 << 4)
  45. #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 5)
  46. #define MT_QUIRK_EGALAX_XYZ_FIXUP (1 << 6)
  47. #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 7)
  48. struct 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. struct mt_device {
  55. struct mt_slot curdata; /* placeholder of incoming data */
  56. struct mt_class *mtclass; /* our mt device class */
  57. unsigned last_field_index; /* last field index of the report */
  58. unsigned last_slot_field; /* the last field of a slot */
  59. int last_mt_collection; /* last known mt-related collection */
  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 */
  63. __u8 maxcontacts;
  64. bool curvalid; /* is the current contact valid? */
  65. struct mt_slot *slots;
  66. };
  67. struct mt_class {
  68. __s32 name; /* MT_CLS */
  69. __s32 quirks;
  70. __s32 sn_move; /* Signal/noise ratio for move events */
  71. __s32 sn_width; /* Signal/noise ratio for width events */
  72. __s32 sn_height; /* Signal/noise ratio for height events */
  73. __s32 sn_pressure; /* Signal/noise ratio for pressure events */
  74. __u8 maxcontacts;
  75. };
  76. /* classes of device behavior */
  77. #define MT_CLS_DEFAULT 0x0001
  78. #define MT_CLS_CONFIDENCE 0x0002
  79. #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0003
  80. #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0004
  81. #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0005
  82. #define MT_CLS_DUAL_NSMU_CONTACTID 0x0006
  83. /* vendor specific classes */
  84. #define MT_CLS_3M 0x0101
  85. #define MT_CLS_CYPRESS 0x0102
  86. #define MT_CLS_EGALAX 0x0103
  87. #define MT_DEFAULT_MAXCONTACT 10
  88. /*
  89. * these device-dependent functions determine what slot corresponds
  90. * to a valid contact that was just read.
  91. */
  92. static int cypress_compute_slot(struct mt_device *td)
  93. {
  94. if (td->curdata.contactid != 0 || td->num_received == 0)
  95. return td->curdata.contactid;
  96. else
  97. return -1;
  98. }
  99. static int find_slot_from_contactid(struct mt_device *td)
  100. {
  101. int i;
  102. for (i = 0; i < td->maxcontacts; ++i) {
  103. if (td->slots[i].contactid == td->curdata.contactid &&
  104. td->slots[i].touch_state)
  105. return i;
  106. }
  107. for (i = 0; i < td->maxcontacts; ++i) {
  108. if (!td->slots[i].seen_in_this_frame &&
  109. !td->slots[i].touch_state)
  110. return i;
  111. }
  112. /* 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. */
  115. return -1;
  116. }
  117. struct mt_class mt_classes[] = {
  118. { .name = MT_CLS_DEFAULT,
  119. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
  120. { .name = MT_CLS_CONFIDENCE,
  121. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
  122. { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
  123. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  124. MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
  125. { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
  126. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  127. MT_QUIRK_SLOT_IS_CONTACTID,
  128. .maxcontacts = 2 },
  129. { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  130. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  131. MT_QUIRK_SLOT_IS_CONTACTNUMBER,
  132. .maxcontacts = 2 },
  133. { .name = MT_CLS_DUAL_NSMU_CONTACTID,
  134. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  135. MT_QUIRK_SLOT_IS_CONTACTID,
  136. .maxcontacts = 2 },
  137. /*
  138. * vendor specific classes
  139. */
  140. { .name = MT_CLS_3M,
  141. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  142. MT_QUIRK_SLOT_IS_CONTACTID,
  143. .sn_move = 2048,
  144. .sn_width = 128,
  145. .sn_height = 128 },
  146. { .name = MT_CLS_CYPRESS,
  147. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  148. MT_QUIRK_CYPRESS,
  149. .maxcontacts = 10 },
  150. { .name = MT_CLS_EGALAX,
  151. .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
  152. MT_QUIRK_VALID_IS_INRANGE |
  153. MT_QUIRK_EGALAX_XYZ_FIXUP,
  154. .maxcontacts = 2,
  155. .sn_move = 4096,
  156. .sn_pressure = 32,
  157. },
  158. { }
  159. };
  160. static void mt_feature_mapping(struct hid_device *hdev,
  161. struct hid_field *field, struct hid_usage *usage)
  162. {
  163. struct mt_device *td = hid_get_drvdata(hdev);
  164. switch (usage->hid) {
  165. case HID_DG_INPUTMODE:
  166. td->inputmode = field->report->id;
  167. break;
  168. case HID_DG_CONTACTMAX:
  169. td->maxcontacts = field->value[0];
  170. if (td->mtclass->maxcontacts)
  171. /* check if the maxcontacts is given by the class */
  172. td->maxcontacts = td->mtclass->maxcontacts;
  173. break;
  174. }
  175. }
  176. static void set_abs(struct input_dev *input, unsigned int code,
  177. struct hid_field *field, int snratio)
  178. {
  179. int fmin = field->logical_minimum;
  180. int fmax = field->logical_maximum;
  181. int fuzz = snratio ? (fmax - fmin) / snratio : 0;
  182. input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
  183. }
  184. static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  185. struct hid_field *field, struct hid_usage *usage,
  186. unsigned long **bit, int *max)
  187. {
  188. struct mt_device *td = hid_get_drvdata(hdev);
  189. struct mt_class *cls = td->mtclass;
  190. __s32 quirks = cls->quirks;
  191. /* Only map fields from TouchScreen or TouchPad collections.
  192. * We need to ignore fields that belong to other collections
  193. * such as Mouse that might have the same GenericDesktop usages. */
  194. if (field->application == HID_DG_TOUCHSCREEN)
  195. set_bit(INPUT_PROP_DIRECT, hi->input->propbit);
  196. else if (field->application == HID_DG_TOUCHPAD)
  197. set_bit(INPUT_PROP_POINTER, hi->input->propbit);
  198. else
  199. return 0;
  200. switch (usage->hid & HID_USAGE_PAGE) {
  201. case HID_UP_GENDESK:
  202. switch (usage->hid) {
  203. case HID_GD_X:
  204. if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
  205. field->logical_maximum = 32760;
  206. hid_map_usage(hi, usage, bit, max,
  207. EV_ABS, ABS_MT_POSITION_X);
  208. set_abs(hi->input, ABS_MT_POSITION_X, field,
  209. cls->sn_move);
  210. /* touchscreen emulation */
  211. set_abs(hi->input, ABS_X, field, cls->sn_move);
  212. if (td->last_mt_collection == usage->collection_index) {
  213. td->last_slot_field = usage->hid;
  214. td->last_field_index = field->index;
  215. }
  216. return 1;
  217. case HID_GD_Y:
  218. if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
  219. field->logical_maximum = 32760;
  220. hid_map_usage(hi, usage, bit, max,
  221. EV_ABS, ABS_MT_POSITION_Y);
  222. set_abs(hi->input, ABS_MT_POSITION_Y, field,
  223. cls->sn_move);
  224. /* touchscreen emulation */
  225. set_abs(hi->input, ABS_Y, field, cls->sn_move);
  226. if (td->last_mt_collection == usage->collection_index) {
  227. td->last_slot_field = usage->hid;
  228. td->last_field_index = field->index;
  229. }
  230. return 1;
  231. }
  232. return 0;
  233. case HID_UP_DIGITIZER:
  234. switch (usage->hid) {
  235. case HID_DG_INRANGE:
  236. if (td->last_mt_collection == usage->collection_index) {
  237. td->last_slot_field = usage->hid;
  238. td->last_field_index = field->index;
  239. }
  240. return 1;
  241. case HID_DG_CONFIDENCE:
  242. if (td->last_mt_collection == usage->collection_index) {
  243. td->last_slot_field = usage->hid;
  244. td->last_field_index = field->index;
  245. }
  246. return 1;
  247. case HID_DG_TIPSWITCH:
  248. hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
  249. input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
  250. if (td->last_mt_collection == usage->collection_index) {
  251. td->last_slot_field = usage->hid;
  252. td->last_field_index = field->index;
  253. }
  254. return 1;
  255. case HID_DG_CONTACTID:
  256. if (!td->maxcontacts)
  257. td->maxcontacts = MT_DEFAULT_MAXCONTACT;
  258. input_mt_init_slots(hi->input, td->maxcontacts);
  259. td->last_slot_field = usage->hid;
  260. td->last_field_index = field->index;
  261. td->last_mt_collection = usage->collection_index;
  262. return 1;
  263. case HID_DG_WIDTH:
  264. hid_map_usage(hi, usage, bit, max,
  265. EV_ABS, ABS_MT_TOUCH_MAJOR);
  266. set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
  267. cls->sn_width);
  268. if (td->last_mt_collection == usage->collection_index) {
  269. td->last_slot_field = usage->hid;
  270. td->last_field_index = field->index;
  271. }
  272. return 1;
  273. case HID_DG_HEIGHT:
  274. hid_map_usage(hi, usage, bit, max,
  275. EV_ABS, ABS_MT_TOUCH_MINOR);
  276. set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
  277. cls->sn_height);
  278. input_set_abs_params(hi->input,
  279. ABS_MT_ORIENTATION, 0, 1, 0, 0);
  280. if (td->last_mt_collection == usage->collection_index) {
  281. td->last_slot_field = usage->hid;
  282. td->last_field_index = field->index;
  283. }
  284. return 1;
  285. case HID_DG_TIPPRESSURE:
  286. if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
  287. field->logical_minimum = 0;
  288. hid_map_usage(hi, usage, bit, max,
  289. EV_ABS, ABS_MT_PRESSURE);
  290. set_abs(hi->input, ABS_MT_PRESSURE, field,
  291. cls->sn_pressure);
  292. /* touchscreen emulation */
  293. set_abs(hi->input, ABS_PRESSURE, field,
  294. cls->sn_pressure);
  295. if (td->last_mt_collection == usage->collection_index) {
  296. td->last_slot_field = usage->hid;
  297. td->last_field_index = field->index;
  298. }
  299. return 1;
  300. case HID_DG_CONTACTCOUNT:
  301. if (td->last_mt_collection == usage->collection_index)
  302. td->last_field_index = field->index;
  303. return 1;
  304. case HID_DG_CONTACTMAX:
  305. /* we don't set td->last_slot_field as contactcount and
  306. * contact max are global to the report */
  307. if (td->last_mt_collection == usage->collection_index)
  308. td->last_field_index = field->index;
  309. return -1;
  310. }
  311. /* let hid-input decide for the others */
  312. return 0;
  313. case 0xff000000:
  314. /* we do not want to map these: no input-oriented meaning */
  315. return -1;
  316. }
  317. return 0;
  318. }
  319. static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  320. struct hid_field *field, struct hid_usage *usage,
  321. unsigned long **bit, int *max)
  322. {
  323. if (usage->type == EV_KEY || usage->type == EV_ABS)
  324. set_bit(usage->type, hi->input->evbit);
  325. return -1;
  326. }
  327. static int mt_compute_slot(struct mt_device *td)
  328. {
  329. __s32 quirks = td->mtclass->quirks;
  330. if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
  331. return td->curdata.contactid;
  332. if (quirks & MT_QUIRK_CYPRESS)
  333. return cypress_compute_slot(td);
  334. if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
  335. return td->num_received;
  336. if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
  337. return td->curdata.contactid - 1;
  338. return find_slot_from_contactid(td);
  339. }
  340. /*
  341. * this function is called when a whole contact has been processed,
  342. * so that it can assign it to a slot and store the data there
  343. */
  344. static void mt_complete_slot(struct mt_device *td)
  345. {
  346. td->curdata.seen_in_this_frame = true;
  347. if (td->curvalid) {
  348. int slotnum = mt_compute_slot(td);
  349. if (slotnum >= 0 && slotnum < td->maxcontacts)
  350. td->slots[slotnum] = td->curdata;
  351. }
  352. td->num_received++;
  353. }
  354. /*
  355. * this function is called when a whole packet has been received and processed,
  356. * so that it can decide what to send to the input layer.
  357. */
  358. static void mt_emit_event(struct mt_device *td, struct input_dev *input)
  359. {
  360. int i;
  361. for (i = 0; i < td->maxcontacts; ++i) {
  362. struct mt_slot *s = &(td->slots[i]);
  363. if ((td->mtclass->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
  364. !s->seen_in_this_frame) {
  365. s->touch_state = false;
  366. }
  367. input_mt_slot(input, i);
  368. input_mt_report_slot_state(input, MT_TOOL_FINGER,
  369. s->touch_state);
  370. if (s->touch_state) {
  371. /* this finger is on the screen */
  372. int wide = (s->w > s->h);
  373. /* divided by two to match visual scale of touch */
  374. int major = max(s->w, s->h) >> 1;
  375. int minor = min(s->w, s->h) >> 1;
  376. input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
  377. input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
  378. input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
  379. input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
  380. input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
  381. input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
  382. }
  383. s->seen_in_this_frame = false;
  384. }
  385. input_mt_report_pointer_emulation(input, true);
  386. input_sync(input);
  387. td->num_received = 0;
  388. }
  389. static int mt_event(struct hid_device *hid, struct hid_field *field,
  390. struct hid_usage *usage, __s32 value)
  391. {
  392. struct mt_device *td = hid_get_drvdata(hid);
  393. __s32 quirks = td->mtclass->quirks;
  394. if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
  395. switch (usage->hid) {
  396. case HID_DG_INRANGE:
  397. if (quirks & MT_QUIRK_VALID_IS_INRANGE)
  398. td->curvalid = value;
  399. break;
  400. case HID_DG_TIPSWITCH:
  401. if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
  402. td->curvalid = value;
  403. td->curdata.touch_state = value;
  404. break;
  405. case HID_DG_CONFIDENCE:
  406. if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
  407. td->curvalid = value;
  408. break;
  409. case HID_DG_CONTACTID:
  410. td->curdata.contactid = value;
  411. break;
  412. case HID_DG_TIPPRESSURE:
  413. td->curdata.p = value;
  414. break;
  415. case HID_GD_X:
  416. td->curdata.x = value;
  417. break;
  418. case HID_GD_Y:
  419. td->curdata.y = value;
  420. break;
  421. case HID_DG_WIDTH:
  422. td->curdata.w = value;
  423. break;
  424. case HID_DG_HEIGHT:
  425. td->curdata.h = value;
  426. break;
  427. case HID_DG_CONTACTCOUNT:
  428. /*
  429. * Includes multi-packet support where subsequent
  430. * packets are sent with zero contactcount.
  431. */
  432. if (value)
  433. td->num_expected = value;
  434. break;
  435. default:
  436. /* fallback to the generic hidinput handling */
  437. return 0;
  438. }
  439. if (usage->hid == td->last_slot_field) {
  440. mt_complete_slot(td);
  441. }
  442. if (field->index == td->last_field_index
  443. && td->num_received >= td->num_expected)
  444. mt_emit_event(td, field->hidinput->input);
  445. }
  446. /* we have handled the hidinput part, now remains hiddev */
  447. if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
  448. hid->hiddev_hid_event(hid, field, usage, value);
  449. return 1;
  450. }
  451. static void mt_set_input_mode(struct hid_device *hdev)
  452. {
  453. struct mt_device *td = hid_get_drvdata(hdev);
  454. struct hid_report *r;
  455. struct hid_report_enum *re;
  456. if (td->inputmode < 0)
  457. return;
  458. re = &(hdev->report_enum[HID_FEATURE_REPORT]);
  459. r = re->report_id_hash[td->inputmode];
  460. if (r) {
  461. r->field[0]->value[0] = 0x02;
  462. usbhid_submit_report(hdev, r, USB_DIR_OUT);
  463. }
  464. }
  465. static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
  466. {
  467. int ret, i;
  468. struct mt_device *td;
  469. struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
  470. for (i = 0; mt_classes[i].name ; i++) {
  471. if (id->driver_data == mt_classes[i].name) {
  472. mtclass = &(mt_classes[i]);
  473. break;
  474. }
  475. }
  476. /* This allows the driver to correctly support devices
  477. * that emit events over several HID messages.
  478. */
  479. hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
  480. td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
  481. if (!td) {
  482. dev_err(&hdev->dev, "cannot allocate multitouch data\n");
  483. return -ENOMEM;
  484. }
  485. td->mtclass = mtclass;
  486. td->inputmode = -1;
  487. td->last_mt_collection = -1;
  488. hid_set_drvdata(hdev, td);
  489. ret = hid_parse(hdev);
  490. if (ret != 0)
  491. goto fail;
  492. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  493. if (ret)
  494. goto fail;
  495. td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
  496. GFP_KERNEL);
  497. if (!td->slots) {
  498. dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
  499. hid_hw_stop(hdev);
  500. ret = -ENOMEM;
  501. goto fail;
  502. }
  503. mt_set_input_mode(hdev);
  504. return 0;
  505. fail:
  506. kfree(td);
  507. return ret;
  508. }
  509. #ifdef CONFIG_PM
  510. static int mt_reset_resume(struct hid_device *hdev)
  511. {
  512. mt_set_input_mode(hdev);
  513. return 0;
  514. }
  515. #endif
  516. static void mt_remove(struct hid_device *hdev)
  517. {
  518. struct mt_device *td = hid_get_drvdata(hdev);
  519. hid_hw_stop(hdev);
  520. kfree(td->slots);
  521. kfree(td);
  522. hid_set_drvdata(hdev, NULL);
  523. }
  524. static const struct hid_device_id mt_devices[] = {
  525. /* 3M panels */
  526. { .driver_data = MT_CLS_3M,
  527. HID_USB_DEVICE(USB_VENDOR_ID_3M,
  528. USB_DEVICE_ID_3M1968) },
  529. { .driver_data = MT_CLS_3M,
  530. HID_USB_DEVICE(USB_VENDOR_ID_3M,
  531. USB_DEVICE_ID_3M2256) },
  532. { .driver_data = MT_CLS_3M,
  533. HID_USB_DEVICE(USB_VENDOR_ID_3M,
  534. USB_DEVICE_ID_3M3266) },
  535. /* ActionStar panels */
  536. { .driver_data = MT_CLS_DEFAULT,
  537. HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
  538. USB_DEVICE_ID_ACTIONSTAR_1011) },
  539. /* Cando panels */
  540. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  541. HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
  542. USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
  543. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  544. HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
  545. USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
  546. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  547. HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
  548. USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
  549. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  550. HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
  551. USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
  552. /* Chunghwa Telecom touch panels */
  553. { .driver_data = MT_CLS_DEFAULT,
  554. HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
  555. USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
  556. /* CVTouch panels */
  557. { .driver_data = MT_CLS_DEFAULT,
  558. HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
  559. USB_DEVICE_ID_CVTOUCH_SCREEN) },
  560. /* Cypress panel */
  561. { .driver_data = MT_CLS_CYPRESS,
  562. HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS,
  563. USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
  564. /* eGalax devices (resistive) */
  565. { .driver_data = MT_CLS_EGALAX,
  566. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  567. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
  568. { .driver_data = MT_CLS_EGALAX,
  569. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  570. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
  571. /* eGalax devices (capacitive) */
  572. { .driver_data = MT_CLS_EGALAX,
  573. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  574. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
  575. { .driver_data = MT_CLS_EGALAX,
  576. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  577. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
  578. { .driver_data = MT_CLS_EGALAX,
  579. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  580. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
  581. { .driver_data = MT_CLS_EGALAX,
  582. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  583. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
  584. { .driver_data = MT_CLS_EGALAX,
  585. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  586. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
  587. { .driver_data = MT_CLS_EGALAX,
  588. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  589. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
  590. /* Elo TouchSystems IntelliTouch Plus panel */
  591. { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
  592. HID_USB_DEVICE(USB_VENDOR_ID_ELO,
  593. USB_DEVICE_ID_ELO_TS2515) },
  594. /* GeneralTouch panel */
  595. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  596. HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  597. USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
  598. /* GoodTouch panels */
  599. { .driver_data = MT_CLS_DEFAULT,
  600. HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
  601. USB_DEVICE_ID_GOODTOUCH_000f) },
  602. /* Ilitek dual touch panel */
  603. { .driver_data = MT_CLS_DEFAULT,
  604. HID_USB_DEVICE(USB_VENDOR_ID_ILITEK,
  605. USB_DEVICE_ID_ILITEK_MULTITOUCH) },
  606. /* IRTOUCH panels */
  607. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  608. HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS,
  609. USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
  610. /* LG Display panels */
  611. { .driver_data = MT_CLS_DEFAULT,
  612. HID_USB_DEVICE(USB_VENDOR_ID_LG,
  613. USB_DEVICE_ID_LG_MULTITOUCH) },
  614. /* Lumio panels */
  615. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  616. HID_USB_DEVICE(USB_VENDOR_ID_LUMIO,
  617. USB_DEVICE_ID_CRYSTALTOUCH) },
  618. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  619. HID_USB_DEVICE(USB_VENDOR_ID_LUMIO,
  620. USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
  621. /* MosArt panels */
  622. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  623. HID_USB_DEVICE(USB_VENDOR_ID_ASUS,
  624. USB_DEVICE_ID_ASUS_T91MT)},
  625. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  626. HID_USB_DEVICE(USB_VENDOR_ID_ASUS,
  627. USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
  628. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  629. HID_USB_DEVICE(USB_VENDOR_ID_TURBOX,
  630. USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
  631. /* PenMount panels */
  632. { .driver_data = MT_CLS_CONFIDENCE,
  633. HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
  634. USB_DEVICE_ID_PENMOUNT_PCI) },
  635. /* PixCir-based panels */
  636. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  637. HID_USB_DEVICE(USB_VENDOR_ID_HANVON,
  638. USB_DEVICE_ID_HANVON_MULTITOUCH) },
  639. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  640. HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
  641. USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
  642. /* Stantum panels */
  643. { .driver_data = MT_CLS_CONFIDENCE,
  644. HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
  645. USB_DEVICE_ID_MTP)},
  646. { .driver_data = MT_CLS_CONFIDENCE,
  647. HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
  648. USB_DEVICE_ID_MTP_STM)},
  649. { .driver_data = MT_CLS_CONFIDENCE,
  650. HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX,
  651. USB_DEVICE_ID_MTP_SITRONIX)},
  652. /* Touch International panels */
  653. { .driver_data = MT_CLS_DEFAULT,
  654. HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
  655. USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
  656. /* Unitec panels */
  657. { .driver_data = MT_CLS_DEFAULT,
  658. HID_USB_DEVICE(USB_VENDOR_ID_UNITEC,
  659. USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
  660. { .driver_data = MT_CLS_DEFAULT,
  661. HID_USB_DEVICE(USB_VENDOR_ID_UNITEC,
  662. USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
  663. { }
  664. };
  665. MODULE_DEVICE_TABLE(hid, mt_devices);
  666. static const struct hid_usage_id mt_grabbed_usages[] = {
  667. { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
  668. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
  669. };
  670. static struct hid_driver mt_driver = {
  671. .name = "hid-multitouch",
  672. .id_table = mt_devices,
  673. .probe = mt_probe,
  674. .remove = mt_remove,
  675. .input_mapping = mt_input_mapping,
  676. .input_mapped = mt_input_mapped,
  677. .feature_mapping = mt_feature_mapping,
  678. .usage_table = mt_grabbed_usages,
  679. .event = mt_event,
  680. #ifdef CONFIG_PM
  681. .reset_resume = mt_reset_resume,
  682. #endif
  683. };
  684. static int __init mt_init(void)
  685. {
  686. return hid_register_driver(&mt_driver);
  687. }
  688. static void __exit mt_exit(void)
  689. {
  690. hid_unregister_driver(&mt_driver);
  691. }
  692. module_init(mt_init);
  693. module_exit(mt_exit);