hid-core.c 72 KB

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