hid-core.c 88 KB

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