hid-multitouch.c 66 KB

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