Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / hid / hid-core.c
blob023bee9b40730162ee7929c2bada6d09b386a037
1 /*
2 * HID support for Linux
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2010 Jiri Kosina
8 */
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.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
34 #include <linux/hid.h>
35 #include <linux/hiddev.h>
36 #include <linux/hid-debug.h>
37 #include <linux/hidraw.h>
39 #include "hid-ids.h"
42 * Version Information
45 #define DRIVER_DESC "HID core driver"
46 #define DRIVER_LICENSE "GPL"
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);
54 * Register a new report for a device.
57 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
59 struct hid_report_enum *report_enum = device->report_enum + type;
60 struct hid_report *report;
62 if (report_enum->report_id_hash[id])
63 return report_enum->report_id_hash[id];
65 report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
66 if (!report)
67 return NULL;
69 if (id != 0)
70 report_enum->numbered = 1;
72 report->id = id;
73 report->type = type;
74 report->size = 0;
75 report->device = device;
76 report_enum->report_id_hash[id] = report;
78 list_add_tail(&report->list, &report_enum->report_list);
80 return report;
82 EXPORT_SYMBOL_GPL(hid_register_report);
85 * Register a new field for this report.
88 static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
90 struct hid_field *field;
92 if (report->maxfield == HID_MAX_FIELDS) {
93 dbg_hid("too many fields in report\n");
94 return NULL;
97 field = kzalloc((sizeof(struct hid_field) +
98 usages * sizeof(struct hid_usage) +
99 values * sizeof(unsigned)), GFP_KERNEL);
100 if (!field)
101 return NULL;
103 field->index = report->maxfield++;
104 report->field[field->index] = field;
105 field->usage = (struct hid_usage *)(field + 1);
106 field->value = (s32 *)(field->usage + usages);
107 field->report = report;
109 return field;
113 * Open a collection. The type/usage is pushed on the stack.
116 static int open_collection(struct hid_parser *parser, unsigned type)
118 struct hid_collection *collection;
119 unsigned usage;
121 usage = parser->local.usage[0];
123 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
124 dbg_hid("collection stack overflow\n");
125 return -1;
128 if (parser->device->maxcollection == parser->device->collection_size) {
129 collection = kmalloc(sizeof(struct hid_collection) *
130 parser->device->collection_size * 2, GFP_KERNEL);
131 if (collection == NULL) {
132 dbg_hid("failed to reallocate collection array\n");
133 return -1;
135 memcpy(collection, parser->device->collection,
136 sizeof(struct hid_collection) *
137 parser->device->collection_size);
138 memset(collection + parser->device->collection_size, 0,
139 sizeof(struct hid_collection) *
140 parser->device->collection_size);
141 kfree(parser->device->collection);
142 parser->device->collection = collection;
143 parser->device->collection_size *= 2;
146 parser->collection_stack[parser->collection_stack_ptr++] =
147 parser->device->maxcollection;
149 collection = parser->device->collection +
150 parser->device->maxcollection++;
151 collection->type = type;
152 collection->usage = usage;
153 collection->level = parser->collection_stack_ptr - 1;
155 if (type == HID_COLLECTION_APPLICATION)
156 parser->device->maxapplication++;
158 return 0;
162 * Close a collection.
165 static int close_collection(struct hid_parser *parser)
167 if (!parser->collection_stack_ptr) {
168 dbg_hid("collection stack underflow\n");
169 return -1;
171 parser->collection_stack_ptr--;
172 return 0;
176 * Climb up the stack, search for the specified collection type
177 * and return the usage.
180 static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
182 struct hid_collection *collection = parser->device->collection;
183 int n;
185 for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
186 unsigned index = parser->collection_stack[n];
187 if (collection[index].type == type)
188 return collection[index].usage;
190 return 0; /* we know nothing about this usage type */
194 * Add a usage to the temporary parser table.
197 static int hid_add_usage(struct hid_parser *parser, unsigned usage)
199 if (parser->local.usage_index >= HID_MAX_USAGES) {
200 dbg_hid("usage index exceeded\n");
201 return -1;
203 parser->local.usage[parser->local.usage_index] = usage;
204 parser->local.collection_index[parser->local.usage_index] =
205 parser->collection_stack_ptr ?
206 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
207 parser->local.usage_index++;
208 return 0;
212 * Register a new field for this report.
215 static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
217 struct hid_report *report;
218 struct hid_field *field;
219 int usages;
220 unsigned offset;
221 int i;
223 report = hid_register_report(parser->device, report_type, parser->global.report_id);
224 if (!report) {
225 dbg_hid("hid_register_report failed\n");
226 return -1;
229 if (parser->global.logical_maximum < parser->global.logical_minimum) {
230 dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
231 return -1;
234 offset = report->size;
235 report->size += parser->global.report_size * parser->global.report_count;
237 if (!parser->local.usage_index) /* Ignore padding fields */
238 return 0;
240 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
242 field = hid_register_field(report, usages, parser->global.report_count);
243 if (!field)
244 return 0;
246 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
247 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
248 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
250 for (i = 0; i < usages; i++) {
251 int j = i;
252 /* Duplicate the last usage we parsed if we have excess values */
253 if (i >= parser->local.usage_index)
254 j = parser->local.usage_index - 1;
255 field->usage[i].hid = parser->local.usage[j];
256 field->usage[i].collection_index =
257 parser->local.collection_index[j];
260 field->maxusage = usages;
261 field->flags = flags;
262 field->report_offset = offset;
263 field->report_type = report_type;
264 field->report_size = parser->global.report_size;
265 field->report_count = parser->global.report_count;
266 field->logical_minimum = parser->global.logical_minimum;
267 field->logical_maximum = parser->global.logical_maximum;
268 field->physical_minimum = parser->global.physical_minimum;
269 field->physical_maximum = parser->global.physical_maximum;
270 field->unit_exponent = parser->global.unit_exponent;
271 field->unit = parser->global.unit;
273 return 0;
277 * Read data value from item.
280 static u32 item_udata(struct hid_item *item)
282 switch (item->size) {
283 case 1: return item->data.u8;
284 case 2: return item->data.u16;
285 case 4: return item->data.u32;
287 return 0;
290 static s32 item_sdata(struct hid_item *item)
292 switch (item->size) {
293 case 1: return item->data.s8;
294 case 2: return item->data.s16;
295 case 4: return item->data.s32;
297 return 0;
301 * Process a global item.
304 static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
306 switch (item->tag) {
307 case HID_GLOBAL_ITEM_TAG_PUSH:
309 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
310 dbg_hid("global environment stack overflow\n");
311 return -1;
314 memcpy(parser->global_stack + parser->global_stack_ptr++,
315 &parser->global, sizeof(struct hid_global));
316 return 0;
318 case HID_GLOBAL_ITEM_TAG_POP:
320 if (!parser->global_stack_ptr) {
321 dbg_hid("global environment stack underflow\n");
322 return -1;
325 memcpy(&parser->global, parser->global_stack +
326 --parser->global_stack_ptr, sizeof(struct hid_global));
327 return 0;
329 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
330 parser->global.usage_page = item_udata(item);
331 return 0;
333 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
334 parser->global.logical_minimum = item_sdata(item);
335 return 0;
337 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
338 if (parser->global.logical_minimum < 0)
339 parser->global.logical_maximum = item_sdata(item);
340 else
341 parser->global.logical_maximum = item_udata(item);
342 return 0;
344 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
345 parser->global.physical_minimum = item_sdata(item);
346 return 0;
348 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
349 if (parser->global.physical_minimum < 0)
350 parser->global.physical_maximum = item_sdata(item);
351 else
352 parser->global.physical_maximum = item_udata(item);
353 return 0;
355 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
356 parser->global.unit_exponent = item_sdata(item);
357 return 0;
359 case HID_GLOBAL_ITEM_TAG_UNIT:
360 parser->global.unit = item_udata(item);
361 return 0;
363 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
364 parser->global.report_size = item_udata(item);
365 if (parser->global.report_size > 32) {
366 dbg_hid("invalid report_size %d\n",
367 parser->global.report_size);
368 return -1;
370 return 0;
372 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
373 parser->global.report_count = item_udata(item);
374 if (parser->global.report_count > HID_MAX_USAGES) {
375 dbg_hid("invalid report_count %d\n",
376 parser->global.report_count);
377 return -1;
379 return 0;
381 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
382 parser->global.report_id = item_udata(item);
383 if (parser->global.report_id == 0) {
384 dbg_hid("report_id 0 is invalid\n");
385 return -1;
387 return 0;
389 default:
390 dbg_hid("unknown global tag 0x%x\n", item->tag);
391 return -1;
396 * Process a local item.
399 static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
401 __u32 data;
402 unsigned n;
404 data = item_udata(item);
406 switch (item->tag) {
407 case HID_LOCAL_ITEM_TAG_DELIMITER:
409 if (data) {
411 * We treat items before the first delimiter
412 * as global to all usage sets (branch 0).
413 * In the moment we process only these global
414 * items and the first delimiter set.
416 if (parser->local.delimiter_depth != 0) {
417 dbg_hid("nested delimiters\n");
418 return -1;
420 parser->local.delimiter_depth++;
421 parser->local.delimiter_branch++;
422 } else {
423 if (parser->local.delimiter_depth < 1) {
424 dbg_hid("bogus close delimiter\n");
425 return -1;
427 parser->local.delimiter_depth--;
429 return 1;
431 case HID_LOCAL_ITEM_TAG_USAGE:
433 if (parser->local.delimiter_branch > 1) {
434 dbg_hid("alternative usage ignored\n");
435 return 0;
438 if (item->size <= 2)
439 data = (parser->global.usage_page << 16) + data;
441 return hid_add_usage(parser, data);
443 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
445 if (parser->local.delimiter_branch > 1) {
446 dbg_hid("alternative usage ignored\n");
447 return 0;
450 if (item->size <= 2)
451 data = (parser->global.usage_page << 16) + data;
453 parser->local.usage_minimum = data;
454 return 0;
456 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
458 if (parser->local.delimiter_branch > 1) {
459 dbg_hid("alternative usage ignored\n");
460 return 0;
463 if (item->size <= 2)
464 data = (parser->global.usage_page << 16) + data;
466 for (n = parser->local.usage_minimum; n <= data; n++)
467 if (hid_add_usage(parser, n)) {
468 dbg_hid("hid_add_usage failed\n");
469 return -1;
471 return 0;
473 default:
475 dbg_hid("unknown local item tag 0x%x\n", item->tag);
476 return 0;
478 return 0;
482 * Process a main item.
485 static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
487 __u32 data;
488 int ret;
490 data = item_udata(item);
492 switch (item->tag) {
493 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
494 ret = open_collection(parser, data & 0xff);
495 break;
496 case HID_MAIN_ITEM_TAG_END_COLLECTION:
497 ret = close_collection(parser);
498 break;
499 case HID_MAIN_ITEM_TAG_INPUT:
500 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
501 break;
502 case HID_MAIN_ITEM_TAG_OUTPUT:
503 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
504 break;
505 case HID_MAIN_ITEM_TAG_FEATURE:
506 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
507 break;
508 default:
509 dbg_hid("unknown main item tag 0x%x\n", item->tag);
510 ret = 0;
513 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
515 return ret;
519 * Process a reserved item.
522 static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
524 dbg_hid("reserved item type, tag 0x%x\n", item->tag);
525 return 0;
529 * Free a report and all registered fields. The field->usage and
530 * field->value table's are allocated behind the field, so we need
531 * only to free(field) itself.
534 static void hid_free_report(struct hid_report *report)
536 unsigned n;
538 for (n = 0; n < report->maxfield; n++)
539 kfree(report->field[n]);
540 kfree(report);
544 * Free a device structure, all reports, and all fields.
547 static void hid_device_release(struct device *dev)
549 struct hid_device *device = container_of(dev, struct hid_device, dev);
550 unsigned i, j;
552 for (i = 0; i < HID_REPORT_TYPES; i++) {
553 struct hid_report_enum *report_enum = device->report_enum + i;
555 for (j = 0; j < 256; j++) {
556 struct hid_report *report = report_enum->report_id_hash[j];
557 if (report)
558 hid_free_report(report);
562 kfree(device->rdesc);
563 kfree(device->collection);
564 kfree(device);
568 * Fetch a report description item from the data stream. We support long
569 * items, though they are not used yet.
572 static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
574 u8 b;
576 if ((end - start) <= 0)
577 return NULL;
579 b = *start++;
581 item->type = (b >> 2) & 3;
582 item->tag = (b >> 4) & 15;
584 if (item->tag == HID_ITEM_TAG_LONG) {
586 item->format = HID_ITEM_FORMAT_LONG;
588 if ((end - start) < 2)
589 return NULL;
591 item->size = *start++;
592 item->tag = *start++;
594 if ((end - start) < item->size)
595 return NULL;
597 item->data.longdata = start;
598 start += item->size;
599 return start;
602 item->format = HID_ITEM_FORMAT_SHORT;
603 item->size = b & 3;
605 switch (item->size) {
606 case 0:
607 return start;
609 case 1:
610 if ((end - start) < 1)
611 return NULL;
612 item->data.u8 = *start++;
613 return start;
615 case 2:
616 if ((end - start) < 2)
617 return NULL;
618 item->data.u16 = get_unaligned_le16(start);
619 start = (__u8 *)((__le16 *)start + 1);
620 return start;
622 case 3:
623 item->size++;
624 if ((end - start) < 4)
625 return NULL;
626 item->data.u32 = get_unaligned_le32(start);
627 start = (__u8 *)((__le32 *)start + 1);
628 return start;
631 return NULL;
635 * hid_parse_report - parse device report
637 * @device: hid device
638 * @start: report start
639 * @size: report size
641 * Parse a report description into a hid_device structure. Reports are
642 * enumerated, fields are attached to these reports.
643 * 0 returned on success, otherwise nonzero error value.
645 int hid_parse_report(struct hid_device *device, __u8 *start,
646 unsigned size)
648 struct hid_parser *parser;
649 struct hid_item item;
650 __u8 *end;
651 int ret;
652 static int (*dispatch_type[])(struct hid_parser *parser,
653 struct hid_item *item) = {
654 hid_parser_main,
655 hid_parser_global,
656 hid_parser_local,
657 hid_parser_reserved
660 if (device->driver->report_fixup)
661 start = device->driver->report_fixup(device, start, &size);
663 device->rdesc = kmemdup(start, size, GFP_KERNEL);
664 if (device->rdesc == NULL)
665 return -ENOMEM;
666 device->rsize = size;
668 parser = vzalloc(sizeof(struct hid_parser));
669 if (!parser) {
670 ret = -ENOMEM;
671 goto err;
674 parser->device = device;
676 end = start + size;
677 ret = -EINVAL;
678 while ((start = fetch_item(start, end, &item)) != NULL) {
680 if (item.format != HID_ITEM_FORMAT_SHORT) {
681 dbg_hid("unexpected long global item\n");
682 goto err;
685 if (dispatch_type[item.type](parser, &item)) {
686 dbg_hid("item %u %u %u %u parsing failed\n",
687 item.format, (unsigned)item.size,
688 (unsigned)item.type, (unsigned)item.tag);
689 goto err;
692 if (start == end) {
693 if (parser->collection_stack_ptr) {
694 dbg_hid("unbalanced collection at end of report description\n");
695 goto err;
697 if (parser->local.delimiter_depth) {
698 dbg_hid("unbalanced delimiter at end of report description\n");
699 goto err;
701 vfree(parser);
702 return 0;
706 dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
707 err:
708 vfree(parser);
709 return ret;
711 EXPORT_SYMBOL_GPL(hid_parse_report);
714 * Convert a signed n-bit integer to signed 32-bit integer. Common
715 * cases are done through the compiler, the screwed things has to be
716 * done by hand.
719 static s32 snto32(__u32 value, unsigned n)
721 switch (n) {
722 case 8: return ((__s8)value);
723 case 16: return ((__s16)value);
724 case 32: return ((__s32)value);
726 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
730 * Convert a signed 32-bit integer to a signed n-bit integer.
733 static u32 s32ton(__s32 value, unsigned n)
735 s32 a = value >> (n - 1);
736 if (a && a != -1)
737 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
738 return value & ((1 << n) - 1);
742 * Extract/implement a data field from/to a little endian report (bit array).
744 * Code sort-of follows HID spec:
745 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
747 * While the USB HID spec allows unlimited length bit fields in "report
748 * descriptors", most devices never use more than 16 bits.
749 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
750 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
753 static __u32 extract(const struct hid_device *hid, __u8 *report,
754 unsigned offset, unsigned n)
756 u64 x;
758 if (n > 32)
759 hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
760 n, current->comm);
762 report += offset >> 3; /* adjust byte index */
763 offset &= 7; /* now only need bit offset into one byte */
764 x = get_unaligned_le64(report);
765 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
766 return (u32) x;
770 * "implement" : set bits in a little endian bit stream.
771 * Same concepts as "extract" (see comments above).
772 * The data mangled in the bit stream remains in little endian
773 * order the whole time. It make more sense to talk about
774 * endianness of register values by considering a register
775 * a "cached" copy of the little endiad bit stream.
777 static void implement(const struct hid_device *hid, __u8 *report,
778 unsigned offset, unsigned n, __u32 value)
780 u64 x;
781 u64 m = (1ULL << n) - 1;
783 if (n > 32)
784 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
785 __func__, n, current->comm);
787 if (value > m)
788 hid_warn(hid, "%s() called with too large value %d! (%s)\n",
789 __func__, value, current->comm);
790 WARN_ON(value > m);
791 value &= m;
793 report += offset >> 3;
794 offset &= 7;
796 x = get_unaligned_le64(report);
797 x &= ~(m << offset);
798 x |= ((u64)value) << offset;
799 put_unaligned_le64(x, report);
803 * Search an array for a value.
806 static int search(__s32 *array, __s32 value, unsigned n)
808 while (n--) {
809 if (*array++ == value)
810 return 0;
812 return -1;
816 * hid_match_report - check if driver's raw_event should be called
818 * @hid: hid device
819 * @report_type: type to match against
821 * compare hid->driver->report_table->report_type to report->type
823 static int hid_match_report(struct hid_device *hid, struct hid_report *report)
825 const struct hid_report_id *id = hid->driver->report_table;
827 if (!id) /* NULL means all */
828 return 1;
830 for (; id->report_type != HID_TERMINATOR; id++)
831 if (id->report_type == HID_ANY_ID ||
832 id->report_type == report->type)
833 return 1;
834 return 0;
838 * hid_match_usage - check if driver's event should be called
840 * @hid: hid device
841 * @usage: usage to match against
843 * compare hid->driver->usage_table->usage_{type,code} to
844 * usage->usage_{type,code}
846 static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
848 const struct hid_usage_id *id = hid->driver->usage_table;
850 if (!id) /* NULL means all */
851 return 1;
853 for (; id->usage_type != HID_ANY_ID - 1; id++)
854 if ((id->usage_hid == HID_ANY_ID ||
855 id->usage_hid == usage->hid) &&
856 (id->usage_type == HID_ANY_ID ||
857 id->usage_type == usage->type) &&
858 (id->usage_code == HID_ANY_ID ||
859 id->usage_code == usage->code))
860 return 1;
861 return 0;
864 static void hid_process_event(struct hid_device *hid, struct hid_field *field,
865 struct hid_usage *usage, __s32 value, int interrupt)
867 struct hid_driver *hdrv = hid->driver;
868 int ret;
870 hid_dump_input(hid, usage, value);
872 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
873 ret = hdrv->event(hid, field, usage, value);
874 if (ret != 0) {
875 if (ret < 0)
876 dbg_hid("%s's event failed with %d\n",
877 hdrv->name, ret);
878 return;
882 if (hid->claimed & HID_CLAIMED_INPUT)
883 hidinput_hid_event(hid, field, usage, value);
884 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
885 hid->hiddev_hid_event(hid, field, usage, value);
889 * Analyse a received field, and fetch the data from it. The field
890 * content is stored for next report processing (we do differential
891 * reporting to the layer).
894 static void hid_input_field(struct hid_device *hid, struct hid_field *field,
895 __u8 *data, int interrupt)
897 unsigned n;
898 unsigned count = field->report_count;
899 unsigned offset = field->report_offset;
900 unsigned size = field->report_size;
901 __s32 min = field->logical_minimum;
902 __s32 max = field->logical_maximum;
903 __s32 *value;
905 value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
906 if (!value)
907 return;
909 for (n = 0; n < count; n++) {
911 value[n] = min < 0 ?
912 snto32(extract(hid, data, offset + n * size, size),
913 size) :
914 extract(hid, data, offset + n * size, size);
916 /* Ignore report if ErrorRollOver */
917 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
918 value[n] >= min && value[n] <= max &&
919 field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
920 goto exit;
923 for (n = 0; n < count; n++) {
925 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
926 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
927 continue;
930 if (field->value[n] >= min && field->value[n] <= max
931 && field->usage[field->value[n] - min].hid
932 && search(value, field->value[n], count))
933 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
935 if (value[n] >= min && value[n] <= max
936 && field->usage[value[n] - min].hid
937 && search(field->value, value[n], count))
938 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
941 memcpy(field->value, value, count * sizeof(__s32));
942 exit:
943 kfree(value);
947 * Output the field into the report.
950 static void hid_output_field(const struct hid_device *hid,
951 struct hid_field *field, __u8 *data)
953 unsigned count = field->report_count;
954 unsigned offset = field->report_offset;
955 unsigned size = field->report_size;
956 unsigned n;
958 for (n = 0; n < count; n++) {
959 if (field->logical_minimum < 0) /* signed values */
960 implement(hid, data, offset + n * size, size,
961 s32ton(field->value[n], size));
962 else /* unsigned values */
963 implement(hid, data, offset + n * size, size,
964 field->value[n]);
969 * Create a report.
972 void hid_output_report(struct hid_report *report, __u8 *data)
974 unsigned n;
976 if (report->id > 0)
977 *data++ = report->id;
979 memset(data, 0, ((report->size - 1) >> 3) + 1);
980 for (n = 0; n < report->maxfield; n++)
981 hid_output_field(report->device, report->field[n], data);
983 EXPORT_SYMBOL_GPL(hid_output_report);
986 * Set a field value. The report this field belongs to has to be
987 * created and transferred to the device, to set this value in the
988 * device.
991 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
993 unsigned size = field->report_size;
995 hid_dump_input(field->report->device, field->usage + offset, value);
997 if (offset >= field->report_count) {
998 dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
999 return -1;
1001 if (field->logical_minimum < 0) {
1002 if (value != snto32(s32ton(value, size), size)) {
1003 dbg_hid("value %d is out of range\n", value);
1004 return -1;
1007 field->value[offset] = value;
1008 return 0;
1010 EXPORT_SYMBOL_GPL(hid_set_field);
1012 static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1013 const u8 *data)
1015 struct hid_report *report;
1016 unsigned int n = 0; /* Normally report number is 0 */
1018 /* Device uses numbered reports, data[0] is report number */
1019 if (report_enum->numbered)
1020 n = *data;
1022 report = report_enum->report_id_hash[n];
1023 if (report == NULL)
1024 dbg_hid("undefined report_id %u received\n", n);
1026 return report;
1029 void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1030 int interrupt)
1032 struct hid_report_enum *report_enum = hid->report_enum + type;
1033 struct hid_report *report;
1034 unsigned int a;
1035 int rsize, csize = size;
1036 u8 *cdata = data;
1038 report = hid_get_report(report_enum, data);
1039 if (!report)
1040 return;
1042 if (report_enum->numbered) {
1043 cdata++;
1044 csize--;
1047 rsize = ((report->size - 1) >> 3) + 1;
1049 if (rsize > HID_MAX_BUFFER_SIZE)
1050 rsize = HID_MAX_BUFFER_SIZE;
1052 if (csize < rsize) {
1053 dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1054 csize, rsize);
1055 memset(cdata + csize, 0, rsize - csize);
1058 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1059 hid->hiddev_report_event(hid, report);
1060 if (hid->claimed & HID_CLAIMED_HIDRAW)
1061 hidraw_report_event(hid, data, size);
1063 for (a = 0; a < report->maxfield; a++)
1064 hid_input_field(hid, report->field[a], cdata, interrupt);
1066 if (hid->claimed & HID_CLAIMED_INPUT)
1067 hidinput_report_event(hid, report);
1069 EXPORT_SYMBOL_GPL(hid_report_raw_event);
1072 * hid_input_report - report data from lower layer (usb, bt...)
1074 * @hid: hid device
1075 * @type: HID report type (HID_*_REPORT)
1076 * @data: report contents
1077 * @size: size of data parameter
1078 * @interrupt: distinguish between interrupt and control transfers
1080 * This is data entry for lower layers.
1082 int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1084 struct hid_report_enum *report_enum;
1085 struct hid_driver *hdrv;
1086 struct hid_report *report;
1087 char *buf;
1088 unsigned int i;
1089 int ret = 0;
1091 if (!hid)
1092 return -ENODEV;
1094 if (down_trylock(&hid->driver_lock))
1095 return -EBUSY;
1097 if (!hid->driver) {
1098 ret = -ENODEV;
1099 goto unlock;
1101 report_enum = hid->report_enum + type;
1102 hdrv = hid->driver;
1104 if (!size) {
1105 dbg_hid("empty report\n");
1106 ret = -1;
1107 goto unlock;
1110 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1112 if (!buf)
1113 goto nomem;
1115 /* dump the report */
1116 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1117 "\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
1118 hid_debug_event(hid, buf);
1120 for (i = 0; i < size; i++) {
1121 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1122 " %02x", data[i]);
1123 hid_debug_event(hid, buf);
1125 hid_debug_event(hid, "\n");
1126 kfree(buf);
1128 nomem:
1129 report = hid_get_report(report_enum, data);
1131 if (!report) {
1132 ret = -1;
1133 goto unlock;
1136 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1137 ret = hdrv->raw_event(hid, report, data, size);
1138 if (ret != 0) {
1139 ret = ret < 0 ? ret : 0;
1140 goto unlock;
1144 hid_report_raw_event(hid, type, data, size, interrupt);
1146 unlock:
1147 up(&hid->driver_lock);
1148 return ret;
1150 EXPORT_SYMBOL_GPL(hid_input_report);
1152 static bool hid_match_one_id(struct hid_device *hdev,
1153 const struct hid_device_id *id)
1155 return id->bus == hdev->bus &&
1156 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1157 (id->product == HID_ANY_ID || id->product == hdev->product);
1160 static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1161 const struct hid_device_id *id)
1163 for (; id->bus; id++)
1164 if (hid_match_one_id(hdev, id))
1165 return id;
1167 return NULL;
1170 static const struct hid_device_id hid_hiddev_list[] = {
1171 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1172 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
1176 static bool hid_hiddev(struct hid_device *hdev)
1178 return !!hid_match_id(hdev, hid_hiddev_list);
1182 static ssize_t
1183 read_report_descriptor(struct file *filp, struct kobject *kobj,
1184 struct bin_attribute *attr,
1185 char *buf, loff_t off, size_t count)
1187 struct device *dev = container_of(kobj, struct device, kobj);
1188 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1190 if (off >= hdev->rsize)
1191 return 0;
1193 if (off + count > hdev->rsize)
1194 count = hdev->rsize - off;
1196 memcpy(buf, hdev->rdesc + off, count);
1198 return count;
1201 static struct bin_attribute dev_bin_attr_report_desc = {
1202 .attr = { .name = "report_descriptor", .mode = 0444 },
1203 .read = read_report_descriptor,
1204 .size = HID_MAX_DESCRIPTOR_SIZE,
1207 int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1209 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1210 "Joystick", "Gamepad", "Keyboard", "Keypad",
1211 "Multi-Axis Controller"
1213 const char *type, *bus;
1214 char buf[64];
1215 unsigned int i;
1216 int len;
1217 int ret;
1219 if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1220 connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
1221 if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
1222 connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
1223 if (hdev->bus != BUS_USB)
1224 connect_mask &= ~HID_CONNECT_HIDDEV;
1225 if (hid_hiddev(hdev))
1226 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
1228 if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1229 connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1230 hdev->claimed |= HID_CLAIMED_INPUT;
1231 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1232 !hdev->hiddev_connect(hdev,
1233 connect_mask & HID_CONNECT_HIDDEV_FORCE))
1234 hdev->claimed |= HID_CLAIMED_HIDDEV;
1235 if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1236 hdev->claimed |= HID_CLAIMED_HIDRAW;
1238 if (!hdev->claimed) {
1239 hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
1240 return -ENODEV;
1243 if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1244 (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1245 hdev->ff_init(hdev);
1247 len = 0;
1248 if (hdev->claimed & HID_CLAIMED_INPUT)
1249 len += sprintf(buf + len, "input");
1250 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1251 len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1252 hdev->minor);
1253 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1254 len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1255 ((struct hidraw *)hdev->hidraw)->minor);
1257 type = "Device";
1258 for (i = 0; i < hdev->maxcollection; i++) {
1259 struct hid_collection *col = &hdev->collection[i];
1260 if (col->type == HID_COLLECTION_APPLICATION &&
1261 (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1262 (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1263 type = types[col->usage & 0xffff];
1264 break;
1268 switch (hdev->bus) {
1269 case BUS_USB:
1270 bus = "USB";
1271 break;
1272 case BUS_BLUETOOTH:
1273 bus = "BLUETOOTH";
1274 break;
1275 default:
1276 bus = "<UNKNOWN>";
1279 ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1280 if (ret)
1281 hid_warn(hdev,
1282 "can't create sysfs report descriptor attribute err: %d\n", ret);
1284 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1285 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1286 type, hdev->name, hdev->phys);
1288 return 0;
1290 EXPORT_SYMBOL_GPL(hid_connect);
1292 void hid_disconnect(struct hid_device *hdev)
1294 device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1295 if (hdev->claimed & HID_CLAIMED_INPUT)
1296 hidinput_disconnect(hdev);
1297 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1298 hdev->hiddev_disconnect(hdev);
1299 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1300 hidraw_disconnect(hdev);
1302 EXPORT_SYMBOL_GPL(hid_disconnect);
1304 /* a list of devices for which there is a specialized driver on HID bus */
1305 static const struct hid_device_id hid_have_special_driver[] = {
1306 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
1307 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
1308 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1309 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1310 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1311 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1312 { HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, USB_DEVICE_ID_ACTIONSTAR_1011) },
1313 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
1314 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1315 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1316 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1317 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
1318 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1319 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1320 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1321 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1322 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1323 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1324 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1325 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1327 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1328 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1330 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1331 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
1332 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1333 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1338 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1339 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1340 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1344 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1345 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1346 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1348 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1349 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1350 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1351 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1352 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1353 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1354 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1355 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1356 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1357 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1358 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1359 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1360 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1361 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
1362 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
1363 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
1364 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
1365 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1366 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1367 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1368 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1369 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1370 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1371 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1372 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1373 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1374 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
1375 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1376 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1377 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
1378 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1379 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1380 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1381 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1382 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1383 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
1384 { HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1385 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
1386 { HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, USB_DEVICE_ID_CVTOUCH_SCREEN) },
1387 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1388 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1389 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
1390 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1391 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
1392 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1393 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
1394 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
1395 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
1396 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) },
1397 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) },
1398 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) },
1399 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1400 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) },
1401 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
1402 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1403 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1404 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
1405 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1406 { HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, USB_DEVICE_ID_GOODTOUCH_000f) },
1407 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
1408 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1409 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
1410 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1411 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
1414 { HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1415 { HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1416 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1417 { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
1418 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1419 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
1420 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
1421 { HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MULTITOUCH) },
1422 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1423 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1424 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1425 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1426 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1427 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1428 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
1429 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1430 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
1431 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1432 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
1433 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1434 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1435 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1436 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1437 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1438 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
1439 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1440 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1441 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1442 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1443 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1444 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
1445 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1446 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
1447 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
1448 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1449 { HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH) },
1450 { HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
1451 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1452 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
1453 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
1454 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1455 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1456 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1457 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1458 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
1459 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1460 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1461 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
1462 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
1463 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
1464 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
1465 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
1466 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
1467 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
1468 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
1469 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
1470 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
1471 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
1472 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
1473 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
1474 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
1475 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
1476 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
1477 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
1478 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
1479 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1480 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1481 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
1482 { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) },
1483 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1484 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1485 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
1486 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1487 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1488 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
1489 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
1490 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
1491 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
1492 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1493 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1494 { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1495 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1496 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1497 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1498 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1499 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1500 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1501 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
1502 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1503 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1504 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
1505 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
1506 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1507 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
1508 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1509 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1510 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1511 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
1512 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1513 { HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1514 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
1515 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1516 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1517 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1518 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1519 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
1520 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1521 { HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1522 { HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
1523 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1524 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
1525 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
1526 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
1527 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
1528 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
1529 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1530 { HID_USB_DEVICE(USB_VENDOR_ID_XAT, USB_DEVICE_ID_XAT_CSR) },
1531 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1532 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1533 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1534 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
1536 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
1537 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1541 struct hid_dynid {
1542 struct list_head list;
1543 struct hid_device_id id;
1547 * store_new_id - add a new HID device ID to this driver and re-probe devices
1548 * @driver: target device driver
1549 * @buf: buffer for scanning device ID data
1550 * @count: input size
1552 * Adds a new dynamic hid device ID to this driver,
1553 * and causes the driver to probe for all devices again.
1555 static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1556 size_t count)
1558 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1559 struct hid_dynid *dynid;
1560 __u32 bus, vendor, product;
1561 unsigned long driver_data = 0;
1562 int ret;
1564 ret = sscanf(buf, "%x %x %x %lx",
1565 &bus, &vendor, &product, &driver_data);
1566 if (ret < 3)
1567 return -EINVAL;
1569 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
1570 if (!dynid)
1571 return -ENOMEM;
1573 dynid->id.bus = bus;
1574 dynid->id.vendor = vendor;
1575 dynid->id.product = product;
1576 dynid->id.driver_data = driver_data;
1578 spin_lock(&hdrv->dyn_lock);
1579 list_add_tail(&dynid->list, &hdrv->dyn_list);
1580 spin_unlock(&hdrv->dyn_lock);
1582 ret = 0;
1583 if (get_driver(&hdrv->driver)) {
1584 ret = driver_attach(&hdrv->driver);
1585 put_driver(&hdrv->driver);
1588 return ret ? : count;
1590 static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
1592 static void hid_free_dynids(struct hid_driver *hdrv)
1594 struct hid_dynid *dynid, *n;
1596 spin_lock(&hdrv->dyn_lock);
1597 list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
1598 list_del(&dynid->list);
1599 kfree(dynid);
1601 spin_unlock(&hdrv->dyn_lock);
1604 static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
1605 struct hid_driver *hdrv)
1607 struct hid_dynid *dynid;
1609 spin_lock(&hdrv->dyn_lock);
1610 list_for_each_entry(dynid, &hdrv->dyn_list, list) {
1611 if (hid_match_one_id(hdev, &dynid->id)) {
1612 spin_unlock(&hdrv->dyn_lock);
1613 return &dynid->id;
1616 spin_unlock(&hdrv->dyn_lock);
1618 return hid_match_id(hdev, hdrv->id_table);
1621 static int hid_bus_match(struct device *dev, struct device_driver *drv)
1623 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1624 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1626 if (!hid_match_device(hdev, hdrv))
1627 return 0;
1629 /* generic wants all that don't have specialized driver */
1630 if (!strncmp(hdrv->name, "generic-", 8))
1631 return !hid_match_id(hdev, hid_have_special_driver);
1633 return 1;
1636 static int hid_device_probe(struct device *dev)
1638 struct hid_driver *hdrv = container_of(dev->driver,
1639 struct hid_driver, driver);
1640 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1641 const struct hid_device_id *id;
1642 int ret = 0;
1644 if (down_interruptible(&hdev->driver_lock))
1645 return -EINTR;
1647 if (!hdev->driver) {
1648 id = hid_match_device(hdev, hdrv);
1649 if (id == NULL) {
1650 ret = -ENODEV;
1651 goto unlock;
1654 hdev->driver = hdrv;
1655 if (hdrv->probe) {
1656 ret = hdrv->probe(hdev, id);
1657 } else { /* default probe */
1658 ret = hid_parse(hdev);
1659 if (!ret)
1660 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1662 if (ret)
1663 hdev->driver = NULL;
1665 unlock:
1666 up(&hdev->driver_lock);
1667 return ret;
1670 static int hid_device_remove(struct device *dev)
1672 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1673 struct hid_driver *hdrv;
1675 if (down_interruptible(&hdev->driver_lock))
1676 return -EINTR;
1678 hdrv = hdev->driver;
1679 if (hdrv) {
1680 if (hdrv->remove)
1681 hdrv->remove(hdev);
1682 else /* default remove */
1683 hid_hw_stop(hdev);
1684 hdev->driver = NULL;
1687 up(&hdev->driver_lock);
1688 return 0;
1691 static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1693 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1695 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1696 hdev->bus, hdev->vendor, hdev->product))
1697 return -ENOMEM;
1699 if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1700 return -ENOMEM;
1702 if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1703 return -ENOMEM;
1705 if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1706 return -ENOMEM;
1708 if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
1709 hdev->bus, hdev->vendor, hdev->product))
1710 return -ENOMEM;
1712 return 0;
1715 static struct bus_type hid_bus_type = {
1716 .name = "hid",
1717 .match = hid_bus_match,
1718 .probe = hid_device_probe,
1719 .remove = hid_device_remove,
1720 .uevent = hid_uevent,
1723 /* a list of devices that shouldn't be handled by HID core at all */
1724 static const struct hid_device_id hid_ignore_list[] = {
1725 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1726 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1727 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1728 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1729 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1730 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1731 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1732 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1733 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1734 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1735 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1736 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
1737 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1738 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
1739 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1740 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1741 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1742 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1743 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1744 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1745 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
1746 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1747 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1748 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1749 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
1750 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
1751 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1752 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1753 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1754 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1755 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1756 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1757 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1758 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1759 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1760 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1761 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1762 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1763 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1764 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1765 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1766 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1767 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1768 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1769 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1770 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1771 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1772 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1773 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1774 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1775 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1776 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1777 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1778 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1779 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1780 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1781 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1782 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1783 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1784 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1785 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1786 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1787 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1788 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1789 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1790 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1791 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1792 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1793 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1794 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1795 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1796 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1797 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1798 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1799 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1800 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1801 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1802 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1803 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1804 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1805 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1806 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1807 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1808 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1809 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1810 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1811 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1812 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1813 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1814 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1815 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1816 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1817 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1818 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1819 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1820 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1821 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1822 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
1823 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1824 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
1825 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1826 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
1827 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
1828 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
1829 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
1830 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
1831 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
1832 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1833 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1834 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1835 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
1836 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
1837 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
1838 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1839 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1840 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
1841 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1842 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1843 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1844 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1845 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1846 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
1847 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
1848 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
1849 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
1850 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
1851 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
1852 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
1853 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1854 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1855 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1856 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1857 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1858 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1859 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1860 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1861 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1862 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1863 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1864 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1865 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1866 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1867 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1868 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1869 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1870 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1871 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
1872 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
1873 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1874 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1875 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1876 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1877 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1878 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1879 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1880 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1881 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1882 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1883 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1888 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1890 * There are composite devices for which we want to ignore only a certain
1891 * interface. This is a list of devices for which only the mouse interface will
1892 * be ignored. This allows a dedicated driver to take care of the interface.
1894 static const struct hid_device_id hid_mouse_ignore_list[] = {
1895 /* appletouch driver */
1896 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1897 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1898 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1899 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1900 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1901 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1902 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1903 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1904 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1905 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1906 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1907 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1908 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1909 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1910 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1911 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1912 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1913 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1914 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1915 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1916 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1917 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1918 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1919 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1920 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1921 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1922 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1923 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1924 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1925 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1926 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1927 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1928 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1929 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1933 static bool hid_ignore(struct hid_device *hdev)
1935 switch (hdev->vendor) {
1936 case USB_VENDOR_ID_CODEMERCS:
1937 /* ignore all Code Mercenaries IOWarrior devices */
1938 if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1939 hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1940 return true;
1941 break;
1942 case USB_VENDOR_ID_LOGITECH:
1943 if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1944 hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1945 return true;
1946 break;
1947 case USB_VENDOR_ID_SOUNDGRAPH:
1948 if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
1949 hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
1950 return true;
1951 break;
1952 case USB_VENDOR_ID_HANWANG:
1953 if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
1954 hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
1955 return true;
1956 break;
1957 case USB_VENDOR_ID_JESS:
1958 if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
1959 hdev->type == HID_TYPE_USBNONE)
1960 return true;
1961 break;
1964 if (hdev->type == HID_TYPE_USBMOUSE &&
1965 hid_match_id(hdev, hid_mouse_ignore_list))
1966 return true;
1968 return !!hid_match_id(hdev, hid_ignore_list);
1971 int hid_add_device(struct hid_device *hdev)
1973 static atomic_t id = ATOMIC_INIT(0);
1974 int ret;
1976 if (WARN_ON(hdev->status & HID_STAT_ADDED))
1977 return -EBUSY;
1979 /* we need to kill them here, otherwise they will stay allocated to
1980 * wait for coming driver */
1981 if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1982 && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
1983 return -ENODEV;
1985 /* XXX hack, any other cleaner solution after the driver core
1986 * is converted to allow more than 20 bytes as the device name? */
1987 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
1988 hdev->vendor, hdev->product, atomic_inc_return(&id));
1990 hid_debug_register(hdev, dev_name(&hdev->dev));
1991 ret = device_add(&hdev->dev);
1992 if (!ret)
1993 hdev->status |= HID_STAT_ADDED;
1994 else
1995 hid_debug_unregister(hdev);
1997 return ret;
1999 EXPORT_SYMBOL_GPL(hid_add_device);
2002 * hid_allocate_device - allocate new hid device descriptor
2004 * Allocate and initialize hid device, so that hid_destroy_device might be
2005 * used to free it.
2007 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
2008 * error value.
2010 struct hid_device *hid_allocate_device(void)
2012 struct hid_device *hdev;
2013 unsigned int i;
2014 int ret = -ENOMEM;
2016 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
2017 if (hdev == NULL)
2018 return ERR_PTR(ret);
2020 device_initialize(&hdev->dev);
2021 hdev->dev.release = hid_device_release;
2022 hdev->dev.bus = &hid_bus_type;
2024 hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
2025 sizeof(struct hid_collection), GFP_KERNEL);
2026 if (hdev->collection == NULL)
2027 goto err;
2028 hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
2030 for (i = 0; i < HID_REPORT_TYPES; i++)
2031 INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
2033 init_waitqueue_head(&hdev->debug_wait);
2034 INIT_LIST_HEAD(&hdev->debug_list);
2035 sema_init(&hdev->driver_lock, 1);
2037 return hdev;
2038 err:
2039 put_device(&hdev->dev);
2040 return ERR_PTR(ret);
2042 EXPORT_SYMBOL_GPL(hid_allocate_device);
2044 static void hid_remove_device(struct hid_device *hdev)
2046 if (hdev->status & HID_STAT_ADDED) {
2047 device_del(&hdev->dev);
2048 hid_debug_unregister(hdev);
2049 hdev->status &= ~HID_STAT_ADDED;
2054 * hid_destroy_device - free previously allocated device
2056 * @hdev: hid device
2058 * If you allocate hid_device through hid_allocate_device, you should ever
2059 * free by this function.
2061 void hid_destroy_device(struct hid_device *hdev)
2063 hid_remove_device(hdev);
2064 put_device(&hdev->dev);
2066 EXPORT_SYMBOL_GPL(hid_destroy_device);
2068 int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
2069 const char *mod_name)
2071 int ret;
2073 hdrv->driver.name = hdrv->name;
2074 hdrv->driver.bus = &hid_bus_type;
2075 hdrv->driver.owner = owner;
2076 hdrv->driver.mod_name = mod_name;
2078 INIT_LIST_HEAD(&hdrv->dyn_list);
2079 spin_lock_init(&hdrv->dyn_lock);
2081 ret = driver_register(&hdrv->driver);
2082 if (ret)
2083 return ret;
2085 ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
2086 if (ret)
2087 driver_unregister(&hdrv->driver);
2089 return ret;
2091 EXPORT_SYMBOL_GPL(__hid_register_driver);
2093 void hid_unregister_driver(struct hid_driver *hdrv)
2095 driver_remove_file(&hdrv->driver, &driver_attr_new_id);
2096 driver_unregister(&hdrv->driver);
2097 hid_free_dynids(hdrv);
2099 EXPORT_SYMBOL_GPL(hid_unregister_driver);
2101 int hid_check_keys_pressed(struct hid_device *hid)
2103 struct hid_input *hidinput;
2104 int i;
2106 if (!(hid->claimed & HID_CLAIMED_INPUT))
2107 return 0;
2109 list_for_each_entry(hidinput, &hid->inputs, list) {
2110 for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
2111 if (hidinput->input->key[i])
2112 return 1;
2115 return 0;
2118 EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
2120 static int __init hid_init(void)
2122 int ret;
2124 if (hid_debug)
2125 pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
2126 "debugfs is now used for inspecting the device (report descriptor, reports)\n");
2128 ret = bus_register(&hid_bus_type);
2129 if (ret) {
2130 pr_err("can't register hid bus\n");
2131 goto err;
2134 ret = hidraw_init();
2135 if (ret)
2136 goto err_bus;
2138 hid_debug_init();
2140 return 0;
2141 err_bus:
2142 bus_unregister(&hid_bus_type);
2143 err:
2144 return ret;
2147 static void __exit hid_exit(void)
2149 hid_debug_exit();
2150 hidraw_exit();
2151 bus_unregister(&hid_bus_type);
2154 module_init(hid_init);
2155 module_exit(hid_exit);
2157 MODULE_AUTHOR("Andreas Gal");
2158 MODULE_AUTHOR("Vojtech Pavlik");
2159 MODULE_AUTHOR("Jiri Kosina");
2160 MODULE_LICENSE(DRIVER_LICENSE);