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