hid-core.c 91 KB

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