hid-multitouch.c 23 KB

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