hid-core.c 88 KB

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