hid-core.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473
  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_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
  1441. { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
  1442. { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
  1443. { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
  1444. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
  1445. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
  1446. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
  1447. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
  1448. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
  1449. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
  1450. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
  1451. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
  1452. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
  1453. { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
  1454. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
  1455. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
  1456. { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
  1457. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
  1458. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
  1459. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
  1460. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
  1461. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
  1462. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
  1463. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
  1464. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
  1465. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
  1466. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
  1467. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
  1468. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
  1469. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
  1470. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
  1471. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
  1472. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
  1473. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
  1474. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
  1475. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
  1476. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
  1477. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
  1478. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
  1479. { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
  1480. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
  1481. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
  1482. { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
  1483. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
  1484. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
  1485. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
  1486. { }
  1487. };
  1488. struct hid_dynid {
  1489. struct list_head list;
  1490. struct hid_device_id id;
  1491. };
  1492. /**
  1493. * store_new_id - add a new HID device ID to this driver and re-probe devices
  1494. * @driver: target device driver
  1495. * @buf: buffer for scanning device ID data
  1496. * @count: input size
  1497. *
  1498. * Adds a new dynamic hid device ID to this driver,
  1499. * and causes the driver to probe for all devices again.
  1500. */
  1501. static ssize_t store_new_id(struct device_driver *drv, const char *buf,
  1502. size_t count)
  1503. {
  1504. struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
  1505. struct hid_dynid *dynid;
  1506. __u32 bus, vendor, product;
  1507. unsigned long driver_data = 0;
  1508. int ret;
  1509. ret = sscanf(buf, "%x %x %x %lx",
  1510. &bus, &vendor, &product, &driver_data);
  1511. if (ret < 3)
  1512. return -EINVAL;
  1513. dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
  1514. if (!dynid)
  1515. return -ENOMEM;
  1516. dynid->id.bus = bus;
  1517. dynid->id.group = HID_GROUP_ANY;
  1518. dynid->id.vendor = vendor;
  1519. dynid->id.product = product;
  1520. dynid->id.driver_data = driver_data;
  1521. spin_lock(&hdrv->dyn_lock);
  1522. list_add_tail(&dynid->list, &hdrv->dyn_list);
  1523. spin_unlock(&hdrv->dyn_lock);
  1524. ret = driver_attach(&hdrv->driver);
  1525. return ret ? : count;
  1526. }
  1527. static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
  1528. static void hid_free_dynids(struct hid_driver *hdrv)
  1529. {
  1530. struct hid_dynid *dynid, *n;
  1531. spin_lock(&hdrv->dyn_lock);
  1532. list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
  1533. list_del(&dynid->list);
  1534. kfree(dynid);
  1535. }
  1536. spin_unlock(&hdrv->dyn_lock);
  1537. }
  1538. static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
  1539. struct hid_driver *hdrv)
  1540. {
  1541. struct hid_dynid *dynid;
  1542. spin_lock(&hdrv->dyn_lock);
  1543. list_for_each_entry(dynid, &hdrv->dyn_list, list) {
  1544. if (hid_match_one_id(hdev, &dynid->id)) {
  1545. spin_unlock(&hdrv->dyn_lock);
  1546. return &dynid->id;
  1547. }
  1548. }
  1549. spin_unlock(&hdrv->dyn_lock);
  1550. return hid_match_id(hdev, hdrv->id_table);
  1551. }
  1552. static int hid_bus_match(struct device *dev, struct device_driver *drv)
  1553. {
  1554. struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
  1555. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1556. return hid_match_device(hdev, hdrv) != NULL;
  1557. }
  1558. static int hid_device_probe(struct device *dev)
  1559. {
  1560. struct hid_driver *hdrv = container_of(dev->driver,
  1561. struct hid_driver, driver);
  1562. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1563. const struct hid_device_id *id;
  1564. int ret = 0;
  1565. if (down_interruptible(&hdev->driver_lock))
  1566. return -EINTR;
  1567. if (down_interruptible(&hdev->driver_input_lock)) {
  1568. ret = -EINTR;
  1569. goto unlock_driver_lock;
  1570. }
  1571. hdev->io_started = false;
  1572. if (!hdev->driver) {
  1573. id = hid_match_device(hdev, hdrv);
  1574. if (id == NULL) {
  1575. ret = -ENODEV;
  1576. goto unlock;
  1577. }
  1578. hdev->driver = hdrv;
  1579. if (hdrv->probe) {
  1580. ret = hdrv->probe(hdev, id);
  1581. } else { /* default probe */
  1582. ret = hid_open_report(hdev);
  1583. if (!ret)
  1584. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1585. }
  1586. if (ret) {
  1587. hid_close_report(hdev);
  1588. hdev->driver = NULL;
  1589. }
  1590. }
  1591. unlock:
  1592. if (!hdev->io_started)
  1593. up(&hdev->driver_input_lock);
  1594. unlock_driver_lock:
  1595. up(&hdev->driver_lock);
  1596. return ret;
  1597. }
  1598. static int hid_device_remove(struct device *dev)
  1599. {
  1600. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1601. struct hid_driver *hdrv;
  1602. int ret = 0;
  1603. if (down_interruptible(&hdev->driver_lock))
  1604. return -EINTR;
  1605. if (down_interruptible(&hdev->driver_input_lock)) {
  1606. ret = -EINTR;
  1607. goto unlock_driver_lock;
  1608. }
  1609. hdev->io_started = false;
  1610. hdrv = hdev->driver;
  1611. if (hdrv) {
  1612. if (hdrv->remove)
  1613. hdrv->remove(hdev);
  1614. else /* default remove */
  1615. hid_hw_stop(hdev);
  1616. hid_close_report(hdev);
  1617. hdev->driver = NULL;
  1618. }
  1619. if (!hdev->io_started)
  1620. up(&hdev->driver_input_lock);
  1621. unlock_driver_lock:
  1622. up(&hdev->driver_lock);
  1623. return ret;
  1624. }
  1625. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  1626. char *buf)
  1627. {
  1628. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1629. int len;
  1630. len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
  1631. hdev->bus, hdev->group, hdev->vendor, hdev->product);
  1632. return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
  1633. }
  1634. static struct device_attribute hid_dev_attrs[] = {
  1635. __ATTR_RO(modalias),
  1636. __ATTR_NULL,
  1637. };
  1638. static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
  1639. {
  1640. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1641. if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
  1642. hdev->bus, hdev->vendor, hdev->product))
  1643. return -ENOMEM;
  1644. if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
  1645. return -ENOMEM;
  1646. if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
  1647. return -ENOMEM;
  1648. if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
  1649. return -ENOMEM;
  1650. if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
  1651. hdev->bus, hdev->group, hdev->vendor, hdev->product))
  1652. return -ENOMEM;
  1653. return 0;
  1654. }
  1655. static struct bus_type hid_bus_type = {
  1656. .name = "hid",
  1657. .dev_attrs = hid_dev_attrs,
  1658. .match = hid_bus_match,
  1659. .probe = hid_device_probe,
  1660. .remove = hid_device_remove,
  1661. .uevent = hid_uevent,
  1662. };
  1663. /* a list of devices that shouldn't be handled by HID core at all */
  1664. static const struct hid_device_id hid_ignore_list[] = {
  1665. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
  1666. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
  1667. { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
  1668. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
  1669. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
  1670. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
  1671. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
  1672. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
  1673. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
  1674. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
  1675. { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
  1676. { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
  1677. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
  1678. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
  1679. { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
  1680. { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
  1681. { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
  1682. { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
  1683. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
  1684. { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
  1685. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
  1686. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
  1687. { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
  1688. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
  1689. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
  1690. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
  1691. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
  1692. { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
  1693. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
  1694. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
  1695. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
  1696. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
  1697. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
  1698. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
  1699. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
  1700. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
  1701. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
  1702. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
  1703. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
  1704. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
  1705. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
  1706. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
  1707. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
  1708. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
  1709. { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
  1710. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
  1711. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
  1712. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
  1713. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
  1714. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
  1715. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
  1716. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
  1717. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
  1718. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
  1719. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
  1720. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
  1721. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
  1722. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
  1723. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
  1724. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
  1725. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
  1726. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
  1727. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
  1728. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
  1729. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
  1730. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
  1731. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
  1732. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
  1733. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
  1734. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
  1735. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
  1736. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
  1737. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
  1738. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
  1739. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
  1740. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
  1741. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
  1742. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
  1743. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
  1744. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
  1745. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
  1746. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
  1747. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
  1748. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
  1749. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
  1750. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
  1751. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
  1752. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
  1753. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
  1754. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
  1755. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
  1756. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
  1757. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
  1758. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
  1759. { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
  1760. { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
  1761. { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
  1762. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
  1763. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
  1764. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
  1765. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
  1766. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
  1767. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
  1768. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
  1769. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
  1770. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
  1771. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
  1772. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
  1773. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
  1774. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
  1775. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
  1776. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
  1777. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
  1778. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
  1779. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
  1780. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
  1781. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
  1782. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
  1783. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
  1784. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
  1785. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
  1786. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
  1787. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
  1788. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
  1789. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
  1790. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
  1791. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
  1792. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
  1793. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
  1794. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
  1795. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
  1796. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
  1797. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
  1798. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
  1799. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
  1800. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
  1801. { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
  1802. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
  1803. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
  1804. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
  1805. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
  1806. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
  1807. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
  1808. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
  1809. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
  1810. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
  1811. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
  1812. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
  1813. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
  1814. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
  1815. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
  1816. { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
  1817. { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
  1818. #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
  1819. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
  1820. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
  1821. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
  1822. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
  1823. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
  1824. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
  1825. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
  1826. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
  1827. #endif
  1828. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
  1829. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
  1830. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
  1831. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
  1832. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
  1833. { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
  1834. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
  1835. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
  1836. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
  1837. { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
  1838. { }
  1839. };
  1840. /**
  1841. * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
  1842. *
  1843. * There are composite devices for which we want to ignore only a certain
  1844. * interface. This is a list of devices for which only the mouse interface will
  1845. * be ignored. This allows a dedicated driver to take care of the interface.
  1846. */
  1847. static const struct hid_device_id hid_mouse_ignore_list[] = {
  1848. /* appletouch driver */
  1849. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  1850. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  1851. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  1852. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  1853. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  1854. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  1855. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  1856. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  1857. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  1858. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  1859. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  1860. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  1861. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  1862. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  1863. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  1864. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  1865. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  1866. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  1867. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  1868. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  1869. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  1870. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  1871. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  1872. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  1873. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  1874. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  1875. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  1876. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  1877. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  1878. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  1879. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  1880. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  1881. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  1882. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  1883. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  1884. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  1885. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  1886. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  1887. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  1888. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  1889. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  1890. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  1891. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  1892. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  1893. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  1894. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  1895. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  1896. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  1897. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  1898. { }
  1899. };
  1900. bool hid_ignore(struct hid_device *hdev)
  1901. {
  1902. if (hdev->quirks & HID_QUIRK_NO_IGNORE)
  1903. return false;
  1904. if (hdev->quirks & HID_QUIRK_IGNORE)
  1905. return true;
  1906. switch (hdev->vendor) {
  1907. case USB_VENDOR_ID_CODEMERCS:
  1908. /* ignore all Code Mercenaries IOWarrior devices */
  1909. if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
  1910. hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
  1911. return true;
  1912. break;
  1913. case USB_VENDOR_ID_LOGITECH:
  1914. if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
  1915. hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
  1916. return true;
  1917. /*
  1918. * The Keene FM transmitter USB device has the same USB ID as
  1919. * the Logitech AudioHub Speaker, but it should ignore the hid.
  1920. * Check if the name is that of the Keene device.
  1921. * For reference: the name of the AudioHub is
  1922. * "HOLTEK AudioHub Speaker".
  1923. */
  1924. if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
  1925. !strcmp(hdev->name, "HOLTEK B-LINK USB Audio "))
  1926. return true;
  1927. break;
  1928. case USB_VENDOR_ID_SOUNDGRAPH:
  1929. if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
  1930. hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
  1931. return true;
  1932. break;
  1933. case USB_VENDOR_ID_HANWANG:
  1934. if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
  1935. hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
  1936. return true;
  1937. break;
  1938. case USB_VENDOR_ID_JESS:
  1939. if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
  1940. hdev->type == HID_TYPE_USBNONE)
  1941. return true;
  1942. break;
  1943. case USB_VENDOR_ID_DWAV:
  1944. /* These are handled by usbtouchscreen. hdev->type is probably
  1945. * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match
  1946. * usbtouchscreen. */
  1947. if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER ||
  1948. hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) &&
  1949. hdev->type != HID_TYPE_USBMOUSE)
  1950. return true;
  1951. break;
  1952. case USB_VENDOR_ID_VELLEMAN:
  1953. /* These are not HID devices. They are handled by comedi. */
  1954. if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
  1955. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
  1956. (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
  1957. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
  1958. return true;
  1959. break;
  1960. case USB_VENDOR_ID_ATMEL_V_USB:
  1961. /* Masterkit MA901 usb radio based on Atmel tiny85 chip and
  1962. * it has the same USB ID as many Atmel V-USB devices. This
  1963. * usb radio is handled by radio-ma901.c driver so we want
  1964. * ignore the hid. Check the name, bus, product and ignore
  1965. * if we have MA901 usb radio.
  1966. */
  1967. if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
  1968. hdev->bus == BUS_USB &&
  1969. strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
  1970. return true;
  1971. break;
  1972. }
  1973. if (hdev->type == HID_TYPE_USBMOUSE &&
  1974. hid_match_id(hdev, hid_mouse_ignore_list))
  1975. return true;
  1976. return !!hid_match_id(hdev, hid_ignore_list);
  1977. }
  1978. EXPORT_SYMBOL_GPL(hid_ignore);
  1979. int hid_add_device(struct hid_device *hdev)
  1980. {
  1981. static atomic_t id = ATOMIC_INIT(0);
  1982. int ret;
  1983. if (WARN_ON(hdev->status & HID_STAT_ADDED))
  1984. return -EBUSY;
  1985. /* we need to kill them here, otherwise they will stay allocated to
  1986. * wait for coming driver */
  1987. if (hid_ignore(hdev))
  1988. return -ENODEV;
  1989. /*
  1990. * Read the device report descriptor once and use as template
  1991. * for the driver-specific modifications.
  1992. */
  1993. ret = hdev->ll_driver->parse(hdev);
  1994. if (ret)
  1995. return ret;
  1996. if (!hdev->dev_rdesc)
  1997. return -ENODEV;
  1998. /*
  1999. * Scan generic devices for group information
  2000. */
  2001. if (hid_ignore_special_drivers ||
  2002. !hid_match_id(hdev, hid_have_special_driver)) {
  2003. ret = hid_scan_report(hdev);
  2004. if (ret)
  2005. hid_warn(hdev, "bad device descriptor (%d)\n", ret);
  2006. }
  2007. /* XXX hack, any other cleaner solution after the driver core
  2008. * is converted to allow more than 20 bytes as the device name? */
  2009. dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
  2010. hdev->vendor, hdev->product, atomic_inc_return(&id));
  2011. hid_debug_register(hdev, dev_name(&hdev->dev));
  2012. ret = device_add(&hdev->dev);
  2013. if (!ret)
  2014. hdev->status |= HID_STAT_ADDED;
  2015. else
  2016. hid_debug_unregister(hdev);
  2017. return ret;
  2018. }
  2019. EXPORT_SYMBOL_GPL(hid_add_device);
  2020. /**
  2021. * hid_allocate_device - allocate new hid device descriptor
  2022. *
  2023. * Allocate and initialize hid device, so that hid_destroy_device might be
  2024. * used to free it.
  2025. *
  2026. * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
  2027. * error value.
  2028. */
  2029. struct hid_device *hid_allocate_device(void)
  2030. {
  2031. struct hid_device *hdev;
  2032. int ret = -ENOMEM;
  2033. hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
  2034. if (hdev == NULL)
  2035. return ERR_PTR(ret);
  2036. device_initialize(&hdev->dev);
  2037. hdev->dev.release = hid_device_release;
  2038. hdev->dev.bus = &hid_bus_type;
  2039. hid_close_report(hdev);
  2040. init_waitqueue_head(&hdev->debug_wait);
  2041. INIT_LIST_HEAD(&hdev->debug_list);
  2042. spin_lock_init(&hdev->debug_list_lock);
  2043. sema_init(&hdev->driver_lock, 1);
  2044. sema_init(&hdev->driver_input_lock, 1);
  2045. return hdev;
  2046. }
  2047. EXPORT_SYMBOL_GPL(hid_allocate_device);
  2048. static void hid_remove_device(struct hid_device *hdev)
  2049. {
  2050. if (hdev->status & HID_STAT_ADDED) {
  2051. device_del(&hdev->dev);
  2052. hid_debug_unregister(hdev);
  2053. hdev->status &= ~HID_STAT_ADDED;
  2054. }
  2055. kfree(hdev->dev_rdesc);
  2056. hdev->dev_rdesc = NULL;
  2057. hdev->dev_rsize = 0;
  2058. }
  2059. /**
  2060. * hid_destroy_device - free previously allocated device
  2061. *
  2062. * @hdev: hid device
  2063. *
  2064. * If you allocate hid_device through hid_allocate_device, you should ever
  2065. * free by this function.
  2066. */
  2067. void hid_destroy_device(struct hid_device *hdev)
  2068. {
  2069. hid_remove_device(hdev);
  2070. put_device(&hdev->dev);
  2071. }
  2072. EXPORT_SYMBOL_GPL(hid_destroy_device);
  2073. int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
  2074. const char *mod_name)
  2075. {
  2076. int ret;
  2077. hdrv->driver.name = hdrv->name;
  2078. hdrv->driver.bus = &hid_bus_type;
  2079. hdrv->driver.owner = owner;
  2080. hdrv->driver.mod_name = mod_name;
  2081. INIT_LIST_HEAD(&hdrv->dyn_list);
  2082. spin_lock_init(&hdrv->dyn_lock);
  2083. ret = driver_register(&hdrv->driver);
  2084. if (ret)
  2085. return ret;
  2086. ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
  2087. if (ret)
  2088. driver_unregister(&hdrv->driver);
  2089. return ret;
  2090. }
  2091. EXPORT_SYMBOL_GPL(__hid_register_driver);
  2092. void hid_unregister_driver(struct hid_driver *hdrv)
  2093. {
  2094. driver_remove_file(&hdrv->driver, &driver_attr_new_id);
  2095. driver_unregister(&hdrv->driver);
  2096. hid_free_dynids(hdrv);
  2097. }
  2098. EXPORT_SYMBOL_GPL(hid_unregister_driver);
  2099. int hid_check_keys_pressed(struct hid_device *hid)
  2100. {
  2101. struct hid_input *hidinput;
  2102. int i;
  2103. if (!(hid->claimed & HID_CLAIMED_INPUT))
  2104. return 0;
  2105. list_for_each_entry(hidinput, &hid->inputs, list) {
  2106. for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
  2107. if (hidinput->input->key[i])
  2108. return 1;
  2109. }
  2110. return 0;
  2111. }
  2112. EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
  2113. static int __init hid_init(void)
  2114. {
  2115. int ret;
  2116. if (hid_debug)
  2117. pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
  2118. "debugfs is now used for inspecting the device (report descriptor, reports)\n");
  2119. ret = bus_register(&hid_bus_type);
  2120. if (ret) {
  2121. pr_err("can't register hid bus\n");
  2122. goto err;
  2123. }
  2124. ret = hidraw_init();
  2125. if (ret)
  2126. goto err_bus;
  2127. hid_debug_init();
  2128. return 0;
  2129. err_bus:
  2130. bus_unregister(&hid_bus_type);
  2131. err:
  2132. return ret;
  2133. }
  2134. static void __exit hid_exit(void)
  2135. {
  2136. hid_debug_exit();
  2137. hidraw_exit();
  2138. bus_unregister(&hid_bus_type);
  2139. }
  2140. module_init(hid_init);
  2141. module_exit(hid_exit);
  2142. MODULE_AUTHOR("Andreas Gal");
  2143. MODULE_AUTHOR("Vojtech Pavlik");
  2144. MODULE_AUTHOR("Jiri Kosina");
  2145. MODULE_LICENSE(DRIVER_LICENSE);