hid-multitouch.c 63 KB

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