2 * USB 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
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/list.h>
23 #include <linux/smp_lock.h>
24 #include <linux/spinlock.h>
25 #include <asm/unaligned.h>
26 #include <asm/byteorder.h>
27 #include <linux/input.h>
28 #include <linux/wait.h>
33 #include <linux/usb.h>
36 #include <linux/hiddev.h>
42 #define DRIVER_VERSION "v2.6"
43 #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
44 #define DRIVER_DESC "USB HID core driver"
45 #define DRIVER_LICENSE "GPL"
47 static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
48 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
53 static unsigned int hid_mousepoll_interval;
54 module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
55 MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
58 * Register a new report for a device.
61 static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
63 struct hid_report_enum *report_enum = device->report_enum + type;
64 struct hid_report *report;
66 if (report_enum->report_id_hash[id])
67 return report_enum->report_id_hash[id];
69 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
73 report_enum->numbered = 1;
78 report->device = device;
79 report_enum->report_id_hash[id] = report;
81 list_add_tail(&report->list, &report_enum->report_list);
87 * Register a new field for this report.
90 static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
92 struct hid_field *field;
94 if (report->maxfield == HID_MAX_FIELDS) {
95 dbg("too many fields in report");
99 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
100 + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
102 field->index = report->maxfield++;
103 report->field[field->index] = field;
104 field->usage = (struct hid_usage *)(field + 1);
105 field->value = (unsigned *)(field->usage + usages);
106 field->report = report;
112 * Open a collection. The type/usage is pushed on the stack.
115 static int open_collection(struct hid_parser *parser, unsigned type)
117 struct hid_collection *collection;
120 usage = parser->local.usage[0];
122 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
123 dbg("collection stack overflow");
127 if (parser->device->maxcollection == parser->device->collection_size) {
128 collection = kmalloc(sizeof(struct hid_collection) *
129 parser->device->collection_size * 2, GFP_KERNEL);
130 if (collection == NULL) {
131 dbg("failed to reallocate collection array");
134 memcpy(collection, parser->device->collection,
135 sizeof(struct hid_collection) *
136 parser->device->collection_size);
137 memset(collection + parser->device->collection_size, 0,
138 sizeof(struct hid_collection) *
139 parser->device->collection_size);
140 kfree(parser->device->collection);
141 parser->device->collection = collection;
142 parser->device->collection_size *= 2;
145 parser->collection_stack[parser->collection_stack_ptr++] =
146 parser->device->maxcollection;
148 collection = parser->device->collection +
149 parser->device->maxcollection++;
150 collection->type = type;
151 collection->usage = usage;
152 collection->level = parser->collection_stack_ptr - 1;
154 if (type == HID_COLLECTION_APPLICATION)
155 parser->device->maxapplication++;
161 * Close a collection.
164 static int close_collection(struct hid_parser *parser)
166 if (!parser->collection_stack_ptr) {
167 dbg("collection stack underflow");
170 parser->collection_stack_ptr--;
175 * Climb up the stack, search for the specified collection type
176 * and return the usage.
179 static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
182 for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
183 if (parser->device->collection[parser->collection_stack[n]].type == type)
184 return parser->device->collection[parser->collection_stack[n]].usage;
185 return 0; /* we know nothing about this usage type */
189 * Add a usage to the temporary parser table.
192 static int hid_add_usage(struct hid_parser *parser, unsigned usage)
194 if (parser->local.usage_index >= HID_MAX_USAGES) {
195 dbg("usage index exceeded");
198 parser->local.usage[parser->local.usage_index] = usage;
199 parser->local.collection_index[parser->local.usage_index] =
200 parser->collection_stack_ptr ?
201 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
202 parser->local.usage_index++;
207 * Register a new field for this report.
210 static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
212 struct hid_report *report;
213 struct hid_field *field;
218 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
219 dbg("hid_register_report failed");
223 if (parser->global.logical_maximum < parser->global.logical_minimum) {
224 dbg("logical range invalid %d %d", parser->global.logical_minimum, parser->global.logical_maximum);
228 offset = report->size;
229 report->size += parser->global.report_size * parser->global.report_count;
231 if (!parser->local.usage_index) /* Ignore padding fields */
234 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
236 if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
239 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
240 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
241 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
243 for (i = 0; i < usages; i++) {
245 /* Duplicate the last usage we parsed if we have excess values */
246 if (i >= parser->local.usage_index)
247 j = parser->local.usage_index - 1;
248 field->usage[i].hid = parser->local.usage[j];
249 field->usage[i].collection_index =
250 parser->local.collection_index[j];
253 field->maxusage = usages;
254 field->flags = flags;
255 field->report_offset = offset;
256 field->report_type = report_type;
257 field->report_size = parser->global.report_size;
258 field->report_count = parser->global.report_count;
259 field->logical_minimum = parser->global.logical_minimum;
260 field->logical_maximum = parser->global.logical_maximum;
261 field->physical_minimum = parser->global.physical_minimum;
262 field->physical_maximum = parser->global.physical_maximum;
263 field->unit_exponent = parser->global.unit_exponent;
264 field->unit = parser->global.unit;
270 * Read data value from item.
273 static u32 item_udata(struct hid_item *item)
275 switch (item->size) {
276 case 1: return item->data.u8;
277 case 2: return item->data.u16;
278 case 4: return item->data.u32;
283 static s32 item_sdata(struct hid_item *item)
285 switch (item->size) {
286 case 1: return item->data.s8;
287 case 2: return item->data.s16;
288 case 4: return item->data.s32;
294 * Process a global item.
297 static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
301 case HID_GLOBAL_ITEM_TAG_PUSH:
303 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
304 dbg("global enviroment stack overflow");
308 memcpy(parser->global_stack + parser->global_stack_ptr++,
309 &parser->global, sizeof(struct hid_global));
312 case HID_GLOBAL_ITEM_TAG_POP:
314 if (!parser->global_stack_ptr) {
315 dbg("global enviroment stack underflow");
319 memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr,
320 sizeof(struct hid_global));
323 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
324 parser->global.usage_page = item_udata(item);
327 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
328 parser->global.logical_minimum = item_sdata(item);
331 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
332 if (parser->global.logical_minimum < 0)
333 parser->global.logical_maximum = item_sdata(item);
335 parser->global.logical_maximum = item_udata(item);
338 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
339 parser->global.physical_minimum = item_sdata(item);
342 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
343 if (parser->global.physical_minimum < 0)
344 parser->global.physical_maximum = item_sdata(item);
346 parser->global.physical_maximum = item_udata(item);
349 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
350 parser->global.unit_exponent = item_sdata(item);
353 case HID_GLOBAL_ITEM_TAG_UNIT:
354 parser->global.unit = item_udata(item);
357 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
358 if ((parser->global.report_size = item_udata(item)) > 32) {
359 dbg("invalid report_size %d", parser->global.report_size);
364 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
365 if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) {
366 dbg("invalid report_count %d", parser->global.report_count);
371 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
372 if ((parser->global.report_id = item_udata(item)) == 0) {
373 dbg("report_id 0 is invalid");
379 dbg("unknown global tag 0x%x", item->tag);
385 * Process a local item.
388 static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
393 if (item->size == 0) {
394 dbg("item data expected for local item");
398 data = item_udata(item);
402 case HID_LOCAL_ITEM_TAG_DELIMITER:
406 * We treat items before the first delimiter
407 * as global to all usage sets (branch 0).
408 * In the moment we process only these global
409 * items and the first delimiter set.
411 if (parser->local.delimiter_depth != 0) {
412 dbg("nested delimiters");
415 parser->local.delimiter_depth++;
416 parser->local.delimiter_branch++;
418 if (parser->local.delimiter_depth < 1) {
419 dbg("bogus close delimiter");
422 parser->local.delimiter_depth--;
426 case HID_LOCAL_ITEM_TAG_USAGE:
428 if (parser->local.delimiter_branch > 1) {
429 dbg("alternative usage ignored");
434 data = (parser->global.usage_page << 16) + data;
436 return hid_add_usage(parser, data);
438 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
440 if (parser->local.delimiter_branch > 1) {
441 dbg("alternative usage ignored");
446 data = (parser->global.usage_page << 16) + data;
448 parser->local.usage_minimum = data;
451 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
453 if (parser->local.delimiter_branch > 1) {
454 dbg("alternative usage ignored");
459 data = (parser->global.usage_page << 16) + data;
461 for (n = parser->local.usage_minimum; n <= data; n++)
462 if (hid_add_usage(parser, n)) {
463 dbg("hid_add_usage failed\n");
470 dbg("unknown local item tag 0x%x", item->tag);
477 * Process a main item.
480 static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
485 data = item_udata(item);
488 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
489 ret = open_collection(parser, data & 0xff);
491 case HID_MAIN_ITEM_TAG_END_COLLECTION:
492 ret = close_collection(parser);
494 case HID_MAIN_ITEM_TAG_INPUT:
495 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
497 case HID_MAIN_ITEM_TAG_OUTPUT:
498 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
500 case HID_MAIN_ITEM_TAG_FEATURE:
501 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
504 dbg("unknown main item tag 0x%x", item->tag);
508 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
514 * Process a reserved item.
517 static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
519 dbg("reserved item type, tag 0x%x", item->tag);
524 * Free a report and all registered fields. The field->usage and
525 * field->value table's are allocated behind the field, so we need
526 * only to free(field) itself.
529 static void hid_free_report(struct hid_report *report)
533 for (n = 0; n < report->maxfield; n++)
534 kfree(report->field[n]);
539 * Free a device structure, all reports, and all fields.
542 static void hid_free_device(struct hid_device *device)
546 for (i = 0; i < HID_REPORT_TYPES; i++) {
547 struct hid_report_enum *report_enum = device->report_enum + i;
549 for (j = 0; j < 256; j++) {
550 struct hid_report *report = report_enum->report_id_hash[j];
552 hid_free_report(report);
556 kfree(device->rdesc);
561 * Fetch a report description item from the data stream. We support long
562 * items, though they are not used yet.
565 static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
569 if ((end - start) <= 0)
574 item->type = (b >> 2) & 3;
575 item->tag = (b >> 4) & 15;
577 if (item->tag == HID_ITEM_TAG_LONG) {
579 item->format = HID_ITEM_FORMAT_LONG;
581 if ((end - start) < 2)
584 item->size = *start++;
585 item->tag = *start++;
587 if ((end - start) < item->size)
590 item->data.longdata = start;
595 item->format = HID_ITEM_FORMAT_SHORT;
598 switch (item->size) {
604 if ((end - start) < 1)
606 item->data.u8 = *start++;
610 if ((end - start) < 2)
612 item->data.u16 = le16_to_cpu(get_unaligned((__le16*)start));
613 start = (__u8 *)((__le16 *)start + 1);
618 if ((end - start) < 4)
620 item->data.u32 = le32_to_cpu(get_unaligned((__le32*)start));
621 start = (__u8 *)((__le32 *)start + 1);
629 * Parse a report description into a hid_device structure. Reports are
630 * enumerated, fields are attached to these reports.
633 static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
635 struct hid_device *device;
636 struct hid_parser *parser;
637 struct hid_item item;
640 static int (*dispatch_type[])(struct hid_parser *parser,
641 struct hid_item *item) = {
648 if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL)))
651 if (!(device->collection = kzalloc(sizeof(struct hid_collection) *
652 HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
656 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
658 for (i = 0; i < HID_REPORT_TYPES; i++)
659 INIT_LIST_HEAD(&device->report_enum[i].report_list);
661 if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) {
662 kfree(device->collection);
666 memcpy(device->rdesc, start, size);
667 device->rsize = size;
669 if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
670 kfree(device->rdesc);
671 kfree(device->collection);
675 parser->device = device;
678 while ((start = fetch_item(start, end, &item)) != NULL) {
680 if (item.format != HID_ITEM_FORMAT_SHORT) {
681 dbg("unexpected long global item");
682 kfree(device->collection);
683 hid_free_device(device);
688 if (dispatch_type[item.type](parser, &item)) {
689 dbg("item %u %u %u %u parsing failed\n",
690 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
691 kfree(device->collection);
692 hid_free_device(device);
698 if (parser->collection_stack_ptr) {
699 dbg("unbalanced collection at end of report description");
700 kfree(device->collection);
701 hid_free_device(device);
705 if (parser->local.delimiter_depth) {
706 dbg("unbalanced delimiter at end of report description");
707 kfree(device->collection);
708 hid_free_device(device);
717 dbg("item fetching failed at offset %d\n", (int)(end - start));
718 kfree(device->collection);
719 hid_free_device(device);
725 * Convert a signed n-bit integer to signed 32-bit integer. Common
726 * cases are done through the compiler, the screwed things has to be
730 static s32 snto32(__u32 value, unsigned n)
733 case 8: return ((__s8)value);
734 case 16: return ((__s16)value);
735 case 32: return ((__s32)value);
737 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
741 * Convert a signed 32-bit integer to a signed n-bit integer.
744 static u32 s32ton(__s32 value, unsigned n)
746 s32 a = value >> (n - 1);
748 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
749 return value & ((1 << n) - 1);
753 * Extract/implement a data field from/to a little endian report (bit array).
755 * Code sort-of follows HID spec:
756 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
758 * While the USB HID spec allows unlimited length bit fields in "report
759 * descriptors", most devices never use more than 16 bits.
760 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
761 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
764 static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
770 report += offset >> 3; /* adjust byte index */
771 offset &= 7; /* now only need bit offset into one byte */
772 x = get_unaligned((u64 *) report);
774 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
779 * "implement" : set bits in a little endian bit stream.
780 * Same concepts as "extract" (see comments above).
781 * The data mangled in the bit stream remains in little endian
782 * order the whole time. It make more sense to talk about
783 * endianness of register values by considering a register
784 * a "cached" copy of the little endiad bit stream.
786 static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
789 u64 m = (1ULL << n) - 1;
796 report += offset >> 3;
799 x = get_unaligned((u64 *)report);
800 x &= cpu_to_le64(~(m << offset));
801 x |= cpu_to_le64(((u64) value) << offset);
802 put_unaligned(x, (u64 *) report);
806 * Search an array for a value.
809 static __inline__ int search(__s32 *array, __s32 value, unsigned n)
812 if (*array++ == value)
818 static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt)
820 hid_dump_input(usage, value);
821 if (hid->claimed & HID_CLAIMED_INPUT)
822 hidinput_hid_event(hid, field, usage, value);
823 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt)
824 hiddev_hid_event(hid, field, usage, value);
828 * Analyse a received field, and fetch the data from it. The field
829 * content is stored for next report processing (we do differential
830 * reporting to the layer).
833 static void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt)
836 unsigned count = field->report_count;
837 unsigned offset = field->report_offset;
838 unsigned size = field->report_size;
839 __s32 min = field->logical_minimum;
840 __s32 max = field->logical_maximum;
843 if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
846 for (n = 0; n < count; n++) {
848 value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
849 extract(data, offset + n * size, size);
851 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
852 && value[n] >= min && value[n] <= max
853 && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
857 for (n = 0; n < count; n++) {
859 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
860 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
864 if (field->value[n] >= min && field->value[n] <= max
865 && field->usage[field->value[n] - min].hid
866 && search(value, field->value[n], count))
867 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
869 if (value[n] >= min && value[n] <= max
870 && field->usage[value[n] - min].hid
871 && search(field->value, value[n], count))
872 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
875 memcpy(field->value, value, count * sizeof(__s32));
880 static int hid_input_report(int type, struct urb *urb, int interrupt)
882 struct hid_device *hid = urb->context;
883 struct hid_report_enum *report_enum = hid->report_enum + type;
884 u8 *data = urb->transfer_buffer;
885 int len = urb->actual_length;
886 struct hid_report *report;
895 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un");
898 n = 0; /* Normally report number is 0 */
899 if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */
907 printk(KERN_DEBUG __FILE__ ": report %d (size %u) = ", n, len);
908 for (i = 0; i < len; i++)
909 printk(" %02x", data[i]);
914 if (!(report = report_enum->report_id_hash[n])) {
915 dbg("undefined report_id %d received", n);
919 size = ((report->size - 1) >> 3) + 1;
922 dbg("report %d is too short, (%d < %d)", report->id, len, size);
923 memset(data + len, 0, size - len);
926 if (hid->claimed & HID_CLAIMED_HIDDEV)
927 hiddev_report_event(hid, report);
929 for (n = 0; n < report->maxfield; n++)
930 hid_input_field(hid, report->field[n], data, interrupt);
932 if (hid->claimed & HID_CLAIMED_INPUT)
933 hidinput_report_event(hid, report);
939 * Input submission and I/O error handler.
942 static void hid_io_error(struct hid_device *hid);
944 /* Start up the input URB */
945 static int hid_start_in(struct hid_device *hid)
950 spin_lock_irqsave(&hid->inlock, flags);
951 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) &&
952 !test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) {
953 rc = usb_submit_urb(hid->urbin, GFP_ATOMIC);
955 clear_bit(HID_IN_RUNNING, &hid->iofl);
957 spin_unlock_irqrestore(&hid->inlock, flags);
961 /* I/O retry timer routine */
962 static void hid_retry_timeout(unsigned long _hid)
964 struct hid_device *hid = (struct hid_device *) _hid;
966 dev_dbg(&hid->intf->dev, "retrying intr urb\n");
967 if (hid_start_in(hid))
971 /* Workqueue routine to reset the device or clear a halt */
972 static void hid_reset(struct work_struct *work)
974 struct hid_device *hid =
975 container_of(work, struct hid_device, reset_work);
978 if (test_bit(HID_CLEAR_HALT, &hid->iofl)) {
979 dev_dbg(&hid->intf->dev, "clear halt\n");
980 rc = usb_clear_halt(hid->dev, hid->urbin->pipe);
981 clear_bit(HID_CLEAR_HALT, &hid->iofl);
985 else if (test_bit(HID_RESET_PENDING, &hid->iofl)) {
986 dev_dbg(&hid->intf->dev, "resetting device\n");
987 rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf);
989 rc = usb_reset_composite_device(hid->dev, hid->intf);
991 usb_unlock_device(hid->dev);
993 clear_bit(HID_RESET_PENDING, &hid->iofl);
998 if (!test_bit(HID_IN_RUNNING, &hid->iofl))
1002 err("can't reset device, %s-%s/input%d, status %d",
1003 hid->dev->bus->bus_name,
1014 /* Main I/O error handler */
1015 static void hid_io_error(struct hid_device *hid)
1017 unsigned long flags;
1019 spin_lock_irqsave(&hid->inlock, flags);
1021 /* Stop when disconnected */
1022 if (usb_get_intfdata(hid->intf) == NULL)
1025 /* When an error occurs, retry at increasing intervals */
1026 if (hid->retry_delay == 0) {
1027 hid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */
1028 hid->stop_retry = jiffies + msecs_to_jiffies(1000);
1029 } else if (hid->retry_delay < 100)
1030 hid->retry_delay *= 2;
1032 if (time_after(jiffies, hid->stop_retry)) {
1034 /* Retries failed, so do a port reset */
1035 if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) {
1036 schedule_work(&hid->reset_work);
1041 mod_timer(&hid->io_retry,
1042 jiffies + msecs_to_jiffies(hid->retry_delay));
1044 spin_unlock_irqrestore(&hid->inlock, flags);
1048 * Input interrupt completion handler.
1051 static void hid_irq_in(struct urb *urb)
1053 struct hid_device *hid = urb->context;
1056 switch (urb->status) {
1057 case 0: /* success */
1058 hid->retry_delay = 0;
1059 hid_input_report(HID_INPUT_REPORT, urb, 1);
1061 case -EPIPE: /* stall */
1062 clear_bit(HID_IN_RUNNING, &hid->iofl);
1063 set_bit(HID_CLEAR_HALT, &hid->iofl);
1064 schedule_work(&hid->reset_work);
1066 case -ECONNRESET: /* unlink */
1068 case -ESHUTDOWN: /* unplug */
1069 clear_bit(HID_IN_RUNNING, &hid->iofl);
1071 case -EILSEQ: /* protocol error or unplug */
1072 case -EPROTO: /* protocol error or unplug */
1073 case -ETIME: /* protocol error or unplug */
1074 case -ETIMEDOUT: /* Should never happen, but... */
1075 clear_bit(HID_IN_RUNNING, &hid->iofl);
1078 default: /* error */
1079 warn("input irq status %d received", urb->status);
1082 status = usb_submit_urb(urb, SLAB_ATOMIC);
1084 clear_bit(HID_IN_RUNNING, &hid->iofl);
1085 if (status != -EPERM) {
1086 err("can't resubmit intr, %s-%s/input%d, status %d",
1087 hid->dev->bus->bus_name,
1089 hid->ifnum, status);
1096 * Output the field into the report.
1099 static void hid_output_field(struct hid_field *field, __u8 *data)
1101 unsigned count = field->report_count;
1102 unsigned offset = field->report_offset;
1103 unsigned size = field->report_size;
1106 for (n = 0; n < count; n++) {
1107 if (field->logical_minimum < 0) /* signed values */
1108 implement(data, offset + n * size, size, s32ton(field->value[n], size));
1109 else /* unsigned values */
1110 implement(data, offset + n * size, size, field->value[n]);
1118 static void hid_output_report(struct hid_report *report, __u8 *data)
1123 *data++ = report->id;
1125 for (n = 0; n < report->maxfield; n++)
1126 hid_output_field(report->field[n], data);
1130 * Set a field value. The report this field belongs to has to be
1131 * created and transferred to the device, to set this value in the
1135 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1137 unsigned size = field->report_size;
1139 hid_dump_input(field->usage + offset, value);
1141 if (offset >= field->report_count) {
1142 dbg("offset (%d) exceeds report_count (%d)", offset, field->report_count);
1143 hid_dump_field(field, 8);
1146 if (field->logical_minimum < 0) {
1147 if (value != snto32(s32ton(value, size), size)) {
1148 dbg("value %d is out of range", value);
1152 field->value[offset] = value;
1157 * Find a report field with a specified HID usage.
1160 struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type)
1162 struct hid_report *report;
1165 list_for_each_entry(report, &hid->report_enum[type].report_list, list)
1166 for (i = 0; i < report->maxfield; i++)
1167 if (report->field[i]->logical == wanted_usage)
1168 return report->field[i];
1173 static int hid_submit_out(struct hid_device *hid)
1175 struct hid_report *report;
1177 report = hid->out[hid->outtail];
1179 hid_output_report(report, hid->outbuf);
1180 hid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1181 hid->urbout->dev = hid->dev;
1183 dbg("submitting out urb");
1185 if (usb_submit_urb(hid->urbout, GFP_ATOMIC)) {
1186 err("usb_submit_urb(out) failed");
1193 static int hid_submit_ctrl(struct hid_device *hid)
1195 struct hid_report *report;
1199 report = hid->ctrl[hid->ctrltail].report;
1200 dir = hid->ctrl[hid->ctrltail].dir;
1202 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1203 if (dir == USB_DIR_OUT) {
1204 hid_output_report(report, hid->ctrlbuf);
1205 hid->urbctrl->pipe = usb_sndctrlpipe(hid->dev, 0);
1206 hid->urbctrl->transfer_buffer_length = len;
1208 int maxpacket, padlen;
1210 hid->urbctrl->pipe = usb_rcvctrlpipe(hid->dev, 0);
1211 maxpacket = usb_maxpacket(hid->dev, hid->urbctrl->pipe, 0);
1212 if (maxpacket > 0) {
1213 padlen = (len + maxpacket - 1) / maxpacket;
1214 padlen *= maxpacket;
1215 if (padlen > hid->bufsize)
1216 padlen = hid->bufsize;
1219 hid->urbctrl->transfer_buffer_length = padlen;
1221 hid->urbctrl->dev = hid->dev;
1223 hid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
1224 hid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
1225 hid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
1226 hid->cr->wIndex = cpu_to_le16(hid->ifnum);
1227 hid->cr->wLength = cpu_to_le16(len);
1229 dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u",
1230 hid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report",
1231 hid->cr->wValue, hid->cr->wIndex, hid->cr->wLength);
1233 if (usb_submit_urb(hid->urbctrl, GFP_ATOMIC)) {
1234 err("usb_submit_urb(ctrl) failed");
1242 * Output interrupt completion handler.
1245 static void hid_irq_out(struct urb *urb)
1247 struct hid_device *hid = urb->context;
1248 unsigned long flags;
1251 switch (urb->status) {
1252 case 0: /* success */
1254 case -ESHUTDOWN: /* unplug */
1256 case -EILSEQ: /* protocol error or unplug */
1257 case -EPROTO: /* protocol error or unplug */
1258 case -ECONNRESET: /* unlink */
1261 default: /* error */
1262 warn("output irq status %d received", urb->status);
1265 spin_lock_irqsave(&hid->outlock, flags);
1268 hid->outtail = hid->outhead;
1270 hid->outtail = (hid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
1272 if (hid->outhead != hid->outtail) {
1273 if (hid_submit_out(hid)) {
1274 clear_bit(HID_OUT_RUNNING, &hid->iofl);
1275 wake_up(&hid->wait);
1277 spin_unlock_irqrestore(&hid->outlock, flags);
1281 clear_bit(HID_OUT_RUNNING, &hid->iofl);
1282 spin_unlock_irqrestore(&hid->outlock, flags);
1283 wake_up(&hid->wait);
1287 * Control pipe completion handler.
1290 static void hid_ctrl(struct urb *urb)
1292 struct hid_device *hid = urb->context;
1293 unsigned long flags;
1296 spin_lock_irqsave(&hid->ctrllock, flags);
1298 switch (urb->status) {
1299 case 0: /* success */
1300 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN)
1301 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0);
1303 case -ESHUTDOWN: /* unplug */
1305 case -EILSEQ: /* protocol error or unplug */
1306 case -EPROTO: /* protocol error or unplug */
1307 case -ECONNRESET: /* unlink */
1309 case -EPIPE: /* report not available */
1311 default: /* error */
1312 warn("ctrl urb status %d received", urb->status);
1316 hid->ctrltail = hid->ctrlhead;
1318 hid->ctrltail = (hid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
1320 if (hid->ctrlhead != hid->ctrltail) {
1321 if (hid_submit_ctrl(hid)) {
1322 clear_bit(HID_CTRL_RUNNING, &hid->iofl);
1323 wake_up(&hid->wait);
1325 spin_unlock_irqrestore(&hid->ctrllock, flags);
1329 clear_bit(HID_CTRL_RUNNING, &hid->iofl);
1330 spin_unlock_irqrestore(&hid->ctrllock, flags);
1331 wake_up(&hid->wait);
1334 void hid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
1337 unsigned long flags;
1339 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
1342 if (hid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
1344 spin_lock_irqsave(&hid->outlock, flags);
1346 if ((head = (hid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == hid->outtail) {
1347 spin_unlock_irqrestore(&hid->outlock, flags);
1348 warn("output queue full");
1352 hid->out[hid->outhead] = report;
1353 hid->outhead = head;
1355 if (!test_and_set_bit(HID_OUT_RUNNING, &hid->iofl))
1356 if (hid_submit_out(hid))
1357 clear_bit(HID_OUT_RUNNING, &hid->iofl);
1359 spin_unlock_irqrestore(&hid->outlock, flags);
1363 spin_lock_irqsave(&hid->ctrllock, flags);
1365 if ((head = (hid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == hid->ctrltail) {
1366 spin_unlock_irqrestore(&hid->ctrllock, flags);
1367 warn("control queue full");
1371 hid->ctrl[hid->ctrlhead].report = report;
1372 hid->ctrl[hid->ctrlhead].dir = dir;
1373 hid->ctrlhead = head;
1375 if (!test_and_set_bit(HID_CTRL_RUNNING, &hid->iofl))
1376 if (hid_submit_ctrl(hid))
1377 clear_bit(HID_CTRL_RUNNING, &hid->iofl);
1379 spin_unlock_irqrestore(&hid->ctrllock, flags);
1382 int hid_wait_io(struct hid_device *hid)
1384 if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &hid->iofl) &&
1385 !test_bit(HID_OUT_RUNNING, &hid->iofl)),
1387 dbg("timeout waiting for ctrl or out queue to clear");
1394 static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
1396 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1397 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
1398 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1401 static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
1402 unsigned char type, void *buf, int size)
1404 int result, retries = 4;
1406 memset(buf,0,size); // Make sure we parse really received data
1409 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
1410 USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN,
1411 (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT);
1413 } while (result < size && retries);
1417 int hid_open(struct hid_device *hid)
1420 if (hid_start_in(hid))
1425 void hid_close(struct hid_device *hid)
1428 usb_kill_urb(hid->urbin);
1431 #define USB_VENDOR_ID_PANJIT 0x134c
1433 #define USB_VENDOR_ID_TURBOX 0x062a
1434 #define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
1437 * Initialize all reports
1440 void hid_init_reports(struct hid_device *hid)
1442 struct hid_report *report;
1445 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
1446 hid_submit_report(hid, report, USB_DIR_IN);
1448 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
1449 hid_submit_report(hid, report, USB_DIR_IN);
1452 ret = hid_wait_io(hid);
1455 if (test_bit(HID_CTRL_RUNNING, &hid->iofl))
1456 usb_kill_urb(hid->urbctrl);
1457 if (test_bit(HID_OUT_RUNNING, &hid->iofl))
1458 usb_kill_urb(hid->urbout);
1459 ret = hid_wait_io(hid);
1463 warn("timeout initializing reports");
1466 #define USB_VENDOR_ID_GTCO 0x078c
1467 #define USB_DEVICE_ID_GTCO_90 0x0090
1468 #define USB_DEVICE_ID_GTCO_100 0x0100
1469 #define USB_DEVICE_ID_GTCO_101 0x0101
1470 #define USB_DEVICE_ID_GTCO_103 0x0103
1471 #define USB_DEVICE_ID_GTCO_104 0x0104
1472 #define USB_DEVICE_ID_GTCO_105 0x0105
1473 #define USB_DEVICE_ID_GTCO_106 0x0106
1474 #define USB_DEVICE_ID_GTCO_107 0x0107
1475 #define USB_DEVICE_ID_GTCO_108 0x0108
1476 #define USB_DEVICE_ID_GTCO_200 0x0200
1477 #define USB_DEVICE_ID_GTCO_201 0x0201
1478 #define USB_DEVICE_ID_GTCO_202 0x0202
1479 #define USB_DEVICE_ID_GTCO_203 0x0203
1480 #define USB_DEVICE_ID_GTCO_204 0x0204
1481 #define USB_DEVICE_ID_GTCO_205 0x0205
1482 #define USB_DEVICE_ID_GTCO_206 0x0206
1483 #define USB_DEVICE_ID_GTCO_207 0x0207
1484 #define USB_DEVICE_ID_GTCO_300 0x0300
1485 #define USB_DEVICE_ID_GTCO_301 0x0301
1486 #define USB_DEVICE_ID_GTCO_302 0x0302
1487 #define USB_DEVICE_ID_GTCO_303 0x0303
1488 #define USB_DEVICE_ID_GTCO_304 0x0304
1489 #define USB_DEVICE_ID_GTCO_305 0x0305
1490 #define USB_DEVICE_ID_GTCO_306 0x0306
1491 #define USB_DEVICE_ID_GTCO_307 0x0307
1492 #define USB_DEVICE_ID_GTCO_308 0x0308
1493 #define USB_DEVICE_ID_GTCO_309 0x0309
1494 #define USB_DEVICE_ID_GTCO_400 0x0400
1495 #define USB_DEVICE_ID_GTCO_401 0x0401
1496 #define USB_DEVICE_ID_GTCO_402 0x0402
1497 #define USB_DEVICE_ID_GTCO_403 0x0403
1498 #define USB_DEVICE_ID_GTCO_404 0x0404
1499 #define USB_DEVICE_ID_GTCO_405 0x0405
1500 #define USB_DEVICE_ID_GTCO_500 0x0500
1501 #define USB_DEVICE_ID_GTCO_501 0x0501
1502 #define USB_DEVICE_ID_GTCO_502 0x0502
1503 #define USB_DEVICE_ID_GTCO_503 0x0503
1504 #define USB_DEVICE_ID_GTCO_504 0x0504
1505 #define USB_DEVICE_ID_GTCO_1000 0x1000
1506 #define USB_DEVICE_ID_GTCO_1001 0x1001
1507 #define USB_DEVICE_ID_GTCO_1002 0x1002
1508 #define USB_DEVICE_ID_GTCO_1003 0x1003
1509 #define USB_DEVICE_ID_GTCO_1004 0x1004
1510 #define USB_DEVICE_ID_GTCO_1005 0x1005
1511 #define USB_DEVICE_ID_GTCO_1006 0x1006
1513 #define USB_VENDOR_ID_WACOM 0x056a
1515 #define USB_VENDOR_ID_ACECAD 0x0460
1516 #define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
1517 #define USB_DEVICE_ID_ACECAD_302 0x0008
1519 #define USB_VENDOR_ID_KBGEAR 0x084e
1520 #define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
1522 #define USB_VENDOR_ID_AIPTEK 0x08ca
1523 #define USB_DEVICE_ID_AIPTEK_01 0x0001
1524 #define USB_DEVICE_ID_AIPTEK_10 0x0010
1525 #define USB_DEVICE_ID_AIPTEK_20 0x0020
1526 #define USB_DEVICE_ID_AIPTEK_21 0x0021
1527 #define USB_DEVICE_ID_AIPTEK_22 0x0022
1528 #define USB_DEVICE_ID_AIPTEK_23 0x0023
1529 #define USB_DEVICE_ID_AIPTEK_24 0x0024
1531 #define USB_VENDOR_ID_GRIFFIN 0x077d
1532 #define USB_DEVICE_ID_POWERMATE 0x0410
1533 #define USB_DEVICE_ID_SOUNDKNOB 0x04AA
1535 #define USB_VENDOR_ID_ATEN 0x0557
1536 #define USB_DEVICE_ID_ATEN_UC100KM 0x2004
1537 #define USB_DEVICE_ID_ATEN_CS124U 0x2202
1538 #define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204
1539 #define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
1540 #define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
1542 #define USB_VENDOR_ID_TOPMAX 0x0663
1543 #define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103
1545 #define USB_VENDOR_ID_HAPP 0x078b
1546 #define USB_DEVICE_ID_UGCI_DRIVING 0x0010
1547 #define USB_DEVICE_ID_UGCI_FLYING 0x0020
1548 #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030
1550 #define USB_VENDOR_ID_MGE 0x0463
1551 #define USB_DEVICE_ID_MGE_UPS 0xffff
1552 #define USB_DEVICE_ID_MGE_UPS1 0x0001
1554 #define USB_VENDOR_ID_ONTRAK 0x0a07
1555 #define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
1557 #define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
1558 #define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
1560 #define USB_VENDOR_ID_A4TECH 0x09da
1561 #define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
1563 #define USB_VENDOR_ID_AASHIMA 0x06d6
1564 #define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
1565 #define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026
1567 #define USB_VENDOR_ID_CYPRESS 0x04b4
1568 #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
1569 #define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
1570 #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
1572 #define USB_VENDOR_ID_BERKSHIRE 0x0c98
1573 #define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140
1575 #define USB_VENDOR_ID_ALPS 0x0433
1576 #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101
1578 #define USB_VENDOR_ID_SAITEK 0x06a3
1579 #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
1581 #define USB_VENDOR_ID_NEC 0x073e
1582 #define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301
1584 #define USB_VENDOR_ID_CHIC 0x05fe
1585 #define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014
1587 #define USB_VENDOR_ID_GLAB 0x06c2
1588 #define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
1589 #define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039
1590 #define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040
1591 #define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044
1592 #define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045
1593 #define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051
1594 #define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053
1595 #define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058
1597 #define USB_VENDOR_ID_WISEGROUP 0x0925
1598 #define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101
1599 #define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
1600 #define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201
1601 #define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866
1603 #define USB_VENDOR_ID_WISEGROUP_LTD 0x6677
1604 #define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
1606 #define USB_VENDOR_ID_CODEMERCS 0x07c0
1607 #define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500
1608 #define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501
1609 #define USB_DEVICE_ID_CODEMERCS_IOW48 0x1502
1610 #define USB_DEVICE_ID_CODEMERCS_IOW28 0x1503
1612 #define USB_VENDOR_ID_DELORME 0x1163
1613 #define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
1614 #define USB_DEVICE_ID_DELORME_EM_LT20 0x0200
1616 #define USB_VENDOR_ID_MCC 0x09db
1617 #define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
1618 #define USB_DEVICE_ID_MCC_PMD1208LS 0x007a
1620 #define USB_VENDOR_ID_VERNIER 0x08f7
1621 #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
1622 #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
1623 #define USB_DEVICE_ID_VERNIER_SKIP 0x0003
1624 #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
1626 #define USB_VENDOR_ID_LD 0x0f11
1627 #define USB_DEVICE_ID_LD_CASSY 0x1000
1628 #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010
1629 #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020
1630 #define USB_DEVICE_ID_LD_JWM 0x1080
1631 #define USB_DEVICE_ID_LD_DMMP 0x1081
1632 #define USB_DEVICE_ID_LD_UMIP 0x1090
1633 #define USB_DEVICE_ID_LD_XRAY1 0x1100
1634 #define USB_DEVICE_ID_LD_XRAY2 0x1101
1635 #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200
1636 #define USB_DEVICE_ID_LD_COM3LAB 0x2000
1637 #define USB_DEVICE_ID_LD_TELEPORT 0x2010
1638 #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020
1639 #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030
1640 #define USB_DEVICE_ID_LD_MACHINETEST 0x2040
1642 #define USB_VENDOR_ID_APPLE 0x05ac
1643 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
1644 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
1645 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
1646 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
1647 #define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215
1648 #define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216
1649 #define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217
1650 #define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218
1651 #define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219
1652 #define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a
1653 #define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b
1654 #define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c
1655 #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
1656 #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
1658 #define USB_VENDOR_ID_CHERRY 0x046a
1659 #define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023
1661 #define USB_VENDOR_ID_YEALINK 0x6993
1662 #define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
1664 #define USB_VENDOR_ID_ALCOR 0x058f
1665 #define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
1667 #define USB_VENDOR_ID_SUN 0x0430
1668 #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
1670 #define USB_VENDOR_ID_AIRCABLE 0x16CA
1671 #define USB_DEVICE_ID_AIRCABLE1 0x1502
1674 * Alphabetically sorted blacklist by quirk type.
1677 static const struct hid_blacklist {
1681 } hid_blacklist[] = {
1683 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE },
1684 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE },
1685 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE },
1686 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE },
1687 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE },
1688 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE },
1689 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE },
1690 { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE },
1691 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
1692 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
1693 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE },
1694 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE },
1695 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE },
1696 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
1697 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
1698 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
1699 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
1700 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
1701 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
1702 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
1703 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
1704 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE },
1705 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE },
1706 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE },
1707 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE },
1708 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE },
1709 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE },
1710 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
1711 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
1712 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE },
1713 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE },
1714 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE },
1715 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE },
1716 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE },
1717 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE },
1718 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE },
1719 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE },
1720 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE },
1721 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE },
1722 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE },
1723 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE },
1724 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE },
1725 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE },
1726 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE },
1727 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE },
1728 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE },
1729 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE },
1730 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE },
1731 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE },
1732 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE },
1733 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE },
1734 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE },
1735 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE },
1736 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE },
1737 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE },
1738 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE },
1739 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE },
1740 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE },
1741 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE },
1742 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE },
1743 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE },
1744 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE },
1745 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE },
1746 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE },
1747 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE },
1748 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE },
1749 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE },
1750 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE },
1751 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE },
1752 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE },
1753 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE },
1754 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
1755 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
1756 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
1757 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
1758 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
1759 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
1760 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE },
1761 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE },
1762 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE },
1763 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE },
1764 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE },
1765 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE },
1766 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE },
1767 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE },
1768 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE },
1769 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE },
1770 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE },
1771 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE },
1772 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE },
1773 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE },
1774 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
1775 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE },
1776 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE },
1777 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE },
1778 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE },
1779 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE },
1780 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE },
1781 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE },
1782 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE },
1783 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE },
1784 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE },
1785 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE },
1786 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE },
1787 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE },
1788 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE },
1789 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
1790 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1791 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1792 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE },
1793 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE },
1795 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
1796 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE },
1798 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
1799 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
1800 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
1801 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
1802 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
1803 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
1804 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1805 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1807 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
1808 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
1809 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
1811 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
1812 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
1813 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
1814 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
1815 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
1816 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
1817 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
1818 { USB_VENDOR_ID_NEC, USB_DEVICE_ID_NEC_USB_GAME_PAD, HID_QUIRK_BADPAD },
1819 { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
1820 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
1822 { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION },
1824 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1825 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_POWERBOOK_HAS_FN },
1826 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1827 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
1828 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
1829 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1830 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
1831 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
1832 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1833 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN },
1834 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
1835 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
1836 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
1838 { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE },
1839 { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE },
1840 { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE },
1841 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
1843 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
1849 * Traverse the supplied list of reports and find the longest
1851 static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max)
1853 struct hid_report *report;
1856 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
1857 size = ((report->size - 1) >> 3) + 1;
1858 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
1865 static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1867 if (!(hid->inbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->inbuf_dma)))
1869 if (!(hid->outbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->outbuf_dma)))
1871 if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma)))
1873 if (!(hid->ctrlbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->ctrlbuf_dma)))
1879 static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
1882 usb_buffer_free(dev, hid->bufsize, hid->inbuf, hid->inbuf_dma);
1884 usb_buffer_free(dev, hid->bufsize, hid->outbuf, hid->outbuf_dma);
1886 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma);
1888 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma);
1892 * Cherry Cymotion keyboard have an invalid HID report descriptor,
1893 * that needs fixing before we can parse it.
1896 static void hid_fixup_cymotion_descriptor(char *rdesc, int rsize)
1898 if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
1899 info("Fixing up Cherry Cymotion report descriptor");
1900 rdesc[11] = rdesc[16] = 0xff;
1901 rdesc[12] = rdesc[17] = 0x03;
1905 static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1907 struct usb_host_interface *interface = intf->cur_altsetting;
1908 struct usb_device *dev = interface_to_usbdev (intf);
1909 struct hid_descriptor *hdesc;
1910 struct hid_device *hid;
1911 unsigned quirks = 0, rsize = 0;
1913 int n, len, insize = 0;
1915 /* Ignore all Wacom devices */
1916 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM)
1919 for (n = 0; hid_blacklist[n].idVendor; n++)
1920 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
1921 (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct)))
1922 quirks = hid_blacklist[n].quirks;
1924 /* Many keyboards and mice don't like to be polled for reports,
1925 * so we will always set the HID_QUIRK_NOGET flag for them. */
1926 if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
1927 if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
1928 interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
1929 quirks |= HID_QUIRK_NOGET;
1932 if (quirks & HID_QUIRK_IGNORE)
1935 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
1936 (!interface->desc.bNumEndpoints ||
1937 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
1938 dbg("class descriptor not present\n");
1942 for (n = 0; n < hdesc->bNumDescriptors; n++)
1943 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
1944 rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
1946 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
1947 dbg("weird size of report descriptor (%u)", rsize);
1951 if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
1952 dbg("couldn't allocate rdesc memory");
1956 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
1958 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) {
1959 dbg("reading report descriptor failed");
1964 if ((quirks & HID_QUIRK_CYMOTION))
1965 hid_fixup_cymotion_descriptor(rdesc, rsize);
1968 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
1969 for (n = 0; n < rsize; n++)
1970 printk(" %02x", (unsigned char) rdesc[n]);
1974 if (!(hid = hid_parse_report(rdesc, n))) {
1975 dbg("parsing report descriptor failed");
1981 hid->quirks = quirks;
1983 hid->bufsize = HID_MIN_BUFFER_SIZE;
1984 hid_find_max_report(hid, HID_INPUT_REPORT, &hid->bufsize);
1985 hid_find_max_report(hid, HID_OUTPUT_REPORT, &hid->bufsize);
1986 hid_find_max_report(hid, HID_FEATURE_REPORT, &hid->bufsize);
1988 if (hid->bufsize > HID_MAX_BUFFER_SIZE)
1989 hid->bufsize = HID_MAX_BUFFER_SIZE;
1991 hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
1993 if (insize > HID_MAX_BUFFER_SIZE)
1994 insize = HID_MAX_BUFFER_SIZE;
1996 if (hid_alloc_buffers(dev, hid)) {
1997 hid_free_buffers(dev, hid);
2001 for (n = 0; n < interface->desc.bNumEndpoints; n++) {
2003 struct usb_endpoint_descriptor *endpoint;
2007 endpoint = &interface->endpoint[n].desc;
2008 if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
2011 interval = endpoint->bInterval;
2013 /* Change the polling interval of mice. */
2014 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
2015 interval = hid_mousepoll_interval;
2017 if (usb_endpoint_dir_in(endpoint)) {
2020 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
2022 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
2023 usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, insize,
2024 hid_irq_in, hid, interval);
2025 hid->urbin->transfer_dma = hid->inbuf_dma;
2026 hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2030 if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
2032 pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
2033 usb_fill_int_urb(hid->urbout, dev, pipe, hid->outbuf, 0,
2034 hid_irq_out, hid, interval);
2035 hid->urbout->transfer_dma = hid->outbuf_dma;
2036 hid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2041 err("couldn't find an input interrupt endpoint");
2045 init_waitqueue_head(&hid->wait);
2047 INIT_WORK(&hid->reset_work, hid_reset);
2048 setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid);
2050 spin_lock_init(&hid->inlock);
2051 spin_lock_init(&hid->outlock);
2052 spin_lock_init(&hid->ctrllock);
2054 hid->version = le16_to_cpu(hdesc->bcdHID);
2055 hid->country = hdesc->bCountryCode;
2058 hid->ifnum = interface->desc.bInterfaceNumber;
2062 if (dev->manufacturer)
2063 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
2066 if (dev->manufacturer)
2067 strlcat(hid->name, " ", sizeof(hid->name));
2068 strlcat(hid->name, dev->product, sizeof(hid->name));
2071 if (!strlen(hid->name))
2072 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
2073 le16_to_cpu(dev->descriptor.idVendor),
2074 le16_to_cpu(dev->descriptor.idProduct));
2076 usb_make_path(dev, hid->phys, sizeof(hid->phys));
2077 strlcat(hid->phys, "/input", sizeof(hid->phys));
2078 len = strlen(hid->phys);
2079 if (len < sizeof(hid->phys) - 1)
2080 snprintf(hid->phys + len, sizeof(hid->phys) - len,
2081 "%d", intf->altsetting[0].desc.bInterfaceNumber);
2083 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
2086 hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
2090 usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr,
2091 hid->ctrlbuf, 1, hid_ctrl, hid);
2092 hid->urbctrl->setup_dma = hid->cr_dma;
2093 hid->urbctrl->transfer_dma = hid->ctrlbuf_dma;
2094 hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
2099 usb_free_urb(hid->urbin);
2100 usb_free_urb(hid->urbout);
2101 usb_free_urb(hid->urbctrl);
2102 hid_free_buffers(dev, hid);
2103 hid_free_device(hid);
2108 static void hid_disconnect(struct usb_interface *intf)
2110 struct hid_device *hid = usb_get_intfdata (intf);
2115 spin_lock_irq(&hid->inlock); /* Sync with error handler */
2116 usb_set_intfdata(intf, NULL);
2117 spin_unlock_irq(&hid->inlock);
2118 usb_kill_urb(hid->urbin);
2119 usb_kill_urb(hid->urbout);
2120 usb_kill_urb(hid->urbctrl);
2122 del_timer_sync(&hid->io_retry);
2123 flush_scheduled_work();
2125 if (hid->claimed & HID_CLAIMED_INPUT)
2126 hidinput_disconnect(hid);
2127 if (hid->claimed & HID_CLAIMED_HIDDEV)
2128 hiddev_disconnect(hid);
2130 usb_free_urb(hid->urbin);
2131 usb_free_urb(hid->urbctrl);
2132 usb_free_urb(hid->urbout);
2134 hid_free_buffers(hid->dev, hid);
2135 hid_free_device(hid);
2138 static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
2140 struct hid_device *hid;
2145 dbg("HID probe called for ifnum %d",
2146 intf->altsetting->desc.bInterfaceNumber);
2148 if (!(hid = usb_hid_configure(intf)))
2151 hid_init_reports(hid);
2152 hid_dump_device(hid);
2154 if (!hidinput_connect(hid))
2155 hid->claimed |= HID_CLAIMED_INPUT;
2156 if (!hiddev_connect(hid))
2157 hid->claimed |= HID_CLAIMED_HIDDEV;
2159 usb_set_intfdata(intf, hid);
2161 if (!hid->claimed) {
2162 printk ("HID device not claimed by input or hiddev\n");
2163 hid_disconnect(intf);
2169 if (hid->claimed & HID_CLAIMED_INPUT)
2171 if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV))
2173 if (hid->claimed & HID_CLAIMED_HIDDEV)
2174 printk("hiddev%d", hid->minor);
2177 for (i = 0; i < hid->maxcollection; i++) {
2178 if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
2179 (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
2180 (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) {
2181 c = hid_types[hid->collection[i].usage & 0xffff];
2186 usb_make_path(interface_to_usbdev(intf), path, 63);
2188 printk(": USB HID v%x.%02x %s [%s] on %s\n",
2189 hid->version >> 8, hid->version & 0xff, c, hid->name, path);
2194 static int hid_suspend(struct usb_interface *intf, pm_message_t message)
2196 struct hid_device *hid = usb_get_intfdata (intf);
2198 spin_lock_irq(&hid->inlock); /* Sync with error handler */
2199 set_bit(HID_SUSPENDED, &hid->iofl);
2200 spin_unlock_irq(&hid->inlock);
2201 del_timer(&hid->io_retry);
2202 usb_kill_urb(hid->urbin);
2203 dev_dbg(&intf->dev, "suspend\n");
2207 static int hid_resume(struct usb_interface *intf)
2209 struct hid_device *hid = usb_get_intfdata (intf);
2212 clear_bit(HID_SUSPENDED, &hid->iofl);
2213 hid->retry_delay = 0;
2214 status = hid_start_in(hid);
2215 dev_dbg(&intf->dev, "resume status %d\n", status);
2219 /* Treat USB reset pretty much the same as suspend/resume */
2220 static void hid_pre_reset(struct usb_interface *intf)
2222 /* FIXME: What if the interface is already suspended? */
2223 hid_suspend(intf, PMSG_ON);
2226 static void hid_post_reset(struct usb_interface *intf)
2228 struct usb_device *dev = interface_to_usbdev (intf);
2230 hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
2231 /* FIXME: Any more reinitialization needed? */
2236 static struct usb_device_id hid_usb_ids [] = {
2237 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
2238 .bInterfaceClass = USB_INTERFACE_CLASS_HID },
2239 { } /* Terminating entry */
2242 MODULE_DEVICE_TABLE (usb, hid_usb_ids);
2244 static struct usb_driver hid_driver = {
2247 .disconnect = hid_disconnect,
2248 .suspend = hid_suspend,
2249 .resume = hid_resume,
2250 .pre_reset = hid_pre_reset,
2251 .post_reset = hid_post_reset,
2252 .id_table = hid_usb_ids,
2255 static int __init hid_init(void)
2258 retval = hiddev_init();
2260 goto hiddev_init_fail;
2261 retval = usb_register(&hid_driver);
2263 goto usb_register_fail;
2264 info(DRIVER_VERSION ":" DRIVER_DESC);
2273 static void __exit hid_exit(void)
2275 usb_deregister(&hid_driver);
2279 module_init(hid_init);
2280 module_exit(hid_exit);
2282 MODULE_AUTHOR(DRIVER_AUTHOR);
2283 MODULE_DESCRIPTION(DRIVER_DESC);
2284 MODULE_LICENSE(DRIVER_LICENSE);