hid-core.c 91 KB

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