hid-core.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875
  1. /*
  2. * HID support for Linux
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2006-2012 Jiri Kosina
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/list.h>
  21. #include <linux/mm.h>
  22. #include <linux/spinlock.h>
  23. #include <asm/unaligned.h>
  24. #include <asm/byteorder.h>
  25. #include <linux/input.h>
  26. #include <linux/wait.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/sched.h>
  29. #include <linux/semaphore.h>
  30. #include <linux/hid.h>
  31. #include <linux/hiddev.h>
  32. #include <linux/hid-debug.h>
  33. #include <linux/hidraw.h>
  34. #include "hid-ids.h"
  35. /*
  36. * Version Information
  37. */
  38. #define DRIVER_DESC "HID core driver"
  39. int hid_debug = 0;
  40. module_param_named(debug, hid_debug, int, 0600);
  41. MODULE_PARM_DESC(debug, "toggle HID debugging messages");
  42. EXPORT_SYMBOL_GPL(hid_debug);
  43. static int hid_ignore_special_drivers = 0;
  44. module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
  45. MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
  46. /*
  47. * Register a new report for a device.
  48. */
  49. struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
  50. {
  51. struct hid_report_enum *report_enum = device->report_enum + type;
  52. struct hid_report *report;
  53. if (id >= HID_MAX_IDS)
  54. return NULL;
  55. if (report_enum->report_id_hash[id])
  56. return report_enum->report_id_hash[id];
  57. report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
  58. if (!report)
  59. return NULL;
  60. if (id != 0)
  61. report_enum->numbered = 1;
  62. report->id = id;
  63. report->type = type;
  64. report->size = 0;
  65. report->device = device;
  66. report_enum->report_id_hash[id] = report;
  67. list_add_tail(&report->list, &report_enum->report_list);
  68. return report;
  69. }
  70. EXPORT_SYMBOL_GPL(hid_register_report);
  71. /*
  72. * Register a new field for this report.
  73. */
  74. static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
  75. {
  76. struct hid_field *field;
  77. if (report->maxfield == HID_MAX_FIELDS) {
  78. hid_err(report->device, "too many fields in report\n");
  79. return NULL;
  80. }
  81. field = kzalloc((sizeof(struct hid_field) +
  82. usages * sizeof(struct hid_usage) +
  83. values * sizeof(unsigned)), GFP_KERNEL);
  84. if (!field)
  85. return NULL;
  86. field->index = report->maxfield++;
  87. report->field[field->index] = field;
  88. field->usage = (struct hid_usage *)(field + 1);
  89. field->value = (s32 *)(field->usage + usages);
  90. field->report = report;
  91. return field;
  92. }
  93. /*
  94. * Open a collection. The type/usage is pushed on the stack.
  95. */
  96. static int open_collection(struct hid_parser *parser, unsigned type)
  97. {
  98. struct hid_collection *collection;
  99. unsigned usage;
  100. usage = parser->local.usage[0];
  101. if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
  102. hid_err(parser->device, "collection stack overflow\n");
  103. return -EINVAL;
  104. }
  105. if (parser->device->maxcollection == parser->device->collection_size) {
  106. collection = kmalloc(sizeof(struct hid_collection) *
  107. parser->device->collection_size * 2, GFP_KERNEL);
  108. if (collection == NULL) {
  109. hid_err(parser->device, "failed to reallocate collection array\n");
  110. return -ENOMEM;
  111. }
  112. memcpy(collection, parser->device->collection,
  113. sizeof(struct hid_collection) *
  114. parser->device->collection_size);
  115. memset(collection + parser->device->collection_size, 0,
  116. sizeof(struct hid_collection) *
  117. parser->device->collection_size);
  118. kfree(parser->device->collection);
  119. parser->device->collection = collection;
  120. parser->device->collection_size *= 2;
  121. }
  122. parser->collection_stack[parser->collection_stack_ptr++] =
  123. parser->device->maxcollection;
  124. collection = parser->device->collection +
  125. parser->device->maxcollection++;
  126. collection->type = type;
  127. collection->usage = usage;
  128. collection->level = parser->collection_stack_ptr - 1;
  129. if (type == HID_COLLECTION_APPLICATION)
  130. parser->device->maxapplication++;
  131. return 0;
  132. }
  133. /*
  134. * Close a collection.
  135. */
  136. static int close_collection(struct hid_parser *parser)
  137. {
  138. if (!parser->collection_stack_ptr) {
  139. hid_err(parser->device, "collection stack underflow\n");
  140. return -EINVAL;
  141. }
  142. parser->collection_stack_ptr--;
  143. return 0;
  144. }
  145. /*
  146. * Climb up the stack, search for the specified collection type
  147. * and return the usage.
  148. */
  149. static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
  150. {
  151. struct hid_collection *collection = parser->device->collection;
  152. int n;
  153. for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
  154. unsigned index = parser->collection_stack[n];
  155. if (collection[index].type == type)
  156. return collection[index].usage;
  157. }
  158. return 0; /* we know nothing about this usage type */
  159. }
  160. /*
  161. * Add a usage to the temporary parser table.
  162. */
  163. static int hid_add_usage(struct hid_parser *parser, unsigned usage)
  164. {
  165. if (parser->local.usage_index >= HID_MAX_USAGES) {
  166. hid_err(parser->device, "usage index exceeded\n");
  167. return -1;
  168. }
  169. parser->local.usage[parser->local.usage_index] = usage;
  170. parser->local.collection_index[parser->local.usage_index] =
  171. parser->collection_stack_ptr ?
  172. parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
  173. parser->local.usage_index++;
  174. return 0;
  175. }
  176. /*
  177. * Register a new field for this report.
  178. */
  179. static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
  180. {
  181. struct hid_report *report;
  182. struct hid_field *field;
  183. unsigned usages;
  184. unsigned offset;
  185. unsigned i;
  186. report = hid_register_report(parser->device, report_type, parser->global.report_id);
  187. if (!report) {
  188. hid_err(parser->device, "hid_register_report failed\n");
  189. return -1;
  190. }
  191. /* Handle both signed and unsigned cases properly */
  192. if ((parser->global.logical_minimum < 0 &&
  193. parser->global.logical_maximum <
  194. parser->global.logical_minimum) ||
  195. (parser->global.logical_minimum >= 0 &&
  196. (__u32)parser->global.logical_maximum <
  197. (__u32)parser->global.logical_minimum)) {
  198. dbg_hid("logical range invalid 0x%x 0x%x\n",
  199. parser->global.logical_minimum,
  200. parser->global.logical_maximum);
  201. return -1;
  202. }
  203. offset = report->size;
  204. report->size += parser->global.report_size * parser->global.report_count;
  205. if (!parser->local.usage_index) /* Ignore padding fields */
  206. return 0;
  207. usages = max_t(unsigned, parser->local.usage_index,
  208. parser->global.report_count);
  209. field = hid_register_field(report, usages, parser->global.report_count);
  210. if (!field)
  211. return 0;
  212. field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
  213. field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
  214. field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
  215. for (i = 0; i < usages; i++) {
  216. unsigned j = i;
  217. /* Duplicate the last usage we parsed if we have excess values */
  218. if (i >= parser->local.usage_index)
  219. j = parser->local.usage_index - 1;
  220. field->usage[i].hid = parser->local.usage[j];
  221. field->usage[i].collection_index =
  222. parser->local.collection_index[j];
  223. field->usage[i].usage_index = i;
  224. }
  225. field->maxusage = usages;
  226. field->flags = flags;
  227. field->report_offset = offset;
  228. field->report_type = report_type;
  229. field->report_size = parser->global.report_size;
  230. field->report_count = parser->global.report_count;
  231. field->logical_minimum = parser->global.logical_minimum;
  232. field->logical_maximum = parser->global.logical_maximum;
  233. field->physical_minimum = parser->global.physical_minimum;
  234. field->physical_maximum = parser->global.physical_maximum;
  235. field->unit_exponent = parser->global.unit_exponent;
  236. field->unit = parser->global.unit;
  237. return 0;
  238. }
  239. /*
  240. * Read data value from item.
  241. */
  242. static u32 item_udata(struct hid_item *item)
  243. {
  244. switch (item->size) {
  245. case 1: return item->data.u8;
  246. case 2: return item->data.u16;
  247. case 4: return item->data.u32;
  248. }
  249. return 0;
  250. }
  251. static s32 item_sdata(struct hid_item *item)
  252. {
  253. switch (item->size) {
  254. case 1: return item->data.s8;
  255. case 2: return item->data.s16;
  256. case 4: return item->data.s32;
  257. }
  258. return 0;
  259. }
  260. /*
  261. * Process a global item.
  262. */
  263. static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
  264. {
  265. __s32 raw_value;
  266. switch (item->tag) {
  267. case HID_GLOBAL_ITEM_TAG_PUSH:
  268. if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
  269. hid_err(parser->device, "global environment stack overflow\n");
  270. return -1;
  271. }
  272. memcpy(parser->global_stack + parser->global_stack_ptr++,
  273. &parser->global, sizeof(struct hid_global));
  274. return 0;
  275. case HID_GLOBAL_ITEM_TAG_POP:
  276. if (!parser->global_stack_ptr) {
  277. hid_err(parser->device, "global environment stack underflow\n");
  278. return -1;
  279. }
  280. memcpy(&parser->global, parser->global_stack +
  281. --parser->global_stack_ptr, sizeof(struct hid_global));
  282. return 0;
  283. case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
  284. parser->global.usage_page = item_udata(item);
  285. return 0;
  286. case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
  287. parser->global.logical_minimum = item_sdata(item);
  288. return 0;
  289. case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
  290. if (parser->global.logical_minimum < 0)
  291. parser->global.logical_maximum = item_sdata(item);
  292. else
  293. parser->global.logical_maximum = item_udata(item);
  294. return 0;
  295. case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
  296. parser->global.physical_minimum = item_sdata(item);
  297. return 0;
  298. case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
  299. if (parser->global.physical_minimum < 0)
  300. parser->global.physical_maximum = item_sdata(item);
  301. else
  302. parser->global.physical_maximum = item_udata(item);
  303. return 0;
  304. case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
  305. /* Many devices provide unit exponent as a two's complement
  306. * nibble due to the common misunderstanding of HID
  307. * specification 1.11, 6.2.2.7 Global Items. Attempt to handle
  308. * both this and the standard encoding. */
  309. raw_value = item_sdata(item);
  310. if (!(raw_value & 0xfffffff0))
  311. parser->global.unit_exponent = hid_snto32(raw_value, 4);
  312. else
  313. parser->global.unit_exponent = raw_value;
  314. return 0;
  315. case HID_GLOBAL_ITEM_TAG_UNIT:
  316. parser->global.unit = item_udata(item);
  317. return 0;
  318. case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
  319. parser->global.report_size = item_udata(item);
  320. if (parser->global.report_size > 128) {
  321. hid_err(parser->device, "invalid report_size %d\n",
  322. parser->global.report_size);
  323. return -1;
  324. }
  325. return 0;
  326. case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
  327. parser->global.report_count = item_udata(item);
  328. if (parser->global.report_count > HID_MAX_USAGES) {
  329. hid_err(parser->device, "invalid report_count %d\n",
  330. parser->global.report_count);
  331. return -1;
  332. }
  333. return 0;
  334. case HID_GLOBAL_ITEM_TAG_REPORT_ID:
  335. parser->global.report_id = item_udata(item);
  336. if (parser->global.report_id == 0 ||
  337. parser->global.report_id >= HID_MAX_IDS) {
  338. hid_err(parser->device, "report_id %u is invalid\n",
  339. parser->global.report_id);
  340. return -1;
  341. }
  342. return 0;
  343. default:
  344. hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
  345. return -1;
  346. }
  347. }
  348. /*
  349. * Process a local item.
  350. */
  351. static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
  352. {
  353. __u32 data;
  354. unsigned n;
  355. __u32 count;
  356. data = item_udata(item);
  357. switch (item->tag) {
  358. case HID_LOCAL_ITEM_TAG_DELIMITER:
  359. if (data) {
  360. /*
  361. * We treat items before the first delimiter
  362. * as global to all usage sets (branch 0).
  363. * In the moment we process only these global
  364. * items and the first delimiter set.
  365. */
  366. if (parser->local.delimiter_depth != 0) {
  367. hid_err(parser->device, "nested delimiters\n");
  368. return -1;
  369. }
  370. parser->local.delimiter_depth++;
  371. parser->local.delimiter_branch++;
  372. } else {
  373. if (parser->local.delimiter_depth < 1) {
  374. hid_err(parser->device, "bogus close delimiter\n");
  375. return -1;
  376. }
  377. parser->local.delimiter_depth--;
  378. }
  379. return 0;
  380. case HID_LOCAL_ITEM_TAG_USAGE:
  381. if (parser->local.delimiter_branch > 1) {
  382. dbg_hid("alternative usage ignored\n");
  383. return 0;
  384. }
  385. if (item->size <= 2)
  386. data = (parser->global.usage_page << 16) + data;
  387. return hid_add_usage(parser, data);
  388. case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
  389. if (parser->local.delimiter_branch > 1) {
  390. dbg_hid("alternative usage ignored\n");
  391. return 0;
  392. }
  393. if (item->size <= 2)
  394. data = (parser->global.usage_page << 16) + data;
  395. parser->local.usage_minimum = data;
  396. return 0;
  397. case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
  398. if (parser->local.delimiter_branch > 1) {
  399. dbg_hid("alternative usage ignored\n");
  400. return 0;
  401. }
  402. if (item->size <= 2)
  403. data = (parser->global.usage_page << 16) + data;
  404. count = data - parser->local.usage_minimum;
  405. if (count + parser->local.usage_index >= HID_MAX_USAGES) {
  406. /*
  407. * We do not warn if the name is not set, we are
  408. * actually pre-scanning the device.
  409. */
  410. if (dev_name(&parser->device->dev))
  411. hid_warn(parser->device,
  412. "ignoring exceeding usage max\n");
  413. data = HID_MAX_USAGES - parser->local.usage_index +
  414. parser->local.usage_minimum - 1;
  415. if (data <= 0) {
  416. hid_err(parser->device,
  417. "no more usage index available\n");
  418. return -1;
  419. }
  420. }
  421. for (n = parser->local.usage_minimum; n <= data; n++)
  422. if (hid_add_usage(parser, n)) {
  423. dbg_hid("hid_add_usage failed\n");
  424. return -1;
  425. }
  426. return 0;
  427. default:
  428. dbg_hid("unknown local item tag 0x%x\n", item->tag);
  429. return 0;
  430. }
  431. return 0;
  432. }
  433. /*
  434. * Process a main item.
  435. */
  436. static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
  437. {
  438. __u32 data;
  439. int ret;
  440. data = item_udata(item);
  441. switch (item->tag) {
  442. case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
  443. ret = open_collection(parser, data & 0xff);
  444. break;
  445. case HID_MAIN_ITEM_TAG_END_COLLECTION:
  446. ret = close_collection(parser);
  447. break;
  448. case HID_MAIN_ITEM_TAG_INPUT:
  449. ret = hid_add_field(parser, HID_INPUT_REPORT, data);
  450. break;
  451. case HID_MAIN_ITEM_TAG_OUTPUT:
  452. ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
  453. break;
  454. case HID_MAIN_ITEM_TAG_FEATURE:
  455. ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
  456. break;
  457. default:
  458. hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag);
  459. ret = 0;
  460. }
  461. memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
  462. return ret;
  463. }
  464. /*
  465. * Process a reserved item.
  466. */
  467. static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
  468. {
  469. dbg_hid("reserved item type, tag 0x%x\n", item->tag);
  470. return 0;
  471. }
  472. /*
  473. * Free a report and all registered fields. The field->usage and
  474. * field->value table's are allocated behind the field, so we need
  475. * only to free(field) itself.
  476. */
  477. static void hid_free_report(struct hid_report *report)
  478. {
  479. unsigned n;
  480. for (n = 0; n < report->maxfield; n++)
  481. kfree(report->field[n]);
  482. kfree(report);
  483. }
  484. /*
  485. * Close report. This function returns the device
  486. * state to the point prior to hid_open_report().
  487. */
  488. static void hid_close_report(struct hid_device *device)
  489. {
  490. unsigned i, j;
  491. for (i = 0; i < HID_REPORT_TYPES; i++) {
  492. struct hid_report_enum *report_enum = device->report_enum + i;
  493. for (j = 0; j < HID_MAX_IDS; j++) {
  494. struct hid_report *report = report_enum->report_id_hash[j];
  495. if (report)
  496. hid_free_report(report);
  497. }
  498. memset(report_enum, 0, sizeof(*report_enum));
  499. INIT_LIST_HEAD(&report_enum->report_list);
  500. }
  501. kfree(device->rdesc);
  502. device->rdesc = NULL;
  503. device->rsize = 0;
  504. kfree(device->collection);
  505. device->collection = NULL;
  506. device->collection_size = 0;
  507. device->maxcollection = 0;
  508. device->maxapplication = 0;
  509. device->status &= ~HID_STAT_PARSED;
  510. }
  511. /*
  512. * Free a device structure, all reports, and all fields.
  513. */
  514. static void hid_device_release(struct device *dev)
  515. {
  516. struct hid_device *hid = to_hid_device(dev);
  517. hid_close_report(hid);
  518. kfree(hid->dev_rdesc);
  519. kfree(hid);
  520. }
  521. /*
  522. * Fetch a report description item from the data stream. We support long
  523. * items, though they are not used yet.
  524. */
  525. static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
  526. {
  527. u8 b;
  528. if ((end - start) <= 0)
  529. return NULL;
  530. b = *start++;
  531. item->type = (b >> 2) & 3;
  532. item->tag = (b >> 4) & 15;
  533. if (item->tag == HID_ITEM_TAG_LONG) {
  534. item->format = HID_ITEM_FORMAT_LONG;
  535. if ((end - start) < 2)
  536. return NULL;
  537. item->size = *start++;
  538. item->tag = *start++;
  539. if ((end - start) < item->size)
  540. return NULL;
  541. item->data.longdata = start;
  542. start += item->size;
  543. return start;
  544. }
  545. item->format = HID_ITEM_FORMAT_SHORT;
  546. item->size = b & 3;
  547. switch (item->size) {
  548. case 0:
  549. return start;
  550. case 1:
  551. if ((end - start) < 1)
  552. return NULL;
  553. item->data.u8 = *start++;
  554. return start;
  555. case 2:
  556. if ((end - start) < 2)
  557. return NULL;
  558. item->data.u16 = get_unaligned_le16(start);
  559. start = (__u8 *)((__le16 *)start + 1);
  560. return start;
  561. case 3:
  562. item->size++;
  563. if ((end - start) < 4)
  564. return NULL;
  565. item->data.u32 = get_unaligned_le32(start);
  566. start = (__u8 *)((__le32 *)start + 1);
  567. return start;
  568. }
  569. return NULL;
  570. }
  571. static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
  572. {
  573. struct hid_device *hid = parser->device;
  574. if (usage == HID_DG_CONTACTID)
  575. hid->group = HID_GROUP_MULTITOUCH;
  576. }
  577. static void hid_scan_feature_usage(struct hid_parser *parser, u32 usage)
  578. {
  579. if (usage == 0xff0000c5 && parser->global.report_count == 256 &&
  580. parser->global.report_size == 8)
  581. parser->scan_flags |= HID_SCAN_FLAG_MT_WIN_8;
  582. }
  583. static void hid_scan_collection(struct hid_parser *parser, unsigned type)
  584. {
  585. struct hid_device *hid = parser->device;
  586. int i;
  587. if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
  588. type == HID_COLLECTION_PHYSICAL)
  589. hid->group = HID_GROUP_SENSOR_HUB;
  590. if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
  591. hid->product == USB_DEVICE_ID_MS_POWER_COVER &&
  592. hid->group == HID_GROUP_MULTITOUCH)
  593. hid->group = HID_GROUP_GENERIC;
  594. if ((parser->global.usage_page << 16) == HID_UP_GENDESK)
  595. for (i = 0; i < parser->local.usage_index; i++)
  596. if (parser->local.usage[i] == HID_GD_POINTER)
  597. parser->scan_flags |= HID_SCAN_FLAG_GD_POINTER;
  598. if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
  599. parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
  600. }
  601. static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
  602. {
  603. __u32 data;
  604. int i;
  605. data = item_udata(item);
  606. switch (item->tag) {
  607. case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
  608. hid_scan_collection(parser, data & 0xff);
  609. break;
  610. case HID_MAIN_ITEM_TAG_END_COLLECTION:
  611. break;
  612. case HID_MAIN_ITEM_TAG_INPUT:
  613. /* ignore constant inputs, they will be ignored by hid-input */
  614. if (data & HID_MAIN_ITEM_CONSTANT)
  615. break;
  616. for (i = 0; i < parser->local.usage_index; i++)
  617. hid_scan_input_usage(parser, parser->local.usage[i]);
  618. break;
  619. case HID_MAIN_ITEM_TAG_OUTPUT:
  620. break;
  621. case HID_MAIN_ITEM_TAG_FEATURE:
  622. for (i = 0; i < parser->local.usage_index; i++)
  623. hid_scan_feature_usage(parser, parser->local.usage[i]);
  624. break;
  625. }
  626. /* Reset the local parser environment */
  627. memset(&parser->local, 0, sizeof(parser->local));
  628. return 0;
  629. }
  630. /*
  631. * Scan a report descriptor before the device is added to the bus.
  632. * Sets device groups and other properties that determine what driver
  633. * to load.
  634. */
  635. static int hid_scan_report(struct hid_device *hid)
  636. {
  637. struct hid_parser *parser;
  638. struct hid_item item;
  639. __u8 *start = hid->dev_rdesc;
  640. __u8 *end = start + hid->dev_rsize;
  641. static int (*dispatch_type[])(struct hid_parser *parser,
  642. struct hid_item *item) = {
  643. hid_scan_main,
  644. hid_parser_global,
  645. hid_parser_local,
  646. hid_parser_reserved
  647. };
  648. parser = vzalloc(sizeof(struct hid_parser));
  649. if (!parser)
  650. return -ENOMEM;
  651. parser->device = hid;
  652. hid->group = HID_GROUP_GENERIC;
  653. /*
  654. * The parsing is simpler than the one in hid_open_report() as we should
  655. * be robust against hid errors. Those errors will be raised by
  656. * hid_open_report() anyway.
  657. */
  658. while ((start = fetch_item(start, end, &item)) != NULL)
  659. dispatch_type[item.type](parser, &item);
  660. /*
  661. * Handle special flags set during scanning.
  662. */
  663. if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
  664. (hid->group == HID_GROUP_MULTITOUCH))
  665. hid->group = HID_GROUP_MULTITOUCH_WIN_8;
  666. /*
  667. * Vendor specific handlings
  668. */
  669. switch (hid->vendor) {
  670. case USB_VENDOR_ID_WACOM:
  671. hid->group = HID_GROUP_WACOM;
  672. break;
  673. case USB_VENDOR_ID_SYNAPTICS:
  674. if (hid->group == HID_GROUP_GENERIC)
  675. if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
  676. && (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER))
  677. /*
  678. * hid-rmi should take care of them,
  679. * not hid-generic
  680. */
  681. if (IS_ENABLED(CONFIG_HID_RMI))
  682. hid->group = HID_GROUP_RMI;
  683. break;
  684. }
  685. vfree(parser);
  686. return 0;
  687. }
  688. /**
  689. * hid_parse_report - parse device report
  690. *
  691. * @device: hid device
  692. * @start: report start
  693. * @size: report size
  694. *
  695. * Allocate the device report as read by the bus driver. This function should
  696. * only be called from parse() in ll drivers.
  697. */
  698. int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
  699. {
  700. hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
  701. if (!hid->dev_rdesc)
  702. return -ENOMEM;
  703. hid->dev_rsize = size;
  704. return 0;
  705. }
  706. EXPORT_SYMBOL_GPL(hid_parse_report);
  707. static const char * const hid_report_names[] = {
  708. "HID_INPUT_REPORT",
  709. "HID_OUTPUT_REPORT",
  710. "HID_FEATURE_REPORT",
  711. };
  712. /**
  713. * hid_validate_values - validate existing device report's value indexes
  714. *
  715. * @device: hid device
  716. * @type: which report type to examine
  717. * @id: which report ID to examine (0 for first)
  718. * @field_index: which report field to examine
  719. * @report_counts: expected number of values
  720. *
  721. * Validate the number of values in a given field of a given report, after
  722. * parsing.
  723. */
  724. struct hid_report *hid_validate_values(struct hid_device *hid,
  725. unsigned int type, unsigned int id,
  726. unsigned int field_index,
  727. unsigned int report_counts)
  728. {
  729. struct hid_report *report;
  730. if (type > HID_FEATURE_REPORT) {
  731. hid_err(hid, "invalid HID report type %u\n", type);
  732. return NULL;
  733. }
  734. if (id >= HID_MAX_IDS) {
  735. hid_err(hid, "invalid HID report id %u\n", id);
  736. return NULL;
  737. }
  738. /*
  739. * Explicitly not using hid_get_report() here since it depends on
  740. * ->numbered being checked, which may not always be the case when
  741. * drivers go to access report values.
  742. */
  743. if (id == 0) {
  744. /*
  745. * Validating on id 0 means we should examine the first
  746. * report in the list.
  747. */
  748. report = list_entry(
  749. hid->report_enum[type].report_list.next,
  750. struct hid_report, list);
  751. } else {
  752. report = hid->report_enum[type].report_id_hash[id];
  753. }
  754. if (!report) {
  755. hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
  756. return NULL;
  757. }
  758. if (report->maxfield <= field_index) {
  759. hid_err(hid, "not enough fields in %s %u\n",
  760. hid_report_names[type], id);
  761. return NULL;
  762. }
  763. if (report->field[field_index]->report_count < report_counts) {
  764. hid_err(hid, "not enough values in %s %u field %u\n",
  765. hid_report_names[type], id, field_index);
  766. return NULL;
  767. }
  768. return report;
  769. }
  770. EXPORT_SYMBOL_GPL(hid_validate_values);
  771. /**
  772. * hid_open_report - open a driver-specific device report
  773. *
  774. * @device: hid device
  775. *
  776. * Parse a report description into a hid_device structure. Reports are
  777. * enumerated, fields are attached to these reports.
  778. * 0 returned on success, otherwise nonzero error value.
  779. *
  780. * This function (or the equivalent hid_parse() macro) should only be
  781. * called from probe() in drivers, before starting the device.
  782. */
  783. int hid_open_report(struct hid_device *device)
  784. {
  785. struct hid_parser *parser;
  786. struct hid_item item;
  787. unsigned int size;
  788. __u8 *start;
  789. __u8 *buf;
  790. __u8 *end;
  791. int ret;
  792. static int (*dispatch_type[])(struct hid_parser *parser,
  793. struct hid_item *item) = {
  794. hid_parser_main,
  795. hid_parser_global,
  796. hid_parser_local,
  797. hid_parser_reserved
  798. };
  799. if (WARN_ON(device->status & HID_STAT_PARSED))
  800. return -EBUSY;
  801. start = device->dev_rdesc;
  802. if (WARN_ON(!start))
  803. return -ENODEV;
  804. size = device->dev_rsize;
  805. buf = kmemdup(start, size, GFP_KERNEL);
  806. if (buf == NULL)
  807. return -ENOMEM;
  808. if (device->driver->report_fixup)
  809. start = device->driver->report_fixup(device, buf, &size);
  810. else
  811. start = buf;
  812. start = kmemdup(start, size, GFP_KERNEL);
  813. kfree(buf);
  814. if (start == NULL)
  815. return -ENOMEM;
  816. device->rdesc = start;
  817. device->rsize = size;
  818. parser = vzalloc(sizeof(struct hid_parser));
  819. if (!parser) {
  820. ret = -ENOMEM;
  821. goto err;
  822. }
  823. parser->device = device;
  824. end = start + size;
  825. device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
  826. sizeof(struct hid_collection), GFP_KERNEL);
  827. if (!device->collection) {
  828. ret = -ENOMEM;
  829. goto err;
  830. }
  831. device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
  832. ret = -EINVAL;
  833. while ((start = fetch_item(start, end, &item)) != NULL) {
  834. if (item.format != HID_ITEM_FORMAT_SHORT) {
  835. hid_err(device, "unexpected long global item\n");
  836. goto err;
  837. }
  838. if (dispatch_type[item.type](parser, &item)) {
  839. hid_err(device, "item %u %u %u %u parsing failed\n",
  840. item.format, (unsigned)item.size,
  841. (unsigned)item.type, (unsigned)item.tag);
  842. goto err;
  843. }
  844. if (start == end) {
  845. if (parser->collection_stack_ptr) {
  846. hid_err(device, "unbalanced collection at end of report description\n");
  847. goto err;
  848. }
  849. if (parser->local.delimiter_depth) {
  850. hid_err(device, "unbalanced delimiter at end of report description\n");
  851. goto err;
  852. }
  853. vfree(parser);
  854. device->status |= HID_STAT_PARSED;
  855. return 0;
  856. }
  857. }
  858. hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
  859. err:
  860. vfree(parser);
  861. hid_close_report(device);
  862. return ret;
  863. }
  864. EXPORT_SYMBOL_GPL(hid_open_report);
  865. /*
  866. * Convert a signed n-bit integer to signed 32-bit integer. Common
  867. * cases are done through the compiler, the screwed things has to be
  868. * done by hand.
  869. */
  870. static s32 snto32(__u32 value, unsigned n)
  871. {
  872. switch (n) {
  873. case 8: return ((__s8)value);
  874. case 16: return ((__s16)value);
  875. case 32: return ((__s32)value);
  876. }
  877. return value & (1 << (n - 1)) ? value | (-1 << n) : value;
  878. }
  879. s32 hid_snto32(__u32 value, unsigned n)
  880. {
  881. return snto32(value, n);
  882. }
  883. EXPORT_SYMBOL_GPL(hid_snto32);
  884. /*
  885. * Convert a signed 32-bit integer to a signed n-bit integer.
  886. */
  887. static u32 s32ton(__s32 value, unsigned n)
  888. {
  889. s32 a = value >> (n - 1);
  890. if (a && a != -1)
  891. return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
  892. return value & ((1 << n) - 1);
  893. }
  894. /*
  895. * Extract/implement a data field from/to a little endian report (bit array).
  896. *
  897. * Code sort-of follows HID spec:
  898. * http://www.usb.org/developers/hidpage/HID1_11.pdf
  899. *
  900. * While the USB HID spec allows unlimited length bit fields in "report
  901. * descriptors", most devices never use more than 16 bits.
  902. * One model of UPS is claimed to report "LINEV" as a 32-bit field.
  903. * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
  904. */
  905. static u32 __extract(u8 *report, unsigned offset, int n)
  906. {
  907. unsigned int idx = offset / 8;
  908. unsigned int bit_nr = 0;
  909. unsigned int bit_shift = offset % 8;
  910. int bits_to_copy = 8 - bit_shift;
  911. u32 value = 0;
  912. u32 mask = n < 32 ? (1U << n) - 1 : ~0U;
  913. while (n > 0) {
  914. value |= ((u32)report[idx] >> bit_shift) << bit_nr;
  915. n -= bits_to_copy;
  916. bit_nr += bits_to_copy;
  917. bits_to_copy = 8;
  918. bit_shift = 0;
  919. idx++;
  920. }
  921. return value & mask;
  922. }
  923. u32 hid_field_extract(const struct hid_device *hid, u8 *report,
  924. unsigned offset, unsigned n)
  925. {
  926. if (n > 32) {
  927. hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
  928. n, current->comm);
  929. n = 32;
  930. }
  931. return __extract(report, offset, n);
  932. }
  933. EXPORT_SYMBOL_GPL(hid_field_extract);
  934. /*
  935. * "implement" : set bits in a little endian bit stream.
  936. * Same concepts as "extract" (see comments above).
  937. * The data mangled in the bit stream remains in little endian
  938. * order the whole time. It make more sense to talk about
  939. * endianness of register values by considering a register
  940. * a "cached" copy of the little endian bit stream.
  941. */
  942. static void __implement(u8 *report, unsigned offset, int n, u32 value)
  943. {
  944. unsigned int idx = offset / 8;
  945. unsigned int bit_shift = offset % 8;
  946. int bits_to_set = 8 - bit_shift;
  947. while (n - bits_to_set >= 0) {
  948. report[idx] &= ~(0xff << bit_shift);
  949. report[idx] |= value << bit_shift;
  950. value >>= bits_to_set;
  951. n -= bits_to_set;
  952. bits_to_set = 8;
  953. bit_shift = 0;
  954. idx++;
  955. }
  956. /* last nibble */
  957. if (n) {
  958. u8 bit_mask = ((1U << n) - 1);
  959. report[idx] &= ~(bit_mask << bit_shift);
  960. report[idx] |= value << bit_shift;
  961. }
  962. }
  963. static void implement(const struct hid_device *hid, u8 *report,
  964. unsigned offset, unsigned n, u32 value)
  965. {
  966. if (unlikely(n > 32)) {
  967. hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
  968. __func__, n, current->comm);
  969. n = 32;
  970. } else if (n < 32) {
  971. u32 m = (1U << n) - 1;
  972. if (unlikely(value > m)) {
  973. hid_warn(hid,
  974. "%s() called with too large value %d (n: %d)! (%s)\n",
  975. __func__, value, n, current->comm);
  976. WARN_ON(1);
  977. value &= m;
  978. }
  979. }
  980. __implement(report, offset, n, value);
  981. }
  982. /*
  983. * Search an array for a value.
  984. */
  985. static int search(__s32 *array, __s32 value, unsigned n)
  986. {
  987. while (n--) {
  988. if (*array++ == value)
  989. return 0;
  990. }
  991. return -1;
  992. }
  993. /**
  994. * hid_match_report - check if driver's raw_event should be called
  995. *
  996. * @hid: hid device
  997. * @report_type: type to match against
  998. *
  999. * compare hid->driver->report_table->report_type to report->type
  1000. */
  1001. static int hid_match_report(struct hid_device *hid, struct hid_report *report)
  1002. {
  1003. const struct hid_report_id *id = hid->driver->report_table;
  1004. if (!id) /* NULL means all */
  1005. return 1;
  1006. for (; id->report_type != HID_TERMINATOR; id++)
  1007. if (id->report_type == HID_ANY_ID ||
  1008. id->report_type == report->type)
  1009. return 1;
  1010. return 0;
  1011. }
  1012. /**
  1013. * hid_match_usage - check if driver's event should be called
  1014. *
  1015. * @hid: hid device
  1016. * @usage: usage to match against
  1017. *
  1018. * compare hid->driver->usage_table->usage_{type,code} to
  1019. * usage->usage_{type,code}
  1020. */
  1021. static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
  1022. {
  1023. const struct hid_usage_id *id = hid->driver->usage_table;
  1024. if (!id) /* NULL means all */
  1025. return 1;
  1026. for (; id->usage_type != HID_ANY_ID - 1; id++)
  1027. if ((id->usage_hid == HID_ANY_ID ||
  1028. id->usage_hid == usage->hid) &&
  1029. (id->usage_type == HID_ANY_ID ||
  1030. id->usage_type == usage->type) &&
  1031. (id->usage_code == HID_ANY_ID ||
  1032. id->usage_code == usage->code))
  1033. return 1;
  1034. return 0;
  1035. }
  1036. static void hid_process_event(struct hid_device *hid, struct hid_field *field,
  1037. struct hid_usage *usage, __s32 value, int interrupt)
  1038. {
  1039. struct hid_driver *hdrv = hid->driver;
  1040. int ret;
  1041. if (!list_empty(&hid->debug_list))
  1042. hid_dump_input(hid, usage, value);
  1043. if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
  1044. ret = hdrv->event(hid, field, usage, value);
  1045. if (ret != 0) {
  1046. if (ret < 0)
  1047. hid_err(hid, "%s's event failed with %d\n",
  1048. hdrv->name, ret);
  1049. return;
  1050. }
  1051. }
  1052. if (hid->claimed & HID_CLAIMED_INPUT)
  1053. hidinput_hid_event(hid, field, usage, value);
  1054. if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
  1055. hid->hiddev_hid_event(hid, field, usage, value);
  1056. }
  1057. /*
  1058. * Analyse a received field, and fetch the data from it. The field
  1059. * content is stored for next report processing (we do differential
  1060. * reporting to the layer).
  1061. */
  1062. static void hid_input_field(struct hid_device *hid, struct hid_field *field,
  1063. __u8 *data, int interrupt)
  1064. {
  1065. unsigned n;
  1066. unsigned count = field->report_count;
  1067. unsigned offset = field->report_offset;
  1068. unsigned size = field->report_size;
  1069. __s32 min = field->logical_minimum;
  1070. __s32 max = field->logical_maximum;
  1071. __s32 *value;
  1072. value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
  1073. if (!value)
  1074. return;
  1075. for (n = 0; n < count; n++) {
  1076. value[n] = min < 0 ?
  1077. snto32(hid_field_extract(hid, data, offset + n * size,
  1078. size), size) :
  1079. hid_field_extract(hid, data, offset + n * size, size);
  1080. /* Ignore report if ErrorRollOver */
  1081. if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
  1082. value[n] >= min && value[n] <= max &&
  1083. value[n] - min < field->maxusage &&
  1084. field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
  1085. goto exit;
  1086. }
  1087. for (n = 0; n < count; n++) {
  1088. if (HID_MAIN_ITEM_VARIABLE & field->flags) {
  1089. hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
  1090. continue;
  1091. }
  1092. if (field->value[n] >= min && field->value[n] <= max
  1093. && field->value[n] - min < field->maxusage
  1094. && field->usage[field->value[n] - min].hid
  1095. && search(value, field->value[n], count))
  1096. hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
  1097. if (value[n] >= min && value[n] <= max
  1098. && value[n] - min < field->maxusage
  1099. && field->usage[value[n] - min].hid
  1100. && search(field->value, value[n], count))
  1101. hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
  1102. }
  1103. memcpy(field->value, value, count * sizeof(__s32));
  1104. exit:
  1105. kfree(value);
  1106. }
  1107. /*
  1108. * Output the field into the report.
  1109. */
  1110. static void hid_output_field(const struct hid_device *hid,
  1111. struct hid_field *field, __u8 *data)
  1112. {
  1113. unsigned count = field->report_count;
  1114. unsigned offset = field->report_offset;
  1115. unsigned size = field->report_size;
  1116. unsigned n;
  1117. for (n = 0; n < count; n++) {
  1118. if (field->logical_minimum < 0) /* signed values */
  1119. implement(hid, data, offset + n * size, size,
  1120. s32ton(field->value[n], size));
  1121. else /* unsigned values */
  1122. implement(hid, data, offset + n * size, size,
  1123. field->value[n]);
  1124. }
  1125. }
  1126. /*
  1127. * Create a report. 'data' has to be allocated using
  1128. * hid_alloc_report_buf() so that it has proper size.
  1129. */
  1130. void hid_output_report(struct hid_report *report, __u8 *data)
  1131. {
  1132. unsigned n;
  1133. if (report->id > 0)
  1134. *data++ = report->id;
  1135. memset(data, 0, ((report->size - 1) >> 3) + 1);
  1136. for (n = 0; n < report->maxfield; n++)
  1137. hid_output_field(report->device, report->field[n], data);
  1138. }
  1139. EXPORT_SYMBOL_GPL(hid_output_report);
  1140. /*
  1141. * Allocator for buffer that is going to be passed to hid_output_report()
  1142. */
  1143. u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
  1144. {
  1145. /*
  1146. * 7 extra bytes are necessary to achieve proper functionality
  1147. * of implement() working on 8 byte chunks
  1148. */
  1149. int len = hid_report_len(report) + 7;
  1150. return kmalloc(len, flags);
  1151. }
  1152. EXPORT_SYMBOL_GPL(hid_alloc_report_buf);
  1153. /*
  1154. * Set a field value. The report this field belongs to has to be
  1155. * created and transferred to the device, to set this value in the
  1156. * device.
  1157. */
  1158. int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
  1159. {
  1160. unsigned size;
  1161. if (!field)
  1162. return -1;
  1163. size = field->report_size;
  1164. hid_dump_input(field->report->device, field->usage + offset, value);
  1165. if (offset >= field->report_count) {
  1166. hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
  1167. offset, field->report_count);
  1168. return -1;
  1169. }
  1170. if (field->logical_minimum < 0) {
  1171. if (value != snto32(s32ton(value, size), size)) {
  1172. hid_err(field->report->device, "value %d is out of range\n", value);
  1173. return -1;
  1174. }
  1175. }
  1176. field->value[offset] = value;
  1177. return 0;
  1178. }
  1179. EXPORT_SYMBOL_GPL(hid_set_field);
  1180. static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
  1181. const u8 *data)
  1182. {
  1183. struct hid_report *report;
  1184. unsigned int n = 0; /* Normally report number is 0 */
  1185. /* Device uses numbered reports, data[0] is report number */
  1186. if (report_enum->numbered)
  1187. n = *data;
  1188. report = report_enum->report_id_hash[n];
  1189. if (report == NULL)
  1190. dbg_hid("undefined report_id %u received\n", n);
  1191. return report;
  1192. }
  1193. /*
  1194. * Implement a generic .request() callback, using .raw_request()
  1195. * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
  1196. */
  1197. void __hid_request(struct hid_device *hid, struct hid_report *report,
  1198. int reqtype)
  1199. {
  1200. char *buf;
  1201. int ret;
  1202. int len;
  1203. buf = hid_alloc_report_buf(report, GFP_KERNEL);
  1204. if (!buf)
  1205. return;
  1206. len = hid_report_len(report);
  1207. if (reqtype == HID_REQ_SET_REPORT)
  1208. hid_output_report(report, buf);
  1209. ret = hid->ll_driver->raw_request(hid, report->id, buf, len,
  1210. report->type, reqtype);
  1211. if (ret < 0) {
  1212. dbg_hid("unable to complete request: %d\n", ret);
  1213. goto out;
  1214. }
  1215. if (reqtype == HID_REQ_GET_REPORT)
  1216. hid_input_report(hid, report->type, buf, ret, 0);
  1217. out:
  1218. kfree(buf);
  1219. }
  1220. EXPORT_SYMBOL_GPL(__hid_request);
  1221. int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
  1222. int interrupt)
  1223. {
  1224. struct hid_report_enum *report_enum = hid->report_enum + type;
  1225. struct hid_report *report;
  1226. struct hid_driver *hdrv;
  1227. unsigned int a;
  1228. int rsize, csize = size;
  1229. u8 *cdata = data;
  1230. int ret = 0;
  1231. report = hid_get_report(report_enum, data);
  1232. if (!report)
  1233. goto out;
  1234. if (report_enum->numbered) {
  1235. cdata++;
  1236. csize--;
  1237. }
  1238. rsize = ((report->size - 1) >> 3) + 1;
  1239. if (rsize > HID_MAX_BUFFER_SIZE)
  1240. rsize = HID_MAX_BUFFER_SIZE;
  1241. if (csize < rsize) {
  1242. dbg_hid("report %d is too short, (%d < %d)\n", report->id,
  1243. csize, rsize);
  1244. memset(cdata + csize, 0, rsize - csize);
  1245. }
  1246. if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
  1247. hid->hiddev_report_event(hid, report);
  1248. if (hid->claimed & HID_CLAIMED_HIDRAW) {
  1249. ret = hidraw_report_event(hid, data, size);
  1250. if (ret)
  1251. goto out;
  1252. }
  1253. if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) {
  1254. for (a = 0; a < report->maxfield; a++)
  1255. hid_input_field(hid, report->field[a], cdata, interrupt);
  1256. hdrv = hid->driver;
  1257. if (hdrv && hdrv->report)
  1258. hdrv->report(hid, report);
  1259. }
  1260. if (hid->claimed & HID_CLAIMED_INPUT)
  1261. hidinput_report_event(hid, report);
  1262. out:
  1263. return ret;
  1264. }
  1265. EXPORT_SYMBOL_GPL(hid_report_raw_event);
  1266. /**
  1267. * hid_input_report - report data from lower layer (usb, bt...)
  1268. *
  1269. * @hid: hid device
  1270. * @type: HID report type (HID_*_REPORT)
  1271. * @data: report contents
  1272. * @size: size of data parameter
  1273. * @interrupt: distinguish between interrupt and control transfers
  1274. *
  1275. * This is data entry for lower layers.
  1276. */
  1277. int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
  1278. {
  1279. struct hid_report_enum *report_enum;
  1280. struct hid_driver *hdrv;
  1281. struct hid_report *report;
  1282. int ret = 0;
  1283. if (!hid)
  1284. return -ENODEV;
  1285. if (down_trylock(&hid->driver_input_lock))
  1286. return -EBUSY;
  1287. if (!hid->driver) {
  1288. ret = -ENODEV;
  1289. goto unlock;
  1290. }
  1291. report_enum = hid->report_enum + type;
  1292. hdrv = hid->driver;
  1293. if (!size) {
  1294. dbg_hid("empty report\n");
  1295. ret = -1;
  1296. goto unlock;
  1297. }
  1298. /* Avoid unnecessary overhead if debugfs is disabled */
  1299. if (!list_empty(&hid->debug_list))
  1300. hid_dump_report(hid, type, data, size);
  1301. report = hid_get_report(report_enum, data);
  1302. if (!report) {
  1303. ret = -1;
  1304. goto unlock;
  1305. }
  1306. if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
  1307. ret = hdrv->raw_event(hid, report, data, size);
  1308. if (ret < 0)
  1309. goto unlock;
  1310. }
  1311. ret = hid_report_raw_event(hid, type, data, size, interrupt);
  1312. unlock:
  1313. up(&hid->driver_input_lock);
  1314. return ret;
  1315. }
  1316. EXPORT_SYMBOL_GPL(hid_input_report);
  1317. static bool hid_match_one_id(struct hid_device *hdev,
  1318. const struct hid_device_id *id)
  1319. {
  1320. return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
  1321. (id->group == HID_GROUP_ANY || id->group == hdev->group) &&
  1322. (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
  1323. (id->product == HID_ANY_ID || id->product == hdev->product);
  1324. }
  1325. const struct hid_device_id *hid_match_id(struct hid_device *hdev,
  1326. const struct hid_device_id *id)
  1327. {
  1328. for (; id->bus; id++)
  1329. if (hid_match_one_id(hdev, id))
  1330. return id;
  1331. return NULL;
  1332. }
  1333. static const struct hid_device_id hid_hiddev_list[] = {
  1334. { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
  1335. { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
  1336. { }
  1337. };
  1338. static bool hid_hiddev(struct hid_device *hdev)
  1339. {
  1340. return !!hid_match_id(hdev, hid_hiddev_list);
  1341. }
  1342. static ssize_t
  1343. read_report_descriptor(struct file *filp, struct kobject *kobj,
  1344. struct bin_attribute *attr,
  1345. char *buf, loff_t off, size_t count)
  1346. {
  1347. struct device *dev = kobj_to_dev(kobj);
  1348. struct hid_device *hdev = to_hid_device(dev);
  1349. if (off >= hdev->rsize)
  1350. return 0;
  1351. if (off + count > hdev->rsize)
  1352. count = hdev->rsize - off;
  1353. memcpy(buf, hdev->rdesc + off, count);
  1354. return count;
  1355. }
  1356. static ssize_t
  1357. show_country(struct device *dev, struct device_attribute *attr,
  1358. char *buf)
  1359. {
  1360. struct hid_device *hdev = to_hid_device(dev);
  1361. return sprintf(buf, "%02x\n", hdev->country & 0xff);
  1362. }
  1363. static struct bin_attribute dev_bin_attr_report_desc = {
  1364. .attr = { .name = "report_descriptor", .mode = 0444 },
  1365. .read = read_report_descriptor,
  1366. .size = HID_MAX_DESCRIPTOR_SIZE,
  1367. };
  1368. static struct device_attribute dev_attr_country = {
  1369. .attr = { .name = "country", .mode = 0444 },
  1370. .show = show_country,
  1371. };
  1372. int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
  1373. {
  1374. static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
  1375. "Joystick", "Gamepad", "Keyboard", "Keypad",
  1376. "Multi-Axis Controller"
  1377. };
  1378. const char *type, *bus;
  1379. char buf[64] = "";
  1380. unsigned int i;
  1381. int len;
  1382. int ret;
  1383. if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
  1384. connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
  1385. if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
  1386. connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
  1387. if (hdev->bus != BUS_USB)
  1388. connect_mask &= ~HID_CONNECT_HIDDEV;
  1389. if (hid_hiddev(hdev))
  1390. connect_mask |= HID_CONNECT_HIDDEV_FORCE;
  1391. if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
  1392. connect_mask & HID_CONNECT_HIDINPUT_FORCE))
  1393. hdev->claimed |= HID_CLAIMED_INPUT;
  1394. if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
  1395. !hdev->hiddev_connect(hdev,
  1396. connect_mask & HID_CONNECT_HIDDEV_FORCE))
  1397. hdev->claimed |= HID_CLAIMED_HIDDEV;
  1398. if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
  1399. hdev->claimed |= HID_CLAIMED_HIDRAW;
  1400. if (connect_mask & HID_CONNECT_DRIVER)
  1401. hdev->claimed |= HID_CLAIMED_DRIVER;
  1402. /* Drivers with the ->raw_event callback set are not required to connect
  1403. * to any other listener. */
  1404. if (!hdev->claimed && !hdev->driver->raw_event) {
  1405. hid_err(hdev, "device has no listeners, quitting\n");
  1406. return -ENODEV;
  1407. }
  1408. if ((hdev->claimed & HID_CLAIMED_INPUT) &&
  1409. (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
  1410. hdev->ff_init(hdev);
  1411. len = 0;
  1412. if (hdev->claimed & HID_CLAIMED_INPUT)
  1413. len += sprintf(buf + len, "input");
  1414. if (hdev->claimed & HID_CLAIMED_HIDDEV)
  1415. len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
  1416. ((struct hiddev *)hdev->hiddev)->minor);
  1417. if (hdev->claimed & HID_CLAIMED_HIDRAW)
  1418. len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
  1419. ((struct hidraw *)hdev->hidraw)->minor);
  1420. type = "Device";
  1421. for (i = 0; i < hdev->maxcollection; i++) {
  1422. struct hid_collection *col = &hdev->collection[i];
  1423. if (col->type == HID_COLLECTION_APPLICATION &&
  1424. (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  1425. (col->usage & 0xffff) < ARRAY_SIZE(types)) {
  1426. type = types[col->usage & 0xffff];
  1427. break;
  1428. }
  1429. }
  1430. switch (hdev->bus) {
  1431. case BUS_USB:
  1432. bus = "USB";
  1433. break;
  1434. case BUS_BLUETOOTH:
  1435. bus = "BLUETOOTH";
  1436. break;
  1437. case BUS_I2C:
  1438. bus = "I2C";
  1439. break;
  1440. default:
  1441. bus = "<UNKNOWN>";
  1442. }
  1443. ret = device_create_file(&hdev->dev, &dev_attr_country);
  1444. if (ret)
  1445. hid_warn(hdev,
  1446. "can't create sysfs country code attribute err: %d\n", ret);
  1447. hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
  1448. buf, bus, hdev->version >> 8, hdev->version & 0xff,
  1449. type, hdev->name, hdev->phys);
  1450. return 0;
  1451. }
  1452. EXPORT_SYMBOL_GPL(hid_connect);
  1453. void hid_disconnect(struct hid_device *hdev)
  1454. {
  1455. device_remove_file(&hdev->dev, &dev_attr_country);
  1456. if (hdev->claimed & HID_CLAIMED_INPUT)
  1457. hidinput_disconnect(hdev);
  1458. if (hdev->claimed & HID_CLAIMED_HIDDEV)
  1459. hdev->hiddev_disconnect(hdev);
  1460. if (hdev->claimed & HID_CLAIMED_HIDRAW)
  1461. hidraw_disconnect(hdev);
  1462. hdev->claimed = 0;
  1463. }
  1464. EXPORT_SYMBOL_GPL(hid_disconnect);
  1465. /*
  1466. * A list of devices for which there is a specialized driver on HID bus.
  1467. *
  1468. * Please note that for multitouch devices (driven by hid-multitouch driver),
  1469. * there is a proper autodetection and autoloading in place (based on presence
  1470. * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
  1471. * as we are doing the right thing in hid_scan_usage().
  1472. *
  1473. * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
  1474. * physical is found inside a usage page of type sensor, hid-sensor-hub will be
  1475. * used as a driver. See hid_scan_report().
  1476. */
  1477. static const struct hid_device_id hid_have_special_driver[] = {
  1478. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
  1479. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
  1480. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
  1481. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
  1482. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
  1483. { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
  1484. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
  1485. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
  1486. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
  1487. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  1488. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  1489. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  1490. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  1491. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  1492. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  1493. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  1494. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  1495. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  1496. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  1497. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  1498. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
  1499. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
  1500. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
  1501. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
  1502. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
  1503. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
  1504. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  1505. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  1506. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  1507. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
  1508. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
  1509. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
  1510. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
  1511. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
  1512. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
  1513. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
  1514. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
  1515. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  1516. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  1517. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  1518. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  1519. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  1520. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  1521. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  1522. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  1523. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  1524. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  1525. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  1526. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  1527. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  1528. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  1529. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  1530. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  1531. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  1532. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  1533. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  1534. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  1535. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  1536. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
  1537. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
  1538. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
  1539. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  1540. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  1541. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  1542. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  1543. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  1544. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  1545. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  1546. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  1547. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  1548. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  1549. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  1550. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  1551. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
  1552. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
  1553. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
  1554. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI) },
  1555. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO) },
  1556. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS) },
  1557. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
  1558. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
  1559. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
  1560. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
  1561. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
  1562. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
  1563. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
  1564. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  1565. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  1566. { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD) },
  1567. { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD) },
  1568. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1) },
  1569. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2) },
  1570. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T100_KEYBOARD) },
  1571. { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
  1572. { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
  1573. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185BFM, 0x2208) },
  1574. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185PC, 0x5506) },
  1575. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2PC, 0x1850) },
  1576. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2BFM, 0x5500) },
  1577. { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
  1578. { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
  1579. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
  1580. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
  1581. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
  1582. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
  1583. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
  1584. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
  1585. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) },
  1586. { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K90) },
  1587. { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_SCIMITAR_PRO_RGB) },
  1588. { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
  1589. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
  1590. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
  1591. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
  1592. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
  1593. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
  1594. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
  1595. { HID_USB_DEVICE(USB_VENDOR_ID_DELCOM, USB_DEVICE_ID_DELCOM_VISUAL_IND) },
  1596. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
  1597. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
  1598. #if IS_ENABLED(CONFIG_HID_MAYFLASH)
  1599. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3) },
  1600. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR) },
  1601. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE1) },
  1602. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE2) },
  1603. #endif
  1604. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_WN) },
  1605. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_FA) },
  1606. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
  1607. { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRED) },
  1608. { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRELESS) },
  1609. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
  1610. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
  1611. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_ACCUTOUCH_2216) },
  1612. { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
  1613. { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
  1614. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
  1615. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
  1616. { HID_USB_DEVICE(USB_VENDOR_ID_GEMBIRD, USB_DEVICE_ID_GEMBIRD_JPD_DUALFORCE2) },
  1617. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
  1618. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
  1619. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
  1620. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
  1621. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
  1622. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
  1623. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
  1624. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
  1625. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
  1626. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
  1627. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
  1628. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
  1629. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
  1630. { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
  1631. { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_JESS_ZEN_AIO_KBD) },
  1632. { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
  1633. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
  1634. { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
  1635. { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
  1636. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
  1637. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_MANTICORE) },
  1638. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
  1639. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  1640. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  1641. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  1642. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2) },
  1643. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  1644. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_PENSKETCH_M912) },
  1645. { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
  1646. { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
  1647. #if IS_ENABLED(CONFIG_HID_LENOVO)
  1648. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
  1649. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) },
  1650. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) },
  1651. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) },
  1652. #endif
  1653. { HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MELFAS_MT) },
  1654. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
  1655. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
  1656. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
  1657. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
  1658. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
  1659. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_T651) },
  1660. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
  1661. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
  1662. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
  1663. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
  1664. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
  1665. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
  1666. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DUAL_ACTION) },
  1667. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
  1668. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
  1669. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
  1670. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
  1671. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G29_WHEEL) },
  1672. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL) },
  1673. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
  1674. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
  1675. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
  1676. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
  1677. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
  1678. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
  1679. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL) },
  1680. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
  1681. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
  1682. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
  1683. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
  1684. #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
  1685. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
  1686. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
  1687. #endif
  1688. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
  1689. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
  1690. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
  1691. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
  1692. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
  1693. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
  1694. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_LUXAFOR) },
  1695. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
  1696. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD) },
  1697. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
  1698. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
  1699. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
  1700. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE7K) },
  1701. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
  1702. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
  1703. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
  1704. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
  1705. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
  1706. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K) },
  1707. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600) },
  1708. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1) },
  1709. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER) },
  1710. { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
  1711. { HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
  1712. { HID_USB_DEVICE(USB_VENDOR_ID_NTI, USB_DEVICE_ID_USB_SUN) },
  1713. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
  1714. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
  1715. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
  1716. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
  1717. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
  1718. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
  1719. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
  1720. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
  1721. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
  1722. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
  1723. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
  1724. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
  1725. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
  1726. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
  1727. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
  1728. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
  1729. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
  1730. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
  1731. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
  1732. { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
  1733. { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
  1734. { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_6000) },
  1735. { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
  1736. { HID_USB_DEVICE(USB_VENDOR_ID_PLANTRONICS, HID_ANY_ID) },
  1737. { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
  1738. { HID_USB_DEVICE(USB_VENDOR_ID_RISO_KAGAKU, USB_DEVICE_ID_RI_KA_WEBMAIL) },
  1739. #if IS_ENABLED(CONFIG_HID_ROCCAT)
  1740. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
  1741. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
  1742. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKUFX) },
  1743. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
  1744. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
  1745. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
  1746. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
  1747. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEXTD) },
  1748. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
  1749. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
  1750. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
  1751. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
  1752. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK) },
  1753. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW) },
  1754. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO) },
  1755. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
  1756. #endif
  1757. #if IS_ENABLED(CONFIG_HID_SAITEK)
  1758. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
  1759. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7_OLD) },
  1760. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7) },
  1761. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT9) },
  1762. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7) },
  1763. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT5) },
  1764. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9) },
  1765. #endif
  1766. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  1767. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
  1768. { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
  1769. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE) },
  1770. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
  1771. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
  1772. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) },
  1773. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) },
  1774. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
  1775. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
  1776. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
  1777. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  1778. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  1779. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
  1780. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
  1781. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) },
  1782. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) },
  1783. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) },
  1784. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
  1785. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
  1786. { HID_USB_DEVICE(USB_VENDOR_ID_SINO_LITE, USB_DEVICE_ID_SINO_LITE_CONTROLLER) },
  1787. { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
  1788. { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
  1789. { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
  1790. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
  1791. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
  1792. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
  1793. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
  1794. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
  1795. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
  1796. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
  1797. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
  1798. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
  1799. { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
  1800. { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_PRO) },
  1801. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
  1802. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
  1803. { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
  1804. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
  1805. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
  1806. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
  1807. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
  1808. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
  1809. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
  1810. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
  1811. { HID_USB_DEVICE(USB_VENDOR_ID_THQ, USB_DEVICE_ID_THQ_PS3_UDRAW) },
  1812. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_YIYNOVA_TABLET) },
  1813. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UGEE_TABLET_81) },
  1814. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UGEE_TABLET_45) },
  1815. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3) },
  1816. { HID_USB_DEVICE(USB_VENDOR_ID_UGTIZER, USB_DEVICE_ID_UGTIZER_TABLET_GP0610) },
  1817. { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_TABLET_EX07S) },
  1818. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
  1819. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
  1820. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
  1821. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
  1822. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
  1823. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
  1824. { HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII) },
  1825. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
  1826. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
  1827. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
  1828. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
  1829. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
  1830. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
  1831. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
  1832. { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
  1833. { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
  1834. { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_THT_2P_ARCADE) },
  1835. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
  1836. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
  1837. { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
  1838. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
  1839. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
  1840. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
  1841. { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) },
  1842. { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
  1843. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
  1844. { }
  1845. };
  1846. struct hid_dynid {
  1847. struct list_head list;
  1848. struct hid_device_id id;
  1849. };
  1850. /**
  1851. * store_new_id - add a new HID device ID to this driver and re-probe devices
  1852. * @driver: target device driver
  1853. * @buf: buffer for scanning device ID data
  1854. * @count: input size
  1855. *
  1856. * Adds a new dynamic hid device ID to this driver,
  1857. * and causes the driver to probe for all devices again.
  1858. */
  1859. static ssize_t store_new_id(struct device_driver *drv, const char *buf,
  1860. size_t count)
  1861. {
  1862. struct hid_driver *hdrv = to_hid_driver(drv);
  1863. struct hid_dynid *dynid;
  1864. __u32 bus, vendor, product;
  1865. unsigned long driver_data = 0;
  1866. int ret;
  1867. ret = sscanf(buf, "%x %x %x %lx",
  1868. &bus, &vendor, &product, &driver_data);
  1869. if (ret < 3)
  1870. return -EINVAL;
  1871. dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
  1872. if (!dynid)
  1873. return -ENOMEM;
  1874. dynid->id.bus = bus;
  1875. dynid->id.group = HID_GROUP_ANY;
  1876. dynid->id.vendor = vendor;
  1877. dynid->id.product = product;
  1878. dynid->id.driver_data = driver_data;
  1879. spin_lock(&hdrv->dyn_lock);
  1880. list_add_tail(&dynid->list, &hdrv->dyn_list);
  1881. spin_unlock(&hdrv->dyn_lock);
  1882. ret = driver_attach(&hdrv->driver);
  1883. return ret ? : count;
  1884. }
  1885. static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
  1886. static void hid_free_dynids(struct hid_driver *hdrv)
  1887. {
  1888. struct hid_dynid *dynid, *n;
  1889. spin_lock(&hdrv->dyn_lock);
  1890. list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
  1891. list_del(&dynid->list);
  1892. kfree(dynid);
  1893. }
  1894. spin_unlock(&hdrv->dyn_lock);
  1895. }
  1896. static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
  1897. struct hid_driver *hdrv)
  1898. {
  1899. struct hid_dynid *dynid;
  1900. spin_lock(&hdrv->dyn_lock);
  1901. list_for_each_entry(dynid, &hdrv->dyn_list, list) {
  1902. if (hid_match_one_id(hdev, &dynid->id)) {
  1903. spin_unlock(&hdrv->dyn_lock);
  1904. return &dynid->id;
  1905. }
  1906. }
  1907. spin_unlock(&hdrv->dyn_lock);
  1908. return hid_match_id(hdev, hdrv->id_table);
  1909. }
  1910. static int hid_bus_match(struct device *dev, struct device_driver *drv)
  1911. {
  1912. struct hid_driver *hdrv = to_hid_driver(drv);
  1913. struct hid_device *hdev = to_hid_device(dev);
  1914. return hid_match_device(hdev, hdrv) != NULL;
  1915. }
  1916. static int hid_device_probe(struct device *dev)
  1917. {
  1918. struct hid_driver *hdrv = to_hid_driver(dev->driver);
  1919. struct hid_device *hdev = to_hid_device(dev);
  1920. const struct hid_device_id *id;
  1921. int ret = 0;
  1922. if (down_interruptible(&hdev->driver_lock))
  1923. return -EINTR;
  1924. if (down_interruptible(&hdev->driver_input_lock)) {
  1925. ret = -EINTR;
  1926. goto unlock_driver_lock;
  1927. }
  1928. hdev->io_started = false;
  1929. if (!hdev->driver) {
  1930. id = hid_match_device(hdev, hdrv);
  1931. if (id == NULL) {
  1932. ret = -ENODEV;
  1933. goto unlock;
  1934. }
  1935. hdev->driver = hdrv;
  1936. if (hdrv->probe) {
  1937. ret = hdrv->probe(hdev, id);
  1938. } else { /* default probe */
  1939. ret = hid_open_report(hdev);
  1940. if (!ret)
  1941. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1942. }
  1943. if (ret) {
  1944. hid_close_report(hdev);
  1945. hdev->driver = NULL;
  1946. }
  1947. }
  1948. unlock:
  1949. if (!hdev->io_started)
  1950. up(&hdev->driver_input_lock);
  1951. unlock_driver_lock:
  1952. up(&hdev->driver_lock);
  1953. return ret;
  1954. }
  1955. static int hid_device_remove(struct device *dev)
  1956. {
  1957. struct hid_device *hdev = to_hid_device(dev);
  1958. struct hid_driver *hdrv;
  1959. int ret = 0;
  1960. if (down_interruptible(&hdev->driver_lock))
  1961. return -EINTR;
  1962. if (down_interruptible(&hdev->driver_input_lock)) {
  1963. ret = -EINTR;
  1964. goto unlock_driver_lock;
  1965. }
  1966. hdev->io_started = false;
  1967. hdrv = hdev->driver;
  1968. if (hdrv) {
  1969. if (hdrv->remove)
  1970. hdrv->remove(hdev);
  1971. else /* default remove */
  1972. hid_hw_stop(hdev);
  1973. hid_close_report(hdev);
  1974. hdev->driver = NULL;
  1975. }
  1976. if (!hdev->io_started)
  1977. up(&hdev->driver_input_lock);
  1978. unlock_driver_lock:
  1979. up(&hdev->driver_lock);
  1980. return ret;
  1981. }
  1982. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  1983. char *buf)
  1984. {
  1985. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1986. return scnprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
  1987. hdev->bus, hdev->group, hdev->vendor, hdev->product);
  1988. }
  1989. static DEVICE_ATTR_RO(modalias);
  1990. static struct attribute *hid_dev_attrs[] = {
  1991. &dev_attr_modalias.attr,
  1992. NULL,
  1993. };
  1994. static struct bin_attribute *hid_dev_bin_attrs[] = {
  1995. &dev_bin_attr_report_desc,
  1996. NULL
  1997. };
  1998. static const struct attribute_group hid_dev_group = {
  1999. .attrs = hid_dev_attrs,
  2000. .bin_attrs = hid_dev_bin_attrs,
  2001. };
  2002. __ATTRIBUTE_GROUPS(hid_dev);
  2003. static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
  2004. {
  2005. struct hid_device *hdev = to_hid_device(dev);
  2006. if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
  2007. hdev->bus, hdev->vendor, hdev->product))
  2008. return -ENOMEM;
  2009. if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
  2010. return -ENOMEM;
  2011. if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
  2012. return -ENOMEM;
  2013. if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
  2014. return -ENOMEM;
  2015. if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
  2016. hdev->bus, hdev->group, hdev->vendor, hdev->product))
  2017. return -ENOMEM;
  2018. return 0;
  2019. }
  2020. static struct bus_type hid_bus_type = {
  2021. .name = "hid",
  2022. .dev_groups = hid_dev_groups,
  2023. .match = hid_bus_match,
  2024. .probe = hid_device_probe,
  2025. .remove = hid_device_remove,
  2026. .uevent = hid_uevent,
  2027. };
  2028. /* a list of devices that shouldn't be handled by HID core at all */
  2029. static const struct hid_device_id hid_ignore_list[] = {
  2030. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
  2031. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
  2032. { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
  2033. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
  2034. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
  2035. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
  2036. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
  2037. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
  2038. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
  2039. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
  2040. { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
  2041. { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
  2042. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
  2043. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
  2044. { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
  2045. { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
  2046. { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
  2047. { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
  2048. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
  2049. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) },
  2050. { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
  2051. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
  2052. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
  2053. { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
  2054. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
  2055. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
  2056. { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, 0x0400) },
  2057. { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, 0x0401) },
  2058. { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
  2059. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
  2060. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
  2061. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
  2062. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
  2063. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
  2064. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
  2065. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
  2066. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
  2067. { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
  2068. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
  2069. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
  2070. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
  2071. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
  2072. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
  2073. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
  2074. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
  2075. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
  2076. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
  2077. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
  2078. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
  2079. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
  2080. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
  2081. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
  2082. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
  2083. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
  2084. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
  2085. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
  2086. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
  2087. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
  2088. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
  2089. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
  2090. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
  2091. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
  2092. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
  2093. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
  2094. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
  2095. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
  2096. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
  2097. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
  2098. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
  2099. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
  2100. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
  2101. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
  2102. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
  2103. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
  2104. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
  2105. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
  2106. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
  2107. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
  2108. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
  2109. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
  2110. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
  2111. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
  2112. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
  2113. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
  2114. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
  2115. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
  2116. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
  2117. { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
  2118. { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) },
  2119. { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) },
  2120. { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_GN9350E) },
  2121. { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
  2122. { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
  2123. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
  2124. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
  2125. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
  2126. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
  2127. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
  2128. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
  2129. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
  2130. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
  2131. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
  2132. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
  2133. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
  2134. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
  2135. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
  2136. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
  2137. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
  2138. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
  2139. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
  2140. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
  2141. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
  2142. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
  2143. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
  2144. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
  2145. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
  2146. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
  2147. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
  2148. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
  2149. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
  2150. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
  2151. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
  2152. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
  2153. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
  2154. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
  2155. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
  2156. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
  2157. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
  2158. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
  2159. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
  2160. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
  2161. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
  2162. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICK16F1454) },
  2163. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICK16F1454_V2) },
  2164. { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
  2165. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
  2166. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
  2167. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
  2168. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
  2169. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
  2170. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
  2171. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
  2172. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
  2173. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
  2174. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
  2175. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
  2176. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
  2177. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
  2178. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
  2179. { HID_USB_DEVICE(USB_VENDOR_ID_PETZL, USB_DEVICE_ID_PETZL_HEADLAMP) },
  2180. { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
  2181. { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
  2182. #if IS_ENABLED(CONFIG_MOUSE_SYNAPTICS_USB)
  2183. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
  2184. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
  2185. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
  2186. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
  2187. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
  2188. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
  2189. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
  2190. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
  2191. #endif
  2192. { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
  2193. { }
  2194. };
  2195. /**
  2196. * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
  2197. *
  2198. * There are composite devices for which we want to ignore only a certain
  2199. * interface. This is a list of devices for which only the mouse interface will
  2200. * be ignored. This allows a dedicated driver to take care of the interface.
  2201. */
  2202. static const struct hid_device_id hid_mouse_ignore_list[] = {
  2203. /* appletouch driver */
  2204. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  2205. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  2206. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  2207. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  2208. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  2209. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  2210. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  2211. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  2212. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  2213. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  2214. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  2215. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  2216. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  2217. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  2218. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  2219. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  2220. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  2221. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  2222. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  2223. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  2224. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  2225. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  2226. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  2227. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  2228. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  2229. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  2230. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  2231. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  2232. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  2233. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  2234. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  2235. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  2236. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  2237. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  2238. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  2239. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  2240. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  2241. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  2242. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  2243. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  2244. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  2245. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  2246. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  2247. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  2248. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  2249. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  2250. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  2251. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
  2252. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
  2253. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
  2254. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI) },
  2255. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO) },
  2256. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS) },
  2257. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  2258. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  2259. { }
  2260. };
  2261. bool hid_ignore(struct hid_device *hdev)
  2262. {
  2263. if (hdev->quirks & HID_QUIRK_NO_IGNORE)
  2264. return false;
  2265. if (hdev->quirks & HID_QUIRK_IGNORE)
  2266. return true;
  2267. switch (hdev->vendor) {
  2268. case USB_VENDOR_ID_CODEMERCS:
  2269. /* ignore all Code Mercenaries IOWarrior devices */
  2270. if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
  2271. hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
  2272. return true;
  2273. break;
  2274. case USB_VENDOR_ID_LOGITECH:
  2275. if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
  2276. hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
  2277. return true;
  2278. /*
  2279. * The Keene FM transmitter USB device has the same USB ID as
  2280. * the Logitech AudioHub Speaker, but it should ignore the hid.
  2281. * Check if the name is that of the Keene device.
  2282. * For reference: the name of the AudioHub is
  2283. * "HOLTEK AudioHub Speaker".
  2284. */
  2285. if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
  2286. !strcmp(hdev->name, "HOLTEK B-LINK USB Audio "))
  2287. return true;
  2288. break;
  2289. case USB_VENDOR_ID_SOUNDGRAPH:
  2290. if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
  2291. hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
  2292. return true;
  2293. break;
  2294. case USB_VENDOR_ID_HANWANG:
  2295. if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
  2296. hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
  2297. return true;
  2298. break;
  2299. case USB_VENDOR_ID_JESS:
  2300. if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
  2301. hdev->type == HID_TYPE_USBNONE)
  2302. return true;
  2303. break;
  2304. case USB_VENDOR_ID_VELLEMAN:
  2305. /* These are not HID devices. They are handled by comedi. */
  2306. if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
  2307. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
  2308. (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
  2309. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
  2310. return true;
  2311. break;
  2312. case USB_VENDOR_ID_ATMEL_V_USB:
  2313. /* Masterkit MA901 usb radio based on Atmel tiny85 chip and
  2314. * it has the same USB ID as many Atmel V-USB devices. This
  2315. * usb radio is handled by radio-ma901.c driver so we want
  2316. * ignore the hid. Check the name, bus, product and ignore
  2317. * if we have MA901 usb radio.
  2318. */
  2319. if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
  2320. hdev->bus == BUS_USB &&
  2321. strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
  2322. return true;
  2323. break;
  2324. }
  2325. if (hdev->type == HID_TYPE_USBMOUSE &&
  2326. hid_match_id(hdev, hid_mouse_ignore_list))
  2327. return true;
  2328. return !!hid_match_id(hdev, hid_ignore_list);
  2329. }
  2330. EXPORT_SYMBOL_GPL(hid_ignore);
  2331. int hid_add_device(struct hid_device *hdev)
  2332. {
  2333. static atomic_t id = ATOMIC_INIT(0);
  2334. int ret;
  2335. if (WARN_ON(hdev->status & HID_STAT_ADDED))
  2336. return -EBUSY;
  2337. /* we need to kill them here, otherwise they will stay allocated to
  2338. * wait for coming driver */
  2339. if (hid_ignore(hdev))
  2340. return -ENODEV;
  2341. /*
  2342. * Check for the mandatory transport channel.
  2343. */
  2344. if (!hdev->ll_driver->raw_request) {
  2345. hid_err(hdev, "transport driver missing .raw_request()\n");
  2346. return -EINVAL;
  2347. }
  2348. /*
  2349. * Read the device report descriptor once and use as template
  2350. * for the driver-specific modifications.
  2351. */
  2352. ret = hdev->ll_driver->parse(hdev);
  2353. if (ret)
  2354. return ret;
  2355. if (!hdev->dev_rdesc)
  2356. return -ENODEV;
  2357. /*
  2358. * Scan generic devices for group information
  2359. */
  2360. if (hid_ignore_special_drivers) {
  2361. hdev->group = HID_GROUP_GENERIC;
  2362. } else if (!hdev->group &&
  2363. !hid_match_id(hdev, hid_have_special_driver)) {
  2364. ret = hid_scan_report(hdev);
  2365. if (ret)
  2366. hid_warn(hdev, "bad device descriptor (%d)\n", ret);
  2367. }
  2368. /* XXX hack, any other cleaner solution after the driver core
  2369. * is converted to allow more than 20 bytes as the device name? */
  2370. dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
  2371. hdev->vendor, hdev->product, atomic_inc_return(&id));
  2372. hid_debug_register(hdev, dev_name(&hdev->dev));
  2373. ret = device_add(&hdev->dev);
  2374. if (!ret)
  2375. hdev->status |= HID_STAT_ADDED;
  2376. else
  2377. hid_debug_unregister(hdev);
  2378. return ret;
  2379. }
  2380. EXPORT_SYMBOL_GPL(hid_add_device);
  2381. /**
  2382. * hid_allocate_device - allocate new hid device descriptor
  2383. *
  2384. * Allocate and initialize hid device, so that hid_destroy_device might be
  2385. * used to free it.
  2386. *
  2387. * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
  2388. * error value.
  2389. */
  2390. struct hid_device *hid_allocate_device(void)
  2391. {
  2392. struct hid_device *hdev;
  2393. int ret = -ENOMEM;
  2394. hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
  2395. if (hdev == NULL)
  2396. return ERR_PTR(ret);
  2397. device_initialize(&hdev->dev);
  2398. hdev->dev.release = hid_device_release;
  2399. hdev->dev.bus = &hid_bus_type;
  2400. device_enable_async_suspend(&hdev->dev);
  2401. hid_close_report(hdev);
  2402. init_waitqueue_head(&hdev->debug_wait);
  2403. INIT_LIST_HEAD(&hdev->debug_list);
  2404. spin_lock_init(&hdev->debug_list_lock);
  2405. sema_init(&hdev->driver_lock, 1);
  2406. sema_init(&hdev->driver_input_lock, 1);
  2407. return hdev;
  2408. }
  2409. EXPORT_SYMBOL_GPL(hid_allocate_device);
  2410. static void hid_remove_device(struct hid_device *hdev)
  2411. {
  2412. if (hdev->status & HID_STAT_ADDED) {
  2413. device_del(&hdev->dev);
  2414. hid_debug_unregister(hdev);
  2415. hdev->status &= ~HID_STAT_ADDED;
  2416. }
  2417. kfree(hdev->dev_rdesc);
  2418. hdev->dev_rdesc = NULL;
  2419. hdev->dev_rsize = 0;
  2420. }
  2421. /**
  2422. * hid_destroy_device - free previously allocated device
  2423. *
  2424. * @hdev: hid device
  2425. *
  2426. * If you allocate hid_device through hid_allocate_device, you should ever
  2427. * free by this function.
  2428. */
  2429. void hid_destroy_device(struct hid_device *hdev)
  2430. {
  2431. hid_remove_device(hdev);
  2432. put_device(&hdev->dev);
  2433. }
  2434. EXPORT_SYMBOL_GPL(hid_destroy_device);
  2435. int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
  2436. const char *mod_name)
  2437. {
  2438. int ret;
  2439. hdrv->driver.name = hdrv->name;
  2440. hdrv->driver.bus = &hid_bus_type;
  2441. hdrv->driver.owner = owner;
  2442. hdrv->driver.mod_name = mod_name;
  2443. INIT_LIST_HEAD(&hdrv->dyn_list);
  2444. spin_lock_init(&hdrv->dyn_lock);
  2445. ret = driver_register(&hdrv->driver);
  2446. if (ret)
  2447. return ret;
  2448. ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
  2449. if (ret)
  2450. driver_unregister(&hdrv->driver);
  2451. return ret;
  2452. }
  2453. EXPORT_SYMBOL_GPL(__hid_register_driver);
  2454. void hid_unregister_driver(struct hid_driver *hdrv)
  2455. {
  2456. driver_remove_file(&hdrv->driver, &driver_attr_new_id);
  2457. driver_unregister(&hdrv->driver);
  2458. hid_free_dynids(hdrv);
  2459. }
  2460. EXPORT_SYMBOL_GPL(hid_unregister_driver);
  2461. int hid_check_keys_pressed(struct hid_device *hid)
  2462. {
  2463. struct hid_input *hidinput;
  2464. int i;
  2465. if (!(hid->claimed & HID_CLAIMED_INPUT))
  2466. return 0;
  2467. list_for_each_entry(hidinput, &hid->inputs, list) {
  2468. for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
  2469. if (hidinput->input->key[i])
  2470. return 1;
  2471. }
  2472. return 0;
  2473. }
  2474. EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
  2475. static int __init hid_init(void)
  2476. {
  2477. int ret;
  2478. if (hid_debug)
  2479. pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
  2480. "debugfs is now used for inspecting the device (report descriptor, reports)\n");
  2481. ret = bus_register(&hid_bus_type);
  2482. if (ret) {
  2483. pr_err("can't register hid bus\n");
  2484. goto err;
  2485. }
  2486. ret = hidraw_init();
  2487. if (ret)
  2488. goto err_bus;
  2489. hid_debug_init();
  2490. return 0;
  2491. err_bus:
  2492. bus_unregister(&hid_bus_type);
  2493. err:
  2494. return ret;
  2495. }
  2496. static void __exit hid_exit(void)
  2497. {
  2498. hid_debug_exit();
  2499. hidraw_exit();
  2500. bus_unregister(&hid_bus_type);
  2501. }
  2502. module_init(hid_init);
  2503. module_exit(hid_exit);
  2504. MODULE_AUTHOR("Andreas Gal");
  2505. MODULE_AUTHOR("Vojtech Pavlik");
  2506. MODULE_AUTHOR("Jiri Kosina");
  2507. MODULE_LICENSE("GPL");