hid-multitouch.c 26 KB

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