2 * HID support for Linux
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/list.h>
23 #include <linux/spinlock.h>
24 #include <asm/unaligned.h>
25 #include <asm/byteorder.h>
26 #include <linux/input.h>
27 #include <linux/wait.h>
28 #include <linux/vmalloc.h>
29 #include <linux/sched.h>
31 #include <linux/hid.h>
32 #include <linux/hiddev.h>
33 #include <linux/hid-debug.h>
34 #include <linux/hidraw.h>
42 #define DRIVER_DESC "HID core driver"
43 #define DRIVER_LICENSE "GPL"
46 module_param_named(debug
, hid_debug
, int, 0600);
47 MODULE_PARM_DESC(debug
, "toggle HID debugging messages");
48 EXPORT_SYMBOL_GPL(hid_debug
);
51 * Register a new report for a device.
54 static struct hid_report
*hid_register_report(struct hid_device
*device
, unsigned type
, unsigned id
)
56 struct hid_report_enum
*report_enum
= device
->report_enum
+ type
;
57 struct hid_report
*report
;
59 if (report_enum
->report_id_hash
[id
])
60 return report_enum
->report_id_hash
[id
];
62 if (!(report
= kzalloc(sizeof(struct hid_report
), GFP_KERNEL
)))
66 report_enum
->numbered
= 1;
71 report
->device
= device
;
72 report_enum
->report_id_hash
[id
] = report
;
74 list_add_tail(&report
->list
, &report_enum
->report_list
);
80 * Register a new field for this report.
83 static struct hid_field
*hid_register_field(struct hid_report
*report
, unsigned usages
, unsigned values
)
85 struct hid_field
*field
;
87 if (report
->maxfield
== HID_MAX_FIELDS
) {
88 dbg_hid("too many fields in report\n");
92 if (!(field
= kzalloc(sizeof(struct hid_field
) + usages
* sizeof(struct hid_usage
)
93 + values
* sizeof(unsigned), GFP_KERNEL
))) return NULL
;
95 field
->index
= report
->maxfield
++;
96 report
->field
[field
->index
] = field
;
97 field
->usage
= (struct hid_usage
*)(field
+ 1);
98 field
->value
= (s32
*)(field
->usage
+ usages
);
99 field
->report
= report
;
105 * Open a collection. The type/usage is pushed on the stack.
108 static int open_collection(struct hid_parser
*parser
, unsigned type
)
110 struct hid_collection
*collection
;
113 usage
= parser
->local
.usage
[0];
115 if (parser
->collection_stack_ptr
== HID_COLLECTION_STACK_SIZE
) {
116 dbg_hid("collection stack overflow\n");
120 if (parser
->device
->maxcollection
== parser
->device
->collection_size
) {
121 collection
= kmalloc(sizeof(struct hid_collection
) *
122 parser
->device
->collection_size
* 2, GFP_KERNEL
);
123 if (collection
== NULL
) {
124 dbg_hid("failed to reallocate collection array\n");
127 memcpy(collection
, parser
->device
->collection
,
128 sizeof(struct hid_collection
) *
129 parser
->device
->collection_size
);
130 memset(collection
+ parser
->device
->collection_size
, 0,
131 sizeof(struct hid_collection
) *
132 parser
->device
->collection_size
);
133 kfree(parser
->device
->collection
);
134 parser
->device
->collection
= collection
;
135 parser
->device
->collection_size
*= 2;
138 parser
->collection_stack
[parser
->collection_stack_ptr
++] =
139 parser
->device
->maxcollection
;
141 collection
= parser
->device
->collection
+
142 parser
->device
->maxcollection
++;
143 collection
->type
= type
;
144 collection
->usage
= usage
;
145 collection
->level
= parser
->collection_stack_ptr
- 1;
147 if (type
== HID_COLLECTION_APPLICATION
)
148 parser
->device
->maxapplication
++;
154 * Close a collection.
157 static int close_collection(struct hid_parser
*parser
)
159 if (!parser
->collection_stack_ptr
) {
160 dbg_hid("collection stack underflow\n");
163 parser
->collection_stack_ptr
--;
168 * Climb up the stack, search for the specified collection type
169 * and return the usage.
172 static unsigned hid_lookup_collection(struct hid_parser
*parser
, unsigned type
)
175 for (n
= parser
->collection_stack_ptr
- 1; n
>= 0; n
--)
176 if (parser
->device
->collection
[parser
->collection_stack
[n
]].type
== type
)
177 return parser
->device
->collection
[parser
->collection_stack
[n
]].usage
;
178 return 0; /* we know nothing about this usage type */
182 * Add a usage to the temporary parser table.
185 static int hid_add_usage(struct hid_parser
*parser
, unsigned usage
)
187 if (parser
->local
.usage_index
>= HID_MAX_USAGES
) {
188 dbg_hid("usage index exceeded\n");
191 parser
->local
.usage
[parser
->local
.usage_index
] = usage
;
192 parser
->local
.collection_index
[parser
->local
.usage_index
] =
193 parser
->collection_stack_ptr
?
194 parser
->collection_stack
[parser
->collection_stack_ptr
- 1] : 0;
195 parser
->local
.usage_index
++;
200 * Register a new field for this report.
203 static int hid_add_field(struct hid_parser
*parser
, unsigned report_type
, unsigned flags
)
205 struct hid_report
*report
;
206 struct hid_field
*field
;
211 if (!(report
= hid_register_report(parser
->device
, report_type
, parser
->global
.report_id
))) {
212 dbg_hid("hid_register_report failed\n");
216 if (parser
->global
.logical_maximum
< parser
->global
.logical_minimum
) {
217 dbg_hid("logical range invalid %d %d\n", parser
->global
.logical_minimum
, parser
->global
.logical_maximum
);
221 offset
= report
->size
;
222 report
->size
+= parser
->global
.report_size
* parser
->global
.report_count
;
224 if (!parser
->local
.usage_index
) /* Ignore padding fields */
227 usages
= max_t(int, parser
->local
.usage_index
, parser
->global
.report_count
);
229 if ((field
= hid_register_field(report
, usages
, parser
->global
.report_count
)) == NULL
)
232 field
->physical
= hid_lookup_collection(parser
, HID_COLLECTION_PHYSICAL
);
233 field
->logical
= hid_lookup_collection(parser
, HID_COLLECTION_LOGICAL
);
234 field
->application
= hid_lookup_collection(parser
, HID_COLLECTION_APPLICATION
);
236 for (i
= 0; i
< usages
; i
++) {
238 /* Duplicate the last usage we parsed if we have excess values */
239 if (i
>= parser
->local
.usage_index
)
240 j
= parser
->local
.usage_index
- 1;
241 field
->usage
[i
].hid
= parser
->local
.usage
[j
];
242 field
->usage
[i
].collection_index
=
243 parser
->local
.collection_index
[j
];
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
;
263 * Read data value from item.
266 static u32
item_udata(struct hid_item
*item
)
268 switch (item
->size
) {
269 case 1: return item
->data
.u8
;
270 case 2: return item
->data
.u16
;
271 case 4: return item
->data
.u32
;
276 static s32
item_sdata(struct hid_item
*item
)
278 switch (item
->size
) {
279 case 1: return item
->data
.s8
;
280 case 2: return item
->data
.s16
;
281 case 4: return item
->data
.s32
;
287 * Process a global item.
290 static int hid_parser_global(struct hid_parser
*parser
, struct hid_item
*item
)
293 case HID_GLOBAL_ITEM_TAG_PUSH
:
295 if (parser
->global_stack_ptr
== HID_GLOBAL_STACK_SIZE
) {
296 dbg_hid("global enviroment stack overflow\n");
300 memcpy(parser
->global_stack
+ parser
->global_stack_ptr
++,
301 &parser
->global
, sizeof(struct hid_global
));
304 case HID_GLOBAL_ITEM_TAG_POP
:
306 if (!parser
->global_stack_ptr
) {
307 dbg_hid("global enviroment stack underflow\n");
311 memcpy(&parser
->global
, parser
->global_stack
+
312 --parser
->global_stack_ptr
, sizeof(struct hid_global
));
315 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE
:
316 parser
->global
.usage_page
= item_udata(item
);
319 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM
:
320 parser
->global
.logical_minimum
= item_sdata(item
);
323 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM
:
324 if (parser
->global
.logical_minimum
< 0)
325 parser
->global
.logical_maximum
= item_sdata(item
);
327 parser
->global
.logical_maximum
= item_udata(item
);
330 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM
:
331 parser
->global
.physical_minimum
= item_sdata(item
);
334 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM
:
335 if (parser
->global
.physical_minimum
< 0)
336 parser
->global
.physical_maximum
= item_sdata(item
);
338 parser
->global
.physical_maximum
= item_udata(item
);
341 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT
:
342 parser
->global
.unit_exponent
= item_sdata(item
);
345 case HID_GLOBAL_ITEM_TAG_UNIT
:
346 parser
->global
.unit
= item_udata(item
);
349 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE
:
350 parser
->global
.report_size
= item_udata(item
);
351 if (parser
->global
.report_size
> 32) {
352 dbg_hid("invalid report_size %d\n",
353 parser
->global
.report_size
);
358 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT
:
359 parser
->global
.report_count
= item_udata(item
);
360 if (parser
->global
.report_count
> HID_MAX_USAGES
) {
361 dbg_hid("invalid report_count %d\n",
362 parser
->global
.report_count
);
367 case HID_GLOBAL_ITEM_TAG_REPORT_ID
:
368 parser
->global
.report_id
= item_udata(item
);
369 if (parser
->global
.report_id
== 0) {
370 dbg_hid("report_id 0 is invalid\n");
376 dbg_hid("unknown global tag 0x%x\n", item
->tag
);
382 * Process a local item.
385 static int hid_parser_local(struct hid_parser
*parser
, struct hid_item
*item
)
390 if (item
->size
== 0) {
391 dbg_hid("item data expected for local item\n");
395 data
= item_udata(item
);
398 case HID_LOCAL_ITEM_TAG_DELIMITER
:
402 * We treat items before the first delimiter
403 * as global to all usage sets (branch 0).
404 * In the moment we process only these global
405 * items and the first delimiter set.
407 if (parser
->local
.delimiter_depth
!= 0) {
408 dbg_hid("nested delimiters\n");
411 parser
->local
.delimiter_depth
++;
412 parser
->local
.delimiter_branch
++;
414 if (parser
->local
.delimiter_depth
< 1) {
415 dbg_hid("bogus close delimiter\n");
418 parser
->local
.delimiter_depth
--;
422 case HID_LOCAL_ITEM_TAG_USAGE
:
424 if (parser
->local
.delimiter_branch
> 1) {
425 dbg_hid("alternative usage ignored\n");
430 data
= (parser
->global
.usage_page
<< 16) + data
;
432 return hid_add_usage(parser
, data
);
434 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM
:
436 if (parser
->local
.delimiter_branch
> 1) {
437 dbg_hid("alternative usage ignored\n");
442 data
= (parser
->global
.usage_page
<< 16) + data
;
444 parser
->local
.usage_minimum
= data
;
447 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM
:
449 if (parser
->local
.delimiter_branch
> 1) {
450 dbg_hid("alternative usage ignored\n");
455 data
= (parser
->global
.usage_page
<< 16) + data
;
457 for (n
= parser
->local
.usage_minimum
; n
<= data
; n
++)
458 if (hid_add_usage(parser
, n
)) {
459 dbg_hid("hid_add_usage failed\n");
466 dbg_hid("unknown local item tag 0x%x\n", item
->tag
);
473 * Process a main item.
476 static int hid_parser_main(struct hid_parser
*parser
, struct hid_item
*item
)
481 data
= item_udata(item
);
484 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION
:
485 ret
= open_collection(parser
, data
& 0xff);
487 case HID_MAIN_ITEM_TAG_END_COLLECTION
:
488 ret
= close_collection(parser
);
490 case HID_MAIN_ITEM_TAG_INPUT
:
491 ret
= hid_add_field(parser
, HID_INPUT_REPORT
, data
);
493 case HID_MAIN_ITEM_TAG_OUTPUT
:
494 ret
= hid_add_field(parser
, HID_OUTPUT_REPORT
, data
);
496 case HID_MAIN_ITEM_TAG_FEATURE
:
497 ret
= hid_add_field(parser
, HID_FEATURE_REPORT
, data
);
500 dbg_hid("unknown main item tag 0x%x\n", item
->tag
);
504 memset(&parser
->local
, 0, sizeof(parser
->local
)); /* Reset the local parser environment */
510 * Process a reserved item.
513 static int hid_parser_reserved(struct hid_parser
*parser
, struct hid_item
*item
)
515 dbg_hid("reserved item type, tag 0x%x\n", item
->tag
);
520 * Free a report and all registered fields. The field->usage and
521 * field->value table's are allocated behind the field, so we need
522 * only to free(field) itself.
525 static void hid_free_report(struct hid_report
*report
)
529 for (n
= 0; n
< report
->maxfield
; n
++)
530 kfree(report
->field
[n
]);
535 * Free a device structure, all reports, and all fields.
538 static void hid_device_release(struct device
*dev
)
540 struct hid_device
*device
= container_of(dev
, struct hid_device
, dev
);
543 for (i
= 0; i
< HID_REPORT_TYPES
; i
++) {
544 struct hid_report_enum
*report_enum
= device
->report_enum
+ i
;
546 for (j
= 0; j
< 256; j
++) {
547 struct hid_report
*report
= report_enum
->report_id_hash
[j
];
549 hid_free_report(report
);
553 kfree(device
->rdesc
);
554 kfree(device
->collection
);
559 * Fetch a report description item from the data stream. We support long
560 * items, though they are not used yet.
563 static u8
*fetch_item(__u8
*start
, __u8
*end
, struct hid_item
*item
)
567 if ((end
- start
) <= 0)
572 item
->type
= (b
>> 2) & 3;
573 item
->tag
= (b
>> 4) & 15;
575 if (item
->tag
== HID_ITEM_TAG_LONG
) {
577 item
->format
= HID_ITEM_FORMAT_LONG
;
579 if ((end
- start
) < 2)
582 item
->size
= *start
++;
583 item
->tag
= *start
++;
585 if ((end
- start
) < item
->size
)
588 item
->data
.longdata
= start
;
593 item
->format
= HID_ITEM_FORMAT_SHORT
;
596 switch (item
->size
) {
601 if ((end
- start
) < 1)
603 item
->data
.u8
= *start
++;
607 if ((end
- start
) < 2)
609 item
->data
.u16
= get_unaligned_le16(start
);
610 start
= (__u8
*)((__le16
*)start
+ 1);
615 if ((end
- start
) < 4)
617 item
->data
.u32
= get_unaligned_le32(start
);
618 start
= (__u8
*)((__le32
*)start
+ 1);
626 * hid_parse_report - parse device report
628 * @device: hid device
629 * @start: report start
632 * Parse a report description into a hid_device structure. Reports are
633 * enumerated, fields are attached to these reports.
634 * 0 returned on success, otherwise nonzero error value.
636 int hid_parse_report(struct hid_device
*device
, __u8
*start
,
639 struct hid_parser
*parser
;
640 struct hid_item item
;
643 static int (*dispatch_type
[])(struct hid_parser
*parser
,
644 struct hid_item
*item
) = {
651 if (device
->driver
->report_fixup
)
652 device
->driver
->report_fixup(device
, start
, size
);
654 device
->rdesc
= kmalloc(size
, GFP_KERNEL
);
655 if (device
->rdesc
== NULL
)
657 memcpy(device
->rdesc
, start
, size
);
658 device
->rsize
= size
;
660 parser
= vmalloc(sizeof(struct hid_parser
));
666 memset(parser
, 0, sizeof(struct hid_parser
));
667 parser
->device
= device
;
671 while ((start
= fetch_item(start
, end
, &item
)) != NULL
) {
673 if (item
.format
!= HID_ITEM_FORMAT_SHORT
) {
674 dbg_hid("unexpected long global item\n");
678 if (dispatch_type
[item
.type
](parser
, &item
)) {
679 dbg_hid("item %u %u %u %u parsing failed\n",
680 item
.format
, (unsigned)item
.size
, (unsigned)item
.type
, (unsigned)item
.tag
);
685 if (parser
->collection_stack_ptr
) {
686 dbg_hid("unbalanced collection at end of report description\n");
689 if (parser
->local
.delimiter_depth
) {
690 dbg_hid("unbalanced delimiter at end of report description\n");
698 dbg_hid("item fetching failed at offset %d\n", (int)(end
- start
));
703 EXPORT_SYMBOL_GPL(hid_parse_report
);
706 * Convert a signed n-bit integer to signed 32-bit integer. Common
707 * cases are done through the compiler, the screwed things has to be
711 static s32
snto32(__u32 value
, unsigned n
)
714 case 8: return ((__s8
)value
);
715 case 16: return ((__s16
)value
);
716 case 32: return ((__s32
)value
);
718 return value
& (1 << (n
- 1)) ? value
| (-1 << n
) : value
;
722 * Convert a signed 32-bit integer to a signed n-bit integer.
725 static u32
s32ton(__s32 value
, unsigned n
)
727 s32 a
= value
>> (n
- 1);
729 return value
< 0 ? 1 << (n
- 1) : (1 << (n
- 1)) - 1;
730 return value
& ((1 << n
) - 1);
734 * Extract/implement a data field from/to a little endian report (bit array).
736 * Code sort-of follows HID spec:
737 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
739 * While the USB HID spec allows unlimited length bit fields in "report
740 * descriptors", most devices never use more than 16 bits.
741 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
742 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
745 static __inline__ __u32
extract(__u8
*report
, unsigned offset
, unsigned n
)
750 printk(KERN_WARNING
"HID: extract() called with n (%d) > 32! (%s)\n",
753 report
+= offset
>> 3; /* adjust byte index */
754 offset
&= 7; /* now only need bit offset into one byte */
755 x
= get_unaligned_le64(report
);
756 x
= (x
>> offset
) & ((1ULL << n
) - 1); /* extract bit field */
761 * "implement" : set bits in a little endian bit stream.
762 * Same concepts as "extract" (see comments above).
763 * The data mangled in the bit stream remains in little endian
764 * order the whole time. It make more sense to talk about
765 * endianness of register values by considering a register
766 * a "cached" copy of the little endiad bit stream.
768 static __inline__
void implement(__u8
*report
, unsigned offset
, unsigned n
, __u32 value
)
771 u64 m
= (1ULL << n
) - 1;
774 printk(KERN_WARNING
"HID: implement() called with n (%d) > 32! (%s)\n",
778 printk(KERN_WARNING
"HID: implement() called with too large value %d! (%s)\n",
779 value
, current
->comm
);
783 report
+= offset
>> 3;
786 x
= get_unaligned_le64(report
);
788 x
|= ((u64
)value
) << offset
;
789 put_unaligned_le64(x
, report
);
793 * Search an array for a value.
796 static __inline__
int search(__s32
*array
, __s32 value
, unsigned n
)
799 if (*array
++ == value
)
806 * hid_match_report - check if driver's raw_event should be called
809 * @report_type: type to match against
811 * compare hid->driver->report_table->report_type to report->type
813 static int hid_match_report(struct hid_device
*hid
, struct hid_report
*report
)
815 const struct hid_report_id
*id
= hid
->driver
->report_table
;
817 if (!id
) /* NULL means all */
820 for (; id
->report_type
!= HID_TERMINATOR
; id
++)
821 if (id
->report_type
== HID_ANY_ID
||
822 id
->report_type
== report
->type
)
828 * hid_match_usage - check if driver's event should be called
831 * @usage: usage to match against
833 * compare hid->driver->usage_table->usage_{type,code} to
834 * usage->usage_{type,code}
836 static int hid_match_usage(struct hid_device
*hid
, struct hid_usage
*usage
)
838 const struct hid_usage_id
*id
= hid
->driver
->usage_table
;
840 if (!id
) /* NULL means all */
843 for (; id
->usage_type
!= HID_ANY_ID
- 1; id
++)
844 if ((id
->usage_hid
== HID_ANY_ID
||
845 id
->usage_hid
== usage
->hid
) &&
846 (id
->usage_type
== HID_ANY_ID
||
847 id
->usage_type
== usage
->type
) &&
848 (id
->usage_code
== HID_ANY_ID
||
849 id
->usage_code
== usage
->code
))
854 static void hid_process_event(struct hid_device
*hid
, struct hid_field
*field
,
855 struct hid_usage
*usage
, __s32 value
, int interrupt
)
857 struct hid_driver
*hdrv
= hid
->driver
;
860 hid_dump_input(hid
, usage
, value
);
862 if (hdrv
&& hdrv
->event
&& hid_match_usage(hid
, usage
)) {
863 ret
= hdrv
->event(hid
, field
, usage
, value
);
866 dbg_hid("%s's event failed with %d\n",
872 if (hid
->claimed
& HID_CLAIMED_INPUT
)
873 hidinput_hid_event(hid
, field
, usage
, value
);
874 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& interrupt
&& hid
->hiddev_hid_event
)
875 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
879 * Analyse a received field, and fetch the data from it. The field
880 * content is stored for next report processing (we do differential
881 * reporting to the layer).
884 static void hid_input_field(struct hid_device
*hid
, struct hid_field
*field
,
885 __u8
*data
, int interrupt
)
888 unsigned count
= field
->report_count
;
889 unsigned offset
= field
->report_offset
;
890 unsigned size
= field
->report_size
;
891 __s32 min
= field
->logical_minimum
;
892 __s32 max
= field
->logical_maximum
;
895 if (!(value
= kmalloc(sizeof(__s32
) * count
, GFP_ATOMIC
)))
898 for (n
= 0; n
< count
; n
++) {
900 value
[n
] = min
< 0 ? snto32(extract(data
, offset
+ n
* size
, size
), size
) :
901 extract(data
, offset
+ n
* size
, size
);
903 if (!(field
->flags
& HID_MAIN_ITEM_VARIABLE
) /* Ignore report if ErrorRollOver */
904 && value
[n
] >= min
&& value
[n
] <= max
905 && field
->usage
[value
[n
] - min
].hid
== HID_UP_KEYBOARD
+ 1)
909 for (n
= 0; n
< count
; n
++) {
911 if (HID_MAIN_ITEM_VARIABLE
& field
->flags
) {
912 hid_process_event(hid
, field
, &field
->usage
[n
], value
[n
], interrupt
);
916 if (field
->value
[n
] >= min
&& field
->value
[n
] <= max
917 && field
->usage
[field
->value
[n
] - min
].hid
918 && search(value
, field
->value
[n
], count
))
919 hid_process_event(hid
, field
, &field
->usage
[field
->value
[n
] - min
], 0, interrupt
);
921 if (value
[n
] >= min
&& value
[n
] <= max
922 && field
->usage
[value
[n
] - min
].hid
923 && search(field
->value
, value
[n
], count
))
924 hid_process_event(hid
, field
, &field
->usage
[value
[n
] - min
], 1, interrupt
);
927 memcpy(field
->value
, value
, count
* sizeof(__s32
));
933 * Output the field into the report.
936 static void hid_output_field(struct hid_field
*field
, __u8
*data
)
938 unsigned count
= field
->report_count
;
939 unsigned offset
= field
->report_offset
;
940 unsigned size
= field
->report_size
;
941 unsigned bitsused
= offset
+ count
* size
;
944 /* make sure the unused bits in the last byte are zeros */
945 if (count
> 0 && size
> 0 && (bitsused
% 8) != 0)
946 data
[(bitsused
-1)/8] &= (1 << (bitsused
% 8)) - 1;
948 for (n
= 0; n
< count
; n
++) {
949 if (field
->logical_minimum
< 0) /* signed values */
950 implement(data
, offset
+ n
* size
, size
, s32ton(field
->value
[n
], size
));
951 else /* unsigned values */
952 implement(data
, offset
+ n
* size
, size
, field
->value
[n
]);
960 void hid_output_report(struct hid_report
*report
, __u8
*data
)
965 *data
++ = report
->id
;
967 for (n
= 0; n
< report
->maxfield
; n
++)
968 hid_output_field(report
->field
[n
], data
);
970 EXPORT_SYMBOL_GPL(hid_output_report
);
973 * Set a field value. The report this field belongs to has to be
974 * created and transferred to the device, to set this value in the
978 int hid_set_field(struct hid_field
*field
, unsigned offset
, __s32 value
)
980 unsigned size
= field
->report_size
;
982 hid_dump_input(field
->report
->device
, field
->usage
+ offset
, value
);
984 if (offset
>= field
->report_count
) {
985 dbg_hid("offset (%d) exceeds report_count (%d)\n", offset
, field
->report_count
);
988 if (field
->logical_minimum
< 0) {
989 if (value
!= snto32(s32ton(value
, size
), size
)) {
990 dbg_hid("value %d is out of range\n", value
);
994 field
->value
[offset
] = value
;
997 EXPORT_SYMBOL_GPL(hid_set_field
);
999 static struct hid_report
*hid_get_report(struct hid_report_enum
*report_enum
,
1002 struct hid_report
*report
;
1003 unsigned int n
= 0; /* Normally report number is 0 */
1005 /* Device uses numbered reports, data[0] is report number */
1006 if (report_enum
->numbered
)
1009 report
= report_enum
->report_id_hash
[n
];
1011 dbg_hid("undefined report_id %u received\n", n
);
1016 void hid_report_raw_event(struct hid_device
*hid
, int type
, u8
*data
, int size
,
1019 struct hid_report_enum
*report_enum
= hid
->report_enum
+ type
;
1020 struct hid_report
*report
;
1022 int rsize
, csize
= size
;
1025 report
= hid_get_report(report_enum
, data
);
1029 if (report_enum
->numbered
) {
1034 rsize
= ((report
->size
- 1) >> 3) + 1;
1036 if (csize
< rsize
) {
1037 dbg_hid("report %d is too short, (%d < %d)\n", report
->id
,
1039 memset(cdata
+ csize
, 0, rsize
- csize
);
1042 if ((hid
->claimed
& HID_CLAIMED_HIDDEV
) && hid
->hiddev_report_event
)
1043 hid
->hiddev_report_event(hid
, report
);
1044 if (hid
->claimed
& HID_CLAIMED_HIDRAW
) {
1045 /* numbered reports need to be passed with the report num */
1046 if (report_enum
->numbered
)
1047 hidraw_report_event(hid
, data
- 1, size
+ 1);
1049 hidraw_report_event(hid
, data
, size
);
1052 for (a
= 0; a
< report
->maxfield
; a
++)
1053 hid_input_field(hid
, report
->field
[a
], cdata
, interrupt
);
1055 if (hid
->claimed
& HID_CLAIMED_INPUT
)
1056 hidinput_report_event(hid
, report
);
1058 EXPORT_SYMBOL_GPL(hid_report_raw_event
);
1061 * hid_input_report - report data from lower layer (usb, bt...)
1064 * @type: HID report type (HID_*_REPORT)
1065 * @data: report contents
1066 * @size: size of data parameter
1067 * @interrupt: distinguish between interrupt and control transfers
1069 * This is data entry for lower layers.
1071 int hid_input_report(struct hid_device
*hid
, int type
, u8
*data
, int size
, int interrupt
)
1073 struct hid_report_enum
*report_enum
;
1074 struct hid_driver
*hdrv
;
1075 struct hid_report
*report
;
1080 if (!hid
|| !hid
->driver
)
1082 report_enum
= hid
->report_enum
+ type
;
1086 dbg_hid("empty report\n");
1090 buf
= kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE
, GFP_ATOMIC
);
1093 report
= hid_get_report(report_enum
, data
);
1097 snprintf(buf
, HID_DEBUG_BUFSIZE
- 1,
1098 "\nreport (size %u) (%snumbered)\n", size
, report_enum
->numbered
? "" : "un");
1099 hid_debug_event(hid
, buf
);
1101 report
= hid_get_report(report_enum
, data
);
1107 /* dump the report */
1108 snprintf(buf
, HID_DEBUG_BUFSIZE
- 1,
1109 "report %d (size %u) = ", report
->id
, size
);
1110 hid_debug_event(hid
, buf
);
1111 for (i
= 0; i
< size
; i
++) {
1112 snprintf(buf
, HID_DEBUG_BUFSIZE
- 1,
1114 hid_debug_event(hid
, buf
);
1116 hid_debug_event(hid
, "\n");
1121 if (hdrv
&& hdrv
->raw_event
&& hid_match_report(hid
, report
)) {
1122 ret
= hdrv
->raw_event(hid
, report
, data
, size
);
1124 return ret
< 0 ? ret
: 0;
1127 hid_report_raw_event(hid
, type
, data
, size
, interrupt
);
1131 EXPORT_SYMBOL_GPL(hid_input_report
);
1133 static bool hid_match_one_id(struct hid_device
*hdev
,
1134 const struct hid_device_id
*id
)
1136 return id
->bus
== hdev
->bus
&&
1137 (id
->vendor
== HID_ANY_ID
|| id
->vendor
== hdev
->vendor
) &&
1138 (id
->product
== HID_ANY_ID
|| id
->product
== hdev
->product
);
1141 static const struct hid_device_id
*hid_match_id(struct hid_device
*hdev
,
1142 const struct hid_device_id
*id
)
1144 for (; id
->bus
; id
++)
1145 if (hid_match_one_id(hdev
, id
))
1151 static const struct hid_device_id hid_hiddev_list
[] = {
1152 { HID_USB_DEVICE(USB_VENDOR_ID_MGE
, USB_DEVICE_ID_MGE_UPS
) },
1153 { HID_USB_DEVICE(USB_VENDOR_ID_MGE
, USB_DEVICE_ID_MGE_UPS1
) },
1157 static bool hid_hiddev(struct hid_device
*hdev
)
1159 return !!hid_match_id(hdev
, hid_hiddev_list
);
1162 int hid_connect(struct hid_device
*hdev
, unsigned int connect_mask
)
1164 static const char *types
[] = { "Device", "Pointer", "Mouse", "Device",
1165 "Joystick", "Gamepad", "Keyboard", "Keypad",
1166 "Multi-Axis Controller"
1168 const char *type
, *bus
;
1173 if (hdev
->bus
!= BUS_USB
)
1174 connect_mask
&= ~HID_CONNECT_HIDDEV
;
1175 if (hid_hiddev(hdev
))
1176 connect_mask
|= HID_CONNECT_HIDDEV_FORCE
;
1178 if ((connect_mask
& HID_CONNECT_HIDINPUT
) && !hidinput_connect(hdev
,
1179 connect_mask
& HID_CONNECT_HIDINPUT_FORCE
))
1180 hdev
->claimed
|= HID_CLAIMED_INPUT
;
1181 if ((connect_mask
& HID_CONNECT_HIDDEV
) && hdev
->hiddev_connect
&&
1182 !hdev
->hiddev_connect(hdev
,
1183 connect_mask
& HID_CONNECT_HIDDEV_FORCE
))
1184 hdev
->claimed
|= HID_CLAIMED_HIDDEV
;
1185 if ((connect_mask
& HID_CONNECT_HIDRAW
) && !hidraw_connect(hdev
))
1186 hdev
->claimed
|= HID_CLAIMED_HIDRAW
;
1188 if (!hdev
->claimed
) {
1189 dev_err(&hdev
->dev
, "claimed by neither input, hiddev nor "
1194 if ((hdev
->claimed
& HID_CLAIMED_INPUT
) &&
1195 (connect_mask
& HID_CONNECT_FF
) && hdev
->ff_init
)
1196 hdev
->ff_init(hdev
);
1199 if (hdev
->claimed
& HID_CLAIMED_INPUT
)
1200 len
+= sprintf(buf
+ len
, "input");
1201 if (hdev
->claimed
& HID_CLAIMED_HIDDEV
)
1202 len
+= sprintf(buf
+ len
, "%shiddev%d", len
? "," : "",
1204 if (hdev
->claimed
& HID_CLAIMED_HIDRAW
)
1205 len
+= sprintf(buf
+ len
, "%shidraw%d", len
? "," : "",
1206 ((struct hidraw
*)hdev
->hidraw
)->minor
);
1209 for (i
= 0; i
< hdev
->maxcollection
; i
++) {
1210 struct hid_collection
*col
= &hdev
->collection
[i
];
1211 if (col
->type
== HID_COLLECTION_APPLICATION
&&
1212 (col
->usage
& HID_USAGE_PAGE
) == HID_UP_GENDESK
&&
1213 (col
->usage
& 0xffff) < ARRAY_SIZE(types
)) {
1214 type
= types
[col
->usage
& 0xffff];
1219 switch (hdev
->bus
) {
1230 dev_info(&hdev
->dev
, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1231 buf
, bus
, hdev
->version
>> 8, hdev
->version
& 0xff,
1232 type
, hdev
->name
, hdev
->phys
);
1236 EXPORT_SYMBOL_GPL(hid_connect
);
1238 void hid_disconnect(struct hid_device
*hdev
)
1240 if (hdev
->claimed
& HID_CLAIMED_INPUT
)
1241 hidinput_disconnect(hdev
);
1242 if (hdev
->claimed
& HID_CLAIMED_HIDDEV
)
1243 hdev
->hiddev_disconnect(hdev
);
1244 if (hdev
->claimed
& HID_CLAIMED_HIDRAW
)
1245 hidraw_disconnect(hdev
);
1247 EXPORT_SYMBOL_GPL(hid_disconnect
);
1249 /* a list of devices for which there is a specialized driver on HID bus */
1250 static const struct hid_device_id hid_blacklist
[] = {
1251 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH
, USB_DEVICE_ID_A4TECH_WCP32PU
) },
1252 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH
, USB_DEVICE_ID_A4TECH_X5_005D
) },
1253 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ATV_IRCONTROL
) },
1254 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_IRCONTROL4
) },
1255 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_MIGHTYMOUSE
) },
1256 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI
) },
1257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO
) },
1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ANSI
) },
1259 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ISO
) },
1260 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_JIS
) },
1261 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ANSI
) },
1262 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ISO
) },
1263 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_JIS
) },
1264 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ANSI
) },
1265 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ISO
) },
1266 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_JIS
) },
1267 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI
) },
1268 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_MINI_ISO
) },
1269 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_MINI_JIS
) },
1270 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_ANSI
) },
1271 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_ISO
) },
1272 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_JIS
) },
1273 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI
) },
1274 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO
) },
1275 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS
) },
1276 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI
) },
1277 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO
) },
1278 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS
) },
1279 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI
) },
1280 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ISO
) },
1281 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_JIS
) },
1282 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI
) },
1283 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO
) },
1284 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS
) },
1285 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI
) },
1286 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO
) },
1287 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS
) },
1288 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY
) },
1289 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY
) },
1290 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN
, USB_DEVICE_ID_FLIP_KVM
) },
1291 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY
, USB_DEVICE_ID_CHERRY_CYMOTION
) },
1292 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY
, USB_DEVICE_ID_CHICONY_TACTICAL_PAD
) },
1293 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_1
) },
1294 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_2
) },
1295 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_MOUSE
) },
1296 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE
, 0x0006) },
1297 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY
, USB_DEVICE_ID_BTC_8193
) },
1298 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON
, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR
) },
1299 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON
, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR
) },
1300 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA
, 0x0003) },
1301 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA
, 0x0012) },
1302 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION
, USB_DEVICE_ID_GYRATION_REMOTE
) },
1303 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION
, USB_DEVICE_ID_GYRATION_REMOTE_2
) },
1304 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON
, USB_DEVICE_ID_KS_SLIMBLADE
) },
1305 { HID_USB_DEVICE(USB_VENDOR_ID_KYE
, USB_DEVICE_ID_KYE_ERGO_525V
) },
1306 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC
, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD
) },
1307 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_MX3000_RECEIVER
) },
1308 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_S510_RECEIVER
) },
1309 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_S510_RECEIVER_2
) },
1310 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RECEIVER
) },
1311 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_DINOVO_DESKTOP
) },
1312 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_DINOVO_EDGE
) },
1313 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_DINOVO_MINI
) },
1314 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_ELITE_KBD
) },
1315 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500
) },
1316 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_EXTREME_3D
) },
1317 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_WHEEL
) },
1318 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RUMBLEPAD
) },
1319 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2
) },
1320 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D
) },
1321 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG
) },
1322 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO
) },
1323 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL
) },
1324 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2
) },
1325 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_G25_WHEEL
) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2
) },
1327 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_SIDEWINDER_GV
) },
1328 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE4K
) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_LK6K
) },
1330 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_USB
) },
1331 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0
) },
1332 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY
, USB_DEVICE_ID_GENIUS_KB29E
) },
1333 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG
, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN
) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX
, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE
) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG
, USB_DEVICE_ID_SAMSUNG_IR_REMOTE
) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_SONY
, USB_DEVICE_ID_SONY_PS3_CONTROLLER
) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_SONY
, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE
) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS
, USB_DEVICE_ID_SUNPLUS_WDESKTOP
) },
1339 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb300) },
1340 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb304) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb323) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb324) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb651) },
1344 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb654) },
1345 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED
, USB_DEVICE_ID_TOPSEED_CYBERLINK
) },
1346 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN
, USB_DEVICE_ID_TWINHAN_IR_REMOTE
) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_SMARTJOY_PLUS
) },
1348 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM
, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
) },
1349 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS
, 0x0005) },
1350 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS
, 0x0030) },
1352 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_BT
) },
1357 struct list_head list
;
1358 struct hid_device_id id
;
1362 * store_new_id - add a new HID device ID to this driver and re-probe devices
1363 * @driver: target device driver
1364 * @buf: buffer for scanning device ID data
1365 * @count: input size
1367 * Adds a new dynamic hid device ID to this driver,
1368 * and causes the driver to probe for all devices again.
1370 static ssize_t
store_new_id(struct device_driver
*drv
, const char *buf
,
1373 struct hid_driver
*hdrv
= container_of(drv
, struct hid_driver
, driver
);
1374 struct hid_dynid
*dynid
;
1375 __u32 bus
, vendor
, product
;
1376 unsigned long driver_data
= 0;
1379 ret
= sscanf(buf
, "%x %x %x %lx",
1380 &bus
, &vendor
, &product
, &driver_data
);
1384 dynid
= kzalloc(sizeof(*dynid
), GFP_KERNEL
);
1388 dynid
->id
.bus
= bus
;
1389 dynid
->id
.vendor
= vendor
;
1390 dynid
->id
.product
= product
;
1391 dynid
->id
.driver_data
= driver_data
;
1393 spin_lock(&hdrv
->dyn_lock
);
1394 list_add_tail(&dynid
->list
, &hdrv
->dyn_list
);
1395 spin_unlock(&hdrv
->dyn_lock
);
1398 if (get_driver(&hdrv
->driver
)) {
1399 ret
= driver_attach(&hdrv
->driver
);
1400 put_driver(&hdrv
->driver
);
1403 return ret
? : count
;
1405 static DRIVER_ATTR(new_id
, S_IWUSR
, NULL
, store_new_id
);
1407 static void hid_free_dynids(struct hid_driver
*hdrv
)
1409 struct hid_dynid
*dynid
, *n
;
1411 spin_lock(&hdrv
->dyn_lock
);
1412 list_for_each_entry_safe(dynid
, n
, &hdrv
->dyn_list
, list
) {
1413 list_del(&dynid
->list
);
1416 spin_unlock(&hdrv
->dyn_lock
);
1419 static const struct hid_device_id
*hid_match_device(struct hid_device
*hdev
,
1420 struct hid_driver
*hdrv
)
1422 struct hid_dynid
*dynid
;
1424 spin_lock(&hdrv
->dyn_lock
);
1425 list_for_each_entry(dynid
, &hdrv
->dyn_list
, list
) {
1426 if (hid_match_one_id(hdev
, &dynid
->id
)) {
1427 spin_unlock(&hdrv
->dyn_lock
);
1431 spin_unlock(&hdrv
->dyn_lock
);
1433 return hid_match_id(hdev
, hdrv
->id_table
);
1436 static int hid_bus_match(struct device
*dev
, struct device_driver
*drv
)
1438 struct hid_driver
*hdrv
= container_of(drv
, struct hid_driver
, driver
);
1439 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1441 if (!hid_match_device(hdev
, hdrv
))
1444 /* generic wants all non-blacklisted */
1445 if (!strncmp(hdrv
->name
, "generic-", 8))
1446 return !hid_match_id(hdev
, hid_blacklist
);
1451 static int hid_device_probe(struct device
*dev
)
1453 struct hid_driver
*hdrv
= container_of(dev
->driver
,
1454 struct hid_driver
, driver
);
1455 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1456 const struct hid_device_id
*id
;
1459 if (!hdev
->driver
) {
1460 id
= hid_match_device(hdev
, hdrv
);
1464 hdev
->driver
= hdrv
;
1466 ret
= hdrv
->probe(hdev
, id
);
1467 } else { /* default probe */
1468 ret
= hid_parse(hdev
);
1470 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
1473 hdev
->driver
= NULL
;
1478 static int hid_device_remove(struct device
*dev
)
1480 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1481 struct hid_driver
*hdrv
= hdev
->driver
;
1486 else /* default remove */
1488 hdev
->driver
= NULL
;
1494 static int hid_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1496 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1498 if (add_uevent_var(env
, "HID_ID=%04X:%08X:%08X",
1499 hdev
->bus
, hdev
->vendor
, hdev
->product
))
1502 if (add_uevent_var(env
, "HID_NAME=%s", hdev
->name
))
1505 if (add_uevent_var(env
, "HID_PHYS=%s", hdev
->phys
))
1508 if (add_uevent_var(env
, "HID_UNIQ=%s", hdev
->uniq
))
1511 if (add_uevent_var(env
, "MODALIAS=hid:b%04Xv%08Xp%08X",
1512 hdev
->bus
, hdev
->vendor
, hdev
->product
))
1518 static struct bus_type hid_bus_type
= {
1520 .match
= hid_bus_match
,
1521 .probe
= hid_device_probe
,
1522 .remove
= hid_device_remove
,
1523 .uevent
= hid_uevent
,
1526 /* a list of devices that shouldn't be handled by HID core at all */
1527 static const struct hid_device_id hid_ignore_list
[] = {
1528 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD
, USB_DEVICE_ID_ACECAD_FLAIR
) },
1529 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD
, USB_DEVICE_ID_ACECAD_302
) },
1530 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH
, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X
) },
1531 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_01
) },
1532 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_10
) },
1533 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_20
) },
1534 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_21
) },
1535 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_22
) },
1536 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_23
) },
1537 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_24
) },
1538 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE
, USB_DEVICE_ID_AIRCABLE1
) },
1539 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR
, USB_DEVICE_ID_ALCOR_USBRS232
) },
1540 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS
, USB_DEVICE_ID_ASUS_LCM
)},
1541 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS
, USB_DEVICE_ID_ASUS_LCM2
)},
1542 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA
, USB_DEVICE_ID_AVER_FM_MR800
) },
1543 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE
, USB_DEVICE_ID_BERKSHIRE_PCWD
) },
1544 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC
, 0x0103) },
1545 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL
, USB_DEVICE_ID_CYGNAL_RADIO_SI470X
) },
1546 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA
, USB_DEVICE_ID_CM109
) },
1547 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_HIDCOM
) },
1548 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE
) },
1549 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME
, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701
) },
1550 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME
, USB_DEVICE_ID_DELORME_EARTHMATE
) },
1551 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME
, USB_DEVICE_ID_DELORME_EM_LT20
) },
1552 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY
, USB_DEVICE_ID_ESSENTIAL_REALITY_P5
) },
1553 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0001) },
1554 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0002) },
1555 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0003) },
1556 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0004) },
1557 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_4_PHIDGETSERVO_30
) },
1558 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_1_PHIDGETSERVO_30
) },
1559 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_0_4_IF_KIT
) },
1560 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_16_16_IF_KIT
) },
1561 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_8_8_8_IF_KIT
) },
1562 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_8_7_IF_KIT
) },
1563 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_8_8_IF_KIT
) },
1564 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_PHIDGET_MOTORCONTROL
) },
1565 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP
, USB_DEVICE_ID_SUPER_Q2
) },
1566 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP
, USB_DEVICE_ID_GOGOPEN
) },
1567 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP
, USB_DEVICE_ID_PENPOWER
) },
1568 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH
, USB_DEVICE_ID_GRETAGMACBETH_HUEY
) },
1569 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN
, USB_DEVICE_ID_POWERMATE
) },
1570 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN
, USB_DEVICE_ID_SOUNDKNOB
) },
1571 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_90
) },
1572 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_100
) },
1573 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_101
) },
1574 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_103
) },
1575 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_104
) },
1576 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_105
) },
1577 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_106
) },
1578 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_107
) },
1579 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_108
) },
1580 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_200
) },
1581 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_201
) },
1582 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_202
) },
1583 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_203
) },
1584 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_204
) },
1585 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_205
) },
1586 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_206
) },
1587 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_207
) },
1588 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_300
) },
1589 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_301
) },
1590 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_302
) },
1591 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_303
) },
1592 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_304
) },
1593 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_305
) },
1594 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_306
) },
1595 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_307
) },
1596 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_308
) },
1597 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_309
) },
1598 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_400
) },
1599 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_401
) },
1600 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_402
) },
1601 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_403
) },
1602 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_404
) },
1603 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_405
) },
1604 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_500
) },
1605 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_501
) },
1606 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_502
) },
1607 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_503
) },
1608 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_504
) },
1609 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1000
) },
1610 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1001
) },
1611 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1002
) },
1612 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1003
) },
1613 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1004
) },
1614 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1005
) },
1615 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1006
) },
1616 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1007
) },
1617 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION
, USB_DEVICE_ID_DISC_STAKKA
) },
1618 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR
, USB_DEVICE_ID_KBGEAR_JAMSTUDIO
) },
1619 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD
, USB_DEVICE_ID_KWORLD_RADIO_FM700
) },
1620 { HID_USB_DEVICE(USB_VENDOR_ID_KYE
, USB_DEVICE_ID_KYE_GPEN_560
) },
1621 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE
, 0x0058) },
1622 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_CASSY
) },
1623 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_POCKETCASSY
) },
1624 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_MOBILECASSY
) },
1625 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_JWM
) },
1626 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_DMMP
) },
1627 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_UMIP
) },
1628 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_XRAY1
) },
1629 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_XRAY2
) },
1630 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_VIDEOCOM
) },
1631 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_COM3LAB
) },
1632 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_TELEPORT
) },
1633 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_NETWORKANALYSER
) },
1634 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_POWERCONTROL
) },
1635 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_MACHINETEST
) },
1636 { HID_USB_DEVICE(USB_VENDOR_ID_MCC
, USB_DEVICE_ID_MCC_PMD1024LS
) },
1637 { HID_USB_DEVICE(USB_VENDOR_ID_MCC
, USB_DEVICE_ID_MCC_PMD1208LS
) },
1638 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICKIT1
) },
1639 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICKIT2
) },
1640 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR
, USB_DEVICE_ID_N_S_HARMONY
) },
1641 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
) },
1642 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 20) },
1643 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 30) },
1644 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 100) },
1645 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 108) },
1646 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 118) },
1647 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 200) },
1648 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 300) },
1649 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 400) },
1650 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 500) },
1651 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0001) },
1652 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0002) },
1653 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0003) },
1654 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0004) },
1655 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS
, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE
) },
1656 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM
, USB_DEVICE_ID_POWERCOM_UPS
) },
1657 { HID_USB_DEVICE(USB_VENDOR_ID_TENX
, USB_DEVICE_ID_TENX_IBUDDY1
) },
1658 { HID_USB_DEVICE(USB_VENDOR_ID_TENX
, USB_DEVICE_ID_TENX_IBUDDY2
) },
1659 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_LABPRO
) },
1660 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_GOTEMP
) },
1661 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_SKIP
) },
1662 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_CYCLOPS
) },
1663 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_LCSPEC
) },
1664 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM
, HID_ANY_ID
) },
1665 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_4_PHIDGETSERVO_20
) },
1666 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_1_PHIDGETSERVO_20
) },
1667 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_8_8_4_IF_KIT
) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK
, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K
) },
1673 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1675 * There are composite devices for which we want to ignore only a certain
1676 * interface. This is a list of devices for which only the mouse interface will
1677 * be ignored. This allows a dedicated driver to take care of the interface.
1679 static const struct hid_device_id hid_mouse_ignore_list
[] = {
1680 /* appletouch driver */
1681 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI
) },
1682 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO
) },
1683 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ANSI
) },
1684 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ISO
) },
1685 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_JIS
) },
1686 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ANSI
) },
1687 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ISO
) },
1688 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_JIS
) },
1689 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ANSI
) },
1690 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ISO
) },
1691 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_JIS
) },
1692 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI
) },
1693 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO
) },
1694 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS
) },
1695 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI
) },
1696 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ISO
) },
1697 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_JIS
) },
1698 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI
) },
1699 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO
) },
1700 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS
) },
1701 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI
) },
1702 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO
) },
1703 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS
) },
1704 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY
) },
1705 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY
) },
1709 static bool hid_ignore(struct hid_device
*hdev
)
1711 switch (hdev
->vendor
) {
1712 case USB_VENDOR_ID_CODEMERCS
:
1713 /* ignore all Code Mercenaries IOWarrior devices */
1714 if (hdev
->product
>= USB_DEVICE_ID_CODEMERCS_IOW_FIRST
&&
1715 hdev
->product
<= USB_DEVICE_ID_CODEMERCS_IOW_LAST
)
1718 case USB_VENDOR_ID_LOGITECH
:
1719 if (hdev
->product
>= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST
&&
1720 hdev
->product
<= USB_DEVICE_ID_LOGITECH_HARMONY_LAST
)
1723 case USB_VENDOR_ID_SOUNDGRAPH
:
1724 if (hdev
->product
>= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST
&&
1725 hdev
->product
<= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST
)
1730 if (hdev
->type
== HID_TYPE_USBMOUSE
&&
1731 hid_match_id(hdev
, hid_mouse_ignore_list
))
1734 return !!hid_match_id(hdev
, hid_ignore_list
);
1737 int hid_add_device(struct hid_device
*hdev
)
1739 static atomic_t id
= ATOMIC_INIT(0);
1742 if (WARN_ON(hdev
->status
& HID_STAT_ADDED
))
1745 /* we need to kill them here, otherwise they will stay allocated to
1746 * wait for coming driver */
1747 if (hid_ignore(hdev
))
1750 /* XXX hack, any other cleaner solution after the driver core
1751 * is converted to allow more than 20 bytes as the device name? */
1752 dev_set_name(&hdev
->dev
, "%04X:%04X:%04X.%04X", hdev
->bus
,
1753 hdev
->vendor
, hdev
->product
, atomic_inc_return(&id
));
1755 ret
= device_add(&hdev
->dev
);
1757 hdev
->status
|= HID_STAT_ADDED
;
1759 hid_debug_register(hdev
, dev_name(&hdev
->dev
));
1763 EXPORT_SYMBOL_GPL(hid_add_device
);
1766 * hid_allocate_device - allocate new hid device descriptor
1768 * Allocate and initialize hid device, so that hid_destroy_device might be
1771 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1774 struct hid_device
*hid_allocate_device(void)
1776 struct hid_device
*hdev
;
1780 hdev
= kzalloc(sizeof(*hdev
), GFP_KERNEL
);
1782 return ERR_PTR(ret
);
1784 device_initialize(&hdev
->dev
);
1785 hdev
->dev
.release
= hid_device_release
;
1786 hdev
->dev
.bus
= &hid_bus_type
;
1788 hdev
->collection
= kcalloc(HID_DEFAULT_NUM_COLLECTIONS
,
1789 sizeof(struct hid_collection
), GFP_KERNEL
);
1790 if (hdev
->collection
== NULL
)
1792 hdev
->collection_size
= HID_DEFAULT_NUM_COLLECTIONS
;
1794 for (i
= 0; i
< HID_REPORT_TYPES
; i
++)
1795 INIT_LIST_HEAD(&hdev
->report_enum
[i
].report_list
);
1797 init_waitqueue_head(&hdev
->debug_wait
);
1798 INIT_LIST_HEAD(&hdev
->debug_list
);
1802 put_device(&hdev
->dev
);
1803 return ERR_PTR(ret
);
1805 EXPORT_SYMBOL_GPL(hid_allocate_device
);
1807 static void hid_remove_device(struct hid_device
*hdev
)
1809 if (hdev
->status
& HID_STAT_ADDED
) {
1810 device_del(&hdev
->dev
);
1811 hid_debug_unregister(hdev
);
1812 hdev
->status
&= ~HID_STAT_ADDED
;
1817 * hid_destroy_device - free previously allocated device
1821 * If you allocate hid_device through hid_allocate_device, you should ever
1822 * free by this function.
1824 void hid_destroy_device(struct hid_device
*hdev
)
1826 hid_remove_device(hdev
);
1827 put_device(&hdev
->dev
);
1829 EXPORT_SYMBOL_GPL(hid_destroy_device
);
1831 int __hid_register_driver(struct hid_driver
*hdrv
, struct module
*owner
,
1832 const char *mod_name
)
1836 hdrv
->driver
.name
= hdrv
->name
;
1837 hdrv
->driver
.bus
= &hid_bus_type
;
1838 hdrv
->driver
.owner
= owner
;
1839 hdrv
->driver
.mod_name
= mod_name
;
1841 INIT_LIST_HEAD(&hdrv
->dyn_list
);
1842 spin_lock_init(&hdrv
->dyn_lock
);
1844 ret
= driver_register(&hdrv
->driver
);
1848 ret
= driver_create_file(&hdrv
->driver
, &driver_attr_new_id
);
1850 driver_unregister(&hdrv
->driver
);
1854 EXPORT_SYMBOL_GPL(__hid_register_driver
);
1856 void hid_unregister_driver(struct hid_driver
*hdrv
)
1858 driver_remove_file(&hdrv
->driver
, &driver_attr_new_id
);
1859 driver_unregister(&hdrv
->driver
);
1860 hid_free_dynids(hdrv
);
1862 EXPORT_SYMBOL_GPL(hid_unregister_driver
);
1864 int hid_check_keys_pressed(struct hid_device
*hid
)
1866 struct hid_input
*hidinput
;
1869 if (!(hid
->claimed
& HID_CLAIMED_INPUT
))
1872 list_for_each_entry(hidinput
, &hid
->inputs
, list
) {
1873 for (i
= 0; i
< BITS_TO_LONGS(KEY_MAX
); i
++)
1874 if (hidinput
->input
->key
[i
])
1881 EXPORT_SYMBOL_GPL(hid_check_keys_pressed
);
1883 static int __init
hid_init(void)
1888 printk(KERN_WARNING
"HID: hid_debug is now used solely for parser and driver debugging.\n"
1889 "HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
1891 ret
= bus_register(&hid_bus_type
);
1893 printk(KERN_ERR
"HID: can't register hid bus\n");
1897 ret
= hidraw_init();
1905 bus_unregister(&hid_bus_type
);
1910 static void __exit
hid_exit(void)
1914 bus_unregister(&hid_bus_type
);
1917 module_init(hid_init
);
1918 module_exit(hid_exit
);
1920 MODULE_AUTHOR("Andreas Gal");
1921 MODULE_AUTHOR("Vojtech Pavlik");
1922 MODULE_AUTHOR("Jiri Kosina");
1923 MODULE_LICENSE(DRIVER_LICENSE
);