xref: /openbmc/linux/drivers/hid/hid-core.c (revision 11576c6114c3b6505aea2e0c988bedb856a0e20c)
1dde5845aSJiri Kosina /*
2229695e5SJiri Kosina  *  HID support for Linux
3dde5845aSJiri Kosina  *
4dde5845aSJiri Kosina  *  Copyright (c) 1999 Andreas Gal
5dde5845aSJiri Kosina  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6dde5845aSJiri Kosina  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
77d39e849SJiri Kosina  *  Copyright (c) 2006-2010 Jiri Kosina
8dde5845aSJiri Kosina  */
9dde5845aSJiri Kosina 
10dde5845aSJiri Kosina /*
11dde5845aSJiri Kosina  * This program is free software; you can redistribute it and/or modify it
12dde5845aSJiri Kosina  * under the terms of the GNU General Public License as published by the Free
13dde5845aSJiri Kosina  * Software Foundation; either version 2 of the License, or (at your option)
14dde5845aSJiri Kosina  * any later version.
15dde5845aSJiri Kosina  */
16dde5845aSJiri Kosina 
174291ee30SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
184291ee30SJoe Perches 
19dde5845aSJiri Kosina #include <linux/module.h>
20dde5845aSJiri Kosina #include <linux/slab.h>
21dde5845aSJiri Kosina #include <linux/init.h>
22dde5845aSJiri Kosina #include <linux/kernel.h>
23dde5845aSJiri Kosina #include <linux/list.h>
24dde5845aSJiri Kosina #include <linux/mm.h>
25dde5845aSJiri Kosina #include <linux/spinlock.h>
26dde5845aSJiri Kosina #include <asm/unaligned.h>
27dde5845aSJiri Kosina #include <asm/byteorder.h>
28dde5845aSJiri Kosina #include <linux/input.h>
29dde5845aSJiri Kosina #include <linux/wait.h>
3047a80edbSJiri Kosina #include <linux/vmalloc.h>
31c4124c9bSJiri Kosina #include <linux/sched.h>
324ea54542SDavid Herrmann #include <linux/semaphore.h>
33dde5845aSJiri Kosina 
34dde5845aSJiri Kosina #include <linux/hid.h>
35dde5845aSJiri Kosina #include <linux/hiddev.h>
36c080d89aSJiri Kosina #include <linux/hid-debug.h>
3786166b7bSJiri Kosina #include <linux/hidraw.h>
38dde5845aSJiri Kosina 
395f22a799SJiri Slaby #include "hid-ids.h"
405f22a799SJiri Slaby 
41dde5845aSJiri Kosina /*
42dde5845aSJiri Kosina  * Version Information
43dde5845aSJiri Kosina  */
44dde5845aSJiri Kosina 
4553149801SJiri Kosina #define DRIVER_DESC "HID core driver"
46dde5845aSJiri Kosina #define DRIVER_LICENSE "GPL"
47dde5845aSJiri Kosina 
4858037eb9SJiri Kosina int hid_debug = 0;
49377e10fbSAnssi Hannula module_param_named(debug, hid_debug, int, 0600);
50cd667ce2SJiri Kosina MODULE_PARM_DESC(debug, "toggle HID debugging messages");
5158037eb9SJiri Kosina EXPORT_SYMBOL_GPL(hid_debug);
5258037eb9SJiri Kosina 
53dde5845aSJiri Kosina /*
54dde5845aSJiri Kosina  * Register a new report for a device.
55dde5845aSJiri Kosina  */
56dde5845aSJiri Kosina 
5790a006abSMichael Poole struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
58dde5845aSJiri Kosina {
59dde5845aSJiri Kosina 	struct hid_report_enum *report_enum = device->report_enum + type;
60dde5845aSJiri Kosina 	struct hid_report *report;
61dde5845aSJiri Kosina 
62dde5845aSJiri Kosina 	if (report_enum->report_id_hash[id])
63dde5845aSJiri Kosina 		return report_enum->report_id_hash[id];
64dde5845aSJiri Kosina 
65a3789a17SJoe Perches 	report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
66a3789a17SJoe Perches 	if (!report)
67dde5845aSJiri Kosina 		return NULL;
68dde5845aSJiri Kosina 
69dde5845aSJiri Kosina 	if (id != 0)
70dde5845aSJiri Kosina 		report_enum->numbered = 1;
71dde5845aSJiri Kosina 
72dde5845aSJiri Kosina 	report->id = id;
73dde5845aSJiri Kosina 	report->type = type;
74dde5845aSJiri Kosina 	report->size = 0;
75dde5845aSJiri Kosina 	report->device = device;
76dde5845aSJiri Kosina 	report_enum->report_id_hash[id] = report;
77dde5845aSJiri Kosina 
78dde5845aSJiri Kosina 	list_add_tail(&report->list, &report_enum->report_list);
79dde5845aSJiri Kosina 
80dde5845aSJiri Kosina 	return report;
81dde5845aSJiri Kosina }
8290a006abSMichael Poole EXPORT_SYMBOL_GPL(hid_register_report);
83dde5845aSJiri Kosina 
84dde5845aSJiri Kosina /*
85dde5845aSJiri Kosina  * Register a new field for this report.
86dde5845aSJiri Kosina  */
87dde5845aSJiri Kosina 
88dde5845aSJiri Kosina static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
89dde5845aSJiri Kosina {
90dde5845aSJiri Kosina 	struct hid_field *field;
91dde5845aSJiri Kosina 
92dde5845aSJiri Kosina 	if (report->maxfield == HID_MAX_FIELDS) {
9358037eb9SJiri Kosina 		dbg_hid("too many fields in report\n");
94dde5845aSJiri Kosina 		return NULL;
95dde5845aSJiri Kosina 	}
96dde5845aSJiri Kosina 
97a3789a17SJoe Perches 	field = kzalloc((sizeof(struct hid_field) +
98a3789a17SJoe Perches 			 usages * sizeof(struct hid_usage) +
99a3789a17SJoe Perches 			 values * sizeof(unsigned)), GFP_KERNEL);
100a3789a17SJoe Perches 	if (!field)
101a3789a17SJoe Perches 		return NULL;
102dde5845aSJiri Kosina 
103dde5845aSJiri Kosina 	field->index = report->maxfield++;
104dde5845aSJiri Kosina 	report->field[field->index] = field;
105dde5845aSJiri Kosina 	field->usage = (struct hid_usage *)(field + 1);
106282bfd4cSJiri Slaby 	field->value = (s32 *)(field->usage + usages);
107dde5845aSJiri Kosina 	field->report = report;
108dde5845aSJiri Kosina 
109dde5845aSJiri Kosina 	return field;
110dde5845aSJiri Kosina }
111dde5845aSJiri Kosina 
112dde5845aSJiri Kosina /*
113dde5845aSJiri Kosina  * Open a collection. The type/usage is pushed on the stack.
114dde5845aSJiri Kosina  */
115dde5845aSJiri Kosina 
116dde5845aSJiri Kosina static int open_collection(struct hid_parser *parser, unsigned type)
117dde5845aSJiri Kosina {
118dde5845aSJiri Kosina 	struct hid_collection *collection;
119dde5845aSJiri Kosina 	unsigned usage;
120dde5845aSJiri Kosina 
121dde5845aSJiri Kosina 	usage = parser->local.usage[0];
122dde5845aSJiri Kosina 
123dde5845aSJiri Kosina 	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
12458037eb9SJiri Kosina 		dbg_hid("collection stack overflow\n");
125dde5845aSJiri Kosina 		return -1;
126dde5845aSJiri Kosina 	}
127dde5845aSJiri Kosina 
128dde5845aSJiri Kosina 	if (parser->device->maxcollection == parser->device->collection_size) {
129dde5845aSJiri Kosina 		collection = kmalloc(sizeof(struct hid_collection) *
130dde5845aSJiri Kosina 				parser->device->collection_size * 2, GFP_KERNEL);
131dde5845aSJiri Kosina 		if (collection == NULL) {
13258037eb9SJiri Kosina 			dbg_hid("failed to reallocate collection array\n");
133dde5845aSJiri Kosina 			return -1;
134dde5845aSJiri Kosina 		}
135dde5845aSJiri Kosina 		memcpy(collection, parser->device->collection,
136dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
137dde5845aSJiri Kosina 			parser->device->collection_size);
138dde5845aSJiri Kosina 		memset(collection + parser->device->collection_size, 0,
139dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
140dde5845aSJiri Kosina 			parser->device->collection_size);
141dde5845aSJiri Kosina 		kfree(parser->device->collection);
142dde5845aSJiri Kosina 		parser->device->collection = collection;
143dde5845aSJiri Kosina 		parser->device->collection_size *= 2;
144dde5845aSJiri Kosina 	}
145dde5845aSJiri Kosina 
146dde5845aSJiri Kosina 	parser->collection_stack[parser->collection_stack_ptr++] =
147dde5845aSJiri Kosina 		parser->device->maxcollection;
148dde5845aSJiri Kosina 
149dde5845aSJiri Kosina 	collection = parser->device->collection +
150dde5845aSJiri Kosina 		parser->device->maxcollection++;
151dde5845aSJiri Kosina 	collection->type = type;
152dde5845aSJiri Kosina 	collection->usage = usage;
153dde5845aSJiri Kosina 	collection->level = parser->collection_stack_ptr - 1;
154dde5845aSJiri Kosina 
155dde5845aSJiri Kosina 	if (type == HID_COLLECTION_APPLICATION)
156dde5845aSJiri Kosina 		parser->device->maxapplication++;
157dde5845aSJiri Kosina 
158dde5845aSJiri Kosina 	return 0;
159dde5845aSJiri Kosina }
160dde5845aSJiri Kosina 
161dde5845aSJiri Kosina /*
162dde5845aSJiri Kosina  * Close a collection.
163dde5845aSJiri Kosina  */
164dde5845aSJiri Kosina 
165dde5845aSJiri Kosina static int close_collection(struct hid_parser *parser)
166dde5845aSJiri Kosina {
167dde5845aSJiri Kosina 	if (!parser->collection_stack_ptr) {
16858037eb9SJiri Kosina 		dbg_hid("collection stack underflow\n");
169dde5845aSJiri Kosina 		return -1;
170dde5845aSJiri Kosina 	}
171dde5845aSJiri Kosina 	parser->collection_stack_ptr--;
172dde5845aSJiri Kosina 	return 0;
173dde5845aSJiri Kosina }
174dde5845aSJiri Kosina 
175dde5845aSJiri Kosina /*
176dde5845aSJiri Kosina  * Climb up the stack, search for the specified collection type
177dde5845aSJiri Kosina  * and return the usage.
178dde5845aSJiri Kosina  */
179dde5845aSJiri Kosina 
180dde5845aSJiri Kosina static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
181dde5845aSJiri Kosina {
182504499f2SJoe Perches 	struct hid_collection *collection = parser->device->collection;
183dde5845aSJiri Kosina 	int n;
184504499f2SJoe Perches 
185504499f2SJoe Perches 	for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
186504499f2SJoe Perches 		unsigned index = parser->collection_stack[n];
187504499f2SJoe Perches 		if (collection[index].type == type)
188504499f2SJoe Perches 			return collection[index].usage;
189504499f2SJoe Perches 	}
190dde5845aSJiri Kosina 	return 0; /* we know nothing about this usage type */
191dde5845aSJiri Kosina }
192dde5845aSJiri Kosina 
193dde5845aSJiri Kosina /*
194dde5845aSJiri Kosina  * Add a usage to the temporary parser table.
195dde5845aSJiri Kosina  */
196dde5845aSJiri Kosina 
197dde5845aSJiri Kosina static int hid_add_usage(struct hid_parser *parser, unsigned usage)
198dde5845aSJiri Kosina {
199dde5845aSJiri Kosina 	if (parser->local.usage_index >= HID_MAX_USAGES) {
20058037eb9SJiri Kosina 		dbg_hid("usage index exceeded\n");
201dde5845aSJiri Kosina 		return -1;
202dde5845aSJiri Kosina 	}
203dde5845aSJiri Kosina 	parser->local.usage[parser->local.usage_index] = usage;
204dde5845aSJiri Kosina 	parser->local.collection_index[parser->local.usage_index] =
205dde5845aSJiri Kosina 		parser->collection_stack_ptr ?
206dde5845aSJiri Kosina 		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
207dde5845aSJiri Kosina 	parser->local.usage_index++;
208dde5845aSJiri Kosina 	return 0;
209dde5845aSJiri Kosina }
210dde5845aSJiri Kosina 
211dde5845aSJiri Kosina /*
212dde5845aSJiri Kosina  * Register a new field for this report.
213dde5845aSJiri Kosina  */
214dde5845aSJiri Kosina 
215dde5845aSJiri Kosina static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
216dde5845aSJiri Kosina {
217dde5845aSJiri Kosina 	struct hid_report *report;
218dde5845aSJiri Kosina 	struct hid_field *field;
219dde5845aSJiri Kosina 	int usages;
220dde5845aSJiri Kosina 	unsigned offset;
221dde5845aSJiri Kosina 	int i;
222dde5845aSJiri Kosina 
223a3789a17SJoe Perches 	report = hid_register_report(parser->device, report_type, parser->global.report_id);
224a3789a17SJoe Perches 	if (!report) {
22558037eb9SJiri Kosina 		dbg_hid("hid_register_report failed\n");
226dde5845aSJiri Kosina 		return -1;
227dde5845aSJiri Kosina 	}
228dde5845aSJiri Kosina 
229dde5845aSJiri Kosina 	if (parser->global.logical_maximum < parser->global.logical_minimum) {
23058037eb9SJiri Kosina 		dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
231dde5845aSJiri Kosina 		return -1;
232dde5845aSJiri Kosina 	}
233dde5845aSJiri Kosina 
234dde5845aSJiri Kosina 	offset = report->size;
235dde5845aSJiri Kosina 	report->size += parser->global.report_size * parser->global.report_count;
236dde5845aSJiri Kosina 
237dde5845aSJiri Kosina 	if (!parser->local.usage_index) /* Ignore padding fields */
238dde5845aSJiri Kosina 		return 0;
239dde5845aSJiri Kosina 
240dde5845aSJiri Kosina 	usages = max_t(int, parser->local.usage_index, parser->global.report_count);
241dde5845aSJiri Kosina 
242a3789a17SJoe Perches 	field = hid_register_field(report, usages, parser->global.report_count);
243a3789a17SJoe Perches 	if (!field)
244dde5845aSJiri Kosina 		return 0;
245dde5845aSJiri Kosina 
246dde5845aSJiri Kosina 	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
247dde5845aSJiri Kosina 	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
248dde5845aSJiri Kosina 	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
249dde5845aSJiri Kosina 
250dde5845aSJiri Kosina 	for (i = 0; i < usages; i++) {
251dde5845aSJiri Kosina 		int j = i;
252dde5845aSJiri Kosina 		/* Duplicate the last usage we parsed if we have excess values */
253dde5845aSJiri Kosina 		if (i >= parser->local.usage_index)
254dde5845aSJiri Kosina 			j = parser->local.usage_index - 1;
255dde5845aSJiri Kosina 		field->usage[i].hid = parser->local.usage[j];
256dde5845aSJiri Kosina 		field->usage[i].collection_index =
257dde5845aSJiri Kosina 			parser->local.collection_index[j];
258dde5845aSJiri Kosina 	}
259dde5845aSJiri Kosina 
260dde5845aSJiri Kosina 	field->maxusage = usages;
261dde5845aSJiri Kosina 	field->flags = flags;
262dde5845aSJiri Kosina 	field->report_offset = offset;
263dde5845aSJiri Kosina 	field->report_type = report_type;
264dde5845aSJiri Kosina 	field->report_size = parser->global.report_size;
265dde5845aSJiri Kosina 	field->report_count = parser->global.report_count;
266dde5845aSJiri Kosina 	field->logical_minimum = parser->global.logical_minimum;
267dde5845aSJiri Kosina 	field->logical_maximum = parser->global.logical_maximum;
268dde5845aSJiri Kosina 	field->physical_minimum = parser->global.physical_minimum;
269dde5845aSJiri Kosina 	field->physical_maximum = parser->global.physical_maximum;
270dde5845aSJiri Kosina 	field->unit_exponent = parser->global.unit_exponent;
271dde5845aSJiri Kosina 	field->unit = parser->global.unit;
272dde5845aSJiri Kosina 
273dde5845aSJiri Kosina 	return 0;
274dde5845aSJiri Kosina }
275dde5845aSJiri Kosina 
276dde5845aSJiri Kosina /*
277dde5845aSJiri Kosina  * Read data value from item.
278dde5845aSJiri Kosina  */
279dde5845aSJiri Kosina 
280dde5845aSJiri Kosina static u32 item_udata(struct hid_item *item)
281dde5845aSJiri Kosina {
282dde5845aSJiri Kosina 	switch (item->size) {
283dde5845aSJiri Kosina 	case 1: return item->data.u8;
284dde5845aSJiri Kosina 	case 2: return item->data.u16;
285dde5845aSJiri Kosina 	case 4: return item->data.u32;
286dde5845aSJiri Kosina 	}
287dde5845aSJiri Kosina 	return 0;
288dde5845aSJiri Kosina }
289dde5845aSJiri Kosina 
290dde5845aSJiri Kosina static s32 item_sdata(struct hid_item *item)
291dde5845aSJiri Kosina {
292dde5845aSJiri Kosina 	switch (item->size) {
293dde5845aSJiri Kosina 	case 1: return item->data.s8;
294dde5845aSJiri Kosina 	case 2: return item->data.s16;
295dde5845aSJiri Kosina 	case 4: return item->data.s32;
296dde5845aSJiri Kosina 	}
297dde5845aSJiri Kosina 	return 0;
298dde5845aSJiri Kosina }
299dde5845aSJiri Kosina 
300dde5845aSJiri Kosina /*
301dde5845aSJiri Kosina  * Process a global item.
302dde5845aSJiri Kosina  */
303dde5845aSJiri Kosina 
304dde5845aSJiri Kosina static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
305dde5845aSJiri Kosina {
306dde5845aSJiri Kosina 	switch (item->tag) {
307dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PUSH:
308dde5845aSJiri Kosina 
309dde5845aSJiri Kosina 		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
31025985edcSLucas De Marchi 			dbg_hid("global environment stack overflow\n");
311dde5845aSJiri Kosina 			return -1;
312dde5845aSJiri Kosina 		}
313dde5845aSJiri Kosina 
314dde5845aSJiri Kosina 		memcpy(parser->global_stack + parser->global_stack_ptr++,
315dde5845aSJiri Kosina 			&parser->global, sizeof(struct hid_global));
316dde5845aSJiri Kosina 		return 0;
317dde5845aSJiri Kosina 
318dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_POP:
319dde5845aSJiri Kosina 
320dde5845aSJiri Kosina 		if (!parser->global_stack_ptr) {
32125985edcSLucas De Marchi 			dbg_hid("global environment stack underflow\n");
322dde5845aSJiri Kosina 			return -1;
323dde5845aSJiri Kosina 		}
324dde5845aSJiri Kosina 
325880d29f1SJiri Slaby 		memcpy(&parser->global, parser->global_stack +
326880d29f1SJiri Slaby 			--parser->global_stack_ptr, sizeof(struct hid_global));
327dde5845aSJiri Kosina 		return 0;
328dde5845aSJiri Kosina 
329dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
330dde5845aSJiri Kosina 		parser->global.usage_page = item_udata(item);
331dde5845aSJiri Kosina 		return 0;
332dde5845aSJiri Kosina 
333dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
334dde5845aSJiri Kosina 		parser->global.logical_minimum = item_sdata(item);
335dde5845aSJiri Kosina 		return 0;
336dde5845aSJiri Kosina 
337dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
338dde5845aSJiri Kosina 		if (parser->global.logical_minimum < 0)
339dde5845aSJiri Kosina 			parser->global.logical_maximum = item_sdata(item);
340dde5845aSJiri Kosina 		else
341dde5845aSJiri Kosina 			parser->global.logical_maximum = item_udata(item);
342dde5845aSJiri Kosina 		return 0;
343dde5845aSJiri Kosina 
344dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
345dde5845aSJiri Kosina 		parser->global.physical_minimum = item_sdata(item);
346dde5845aSJiri Kosina 		return 0;
347dde5845aSJiri Kosina 
348dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
349dde5845aSJiri Kosina 		if (parser->global.physical_minimum < 0)
350dde5845aSJiri Kosina 			parser->global.physical_maximum = item_sdata(item);
351dde5845aSJiri Kosina 		else
352dde5845aSJiri Kosina 			parser->global.physical_maximum = item_udata(item);
353dde5845aSJiri Kosina 		return 0;
354dde5845aSJiri Kosina 
355dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
356dde5845aSJiri Kosina 		parser->global.unit_exponent = item_sdata(item);
357dde5845aSJiri Kosina 		return 0;
358dde5845aSJiri Kosina 
359dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT:
360dde5845aSJiri Kosina 		parser->global.unit = item_udata(item);
361dde5845aSJiri Kosina 		return 0;
362dde5845aSJiri Kosina 
363dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
364880d29f1SJiri Slaby 		parser->global.report_size = item_udata(item);
365880d29f1SJiri Slaby 		if (parser->global.report_size > 32) {
366880d29f1SJiri Slaby 			dbg_hid("invalid report_size %d\n",
367880d29f1SJiri Slaby 					parser->global.report_size);
368dde5845aSJiri Kosina 			return -1;
369dde5845aSJiri Kosina 		}
370dde5845aSJiri Kosina 		return 0;
371dde5845aSJiri Kosina 
372dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
373880d29f1SJiri Slaby 		parser->global.report_count = item_udata(item);
374880d29f1SJiri Slaby 		if (parser->global.report_count > HID_MAX_USAGES) {
375880d29f1SJiri Slaby 			dbg_hid("invalid report_count %d\n",
376880d29f1SJiri Slaby 					parser->global.report_count);
377dde5845aSJiri Kosina 			return -1;
378dde5845aSJiri Kosina 		}
379dde5845aSJiri Kosina 		return 0;
380dde5845aSJiri Kosina 
381dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
382880d29f1SJiri Slaby 		parser->global.report_id = item_udata(item);
383880d29f1SJiri Slaby 		if (parser->global.report_id == 0) {
38458037eb9SJiri Kosina 			dbg_hid("report_id 0 is invalid\n");
385dde5845aSJiri Kosina 			return -1;
386dde5845aSJiri Kosina 		}
387dde5845aSJiri Kosina 		return 0;
388dde5845aSJiri Kosina 
389dde5845aSJiri Kosina 	default:
39058037eb9SJiri Kosina 		dbg_hid("unknown global tag 0x%x\n", item->tag);
391dde5845aSJiri Kosina 		return -1;
392dde5845aSJiri Kosina 	}
393dde5845aSJiri Kosina }
394dde5845aSJiri Kosina 
395dde5845aSJiri Kosina /*
396dde5845aSJiri Kosina  * Process a local item.
397dde5845aSJiri Kosina  */
398dde5845aSJiri Kosina 
399dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
400dde5845aSJiri Kosina {
401dde5845aSJiri Kosina 	__u32 data;
402dde5845aSJiri Kosina 	unsigned n;
403dde5845aSJiri Kosina 
404dde5845aSJiri Kosina 	data = item_udata(item);
405dde5845aSJiri Kosina 
406dde5845aSJiri Kosina 	switch (item->tag) {
407dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_DELIMITER:
408dde5845aSJiri Kosina 
409dde5845aSJiri Kosina 		if (data) {
410dde5845aSJiri Kosina 			/*
411dde5845aSJiri Kosina 			 * We treat items before the first delimiter
412dde5845aSJiri Kosina 			 * as global to all usage sets (branch 0).
413dde5845aSJiri Kosina 			 * In the moment we process only these global
414dde5845aSJiri Kosina 			 * items and the first delimiter set.
415dde5845aSJiri Kosina 			 */
416dde5845aSJiri Kosina 			if (parser->local.delimiter_depth != 0) {
41758037eb9SJiri Kosina 				dbg_hid("nested delimiters\n");
418dde5845aSJiri Kosina 				return -1;
419dde5845aSJiri Kosina 			}
420dde5845aSJiri Kosina 			parser->local.delimiter_depth++;
421dde5845aSJiri Kosina 			parser->local.delimiter_branch++;
422dde5845aSJiri Kosina 		} else {
423dde5845aSJiri Kosina 			if (parser->local.delimiter_depth < 1) {
42458037eb9SJiri Kosina 				dbg_hid("bogus close delimiter\n");
425dde5845aSJiri Kosina 				return -1;
426dde5845aSJiri Kosina 			}
427dde5845aSJiri Kosina 			parser->local.delimiter_depth--;
428dde5845aSJiri Kosina 		}
429dde5845aSJiri Kosina 		return 1;
430dde5845aSJiri Kosina 
431dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE:
432dde5845aSJiri Kosina 
433dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
43458037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
435dde5845aSJiri Kosina 			return 0;
436dde5845aSJiri Kosina 		}
437dde5845aSJiri Kosina 
438dde5845aSJiri Kosina 		if (item->size <= 2)
439dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
440dde5845aSJiri Kosina 
441dde5845aSJiri Kosina 		return hid_add_usage(parser, data);
442dde5845aSJiri Kosina 
443dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
444dde5845aSJiri Kosina 
445dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
44658037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
447dde5845aSJiri Kosina 			return 0;
448dde5845aSJiri Kosina 		}
449dde5845aSJiri Kosina 
450dde5845aSJiri Kosina 		if (item->size <= 2)
451dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
452dde5845aSJiri Kosina 
453dde5845aSJiri Kosina 		parser->local.usage_minimum = data;
454dde5845aSJiri Kosina 		return 0;
455dde5845aSJiri Kosina 
456dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
457dde5845aSJiri Kosina 
458dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
45958037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
460dde5845aSJiri Kosina 			return 0;
461dde5845aSJiri Kosina 		}
462dde5845aSJiri Kosina 
463dde5845aSJiri Kosina 		if (item->size <= 2)
464dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
465dde5845aSJiri Kosina 
466dde5845aSJiri Kosina 		for (n = parser->local.usage_minimum; n <= data; n++)
467dde5845aSJiri Kosina 			if (hid_add_usage(parser, n)) {
46858037eb9SJiri Kosina 				dbg_hid("hid_add_usage failed\n");
469dde5845aSJiri Kosina 				return -1;
470dde5845aSJiri Kosina 			}
471dde5845aSJiri Kosina 		return 0;
472dde5845aSJiri Kosina 
473dde5845aSJiri Kosina 	default:
474dde5845aSJiri Kosina 
47558037eb9SJiri Kosina 		dbg_hid("unknown local item tag 0x%x\n", item->tag);
476dde5845aSJiri Kosina 		return 0;
477dde5845aSJiri Kosina 	}
478dde5845aSJiri Kosina 	return 0;
479dde5845aSJiri Kosina }
480dde5845aSJiri Kosina 
481dde5845aSJiri Kosina /*
482dde5845aSJiri Kosina  * Process a main item.
483dde5845aSJiri Kosina  */
484dde5845aSJiri Kosina 
485dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
486dde5845aSJiri Kosina {
487dde5845aSJiri Kosina 	__u32 data;
488dde5845aSJiri Kosina 	int ret;
489dde5845aSJiri Kosina 
490dde5845aSJiri Kosina 	data = item_udata(item);
491dde5845aSJiri Kosina 
492dde5845aSJiri Kosina 	switch (item->tag) {
493dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
494dde5845aSJiri Kosina 		ret = open_collection(parser, data & 0xff);
495dde5845aSJiri Kosina 		break;
496dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
497dde5845aSJiri Kosina 		ret = close_collection(parser);
498dde5845aSJiri Kosina 		break;
499dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_INPUT:
500dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
501dde5845aSJiri Kosina 		break;
502dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_OUTPUT:
503dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
504dde5845aSJiri Kosina 		break;
505dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_FEATURE:
506dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
507dde5845aSJiri Kosina 		break;
508dde5845aSJiri Kosina 	default:
50958037eb9SJiri Kosina 		dbg_hid("unknown main item tag 0x%x\n", item->tag);
510dde5845aSJiri Kosina 		ret = 0;
511dde5845aSJiri Kosina 	}
512dde5845aSJiri Kosina 
513dde5845aSJiri Kosina 	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
514dde5845aSJiri Kosina 
515dde5845aSJiri Kosina 	return ret;
516dde5845aSJiri Kosina }
517dde5845aSJiri Kosina 
518dde5845aSJiri Kosina /*
519dde5845aSJiri Kosina  * Process a reserved item.
520dde5845aSJiri Kosina  */
521dde5845aSJiri Kosina 
522dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
523dde5845aSJiri Kosina {
52458037eb9SJiri Kosina 	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
525dde5845aSJiri Kosina 	return 0;
526dde5845aSJiri Kosina }
527dde5845aSJiri Kosina 
528dde5845aSJiri Kosina /*
529dde5845aSJiri Kosina  * Free a report and all registered fields. The field->usage and
530dde5845aSJiri Kosina  * field->value table's are allocated behind the field, so we need
531dde5845aSJiri Kosina  * only to free(field) itself.
532dde5845aSJiri Kosina  */
533dde5845aSJiri Kosina 
534dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report)
535dde5845aSJiri Kosina {
536dde5845aSJiri Kosina 	unsigned n;
537dde5845aSJiri Kosina 
538dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
539dde5845aSJiri Kosina 		kfree(report->field[n]);
540dde5845aSJiri Kosina 	kfree(report);
541dde5845aSJiri Kosina }
542dde5845aSJiri Kosina 
543dde5845aSJiri Kosina /*
544dde5845aSJiri Kosina  * Free a device structure, all reports, and all fields.
545dde5845aSJiri Kosina  */
546dde5845aSJiri Kosina 
54785cdaf52SJiri Slaby static void hid_device_release(struct device *dev)
548dde5845aSJiri Kosina {
54985cdaf52SJiri Slaby 	struct hid_device *device = container_of(dev, struct hid_device, dev);
550dde5845aSJiri Kosina 	unsigned i, j;
551dde5845aSJiri Kosina 
552dde5845aSJiri Kosina 	for (i = 0; i < HID_REPORT_TYPES; i++) {
553dde5845aSJiri Kosina 		struct hid_report_enum *report_enum = device->report_enum + i;
554dde5845aSJiri Kosina 
555dde5845aSJiri Kosina 		for (j = 0; j < 256; j++) {
556dde5845aSJiri Kosina 			struct hid_report *report = report_enum->report_id_hash[j];
557dde5845aSJiri Kosina 			if (report)
558dde5845aSJiri Kosina 				hid_free_report(report);
559dde5845aSJiri Kosina 		}
560dde5845aSJiri Kosina 	}
561dde5845aSJiri Kosina 
562dde5845aSJiri Kosina 	kfree(device->rdesc);
563767fe787SJiri Kosina 	kfree(device->collection);
564dde5845aSJiri Kosina 	kfree(device);
565dde5845aSJiri Kosina }
566dde5845aSJiri Kosina 
567dde5845aSJiri Kosina /*
568dde5845aSJiri Kosina  * Fetch a report description item from the data stream. We support long
569dde5845aSJiri Kosina  * items, though they are not used yet.
570dde5845aSJiri Kosina  */
571dde5845aSJiri Kosina 
572dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
573dde5845aSJiri Kosina {
574dde5845aSJiri Kosina 	u8 b;
575dde5845aSJiri Kosina 
576dde5845aSJiri Kosina 	if ((end - start) <= 0)
577dde5845aSJiri Kosina 		return NULL;
578dde5845aSJiri Kosina 
579dde5845aSJiri Kosina 	b = *start++;
580dde5845aSJiri Kosina 
581dde5845aSJiri Kosina 	item->type = (b >> 2) & 3;
582dde5845aSJiri Kosina 	item->tag  = (b >> 4) & 15;
583dde5845aSJiri Kosina 
584dde5845aSJiri Kosina 	if (item->tag == HID_ITEM_TAG_LONG) {
585dde5845aSJiri Kosina 
586dde5845aSJiri Kosina 		item->format = HID_ITEM_FORMAT_LONG;
587dde5845aSJiri Kosina 
588dde5845aSJiri Kosina 		if ((end - start) < 2)
589dde5845aSJiri Kosina 			return NULL;
590dde5845aSJiri Kosina 
591dde5845aSJiri Kosina 		item->size = *start++;
592dde5845aSJiri Kosina 		item->tag  = *start++;
593dde5845aSJiri Kosina 
594dde5845aSJiri Kosina 		if ((end - start) < item->size)
595dde5845aSJiri Kosina 			return NULL;
596dde5845aSJiri Kosina 
597dde5845aSJiri Kosina 		item->data.longdata = start;
598dde5845aSJiri Kosina 		start += item->size;
599dde5845aSJiri Kosina 		return start;
600dde5845aSJiri Kosina 	}
601dde5845aSJiri Kosina 
602dde5845aSJiri Kosina 	item->format = HID_ITEM_FORMAT_SHORT;
603dde5845aSJiri Kosina 	item->size = b & 3;
604dde5845aSJiri Kosina 
605dde5845aSJiri Kosina 	switch (item->size) {
606dde5845aSJiri Kosina 	case 0:
607dde5845aSJiri Kosina 		return start;
608dde5845aSJiri Kosina 
609dde5845aSJiri Kosina 	case 1:
610dde5845aSJiri Kosina 		if ((end - start) < 1)
611dde5845aSJiri Kosina 			return NULL;
612dde5845aSJiri Kosina 		item->data.u8 = *start++;
613dde5845aSJiri Kosina 		return start;
614dde5845aSJiri Kosina 
615dde5845aSJiri Kosina 	case 2:
616dde5845aSJiri Kosina 		if ((end - start) < 2)
617dde5845aSJiri Kosina 			return NULL;
618c105068fSHarvey Harrison 		item->data.u16 = get_unaligned_le16(start);
619dde5845aSJiri Kosina 		start = (__u8 *)((__le16 *)start + 1);
620dde5845aSJiri Kosina 		return start;
621dde5845aSJiri Kosina 
622dde5845aSJiri Kosina 	case 3:
623dde5845aSJiri Kosina 		item->size++;
624dde5845aSJiri Kosina 		if ((end - start) < 4)
625dde5845aSJiri Kosina 			return NULL;
626c105068fSHarvey Harrison 		item->data.u32 = get_unaligned_le32(start);
627dde5845aSJiri Kosina 		start = (__u8 *)((__le32 *)start + 1);
628dde5845aSJiri Kosina 		return start;
629dde5845aSJiri Kosina 	}
630dde5845aSJiri Kosina 
631dde5845aSJiri Kosina 	return NULL;
632dde5845aSJiri Kosina }
633dde5845aSJiri Kosina 
63485cdaf52SJiri Slaby /**
63585cdaf52SJiri Slaby  * hid_parse_report - parse device report
63685cdaf52SJiri Slaby  *
63785cdaf52SJiri Slaby  * @device: hid device
63885cdaf52SJiri Slaby  * @start: report start
63985cdaf52SJiri Slaby  * @size: report size
64085cdaf52SJiri Slaby  *
641dde5845aSJiri Kosina  * Parse a report description into a hid_device structure. Reports are
642dde5845aSJiri Kosina  * enumerated, fields are attached to these reports.
64385cdaf52SJiri Slaby  * 0 returned on success, otherwise nonzero error value.
644dde5845aSJiri Kosina  */
64585cdaf52SJiri Slaby int hid_parse_report(struct hid_device *device, __u8 *start,
64685cdaf52SJiri Slaby 		unsigned size)
647dde5845aSJiri Kosina {
648dde5845aSJiri Kosina 	struct hid_parser *parser;
649dde5845aSJiri Kosina 	struct hid_item item;
650dde5845aSJiri Kosina 	__u8 *end;
65185cdaf52SJiri Slaby 	int ret;
652dde5845aSJiri Kosina 	static int (*dispatch_type[])(struct hid_parser *parser,
653dde5845aSJiri Kosina 				      struct hid_item *item) = {
654dde5845aSJiri Kosina 		hid_parser_main,
655dde5845aSJiri Kosina 		hid_parser_global,
656dde5845aSJiri Kosina 		hid_parser_local,
657dde5845aSJiri Kosina 		hid_parser_reserved
658dde5845aSJiri Kosina 	};
659dde5845aSJiri Kosina 
660c500c971SJiri Slaby 	if (device->driver->report_fixup)
66173e4008dSNikolai Kondrashov 		start = device->driver->report_fixup(device, start, &size);
662c500c971SJiri Slaby 
6631721a238SJulia Lawall 	device->rdesc = kmemdup(start, size, GFP_KERNEL);
66485cdaf52SJiri Slaby 	if (device->rdesc == NULL)
66585cdaf52SJiri Slaby 		return -ENOMEM;
666dde5845aSJiri Kosina 	device->rsize = size;
667dde5845aSJiri Kosina 
668fe258020SJoe Perches 	parser = vzalloc(sizeof(struct hid_parser));
66985cdaf52SJiri Slaby 	if (!parser) {
67085cdaf52SJiri Slaby 		ret = -ENOMEM;
67185cdaf52SJiri Slaby 		goto err;
672dde5845aSJiri Kosina 	}
67385cdaf52SJiri Slaby 
674dde5845aSJiri Kosina 	parser->device = device;
675dde5845aSJiri Kosina 
676dde5845aSJiri Kosina 	end = start + size;
67785cdaf52SJiri Slaby 	ret = -EINVAL;
678dde5845aSJiri Kosina 	while ((start = fetch_item(start, end, &item)) != NULL) {
679dde5845aSJiri Kosina 
680dde5845aSJiri Kosina 		if (item.format != HID_ITEM_FORMAT_SHORT) {
68158037eb9SJiri Kosina 			dbg_hid("unexpected long global item\n");
68285cdaf52SJiri Slaby 			goto err;
683dde5845aSJiri Kosina 		}
684dde5845aSJiri Kosina 
685dde5845aSJiri Kosina 		if (dispatch_type[item.type](parser, &item)) {
68658037eb9SJiri Kosina 			dbg_hid("item %u %u %u %u parsing failed\n",
6874291ee30SJoe Perches 				item.format, (unsigned)item.size,
6884291ee30SJoe Perches 				(unsigned)item.type, (unsigned)item.tag);
68985cdaf52SJiri Slaby 			goto err;
690dde5845aSJiri Kosina 		}
691dde5845aSJiri Kosina 
692dde5845aSJiri Kosina 		if (start == end) {
693dde5845aSJiri Kosina 			if (parser->collection_stack_ptr) {
69458037eb9SJiri Kosina 				dbg_hid("unbalanced collection at end of report description\n");
69585cdaf52SJiri Slaby 				goto err;
696dde5845aSJiri Kosina 			}
697dde5845aSJiri Kosina 			if (parser->local.delimiter_depth) {
69858037eb9SJiri Kosina 				dbg_hid("unbalanced delimiter at end of report description\n");
69985cdaf52SJiri Slaby 				goto err;
700dde5845aSJiri Kosina 			}
70147a80edbSJiri Kosina 			vfree(parser);
70285cdaf52SJiri Slaby 			return 0;
703dde5845aSJiri Kosina 		}
704dde5845aSJiri Kosina 	}
705dde5845aSJiri Kosina 
70658037eb9SJiri Kosina 	dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
70785cdaf52SJiri Slaby err:
70847a80edbSJiri Kosina 	vfree(parser);
70985cdaf52SJiri Slaby 	return ret;
710dde5845aSJiri Kosina }
711229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_parse_report);
712dde5845aSJiri Kosina 
713dde5845aSJiri Kosina /*
714dde5845aSJiri Kosina  * Convert a signed n-bit integer to signed 32-bit integer. Common
715dde5845aSJiri Kosina  * cases are done through the compiler, the screwed things has to be
716dde5845aSJiri Kosina  * done by hand.
717dde5845aSJiri Kosina  */
718dde5845aSJiri Kosina 
719dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n)
720dde5845aSJiri Kosina {
721dde5845aSJiri Kosina 	switch (n) {
722dde5845aSJiri Kosina 	case 8:  return ((__s8)value);
723dde5845aSJiri Kosina 	case 16: return ((__s16)value);
724dde5845aSJiri Kosina 	case 32: return ((__s32)value);
725dde5845aSJiri Kosina 	}
726dde5845aSJiri Kosina 	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
727dde5845aSJiri Kosina }
728dde5845aSJiri Kosina 
729dde5845aSJiri Kosina /*
730dde5845aSJiri Kosina  * Convert a signed 32-bit integer to a signed n-bit integer.
731dde5845aSJiri Kosina  */
732dde5845aSJiri Kosina 
733dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n)
734dde5845aSJiri Kosina {
735dde5845aSJiri Kosina 	s32 a = value >> (n - 1);
736dde5845aSJiri Kosina 	if (a && a != -1)
737dde5845aSJiri Kosina 		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
738dde5845aSJiri Kosina 	return value & ((1 << n) - 1);
739dde5845aSJiri Kosina }
740dde5845aSJiri Kosina 
741dde5845aSJiri Kosina /*
742dde5845aSJiri Kosina  * Extract/implement a data field from/to a little endian report (bit array).
743dde5845aSJiri Kosina  *
744dde5845aSJiri Kosina  * Code sort-of follows HID spec:
745dde5845aSJiri Kosina  *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
746dde5845aSJiri Kosina  *
747dde5845aSJiri Kosina  * While the USB HID spec allows unlimited length bit fields in "report
748dde5845aSJiri Kosina  * descriptors", most devices never use more than 16 bits.
749dde5845aSJiri Kosina  * One model of UPS is claimed to report "LINEV" as a 32-bit field.
750dde5845aSJiri Kosina  * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
751dde5845aSJiri Kosina  */
752dde5845aSJiri Kosina 
75316ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report,
7544291ee30SJoe Perches 		     unsigned offset, unsigned n)
755dde5845aSJiri Kosina {
756dde5845aSJiri Kosina 	u64 x;
757dde5845aSJiri Kosina 
758c4124c9bSJiri Kosina 	if (n > 32)
7594291ee30SJoe Perches 		hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
760c4124c9bSJiri Kosina 			 n, current->comm);
761dde5845aSJiri Kosina 
762dde5845aSJiri Kosina 	report += offset >> 3;  /* adjust byte index */
763dde5845aSJiri Kosina 	offset &= 7;            /* now only need bit offset into one byte */
764c105068fSHarvey Harrison 	x = get_unaligned_le64(report);
765dde5845aSJiri Kosina 	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
766dde5845aSJiri Kosina 	return (u32) x;
767dde5845aSJiri Kosina }
768dde5845aSJiri Kosina 
769dde5845aSJiri Kosina /*
770dde5845aSJiri Kosina  * "implement" : set bits in a little endian bit stream.
771dde5845aSJiri Kosina  * Same concepts as "extract" (see comments above).
772dde5845aSJiri Kosina  * The data mangled in the bit stream remains in little endian
773dde5845aSJiri Kosina  * order the whole time. It make more sense to talk about
774dde5845aSJiri Kosina  * endianness of register values by considering a register
775dde5845aSJiri Kosina  * a "cached" copy of the little endiad bit stream.
776dde5845aSJiri Kosina  */
77716ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report,
7784291ee30SJoe Perches 		      unsigned offset, unsigned n, __u32 value)
779dde5845aSJiri Kosina {
7806f0168d2SHarvey Harrison 	u64 x;
781dde5845aSJiri Kosina 	u64 m = (1ULL << n) - 1;
782dde5845aSJiri Kosina 
783c4124c9bSJiri Kosina 	if (n > 32)
7844291ee30SJoe Perches 		hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
7854291ee30SJoe Perches 			 __func__, n, current->comm);
786dde5845aSJiri Kosina 
787c4124c9bSJiri Kosina 	if (value > m)
7884291ee30SJoe Perches 		hid_warn(hid, "%s() called with too large value %d! (%s)\n",
7894291ee30SJoe Perches 			 __func__, value, current->comm);
790dde5845aSJiri Kosina 	WARN_ON(value > m);
791dde5845aSJiri Kosina 	value &= m;
792dde5845aSJiri Kosina 
793dde5845aSJiri Kosina 	report += offset >> 3;
794dde5845aSJiri Kosina 	offset &= 7;
795dde5845aSJiri Kosina 
7966f0168d2SHarvey Harrison 	x = get_unaligned_le64(report);
7976f0168d2SHarvey Harrison 	x &= ~(m << offset);
7986f0168d2SHarvey Harrison 	x |= ((u64)value) << offset;
7996f0168d2SHarvey Harrison 	put_unaligned_le64(x, report);
800dde5845aSJiri Kosina }
801dde5845aSJiri Kosina 
802dde5845aSJiri Kosina /*
803dde5845aSJiri Kosina  * Search an array for a value.
804dde5845aSJiri Kosina  */
805dde5845aSJiri Kosina 
80616ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n)
807dde5845aSJiri Kosina {
808dde5845aSJiri Kosina 	while (n--) {
809dde5845aSJiri Kosina 		if (*array++ == value)
810dde5845aSJiri Kosina 			return 0;
811dde5845aSJiri Kosina 	}
812dde5845aSJiri Kosina 	return -1;
813dde5845aSJiri Kosina }
814dde5845aSJiri Kosina 
81585cdaf52SJiri Slaby /**
81685cdaf52SJiri Slaby  * hid_match_report - check if driver's raw_event should be called
81785cdaf52SJiri Slaby  *
81885cdaf52SJiri Slaby  * @hid: hid device
81985cdaf52SJiri Slaby  * @report_type: type to match against
82085cdaf52SJiri Slaby  *
82185cdaf52SJiri Slaby  * compare hid->driver->report_table->report_type to report->type
82285cdaf52SJiri Slaby  */
82385cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report)
824dde5845aSJiri Kosina {
82585cdaf52SJiri Slaby 	const struct hid_report_id *id = hid->driver->report_table;
82685cdaf52SJiri Slaby 
82785cdaf52SJiri Slaby 	if (!id) /* NULL means all */
82885cdaf52SJiri Slaby 		return 1;
82985cdaf52SJiri Slaby 
83085cdaf52SJiri Slaby 	for (; id->report_type != HID_TERMINATOR; id++)
83185cdaf52SJiri Slaby 		if (id->report_type == HID_ANY_ID ||
83285cdaf52SJiri Slaby 				id->report_type == report->type)
83385cdaf52SJiri Slaby 			return 1;
83485cdaf52SJiri Slaby 	return 0;
83585cdaf52SJiri Slaby }
83685cdaf52SJiri Slaby 
83785cdaf52SJiri Slaby /**
83885cdaf52SJiri Slaby  * hid_match_usage - check if driver's event should be called
83985cdaf52SJiri Slaby  *
84085cdaf52SJiri Slaby  * @hid: hid device
84185cdaf52SJiri Slaby  * @usage: usage to match against
84285cdaf52SJiri Slaby  *
84385cdaf52SJiri Slaby  * compare hid->driver->usage_table->usage_{type,code} to
84485cdaf52SJiri Slaby  * usage->usage_{type,code}
84585cdaf52SJiri Slaby  */
84685cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
84785cdaf52SJiri Slaby {
84885cdaf52SJiri Slaby 	const struct hid_usage_id *id = hid->driver->usage_table;
84985cdaf52SJiri Slaby 
85085cdaf52SJiri Slaby 	if (!id) /* NULL means all */
85185cdaf52SJiri Slaby 		return 1;
85285cdaf52SJiri Slaby 
85385cdaf52SJiri Slaby 	for (; id->usage_type != HID_ANY_ID - 1; id++)
85485cdaf52SJiri Slaby 		if ((id->usage_hid == HID_ANY_ID ||
85585cdaf52SJiri Slaby 				id->usage_hid == usage->hid) &&
85685cdaf52SJiri Slaby 				(id->usage_type == HID_ANY_ID ||
85785cdaf52SJiri Slaby 				id->usage_type == usage->type) &&
85885cdaf52SJiri Slaby 				(id->usage_code == HID_ANY_ID ||
85985cdaf52SJiri Slaby 				 id->usage_code == usage->code))
86085cdaf52SJiri Slaby 			return 1;
86185cdaf52SJiri Slaby 	return 0;
86285cdaf52SJiri Slaby }
86385cdaf52SJiri Slaby 
86485cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field,
86585cdaf52SJiri Slaby 		struct hid_usage *usage, __s32 value, int interrupt)
86685cdaf52SJiri Slaby {
86785cdaf52SJiri Slaby 	struct hid_driver *hdrv = hid->driver;
86885cdaf52SJiri Slaby 	int ret;
86985cdaf52SJiri Slaby 
870cd667ce2SJiri Kosina 	hid_dump_input(hid, usage, value);
87185cdaf52SJiri Slaby 
87285cdaf52SJiri Slaby 	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
87385cdaf52SJiri Slaby 		ret = hdrv->event(hid, field, usage, value);
87485cdaf52SJiri Slaby 		if (ret != 0) {
87585cdaf52SJiri Slaby 			if (ret < 0)
87685cdaf52SJiri Slaby 				dbg_hid("%s's event failed with %d\n",
87785cdaf52SJiri Slaby 						hdrv->name, ret);
87885cdaf52SJiri Slaby 			return;
87985cdaf52SJiri Slaby 		}
88085cdaf52SJiri Slaby 	}
88185cdaf52SJiri Slaby 
882dde5845aSJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
883dde5845aSJiri Kosina 		hidinput_hid_event(hid, field, usage, value);
884aa938f79SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
885aa938f79SJiri Kosina 		hid->hiddev_hid_event(hid, field, usage, value);
886dde5845aSJiri Kosina }
887dde5845aSJiri Kosina 
888dde5845aSJiri Kosina /*
889dde5845aSJiri Kosina  * Analyse a received field, and fetch the data from it. The field
890dde5845aSJiri Kosina  * content is stored for next report processing (we do differential
891dde5845aSJiri Kosina  * reporting to the layer).
892dde5845aSJiri Kosina  */
893dde5845aSJiri Kosina 
894abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field,
895abdff0f7SAdrian Bunk 			    __u8 *data, int interrupt)
896dde5845aSJiri Kosina {
897dde5845aSJiri Kosina 	unsigned n;
898dde5845aSJiri Kosina 	unsigned count = field->report_count;
899dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
900dde5845aSJiri Kosina 	unsigned size = field->report_size;
901dde5845aSJiri Kosina 	__s32 min = field->logical_minimum;
902dde5845aSJiri Kosina 	__s32 max = field->logical_maximum;
903dde5845aSJiri Kosina 	__s32 *value;
904dde5845aSJiri Kosina 
905a3789a17SJoe Perches 	value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
906a3789a17SJoe Perches 	if (!value)
907dde5845aSJiri Kosina 		return;
908dde5845aSJiri Kosina 
909dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
910dde5845aSJiri Kosina 
9114291ee30SJoe Perches 		value[n] = min < 0 ?
9124291ee30SJoe Perches 			snto32(extract(hid, data, offset + n * size, size),
9134291ee30SJoe Perches 			       size) :
9144291ee30SJoe Perches 			extract(hid, data, offset + n * size, size);
915dde5845aSJiri Kosina 
9164291ee30SJoe Perches 		/* Ignore report if ErrorRollOver */
9174291ee30SJoe Perches 		if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
9184291ee30SJoe Perches 		    value[n] >= min && value[n] <= max &&
9194291ee30SJoe Perches 		    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
920dde5845aSJiri Kosina 			goto exit;
921dde5845aSJiri Kosina 	}
922dde5845aSJiri Kosina 
923dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
924dde5845aSJiri Kosina 
925dde5845aSJiri Kosina 		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
926dde5845aSJiri Kosina 			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
927dde5845aSJiri Kosina 			continue;
928dde5845aSJiri Kosina 		}
929dde5845aSJiri Kosina 
930dde5845aSJiri Kosina 		if (field->value[n] >= min && field->value[n] <= max
931dde5845aSJiri Kosina 			&& field->usage[field->value[n] - min].hid
932dde5845aSJiri Kosina 			&& search(value, field->value[n], count))
933dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
934dde5845aSJiri Kosina 
935dde5845aSJiri Kosina 		if (value[n] >= min && value[n] <= max
936dde5845aSJiri Kosina 			&& field->usage[value[n] - min].hid
937dde5845aSJiri Kosina 			&& search(field->value, value[n], count))
938dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
939dde5845aSJiri Kosina 	}
940dde5845aSJiri Kosina 
941dde5845aSJiri Kosina 	memcpy(field->value, value, count * sizeof(__s32));
942dde5845aSJiri Kosina exit:
943dde5845aSJiri Kosina 	kfree(value);
944dde5845aSJiri Kosina }
945dde5845aSJiri Kosina 
946dde5845aSJiri Kosina /*
947dde5845aSJiri Kosina  * Output the field into the report.
948dde5845aSJiri Kosina  */
949dde5845aSJiri Kosina 
9504291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid,
9514291ee30SJoe Perches 			     struct hid_field *field, __u8 *data)
952dde5845aSJiri Kosina {
953dde5845aSJiri Kosina 	unsigned count = field->report_count;
954dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
955dde5845aSJiri Kosina 	unsigned size = field->report_size;
956dde5845aSJiri Kosina 	unsigned n;
957dde5845aSJiri Kosina 
958dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
959dde5845aSJiri Kosina 		if (field->logical_minimum < 0)	/* signed values */
9604291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
9614291ee30SJoe Perches 				  s32ton(field->value[n], size));
962dde5845aSJiri Kosina 		else				/* unsigned values */
9634291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
9644291ee30SJoe Perches 				  field->value[n]);
965dde5845aSJiri Kosina 	}
966dde5845aSJiri Kosina }
967dde5845aSJiri Kosina 
968dde5845aSJiri Kosina /*
969dde5845aSJiri Kosina  * Create a report.
970dde5845aSJiri Kosina  */
971dde5845aSJiri Kosina 
972229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data)
973dde5845aSJiri Kosina {
974dde5845aSJiri Kosina 	unsigned n;
975dde5845aSJiri Kosina 
976dde5845aSJiri Kosina 	if (report->id > 0)
977dde5845aSJiri Kosina 		*data++ = report->id;
978dde5845aSJiri Kosina 
97975c28df8SPete Zaitcev 	memset(data, 0, ((report->size - 1) >> 3) + 1);
980dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
9814291ee30SJoe Perches 		hid_output_field(report->device, report->field[n], data);
982dde5845aSJiri Kosina }
983229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report);
984dde5845aSJiri Kosina 
985dde5845aSJiri Kosina /*
986dde5845aSJiri Kosina  * Set a field value. The report this field belongs to has to be
987dde5845aSJiri Kosina  * created and transferred to the device, to set this value in the
988dde5845aSJiri Kosina  * device.
989dde5845aSJiri Kosina  */
990dde5845aSJiri Kosina 
991dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
992dde5845aSJiri Kosina {
993dde5845aSJiri Kosina 	unsigned size = field->report_size;
994dde5845aSJiri Kosina 
995cd667ce2SJiri Kosina 	hid_dump_input(field->report->device, field->usage + offset, value);
996dde5845aSJiri Kosina 
997dde5845aSJiri Kosina 	if (offset >= field->report_count) {
99858037eb9SJiri Kosina 		dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
999dde5845aSJiri Kosina 		return -1;
1000dde5845aSJiri Kosina 	}
1001dde5845aSJiri Kosina 	if (field->logical_minimum < 0) {
1002dde5845aSJiri Kosina 		if (value != snto32(s32ton(value, size), size)) {
100358037eb9SJiri Kosina 			dbg_hid("value %d is out of range\n", value);
1004dde5845aSJiri Kosina 			return -1;
1005dde5845aSJiri Kosina 		}
1006dde5845aSJiri Kosina 	}
1007dde5845aSJiri Kosina 	field->value[offset] = value;
1008dde5845aSJiri Kosina 	return 0;
1009dde5845aSJiri Kosina }
1010229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field);
1011dde5845aSJiri Kosina 
101285cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
101385cdaf52SJiri Slaby 		const u8 *data)
101485cdaf52SJiri Slaby {
101585cdaf52SJiri Slaby 	struct hid_report *report;
101685cdaf52SJiri Slaby 	unsigned int n = 0;	/* Normally report number is 0 */
101785cdaf52SJiri Slaby 
101885cdaf52SJiri Slaby 	/* Device uses numbered reports, data[0] is report number */
101985cdaf52SJiri Slaby 	if (report_enum->numbered)
102085cdaf52SJiri Slaby 		n = *data;
102185cdaf52SJiri Slaby 
102285cdaf52SJiri Slaby 	report = report_enum->report_id_hash[n];
102385cdaf52SJiri Slaby 	if (report == NULL)
102485cdaf52SJiri Slaby 		dbg_hid("undefined report_id %u received\n", n);
102585cdaf52SJiri Slaby 
102685cdaf52SJiri Slaby 	return report;
102785cdaf52SJiri Slaby }
102885cdaf52SJiri Slaby 
102985cdaf52SJiri Slaby void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
103085cdaf52SJiri Slaby 		int interrupt)
1031aa8de2f0SJiri Kosina {
1032aa8de2f0SJiri Kosina 	struct hid_report_enum *report_enum = hid->report_enum + type;
1033aa8de2f0SJiri Kosina 	struct hid_report *report;
103485cdaf52SJiri Slaby 	unsigned int a;
103585cdaf52SJiri Slaby 	int rsize, csize = size;
103685cdaf52SJiri Slaby 	u8 *cdata = data;
1037aa8de2f0SJiri Kosina 
103885cdaf52SJiri Slaby 	report = hid_get_report(report_enum, data);
103985cdaf52SJiri Slaby 	if (!report)
104085cdaf52SJiri Slaby 		return;
1041aa8de2f0SJiri Kosina 
104285cdaf52SJiri Slaby 	if (report_enum->numbered) {
104385cdaf52SJiri Slaby 		cdata++;
104485cdaf52SJiri Slaby 		csize--;
1045aa8de2f0SJiri Kosina 	}
1046aa8de2f0SJiri Kosina 
1047aa8de2f0SJiri Kosina 	rsize = ((report->size - 1) >> 3) + 1;
1048aa8de2f0SJiri Kosina 
1049966922f2SArmando Visconti 	if (rsize > HID_MAX_BUFFER_SIZE)
1050966922f2SArmando Visconti 		rsize = HID_MAX_BUFFER_SIZE;
1051966922f2SArmando Visconti 
105285cdaf52SJiri Slaby 	if (csize < rsize) {
105385cdaf52SJiri Slaby 		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
105485cdaf52SJiri Slaby 				csize, rsize);
105585cdaf52SJiri Slaby 		memset(cdata + csize, 0, rsize - csize);
1056aa8de2f0SJiri Kosina 	}
1057aa8de2f0SJiri Kosina 
1058aa8de2f0SJiri Kosina 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1059aa8de2f0SJiri Kosina 		hid->hiddev_report_event(hid, report);
10605a38f2c7SAlan Ott 	if (hid->claimed & HID_CLAIMED_HIDRAW)
106186166b7bSJiri Kosina 		hidraw_report_event(hid, data, size);
1062aa8de2f0SJiri Kosina 
106385cdaf52SJiri Slaby 	for (a = 0; a < report->maxfield; a++)
106485cdaf52SJiri Slaby 		hid_input_field(hid, report->field[a], cdata, interrupt);
1065aa8de2f0SJiri Kosina 
1066aa8de2f0SJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1067aa8de2f0SJiri Kosina 		hidinput_report_event(hid, report);
106885cdaf52SJiri Slaby }
106985cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event);
107085cdaf52SJiri Slaby 
107185cdaf52SJiri Slaby /**
107285cdaf52SJiri Slaby  * hid_input_report - report data from lower layer (usb, bt...)
107385cdaf52SJiri Slaby  *
107485cdaf52SJiri Slaby  * @hid: hid device
107585cdaf52SJiri Slaby  * @type: HID report type (HID_*_REPORT)
107685cdaf52SJiri Slaby  * @data: report contents
107785cdaf52SJiri Slaby  * @size: size of data parameter
1078ff9b00a2SJiri Kosina  * @interrupt: distinguish between interrupt and control transfers
107985cdaf52SJiri Slaby  *
108085cdaf52SJiri Slaby  * This is data entry for lower layers.
108185cdaf52SJiri Slaby  */
108285cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
108385cdaf52SJiri Slaby {
108476c317d6SJulia Lawall 	struct hid_report_enum *report_enum;
108576c317d6SJulia Lawall 	struct hid_driver *hdrv;
108685cdaf52SJiri Slaby 	struct hid_report *report;
1087cd667ce2SJiri Kosina 	char *buf;
108885cdaf52SJiri Slaby 	unsigned int i;
108945dc1ac7SJiri Kosina 	int ret = 0;
109085cdaf52SJiri Slaby 
10914ea54542SDavid Herrmann 	if (!hid)
109285cdaf52SJiri Slaby 		return -ENODEV;
10934ea54542SDavid Herrmann 
10944ea54542SDavid Herrmann 	if (down_trylock(&hid->driver_lock))
10954ea54542SDavid Herrmann 		return -EBUSY;
10964ea54542SDavid Herrmann 
10974ea54542SDavid Herrmann 	if (!hid->driver) {
10984ea54542SDavid Herrmann 		ret = -ENODEV;
10994ea54542SDavid Herrmann 		goto unlock;
11004ea54542SDavid Herrmann 	}
110176c317d6SJulia Lawall 	report_enum = hid->report_enum + type;
110276c317d6SJulia Lawall 	hdrv = hid->driver;
110385cdaf52SJiri Slaby 
110485cdaf52SJiri Slaby 	if (!size) {
110585cdaf52SJiri Slaby 		dbg_hid("empty report\n");
11064ea54542SDavid Herrmann 		ret = -1;
11074ea54542SDavid Herrmann 		goto unlock;
110885cdaf52SJiri Slaby 	}
110985cdaf52SJiri Slaby 
1110d1ff6522SJiri Kosina 	buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1111cd667ce2SJiri Kosina 
1112f77e347bSJiri Kosina 	if (!buf)
1113cd667ce2SJiri Kosina 		goto nomem;
111485cdaf52SJiri Slaby 
111585cdaf52SJiri Slaby 	/* dump the report */
1116cd667ce2SJiri Kosina 	snprintf(buf, HID_DEBUG_BUFSIZE - 1,
11171caea61eSJiri Kosina 			"\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
1118cd667ce2SJiri Kosina 	hid_debug_event(hid, buf);
11191caea61eSJiri Kosina 
1120cd667ce2SJiri Kosina 	for (i = 0; i < size; i++) {
1121cd667ce2SJiri Kosina 		snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1122cd667ce2SJiri Kosina 				" %02x", data[i]);
1123cd667ce2SJiri Kosina 		hid_debug_event(hid, buf);
1124cd667ce2SJiri Kosina 	}
1125cd667ce2SJiri Kosina 	hid_debug_event(hid, "\n");
1126cd667ce2SJiri Kosina 	kfree(buf);
1127cd667ce2SJiri Kosina 
1128cd667ce2SJiri Kosina nomem:
1129f77e347bSJiri Kosina 	report = hid_get_report(report_enum, data);
1130f77e347bSJiri Kosina 
11314ea54542SDavid Herrmann 	if (!report) {
11324ea54542SDavid Herrmann 		ret = -1;
11334ea54542SDavid Herrmann 		goto unlock;
11344ea54542SDavid Herrmann 	}
1135f77e347bSJiri Kosina 
113685cdaf52SJiri Slaby 	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
113785cdaf52SJiri Slaby 		ret = hdrv->raw_event(hid, report, data, size);
11384ea54542SDavid Herrmann 		if (ret != 0) {
11394ea54542SDavid Herrmann 			ret = ret < 0 ? ret : 0;
11404ea54542SDavid Herrmann 			goto unlock;
11414ea54542SDavid Herrmann 		}
114285cdaf52SJiri Slaby 	}
114385cdaf52SJiri Slaby 
114485cdaf52SJiri Slaby 	hid_report_raw_event(hid, type, data, size, interrupt);
1145aa8de2f0SJiri Kosina 
11464ea54542SDavid Herrmann unlock:
11474ea54542SDavid Herrmann 	up(&hid->driver_lock);
114845dc1ac7SJiri Kosina 	return ret;
1149aa8de2f0SJiri Kosina }
1150aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report);
1151aa8de2f0SJiri Kosina 
11520f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev,
11530f37cd03SJiri Kosina 		const struct hid_device_id *id)
11540f37cd03SJiri Kosina {
11550f37cd03SJiri Kosina 	return id->bus == hdev->bus &&
11560f37cd03SJiri Kosina 		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
11570f37cd03SJiri Kosina 		(id->product == HID_ANY_ID || id->product == hdev->product);
11580f37cd03SJiri Kosina }
11590f37cd03SJiri Kosina 
11600f37cd03SJiri Kosina static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
11610f37cd03SJiri Kosina 		const struct hid_device_id *id)
11620f37cd03SJiri Kosina {
11630f37cd03SJiri Kosina 	for (; id->bus; id++)
11640f37cd03SJiri Kosina 		if (hid_match_one_id(hdev, id))
11650f37cd03SJiri Kosina 			return id;
11660f37cd03SJiri Kosina 
11670f37cd03SJiri Kosina 	return NULL;
11680f37cd03SJiri Kosina }
11690f37cd03SJiri Kosina 
11700f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = {
1171c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1172c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
11730f37cd03SJiri Kosina 	{ }
11740f37cd03SJiri Kosina };
11750f37cd03SJiri Kosina 
11760f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev)
11770f37cd03SJiri Kosina {
11780f37cd03SJiri Kosina 	return !!hid_match_id(hdev, hid_hiddev_list);
11790f37cd03SJiri Kosina }
11800f37cd03SJiri Kosina 
11816d3bfb74SAlan Ott 
11826d3bfb74SAlan Ott static ssize_t
11836d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj,
11846d3bfb74SAlan Ott 		struct bin_attribute *attr,
11856d3bfb74SAlan Ott 		char *buf, loff_t off, size_t count)
11866d3bfb74SAlan Ott {
11876d3bfb74SAlan Ott 	struct device *dev = container_of(kobj, struct device, kobj);
11886d3bfb74SAlan Ott 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
11896d3bfb74SAlan Ott 
11906d3bfb74SAlan Ott 	if (off >= hdev->rsize)
11916d3bfb74SAlan Ott 		return 0;
11926d3bfb74SAlan Ott 
11936d3bfb74SAlan Ott 	if (off + count > hdev->rsize)
11946d3bfb74SAlan Ott 		count = hdev->rsize - off;
11956d3bfb74SAlan Ott 
11966d3bfb74SAlan Ott 	memcpy(buf, hdev->rdesc + off, count);
11976d3bfb74SAlan Ott 
11986d3bfb74SAlan Ott 	return count;
11996d3bfb74SAlan Ott }
12006d3bfb74SAlan Ott 
12016d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = {
12026d3bfb74SAlan Ott 	.attr = { .name = "report_descriptor", .mode = 0444 },
12036d3bfb74SAlan Ott 	.read = read_report_descriptor,
12046d3bfb74SAlan Ott 	.size = HID_MAX_DESCRIPTOR_SIZE,
12056d3bfb74SAlan Ott };
12066d3bfb74SAlan Ott 
120793c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
120893c10132SJiri Slaby {
120993c10132SJiri Slaby 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
121093c10132SJiri Slaby 		"Joystick", "Gamepad", "Keyboard", "Keypad",
121193c10132SJiri Slaby 		"Multi-Axis Controller"
121293c10132SJiri Slaby 	};
121393c10132SJiri Slaby 	const char *type, *bus;
121493c10132SJiri Slaby 	char buf[64];
121593c10132SJiri Slaby 	unsigned int i;
121693c10132SJiri Slaby 	int len;
12176d3bfb74SAlan Ott 	int ret;
121893c10132SJiri Slaby 
1219b5e5a37eSBastien Nocera 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1220b5e5a37eSBastien Nocera 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
12213a343ee4SDaniel Mack 	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
12223a343ee4SDaniel Mack 		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
122393c10132SJiri Slaby 	if (hdev->bus != BUS_USB)
122493c10132SJiri Slaby 		connect_mask &= ~HID_CONNECT_HIDDEV;
12250f37cd03SJiri Kosina 	if (hid_hiddev(hdev))
12260f37cd03SJiri Kosina 		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
122793c10132SJiri Slaby 
122893c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
122993c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
123093c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_INPUT;
1231b77c3920SBenjamin Tissoires 	if (hdev->quirks & HID_QUIRK_MULTITOUCH) {
1232b77c3920SBenjamin Tissoires 		/* this device should be handled by hid-multitouch, skip it */
1233b77c3920SBenjamin Tissoires 		hdev->quirks &= ~HID_QUIRK_MULTITOUCH;
1234b77c3920SBenjamin Tissoires 		return -ENODEV;
1235b77c3920SBenjamin Tissoires 	}
1236b77c3920SBenjamin Tissoires 
123793c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
123893c10132SJiri Slaby 			!hdev->hiddev_connect(hdev,
123993c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDDEV_FORCE))
124093c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDDEV;
124193c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
124293c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDRAW;
124393c10132SJiri Slaby 
124493c10132SJiri Slaby 	if (!hdev->claimed) {
12454291ee30SJoe Perches 		hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
124693c10132SJiri Slaby 		return -ENODEV;
124793c10132SJiri Slaby 	}
124893c10132SJiri Slaby 
124993c10132SJiri Slaby 	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
125093c10132SJiri Slaby 			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
125193c10132SJiri Slaby 		hdev->ff_init(hdev);
125293c10132SJiri Slaby 
125393c10132SJiri Slaby 	len = 0;
125493c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_INPUT)
125593c10132SJiri Slaby 		len += sprintf(buf + len, "input");
125693c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
125793c10132SJiri Slaby 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
125893c10132SJiri Slaby 				hdev->minor);
125993c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
126093c10132SJiri Slaby 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
126193c10132SJiri Slaby 				((struct hidraw *)hdev->hidraw)->minor);
126293c10132SJiri Slaby 
126393c10132SJiri Slaby 	type = "Device";
126493c10132SJiri Slaby 	for (i = 0; i < hdev->maxcollection; i++) {
126593c10132SJiri Slaby 		struct hid_collection *col = &hdev->collection[i];
126693c10132SJiri Slaby 		if (col->type == HID_COLLECTION_APPLICATION &&
126793c10132SJiri Slaby 		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
126893c10132SJiri Slaby 		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
126993c10132SJiri Slaby 			type = types[col->usage & 0xffff];
127093c10132SJiri Slaby 			break;
127193c10132SJiri Slaby 		}
127293c10132SJiri Slaby 	}
127393c10132SJiri Slaby 
127493c10132SJiri Slaby 	switch (hdev->bus) {
127593c10132SJiri Slaby 	case BUS_USB:
127693c10132SJiri Slaby 		bus = "USB";
127793c10132SJiri Slaby 		break;
127893c10132SJiri Slaby 	case BUS_BLUETOOTH:
127993c10132SJiri Slaby 		bus = "BLUETOOTH";
128093c10132SJiri Slaby 		break;
128193c10132SJiri Slaby 	default:
128293c10132SJiri Slaby 		bus = "<UNKNOWN>";
128393c10132SJiri Slaby 	}
128493c10132SJiri Slaby 
12856d3bfb74SAlan Ott 	ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
12866d3bfb74SAlan Ott 	if (ret)
12876d3bfb74SAlan Ott 		hid_warn(hdev,
12886d3bfb74SAlan Ott 			 "can't create sysfs report descriptor attribute err: %d\n", ret);
12896d3bfb74SAlan Ott 
12904291ee30SJoe Perches 	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
129193c10132SJiri Slaby 		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
129293c10132SJiri Slaby 		 type, hdev->name, hdev->phys);
129393c10132SJiri Slaby 
129493c10132SJiri Slaby 	return 0;
129593c10132SJiri Slaby }
129693c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect);
129793c10132SJiri Slaby 
1298c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev)
1299c4c259bcSJiri Kosina {
13006d3bfb74SAlan Ott 	device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1301c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_INPUT)
1302c4c259bcSJiri Kosina 		hidinput_disconnect(hdev);
1303c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1304c4c259bcSJiri Kosina 		hdev->hiddev_disconnect(hdev);
1305c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1306c4c259bcSJiri Kosina 		hidraw_disconnect(hdev);
1307c4c259bcSJiri Kosina }
1308c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect);
1309c4c259bcSJiri Kosina 
1310bae7eb33SJiri Kosina /* a list of devices for which there is a specialized driver on HID bus */
1311ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = {
1312b6353f4fSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
13136dec143aSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
131414a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
131514a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1316b7e1b203SLech Perczak 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1317c0dbcc33SSergei Kolzun 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1318e6aac342SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, USB_DEVICE_ID_ACTIONSTAR_1011) },
1319df9bcaceSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
13208c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
13218c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1322128537ceSMichael Poole 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1323a462230eSChase Douglas 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
13248c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
13258c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
13268c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
13278c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
13288c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
13298c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
13308c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
13318c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
13328c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
13338c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
13348c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1335fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1336fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1337fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
13388c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
13398c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
13408c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
13418c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
13428c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
13438c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1344ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1345ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1346ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
13478c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
13488c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
13498c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
13508c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
13518c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
13528c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1353a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1354a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1355a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
135699b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
135799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
135899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
135999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
136099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
136199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
136247340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
136347340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
136447340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1365213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1366213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1367213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
13684a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
13694a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
13704a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
1371f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1372f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1373f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
1374d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
1375d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
1376d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
137723aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
137823aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
137923aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1380ad734bc1SAndreas Krist 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
13818c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
13828c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1383eaca1386SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1384cec15a0eSRoland Baum 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1385b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1386bf280628SWayne Thomas 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1387c3dc66deSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
13885519cab4SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
138936213e1eSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1390bc5ab083SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
1391ba4d8abbSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1392272036edSFrançois Jaouen 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
13933b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
13941ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1395fcfacfd3SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1396b9e4b1e0SDennis Kügler 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
1397942fd422SAustin Zhang 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
13983a370ca1SDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
139979603dc9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, USB_DEVICE_ID_CVTOUCH_SCREEN) },
14000f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
14010f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1402e8d0eab4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
14030f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1404a3b5e577SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
14053f866fbdSRichard Walmsley 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1406e05eefb9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
1407e36f690bSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1408e36f690bSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1409e36f690bSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1410e36f690bSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1411e36f690bSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1412bb9ff210SMarek Vasut 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1413e36f690bSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
141464b386eaSRichard Nauber 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1415c04abeefSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) },
141604561c5aSIgnaz Forster 	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
14171f243e30SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
14185181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1419578f3a35SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
14205572da08SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1421ee0fbd14SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, USB_DEVICE_ID_GOODTOUCH_000f) },
14225181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
142342859e0bSLukasz Lubojanski 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1424949f8fefSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
14251e093206SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1426c2fd1a4eSCory Maccarrone 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
14275519cab4SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
142854580365SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT, USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1429a062cc5aSStephane Chatty  	{ HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, USB_DEVICE_ID_IDEACOM_IDC6650) },
1430d946e65eSAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
14314e61f0d7SAustin Zhang 	{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1432b2e7617eSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1433fdf93aa3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1434177900e8SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
143579422741SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1436b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
143775b07022SChris Schlund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
1438c50bb1a4SJeff Brown 	{ HID_USB_DEVICE(USB_VENDOR_ID_LG, USB_DEVICE_ID_LG_MULTITOUCH) },
14395f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
14405f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
14415f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
14425f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
14435f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
14445f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
14455f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
14465f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
14475f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
14485f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
14495f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
14502c6118e4SHendrik Iben 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1451606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1452606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1453606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1454fd30ea8cSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1455606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
145674f292caSGary Stein 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1457606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1458606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
14595623a24aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1460e00ddc9bSMichal Malý 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
1461243b706dSChristophe Borivant 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1462fdc6807fSPeter Gundermann 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
1463534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
1464534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
146532c88cbcSSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1466606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
146724985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
146824985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1469df167c4aSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH) },
1470c3ead6deSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
1471236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1472236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
1473b580169aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
147478a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
147578a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
147678a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
147778a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1478f3b83d71SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
147978a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
14803b8006e5SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
148194011f93SRafi Rubin 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
14826e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
14836e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
14846e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
14856e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
14866e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
14876e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
14886e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
14896e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
14906e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
14916e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
14926e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
14936e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
14946e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
14956e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
14966e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
14976e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
14986e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
14996e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1500270fdc07SHerton Ronaldo Krzesinski 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1501cd9ec30dSJohnathon Harris 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
15026ab3a9a6SJohn Sung 	{ HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) },
15031e762532SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1504b7ea95ffSAaron Tian 	{ HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1505b7ea95ffSAaron Tian 	{ HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1506b7ea95ffSAaron Tian 	{ HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1507f6a04605STerry Lambert 	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
150849e4739aSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1509f54405dbSAlex Neblett 	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
151014bf62cdSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1511e68cc603SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
151247dbdbffSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
15130e70f97fSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
1514cb7cf3daSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
15153fce2246SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
1516980a3da6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1517b355850bSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1518d586dca0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1519bd28ce00SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
152035dca5b4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1521f9ce7c28SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1522cc6e0bbbSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1523d3fb5454SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1524b6dc7992SPascal Auriel - Stantum 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1525b6dc7992SPascal Auriel - Stantum 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
152690231e7eSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1527daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1528daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
15297a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
15307a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1531daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
15323ee8f0a2SMarkus Rathgeb 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1533daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1534d65c3768SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1535f14f526dSLev Babiev 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
153654001081SKees Bakker 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
15375e74e56dSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1538711a680eSBruno Premont 	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
1539c64f6f93SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
154041fa9230SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1541f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1542f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1543f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
15446be914f1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1545617b64f9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1546617b64f9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
1547fac733f0SJussi Kivilinna 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1548ad395ccaSSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
15491bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
15501bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
15511bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
1552ca2dcd40SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
155372a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
155400e7f964SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
155572a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
15568f1acc32SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1557bc8a2a9bSice chien 	{ HID_USB_DEVICE(USB_VENDOR_ID_XAT, USB_DEVICE_ID_XAT_CSR) },
1558*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX) },
1559*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX) },
1560*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR) },
1561*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX1) },
1562*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX1) },
1563*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR1) },
1564*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX2) },
1565*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX2) },
1566*11576c61SMasatoshi Hoshikawa 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR2) },
156774bc6953SStefan Kriwanek 	{ HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1568daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1569daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1570a9885c8fSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
15718c19a515SJiri Slaby 
157278a849a6SJiri Slaby 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
157302fb72a0SDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
157485cdaf52SJiri Slaby 	{ }
157585cdaf52SJiri Slaby };
157685cdaf52SJiri Slaby 
15773a6f82f7SJiri Slaby struct hid_dynid {
15783a6f82f7SJiri Slaby 	struct list_head list;
15793a6f82f7SJiri Slaby 	struct hid_device_id id;
15803a6f82f7SJiri Slaby };
15813a6f82f7SJiri Slaby 
15823a6f82f7SJiri Slaby /**
15833a6f82f7SJiri Slaby  * store_new_id - add a new HID device ID to this driver and re-probe devices
15843a6f82f7SJiri Slaby  * @driver: target device driver
15853a6f82f7SJiri Slaby  * @buf: buffer for scanning device ID data
15863a6f82f7SJiri Slaby  * @count: input size
15873a6f82f7SJiri Slaby  *
15883a6f82f7SJiri Slaby  * Adds a new dynamic hid device ID to this driver,
15893a6f82f7SJiri Slaby  * and causes the driver to probe for all devices again.
15903a6f82f7SJiri Slaby  */
15913a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf,
15923a6f82f7SJiri Slaby 		size_t count)
15933a6f82f7SJiri Slaby {
15943a6f82f7SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
15953a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
15963a6f82f7SJiri Slaby 	__u32 bus, vendor, product;
15973a6f82f7SJiri Slaby 	unsigned long driver_data = 0;
15983a6f82f7SJiri Slaby 	int ret;
15993a6f82f7SJiri Slaby 
16003a6f82f7SJiri Slaby 	ret = sscanf(buf, "%x %x %x %lx",
16013a6f82f7SJiri Slaby 			&bus, &vendor, &product, &driver_data);
16023a6f82f7SJiri Slaby 	if (ret < 3)
16033a6f82f7SJiri Slaby 		return -EINVAL;
16043a6f82f7SJiri Slaby 
16053a6f82f7SJiri Slaby 	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
16063a6f82f7SJiri Slaby 	if (!dynid)
16073a6f82f7SJiri Slaby 		return -ENOMEM;
16083a6f82f7SJiri Slaby 
16093a6f82f7SJiri Slaby 	dynid->id.bus = bus;
16103a6f82f7SJiri Slaby 	dynid->id.vendor = vendor;
16113a6f82f7SJiri Slaby 	dynid->id.product = product;
16123a6f82f7SJiri Slaby 	dynid->id.driver_data = driver_data;
16133a6f82f7SJiri Slaby 
16143a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
16153a6f82f7SJiri Slaby 	list_add_tail(&dynid->list, &hdrv->dyn_list);
16163a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
16173a6f82f7SJiri Slaby 
16183a6f82f7SJiri Slaby 	ret = 0;
16193a6f82f7SJiri Slaby 	if (get_driver(&hdrv->driver)) {
16203a6f82f7SJiri Slaby 		ret = driver_attach(&hdrv->driver);
16213a6f82f7SJiri Slaby 		put_driver(&hdrv->driver);
16223a6f82f7SJiri Slaby 	}
16233a6f82f7SJiri Slaby 
16243a6f82f7SJiri Slaby 	return ret ? : count;
16253a6f82f7SJiri Slaby }
16263a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
16273a6f82f7SJiri Slaby 
16283a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv)
16293a6f82f7SJiri Slaby {
16303a6f82f7SJiri Slaby 	struct hid_dynid *dynid, *n;
16313a6f82f7SJiri Slaby 
16323a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
16333a6f82f7SJiri Slaby 	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
16343a6f82f7SJiri Slaby 		list_del(&dynid->list);
16353a6f82f7SJiri Slaby 		kfree(dynid);
16363a6f82f7SJiri Slaby 	}
16373a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
16383a6f82f7SJiri Slaby }
16393a6f82f7SJiri Slaby 
16403a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
16413a6f82f7SJiri Slaby 		struct hid_driver *hdrv)
16423a6f82f7SJiri Slaby {
16433a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
16443a6f82f7SJiri Slaby 
16453a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
16463a6f82f7SJiri Slaby 	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
16473a6f82f7SJiri Slaby 		if (hid_match_one_id(hdev, &dynid->id)) {
16483a6f82f7SJiri Slaby 			spin_unlock(&hdrv->dyn_lock);
16493a6f82f7SJiri Slaby 			return &dynid->id;
16503a6f82f7SJiri Slaby 		}
16513a6f82f7SJiri Slaby 	}
16523a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
16533a6f82f7SJiri Slaby 
16543a6f82f7SJiri Slaby 	return hid_match_id(hdev, hdrv->id_table);
16553a6f82f7SJiri Slaby }
16563a6f82f7SJiri Slaby 
165785cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv)
165885cdaf52SJiri Slaby {
165985cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
166085cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
166185cdaf52SJiri Slaby 
16623a6f82f7SJiri Slaby 	if (!hid_match_device(hdev, hdrv))
166385cdaf52SJiri Slaby 		return 0;
166485cdaf52SJiri Slaby 
1665ce06b9d6SDmitry Torokhov 	/* generic wants all that don't have specialized driver */
166685cdaf52SJiri Slaby 	if (!strncmp(hdrv->name, "generic-", 8))
1667ce06b9d6SDmitry Torokhov 		return !hid_match_id(hdev, hid_have_special_driver);
166885cdaf52SJiri Slaby 
166985cdaf52SJiri Slaby 	return 1;
167085cdaf52SJiri Slaby }
167185cdaf52SJiri Slaby 
167285cdaf52SJiri Slaby static int hid_device_probe(struct device *dev)
167385cdaf52SJiri Slaby {
167485cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(dev->driver,
167585cdaf52SJiri Slaby 			struct hid_driver, driver);
167685cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
167785cdaf52SJiri Slaby 	const struct hid_device_id *id;
167885cdaf52SJiri Slaby 	int ret = 0;
167985cdaf52SJiri Slaby 
16804ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
16814ea54542SDavid Herrmann 		return -EINTR;
16824ea54542SDavid Herrmann 
168385cdaf52SJiri Slaby 	if (!hdev->driver) {
16843a6f82f7SJiri Slaby 		id = hid_match_device(hdev, hdrv);
1685ba623a77SDan Carpenter 		if (id == NULL) {
1686ba623a77SDan Carpenter 			ret = -ENODEV;
1687ba623a77SDan Carpenter 			goto unlock;
1688ba623a77SDan Carpenter 		}
1689c500c971SJiri Slaby 
169085cdaf52SJiri Slaby 		hdev->driver = hdrv;
1691c500c971SJiri Slaby 		if (hdrv->probe) {
1692c500c971SJiri Slaby 			ret = hdrv->probe(hdev, id);
1693c500c971SJiri Slaby 		} else { /* default probe */
1694c500c971SJiri Slaby 			ret = hid_parse(hdev);
1695c500c971SJiri Slaby 			if (!ret)
169693c10132SJiri Slaby 				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1697c500c971SJiri Slaby 		}
1698c500c971SJiri Slaby 		if (ret)
1699c500c971SJiri Slaby 			hdev->driver = NULL;
170085cdaf52SJiri Slaby 	}
1701ba623a77SDan Carpenter unlock:
17024ea54542SDavid Herrmann 	up(&hdev->driver_lock);
170385cdaf52SJiri Slaby 	return ret;
170485cdaf52SJiri Slaby }
170585cdaf52SJiri Slaby 
170685cdaf52SJiri Slaby static int hid_device_remove(struct device *dev)
170785cdaf52SJiri Slaby {
170885cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
17094ea54542SDavid Herrmann 	struct hid_driver *hdrv;
171085cdaf52SJiri Slaby 
17114ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
17124ea54542SDavid Herrmann 		return -EINTR;
17134ea54542SDavid Herrmann 
17144ea54542SDavid Herrmann 	hdrv = hdev->driver;
171585cdaf52SJiri Slaby 	if (hdrv) {
171685cdaf52SJiri Slaby 		if (hdrv->remove)
171785cdaf52SJiri Slaby 			hdrv->remove(hdev);
1718c500c971SJiri Slaby 		else /* default remove */
1719c500c971SJiri Slaby 			hid_hw_stop(hdev);
172085cdaf52SJiri Slaby 		hdev->driver = NULL;
172185cdaf52SJiri Slaby 	}
172285cdaf52SJiri Slaby 
17234ea54542SDavid Herrmann 	up(&hdev->driver_lock);
172485cdaf52SJiri Slaby 	return 0;
172585cdaf52SJiri Slaby }
172685cdaf52SJiri Slaby 
172785cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
172885cdaf52SJiri Slaby {
172985cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
173085cdaf52SJiri Slaby 
173185cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
173285cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
173385cdaf52SJiri Slaby 		return -ENOMEM;
173485cdaf52SJiri Slaby 
173585cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
173685cdaf52SJiri Slaby 		return -ENOMEM;
173785cdaf52SJiri Slaby 
173885cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
173985cdaf52SJiri Slaby 		return -ENOMEM;
174085cdaf52SJiri Slaby 
174185cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
174285cdaf52SJiri Slaby 		return -ENOMEM;
174385cdaf52SJiri Slaby 
174485cdaf52SJiri Slaby 	if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
174585cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
174685cdaf52SJiri Slaby 		return -ENOMEM;
174785cdaf52SJiri Slaby 
174885cdaf52SJiri Slaby 	return 0;
174985cdaf52SJiri Slaby }
175085cdaf52SJiri Slaby 
175185cdaf52SJiri Slaby static struct bus_type hid_bus_type = {
175285cdaf52SJiri Slaby 	.name		= "hid",
175385cdaf52SJiri Slaby 	.match		= hid_bus_match,
175485cdaf52SJiri Slaby 	.probe		= hid_device_probe,
175585cdaf52SJiri Slaby 	.remove		= hid_device_remove,
175685cdaf52SJiri Slaby 	.uevent		= hid_uevent,
175785cdaf52SJiri Slaby };
175885cdaf52SJiri Slaby 
1759bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */
1760d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = {
1761d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1762d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1763d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1764d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1765d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1766d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1767d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1768d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1769d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1770d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1771d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1772d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
177377f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
177477f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
177562a56582SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1776d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1777d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1778d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1779d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1780d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1781d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
17825f6108cfSAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1783d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1784d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
178573bc7d31SMelchior FRANZ 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
1786d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
178770c66567SPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1788df506f2cSPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1789d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1790d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1791d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1792d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1793d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1794d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1795d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1796d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1797d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1798d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1799d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1800d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1801d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1802d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1803d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1804d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1805d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1806d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1807d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1808d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1809d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1810d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1811d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1812d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1813d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1814d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1815d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1816d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1817d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1818d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1819d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1820d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1821d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1822d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1823d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1824d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1825d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1826d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1827d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1828d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1829d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1830d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1831d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1832d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1833d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1834d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1835d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1836d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1837d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1838d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1839d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1840d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1841d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1842d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1843d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1844d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1845d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1846d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1847d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1848d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1849d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1850d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1851d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1852d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1853d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1854c91c21c5SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1855d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1856eb8141ccSLamarque Vieira Souza 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1857d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1858ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
1859d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1860ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
1861d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1862ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
1863ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
1864ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
1865ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
1866ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
1867ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
1868d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1869d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1870d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1871ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
1872ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
1873ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
1874d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1875d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1876ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
1877d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1878d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1879d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1880d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1881d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1882ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
1883ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
1884ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
1885ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
1886ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
1887ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
1888ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
1889d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1890d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1891d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1892d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1893d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1894d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1895d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1896d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1897d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1898d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1899d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1900d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1901d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1902d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1903d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1904d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1905d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1906d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1907d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
19084cfae3e8SHenning Glawe 	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
190935cfd1d9SMichael Tokarev 	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1910d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1911d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1912d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1913d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1914d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1915d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1916d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1917d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1918d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1919d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1920d458a9dfSJiri Slaby 	{ }
1921d458a9dfSJiri Slaby };
1922d458a9dfSJiri Slaby 
1923b4d8e473SJiri Slaby /**
1924b4d8e473SJiri Slaby  * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1925b4d8e473SJiri Slaby  *
1926b4d8e473SJiri Slaby  * There are composite devices for which we want to ignore only a certain
1927b4d8e473SJiri Slaby  * interface. This is a list of devices for which only the mouse interface will
1928b4d8e473SJiri Slaby  * be ignored. This allows a dedicated driver to take care of the interface.
1929b4d8e473SJiri Slaby  */
1930b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = {
1931b4d8e473SJiri Slaby 	/* appletouch driver */
1932b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1933b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1934b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1935b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1936b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1937b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1938b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1939b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1940b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1941b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1942b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1943b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1944b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1945b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1946b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1947b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1948b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1949b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1950b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1951b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1952ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1953ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1954ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
195599b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
195699b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
195799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
195899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
195999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
196099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
196147340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
196247340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
196347340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1964213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1965213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1966213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
19674b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
19684b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
19694b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
19704b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
19714b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
19724b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
1973b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1974b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1975b4d8e473SJiri Slaby 	{ }
1976b4d8e473SJiri Slaby };
1977b4d8e473SJiri Slaby 
1978d458a9dfSJiri Slaby static bool hid_ignore(struct hid_device *hdev)
1979d458a9dfSJiri Slaby {
1980d458a9dfSJiri Slaby 	switch (hdev->vendor) {
1981d458a9dfSJiri Slaby 	case USB_VENDOR_ID_CODEMERCS:
1982d458a9dfSJiri Slaby 		/* ignore all Code Mercenaries IOWarrior devices */
1983d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1984d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1985d458a9dfSJiri Slaby 			return true;
1986d458a9dfSJiri Slaby 		break;
1987d458a9dfSJiri Slaby 	case USB_VENDOR_ID_LOGITECH:
1988d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1989d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1990d458a9dfSJiri Slaby 			return true;
1991d458a9dfSJiri Slaby 		break;
199231f7fd79SJarod Wilson 	case USB_VENDOR_ID_SOUNDGRAPH:
199331f7fd79SJarod Wilson 		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
199431f7fd79SJarod Wilson 		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
199531f7fd79SJarod Wilson 			return true;
199631f7fd79SJarod Wilson 		break;
1997bba5394aSXing Wei 	case USB_VENDOR_ID_HANWANG:
1998bba5394aSXing Wei 		if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
1999bba5394aSXing Wei 		    hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
2000bba5394aSXing Wei 			return true;
2001bba5394aSXing Wei 		break;
20026dc1418eSTomoki Sekiyama 	case USB_VENDOR_ID_JESS:
20036dc1418eSTomoki Sekiyama 		if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
20046dc1418eSTomoki Sekiyama 				hdev->type == HID_TYPE_USBNONE)
20056dc1418eSTomoki Sekiyama 			return true;
20066dc1418eSTomoki Sekiyama 	break;
2007d458a9dfSJiri Slaby 	}
2008d458a9dfSJiri Slaby 
2009b4d8e473SJiri Slaby 	if (hdev->type == HID_TYPE_USBMOUSE &&
2010b4d8e473SJiri Slaby 			hid_match_id(hdev, hid_mouse_ignore_list))
2011b4d8e473SJiri Slaby 		return true;
2012b4d8e473SJiri Slaby 
2013d458a9dfSJiri Slaby 	return !!hid_match_id(hdev, hid_ignore_list);
2014d458a9dfSJiri Slaby }
2015d458a9dfSJiri Slaby 
201685cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev)
201785cdaf52SJiri Slaby {
201885cdaf52SJiri Slaby 	static atomic_t id = ATOMIC_INIT(0);
201985cdaf52SJiri Slaby 	int ret;
202085cdaf52SJiri Slaby 
202185cdaf52SJiri Slaby 	if (WARN_ON(hdev->status & HID_STAT_ADDED))
202285cdaf52SJiri Slaby 		return -EBUSY;
202385cdaf52SJiri Slaby 
2024d458a9dfSJiri Slaby 	/* we need to kill them here, otherwise they will stay allocated to
2025d458a9dfSJiri Slaby 	 * wait for coming driver */
2026e5a2a04cSJindrich Makovicka 	if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
2027e5a2a04cSJindrich Makovicka             && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
2028d458a9dfSJiri Slaby 		return -ENODEV;
2029d458a9dfSJiri Slaby 
20306bbe586fSKay Sievers 	/* XXX hack, any other cleaner solution after the driver core
20316bbe586fSKay Sievers 	 * is converted to allow more than 20 bytes as the device name? */
20326bbe586fSKay Sievers 	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
203385cdaf52SJiri Slaby 		     hdev->vendor, hdev->product, atomic_inc_return(&id));
203485cdaf52SJiri Slaby 
20354da361b6SBruno Prémont 	hid_debug_register(hdev, dev_name(&hdev->dev));
203685cdaf52SJiri Slaby 	ret = device_add(&hdev->dev);
203785cdaf52SJiri Slaby 	if (!ret)
203885cdaf52SJiri Slaby 		hdev->status |= HID_STAT_ADDED;
20394da361b6SBruno Prémont 	else
20404da361b6SBruno Prémont 		hid_debug_unregister(hdev);
2041a635f9ddSJiri Kosina 
204285cdaf52SJiri Slaby 	return ret;
204385cdaf52SJiri Slaby }
204485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device);
204585cdaf52SJiri Slaby 
204685cdaf52SJiri Slaby /**
204785cdaf52SJiri Slaby  * hid_allocate_device - allocate new hid device descriptor
204885cdaf52SJiri Slaby  *
204985cdaf52SJiri Slaby  * Allocate and initialize hid device, so that hid_destroy_device might be
205085cdaf52SJiri Slaby  * used to free it.
205185cdaf52SJiri Slaby  *
205285cdaf52SJiri Slaby  * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
205385cdaf52SJiri Slaby  * error value.
205485cdaf52SJiri Slaby  */
205585cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void)
205685cdaf52SJiri Slaby {
205785cdaf52SJiri Slaby 	struct hid_device *hdev;
205885cdaf52SJiri Slaby 	unsigned int i;
205985cdaf52SJiri Slaby 	int ret = -ENOMEM;
206085cdaf52SJiri Slaby 
206185cdaf52SJiri Slaby 	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
206285cdaf52SJiri Slaby 	if (hdev == NULL)
206385cdaf52SJiri Slaby 		return ERR_PTR(ret);
206485cdaf52SJiri Slaby 
206585cdaf52SJiri Slaby 	device_initialize(&hdev->dev);
206685cdaf52SJiri Slaby 	hdev->dev.release = hid_device_release;
206785cdaf52SJiri Slaby 	hdev->dev.bus = &hid_bus_type;
206885cdaf52SJiri Slaby 
206985cdaf52SJiri Slaby 	hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
207085cdaf52SJiri Slaby 			sizeof(struct hid_collection), GFP_KERNEL);
207185cdaf52SJiri Slaby 	if (hdev->collection == NULL)
207285cdaf52SJiri Slaby 		goto err;
207385cdaf52SJiri Slaby 	hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
207485cdaf52SJiri Slaby 
207585cdaf52SJiri Slaby 	for (i = 0; i < HID_REPORT_TYPES; i++)
207685cdaf52SJiri Slaby 		INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
207785cdaf52SJiri Slaby 
2078cd667ce2SJiri Kosina 	init_waitqueue_head(&hdev->debug_wait);
2079cd667ce2SJiri Kosina 	INIT_LIST_HEAD(&hdev->debug_list);
20804ea54542SDavid Herrmann 	sema_init(&hdev->driver_lock, 1);
2081cd667ce2SJiri Kosina 
208285cdaf52SJiri Slaby 	return hdev;
208385cdaf52SJiri Slaby err:
208485cdaf52SJiri Slaby 	put_device(&hdev->dev);
208585cdaf52SJiri Slaby 	return ERR_PTR(ret);
208685cdaf52SJiri Slaby }
208785cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device);
208885cdaf52SJiri Slaby 
208985cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev)
209085cdaf52SJiri Slaby {
209185cdaf52SJiri Slaby 	if (hdev->status & HID_STAT_ADDED) {
209285cdaf52SJiri Slaby 		device_del(&hdev->dev);
2093a635f9ddSJiri Kosina 		hid_debug_unregister(hdev);
209485cdaf52SJiri Slaby 		hdev->status &= ~HID_STAT_ADDED;
209585cdaf52SJiri Slaby 	}
209685cdaf52SJiri Slaby }
209785cdaf52SJiri Slaby 
209885cdaf52SJiri Slaby /**
209985cdaf52SJiri Slaby  * hid_destroy_device - free previously allocated device
210085cdaf52SJiri Slaby  *
210185cdaf52SJiri Slaby  * @hdev: hid device
210285cdaf52SJiri Slaby  *
210385cdaf52SJiri Slaby  * If you allocate hid_device through hid_allocate_device, you should ever
210485cdaf52SJiri Slaby  * free by this function.
210585cdaf52SJiri Slaby  */
210685cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev)
210785cdaf52SJiri Slaby {
210885cdaf52SJiri Slaby 	hid_remove_device(hdev);
210985cdaf52SJiri Slaby 	put_device(&hdev->dev);
211085cdaf52SJiri Slaby }
211185cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device);
211285cdaf52SJiri Slaby 
211385cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
211485cdaf52SJiri Slaby 		const char *mod_name)
211585cdaf52SJiri Slaby {
21163a6f82f7SJiri Slaby 	int ret;
21173a6f82f7SJiri Slaby 
211885cdaf52SJiri Slaby 	hdrv->driver.name = hdrv->name;
211985cdaf52SJiri Slaby 	hdrv->driver.bus = &hid_bus_type;
212085cdaf52SJiri Slaby 	hdrv->driver.owner = owner;
212185cdaf52SJiri Slaby 	hdrv->driver.mod_name = mod_name;
212285cdaf52SJiri Slaby 
21233a6f82f7SJiri Slaby 	INIT_LIST_HEAD(&hdrv->dyn_list);
21243a6f82f7SJiri Slaby 	spin_lock_init(&hdrv->dyn_lock);
21253a6f82f7SJiri Slaby 
21263a6f82f7SJiri Slaby 	ret = driver_register(&hdrv->driver);
21273a6f82f7SJiri Slaby 	if (ret)
21283a6f82f7SJiri Slaby 		return ret;
21293a6f82f7SJiri Slaby 
21303a6f82f7SJiri Slaby 	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
21313a6f82f7SJiri Slaby 	if (ret)
21323a6f82f7SJiri Slaby 		driver_unregister(&hdrv->driver);
21333a6f82f7SJiri Slaby 
21343a6f82f7SJiri Slaby 	return ret;
213585cdaf52SJiri Slaby }
213685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver);
213785cdaf52SJiri Slaby 
213885cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv)
213985cdaf52SJiri Slaby {
21403a6f82f7SJiri Slaby 	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
214185cdaf52SJiri Slaby 	driver_unregister(&hdrv->driver);
21423a6f82f7SJiri Slaby 	hid_free_dynids(hdrv);
214385cdaf52SJiri Slaby }
214485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver);
214585cdaf52SJiri Slaby 
21460361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid)
21470361a28dSOliver Neukum {
21480361a28dSOliver Neukum 	struct hid_input *hidinput;
21490361a28dSOliver Neukum 	int i;
21500361a28dSOliver Neukum 
2151e5288eb5SJiri Kosina 	if (!(hid->claimed & HID_CLAIMED_INPUT))
2152e5288eb5SJiri Kosina 		return 0;
2153e5288eb5SJiri Kosina 
21540361a28dSOliver Neukum 	list_for_each_entry(hidinput, &hid->inputs, list) {
21550361a28dSOliver Neukum 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
21560361a28dSOliver Neukum 			if (hidinput->input->key[i])
21570361a28dSOliver Neukum 				return 1;
21580361a28dSOliver Neukum 	}
21590361a28dSOliver Neukum 
21600361a28dSOliver Neukum 	return 0;
21610361a28dSOliver Neukum }
21620361a28dSOliver Neukum 
21630361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
21640361a28dSOliver Neukum 
216586166b7bSJiri Kosina static int __init hid_init(void)
216686166b7bSJiri Kosina {
216785cdaf52SJiri Slaby 	int ret;
216885cdaf52SJiri Slaby 
2169a635f9ddSJiri Kosina 	if (hid_debug)
21704291ee30SJoe Perches 		pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
21714291ee30SJoe Perches 			"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2172a635f9ddSJiri Kosina 
217385cdaf52SJiri Slaby 	ret = bus_register(&hid_bus_type);
217485cdaf52SJiri Slaby 	if (ret) {
21754291ee30SJoe Perches 		pr_err("can't register hid bus\n");
217685cdaf52SJiri Slaby 		goto err;
217785cdaf52SJiri Slaby 	}
217885cdaf52SJiri Slaby 
217985cdaf52SJiri Slaby 	ret = hidraw_init();
218085cdaf52SJiri Slaby 	if (ret)
218185cdaf52SJiri Slaby 		goto err_bus;
218285cdaf52SJiri Slaby 
2183a635f9ddSJiri Kosina 	hid_debug_init();
2184a635f9ddSJiri Kosina 
218585cdaf52SJiri Slaby 	return 0;
218685cdaf52SJiri Slaby err_bus:
218785cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
218885cdaf52SJiri Slaby err:
218985cdaf52SJiri Slaby 	return ret;
219086166b7bSJiri Kosina }
219186166b7bSJiri Kosina 
219286166b7bSJiri Kosina static void __exit hid_exit(void)
219386166b7bSJiri Kosina {
2194a635f9ddSJiri Kosina 	hid_debug_exit();
219586166b7bSJiri Kosina 	hidraw_exit();
219685cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
219786166b7bSJiri Kosina }
219886166b7bSJiri Kosina 
219986166b7bSJiri Kosina module_init(hid_init);
220086166b7bSJiri Kosina module_exit(hid_exit);
220186166b7bSJiri Kosina 
220288adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal");
220388adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik");
220488adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina");
2205aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
2206aa938f79SJiri Kosina 
2207