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