hid-core.c revision 4d53b8012f1f01ddb3f24db2031b042bb4cbd0d0
1/*
2 *  HID support for Linux
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
7 *  Copyright (c) 2006-2012 Jiri Kosina
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
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/list.h>
24#include <linux/mm.h>
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>
30#include <linux/vmalloc.h>
31#include <linux/sched.h>
32#include <linux/semaphore.h>
33
34#include <linux/hid.h>
35#include <linux/hiddev.h>
36#include <linux/hid-debug.h>
37#include <linux/hidraw.h>
38
39#include "hid-ids.h"
40
41/*
42 * Version Information
43 */
44
45#define DRIVER_DESC "HID core driver"
46#define DRIVER_LICENSE "GPL"
47
48int hid_debug = 0;
49module_param_named(debug, hid_debug, int, 0600);
50MODULE_PARM_DESC(debug, "toggle HID debugging messages");
51EXPORT_SYMBOL_GPL(hid_debug);
52
53static int hid_ignore_special_drivers = 0;
54module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
55MODULE_PARM_DESC(debug, "Ignore any special drivers and handle all devices by generic driver");
56
57/*
58 * Register a new report for a device.
59 */
60
61struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
62{
63	struct hid_report_enum *report_enum = device->report_enum + type;
64	struct hid_report *report;
65
66	if (report_enum->report_id_hash[id])
67		return report_enum->report_id_hash[id];
68
69	report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
70	if (!report)
71		return NULL;
72
73	if (id != 0)
74		report_enum->numbered = 1;
75
76	report->id = id;
77	report->type = type;
78	report->size = 0;
79	report->device = device;
80	report_enum->report_id_hash[id] = report;
81
82	list_add_tail(&report->list, &report_enum->report_list);
83
84	return report;
85}
86EXPORT_SYMBOL_GPL(hid_register_report);
87
88/*
89 * Register a new field for this report.
90 */
91
92static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
93{
94	struct hid_field *field;
95
96	if (report->maxfield == HID_MAX_FIELDS) {
97		hid_err(report->device, "too many fields in report\n");
98		return NULL;
99	}
100
101	field = kzalloc((sizeof(struct hid_field) +
102			 usages * sizeof(struct hid_usage) +
103			 values * sizeof(unsigned)), GFP_KERNEL);
104	if (!field)
105		return NULL;
106
107	field->index = report->maxfield++;
108	report->field[field->index] = field;
109	field->usage = (struct hid_usage *)(field + 1);
110	field->value = (s32 *)(field->usage + usages);
111	field->report = report;
112
113	return field;
114}
115
116/*
117 * Open a collection. The type/usage is pushed on the stack.
118 */
119
120static int open_collection(struct hid_parser *parser, unsigned type)
121{
122	struct hid_collection *collection;
123	unsigned usage;
124
125	usage = parser->local.usage[0];
126
127	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
128		hid_err(parser->device, "collection stack overflow\n");
129		return -1;
130	}
131
132	if (parser->device->maxcollection == parser->device->collection_size) {
133		collection = kmalloc(sizeof(struct hid_collection) *
134				parser->device->collection_size * 2, GFP_KERNEL);
135		if (collection == NULL) {
136			hid_err(parser->device, "failed to reallocate collection array\n");
137			return -1;
138		}
139		memcpy(collection, parser->device->collection,
140			sizeof(struct hid_collection) *
141			parser->device->collection_size);
142		memset(collection + parser->device->collection_size, 0,
143			sizeof(struct hid_collection) *
144			parser->device->collection_size);
145		kfree(parser->device->collection);
146		parser->device->collection = collection;
147		parser->device->collection_size *= 2;
148	}
149
150	parser->collection_stack[parser->collection_stack_ptr++] =
151		parser->device->maxcollection;
152
153	collection = parser->device->collection +
154		parser->device->maxcollection++;
155	collection->type = type;
156	collection->usage = usage;
157	collection->level = parser->collection_stack_ptr - 1;
158
159	if (type == HID_COLLECTION_APPLICATION)
160		parser->device->maxapplication++;
161
162	return 0;
163}
164
165/*
166 * Close a collection.
167 */
168
169static int close_collection(struct hid_parser *parser)
170{
171	if (!parser->collection_stack_ptr) {
172		hid_err(parser->device, "collection stack underflow\n");
173		return -1;
174	}
175	parser->collection_stack_ptr--;
176	return 0;
177}
178
179/*
180 * Climb up the stack, search for the specified collection type
181 * and return the usage.
182 */
183
184static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
185{
186	struct hid_collection *collection = parser->device->collection;
187	int n;
188
189	for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
190		unsigned index = parser->collection_stack[n];
191		if (collection[index].type == type)
192			return collection[index].usage;
193	}
194	return 0; /* we know nothing about this usage type */
195}
196
197/*
198 * Add a usage to the temporary parser table.
199 */
200
201static int hid_add_usage(struct hid_parser *parser, unsigned usage)
202{
203	if (parser->local.usage_index >= HID_MAX_USAGES) {
204		hid_err(parser->device, "usage index exceeded\n");
205		return -1;
206	}
207	parser->local.usage[parser->local.usage_index] = usage;
208	parser->local.collection_index[parser->local.usage_index] =
209		parser->collection_stack_ptr ?
210		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
211	parser->local.usage_index++;
212	return 0;
213}
214
215/*
216 * Register a new field for this report.
217 */
218
219static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
220{
221	struct hid_report *report;
222	struct hid_field *field;
223	int usages;
224	unsigned offset;
225	int i;
226
227	report = hid_register_report(parser->device, report_type, parser->global.report_id);
228	if (!report) {
229		hid_err(parser->device, "hid_register_report failed\n");
230		return -1;
231	}
232
233	if (parser->global.logical_maximum < parser->global.logical_minimum) {
234		hid_err(parser->device, "logical range invalid %d %d\n",
235				parser->global.logical_minimum, parser->global.logical_maximum);
236		return -1;
237	}
238
239	offset = report->size;
240	report->size += parser->global.report_size * parser->global.report_count;
241
242	if (!parser->local.usage_index) /* Ignore padding fields */
243		return 0;
244
245	usages = max_t(int, parser->local.usage_index, parser->global.report_count);
246
247	field = hid_register_field(report, usages, parser->global.report_count);
248	if (!field)
249		return 0;
250
251	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
252	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
253	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
254
255	for (i = 0; i < usages; i++) {
256		int j = i;
257		/* Duplicate the last usage we parsed if we have excess values */
258		if (i >= parser->local.usage_index)
259			j = parser->local.usage_index - 1;
260		field->usage[i].hid = parser->local.usage[j];
261		field->usage[i].collection_index =
262			parser->local.collection_index[j];
263	}
264
265	field->maxusage = usages;
266	field->flags = flags;
267	field->report_offset = offset;
268	field->report_type = report_type;
269	field->report_size = parser->global.report_size;
270	field->report_count = parser->global.report_count;
271	field->logical_minimum = parser->global.logical_minimum;
272	field->logical_maximum = parser->global.logical_maximum;
273	field->physical_minimum = parser->global.physical_minimum;
274	field->physical_maximum = parser->global.physical_maximum;
275	field->unit_exponent = parser->global.unit_exponent;
276	field->unit = parser->global.unit;
277
278	return 0;
279}
280
281/*
282 * Read data value from item.
283 */
284
285static u32 item_udata(struct hid_item *item)
286{
287	switch (item->size) {
288	case 1: return item->data.u8;
289	case 2: return item->data.u16;
290	case 4: return item->data.u32;
291	}
292	return 0;
293}
294
295static s32 item_sdata(struct hid_item *item)
296{
297	switch (item->size) {
298	case 1: return item->data.s8;
299	case 2: return item->data.s16;
300	case 4: return item->data.s32;
301	}
302	return 0;
303}
304
305/*
306 * Process a global item.
307 */
308
309static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
310{
311	switch (item->tag) {
312	case HID_GLOBAL_ITEM_TAG_PUSH:
313
314		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
315			hid_err(parser->device, "global environment stack overflow\n");
316			return -1;
317		}
318
319		memcpy(parser->global_stack + parser->global_stack_ptr++,
320			&parser->global, sizeof(struct hid_global));
321		return 0;
322
323	case HID_GLOBAL_ITEM_TAG_POP:
324
325		if (!parser->global_stack_ptr) {
326			hid_err(parser->device, "global environment stack underflow\n");
327			return -1;
328		}
329
330		memcpy(&parser->global, parser->global_stack +
331			--parser->global_stack_ptr, sizeof(struct hid_global));
332		return 0;
333
334	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
335		parser->global.usage_page = item_udata(item);
336		return 0;
337
338	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
339		parser->global.logical_minimum = item_sdata(item);
340		return 0;
341
342	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
343		if (parser->global.logical_minimum < 0)
344			parser->global.logical_maximum = item_sdata(item);
345		else
346			parser->global.logical_maximum = item_udata(item);
347		return 0;
348
349	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
350		parser->global.physical_minimum = item_sdata(item);
351		return 0;
352
353	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
354		if (parser->global.physical_minimum < 0)
355			parser->global.physical_maximum = item_sdata(item);
356		else
357			parser->global.physical_maximum = item_udata(item);
358		return 0;
359
360	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
361		parser->global.unit_exponent = item_sdata(item);
362		return 0;
363
364	case HID_GLOBAL_ITEM_TAG_UNIT:
365		parser->global.unit = item_udata(item);
366		return 0;
367
368	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
369		parser->global.report_size = item_udata(item);
370		if (parser->global.report_size > 96) {
371			hid_err(parser->device, "invalid report_size %d\n",
372					parser->global.report_size);
373			return -1;
374		}
375		return 0;
376
377	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
378		parser->global.report_count = item_udata(item);
379		if (parser->global.report_count > HID_MAX_USAGES) {
380			hid_err(parser->device, "invalid report_count %d\n",
381					parser->global.report_count);
382			return -1;
383		}
384		return 0;
385
386	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
387		parser->global.report_id = item_udata(item);
388		if (parser->global.report_id == 0) {
389			hid_err(parser->device, "report_id 0 is invalid\n");
390			return -1;
391		}
392		return 0;
393
394	default:
395		hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
396		return -1;
397	}
398}
399
400/*
401 * Process a local item.
402 */
403
404static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
405{
406	__u32 data;
407	unsigned n;
408
409	data = item_udata(item);
410
411	switch (item->tag) {
412	case HID_LOCAL_ITEM_TAG_DELIMITER:
413
414		if (data) {
415			/*
416			 * We treat items before the first delimiter
417			 * as global to all usage sets (branch 0).
418			 * In the moment we process only these global
419			 * items and the first delimiter set.
420			 */
421			if (parser->local.delimiter_depth != 0) {
422				hid_err(parser->device, "nested delimiters\n");
423				return -1;
424			}
425			parser->local.delimiter_depth++;
426			parser->local.delimiter_branch++;
427		} else {
428			if (parser->local.delimiter_depth < 1) {
429				hid_err(parser->device, "bogus close delimiter\n");
430				return -1;
431			}
432			parser->local.delimiter_depth--;
433		}
434		return 1;
435
436	case HID_LOCAL_ITEM_TAG_USAGE:
437
438		if (parser->local.delimiter_branch > 1) {
439			dbg_hid("alternative usage ignored\n");
440			return 0;
441		}
442
443		if (item->size <= 2)
444			data = (parser->global.usage_page << 16) + data;
445
446		return hid_add_usage(parser, data);
447
448	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
449
450		if (parser->local.delimiter_branch > 1) {
451			dbg_hid("alternative usage ignored\n");
452			return 0;
453		}
454
455		if (item->size <= 2)
456			data = (parser->global.usage_page << 16) + data;
457
458		parser->local.usage_minimum = data;
459		return 0;
460
461	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
462
463		if (parser->local.delimiter_branch > 1) {
464			dbg_hid("alternative usage ignored\n");
465			return 0;
466		}
467
468		if (item->size <= 2)
469			data = (parser->global.usage_page << 16) + data;
470
471		for (n = parser->local.usage_minimum; n <= data; n++)
472			if (hid_add_usage(parser, n)) {
473				dbg_hid("hid_add_usage failed\n");
474				return -1;
475			}
476		return 0;
477
478	default:
479
480		dbg_hid("unknown local item tag 0x%x\n", item->tag);
481		return 0;
482	}
483	return 0;
484}
485
486/*
487 * Process a main item.
488 */
489
490static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
491{
492	__u32 data;
493	int ret;
494
495	data = item_udata(item);
496
497	switch (item->tag) {
498	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
499		ret = open_collection(parser, data & 0xff);
500		break;
501	case HID_MAIN_ITEM_TAG_END_COLLECTION:
502		ret = close_collection(parser);
503		break;
504	case HID_MAIN_ITEM_TAG_INPUT:
505		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
506		break;
507	case HID_MAIN_ITEM_TAG_OUTPUT:
508		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
509		break;
510	case HID_MAIN_ITEM_TAG_FEATURE:
511		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
512		break;
513	default:
514		hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag);
515		ret = 0;
516	}
517
518	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
519
520	return ret;
521}
522
523/*
524 * Process a reserved item.
525 */
526
527static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
528{
529	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
530	return 0;
531}
532
533/*
534 * Free a report and all registered fields. The field->usage and
535 * field->value table's are allocated behind the field, so we need
536 * only to free(field) itself.
537 */
538
539static void hid_free_report(struct hid_report *report)
540{
541	unsigned n;
542
543	for (n = 0; n < report->maxfield; n++)
544		kfree(report->field[n]);
545	kfree(report);
546}
547
548/*
549 * Close report. This function returns the device
550 * state to the point prior to hid_open_report().
551 */
552static void hid_close_report(struct hid_device *device)
553{
554	unsigned i, j;
555
556	for (i = 0; i < HID_REPORT_TYPES; i++) {
557		struct hid_report_enum *report_enum = device->report_enum + i;
558
559		for (j = 0; j < 256; j++) {
560			struct hid_report *report = report_enum->report_id_hash[j];
561			if (report)
562				hid_free_report(report);
563		}
564		memset(report_enum, 0, sizeof(*report_enum));
565		INIT_LIST_HEAD(&report_enum->report_list);
566	}
567
568	kfree(device->rdesc);
569	device->rdesc = NULL;
570	device->rsize = 0;
571
572	kfree(device->collection);
573	device->collection = NULL;
574	device->collection_size = 0;
575	device->maxcollection = 0;
576	device->maxapplication = 0;
577
578	device->status &= ~HID_STAT_PARSED;
579}
580
581/*
582 * Free a device structure, all reports, and all fields.
583 */
584
585static void hid_device_release(struct device *dev)
586{
587	struct hid_device *hid = container_of(dev, struct hid_device, dev);
588
589	hid_close_report(hid);
590	kfree(hid->dev_rdesc);
591	kfree(hid);
592}
593
594/*
595 * Fetch a report description item from the data stream. We support long
596 * items, though they are not used yet.
597 */
598
599static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
600{
601	u8 b;
602
603	if ((end - start) <= 0)
604		return NULL;
605
606	b = *start++;
607
608	item->type = (b >> 2) & 3;
609	item->tag  = (b >> 4) & 15;
610
611	if (item->tag == HID_ITEM_TAG_LONG) {
612
613		item->format = HID_ITEM_FORMAT_LONG;
614
615		if ((end - start) < 2)
616			return NULL;
617
618		item->size = *start++;
619		item->tag  = *start++;
620
621		if ((end - start) < item->size)
622			return NULL;
623
624		item->data.longdata = start;
625		start += item->size;
626		return start;
627	}
628
629	item->format = HID_ITEM_FORMAT_SHORT;
630	item->size = b & 3;
631
632	switch (item->size) {
633	case 0:
634		return start;
635
636	case 1:
637		if ((end - start) < 1)
638			return NULL;
639		item->data.u8 = *start++;
640		return start;
641
642	case 2:
643		if ((end - start) < 2)
644			return NULL;
645		item->data.u16 = get_unaligned_le16(start);
646		start = (__u8 *)((__le16 *)start + 1);
647		return start;
648
649	case 3:
650		item->size++;
651		if ((end - start) < 4)
652			return NULL;
653		item->data.u32 = get_unaligned_le32(start);
654		start = (__u8 *)((__le32 *)start + 1);
655		return start;
656	}
657
658	return NULL;
659}
660
661/**
662 * hid_parse_report - parse device report
663 *
664 * @device: hid device
665 * @start: report start
666 * @size: report size
667 *
668 * Allocate the device report as read by the bus driver. This function should
669 * only be called from parse() in ll drivers.
670 */
671int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
672{
673	hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
674	if (!hid->dev_rdesc)
675		return -ENOMEM;
676	hid->dev_rsize = size;
677	return 0;
678}
679EXPORT_SYMBOL_GPL(hid_parse_report);
680
681/**
682 * hid_open_report - open a driver-specific device report
683 *
684 * @device: hid device
685 *
686 * Parse a report description into a hid_device structure. Reports are
687 * enumerated, fields are attached to these reports.
688 * 0 returned on success, otherwise nonzero error value.
689 *
690 * This function (or the equivalent hid_parse() macro) should only be
691 * called from probe() in drivers, before starting the device.
692 */
693int hid_open_report(struct hid_device *device)
694{
695	struct hid_parser *parser;
696	struct hid_item item;
697	unsigned int size;
698	__u8 *start;
699	__u8 *end;
700	int ret;
701	static int (*dispatch_type[])(struct hid_parser *parser,
702				      struct hid_item *item) = {
703		hid_parser_main,
704		hid_parser_global,
705		hid_parser_local,
706		hid_parser_reserved
707	};
708
709	if (WARN_ON(device->status & HID_STAT_PARSED))
710		return -EBUSY;
711
712	start = device->dev_rdesc;
713	if (WARN_ON(!start))
714		return -ENODEV;
715	size = device->dev_rsize;
716
717	if (device->driver->report_fixup)
718		start = device->driver->report_fixup(device, start, &size);
719
720	device->rdesc = kmemdup(start, size, GFP_KERNEL);
721	if (device->rdesc == NULL)
722		return -ENOMEM;
723	device->rsize = size;
724
725	parser = vzalloc(sizeof(struct hid_parser));
726	if (!parser) {
727		ret = -ENOMEM;
728		goto err;
729	}
730
731	parser->device = device;
732
733	end = start + size;
734
735	device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
736				     sizeof(struct hid_collection), GFP_KERNEL);
737	if (!device->collection) {
738		ret = -ENOMEM;
739		goto err;
740	}
741	device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
742
743	ret = -EINVAL;
744	while ((start = fetch_item(start, end, &item)) != NULL) {
745
746		if (item.format != HID_ITEM_FORMAT_SHORT) {
747			hid_err(device, "unexpected long global item\n");
748			goto err;
749		}
750
751		if (dispatch_type[item.type](parser, &item)) {
752			hid_err(device, "item %u %u %u %u parsing failed\n",
753				item.format, (unsigned)item.size,
754				(unsigned)item.type, (unsigned)item.tag);
755			goto err;
756		}
757
758		if (start == end) {
759			if (parser->collection_stack_ptr) {
760				hid_err(device, "unbalanced collection at end of report description\n");
761				goto err;
762			}
763			if (parser->local.delimiter_depth) {
764				hid_err(device, "unbalanced delimiter at end of report description\n");
765				goto err;
766			}
767			vfree(parser);
768			device->status |= HID_STAT_PARSED;
769			return 0;
770		}
771	}
772
773	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
774err:
775	vfree(parser);
776	hid_close_report(device);
777	return ret;
778}
779EXPORT_SYMBOL_GPL(hid_open_report);
780
781/*
782 * Convert a signed n-bit integer to signed 32-bit integer. Common
783 * cases are done through the compiler, the screwed things has to be
784 * done by hand.
785 */
786
787static s32 snto32(__u32 value, unsigned n)
788{
789	switch (n) {
790	case 8:  return ((__s8)value);
791	case 16: return ((__s16)value);
792	case 32: return ((__s32)value);
793	}
794	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
795}
796
797/*
798 * Convert a signed 32-bit integer to a signed n-bit integer.
799 */
800
801static u32 s32ton(__s32 value, unsigned n)
802{
803	s32 a = value >> (n - 1);
804	if (a && a != -1)
805		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
806	return value & ((1 << n) - 1);
807}
808
809/*
810 * Extract/implement a data field from/to a little endian report (bit array).
811 *
812 * Code sort-of follows HID spec:
813 *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
814 *
815 * While the USB HID spec allows unlimited length bit fields in "report
816 * descriptors", most devices never use more than 16 bits.
817 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
818 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
819 */
820
821static __u32 extract(const struct hid_device *hid, __u8 *report,
822		     unsigned offset, unsigned n)
823{
824	u64 x;
825
826	if (n > 32)
827		hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
828			 n, current->comm);
829
830	report += offset >> 3;  /* adjust byte index */
831	offset &= 7;            /* now only need bit offset into one byte */
832	x = get_unaligned_le64(report);
833	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
834	return (u32) x;
835}
836
837/*
838 * "implement" : set bits in a little endian bit stream.
839 * Same concepts as "extract" (see comments above).
840 * The data mangled in the bit stream remains in little endian
841 * order the whole time. It make more sense to talk about
842 * endianness of register values by considering a register
843 * a "cached" copy of the little endiad bit stream.
844 */
845static void implement(const struct hid_device *hid, __u8 *report,
846		      unsigned offset, unsigned n, __u32 value)
847{
848	u64 x;
849	u64 m = (1ULL << n) - 1;
850
851	if (n > 32)
852		hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
853			 __func__, n, current->comm);
854
855	if (value > m)
856		hid_warn(hid, "%s() called with too large value %d! (%s)\n",
857			 __func__, value, current->comm);
858	WARN_ON(value > m);
859	value &= m;
860
861	report += offset >> 3;
862	offset &= 7;
863
864	x = get_unaligned_le64(report);
865	x &= ~(m << offset);
866	x |= ((u64)value) << offset;
867	put_unaligned_le64(x, report);
868}
869
870/*
871 * Search an array for a value.
872 */
873
874static int search(__s32 *array, __s32 value, unsigned n)
875{
876	while (n--) {
877		if (*array++ == value)
878			return 0;
879	}
880	return -1;
881}
882
883/**
884 * hid_match_report - check if driver's raw_event should be called
885 *
886 * @hid: hid device
887 * @report_type: type to match against
888 *
889 * compare hid->driver->report_table->report_type to report->type
890 */
891static int hid_match_report(struct hid_device *hid, struct hid_report *report)
892{
893	const struct hid_report_id *id = hid->driver->report_table;
894
895	if (!id) /* NULL means all */
896		return 1;
897
898	for (; id->report_type != HID_TERMINATOR; id++)
899		if (id->report_type == HID_ANY_ID ||
900				id->report_type == report->type)
901			return 1;
902	return 0;
903}
904
905/**
906 * hid_match_usage - check if driver's event should be called
907 *
908 * @hid: hid device
909 * @usage: usage to match against
910 *
911 * compare hid->driver->usage_table->usage_{type,code} to
912 * usage->usage_{type,code}
913 */
914static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
915{
916	const struct hid_usage_id *id = hid->driver->usage_table;
917
918	if (!id) /* NULL means all */
919		return 1;
920
921	for (; id->usage_type != HID_ANY_ID - 1; id++)
922		if ((id->usage_hid == HID_ANY_ID ||
923				id->usage_hid == usage->hid) &&
924				(id->usage_type == HID_ANY_ID ||
925				id->usage_type == usage->type) &&
926				(id->usage_code == HID_ANY_ID ||
927				 id->usage_code == usage->code))
928			return 1;
929	return 0;
930}
931
932static void hid_process_event(struct hid_device *hid, struct hid_field *field,
933		struct hid_usage *usage, __s32 value, int interrupt)
934{
935	struct hid_driver *hdrv = hid->driver;
936	int ret;
937
938	hid_dump_input(hid, usage, value);
939
940	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
941		ret = hdrv->event(hid, field, usage, value);
942		if (ret != 0) {
943			if (ret < 0)
944				hid_err(hid, "%s's event failed with %d\n",
945						hdrv->name, ret);
946			return;
947		}
948	}
949
950	if (hid->claimed & HID_CLAIMED_INPUT)
951		hidinput_hid_event(hid, field, usage, value);
952	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
953		hid->hiddev_hid_event(hid, field, usage, value);
954}
955
956/*
957 * Analyse a received field, and fetch the data from it. The field
958 * content is stored for next report processing (we do differential
959 * reporting to the layer).
960 */
961
962static void hid_input_field(struct hid_device *hid, struct hid_field *field,
963			    __u8 *data, int interrupt)
964{
965	unsigned n;
966	unsigned count = field->report_count;
967	unsigned offset = field->report_offset;
968	unsigned size = field->report_size;
969	__s32 min = field->logical_minimum;
970	__s32 max = field->logical_maximum;
971	__s32 *value;
972
973	value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
974	if (!value)
975		return;
976
977	for (n = 0; n < count; n++) {
978
979		value[n] = min < 0 ?
980			snto32(extract(hid, data, offset + n * size, size),
981			       size) :
982			extract(hid, data, offset + n * size, size);
983
984		/* Ignore report if ErrorRollOver */
985		if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
986		    value[n] >= min && value[n] <= max &&
987		    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
988			goto exit;
989	}
990
991	for (n = 0; n < count; n++) {
992
993		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
994			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
995			continue;
996		}
997
998		if (field->value[n] >= min && field->value[n] <= max
999			&& field->usage[field->value[n] - min].hid
1000			&& search(value, field->value[n], count))
1001				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
1002
1003		if (value[n] >= min && value[n] <= max
1004			&& field->usage[value[n] - min].hid
1005			&& search(field->value, value[n], count))
1006				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
1007	}
1008
1009	memcpy(field->value, value, count * sizeof(__s32));
1010exit:
1011	kfree(value);
1012}
1013
1014/*
1015 * Output the field into the report.
1016 */
1017
1018static void hid_output_field(const struct hid_device *hid,
1019			     struct hid_field *field, __u8 *data)
1020{
1021	unsigned count = field->report_count;
1022	unsigned offset = field->report_offset;
1023	unsigned size = field->report_size;
1024	unsigned n;
1025
1026	for (n = 0; n < count; n++) {
1027		if (field->logical_minimum < 0)	/* signed values */
1028			implement(hid, data, offset + n * size, size,
1029				  s32ton(field->value[n], size));
1030		else				/* unsigned values */
1031			implement(hid, data, offset + n * size, size,
1032				  field->value[n]);
1033	}
1034}
1035
1036/*
1037 * Create a report.
1038 */
1039
1040void hid_output_report(struct hid_report *report, __u8 *data)
1041{
1042	unsigned n;
1043
1044	if (report->id > 0)
1045		*data++ = report->id;
1046
1047	memset(data, 0, ((report->size - 1) >> 3) + 1);
1048	for (n = 0; n < report->maxfield; n++)
1049		hid_output_field(report->device, report->field[n], data);
1050}
1051EXPORT_SYMBOL_GPL(hid_output_report);
1052
1053/*
1054 * Set a field value. The report this field belongs to has to be
1055 * created and transferred to the device, to set this value in the
1056 * device.
1057 */
1058
1059int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1060{
1061	unsigned size = field->report_size;
1062
1063	hid_dump_input(field->report->device, field->usage + offset, value);
1064
1065	if (offset >= field->report_count) {
1066		hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
1067				offset, field->report_count);
1068		return -1;
1069	}
1070	if (field->logical_minimum < 0) {
1071		if (value != snto32(s32ton(value, size), size)) {
1072			hid_err(field->report->device, "value %d is out of range\n", value);
1073			return -1;
1074		}
1075	}
1076	field->value[offset] = value;
1077	return 0;
1078}
1079EXPORT_SYMBOL_GPL(hid_set_field);
1080
1081static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1082		const u8 *data)
1083{
1084	struct hid_report *report;
1085	unsigned int n = 0;	/* Normally report number is 0 */
1086
1087	/* Device uses numbered reports, data[0] is report number */
1088	if (report_enum->numbered)
1089		n = *data;
1090
1091	report = report_enum->report_id_hash[n];
1092	if (report == NULL)
1093		dbg_hid("undefined report_id %u received\n", n);
1094
1095	return report;
1096}
1097
1098void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1099		int interrupt)
1100{
1101	struct hid_report_enum *report_enum = hid->report_enum + type;
1102	struct hid_report *report;
1103	unsigned int a;
1104	int rsize, csize = size;
1105	u8 *cdata = data;
1106
1107	report = hid_get_report(report_enum, data);
1108	if (!report)
1109		return;
1110
1111	if (report_enum->numbered) {
1112		cdata++;
1113		csize--;
1114	}
1115
1116	rsize = ((report->size - 1) >> 3) + 1;
1117
1118	if (rsize > HID_MAX_BUFFER_SIZE)
1119		rsize = HID_MAX_BUFFER_SIZE;
1120
1121	if (csize < rsize) {
1122		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1123				csize, rsize);
1124		memset(cdata + csize, 0, rsize - csize);
1125	}
1126
1127	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1128		hid->hiddev_report_event(hid, report);
1129	if (hid->claimed & HID_CLAIMED_HIDRAW)
1130		hidraw_report_event(hid, data, size);
1131
1132	for (a = 0; a < report->maxfield; a++)
1133		hid_input_field(hid, report->field[a], cdata, interrupt);
1134
1135	if (hid->claimed & HID_CLAIMED_INPUT)
1136		hidinput_report_event(hid, report);
1137}
1138EXPORT_SYMBOL_GPL(hid_report_raw_event);
1139
1140/**
1141 * hid_input_report - report data from lower layer (usb, bt...)
1142 *
1143 * @hid: hid device
1144 * @type: HID report type (HID_*_REPORT)
1145 * @data: report contents
1146 * @size: size of data parameter
1147 * @interrupt: distinguish between interrupt and control transfers
1148 *
1149 * This is data entry for lower layers.
1150 */
1151int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1152{
1153	struct hid_report_enum *report_enum;
1154	struct hid_driver *hdrv;
1155	struct hid_report *report;
1156	char *buf;
1157	unsigned int i;
1158	int ret = 0;
1159
1160	if (!hid)
1161		return -ENODEV;
1162
1163	if (down_trylock(&hid->driver_lock))
1164		return -EBUSY;
1165
1166	if (!hid->driver) {
1167		ret = -ENODEV;
1168		goto unlock;
1169	}
1170	report_enum = hid->report_enum + type;
1171	hdrv = hid->driver;
1172
1173	if (!size) {
1174		dbg_hid("empty report\n");
1175		ret = -1;
1176		goto unlock;
1177	}
1178
1179	buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1180
1181	if (!buf)
1182		goto nomem;
1183
1184	/* dump the report */
1185	snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1186			"\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
1187	hid_debug_event(hid, buf);
1188
1189	for (i = 0; i < size; i++) {
1190		snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1191				" %02x", data[i]);
1192		hid_debug_event(hid, buf);
1193	}
1194	hid_debug_event(hid, "\n");
1195	kfree(buf);
1196
1197nomem:
1198	report = hid_get_report(report_enum, data);
1199
1200	if (!report) {
1201		ret = -1;
1202		goto unlock;
1203	}
1204
1205	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1206		ret = hdrv->raw_event(hid, report, data, size);
1207		if (ret != 0) {
1208			ret = ret < 0 ? ret : 0;
1209			goto unlock;
1210		}
1211	}
1212
1213	hid_report_raw_event(hid, type, data, size, interrupt);
1214
1215unlock:
1216	up(&hid->driver_lock);
1217	return ret;
1218}
1219EXPORT_SYMBOL_GPL(hid_input_report);
1220
1221static bool hid_match_one_id(struct hid_device *hdev,
1222		const struct hid_device_id *id)
1223{
1224	return id->bus == hdev->bus &&
1225		(id->group == HID_GROUP_ANY || id->group == hdev->group) &&
1226		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1227		(id->product == HID_ANY_ID || id->product == hdev->product);
1228}
1229
1230const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1231		const struct hid_device_id *id)
1232{
1233	for (; id->bus; id++)
1234		if (hid_match_one_id(hdev, id))
1235			return id;
1236
1237	return NULL;
1238}
1239
1240static const struct hid_device_id hid_hiddev_list[] = {
1241	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1242	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
1243	{ }
1244};
1245
1246static bool hid_hiddev(struct hid_device *hdev)
1247{
1248	return !!hid_match_id(hdev, hid_hiddev_list);
1249}
1250
1251
1252static ssize_t
1253read_report_descriptor(struct file *filp, struct kobject *kobj,
1254		struct bin_attribute *attr,
1255		char *buf, loff_t off, size_t count)
1256{
1257	struct device *dev = container_of(kobj, struct device, kobj);
1258	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1259
1260	if (off >= hdev->rsize)
1261		return 0;
1262
1263	if (off + count > hdev->rsize)
1264		count = hdev->rsize - off;
1265
1266	memcpy(buf, hdev->rdesc + off, count);
1267
1268	return count;
1269}
1270
1271static struct bin_attribute dev_bin_attr_report_desc = {
1272	.attr = { .name = "report_descriptor", .mode = 0444 },
1273	.read = read_report_descriptor,
1274	.size = HID_MAX_DESCRIPTOR_SIZE,
1275};
1276
1277int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1278{
1279	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1280		"Joystick", "Gamepad", "Keyboard", "Keypad",
1281		"Multi-Axis Controller"
1282	};
1283	const char *type, *bus;
1284	char buf[64];
1285	unsigned int i;
1286	int len;
1287	int ret;
1288
1289	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1290		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
1291	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
1292		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
1293	if (hdev->bus != BUS_USB)
1294		connect_mask &= ~HID_CONNECT_HIDDEV;
1295	if (hid_hiddev(hdev))
1296		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
1297
1298	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1299				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1300		hdev->claimed |= HID_CLAIMED_INPUT;
1301	if (hdev->quirks & HID_QUIRK_MULTITOUCH) {
1302		/* this device should be handled by hid-multitouch, skip it */
1303		return -ENODEV;
1304	}
1305
1306	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1307			!hdev->hiddev_connect(hdev,
1308				connect_mask & HID_CONNECT_HIDDEV_FORCE))
1309		hdev->claimed |= HID_CLAIMED_HIDDEV;
1310	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1311		hdev->claimed |= HID_CLAIMED_HIDRAW;
1312
1313	if (!hdev->claimed) {
1314		hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
1315		return -ENODEV;
1316	}
1317
1318	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1319			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1320		hdev->ff_init(hdev);
1321
1322	len = 0;
1323	if (hdev->claimed & HID_CLAIMED_INPUT)
1324		len += sprintf(buf + len, "input");
1325	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1326		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1327				hdev->minor);
1328	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1329		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1330				((struct hidraw *)hdev->hidraw)->minor);
1331
1332	type = "Device";
1333	for (i = 0; i < hdev->maxcollection; i++) {
1334		struct hid_collection *col = &hdev->collection[i];
1335		if (col->type == HID_COLLECTION_APPLICATION &&
1336		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1337		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1338			type = types[col->usage & 0xffff];
1339			break;
1340		}
1341	}
1342
1343	switch (hdev->bus) {
1344	case BUS_USB:
1345		bus = "USB";
1346		break;
1347	case BUS_BLUETOOTH:
1348		bus = "BLUETOOTH";
1349		break;
1350	default:
1351		bus = "<UNKNOWN>";
1352	}
1353
1354	ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1355	if (ret)
1356		hid_warn(hdev,
1357			 "can't create sysfs report descriptor attribute err: %d\n", ret);
1358
1359	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1360		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1361		 type, hdev->name, hdev->phys);
1362
1363	return 0;
1364}
1365EXPORT_SYMBOL_GPL(hid_connect);
1366
1367void hid_disconnect(struct hid_device *hdev)
1368{
1369	device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1370	if (hdev->claimed & HID_CLAIMED_INPUT)
1371		hidinput_disconnect(hdev);
1372	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1373		hdev->hiddev_disconnect(hdev);
1374	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1375		hidraw_disconnect(hdev);
1376}
1377EXPORT_SYMBOL_GPL(hid_disconnect);
1378
1379/* a list of devices for which there is a specialized driver on HID bus */
1380static const struct hid_device_id hid_have_special_driver[] = {
1381	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
1382	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
1383	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1384	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1385	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1386	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1387	{ HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, USB_DEVICE_ID_ACTIONSTAR_1011) },
1388	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
1389	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1390	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1391	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1392	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
1393	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1394	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1395	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1396	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1397	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1398	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1399	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1400	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1401	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1402	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1403	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1404	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1405	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1406	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
1407	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1408	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1409	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1410	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1411	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1412	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1413	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1414	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1415	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
1416	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1417	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1418	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1419	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1420	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1421	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1422	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1423	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1424	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
1425	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1426	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1427	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1428	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1429	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1430	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1431	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1432	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1433	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1434	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1435	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1436	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
1437	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
1438	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
1439	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
1440	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1441	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1442	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
1443	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
1444	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
1445	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
1446	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1447	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1448	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1449	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
1450	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1451	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1452	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1453	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1454	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1455	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1456	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
1457	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
1458	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1459	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
1460	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1461	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1462	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1463	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1464	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1465	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
1466	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
1467	{ HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
1468	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
1469	{ HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, USB_DEVICE_ID_CVTOUCH_SCREEN) },
1470	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1471	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1472	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
1473	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1474	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
1475	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1476	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
1477	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1478	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1479	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1480	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7224) },
1481	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_725E) },
1482	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1483	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1484	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1485	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
1486	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1487	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) },
1488	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
1489	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1490	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_FRUCTEL, USB_DEVICE_ID_GAMETEL_MT_MODE) },
1491	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1492	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
1493	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1494	{ HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, USB_DEVICE_ID_GOODTOUCH_000f) },
1495	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
1496	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1497	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
1498	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1499	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1500	{ HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
1501	{ HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT, USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1502 	{ HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, USB_DEVICE_ID_IDEACOM_IDC6650) },
1503	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
1504	{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1505	{ HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1506	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1507	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
1508	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1509	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
1510	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
1511	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
1512	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
1513	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
1514	{ HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MULTITOUCH) },
1515	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1516	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1517	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1518	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1519	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1520	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1521	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
1522	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1523	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
1524	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1525	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
1526	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1527	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1528	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1529	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1530	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1531	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
1532	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1533	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1534	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1535	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1536	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
1537	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1538	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
1539#if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
1540	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
1541	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
1542#endif
1543	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1544	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
1545	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
1546	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1547	{ HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH) },
1548	{ HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
1549	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1550	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
1551	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
1552	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1553	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1554	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1555	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1556	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
1557	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1558	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1559	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
1560	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
1561	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
1562	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
1563	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
1564	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
1565	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
1566	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
1567	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
1568	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
1569	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
1570	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
1571	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
1572	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
1573	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
1574	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
1575	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
1576	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
1577	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1578	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1579	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
1580	{ HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC, USB_DEVICE_ID_PANABOARD_UBT780) },
1581	{ HID_USB_DEVICE(USB_VENDOR_ID_PANASONIC, USB_DEVICE_ID_PANABOARD_UBT880) },
1582	{ HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) },
1583	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1584	{ HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1585	{ HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1586	{ HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1587	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
1588	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1589	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
1590	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1591	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1592	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
1593	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
1594	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
1595	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
1596	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
1597	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
1598	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1599	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1600	{ HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1601	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1602	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1603	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1604	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1605	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1606	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1607	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
1608	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1609	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1610	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
1611	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
1612	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1613	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
1614	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1615	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1616	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1617	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
1618	{ HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
1619	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
1620	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1621	{ HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1622	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
1623	{ HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
1624	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1625	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1626	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1627	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
1628	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1629	{ HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1630	{ HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
1631	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1632	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
1633	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
1634	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
1635	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
1636	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
1637	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
1638	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
1639	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
1640	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
1641	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
1642	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
1643	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
1644	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1645	{ HID_USB_DEVICE(USB_VENDOR_ID_XAT, USB_DEVICE_ID_XAT_CSR) },
1646	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX) },
1647	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX) },
1648	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR) },
1649	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX1) },
1650	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX1) },
1651	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR1) },
1652	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX2) },
1653	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX2) },
1654	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR2) },
1655	{ HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1656	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1657	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1658	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
1659
1660	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
1661	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1662	{ }
1663};
1664
1665struct hid_dynid {
1666	struct list_head list;
1667	struct hid_device_id id;
1668};
1669
1670/**
1671 * store_new_id - add a new HID device ID to this driver and re-probe devices
1672 * @driver: target device driver
1673 * @buf: buffer for scanning device ID data
1674 * @count: input size
1675 *
1676 * Adds a new dynamic hid device ID to this driver,
1677 * and causes the driver to probe for all devices again.
1678 */
1679static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1680		size_t count)
1681{
1682	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1683	struct hid_dynid *dynid;
1684	__u32 bus, vendor, product;
1685	unsigned long driver_data = 0;
1686	int ret;
1687
1688	ret = sscanf(buf, "%x %x %x %lx",
1689			&bus, &vendor, &product, &driver_data);
1690	if (ret < 3)
1691		return -EINVAL;
1692
1693	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
1694	if (!dynid)
1695		return -ENOMEM;
1696
1697	dynid->id.bus = bus;
1698	dynid->id.group = HID_GROUP_ANY;
1699	dynid->id.vendor = vendor;
1700	dynid->id.product = product;
1701	dynid->id.driver_data = driver_data;
1702
1703	spin_lock(&hdrv->dyn_lock);
1704	list_add_tail(&dynid->list, &hdrv->dyn_list);
1705	spin_unlock(&hdrv->dyn_lock);
1706
1707	ret = driver_attach(&hdrv->driver);
1708
1709	return ret ? : count;
1710}
1711static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
1712
1713static void hid_free_dynids(struct hid_driver *hdrv)
1714{
1715	struct hid_dynid *dynid, *n;
1716
1717	spin_lock(&hdrv->dyn_lock);
1718	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
1719		list_del(&dynid->list);
1720		kfree(dynid);
1721	}
1722	spin_unlock(&hdrv->dyn_lock);
1723}
1724
1725static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
1726		struct hid_driver *hdrv)
1727{
1728	struct hid_dynid *dynid;
1729
1730	spin_lock(&hdrv->dyn_lock);
1731	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
1732		if (hid_match_one_id(hdev, &dynid->id)) {
1733			spin_unlock(&hdrv->dyn_lock);
1734			return &dynid->id;
1735		}
1736	}
1737	spin_unlock(&hdrv->dyn_lock);
1738
1739	return hid_match_id(hdev, hdrv->id_table);
1740}
1741
1742static int hid_bus_match(struct device *dev, struct device_driver *drv)
1743{
1744	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1745	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1746
1747	if ((hdev->quirks & HID_QUIRK_MULTITOUCH) &&
1748		!strncmp(hdrv->name, "hid-multitouch", 14))
1749		return 1;
1750
1751	if (!hid_match_device(hdev, hdrv))
1752		return 0;
1753
1754	/* generic wants all that don't have specialized driver */
1755	if (!strncmp(hdrv->name, "generic-", 8) && !hid_ignore_special_drivers)
1756		return !hid_match_id(hdev, hid_have_special_driver);
1757
1758	return 1;
1759}
1760
1761static int hid_device_probe(struct device *dev)
1762{
1763	struct hid_driver *hdrv = container_of(dev->driver,
1764			struct hid_driver, driver);
1765	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1766	const struct hid_device_id *id;
1767	int ret = 0;
1768
1769	if (down_interruptible(&hdev->driver_lock))
1770		return -EINTR;
1771
1772	if (!hdev->driver) {
1773		id = hid_match_device(hdev, hdrv);
1774		if (id == NULL) {
1775			if (!((hdev->quirks & HID_QUIRK_MULTITOUCH) &&
1776				!strncmp(hdrv->name, "hid-multitouch", 14))) {
1777				ret = -ENODEV;
1778				goto unlock;
1779			}
1780		}
1781
1782		hdev->driver = hdrv;
1783		if (hdrv->probe) {
1784			ret = hdrv->probe(hdev, id);
1785		} else { /* default probe */
1786			ret = hid_open_report(hdev);
1787			if (!ret)
1788				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1789		}
1790		if (ret) {
1791			hid_close_report(hdev);
1792			hdev->driver = NULL;
1793		}
1794	}
1795unlock:
1796	up(&hdev->driver_lock);
1797	return ret;
1798}
1799
1800static int hid_device_remove(struct device *dev)
1801{
1802	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1803	struct hid_driver *hdrv;
1804
1805	if (down_interruptible(&hdev->driver_lock))
1806		return -EINTR;
1807
1808	hdrv = hdev->driver;
1809	if (hdrv) {
1810		if (hdrv->remove)
1811			hdrv->remove(hdev);
1812		else /* default remove */
1813			hid_hw_stop(hdev);
1814		hid_close_report(hdev);
1815		hdev->driver = NULL;
1816	}
1817
1818	up(&hdev->driver_lock);
1819	return 0;
1820}
1821
1822static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
1823			     char *buf)
1824{
1825	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1826	int len;
1827
1828	len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
1829		       hdev->bus, hdev->group, hdev->vendor, hdev->product);
1830
1831	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
1832}
1833
1834static struct device_attribute hid_dev_attrs[] = {
1835	__ATTR_RO(modalias),
1836	__ATTR_NULL,
1837};
1838
1839static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1840{
1841	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1842
1843	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1844			hdev->bus, hdev->vendor, hdev->product))
1845		return -ENOMEM;
1846
1847	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1848		return -ENOMEM;
1849
1850	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1851		return -ENOMEM;
1852
1853	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1854		return -ENOMEM;
1855
1856	if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
1857			   hdev->bus, hdev->group, hdev->vendor, hdev->product))
1858		return -ENOMEM;
1859
1860	return 0;
1861}
1862
1863static struct bus_type hid_bus_type = {
1864	.name		= "hid",
1865	.dev_attrs	= hid_dev_attrs,
1866	.match		= hid_bus_match,
1867	.probe		= hid_device_probe,
1868	.remove		= hid_device_remove,
1869	.uevent		= hid_uevent,
1870};
1871
1872/* a list of devices that shouldn't be handled by HID core at all */
1873static const struct hid_device_id hid_ignore_list[] = {
1874	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1875	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1876	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1877	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1878	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1879	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1880	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1881	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1882	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1883	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1884	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1885	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
1886	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1887	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
1888	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1889	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1890	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1891	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1892	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1893	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1894	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
1895	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1896	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1897	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1898	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
1899	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
1900	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
1901	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1902	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1903	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1904	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1905	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1906	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1907	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1908	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1909	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1910	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1911	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1912	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1913	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1914	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1915	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1916	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1917	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1918	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1919	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1920	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1921	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1922	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1923	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1924	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1925	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1926	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1927	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1928	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1929	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1930	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1931	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1932	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1933	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1934	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1935	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1936	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1937	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1938	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1939	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1940	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1941	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1942	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1943	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1944	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1945	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1946	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1947	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1948	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1949	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1950	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1951	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1952	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1953	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1954	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1955	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1956	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1957	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1958	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1959	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1960	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1961	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1962	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1963	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1964	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1965	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1966	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1967	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1968	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1969	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1970	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1971	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1972	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
1973	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1974	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
1975	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1976	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
1977	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
1978	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
1979	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
1980	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
1981	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
1982	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1983	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1984	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1985	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
1986	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
1987	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
1988	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1989	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1990	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
1991	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1992	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1993	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1994	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1995	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1996	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
1997	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
1998	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
1999	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
2000	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
2001	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
2002	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
2003	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
2004	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
2005	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
2006	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
2007	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
2008	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
2009	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
2010	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
2011	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
2012	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
2013	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
2014	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
2015	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
2016	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
2017	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
2018	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
2019	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
2020	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
2021	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
2022	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
2023	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
2024#if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
2025	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
2026	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
2027	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
2028	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
2029	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
2030	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
2031	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
2032	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
2033#endif
2034	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
2035	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
2036	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
2037	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
2038	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
2039	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
2040	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
2041	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
2042	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
2043	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
2044	{ }
2045};
2046
2047/**
2048 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
2049 *
2050 * There are composite devices for which we want to ignore only a certain
2051 * interface. This is a list of devices for which only the mouse interface will
2052 * be ignored. This allows a dedicated driver to take care of the interface.
2053 */
2054static const struct hid_device_id hid_mouse_ignore_list[] = {
2055	/* appletouch driver */
2056	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
2057	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
2058	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
2059	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
2060	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
2061	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
2062	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
2063	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
2064	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
2065	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
2066	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
2067	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
2068	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
2069	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
2070	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
2071	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
2072	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
2073	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
2074	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
2075	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
2076	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
2077	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
2078	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
2079	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
2080	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
2081	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
2082	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
2083	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
2084	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
2085	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
2086	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
2087	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
2088	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
2089	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
2090	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
2091	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
2092	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
2093	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
2094	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
2095	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
2096	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
2097	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2098	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
2099	{ }
2100};
2101
2102static bool hid_ignore(struct hid_device *hdev)
2103{
2104	switch (hdev->vendor) {
2105	case USB_VENDOR_ID_CODEMERCS:
2106		/* ignore all Code Mercenaries IOWarrior devices */
2107		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
2108				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
2109			return true;
2110		break;
2111	case USB_VENDOR_ID_LOGITECH:
2112		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
2113				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
2114			return true;
2115		/*
2116		 * The Keene FM transmitter USB device has the same USB ID as
2117		 * the Logitech AudioHub Speaker, but it should ignore the hid.
2118		 * Check if the name is that of the Keene device.
2119		 * For reference: the name of the AudioHub is
2120		 * "HOLTEK  AudioHub Speaker".
2121		 */
2122		if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
2123			!strcmp(hdev->name, "HOLTEK  B-LINK USB Audio  "))
2124				return true;
2125		break;
2126	case USB_VENDOR_ID_SOUNDGRAPH:
2127		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
2128		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
2129			return true;
2130		break;
2131	case USB_VENDOR_ID_HANWANG:
2132		if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
2133		    hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
2134			return true;
2135		break;
2136	case USB_VENDOR_ID_JESS:
2137		if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
2138				hdev->type == HID_TYPE_USBNONE)
2139			return true;
2140	break;
2141	}
2142
2143	if (hdev->type == HID_TYPE_USBMOUSE &&
2144			hid_match_id(hdev, hid_mouse_ignore_list))
2145		return true;
2146
2147	return !!hid_match_id(hdev, hid_ignore_list);
2148}
2149
2150int hid_add_device(struct hid_device *hdev)
2151{
2152	static atomic_t id = ATOMIC_INIT(0);
2153	int ret;
2154
2155	if (WARN_ON(hdev->status & HID_STAT_ADDED))
2156		return -EBUSY;
2157
2158	/* we need to kill them here, otherwise they will stay allocated to
2159	 * wait for coming driver */
2160	if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
2161            && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
2162		return -ENODEV;
2163
2164	/*
2165	 * Read the device report descriptor once and use as template
2166	 * for the driver-specific modifications.
2167	 */
2168	ret = hdev->ll_driver->parse(hdev);
2169	if (ret)
2170		return ret;
2171	if (!hdev->dev_rdesc)
2172		return -ENODEV;
2173
2174	/* XXX hack, any other cleaner solution after the driver core
2175	 * is converted to allow more than 20 bytes as the device name? */
2176	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
2177		     hdev->vendor, hdev->product, atomic_inc_return(&id));
2178
2179	hid_debug_register(hdev, dev_name(&hdev->dev));
2180	ret = device_add(&hdev->dev);
2181	if (!ret)
2182		hdev->status |= HID_STAT_ADDED;
2183	else
2184		hid_debug_unregister(hdev);
2185
2186	return ret;
2187}
2188EXPORT_SYMBOL_GPL(hid_add_device);
2189
2190/**
2191 * hid_allocate_device - allocate new hid device descriptor
2192 *
2193 * Allocate and initialize hid device, so that hid_destroy_device might be
2194 * used to free it.
2195 *
2196 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
2197 * error value.
2198 */
2199struct hid_device *hid_allocate_device(void)
2200{
2201	struct hid_device *hdev;
2202	int ret = -ENOMEM;
2203
2204	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
2205	if (hdev == NULL)
2206		return ERR_PTR(ret);
2207
2208	device_initialize(&hdev->dev);
2209	hdev->dev.release = hid_device_release;
2210	hdev->dev.bus = &hid_bus_type;
2211
2212	hid_close_report(hdev);
2213
2214	init_waitqueue_head(&hdev->debug_wait);
2215	INIT_LIST_HEAD(&hdev->debug_list);
2216	sema_init(&hdev->driver_lock, 1);
2217
2218	return hdev;
2219}
2220EXPORT_SYMBOL_GPL(hid_allocate_device);
2221
2222static void hid_remove_device(struct hid_device *hdev)
2223{
2224	if (hdev->status & HID_STAT_ADDED) {
2225		device_del(&hdev->dev);
2226		hid_debug_unregister(hdev);
2227		hdev->status &= ~HID_STAT_ADDED;
2228	}
2229	kfree(hdev->dev_rdesc);
2230	hdev->dev_rdesc = NULL;
2231	hdev->dev_rsize = 0;
2232}
2233
2234/**
2235 * hid_destroy_device - free previously allocated device
2236 *
2237 * @hdev: hid device
2238 *
2239 * If you allocate hid_device through hid_allocate_device, you should ever
2240 * free by this function.
2241 */
2242void hid_destroy_device(struct hid_device *hdev)
2243{
2244	hid_remove_device(hdev);
2245	put_device(&hdev->dev);
2246}
2247EXPORT_SYMBOL_GPL(hid_destroy_device);
2248
2249int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
2250		const char *mod_name)
2251{
2252	int ret;
2253
2254	hdrv->driver.name = hdrv->name;
2255	hdrv->driver.bus = &hid_bus_type;
2256	hdrv->driver.owner = owner;
2257	hdrv->driver.mod_name = mod_name;
2258
2259	INIT_LIST_HEAD(&hdrv->dyn_list);
2260	spin_lock_init(&hdrv->dyn_lock);
2261
2262	ret = driver_register(&hdrv->driver);
2263	if (ret)
2264		return ret;
2265
2266	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
2267	if (ret)
2268		driver_unregister(&hdrv->driver);
2269
2270	return ret;
2271}
2272EXPORT_SYMBOL_GPL(__hid_register_driver);
2273
2274void hid_unregister_driver(struct hid_driver *hdrv)
2275{
2276	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
2277	driver_unregister(&hdrv->driver);
2278	hid_free_dynids(hdrv);
2279}
2280EXPORT_SYMBOL_GPL(hid_unregister_driver);
2281
2282int hid_check_keys_pressed(struct hid_device *hid)
2283{
2284	struct hid_input *hidinput;
2285	int i;
2286
2287	if (!(hid->claimed & HID_CLAIMED_INPUT))
2288		return 0;
2289
2290	list_for_each_entry(hidinput, &hid->inputs, list) {
2291		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
2292			if (hidinput->input->key[i])
2293				return 1;
2294	}
2295
2296	return 0;
2297}
2298
2299EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
2300
2301static int __init hid_init(void)
2302{
2303	int ret;
2304
2305	if (hid_debug)
2306		pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
2307			"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2308
2309	ret = bus_register(&hid_bus_type);
2310	if (ret) {
2311		pr_err("can't register hid bus\n");
2312		goto err;
2313	}
2314
2315	ret = hidraw_init();
2316	if (ret)
2317		goto err_bus;
2318
2319	hid_debug_init();
2320
2321	return 0;
2322err_bus:
2323	bus_unregister(&hid_bus_type);
2324err:
2325	return ret;
2326}
2327
2328static void __exit hid_exit(void)
2329{
2330	hid_debug_exit();
2331	hidraw_exit();
2332	bus_unregister(&hid_bus_type);
2333}
2334
2335module_init(hid_init);
2336module_exit(hid_exit);
2337
2338MODULE_AUTHOR("Andreas Gal");
2339MODULE_AUTHOR("Vojtech Pavlik");
2340MODULE_AUTHOR("Jiri Kosina");
2341MODULE_LICENSE(DRIVER_LICENSE);
2342
2343