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