hid-multitouch.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144
  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 test suite in hid-tools[1].
  30. * Please run these regression tests before patching this module so that
  31. * your patch won't break existing known devices.
  32. *
  33. * [1] https://gitlab.freedesktop.org/libevdev/hid-tools
  34. */
  35. #include <linux/device.h>
  36. #include <linux/hid.h>
  37. #include <linux/module.h>
  38. #include <linux/slab.h>
  39. #include <linux/input/mt.h>
  40. #include <linux/jiffies.h>
  41. #include <linux/string.h>
  42. #include <linux/timer.h>
  43. MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
  44. MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
  45. MODULE_DESCRIPTION("HID multitouch panels");
  46. MODULE_LICENSE("GPL");
  47. #include "hid-ids.h"
  48. /* quirks to control the device */
  49. #define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0)
  50. #define MT_QUIRK_SLOT_IS_CONTACTID BIT(1)
  51. #define MT_QUIRK_CYPRESS BIT(2)
  52. #define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3)
  53. #define MT_QUIRK_ALWAYS_VALID BIT(4)
  54. #define MT_QUIRK_VALID_IS_INRANGE BIT(5)
  55. #define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6)
  56. #define MT_QUIRK_CONFIDENCE BIT(7)
  57. #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8)
  58. #define MT_QUIRK_NO_AREA BIT(9)
  59. #define MT_QUIRK_IGNORE_DUPLICATES BIT(10)
  60. #define MT_QUIRK_HOVERING BIT(11)
  61. #define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12)
  62. #define MT_QUIRK_FORCE_GET_FEATURE BIT(13)
  63. #define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14)
  64. #define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15)
  65. #define MT_QUIRK_STICKY_FINGERS BIT(16)
  66. #define MT_QUIRK_ASUS_CUSTOM_UP BIT(17)
  67. #define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18)
  68. #define MT_INPUTMODE_TOUCHSCREEN 0x02
  69. #define MT_INPUTMODE_TOUCHPAD 0x03
  70. #define MT_BUTTONTYPE_CLICKPAD 0
  71. enum latency_mode {
  72. HID_LATENCY_NORMAL = 0,
  73. HID_LATENCY_HIGH = 1,
  74. };
  75. #define MT_IO_FLAGS_RUNNING 0
  76. #define MT_IO_FLAGS_ACTIVE_SLOTS 1
  77. #define MT_IO_FLAGS_PENDING_SLOTS 2
  78. static const bool mtrue = true; /* default for true */
  79. static const bool mfalse; /* default for false */
  80. static const __s32 mzero; /* default for 0 */
  81. #define DEFAULT_TRUE ((void *)&mtrue)
  82. #define DEFAULT_FALSE ((void *)&mfalse)
  83. #define DEFAULT_ZERO ((void *)&mzero)
  84. struct mt_usages {
  85. struct list_head list;
  86. __s32 *x, *y, *cx, *cy, *p, *w, *h, *a;
  87. __s32 *contactid; /* the device ContactID assigned to this slot */
  88. bool *tip_state; /* is the touch valid? */
  89. bool *inrange_state; /* is the finger in proximity of the sensor? */
  90. bool *confidence_state; /* is the touch made by a finger? */
  91. };
  92. struct mt_application {
  93. struct list_head list;
  94. unsigned int application;
  95. struct list_head mt_usages; /* mt usages list */
  96. __s32 quirks;
  97. __s32 *scantime; /* scantime reported */
  98. __s32 scantime_logical_max; /* max value for raw scantime */
  99. __s32 *raw_cc; /* contact count in the report */
  100. int left_button_state; /* left button state */
  101. unsigned int mt_flags; /* flags to pass to input-mt */
  102. unsigned long *pending_palm_slots; /* slots where we reported palm
  103. * and need to release */
  104. __u8 num_received; /* how many contacts we received */
  105. __u8 num_expected; /* expected last contact index */
  106. __u8 buttons_count; /* number of physical buttons per touchpad */
  107. __u8 touches_by_report; /* how many touches are present in one report:
  108. * 1 means we should use a serial protocol
  109. * > 1 means hybrid (multitouch) protocol
  110. */
  111. __s32 dev_time; /* the scan time provided by the device */
  112. unsigned long jiffies; /* the frame's jiffies */
  113. int timestamp; /* the timestamp to be sent */
  114. int prev_scantime; /* scantime reported previously */
  115. bool have_contact_count;
  116. };
  117. struct mt_class {
  118. __s32 name; /* MT_CLS */
  119. __s32 quirks;
  120. __s32 sn_move; /* Signal/noise ratio for move events */
  121. __s32 sn_width; /* Signal/noise ratio for width events */
  122. __s32 sn_height; /* Signal/noise ratio for height events */
  123. __s32 sn_pressure; /* Signal/noise ratio for pressure events */
  124. __u8 maxcontacts;
  125. bool is_indirect; /* true for touchpads */
  126. bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */
  127. };
  128. struct mt_report_data {
  129. struct list_head list;
  130. struct hid_report *report;
  131. struct mt_application *application;
  132. bool is_mt_collection;
  133. };
  134. struct mt_device {
  135. struct mt_class mtclass; /* our mt device class */
  136. struct timer_list release_timer; /* to release sticky fingers */
  137. struct hid_device *hdev; /* hid_device we're attached to */
  138. unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */
  139. __u8 inputmode_value; /* InputMode HID feature value */
  140. __u8 maxcontacts;
  141. bool is_buttonpad; /* is this device a button pad? */
  142. bool serial_maybe; /* need to check for serial protocol */
  143. struct list_head applications;
  144. struct list_head reports;
  145. };
  146. static void mt_post_parse_default_settings(struct mt_device *td,
  147. struct mt_application *app);
  148. static void mt_post_parse(struct mt_device *td, struct mt_application *app);
  149. /* classes of device behavior */
  150. #define MT_CLS_DEFAULT 0x0001
  151. #define MT_CLS_SERIAL 0x0002
  152. #define MT_CLS_CONFIDENCE 0x0003
  153. #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
  154. #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
  155. #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
  156. #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
  157. /* reserved 0x0008 */
  158. #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
  159. #define MT_CLS_NSMU 0x000a
  160. /* reserved 0x0010 */
  161. /* reserved 0x0011 */
  162. #define MT_CLS_WIN_8 0x0012
  163. #define MT_CLS_EXPORT_ALL_INPUTS 0x0013
  164. #define MT_CLS_WIN_8_DUAL 0x0014
  165. /* vendor specific classes */
  166. #define MT_CLS_3M 0x0101
  167. /* reserved 0x0102 */
  168. #define MT_CLS_EGALAX 0x0103
  169. #define MT_CLS_EGALAX_SERIAL 0x0104
  170. #define MT_CLS_TOPSEED 0x0105
  171. #define MT_CLS_PANASONIC 0x0106
  172. #define MT_CLS_FLATFROG 0x0107
  173. #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
  174. #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
  175. #define MT_CLS_LG 0x010a
  176. #define MT_CLS_ASUS 0x010b
  177. #define MT_CLS_VTL 0x0110
  178. #define MT_CLS_GOOGLE 0x0111
  179. #define MT_CLS_RAZER_BLADE_STEALTH 0x0112
  180. #define MT_DEFAULT_MAXCONTACT 10
  181. #define MT_MAX_MAXCONTACT 250
  182. /*
  183. * Resync device and local timestamps after that many microseconds without
  184. * receiving data.
  185. */
  186. #define MAX_TIMESTAMP_INTERVAL 1000000
  187. #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
  188. #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
  189. /*
  190. * these device-dependent functions determine what slot corresponds
  191. * to a valid contact that was just read.
  192. */
  193. static int cypress_compute_slot(struct mt_application *application,
  194. struct mt_usages *slot)
  195. {
  196. if (*slot->contactid != 0 || application->num_received == 0)
  197. return *slot->contactid;
  198. else
  199. return -1;
  200. }
  201. static const struct mt_class mt_classes[] = {
  202. { .name = MT_CLS_DEFAULT,
  203. .quirks = MT_QUIRK_ALWAYS_VALID |
  204. MT_QUIRK_CONTACT_CNT_ACCURATE },
  205. { .name = MT_CLS_NSMU,
  206. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
  207. { .name = MT_CLS_SERIAL,
  208. .quirks = MT_QUIRK_ALWAYS_VALID},
  209. { .name = MT_CLS_CONFIDENCE,
  210. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
  211. { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
  212. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  213. MT_QUIRK_SLOT_IS_CONTACTID },
  214. { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
  215. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  216. MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
  217. { .name = MT_CLS_DUAL_INRANGE_CONTACTID,
  218. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  219. MT_QUIRK_SLOT_IS_CONTACTID,
  220. .maxcontacts = 2 },
  221. { .name = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  222. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  223. MT_QUIRK_SLOT_IS_CONTACTNUMBER,
  224. .maxcontacts = 2 },
  225. { .name = MT_CLS_INRANGE_CONTACTNUMBER,
  226. .quirks = MT_QUIRK_VALID_IS_INRANGE |
  227. MT_QUIRK_SLOT_IS_CONTACTNUMBER },
  228. { .name = MT_CLS_WIN_8,
  229. .quirks = MT_QUIRK_ALWAYS_VALID |
  230. MT_QUIRK_IGNORE_DUPLICATES |
  231. MT_QUIRK_HOVERING |
  232. MT_QUIRK_CONTACT_CNT_ACCURATE |
  233. MT_QUIRK_STICKY_FINGERS |
  234. MT_QUIRK_WIN8_PTP_BUTTONS },
  235. { .name = MT_CLS_EXPORT_ALL_INPUTS,
  236. .quirks = MT_QUIRK_ALWAYS_VALID |
  237. MT_QUIRK_CONTACT_CNT_ACCURATE,
  238. .export_all_inputs = true },
  239. { .name = MT_CLS_WIN_8_DUAL,
  240. .quirks = MT_QUIRK_ALWAYS_VALID |
  241. MT_QUIRK_IGNORE_DUPLICATES |
  242. MT_QUIRK_HOVERING |
  243. MT_QUIRK_CONTACT_CNT_ACCURATE |
  244. MT_QUIRK_WIN8_PTP_BUTTONS,
  245. .export_all_inputs = true },
  246. /*
  247. * vendor specific classes
  248. */
  249. { .name = MT_CLS_3M,
  250. .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
  251. MT_QUIRK_SLOT_IS_CONTACTID |
  252. MT_QUIRK_TOUCH_SIZE_SCALING,
  253. .sn_move = 2048,
  254. .sn_width = 128,
  255. .sn_height = 128,
  256. .maxcontacts = 60,
  257. },
  258. { .name = MT_CLS_EGALAX,
  259. .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
  260. MT_QUIRK_VALID_IS_INRANGE,
  261. .sn_move = 4096,
  262. .sn_pressure = 32,
  263. },
  264. { .name = MT_CLS_EGALAX_SERIAL,
  265. .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
  266. MT_QUIRK_ALWAYS_VALID,
  267. .sn_move = 4096,
  268. .sn_pressure = 32,
  269. },
  270. { .name = MT_CLS_TOPSEED,
  271. .quirks = MT_QUIRK_ALWAYS_VALID,
  272. .is_indirect = true,
  273. .maxcontacts = 2,
  274. },
  275. { .name = MT_CLS_PANASONIC,
  276. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP,
  277. .maxcontacts = 4 },
  278. { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
  279. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  280. MT_QUIRK_VALID_IS_INRANGE |
  281. MT_QUIRK_SLOT_IS_CONTACTID,
  282. .maxcontacts = 2
  283. },
  284. { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  285. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  286. MT_QUIRK_SLOT_IS_CONTACTID
  287. },
  288. { .name = MT_CLS_FLATFROG,
  289. .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
  290. MT_QUIRK_NO_AREA,
  291. .sn_move = 2048,
  292. .maxcontacts = 40,
  293. },
  294. { .name = MT_CLS_LG,
  295. .quirks = MT_QUIRK_ALWAYS_VALID |
  296. MT_QUIRK_FIX_CONST_CONTACT_ID |
  297. MT_QUIRK_IGNORE_DUPLICATES |
  298. MT_QUIRK_HOVERING |
  299. MT_QUIRK_CONTACT_CNT_ACCURATE },
  300. { .name = MT_CLS_ASUS,
  301. .quirks = MT_QUIRK_ALWAYS_VALID |
  302. MT_QUIRK_CONTACT_CNT_ACCURATE |
  303. MT_QUIRK_ASUS_CUSTOM_UP },
  304. { .name = MT_CLS_VTL,
  305. .quirks = MT_QUIRK_ALWAYS_VALID |
  306. MT_QUIRK_CONTACT_CNT_ACCURATE |
  307. MT_QUIRK_FORCE_GET_FEATURE,
  308. },
  309. { .name = MT_CLS_GOOGLE,
  310. .quirks = MT_QUIRK_ALWAYS_VALID |
  311. MT_QUIRK_CONTACT_CNT_ACCURATE |
  312. MT_QUIRK_SLOT_IS_CONTACTID |
  313. MT_QUIRK_HOVERING
  314. },
  315. { .name = MT_CLS_RAZER_BLADE_STEALTH,
  316. .quirks = MT_QUIRK_ALWAYS_VALID |
  317. MT_QUIRK_IGNORE_DUPLICATES |
  318. MT_QUIRK_HOVERING |
  319. MT_QUIRK_CONTACT_CNT_ACCURATE |
  320. MT_QUIRK_WIN8_PTP_BUTTONS,
  321. },
  322. { }
  323. };
  324. static ssize_t mt_show_quirks(struct device *dev,
  325. struct device_attribute *attr,
  326. char *buf)
  327. {
  328. struct hid_device *hdev = to_hid_device(dev);
  329. struct mt_device *td = hid_get_drvdata(hdev);
  330. return sprintf(buf, "%u\n", td->mtclass.quirks);
  331. }
  332. static ssize_t mt_set_quirks(struct device *dev,
  333. struct device_attribute *attr,
  334. const char *buf, size_t count)
  335. {
  336. struct hid_device *hdev = to_hid_device(dev);
  337. struct mt_device *td = hid_get_drvdata(hdev);
  338. struct mt_application *application;
  339. unsigned long val;
  340. if (kstrtoul(buf, 0, &val))
  341. return -EINVAL;
  342. td->mtclass.quirks = val;
  343. list_for_each_entry(application, &td->applications, list) {
  344. application->quirks = val;
  345. if (!application->have_contact_count)
  346. application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
  347. }
  348. return count;
  349. }
  350. static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
  351. static struct attribute *sysfs_attrs[] = {
  352. &dev_attr_quirks.attr,
  353. NULL
  354. };
  355. static const struct attribute_group mt_attribute_group = {
  356. .attrs = sysfs_attrs
  357. };
  358. static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
  359. {
  360. int ret;
  361. u32 size = hid_report_len(report);
  362. u8 *buf;
  363. /*
  364. * Do not fetch the feature report if the device has been explicitly
  365. * marked as non-capable.
  366. */
  367. if (hdev->quirks & HID_QUIRK_NO_INIT_REPORTS)
  368. return;
  369. buf = hid_alloc_report_buf(report, GFP_KERNEL);
  370. if (!buf)
  371. return;
  372. ret = hid_hw_raw_request(hdev, report->id, buf, size,
  373. HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
  374. if (ret < 0) {
  375. dev_warn(&hdev->dev, "failed to fetch feature %d\n",
  376. report->id);
  377. } else {
  378. ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
  379. size, 0);
  380. if (ret)
  381. dev_warn(&hdev->dev, "failed to report feature\n");
  382. }
  383. kfree(buf);
  384. }
  385. static void mt_feature_mapping(struct hid_device *hdev,
  386. struct hid_field *field, struct hid_usage *usage)
  387. {
  388. struct mt_device *td = hid_get_drvdata(hdev);
  389. switch (usage->hid) {
  390. case HID_DG_CONTACTMAX:
  391. mt_get_feature(hdev, field->report);
  392. td->maxcontacts = field->value[0];
  393. if (!td->maxcontacts &&
  394. field->logical_maximum <= MT_MAX_MAXCONTACT)
  395. td->maxcontacts = field->logical_maximum;
  396. if (td->mtclass.maxcontacts)
  397. /* check if the maxcontacts is given by the class */
  398. td->maxcontacts = td->mtclass.maxcontacts;
  399. break;
  400. case HID_DG_BUTTONTYPE:
  401. if (usage->usage_index >= field->report_count) {
  402. dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
  403. break;
  404. }
  405. mt_get_feature(hdev, field->report);
  406. if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
  407. td->is_buttonpad = true;
  408. break;
  409. case 0xff0000c5:
  410. /* Retrieve the Win8 blob once to enable some devices */
  411. if (usage->usage_index == 0)
  412. mt_get_feature(hdev, field->report);
  413. break;
  414. }
  415. }
  416. static void set_abs(struct input_dev *input, unsigned int code,
  417. struct hid_field *field, int snratio)
  418. {
  419. int fmin = field->logical_minimum;
  420. int fmax = field->logical_maximum;
  421. int fuzz = snratio ? (fmax - fmin) / snratio : 0;
  422. input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
  423. input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
  424. }
  425. static struct mt_usages *mt_allocate_usage(struct hid_device *hdev,
  426. struct mt_application *application)
  427. {
  428. struct mt_usages *usage;
  429. usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL);
  430. if (!usage)
  431. return NULL;
  432. /* set some defaults so we do not need to check for null pointers */
  433. usage->x = DEFAULT_ZERO;
  434. usage->y = DEFAULT_ZERO;
  435. usage->cx = DEFAULT_ZERO;
  436. usage->cy = DEFAULT_ZERO;
  437. usage->p = DEFAULT_ZERO;
  438. usage->w = DEFAULT_ZERO;
  439. usage->h = DEFAULT_ZERO;
  440. usage->a = DEFAULT_ZERO;
  441. usage->contactid = DEFAULT_ZERO;
  442. usage->tip_state = DEFAULT_FALSE;
  443. usage->inrange_state = DEFAULT_FALSE;
  444. usage->confidence_state = DEFAULT_TRUE;
  445. list_add_tail(&usage->list, &application->mt_usages);
  446. return usage;
  447. }
  448. static struct mt_application *mt_allocate_application(struct mt_device *td,
  449. unsigned int application)
  450. {
  451. struct mt_application *mt_application;
  452. mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application),
  453. GFP_KERNEL);
  454. if (!mt_application)
  455. return NULL;
  456. mt_application->application = application;
  457. INIT_LIST_HEAD(&mt_application->mt_usages);
  458. if (application == HID_DG_TOUCHSCREEN)
  459. mt_application->mt_flags |= INPUT_MT_DIRECT;
  460. /*
  461. * Model touchscreens providing buttons as touchpads.
  462. */
  463. if (application == HID_DG_TOUCHPAD) {
  464. mt_application->mt_flags |= INPUT_MT_POINTER;
  465. td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
  466. }
  467. mt_application->scantime = DEFAULT_ZERO;
  468. mt_application->raw_cc = DEFAULT_ZERO;
  469. mt_application->quirks = td->mtclass.quirks;
  470. list_add_tail(&mt_application->list, &td->applications);
  471. return mt_application;
  472. }
  473. static struct mt_application *mt_find_application(struct mt_device *td,
  474. unsigned int application)
  475. {
  476. struct mt_application *tmp, *mt_application = NULL;
  477. list_for_each_entry(tmp, &td->applications, list) {
  478. if (application == tmp->application) {
  479. mt_application = tmp;
  480. break;
  481. }
  482. }
  483. if (!mt_application)
  484. mt_application = mt_allocate_application(td, application);
  485. return mt_application;
  486. }
  487. static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
  488. struct hid_report *report)
  489. {
  490. struct mt_report_data *rdata;
  491. struct hid_field *field;
  492. int r, n;
  493. rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL);
  494. if (!rdata)
  495. return NULL;
  496. rdata->report = report;
  497. rdata->application = mt_find_application(td, report->application);
  498. if (!rdata->application) {
  499. devm_kfree(&td->hdev->dev, rdata);
  500. return NULL;
  501. }
  502. for (r = 0; r < report->maxfield; r++) {
  503. field = report->field[r];
  504. if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
  505. continue;
  506. for (n = 0; n < field->report_count; n++) {
  507. if (field->usage[n].hid == HID_DG_CONTACTID)
  508. rdata->is_mt_collection = true;
  509. }
  510. }
  511. list_add_tail(&rdata->list, &td->reports);
  512. return rdata;
  513. }
  514. static struct mt_report_data *mt_find_report_data(struct mt_device *td,
  515. struct hid_report *report)
  516. {
  517. struct mt_report_data *tmp, *rdata = NULL;
  518. list_for_each_entry(tmp, &td->reports, list) {
  519. if (report == tmp->report) {
  520. rdata = tmp;
  521. break;
  522. }
  523. }
  524. if (!rdata)
  525. rdata = mt_allocate_report_data(td, report);
  526. return rdata;
  527. }
  528. static void mt_store_field(struct hid_device *hdev,
  529. struct mt_application *application,
  530. __s32 *value,
  531. size_t offset)
  532. {
  533. struct mt_usages *usage;
  534. __s32 **target;
  535. if (list_empty(&application->mt_usages))
  536. usage = mt_allocate_usage(hdev, application);
  537. else
  538. usage = list_last_entry(&application->mt_usages,
  539. struct mt_usages,
  540. list);
  541. if (!usage)
  542. return;
  543. target = (__s32 **)((char *)usage + offset);
  544. /* the value has already been filled, create a new slot */
  545. if (*target != DEFAULT_TRUE &&
  546. *target != DEFAULT_FALSE &&
  547. *target != DEFAULT_ZERO) {
  548. if (usage->contactid == DEFAULT_ZERO ||
  549. usage->x == DEFAULT_ZERO ||
  550. usage->y == DEFAULT_ZERO) {
  551. hid_dbg(hdev,
  552. "ignoring duplicate usage on incomplete");
  553. return;
  554. }
  555. usage = mt_allocate_usage(hdev, application);
  556. if (!usage)
  557. return;
  558. target = (__s32 **)((char *)usage + offset);
  559. }
  560. *target = value;
  561. }
  562. #define MT_STORE_FIELD(__name) \
  563. mt_store_field(hdev, app, \
  564. &field->value[usage->usage_index], \
  565. offsetof(struct mt_usages, __name))
  566. static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  567. struct hid_field *field, struct hid_usage *usage,
  568. unsigned long **bit, int *max, struct mt_application *app)
  569. {
  570. struct mt_device *td = hid_get_drvdata(hdev);
  571. struct mt_class *cls = &td->mtclass;
  572. int code;
  573. struct hid_usage *prev_usage = NULL;
  574. /*
  575. * Model touchscreens providing buttons as touchpads.
  576. */
  577. if (field->application == HID_DG_TOUCHSCREEN &&
  578. (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
  579. app->mt_flags |= INPUT_MT_POINTER;
  580. td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
  581. }
  582. /* count the buttons on touchpads */
  583. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
  584. app->buttons_count++;
  585. if (usage->usage_index)
  586. prev_usage = &field->usage[usage->usage_index - 1];
  587. switch (usage->hid & HID_USAGE_PAGE) {
  588. case HID_UP_GENDESK:
  589. switch (usage->hid) {
  590. case HID_GD_X:
  591. if (prev_usage && (prev_usage->hid == usage->hid)) {
  592. code = ABS_MT_TOOL_X;
  593. MT_STORE_FIELD(cx);
  594. } else {
  595. code = ABS_MT_POSITION_X;
  596. MT_STORE_FIELD(x);
  597. }
  598. set_abs(hi->input, code, field, cls->sn_move);
  599. /*
  600. * A system multi-axis that exports X and Y has a high
  601. * chance of being used directly on a surface
  602. */
  603. if (field->application == HID_GD_SYSTEM_MULTIAXIS) {
  604. __set_bit(INPUT_PROP_DIRECT,
  605. hi->input->propbit);
  606. input_set_abs_params(hi->input,
  607. ABS_MT_TOOL_TYPE,
  608. MT_TOOL_DIAL,
  609. MT_TOOL_DIAL, 0, 0);
  610. }
  611. return 1;
  612. case HID_GD_Y:
  613. if (prev_usage && (prev_usage->hid == usage->hid)) {
  614. code = ABS_MT_TOOL_Y;
  615. MT_STORE_FIELD(cy);
  616. } else {
  617. code = ABS_MT_POSITION_Y;
  618. MT_STORE_FIELD(y);
  619. }
  620. set_abs(hi->input, code, field, cls->sn_move);
  621. return 1;
  622. }
  623. return 0;
  624. case HID_UP_DIGITIZER:
  625. switch (usage->hid) {
  626. case HID_DG_INRANGE:
  627. if (app->quirks & MT_QUIRK_HOVERING) {
  628. input_set_abs_params(hi->input,
  629. ABS_MT_DISTANCE, 0, 1, 0, 0);
  630. }
  631. MT_STORE_FIELD(inrange_state);
  632. return 1;
  633. case HID_DG_CONFIDENCE:
  634. if ((cls->name == MT_CLS_WIN_8 ||
  635. cls->name == MT_CLS_WIN_8_DUAL) &&
  636. (field->application == HID_DG_TOUCHPAD ||
  637. field->application == HID_DG_TOUCHSCREEN))
  638. app->quirks |= MT_QUIRK_CONFIDENCE;
  639. if (app->quirks & MT_QUIRK_CONFIDENCE)
  640. input_set_abs_params(hi->input,
  641. ABS_MT_TOOL_TYPE,
  642. MT_TOOL_FINGER,
  643. MT_TOOL_PALM, 0, 0);
  644. MT_STORE_FIELD(confidence_state);
  645. return 1;
  646. case HID_DG_TIPSWITCH:
  647. if (field->application != HID_GD_SYSTEM_MULTIAXIS)
  648. input_set_capability(hi->input,
  649. EV_KEY, BTN_TOUCH);
  650. MT_STORE_FIELD(tip_state);
  651. return 1;
  652. case HID_DG_CONTACTID:
  653. MT_STORE_FIELD(contactid);
  654. app->touches_by_report++;
  655. return 1;
  656. case HID_DG_WIDTH:
  657. if (!(app->quirks & MT_QUIRK_NO_AREA))
  658. set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field,
  659. cls->sn_width);
  660. MT_STORE_FIELD(w);
  661. return 1;
  662. case HID_DG_HEIGHT:
  663. if (!(app->quirks & MT_QUIRK_NO_AREA)) {
  664. set_abs(hi->input, ABS_MT_TOUCH_MINOR, field,
  665. cls->sn_height);
  666. /*
  667. * Only set ABS_MT_ORIENTATION if it is not
  668. * already set by the HID_DG_AZIMUTH usage.
  669. */
  670. if (!test_bit(ABS_MT_ORIENTATION,
  671. hi->input->absbit))
  672. input_set_abs_params(hi->input,
  673. ABS_MT_ORIENTATION, 0, 1, 0, 0);
  674. }
  675. MT_STORE_FIELD(h);
  676. return 1;
  677. case HID_DG_TIPPRESSURE:
  678. set_abs(hi->input, ABS_MT_PRESSURE, field,
  679. cls->sn_pressure);
  680. MT_STORE_FIELD(p);
  681. return 1;
  682. case HID_DG_SCANTIME:
  683. input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP);
  684. app->scantime = &field->value[usage->usage_index];
  685. app->scantime_logical_max = field->logical_maximum;
  686. return 1;
  687. case HID_DG_CONTACTCOUNT:
  688. app->have_contact_count = true;
  689. app->raw_cc = &field->value[usage->usage_index];
  690. return 1;
  691. case HID_DG_AZIMUTH:
  692. /*
  693. * Azimuth has the range of [0, MAX) representing a full
  694. * revolution. Set ABS_MT_ORIENTATION to a quarter of
  695. * MAX according the definition of ABS_MT_ORIENTATION
  696. */
  697. input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
  698. -field->logical_maximum / 4,
  699. field->logical_maximum / 4,
  700. cls->sn_move ?
  701. field->logical_maximum / cls->sn_move : 0, 0);
  702. MT_STORE_FIELD(a);
  703. return 1;
  704. case HID_DG_CONTACTMAX:
  705. /* contact max are global to the report */
  706. return -1;
  707. case HID_DG_TOUCH:
  708. /* Legacy devices use TIPSWITCH and not TOUCH.
  709. * Let's just ignore this field. */
  710. return -1;
  711. }
  712. /* let hid-input decide for the others */
  713. return 0;
  714. case HID_UP_BUTTON:
  715. code = BTN_MOUSE + ((usage->hid - 1) & HID_USAGE);
  716. /*
  717. * MS PTP spec says that external buttons left and right have
  718. * usages 2 and 3.
  719. */
  720. if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
  721. field->application == HID_DG_TOUCHPAD &&
  722. (usage->hid & HID_USAGE) > 1)
  723. code--;
  724. if (field->application == HID_GD_SYSTEM_MULTIAXIS)
  725. code = BTN_0 + ((usage->hid - 1) & HID_USAGE);
  726. hid_map_usage(hi, usage, bit, max, EV_KEY, code);
  727. if (!*bit)
  728. return -1;
  729. input_set_capability(hi->input, EV_KEY, code);
  730. return 1;
  731. case 0xff000000:
  732. /* we do not want to map these: no input-oriented meaning */
  733. return -1;
  734. }
  735. return 0;
  736. }
  737. static int mt_compute_slot(struct mt_device *td, struct mt_application *app,
  738. struct mt_usages *slot,
  739. struct input_dev *input)
  740. {
  741. __s32 quirks = app->quirks;
  742. if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
  743. return *slot->contactid;
  744. if (quirks & MT_QUIRK_CYPRESS)
  745. return cypress_compute_slot(app, slot);
  746. if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER)
  747. return app->num_received;
  748. if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
  749. return *slot->contactid - 1;
  750. return input_mt_get_slot_by_key(input, *slot->contactid);
  751. }
  752. static void mt_release_pending_palms(struct mt_device *td,
  753. struct mt_application *app,
  754. struct input_dev *input)
  755. {
  756. int slotnum;
  757. bool need_sync = false;
  758. for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) {
  759. clear_bit(slotnum, app->pending_palm_slots);
  760. input_mt_slot(input, slotnum);
  761. input_mt_report_slot_state(input, MT_TOOL_PALM, false);
  762. need_sync = true;
  763. }
  764. if (need_sync) {
  765. input_mt_sync_frame(input);
  766. input_sync(input);
  767. }
  768. }
  769. /*
  770. * this function is called when a whole packet has been received and processed,
  771. * so that it can decide what to send to the input layer.
  772. */
  773. static void mt_sync_frame(struct mt_device *td, struct mt_application *app,
  774. struct input_dev *input)
  775. {
  776. if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS)
  777. input_event(input, EV_KEY, BTN_LEFT, app->left_button_state);
  778. input_mt_sync_frame(input);
  779. input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp);
  780. input_sync(input);
  781. mt_release_pending_palms(td, app, input);
  782. app->num_received = 0;
  783. app->left_button_state = 0;
  784. if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
  785. set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
  786. else
  787. clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
  788. clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
  789. }
  790. static int mt_compute_timestamp(struct mt_application *app, __s32 value)
  791. {
  792. long delta = value - app->prev_scantime;
  793. unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies);
  794. app->jiffies = jiffies;
  795. if (delta < 0)
  796. delta += app->scantime_logical_max;
  797. /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */
  798. delta *= 100;
  799. if (jdelta > MAX_TIMESTAMP_INTERVAL)
  800. /* No data received for a while, resync the timestamp. */
  801. return 0;
  802. else
  803. return app->timestamp + delta;
  804. }
  805. static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
  806. struct hid_usage *usage, __s32 value)
  807. {
  808. /* we will handle the hidinput part later, now remains hiddev */
  809. if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
  810. hid->hiddev_hid_event(hid, field, usage, value);
  811. return 1;
  812. }
  813. static int mt_process_slot(struct mt_device *td, struct input_dev *input,
  814. struct mt_application *app,
  815. struct mt_usages *slot)
  816. {
  817. struct input_mt *mt = input->mt;
  818. __s32 quirks = app->quirks;
  819. bool valid = true;
  820. bool confidence_state = true;
  821. bool inrange_state = false;
  822. int active;
  823. int slotnum;
  824. int tool = MT_TOOL_FINGER;
  825. if (!slot)
  826. return -EINVAL;
  827. if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) &&
  828. app->num_received >= app->num_expected)
  829. return -EAGAIN;
  830. if (!(quirks & MT_QUIRK_ALWAYS_VALID)) {
  831. if (quirks & MT_QUIRK_VALID_IS_INRANGE)
  832. valid = *slot->inrange_state;
  833. if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
  834. valid = *slot->tip_state;
  835. if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
  836. valid = *slot->confidence_state;
  837. if (!valid)
  838. return 0;
  839. }
  840. slotnum = mt_compute_slot(td, app, slot, input);
  841. if (slotnum < 0 || slotnum >= td->maxcontacts)
  842. return 0;
  843. if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) {
  844. struct input_mt_slot *i_slot = &mt->slots[slotnum];
  845. if (input_mt_is_active(i_slot) &&
  846. input_mt_is_used(mt, i_slot))
  847. return -EAGAIN;
  848. }
  849. if (quirks & MT_QUIRK_CONFIDENCE)
  850. confidence_state = *slot->confidence_state;
  851. if (quirks & MT_QUIRK_HOVERING)
  852. inrange_state = *slot->inrange_state;
  853. active = *slot->tip_state || inrange_state;
  854. if (app->application == HID_GD_SYSTEM_MULTIAXIS)
  855. tool = MT_TOOL_DIAL;
  856. else if (unlikely(!confidence_state)) {
  857. tool = MT_TOOL_PALM;
  858. if (!active && mt &&
  859. input_mt_is_active(&mt->slots[slotnum])) {
  860. /*
  861. * The non-confidence was reported for
  862. * previously valid contact that is also no
  863. * longer valid. We can't simply report
  864. * lift-off as userspace will not be aware
  865. * of non-confidence, so we need to split
  866. * it into 2 events: active MT_TOOL_PALM
  867. * and a separate liftoff.
  868. */
  869. active = true;
  870. set_bit(slotnum, app->pending_palm_slots);
  871. }
  872. }
  873. input_mt_slot(input, slotnum);
  874. input_mt_report_slot_state(input, tool, active);
  875. if (active) {
  876. /* this finger is in proximity of the sensor */
  877. int wide = (*slot->w > *slot->h);
  878. int major = max(*slot->w, *slot->h);
  879. int minor = min(*slot->w, *slot->h);
  880. int orientation = wide;
  881. int max_azimuth;
  882. int azimuth;
  883. if (slot->a != DEFAULT_ZERO) {
  884. /*
  885. * Azimuth is counter-clockwise and ranges from [0, MAX)
  886. * (a full revolution). Convert it to clockwise ranging
  887. * [-MAX/2, MAX/2].
  888. *
  889. * Note that ABS_MT_ORIENTATION require us to report
  890. * the limit of [-MAX/4, MAX/4], but the value can go
  891. * out of range to [-MAX/2, MAX/2] to report an upside
  892. * down ellipsis.
  893. */
  894. azimuth = *slot->a;
  895. max_azimuth = input_abs_get_max(input,
  896. ABS_MT_ORIENTATION);
  897. if (azimuth > max_azimuth * 2)
  898. azimuth -= max_azimuth * 4;
  899. orientation = -azimuth;
  900. }
  901. if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) {
  902. /*
  903. * divided by two to match visual scale of touch
  904. * for devices with this quirk
  905. */
  906. major = major >> 1;
  907. minor = minor >> 1;
  908. }
  909. input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x);
  910. input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y);
  911. input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx);
  912. input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy);
  913. input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state);
  914. input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation);
  915. input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p);
  916. input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
  917. input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
  918. set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
  919. }
  920. return 0;
  921. }
  922. static void mt_process_mt_event(struct hid_device *hid,
  923. struct mt_application *app,
  924. struct hid_field *field,
  925. struct hid_usage *usage,
  926. __s32 value,
  927. bool first_packet)
  928. {
  929. __s32 quirks = app->quirks;
  930. struct input_dev *input = field->hidinput->input;
  931. if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT))
  932. return;
  933. if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) {
  934. /*
  935. * For Win8 PTP touchpads we should only look at
  936. * non finger/touch events in the first_packet of a
  937. * (possible) multi-packet frame.
  938. */
  939. if (!first_packet)
  940. return;
  941. /*
  942. * For Win8 PTP touchpads we map both the clickpad click
  943. * and any "external" left buttons to BTN_LEFT if a
  944. * device claims to have both we need to report 1 for
  945. * BTN_LEFT if either is pressed, so we or all values
  946. * together and report the result in mt_sync_frame().
  947. */
  948. if (usage->type == EV_KEY && usage->code == BTN_LEFT) {
  949. app->left_button_state |= value;
  950. return;
  951. }
  952. }
  953. input_event(input, usage->type, usage->code, value);
  954. }
  955. static void mt_touch_report(struct hid_device *hid,
  956. struct mt_report_data *rdata)
  957. {
  958. struct mt_device *td = hid_get_drvdata(hid);
  959. struct hid_report *report = rdata->report;
  960. struct mt_application *app = rdata->application;
  961. struct hid_field *field;
  962. struct input_dev *input;
  963. struct mt_usages *slot;
  964. bool first_packet;
  965. unsigned count;
  966. int r, n;
  967. int scantime = 0;
  968. int contact_count = -1;
  969. /* sticky fingers release in progress, abort */
  970. if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
  971. return;
  972. scantime = *app->scantime;
  973. app->timestamp = mt_compute_timestamp(app, scantime);
  974. if (app->raw_cc != DEFAULT_ZERO)
  975. contact_count = *app->raw_cc;
  976. /*
  977. * Includes multi-packet support where subsequent
  978. * packets are sent with zero contactcount.
  979. */
  980. if (contact_count >= 0) {
  981. /*
  982. * For Win8 PTPs the first packet (td->num_received == 0) may
  983. * have a contactcount of 0 if there only is a button event.
  984. * We double check that this is not a continuation packet
  985. * of a possible multi-packet frame be checking that the
  986. * timestamp has changed.
  987. */
  988. if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
  989. app->num_received == 0 &&
  990. app->prev_scantime != scantime)
  991. app->num_expected = contact_count;
  992. /* A non 0 contact count always indicates a first packet */
  993. else if (contact_count)
  994. app->num_expected = contact_count;
  995. }
  996. app->prev_scantime = scantime;
  997. first_packet = app->num_received == 0;
  998. input = report->field[0]->hidinput->input;
  999. list_for_each_entry(slot, &app->mt_usages, list) {
  1000. if (!mt_process_slot(td, input, app, slot))
  1001. app->num_received++;
  1002. }
  1003. for (r = 0; r < report->maxfield; r++) {
  1004. field = report->field[r];
  1005. count = field->report_count;
  1006. if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
  1007. continue;
  1008. for (n = 0; n < count; n++)
  1009. mt_process_mt_event(hid, app, field,
  1010. &field->usage[n], field->value[n],
  1011. first_packet);
  1012. }
  1013. if (app->num_received >= app->num_expected)
  1014. mt_sync_frame(td, app, input);
  1015. /*
  1016. * Windows 8 specs says 2 things:
  1017. * - once a contact has been reported, it has to be reported in each
  1018. * subsequent report
  1019. * - the report rate when fingers are present has to be at least
  1020. * the refresh rate of the screen, 60 or 120 Hz
  1021. *
  1022. * I interprete this that the specification forces a report rate of
  1023. * at least 60 Hz for a touchscreen to be certified.
  1024. * Which means that if we do not get a report whithin 16 ms, either
  1025. * something wrong happens, either the touchscreen forgets to send
  1026. * a release. Taking a reasonable margin allows to remove issues
  1027. * with USB communication or the load of the machine.
  1028. *
  1029. * Given that Win 8 devices are forced to send a release, this will
  1030. * only affect laggish machines and the ones that have a firmware
  1031. * defect.
  1032. */
  1033. if (app->quirks & MT_QUIRK_STICKY_FINGERS) {
  1034. if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
  1035. mod_timer(&td->release_timer,
  1036. jiffies + msecs_to_jiffies(100));
  1037. else
  1038. del_timer(&td->release_timer);
  1039. }
  1040. clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
  1041. }
  1042. static int mt_touch_input_configured(struct hid_device *hdev,
  1043. struct hid_input *hi,
  1044. struct mt_application *app)
  1045. {
  1046. struct mt_device *td = hid_get_drvdata(hdev);
  1047. struct mt_class *cls = &td->mtclass;
  1048. struct input_dev *input = hi->input;
  1049. int ret;
  1050. if (!td->maxcontacts)
  1051. td->maxcontacts = MT_DEFAULT_MAXCONTACT;
  1052. mt_post_parse(td, app);
  1053. if (td->serial_maybe)
  1054. mt_post_parse_default_settings(td, app);
  1055. if (cls->is_indirect)
  1056. app->mt_flags |= INPUT_MT_POINTER;
  1057. if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
  1058. app->mt_flags |= INPUT_MT_DROP_UNUSED;
  1059. /* check for clickpads */
  1060. if ((app->mt_flags & INPUT_MT_POINTER) &&
  1061. (app->buttons_count == 1))
  1062. td->is_buttonpad = true;
  1063. if (td->is_buttonpad)
  1064. __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
  1065. app->pending_palm_slots = devm_kcalloc(&hi->input->dev,
  1066. BITS_TO_LONGS(td->maxcontacts),
  1067. sizeof(long),
  1068. GFP_KERNEL);
  1069. if (!app->pending_palm_slots)
  1070. return -ENOMEM;
  1071. ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags);
  1072. if (ret)
  1073. return ret;
  1074. app->mt_flags = 0;
  1075. return 0;
  1076. }
  1077. #define mt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \
  1078. max, EV_KEY, (c))
  1079. static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  1080. struct hid_field *field, struct hid_usage *usage,
  1081. unsigned long **bit, int *max)
  1082. {
  1083. struct mt_device *td = hid_get_drvdata(hdev);
  1084. struct mt_application *application;
  1085. struct mt_report_data *rdata;
  1086. rdata = mt_find_report_data(td, field->report);
  1087. if (!rdata) {
  1088. hid_err(hdev, "failed to allocate data for report\n");
  1089. return 0;
  1090. }
  1091. application = rdata->application;
  1092. /*
  1093. * If mtclass.export_all_inputs is not set, only map fields from
  1094. * TouchScreen or TouchPad collections. We need to ignore fields
  1095. * that belong to other collections such as Mouse that might have
  1096. * the same GenericDesktop usages.
  1097. */
  1098. if (!td->mtclass.export_all_inputs &&
  1099. field->application != HID_DG_TOUCHSCREEN &&
  1100. field->application != HID_DG_PEN &&
  1101. field->application != HID_DG_TOUCHPAD &&
  1102. field->application != HID_GD_KEYBOARD &&
  1103. field->application != HID_GD_SYSTEM_CONTROL &&
  1104. field->application != HID_CP_CONSUMER_CONTROL &&
  1105. field->application != HID_GD_WIRELESS_RADIO_CTLS &&
  1106. field->application != HID_GD_SYSTEM_MULTIAXIS &&
  1107. !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
  1108. application->quirks & MT_QUIRK_ASUS_CUSTOM_UP))
  1109. return -1;
  1110. /*
  1111. * Some Asus keyboard+touchpad devices have the hotkeys defined in the
  1112. * touchpad report descriptor. We need to treat these as an array to
  1113. * map usages to input keys.
  1114. */
  1115. if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
  1116. application->quirks & MT_QUIRK_ASUS_CUSTOM_UP &&
  1117. (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) {
  1118. set_bit(EV_REP, hi->input->evbit);
  1119. if (field->flags & HID_MAIN_ITEM_VARIABLE)
  1120. field->flags &= ~HID_MAIN_ITEM_VARIABLE;
  1121. switch (usage->hid & HID_USAGE) {
  1122. case 0x10: mt_map_key_clear(KEY_BRIGHTNESSDOWN); break;
  1123. case 0x20: mt_map_key_clear(KEY_BRIGHTNESSUP); break;
  1124. case 0x35: mt_map_key_clear(KEY_DISPLAY_OFF); break;
  1125. case 0x6b: mt_map_key_clear(KEY_F21); break;
  1126. case 0x6c: mt_map_key_clear(KEY_SLEEP); break;
  1127. default:
  1128. return -1;
  1129. }
  1130. return 1;
  1131. }
  1132. if (rdata->is_mt_collection)
  1133. return mt_touch_input_mapping(hdev, hi, field, usage, bit, max,
  1134. application);
  1135. /* let hid-core decide for the others */
  1136. return 0;
  1137. }
  1138. static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  1139. struct hid_field *field, struct hid_usage *usage,
  1140. unsigned long **bit, int *max)
  1141. {
  1142. struct mt_device *td = hid_get_drvdata(hdev);
  1143. struct mt_report_data *rdata;
  1144. rdata = mt_find_report_data(td, field->report);
  1145. if (rdata && rdata->is_mt_collection) {
  1146. /* We own these mappings, tell hid-input to ignore them */
  1147. return -1;
  1148. }
  1149. /* let hid-core decide for the others */
  1150. return 0;
  1151. }
  1152. static int mt_event(struct hid_device *hid, struct hid_field *field,
  1153. struct hid_usage *usage, __s32 value)
  1154. {
  1155. struct mt_device *td = hid_get_drvdata(hid);
  1156. struct mt_report_data *rdata;
  1157. rdata = mt_find_report_data(td, field->report);
  1158. if (rdata && rdata->is_mt_collection)
  1159. return mt_touch_event(hid, field, usage, value);
  1160. return 0;
  1161. }
  1162. static void mt_report(struct hid_device *hid, struct hid_report *report)
  1163. {
  1164. struct mt_device *td = hid_get_drvdata(hid);
  1165. struct hid_field *field = report->field[0];
  1166. struct mt_report_data *rdata;
  1167. if (!(hid->claimed & HID_CLAIMED_INPUT))
  1168. return;
  1169. rdata = mt_find_report_data(td, report);
  1170. if (rdata && rdata->is_mt_collection)
  1171. return mt_touch_report(hid, rdata);
  1172. if (field && field->hidinput && field->hidinput->input)
  1173. input_sync(field->hidinput->input);
  1174. }
  1175. static bool mt_need_to_apply_feature(struct hid_device *hdev,
  1176. struct hid_field *field,
  1177. struct hid_usage *usage,
  1178. enum latency_mode latency,
  1179. bool surface_switch,
  1180. bool button_switch,
  1181. bool *inputmode_found)
  1182. {
  1183. struct mt_device *td = hid_get_drvdata(hdev);
  1184. struct mt_class *cls = &td->mtclass;
  1185. struct hid_report *report = field->report;
  1186. unsigned int index = usage->usage_index;
  1187. char *buf;
  1188. u32 report_len;
  1189. int max;
  1190. switch (usage->hid) {
  1191. case HID_DG_INPUTMODE:
  1192. /*
  1193. * Some elan panels wrongly declare 2 input mode features,
  1194. * and silently ignore when we set the value in the second
  1195. * field. Skip the second feature and hope for the best.
  1196. */
  1197. if (*inputmode_found)
  1198. return false;
  1199. if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
  1200. report_len = hid_report_len(report);
  1201. buf = hid_alloc_report_buf(report, GFP_KERNEL);
  1202. if (!buf) {
  1203. hid_err(hdev,
  1204. "failed to allocate buffer for report\n");
  1205. return false;
  1206. }
  1207. hid_hw_raw_request(hdev, report->id, buf, report_len,
  1208. HID_FEATURE_REPORT,
  1209. HID_REQ_GET_REPORT);
  1210. kfree(buf);
  1211. }
  1212. field->value[index] = td->inputmode_value;
  1213. *inputmode_found = true;
  1214. return true;
  1215. case HID_DG_CONTACTMAX:
  1216. if (cls->maxcontacts) {
  1217. max = min_t(int, field->logical_maximum,
  1218. cls->maxcontacts);
  1219. if (field->value[index] != max) {
  1220. field->value[index] = max;
  1221. return true;
  1222. }
  1223. }
  1224. break;
  1225. case HID_DG_LATENCYMODE:
  1226. field->value[index] = latency;
  1227. return true;
  1228. case HID_DG_SURFACESWITCH:
  1229. field->value[index] = surface_switch;
  1230. return true;
  1231. case HID_DG_BUTTONSWITCH:
  1232. field->value[index] = button_switch;
  1233. return true;
  1234. }
  1235. return false; /* no need to update the report */
  1236. }
  1237. static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
  1238. bool surface_switch, bool button_switch)
  1239. {
  1240. struct hid_report_enum *rep_enum;
  1241. struct hid_report *rep;
  1242. struct hid_usage *usage;
  1243. int i, j;
  1244. bool update_report;
  1245. bool inputmode_found = false;
  1246. rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
  1247. list_for_each_entry(rep, &rep_enum->report_list, list) {
  1248. update_report = false;
  1249. for (i = 0; i < rep->maxfield; i++) {
  1250. /* Ignore if report count is out of bounds. */
  1251. if (rep->field[i]->report_count < 1)
  1252. continue;
  1253. for (j = 0; j < rep->field[i]->maxusage; j++) {
  1254. usage = &rep->field[i]->usage[j];
  1255. if (mt_need_to_apply_feature(hdev,
  1256. rep->field[i],
  1257. usage,
  1258. latency,
  1259. surface_switch,
  1260. button_switch,
  1261. &inputmode_found))
  1262. update_report = true;
  1263. }
  1264. }
  1265. if (update_report)
  1266. hid_hw_request(hdev, rep, HID_REQ_SET_REPORT);
  1267. }
  1268. }
  1269. static void mt_post_parse_default_settings(struct mt_device *td,
  1270. struct mt_application *app)
  1271. {
  1272. __s32 quirks = app->quirks;
  1273. /* unknown serial device needs special quirks */
  1274. if (list_is_singular(&app->mt_usages)) {
  1275. quirks |= MT_QUIRK_ALWAYS_VALID;
  1276. quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
  1277. quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
  1278. quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
  1279. quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
  1280. }
  1281. app->quirks = quirks;
  1282. }
  1283. static void mt_post_parse(struct mt_device *td, struct mt_application *app)
  1284. {
  1285. if (!app->have_contact_count)
  1286. app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
  1287. }
  1288. static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
  1289. {
  1290. struct mt_device *td = hid_get_drvdata(hdev);
  1291. char *name;
  1292. const char *suffix = NULL;
  1293. unsigned int application = 0;
  1294. struct mt_report_data *rdata;
  1295. struct mt_application *mt_application = NULL;
  1296. struct hid_report *report;
  1297. int ret;
  1298. list_for_each_entry(report, &hi->reports, hidinput_list) {
  1299. application = report->application;
  1300. rdata = mt_find_report_data(td, report);
  1301. if (!rdata) {
  1302. hid_err(hdev, "failed to allocate data for report\n");
  1303. return -ENOMEM;
  1304. }
  1305. mt_application = rdata->application;
  1306. if (rdata->is_mt_collection) {
  1307. ret = mt_touch_input_configured(hdev, hi,
  1308. mt_application);
  1309. if (ret)
  1310. return ret;
  1311. }
  1312. /*
  1313. * some egalax touchscreens have "application == DG_TOUCHSCREEN"
  1314. * for the stylus. Check this first, and then rely on
  1315. * the application field.
  1316. */
  1317. if (report->field[0]->physical == HID_DG_STYLUS) {
  1318. suffix = "Pen";
  1319. /* force BTN_STYLUS to allow tablet matching in udev */
  1320. __set_bit(BTN_STYLUS, hi->input->keybit);
  1321. }
  1322. }
  1323. if (!suffix) {
  1324. switch (application) {
  1325. case HID_GD_KEYBOARD:
  1326. case HID_GD_KEYPAD:
  1327. case HID_GD_MOUSE:
  1328. case HID_DG_TOUCHPAD:
  1329. case HID_GD_SYSTEM_CONTROL:
  1330. case HID_CP_CONSUMER_CONTROL:
  1331. case HID_GD_WIRELESS_RADIO_CTLS:
  1332. case HID_GD_SYSTEM_MULTIAXIS:
  1333. /* already handled by hid core */
  1334. break;
  1335. case HID_DG_TOUCHSCREEN:
  1336. /* we do not set suffix = "Touchscreen" */
  1337. hi->input->name = hdev->name;
  1338. break;
  1339. case HID_DG_STYLUS:
  1340. /* force BTN_STYLUS to allow tablet matching in udev */
  1341. __set_bit(BTN_STYLUS, hi->input->keybit);
  1342. break;
  1343. case HID_VD_ASUS_CUSTOM_MEDIA_KEYS:
  1344. suffix = "Custom Media Keys";
  1345. break;
  1346. default:
  1347. suffix = "UNKNOWN";
  1348. break;
  1349. }
  1350. }
  1351. if (suffix) {
  1352. name = devm_kzalloc(&hi->input->dev,
  1353. strlen(hdev->name) + strlen(suffix) + 2,
  1354. GFP_KERNEL);
  1355. if (name) {
  1356. sprintf(name, "%s %s", hdev->name, suffix);
  1357. hi->input->name = name;
  1358. }
  1359. }
  1360. return 0;
  1361. }
  1362. static void mt_fix_const_field(struct hid_field *field, unsigned int usage)
  1363. {
  1364. if (field->usage[0].hid != usage ||
  1365. !(field->flags & HID_MAIN_ITEM_CONSTANT))
  1366. return;
  1367. field->flags &= ~HID_MAIN_ITEM_CONSTANT;
  1368. field->flags |= HID_MAIN_ITEM_VARIABLE;
  1369. }
  1370. static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage)
  1371. {
  1372. struct hid_report *report;
  1373. int i;
  1374. list_for_each_entry(report,
  1375. &hdev->report_enum[HID_INPUT_REPORT].report_list,
  1376. list) {
  1377. if (!report->maxfield)
  1378. continue;
  1379. for (i = 0; i < report->maxfield; i++)
  1380. if (report->field[i]->maxusage >= 1)
  1381. mt_fix_const_field(report->field[i], usage);
  1382. }
  1383. }
  1384. static void mt_release_contacts(struct hid_device *hid)
  1385. {
  1386. struct hid_input *hidinput;
  1387. struct mt_application *application;
  1388. struct mt_device *td = hid_get_drvdata(hid);
  1389. list_for_each_entry(hidinput, &hid->inputs, list) {
  1390. struct input_dev *input_dev = hidinput->input;
  1391. struct input_mt *mt = input_dev->mt;
  1392. int i;
  1393. if (mt) {
  1394. for (i = 0; i < mt->num_slots; i++) {
  1395. input_mt_slot(input_dev, i);
  1396. input_mt_report_slot_state(input_dev,
  1397. MT_TOOL_FINGER,
  1398. false);
  1399. }
  1400. input_mt_sync_frame(input_dev);
  1401. input_sync(input_dev);
  1402. }
  1403. }
  1404. list_for_each_entry(application, &td->applications, list) {
  1405. application->num_received = 0;
  1406. }
  1407. }
  1408. static void mt_expired_timeout(struct timer_list *t)
  1409. {
  1410. struct mt_device *td = from_timer(td, t, release_timer);
  1411. struct hid_device *hdev = td->hdev;
  1412. /*
  1413. * An input report came in just before we release the sticky fingers,
  1414. * it will take care of the sticky fingers.
  1415. */
  1416. if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
  1417. return;
  1418. if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
  1419. mt_release_contacts(hdev);
  1420. clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
  1421. }
  1422. static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
  1423. {
  1424. int ret, i;
  1425. struct mt_device *td;
  1426. const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
  1427. for (i = 0; mt_classes[i].name ; i++) {
  1428. if (id->driver_data == mt_classes[i].name) {
  1429. mtclass = &(mt_classes[i]);
  1430. break;
  1431. }
  1432. }
  1433. td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
  1434. if (!td) {
  1435. dev_err(&hdev->dev, "cannot allocate multitouch data\n");
  1436. return -ENOMEM;
  1437. }
  1438. td->hdev = hdev;
  1439. td->mtclass = *mtclass;
  1440. td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
  1441. hid_set_drvdata(hdev, td);
  1442. INIT_LIST_HEAD(&td->applications);
  1443. INIT_LIST_HEAD(&td->reports);
  1444. if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
  1445. td->serial_maybe = true;
  1446. /* This allows the driver to correctly support devices
  1447. * that emit events over several HID messages.
  1448. */
  1449. hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
  1450. /*
  1451. * This allows the driver to handle different input sensors
  1452. * that emits events through different applications on the same HID
  1453. * device.
  1454. */
  1455. hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
  1456. if (id->group != HID_GROUP_MULTITOUCH_WIN_8)
  1457. hdev->quirks |= HID_QUIRK_MULTI_INPUT;
  1458. timer_setup(&td->release_timer, mt_expired_timeout, 0);
  1459. ret = hid_parse(hdev);
  1460. if (ret != 0)
  1461. return ret;
  1462. if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID)
  1463. mt_fix_const_fields(hdev, HID_DG_CONTACTID);
  1464. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1465. if (ret)
  1466. return ret;
  1467. ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
  1468. if (ret)
  1469. dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
  1470. hdev->name);
  1471. mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
  1472. return 0;
  1473. }
  1474. #ifdef CONFIG_PM
  1475. static int mt_reset_resume(struct hid_device *hdev)
  1476. {
  1477. mt_release_contacts(hdev);
  1478. mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
  1479. return 0;
  1480. }
  1481. static int mt_resume(struct hid_device *hdev)
  1482. {
  1483. /* Some Elan legacy devices require SET_IDLE to be set on resume.
  1484. * It should be safe to send it to other devices too.
  1485. * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */
  1486. hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
  1487. return 0;
  1488. }
  1489. #endif
  1490. static void mt_remove(struct hid_device *hdev)
  1491. {
  1492. struct mt_device *td = hid_get_drvdata(hdev);
  1493. del_timer_sync(&td->release_timer);
  1494. sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
  1495. hid_hw_stop(hdev);
  1496. }
  1497. /*
  1498. * This list contains only:
  1499. * - VID/PID of products not working with the default multitouch handling
  1500. * - 2 generic rules.
  1501. * So there is no point in adding here any device with MT_CLS_DEFAULT.
  1502. */
  1503. static const struct hid_device_id mt_devices[] = {
  1504. /* 3M panels */
  1505. { .driver_data = MT_CLS_3M,
  1506. MT_USB_DEVICE(USB_VENDOR_ID_3M,
  1507. USB_DEVICE_ID_3M1968) },
  1508. { .driver_data = MT_CLS_3M,
  1509. MT_USB_DEVICE(USB_VENDOR_ID_3M,
  1510. USB_DEVICE_ID_3M2256) },
  1511. { .driver_data = MT_CLS_3M,
  1512. MT_USB_DEVICE(USB_VENDOR_ID_3M,
  1513. USB_DEVICE_ID_3M3266) },
  1514. /* Alps devices */
  1515. { .driver_data = MT_CLS_WIN_8_DUAL,
  1516. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1517. USB_VENDOR_ID_ALPS_JP,
  1518. HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
  1519. { .driver_data = MT_CLS_WIN_8_DUAL,
  1520. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1521. USB_VENDOR_ID_ALPS_JP,
  1522. HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
  1523. { .driver_data = MT_CLS_WIN_8_DUAL,
  1524. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1525. USB_VENDOR_ID_ALPS_JP,
  1526. HID_DEVICE_ID_ALPS_1222) },
  1527. /* Lenovo X1 TAB Gen 2 */
  1528. { .driver_data = MT_CLS_WIN_8_DUAL,
  1529. HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
  1530. USB_VENDOR_ID_LENOVO,
  1531. USB_DEVICE_ID_LENOVO_X1_TAB) },
  1532. /* Anton devices */
  1533. { .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
  1534. MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
  1535. USB_DEVICE_ID_ANTON_TOUCH_PAD) },
  1536. /* Asus T304UA */
  1537. { .driver_data = MT_CLS_ASUS,
  1538. HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8,
  1539. USB_VENDOR_ID_ASUSTEK,
  1540. USB_DEVICE_ID_ASUSTEK_T304_KEYBOARD) },
  1541. /* Atmel panels */
  1542. { .driver_data = MT_CLS_SERIAL,
  1543. MT_USB_DEVICE(USB_VENDOR_ID_ATMEL,
  1544. USB_DEVICE_ID_ATMEL_MXT_DIGITIZER) },
  1545. /* Baanto multitouch devices */
  1546. { .driver_data = MT_CLS_NSMU,
  1547. MT_USB_DEVICE(USB_VENDOR_ID_BAANTO,
  1548. USB_DEVICE_ID_BAANTO_MT_190W2) },
  1549. /* Cando panels */
  1550. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  1551. MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
  1552. USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
  1553. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
  1554. MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
  1555. USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
  1556. /* Chunghwa Telecom touch panels */
  1557. { .driver_data = MT_CLS_NSMU,
  1558. MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
  1559. USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
  1560. /* Cirque devices */
  1561. { .driver_data = MT_CLS_WIN_8_DUAL,
  1562. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1563. I2C_VENDOR_ID_CIRQUE,
  1564. I2C_PRODUCT_ID_CIRQUE_121F) },
  1565. /* CJTouch panels */
  1566. { .driver_data = MT_CLS_NSMU,
  1567. MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
  1568. USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
  1569. { .driver_data = MT_CLS_NSMU,
  1570. MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
  1571. USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
  1572. /* CVTouch panels */
  1573. { .driver_data = MT_CLS_NSMU,
  1574. MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,
  1575. USB_DEVICE_ID_CVTOUCH_SCREEN) },
  1576. /* eGalax devices (resistive) */
  1577. { .driver_data = MT_CLS_EGALAX,
  1578. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1579. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
  1580. { .driver_data = MT_CLS_EGALAX,
  1581. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1582. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
  1583. /* eGalax devices (capacitive) */
  1584. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1585. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1586. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7207) },
  1587. { .driver_data = MT_CLS_EGALAX,
  1588. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1589. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
  1590. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1591. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1592. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
  1593. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1594. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1595. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_722A) },
  1596. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1597. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1598. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
  1599. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1600. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1601. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7262) },
  1602. { .driver_data = MT_CLS_EGALAX,
  1603. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1604. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
  1605. { .driver_data = MT_CLS_EGALAX,
  1606. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1607. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
  1608. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1609. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1610. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72AA) },
  1611. { .driver_data = MT_CLS_EGALAX,
  1612. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1613. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72C4) },
  1614. { .driver_data = MT_CLS_EGALAX,
  1615. HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1616. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72D0) },
  1617. { .driver_data = MT_CLS_EGALAX,
  1618. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1619. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
  1620. { .driver_data = MT_CLS_EGALAX,
  1621. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1622. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
  1623. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1624. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1625. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7349) },
  1626. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1627. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1628. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_73F7) },
  1629. { .driver_data = MT_CLS_EGALAX_SERIAL,
  1630. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1631. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
  1632. { .driver_data = MT_CLS_EGALAX,
  1633. MT_USB_DEVICE(USB_VENDOR_ID_DWAV,
  1634. USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_C002) },
  1635. /* Elitegroup panel */
  1636. { .driver_data = MT_CLS_SERIAL,
  1637. MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,
  1638. USB_DEVICE_ID_ELITEGROUP_05D8) },
  1639. /* Flatfrog Panels */
  1640. { .driver_data = MT_CLS_FLATFROG,
  1641. MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG,
  1642. USB_DEVICE_ID_MULTITOUCH_3200) },
  1643. /* FocalTech Panels */
  1644. { .driver_data = MT_CLS_SERIAL,
  1645. MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL,
  1646. USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) },
  1647. /* GeneralTouch panel */
  1648. { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
  1649. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1650. USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
  1651. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1652. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1653. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
  1654. { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
  1655. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1656. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
  1657. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1658. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1659. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
  1660. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1661. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1662. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
  1663. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1664. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1665. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
  1666. { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
  1667. MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
  1668. USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
  1669. /* Gametel game controller */
  1670. { .driver_data = MT_CLS_NSMU,
  1671. MT_BT_DEVICE(USB_VENDOR_ID_FRUCTEL,
  1672. USB_DEVICE_ID_GAMETEL_MT_MODE) },
  1673. /* GoodTouch panels */
  1674. { .driver_data = MT_CLS_NSMU,
  1675. MT_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
  1676. USB_DEVICE_ID_GOODTOUCH_000f) },
  1677. /* Hanvon panels */
  1678. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  1679. MT_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
  1680. USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
  1681. /* Ilitek dual touch panel */
  1682. { .driver_data = MT_CLS_NSMU,
  1683. MT_USB_DEVICE(USB_VENDOR_ID_ILITEK,
  1684. USB_DEVICE_ID_ILITEK_MULTITOUCH) },
  1685. /* LG Melfas panel */
  1686. { .driver_data = MT_CLS_LG,
  1687. HID_USB_DEVICE(USB_VENDOR_ID_LG,
  1688. USB_DEVICE_ID_LG_MELFAS_MT) },
  1689. { .driver_data = MT_CLS_LG,
  1690. HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
  1691. USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_7010) },
  1692. /* MosArt panels */
  1693. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  1694. MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
  1695. USB_DEVICE_ID_ASUS_T91MT)},
  1696. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  1697. MT_USB_DEVICE(USB_VENDOR_ID_ASUS,
  1698. USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
  1699. { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE,
  1700. MT_USB_DEVICE(USB_VENDOR_ID_TURBOX,
  1701. USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
  1702. /* Novatek Panel */
  1703. { .driver_data = MT_CLS_NSMU,
  1704. MT_USB_DEVICE(USB_VENDOR_ID_NOVATEK,
  1705. USB_DEVICE_ID_NOVATEK_PCT) },
  1706. /* Ntrig Panel */
  1707. { .driver_data = MT_CLS_NSMU,
  1708. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1709. USB_VENDOR_ID_NTRIG, 0x1b05) },
  1710. /* Panasonic panels */
  1711. { .driver_data = MT_CLS_PANASONIC,
  1712. MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
  1713. USB_DEVICE_ID_PANABOARD_UBT780) },
  1714. { .driver_data = MT_CLS_PANASONIC,
  1715. MT_USB_DEVICE(USB_VENDOR_ID_PANASONIC,
  1716. USB_DEVICE_ID_PANABOARD_UBT880) },
  1717. /* PixArt optical touch screen */
  1718. { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
  1719. MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
  1720. USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
  1721. { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
  1722. MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
  1723. USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
  1724. { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
  1725. MT_USB_DEVICE(USB_VENDOR_ID_PIXART,
  1726. USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
  1727. /* PixCir-based panels */
  1728. { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
  1729. MT_USB_DEVICE(USB_VENDOR_ID_CANDO,
  1730. USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
  1731. /* Quanta-based panels */
  1732. { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
  1733. MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
  1734. USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
  1735. /* Razer touchpads */
  1736. { .driver_data = MT_CLS_RAZER_BLADE_STEALTH,
  1737. HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
  1738. USB_VENDOR_ID_SYNAPTICS, 0x8323) },
  1739. /* Stantum panels */
  1740. { .driver_data = MT_CLS_CONFIDENCE,
  1741. MT_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
  1742. USB_DEVICE_ID_MTP_STM)},
  1743. /* TopSeed panels */
  1744. { .driver_data = MT_CLS_TOPSEED,
  1745. MT_USB_DEVICE(USB_VENDOR_ID_TOPSEED2,
  1746. USB_DEVICE_ID_TOPSEED2_PERIPAD_701) },
  1747. /* Touch International panels */
  1748. { .driver_data = MT_CLS_NSMU,
  1749. MT_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL,
  1750. USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
  1751. /* Unitec panels */
  1752. { .driver_data = MT_CLS_NSMU,
  1753. MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
  1754. USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
  1755. { .driver_data = MT_CLS_NSMU,
  1756. MT_USB_DEVICE(USB_VENDOR_ID_UNITEC,
  1757. USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
  1758. /* VTL panels */
  1759. { .driver_data = MT_CLS_VTL,
  1760. MT_USB_DEVICE(USB_VENDOR_ID_VTL,
  1761. USB_DEVICE_ID_VTL_MULTITOUCH_FF3F) },
  1762. /* Wistron panels */
  1763. { .driver_data = MT_CLS_NSMU,
  1764. MT_USB_DEVICE(USB_VENDOR_ID_WISTRON,
  1765. USB_DEVICE_ID_WISTRON_OPTICAL_TOUCH) },
  1766. /* XAT */
  1767. { .driver_data = MT_CLS_NSMU,
  1768. MT_USB_DEVICE(USB_VENDOR_ID_XAT,
  1769. USB_DEVICE_ID_XAT_CSR) },
  1770. /* Xiroku */
  1771. { .driver_data = MT_CLS_NSMU,
  1772. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1773. USB_DEVICE_ID_XIROKU_SPX) },
  1774. { .driver_data = MT_CLS_NSMU,
  1775. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1776. USB_DEVICE_ID_XIROKU_MPX) },
  1777. { .driver_data = MT_CLS_NSMU,
  1778. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1779. USB_DEVICE_ID_XIROKU_CSR) },
  1780. { .driver_data = MT_CLS_NSMU,
  1781. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1782. USB_DEVICE_ID_XIROKU_SPX1) },
  1783. { .driver_data = MT_CLS_NSMU,
  1784. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1785. USB_DEVICE_ID_XIROKU_MPX1) },
  1786. { .driver_data = MT_CLS_NSMU,
  1787. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1788. USB_DEVICE_ID_XIROKU_CSR1) },
  1789. { .driver_data = MT_CLS_NSMU,
  1790. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1791. USB_DEVICE_ID_XIROKU_SPX2) },
  1792. { .driver_data = MT_CLS_NSMU,
  1793. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1794. USB_DEVICE_ID_XIROKU_MPX2) },
  1795. { .driver_data = MT_CLS_NSMU,
  1796. MT_USB_DEVICE(USB_VENDOR_ID_XIROKU,
  1797. USB_DEVICE_ID_XIROKU_CSR2) },
  1798. /* Google MT devices */
  1799. { .driver_data = MT_CLS_GOOGLE,
  1800. HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE,
  1801. USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) },
  1802. /* Generic MT device */
  1803. { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
  1804. /* Generic Win 8 certified MT device */
  1805. { .driver_data = MT_CLS_WIN_8,
  1806. HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
  1807. HID_ANY_ID, HID_ANY_ID) },
  1808. { }
  1809. };
  1810. MODULE_DEVICE_TABLE(hid, mt_devices);
  1811. static const struct hid_usage_id mt_grabbed_usages[] = {
  1812. { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
  1813. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
  1814. };
  1815. static struct hid_driver mt_driver = {
  1816. .name = "hid-multitouch",
  1817. .id_table = mt_devices,
  1818. .probe = mt_probe,
  1819. .remove = mt_remove,
  1820. .input_mapping = mt_input_mapping,
  1821. .input_mapped = mt_input_mapped,
  1822. .input_configured = mt_input_configured,
  1823. .feature_mapping = mt_feature_mapping,
  1824. .usage_table = mt_grabbed_usages,
  1825. .event = mt_event,
  1826. .report = mt_report,
  1827. #ifdef CONFIG_PM
  1828. .reset_resume = mt_reset_resume,
  1829. .resume = mt_resume,
  1830. #endif
  1831. };
  1832. module_hid_driver(mt_driver);