hid-core.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758
  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. int i;
  570. if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
  571. type == HID_COLLECTION_PHYSICAL)
  572. hid->group = HID_GROUP_SENSOR_HUB;
  573. if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
  574. (hid->product == USB_DEVICE_ID_MS_TYPE_COVER_3 ||
  575. hid->product == USB_DEVICE_ID_MS_TYPE_COVER_3_JP ||
  576. hid->product == USB_DEVICE_ID_MS_POWER_COVER) &&
  577. hid->group == HID_GROUP_MULTITOUCH)
  578. hid->group = HID_GROUP_GENERIC;
  579. if ((parser->global.usage_page << 16) == HID_UP_GENDESK)
  580. for (i = 0; i < parser->local.usage_index; i++)
  581. if (parser->local.usage[i] == HID_GD_POINTER)
  582. parser->scan_flags |= HID_SCAN_FLAG_GD_POINTER;
  583. if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
  584. parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
  585. }
  586. static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
  587. {
  588. __u32 data;
  589. int i;
  590. data = item_udata(item);
  591. switch (item->tag) {
  592. case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
  593. hid_scan_collection(parser, data & 0xff);
  594. break;
  595. case HID_MAIN_ITEM_TAG_END_COLLECTION:
  596. break;
  597. case HID_MAIN_ITEM_TAG_INPUT:
  598. /* ignore constant inputs, they will be ignored by hid-input */
  599. if (data & HID_MAIN_ITEM_CONSTANT)
  600. break;
  601. for (i = 0; i < parser->local.usage_index; i++)
  602. hid_scan_input_usage(parser, parser->local.usage[i]);
  603. break;
  604. case HID_MAIN_ITEM_TAG_OUTPUT:
  605. break;
  606. case HID_MAIN_ITEM_TAG_FEATURE:
  607. for (i = 0; i < parser->local.usage_index; i++)
  608. hid_scan_feature_usage(parser, parser->local.usage[i]);
  609. break;
  610. }
  611. /* Reset the local parser environment */
  612. memset(&parser->local, 0, sizeof(parser->local));
  613. return 0;
  614. }
  615. /*
  616. * Scan a report descriptor before the device is added to the bus.
  617. * Sets device groups and other properties that determine what driver
  618. * to load.
  619. */
  620. static int hid_scan_report(struct hid_device *hid)
  621. {
  622. struct hid_parser *parser;
  623. struct hid_item item;
  624. __u8 *start = hid->dev_rdesc;
  625. __u8 *end = start + hid->dev_rsize;
  626. static int (*dispatch_type[])(struct hid_parser *parser,
  627. struct hid_item *item) = {
  628. hid_scan_main,
  629. hid_parser_global,
  630. hid_parser_local,
  631. hid_parser_reserved
  632. };
  633. parser = vzalloc(sizeof(struct hid_parser));
  634. if (!parser)
  635. return -ENOMEM;
  636. parser->device = hid;
  637. hid->group = HID_GROUP_GENERIC;
  638. /*
  639. * The parsing is simpler than the one in hid_open_report() as we should
  640. * be robust against hid errors. Those errors will be raised by
  641. * hid_open_report() anyway.
  642. */
  643. while ((start = fetch_item(start, end, &item)) != NULL)
  644. dispatch_type[item.type](parser, &item);
  645. /*
  646. * Handle special flags set during scanning.
  647. */
  648. if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
  649. (hid->group == HID_GROUP_MULTITOUCH))
  650. hid->group = HID_GROUP_MULTITOUCH_WIN_8;
  651. /*
  652. * Vendor specific handlings
  653. */
  654. switch (hid->vendor) {
  655. case USB_VENDOR_ID_WACOM:
  656. hid->group = HID_GROUP_WACOM;
  657. break;
  658. case USB_VENDOR_ID_SYNAPTICS:
  659. if (hid->group == HID_GROUP_GENERIC)
  660. if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
  661. && (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER))
  662. /*
  663. * hid-rmi should take care of them,
  664. * not hid-generic
  665. */
  666. hid->group = HID_GROUP_RMI;
  667. break;
  668. }
  669. vfree(parser);
  670. return 0;
  671. }
  672. /**
  673. * hid_parse_report - parse device report
  674. *
  675. * @device: hid device
  676. * @start: report start
  677. * @size: report size
  678. *
  679. * Allocate the device report as read by the bus driver. This function should
  680. * only be called from parse() in ll drivers.
  681. */
  682. int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
  683. {
  684. hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
  685. if (!hid->dev_rdesc)
  686. return -ENOMEM;
  687. hid->dev_rsize = size;
  688. return 0;
  689. }
  690. EXPORT_SYMBOL_GPL(hid_parse_report);
  691. static const char * const hid_report_names[] = {
  692. "HID_INPUT_REPORT",
  693. "HID_OUTPUT_REPORT",
  694. "HID_FEATURE_REPORT",
  695. };
  696. /**
  697. * hid_validate_values - validate existing device report's value indexes
  698. *
  699. * @device: hid device
  700. * @type: which report type to examine
  701. * @id: which report ID to examine (0 for first)
  702. * @field_index: which report field to examine
  703. * @report_counts: expected number of values
  704. *
  705. * Validate the number of values in a given field of a given report, after
  706. * parsing.
  707. */
  708. struct hid_report *hid_validate_values(struct hid_device *hid,
  709. unsigned int type, unsigned int id,
  710. unsigned int field_index,
  711. unsigned int report_counts)
  712. {
  713. struct hid_report *report;
  714. if (type > HID_FEATURE_REPORT) {
  715. hid_err(hid, "invalid HID report type %u\n", type);
  716. return NULL;
  717. }
  718. if (id >= HID_MAX_IDS) {
  719. hid_err(hid, "invalid HID report id %u\n", id);
  720. return NULL;
  721. }
  722. /*
  723. * Explicitly not using hid_get_report() here since it depends on
  724. * ->numbered being checked, which may not always be the case when
  725. * drivers go to access report values.
  726. */
  727. if (id == 0) {
  728. /*
  729. * Validating on id 0 means we should examine the first
  730. * report in the list.
  731. */
  732. report = list_entry(
  733. hid->report_enum[type].report_list.next,
  734. struct hid_report, list);
  735. } else {
  736. report = hid->report_enum[type].report_id_hash[id];
  737. }
  738. if (!report) {
  739. hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
  740. return NULL;
  741. }
  742. if (report->maxfield <= field_index) {
  743. hid_err(hid, "not enough fields in %s %u\n",
  744. hid_report_names[type], id);
  745. return NULL;
  746. }
  747. if (report->field[field_index]->report_count < report_counts) {
  748. hid_err(hid, "not enough values in %s %u field %u\n",
  749. hid_report_names[type], id, field_index);
  750. return NULL;
  751. }
  752. return report;
  753. }
  754. EXPORT_SYMBOL_GPL(hid_validate_values);
  755. /**
  756. * hid_open_report - open a driver-specific device report
  757. *
  758. * @device: hid device
  759. *
  760. * Parse a report description into a hid_device structure. Reports are
  761. * enumerated, fields are attached to these reports.
  762. * 0 returned on success, otherwise nonzero error value.
  763. *
  764. * This function (or the equivalent hid_parse() macro) should only be
  765. * called from probe() in drivers, before starting the device.
  766. */
  767. int hid_open_report(struct hid_device *device)
  768. {
  769. struct hid_parser *parser;
  770. struct hid_item item;
  771. unsigned int size;
  772. __u8 *start;
  773. __u8 *buf;
  774. __u8 *end;
  775. int ret;
  776. static int (*dispatch_type[])(struct hid_parser *parser,
  777. struct hid_item *item) = {
  778. hid_parser_main,
  779. hid_parser_global,
  780. hid_parser_local,
  781. hid_parser_reserved
  782. };
  783. if (WARN_ON(device->status & HID_STAT_PARSED))
  784. return -EBUSY;
  785. start = device->dev_rdesc;
  786. if (WARN_ON(!start))
  787. return -ENODEV;
  788. size = device->dev_rsize;
  789. buf = kmemdup(start, size, GFP_KERNEL);
  790. if (buf == NULL)
  791. return -ENOMEM;
  792. if (device->driver->report_fixup)
  793. start = device->driver->report_fixup(device, buf, &size);
  794. else
  795. start = buf;
  796. start = kmemdup(start, size, GFP_KERNEL);
  797. kfree(buf);
  798. if (start == NULL)
  799. return -ENOMEM;
  800. device->rdesc = start;
  801. device->rsize = size;
  802. parser = vzalloc(sizeof(struct hid_parser));
  803. if (!parser) {
  804. ret = -ENOMEM;
  805. goto err;
  806. }
  807. parser->device = device;
  808. end = start + size;
  809. device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
  810. sizeof(struct hid_collection), GFP_KERNEL);
  811. if (!device->collection) {
  812. ret = -ENOMEM;
  813. goto err;
  814. }
  815. device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
  816. ret = -EINVAL;
  817. while ((start = fetch_item(start, end, &item)) != NULL) {
  818. if (item.format != HID_ITEM_FORMAT_SHORT) {
  819. hid_err(device, "unexpected long global item\n");
  820. goto err;
  821. }
  822. if (dispatch_type[item.type](parser, &item)) {
  823. hid_err(device, "item %u %u %u %u parsing failed\n",
  824. item.format, (unsigned)item.size,
  825. (unsigned)item.type, (unsigned)item.tag);
  826. goto err;
  827. }
  828. if (start == end) {
  829. if (parser->collection_stack_ptr) {
  830. hid_err(device, "unbalanced collection at end of report description\n");
  831. goto err;
  832. }
  833. if (parser->local.delimiter_depth) {
  834. hid_err(device, "unbalanced delimiter at end of report description\n");
  835. goto err;
  836. }
  837. vfree(parser);
  838. device->status |= HID_STAT_PARSED;
  839. return 0;
  840. }
  841. }
  842. hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
  843. err:
  844. vfree(parser);
  845. hid_close_report(device);
  846. return ret;
  847. }
  848. EXPORT_SYMBOL_GPL(hid_open_report);
  849. /*
  850. * Convert a signed n-bit integer to signed 32-bit integer. Common
  851. * cases are done through the compiler, the screwed things has to be
  852. * done by hand.
  853. */
  854. static s32 snto32(__u32 value, unsigned n)
  855. {
  856. switch (n) {
  857. case 8: return ((__s8)value);
  858. case 16: return ((__s16)value);
  859. case 32: return ((__s32)value);
  860. }
  861. return value & (1 << (n - 1)) ? value | (-1 << n) : value;
  862. }
  863. s32 hid_snto32(__u32 value, unsigned n)
  864. {
  865. return snto32(value, n);
  866. }
  867. EXPORT_SYMBOL_GPL(hid_snto32);
  868. /*
  869. * Convert a signed 32-bit integer to a signed n-bit integer.
  870. */
  871. static u32 s32ton(__s32 value, unsigned n)
  872. {
  873. s32 a = value >> (n - 1);
  874. if (a && a != -1)
  875. return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
  876. return value & ((1 << n) - 1);
  877. }
  878. /*
  879. * Extract/implement a data field from/to a little endian report (bit array).
  880. *
  881. * Code sort-of follows HID spec:
  882. * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
  883. *
  884. * While the USB HID spec allows unlimited length bit fields in "report
  885. * descriptors", most devices never use more than 16 bits.
  886. * One model of UPS is claimed to report "LINEV" as a 32-bit field.
  887. * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
  888. */
  889. __u32 hid_field_extract(const struct hid_device *hid, __u8 *report,
  890. unsigned offset, unsigned n)
  891. {
  892. u64 x;
  893. if (n > 32)
  894. hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
  895. n, current->comm);
  896. report += offset >> 3; /* adjust byte index */
  897. offset &= 7; /* now only need bit offset into one byte */
  898. x = get_unaligned_le64(report);
  899. x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
  900. return (u32) x;
  901. }
  902. EXPORT_SYMBOL_GPL(hid_field_extract);
  903. /*
  904. * "implement" : set bits in a little endian bit stream.
  905. * Same concepts as "extract" (see comments above).
  906. * The data mangled in the bit stream remains in little endian
  907. * order the whole time. It make more sense to talk about
  908. * endianness of register values by considering a register
  909. * a "cached" copy of the little endiad bit stream.
  910. */
  911. static void implement(const struct hid_device *hid, __u8 *report,
  912. unsigned offset, unsigned n, __u32 value)
  913. {
  914. u64 x;
  915. u64 m = (1ULL << n) - 1;
  916. if (n > 32)
  917. hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
  918. __func__, n, current->comm);
  919. if (value > m)
  920. hid_warn(hid, "%s() called with too large value %d! (%s)\n",
  921. __func__, value, current->comm);
  922. WARN_ON(value > m);
  923. value &= m;
  924. report += offset >> 3;
  925. offset &= 7;
  926. x = get_unaligned_le64(report);
  927. x &= ~(m << offset);
  928. x |= ((u64)value) << offset;
  929. put_unaligned_le64(x, report);
  930. }
  931. /*
  932. * Search an array for a value.
  933. */
  934. static int search(__s32 *array, __s32 value, unsigned n)
  935. {
  936. while (n--) {
  937. if (*array++ == value)
  938. return 0;
  939. }
  940. return -1;
  941. }
  942. /**
  943. * hid_match_report - check if driver's raw_event should be called
  944. *
  945. * @hid: hid device
  946. * @report_type: type to match against
  947. *
  948. * compare hid->driver->report_table->report_type to report->type
  949. */
  950. static int hid_match_report(struct hid_device *hid, struct hid_report *report)
  951. {
  952. const struct hid_report_id *id = hid->driver->report_table;
  953. if (!id) /* NULL means all */
  954. return 1;
  955. for (; id->report_type != HID_TERMINATOR; id++)
  956. if (id->report_type == HID_ANY_ID ||
  957. id->report_type == report->type)
  958. return 1;
  959. return 0;
  960. }
  961. /**
  962. * hid_match_usage - check if driver's event should be called
  963. *
  964. * @hid: hid device
  965. * @usage: usage to match against
  966. *
  967. * compare hid->driver->usage_table->usage_{type,code} to
  968. * usage->usage_{type,code}
  969. */
  970. static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
  971. {
  972. const struct hid_usage_id *id = hid->driver->usage_table;
  973. if (!id) /* NULL means all */
  974. return 1;
  975. for (; id->usage_type != HID_ANY_ID - 1; id++)
  976. if ((id->usage_hid == HID_ANY_ID ||
  977. id->usage_hid == usage->hid) &&
  978. (id->usage_type == HID_ANY_ID ||
  979. id->usage_type == usage->type) &&
  980. (id->usage_code == HID_ANY_ID ||
  981. id->usage_code == usage->code))
  982. return 1;
  983. return 0;
  984. }
  985. static void hid_process_event(struct hid_device *hid, struct hid_field *field,
  986. struct hid_usage *usage, __s32 value, int interrupt)
  987. {
  988. struct hid_driver *hdrv = hid->driver;
  989. int ret;
  990. if (!list_empty(&hid->debug_list))
  991. hid_dump_input(hid, usage, value);
  992. if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
  993. ret = hdrv->event(hid, field, usage, value);
  994. if (ret != 0) {
  995. if (ret < 0)
  996. hid_err(hid, "%s's event failed with %d\n",
  997. hdrv->name, ret);
  998. return;
  999. }
  1000. }
  1001. if (hid->claimed & HID_CLAIMED_INPUT)
  1002. hidinput_hid_event(hid, field, usage, value);
  1003. if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
  1004. hid->hiddev_hid_event(hid, field, usage, value);
  1005. }
  1006. /*
  1007. * Analyse a received field, and fetch the data from it. The field
  1008. * content is stored for next report processing (we do differential
  1009. * reporting to the layer).
  1010. */
  1011. static void hid_input_field(struct hid_device *hid, struct hid_field *field,
  1012. __u8 *data, int interrupt)
  1013. {
  1014. unsigned n;
  1015. unsigned count = field->report_count;
  1016. unsigned offset = field->report_offset;
  1017. unsigned size = field->report_size;
  1018. __s32 min = field->logical_minimum;
  1019. __s32 max = field->logical_maximum;
  1020. __s32 *value;
  1021. value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
  1022. if (!value)
  1023. return;
  1024. for (n = 0; n < count; n++) {
  1025. value[n] = min < 0 ?
  1026. snto32(hid_field_extract(hid, data, offset + n * size,
  1027. size), size) :
  1028. hid_field_extract(hid, data, offset + n * size, size);
  1029. /* Ignore report if ErrorRollOver */
  1030. if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
  1031. value[n] >= min && value[n] <= max &&
  1032. field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
  1033. goto exit;
  1034. }
  1035. for (n = 0; n < count; n++) {
  1036. if (HID_MAIN_ITEM_VARIABLE & field->flags) {
  1037. hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
  1038. continue;
  1039. }
  1040. if (field->value[n] >= min && field->value[n] <= max
  1041. && field->usage[field->value[n] - min].hid
  1042. && search(value, field->value[n], count))
  1043. hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
  1044. if (value[n] >= min && value[n] <= max
  1045. && field->usage[value[n] - min].hid
  1046. && search(field->value, value[n], count))
  1047. hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
  1048. }
  1049. memcpy(field->value, value, count * sizeof(__s32));
  1050. exit:
  1051. kfree(value);
  1052. }
  1053. /*
  1054. * Output the field into the report.
  1055. */
  1056. static void hid_output_field(const struct hid_device *hid,
  1057. struct hid_field *field, __u8 *data)
  1058. {
  1059. unsigned count = field->report_count;
  1060. unsigned offset = field->report_offset;
  1061. unsigned size = field->report_size;
  1062. unsigned n;
  1063. for (n = 0; n < count; n++) {
  1064. if (field->logical_minimum < 0) /* signed values */
  1065. implement(hid, data, offset + n * size, size,
  1066. s32ton(field->value[n], size));
  1067. else /* unsigned values */
  1068. implement(hid, data, offset + n * size, size,
  1069. field->value[n]);
  1070. }
  1071. }
  1072. /*
  1073. * Create a report. 'data' has to be allocated using
  1074. * hid_alloc_report_buf() so that it has proper size.
  1075. */
  1076. void hid_output_report(struct hid_report *report, __u8 *data)
  1077. {
  1078. unsigned n;
  1079. if (report->id > 0)
  1080. *data++ = report->id;
  1081. memset(data, 0, ((report->size - 1) >> 3) + 1);
  1082. for (n = 0; n < report->maxfield; n++)
  1083. hid_output_field(report->device, report->field[n], data);
  1084. }
  1085. EXPORT_SYMBOL_GPL(hid_output_report);
  1086. /*
  1087. * Allocator for buffer that is going to be passed to hid_output_report()
  1088. */
  1089. u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
  1090. {
  1091. /*
  1092. * 7 extra bytes are necessary to achieve proper functionality
  1093. * of implement() working on 8 byte chunks
  1094. */
  1095. int len = hid_report_len(report) + 7;
  1096. return kmalloc(len, flags);
  1097. }
  1098. EXPORT_SYMBOL_GPL(hid_alloc_report_buf);
  1099. /*
  1100. * Set a field value. The report this field belongs to has to be
  1101. * created and transferred to the device, to set this value in the
  1102. * device.
  1103. */
  1104. int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
  1105. {
  1106. unsigned size;
  1107. if (!field)
  1108. return -1;
  1109. size = field->report_size;
  1110. hid_dump_input(field->report->device, field->usage + offset, value);
  1111. if (offset >= field->report_count) {
  1112. hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
  1113. offset, field->report_count);
  1114. return -1;
  1115. }
  1116. if (field->logical_minimum < 0) {
  1117. if (value != snto32(s32ton(value, size), size)) {
  1118. hid_err(field->report->device, "value %d is out of range\n", value);
  1119. return -1;
  1120. }
  1121. }
  1122. field->value[offset] = value;
  1123. return 0;
  1124. }
  1125. EXPORT_SYMBOL_GPL(hid_set_field);
  1126. static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
  1127. const u8 *data)
  1128. {
  1129. struct hid_report *report;
  1130. unsigned int n = 0; /* Normally report number is 0 */
  1131. /* Device uses numbered reports, data[0] is report number */
  1132. if (report_enum->numbered)
  1133. n = *data;
  1134. report = report_enum->report_id_hash[n];
  1135. if (report == NULL)
  1136. dbg_hid("undefined report_id %u received\n", n);
  1137. return report;
  1138. }
  1139. /*
  1140. * Implement a generic .request() callback, using .raw_request()
  1141. * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
  1142. */
  1143. void __hid_request(struct hid_device *hid, struct hid_report *report,
  1144. int reqtype)
  1145. {
  1146. char *buf;
  1147. int ret;
  1148. int len;
  1149. buf = hid_alloc_report_buf(report, GFP_KERNEL);
  1150. if (!buf)
  1151. return;
  1152. len = hid_report_len(report);
  1153. if (reqtype == HID_REQ_SET_REPORT)
  1154. hid_output_report(report, buf);
  1155. ret = hid->ll_driver->raw_request(hid, report->id, buf, len,
  1156. report->type, reqtype);
  1157. if (ret < 0) {
  1158. dbg_hid("unable to complete request: %d\n", ret);
  1159. goto out;
  1160. }
  1161. if (reqtype == HID_REQ_GET_REPORT)
  1162. hid_input_report(hid, report->type, buf, ret, 0);
  1163. out:
  1164. kfree(buf);
  1165. }
  1166. EXPORT_SYMBOL_GPL(__hid_request);
  1167. int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
  1168. int interrupt)
  1169. {
  1170. struct hid_report_enum *report_enum = hid->report_enum + type;
  1171. struct hid_report *report;
  1172. struct hid_driver *hdrv;
  1173. unsigned int a;
  1174. int rsize, csize = size;
  1175. u8 *cdata = data;
  1176. int ret = 0;
  1177. report = hid_get_report(report_enum, data);
  1178. if (!report)
  1179. goto out;
  1180. if (report_enum->numbered) {
  1181. cdata++;
  1182. csize--;
  1183. }
  1184. rsize = ((report->size - 1) >> 3) + 1;
  1185. if (rsize > HID_MAX_BUFFER_SIZE)
  1186. rsize = HID_MAX_BUFFER_SIZE;
  1187. if (csize < rsize) {
  1188. dbg_hid("report %d is too short, (%d < %d)\n", report->id,
  1189. csize, rsize);
  1190. memset(cdata + csize, 0, rsize - csize);
  1191. }
  1192. if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
  1193. hid->hiddev_report_event(hid, report);
  1194. if (hid->claimed & HID_CLAIMED_HIDRAW) {
  1195. ret = hidraw_report_event(hid, data, size);
  1196. if (ret)
  1197. goto out;
  1198. }
  1199. if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) {
  1200. for (a = 0; a < report->maxfield; a++)
  1201. hid_input_field(hid, report->field[a], cdata, interrupt);
  1202. hdrv = hid->driver;
  1203. if (hdrv && hdrv->report)
  1204. hdrv->report(hid, report);
  1205. }
  1206. if (hid->claimed & HID_CLAIMED_INPUT)
  1207. hidinput_report_event(hid, report);
  1208. out:
  1209. return ret;
  1210. }
  1211. EXPORT_SYMBOL_GPL(hid_report_raw_event);
  1212. /**
  1213. * hid_input_report - report data from lower layer (usb, bt...)
  1214. *
  1215. * @hid: hid device
  1216. * @type: HID report type (HID_*_REPORT)
  1217. * @data: report contents
  1218. * @size: size of data parameter
  1219. * @interrupt: distinguish between interrupt and control transfers
  1220. *
  1221. * This is data entry for lower layers.
  1222. */
  1223. int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
  1224. {
  1225. struct hid_report_enum *report_enum;
  1226. struct hid_driver *hdrv;
  1227. struct hid_report *report;
  1228. int ret = 0;
  1229. if (!hid)
  1230. return -ENODEV;
  1231. if (down_trylock(&hid->driver_input_lock))
  1232. return -EBUSY;
  1233. if (!hid->driver) {
  1234. ret = -ENODEV;
  1235. goto unlock;
  1236. }
  1237. report_enum = hid->report_enum + type;
  1238. hdrv = hid->driver;
  1239. if (!size) {
  1240. dbg_hid("empty report\n");
  1241. ret = -1;
  1242. goto unlock;
  1243. }
  1244. /* Avoid unnecessary overhead if debugfs is disabled */
  1245. if (!list_empty(&hid->debug_list))
  1246. hid_dump_report(hid, type, data, size);
  1247. report = hid_get_report(report_enum, data);
  1248. if (!report) {
  1249. ret = -1;
  1250. goto unlock;
  1251. }
  1252. if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
  1253. ret = hdrv->raw_event(hid, report, data, size);
  1254. if (ret < 0)
  1255. goto unlock;
  1256. }
  1257. ret = hid_report_raw_event(hid, type, data, size, interrupt);
  1258. unlock:
  1259. up(&hid->driver_input_lock);
  1260. return ret;
  1261. }
  1262. EXPORT_SYMBOL_GPL(hid_input_report);
  1263. static bool hid_match_one_id(struct hid_device *hdev,
  1264. const struct hid_device_id *id)
  1265. {
  1266. return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
  1267. (id->group == HID_GROUP_ANY || id->group == hdev->group) &&
  1268. (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
  1269. (id->product == HID_ANY_ID || id->product == hdev->product);
  1270. }
  1271. const struct hid_device_id *hid_match_id(struct hid_device *hdev,
  1272. const struct hid_device_id *id)
  1273. {
  1274. for (; id->bus; id++)
  1275. if (hid_match_one_id(hdev, id))
  1276. return id;
  1277. return NULL;
  1278. }
  1279. static const struct hid_device_id hid_hiddev_list[] = {
  1280. { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
  1281. { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
  1282. { }
  1283. };
  1284. static bool hid_hiddev(struct hid_device *hdev)
  1285. {
  1286. return !!hid_match_id(hdev, hid_hiddev_list);
  1287. }
  1288. static ssize_t
  1289. read_report_descriptor(struct file *filp, struct kobject *kobj,
  1290. struct bin_attribute *attr,
  1291. char *buf, loff_t off, size_t count)
  1292. {
  1293. struct device *dev = container_of(kobj, struct device, kobj);
  1294. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1295. if (off >= hdev->rsize)
  1296. return 0;
  1297. if (off + count > hdev->rsize)
  1298. count = hdev->rsize - off;
  1299. memcpy(buf, hdev->rdesc + off, count);
  1300. return count;
  1301. }
  1302. static ssize_t
  1303. show_country(struct device *dev, struct device_attribute *attr,
  1304. char *buf)
  1305. {
  1306. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1307. return sprintf(buf, "%02x\n", hdev->country & 0xff);
  1308. }
  1309. static struct bin_attribute dev_bin_attr_report_desc = {
  1310. .attr = { .name = "report_descriptor", .mode = 0444 },
  1311. .read = read_report_descriptor,
  1312. .size = HID_MAX_DESCRIPTOR_SIZE,
  1313. };
  1314. static struct device_attribute dev_attr_country = {
  1315. .attr = { .name = "country", .mode = 0444 },
  1316. .show = show_country,
  1317. };
  1318. int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
  1319. {
  1320. static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
  1321. "Joystick", "Gamepad", "Keyboard", "Keypad",
  1322. "Multi-Axis Controller"
  1323. };
  1324. const char *type, *bus;
  1325. char buf[64];
  1326. unsigned int i;
  1327. int len;
  1328. int ret;
  1329. if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
  1330. connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
  1331. if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
  1332. connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
  1333. if (hdev->bus != BUS_USB)
  1334. connect_mask &= ~HID_CONNECT_HIDDEV;
  1335. if (hid_hiddev(hdev))
  1336. connect_mask |= HID_CONNECT_HIDDEV_FORCE;
  1337. if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
  1338. connect_mask & HID_CONNECT_HIDINPUT_FORCE))
  1339. hdev->claimed |= HID_CLAIMED_INPUT;
  1340. if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
  1341. !hdev->hiddev_connect(hdev,
  1342. connect_mask & HID_CONNECT_HIDDEV_FORCE))
  1343. hdev->claimed |= HID_CLAIMED_HIDDEV;
  1344. if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
  1345. hdev->claimed |= HID_CLAIMED_HIDRAW;
  1346. if (connect_mask & HID_CONNECT_DRIVER)
  1347. hdev->claimed |= HID_CLAIMED_DRIVER;
  1348. /* Drivers with the ->raw_event callback set are not required to connect
  1349. * to any other listener. */
  1350. if (!hdev->claimed && !hdev->driver->raw_event) {
  1351. hid_err(hdev, "device has no listeners, quitting\n");
  1352. return -ENODEV;
  1353. }
  1354. if ((hdev->claimed & HID_CLAIMED_INPUT) &&
  1355. (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
  1356. hdev->ff_init(hdev);
  1357. len = 0;
  1358. if (hdev->claimed & HID_CLAIMED_INPUT)
  1359. len += sprintf(buf + len, "input");
  1360. if (hdev->claimed & HID_CLAIMED_HIDDEV)
  1361. len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
  1362. hdev->minor);
  1363. if (hdev->claimed & HID_CLAIMED_HIDRAW)
  1364. len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
  1365. ((struct hidraw *)hdev->hidraw)->minor);
  1366. type = "Device";
  1367. for (i = 0; i < hdev->maxcollection; i++) {
  1368. struct hid_collection *col = &hdev->collection[i];
  1369. if (col->type == HID_COLLECTION_APPLICATION &&
  1370. (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  1371. (col->usage & 0xffff) < ARRAY_SIZE(types)) {
  1372. type = types[col->usage & 0xffff];
  1373. break;
  1374. }
  1375. }
  1376. switch (hdev->bus) {
  1377. case BUS_USB:
  1378. bus = "USB";
  1379. break;
  1380. case BUS_BLUETOOTH:
  1381. bus = "BLUETOOTH";
  1382. break;
  1383. default:
  1384. bus = "<UNKNOWN>";
  1385. }
  1386. ret = device_create_file(&hdev->dev, &dev_attr_country);
  1387. if (ret)
  1388. hid_warn(hdev,
  1389. "can't create sysfs country code attribute err: %d\n", ret);
  1390. ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
  1391. if (ret)
  1392. hid_warn(hdev,
  1393. "can't create sysfs report descriptor attribute err: %d\n", ret);
  1394. hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
  1395. buf, bus, hdev->version >> 8, hdev->version & 0xff,
  1396. type, hdev->name, hdev->phys);
  1397. return 0;
  1398. }
  1399. EXPORT_SYMBOL_GPL(hid_connect);
  1400. void hid_disconnect(struct hid_device *hdev)
  1401. {
  1402. device_remove_file(&hdev->dev, &dev_attr_country);
  1403. device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
  1404. if (hdev->claimed & HID_CLAIMED_INPUT)
  1405. hidinput_disconnect(hdev);
  1406. if (hdev->claimed & HID_CLAIMED_HIDDEV)
  1407. hdev->hiddev_disconnect(hdev);
  1408. if (hdev->claimed & HID_CLAIMED_HIDRAW)
  1409. hidraw_disconnect(hdev);
  1410. hdev->claimed = 0;
  1411. }
  1412. EXPORT_SYMBOL_GPL(hid_disconnect);
  1413. /*
  1414. * A list of devices for which there is a specialized driver on HID bus.
  1415. *
  1416. * Please note that for multitouch devices (driven by hid-multitouch driver),
  1417. * there is a proper autodetection and autoloading in place (based on presence
  1418. * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
  1419. * as we are doing the right thing in hid_scan_usage().
  1420. *
  1421. * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
  1422. * physical is found inside a usage page of type sensor, hid-sensor-hub will be
  1423. * used as a driver. See hid_scan_report().
  1424. */
  1425. static const struct hid_device_id hid_have_special_driver[] = {
  1426. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
  1427. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
  1428. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
  1429. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
  1430. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
  1431. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
  1432. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
  1433. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
  1434. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  1435. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  1436. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  1437. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  1438. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  1439. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  1440. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  1441. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  1442. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  1443. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  1444. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  1445. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
  1446. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
  1447. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
  1448. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
  1449. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
  1450. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
  1451. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  1452. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  1453. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  1454. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
  1455. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
  1456. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
  1457. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
  1458. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
  1459. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
  1460. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
  1461. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
  1462. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  1463. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  1464. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  1465. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  1466. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  1467. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  1468. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  1469. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  1470. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  1471. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  1472. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  1473. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  1474. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  1475. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  1476. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  1477. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  1478. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  1479. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  1480. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  1481. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  1482. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  1483. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
  1484. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
  1485. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
  1486. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  1487. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  1488. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  1489. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  1490. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  1491. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  1492. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  1493. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  1494. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  1495. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  1496. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  1497. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  1498. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
  1499. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
  1500. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
  1501. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
  1502. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
  1503. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
  1504. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
  1505. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
  1506. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
  1507. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  1508. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  1509. { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
  1510. { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
  1511. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185BFM, 0x2208) },
  1512. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185PC, 0x5506) },
  1513. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2PC, 0x1850) },
  1514. { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2BFM, 0x5500) },
  1515. { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
  1516. { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
  1517. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
  1518. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
  1519. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
  1520. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
  1521. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
  1522. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
  1523. { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
  1524. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
  1525. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
  1526. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
  1527. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
  1528. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
  1529. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
  1530. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
  1531. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
  1532. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
  1533. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
  1534. { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
  1535. { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
  1536. { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
  1537. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
  1538. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
  1539. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
  1540. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
  1541. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
  1542. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
  1543. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
  1544. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
  1545. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
  1546. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
  1547. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
  1548. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
  1549. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
  1550. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
  1551. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
  1552. { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
  1553. { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
  1554. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
  1555. { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
  1556. { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
  1557. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
  1558. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_MANTICORE) },
  1559. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
  1560. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  1561. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  1562. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  1563. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
  1564. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  1565. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_PENSKETCH_M912) },
  1566. { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
  1567. { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
  1568. #if IS_ENABLED(CONFIG_HID_LENOVO)
  1569. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
  1570. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) },
  1571. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) },
  1572. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) },
  1573. #endif
  1574. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
  1575. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
  1576. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
  1577. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
  1578. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
  1579. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_T651) },
  1580. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
  1581. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
  1582. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
  1583. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
  1584. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
  1585. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
  1586. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
  1587. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
  1588. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
  1589. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
  1590. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
  1591. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
  1592. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
  1593. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
  1594. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
  1595. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
  1596. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL) },
  1597. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
  1598. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
  1599. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
  1600. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
  1601. #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
  1602. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
  1603. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
  1604. #endif
  1605. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
  1606. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
  1607. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
  1608. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
  1609. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
  1610. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
  1611. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
  1612. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
  1613. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
  1614. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
  1615. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE7K) },
  1616. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
  1617. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
  1618. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
  1619. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
  1620. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
  1621. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3) },
  1622. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3_JP) },
  1623. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER) },
  1624. { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
  1625. { HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
  1626. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
  1627. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
  1628. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
  1629. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
  1630. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
  1631. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
  1632. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
  1633. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
  1634. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
  1635. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
  1636. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
  1637. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
  1638. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
  1639. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
  1640. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
  1641. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
  1642. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
  1643. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
  1644. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
  1645. { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
  1646. { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
  1647. { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_6000) },
  1648. { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
  1649. { HID_USB_DEVICE(USB_VENDOR_ID_PLANTRONICS, HID_ANY_ID) },
  1650. { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
  1651. #if IS_ENABLED(CONFIG_HID_ROCCAT)
  1652. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
  1653. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
  1654. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKUFX) },
  1655. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
  1656. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
  1657. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
  1658. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
  1659. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEXTD) },
  1660. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
  1661. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
  1662. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
  1663. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
  1664. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK) },
  1665. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW) },
  1666. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO) },
  1667. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
  1668. #endif
  1669. #if IS_ENABLED(CONFIG_HID_SAITEK)
  1670. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
  1671. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7_OLD) },
  1672. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7) },
  1673. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7) },
  1674. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9) },
  1675. #endif
  1676. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  1677. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
  1678. { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
  1679. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE) },
  1680. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
  1681. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
  1682. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) },
  1683. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) },
  1684. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
  1685. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
  1686. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
  1687. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  1688. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  1689. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
  1690. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
  1691. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
  1692. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
  1693. { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
  1694. { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
  1695. { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
  1696. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
  1697. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
  1698. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
  1699. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
  1700. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
  1701. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
  1702. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
  1703. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
  1704. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
  1705. { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
  1706. { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_PRO) },
  1707. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
  1708. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
  1709. { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
  1710. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
  1711. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
  1712. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
  1713. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
  1714. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
  1715. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
  1716. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
  1717. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
  1718. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
  1719. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
  1720. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
  1721. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
  1722. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
  1723. { HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII) },
  1724. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
  1725. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
  1726. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
  1727. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
  1728. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
  1729. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
  1730. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
  1731. { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
  1732. { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
  1733. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
  1734. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
  1735. { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
  1736. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
  1737. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
  1738. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
  1739. { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) },
  1740. { }
  1741. };
  1742. struct hid_dynid {
  1743. struct list_head list;
  1744. struct hid_device_id id;
  1745. };
  1746. /**
  1747. * store_new_id - add a new HID device ID to this driver and re-probe devices
  1748. * @driver: target device driver
  1749. * @buf: buffer for scanning device ID data
  1750. * @count: input size
  1751. *
  1752. * Adds a new dynamic hid device ID to this driver,
  1753. * and causes the driver to probe for all devices again.
  1754. */
  1755. static ssize_t store_new_id(struct device_driver *drv, const char *buf,
  1756. size_t count)
  1757. {
  1758. struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
  1759. struct hid_dynid *dynid;
  1760. __u32 bus, vendor, product;
  1761. unsigned long driver_data = 0;
  1762. int ret;
  1763. ret = sscanf(buf, "%x %x %x %lx",
  1764. &bus, &vendor, &product, &driver_data);
  1765. if (ret < 3)
  1766. return -EINVAL;
  1767. dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
  1768. if (!dynid)
  1769. return -ENOMEM;
  1770. dynid->id.bus = bus;
  1771. dynid->id.group = HID_GROUP_ANY;
  1772. dynid->id.vendor = vendor;
  1773. dynid->id.product = product;
  1774. dynid->id.driver_data = driver_data;
  1775. spin_lock(&hdrv->dyn_lock);
  1776. list_add_tail(&dynid->list, &hdrv->dyn_list);
  1777. spin_unlock(&hdrv->dyn_lock);
  1778. ret = driver_attach(&hdrv->driver);
  1779. return ret ? : count;
  1780. }
  1781. static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
  1782. static void hid_free_dynids(struct hid_driver *hdrv)
  1783. {
  1784. struct hid_dynid *dynid, *n;
  1785. spin_lock(&hdrv->dyn_lock);
  1786. list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
  1787. list_del(&dynid->list);
  1788. kfree(dynid);
  1789. }
  1790. spin_unlock(&hdrv->dyn_lock);
  1791. }
  1792. static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
  1793. struct hid_driver *hdrv)
  1794. {
  1795. struct hid_dynid *dynid;
  1796. spin_lock(&hdrv->dyn_lock);
  1797. list_for_each_entry(dynid, &hdrv->dyn_list, list) {
  1798. if (hid_match_one_id(hdev, &dynid->id)) {
  1799. spin_unlock(&hdrv->dyn_lock);
  1800. return &dynid->id;
  1801. }
  1802. }
  1803. spin_unlock(&hdrv->dyn_lock);
  1804. return hid_match_id(hdev, hdrv->id_table);
  1805. }
  1806. static int hid_bus_match(struct device *dev, struct device_driver *drv)
  1807. {
  1808. struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
  1809. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1810. return hid_match_device(hdev, hdrv) != NULL;
  1811. }
  1812. static int hid_device_probe(struct device *dev)
  1813. {
  1814. struct hid_driver *hdrv = container_of(dev->driver,
  1815. struct hid_driver, driver);
  1816. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1817. const struct hid_device_id *id;
  1818. int ret = 0;
  1819. if (down_interruptible(&hdev->driver_lock))
  1820. return -EINTR;
  1821. if (down_interruptible(&hdev->driver_input_lock)) {
  1822. ret = -EINTR;
  1823. goto unlock_driver_lock;
  1824. }
  1825. hdev->io_started = false;
  1826. if (!hdev->driver) {
  1827. id = hid_match_device(hdev, hdrv);
  1828. if (id == NULL) {
  1829. ret = -ENODEV;
  1830. goto unlock;
  1831. }
  1832. hdev->driver = hdrv;
  1833. if (hdrv->probe) {
  1834. ret = hdrv->probe(hdev, id);
  1835. } else { /* default probe */
  1836. ret = hid_open_report(hdev);
  1837. if (!ret)
  1838. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1839. }
  1840. if (ret) {
  1841. hid_close_report(hdev);
  1842. hdev->driver = NULL;
  1843. }
  1844. }
  1845. unlock:
  1846. if (!hdev->io_started)
  1847. up(&hdev->driver_input_lock);
  1848. unlock_driver_lock:
  1849. up(&hdev->driver_lock);
  1850. return ret;
  1851. }
  1852. static int hid_device_remove(struct device *dev)
  1853. {
  1854. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1855. struct hid_driver *hdrv;
  1856. int ret = 0;
  1857. if (down_interruptible(&hdev->driver_lock))
  1858. return -EINTR;
  1859. if (down_interruptible(&hdev->driver_input_lock)) {
  1860. ret = -EINTR;
  1861. goto unlock_driver_lock;
  1862. }
  1863. hdev->io_started = false;
  1864. hdrv = hdev->driver;
  1865. if (hdrv) {
  1866. if (hdrv->remove)
  1867. hdrv->remove(hdev);
  1868. else /* default remove */
  1869. hid_hw_stop(hdev);
  1870. hid_close_report(hdev);
  1871. hdev->driver = NULL;
  1872. }
  1873. if (!hdev->io_started)
  1874. up(&hdev->driver_input_lock);
  1875. unlock_driver_lock:
  1876. up(&hdev->driver_lock);
  1877. return ret;
  1878. }
  1879. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  1880. char *buf)
  1881. {
  1882. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1883. int len;
  1884. len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
  1885. hdev->bus, hdev->group, hdev->vendor, hdev->product);
  1886. return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
  1887. }
  1888. static DEVICE_ATTR_RO(modalias);
  1889. static struct attribute *hid_dev_attrs[] = {
  1890. &dev_attr_modalias.attr,
  1891. NULL,
  1892. };
  1893. ATTRIBUTE_GROUPS(hid_dev);
  1894. static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
  1895. {
  1896. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1897. if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
  1898. hdev->bus, hdev->vendor, hdev->product))
  1899. return -ENOMEM;
  1900. if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
  1901. return -ENOMEM;
  1902. if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
  1903. return -ENOMEM;
  1904. if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
  1905. return -ENOMEM;
  1906. if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
  1907. hdev->bus, hdev->group, hdev->vendor, hdev->product))
  1908. return -ENOMEM;
  1909. return 0;
  1910. }
  1911. static struct bus_type hid_bus_type = {
  1912. .name = "hid",
  1913. .dev_groups = hid_dev_groups,
  1914. .match = hid_bus_match,
  1915. .probe = hid_device_probe,
  1916. .remove = hid_device_remove,
  1917. .uevent = hid_uevent,
  1918. };
  1919. /* a list of devices that shouldn't be handled by HID core at all */
  1920. static const struct hid_device_id hid_ignore_list[] = {
  1921. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
  1922. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
  1923. { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
  1924. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
  1925. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
  1926. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
  1927. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
  1928. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
  1929. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
  1930. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
  1931. { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
  1932. { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
  1933. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
  1934. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
  1935. { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
  1936. { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
  1937. { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
  1938. { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
  1939. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
  1940. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) },
  1941. { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
  1942. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
  1943. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
  1944. { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
  1945. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
  1946. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
  1947. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
  1948. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
  1949. { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
  1950. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
  1951. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
  1952. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
  1953. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
  1954. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
  1955. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
  1956. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
  1957. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
  1958. { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
  1959. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
  1960. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
  1961. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
  1962. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
  1963. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
  1964. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
  1965. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
  1966. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
  1967. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
  1968. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
  1969. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
  1970. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
  1971. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
  1972. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
  1973. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
  1974. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
  1975. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
  1976. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
  1977. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
  1978. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
  1979. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
  1980. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
  1981. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
  1982. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
  1983. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
  1984. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
  1985. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
  1986. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
  1987. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
  1988. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
  1989. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
  1990. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
  1991. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
  1992. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
  1993. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
  1994. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
  1995. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
  1996. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
  1997. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
  1998. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
  1999. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
  2000. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
  2001. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
  2002. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
  2003. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
  2004. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
  2005. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
  2006. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
  2007. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
  2008. { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
  2009. { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) },
  2010. { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) },
  2011. { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_GN9350E) },
  2012. { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
  2013. { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
  2014. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
  2015. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
  2016. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
  2017. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
  2018. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
  2019. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
  2020. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
  2021. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
  2022. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
  2023. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
  2024. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
  2025. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
  2026. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
  2027. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
  2028. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
  2029. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
  2030. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
  2031. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
  2032. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
  2033. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
  2034. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
  2035. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
  2036. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
  2037. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
  2038. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
  2039. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
  2040. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
  2041. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
  2042. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
  2043. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
  2044. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
  2045. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
  2046. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
  2047. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
  2048. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
  2049. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
  2050. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
  2051. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
  2052. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
  2053. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICK16F1454) },
  2054. { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
  2055. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
  2056. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
  2057. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
  2058. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
  2059. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
  2060. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
  2061. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
  2062. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
  2063. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
  2064. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
  2065. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
  2066. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
  2067. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
  2068. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
  2069. { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
  2070. { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
  2071. #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
  2072. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
  2073. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
  2074. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
  2075. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
  2076. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
  2077. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
  2078. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
  2079. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
  2080. #endif
  2081. { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
  2082. { HID_USB_DEVICE(USB_VENDOR_ID_RISO_KAGAKU, USB_DEVICE_ID_RI_KA_WEBMAIL) },
  2083. { }
  2084. };
  2085. /**
  2086. * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
  2087. *
  2088. * There are composite devices for which we want to ignore only a certain
  2089. * interface. This is a list of devices for which only the mouse interface will
  2090. * be ignored. This allows a dedicated driver to take care of the interface.
  2091. */
  2092. static const struct hid_device_id hid_mouse_ignore_list[] = {
  2093. /* appletouch driver */
  2094. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  2095. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  2096. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  2097. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  2098. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  2099. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  2100. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  2101. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  2102. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  2103. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  2104. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  2105. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  2106. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  2107. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  2108. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  2109. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  2110. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  2111. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  2112. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  2113. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  2114. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  2115. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  2116. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  2117. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  2118. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  2119. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  2120. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  2121. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  2122. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  2123. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  2124. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  2125. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  2126. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  2127. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  2128. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  2129. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  2130. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  2131. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  2132. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  2133. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  2134. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  2135. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  2136. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  2137. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  2138. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  2139. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  2140. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  2141. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
  2142. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
  2143. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
  2144. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  2145. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  2146. { }
  2147. };
  2148. bool hid_ignore(struct hid_device *hdev)
  2149. {
  2150. if (hdev->quirks & HID_QUIRK_NO_IGNORE)
  2151. return false;
  2152. if (hdev->quirks & HID_QUIRK_IGNORE)
  2153. return true;
  2154. switch (hdev->vendor) {
  2155. case USB_VENDOR_ID_CODEMERCS:
  2156. /* ignore all Code Mercenaries IOWarrior devices */
  2157. if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
  2158. hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
  2159. return true;
  2160. break;
  2161. case USB_VENDOR_ID_LOGITECH:
  2162. if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
  2163. hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
  2164. return true;
  2165. /*
  2166. * The Keene FM transmitter USB device has the same USB ID as
  2167. * the Logitech AudioHub Speaker, but it should ignore the hid.
  2168. * Check if the name is that of the Keene device.
  2169. * For reference: the name of the AudioHub is
  2170. * "HOLTEK AudioHub Speaker".
  2171. */
  2172. if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
  2173. !strcmp(hdev->name, "HOLTEK B-LINK USB Audio "))
  2174. return true;
  2175. break;
  2176. case USB_VENDOR_ID_SOUNDGRAPH:
  2177. if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
  2178. hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
  2179. return true;
  2180. break;
  2181. case USB_VENDOR_ID_HANWANG:
  2182. if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
  2183. hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
  2184. return true;
  2185. break;
  2186. case USB_VENDOR_ID_JESS:
  2187. if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
  2188. hdev->type == HID_TYPE_USBNONE)
  2189. return true;
  2190. break;
  2191. case USB_VENDOR_ID_VELLEMAN:
  2192. /* These are not HID devices. They are handled by comedi. */
  2193. if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
  2194. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
  2195. (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
  2196. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
  2197. return true;
  2198. break;
  2199. case USB_VENDOR_ID_ATMEL_V_USB:
  2200. /* Masterkit MA901 usb radio based on Atmel tiny85 chip and
  2201. * it has the same USB ID as many Atmel V-USB devices. This
  2202. * usb radio is handled by radio-ma901.c driver so we want
  2203. * ignore the hid. Check the name, bus, product and ignore
  2204. * if we have MA901 usb radio.
  2205. */
  2206. if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
  2207. hdev->bus == BUS_USB &&
  2208. strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
  2209. return true;
  2210. break;
  2211. }
  2212. if (hdev->type == HID_TYPE_USBMOUSE &&
  2213. hid_match_id(hdev, hid_mouse_ignore_list))
  2214. return true;
  2215. return !!hid_match_id(hdev, hid_ignore_list);
  2216. }
  2217. EXPORT_SYMBOL_GPL(hid_ignore);
  2218. int hid_add_device(struct hid_device *hdev)
  2219. {
  2220. static atomic_t id = ATOMIC_INIT(0);
  2221. int ret;
  2222. if (WARN_ON(hdev->status & HID_STAT_ADDED))
  2223. return -EBUSY;
  2224. /* we need to kill them here, otherwise they will stay allocated to
  2225. * wait for coming driver */
  2226. if (hid_ignore(hdev))
  2227. return -ENODEV;
  2228. /*
  2229. * Check for the mandatory transport channel.
  2230. */
  2231. if (!hdev->ll_driver->raw_request) {
  2232. hid_err(hdev, "transport driver missing .raw_request()\n");
  2233. return -EINVAL;
  2234. }
  2235. /*
  2236. * Read the device report descriptor once and use as template
  2237. * for the driver-specific modifications.
  2238. */
  2239. ret = hdev->ll_driver->parse(hdev);
  2240. if (ret)
  2241. return ret;
  2242. if (!hdev->dev_rdesc)
  2243. return -ENODEV;
  2244. /*
  2245. * Scan generic devices for group information
  2246. */
  2247. if (hid_ignore_special_drivers ||
  2248. (!hdev->group &&
  2249. !hid_match_id(hdev, hid_have_special_driver))) {
  2250. ret = hid_scan_report(hdev);
  2251. if (ret)
  2252. hid_warn(hdev, "bad device descriptor (%d)\n", ret);
  2253. }
  2254. /* XXX hack, any other cleaner solution after the driver core
  2255. * is converted to allow more than 20 bytes as the device name? */
  2256. dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
  2257. hdev->vendor, hdev->product, atomic_inc_return(&id));
  2258. hid_debug_register(hdev, dev_name(&hdev->dev));
  2259. ret = device_add(&hdev->dev);
  2260. if (!ret)
  2261. hdev->status |= HID_STAT_ADDED;
  2262. else
  2263. hid_debug_unregister(hdev);
  2264. return ret;
  2265. }
  2266. EXPORT_SYMBOL_GPL(hid_add_device);
  2267. /**
  2268. * hid_allocate_device - allocate new hid device descriptor
  2269. *
  2270. * Allocate and initialize hid device, so that hid_destroy_device might be
  2271. * used to free it.
  2272. *
  2273. * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
  2274. * error value.
  2275. */
  2276. struct hid_device *hid_allocate_device(void)
  2277. {
  2278. struct hid_device *hdev;
  2279. int ret = -ENOMEM;
  2280. hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
  2281. if (hdev == NULL)
  2282. return ERR_PTR(ret);
  2283. device_initialize(&hdev->dev);
  2284. hdev->dev.release = hid_device_release;
  2285. hdev->dev.bus = &hid_bus_type;
  2286. hid_close_report(hdev);
  2287. init_waitqueue_head(&hdev->debug_wait);
  2288. INIT_LIST_HEAD(&hdev->debug_list);
  2289. spin_lock_init(&hdev->debug_list_lock);
  2290. sema_init(&hdev->driver_lock, 1);
  2291. sema_init(&hdev->driver_input_lock, 1);
  2292. return hdev;
  2293. }
  2294. EXPORT_SYMBOL_GPL(hid_allocate_device);
  2295. static void hid_remove_device(struct hid_device *hdev)
  2296. {
  2297. if (hdev->status & HID_STAT_ADDED) {
  2298. device_del(&hdev->dev);
  2299. hid_debug_unregister(hdev);
  2300. hdev->status &= ~HID_STAT_ADDED;
  2301. }
  2302. kfree(hdev->dev_rdesc);
  2303. hdev->dev_rdesc = NULL;
  2304. hdev->dev_rsize = 0;
  2305. }
  2306. /**
  2307. * hid_destroy_device - free previously allocated device
  2308. *
  2309. * @hdev: hid device
  2310. *
  2311. * If you allocate hid_device through hid_allocate_device, you should ever
  2312. * free by this function.
  2313. */
  2314. void hid_destroy_device(struct hid_device *hdev)
  2315. {
  2316. hid_remove_device(hdev);
  2317. put_device(&hdev->dev);
  2318. }
  2319. EXPORT_SYMBOL_GPL(hid_destroy_device);
  2320. int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
  2321. const char *mod_name)
  2322. {
  2323. int ret;
  2324. hdrv->driver.name = hdrv->name;
  2325. hdrv->driver.bus = &hid_bus_type;
  2326. hdrv->driver.owner = owner;
  2327. hdrv->driver.mod_name = mod_name;
  2328. INIT_LIST_HEAD(&hdrv->dyn_list);
  2329. spin_lock_init(&hdrv->dyn_lock);
  2330. ret = driver_register(&hdrv->driver);
  2331. if (ret)
  2332. return ret;
  2333. ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
  2334. if (ret)
  2335. driver_unregister(&hdrv->driver);
  2336. return ret;
  2337. }
  2338. EXPORT_SYMBOL_GPL(__hid_register_driver);
  2339. void hid_unregister_driver(struct hid_driver *hdrv)
  2340. {
  2341. driver_remove_file(&hdrv->driver, &driver_attr_new_id);
  2342. driver_unregister(&hdrv->driver);
  2343. hid_free_dynids(hdrv);
  2344. }
  2345. EXPORT_SYMBOL_GPL(hid_unregister_driver);
  2346. int hid_check_keys_pressed(struct hid_device *hid)
  2347. {
  2348. struct hid_input *hidinput;
  2349. int i;
  2350. if (!(hid->claimed & HID_CLAIMED_INPUT))
  2351. return 0;
  2352. list_for_each_entry(hidinput, &hid->inputs, list) {
  2353. for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
  2354. if (hidinput->input->key[i])
  2355. return 1;
  2356. }
  2357. return 0;
  2358. }
  2359. EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
  2360. static int __init hid_init(void)
  2361. {
  2362. int ret;
  2363. if (hid_debug)
  2364. pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
  2365. "debugfs is now used for inspecting the device (report descriptor, reports)\n");
  2366. ret = bus_register(&hid_bus_type);
  2367. if (ret) {
  2368. pr_err("can't register hid bus\n");
  2369. goto err;
  2370. }
  2371. ret = hidraw_init();
  2372. if (ret)
  2373. goto err_bus;
  2374. hid_debug_init();
  2375. return 0;
  2376. err_bus:
  2377. bus_unregister(&hid_bus_type);
  2378. err:
  2379. return ret;
  2380. }
  2381. static void __exit hid_exit(void)
  2382. {
  2383. hid_debug_exit();
  2384. hidraw_exit();
  2385. bus_unregister(&hid_bus_type);
  2386. }
  2387. module_init(hid_init);
  2388. module_exit(hid_exit);
  2389. MODULE_AUTHOR("Andreas Gal");
  2390. MODULE_AUTHOR("Vojtech Pavlik");
  2391. MODULE_AUTHOR("Jiri Kosina");
  2392. MODULE_LICENSE(DRIVER_LICENSE);