hid-core.c 83 KB

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