hid-core.c 88 KB

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