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_VERSION "v2.6"
43 #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina"
44 #define DRIVER_DESC "HID core driver"
45 #define DRIVER_LICENSE "GPL"
48 module_param_named(debug
, hid_debug
, int, 0600);
49 MODULE_PARM_DESC(debug
, "toggle HID debugging messages");
50 EXPORT_SYMBOL_GPL(hid_debug
);
53 * Register a new report for a device.
56 static struct hid_report
*hid_register_report(struct hid_device
*device
, unsigned type
, unsigned id
)
58 struct hid_report_enum
*report_enum
= device
->report_enum
+ type
;
59 struct hid_report
*report
;
61 if (id
>= HID_MAX_IDS
)
63 if (report_enum
->report_id_hash
[id
])
64 return report_enum
->report_id_hash
[id
];
66 if (!(report
= kzalloc(sizeof(struct hid_report
), GFP_KERNEL
)))
70 report_enum
->numbered
= 1;
75 report
->device
= device
;
76 report_enum
->report_id_hash
[id
] = report
;
78 list_add_tail(&report
->list
, &report_enum
->report_list
);
84 * Register a new field for this report.
87 static struct hid_field
*hid_register_field(struct hid_report
*report
, unsigned usages
, unsigned values
)
89 struct hid_field
*field
;
91 if (report
->maxfield
== HID_MAX_FIELDS
) {
92 dbg_hid("too many fields in report\n");
96 if (!(field
= kzalloc(sizeof(struct hid_field
) + usages
* sizeof(struct hid_usage
)
97 + values
* sizeof(unsigned), GFP_KERNEL
))) return NULL
;
99 field
->index
= report
->maxfield
++;
100 report
->field
[field
->index
] = field
;
101 field
->usage
= (struct hid_usage
*)(field
+ 1);
102 field
->value
= (s32
*)(field
->usage
+ usages
);
103 field
->report
= report
;
109 * Open a collection. The type/usage is pushed on the stack.
112 static int open_collection(struct hid_parser
*parser
, unsigned type
)
114 struct hid_collection
*collection
;
117 usage
= parser
->local
.usage
[0];
119 if (parser
->collection_stack_ptr
== HID_COLLECTION_STACK_SIZE
) {
120 dbg_hid("collection stack overflow\n");
124 if (parser
->device
->maxcollection
== parser
->device
->collection_size
) {
125 collection
= kmalloc(sizeof(struct hid_collection
) *
126 parser
->device
->collection_size
* 2, GFP_KERNEL
);
127 if (collection
== NULL
) {
128 dbg_hid("failed to reallocate collection array\n");
131 memcpy(collection
, parser
->device
->collection
,
132 sizeof(struct hid_collection
) *
133 parser
->device
->collection_size
);
134 memset(collection
+ parser
->device
->collection_size
, 0,
135 sizeof(struct hid_collection
) *
136 parser
->device
->collection_size
);
137 kfree(parser
->device
->collection
);
138 parser
->device
->collection
= collection
;
139 parser
->device
->collection_size
*= 2;
142 parser
->collection_stack
[parser
->collection_stack_ptr
++] =
143 parser
->device
->maxcollection
;
145 collection
= parser
->device
->collection
+
146 parser
->device
->maxcollection
++;
147 collection
->type
= type
;
148 collection
->usage
= usage
;
149 collection
->level
= parser
->collection_stack_ptr
- 1;
151 if (type
== HID_COLLECTION_APPLICATION
)
152 parser
->device
->maxapplication
++;
158 * Close a collection.
161 static int close_collection(struct hid_parser
*parser
)
163 if (!parser
->collection_stack_ptr
) {
164 dbg_hid("collection stack underflow\n");
167 parser
->collection_stack_ptr
--;
172 * Climb up the stack, search for the specified collection type
173 * and return the usage.
176 static unsigned hid_lookup_collection(struct hid_parser
*parser
, unsigned type
)
179 for (n
= parser
->collection_stack_ptr
- 1; n
>= 0; n
--)
180 if (parser
->device
->collection
[parser
->collection_stack
[n
]].type
== type
)
181 return parser
->device
->collection
[parser
->collection_stack
[n
]].usage
;
182 return 0; /* we know nothing about this usage type */
186 * Add a usage to the temporary parser table.
189 static int hid_add_usage(struct hid_parser
*parser
, unsigned usage
)
191 if (parser
->local
.usage_index
>= HID_MAX_USAGES
) {
192 dbg_hid("usage index exceeded\n");
195 parser
->local
.usage
[parser
->local
.usage_index
] = usage
;
196 parser
->local
.collection_index
[parser
->local
.usage_index
] =
197 parser
->collection_stack_ptr
?
198 parser
->collection_stack
[parser
->collection_stack_ptr
- 1] : 0;
199 parser
->local
.usage_index
++;
204 * Register a new field for this report.
207 static int hid_add_field(struct hid_parser
*parser
, unsigned report_type
, unsigned flags
)
209 struct hid_report
*report
;
210 struct hid_field
*field
;
215 if (!(report
= hid_register_report(parser
->device
, report_type
, parser
->global
.report_id
))) {
216 dbg_hid("hid_register_report failed\n");
220 if (parser
->global
.logical_maximum
< parser
->global
.logical_minimum
) {
221 dbg_hid("logical range invalid %d %d\n", parser
->global
.logical_minimum
, parser
->global
.logical_maximum
);
225 offset
= report
->size
;
226 report
->size
+= parser
->global
.report_size
* parser
->global
.report_count
;
228 if (!parser
->local
.usage_index
) /* Ignore padding fields */
231 usages
= max_t(int, parser
->local
.usage_index
, parser
->global
.report_count
);
233 if ((field
= hid_register_field(report
, usages
, parser
->global
.report_count
)) == NULL
)
236 field
->physical
= hid_lookup_collection(parser
, HID_COLLECTION_PHYSICAL
);
237 field
->logical
= hid_lookup_collection(parser
, HID_COLLECTION_LOGICAL
);
238 field
->application
= hid_lookup_collection(parser
, HID_COLLECTION_APPLICATION
);
240 for (i
= 0; i
< usages
; i
++) {
242 /* Duplicate the last usage we parsed if we have excess values */
243 if (i
>= parser
->local
.usage_index
)
244 j
= parser
->local
.usage_index
- 1;
245 field
->usage
[i
].hid
= parser
->local
.usage
[j
];
246 field
->usage
[i
].collection_index
=
247 parser
->local
.collection_index
[j
];
250 field
->maxusage
= usages
;
251 field
->flags
= flags
;
252 field
->report_offset
= offset
;
253 field
->report_type
= report_type
;
254 field
->report_size
= parser
->global
.report_size
;
255 field
->report_count
= parser
->global
.report_count
;
256 field
->logical_minimum
= parser
->global
.logical_minimum
;
257 field
->logical_maximum
= parser
->global
.logical_maximum
;
258 field
->physical_minimum
= parser
->global
.physical_minimum
;
259 field
->physical_maximum
= parser
->global
.physical_maximum
;
260 field
->unit_exponent
= parser
->global
.unit_exponent
;
261 field
->unit
= parser
->global
.unit
;
267 * Read data value from item.
270 static u32
item_udata(struct hid_item
*item
)
272 switch (item
->size
) {
273 case 1: return item
->data
.u8
;
274 case 2: return item
->data
.u16
;
275 case 4: return item
->data
.u32
;
280 static s32
item_sdata(struct hid_item
*item
)
282 switch (item
->size
) {
283 case 1: return item
->data
.s8
;
284 case 2: return item
->data
.s16
;
285 case 4: return item
->data
.s32
;
291 * Process a global item.
294 static int hid_parser_global(struct hid_parser
*parser
, struct hid_item
*item
)
297 case HID_GLOBAL_ITEM_TAG_PUSH
:
299 if (parser
->global_stack_ptr
== HID_GLOBAL_STACK_SIZE
) {
300 dbg_hid("global enviroment stack overflow\n");
304 memcpy(parser
->global_stack
+ parser
->global_stack_ptr
++,
305 &parser
->global
, sizeof(struct hid_global
));
308 case HID_GLOBAL_ITEM_TAG_POP
:
310 if (!parser
->global_stack_ptr
) {
311 dbg_hid("global enviroment stack underflow\n");
315 memcpy(&parser
->global
, parser
->global_stack
+
316 --parser
->global_stack_ptr
, sizeof(struct hid_global
));
319 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE
:
320 parser
->global
.usage_page
= item_udata(item
);
323 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM
:
324 parser
->global
.logical_minimum
= item_sdata(item
);
327 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM
:
328 if (parser
->global
.logical_minimum
< 0)
329 parser
->global
.logical_maximum
= item_sdata(item
);
331 parser
->global
.logical_maximum
= item_udata(item
);
334 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM
:
335 parser
->global
.physical_minimum
= item_sdata(item
);
338 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM
:
339 if (parser
->global
.physical_minimum
< 0)
340 parser
->global
.physical_maximum
= item_sdata(item
);
342 parser
->global
.physical_maximum
= item_udata(item
);
345 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT
:
346 parser
->global
.unit_exponent
= item_sdata(item
);
349 case HID_GLOBAL_ITEM_TAG_UNIT
:
350 parser
->global
.unit
= item_udata(item
);
353 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE
:
354 parser
->global
.report_size
= item_udata(item
);
355 if (parser
->global
.report_size
> 96) {
356 dbg_hid("invalid report_size %d\n",
357 parser
->global
.report_size
);
362 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT
:
363 parser
->global
.report_count
= item_udata(item
);
364 if (parser
->global
.report_count
> HID_MAX_USAGES
) {
365 dbg_hid("invalid report_count %d\n",
366 parser
->global
.report_count
);
371 case HID_GLOBAL_ITEM_TAG_REPORT_ID
:
372 parser
->global
.report_id
= item_udata(item
);
373 if (parser
->global
.report_id
== 0 ||
374 parser
->global
.report_id
>= HID_MAX_IDS
) {
375 dbg_hid("report_id %u is invalid\n",
376 parser
->global
.report_id
);
382 dbg_hid("unknown global tag 0x%x\n", item
->tag
);
388 * Process a local item.
391 static int hid_parser_local(struct hid_parser
*parser
, struct hid_item
*item
)
396 if (item
->size
== 0) {
397 dbg_hid("item data expected for local item\n");
401 data
= item_udata(item
);
404 case HID_LOCAL_ITEM_TAG_DELIMITER
:
408 * We treat items before the first delimiter
409 * as global to all usage sets (branch 0).
410 * In the moment we process only these global
411 * items and the first delimiter set.
413 if (parser
->local
.delimiter_depth
!= 0) {
414 dbg_hid("nested delimiters\n");
417 parser
->local
.delimiter_depth
++;
418 parser
->local
.delimiter_branch
++;
420 if (parser
->local
.delimiter_depth
< 1) {
421 dbg_hid("bogus close delimiter\n");
424 parser
->local
.delimiter_depth
--;
428 case HID_LOCAL_ITEM_TAG_USAGE
:
430 if (parser
->local
.delimiter_branch
> 1) {
431 dbg_hid("alternative usage ignored\n");
436 data
= (parser
->global
.usage_page
<< 16) + data
;
438 return hid_add_usage(parser
, data
);
440 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM
:
442 if (parser
->local
.delimiter_branch
> 1) {
443 dbg_hid("alternative usage ignored\n");
448 data
= (parser
->global
.usage_page
<< 16) + data
;
450 parser
->local
.usage_minimum
= data
;
453 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM
:
455 if (parser
->local
.delimiter_branch
> 1) {
456 dbg_hid("alternative usage ignored\n");
461 data
= (parser
->global
.usage_page
<< 16) + data
;
463 for (n
= parser
->local
.usage_minimum
; n
<= data
; n
++)
464 if (hid_add_usage(parser
, n
)) {
465 dbg_hid("hid_add_usage failed\n");
472 dbg_hid("unknown local item tag 0x%x\n", item
->tag
);
479 * Process a main item.
482 static int hid_parser_main(struct hid_parser
*parser
, struct hid_item
*item
)
487 data
= item_udata(item
);
490 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION
:
491 ret
= open_collection(parser
, data
& 0xff);
493 case HID_MAIN_ITEM_TAG_END_COLLECTION
:
494 ret
= close_collection(parser
);
496 case HID_MAIN_ITEM_TAG_INPUT
:
497 ret
= hid_add_field(parser
, HID_INPUT_REPORT
, data
);
499 case HID_MAIN_ITEM_TAG_OUTPUT
:
500 ret
= hid_add_field(parser
, HID_OUTPUT_REPORT
, data
);
502 case HID_MAIN_ITEM_TAG_FEATURE
:
503 ret
= hid_add_field(parser
, HID_FEATURE_REPORT
, data
);
506 dbg_hid("unknown main item tag 0x%x\n", item
->tag
);
510 memset(&parser
->local
, 0, sizeof(parser
->local
)); /* Reset the local parser environment */
516 * Process a reserved item.
519 static int hid_parser_reserved(struct hid_parser
*parser
, struct hid_item
*item
)
521 dbg_hid("reserved item type, tag 0x%x\n", item
->tag
);
526 * Free a report and all registered fields. The field->usage and
527 * field->value table's are allocated behind the field, so we need
528 * only to free(field) itself.
531 static void hid_free_report(struct hid_report
*report
)
535 for (n
= 0; n
< report
->maxfield
; n
++)
536 kfree(report
->field
[n
]);
541 * Free a device structure, all reports, and all fields.
544 static void hid_device_release(struct device
*dev
)
546 struct hid_device
*device
= container_of(dev
, struct hid_device
, dev
);
549 for (i
= 0; i
< HID_REPORT_TYPES
; i
++) {
550 struct hid_report_enum
*report_enum
= device
->report_enum
+ i
;
552 for (j
= 0; j
< HID_MAX_IDS
; j
++) {
553 struct hid_report
*report
= report_enum
->report_id_hash
[j
];
555 hid_free_report(report
);
559 kfree(device
->rdesc
);
560 kfree(device
->collection
);
565 * Fetch a report description item from the data stream. We support long
566 * items, though they are not used yet.
569 static u8
*fetch_item(__u8
*start
, __u8
*end
, struct hid_item
*item
)
573 if ((end
- start
) <= 0)
578 item
->type
= (b
>> 2) & 3;
579 item
->tag
= (b
>> 4) & 15;
581 if (item
->tag
== HID_ITEM_TAG_LONG
) {
583 item
->format
= HID_ITEM_FORMAT_LONG
;
585 if ((end
- start
) < 2)
588 item
->size
= *start
++;
589 item
->tag
= *start
++;
591 if ((end
- start
) < item
->size
)
594 item
->data
.longdata
= start
;
599 item
->format
= HID_ITEM_FORMAT_SHORT
;
602 switch (item
->size
) {
607 if ((end
- start
) < 1)
609 item
->data
.u8
= *start
++;
613 if ((end
- start
) < 2)
615 item
->data
.u16
= get_unaligned_le16(start
);
616 start
= (__u8
*)((__le16
*)start
+ 1);
621 if ((end
- start
) < 4)
623 item
->data
.u32
= get_unaligned_le32(start
);
624 start
= (__u8
*)((__le32
*)start
+ 1);
632 * hid_parse_report - parse device report
634 * @device: hid device
635 * @start: report start
638 * Parse a report description into a hid_device structure. Reports are
639 * enumerated, fields are attached to these reports.
640 * 0 returned on success, otherwise nonzero error value.
642 int hid_parse_report(struct hid_device
*device
, __u8
*start
,
645 struct hid_parser
*parser
;
646 struct hid_item item
;
649 static int (*dispatch_type
[])(struct hid_parser
*parser
,
650 struct hid_item
*item
) = {
657 if (device
->driver
->report_fixup
)
658 device
->driver
->report_fixup(device
, start
, size
);
660 device
->rdesc
= kmalloc(size
, GFP_KERNEL
);
661 if (device
->rdesc
== NULL
)
663 memcpy(device
->rdesc
, start
, size
);
664 device
->rsize
= size
;
666 parser
= vmalloc(sizeof(struct hid_parser
));
672 memset(parser
, 0, sizeof(struct hid_parser
));
673 parser
->device
= device
;
677 while ((start
= fetch_item(start
, end
, &item
)) != NULL
) {
679 if (item
.format
!= HID_ITEM_FORMAT_SHORT
) {
680 dbg_hid("unexpected long global item\n");
684 if (dispatch_type
[item
.type
](parser
, &item
)) {
685 dbg_hid("item %u %u %u %u parsing failed\n",
686 item
.format
, (unsigned)item
.size
, (unsigned)item
.type
, (unsigned)item
.tag
);
691 if (parser
->collection_stack_ptr
) {
692 dbg_hid("unbalanced collection at end of report description\n");
695 if (parser
->local
.delimiter_depth
) {
696 dbg_hid("unbalanced delimiter at end of report description\n");
704 dbg_hid("item fetching failed at offset %d\n", (int)(end
- start
));
709 EXPORT_SYMBOL_GPL(hid_parse_report
);
712 * Convert a signed n-bit integer to signed 32-bit integer. Common
713 * cases are done through the compiler, the screwed things has to be
717 static s32
snto32(__u32 value
, unsigned n
)
720 case 8: return ((__s8
)value
);
721 case 16: return ((__s16
)value
);
722 case 32: return ((__s32
)value
);
724 return value
& (1 << (n
- 1)) ? value
| (-1 << n
) : value
;
728 * Convert a signed 32-bit integer to a signed n-bit integer.
731 static u32
s32ton(__s32 value
, unsigned n
)
733 s32 a
= value
>> (n
- 1);
735 return value
< 0 ? 1 << (n
- 1) : (1 << (n
- 1)) - 1;
736 return value
& ((1 << n
) - 1);
740 * Extract/implement a data field from/to a little endian report (bit array).
742 * Code sort-of follows HID spec:
743 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
745 * While the USB HID spec allows unlimited length bit fields in "report
746 * descriptors", most devices never use more than 16 bits.
747 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
748 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
751 static __inline__ __u32
extract(__u8
*report
, unsigned offset
, unsigned n
)
756 printk(KERN_WARNING
"HID: extract() called with n (%d) > 32! (%s)\n",
759 report
+= offset
>> 3; /* adjust byte index */
760 offset
&= 7; /* now only need bit offset into one byte */
761 x
= get_unaligned_le64(report
);
762 x
= (x
>> offset
) & ((1ULL << n
) - 1); /* extract bit field */
767 * "implement" : set bits in a little endian bit stream.
768 * Same concepts as "extract" (see comments above).
769 * The data mangled in the bit stream remains in little endian
770 * order the whole time. It make more sense to talk about
771 * endianness of register values by considering a register
772 * a "cached" copy of the little endiad bit stream.
774 static __inline__
void implement(__u8
*report
, unsigned offset
, unsigned n
, __u32 value
)
777 u64 m
= (1ULL << n
) - 1;
780 printk(KERN_WARNING
"HID: implement() called with n (%d) > 32! (%s)\n",
784 printk(KERN_WARNING
"HID: implement() called with too large value %d! (%s)\n",
785 value
, current
->comm
);
789 report
+= offset
>> 3;
792 x
= get_unaligned_le64(report
);
794 x
|= ((u64
)value
) << offset
;
795 put_unaligned_le64(x
, report
);
799 * Search an array for a value.
802 static __inline__
int search(__s32
*array
, __s32 value
, unsigned n
)
805 if (*array
++ == value
)
811 static const char * const hid_report_names
[] = {
814 "HID_FEATURE_REPORT",
817 * hid_validate_values - validate existing device report's value indexes
819 * @device: hid device
820 * @type: which report type to examine
821 * @id: which report ID to examine (0 for first)
822 * @field_index: which report field to examine
823 * @report_counts: expected number of values
825 * Validate the number of values in a given field of a given report, after
828 struct hid_report
*hid_validate_values(struct hid_device
*hid
,
829 unsigned int type
, unsigned int id
,
830 unsigned int field_index
,
831 unsigned int report_counts
)
833 struct hid_report
*report
;
835 if (type
> HID_FEATURE_REPORT
) {
836 dev_err(&hid
->dev
, "invalid HID report type %u\n", type
);
840 if (id
>= HID_MAX_IDS
) {
841 dev_err(&hid
->dev
, "invalid HID report id %u\n", id
);
846 * Explicitly not using hid_get_report() here since it depends on
847 * ->numbered being checked, which may not always be the case when
848 * drivers go to access report values.
850 report
= hid
->report_enum
[type
].report_id_hash
[id
];
852 dev_err(&hid
->dev
, "missing %s %u\n", hid_report_names
[type
], id
);
855 if (report
->maxfield
<= field_index
) {
856 dev_err(&hid
->dev
, "not enough fields in %s %u\n",
857 hid_report_names
[type
], id
);
860 if (report
->field
[field_index
]->report_count
< report_counts
) {
861 dev_err(&hid
->dev
, "not enough values in %s %u field %u\n",
862 hid_report_names
[type
], id
, field_index
);
867 EXPORT_SYMBOL_GPL(hid_validate_values
);
870 * hid_match_report - check if driver's raw_event should be called
873 * @report_type: type to match against
875 * compare hid->driver->report_table->report_type to report->type
877 static int hid_match_report(struct hid_device
*hid
, struct hid_report
*report
)
879 const struct hid_report_id
*id
= hid
->driver
->report_table
;
881 if (!id
) /* NULL means all */
884 for (; id
->report_type
!= HID_TERMINATOR
; id
++)
885 if (id
->report_type
== HID_ANY_ID
||
886 id
->report_type
== report
->type
)
892 * hid_match_usage - check if driver's event should be called
895 * @usage: usage to match against
897 * compare hid->driver->usage_table->usage_{type,code} to
898 * usage->usage_{type,code}
900 static int hid_match_usage(struct hid_device
*hid
, struct hid_usage
*usage
)
902 const struct hid_usage_id
*id
= hid
->driver
->usage_table
;
904 if (!id
) /* NULL means all */
907 for (; id
->usage_type
!= HID_ANY_ID
- 1; id
++)
908 if ((id
->usage_hid
== HID_ANY_ID
||
909 id
->usage_hid
== usage
->hid
) &&
910 (id
->usage_type
== HID_ANY_ID
||
911 id
->usage_type
== usage
->type
) &&
912 (id
->usage_code
== HID_ANY_ID
||
913 id
->usage_code
== usage
->code
))
918 static void hid_process_event(struct hid_device
*hid
, struct hid_field
*field
,
919 struct hid_usage
*usage
, __s32 value
, int interrupt
)
921 struct hid_driver
*hdrv
= hid
->driver
;
924 hid_dump_input(hid
, usage
, value
);
926 if (hdrv
&& hdrv
->event
&& hid_match_usage(hid
, usage
)) {
927 ret
= hdrv
->event(hid
, field
, usage
, value
);
930 dbg_hid("%s's event failed with %d\n",
936 if (hid
->claimed
& HID_CLAIMED_INPUT
)
937 hidinput_hid_event(hid
, field
, usage
, value
);
938 if (hid
->claimed
& HID_CLAIMED_HIDDEV
&& interrupt
&& hid
->hiddev_hid_event
)
939 hid
->hiddev_hid_event(hid
, field
, usage
, value
);
943 * Analyse a received field, and fetch the data from it. The field
944 * content is stored for next report processing (we do differential
945 * reporting to the layer).
948 static void hid_input_field(struct hid_device
*hid
, struct hid_field
*field
,
949 __u8
*data
, int interrupt
)
952 unsigned count
= field
->report_count
;
953 unsigned offset
= field
->report_offset
;
954 unsigned size
= field
->report_size
;
955 __s32 min
= field
->logical_minimum
;
956 __s32 max
= field
->logical_maximum
;
959 if (!(value
= kmalloc(sizeof(__s32
) * count
, GFP_ATOMIC
)))
962 for (n
= 0; n
< count
; n
++) {
964 value
[n
] = min
< 0 ? snto32(extract(data
, offset
+ n
* size
, size
), size
) :
965 extract(data
, offset
+ n
* size
, size
);
967 if (!(field
->flags
& HID_MAIN_ITEM_VARIABLE
) /* Ignore report if ErrorRollOver */
968 && value
[n
] >= min
&& value
[n
] <= max
969 && field
->usage
[value
[n
] - min
].hid
== HID_UP_KEYBOARD
+ 1)
973 for (n
= 0; n
< count
; n
++) {
975 if (HID_MAIN_ITEM_VARIABLE
& field
->flags
) {
976 hid_process_event(hid
, field
, &field
->usage
[n
], value
[n
], interrupt
);
980 if (field
->value
[n
] >= min
&& field
->value
[n
] <= max
981 && field
->usage
[field
->value
[n
] - min
].hid
982 && search(value
, field
->value
[n
], count
))
983 hid_process_event(hid
, field
, &field
->usage
[field
->value
[n
] - min
], 0, interrupt
);
985 if (value
[n
] >= min
&& value
[n
] <= max
986 && field
->usage
[value
[n
] - min
].hid
987 && search(field
->value
, value
[n
], count
))
988 hid_process_event(hid
, field
, &field
->usage
[value
[n
] - min
], 1, interrupt
);
991 memcpy(field
->value
, value
, count
* sizeof(__s32
));
997 * Output the field into the report.
1000 static void hid_output_field(struct hid_field
*field
, __u8
*data
)
1002 unsigned count
= field
->report_count
;
1003 unsigned offset
= field
->report_offset
;
1004 unsigned size
= field
->report_size
;
1005 unsigned bitsused
= offset
+ count
* size
;
1008 /* make sure the unused bits in the last byte are zeros */
1009 if (count
> 0 && size
> 0 && (bitsused
% 8) != 0)
1010 data
[(bitsused
-1)/8] &= (1 << (bitsused
% 8)) - 1;
1012 for (n
= 0; n
< count
; n
++) {
1013 if (field
->logical_minimum
< 0) /* signed values */
1014 implement(data
, offset
+ n
* size
, size
, s32ton(field
->value
[n
], size
));
1015 else /* unsigned values */
1016 implement(data
, offset
+ n
* size
, size
, field
->value
[n
]);
1024 void hid_output_report(struct hid_report
*report
, __u8
*data
)
1029 *data
++ = report
->id
;
1031 for (n
= 0; n
< report
->maxfield
; n
++)
1032 hid_output_field(report
->field
[n
], data
);
1034 EXPORT_SYMBOL_GPL(hid_output_report
);
1037 * Set a field value. The report this field belongs to has to be
1038 * created and transferred to the device, to set this value in the
1042 int hid_set_field(struct hid_field
*field
, unsigned offset
, __s32 value
)
1049 size
= field
->report_size
;
1051 hid_dump_input(field
->report
->device
, field
->usage
+ offset
, value
);
1053 if (offset
>= field
->report_count
) {
1054 dbg_hid("offset (%d) exceeds report_count (%d)\n", offset
, field
->report_count
);
1057 if (field
->logical_minimum
< 0) {
1058 if (value
!= snto32(s32ton(value
, size
), size
)) {
1059 dbg_hid("value %d is out of range\n", value
);
1063 field
->value
[offset
] = value
;
1066 EXPORT_SYMBOL_GPL(hid_set_field
);
1068 static struct hid_report
*hid_get_report(struct hid_report_enum
*report_enum
,
1071 struct hid_report
*report
;
1072 unsigned int n
= 0; /* Normally report number is 0 */
1074 /* Device uses numbered reports, data[0] is report number */
1075 if (report_enum
->numbered
)
1078 report
= report_enum
->report_id_hash
[n
];
1080 dbg_hid("undefined report_id %u received\n", n
);
1085 void hid_report_raw_event(struct hid_device
*hid
, int type
, u8
*data
, int size
,
1088 struct hid_report_enum
*report_enum
= hid
->report_enum
+ type
;
1089 struct hid_report
*report
;
1091 int rsize
, csize
= size
;
1094 report
= hid_get_report(report_enum
, data
);
1098 if (report_enum
->numbered
) {
1103 rsize
= ((report
->size
- 1) >> 3) + 1;
1105 if (csize
< rsize
) {
1106 dbg_hid("report %d is too short, (%d < %d)\n", report
->id
,
1108 memset(cdata
+ csize
, 0, rsize
- csize
);
1111 if ((hid
->claimed
& HID_CLAIMED_HIDDEV
) && hid
->hiddev_report_event
)
1112 hid
->hiddev_report_event(hid
, report
);
1113 if (hid
->claimed
& HID_CLAIMED_HIDRAW
) {
1114 /* numbered reports need to be passed with the report num */
1115 if (report_enum
->numbered
)
1116 hidraw_report_event(hid
, data
- 1, size
+ 1);
1118 hidraw_report_event(hid
, data
, size
);
1121 for (a
= 0; a
< report
->maxfield
; a
++)
1122 hid_input_field(hid
, report
->field
[a
], cdata
, interrupt
);
1124 if (hid
->claimed
& HID_CLAIMED_INPUT
)
1125 hidinput_report_event(hid
, report
);
1127 EXPORT_SYMBOL_GPL(hid_report_raw_event
);
1130 * hid_input_report - report data from lower layer (usb, bt...)
1133 * @type: HID report type (HID_*_REPORT)
1134 * @data: report contents
1135 * @size: size of data parameter
1136 * @interrupt: distinguish between interrupt and control transfers
1138 * This is data entry for lower layers.
1140 int hid_input_report(struct hid_device
*hid
, int type
, u8
*data
, int size
, int interrupt
)
1142 struct hid_report_enum
*report_enum
;
1143 struct hid_driver
*hdrv
;
1144 struct hid_report
*report
;
1149 if (!hid
|| !hid
->driver
)
1151 report_enum
= hid
->report_enum
+ type
;
1155 dbg_hid("empty report\n");
1159 buf
= kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE
, GFP_ATOMIC
);
1162 report
= hid_get_report(report_enum
, data
);
1166 snprintf(buf
, HID_DEBUG_BUFSIZE
- 1,
1167 "\nreport (size %u) (%snumbered)\n", size
, report_enum
->numbered
? "" : "un");
1168 hid_debug_event(hid
, buf
);
1170 report
= hid_get_report(report_enum
, data
);
1176 /* dump the report */
1177 snprintf(buf
, HID_DEBUG_BUFSIZE
- 1,
1178 "report %d (size %u) = ", report
->id
, size
);
1179 hid_debug_event(hid
, buf
);
1180 for (i
= 0; i
< size
; i
++) {
1181 snprintf(buf
, HID_DEBUG_BUFSIZE
- 1,
1183 hid_debug_event(hid
, buf
);
1185 hid_debug_event(hid
, "\n");
1190 if (hdrv
&& hdrv
->raw_event
&& hid_match_report(hid
, report
)) {
1191 ret
= hdrv
->raw_event(hid
, report
, data
, size
);
1193 return ret
< 0 ? ret
: 0;
1196 hid_report_raw_event(hid
, type
, data
, size
, interrupt
);
1200 EXPORT_SYMBOL_GPL(hid_input_report
);
1202 static bool hid_match_one_id(struct hid_device
*hdev
,
1203 const struct hid_device_id
*id
)
1205 return id
->bus
== hdev
->bus
&&
1206 (id
->vendor
== HID_ANY_ID
|| id
->vendor
== hdev
->vendor
) &&
1207 (id
->product
== HID_ANY_ID
|| id
->product
== hdev
->product
);
1210 static const struct hid_device_id
*hid_match_id(struct hid_device
*hdev
,
1211 const struct hid_device_id
*id
)
1213 for (; id
->bus
; id
++)
1214 if (hid_match_one_id(hdev
, id
))
1220 static const struct hid_device_id hid_hiddev_list
[] = {
1221 { HID_USB_DEVICE(USB_VENDOR_ID_MGE
, USB_DEVICE_ID_MGE_UPS
) },
1222 { HID_USB_DEVICE(USB_VENDOR_ID_MGE
, USB_DEVICE_ID_MGE_UPS1
) },
1226 static bool hid_hiddev(struct hid_device
*hdev
)
1228 return !!hid_match_id(hdev
, hid_hiddev_list
);
1231 int hid_connect(struct hid_device
*hdev
, unsigned int connect_mask
)
1233 static const char *types
[] = { "Device", "Pointer", "Mouse", "Device",
1234 "Joystick", "Gamepad", "Keyboard", "Keypad",
1235 "Multi-Axis Controller"
1237 const char *type
, *bus
;
1242 if (hdev
->bus
!= BUS_USB
)
1243 connect_mask
&= ~HID_CONNECT_HIDDEV
;
1244 if (hid_hiddev(hdev
))
1245 connect_mask
|= HID_CONNECT_HIDDEV_FORCE
;
1247 if ((connect_mask
& HID_CONNECT_HIDINPUT
) && !hidinput_connect(hdev
,
1248 connect_mask
& HID_CONNECT_HIDINPUT_FORCE
))
1249 hdev
->claimed
|= HID_CLAIMED_INPUT
;
1250 if ((connect_mask
& HID_CONNECT_HIDDEV
) && hdev
->hiddev_connect
&&
1251 !hdev
->hiddev_connect(hdev
,
1252 connect_mask
& HID_CONNECT_HIDDEV_FORCE
))
1253 hdev
->claimed
|= HID_CLAIMED_HIDDEV
;
1254 if ((connect_mask
& HID_CONNECT_HIDRAW
) && !hidraw_connect(hdev
))
1255 hdev
->claimed
|= HID_CLAIMED_HIDRAW
;
1257 if (!hdev
->claimed
) {
1258 dev_err(&hdev
->dev
, "claimed by neither input, hiddev nor "
1263 if ((hdev
->claimed
& HID_CLAIMED_INPUT
) &&
1264 (connect_mask
& HID_CONNECT_FF
) && hdev
->ff_init
)
1265 hdev
->ff_init(hdev
);
1268 if (hdev
->claimed
& HID_CLAIMED_INPUT
)
1269 len
+= sprintf(buf
+ len
, "input");
1270 if (hdev
->claimed
& HID_CLAIMED_HIDDEV
)
1271 len
+= sprintf(buf
+ len
, "%shiddev%d", len
? "," : "",
1273 if (hdev
->claimed
& HID_CLAIMED_HIDRAW
)
1274 len
+= sprintf(buf
+ len
, "%shidraw%d", len
? "," : "",
1275 ((struct hidraw
*)hdev
->hidraw
)->minor
);
1278 for (i
= 0; i
< hdev
->maxcollection
; i
++) {
1279 struct hid_collection
*col
= &hdev
->collection
[i
];
1280 if (col
->type
== HID_COLLECTION_APPLICATION
&&
1281 (col
->usage
& HID_USAGE_PAGE
) == HID_UP_GENDESK
&&
1282 (col
->usage
& 0xffff) < ARRAY_SIZE(types
)) {
1283 type
= types
[col
->usage
& 0xffff];
1288 switch (hdev
->bus
) {
1299 dev_info(&hdev
->dev
, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1300 buf
, bus
, hdev
->version
>> 8, hdev
->version
& 0xff,
1301 type
, hdev
->name
, hdev
->phys
);
1305 EXPORT_SYMBOL_GPL(hid_connect
);
1307 void hid_disconnect(struct hid_device
*hdev
)
1309 if (hdev
->claimed
& HID_CLAIMED_INPUT
)
1310 hidinput_disconnect(hdev
);
1311 if (hdev
->claimed
& HID_CLAIMED_HIDDEV
)
1312 hdev
->hiddev_disconnect(hdev
);
1313 if (hdev
->claimed
& HID_CLAIMED_HIDRAW
)
1314 hidraw_disconnect(hdev
);
1316 EXPORT_SYMBOL_GPL(hid_disconnect
);
1318 /* a list of devices for which there is a specialized driver on HID bus */
1319 static const struct hid_device_id hid_blacklist
[] = {
1320 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH
, USB_DEVICE_ID_A4TECH_WCP32PU
) },
1321 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH
, USB_DEVICE_ID_A4TECH_X5_005D
) },
1322 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ATV_IRCONTROL
) },
1323 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_IRCONTROL4
) },
1324 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_MIGHTYMOUSE
) },
1325 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI
) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO
) },
1327 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ANSI
) },
1328 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ISO
) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_JIS
) },
1330 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ANSI
) },
1331 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ISO
) },
1332 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_JIS
) },
1333 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ANSI
) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ISO
) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_JIS
) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI
) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_MINI_ISO
) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_MINI_JIS
) },
1339 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_ANSI
) },
1340 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_ISO
) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_JIS
) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI
) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO
) },
1344 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS
) },
1345 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI
) },
1346 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO
) },
1347 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS
) },
1348 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI
) },
1349 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ISO
) },
1350 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_JIS
) },
1351 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI
) },
1352 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO
) },
1353 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS
) },
1354 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI
) },
1355 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO
) },
1356 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS
) },
1357 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI
) },
1358 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO
) },
1359 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS
) },
1360 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI
) },
1361 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO
) },
1362 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS
) },
1363 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI
) },
1364 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO
) },
1365 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS
) },
1366 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY
) },
1367 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY
) },
1368 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN
, USB_DEVICE_ID_FLIP_KVM
) },
1369 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY
, USB_DEVICE_ID_CHERRY_CYMOTION
) },
1370 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY
, USB_DEVICE_ID_CHICONY_TACTICAL_PAD
) },
1371 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_1
) },
1372 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_2
) },
1373 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_BARCODE_3
) },
1374 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_MOUSE
) },
1375 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE
, 0x0006) },
1376 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY
, USB_DEVICE_ID_BTC_8193
) },
1377 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON
, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR
) },
1378 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON
, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR
) },
1379 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA
, 0x0003) },
1380 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA
, 0x0012) },
1381 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION
, USB_DEVICE_ID_GYRATION_REMOTE
) },
1382 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION
, USB_DEVICE_ID_GYRATION_REMOTE_2
) },
1383 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION
, USB_DEVICE_ID_GYRATION_REMOTE_3
) },
1384 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON
, USB_DEVICE_ID_KS_SLIMBLADE
) },
1385 { HID_USB_DEVICE(USB_VENDOR_ID_KYE
, USB_DEVICE_ID_KYE_ERGO_525V
) },
1386 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC
, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD
) },
1387 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_MX3000_RECEIVER
) },
1388 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_S510_RECEIVER
) },
1389 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_S510_RECEIVER_2
) },
1390 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RECEIVER
) },
1391 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_DINOVO_DESKTOP
) },
1392 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_DINOVO_EDGE
) },
1393 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_DINOVO_MINI
) },
1394 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_ELITE_KBD
) },
1395 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500
) },
1396 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_EXTREME_3D
) },
1397 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_WHEEL
) },
1398 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RUMBLEPAD
) },
1399 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2
) },
1400 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D
) },
1401 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG
) },
1402 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO
) },
1403 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL
) },
1404 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2
) },
1405 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_G25_WHEEL
) },
1406 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2
) },
1407 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_SIDEWINDER_GV
) },
1408 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE4K
) },
1409 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_LK6K
) },
1410 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_USB
) },
1411 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0
) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY
, USB_DEVICE_ID_GENIUS_KB29E
) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG
, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN
) },
1414 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX
, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE
) },
1415 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG
, USB_DEVICE_ID_SAMSUNG_IR_REMOTE
) },
1416 { HID_USB_DEVICE(USB_VENDOR_ID_SONY
, USB_DEVICE_ID_SONY_PS3_CONTROLLER
) },
1417 { HID_USB_DEVICE(USB_VENDOR_ID_SONY
, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE
) },
1418 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS
, USB_DEVICE_ID_SUNPLUS_WDESKTOP
) },
1419 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb300) },
1420 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb304) },
1421 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb323) },
1422 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb324) },
1423 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb651) },
1424 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER
, 0xb654) },
1425 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED
, USB_DEVICE_ID_TOPSEED_CYBERLINK
) },
1426 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN
, USB_DEVICE_ID_TWINHAN_IR_REMOTE
) },
1427 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_SMARTJOY_PLUS
) },
1428 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM
, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
) },
1429 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS
, 0x0005) },
1430 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS
, 0x0030) },
1432 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_BT
) },
1437 struct list_head list
;
1438 struct hid_device_id id
;
1442 * store_new_id - add a new HID device ID to this driver and re-probe devices
1443 * @driver: target device driver
1444 * @buf: buffer for scanning device ID data
1445 * @count: input size
1447 * Adds a new dynamic hid device ID to this driver,
1448 * and causes the driver to probe for all devices again.
1450 static ssize_t
store_new_id(struct device_driver
*drv
, const char *buf
,
1453 struct hid_driver
*hdrv
= container_of(drv
, struct hid_driver
, driver
);
1454 struct hid_dynid
*dynid
;
1455 __u32 bus
, vendor
, product
;
1456 unsigned long driver_data
= 0;
1459 ret
= sscanf(buf
, "%x %x %x %lx",
1460 &bus
, &vendor
, &product
, &driver_data
);
1464 dynid
= kzalloc(sizeof(*dynid
), GFP_KERNEL
);
1468 dynid
->id
.bus
= bus
;
1469 dynid
->id
.vendor
= vendor
;
1470 dynid
->id
.product
= product
;
1471 dynid
->id
.driver_data
= driver_data
;
1473 spin_lock(&hdrv
->dyn_lock
);
1474 list_add_tail(&dynid
->list
, &hdrv
->dyn_list
);
1475 spin_unlock(&hdrv
->dyn_lock
);
1478 if (get_driver(&hdrv
->driver
)) {
1479 ret
= driver_attach(&hdrv
->driver
);
1480 put_driver(&hdrv
->driver
);
1483 return ret
? : count
;
1485 static DRIVER_ATTR(new_id
, S_IWUSR
, NULL
, store_new_id
);
1487 static void hid_free_dynids(struct hid_driver
*hdrv
)
1489 struct hid_dynid
*dynid
, *n
;
1491 spin_lock(&hdrv
->dyn_lock
);
1492 list_for_each_entry_safe(dynid
, n
, &hdrv
->dyn_list
, list
) {
1493 list_del(&dynid
->list
);
1496 spin_unlock(&hdrv
->dyn_lock
);
1499 static const struct hid_device_id
*hid_match_device(struct hid_device
*hdev
,
1500 struct hid_driver
*hdrv
)
1502 struct hid_dynid
*dynid
;
1504 spin_lock(&hdrv
->dyn_lock
);
1505 list_for_each_entry(dynid
, &hdrv
->dyn_list
, list
) {
1506 if (hid_match_one_id(hdev
, &dynid
->id
)) {
1507 spin_unlock(&hdrv
->dyn_lock
);
1511 spin_unlock(&hdrv
->dyn_lock
);
1513 return hid_match_id(hdev
, hdrv
->id_table
);
1516 static int hid_bus_match(struct device
*dev
, struct device_driver
*drv
)
1518 struct hid_driver
*hdrv
= container_of(drv
, struct hid_driver
, driver
);
1519 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1521 if (!hid_match_device(hdev
, hdrv
))
1524 /* generic wants all non-blacklisted */
1525 if (!strncmp(hdrv
->name
, "generic-", 8))
1526 return !hid_match_id(hdev
, hid_blacklist
);
1531 static int hid_device_probe(struct device
*dev
)
1533 struct hid_driver
*hdrv
= container_of(dev
->driver
,
1534 struct hid_driver
, driver
);
1535 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1536 const struct hid_device_id
*id
;
1539 if (!hdev
->driver
) {
1540 id
= hid_match_device(hdev
, hdrv
);
1544 hdev
->driver
= hdrv
;
1546 ret
= hdrv
->probe(hdev
, id
);
1547 } else { /* default probe */
1548 ret
= hid_parse(hdev
);
1550 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
1553 hdev
->driver
= NULL
;
1558 static int hid_device_remove(struct device
*dev
)
1560 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1561 struct hid_driver
*hdrv
= hdev
->driver
;
1566 else /* default remove */
1568 hdev
->driver
= NULL
;
1574 static int hid_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1576 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1578 if (add_uevent_var(env
, "HID_ID=%04X:%08X:%08X",
1579 hdev
->bus
, hdev
->vendor
, hdev
->product
))
1582 if (add_uevent_var(env
, "HID_NAME=%s", hdev
->name
))
1585 if (add_uevent_var(env
, "HID_PHYS=%s", hdev
->phys
))
1588 if (add_uevent_var(env
, "HID_UNIQ=%s", hdev
->uniq
))
1591 if (add_uevent_var(env
, "MODALIAS=hid:b%04Xv%08Xp%08X",
1592 hdev
->bus
, hdev
->vendor
, hdev
->product
))
1598 static struct bus_type hid_bus_type
= {
1600 .match
= hid_bus_match
,
1601 .probe
= hid_device_probe
,
1602 .remove
= hid_device_remove
,
1603 .uevent
= hid_uevent
,
1606 /* a list of devices that shouldn't be handled by HID core at all */
1607 static const struct hid_device_id hid_ignore_list
[] = {
1608 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD
, USB_DEVICE_ID_ACECAD_FLAIR
) },
1609 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD
, USB_DEVICE_ID_ACECAD_302
) },
1610 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH
, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X
) },
1611 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_01
) },
1612 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_10
) },
1613 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_20
) },
1614 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_21
) },
1615 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_22
) },
1616 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_23
) },
1617 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK
, USB_DEVICE_ID_AIPTEK_24
) },
1618 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE
, USB_DEVICE_ID_AIRCABLE1
) },
1619 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR
, USB_DEVICE_ID_ALCOR_USBRS232
) },
1620 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS
, USB_DEVICE_ID_ASUS_LCM
)},
1621 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS
, USB_DEVICE_ID_ASUS_LCM2
)},
1622 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA
, USB_DEVICE_ID_AVER_FM_MR800
) },
1623 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE
, USB_DEVICE_ID_BERKSHIRE_PCWD
) },
1624 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC
, 0x0103) },
1625 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL
, USB_DEVICE_ID_CYGNAL_RADIO_SI470X
) },
1626 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA
, USB_DEVICE_ID_CM109
) },
1627 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_HIDCOM
) },
1628 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS
, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE
) },
1629 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME
, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701
) },
1630 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME
, USB_DEVICE_ID_DELORME_EARTHMATE
) },
1631 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME
, USB_DEVICE_ID_DELORME_EM_LT20
) },
1632 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY
, USB_DEVICE_ID_ESSENTIAL_REALITY_P5
) },
1633 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0001) },
1634 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0002) },
1635 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0003) },
1636 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH
, 0x0004) },
1637 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_4_PHIDGETSERVO_30
) },
1638 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_1_PHIDGETSERVO_30
) },
1639 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_0_4_IF_KIT
) },
1640 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_16_16_IF_KIT
) },
1641 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_8_8_8_IF_KIT
) },
1642 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_8_7_IF_KIT
) },
1643 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_0_8_8_IF_KIT
) },
1644 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB
, USB_DEVICE_ID_PHIDGET_MOTORCONTROL
) },
1645 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP
, USB_DEVICE_ID_SUPER_Q2
) },
1646 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP
, USB_DEVICE_ID_GOGOPEN
) },
1647 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP
, USB_DEVICE_ID_PENPOWER
) },
1648 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH
, USB_DEVICE_ID_GRETAGMACBETH_HUEY
) },
1649 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN
, USB_DEVICE_ID_POWERMATE
) },
1650 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN
, USB_DEVICE_ID_SOUNDKNOB
) },
1651 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_90
) },
1652 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_100
) },
1653 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_101
) },
1654 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_103
) },
1655 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_104
) },
1656 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_105
) },
1657 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_106
) },
1658 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_107
) },
1659 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_108
) },
1660 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_200
) },
1661 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_201
) },
1662 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_202
) },
1663 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_203
) },
1664 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_204
) },
1665 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_205
) },
1666 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_206
) },
1667 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_207
) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_300
) },
1669 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_301
) },
1670 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_302
) },
1671 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_303
) },
1672 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_304
) },
1673 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_305
) },
1674 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_306
) },
1675 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_307
) },
1676 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_308
) },
1677 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_309
) },
1678 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_400
) },
1679 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_401
) },
1680 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_402
) },
1681 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_403
) },
1682 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_404
) },
1683 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_405
) },
1684 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_500
) },
1685 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_501
) },
1686 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_502
) },
1687 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_503
) },
1688 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_504
) },
1689 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1000
) },
1690 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1001
) },
1691 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1002
) },
1692 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1003
) },
1693 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1004
) },
1694 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1005
) },
1695 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1006
) },
1696 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO
, USB_DEVICE_ID_GTCO_1007
) },
1697 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION
, USB_DEVICE_ID_DISC_STAKKA
) },
1698 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR
, USB_DEVICE_ID_KBGEAR_JAMSTUDIO
) },
1699 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD
, USB_DEVICE_ID_KWORLD_RADIO_FM700
) },
1700 { HID_USB_DEVICE(USB_VENDOR_ID_KYE
, USB_DEVICE_ID_KYE_GPEN_560
) },
1701 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_CASSY
) },
1702 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_POCKETCASSY
) },
1703 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_MOBILECASSY
) },
1704 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_JWM
) },
1705 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_DMMP
) },
1706 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_UMIP
) },
1707 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_XRAY1
) },
1708 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_XRAY2
) },
1709 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_VIDEOCOM
) },
1710 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_COM3LAB
) },
1711 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_TELEPORT
) },
1712 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_NETWORKANALYSER
) },
1713 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_POWERCONTROL
) },
1714 { HID_USB_DEVICE(USB_VENDOR_ID_LD
, USB_DEVICE_ID_LD_MACHINETEST
) },
1715 { HID_USB_DEVICE(USB_VENDOR_ID_MCC
, USB_DEVICE_ID_MCC_PMD1024LS
) },
1716 { HID_USB_DEVICE(USB_VENDOR_ID_MCC
, USB_DEVICE_ID_MCC_PMD1208LS
) },
1717 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICKIT1
) },
1718 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP
, USB_DEVICE_ID_PICKIT2
) },
1719 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR
, USB_DEVICE_ID_N_S_HARMONY
) },
1720 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
) },
1721 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 20) },
1722 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 30) },
1723 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 100) },
1724 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 108) },
1725 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 118) },
1726 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 200) },
1727 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 300) },
1728 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 400) },
1729 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK
, USB_DEVICE_ID_ONTRAK_ADU100
+ 500) },
1730 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0001) },
1731 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0002) },
1732 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0003) },
1733 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT
, 0x0004) },
1734 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS
, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE
) },
1735 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM
, USB_DEVICE_ID_POWERCOM_UPS
) },
1736 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_LABPRO
) },
1737 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_GOTEMP
) },
1738 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_SKIP
) },
1739 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_CYCLOPS
) },
1740 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER
, USB_DEVICE_ID_VERNIER_LCSPEC
) },
1741 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM
, HID_ANY_ID
) },
1742 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_4_PHIDGETSERVO_20
) },
1743 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_1_PHIDGETSERVO_20
) },
1744 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP
, USB_DEVICE_ID_8_8_4_IF_KIT
) },
1745 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK
, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K
) },
1750 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1752 * There are composite devices for which we want to ignore only a certain
1753 * interface. This is a list of devices for which only the mouse interface will
1754 * be ignored. This allows a dedicated driver to take care of the interface.
1756 static const struct hid_device_id hid_mouse_ignore_list
[] = {
1757 /* appletouch driver */
1758 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI
) },
1759 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO
) },
1760 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ANSI
) },
1761 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_ISO
) },
1762 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER_JIS
) },
1763 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ANSI
) },
1764 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_ISO
) },
1765 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER3_JIS
) },
1766 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ANSI
) },
1767 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_ISO
) },
1768 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_JIS
) },
1769 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI
) },
1770 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO
) },
1771 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS
) },
1772 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI
) },
1773 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_ISO
) },
1774 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING_JIS
) },
1775 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI
) },
1776 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO
) },
1777 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS
) },
1778 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI
) },
1779 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO
) },
1780 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS
) },
1781 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI
) },
1782 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO
) },
1783 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS
) },
1784 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI
) },
1785 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO
) },
1786 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS
) },
1787 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY
) },
1788 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE
, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY
) },
1792 static bool hid_ignore(struct hid_device
*hdev
)
1794 switch (hdev
->vendor
) {
1795 case USB_VENDOR_ID_CODEMERCS
:
1796 /* ignore all Code Mercenaries IOWarrior devices */
1797 if (hdev
->product
>= USB_DEVICE_ID_CODEMERCS_IOW_FIRST
&&
1798 hdev
->product
<= USB_DEVICE_ID_CODEMERCS_IOW_LAST
)
1801 case USB_VENDOR_ID_LOGITECH
:
1802 if (hdev
->product
>= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST
&&
1803 hdev
->product
<= USB_DEVICE_ID_LOGITECH_HARMONY_LAST
)
1806 case USB_VENDOR_ID_SOUNDGRAPH
:
1807 if (hdev
->product
>= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST
&&
1808 hdev
->product
<= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST
)
1813 if (hdev
->type
== HID_TYPE_USBMOUSE
&&
1814 hid_match_id(hdev
, hid_mouse_ignore_list
))
1817 return !!hid_match_id(hdev
, hid_ignore_list
);
1820 int hid_add_device(struct hid_device
*hdev
)
1822 static atomic_t id
= ATOMIC_INIT(0);
1825 if (WARN_ON(hdev
->status
& HID_STAT_ADDED
))
1828 /* we need to kill them here, otherwise they will stay allocated to
1829 * wait for coming driver */
1830 if (hid_ignore(hdev
))
1833 /* XXX hack, any other cleaner solution after the driver core
1834 * is converted to allow more than 20 bytes as the device name? */
1835 dev_set_name(&hdev
->dev
, "%04X:%04X:%04X.%04X", hdev
->bus
,
1836 hdev
->vendor
, hdev
->product
, atomic_inc_return(&id
));
1838 ret
= device_add(&hdev
->dev
);
1840 hdev
->status
|= HID_STAT_ADDED
;
1842 hid_debug_register(hdev
, dev_name(&hdev
->dev
));
1846 EXPORT_SYMBOL_GPL(hid_add_device
);
1849 * hid_allocate_device - allocate new hid device descriptor
1851 * Allocate and initialize hid device, so that hid_destroy_device might be
1854 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1857 struct hid_device
*hid_allocate_device(void)
1859 struct hid_device
*hdev
;
1863 hdev
= kzalloc(sizeof(*hdev
), GFP_KERNEL
);
1865 return ERR_PTR(ret
);
1867 device_initialize(&hdev
->dev
);
1868 hdev
->dev
.release
= hid_device_release
;
1869 hdev
->dev
.bus
= &hid_bus_type
;
1871 hdev
->collection
= kcalloc(HID_DEFAULT_NUM_COLLECTIONS
,
1872 sizeof(struct hid_collection
), GFP_KERNEL
);
1873 if (hdev
->collection
== NULL
)
1875 hdev
->collection_size
= HID_DEFAULT_NUM_COLLECTIONS
;
1877 for (i
= 0; i
< HID_REPORT_TYPES
; i
++)
1878 INIT_LIST_HEAD(&hdev
->report_enum
[i
].report_list
);
1880 init_waitqueue_head(&hdev
->debug_wait
);
1881 INIT_LIST_HEAD(&hdev
->debug_list
);
1885 put_device(&hdev
->dev
);
1886 return ERR_PTR(ret
);
1888 EXPORT_SYMBOL_GPL(hid_allocate_device
);
1890 static void hid_remove_device(struct hid_device
*hdev
)
1892 if (hdev
->status
& HID_STAT_ADDED
) {
1893 device_del(&hdev
->dev
);
1894 hid_debug_unregister(hdev
);
1895 hdev
->status
&= ~HID_STAT_ADDED
;
1900 * hid_destroy_device - free previously allocated device
1904 * If you allocate hid_device through hid_allocate_device, you should ever
1905 * free by this function.
1907 void hid_destroy_device(struct hid_device
*hdev
)
1909 hid_remove_device(hdev
);
1910 put_device(&hdev
->dev
);
1912 EXPORT_SYMBOL_GPL(hid_destroy_device
);
1914 int __hid_register_driver(struct hid_driver
*hdrv
, struct module
*owner
,
1915 const char *mod_name
)
1919 hdrv
->driver
.name
= hdrv
->name
;
1920 hdrv
->driver
.bus
= &hid_bus_type
;
1921 hdrv
->driver
.owner
= owner
;
1922 hdrv
->driver
.mod_name
= mod_name
;
1924 INIT_LIST_HEAD(&hdrv
->dyn_list
);
1925 spin_lock_init(&hdrv
->dyn_lock
);
1927 ret
= driver_register(&hdrv
->driver
);
1931 ret
= driver_create_file(&hdrv
->driver
, &driver_attr_new_id
);
1933 driver_unregister(&hdrv
->driver
);
1937 EXPORT_SYMBOL_GPL(__hid_register_driver
);
1939 void hid_unregister_driver(struct hid_driver
*hdrv
)
1941 driver_remove_file(&hdrv
->driver
, &driver_attr_new_id
);
1942 driver_unregister(&hdrv
->driver
);
1943 hid_free_dynids(hdrv
);
1945 EXPORT_SYMBOL_GPL(hid_unregister_driver
);
1947 int hid_check_keys_pressed(struct hid_device
*hid
)
1949 struct hid_input
*hidinput
;
1952 if (!(hid
->claimed
& HID_CLAIMED_INPUT
))
1955 list_for_each_entry(hidinput
, &hid
->inputs
, list
) {
1956 for (i
= 0; i
< BITS_TO_LONGS(KEY_MAX
); i
++)
1957 if (hidinput
->input
->key
[i
])
1964 EXPORT_SYMBOL_GPL(hid_check_keys_pressed
);
1966 static int __init
hid_init(void)
1971 printk(KERN_WARNING
"HID: hid_debug is now used solely for parser and driver debugging.\n"
1972 "HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
1974 ret
= bus_register(&hid_bus_type
);
1976 printk(KERN_ERR
"HID: can't register hid bus\n");
1980 ret
= hidraw_init();
1988 bus_unregister(&hid_bus_type
);
1993 static void __exit
hid_exit(void)
1997 bus_unregister(&hid_bus_type
);
2000 module_init(hid_init
);
2001 module_exit(hid_exit
);
2003 MODULE_LICENSE(DRIVER_LICENSE
);