hid-core.c 86 KB

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