- Linus: more PageDirty / swapcache handling
[davej-history.git] / drivers / usb / hid.c
blobf3901d24ad1207b96e17139f6315d4b2602652f8
1 /*
2 * $Id: hid.c,v 1.16 2000/09/18 21:38:55 vojtech Exp $
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000 Vojtech Pavlik
7 * USB HID support for the Linux input drivers
9 * Sponsored by SuSE
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
29 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
32 #include <linux/module.h>
33 #include <linux/malloc.h>
34 #include <linux/input.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/sched.h>
38 #include <linux/list.h>
39 #include <linux/mm.h>
40 #include <linux/smp_lock.h>
41 #include <linux/spinlock.h>
42 #undef DEBUG
43 #undef DEBUG_DATA
44 #include <linux/usb.h>
46 #include <asm/unaligned.h>
48 #include "hid.h"
50 #ifdef DEBUG
51 #include "hid-debug.h"
52 #else
53 #define hid_dump_input(a,b) do { } while (0)
54 #define hid_dump_device(c) do { } while (0)
55 #endif
57 #define unk KEY_UNKNOWN
59 static unsigned char hid_keyboard[256] = {
60 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
61 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
62 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
63 27, 43, 84, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
64 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
65 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
66 72, 73, 82, 83, 86,127,116,117, 85, 89, 90, 91, 92, 93, 94, 95,
67 120,121,122,123,134,138,130,132,128,129,131,137,133,135,136,113,
68 115,114,unk,unk,unk,124,unk,181,182,183,184,185,186,187,188,189,
69 190,191,192,193,194,195,196,197,198,unk,unk,unk,unk,unk,unk,unk,
70 unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
71 unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
72 unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
73 unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,unk,
74 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
75 150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk
78 static struct {
79 __s32 x;
80 __s32 y;
81 } hid_hat_to_axis[] = {{ 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}, { 0, 0}};
83 static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
84 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
87 * Register a new report for a device.
90 static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
92 struct hid_report_enum *report_enum = device->report_enum + type;
93 struct hid_report *report;
95 if (report_enum->report_id_hash[id])
96 return report_enum->report_id_hash[id];
98 if (!(report = kmalloc(sizeof(struct hid_report), GFP_KERNEL)))
99 return NULL;
100 memset(report, 0, sizeof(struct hid_report));
102 if (id != 0) report_enum->numbered = 1;
104 report->id = id;
105 report->type = type;
106 report->size = 0;
107 report->device = device;
108 report_enum->report_id_hash[id] = report;
110 list_add_tail(&report->list, &report_enum->report_list);
112 return report;
116 * Register a new field for this report.
119 static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
121 if (report->maxfield < HID_MAX_FIELDS) {
122 struct hid_field *field;
124 if (!(field = kmalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
125 + values * sizeof(unsigned), GFP_KERNEL)))
126 return NULL;
127 memset(field, 0, sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
128 + values * sizeof(unsigned));
130 report->field[report->maxfield++] = field;
131 field->usage = (struct hid_usage *)(field + 1);
132 field->value = (unsigned *)(field->usage + usages);
133 field->report = report;
135 return field;
138 dbg("too many fields in report");
139 return NULL;
143 * Open a collection. The type/usage is pushed on the stack.
146 static int open_collection(struct hid_parser *parser, unsigned type)
148 unsigned usage;
150 usage = parser->local.usage[0];
152 if (type == HID_COLLECTION_APPLICATION && !parser->device->application)
153 parser->device->application = usage;
155 if (parser->collection_stack_ptr < HID_COLLECTION_STACK_SIZE) { /* PUSH on stack */
156 struct hid_collection *collection = parser->collection_stack + parser->collection_stack_ptr++;
157 collection->type = type;
158 collection->usage = usage;
159 return 0;
162 dbg("collection stack overflow");
163 return -1;
167 * Close a collection.
170 static int close_collection(struct hid_parser *parser)
172 if (parser->collection_stack_ptr > 0) { /* POP from stack */
173 parser->collection_stack_ptr--;
174 return 0;
176 dbg("collection stack underflow");
177 return -1;
181 * Climb up the stack, search for the specified collection type
182 * and return the usage.
185 static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
187 int n;
188 for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
189 if (parser->collection_stack[n].type == type)
190 return parser->collection_stack[n].usage;
191 return 0; /* we know nothing about this usage type */
195 * Add a usage to the temporary parser table.
198 static int hid_add_usage(struct hid_parser *parser, unsigned usage)
200 if (parser->local.usage_index >= HID_MAX_USAGES) {
201 dbg("usage index exceeded");
202 return -1;
204 parser->local.usage[parser->local.usage_index++] = usage;
205 return 0;
209 * Register a new field for this report.
212 static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
214 struct hid_report *report;
215 struct hid_field *field;
216 int usages;
217 unsigned offset;
218 int i;
220 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
221 dbg("hid_register_report failed");
222 return -1;
225 if (HID_MAIN_ITEM_VARIABLE & ~flags) { /* ARRAY */
226 if (parser->global.logical_maximum <= parser->global.logical_minimum) {
227 dbg("logical range invalid %d %d", parser->global.logical_minimum, parser->global.logical_maximum);
228 return -1;
230 usages = parser->local.usage_index;
231 /* Hint: we can assume usages < MAX_USAGE here */
232 } else { /* VARIABLE */
233 usages = parser->global.report_count;
235 offset = report->size;
236 report->size += parser->global.report_size *
237 parser->global.report_count;
238 if (usages == 0)
239 return 0; /* ignore padding fields */
240 if ((field = hid_register_field(report, usages,
241 parser->global.report_count)) == NULL)
242 return 0;
243 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
244 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
245 for (i = 0; i < usages; i++) field->usage[i].hid = parser->local.usage[i];
246 field->maxusage = usages;
247 field->flags = flags;
248 field->report_offset = offset;
249 field->report_type = report_type;
250 field->report_size = parser->global.report_size;
251 field->report_count = parser->global.report_count;
252 field->logical_minimum = parser->global.logical_minimum;
253 field->logical_maximum = parser->global.logical_maximum;
254 field->physical_minimum = parser->global.physical_minimum;
255 field->physical_maximum = parser->global.physical_maximum;
256 field->unit_exponent = parser->global.unit_exponent;
257 field->unit = parser->global.unit;
258 return 0;
262 * Read data value from item.
265 static __inline__ __u32 item_udata(struct hid_item *item)
267 switch (item->size) {
268 case 1: return item->data.u8;
269 case 2: return item->data.u16;
270 case 4: return item->data.u32;
272 return 0;
275 static __inline__ __s32 item_sdata(struct hid_item *item)
277 switch (item->size) {
278 case 1: return item->data.s8;
279 case 2: return item->data.s16;
280 case 4: return item->data.s32;
282 return 0;
286 * Process a global item.
289 static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
291 switch (item->tag) {
293 case HID_GLOBAL_ITEM_TAG_PUSH:
295 if (parser->global_stack_ptr < HID_GLOBAL_STACK_SIZE) {
296 memcpy(parser->global_stack + parser->global_stack_ptr++,
297 &parser->global, sizeof(struct hid_global));
298 return 0;
300 dbg("global enviroment stack overflow");
301 return -1;
303 case HID_GLOBAL_ITEM_TAG_POP:
305 if (parser->global_stack_ptr > 0) {
306 memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr,
307 sizeof(struct hid_global));
308 return 0;
310 dbg("global enviroment stack underflow");
311 return -1;
313 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
314 parser->global.usage_page = item_udata(item);
315 return 0;
317 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
318 parser->global.logical_minimum = item_sdata(item);
319 return 0;
321 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
322 parser->global.logical_maximum = item_sdata(item);
323 return 0;
325 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
326 parser->global.physical_minimum = item_sdata(item);
327 return 0;
329 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
330 parser->global.physical_maximum = item_sdata(item);
331 return 0;
333 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
334 parser->global.unit_exponent = item_udata(item);
335 return 0;
337 case HID_GLOBAL_ITEM_TAG_UNIT:
338 parser->global.unit = item_udata(item);
339 return 0;
341 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
342 if ((parser->global.report_size = item_udata(item)) > 32) {
343 dbg("invalid report_size %d", parser->global.report_size);
344 return -1;
346 return 0;
348 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
349 if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) {
350 dbg("invalid report_count %d", parser->global.report_count);
351 return -1;
353 return 0;
355 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
356 if ((parser->global.report_id = item_udata(item)) == 0) {
357 dbg("report_id 0 is invalid");
358 return -1;
360 return 0;
362 default:
363 dbg("unknown global tag 0x%x", item->tag);
364 return -1;
369 * Process a local item.
372 static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
374 __u32 data;
376 if (item->size == 0) {
377 dbg("item data expected for local item");
378 return -1;
381 data = item_udata(item);
383 switch (item->tag) {
385 case HID_LOCAL_ITEM_TAG_DELIMITER:
387 if (data) {
389 * We treat items before the first delimiter
390 * as global to all usage sets (branch 0).
391 * In the moment we process only these global
392 * items and the first delimiter set.
394 if (parser->local.delimiter_depth != 0) {
395 dbg("nested delimiters");
396 return -1;
398 parser->local.delimiter_depth++;
399 parser->local.delimiter_branch++;
400 } else {
401 if (parser->local.delimiter_depth < 1) {
402 dbg("bogus close delimiter");
403 return -1;
405 parser->local.delimiter_depth--;
407 return 1;
409 case HID_LOCAL_ITEM_TAG_USAGE:
411 if (parser->local.delimiter_branch < 2) {
412 if (item->size <= 2)
413 data = (parser->global.usage_page << 16) + data;
414 return hid_add_usage(parser, data);
416 dbg("alternative usage ignored");
417 return 0;
419 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
421 if (parser->local.delimiter_branch < 2) {
422 if (item->size <= 2)
423 data = (parser->global.usage_page << 16) + data;
424 parser->local.usage_minimum = data;
425 return 0;
427 dbg("alternative usage ignored");
428 return 0;
430 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
432 if (parser->local.delimiter_branch < 2) {
433 unsigned n;
434 if (item->size <= 2)
435 data = (parser->global.usage_page << 16) + data;
436 for (n = parser->local.usage_minimum; n <= data; n++)
437 if (hid_add_usage(parser, n)) {
438 dbg("hid_add_usage failed\n");
439 return -1;
441 return 0;
443 dbg("alternative usage ignored");
444 return 0;
446 default:
448 dbg("unknown local item tag 0x%x", item->tag);
449 return 0;
454 * Process a main item.
457 static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
459 __u32 data;
460 int ret;
462 data = item_udata(item);
464 switch (item->tag) {
465 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
466 ret = open_collection(parser, data & 3);
467 break;
468 case HID_MAIN_ITEM_TAG_END_COLLECTION:
469 ret = close_collection(parser);
470 break;
471 case HID_MAIN_ITEM_TAG_INPUT:
472 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
473 break;
474 case HID_MAIN_ITEM_TAG_OUTPUT:
475 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
476 break;
477 case HID_MAIN_ITEM_TAG_FEATURE:
478 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
479 break;
480 default:
481 dbg("unknown main item tag 0x%x", item->tag);
482 ret = 0;
485 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
487 return ret;
491 * Process a reserved item.
494 static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
496 dbg("reserved item type, tag 0x%x", item->tag);
497 return 0;
501 * Free a report and all registered fields. The field->usage and
502 * field->value table's are allocated behind the field, so we need
503 * only to free(field) itself.
506 static void hid_free_report(struct hid_report *report)
508 unsigned n;
510 for (n = 0; n < report->maxfield; n++)
511 kfree(report->field[n]);
512 kfree(report);
516 * Free a device structure, all reports, and all fields.
519 static void hid_free_device(struct hid_device *device)
521 unsigned i,j;
523 for (i = 0; i < HID_REPORT_TYPES; i++) {
524 struct hid_report_enum *report_enum = device->report_enum + i;
526 for (j = 0; j < 256; j++) {
527 struct hid_report *report = report_enum->report_id_hash[j];
528 if (report) hid_free_report(report);
532 if (device->rdesc) kfree(device->rdesc);
536 * Fetch a report description item from the data stream. We support long
537 * items, though they are not used yet.
540 static __u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
542 if ((end - start) > 0) {
544 __u8 b = *start++;
545 item->type = (b >> 2) & 3;
546 item->tag = (b >> 4) & 15;
548 if (item->tag == HID_ITEM_TAG_LONG) {
550 item->format = HID_ITEM_FORMAT_LONG;
552 if ((end - start) >= 2) {
554 item->size = *start++;
555 item->tag = *start++;
557 if ((end - start) >= item->size) {
558 item->data.longdata = start;
559 start += item->size;
560 return start;
563 } else {
565 item->format = HID_ITEM_FORMAT_SHORT;
566 item->size = b & 3;
567 switch (item->size) {
569 case 0:
570 return start;
572 case 1:
573 if ((end - start) >= 1) {
574 item->data.u8 = *start++;
575 return start;
577 break;
579 case 2:
580 if ((end - start) >= 2) {
581 item->data.u16 = le16_to_cpu( get_unaligned(((__u16*)start)++));
582 return start;
585 case 3:
586 item->size++;
587 if ((end - start) >= 4) {
588 item->data.u32 = le32_to_cpu( get_unaligned(((__u32*)start)++));
589 return start;
594 return NULL;
598 * Parse a report description into a hid_device structure. Reports are
599 * enumerated, fields are attached to these reports.
602 static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
604 struct hid_device *device;
605 struct hid_parser *parser;
606 struct hid_item item;
607 __u8 *end;
608 unsigned i;
609 static int (*dispatch_type[])(struct hid_parser *parser,
610 struct hid_item *item) = {
611 hid_parser_main,
612 hid_parser_global,
613 hid_parser_local,
614 hid_parser_reserved
617 if (!(device = kmalloc(sizeof(struct hid_device), GFP_KERNEL)))
618 return NULL;
619 memset(device, 0, sizeof(struct hid_device));
621 for (i = 0; i < HID_REPORT_TYPES; i++)
622 INIT_LIST_HEAD(&device->report_enum[i].report_list);
624 if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) {
625 kfree(device);
626 return NULL;
628 memcpy(device->rdesc, start, size);
630 if (!(parser = kmalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
631 kfree(device->rdesc);
632 kfree(device);
633 return NULL;
635 memset(parser, 0, sizeof(struct hid_parser));
636 parser->device = device;
638 end = start + size;
639 while ((start = fetch_item(start, end, &item)) != 0) {
640 if (item.format != HID_ITEM_FORMAT_SHORT) {
641 dbg("unexpected long global item");
642 hid_free_device(device);
643 kfree(parser);
644 return NULL;
646 if (dispatch_type[item.type](parser, &item)) {
647 dbg("item %u %u %u %u parsing failed\n",
648 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
649 hid_free_device(device);
650 kfree(parser);
651 return NULL;
654 if (start == end) {
655 if (parser->collection_stack_ptr) {
656 dbg("unbalanced collection at end of report description");
657 hid_free_device(device);
658 kfree(parser);
659 return NULL;
661 if (parser->local.delimiter_depth) {
662 dbg("unbalanced delimiter at end of report description");
663 hid_free_device(device);
664 kfree(parser);
665 return NULL;
667 kfree(parser);
668 return device;
672 dbg("item fetching failed at offset %d\n", (int)(end - start));
673 hid_free_device(device);
674 kfree(parser);
675 return NULL;
679 * Convert a signed n-bit integer to signed 32-bit integer. Common
680 * cases are done through the compiler, the screwed things has to be
681 * done by hand.
684 static __inline__ __s32 snto32(__u32 value, unsigned n)
686 switch (n) {
687 case 8: return ((__s8)value);
688 case 16: return ((__s16)value);
689 case 32: return ((__s32)value);
691 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
695 * Convert a signed 32-bit integer to a signed n-bit integer.
698 static __inline__ __u32 s32ton(__s32 value, unsigned n)
700 __s32 a = value >> (n - 1);
701 if (a && a != -1) return value > 0 ? 1 << (n - 1) : (1 << n) - 1;
702 return value & ((1 << n) - 1);
706 * Extract/implement a data field from/to a report. We use 64-bit unsigned,
707 * 32-bit aligned, so that we can possibly have alignment problems on some
708 * odd architectures.
711 static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
713 report += (offset >> 5) << 2; offset &= 31;
714 return (le64_to_cpu(get_unaligned((__u64*)report)) >> offset) & ((1 << n) - 1);
717 static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
719 report += (offset >> 5) << 2; offset &= 31;
720 *(__u64*)report &= cpu_to_le64(~((((__u64) 1 << n) - 1) << offset));
721 *(__u64*)report |= cpu_to_le64((__u64)value << offset);
724 static void hid_configure_usage(struct hid_device *device, struct hid_field *field, struct hid_usage *usage)
726 struct input_dev *input = &device->input;
727 int max;
728 unsigned long *bit;
730 switch (usage->hid & HID_USAGE_PAGE) {
732 case HID_UP_KEYBOARD:
734 set_bit(EV_REP, input->evbit);
735 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
737 if ((usage->hid & HID_USAGE) < 256) {
738 if (!(usage->code = hid_keyboard[usage->hid & HID_USAGE]))
739 return;
740 clear_bit(usage->code, bit);
741 } else
742 usage->code = KEY_UNKNOWN;
744 break;
746 case HID_UP_BUTTON:
748 usage->code = ((usage->hid - 1) & 0xf) + 0x100;
749 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
751 switch (device->application) {
752 case HID_GD_GAMEPAD: usage->code += 0x10;
753 case HID_GD_JOYSTICK: usage->code += 0x10;
754 case HID_GD_MOUSE: usage->code += 0x10; break;
755 default:
756 if (field->physical == HID_GD_POINTER)
757 usage->code += 0x10;
758 break;
760 break;
762 case HID_UP_GENDESK:
764 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */
765 switch (usage->hid & 0xf) {
766 case 0x1: usage->code = KEY_POWER; break;
767 case 0x2: usage->code = KEY_SLEEP; break;
768 case 0x3: usage->code = KEY_WAKEUP; break;
769 default: usage->code = KEY_UNKNOWN; break;
771 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
772 break;
775 usage->code = usage->hid & 0xf;
777 if (field->report_size == 1) {
778 usage->code = BTN_MISC;
779 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
780 break;
783 if (field->flags & HID_MAIN_ITEM_RELATIVE) {
784 usage->type = EV_REL; bit = input->relbit; max = REL_MAX;
785 break;
788 usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
790 if (usage->hid == HID_GD_HATSWITCH) {
791 usage->code = ABS_HAT0X;
792 usage->hat = 1 + (field->logical_maximum == 4);
794 break;
796 case HID_UP_LED:
798 usage->code = (usage->hid - 1) & 0xf;
799 usage->type = EV_LED; bit = input->ledbit; max = LED_MAX;
800 break;
802 case HID_UP_DIGITIZER:
804 switch (usage->hid & 0xff) {
806 case 0x30: /* TipPressure */
808 if (!test_bit(BTN_TOUCH, input->keybit)) {
809 device->quirks |= HID_QUIRK_NOTOUCH;
810 set_bit(EV_KEY, input->evbit);
811 set_bit(BTN_TOUCH, input->keybit);
813 usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
814 usage->code = ABS_PRESSURE;
815 clear_bit(usage->code, bit);
816 break;
818 case 0x32: /* InRange */
820 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
821 switch (field->physical & 0xff) {
822 case 0x21: usage->code = BTN_TOOL_MOUSE; break;
823 case 0x22: usage->code = BTN_TOOL_FINGER; break;
824 default: usage->code = BTN_TOOL_PEN; break;
826 break;
828 case 0x3c: /* Invert */
830 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
831 usage->code = BTN_TOOL_RUBBER;
832 clear_bit(usage->code, bit);
833 break;
835 case 0x33: /* Touch */
836 case 0x42: /* TipSwitch */
837 case 0x43: /* TipSwitch2 */
839 device->quirks &= ~HID_QUIRK_NOTOUCH;
840 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
841 usage->code = BTN_TOUCH;
842 clear_bit(usage->code, bit);
843 break;
845 case 0x44: /* BarrelSwitch */
847 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
848 usage->code = BTN_STYLUS;
849 clear_bit(usage->code, bit);
850 break;
852 default: goto unknown;
854 break;
856 case HID_UP_CONSUMER: /* USB HUT v1.1, pages 56-62 */
858 switch (usage->hid & HID_USAGE) {
859 case 0x000: usage->code = 0; break;
860 case 0x034: usage->code = KEY_SLEEP; break;
861 case 0x036: usage->code = BTN_MISC; break;
862 case 0x08a: usage->code = KEY_WWW; break;
863 case 0x095: usage->code = KEY_HELP; break;
865 case 0x0b4: usage->code = KEY_REWIND; break;
866 case 0x0b5: usage->code = KEY_NEXTSONG; break;
867 case 0x0b6: usage->code = KEY_PREVIOUSSONG; break;
868 case 0x0b7: usage->code = KEY_STOPCD; break;
869 case 0x0b8: usage->code = KEY_EJECTCD; break;
870 case 0x0cd: usage->code = KEY_PLAYPAUSE; break;
872 case 0x0e2: usage->code = KEY_MUTE; break;
873 case 0x0e9: usage->code = KEY_VOLUMEUP; break;
874 case 0x0ea: usage->code = KEY_VOLUMEDOWN; break;
876 case 0x183: usage->code = KEY_CONFIG; break;
877 case 0x18a: usage->code = KEY_MAIL; break;
878 case 0x192: usage->code = KEY_CALC; break;
879 case 0x194: usage->code = KEY_FILE; break;
881 case 0x21a: usage->code = KEY_UNDO; break;
882 case 0x21b: usage->code = KEY_COPY; break;
883 case 0x21c: usage->code = KEY_CUT; break;
884 case 0x21d: usage->code = KEY_PASTE; break;
886 case 0x221: usage->code = KEY_FIND; break;
887 case 0x223: usage->code = KEY_HOMEPAGE; break;
888 case 0x224: usage->code = KEY_BACK; break;
889 case 0x225: usage->code = KEY_FORWARD; break;
890 case 0x226: usage->code = KEY_STOP; break;
891 case 0x227: usage->code = KEY_REFRESH; break;
892 case 0x22a: usage->code = KEY_BOOKMARKS; break;
894 default: usage->code = KEY_UNKNOWN; break;
898 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
899 break;
901 default:
902 unknown:
904 if (field->report_size == 1) {
905 usage->code = BTN_MISC;
906 usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX;
907 break;
910 if (field->flags & HID_MAIN_ITEM_RELATIVE) {
911 usage->code = REL_MISC;
912 usage->type = EV_REL; bit = input->relbit; max = REL_MAX;
913 break;
916 usage->code = ABS_MISC;
917 usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX;
918 break;
921 set_bit(usage->type, input->evbit);
923 while (usage->code <= max && test_and_set_bit(usage->code, bit)) {
924 usage->code = find_next_zero_bit(bit, max + 1, usage->code);
927 if (usage->code > max) return;
929 if (usage->type == EV_ABS) {
930 int a = field->logical_minimum;
931 int b = field->logical_maximum;
933 input->absmin[usage->code] = a;
934 input->absmax[usage->code] = b;
935 input->absfuzz[usage->code] = (b - a) >> 8;
936 input->absflat[usage->code] = (b - a) >> 4;
939 if (usage->hat) {
940 int i;
941 for (i = usage->code; i < usage->code + 2 && i <= max; i++) {
942 input->absmax[i] = 1;
943 input->absmin[i] = -1;
944 input->absfuzz[i] = 0;
945 input->absflat[i] = 0;
947 set_bit(usage->code + 1, input->absbit);
951 static void hid_process_event(struct input_dev *input, int *quirks, struct hid_field *field, struct hid_usage *usage, __s32 value)
953 hid_dump_input(usage, value);
955 if (usage->hat) {
956 if (usage->hat == 2) value = value * 2;
957 if (value > 8) value = 8;
958 input_event(input, usage->type, usage->code , hid_hat_to_axis[value].x);
959 input_event(input, usage->type, usage->code + 1, hid_hat_to_axis[value].y);
960 return;
963 if (usage->hid == (HID_UP_DIGITIZER | 0x003c)) { /* Invert */
964 *quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT);
965 return;
968 if (usage->hid == (HID_UP_DIGITIZER | 0x0032)) { /* InRange */
969 if (value) {
970 input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1);
971 return;
973 input_event(input, usage->type, usage->code, 0);
974 input_event(input, usage->type, BTN_TOOL_RUBBER, 0);
975 return;
978 if (usage->hid == (HID_UP_DIGITIZER | 0x0030) && (*quirks & HID_QUIRK_NOTOUCH)) { /* Pressure */
979 int a = field->logical_minimum;
980 int b = field->logical_maximum;
981 input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
984 if((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UKNOWN */
985 return;
987 input_event(input, usage->type, usage->code, value);
989 if ((field->flags & HID_MAIN_ITEM_RELATIVE) && (usage->type == EV_KEY))
990 input_event(input, usage->type, usage->code, 0);
994 * Search an array for a value.
997 static __inline__ int search(__s32 *array, __s32 value, unsigned n)
999 while (n--) if (*array++ == value) return 0;
1000 return -1;
1004 * Analyse a received field, and fetch the data from it. The field
1005 * content is stored for next report processing (we do differential
1006 * reporting to the layer).
1009 static void hid_input_field(struct hid_device *dev, struct hid_field *field, __u8 *data)
1011 unsigned n;
1012 unsigned count = field->report_count;
1013 unsigned offset = field->report_offset;
1014 unsigned size = field->report_size;
1015 __s32 min = field->logical_minimum;
1016 __s32 max = field->logical_maximum;
1017 __s32 value[count]; /* WARNING: gcc specific */
1019 for (n = 0; n < count; n++)
1020 value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
1021 extract(data, offset + n * size, size);
1023 for (n = 0; n < count; n++) {
1025 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
1027 if (field->flags & HID_MAIN_ITEM_RELATIVE) {
1028 if (!value[n]) continue;
1029 } else {
1030 if (value[n] == field->value[n]) continue;
1032 hid_process_event(&dev->input, &dev->quirks, field, &field->usage[n], value[n]);
1034 } else {
1036 if (field->value[n] >= min && field->value[n] <= max /* non-NULL value */
1037 && field->usage[field->value[n] - min].hid /* nonzero usage */
1038 && search(value, field->value[n], count))
1039 hid_process_event(&dev->input, &dev->quirks, field,
1040 &field->usage[field->value[n] - min], 0);
1042 if (value[n] >= min && value[n] <= max /* non-NULL value */
1043 && field->usage[value[n] - min].hid /* nonzero usage */
1044 && search(field->value, value[n], count))
1045 hid_process_event(&dev->input, &dev->quirks,
1046 field, &field->usage[value[n] - min], 1);
1050 memcpy(field->value, value, count * sizeof(__s32));
1054 * Interrupt input handler - analyse a received report.
1057 static void hid_irq(struct urb *urb)
1059 struct hid_device *device = urb->context;
1060 struct hid_report_enum *report_enum = device->report_enum + HID_INPUT_REPORT;
1061 struct hid_report *report;
1062 __u8 *data = urb->transfer_buffer;
1063 int len = urb->actual_length;
1064 int n;
1066 if (urb->status) {
1067 dbg("nonzero status in irq %d", urb->status);
1068 return;
1071 if (!len) {
1072 dbg("empty report");
1073 return;
1076 #ifdef DEBUG_DATA
1077 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered) = ", len, report_enum->numbered ? "" : "un");
1078 for (n = 0; n < len; n++)
1079 printk(" %02x", data[n]);
1080 printk("\n");
1081 #endif
1083 n = 0; /* Normally report number is 0 */
1085 if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */
1086 n = *data++;
1087 len--;
1090 if (!(report = report_enum->report_id_hash[n])) {
1091 dbg("undefined report_id %d received", n);
1092 #ifdef DEBUG
1093 printk(KERN_DEBUG __FILE__ ": report (size %u) = ", len);
1094 for (n = 0; n < len; n++)
1095 printk(" %02x", data[n]);
1096 printk("\n");
1097 #endif
1099 return;
1102 if (len < ((report->size - 1) >> 3) + 1) {
1103 dbg("report %d is too short, (%d < %d)", report->id, len, ((report->size - 1) >> 3) + 1);
1104 return;
1107 for (n = 0; n < report->maxfield; n++)
1108 hid_input_field(device, report->field[n], data);
1110 return;
1114 * hid_read_report() s intended to read the hid devices values even
1115 * before the input device is registered, so that the userland interface
1116 * modules start with real values. This is especially important for joydev.c
1117 * automagic calibration. Doesn't work yet, though. Don't know why, the control
1118 * request just times out on most devices I have and returns nonsense on others.
1121 static void hid_read_report(struct hid_device *hid, struct hid_report *report)
1123 #if 0
1124 int rlen = ((report->size - 1) >> 3) + 1;
1125 char rdata[rlen];
1126 struct urb urb;
1127 int read, j;
1129 memset(&urb, 0, sizeof(struct urb));
1130 memset(rdata, 0, rlen);
1132 urb.transfer_buffer = rdata;
1133 urb.actual_length = rlen;
1134 urb.context = hid;
1136 dbg("getting report type %d id %d len %d", report->type + 1, report->id, rlen);
1138 if ((read = usb_get_report(hid->dev, hid->ifnum, report->type + 1, report->id, rdata, rlen)) != rlen) {
1139 dbg("reading report failed rlen %d read %d", rlen, read);
1140 #ifdef DEBUG
1141 printk(KERN_DEBUG __FILE__ ": report = ");
1142 for (j = 0; j < rlen; j++) printk(" %02x", rdata[j]);
1143 printk("\n");
1144 #endif
1145 return;
1148 hid_irq(&urb);
1149 #endif
1153 * Output the field into the report.
1156 static void hid_output_field(struct hid_field *field, __u8 *data)
1158 unsigned count = field->report_count;
1159 unsigned offset = field->report_offset;
1160 unsigned size = field->report_size;
1161 unsigned n;
1163 for (n = 0; n < count; n++) {
1164 if (field->logical_minimum < 0) /* signed values */
1165 implement(data, offset + n * size, size, s32ton(field->value[n], size));
1166 else /* unsigned values */
1167 implement(data, offset + n * size, size, field->value[n]);
1172 * Create a report.
1175 void hid_output_report(struct hid_report *report, __u8 *data)
1177 unsigned n;
1178 for (n = 0; n < report->maxfield; n++)
1179 hid_output_field(report->field[n], data);
1183 * Set a field value. The report this field belongs to has to be
1184 * created and transfered to the device, to set this value in the
1185 * device.
1188 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1190 unsigned size = field->report_size;
1192 hid_dump_input(field->usage + offset, value);
1194 if (offset >= field->report_count) {
1195 dbg("offset exceeds report_count");
1196 return -1;
1198 if (field->logical_minimum < 0) {
1199 if (value != snto32(s32ton(value, size), size)) {
1200 dbg("value %d is out of range", value);
1201 return -1;
1204 if ( (value > field->logical_maximum)
1205 || (value < field->logical_minimum)) {
1206 dbg("value %d is invalid", value);
1207 return -1;
1209 field->value[offset] = value;
1210 return 0;
1213 static int hid_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field)
1215 struct hid_report_enum *report_enum = hid->report_enum + HID_OUTPUT_REPORT;
1216 struct list_head *list = report_enum->report_list.next;
1217 int i, j;
1219 while (list != &report_enum->report_list) {
1220 struct hid_report *report = (struct hid_report *) list;
1221 list = list->next;
1222 for (i = 0; i < report->maxfield; i++) {
1223 *field = report->field[i];
1224 for (j = 0; j < (*field)->maxusage; j++)
1225 if ((*field)->usage[j].type == type && (*field)->usage[j].code == code)
1226 return j;
1229 return -1;
1232 static int hid_submit_out(struct hid_device *hid)
1234 hid->urbout.transfer_buffer_length = hid->out[hid->outtail].dr.length;
1235 hid->urbout.transfer_buffer = hid->out[hid->outtail].buffer;
1236 hid->urbout.setup_packet = (void *) &(hid->out[hid->outtail].dr);
1237 hid->urbout.dev = hid->dev;
1239 if (usb_submit_urb(&hid->urbout)) {
1240 err("usb_submit_urb(out) failed");
1241 return -1;
1244 return 0;
1247 static void hid_ctrl(struct urb *urb)
1249 struct hid_device *hid = urb->context;
1251 if (urb->status)
1252 warn("ctrl urb status %d received", urb->status);
1254 hid->outtail = (hid->outtail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
1256 if (hid->outhead != hid->outtail)
1257 hid_submit_out(hid);
1260 static int hid_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
1262 struct hid_device *hid = dev->private;
1263 struct hid_field *field = NULL;
1264 int offset;
1266 if ((offset = hid_find_field(hid, type, code, &field)) == -1) {
1267 warn("event field not found");
1268 return -1;
1271 hid_set_field(field, offset, value);
1272 hid_output_report(field->report, hid->out[hid->outhead].buffer);
1274 hid->out[hid->outhead].dr.value = 0x200 | field->report->id;
1275 hid->out[hid->outhead].dr.length = ((field->report->size - 1) >> 3) + 1;
1277 hid->outhead = (hid->outhead + 1) & (HID_CONTROL_FIFO_SIZE - 1);
1279 if (hid->outhead == hid->outtail)
1280 hid->outtail = (hid->outtail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
1282 if (hid->urbout.status != -EINPROGRESS)
1283 hid_submit_out(hid);
1285 return 0;
1288 static int hid_open(struct input_dev *dev)
1290 struct hid_device *hid = dev->private;
1292 if (hid->open++)
1293 return 0;
1295 hid->urb.dev = hid->dev;
1297 if (usb_submit_urb(&hid->urb))
1298 return -EIO;
1300 return 0;
1303 static void hid_close(struct input_dev *dev)
1305 struct hid_device *hid = dev->private;
1307 if (!--hid->open)
1308 usb_unlink_urb(&hid->urb);
1312 * Configure the input layer interface
1313 * Read all reports and initalize the absoulte field values.
1316 static void hid_init_input(struct hid_device *hid)
1318 struct hid_report_enum *report_enum;
1319 struct list_head *list;
1320 int i, j, k;
1322 hid->input.private = hid;
1323 hid->input.event = hid_event;
1324 hid->input.open = hid_open;
1325 hid->input.close = hid_close;
1327 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
1329 report_enum = hid->report_enum + k;
1330 list = report_enum->report_list.next;
1332 while (list != &report_enum->report_list) {
1334 struct hid_report *report = (struct hid_report *) list;
1336 list = list->next;
1338 for (i = 0; i < report->maxfield; i++)
1339 for (j = 0; j < report->field[i]->maxusage; j++)
1340 hid_configure_usage(hid, report->field[i], report->field[i]->usage + j);
1342 if (k == HID_INPUT_REPORT) {
1343 usb_set_idle(hid->dev, hid->ifnum, 0, report->id);
1344 hid_read_report(hid, report);
1350 #define USB_VENDOR_ID_WACOM 0x056a
1351 #define USB_DEVICE_ID_WACOM_GRAPHIRE 0x0010
1352 #define USB_DEVICE_ID_WACOM_INTUOS 0x0020
1354 struct hid_blacklist {
1355 __u16 idVendor;
1356 __u16 idProduct;
1357 } hid_blacklist[] = {
1358 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE },
1359 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS },
1360 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 1},
1361 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 2},
1362 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 3},
1363 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 4},
1364 { 0, 0 }
1367 static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum, char *name)
1369 struct usb_interface_descriptor *interface = dev->actconfig->interface[ifnum].altsetting + 0;
1370 struct hid_descriptor *hdesc;
1371 struct hid_device *hid;
1372 unsigned rsize = 0;
1373 int n;
1375 for (n = 0; hid_blacklist[n].idVendor; n++)
1376 if ((hid_blacklist[n].idVendor == dev->descriptor.idVendor) &&
1377 (hid_blacklist[n].idProduct == dev->descriptor.idProduct)) return NULL;
1379 if (usb_get_extra_descriptor(interface, USB_DT_HID, &hdesc)
1380 && usb_get_extra_descriptor(&interface->endpoint[0], USB_DT_HID, &hdesc)) {
1381 dbg("class descriptor not present\n");
1382 return NULL;
1385 for (n = 0; n < hdesc->bNumDescriptors; n++)
1386 if (hdesc->desc[n].bDescriptorType == USB_DT_REPORT)
1387 rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
1389 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
1390 dbg("weird size of report descriptor (%u)", rsize);
1391 return NULL;
1395 __u8 rdesc[rsize];
1397 if ((n = usb_get_class_descriptor(dev, interface->bInterfaceNumber, USB_DT_REPORT, 0, rdesc, rsize)) < 0) {
1398 dbg("reading report descriptor failed");
1399 return NULL;
1402 #ifdef DEBUG_DATA
1403 printk(KERN_DEBUG __FILE__ ": report (size %u, read %d) = ", rsize, n);
1404 for (n = 0; n < rsize; n++)
1405 printk(" %02x", (unsigned) rdesc[n]);
1406 printk("\n");
1407 #endif
1409 if (!(hid = hid_parse_report(rdesc, rsize))) {
1410 dbg("parsing report descriptor failed");
1411 return NULL;
1415 for (n = 0; n < interface->bNumEndpoints; n++) {
1417 struct usb_endpoint_descriptor *endpoint = &interface->endpoint[n];
1418 int pipe, maxp;
1420 if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
1421 continue;
1423 if (!(endpoint->bEndpointAddress & 0x80)) /* Not an input endpoint */
1424 continue;
1426 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
1427 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
1429 FILL_INT_URB(&hid->urb, dev, pipe, hid->buffer, maxp > 32 ? 32 : maxp, hid_irq, hid, endpoint->bInterval);
1431 break;
1434 if (n == interface->bNumEndpoints) {
1435 dbg("couldn't find an input interrupt endpoint");
1436 hid_free_device(hid);
1437 return NULL;
1440 hid->version = hdesc->bcdHID;
1441 hid->country = hdesc->bCountryCode;
1442 hid->dev = dev;
1443 hid->ifnum = interface->bInterfaceNumber;
1445 for (n = 0; n < HID_CONTROL_FIFO_SIZE; n++) {
1446 hid->out[n].dr.requesttype = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
1447 hid->out[n].dr.request = USB_REQ_SET_REPORT;
1448 hid->out[n].dr.index = hid->ifnum;
1451 hid->input.name = hid->name;
1452 hid->input.idbus = BUS_USB;
1453 hid->input.idvendor = dev->descriptor.idVendor;
1454 hid->input.idproduct = dev->descriptor.idProduct;
1455 hid->input.idversion = dev->descriptor.bcdDevice;
1457 if (strlen(name))
1458 strcpy(hid->name, name);
1459 else
1460 sprintf(hid->name, "USB HID %s %04x:%04x",
1461 ((hid->application >= 0x00010000) && (hid->application <= 0x00010008)) ?
1462 hid_types[hid->application & 0xffff] : "Device",
1463 hid->input.idvendor, hid->input.idproduct);
1465 FILL_CONTROL_URB(&hid->urbout, dev, usb_sndctrlpipe(dev, 0),
1466 (void*) &hid->out[0].dr, hid->out[0].buffer, 1, hid_ctrl, hid);
1468 if (interface->bInterfaceSubClass == 1)
1469 usb_set_protocol(dev, hid->ifnum, 1);
1471 return hid;
1474 static void* hid_probe(struct usb_device *dev, unsigned int ifnum,
1475 const struct usb_device_id *id)
1477 struct hid_device *hid;
1478 char name[128];
1479 char *buf;
1481 dbg("HID probe called for ifnum %d", ifnum);
1483 name[0] = 0;
1485 if (!(buf = kmalloc(63, GFP_KERNEL)))
1486 return NULL;
1488 if (dev->descriptor.iManufacturer &&
1489 usb_string(dev, dev->descriptor.iManufacturer, buf, 63) > 0)
1490 strcat(name, buf);
1491 if (dev->descriptor.iProduct &&
1492 usb_string(dev, dev->descriptor.iProduct, buf, 63) > 0)
1493 sprintf(name, "%s %s", name, buf);
1495 kfree(buf);
1497 if (!(hid = usb_hid_configure(dev, ifnum, name)))
1498 return NULL;
1500 hid_dump_device(hid);
1502 hid_init_input(hid);
1503 input_register_device(&hid->input);
1505 printk(KERN_INFO "input%d: USB HID v%x.%02x %s",
1506 hid->input.number,
1507 hid->version >> 8, hid->version & 0xff,
1508 ((hid->application >= 0x00010000) && (hid->application <= 0x00010008)) ?
1509 hid_types[hid->application & 0xffff] : "Device");
1511 if (strlen(name))
1512 printk(" [%s]", name);
1513 else
1514 printk(" [%04x:%04x]", hid->input.idvendor, hid->input.idproduct);
1516 printk(" on usb%d:%d.%d\n", dev->bus->busnum, dev->devnum, ifnum);
1518 return hid;
1521 static void hid_disconnect(struct usb_device *dev, void *ptr)
1523 struct hid_device *hid = ptr;
1525 dbg("cleanup called");
1526 usb_unlink_urb(&hid->urb);
1527 input_unregister_device(&hid->input);
1528 hid_free_device(hid);
1531 static struct usb_device_id hid_usb_ids [] = {
1532 { bInterfaceClass: USB_INTERFACE_CLASS_HID},
1533 { } /* Terminating entry */
1536 MODULE_DEVICE_TABLE (usb, hid_usb_ids);
1538 static struct usb_driver hid_driver = {
1539 name: "hid",
1540 probe: hid_probe,
1541 disconnect: hid_disconnect,
1542 id_table: hid_usb_ids,
1545 static int __init hid_init(void)
1547 usb_register(&hid_driver);
1548 return 0;
1551 static void __exit hid_exit(void)
1553 usb_deregister(&hid_driver);
1556 module_init(hid_init);
1557 module_exit(hid_exit);
1559 MODULE_AUTHOR("Andreas Gal, Vojtech Pavlik <vojtech@suse.cz>");
1560 MODULE_DESCRIPTION("USB HID support drivers");