hid-core.c 98 KB

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