]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/hid/hid-core.c
HID: hidraw: Fix returning EPOLLOUT from hidraw_poll
[mirror_ubuntu-bionic-kernel.git] / drivers / hid / hid-core.c
CommitLineData
dde5845a 1/*
229695e5 2 * HID support for Linux
dde5845a
JK
3 *
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
6b1968d5 7 * Copyright (c) 2006-2012 Jiri Kosina
dde5845a
JK
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 */
16
4291ee30
JP
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
dde5845a
JK
19#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/init.h>
22#include <linux/kernel.h>
dde5845a
JK
23#include <linux/list.h>
24#include <linux/mm.h>
dde5845a
JK
25#include <linux/spinlock.h>
26#include <asm/unaligned.h>
27#include <asm/byteorder.h>
28#include <linux/input.h>
29#include <linux/wait.h>
47a80edb 30#include <linux/vmalloc.h>
c4124c9b 31#include <linux/sched.h>
4ea54542 32#include <linux/semaphore.h>
dde5845a 33
dde5845a
JK
34#include <linux/hid.h>
35#include <linux/hiddev.h>
c080d89a 36#include <linux/hid-debug.h>
86166b7b 37#include <linux/hidraw.h>
ba3eb73c 38#include <linux/input/elan-i2c-ids.h>
dde5845a 39
5f22a799
JS
40#include "hid-ids.h"
41
dde5845a
JK
42/*
43 * Version Information
44 */
45
53149801 46#define DRIVER_DESC "HID core driver"
dde5845a 47
58037eb9 48int hid_debug = 0;
377e10fb 49module_param_named(debug, hid_debug, int, 0600);
cd667ce2 50MODULE_PARM_DESC(debug, "toggle HID debugging messages");
58037eb9 51EXPORT_SYMBOL_GPL(hid_debug);
58037eb9 52
6b1968d5
JK
53static int hid_ignore_special_drivers = 0;
54module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
643727a9 55MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
6b1968d5 56
dde5845a
JK
57/*
58 * Register a new report for a device.
59 */
60
90a006ab 61struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
dde5845a
JK
62{
63 struct hid_report_enum *report_enum = device->report_enum + type;
64 struct hid_report *report;
65
43622021
KC
66 if (id >= HID_MAX_IDS)
67 return NULL;
dde5845a
JK
68 if (report_enum->report_id_hash[id])
69 return report_enum->report_id_hash[id];
70
a3789a17
JP
71 report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
72 if (!report)
dde5845a
JK
73 return NULL;
74
75 if (id != 0)
76 report_enum->numbered = 1;
77
78 report->id = id;
79 report->type = type;
80 report->size = 0;
81 report->device = device;
82 report_enum->report_id_hash[id] = report;
83
84 list_add_tail(&report->list, &report_enum->report_list);
85
86 return report;
87}
90a006ab 88EXPORT_SYMBOL_GPL(hid_register_report);
dde5845a
JK
89
90/*
91 * Register a new field for this report.
92 */
93
94static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
95{
96 struct hid_field *field;
97
98 if (report->maxfield == HID_MAX_FIELDS) {
8c3d52fc 99 hid_err(report->device, "too many fields in report\n");
dde5845a
JK
100 return NULL;
101 }
102
a3789a17
JP
103 field = kzalloc((sizeof(struct hid_field) +
104 usages * sizeof(struct hid_usage) +
105 values * sizeof(unsigned)), GFP_KERNEL);
106 if (!field)
107 return NULL;
dde5845a
JK
108
109 field->index = report->maxfield++;
110 report->field[field->index] = field;
111 field->usage = (struct hid_usage *)(field + 1);
282bfd4c 112 field->value = (s32 *)(field->usage + usages);
dde5845a
JK
113 field->report = report;
114
115 return field;
116}
117
118/*
119 * Open a collection. The type/usage is pushed on the stack.
120 */
121
122static int open_collection(struct hid_parser *parser, unsigned type)
123{
124 struct hid_collection *collection;
125 unsigned usage;
126
127 usage = parser->local.usage[0];
128
129 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
8c3d52fc 130 hid_err(parser->device, "collection stack overflow\n");
a6fbaacf 131 return -EINVAL;
dde5845a
JK
132 }
133
134 if (parser->device->maxcollection == parser->device->collection_size) {
135 collection = kmalloc(sizeof(struct hid_collection) *
136 parser->device->collection_size * 2, GFP_KERNEL);
137 if (collection == NULL) {
8c3d52fc 138 hid_err(parser->device, "failed to reallocate collection array\n");
a6fbaacf 139 return -ENOMEM;
dde5845a
JK
140 }
141 memcpy(collection, parser->device->collection,
142 sizeof(struct hid_collection) *
143 parser->device->collection_size);
144 memset(collection + parser->device->collection_size, 0,
145 sizeof(struct hid_collection) *
146 parser->device->collection_size);
147 kfree(parser->device->collection);
148 parser->device->collection = collection;
149 parser->device->collection_size *= 2;
150 }
151
152 parser->collection_stack[parser->collection_stack_ptr++] =
153 parser->device->maxcollection;
154
155 collection = parser->device->collection +
156 parser->device->maxcollection++;
157 collection->type = type;
158 collection->usage = usage;
159 collection->level = parser->collection_stack_ptr - 1;
160
161 if (type == HID_COLLECTION_APPLICATION)
162 parser->device->maxapplication++;
163
164 return 0;
165}
166
167/*
168 * Close a collection.
169 */
170
171static int close_collection(struct hid_parser *parser)
172{
173 if (!parser->collection_stack_ptr) {
8c3d52fc 174 hid_err(parser->device, "collection stack underflow\n");
a6fbaacf 175 return -EINVAL;
dde5845a
JK
176 }
177 parser->collection_stack_ptr--;
178 return 0;
179}
180
181/*
182 * Climb up the stack, search for the specified collection type
183 * and return the usage.
184 */
185
186static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
187{
504499f2 188 struct hid_collection *collection = parser->device->collection;
dde5845a 189 int n;
504499f2
JP
190
191 for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
192 unsigned index = parser->collection_stack[n];
193 if (collection[index].type == type)
194 return collection[index].usage;
195 }
dde5845a
JK
196 return 0; /* we know nothing about this usage type */
197}
198
d77b597e
CS
199/*
200 * Concatenate usage which defines 16 bits or less with the
201 * currently defined usage page to form a 32 bit usage
202 */
203
204static void complete_usage(struct hid_parser *parser, unsigned int index)
205{
206 parser->local.usage[index] &= 0xFFFF;
207 parser->local.usage[index] |=
208 (parser->global.usage_page & 0xFFFF) << 16;
209}
210
dde5845a
JK
211/*
212 * Add a usage to the temporary parser table.
213 */
214
10657924 215static int hid_add_usage(struct hid_parser *parser, unsigned usage, u8 size)
dde5845a
JK
216{
217 if (parser->local.usage_index >= HID_MAX_USAGES) {
8c3d52fc 218 hid_err(parser->device, "usage index exceeded\n");
dde5845a
JK
219 return -1;
220 }
221 parser->local.usage[parser->local.usage_index] = usage;
d77b597e
CS
222
223 /*
224 * If Usage item only includes usage id, concatenate it with
225 * currently defined usage page
226 */
227 if (size <= 2)
228 complete_usage(parser, parser->local.usage_index);
229
10657924 230 parser->local.usage_size[parser->local.usage_index] = size;
dde5845a
JK
231 parser->local.collection_index[parser->local.usage_index] =
232 parser->collection_stack_ptr ?
233 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
234 parser->local.usage_index++;
235 return 0;
236}
237
238/*
239 * Register a new field for this report.
240 */
241
242static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
243{
244 struct hid_report *report;
245 struct hid_field *field;
cc6b54aa 246 unsigned usages;
dde5845a 247 unsigned offset;
cc6b54aa 248 unsigned i;
dde5845a 249
a3789a17
JP
250 report = hid_register_report(parser->device, report_type, parser->global.report_id);
251 if (!report) {
8c3d52fc 252 hid_err(parser->device, "hid_register_report failed\n");
dde5845a
JK
253 return -1;
254 }
255
bb2e1976 256 /* Handle both signed and unsigned cases properly */
0cd516c2 257 if ((parser->global.logical_minimum < 0 &&
258 parser->global.logical_maximum <
259 parser->global.logical_minimum) ||
260 (parser->global.logical_minimum >= 0 &&
261 (__u32)parser->global.logical_maximum <
262 (__u32)parser->global.logical_minimum)) {
263 dbg_hid("logical range invalid 0x%x 0x%x\n",
264 parser->global.logical_minimum,
265 parser->global.logical_maximum);
dde5845a
JK
266 return -1;
267 }
268
269 offset = report->size;
270 report->size += parser->global.report_size * parser->global.report_count;
271
fdc37c80
AS
272 /* Total size check: Allow for possible report index byte */
273 if (report->size > (HID_MAX_BUFFER_SIZE - 1) << 3) {
274 hid_err(parser->device, "report is too long\n");
275 return -1;
276 }
277
dde5845a
JK
278 if (!parser->local.usage_index) /* Ignore padding fields */
279 return 0;
280
cc6b54aa
BT
281 usages = max_t(unsigned, parser->local.usage_index,
282 parser->global.report_count);
dde5845a 283
a3789a17
JP
284 field = hid_register_field(report, usages, parser->global.report_count);
285 if (!field)
dde5845a
JK
286 return 0;
287
288 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
289 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
290 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
291
292 for (i = 0; i < usages; i++) {
cc6b54aa 293 unsigned j = i;
dde5845a
JK
294 /* Duplicate the last usage we parsed if we have excess values */
295 if (i >= parser->local.usage_index)
296 j = parser->local.usage_index - 1;
297 field->usage[i].hid = parser->local.usage[j];
298 field->usage[i].collection_index =
299 parser->local.collection_index[j];
cc6b54aa 300 field->usage[i].usage_index = i;
dde5845a
JK
301 }
302
303 field->maxusage = usages;
304 field->flags = flags;
305 field->report_offset = offset;
306 field->report_type = report_type;
307 field->report_size = parser->global.report_size;
308 field->report_count = parser->global.report_count;
309 field->logical_minimum = parser->global.logical_minimum;
310 field->logical_maximum = parser->global.logical_maximum;
311 field->physical_minimum = parser->global.physical_minimum;
312 field->physical_maximum = parser->global.physical_maximum;
313 field->unit_exponent = parser->global.unit_exponent;
314 field->unit = parser->global.unit;
315
316 return 0;
317}
318
319/*
320 * Read data value from item.
321 */
322
323static u32 item_udata(struct hid_item *item)
324{
325 switch (item->size) {
880d29f1
JS
326 case 1: return item->data.u8;
327 case 2: return item->data.u16;
328 case 4: return item->data.u32;
dde5845a
JK
329 }
330 return 0;
331}
332
333static s32 item_sdata(struct hid_item *item)
334{
335 switch (item->size) {
880d29f1
JS
336 case 1: return item->data.s8;
337 case 2: return item->data.s16;
338 case 4: return item->data.s32;
dde5845a
JK
339 }
340 return 0;
341}
342
343/*
344 * Process a global item.
345 */
346
347static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
348{
ad0e669b 349 __s32 raw_value;
dde5845a 350 switch (item->tag) {
880d29f1 351 case HID_GLOBAL_ITEM_TAG_PUSH:
dde5845a 352
880d29f1 353 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
8c3d52fc 354 hid_err(parser->device, "global environment stack overflow\n");
880d29f1
JS
355 return -1;
356 }
dde5845a 357
880d29f1
JS
358 memcpy(parser->global_stack + parser->global_stack_ptr++,
359 &parser->global, sizeof(struct hid_global));
360 return 0;
dde5845a 361
880d29f1 362 case HID_GLOBAL_ITEM_TAG_POP:
dde5845a 363
880d29f1 364 if (!parser->global_stack_ptr) {
8c3d52fc 365 hid_err(parser->device, "global environment stack underflow\n");
880d29f1
JS
366 return -1;
367 }
dde5845a 368
880d29f1
JS
369 memcpy(&parser->global, parser->global_stack +
370 --parser->global_stack_ptr, sizeof(struct hid_global));
371 return 0;
dde5845a 372
880d29f1
JS
373 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
374 parser->global.usage_page = item_udata(item);
375 return 0;
dde5845a 376
880d29f1
JS
377 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
378 parser->global.logical_minimum = item_sdata(item);
379 return 0;
dde5845a 380
880d29f1
JS
381 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
382 if (parser->global.logical_minimum < 0)
383 parser->global.logical_maximum = item_sdata(item);
384 else
385 parser->global.logical_maximum = item_udata(item);
386 return 0;
dde5845a 387
880d29f1
JS
388 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
389 parser->global.physical_minimum = item_sdata(item);
390 return 0;
dde5845a 391
880d29f1
JS
392 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
393 if (parser->global.physical_minimum < 0)
394 parser->global.physical_maximum = item_sdata(item);
395 else
396 parser->global.physical_maximum = item_udata(item);
397 return 0;
dde5845a 398
880d29f1 399 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
ad0e669b
NK
400 /* Many devices provide unit exponent as a two's complement
401 * nibble due to the common misunderstanding of HID
402 * specification 1.11, 6.2.2.7 Global Items. Attempt to handle
403 * both this and the standard encoding. */
404 raw_value = item_sdata(item);
77463838
BT
405 if (!(raw_value & 0xfffffff0))
406 parser->global.unit_exponent = hid_snto32(raw_value, 4);
407 else
408 parser->global.unit_exponent = raw_value;
880d29f1 409 return 0;
dde5845a 410
880d29f1
JS
411 case HID_GLOBAL_ITEM_TAG_UNIT:
412 parser->global.unit = item_udata(item);
413 return 0;
dde5845a 414
880d29f1
JS
415 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
416 parser->global.report_size = item_udata(item);
23408f95 417 if (parser->global.report_size > 128) {
8c3d52fc 418 hid_err(parser->device, "invalid report_size %d\n",
880d29f1
JS
419 parser->global.report_size);
420 return -1;
421 }
422 return 0;
dde5845a 423
880d29f1
JS
424 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
425 parser->global.report_count = item_udata(item);
426 if (parser->global.report_count > HID_MAX_USAGES) {
8c3d52fc 427 hid_err(parser->device, "invalid report_count %d\n",
880d29f1
JS
428 parser->global.report_count);
429 return -1;
430 }
431 return 0;
dde5845a 432
880d29f1
JS
433 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
434 parser->global.report_id = item_udata(item);
43622021
KC
435 if (parser->global.report_id == 0 ||
436 parser->global.report_id >= HID_MAX_IDS) {
437 hid_err(parser->device, "report_id %u is invalid\n",
438 parser->global.report_id);
dde5845a 439 return -1;
880d29f1
JS
440 }
441 return 0;
442
443 default:
8c3d52fc 444 hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
880d29f1 445 return -1;
dde5845a
JK
446 }
447}
448
449/*
450 * Process a local item.
451 */
452
453static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
454{
455 __u32 data;
456 unsigned n;
ba532198 457 __u32 count;
dde5845a 458
dde5845a
JK
459 data = item_udata(item);
460
461 switch (item->tag) {
880d29f1
JS
462 case HID_LOCAL_ITEM_TAG_DELIMITER:
463
464 if (data) {
465 /*
466 * We treat items before the first delimiter
467 * as global to all usage sets (branch 0).
468 * In the moment we process only these global
469 * items and the first delimiter set.
470 */
471 if (parser->local.delimiter_depth != 0) {
8c3d52fc 472 hid_err(parser->device, "nested delimiters\n");
880d29f1 473 return -1;
dde5845a 474 }
880d29f1
JS
475 parser->local.delimiter_depth++;
476 parser->local.delimiter_branch++;
477 } else {
478 if (parser->local.delimiter_depth < 1) {
8c3d52fc 479 hid_err(parser->device, "bogus close delimiter\n");
880d29f1 480 return -1;
dde5845a 481 }
880d29f1
JS
482 parser->local.delimiter_depth--;
483 }
38ead6ef 484 return 0;
dde5845a 485
880d29f1 486 case HID_LOCAL_ITEM_TAG_USAGE:
dde5845a 487
880d29f1
JS
488 if (parser->local.delimiter_branch > 1) {
489 dbg_hid("alternative usage ignored\n");
490 return 0;
491 }
dde5845a 492
10657924 493 return hid_add_usage(parser, data, item->size);
dde5845a 494
880d29f1 495 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
dde5845a 496
880d29f1
JS
497 if (parser->local.delimiter_branch > 1) {
498 dbg_hid("alternative usage ignored\n");
dde5845a 499 return 0;
880d29f1 500 }
dde5845a 501
880d29f1
JS
502 parser->local.usage_minimum = data;
503 return 0;
dde5845a 504
880d29f1 505 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
dde5845a 506
880d29f1
JS
507 if (parser->local.delimiter_branch > 1) {
508 dbg_hid("alternative usage ignored\n");
dde5845a 509 return 0;
880d29f1 510 }
dde5845a 511
ba532198
BT
512 count = data - parser->local.usage_minimum;
513 if (count + parser->local.usage_index >= HID_MAX_USAGES) {
514 /*
515 * We do not warn if the name is not set, we are
516 * actually pre-scanning the device.
517 */
518 if (dev_name(&parser->device->dev))
519 hid_warn(parser->device,
520 "ignoring exceeding usage max\n");
521 data = HID_MAX_USAGES - parser->local.usage_index +
522 parser->local.usage_minimum - 1;
523 if (data <= 0) {
524 hid_err(parser->device,
525 "no more usage index available\n");
526 return -1;
527 }
528 }
529
880d29f1 530 for (n = parser->local.usage_minimum; n <= data; n++)
10657924 531 if (hid_add_usage(parser, n, item->size)) {
880d29f1
JS
532 dbg_hid("hid_add_usage failed\n");
533 return -1;
534 }
535 return 0;
536
537 default:
538
539 dbg_hid("unknown local item tag 0x%x\n", item->tag);
540 return 0;
dde5845a
JK
541 }
542 return 0;
543}
544
10657924
NSJ
545/*
546 * Concatenate Usage Pages into Usages where relevant:
547 * As per specification, 6.2.2.8: "When the parser encounters a main item it
548 * concatenates the last declared Usage Page with a Usage to form a complete
549 * usage value."
550 */
551
d77b597e 552static void hid_concatenate_last_usage_page(struct hid_parser *parser)
10657924
NSJ
553{
554 int i;
d77b597e
CS
555 unsigned int usage_page;
556 unsigned int current_page;
557
558 if (!parser->local.usage_index)
559 return;
560
561 usage_page = parser->global.usage_page;
10657924 562
d77b597e
CS
563 /*
564 * Concatenate usage page again only if last declared Usage Page
565 * has not been already used in previous usages concatenation
566 */
567 for (i = parser->local.usage_index - 1; i >= 0; i--) {
568 if (parser->local.usage_size[i] > 2)
569 /* Ignore extended usages */
570 continue;
571
572 current_page = parser->local.usage[i] >> 16;
573 if (current_page == usage_page)
574 break;
575
576 complete_usage(parser, i);
577 }
10657924
NSJ
578}
579
dde5845a
JK
580/*
581 * Process a main item.
582 */
583
584static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
585{
586 __u32 data;
587 int ret;
588
d77b597e 589 hid_concatenate_last_usage_page(parser);
10657924 590
dde5845a
JK
591 data = item_udata(item);
592
593 switch (item->tag) {
880d29f1
JS
594 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
595 ret = open_collection(parser, data & 0xff);
596 break;
597 case HID_MAIN_ITEM_TAG_END_COLLECTION:
598 ret = close_collection(parser);
599 break;
600 case HID_MAIN_ITEM_TAG_INPUT:
601 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
602 break;
603 case HID_MAIN_ITEM_TAG_OUTPUT:
604 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
605 break;
606 case HID_MAIN_ITEM_TAG_FEATURE:
607 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
608 break;
609 default:
7cb4774e 610 hid_warn(parser->device, "unknown main item tag 0x%x\n", item->tag);
880d29f1 611 ret = 0;
dde5845a
JK
612 }
613
614 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
615
616 return ret;
617}
618
619/*
620 * Process a reserved item.
621 */
622
623static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
624{
58037eb9 625 dbg_hid("reserved item type, tag 0x%x\n", item->tag);
dde5845a
JK
626 return 0;
627}
628
629/*
630 * Free a report and all registered fields. The field->usage and
631 * field->value table's are allocated behind the field, so we need
632 * only to free(field) itself.
633 */
634
635static void hid_free_report(struct hid_report *report)
636{
637 unsigned n;
638
639 for (n = 0; n < report->maxfield; n++)
640 kfree(report->field[n]);
641 kfree(report);
642}
643
644/*
a7197c2e
HR
645 * Close report. This function returns the device
646 * state to the point prior to hid_open_report().
dde5845a 647 */
a7197c2e 648static void hid_close_report(struct hid_device *device)
dde5845a 649{
85cdaf52 650 unsigned i, j;
dde5845a
JK
651
652 for (i = 0; i < HID_REPORT_TYPES; i++) {
653 struct hid_report_enum *report_enum = device->report_enum + i;
654
43622021 655 for (j = 0; j < HID_MAX_IDS; j++) {
dde5845a
JK
656 struct hid_report *report = report_enum->report_id_hash[j];
657 if (report)
658 hid_free_report(report);
659 }
a7197c2e
HR
660 memset(report_enum, 0, sizeof(*report_enum));
661 INIT_LIST_HEAD(&report_enum->report_list);
dde5845a
JK
662 }
663
664 kfree(device->rdesc);
a7197c2e
HR
665 device->rdesc = NULL;
666 device->rsize = 0;
667
767fe787 668 kfree(device->collection);
a7197c2e
HR
669 device->collection = NULL;
670 device->collection_size = 0;
671 device->maxcollection = 0;
672 device->maxapplication = 0;
673
674 device->status &= ~HID_STAT_PARSED;
675}
676
677/*
678 * Free a device structure, all reports, and all fields.
679 */
680
681static void hid_device_release(struct device *dev)
682{
ee79a8f8 683 struct hid_device *hid = to_hid_device(dev);
a7197c2e
HR
684
685 hid_close_report(hid);
686 kfree(hid->dev_rdesc);
687 kfree(hid);
dde5845a
JK
688}
689
690/*
691 * Fetch a report description item from the data stream. We support long
692 * items, though they are not used yet.
693 */
694
695static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
696{
697 u8 b;
698
699 if ((end - start) <= 0)
700 return NULL;
701
702 b = *start++;
703
704 item->type = (b >> 2) & 3;
705 item->tag = (b >> 4) & 15;
706
707 if (item->tag == HID_ITEM_TAG_LONG) {
708
709 item->format = HID_ITEM_FORMAT_LONG;
710
711 if ((end - start) < 2)
712 return NULL;
713
714 item->size = *start++;
715 item->tag = *start++;
716
717 if ((end - start) < item->size)
718 return NULL;
719
720 item->data.longdata = start;
721 start += item->size;
722 return start;
723 }
724
725 item->format = HID_ITEM_FORMAT_SHORT;
726 item->size = b & 3;
727
728 switch (item->size) {
880d29f1
JS
729 case 0:
730 return start;
dde5845a 731
880d29f1
JS
732 case 1:
733 if ((end - start) < 1)
734 return NULL;
735 item->data.u8 = *start++;
736 return start;
737
738 case 2:
739 if ((end - start) < 2)
740 return NULL;
741 item->data.u16 = get_unaligned_le16(start);
742 start = (__u8 *)((__le16 *)start + 1);
743 return start;
744
745 case 3:
746 item->size++;
747 if ((end - start) < 4)
748 return NULL;
749 item->data.u32 = get_unaligned_le32(start);
750 start = (__u8 *)((__le32 *)start + 1);
751 return start;
dde5845a
JK
752 }
753
754 return NULL;
755}
756
3dc8fc08 757static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
734c6609 758{
3dc8fc08
BT
759 struct hid_device *hid = parser->device;
760
4fa3a583
HR
761 if (usage == HID_DG_CONTACTID)
762 hid->group = HID_GROUP_MULTITOUCH;
734c6609
HR
763}
764
f961bd35
BT
765static void hid_scan_feature_usage(struct hid_parser *parser, u32 usage)
766{
767 if (usage == 0xff0000c5 && parser->global.report_count == 256 &&
768 parser->global.report_size == 8)
769 parser->scan_flags |= HID_SCAN_FLAG_MT_WIN_8;
f75c181f
BH
770
771 if (usage == 0xff0000c6 && parser->global.report_count == 1 &&
772 parser->global.report_size == 8)
773 parser->scan_flags |= HID_SCAN_FLAG_MT_WIN_8;
f961bd35
BT
774}
775
3dc8fc08
BT
776static void hid_scan_collection(struct hid_parser *parser, unsigned type)
777{
778 struct hid_device *hid = parser->device;
e39f2d59 779 int i;
3dc8fc08
BT
780
781 if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
782 type == HID_COLLECTION_PHYSICAL)
783 hid->group = HID_GROUP_SENSOR_HUB;
be3b1634
AW
784
785 if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
0a76ac80 786 hid->product == USB_DEVICE_ID_MS_POWER_COVER &&
be3b1634
AW
787 hid->group == HID_GROUP_MULTITOUCH)
788 hid->group = HID_GROUP_GENERIC;
e39f2d59
AD
789
790 if ((parser->global.usage_page << 16) == HID_UP_GENDESK)
791 for (i = 0; i < parser->local.usage_index; i++)
792 if (parser->local.usage[i] == HID_GD_POINTER)
793 parser->scan_flags |= HID_SCAN_FLAG_GD_POINTER;
794
795 if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
796 parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
3dc8fc08
BT
797}
798
799static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
800{
801 __u32 data;
802 int i;
803
d77b597e 804 hid_concatenate_last_usage_page(parser);
10657924 805
3dc8fc08
BT
806 data = item_udata(item);
807
808 switch (item->tag) {
809 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
810 hid_scan_collection(parser, data & 0xff);
811 break;
812 case HID_MAIN_ITEM_TAG_END_COLLECTION:
813 break;
814 case HID_MAIN_ITEM_TAG_INPUT:
e24d0d39
BT
815 /* ignore constant inputs, they will be ignored by hid-input */
816 if (data & HID_MAIN_ITEM_CONSTANT)
817 break;
3dc8fc08
BT
818 for (i = 0; i < parser->local.usage_index; i++)
819 hid_scan_input_usage(parser, parser->local.usage[i]);
820 break;
821 case HID_MAIN_ITEM_TAG_OUTPUT:
822 break;
823 case HID_MAIN_ITEM_TAG_FEATURE:
f961bd35
BT
824 for (i = 0; i < parser->local.usage_index; i++)
825 hid_scan_feature_usage(parser, parser->local.usage[i]);
3dc8fc08
BT
826 break;
827 }
828
829 /* Reset the local parser environment */
830 memset(&parser->local, 0, sizeof(parser->local));
831
832 return 0;
833}
834
734c6609
HR
835/*
836 * Scan a report descriptor before the device is added to the bus.
837 * Sets device groups and other properties that determine what driver
838 * to load.
839 */
840static int hid_scan_report(struct hid_device *hid)
841{
3dc8fc08
BT
842 struct hid_parser *parser;
843 struct hid_item item;
734c6609
HR
844 __u8 *start = hid->dev_rdesc;
845 __u8 *end = start + hid->dev_rsize;
3dc8fc08
BT
846 static int (*dispatch_type[])(struct hid_parser *parser,
847 struct hid_item *item) = {
848 hid_scan_main,
849 hid_parser_global,
850 hid_parser_local,
851 hid_parser_reserved
852 };
853
854 parser = vzalloc(sizeof(struct hid_parser));
855 if (!parser)
856 return -ENOMEM;
734c6609 857
3dc8fc08 858 parser->device = hid;
734c6609 859 hid->group = HID_GROUP_GENERIC;
734c6609 860
3dc8fc08
BT
861 /*
862 * The parsing is simpler than the one in hid_open_report() as we should
863 * be robust against hid errors. Those errors will be raised by
864 * hid_open_report() anyway.
865 */
866 while ((start = fetch_item(start, end, &item)) != NULL)
867 dispatch_type[item.type](parser, &item);
868
f961bd35
BT
869 /*
870 * Handle special flags set during scanning.
871 */
872 if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
873 (hid->group == HID_GROUP_MULTITOUCH))
874 hid->group = HID_GROUP_MULTITOUCH_WIN_8;
875
29b47391
BT
876 /*
877 * Vendor specific handlings
878 */
879 switch (hid->vendor) {
880 case USB_VENDOR_ID_WACOM:
881 hid->group = HID_GROUP_WACOM;
882 break;
c241c5ee 883 case USB_VENDOR_ID_SYNAPTICS:
84379d83 884 if (hid->group == HID_GROUP_GENERIC)
e39f2d59
AD
885 if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
886 && (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER))
887 /*
888 * hid-rmi should take care of them,
889 * not hid-generic
890 */
0ca4cd7b 891 hid->group = HID_GROUP_RMI;
c241c5ee 892 break;
29b47391
BT
893 }
894
0ca4cd7b
JK
895 /* fall back to generic driver in case specific driver doesn't exist */
896 switch (hid->group) {
897 case HID_GROUP_MULTITOUCH_WIN_8:
898 /* fall-through */
899 case HID_GROUP_MULTITOUCH:
900 if (!IS_ENABLED(CONFIG_HID_MULTITOUCH))
901 hid->group = HID_GROUP_GENERIC;
902 break;
903 case HID_GROUP_SENSOR_HUB:
904 if (!IS_ENABLED(CONFIG_HID_SENSOR_HUB))
905 hid->group = HID_GROUP_GENERIC;
906 break;
907 case HID_GROUP_RMI:
908 if (!IS_ENABLED(CONFIG_HID_RMI))
909 hid->group = HID_GROUP_GENERIC;
910 break;
911 case HID_GROUP_WACOM:
912 if (!IS_ENABLED(CONFIG_HID_WACOM))
913 hid->group = HID_GROUP_GENERIC;
914 break;
915 case HID_GROUP_LOGITECH_DJ_DEVICE:
916 if (!IS_ENABLED(CONFIG_HID_LOGITECH_DJ))
917 hid->group = HID_GROUP_GENERIC;
918 break;
919 }
3dc8fc08 920 vfree(parser);
734c6609
HR
921 return 0;
922}
923
85cdaf52
JS
924/**
925 * hid_parse_report - parse device report
926 *
927 * @device: hid device
928 * @start: report start
929 * @size: report size
930 *
a7197c2e
HR
931 * Allocate the device report as read by the bus driver. This function should
932 * only be called from parse() in ll drivers.
933 */
934int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
935{
936 hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
937 if (!hid->dev_rdesc)
938 return -ENOMEM;
939 hid->dev_rsize = size;
940 return 0;
941}
942EXPORT_SYMBOL_GPL(hid_parse_report);
943
331415ff
KC
944static const char * const hid_report_names[] = {
945 "HID_INPUT_REPORT",
946 "HID_OUTPUT_REPORT",
947 "HID_FEATURE_REPORT",
948};
949/**
950 * hid_validate_values - validate existing device report's value indexes
951 *
952 * @device: hid device
953 * @type: which report type to examine
954 * @id: which report ID to examine (0 for first)
955 * @field_index: which report field to examine
956 * @report_counts: expected number of values
957 *
958 * Validate the number of values in a given field of a given report, after
959 * parsing.
960 */
961struct hid_report *hid_validate_values(struct hid_device *hid,
962 unsigned int type, unsigned int id,
963 unsigned int field_index,
964 unsigned int report_counts)
965{
966 struct hid_report *report;
967
968 if (type > HID_FEATURE_REPORT) {
969 hid_err(hid, "invalid HID report type %u\n", type);
970 return NULL;
971 }
972
973 if (id >= HID_MAX_IDS) {
974 hid_err(hid, "invalid HID report id %u\n", id);
975 return NULL;
976 }
977
978 /*
979 * Explicitly not using hid_get_report() here since it depends on
980 * ->numbered being checked, which may not always be the case when
981 * drivers go to access report values.
982 */
1b15d2e5
KC
983 if (id == 0) {
984 /*
985 * Validating on id 0 means we should examine the first
986 * report in the list.
987 */
988 report = list_entry(
989 hid->report_enum[type].report_list.next,
990 struct hid_report, list);
991 } else {
992 report = hid->report_enum[type].report_id_hash[id];
993 }
331415ff
KC
994 if (!report) {
995 hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
996 return NULL;
997 }
998 if (report->maxfield <= field_index) {
999 hid_err(hid, "not enough fields in %s %u\n",
1000 hid_report_names[type], id);
1001 return NULL;
1002 }
1003 if (report->field[field_index]->report_count < report_counts) {
1004 hid_err(hid, "not enough values in %s %u field %u\n",
1005 hid_report_names[type], id, field_index);
1006 return NULL;
1007 }
1008 return report;
1009}
1010EXPORT_SYMBOL_GPL(hid_validate_values);
1011
a7197c2e
HR
1012/**
1013 * hid_open_report - open a driver-specific device report
1014 *
1015 * @device: hid device
1016 *
dde5845a
JK
1017 * Parse a report description into a hid_device structure. Reports are
1018 * enumerated, fields are attached to these reports.
85cdaf52 1019 * 0 returned on success, otherwise nonzero error value.
a7197c2e
HR
1020 *
1021 * This function (or the equivalent hid_parse() macro) should only be
1022 * called from probe() in drivers, before starting the device.
dde5845a 1023 */
a7197c2e 1024int hid_open_report(struct hid_device *device)
dde5845a 1025{
dde5845a
JK
1026 struct hid_parser *parser;
1027 struct hid_item item;
a7197c2e
HR
1028 unsigned int size;
1029 __u8 *start;
86e6b77e 1030 __u8 *buf;
dde5845a 1031 __u8 *end;
7509457e 1032 __u8 *next;
85cdaf52 1033 int ret;
dde5845a
JK
1034 static int (*dispatch_type[])(struct hid_parser *parser,
1035 struct hid_item *item) = {
1036 hid_parser_main,
1037 hid_parser_global,
1038 hid_parser_local,
1039 hid_parser_reserved
1040 };
1041
a7197c2e
HR
1042 if (WARN_ON(device->status & HID_STAT_PARSED))
1043 return -EBUSY;
1044
1045 start = device->dev_rdesc;
1046 if (WARN_ON(!start))
1047 return -ENODEV;
1048 size = device->dev_rsize;
1049
86e6b77e
KD
1050 buf = kmemdup(start, size, GFP_KERNEL);
1051 if (buf == NULL)
1052 return -ENOMEM;
1053
c500c971 1054 if (device->driver->report_fixup)
86e6b77e
KD
1055 start = device->driver->report_fixup(device, buf, &size);
1056 else
1057 start = buf;
c500c971 1058
86e6b77e
KD
1059 start = kmemdup(start, size, GFP_KERNEL);
1060 kfree(buf);
1061 if (start == NULL)
85cdaf52 1062 return -ENOMEM;
86e6b77e
KD
1063
1064 device->rdesc = start;
dde5845a
JK
1065 device->rsize = size;
1066
fe258020 1067 parser = vzalloc(sizeof(struct hid_parser));
85cdaf52
JS
1068 if (!parser) {
1069 ret = -ENOMEM;
1070 goto err;
dde5845a 1071 }
85cdaf52 1072
dde5845a
JK
1073 parser->device = device;
1074
1075 end = start + size;
a7197c2e
HR
1076
1077 device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
1078 sizeof(struct hid_collection), GFP_KERNEL);
1079 if (!device->collection) {
1080 ret = -ENOMEM;
1081 goto err;
1082 }
1083 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
1084
85cdaf52 1085 ret = -EINVAL;
7509457e
MM
1086 while ((next = fetch_item(start, end, &item)) != NULL) {
1087 start = next;
dde5845a
JK
1088
1089 if (item.format != HID_ITEM_FORMAT_SHORT) {
8c3d52fc 1090 hid_err(device, "unexpected long global item\n");
85cdaf52 1091 goto err;
dde5845a
JK
1092 }
1093
1094 if (dispatch_type[item.type](parser, &item)) {
8c3d52fc 1095 hid_err(device, "item %u %u %u %u parsing failed\n",
4291ee30
JP
1096 item.format, (unsigned)item.size,
1097 (unsigned)item.type, (unsigned)item.tag);
85cdaf52 1098 goto err;
dde5845a
JK
1099 }
1100
1101 if (start == end) {
1102 if (parser->collection_stack_ptr) {
8c3d52fc 1103 hid_err(device, "unbalanced collection at end of report description\n");
85cdaf52 1104 goto err;
dde5845a
JK
1105 }
1106 if (parser->local.delimiter_depth) {
8c3d52fc 1107 hid_err(device, "unbalanced delimiter at end of report description\n");
85cdaf52 1108 goto err;
dde5845a 1109 }
47a80edb 1110 vfree(parser);
a7197c2e 1111 device->status |= HID_STAT_PARSED;
85cdaf52 1112 return 0;
dde5845a
JK
1113 }
1114 }
1115
7509457e
MM
1116 hid_err(device, "item fetching failed at offset %u/%u\n",
1117 size - (unsigned int)(end - start), size);
85cdaf52 1118err:
47a80edb 1119 vfree(parser);
a7197c2e 1120 hid_close_report(device);
85cdaf52 1121 return ret;
dde5845a 1122}
a7197c2e 1123EXPORT_SYMBOL_GPL(hid_open_report);
dde5845a
JK
1124
1125/*
1126 * Convert a signed n-bit integer to signed 32-bit integer. Common
1127 * cases are done through the compiler, the screwed things has to be
1128 * done by hand.
1129 */
1130
1131static s32 snto32(__u32 value, unsigned n)
1132{
1133 switch (n) {
880d29f1
JS
1134 case 8: return ((__s8)value);
1135 case 16: return ((__s16)value);
1136 case 32: return ((__s32)value);
dde5845a 1137 }
08585e43 1138 return value & (1 << (n - 1)) ? value | (~0U << n) : value;
dde5845a
JK
1139}
1140
77463838
BT
1141s32 hid_snto32(__u32 value, unsigned n)
1142{
1143 return snto32(value, n);
1144}
1145EXPORT_SYMBOL_GPL(hid_snto32);
1146
dde5845a
JK
1147/*
1148 * Convert a signed 32-bit integer to a signed n-bit integer.
1149 */
1150
1151static u32 s32ton(__s32 value, unsigned n)
1152{
1153 s32 a = value >> (n - 1);
1154 if (a && a != -1)
1155 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
1156 return value & ((1 << n) - 1);
1157}
1158
1159/*
1160 * Extract/implement a data field from/to a little endian report (bit array).
1161 *
1162 * Code sort-of follows HID spec:
5137b354 1163 * http://www.usb.org/developers/hidpage/HID1_11.pdf
dde5845a
JK
1164 *
1165 * While the USB HID spec allows unlimited length bit fields in "report
1166 * descriptors", most devices never use more than 16 bits.
1167 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
1168 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
1169 */
1170
5137b354 1171static u32 __extract(u8 *report, unsigned offset, int n)
dde5845a 1172{
5137b354
DT
1173 unsigned int idx = offset / 8;
1174 unsigned int bit_nr = 0;
1175 unsigned int bit_shift = offset % 8;
1176 int bits_to_copy = 8 - bit_shift;
1177 u32 value = 0;
1178 u32 mask = n < 32 ? (1U << n) - 1 : ~0U;
1179
1180 while (n > 0) {
1181 value |= ((u32)report[idx] >> bit_shift) << bit_nr;
1182 n -= bits_to_copy;
1183 bit_nr += bits_to_copy;
1184 bits_to_copy = 8;
1185 bit_shift = 0;
1186 idx++;
1187 }
1188
1189 return value & mask;
1190}
dde5845a 1191
5137b354
DT
1192u32 hid_field_extract(const struct hid_device *hid, u8 *report,
1193 unsigned offset, unsigned n)
1194{
1195 if (n > 32) {
7acf20a8
JC
1196 hid_warn_once(hid, "%s() called with n (%d) > 32! (%s)\n",
1197 __func__, n, current->comm);
5137b354
DT
1198 n = 32;
1199 }
dde5845a 1200
5137b354 1201 return __extract(report, offset, n);
dde5845a 1202}
04fba786 1203EXPORT_SYMBOL_GPL(hid_field_extract);
dde5845a
JK
1204
1205/*
1206 * "implement" : set bits in a little endian bit stream.
1207 * Same concepts as "extract" (see comments above).
1208 * The data mangled in the bit stream remains in little endian
1209 * order the whole time. It make more sense to talk about
1210 * endianness of register values by considering a register
5137b354 1211 * a "cached" copy of the little endian bit stream.
dde5845a 1212 */
5137b354
DT
1213
1214static void __implement(u8 *report, unsigned offset, int n, u32 value)
1215{
1216 unsigned int idx = offset / 8;
5137b354
DT
1217 unsigned int bit_shift = offset % 8;
1218 int bits_to_set = 8 - bit_shift;
5137b354
DT
1219
1220 while (n - bits_to_set >= 0) {
95d1c895 1221 report[idx] &= ~(0xff << bit_shift);
5137b354
DT
1222 report[idx] |= value << bit_shift;
1223 value >>= bits_to_set;
1224 n -= bits_to_set;
1225 bits_to_set = 8;
5137b354
DT
1226 bit_shift = 0;
1227 idx++;
1228 }
1229
1230 /* last nibble */
1231 if (n) {
95d1c895
DT
1232 u8 bit_mask = ((1U << n) - 1);
1233 report[idx] &= ~(bit_mask << bit_shift);
1234 report[idx] |= value << bit_shift;
5137b354
DT
1235 }
1236}
1237
1238static void implement(const struct hid_device *hid, u8 *report,
1239 unsigned offset, unsigned n, u32 value)
dde5845a 1240{
95d1c895 1241 if (unlikely(n > 32)) {
4291ee30
JP
1242 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
1243 __func__, n, current->comm);
5137b354 1244 n = 32;
95d1c895
DT
1245 } else if (n < 32) {
1246 u32 m = (1U << n) - 1;
1247
1248 if (unlikely(value > m)) {
1249 hid_warn(hid,
1250 "%s() called with too large value %d (n: %d)! (%s)\n",
1251 __func__, value, n, current->comm);
1252 WARN_ON(1);
1253 value &= m;
1254 }
5137b354 1255 }
dde5845a 1256
5137b354 1257 __implement(report, offset, n, value);
dde5845a
JK
1258}
1259
1260/*
1261 * Search an array for a value.
1262 */
1263
16ee4cc8 1264static int search(__s32 *array, __s32 value, unsigned n)
dde5845a
JK
1265{
1266 while (n--) {
1267 if (*array++ == value)
1268 return 0;
1269 }
1270 return -1;
1271}
1272
85cdaf52
JS
1273/**
1274 * hid_match_report - check if driver's raw_event should be called
1275 *
1276 * @hid: hid device
1277 * @report_type: type to match against
1278 *
1279 * compare hid->driver->report_table->report_type to report->type
1280 */
1281static int hid_match_report(struct hid_device *hid, struct hid_report *report)
dde5845a 1282{
85cdaf52
JS
1283 const struct hid_report_id *id = hid->driver->report_table;
1284
1285 if (!id) /* NULL means all */
1286 return 1;
1287
1288 for (; id->report_type != HID_TERMINATOR; id++)
1289 if (id->report_type == HID_ANY_ID ||
1290 id->report_type == report->type)
1291 return 1;
1292 return 0;
1293}
1294
1295/**
1296 * hid_match_usage - check if driver's event should be called
1297 *
1298 * @hid: hid device
1299 * @usage: usage to match against
1300 *
1301 * compare hid->driver->usage_table->usage_{type,code} to
1302 * usage->usage_{type,code}
1303 */
1304static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
1305{
1306 const struct hid_usage_id *id = hid->driver->usage_table;
1307
1308 if (!id) /* NULL means all */
1309 return 1;
1310
1311 for (; id->usage_type != HID_ANY_ID - 1; id++)
1312 if ((id->usage_hid == HID_ANY_ID ||
1313 id->usage_hid == usage->hid) &&
1314 (id->usage_type == HID_ANY_ID ||
1315 id->usage_type == usage->type) &&
1316 (id->usage_code == HID_ANY_ID ||
1317 id->usage_code == usage->code))
1318 return 1;
1319 return 0;
1320}
1321
1322static void hid_process_event(struct hid_device *hid, struct hid_field *field,
1323 struct hid_usage *usage, __s32 value, int interrupt)
1324{
1325 struct hid_driver *hdrv = hid->driver;
1326 int ret;
1327
9bfc8da0
HR
1328 if (!list_empty(&hid->debug_list))
1329 hid_dump_input(hid, usage, value);
85cdaf52
JS
1330
1331 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
1332 ret = hdrv->event(hid, field, usage, value);
1333 if (ret != 0) {
1334 if (ret < 0)
8c3d52fc 1335 hid_err(hid, "%s's event failed with %d\n",
85cdaf52
JS
1336 hdrv->name, ret);
1337 return;
1338 }
1339 }
1340
dde5845a
JK
1341 if (hid->claimed & HID_CLAIMED_INPUT)
1342 hidinput_hid_event(hid, field, usage, value);
aa938f79
JK
1343 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
1344 hid->hiddev_hid_event(hid, field, usage, value);
dde5845a
JK
1345}
1346
1347/*
1348 * Analyse a received field, and fetch the data from it. The field
1349 * content is stored for next report processing (we do differential
1350 * reporting to the layer).
1351 */
1352
abdff0f7
AB
1353static void hid_input_field(struct hid_device *hid, struct hid_field *field,
1354 __u8 *data, int interrupt)
dde5845a
JK
1355{
1356 unsigned n;
1357 unsigned count = field->report_count;
1358 unsigned offset = field->report_offset;
1359 unsigned size = field->report_size;
1360 __s32 min = field->logical_minimum;
1361 __s32 max = field->logical_maximum;
1362 __s32 *value;
1363
a3789a17
JP
1364 value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
1365 if (!value)
dde5845a
JK
1366 return;
1367
1368 for (n = 0; n < count; n++) {
1369
4291ee30 1370 value[n] = min < 0 ?
04fba786
GB
1371 snto32(hid_field_extract(hid, data, offset + n * size,
1372 size), size) :
1373 hid_field_extract(hid, data, offset + n * size, size);
dde5845a 1374
4291ee30
JP
1375 /* Ignore report if ErrorRollOver */
1376 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
1377 value[n] >= min && value[n] <= max &&
50220dea 1378 value[n] - min < field->maxusage &&
4291ee30
JP
1379 field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
1380 goto exit;
dde5845a
JK
1381 }
1382
1383 for (n = 0; n < count; n++) {
1384
1385 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
1386 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
1387 continue;
1388 }
1389
1390 if (field->value[n] >= min && field->value[n] <= max
50220dea 1391 && field->value[n] - min < field->maxusage
dde5845a
JK
1392 && field->usage[field->value[n] - min].hid
1393 && search(value, field->value[n], count))
1394 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
1395
1396 if (value[n] >= min && value[n] <= max
50220dea 1397 && value[n] - min < field->maxusage
dde5845a
JK
1398 && field->usage[value[n] - min].hid
1399 && search(field->value, value[n], count))
1400 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
1401 }
1402
1403 memcpy(field->value, value, count * sizeof(__s32));
1404exit:
1405 kfree(value);
1406}
dde5845a
JK
1407
1408/*
1409 * Output the field into the report.
1410 */
1411
4291ee30
JP
1412static void hid_output_field(const struct hid_device *hid,
1413 struct hid_field *field, __u8 *data)
dde5845a
JK
1414{
1415 unsigned count = field->report_count;
1416 unsigned offset = field->report_offset;
1417 unsigned size = field->report_size;
1418 unsigned n;
1419
1420 for (n = 0; n < count; n++) {
1421 if (field->logical_minimum < 0) /* signed values */
4291ee30
JP
1422 implement(hid, data, offset + n * size, size,
1423 s32ton(field->value[n], size));
dde5845a 1424 else /* unsigned values */
4291ee30
JP
1425 implement(hid, data, offset + n * size, size,
1426 field->value[n]);
dde5845a
JK
1427 }
1428}
1429
1430/*
27ce4050
JK
1431 * Create a report. 'data' has to be allocated using
1432 * hid_alloc_report_buf() so that it has proper size.
dde5845a
JK
1433 */
1434
229695e5 1435void hid_output_report(struct hid_report *report, __u8 *data)
dde5845a
JK
1436{
1437 unsigned n;
1438
1439 if (report->id > 0)
1440 *data++ = report->id;
1441
75c28df8 1442 memset(data, 0, ((report->size - 1) >> 3) + 1);
dde5845a 1443 for (n = 0; n < report->maxfield; n++)
4291ee30 1444 hid_output_field(report->device, report->field[n], data);
dde5845a 1445}
229695e5 1446EXPORT_SYMBOL_GPL(hid_output_report);
dde5845a 1447
27ce4050
JK
1448/*
1449 * Allocator for buffer that is going to be passed to hid_output_report()
1450 */
1451u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
1452{
1453 /*
1454 * 7 extra bytes are necessary to achieve proper functionality
1455 * of implement() working on 8 byte chunks
1456 */
1457
8a7bae2f 1458 u32 len = hid_report_len(report) + 7;
27ce4050
JK
1459
1460 return kmalloc(len, flags);
1461}
1462EXPORT_SYMBOL_GPL(hid_alloc_report_buf);
1463
dde5845a
JK
1464/*
1465 * Set a field value. The report this field belongs to has to be
1466 * created and transferred to the device, to set this value in the
1467 * device.
1468 */
1469
1470int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1471{
be67b68d
KC
1472 unsigned size;
1473
1474 if (!field)
1475 return -1;
1476
1477 size = field->report_size;
dde5845a 1478
cd667ce2 1479 hid_dump_input(field->report->device, field->usage + offset, value);
dde5845a
JK
1480
1481 if (offset >= field->report_count) {
8c3d52fc
JK
1482 hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
1483 offset, field->report_count);
dde5845a
JK
1484 return -1;
1485 }
1486 if (field->logical_minimum < 0) {
1487 if (value != snto32(s32ton(value, size), size)) {
8c3d52fc 1488 hid_err(field->report->device, "value %d is out of range\n", value);
dde5845a
JK
1489 return -1;
1490 }
1491 }
1492 field->value[offset] = value;
1493 return 0;
1494}
229695e5 1495EXPORT_SYMBOL_GPL(hid_set_field);
dde5845a 1496
85cdaf52
JS
1497static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1498 const u8 *data)
aa8de2f0 1499{
aa8de2f0 1500 struct hid_report *report;
85cdaf52 1501 unsigned int n = 0; /* Normally report number is 0 */
aa8de2f0 1502
85cdaf52
JS
1503 /* Device uses numbered reports, data[0] is report number */
1504 if (report_enum->numbered)
1505 n = *data;
aa8de2f0 1506
85cdaf52
JS
1507 report = report_enum->report_id_hash[n];
1508 if (report == NULL)
1509 dbg_hid("undefined report_id %u received\n", n);
aa8de2f0 1510
85cdaf52
JS
1511 return report;
1512}
aa8de2f0 1513
4fa5a7f7
BT
1514/*
1515 * Implement a generic .request() callback, using .raw_request()
1516 * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
1517 */
1518void __hid_request(struct hid_device *hid, struct hid_report *report,
1519 int reqtype)
1520{
1521 char *buf;
1522 int ret;
8a7bae2f 1523 u32 len;
4fa5a7f7 1524
4fa5a7f7
BT
1525 buf = hid_alloc_report_buf(report, GFP_KERNEL);
1526 if (!buf)
1527 return;
1528
1529 len = hid_report_len(report);
1530
1531 if (reqtype == HID_REQ_SET_REPORT)
1532 hid_output_report(report, buf);
1533
1534 ret = hid->ll_driver->raw_request(hid, report->id, buf, len,
1535 report->type, reqtype);
1536 if (ret < 0) {
1537 dbg_hid("unable to complete request: %d\n", ret);
1538 goto out;
1539 }
1540
1541 if (reqtype == HID_REQ_GET_REPORT)
1542 hid_input_report(hid, report->type, buf, ret, 0);
1543
1544out:
1545 kfree(buf);
1546}
1547EXPORT_SYMBOL_GPL(__hid_request);
1548
8a7bae2f 1549int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
85cdaf52
JS
1550 int interrupt)
1551{
1552 struct hid_report_enum *report_enum = hid->report_enum + type;
1553 struct hid_report *report;
6d85d037 1554 struct hid_driver *hdrv;
85cdaf52 1555 unsigned int a;
8a7bae2f 1556 u32 rsize, csize = size;
85cdaf52 1557 u8 *cdata = data;
b6787242 1558 int ret = 0;
aa8de2f0 1559
85cdaf52
JS
1560 report = hid_get_report(report_enum, data);
1561 if (!report)
b6787242 1562 goto out;
aa8de2f0 1563
85cdaf52
JS
1564 if (report_enum->numbered) {
1565 cdata++;
1566 csize--;
aa8de2f0
JK
1567 }
1568
1569 rsize = ((report->size - 1) >> 3) + 1;
1570
966922f2
AV
1571 if (rsize > HID_MAX_BUFFER_SIZE)
1572 rsize = HID_MAX_BUFFER_SIZE;
1573
85cdaf52
JS
1574 if (csize < rsize) {
1575 dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1576 csize, rsize);
1577 memset(cdata + csize, 0, rsize - csize);
aa8de2f0
JK
1578 }
1579
1580 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1581 hid->hiddev_report_event(hid, report);
b6787242
JK
1582 if (hid->claimed & HID_CLAIMED_HIDRAW) {
1583 ret = hidraw_report_event(hid, data, size);
1584 if (ret)
1585 goto out;
1586 }
aa8de2f0 1587
cc6b54aa 1588 if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) {
b94e3c94
MC
1589 for (a = 0; a < report->maxfield; a++)
1590 hid_input_field(hid, report->field[a], cdata, interrupt);
6d85d037
BT
1591 hdrv = hid->driver;
1592 if (hdrv && hdrv->report)
1593 hdrv->report(hid, report);
b94e3c94 1594 }
aa8de2f0
JK
1595
1596 if (hid->claimed & HID_CLAIMED_INPUT)
1597 hidinput_report_event(hid, report);
b6787242
JK
1598out:
1599 return ret;
85cdaf52
JS
1600}
1601EXPORT_SYMBOL_GPL(hid_report_raw_event);
1602
1603/**
1604 * hid_input_report - report data from lower layer (usb, bt...)
1605 *
1606 * @hid: hid device
1607 * @type: HID report type (HID_*_REPORT)
1608 * @data: report contents
1609 * @size: size of data parameter
ff9b00a2 1610 * @interrupt: distinguish between interrupt and control transfers
85cdaf52
JS
1611 *
1612 * This is data entry for lower layers.
1613 */
8a7bae2f 1614int hid_input_report(struct hid_device *hid, int type, u8 *data, u32 size, int interrupt)
85cdaf52 1615{
76c317d6
JL
1616 struct hid_report_enum *report_enum;
1617 struct hid_driver *hdrv;
85cdaf52 1618 struct hid_report *report;
45dc1ac7 1619 int ret = 0;
85cdaf52 1620
4ea54542 1621 if (!hid)
85cdaf52 1622 return -ENODEV;
4ea54542 1623
c849a614 1624 if (down_trylock(&hid->driver_input_lock))
4ea54542
DH
1625 return -EBUSY;
1626
1627 if (!hid->driver) {
1628 ret = -ENODEV;
1629 goto unlock;
1630 }
76c317d6
JL
1631 report_enum = hid->report_enum + type;
1632 hdrv = hid->driver;
85cdaf52
JS
1633
1634 if (!size) {
1635 dbg_hid("empty report\n");
4ea54542
DH
1636 ret = -1;
1637 goto unlock;
85cdaf52
JS
1638 }
1639
b94e3c94 1640 /* Avoid unnecessary overhead if debugfs is disabled */
a5f04b9d
BT
1641 if (!list_empty(&hid->debug_list))
1642 hid_dump_report(hid, type, data, size);
85cdaf52 1643
1caea61e
JK
1644 report = hid_get_report(report_enum, data);
1645
4ea54542
DH
1646 if (!report) {
1647 ret = -1;
1648 goto unlock;
1649 }
85cdaf52
JS
1650
1651 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1652 ret = hdrv->raw_event(hid, report, data, size);
556483e2 1653 if (ret < 0)
4ea54542 1654 goto unlock;
85cdaf52
JS
1655 }
1656
b6787242 1657 ret = hid_report_raw_event(hid, type, data, size, interrupt);
aa8de2f0 1658
4ea54542 1659unlock:
c849a614 1660 up(&hid->driver_input_lock);
45dc1ac7 1661 return ret;
aa8de2f0
JK
1662}
1663EXPORT_SYMBOL_GPL(hid_input_report);
1664
0f37cd03
JK
1665static bool hid_match_one_id(struct hid_device *hdev,
1666 const struct hid_device_id *id)
1667{
7431fb76 1668 return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
4d53b801 1669 (id->group == HID_GROUP_ANY || id->group == hdev->group) &&
0f37cd03
JK
1670 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1671 (id->product == HID_ANY_ID || id->product == hdev->product);
1672}
1673
bbc21cfd 1674const struct hid_device_id *hid_match_id(struct hid_device *hdev,
0f37cd03
JK
1675 const struct hid_device_id *id)
1676{
1677 for (; id->bus; id++)
1678 if (hid_match_one_id(hdev, id))
1679 return id;
1680
1681 return NULL;
1682}
1683
1684static const struct hid_device_id hid_hiddev_list[] = {
c0bd6a42
RH
1685 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1686 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
0f37cd03
JK
1687 { }
1688};
1689
1690static bool hid_hiddev(struct hid_device *hdev)
1691{
1692 return !!hid_match_id(hdev, hid_hiddev_list);
1693}
1694
6d3bfb74
AO
1695
1696static ssize_t
1697read_report_descriptor(struct file *filp, struct kobject *kobj,
1698 struct bin_attribute *attr,
1699 char *buf, loff_t off, size_t count)
1700{
2cf83833 1701 struct device *dev = kobj_to_dev(kobj);
ee79a8f8 1702 struct hid_device *hdev = to_hid_device(dev);
6d3bfb74
AO
1703
1704 if (off >= hdev->rsize)
1705 return 0;
1706
1707 if (off + count > hdev->rsize)
1708 count = hdev->rsize - off;
1709
1710 memcpy(buf, hdev->rdesc + off, count);
1711
1712 return count;
1713}
1714
a877417e
OG
1715static ssize_t
1716show_country(struct device *dev, struct device_attribute *attr,
1717 char *buf)
1718{
ee79a8f8 1719 struct hid_device *hdev = to_hid_device(dev);
a877417e
OG
1720
1721 return sprintf(buf, "%02x\n", hdev->country & 0xff);
1722}
1723
6d3bfb74
AO
1724static struct bin_attribute dev_bin_attr_report_desc = {
1725 .attr = { .name = "report_descriptor", .mode = 0444 },
1726 .read = read_report_descriptor,
1727 .size = HID_MAX_DESCRIPTOR_SIZE,
1728};
1729
ad8378ed 1730static const struct device_attribute dev_attr_country = {
a877417e
OG
1731 .attr = { .name = "country", .mode = 0444 },
1732 .show = show_country,
1733};
1734
93c10132
JS
1735int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1736{
1737 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1738 "Joystick", "Gamepad", "Keyboard", "Keypad",
1739 "Multi-Axis Controller"
1740 };
1741 const char *type, *bus;
79b568b9 1742 char buf[64] = "";
93c10132
JS
1743 unsigned int i;
1744 int len;
6d3bfb74 1745 int ret;
93c10132 1746
b5e5a37e
BN
1747 if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1748 connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
3a343ee4
DM
1749 if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
1750 connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
93c10132
JS
1751 if (hdev->bus != BUS_USB)
1752 connect_mask &= ~HID_CONNECT_HIDDEV;
0f37cd03
JK
1753 if (hid_hiddev(hdev))
1754 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
93c10132
JS
1755
1756 if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1757 connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1758 hdev->claimed |= HID_CLAIMED_INPUT;
b77c3920 1759
93c10132
JS
1760 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1761 !hdev->hiddev_connect(hdev,
1762 connect_mask & HID_CONNECT_HIDDEV_FORCE))
1763 hdev->claimed |= HID_CLAIMED_HIDDEV;
1764 if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1765 hdev->claimed |= HID_CLAIMED_HIDRAW;
1766
7704ac93
BT
1767 if (connect_mask & HID_CONNECT_DRIVER)
1768 hdev->claimed |= HID_CLAIMED_DRIVER;
1769
4bc19f62
DH
1770 /* Drivers with the ->raw_event callback set are not required to connect
1771 * to any other listener. */
1772 if (!hdev->claimed && !hdev->driver->raw_event) {
1773 hid_err(hdev, "device has no listeners, quitting\n");
93c10132
JS
1774 return -ENODEV;
1775 }
1776
1777 if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1778 (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1779 hdev->ff_init(hdev);
1780
1781 len = 0;
1782 if (hdev->claimed & HID_CLAIMED_INPUT)
1783 len += sprintf(buf + len, "input");
1784 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1785 len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
733aca90 1786 ((struct hiddev *)hdev->hiddev)->minor);
93c10132
JS
1787 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1788 len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1789 ((struct hidraw *)hdev->hidraw)->minor);
1790
1791 type = "Device";
1792 for (i = 0; i < hdev->maxcollection; i++) {
1793 struct hid_collection *col = &hdev->collection[i];
1794 if (col->type == HID_COLLECTION_APPLICATION &&
1795 (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1796 (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1797 type = types[col->usage & 0xffff];
1798 break;
1799 }
1800 }
1801
1802 switch (hdev->bus) {
1803 case BUS_USB:
1804 bus = "USB";
1805 break;
1806 case BUS_BLUETOOTH:
1807 bus = "BLUETOOTH";
1808 break;
06780727
DM
1809 case BUS_I2C:
1810 bus = "I2C";
1811 break;
93c10132
JS
1812 default:
1813 bus = "<UNKNOWN>";
1814 }
1815
a877417e
OG
1816 ret = device_create_file(&hdev->dev, &dev_attr_country);
1817 if (ret)
1818 hid_warn(hdev,
1819 "can't create sysfs country code attribute err: %d\n", ret);
1820
4291ee30
JP
1821 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1822 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1823 type, hdev->name, hdev->phys);
93c10132
JS
1824
1825 return 0;
1826}
1827EXPORT_SYMBOL_GPL(hid_connect);
1828
c4c259bc
JK
1829void hid_disconnect(struct hid_device *hdev)
1830{
a877417e 1831 device_remove_file(&hdev->dev, &dev_attr_country);
c4c259bc
JK
1832 if (hdev->claimed & HID_CLAIMED_INPUT)
1833 hidinput_disconnect(hdev);
1834 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1835 hdev->hiddev_disconnect(hdev);
1836 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1837 hidraw_disconnect(hdev);
9c5c6ed7 1838 hdev->claimed = 0;
c4c259bc
JK
1839}
1840EXPORT_SYMBOL_GPL(hid_disconnect);
1841
aaac082d
DT
1842/**
1843 * hid_hw_start - start underlying HW
1844 * @hdev: hid device
1845 * @connect_mask: which outputs to connect, see HID_CONNECT_*
1846 *
1847 * Call this in probe function *after* hid_parse. This will setup HW
1848 * buffers and start the device (if not defeirred to device open).
1849 * hid_hw_stop must be called if this was successful.
1850 */
1851int hid_hw_start(struct hid_device *hdev, unsigned int connect_mask)
1852{
1853 int error;
1854
1855 error = hdev->ll_driver->start(hdev);
1856 if (error)
1857 return error;
1858
1859 if (connect_mask) {
1860 error = hid_connect(hdev, connect_mask);
1861 if (error) {
1862 hdev->ll_driver->stop(hdev);
1863 return error;
1864 }
1865 }
1866
1867 return 0;
1868}
1869EXPORT_SYMBOL_GPL(hid_hw_start);
1870
1871/**
1872 * hid_hw_stop - stop underlying HW
1873 * @hdev: hid device
1874 *
1875 * This is usually called from remove function or from probe when something
1876 * failed and hid_hw_start was called already.
1877 */
1878void hid_hw_stop(struct hid_device *hdev)
1879{
1880 hid_disconnect(hdev);
1881 hdev->ll_driver->stop(hdev);
1882}
1883EXPORT_SYMBOL_GPL(hid_hw_stop);
1884
1885/**
1886 * hid_hw_open - signal underlying HW to start delivering events
1887 * @hdev: hid device
1888 *
1889 * Tell underlying HW to start delivering events from the device.
1890 * This function should be called sometime after successful call
1891 * to hid_hiw_start().
1892 */
1893int hid_hw_open(struct hid_device *hdev)
1894{
1895 int ret;
1896
1897 ret = mutex_lock_killable(&hdev->ll_open_lock);
1898 if (ret)
1899 return ret;
1900
1901 if (!hdev->ll_open_count++) {
1902 ret = hdev->ll_driver->open(hdev);
1903 if (ret)
1904 hdev->ll_open_count--;
1905 }
1906
1907 mutex_unlock(&hdev->ll_open_lock);
1908 return ret;
1909}
1910EXPORT_SYMBOL_GPL(hid_hw_open);
1911
1912/**
1913 * hid_hw_close - signal underlaying HW to stop delivering events
1914 *
1915 * @hdev: hid device
1916 *
1917 * This function indicates that we are not interested in the events
1918 * from this device anymore. Delivery of events may or may not stop,
1919 * depending on the number of users still outstanding.
1920 */
1921void hid_hw_close(struct hid_device *hdev)
1922{
1923 mutex_lock(&hdev->ll_open_lock);
1924 if (!--hdev->ll_open_count)
1925 hdev->ll_driver->close(hdev);
1926 mutex_unlock(&hdev->ll_open_lock);
1927}
1928EXPORT_SYMBOL_GPL(hid_hw_close);
1929
00315e4f
JK
1930/*
1931 * A list of devices for which there is a specialized driver on HID bus.
1932 *
1933 * Please note that for multitouch devices (driven by hid-multitouch driver),
1934 * there is a proper autodetection and autoloading in place (based on presence
1935 * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
1936 * as we are doing the right thing in hid_scan_usage().
83499b52
AH
1937 *
1938 * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
1939 * physical is found inside a usage page of type sensor, hid-sensor-hub will be
1940 * used as a driver. See hid_scan_report().
00315e4f 1941 */
ce06b9d6 1942static const struct hid_device_id hid_have_special_driver[] = {
0ca4cd7b 1943#if IS_ENABLED(CONFIG_HID_A4TECH)
14a21cd4
JS
1944 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1945 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
b7e1b203 1946 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
0ca4cd7b
JK
1947#endif
1948#if IS_ENABLED(CONFIG_HID_ACCUTOUCH)
1949 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_ACCUTOUCH_2216) },
1950#endif
1951#if IS_ENABLED(CONFIG_HID_ACRUX)
c0dbcc33 1952 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
e17f5d76 1953 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
0ca4cd7b
JK
1954#endif
1955#if IS_ENABLED(CONFIG_HID_ALPS)
819d64e5 1956 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
73196ebe 1957 { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
287b8e11 1958 { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
73196ebe 1959 { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
0ca4cd7b
JK
1960#endif
1961#if IS_ENABLED(CONFIG_HID_APPLE)
8c19a515
JS
1962 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1963 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1964 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1965 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1966 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1967 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1968 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1969 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1970 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1971 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1972 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1973 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
fef3f571
RF
1974 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1975 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1976 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
8c19a515
JS
1977 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1978 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1979 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1980 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1981 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1982 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
ee8a1a0a
JS
1983 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1984 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1985 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
8c19a515
JS
1986 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1987 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1988 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1989 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1990 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1991 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
a96d6ef3
HR
1992 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1993 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1994 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
99b9f758
EH
1995 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1996 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1997 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1998 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1999 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
2000 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
47340bd9
AB
2001 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
2002 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
2003 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
213f9da8
GE
2004 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
2005 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
2006 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
4a4c8799
DB
2007 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
2008 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
2009 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
f6f554f0
JK
2010 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
2011 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
2012 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
b3aec7b6
JK
2013 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
2014 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
2015 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
b2e6ad7d
RB
2016 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
2017 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
2018 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
8d80da90
DH
2019 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
2020 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
2021 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
9d9a04ee
DT
2022 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
2023 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
2024 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
a4a2c545
HR
2025 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI) },
2026 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO) },
2027 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS) },
23aeb61e
CSW
2028 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
2029 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
2030 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
f9af7b9e 2031 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
ad734bc1 2032 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
bd4a7ce1 2033 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
b5d94275 2034 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
64297ee4
NC
2035 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
2036 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI) },
2037 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI) },
8c19a515
JS
2038 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2039 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
0ca4cd7b
JK
2040#endif
2041#if IS_ENABLED(CONFIG_HID_APPLEIR)
2042 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
2043 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
2044 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
2045 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
2046 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
2047#endif
2048#if IS_ENABLED(CONFIG_HID_ASUS)
a93913e1
MH
2049 { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD) },
2050 { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD) },
1caccc25
CC
2051 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1) },
2052 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2) },
832e1eee 2053 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD3) },
76dd1fbe 2054 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T100_KEYBOARD) },
4f94ff4e
JK
2055 { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_ASUS_MD_5112) },
2056 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_ASUS_MD_5110) },
5703e52c 2057 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_T100CHI_KEYBOARD) },
0ca4cd7b
JK
2058#endif
2059#if IS_ENABLED(CONFIG_HID_AUREAL)
212da74d 2060 { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
0ca4cd7b
JK
2061#endif
2062#if IS_ENABLED(CONFIG_HID_BELKIN)
b5635b12 2063 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
0ca4cd7b
JK
2064 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
2065#endif
2066#if IS_ENABLED(CONFIG_HID_BETOP_FF)
fc38a8a6
HB
2067 { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185BFM, 0x2208) },
2068 { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185PC, 0x5506) },
2069 { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2PC, 0x1850) },
2070 { HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2BFM, 0x5500) },
0ca4cd7b
JK
2071#endif
2072#if IS_ENABLED(CONFIG_HID_CHERRY)
3b239cd7 2073 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1ce31b25 2074 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
0ca4cd7b
JK
2075#endif
2076#if IS_ENABLED(CONFIG_HID_CHICONY)
fcfacfd3 2077 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
3596bb92 2078 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
5be91803 2079 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_ASUS_AK1D) },
9a1d78a3 2080 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) },
0ca4cd7b
JK
2081#endif
2082#if IS_ENABLED(CONFIG_HID_CMEDIA)
2083 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
2084#endif
2085#if IS_ENABLED(CONFIG_HID_CORSAIR)
6f78193e 2086 { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K90) },
01adc47e 2087 { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_SCIMITAR_PRO_RGB) },
0ca4cd7b
JK
2088#endif
2089#if IS_ENABLED(CONFIG_HID_CP2112)
e932d817 2090 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
0ca4cd7b
JK
2091#endif
2092#if IS_ENABLED(CONFIG_HID_CYPRESS)
0f221320
JS
2093 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
2094 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
e8d0eab4 2095 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
76c9d8fe 2096 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
0f221320 2097 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
0ca4cd7b
JK
2098#endif
2099#if IS_ENABLED(CONFIG_HID_DRAGONRISE)
3f866fbd 2100 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
e05eefb9 2101 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
f8690450 2102#endif
0ca4cd7b 2103#if IS_ENABLED(CONFIG_HID_ELECOM)
64b386ea 2104 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
0bb7a37f
DEP
2105 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRED) },
2106 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRELESS) },
a0933a45
AM
2107 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_HUGE_WIRED) },
2108 { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_HUGE_WIRELESS) },
0ca4cd7b
JK
2109#endif
2110#if IS_ENABLED(CONFIG_HID_ELO)
d23efc19
JS
2111 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
2112 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
0ca4cd7b
JK
2113#endif
2114#if IS_ENABLED(CONFIG_HID_EMS_FF)
04561c5a 2115 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
0ca4cd7b
JK
2116#endif
2117#if IS_ENABLED(CONFIG_HID_EZKEY)
1f243e30 2118 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
0ca4cd7b
JK
2119#endif
2120#if IS_ENABLED(CONFIG_HID_GEMBIRD)
931830aa 2121 { HID_USB_DEVICE(USB_VENDOR_ID_GEMBIRD, USB_DEVICE_ID_GEMBIRD_JPD_DUALFORCE2) },
0ca4cd7b
JK
2122#endif
2123#if IS_ENABLED(CONFIG_HID_GFRM)
2124 { HID_BLUETOOTH_DEVICE(0x58, 0x2000) },
2125 { HID_BLUETOOTH_DEVICE(0x471, 0x2210) },
2126#endif
2127#if IS_ENABLED(CONFIG_HID_GREENASIA)
42859e0b 2128 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
0ca4cd7b
JK
2129#endif
2130#if IS_ENABLED(CONFIG_HID_GT683R)
2131 { HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
2132#endif
2133#if IS_ENABLED(CONFIG_HID_GYRATION)
949f8fef 2134 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
1e093206 2135 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
c2fd1a4e 2136 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
0ca4cd7b
JK
2137#endif
2138#if IS_ENABLED(CONFIG_HID_HOLTEK)
d946e65e 2139 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
ff9bf5a2 2140 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
40d3597f
JK
2141 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
2142 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
274be3eb 2143 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
f1a4914b 2144 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
7da7cbbb 2145 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
5df4eb05 2146 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
0ca4cd7b
JK
2147#endif
2148#if IS_ENABLED(CONFIG_HID_ICADE)
4ddfe028 2149 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
0ca4cd7b 2150#endif
604250dd
JK
2151#if IS_ENABLED(CONFIG_HID_ITE)
2152 { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) },
2153#endif
0ca4cd7b 2154#if IS_ENABLED(CONFIG_HID_KENSINGTON)
fdf93aa3 2155 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
0ca4cd7b
JK
2156#endif
2157#if IS_ENABLED(CONFIG_HID_KEYTOUCH)
177900e8 2158 { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
0ca4cd7b
JK
2159#endif
2160#if IS_ENABLED(CONFIG_HID_KYE)
3685c18e 2161 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
4a2c94c9 2162 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_MANTICORE) },
0adb9c2c 2163 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
79422741 2164 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
22ca20b2
NK
2165 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
2166 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
102750b8 2167 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_V2) },
22ca20b2 2168 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
feb6faf1 2169 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_PENSKETCH_M912) },
0ca4cd7b
JK
2170#endif
2171#if IS_ENABLED(CONFIG_HID_LCPOWER)
75b07022 2172 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
0ca4cd7b
JK
2173#endif
2174#if IS_ENABLED(CONFIG_HID_LED)
2175 { HID_USB_DEVICE(USB_VENDOR_ID_DELCOM, USB_DEVICE_ID_DELCOM_VISUAL_IND) },
2176 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_WN) },
2177 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, USB_DEVICE_ID_DREAM_CHEEKY_FA) },
2178 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_LUXAFOR) },
2179 { HID_USB_DEVICE(USB_VENDOR_ID_RISO_KAGAKU, USB_DEVICE_ID_RI_KA_WEBMAIL) },
2180 { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
2181#endif
94723bfa 2182#if IS_ENABLED(CONFIG_HID_LENOVO)
aad932e7 2183 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
f3d4ff0e
JL
2184 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) },
2185 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) },
181a8b91 2186 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) },
aad932e7 2187#endif
0ca4cd7b 2188#if IS_ENABLED(CONFIG_HID_LOGITECH)
5f22a799
JS
2189 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
2190 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
2191 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
2192 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
2193 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
2194 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
2195 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
5f22a799
JS
2196 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
2197 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
5f22a799 2198 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
5d74325a 2199 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DUAL_ACTION) },
5f22a799 2200 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
2c6118e4 2201 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
606bd0a8
JS
2202 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
2203 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
29fae1c8 2204 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G29_WHEEL) },
606bd0a8 2205 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
fd30ea8c 2206 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
606bd0a8 2207 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
74f292ca 2208 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
606bd0a8
JS
2209 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
2210 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
bd04363d 2211 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL) },
5623a24a 2212 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
e00ddc9b 2213 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
243b706d 2214 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
fdc6807f 2215 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
32c88cbc 2216 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
606bd0a8 2217 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
24985cf6
JK
2218 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
2219 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
0ca4cd7b
JK
2220#endif
2221#if IS_ENABLED(CONFIG_HID_LOGITECH_HIDPP)
2222 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_T651) },
2223 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL) },
2224#endif
2225#if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
2226 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
2227 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
2228#endif
2229#if IS_ENABLED(CONFIG_HID_MAGICMOUSE)
2230 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
2231 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
2232#endif
2233#if IS_ENABLED(CONFIG_HID_MAYFLASH)
2234 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3) },
2235 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR) },
2236 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE1) },
2237 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE2) },
2238#endif
2239#if IS_ENABLED(CONFIG_HID_MICROSOFT)
b580169a 2240 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
f9a82c20 2241 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD) },
78a849a6
JS
2242 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
2243 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
89759e20 2244 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
ef567cf9 2245 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE7K) },
78a849a6
JS
2246 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
2247 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
f3b83d71 2248 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
78a849a6 2249 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
3faed1af 2250 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
c847a89a
ALH
2251 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K) },
2252 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600) },
2253 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1) },
18eec2cd 2254 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER) },
0ca4cd7b
JK
2255 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
2256#endif
2257#if IS_ENABLED(CONFIG_HID_MONTEREY)
3b8006e5 2258 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
0ca4cd7b
JK
2259#endif
2260#if IS_ENABLED(CONFIG_HID_MULTITOUCH)
2261 { HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MELFAS_MT) },
2262#endif
2263#if IS_ENABLED(CONFIG_HID_WIIMOTE)
2264 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
2265 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
2266#endif
2267#if IS_ENABLED(CONFIG_HID_NTI)
07e88a35 2268 { HID_USB_DEVICE(USB_VENDOR_ID_NTI, USB_DEVICE_ID_USB_SUN) },
0ca4cd7b
JK
2269#endif
2270#if IS_ENABLED(CONFIG_HID_NTRIG)
94011f93 2271 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
6e32819e 2272 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
2273 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
2274 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
2275 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
2276 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
2277 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
2278 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
2279 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
2280 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
2281 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
2282 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
2283 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
2284 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
2285 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
2286 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
2287 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
2288 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
2289 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
0ca4cd7b
JK
2290#endif
2291#if IS_ENABLED(CONFIG_HID_ORTEK)
270fdc07 2292 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
cd9ec30d 2293 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
c228352d 2294 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_IHOME_IMAC_A210S) },
0ca4cd7b
JK
2295 { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
2296#endif
2297#if IS_ENABLED(CONFIG_HID_PANTHERLORD)
2298 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
2299 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
2300 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
2301 { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
2302#endif
2303#if IS_ENABLED(CONFIG_HID_PENMOUNT)
ffe51d0d 2304 { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_6000) },
0ca4cd7b
JK
2305#endif
2306#if IS_ENABLED(CONFIG_HID_PETALYNX)
1e762532 2307 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
0ca4cd7b
JK
2308#endif
2309#if IS_ENABLED(CONFIG_HID_PICOLCD)
2310 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
2311 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
2312#endif
2313#if IS_ENABLED(CONFIG_HID_PLANTRONICS)
1a3f83f6 2314 { HID_USB_DEVICE(USB_VENDOR_ID_PLANTRONICS, HID_ANY_ID) },
0ca4cd7b
JK
2315#endif
2316#if IS_ENABLED(CONFIG_HID_PRIMAX)
f6a04605 2317 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
0ca4cd7b
JK
2318#endif
2319#if IS_ENABLED(CONFIG_HID_PRODIKEYS)
2320 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
2321#endif
13b2e1ba
BN
2322#if IS_ENABLED(CONFIG_HID_RETRODE)
2323 { HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY, USB_DEVICE_ID_RETRODE2) },
2324#endif
0ca4cd7b
JK
2325#if IS_ENABLED(CONFIG_HID_RMI)
2326 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
2327 { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) },
2328#endif
ca9bbdcc 2329#if IS_ENABLED(CONFIG_HID_ROCCAT)
e68cc603 2330 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
d41c2a70 2331 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
e078809d
SA
2332 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKUFX) },
2333 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
47dbdbff 2334 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
8936aa31 2335 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
a4be0ed3 2336 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
e078809d 2337 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEXTD) },
0e70f97f 2338 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
4424f616 2339 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
cb7cf3da 2340 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
3fce2246 2341 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
6f3a1936
SA
2342 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK) },
2343 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW) },
2344 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO) },
6a2a6390 2345 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
ca9bbdcc 2346#endif
37c492c8 2347#if IS_ENABLED(CONFIG_HID_SAITEK)
1e93674a 2348 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
afe98939 2349 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7_OLD) },
37c492c8 2350 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7) },
7d3ea5c1 2351 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT9) },
37c492c8 2352 { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7) },
8ffd341c 2353 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT5) },
7bb9d643 2354 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9) },
37c492c8 2355#endif
0ca4cd7b 2356#if IS_ENABLED(CONFIG_HID_SAMSUNG)
980a3da6 2357 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
b355850b 2358 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
0ca4cd7b
JK
2359#endif
2360#if IS_ENABLED(CONFIG_HID_SMARTJOYPLUS)
2361 { HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII) },
2362 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
2363 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
2364 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
2365 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
2366 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
2367 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
2368#endif
2369#if IS_ENABLED(CONFIG_HID_SONY)
2370 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
68a49e51 2371 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE) },
f04d5140
CL
2372 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
2373 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
7c886d09 2374 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) },
a4afa854 2375 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) },
35dca5b4 2376 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
6eabaaa0 2377 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
5844c1cd 2378 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
bd28ce00 2379 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
f9ce7c28 2380 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
0bd88dd3
FP
2381 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
2382 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
cf1015d6
RC
2383 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) },
2384 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2) },
de66a1a0 2385 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) },
cc6e0bbb 2386 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
c1e0ac19 2387 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
74500cc8 2388 { HID_USB_DEVICE(USB_VENDOR_ID_SINO_LITE, USB_DEVICE_ID_SINO_LITE_CONTROLLER) },
0ca4cd7b
JK
2389#endif
2390#if IS_ENABLED(CONFIG_HID_SPEEDLINK)
2391 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
2392#endif
2393#if IS_ENABLED(CONFIG_HID_STEELSERIES)
75dbb953 2394 { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
0ca4cd7b
JK
2395#endif
2396#if IS_ENABLED(CONFIG_HID_SUNPLUS)
90231e7e 2397 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
0ca4cd7b
JK
2398#endif
2399#if IS_ENABLED(CONFIG_HID_THRUSTMASTER)
daedb3d6
AH
2400 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
2401 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
7a84b133
RAG
2402 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
2403 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1477edb4 2404 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb605) },
daedb3d6 2405 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
3ee8f0a2 2406 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
daedb3d6 2407 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
d65c3768 2408 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
0ca4cd7b
JK
2409#endif
2410#if IS_ENABLED(CONFIG_HID_TIVO)
740363fb 2411 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
44ea35c1 2412 { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
9b028649 2413 { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_PRO) },
0ca4cd7b
JK
2414#endif
2415#if IS_ENABLED(CONFIG_HID_TOPSEED)
2416 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
2417 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
2418 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
f14f526d 2419 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
54001081 2420 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
0ca4cd7b
JK
2421#endif
2422#if IS_ENABLED(CONFIG_HID_TWINHAN)
711a680e 2423 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
0ca4cd7b
JK
2424#endif
2425#if IS_ENABLED(CONFIG_HID_UCLOGIC)
2426 { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
2427 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_HUION_TABLET) },
41fa9230 2428 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
f8a489cc
NK
2429 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
2430 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
2431 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
6be914f1 2432 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
d1257081 2433 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
eb4e426a 2434 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
4b7e7e5e
NK
2435 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_YIYNOVA_TABLET) },
2436 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UGEE_TABLET_81) },
2437 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UGEE_TABLET_45) },
2438 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_DRAWIMAGE_G3) },
fe1a83b4 2439 { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_TABLET_EX07S) },
0ca4cd7b
JK
2440 { HID_USB_DEVICE(USB_VENDOR_ID_UGTIZER, USB_DEVICE_ID_UGTIZER_TABLET_GP0610) },
2441#endif
2442#if IS_ENABLED(CONFIG_HID_UDRAW_PS3)
2443 { HID_USB_DEVICE(USB_VENDOR_ID_THQ, USB_DEVICE_ID_THQ_PS3_UDRAW) },
2444#endif
2445#if IS_ENABLED(CONFIG_HID_WALTOP)
72a46344 2446 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
00e7f964 2447 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
4fdc18d1 2448 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
a786e83c 2449 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
72a46344 2450 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
8f1acc32 2451 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
d2ee4dd9 2452 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
0ca4cd7b
JK
2453#endif
2454#if IS_ENABLED(CONFIG_HID_XINMO)
cb2c9e3f 2455 { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
9257821c 2456 { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_THT_2P_ARCADE) },
0ca4cd7b
JK
2457#endif
2458#if IS_ENABLED(CONFIG_HID_ZEROPLUS)
daedb3d6
AH
2459 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
2460 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
0ca4cd7b
JK
2461#endif
2462#if IS_ENABLED(CONFIG_HID_ZYDACRON)
a9885c8f 2463 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
0ca4cd7b 2464#endif
85cdaf52
JS
2465 { }
2466};
2467
3a6f82f7
JS
2468struct hid_dynid {
2469 struct list_head list;
2470 struct hid_device_id id;
2471};
2472
2473/**
2474 * store_new_id - add a new HID device ID to this driver and re-probe devices
2475 * @driver: target device driver
2476 * @buf: buffer for scanning device ID data
2477 * @count: input size
2478 *
2479 * Adds a new dynamic hid device ID to this driver,
2480 * and causes the driver to probe for all devices again.
2481 */
c2810325 2482static ssize_t new_id_store(struct device_driver *drv, const char *buf,
3a6f82f7
JS
2483 size_t count)
2484{
ba91a967 2485 struct hid_driver *hdrv = to_hid_driver(drv);
3a6f82f7
JS
2486 struct hid_dynid *dynid;
2487 __u32 bus, vendor, product;
2488 unsigned long driver_data = 0;
2489 int ret;
2490
2491 ret = sscanf(buf, "%x %x %x %lx",
2492 &bus, &vendor, &product, &driver_data);
2493 if (ret < 3)
2494 return -EINVAL;
2495
2496 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
2497 if (!dynid)
2498 return -ENOMEM;
2499
2500 dynid->id.bus = bus;
4d53b801 2501 dynid->id.group = HID_GROUP_ANY;
3a6f82f7
JS
2502 dynid->id.vendor = vendor;
2503 dynid->id.product = product;
2504 dynid->id.driver_data = driver_data;
2505
2506 spin_lock(&hdrv->dyn_lock);
2507 list_add_tail(&dynid->list, &hdrv->dyn_list);
2508 spin_unlock(&hdrv->dyn_lock);
2509
cef9bc56 2510 ret = driver_attach(&hdrv->driver);
3a6f82f7
JS
2511
2512 return ret ? : count;
2513}
c2810325
GKH
2514static DRIVER_ATTR_WO(new_id);
2515
2516static struct attribute *hid_drv_attrs[] = {
2517 &driver_attr_new_id.attr,
2518 NULL,
2519};
2520ATTRIBUTE_GROUPS(hid_drv);
3a6f82f7
JS
2521
2522static void hid_free_dynids(struct hid_driver *hdrv)
2523{
2524 struct hid_dynid *dynid, *n;
2525
2526 spin_lock(&hdrv->dyn_lock);
2527 list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
2528 list_del(&dynid->list);
2529 kfree(dynid);
2530 }
2531 spin_unlock(&hdrv->dyn_lock);
2532}
2533
2534static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
2535 struct hid_driver *hdrv)
2536{
2537 struct hid_dynid *dynid;
2538
2539 spin_lock(&hdrv->dyn_lock);
2540 list_for_each_entry(dynid, &hdrv->dyn_list, list) {
2541 if (hid_match_one_id(hdev, &dynid->id)) {
2542 spin_unlock(&hdrv->dyn_lock);
2543 return &dynid->id;
2544 }
2545 }
2546 spin_unlock(&hdrv->dyn_lock);
2547
2548 return hid_match_id(hdev, hdrv->id_table);
2549}
2550
85cdaf52
JS
2551static int hid_bus_match(struct device *dev, struct device_driver *drv)
2552{
ba91a967 2553 struct hid_driver *hdrv = to_hid_driver(drv);
ee79a8f8 2554 struct hid_device *hdev = to_hid_device(dev);
85cdaf52 2555
070748ed 2556 return hid_match_device(hdev, hdrv) != NULL;
85cdaf52
JS
2557}
2558
2559static int hid_device_probe(struct device *dev)
2560{
ba91a967 2561 struct hid_driver *hdrv = to_hid_driver(dev->driver);
ee79a8f8 2562 struct hid_device *hdev = to_hid_device(dev);
85cdaf52
JS
2563 const struct hid_device_id *id;
2564 int ret = 0;
2565
c849a614
AR
2566 if (down_interruptible(&hdev->driver_input_lock)) {
2567 ret = -EINTR;
6f68f0ac 2568 goto end;
c849a614
AR
2569 }
2570 hdev->io_started = false;
4ea54542 2571
85cdaf52 2572 if (!hdev->driver) {
3a6f82f7 2573 id = hid_match_device(hdev, hdrv);
ba623a77 2574 if (id == NULL) {
4fa3a583
HR
2575 ret = -ENODEV;
2576 goto unlock;
ba623a77 2577 }
85cdaf52 2578
c500c971
JS
2579 hdev->driver = hdrv;
2580 if (hdrv->probe) {
2581 ret = hdrv->probe(hdev, id);
2582 } else { /* default probe */
a7197c2e 2583 ret = hid_open_report(hdev);
c500c971 2584 if (!ret)
93c10132 2585 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
85cdaf52 2586 }
a7197c2e
HR
2587 if (ret) {
2588 hid_close_report(hdev);
c500c971 2589 hdev->driver = NULL;
a7197c2e 2590 }
85cdaf52 2591 }
ba623a77 2592unlock:
c849a614
AR
2593 if (!hdev->io_started)
2594 up(&hdev->driver_input_lock);
6f68f0ac 2595end:
85cdaf52
JS
2596 return ret;
2597}
2598
2599static int hid_device_remove(struct device *dev)
2600{
ee79a8f8 2601 struct hid_device *hdev = to_hid_device(dev);
4ea54542 2602 struct hid_driver *hdrv;
c849a614 2603 int ret = 0;
4ea54542 2604
c849a614
AR
2605 if (down_interruptible(&hdev->driver_input_lock)) {
2606 ret = -EINTR;
6f68f0ac 2607 goto end;
c849a614
AR
2608 }
2609 hdev->io_started = false;
85cdaf52 2610
4ea54542 2611 hdrv = hdev->driver;
85cdaf52
JS
2612 if (hdrv) {
2613 if (hdrv->remove)
2614 hdrv->remove(hdev);
c500c971
JS
2615 else /* default remove */
2616 hid_hw_stop(hdev);
a7197c2e 2617 hid_close_report(hdev);
85cdaf52
JS
2618 hdev->driver = NULL;
2619 }
2620
c849a614
AR
2621 if (!hdev->io_started)
2622 up(&hdev->driver_input_lock);
6f68f0ac 2623end:
c849a614 2624 return ret;
85cdaf52
JS
2625}
2626
4d53b801
HR
2627static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
2628 char *buf)
2629{
2630 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
4d53b801 2631
dfa0c5fa
RV
2632 return scnprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
2633 hdev->bus, hdev->group, hdev->vendor, hdev->product);
4d53b801 2634}
0d4260e0 2635static DEVICE_ATTR_RO(modalias);
4d53b801 2636
0d4260e0
GKH
2637static struct attribute *hid_dev_attrs[] = {
2638 &dev_attr_modalias.attr,
2639 NULL,
4d53b801 2640};
54f32fd5
AL
2641static struct bin_attribute *hid_dev_bin_attrs[] = {
2642 &dev_bin_attr_report_desc,
2643 NULL
2644};
2645static const struct attribute_group hid_dev_group = {
2646 .attrs = hid_dev_attrs,
2647 .bin_attrs = hid_dev_bin_attrs,
2648};
2649__ATTRIBUTE_GROUPS(hid_dev);
4d53b801 2650
85cdaf52
JS
2651static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
2652{
d193c169 2653 struct hid_device *hdev = to_hid_device(dev);
85cdaf52
JS
2654
2655 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
2656 hdev->bus, hdev->vendor, hdev->product))
2657 return -ENOMEM;
2658
2659 if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
2660 return -ENOMEM;
2661
2662 if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
2663 return -ENOMEM;
2664
2665 if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
2666 return -ENOMEM;
2667
4d53b801
HR
2668 if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
2669 hdev->bus, hdev->group, hdev->vendor, hdev->product))
85cdaf52
JS
2670 return -ENOMEM;
2671
2672 return 0;
2673}
2674
2675static struct bus_type hid_bus_type = {
2676 .name = "hid",
0d4260e0 2677 .dev_groups = hid_dev_groups,
c2810325 2678 .drv_groups = hid_drv_groups,
85cdaf52
JS
2679 .match = hid_bus_match,
2680 .probe = hid_device_probe,
2681 .remove = hid_device_remove,
2682 .uevent = hid_uevent,
2683};
2684
bae7eb33 2685/* a list of devices that shouldn't be handled by HID core at all */
d458a9df
JS
2686static const struct hid_device_id hid_ignore_list[] = {
2687 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
2688 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
2689 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
2690 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
2691 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
2692 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
2693 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
2694 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
2695 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
2696 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
2697 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
2698 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
77f720b7
SC
2699 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
2700 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
62a56582 2701 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
11030183 2702 { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
d458a9df
JS
2703 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
2704 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
2705 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
adc23259 2706 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) },
d458a9df
JS
2707 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
2708 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
2709 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
5f6108cf 2710 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
d458a9df
JS
2711 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
2712 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
2713 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
70c66567 2714 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
df506f2c 2715 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
b1807719 2716 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
d458a9df 2717 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
d458a9df 2718 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
d458a9df
JS
2719 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
2720 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
2721 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
2722 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
2723 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
2724 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
8e2ce73e 2725 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
d458a9df
JS
2726 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
2727 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
2728 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
2729 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
2730 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
2731 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
2732 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
2733 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
2734 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
2735 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
2736 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
2737 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
2738 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
2739 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
2740 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
2741 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
2742 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
2743 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
2744 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
2745 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
2746 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
2747 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
2748 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
2749 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
2750 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
2751 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
2752 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
2753 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
2754 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
2755 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
2756 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
2757 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
2758 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
2759 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
2760 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
2761 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
2762 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
2763 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
2764 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
2765 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
2766 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
2767 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
2768 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
2769 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
2770 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
2771 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
2772 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
31b9779c
VP
2773 { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) },
2774 { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) },
43c1a0a9 2775 { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_GN9350E) },
d458a9df 2776 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
c91c21c5 2777 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
d458a9df 2778 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
eb8141cc 2779 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
d458a9df 2780 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
ce97cac8 2781 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
d458a9df 2782 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
ce97cac8 2783 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
d458a9df 2784 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
ce97cac8
MH
2785 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
2786 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
2787 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
2788 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
2789 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
2790 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
603ef7aa
KK
2791 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERANALYSERCASSY) },
2792 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CONVERTERCONTROLLERCASSY) },
2793 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETESTCASSY) },
d458a9df
JS
2794 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
2795 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
2796 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
ce97cac8
MH
2797 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
2798 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
2799 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
d458a9df
JS
2800 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
2801 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
ce97cac8 2802 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
d458a9df
JS
2803 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
2804 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
2805 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
2806 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
2807 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
ce97cac8
MH
2808 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
2809 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
2810 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
2811 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
2812 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
2813 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
2814 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
3ffb62cb 2815 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
d458a9df
JS
2816 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
2817 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
d458a9df
JS
2818 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
2819 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
a8c8316b 2820 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICK16F1454) },
84f6ea1d 2821 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICK16F1454_V2) },
d458a9df
JS
2822 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
2823 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
2824 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
2825 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
2826 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
2827 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
2828 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
2829 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
2830 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
2831 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
2832 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
2833 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
2834 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
2835 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
2836 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
08f95726 2837 { HID_USB_DEVICE(USB_VENDOR_ID_PETZL, USB_DEVICE_ID_PETZL_HEADLAMP) },
4cfae3e8 2838 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
35cfd1d9 2839 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
20d11305 2840#if IS_ENABLED(CONFIG_MOUSE_SYNAPTICS_USB)
8491ee10
JS
2841 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
2842 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
2843 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
2844 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
2845 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
2846 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
2847 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
2848 { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
2849#endif
d458a9df
JS
2850 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
2851 { }
2852};
2853
b4d8e473
JS
2854/**
2855 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
2856 *
2857 * There are composite devices for which we want to ignore only a certain
2858 * interface. This is a list of devices for which only the mouse interface will
2859 * be ignored. This allows a dedicated driver to take care of the interface.
2860 */
2861static const struct hid_device_id hid_mouse_ignore_list[] = {
2862 /* appletouch driver */
2863 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
2864 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
2865 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
2866 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
2867 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
2868 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
2869 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
2870 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
2871 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
2872 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
2873 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
2874 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
2875 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
2876 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
2877 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
2878 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
2879 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
2880 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
2881 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
2882 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
ac26fca3
JK
2883 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
2884 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
2885 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
99b9f758
EH
2886 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
2887 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
2888 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
2889 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
2890 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
2891 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
47340bd9
AB
2892 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
2893 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
2894 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
213f9da8
GE
2895 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
2896 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
2897 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
4b086910
JK
2898 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
2899 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
2900 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
2901 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
2902 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
2903 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
b2e6ad7d
RB
2904 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
2905 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
2906 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
8d80da90
DH
2907 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
2908 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
2909 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
9d9a04ee
DT
2910 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
2911 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
2912 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
a4a2c545
HR
2913 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI) },
2914 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO) },
2915 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS) },
b4d8e473
JS
2916 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2917 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
2918 { }
2919};
2920
4529eefa 2921bool hid_ignore(struct hid_device *hdev)
d458a9df 2922{
ba3eb73c
JH
2923 int i;
2924
4529eefa
LS
2925 if (hdev->quirks & HID_QUIRK_NO_IGNORE)
2926 return false;
2927 if (hdev->quirks & HID_QUIRK_IGNORE)
2928 return true;
2929
d458a9df
JS
2930 switch (hdev->vendor) {
2931 case USB_VENDOR_ID_CODEMERCS:
2932 /* ignore all Code Mercenaries IOWarrior devices */
2933 if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
2934 hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
2935 return true;
2936 break;
2937 case USB_VENDOR_ID_LOGITECH:
2938 if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
2939 hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
2940 return true;
65dd3b69
HV
2941 /*
2942 * The Keene FM transmitter USB device has the same USB ID as
2943 * the Logitech AudioHub Speaker, but it should ignore the hid.
2944 * Check if the name is that of the Keene device.
2945 * For reference: the name of the AudioHub is
2946 * "HOLTEK AudioHub Speaker".
2947 */
2948 if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
2949 !strcmp(hdev->name, "HOLTEK B-LINK USB Audio "))
2950 return true;
d458a9df 2951 break;
31f7fd79
JW
2952 case USB_VENDOR_ID_SOUNDGRAPH:
2953 if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
2954 hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
2955 return true;
2956 break;
bba5394a
XW
2957 case USB_VENDOR_ID_HANWANG:
2958 if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
2959 hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
2960 return true;
2961 break;
6dc1418e
TS
2962 case USB_VENDOR_ID_JESS:
2963 if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
2964 hdev->type == HID_TYPE_USBNONE)
2965 return true;
729b814a 2966 break;
30b6b7d8
IA
2967 case USB_VENDOR_ID_VELLEMAN:
2968 /* These are not HID devices. They are handled by comedi. */
2969 if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
2970 hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
2971 (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
2972 hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
2973 return true;
2974 break;
5b4617d8
AK
2975 case USB_VENDOR_ID_ATMEL_V_USB:
2976 /* Masterkit MA901 usb radio based on Atmel tiny85 chip and
2977 * it has the same USB ID as many Atmel V-USB devices. This
2978 * usb radio is handled by radio-ma901.c driver so we want
2979 * ignore the hid. Check the name, bus, product and ignore
2980 * if we have MA901 usb radio.
2981 */
2982 if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
2983 hdev->bus == BUS_USB &&
2984 strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
2985 return true;
2986 break;
d0d234c4
HG
2987 case USB_VENDOR_ID_ELAN:
2988 /*
ba3eb73c
JH
2989 * Blacklist of everything that gets handled by the elan_i2c
2990 * input driver. This avoids disabling valid touchpads and
2991 * other ELAN devices.
d0d234c4 2992 */
ba3eb73c
JH
2993 if ((hdev->product == 0x0401 || hdev->product == 0x0400))
2994 for (i = 0; strlen(elan_acpi_id[i].id); ++i)
2995 if (!strncmp(hdev->name, elan_acpi_id[i].id,
2996 strlen(elan_acpi_id[i].id)))
2997 return true;
d0d234c4 2998 break;
d458a9df
JS
2999 }
3000
b4d8e473
JS
3001 if (hdev->type == HID_TYPE_USBMOUSE &&
3002 hid_match_id(hdev, hid_mouse_ignore_list))
3003 return true;
3004
d458a9df
JS
3005 return !!hid_match_id(hdev, hid_ignore_list);
3006}
4529eefa 3007EXPORT_SYMBOL_GPL(hid_ignore);
d458a9df 3008
85cdaf52
JS
3009int hid_add_device(struct hid_device *hdev)
3010{
3011 static atomic_t id = ATOMIC_INIT(0);
3012 int ret;
3013
3014 if (WARN_ON(hdev->status & HID_STAT_ADDED))
3015 return -EBUSY;
3016
d458a9df
JS
3017 /* we need to kill them here, otherwise they will stay allocated to
3018 * wait for coming driver */
4529eefa 3019 if (hid_ignore(hdev))
d458a9df
JS
3020 return -ENODEV;
3021
3c86726c
BT
3022 /*
3023 * Check for the mandatory transport channel.
3024 */
3025 if (!hdev->ll_driver->raw_request) {
3026 hid_err(hdev, "transport driver missing .raw_request()\n");
3027 return -EINVAL;
3028 }
3029
a7197c2e
HR
3030 /*
3031 * Read the device report descriptor once and use as template
3032 * for the driver-specific modifications.
3033 */
3034 ret = hdev->ll_driver->parse(hdev);
3035 if (ret)
3036 return ret;
3037 if (!hdev->dev_rdesc)
3038 return -ENODEV;
3039
734c6609
HR
3040 /*
3041 * Scan generic devices for group information
3042 */
4392bf33
BT
3043 if (hid_ignore_special_drivers) {
3044 hdev->group = HID_GROUP_GENERIC;
3045 } else if (!hdev->group &&
3046 !hid_match_id(hdev, hid_have_special_driver)) {
734c6609
HR
3047 ret = hid_scan_report(hdev);
3048 if (ret)
3049 hid_warn(hdev, "bad device descriptor (%d)\n", ret);
3050 }
3051
6bbe586f
KS
3052 /* XXX hack, any other cleaner solution after the driver core
3053 * is converted to allow more than 20 bytes as the device name? */
3054 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
3055 hdev->vendor, hdev->product, atomic_inc_return(&id));
85cdaf52 3056
4da361b6 3057 hid_debug_register(hdev, dev_name(&hdev->dev));
85cdaf52
JS
3058 ret = device_add(&hdev->dev);
3059 if (!ret)
3060 hdev->status |= HID_STAT_ADDED;
4da361b6
BP
3061 else
3062 hid_debug_unregister(hdev);
a635f9dd 3063
85cdaf52
JS
3064 return ret;
3065}
3066EXPORT_SYMBOL_GPL(hid_add_device);
3067
3068/**
3069 * hid_allocate_device - allocate new hid device descriptor
3070 *
3071 * Allocate and initialize hid device, so that hid_destroy_device might be
3072 * used to free it.
3073 *
3074 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
3075 * error value.
3076 */
3077struct hid_device *hid_allocate_device(void)
3078{
3079 struct hid_device *hdev;
85cdaf52
JS
3080 int ret = -ENOMEM;
3081
3082 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
3083 if (hdev == NULL)
3084 return ERR_PTR(ret);
3085
3086 device_initialize(&hdev->dev);
3087 hdev->dev.release = hid_device_release;
3088 hdev->dev.bus = &hid_bus_type;
64bebefc 3089 device_enable_async_suspend(&hdev->dev);
85cdaf52 3090
a7197c2e 3091 hid_close_report(hdev);
85cdaf52 3092
cd667ce2
JK
3093 init_waitqueue_head(&hdev->debug_wait);
3094 INIT_LIST_HEAD(&hdev->debug_list);
1deb9d34 3095 spin_lock_init(&hdev->debug_list_lock);
c849a614 3096 sema_init(&hdev->driver_input_lock, 1);
aaac082d 3097 mutex_init(&hdev->ll_open_lock);
cd667ce2 3098
85cdaf52 3099 return hdev;
85cdaf52
JS
3100}
3101EXPORT_SYMBOL_GPL(hid_allocate_device);
3102
3103static void hid_remove_device(struct hid_device *hdev)
3104{
3105 if (hdev->status & HID_STAT_ADDED) {
3106 device_del(&hdev->dev);
a635f9dd 3107 hid_debug_unregister(hdev);
85cdaf52
JS
3108 hdev->status &= ~HID_STAT_ADDED;
3109 }
a7197c2e
HR
3110 kfree(hdev->dev_rdesc);
3111 hdev->dev_rdesc = NULL;
3112 hdev->dev_rsize = 0;
85cdaf52
JS
3113}
3114
3115/**
3116 * hid_destroy_device - free previously allocated device
3117 *
3118 * @hdev: hid device
3119 *
3120 * If you allocate hid_device through hid_allocate_device, you should ever
3121 * free by this function.
3122 */
3123void hid_destroy_device(struct hid_device *hdev)
3124{
3125 hid_remove_device(hdev);
3126 put_device(&hdev->dev);
3127}
3128EXPORT_SYMBOL_GPL(hid_destroy_device);
3129
3130int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
3131 const char *mod_name)
3132{
3133 hdrv->driver.name = hdrv->name;
3134 hdrv->driver.bus = &hid_bus_type;
3135 hdrv->driver.owner = owner;
3136 hdrv->driver.mod_name = mod_name;
3137
3a6f82f7
JS
3138 INIT_LIST_HEAD(&hdrv->dyn_list);
3139 spin_lock_init(&hdrv->dyn_lock);
3140
c2810325 3141 return driver_register(&hdrv->driver);
85cdaf52
JS
3142}
3143EXPORT_SYMBOL_GPL(__hid_register_driver);
3144
3145void hid_unregister_driver(struct hid_driver *hdrv)
3146{
3147 driver_unregister(&hdrv->driver);
3a6f82f7 3148 hid_free_dynids(hdrv);
85cdaf52
JS
3149}
3150EXPORT_SYMBOL_GPL(hid_unregister_driver);
3151
0361a28d
ON
3152int hid_check_keys_pressed(struct hid_device *hid)
3153{
3154 struct hid_input *hidinput;
3155 int i;
3156
e5288eb5
JK
3157 if (!(hid->claimed & HID_CLAIMED_INPUT))
3158 return 0;
3159
0361a28d
ON
3160 list_for_each_entry(hidinput, &hid->inputs, list) {
3161 for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
3162 if (hidinput->input->key[i])
3163 return 1;
3164 }
3165
3166 return 0;
3167}
3168
3169EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
3170
86166b7b
JK
3171static int __init hid_init(void)
3172{
85cdaf52
JS
3173 int ret;
3174
a635f9dd 3175 if (hid_debug)
4291ee30
JP
3176 pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
3177 "debugfs is now used for inspecting the device (report descriptor, reports)\n");
a635f9dd 3178
85cdaf52
JS
3179 ret = bus_register(&hid_bus_type);
3180 if (ret) {
4291ee30 3181 pr_err("can't register hid bus\n");
85cdaf52
JS
3182 goto err;
3183 }
3184
3185 ret = hidraw_init();
3186 if (ret)
3187 goto err_bus;
3188
a635f9dd
JK
3189 hid_debug_init();
3190
85cdaf52
JS
3191 return 0;
3192err_bus:
3193 bus_unregister(&hid_bus_type);
3194err:
3195 return ret;
86166b7b
JK
3196}
3197
3198static void __exit hid_exit(void)
3199{
a635f9dd 3200 hid_debug_exit();
86166b7b 3201 hidraw_exit();
85cdaf52 3202 bus_unregister(&hid_bus_type);
86166b7b
JK
3203}
3204
3205module_init(hid_init);
3206module_exit(hid_exit);
3207
88adb72b
JK
3208MODULE_AUTHOR("Andreas Gal");
3209MODULE_AUTHOR("Vojtech Pavlik");
3210MODULE_AUTHOR("Jiri Kosina");
7021b600 3211MODULE_LICENSE("GPL");