hid-multitouch.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. /*
  2. * HID driver for multitouch panels
  3. *
  4. * Copyright (c) 2010-2012 Stephane Chatty <chatty@enac.fr>
  5. * Copyright (c) 2010-2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
  6. * Copyright (c) 2010-2012 Ecole Nationale de l'Aviation Civile, France
  7. * Copyright (c) 2012-2013 Red Hat, Inc
  8. *
  9. * This code is partly based on hid-egalax.c:
  10. *
  11. * Copyright (c) 2010 Stephane Chatty <chatty@enac.fr>
  12. * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
  13. * Copyright (c) 2010 Canonical, Ltd.
  14. *
  15. * This code is partly based on hid-3m-pct.c:
  16. *
  17. * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
  18. * Copyright (c) 2010 Henrik Rydberg <rydberg@euromail.se>
  19. * Copyright (c) 2010 Canonical, Ltd.
  20. *
  21. */
  22. /*
  23. * This program is free software; you can redistribute it and/or modify it
  24. * under the terms of the GNU General Public License as published by the Free
  25. * Software Foundation; either version 2 of the License, or (at your option)
  26. * any later version.
  27. */
  28. /*
  29. * This driver is regularly tested thanks to the tool hid-test[1].
  30. * This tool relies on hid-replay[2] and a database of hid devices[3].
  31. * Please run these regression tests before patching this module so that
  32. * your patch won't break existing known devices.
  33. *
  34. * [1] https://github.com/bentiss/hid-test
  35. * [2] https://github.com/bentiss/hid-replay
  36. * [3] https://github.com/bentiss/hid-devices
  37. */
  38. #include <linux/device.h>
  39. #include <linux/hid.h>
  40. #include <linux/module.h>
  41. #include <linux/slab.h>
  42. #include <linux/input/mt.h>
  43. #include <linux/string.h>
  44. MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
  45. MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
  46. MODULE_DESCRIPTION("HID multitouch panels");
  47. MODULE_LICENSE("GPL");
  48. #include "hid-ids.h"
  49. /* quirks to control the device */
  50. #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
  51. #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
  52. #define MT_QUIRK_CYPRESS (1 << 2)
  53. #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
  54. #define MT_QUIRK_ALWAYS_VALID (1 << 4)
  55. #define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
  56. #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
  57. #define MT_QUIRK_CONFIDENCE (1 << 7)
  58. #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
  59. #define MT_QUIRK_NO_AREA (1 << 9)
  60. #define MT_QUIRK_IGNORE_DUPLICATES (1 << 10)
  61. #define MT_QUIRK_HOVERING (1 << 11)
  62. #define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12)
  63. #define MT_QUIRK_FORCE_GET_FEATURE (1 << 13)
  64. #define MT_QUIRK_FIX_CONST_CONTACT_ID (1 << 14)
  65. #define MT_QUIRK_TOUCH_SIZE_SCALING (1 << 15)
  66. #define MT_INPUTMODE_TOUCHSCREEN 0x02
  67. #define MT_INPUTMODE_TOUCHPAD 0x03
  68. #define MT_BUTTONTYPE_CLICKPAD 0
  69. struct mt_slot {
  70. __s32 x, y, cx, cy, p, w, h;
  71. __s32 contactid; /* the device ContactID assigned to this slot */
  72. bool touch_state; /* is the touch valid? */
  73. bool inrange_state; /* is the finger in proximity of the sensor? */
  74. bool confidence_state; /* is the touch made by a finger? */
  75. };
  76. struct mt_class {
  77. __s32 name; /* MT_CLS */
  78. __s32 quirks;
  79. __s32 sn_move; /* Signal/noise ratio for move events */
  80. __s32 sn_width; /* Signal/noise ratio for width events */
  81. __s32 sn_height; /* Signal/noise ratio for height events */
  82. __s32 sn_pressure; /* Signal/noise ratio for pressure events */
  83. __u8 maxcontacts;
  84. bool is_indirect; /* true for touchpads */
  85. bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
  86. };
  87. struct mt_fields {
  88. unsigned usages[HID_MAX_FIELDS];
  89. unsigned int length;
  90. };
  91. struct mt_device {
  92. struct mt_slot curdata; /* placeholder of incoming data */
  93. struct mt_class mtclass; /* our mt device class */
  94. struct mt_fields *fields; /* temporary placeholder for storing the
  95. multitouch fields */
  96. int cc_index; /* contact count field index in the report */
  97. int cc_value_index; /* contact count value index in the field */
  98. unsigned last_slot_field; /* the last field of a slot */
  99. unsigned mt_report_id; /* the report ID of the multitouch device */
  100. unsigned long initial_quirks; /* initial quirks state */
  101. __s16 inputmode; /* InputMode HID feature, -1 if non-existent */
  102. __s16 inputmode_index; /* InputMode HID feature index in the report */
  103. __s16 maxcontact_report_id; /* Maximum Contact Number HID feature,
  104. -1 if non-existent */
  105. __u8 inputmode_value; /* InputMode HID feature value */
  106. __u8 num_received; /* how many contacts we received */
  107. __u8 num_expected; /* expected last contact index */
  108. __u8 maxcontacts;
  109. __u8 touches_by_report; /* how many touches are present in one report:
  110. * 1 means we should use a serial protocol
  111. * > 1 means hybrid (multitouch) protocol */
  112. __u8 buttons_count; /* number of physical buttons per touchpad */
  113. bool is_buttonpad; /* is this device a button pad? */
  114. bool serial_maybe; /* need to check for serial protocol */
  115. bool curvalid; /* is the current contact valid? */
  116. unsigned mt_flags; /* flags to pass to input-mt */
  117. };
  118. static void mt_post_parse_default_settings(struct mt_device *td);
  119. static void mt_post_parse(struct mt_device *td);
  120. /* classes of device behavior */
  121. #define MT_CLS_DEFAULT 0x0001
  122. #define MT_CLS_SERIAL 0x0002
  123. #define MT_CLS_CONFIDENCE 0x0003
  124. #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
  125. #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
  126. #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
  127. #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
  128. /* reserved 0x0008 */
  129. #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
  130. #define MT_CLS_NSMU 0x000a
  131. /* reserved 0x0010 */
  132. /* reserved 0x0011 */
  133. #define MT_CLS_WIN_8 0x0012
  134. #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
  135. /* vendor specific classes */
  136. #define MT_CLS_3M 0x0101
  137. /* reserved 0x0102 */
  138. #define MT_CLS_EGALAX 0x0103
  139. #define MT_CLS_EGALAX_SERIAL 0x0104
  140. #define MT_CLS_TOPSEED 0x0105
  141. #define MT_CLS_PANASONIC 0x0106
  142. #define MT_CLS_FLATFROG 0x0107
  143. #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
  144. #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
  145. #define MT_CLS_LG 0x010a
  146. #define MT_CLS_VTL 0x0110
  147. #define MT_DEFAULT_MAXCONTACT 10
  148. #define MT_MAX_MAXCONTACT 250
  149. #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
  150. #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
  151. /*
  152. * these device-dependent functions determine what slot corresponds
  153. * to a valid contact that was just read.
  154. */
  155. static int cypress_compute_slot(struct mt_device *td)
  156. {
  157. if (td->curdata.contactid != 0 || td->num_received == 0)
  158. return td->curdata.contactid;
  159. else
  160. return -1;
  161. }
  162. static struct mt_class mt_classes[] = {
  163. { .name = MT_CLS_DEFAULT,
  164. .quirks = MT_QUIRK_ALWAYS_VALID |
  165. MT_QUIRK_CONTACT_CNT_ACCURATE },
  166. { .name = MT_CLS_NSMU,
  167. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
  168. { .name = MT_CLS_SERIAL,
  169. .quirks = MT_QUIRK_ALWAYS_VALID},
  170. { .name = MT_CLS_CONFIDENCE,
  171. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
  172. { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
  173. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  174. MT_QUIRK_SLOT_IS_CONTACTID },
  175. { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
  176. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  177. MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
  178. { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
  179. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  180. MT_QUIRK_SLOT_IS_CONTACTID,
  181. .maxcontacts = 2 },
  182. { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  183. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  184. MT_QUIRK_SLOT_IS_CONTACTNUMBER,
  185. .maxcontacts = 2 },
  186. { .name = MT_CLS_INRANGE_CONTACTNUMBER,
  187. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  188. MT_QUIRK_SLOT_IS_CONTACTNUMBER },
  189. { .name = MT_CLS_WIN_8,
  190. .quirks = MT_QUIRK_ALWAYS_VALID |
  191. MT_QUIRK_IGNORE_DUPLICATES |
  192. MT_QUIRK_HOVERING |
  193. MT_QUIRK_CONTACT_CNT_ACCURATE },
  194. { .name = MT_CLS_EXPORT_ALL_INPUTS,
  195. .quirks = MT_QUIRK_ALWAYS_VALID |
  196. MT_QUIRK_CONTACT_CNT_ACCURATE,
  197. .export_all_inputs = true },
  198. /*
  199. * vendor specific classes
  200. */
  201. { .name = MT_CLS_3M,
  202. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  203. MT_QUIRK_SLOT_IS_CONTACTID |
  204. MT_QUIRK_TOUCH_SIZE_SCALING,
  205. .sn_move = 2048,
  206. .sn_width = 128,
  207. .sn_height = 128,
  208. .maxcontacts = 60,
  209. },
  210. { .name = MT_CLS_EGALAX,
  211. .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
  212. MT_QUIRK_VALID_IS_INRANGE,
  213. .sn_move = 4096,
  214. .sn_pressure = 32,
  215. },
  216. { .name = MT_CLS_EGALAX_SERIAL,
  217. .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
  218. MT_QUIRK_ALWAYS_VALID,
  219. .sn_move = 4096,
  220. .sn_pressure = 32,
  221. },
  222. { .name = MT_CLS_TOPSEED,
  223. .quirks = MT_QUIRK_ALWAYS_VALID,
  224. .is_indirect = true,
  225. .maxcontacts = 2,
  226. },
  227. { .name = MT_CLS_PANASONIC,
  228. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
  229. .maxcontacts = 4 },
  230. { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
  231. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  232. MT_QUIRK_VALID_IS_INRANGE |
  233. MT_QUIRK_SLOT_IS_CONTACTID,
  234. .maxcontacts = 2
  235. },
  236. { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  237. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  238. MT_QUIRK_SLOT_IS_CONTACTID
  239. },
  240. { .name = MT_CLS_FLATFROG,
  241. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  242. MT_QUIRK_NO_AREA,
  243. .sn_move = 2048,
  244. .maxcontacts = 40,
  245. },
  246. { .name = MT_CLS_LG,
  247. .quirks = MT_QUIRK_ALWAYS_VALID |
  248. MT_QUIRK_FIX_CONST_CONTACT_ID |
  249. MT_QUIRK_IGNORE_DUPLICATES |
  250. MT_QUIRK_HOVERING |
  251. MT_QUIRK_CONTACT_CNT_ACCURATE },
  252. { .name = MT_CLS_VTL,
  253. .quirks = MT_QUIRK_ALWAYS_VALID |
  254. MT_QUIRK_CONTACT_CNT_ACCURATE |
  255. MT_QUIRK_FORCE_GET_FEATURE,
  256. },
  257. { }
  258. };
  259. static ssize_t mt_show_quirks(struct device *dev,
  260. struct device_attribute *attr,
  261. char *buf)
  262. {
  263. struct hid_device *hdev = to_hid_device(dev);
  264. struct mt_device *td = hid_get_drvdata(hdev);
  265. return sprintf(buf, "%u\n", td->mtclass.quirks);
  266. }
  267. static ssize_t mt_set_quirks(struct device *dev,
  268. struct device_attribute *attr,
  269. const char *buf, size_t count)
  270. {
  271. struct hid_device *hdev = to_hid_device(dev);
  272. struct mt_device *td = hid_get_drvdata(hdev);
  273. unsigned long val;
  274. if (kstrtoul(buf, 0, &val))
  275. return -EINVAL;
  276. td->mtclass.quirks = val;
  277. if (td->cc_index < 0)
  278. td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
  279. return count;
  280. }
  281. static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
  282. static struct attribute *sysfs_attrs[] = {
  283. &dev_attr_quirks.attr,
  284. NULL
  285. };
  286. static struct attribute_group mt_attribute_group = {
  287. .attrs = sysfs_attrs
  288. };
  289. static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
  290. {
  291. struct mt_device *td = hid_get_drvdata(hdev);
  292. int ret, size = hid_report_len(report);
  293. u8 *buf;
  294. /*
  295. * Do not fetch the feature report if the device has been explicitly
  296. * marked as non-capable.
  297. */
  298. if (td->initial_quirks & HID_QUIRK_NO_INIT_REPORTS)
  299. return;
  300. buf = hid_alloc_report_buf(report, GFP_KERNEL);
  301. if (!buf)
  302. return;
  303. ret = hid_hw_raw_request(hdev, report->id, buf, size,
  304. HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
  305. if (ret < 0) {
  306. dev_warn(&hdev->dev, "failed to fetch feature %d\n",
  307. report->id);
  308. } else {
  309. ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
  310. size, 0);
  311. if (ret)
  312. dev_warn(&hdev->dev, "failed to report feature\n");
  313. }
  314. kfree(buf);
  315. }
  316. static void mt_feature_mapping(struct hid_device *hdev,
  317. struct hid_field *field, struct hid_usage *usage)
  318. {
  319. struct mt_device *td = hid_get_drvdata(hdev);
  320. switch (usage->hid) {
  321. case HID_DG_INPUTMODE:
  322. /* Ignore if value index is out of bounds. */
  323. if (usage->usage_index >= field->report_count) {
  324. dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
  325. break;
  326. }
  327. if (td->inputmode < 0) {
  328. td->inputmode = field->report->id;
  329. td->inputmode_index = usage->usage_index;
  330. } else {
  331. /*
  332. * Some elan panels wrongly declare 2 input mode
  333. * features, and silently ignore when we set the
  334. * value in the second field. Skip the second feature
  335. * and hope for the best.
  336. */
  337. dev_info(&hdev->dev,
  338. "Ignoring the extra HID_DG_INPUTMODE\n");
  339. }
  340. break;
  341. case HID_DG_CONTACTMAX:
  342. mt_get_feature(hdev, field->report);
  343. td->maxcontact_report_id = field->report->id;
  344. td->maxcontacts = field->value[0];
  345. if (!td->maxcontacts &&
  346. field->logical_maximum <= MT_MAX_MAXCONTACT)
  347. td->maxcontacts = field->logical_maximum;
  348. if (td->mtclass.maxcontacts)
  349. /* check if the maxcontacts is given by the class */
  350. td->maxcontacts = td->mtclass.maxcontacts;
  351. break;
  352. case HID_DG_BUTTONTYPE:
  353. if (usage->usage_index >= field->report_count) {
  354. dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
  355. break;
  356. }
  357. mt_get_feature(hdev, field->report);
  358. if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
  359. td->is_buttonpad = true;
  360. break;
  361. case 0xff0000c5:
  362. /* Retrieve the Win8 blob once to enable some devices */
  363. if (usage->usage_index == 0)
  364. mt_get_feature(hdev, field->report);
  365. break;
  366. }
  367. }
  368. static void set_abs(struct input_dev *input, unsigned int code,
  369. struct hid_field *field, int snratio)
  370. {
  371. int fmin = field->logical_minimum;
  372. int fmax = field->logical_maximum;
  373. int fuzz = snratio ? (fmax - fmin) / snratio : 0;
  374. input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
  375. input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
  376. }
  377. static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
  378. struct hid_input *hi)
  379. {
  380. struct mt_fields *f = td->fields;
  381. if (f->length >= HID_MAX_FIELDS)
  382. return;
  383. f->usages[f->length++] = usage->hid;
  384. }
  385. static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  386. struct hid_field *field, struct hid_usage *usage,
  387. unsigned long **bit, int *max)
  388. {
  389. struct mt_device *td = hid_get_drvdata(hdev);
  390. struct mt_class *cls = &td->mtclass;
  391. int code;
  392. struct hid_usage *prev_usage = NULL;
  393. if (field->application == HID_DG_TOUCHSCREEN)
  394. td->mt_flags |= INPUT_MT_DIRECT;
  395. /*
  396. * Model touchscreens providing buttons as touchpads.
  397. */
  398. if (field->application == HID_DG_TOUCHPAD ||
  399. (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
  400. td->mt_flags |= INPUT_MT_POINTER;
  401. td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
  402. }
  403. /* count the buttons on touchpads */
  404. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
  405. td->buttons_count++;
  406. if (usage->usage_index)
  407. prev_usage = &field->usage[usage->usage_index - 1];
  408. switch (usage->hid & HID_USAGE_PAGE) {
  409. case HID_UP_GENDESK:
  410. switch (usage->hid) {
  411. case HID_GD_X:
  412. if (prev_usage && (prev_usage->hid == usage->hid)) {
  413. hid_map_usage(hi, usage, bit, max,
  414. EV_ABS, ABS_MT_TOOL_X);
  415. set_abs(hi->input, ABS_MT_TOOL_X, field,
  416. cls->sn_move);
  417. } else {
  418. hid_map_usage(hi, usage, bit, max,
  419. EV_ABS, ABS_MT_POSITION_X);
  420. set_abs(hi->input, ABS_MT_POSITION_X, field,
  421. cls->sn_move);
  422. }
  423. mt_store_field(usage, td, hi);
  424. return 1;
  425. case HID_GD_Y:
  426. if (prev_usage && (prev_usage->hid == usage->hid)) {
  427. hid_map_usage(hi, usage, bit, max,
  428. EV_ABS, ABS_MT_TOOL_Y);
  429. set_abs(hi->input, ABS_MT_TOOL_Y, field,
  430. cls->sn_move);
  431. } else {
  432. hid_map_usage(hi, usage, bit, max,
  433. EV_ABS, ABS_MT_POSITION_Y);
  434. set_abs(hi->input, ABS_MT_POSITION_Y, field,
  435. cls->sn_move);
  436. }
  437. mt_store_field(usage, td, hi);
  438. return 1;
  439. }
  440. return 0;
  441. case HID_UP_DIGITIZER:
  442. switch (usage->hid) {
  443. case HID_DG_INRANGE:
  444. if (cls->quirks & MT_QUIRK_HOVERING) {
  445. hid_map_usage(hi, usage, bit, max,
  446. EV_ABS, ABS_MT_DISTANCE);
  447. input_set_abs_params(hi->input,
  448. ABS_MT_DISTANCE, 0, 1, 0, 0);
  449. }
  450. mt_store_field(usage, td, hi);
  451. return 1;
  452. case HID_DG_CONFIDENCE:
  453. if (cls->name == MT_CLS_WIN_8 &&
  454. field->application == HID_DG_TOUCHPAD)
  455. cls->quirks |= MT_QUIRK_CONFIDENCE;
  456. mt_store_field(usage, td, hi);
  457. return 1;
  458. case HID_DG_TIPSWITCH:
  459. hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
  460. input_set_capability(hi->input, EV_KEY, BTN_TOUCH);
  461. mt_store_field(usage, td, hi);
  462. return 1;
  463. case HID_DG_CONTACTID:
  464. mt_store_field(usage, td, hi);
  465. td->touches_by_report++;
  466. td->mt_report_id = field->report->id;
  467. return 1;
  468. case HID_DG_WIDTH:
  469. hid_map_usage(hi, usage, bit, max,
  470. EV_ABS, ABS_MT_TOUCH_MAJOR);
  471. if (!(cls->quirks & MT_QUIRK_NO_AREA))
  472. set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
  473. cls->sn_width);
  474. mt_store_field(usage, td, hi);
  475. return 1;
  476. case HID_DG_HEIGHT:
  477. hid_map_usage(hi, usage, bit, max,
  478. EV_ABS, ABS_MT_TOUCH_MINOR);
  479. if (!(cls->quirks & MT_QUIRK_NO_AREA)) {
  480. set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
  481. cls->sn_height);
  482. input_set_abs_params(hi->input,
  483. ABS_MT_ORIENTATION, 0, 1, 0, 0);
  484. }
  485. mt_store_field(usage, td, hi);
  486. return 1;
  487. case HID_DG_TIPPRESSURE:
  488. hid_map_usage(hi, usage, bit, max,
  489. EV_ABS, ABS_MT_PRESSURE);
  490. set_abs(hi->input, ABS_MT_PRESSURE, field,
  491. cls->sn_pressure);
  492. mt_store_field(usage, td, hi);
  493. return 1;
  494. case HID_DG_CONTACTCOUNT:
  495. /* Ignore if indexes are out of bounds. */
  496. if (field->index >= field->report->maxfield ||
  497. usage->usage_index >= field->report_count)
  498. return 1;
  499. td->cc_index = field->index;
  500. td->cc_value_index = usage->usage_index;
  501. return 1;
  502. case HID_DG_CONTACTMAX:
  503. /* we don't set td->last_slot_field as contactcount and
  504. * contact max are global to the report */
  505. return -1;
  506. case HID_DG_TOUCH:
  507. /* Legacy devices use TIPSWITCH and not TOUCH.
  508. * Let's just ignore this field. */
  509. return -1;
  510. }
  511. /* let hid-input decide for the others */
  512. return 0;
  513. case HID_UP_BUTTON:
  514. code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
  515. /*
  516. * MS PTP spec says that external buttons left and right have
  517. * usages 2 and 3.
  518. */
  519. if (cls->name == MT_CLS_WIN_8 &&
  520. field->application == HID_DG_TOUCHPAD &&
  521. (usage->hid & HID_USAGE) > 1)
  522. code--;
  523. hid_map_usage(hi, usage, bit, max, EV_KEY, code);
  524. input_set_capability(hi->input, EV_KEY, code);
  525. return 1;
  526. case 0xff000000:
  527. /* we do not want to map these: no input-oriented meaning */
  528. return -1;
  529. }
  530. return 0;
  531. }
  532. static int mt_touch_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  533. struct hid_field *field, struct hid_usage *usage,
  534. unsigned long **bit, int *max)
  535. {
  536. if (usage->type == EV_KEY || usage->type == EV_ABS)
  537. set_bit(usage->type, hi->input->evbit);
  538. return -1;
  539. }
  540. static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
  541. {
  542. __s32 quirks = td->mtclass.quirks;
  543. if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
  544. return td->curdata.contactid;
  545. if (quirks & MT_QUIRK_CYPRESS)
  546. return cypress_compute_slot(td);
  547. if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
  548. return td->num_received;
  549. if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
  550. return td->curdata.contactid - 1;
  551. return input_mt_get_slot_by_key(input, td->curdata.contactid);
  552. }
  553. /*
  554. * this function is called when a whole contact has been processed,
  555. * so that it can assign it to a slot and store the data there
  556. */
  557. static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
  558. {
  559. if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
  560. td->num_received >= td->num_expected)
  561. return;
  562. if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
  563. int active;
  564. int slotnum = mt_compute_slot(td, input);
  565. struct mt_slot *s = &td->curdata;
  566. struct input_mt *mt = input->mt;
  567. if (slotnum < 0 || slotnum >= td->maxcontacts)
  568. return;
  569. if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
  570. struct input_mt_slot *slot = &mt->slots[slotnum];
  571. if (input_mt_is_active(slot) &&
  572. input_mt_is_used(mt, slot))
  573. return;
  574. }
  575. if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE))
  576. s->confidence_state = 1;
  577. active = (s->touch_state || s->inrange_state) &&
  578. s->confidence_state;
  579. input_mt_slot(input, slotnum);
  580. input_mt_report_slot_state(input, MT_TOOL_FINGER, active);
  581. if (active) {
  582. /* this finger is in proximity of the sensor */
  583. int wide = (s->w > s->h);
  584. int major = max(s->w, s->h);
  585. int minor = min(s->w, s->h);
  586. /*
  587. * divided by two to match visual scale of touch
  588. * for devices with this quirk
  589. */
  590. if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
  591. major = major >> 1;
  592. minor = minor >> 1;
  593. }
  594. input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
  595. input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
  596. input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
  597. input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
  598. input_event(input, EV_ABS, ABS_MT_DISTANCE,
  599. !s->touch_state);
  600. input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
  601. input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
  602. input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
  603. input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
  604. }
  605. }
  606. td->num_received++;
  607. }
  608. /*
  609. * this function is called when a whole packet has been received and processed,
  610. * so that it can decide what to send to the input layer.
  611. */
  612. static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
  613. {
  614. input_mt_sync_frame(input);
  615. input_sync(input);
  616. td->num_received = 0;
  617. }
  618. static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
  619. struct hid_usage *usage, __s32 value)
  620. {
  621. /* we will handle the hidinput part later, now remains hiddev */
  622. if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
  623. hid->hiddev_hid_event(hid, field, usage, value);
  624. return 1;
  625. }
  626. static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
  627. struct hid_usage *usage, __s32 value)
  628. {
  629. struct mt_device *td = hid_get_drvdata(hid);
  630. __s32 quirks = td->mtclass.quirks;
  631. struct input_dev *input = field->hidinput->input;
  632. if (hid->claimed & HID_CLAIMED_INPUT) {
  633. switch (usage->hid) {
  634. case HID_DG_INRANGE:
  635. if (quirks & MT_QUIRK_VALID_IS_INRANGE)
  636. td->curvalid = value;
  637. if (quirks & MT_QUIRK_HOVERING)
  638. td->curdata.inrange_state = value;
  639. break;
  640. case HID_DG_TIPSWITCH:
  641. if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
  642. td->curvalid = value;
  643. td->curdata.touch_state = value;
  644. break;
  645. case HID_DG_CONFIDENCE:
  646. if (quirks & MT_QUIRK_CONFIDENCE)
  647. td->curdata.confidence_state = value;
  648. if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
  649. td->curvalid = value;
  650. break;
  651. case HID_DG_CONTACTID:
  652. td->curdata.contactid = value;
  653. break;
  654. case HID_DG_TIPPRESSURE:
  655. td->curdata.p = value;
  656. break;
  657. case HID_GD_X:
  658. if (usage->code == ABS_MT_TOOL_X)
  659. td->curdata.cx = value;
  660. else
  661. td->curdata.x = value;
  662. break;
  663. case HID_GD_Y:
  664. if (usage->code == ABS_MT_TOOL_Y)
  665. td->curdata.cy = value;
  666. else
  667. td->curdata.y = value;
  668. break;
  669. case HID_DG_WIDTH:
  670. td->curdata.w = value;
  671. break;
  672. case HID_DG_HEIGHT:
  673. td->curdata.h = value;
  674. break;
  675. case HID_DG_CONTACTCOUNT:
  676. break;
  677. case HID_DG_TOUCH:
  678. /* do nothing */
  679. break;
  680. default:
  681. if (usage->type)
  682. input_event(input, usage->type, usage->code,
  683. value);
  684. return;
  685. }
  686. if (usage->usage_index + 1 == field->report_count) {
  687. /* we only take into account the last report. */
  688. if (usage->hid == td->last_slot_field)
  689. mt_complete_slot(td, field->hidinput->input);
  690. }
  691. }
  692. }
  693. static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
  694. {
  695. struct mt_device *td = hid_get_drvdata(hid);
  696. struct hid_field *field;
  697. unsigned count;
  698. int r, n;
  699. /*
  700. * Includes multi-packet support where subsequent
  701. * packets are sent with zero contactcount.
  702. */
  703. if (td->cc_index >= 0) {
  704. struct hid_field *field = report->field[td->cc_index];
  705. int value = field->value[td->cc_value_index];
  706. if (value)
  707. td->num_expected = value;
  708. }
  709. for (r = 0; r < report->maxfield; r++) {
  710. field = report->field[r];
  711. count = field->report_count;
  712. if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
  713. continue;
  714. for (n = 0; n < count; n++)
  715. mt_process_mt_event(hid, field, &field->usage[n],
  716. field->value[n]);
  717. }
  718. if (td->num_received >= td->num_expected)
  719. mt_sync_frame(td, report->field[0]->hidinput->input);
  720. }
  721. static int mt_touch_input_configured(struct hid_device *hdev,
  722. struct hid_input *hi)
  723. {
  724. struct mt_device *td = hid_get_drvdata(hdev);
  725. struct mt_class *cls = &td->mtclass;
  726. struct input_dev *input = hi->input;
  727. int ret;
  728. if (!td->maxcontacts)
  729. td->maxcontacts = MT_DEFAULT_MAXCONTACT;
  730. mt_post_parse(td);
  731. if (td->serial_maybe)
  732. mt_post_parse_default_settings(td);
  733. if (cls->is_indirect)
  734. td->mt_flags |= INPUT_MT_POINTER;
  735. if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
  736. td->mt_flags |= INPUT_MT_DROP_UNUSED;
  737. /* check for clickpads */
  738. if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1))
  739. td->is_buttonpad = true;
  740. if (td->is_buttonpad)
  741. __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
  742. ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
  743. if (ret)
  744. return ret;
  745. td->mt_flags = 0;
  746. return 0;
  747. }
  748. static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  749. struct hid_field *field, struct hid_usage *usage,
  750. unsigned long **bit, int *max)
  751. {
  752. struct mt_device *td = hid_get_drvdata(hdev);
  753. /*
  754. * If mtclass.export_all_inputs is not set, only map fields from
  755. * TouchScreen or TouchPad collections. We need to ignore fields
  756. * that belong to other collections such as Mouse that might have
  757. * the same GenericDesktop usages.
  758. */
  759. if (!td->mtclass.export_all_inputs &&
  760. field->application != HID_DG_TOUCHSCREEN &&
  761. field->application != HID_DG_PEN &&
  762. field->application != HID_DG_TOUCHPAD &&
  763. field->application != HID_GD_KEYBOARD &&
  764. field->application != HID_CP_CONSUMER_CONTROL)
  765. return -1;
  766. /*
  767. * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
  768. * for the stylus.
  769. * The check for mt_report_id ensures we don't process
  770. * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical
  771. * collection, but within the report ID.
  772. */
  773. if (field->physical == HID_DG_STYLUS)
  774. return 0;
  775. else if ((field->physical == 0) &&
  776. (field->report->id != td->mt_report_id) &&
  777. (td->mt_report_id != -1))
  778. return 0;
  779. if (field->application == HID_DG_TOUCHSCREEN ||
  780. field->application == HID_DG_TOUCHPAD)
  781. return mt_touch_input_mapping(hdev, hi, field, usage, bit, max);
  782. /* let hid-core decide for the others */
  783. return 0;
  784. }
  785. static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  786. struct hid_field *field, struct hid_usage *usage,
  787. unsigned long **bit, int *max)
  788. {
  789. /*
  790. * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
  791. * for the stylus.
  792. */
  793. if (field->physical == HID_DG_STYLUS)
  794. return 0;
  795. if (field->application == HID_DG_TOUCHSCREEN ||
  796. field->application == HID_DG_TOUCHPAD)
  797. return mt_touch_input_mapped(hdev, hi, field, usage, bit, max);
  798. /* let hid-core decide for the others */
  799. return 0;
  800. }
  801. static int mt_event(struct hid_device *hid, struct hid_field *field,
  802. struct hid_usage *usage, __s32 value)
  803. {
  804. struct mt_device *td = hid_get_drvdata(hid);
  805. if (field->report->id == td->mt_report_id)
  806. return mt_touch_event(hid, field, usage, value);
  807. return 0;
  808. }
  809. static void mt_report(struct hid_device *hid, struct hid_report *report)
  810. {
  811. struct mt_device *td = hid_get_drvdata(hid);
  812. struct hid_field *field = report->field[0];
  813. if (!(hid->claimed & HID_CLAIMED_INPUT))
  814. return;
  815. if (report->id == td->mt_report_id)
  816. return mt_touch_report(hid, report);
  817. if (field && field->hidinput && field->hidinput->input)
  818. input_sync(field->hidinput->input);
  819. }
  820. static void mt_set_input_mode(struct hid_device *hdev)
  821. {
  822. struct mt_device *td = hid_get_drvdata(hdev);
  823. struct hid_report *r;
  824. struct hid_report_enum *re;
  825. struct mt_class *cls = &td->mtclass;
  826. char *buf;
  827. int report_len;
  828. if (td->inputmode < 0)
  829. return;
  830. re = &(hdev->report_enum[HID_FEATURE_REPORT]);
  831. r = re->report_id_hash[td->inputmode];
  832. if (r) {
  833. if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
  834. report_len = hid_report_len(r);
  835. buf = hid_alloc_report_buf(r, GFP_KERNEL);
  836. if (!buf) {
  837. hid_err(hdev, "failed to allocate buffer for report\n");
  838. return;
  839. }
  840. hid_hw_raw_request(hdev, r->id, buf, report_len,
  841. HID_FEATURE_REPORT,
  842. HID_REQ_GET_REPORT);
  843. kfree(buf);
  844. }
  845. r->field[0]->value[td->inputmode_index] = td->inputmode_value;
  846. hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
  847. }
  848. }
  849. static void mt_set_maxcontacts(struct hid_device *hdev)
  850. {
  851. struct mt_device *td = hid_get_drvdata(hdev);
  852. struct hid_report *r;
  853. struct hid_report_enum *re;
  854. int fieldmax, max;
  855. if (td->maxcontact_report_id < 0)
  856. return;
  857. if (!td->mtclass.maxcontacts)
  858. return;
  859. re = &hdev->report_enum[HID_FEATURE_REPORT];
  860. r = re->report_id_hash[td->maxcontact_report_id];
  861. if (r) {
  862. max = td->mtclass.maxcontacts;
  863. fieldmax = r->field[0]->logical_maximum;
  864. max = min(fieldmax, max);
  865. if (r->field[0]->value[0] != max) {
  866. r->field[0]->value[0] = max;
  867. hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
  868. }
  869. }
  870. }
  871. static void mt_post_parse_default_settings(struct mt_device *td)
  872. {
  873. __s32 quirks = td->mtclass.quirks;
  874. /* unknown serial device needs special quirks */
  875. if (td->touches_by_report == 1) {
  876. quirks |= MT_QUIRK_ALWAYS_VALID;
  877. quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
  878. quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
  879. quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
  880. quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
  881. }
  882. td->mtclass.quirks = quirks;
  883. }
  884. static void mt_post_parse(struct mt_device *td)
  885. {
  886. struct mt_fields *f = td->fields;
  887. struct mt_class *cls = &td->mtclass;
  888. if (td->touches_by_report > 0) {
  889. int field_count_per_touch = f->length / td->touches_by_report;
  890. td->last_slot_field = f->usages[field_count_per_touch - 1];
  891. }
  892. if (td->cc_index < 0)
  893. cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
  894. }
  895. static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
  896. {
  897. struct mt_device *td = hid_get_drvdata(hdev);
  898. char *name;
  899. const char *suffix = NULL;
  900. struct hid_field *field = hi->report->field[0];
  901. int ret;
  902. if (hi->report->id == td->mt_report_id) {
  903. ret = mt_touch_input_configured(hdev, hi);
  904. if (ret)
  905. return ret;
  906. }
  907. /*
  908. * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
  909. * for the stylus. Check this first, and then rely on the application
  910. * field.
  911. */
  912. if (hi->report->field[0]->physical == HID_DG_STYLUS) {
  913. suffix = "Pen";
  914. /* force BTN_STYLUS to allow tablet matching in udev */
  915. __set_bit(BTN_STYLUS, hi->input->keybit);
  916. } else {
  917. switch (field->application) {
  918. case HID_GD_KEYBOARD:
  919. suffix = "Keyboard";
  920. break;
  921. case HID_GD_KEYPAD:
  922. suffix = "Keypad";
  923. break;
  924. case HID_GD_MOUSE:
  925. suffix = "Mouse";
  926. break;
  927. case HID_DG_STYLUS:
  928. suffix = "Pen";
  929. /* force BTN_STYLUS to allow tablet matching in udev */
  930. __set_bit(BTN_STYLUS, hi->input->keybit);
  931. break;
  932. case HID_DG_TOUCHSCREEN:
  933. /* we do not set suffix = "Touchscreen" */
  934. break;
  935. case HID_DG_TOUCHPAD:
  936. suffix = "Touchpad";
  937. break;
  938. case HID_GD_SYSTEM_CONTROL:
  939. suffix = "System Control";
  940. break;
  941. case HID_CP_CONSUMER_CONTROL:
  942. suffix = "Consumer Control";
  943. break;
  944. default:
  945. suffix = "UNKNOWN";
  946. break;
  947. }
  948. }
  949. if (suffix) {
  950. name = devm_kzalloc(&hi->input->dev,
  951. strlen(hdev->name) + strlen(suffix) + 2,
  952. GFP_KERNEL);
  953. if (name) {
  954. sprintf(name, "%s %s", hdev->name, suffix);
  955. hi->input->name = name;
  956. }
  957. }
  958. return 0;
  959. }
  960. static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
  961. {
  962. if (field->usage[0].hid != usage ||
  963. !(field->flags & HID_MAIN_ITEM_CONSTANT))
  964. return;
  965. field->flags &= ~HID_MAIN_ITEM_CONSTANT;
  966. field->flags |= HID_MAIN_ITEM_VARIABLE;
  967. }
  968. static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
  969. {
  970. struct hid_report *report;
  971. int i;
  972. list_for_each_entry(report,
  973. &hdev->report_enum[HID_INPUT_REPORT].report_list,
  974. list) {
  975. if (!report->maxfield)
  976. continue;
  977. for (i = 0; i < report->maxfield; i++)
  978. if (report->field[i]->maxusage >= 1)
  979. mt_fix_const_field(report->field[i], usage);
  980. }
  981. }
  982. static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
  983. {
  984. int ret, i;
  985. struct mt_device *td;
  986. struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
  987. for (i = 0; mt_classes[i].name ; i++) {
  988. if (id->driver_data == mt_classes[i].name) {
  989. mtclass = &(mt_classes[i]);
  990. break;
  991. }
  992. }
  993. td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
  994. if (!td) {
  995. dev_err(&hdev->dev, "cannot allocate multitouch data\n");
  996. return -ENOMEM;
  997. }
  998. td->mtclass = *mtclass;
  999. td->inputmode = -1;
  1000. td->maxcontact_report_id = -1;
  1001. td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
  1002. td->cc_index = -1;
  1003. td->mt_report_id = -1;
  1004. hid_set_drvdata(hdev, td);
  1005. td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
  1006. GFP_KERNEL);
  1007. if (!td->fields) {
  1008. dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
  1009. return -ENOMEM;
  1010. }
  1011. if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
  1012. td->serial_maybe = true;
  1013. /*
  1014. * Store the initial quirk state
  1015. */
  1016. td->initial_quirks = hdev->quirks;
  1017. /* This allows the driver to correctly support devices
  1018. * that emit events over several HID messages.
  1019. */
  1020. hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
  1021. /*
  1022. * This allows the driver to handle different input sensors
  1023. * that emits events through different reports on the same HID
  1024. * device.
  1025. */
  1026. hdev->quirks |= HID_QUIRK_MULTI_INPUT;
  1027. hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
  1028. /*
  1029. * Some multitouch screens do not like to be polled for input
  1030. * reports. Fortunately, the Win8 spec says that all touches
  1031. * should be sent during each report, making the initialization
  1032. * of input reports unnecessary. For Win7 devices, well, let's hope
  1033. * they will still be happy (this is only be a problem if a touch
  1034. * was already there while probing the device).
  1035. *
  1036. * In addition some touchpads do not behave well if we read
  1037. * all feature reports from them. Instead we prevent
  1038. * initial report fetching and then selectively fetch each
  1039. * report we are interested in.
  1040. */
  1041. hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
  1042. ret = hid_parse(hdev);
  1043. if (ret != 0)
  1044. return ret;
  1045. if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
  1046. mt_fix_const_fields(hdev, HID_DG_CONTACTID);
  1047. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1048. if (ret)
  1049. return ret;
  1050. ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
  1051. if (ret)
  1052. dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
  1053. hdev->name);
  1054. mt_set_maxcontacts(hdev);
  1055. mt_set_input_mode(hdev);
  1056. /* release .fields memory as it is not used anymore */
  1057. devm_kfree(&hdev->dev, td->fields);
  1058. td->fields = NULL;
  1059. return 0;
  1060. }
  1061. #ifdef CONFIG_PM
  1062. static void mt_release_contacts(struct hid_device *hid)
  1063. {
  1064. struct hid_input *hidinput;
  1065. list_for_each_entry(hidinput, &hid->inputs, list) {
  1066. struct input_dev *input_dev = hidinput->input;
  1067. struct input_mt *mt = input_dev->mt;
  1068. int i;
  1069. if (mt) {
  1070. for (i = 0; i < mt->num_slots; i++) {
  1071. input_mt_slot(input_dev, i);
  1072. input_mt_report_slot_state(input_dev,
  1073. MT_TOOL_FINGER,
  1074. false);
  1075. }
  1076. input_mt_sync_frame(input_dev);
  1077. input_sync(input_dev);
  1078. }
  1079. }
  1080. }
  1081. static int mt_reset_resume(struct hid_device *hdev)
  1082. {
  1083. mt_release_contacts(hdev);
  1084. mt_set_maxcontacts(hdev);
  1085. mt_set_input_mode(hdev);
  1086. return 0;
  1087. }
  1088. static int mt_resume(struct hid_device *hdev)
  1089. {
  1090. /* Some Elan legacy devices require SET_IDLE to be set on resume.
  1091. * It should be safe to send it to other devices too.
  1092. * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
  1093. hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
  1094. return 0;
  1095. }
  1096. #endif
  1097. static void mt_remove(struct hid_device *hdev)
  1098. {
  1099. struct mt_device *td = hid_get_drvdata(hdev);
  1100. sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
  1101. hid_hw_stop(hdev);
  1102. hdev->quirks = td->initial_quirks;
  1103. }
  1104. /*
  1105. * This list contains only:
  1106. * - VID/PID of products not working with the default multitouch handling
  1107. * - 2 generic rules.
  1108. * So there is no point in adding here any device with MT_CLS_DEFAULT.
  1109. */
  1110. static const struct hid_device_id mt_devices[] = {
  1111. /* 3M panels */
  1112. { .driver_data = MT_CLS_3M,
  1113. MT_USB_DEVICE(USB_VENDOR_ID_3M,
  1114. USB_DEVICE_ID_3M1968) },
  1115. { .driver_data = MT_CLS_3M,
  1116. MT_USB_DEVICE(USB_VENDOR_ID_3M,
  1117. USB_DEVICE_ID_3M2256) },
  1118. { .driver_data = MT_CLS_3M,
  1119. MT_USB_DEVICE(USB_VENDOR_ID_3M,
  1120. USB_DEVICE_ID_3M3266) },
  1121. /* Anton devices */
  1122. { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
  1123. MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
  1124. USB_DEVICE_ID_ANTON_TOUCH_PAD) },
  1125. /* Atmel panels */
  1126. { .driver_data = MT_CLS_SERIAL,
  1127. MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
  1128. USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
  1129. /* Baanto multitouch devices */
  1130. { .driver_data = MT_CLS_NSMU,
  1131. MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
  1132. USB_DEVICE_ID_BAANTO_MT_190W2) },
  1133. /* Cando panels */
  1134. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  1135. MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
  1136. USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
  1137. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  1138. MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
  1139. USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
  1140. /* Chunghwa Telecom touch panels */
  1141. { .driver_data = MT_CLS_NSMU,
  1142. MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
  1143. USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
  1144. /* CJTouch panels */
  1145. { .driver_data = MT_CLS_NSMU,
  1146. MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
  1147. USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
  1148. { .driver_data = MT_CLS_NSMU,
  1149. MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
  1150. USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
  1151. /* CVTouch panels */
  1152. { .driver_data = MT_CLS_NSMU,
  1153. MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
  1154. USB_DEVICE_ID_CVTOUCH_SCREEN) },
  1155. /* eGalax devices (resistive) */
  1156. { .driver_data = MT_CLS_EGALAX,
  1157. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1158. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
  1159. { .driver_data = MT_CLS_EGALAX,
  1160. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1161. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
  1162. /* eGalax devices (capacitive) */
  1163. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1164. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1165. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
  1166. { .driver_data = MT_CLS_EGALAX,
  1167. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1168. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
  1169. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1170. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1171. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
  1172. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1173. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1174. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
  1175. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1176. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1177. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
  1178. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1179. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1180. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
  1181. { .driver_data = MT_CLS_EGALAX,
  1182. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1183. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
  1184. { .driver_data = MT_CLS_EGALAX,
  1185. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1186. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
  1187. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1188. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1189. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
  1190. { .driver_data = MT_CLS_EGALAX,
  1191. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1192. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
  1193. { .driver_data = MT_CLS_EGALAX,
  1194. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1195. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
  1196. { .driver_data = MT_CLS_EGALAX,
  1197. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1198. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
  1199. { .driver_data = MT_CLS_EGALAX,
  1200. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1201. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
  1202. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1203. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1204. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
  1205. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1206. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1207. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
  1208. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1209. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1210. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
  1211. /* Elitegroup panel */
  1212. { .driver_data = MT_CLS_SERIAL,
  1213. MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
  1214. USB_DEVICE_ID_ELITEGROUP_05D8) },
  1215. /* Flatfrog Panels */
  1216. { .driver_data = MT_CLS_FLATFROG,
  1217. MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
  1218. USB_DEVICE_ID_MULTITOUCH_3200) },
  1219. /* FocalTech Panels */
  1220. { .driver_data = MT_CLS_SERIAL,
  1221. MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
  1222. USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
  1223. /* GeneralTouch panel */
  1224. { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
  1225. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1226. USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
  1227. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1228. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1229. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
  1230. { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
  1231. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1232. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
  1233. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1234. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1235. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
  1236. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1237. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1238. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
  1239. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1240. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1241. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
  1242. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1243. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1244. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
  1245. /* Gametel game controller */
  1246. { .driver_data = MT_CLS_NSMU,
  1247. MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
  1248. USB_DEVICE_ID_GAMETEL_MT_MODE) },
  1249. /* GoodTouch panels */
  1250. { .driver_data = MT_CLS_NSMU,
  1251. MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
  1252. USB_DEVICE_ID_GOODTOUCH_000f) },
  1253. /* Hanvon panels */
  1254. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  1255. MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
  1256. USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
  1257. /* Ilitek dual touch panel */
  1258. { .driver_data = MT_CLS_NSMU,
  1259. MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
  1260. USB_DEVICE_ID_ILITEK_MULTITOUCH) },
  1261. /* LG Melfas panel */
  1262. { .driver_data = MT_CLS_LG,
  1263. HID_USB_DEVICE(USB_VENDOR_ID_LG,
  1264. USB_DEVICE_ID_LG_MELFAS_MT) },
  1265. /* MosArt panels */
  1266. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  1267. MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
  1268. USB_DEVICE_ID_ASUS_T91MT)},
  1269. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  1270. MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
  1271. USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
  1272. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  1273. MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
  1274. USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
  1275. /* Panasonic panels */
  1276. { .driver_data = MT_CLS_PANASONIC,
  1277. MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
  1278. USB_DEVICE_ID_PANABOARD_UBT780) },
  1279. { .driver_data = MT_CLS_PANASONIC,
  1280. MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
  1281. USB_DEVICE_ID_PANABOARD_UBT880) },
  1282. /* Novatek Panel */
  1283. { .driver_data = MT_CLS_NSMU,
  1284. MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
  1285. USB_DEVICE_ID_NOVATEK_PCT) },
  1286. /* Ntrig Panel */
  1287. { .driver_data = MT_CLS_NSMU,
  1288. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1289. USB_VENDOR_ID_NTRIG, 0x1b05) },
  1290. /* PixArt optical touch screen */
  1291. { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
  1292. MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
  1293. USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
  1294. { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
  1295. MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
  1296. USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
  1297. { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
  1298. MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
  1299. USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
  1300. /* PixCir-based panels */
  1301. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  1302. MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
  1303. USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
  1304. /* Quanta-based panels */
  1305. { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
  1306. MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
  1307. USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
  1308. /* Stantum panels */
  1309. { .driver_data = MT_CLS_CONFIDENCE,
  1310. MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
  1311. USB_DEVICE_ID_MTP_STM)},
  1312. /* TopSeed panels */
  1313. { .driver_data = MT_CLS_TOPSEED,
  1314. MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
  1315. USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
  1316. /* Touch International panels */
  1317. { .driver_data = MT_CLS_NSMU,
  1318. MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
  1319. USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
  1320. /* Unitec panels */
  1321. { .driver_data = MT_CLS_NSMU,
  1322. MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
  1323. USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
  1324. { .driver_data = MT_CLS_NSMU,
  1325. MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
  1326. USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
  1327. /* VTL panels */
  1328. { .driver_data = MT_CLS_VTL,
  1329. MT_USB_DEVICE(USB_VENDOR_ID_VTL,
  1330. USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
  1331. /* Wistron panels */
  1332. { .driver_data = MT_CLS_NSMU,
  1333. MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
  1334. USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
  1335. /* XAT */
  1336. { .driver_data = MT_CLS_NSMU,
  1337. MT_USB_DEVICE(USB_VENDOR_ID_XAT,
  1338. USB_DEVICE_ID_XAT_CSR) },
  1339. /* Xiroku */
  1340. { .driver_data = MT_CLS_NSMU,
  1341. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1342. USB_DEVICE_ID_XIROKU_SPX) },
  1343. { .driver_data = MT_CLS_NSMU,
  1344. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1345. USB_DEVICE_ID_XIROKU_MPX) },
  1346. { .driver_data = MT_CLS_NSMU,
  1347. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1348. USB_DEVICE_ID_XIROKU_CSR) },
  1349. { .driver_data = MT_CLS_NSMU,
  1350. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1351. USB_DEVICE_ID_XIROKU_SPX1) },
  1352. { .driver_data = MT_CLS_NSMU,
  1353. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1354. USB_DEVICE_ID_XIROKU_MPX1) },
  1355. { .driver_data = MT_CLS_NSMU,
  1356. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1357. USB_DEVICE_ID_XIROKU_CSR1) },
  1358. { .driver_data = MT_CLS_NSMU,
  1359. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1360. USB_DEVICE_ID_XIROKU_SPX2) },
  1361. { .driver_data = MT_CLS_NSMU,
  1362. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1363. USB_DEVICE_ID_XIROKU_MPX2) },
  1364. { .driver_data = MT_CLS_NSMU,
  1365. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1366. USB_DEVICE_ID_XIROKU_CSR2) },
  1367. /* Generic MT device */
  1368. { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
  1369. /* Generic Win 8 certified MT device */
  1370. { .driver_data = MT_CLS_WIN_8,
  1371. HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
  1372. HID_ANY_ID, HID_ANY_ID) },
  1373. { }
  1374. };
  1375. MODULE_DEVICE_TABLE(hid, mt_devices);
  1376. static const struct hid_usage_id mt_grabbed_usages[] = {
  1377. { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
  1378. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
  1379. };
  1380. static struct hid_driver mt_driver = {
  1381. .name = "hid-multitouch",
  1382. .id_table = mt_devices,
  1383. .probe = mt_probe,
  1384. .remove = mt_remove,
  1385. .input_mapping = mt_input_mapping,
  1386. .input_mapped = mt_input_mapped,
  1387. .input_configured = mt_input_configured,
  1388. .feature_mapping = mt_feature_mapping,
  1389. .usage_table = mt_grabbed_usages,
  1390. .event = mt_event,
  1391. .report = mt_report,
  1392. #ifdef CONFIG_PM
  1393. .reset_resume = mt_reset_resume,
  1394. .resume = mt_resume,
  1395. #endif
  1396. };
  1397. module_hid_driver(mt_driver);