xref: /openbmc/linux/drivers/hid/hid-core.c (revision fc38a8a66e1bda87da13e8eb549dd87ddd86f3b8)
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
76b1968d5SJiri Kosina  *  Copyright (c) 2006-2012 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 
536b1968d5SJiri Kosina static int hid_ignore_special_drivers = 0;
546b1968d5SJiri Kosina module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
55643727a9SHans Petter Selasky MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
566b1968d5SJiri Kosina 
57dde5845aSJiri Kosina /*
58dde5845aSJiri Kosina  * Register a new report for a device.
59dde5845aSJiri Kosina  */
60dde5845aSJiri Kosina 
6190a006abSMichael Poole struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
62dde5845aSJiri Kosina {
63dde5845aSJiri Kosina 	struct hid_report_enum *report_enum = device->report_enum + type;
64dde5845aSJiri Kosina 	struct hid_report *report;
65dde5845aSJiri Kosina 
6643622021SKees Cook 	if (id >= HID_MAX_IDS)
6743622021SKees Cook 		return NULL;
68dde5845aSJiri Kosina 	if (report_enum->report_id_hash[id])
69dde5845aSJiri Kosina 		return report_enum->report_id_hash[id];
70dde5845aSJiri Kosina 
71a3789a17SJoe Perches 	report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
72a3789a17SJoe Perches 	if (!report)
73dde5845aSJiri Kosina 		return NULL;
74dde5845aSJiri Kosina 
75dde5845aSJiri Kosina 	if (id != 0)
76dde5845aSJiri Kosina 		report_enum->numbered = 1;
77dde5845aSJiri Kosina 
78dde5845aSJiri Kosina 	report->id = id;
79dde5845aSJiri Kosina 	report->type = type;
80dde5845aSJiri Kosina 	report->size = 0;
81dde5845aSJiri Kosina 	report->device = device;
82dde5845aSJiri Kosina 	report_enum->report_id_hash[id] = report;
83dde5845aSJiri Kosina 
84dde5845aSJiri Kosina 	list_add_tail(&report->list, &report_enum->report_list);
85dde5845aSJiri Kosina 
86dde5845aSJiri Kosina 	return report;
87dde5845aSJiri Kosina }
8890a006abSMichael Poole EXPORT_SYMBOL_GPL(hid_register_report);
89dde5845aSJiri Kosina 
90dde5845aSJiri Kosina /*
91dde5845aSJiri Kosina  * Register a new field for this report.
92dde5845aSJiri Kosina  */
93dde5845aSJiri Kosina 
94dde5845aSJiri Kosina static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
95dde5845aSJiri Kosina {
96dde5845aSJiri Kosina 	struct hid_field *field;
97dde5845aSJiri Kosina 
98dde5845aSJiri Kosina 	if (report->maxfield == HID_MAX_FIELDS) {
998c3d52fcSJiri Kosina 		hid_err(report->device, "too many fields in report\n");
100dde5845aSJiri Kosina 		return NULL;
101dde5845aSJiri Kosina 	}
102dde5845aSJiri Kosina 
103a3789a17SJoe Perches 	field = kzalloc((sizeof(struct hid_field) +
104a3789a17SJoe Perches 			 usages * sizeof(struct hid_usage) +
105a3789a17SJoe Perches 			 values * sizeof(unsigned)), GFP_KERNEL);
106a3789a17SJoe Perches 	if (!field)
107a3789a17SJoe Perches 		return NULL;
108dde5845aSJiri Kosina 
109dde5845aSJiri Kosina 	field->index = report->maxfield++;
110dde5845aSJiri Kosina 	report->field[field->index] = field;
111dde5845aSJiri Kosina 	field->usage = (struct hid_usage *)(field + 1);
112282bfd4cSJiri Slaby 	field->value = (s32 *)(field->usage + usages);
113dde5845aSJiri Kosina 	field->report = report;
114dde5845aSJiri Kosina 
115dde5845aSJiri Kosina 	return field;
116dde5845aSJiri Kosina }
117dde5845aSJiri Kosina 
118dde5845aSJiri Kosina /*
119dde5845aSJiri Kosina  * Open a collection. The type/usage is pushed on the stack.
120dde5845aSJiri Kosina  */
121dde5845aSJiri Kosina 
122dde5845aSJiri Kosina static int open_collection(struct hid_parser *parser, unsigned type)
123dde5845aSJiri Kosina {
124dde5845aSJiri Kosina 	struct hid_collection *collection;
125dde5845aSJiri Kosina 	unsigned usage;
126dde5845aSJiri Kosina 
127dde5845aSJiri Kosina 	usage = parser->local.usage[0];
128dde5845aSJiri Kosina 
129dde5845aSJiri Kosina 	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
1308c3d52fcSJiri Kosina 		hid_err(parser->device, "collection stack overflow\n");
131a6fbaacfSSachin Kamat 		return -EINVAL;
132dde5845aSJiri Kosina 	}
133dde5845aSJiri Kosina 
134dde5845aSJiri Kosina 	if (parser->device->maxcollection == parser->device->collection_size) {
135dde5845aSJiri Kosina 		collection = kmalloc(sizeof(struct hid_collection) *
136dde5845aSJiri Kosina 				parser->device->collection_size * 2, GFP_KERNEL);
137dde5845aSJiri Kosina 		if (collection == NULL) {
1388c3d52fcSJiri Kosina 			hid_err(parser->device, "failed to reallocate collection array\n");
139a6fbaacfSSachin Kamat 			return -ENOMEM;
140dde5845aSJiri Kosina 		}
141dde5845aSJiri Kosina 		memcpy(collection, parser->device->collection,
142dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
143dde5845aSJiri Kosina 			parser->device->collection_size);
144dde5845aSJiri Kosina 		memset(collection + parser->device->collection_size, 0,
145dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
146dde5845aSJiri Kosina 			parser->device->collection_size);
147dde5845aSJiri Kosina 		kfree(parser->device->collection);
148dde5845aSJiri Kosina 		parser->device->collection = collection;
149dde5845aSJiri Kosina 		parser->device->collection_size *= 2;
150dde5845aSJiri Kosina 	}
151dde5845aSJiri Kosina 
152dde5845aSJiri Kosina 	parser->collection_stack[parser->collection_stack_ptr++] =
153dde5845aSJiri Kosina 		parser->device->maxcollection;
154dde5845aSJiri Kosina 
155dde5845aSJiri Kosina 	collection = parser->device->collection +
156dde5845aSJiri Kosina 		parser->device->maxcollection++;
157dde5845aSJiri Kosina 	collection->type = type;
158dde5845aSJiri Kosina 	collection->usage = usage;
159dde5845aSJiri Kosina 	collection->level = parser->collection_stack_ptr - 1;
160dde5845aSJiri Kosina 
161dde5845aSJiri Kosina 	if (type == HID_COLLECTION_APPLICATION)
162dde5845aSJiri Kosina 		parser->device->maxapplication++;
163dde5845aSJiri Kosina 
164dde5845aSJiri Kosina 	return 0;
165dde5845aSJiri Kosina }
166dde5845aSJiri Kosina 
167dde5845aSJiri Kosina /*
168dde5845aSJiri Kosina  * Close a collection.
169dde5845aSJiri Kosina  */
170dde5845aSJiri Kosina 
171dde5845aSJiri Kosina static int close_collection(struct hid_parser *parser)
172dde5845aSJiri Kosina {
173dde5845aSJiri Kosina 	if (!parser->collection_stack_ptr) {
1748c3d52fcSJiri Kosina 		hid_err(parser->device, "collection stack underflow\n");
175a6fbaacfSSachin Kamat 		return -EINVAL;
176dde5845aSJiri Kosina 	}
177dde5845aSJiri Kosina 	parser->collection_stack_ptr--;
178dde5845aSJiri Kosina 	return 0;
179dde5845aSJiri Kosina }
180dde5845aSJiri Kosina 
181dde5845aSJiri Kosina /*
182dde5845aSJiri Kosina  * Climb up the stack, search for the specified collection type
183dde5845aSJiri Kosina  * and return the usage.
184dde5845aSJiri Kosina  */
185dde5845aSJiri Kosina 
186dde5845aSJiri Kosina static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
187dde5845aSJiri Kosina {
188504499f2SJoe Perches 	struct hid_collection *collection = parser->device->collection;
189dde5845aSJiri Kosina 	int n;
190504499f2SJoe Perches 
191504499f2SJoe Perches 	for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
192504499f2SJoe Perches 		unsigned index = parser->collection_stack[n];
193504499f2SJoe Perches 		if (collection[index].type == type)
194504499f2SJoe Perches 			return collection[index].usage;
195504499f2SJoe Perches 	}
196dde5845aSJiri Kosina 	return 0; /* we know nothing about this usage type */
197dde5845aSJiri Kosina }
198dde5845aSJiri Kosina 
199dde5845aSJiri Kosina /*
200dde5845aSJiri Kosina  * Add a usage to the temporary parser table.
201dde5845aSJiri Kosina  */
202dde5845aSJiri Kosina 
203dde5845aSJiri Kosina static int hid_add_usage(struct hid_parser *parser, unsigned usage)
204dde5845aSJiri Kosina {
205dde5845aSJiri Kosina 	if (parser->local.usage_index >= HID_MAX_USAGES) {
2068c3d52fcSJiri Kosina 		hid_err(parser->device, "usage index exceeded\n");
207dde5845aSJiri Kosina 		return -1;
208dde5845aSJiri Kosina 	}
209dde5845aSJiri Kosina 	parser->local.usage[parser->local.usage_index] = usage;
210dde5845aSJiri Kosina 	parser->local.collection_index[parser->local.usage_index] =
211dde5845aSJiri Kosina 		parser->collection_stack_ptr ?
212dde5845aSJiri Kosina 		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
213dde5845aSJiri Kosina 	parser->local.usage_index++;
214dde5845aSJiri Kosina 	return 0;
215dde5845aSJiri Kosina }
216dde5845aSJiri Kosina 
217dde5845aSJiri Kosina /*
218dde5845aSJiri Kosina  * Register a new field for this report.
219dde5845aSJiri Kosina  */
220dde5845aSJiri Kosina 
221dde5845aSJiri Kosina static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
222dde5845aSJiri Kosina {
223dde5845aSJiri Kosina 	struct hid_report *report;
224dde5845aSJiri Kosina 	struct hid_field *field;
225cc6b54aaSBenjamin Tissoires 	unsigned usages;
226dde5845aSJiri Kosina 	unsigned offset;
227cc6b54aaSBenjamin Tissoires 	unsigned i;
228dde5845aSJiri Kosina 
229a3789a17SJoe Perches 	report = hid_register_report(parser->device, report_type, parser->global.report_id);
230a3789a17SJoe Perches 	if (!report) {
2318c3d52fcSJiri Kosina 		hid_err(parser->device, "hid_register_report failed\n");
232dde5845aSJiri Kosina 		return -1;
233dde5845aSJiri Kosina 	}
234dde5845aSJiri Kosina 
235bb2e1976SJiri Kosina 	/* Handle both signed and unsigned cases properly */
2360cd516c2Ssrinivas pandruvada 	if ((parser->global.logical_minimum < 0 &&
2370cd516c2Ssrinivas pandruvada 		parser->global.logical_maximum <
2380cd516c2Ssrinivas pandruvada 		parser->global.logical_minimum) ||
2390cd516c2Ssrinivas pandruvada 		(parser->global.logical_minimum >= 0 &&
2400cd516c2Ssrinivas pandruvada 		(__u32)parser->global.logical_maximum <
2410cd516c2Ssrinivas pandruvada 		(__u32)parser->global.logical_minimum)) {
2420cd516c2Ssrinivas pandruvada 		dbg_hid("logical range invalid 0x%x 0x%x\n",
2430cd516c2Ssrinivas pandruvada 			parser->global.logical_minimum,
2440cd516c2Ssrinivas pandruvada 			parser->global.logical_maximum);
245dde5845aSJiri Kosina 		return -1;
246dde5845aSJiri Kosina 	}
247dde5845aSJiri Kosina 
248dde5845aSJiri Kosina 	offset = report->size;
249dde5845aSJiri Kosina 	report->size += parser->global.report_size * parser->global.report_count;
250dde5845aSJiri Kosina 
251dde5845aSJiri Kosina 	if (!parser->local.usage_index) /* Ignore padding fields */
252dde5845aSJiri Kosina 		return 0;
253dde5845aSJiri Kosina 
254cc6b54aaSBenjamin Tissoires 	usages = max_t(unsigned, parser->local.usage_index,
255cc6b54aaSBenjamin Tissoires 				 parser->global.report_count);
256dde5845aSJiri Kosina 
257a3789a17SJoe Perches 	field = hid_register_field(report, usages, parser->global.report_count);
258a3789a17SJoe Perches 	if (!field)
259dde5845aSJiri Kosina 		return 0;
260dde5845aSJiri Kosina 
261dde5845aSJiri Kosina 	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
262dde5845aSJiri Kosina 	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
263dde5845aSJiri Kosina 	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
264dde5845aSJiri Kosina 
265dde5845aSJiri Kosina 	for (i = 0; i < usages; i++) {
266cc6b54aaSBenjamin Tissoires 		unsigned j = i;
267dde5845aSJiri Kosina 		/* Duplicate the last usage we parsed if we have excess values */
268dde5845aSJiri Kosina 		if (i >= parser->local.usage_index)
269dde5845aSJiri Kosina 			j = parser->local.usage_index - 1;
270dde5845aSJiri Kosina 		field->usage[i].hid = parser->local.usage[j];
271dde5845aSJiri Kosina 		field->usage[i].collection_index =
272dde5845aSJiri Kosina 			parser->local.collection_index[j];
273cc6b54aaSBenjamin Tissoires 		field->usage[i].usage_index = i;
274dde5845aSJiri Kosina 	}
275dde5845aSJiri Kosina 
276dde5845aSJiri Kosina 	field->maxusage = usages;
277dde5845aSJiri Kosina 	field->flags = flags;
278dde5845aSJiri Kosina 	field->report_offset = offset;
279dde5845aSJiri Kosina 	field->report_type = report_type;
280dde5845aSJiri Kosina 	field->report_size = parser->global.report_size;
281dde5845aSJiri Kosina 	field->report_count = parser->global.report_count;
282dde5845aSJiri Kosina 	field->logical_minimum = parser->global.logical_minimum;
283dde5845aSJiri Kosina 	field->logical_maximum = parser->global.logical_maximum;
284dde5845aSJiri Kosina 	field->physical_minimum = parser->global.physical_minimum;
285dde5845aSJiri Kosina 	field->physical_maximum = parser->global.physical_maximum;
286dde5845aSJiri Kosina 	field->unit_exponent = parser->global.unit_exponent;
287dde5845aSJiri Kosina 	field->unit = parser->global.unit;
288dde5845aSJiri Kosina 
289dde5845aSJiri Kosina 	return 0;
290dde5845aSJiri Kosina }
291dde5845aSJiri Kosina 
292dde5845aSJiri Kosina /*
293dde5845aSJiri Kosina  * Read data value from item.
294dde5845aSJiri Kosina  */
295dde5845aSJiri Kosina 
296dde5845aSJiri Kosina static u32 item_udata(struct hid_item *item)
297dde5845aSJiri Kosina {
298dde5845aSJiri Kosina 	switch (item->size) {
299dde5845aSJiri Kosina 	case 1: return item->data.u8;
300dde5845aSJiri Kosina 	case 2: return item->data.u16;
301dde5845aSJiri Kosina 	case 4: return item->data.u32;
302dde5845aSJiri Kosina 	}
303dde5845aSJiri Kosina 	return 0;
304dde5845aSJiri Kosina }
305dde5845aSJiri Kosina 
306dde5845aSJiri Kosina static s32 item_sdata(struct hid_item *item)
307dde5845aSJiri Kosina {
308dde5845aSJiri Kosina 	switch (item->size) {
309dde5845aSJiri Kosina 	case 1: return item->data.s8;
310dde5845aSJiri Kosina 	case 2: return item->data.s16;
311dde5845aSJiri Kosina 	case 4: return item->data.s32;
312dde5845aSJiri Kosina 	}
313dde5845aSJiri Kosina 	return 0;
314dde5845aSJiri Kosina }
315dde5845aSJiri Kosina 
316dde5845aSJiri Kosina /*
317dde5845aSJiri Kosina  * Process a global item.
318dde5845aSJiri Kosina  */
319dde5845aSJiri Kosina 
320dde5845aSJiri Kosina static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
321dde5845aSJiri Kosina {
322ad0e669bSNikolai Kondrashov 	__s32 raw_value;
323dde5845aSJiri Kosina 	switch (item->tag) {
324dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PUSH:
325dde5845aSJiri Kosina 
326dde5845aSJiri Kosina 		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
3278c3d52fcSJiri Kosina 			hid_err(parser->device, "global environment stack overflow\n");
328dde5845aSJiri Kosina 			return -1;
329dde5845aSJiri Kosina 		}
330dde5845aSJiri Kosina 
331dde5845aSJiri Kosina 		memcpy(parser->global_stack + parser->global_stack_ptr++,
332dde5845aSJiri Kosina 			&parser->global, sizeof(struct hid_global));
333dde5845aSJiri Kosina 		return 0;
334dde5845aSJiri Kosina 
335dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_POP:
336dde5845aSJiri Kosina 
337dde5845aSJiri Kosina 		if (!parser->global_stack_ptr) {
3388c3d52fcSJiri Kosina 			hid_err(parser->device, "global environment stack underflow\n");
339dde5845aSJiri Kosina 			return -1;
340dde5845aSJiri Kosina 		}
341dde5845aSJiri Kosina 
342880d29f1SJiri Slaby 		memcpy(&parser->global, parser->global_stack +
343880d29f1SJiri Slaby 			--parser->global_stack_ptr, sizeof(struct hid_global));
344dde5845aSJiri Kosina 		return 0;
345dde5845aSJiri Kosina 
346dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
347dde5845aSJiri Kosina 		parser->global.usage_page = item_udata(item);
348dde5845aSJiri Kosina 		return 0;
349dde5845aSJiri Kosina 
350dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
351dde5845aSJiri Kosina 		parser->global.logical_minimum = item_sdata(item);
352dde5845aSJiri Kosina 		return 0;
353dde5845aSJiri Kosina 
354dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
355dde5845aSJiri Kosina 		if (parser->global.logical_minimum < 0)
356dde5845aSJiri Kosina 			parser->global.logical_maximum = item_sdata(item);
357dde5845aSJiri Kosina 		else
358dde5845aSJiri Kosina 			parser->global.logical_maximum = item_udata(item);
359dde5845aSJiri Kosina 		return 0;
360dde5845aSJiri Kosina 
361dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
362dde5845aSJiri Kosina 		parser->global.physical_minimum = item_sdata(item);
363dde5845aSJiri Kosina 		return 0;
364dde5845aSJiri Kosina 
365dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
366dde5845aSJiri Kosina 		if (parser->global.physical_minimum < 0)
367dde5845aSJiri Kosina 			parser->global.physical_maximum = item_sdata(item);
368dde5845aSJiri Kosina 		else
369dde5845aSJiri Kosina 			parser->global.physical_maximum = item_udata(item);
370dde5845aSJiri Kosina 		return 0;
371dde5845aSJiri Kosina 
372dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
373ad0e669bSNikolai Kondrashov 		/* Many devices provide unit exponent as a two's complement
374ad0e669bSNikolai Kondrashov 		 * nibble due to the common misunderstanding of HID
375ad0e669bSNikolai Kondrashov 		 * specification 1.11, 6.2.2.7 Global Items. Attempt to handle
376ad0e669bSNikolai Kondrashov 		 * both this and the standard encoding. */
377ad0e669bSNikolai Kondrashov 		raw_value = item_sdata(item);
37877463838SBenjamin Tissoires 		if (!(raw_value & 0xfffffff0))
37977463838SBenjamin Tissoires 			parser->global.unit_exponent = hid_snto32(raw_value, 4);
38077463838SBenjamin Tissoires 		else
38177463838SBenjamin Tissoires 			parser->global.unit_exponent = raw_value;
382dde5845aSJiri Kosina 		return 0;
383dde5845aSJiri Kosina 
384dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT:
385dde5845aSJiri Kosina 		parser->global.unit = item_udata(item);
386dde5845aSJiri Kosina 		return 0;
387dde5845aSJiri Kosina 
388dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
389880d29f1SJiri Slaby 		parser->global.report_size = item_udata(item);
39023408f95SMarek Vasut 		if (parser->global.report_size > 128) {
3918c3d52fcSJiri Kosina 			hid_err(parser->device, "invalid report_size %d\n",
392880d29f1SJiri Slaby 					parser->global.report_size);
393dde5845aSJiri Kosina 			return -1;
394dde5845aSJiri Kosina 		}
395dde5845aSJiri Kosina 		return 0;
396dde5845aSJiri Kosina 
397dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
398880d29f1SJiri Slaby 		parser->global.report_count = item_udata(item);
399880d29f1SJiri Slaby 		if (parser->global.report_count > HID_MAX_USAGES) {
4008c3d52fcSJiri Kosina 			hid_err(parser->device, "invalid report_count %d\n",
401880d29f1SJiri Slaby 					parser->global.report_count);
402dde5845aSJiri Kosina 			return -1;
403dde5845aSJiri Kosina 		}
404dde5845aSJiri Kosina 		return 0;
405dde5845aSJiri Kosina 
406dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
407880d29f1SJiri Slaby 		parser->global.report_id = item_udata(item);
40843622021SKees Cook 		if (parser->global.report_id == 0 ||
40943622021SKees Cook 		    parser->global.report_id >= HID_MAX_IDS) {
41043622021SKees Cook 			hid_err(parser->device, "report_id %u is invalid\n",
41143622021SKees Cook 				parser->global.report_id);
412dde5845aSJiri Kosina 			return -1;
413dde5845aSJiri Kosina 		}
414dde5845aSJiri Kosina 		return 0;
415dde5845aSJiri Kosina 
416dde5845aSJiri Kosina 	default:
4178c3d52fcSJiri Kosina 		hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
418dde5845aSJiri Kosina 		return -1;
419dde5845aSJiri Kosina 	}
420dde5845aSJiri Kosina }
421dde5845aSJiri Kosina 
422dde5845aSJiri Kosina /*
423dde5845aSJiri Kosina  * Process a local item.
424dde5845aSJiri Kosina  */
425dde5845aSJiri Kosina 
426dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
427dde5845aSJiri Kosina {
428dde5845aSJiri Kosina 	__u32 data;
429dde5845aSJiri Kosina 	unsigned n;
430dde5845aSJiri Kosina 
431dde5845aSJiri Kosina 	data = item_udata(item);
432dde5845aSJiri Kosina 
433dde5845aSJiri Kosina 	switch (item->tag) {
434dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_DELIMITER:
435dde5845aSJiri Kosina 
436dde5845aSJiri Kosina 		if (data) {
437dde5845aSJiri Kosina 			/*
438dde5845aSJiri Kosina 			 * We treat items before the first delimiter
439dde5845aSJiri Kosina 			 * as global to all usage sets (branch 0).
440dde5845aSJiri Kosina 			 * In the moment we process only these global
441dde5845aSJiri Kosina 			 * items and the first delimiter set.
442dde5845aSJiri Kosina 			 */
443dde5845aSJiri Kosina 			if (parser->local.delimiter_depth != 0) {
4448c3d52fcSJiri Kosina 				hid_err(parser->device, "nested delimiters\n");
445dde5845aSJiri Kosina 				return -1;
446dde5845aSJiri Kosina 			}
447dde5845aSJiri Kosina 			parser->local.delimiter_depth++;
448dde5845aSJiri Kosina 			parser->local.delimiter_branch++;
449dde5845aSJiri Kosina 		} else {
450dde5845aSJiri Kosina 			if (parser->local.delimiter_depth < 1) {
4518c3d52fcSJiri Kosina 				hid_err(parser->device, "bogus close delimiter\n");
452dde5845aSJiri Kosina 				return -1;
453dde5845aSJiri Kosina 			}
454dde5845aSJiri Kosina 			parser->local.delimiter_depth--;
455dde5845aSJiri Kosina 		}
45638ead6efSPaul Chavent 		return 0;
457dde5845aSJiri Kosina 
458dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE:
459dde5845aSJiri Kosina 
460dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
46158037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
462dde5845aSJiri Kosina 			return 0;
463dde5845aSJiri Kosina 		}
464dde5845aSJiri Kosina 
465dde5845aSJiri Kosina 		if (item->size <= 2)
466dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
467dde5845aSJiri Kosina 
468dde5845aSJiri Kosina 		return hid_add_usage(parser, data);
469dde5845aSJiri Kosina 
470dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
471dde5845aSJiri Kosina 
472dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
47358037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
474dde5845aSJiri Kosina 			return 0;
475dde5845aSJiri Kosina 		}
476dde5845aSJiri Kosina 
477dde5845aSJiri Kosina 		if (item->size <= 2)
478dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
479dde5845aSJiri Kosina 
480dde5845aSJiri Kosina 		parser->local.usage_minimum = data;
481dde5845aSJiri Kosina 		return 0;
482dde5845aSJiri Kosina 
483dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
484dde5845aSJiri Kosina 
485dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
48658037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
487dde5845aSJiri Kosina 			return 0;
488dde5845aSJiri Kosina 		}
489dde5845aSJiri Kosina 
490dde5845aSJiri Kosina 		if (item->size <= 2)
491dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
492dde5845aSJiri Kosina 
493dde5845aSJiri Kosina 		for (n = parser->local.usage_minimum; n <= data; n++)
494dde5845aSJiri Kosina 			if (hid_add_usage(parser, n)) {
49558037eb9SJiri Kosina 				dbg_hid("hid_add_usage failed\n");
496dde5845aSJiri Kosina 				return -1;
497dde5845aSJiri Kosina 			}
498dde5845aSJiri Kosina 		return 0;
499dde5845aSJiri Kosina 
500dde5845aSJiri Kosina 	default:
501dde5845aSJiri Kosina 
50258037eb9SJiri Kosina 		dbg_hid("unknown local item tag 0x%x\n", item->tag);
503dde5845aSJiri Kosina 		return 0;
504dde5845aSJiri Kosina 	}
505dde5845aSJiri Kosina 	return 0;
506dde5845aSJiri Kosina }
507dde5845aSJiri Kosina 
508dde5845aSJiri Kosina /*
509dde5845aSJiri Kosina  * Process a main item.
510dde5845aSJiri Kosina  */
511dde5845aSJiri Kosina 
512dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
513dde5845aSJiri Kosina {
514dde5845aSJiri Kosina 	__u32 data;
515dde5845aSJiri Kosina 	int ret;
516dde5845aSJiri Kosina 
517dde5845aSJiri Kosina 	data = item_udata(item);
518dde5845aSJiri Kosina 
519dde5845aSJiri Kosina 	switch (item->tag) {
520dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
521dde5845aSJiri Kosina 		ret = open_collection(parser, data & 0xff);
522dde5845aSJiri Kosina 		break;
523dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
524dde5845aSJiri Kosina 		ret = close_collection(parser);
525dde5845aSJiri Kosina 		break;
526dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_INPUT:
527dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
528dde5845aSJiri Kosina 		break;
529dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_OUTPUT:
530dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
531dde5845aSJiri Kosina 		break;
532dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_FEATURE:
533dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
534dde5845aSJiri Kosina 		break;
535dde5845aSJiri Kosina 	default:
5368c3d52fcSJiri Kosina 		hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag);
537dde5845aSJiri Kosina 		ret = 0;
538dde5845aSJiri Kosina 	}
539dde5845aSJiri Kosina 
540dde5845aSJiri Kosina 	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
541dde5845aSJiri Kosina 
542dde5845aSJiri Kosina 	return ret;
543dde5845aSJiri Kosina }
544dde5845aSJiri Kosina 
545dde5845aSJiri Kosina /*
546dde5845aSJiri Kosina  * Process a reserved item.
547dde5845aSJiri Kosina  */
548dde5845aSJiri Kosina 
549dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
550dde5845aSJiri Kosina {
55158037eb9SJiri Kosina 	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
552dde5845aSJiri Kosina 	return 0;
553dde5845aSJiri Kosina }
554dde5845aSJiri Kosina 
555dde5845aSJiri Kosina /*
556dde5845aSJiri Kosina  * Free a report and all registered fields. The field->usage and
557dde5845aSJiri Kosina  * field->value table's are allocated behind the field, so we need
558dde5845aSJiri Kosina  * only to free(field) itself.
559dde5845aSJiri Kosina  */
560dde5845aSJiri Kosina 
561dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report)
562dde5845aSJiri Kosina {
563dde5845aSJiri Kosina 	unsigned n;
564dde5845aSJiri Kosina 
565dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
566dde5845aSJiri Kosina 		kfree(report->field[n]);
567dde5845aSJiri Kosina 	kfree(report);
568dde5845aSJiri Kosina }
569dde5845aSJiri Kosina 
570dde5845aSJiri Kosina /*
571a7197c2eSHenrik Rydberg  * Close report. This function returns the device
572a7197c2eSHenrik Rydberg  * state to the point prior to hid_open_report().
573dde5845aSJiri Kosina  */
574a7197c2eSHenrik Rydberg static void hid_close_report(struct hid_device *device)
575dde5845aSJiri Kosina {
576dde5845aSJiri Kosina 	unsigned i, j;
577dde5845aSJiri Kosina 
578dde5845aSJiri Kosina 	for (i = 0; i < HID_REPORT_TYPES; i++) {
579dde5845aSJiri Kosina 		struct hid_report_enum *report_enum = device->report_enum + i;
580dde5845aSJiri Kosina 
58143622021SKees Cook 		for (j = 0; j < HID_MAX_IDS; j++) {
582dde5845aSJiri Kosina 			struct hid_report *report = report_enum->report_id_hash[j];
583dde5845aSJiri Kosina 			if (report)
584dde5845aSJiri Kosina 				hid_free_report(report);
585dde5845aSJiri Kosina 		}
586a7197c2eSHenrik Rydberg 		memset(report_enum, 0, sizeof(*report_enum));
587a7197c2eSHenrik Rydberg 		INIT_LIST_HEAD(&report_enum->report_list);
588dde5845aSJiri Kosina 	}
589dde5845aSJiri Kosina 
590dde5845aSJiri Kosina 	kfree(device->rdesc);
591a7197c2eSHenrik Rydberg 	device->rdesc = NULL;
592a7197c2eSHenrik Rydberg 	device->rsize = 0;
593a7197c2eSHenrik Rydberg 
594767fe787SJiri Kosina 	kfree(device->collection);
595a7197c2eSHenrik Rydberg 	device->collection = NULL;
596a7197c2eSHenrik Rydberg 	device->collection_size = 0;
597a7197c2eSHenrik Rydberg 	device->maxcollection = 0;
598a7197c2eSHenrik Rydberg 	device->maxapplication = 0;
599a7197c2eSHenrik Rydberg 
600a7197c2eSHenrik Rydberg 	device->status &= ~HID_STAT_PARSED;
601a7197c2eSHenrik Rydberg }
602a7197c2eSHenrik Rydberg 
603a7197c2eSHenrik Rydberg /*
604a7197c2eSHenrik Rydberg  * Free a device structure, all reports, and all fields.
605a7197c2eSHenrik Rydberg  */
606a7197c2eSHenrik Rydberg 
607a7197c2eSHenrik Rydberg static void hid_device_release(struct device *dev)
608a7197c2eSHenrik Rydberg {
609a7197c2eSHenrik Rydberg 	struct hid_device *hid = container_of(dev, struct hid_device, dev);
610a7197c2eSHenrik Rydberg 
611a7197c2eSHenrik Rydberg 	hid_close_report(hid);
612a7197c2eSHenrik Rydberg 	kfree(hid->dev_rdesc);
613a7197c2eSHenrik Rydberg 	kfree(hid);
614dde5845aSJiri Kosina }
615dde5845aSJiri Kosina 
616dde5845aSJiri Kosina /*
617dde5845aSJiri Kosina  * Fetch a report description item from the data stream. We support long
618dde5845aSJiri Kosina  * items, though they are not used yet.
619dde5845aSJiri Kosina  */
620dde5845aSJiri Kosina 
621dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
622dde5845aSJiri Kosina {
623dde5845aSJiri Kosina 	u8 b;
624dde5845aSJiri Kosina 
625dde5845aSJiri Kosina 	if ((end - start) <= 0)
626dde5845aSJiri Kosina 		return NULL;
627dde5845aSJiri Kosina 
628dde5845aSJiri Kosina 	b = *start++;
629dde5845aSJiri Kosina 
630dde5845aSJiri Kosina 	item->type = (b >> 2) & 3;
631dde5845aSJiri Kosina 	item->tag  = (b >> 4) & 15;
632dde5845aSJiri Kosina 
633dde5845aSJiri Kosina 	if (item->tag == HID_ITEM_TAG_LONG) {
634dde5845aSJiri Kosina 
635dde5845aSJiri Kosina 		item->format = HID_ITEM_FORMAT_LONG;
636dde5845aSJiri Kosina 
637dde5845aSJiri Kosina 		if ((end - start) < 2)
638dde5845aSJiri Kosina 			return NULL;
639dde5845aSJiri Kosina 
640dde5845aSJiri Kosina 		item->size = *start++;
641dde5845aSJiri Kosina 		item->tag  = *start++;
642dde5845aSJiri Kosina 
643dde5845aSJiri Kosina 		if ((end - start) < item->size)
644dde5845aSJiri Kosina 			return NULL;
645dde5845aSJiri Kosina 
646dde5845aSJiri Kosina 		item->data.longdata = start;
647dde5845aSJiri Kosina 		start += item->size;
648dde5845aSJiri Kosina 		return start;
649dde5845aSJiri Kosina 	}
650dde5845aSJiri Kosina 
651dde5845aSJiri Kosina 	item->format = HID_ITEM_FORMAT_SHORT;
652dde5845aSJiri Kosina 	item->size = b & 3;
653dde5845aSJiri Kosina 
654dde5845aSJiri Kosina 	switch (item->size) {
655dde5845aSJiri Kosina 	case 0:
656dde5845aSJiri Kosina 		return start;
657dde5845aSJiri Kosina 
658dde5845aSJiri Kosina 	case 1:
659dde5845aSJiri Kosina 		if ((end - start) < 1)
660dde5845aSJiri Kosina 			return NULL;
661dde5845aSJiri Kosina 		item->data.u8 = *start++;
662dde5845aSJiri Kosina 		return start;
663dde5845aSJiri Kosina 
664dde5845aSJiri Kosina 	case 2:
665dde5845aSJiri Kosina 		if ((end - start) < 2)
666dde5845aSJiri Kosina 			return NULL;
667c105068fSHarvey Harrison 		item->data.u16 = get_unaligned_le16(start);
668dde5845aSJiri Kosina 		start = (__u8 *)((__le16 *)start + 1);
669dde5845aSJiri Kosina 		return start;
670dde5845aSJiri Kosina 
671dde5845aSJiri Kosina 	case 3:
672dde5845aSJiri Kosina 		item->size++;
673dde5845aSJiri Kosina 		if ((end - start) < 4)
674dde5845aSJiri Kosina 			return NULL;
675c105068fSHarvey Harrison 		item->data.u32 = get_unaligned_le32(start);
676dde5845aSJiri Kosina 		start = (__u8 *)((__le32 *)start + 1);
677dde5845aSJiri Kosina 		return start;
678dde5845aSJiri Kosina 	}
679dde5845aSJiri Kosina 
680dde5845aSJiri Kosina 	return NULL;
681dde5845aSJiri Kosina }
682dde5845aSJiri Kosina 
6833dc8fc08SBenjamin Tissoires static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
684734c6609SHenrik Rydberg {
6853dc8fc08SBenjamin Tissoires 	struct hid_device *hid = parser->device;
6863dc8fc08SBenjamin Tissoires 
6874fa3a583SHenrik Rydberg 	if (usage == HID_DG_CONTACTID)
6884fa3a583SHenrik Rydberg 		hid->group = HID_GROUP_MULTITOUCH;
689734c6609SHenrik Rydberg }
690734c6609SHenrik Rydberg 
691f961bd35SBenjamin Tissoires static void hid_scan_feature_usage(struct hid_parser *parser, u32 usage)
692f961bd35SBenjamin Tissoires {
693f961bd35SBenjamin Tissoires 	if (usage == 0xff0000c5 && parser->global.report_count == 256 &&
694f961bd35SBenjamin Tissoires 	    parser->global.report_size == 8)
695f961bd35SBenjamin Tissoires 		parser->scan_flags |= HID_SCAN_FLAG_MT_WIN_8;
696f961bd35SBenjamin Tissoires }
697f961bd35SBenjamin Tissoires 
6983dc8fc08SBenjamin Tissoires static void hid_scan_collection(struct hid_parser *parser, unsigned type)
6993dc8fc08SBenjamin Tissoires {
7003dc8fc08SBenjamin Tissoires 	struct hid_device *hid = parser->device;
7013dc8fc08SBenjamin Tissoires 
7023dc8fc08SBenjamin Tissoires 	if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
7033dc8fc08SBenjamin Tissoires 	    type == HID_COLLECTION_PHYSICAL)
7043dc8fc08SBenjamin Tissoires 		hid->group = HID_GROUP_SENSOR_HUB;
705be3b1634SAlan Wu 
706be3b1634SAlan Wu 	if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
707be3b1634SAlan Wu 	    hid->product == USB_DEVICE_ID_MS_TYPE_COVER_3 &&
708be3b1634SAlan Wu 	    hid->group == HID_GROUP_MULTITOUCH)
709be3b1634SAlan Wu 		hid->group = HID_GROUP_GENERIC;
7103dc8fc08SBenjamin Tissoires }
7113dc8fc08SBenjamin Tissoires 
7123dc8fc08SBenjamin Tissoires static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
7133dc8fc08SBenjamin Tissoires {
7143dc8fc08SBenjamin Tissoires 	__u32 data;
7153dc8fc08SBenjamin Tissoires 	int i;
7163dc8fc08SBenjamin Tissoires 
7173dc8fc08SBenjamin Tissoires 	data = item_udata(item);
7183dc8fc08SBenjamin Tissoires 
7193dc8fc08SBenjamin Tissoires 	switch (item->tag) {
7203dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
7213dc8fc08SBenjamin Tissoires 		hid_scan_collection(parser, data & 0xff);
7223dc8fc08SBenjamin Tissoires 		break;
7233dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
7243dc8fc08SBenjamin Tissoires 		break;
7253dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_INPUT:
726e24d0d39SBenjamin Tissoires 		/* ignore constant inputs, they will be ignored by hid-input */
727e24d0d39SBenjamin Tissoires 		if (data & HID_MAIN_ITEM_CONSTANT)
728e24d0d39SBenjamin Tissoires 			break;
7293dc8fc08SBenjamin Tissoires 		for (i = 0; i < parser->local.usage_index; i++)
7303dc8fc08SBenjamin Tissoires 			hid_scan_input_usage(parser, parser->local.usage[i]);
7313dc8fc08SBenjamin Tissoires 		break;
7323dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_OUTPUT:
7333dc8fc08SBenjamin Tissoires 		break;
7343dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_FEATURE:
735f961bd35SBenjamin Tissoires 		for (i = 0; i < parser->local.usage_index; i++)
736f961bd35SBenjamin Tissoires 			hid_scan_feature_usage(parser, parser->local.usage[i]);
7373dc8fc08SBenjamin Tissoires 		break;
7383dc8fc08SBenjamin Tissoires 	}
7393dc8fc08SBenjamin Tissoires 
7403dc8fc08SBenjamin Tissoires 	/* Reset the local parser environment */
7413dc8fc08SBenjamin Tissoires 	memset(&parser->local, 0, sizeof(parser->local));
7423dc8fc08SBenjamin Tissoires 
7433dc8fc08SBenjamin Tissoires 	return 0;
7443dc8fc08SBenjamin Tissoires }
7453dc8fc08SBenjamin Tissoires 
746734c6609SHenrik Rydberg /*
747734c6609SHenrik Rydberg  * Scan a report descriptor before the device is added to the bus.
748734c6609SHenrik Rydberg  * Sets device groups and other properties that determine what driver
749734c6609SHenrik Rydberg  * to load.
750734c6609SHenrik Rydberg  */
751734c6609SHenrik Rydberg static int hid_scan_report(struct hid_device *hid)
752734c6609SHenrik Rydberg {
7533dc8fc08SBenjamin Tissoires 	struct hid_parser *parser;
7543dc8fc08SBenjamin Tissoires 	struct hid_item item;
755734c6609SHenrik Rydberg 	__u8 *start = hid->dev_rdesc;
756734c6609SHenrik Rydberg 	__u8 *end = start + hid->dev_rsize;
7573dc8fc08SBenjamin Tissoires 	static int (*dispatch_type[])(struct hid_parser *parser,
7583dc8fc08SBenjamin Tissoires 				      struct hid_item *item) = {
7593dc8fc08SBenjamin Tissoires 		hid_scan_main,
7603dc8fc08SBenjamin Tissoires 		hid_parser_global,
7613dc8fc08SBenjamin Tissoires 		hid_parser_local,
7623dc8fc08SBenjamin Tissoires 		hid_parser_reserved
7633dc8fc08SBenjamin Tissoires 	};
764734c6609SHenrik Rydberg 
7653dc8fc08SBenjamin Tissoires 	parser = vzalloc(sizeof(struct hid_parser));
7663dc8fc08SBenjamin Tissoires 	if (!parser)
7673dc8fc08SBenjamin Tissoires 		return -ENOMEM;
7683dc8fc08SBenjamin Tissoires 
7693dc8fc08SBenjamin Tissoires 	parser->device = hid;
770734c6609SHenrik Rydberg 	hid->group = HID_GROUP_GENERIC;
771734c6609SHenrik Rydberg 
7723dc8fc08SBenjamin Tissoires 	/*
7733dc8fc08SBenjamin Tissoires 	 * The parsing is simpler than the one in hid_open_report() as we should
7743dc8fc08SBenjamin Tissoires 	 * be robust against hid errors. Those errors will be raised by
7753dc8fc08SBenjamin Tissoires 	 * hid_open_report() anyway.
7763dc8fc08SBenjamin Tissoires 	 */
7773dc8fc08SBenjamin Tissoires 	while ((start = fetch_item(start, end, &item)) != NULL)
7783dc8fc08SBenjamin Tissoires 		dispatch_type[item.type](parser, &item);
7793dc8fc08SBenjamin Tissoires 
780f961bd35SBenjamin Tissoires 	/*
781f961bd35SBenjamin Tissoires 	 * Handle special flags set during scanning.
782f961bd35SBenjamin Tissoires 	 */
783f961bd35SBenjamin Tissoires 	if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
784f961bd35SBenjamin Tissoires 	    (hid->group == HID_GROUP_MULTITOUCH))
785f961bd35SBenjamin Tissoires 		hid->group = HID_GROUP_MULTITOUCH_WIN_8;
786f961bd35SBenjamin Tissoires 
787ba391e5aSBenjamin Tissoires 	/*
788ba391e5aSBenjamin Tissoires 	 * Vendor specific handlings
789ba391e5aSBenjamin Tissoires 	 */
79029b47391SBenjamin Tissoires 	switch (hid->vendor) {
79129b47391SBenjamin Tissoires 	case USB_VENDOR_ID_WACOM:
79229b47391SBenjamin Tissoires 		hid->group = HID_GROUP_WACOM;
79329b47391SBenjamin Tissoires 		break;
794c241c5eeSBenjamin Tissoires 	case USB_VENDOR_ID_SYNAPTICS:
795c241c5eeSBenjamin Tissoires 		if ((hid->group == HID_GROUP_GENERIC) &&
796c241c5eeSBenjamin Tissoires 		    (hid->bus != BUS_USB || hid->type == HID_TYPE_USBMOUSE))
797c241c5eeSBenjamin Tissoires 			/* hid-rmi should only bind to the mouse interface of
798c241c5eeSBenjamin Tissoires 			 * composite USB devices */
799c241c5eeSBenjamin Tissoires 			hid->group = HID_GROUP_RMI;
800c241c5eeSBenjamin Tissoires 		break;
80129b47391SBenjamin Tissoires 	}
80229b47391SBenjamin Tissoires 
8033dc8fc08SBenjamin Tissoires 	vfree(parser);
804734c6609SHenrik Rydberg 	return 0;
805734c6609SHenrik Rydberg }
806734c6609SHenrik Rydberg 
80785cdaf52SJiri Slaby /**
80885cdaf52SJiri Slaby  * hid_parse_report - parse device report
80985cdaf52SJiri Slaby  *
81085cdaf52SJiri Slaby  * @device: hid device
81185cdaf52SJiri Slaby  * @start: report start
81285cdaf52SJiri Slaby  * @size: report size
81385cdaf52SJiri Slaby  *
814a7197c2eSHenrik Rydberg  * Allocate the device report as read by the bus driver. This function should
815a7197c2eSHenrik Rydberg  * only be called from parse() in ll drivers.
816a7197c2eSHenrik Rydberg  */
817a7197c2eSHenrik Rydberg int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
818a7197c2eSHenrik Rydberg {
819a7197c2eSHenrik Rydberg 	hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
820a7197c2eSHenrik Rydberg 	if (!hid->dev_rdesc)
821a7197c2eSHenrik Rydberg 		return -ENOMEM;
822a7197c2eSHenrik Rydberg 	hid->dev_rsize = size;
823a7197c2eSHenrik Rydberg 	return 0;
824a7197c2eSHenrik Rydberg }
825a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_parse_report);
826a7197c2eSHenrik Rydberg 
827331415ffSKees Cook static const char * const hid_report_names[] = {
828331415ffSKees Cook 	"HID_INPUT_REPORT",
829331415ffSKees Cook 	"HID_OUTPUT_REPORT",
830331415ffSKees Cook 	"HID_FEATURE_REPORT",
831331415ffSKees Cook };
832331415ffSKees Cook /**
833331415ffSKees Cook  * hid_validate_values - validate existing device report's value indexes
834331415ffSKees Cook  *
835331415ffSKees Cook  * @device: hid device
836331415ffSKees Cook  * @type: which report type to examine
837331415ffSKees Cook  * @id: which report ID to examine (0 for first)
838331415ffSKees Cook  * @field_index: which report field to examine
839331415ffSKees Cook  * @report_counts: expected number of values
840331415ffSKees Cook  *
841331415ffSKees Cook  * Validate the number of values in a given field of a given report, after
842331415ffSKees Cook  * parsing.
843331415ffSKees Cook  */
844331415ffSKees Cook struct hid_report *hid_validate_values(struct hid_device *hid,
845331415ffSKees Cook 				       unsigned int type, unsigned int id,
846331415ffSKees Cook 				       unsigned int field_index,
847331415ffSKees Cook 				       unsigned int report_counts)
848331415ffSKees Cook {
849331415ffSKees Cook 	struct hid_report *report;
850331415ffSKees Cook 
851331415ffSKees Cook 	if (type > HID_FEATURE_REPORT) {
852331415ffSKees Cook 		hid_err(hid, "invalid HID report type %u\n", type);
853331415ffSKees Cook 		return NULL;
854331415ffSKees Cook 	}
855331415ffSKees Cook 
856331415ffSKees Cook 	if (id >= HID_MAX_IDS) {
857331415ffSKees Cook 		hid_err(hid, "invalid HID report id %u\n", id);
858331415ffSKees Cook 		return NULL;
859331415ffSKees Cook 	}
860331415ffSKees Cook 
861331415ffSKees Cook 	/*
862331415ffSKees Cook 	 * Explicitly not using hid_get_report() here since it depends on
863331415ffSKees Cook 	 * ->numbered being checked, which may not always be the case when
864331415ffSKees Cook 	 * drivers go to access report values.
865331415ffSKees Cook 	 */
8661b15d2e5SKees Cook 	if (id == 0) {
8671b15d2e5SKees Cook 		/*
8681b15d2e5SKees Cook 		 * Validating on id 0 means we should examine the first
8691b15d2e5SKees Cook 		 * report in the list.
8701b15d2e5SKees Cook 		 */
8711b15d2e5SKees Cook 		report = list_entry(
8721b15d2e5SKees Cook 				hid->report_enum[type].report_list.next,
8731b15d2e5SKees Cook 				struct hid_report, list);
8741b15d2e5SKees Cook 	} else {
875331415ffSKees Cook 		report = hid->report_enum[type].report_id_hash[id];
8761b15d2e5SKees Cook 	}
877331415ffSKees Cook 	if (!report) {
878331415ffSKees Cook 		hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
879331415ffSKees Cook 		return NULL;
880331415ffSKees Cook 	}
881331415ffSKees Cook 	if (report->maxfield <= field_index) {
882331415ffSKees Cook 		hid_err(hid, "not enough fields in %s %u\n",
883331415ffSKees Cook 			hid_report_names[type], id);
884331415ffSKees Cook 		return NULL;
885331415ffSKees Cook 	}
886331415ffSKees Cook 	if (report->field[field_index]->report_count < report_counts) {
887331415ffSKees Cook 		hid_err(hid, "not enough values in %s %u field %u\n",
888331415ffSKees Cook 			hid_report_names[type], id, field_index);
889331415ffSKees Cook 		return NULL;
890331415ffSKees Cook 	}
891331415ffSKees Cook 	return report;
892331415ffSKees Cook }
893331415ffSKees Cook EXPORT_SYMBOL_GPL(hid_validate_values);
894331415ffSKees Cook 
895a7197c2eSHenrik Rydberg /**
896a7197c2eSHenrik Rydberg  * hid_open_report - open a driver-specific device report
897a7197c2eSHenrik Rydberg  *
898a7197c2eSHenrik Rydberg  * @device: hid device
899a7197c2eSHenrik Rydberg  *
900dde5845aSJiri Kosina  * Parse a report description into a hid_device structure. Reports are
901dde5845aSJiri Kosina  * enumerated, fields are attached to these reports.
90285cdaf52SJiri Slaby  * 0 returned on success, otherwise nonzero error value.
903a7197c2eSHenrik Rydberg  *
904a7197c2eSHenrik Rydberg  * This function (or the equivalent hid_parse() macro) should only be
905a7197c2eSHenrik Rydberg  * called from probe() in drivers, before starting the device.
906dde5845aSJiri Kosina  */
907a7197c2eSHenrik Rydberg int hid_open_report(struct hid_device *device)
908dde5845aSJiri Kosina {
909dde5845aSJiri Kosina 	struct hid_parser *parser;
910dde5845aSJiri Kosina 	struct hid_item item;
911a7197c2eSHenrik Rydberg 	unsigned int size;
912a7197c2eSHenrik Rydberg 	__u8 *start;
91386e6b77eSKevin Daughtridge 	__u8 *buf;
914dde5845aSJiri Kosina 	__u8 *end;
91585cdaf52SJiri Slaby 	int ret;
916dde5845aSJiri Kosina 	static int (*dispatch_type[])(struct hid_parser *parser,
917dde5845aSJiri Kosina 				      struct hid_item *item) = {
918dde5845aSJiri Kosina 		hid_parser_main,
919dde5845aSJiri Kosina 		hid_parser_global,
920dde5845aSJiri Kosina 		hid_parser_local,
921dde5845aSJiri Kosina 		hid_parser_reserved
922dde5845aSJiri Kosina 	};
923dde5845aSJiri Kosina 
924a7197c2eSHenrik Rydberg 	if (WARN_ON(device->status & HID_STAT_PARSED))
925a7197c2eSHenrik Rydberg 		return -EBUSY;
926a7197c2eSHenrik Rydberg 
927a7197c2eSHenrik Rydberg 	start = device->dev_rdesc;
928a7197c2eSHenrik Rydberg 	if (WARN_ON(!start))
929a7197c2eSHenrik Rydberg 		return -ENODEV;
930a7197c2eSHenrik Rydberg 	size = device->dev_rsize;
931a7197c2eSHenrik Rydberg 
93286e6b77eSKevin Daughtridge 	buf = kmemdup(start, size, GFP_KERNEL);
93386e6b77eSKevin Daughtridge 	if (buf == NULL)
93485cdaf52SJiri Slaby 		return -ENOMEM;
93586e6b77eSKevin Daughtridge 
93686e6b77eSKevin Daughtridge 	if (device->driver->report_fixup)
93786e6b77eSKevin Daughtridge 		start = device->driver->report_fixup(device, buf, &size);
93886e6b77eSKevin Daughtridge 	else
93986e6b77eSKevin Daughtridge 		start = buf;
94086e6b77eSKevin Daughtridge 
94186e6b77eSKevin Daughtridge 	start = kmemdup(start, size, GFP_KERNEL);
94286e6b77eSKevin Daughtridge 	kfree(buf);
94386e6b77eSKevin Daughtridge 	if (start == NULL)
94486e6b77eSKevin Daughtridge 		return -ENOMEM;
94586e6b77eSKevin Daughtridge 
94686e6b77eSKevin Daughtridge 	device->rdesc = start;
947dde5845aSJiri Kosina 	device->rsize = size;
948dde5845aSJiri Kosina 
949fe258020SJoe Perches 	parser = vzalloc(sizeof(struct hid_parser));
95085cdaf52SJiri Slaby 	if (!parser) {
95185cdaf52SJiri Slaby 		ret = -ENOMEM;
95285cdaf52SJiri Slaby 		goto err;
953dde5845aSJiri Kosina 	}
95485cdaf52SJiri Slaby 
955dde5845aSJiri Kosina 	parser->device = device;
956dde5845aSJiri Kosina 
957dde5845aSJiri Kosina 	end = start + size;
958a7197c2eSHenrik Rydberg 
959a7197c2eSHenrik Rydberg 	device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
960a7197c2eSHenrik Rydberg 				     sizeof(struct hid_collection), GFP_KERNEL);
961a7197c2eSHenrik Rydberg 	if (!device->collection) {
962a7197c2eSHenrik Rydberg 		ret = -ENOMEM;
963a7197c2eSHenrik Rydberg 		goto err;
964a7197c2eSHenrik Rydberg 	}
965a7197c2eSHenrik Rydberg 	device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
966a7197c2eSHenrik Rydberg 
96785cdaf52SJiri Slaby 	ret = -EINVAL;
968dde5845aSJiri Kosina 	while ((start = fetch_item(start, end, &item)) != NULL) {
969dde5845aSJiri Kosina 
970dde5845aSJiri Kosina 		if (item.format != HID_ITEM_FORMAT_SHORT) {
9718c3d52fcSJiri Kosina 			hid_err(device, "unexpected long global item\n");
97285cdaf52SJiri Slaby 			goto err;
973dde5845aSJiri Kosina 		}
974dde5845aSJiri Kosina 
975dde5845aSJiri Kosina 		if (dispatch_type[item.type](parser, &item)) {
9768c3d52fcSJiri Kosina 			hid_err(device, "item %u %u %u %u parsing failed\n",
9774291ee30SJoe Perches 				item.format, (unsigned)item.size,
9784291ee30SJoe Perches 				(unsigned)item.type, (unsigned)item.tag);
97985cdaf52SJiri Slaby 			goto err;
980dde5845aSJiri Kosina 		}
981dde5845aSJiri Kosina 
982dde5845aSJiri Kosina 		if (start == end) {
983dde5845aSJiri Kosina 			if (parser->collection_stack_ptr) {
9848c3d52fcSJiri Kosina 				hid_err(device, "unbalanced collection at end of report description\n");
98585cdaf52SJiri Slaby 				goto err;
986dde5845aSJiri Kosina 			}
987dde5845aSJiri Kosina 			if (parser->local.delimiter_depth) {
9888c3d52fcSJiri Kosina 				hid_err(device, "unbalanced delimiter at end of report description\n");
98985cdaf52SJiri Slaby 				goto err;
990dde5845aSJiri Kosina 			}
99147a80edbSJiri Kosina 			vfree(parser);
992a7197c2eSHenrik Rydberg 			device->status |= HID_STAT_PARSED;
99385cdaf52SJiri Slaby 			return 0;
994dde5845aSJiri Kosina 		}
995dde5845aSJiri Kosina 	}
996dde5845aSJiri Kosina 
9978c3d52fcSJiri Kosina 	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
99885cdaf52SJiri Slaby err:
99947a80edbSJiri Kosina 	vfree(parser);
1000a7197c2eSHenrik Rydberg 	hid_close_report(device);
100185cdaf52SJiri Slaby 	return ret;
1002dde5845aSJiri Kosina }
1003a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_open_report);
1004dde5845aSJiri Kosina 
1005dde5845aSJiri Kosina /*
1006dde5845aSJiri Kosina  * Convert a signed n-bit integer to signed 32-bit integer. Common
1007dde5845aSJiri Kosina  * cases are done through the compiler, the screwed things has to be
1008dde5845aSJiri Kosina  * done by hand.
1009dde5845aSJiri Kosina  */
1010dde5845aSJiri Kosina 
1011dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n)
1012dde5845aSJiri Kosina {
1013dde5845aSJiri Kosina 	switch (n) {
1014dde5845aSJiri Kosina 	case 8:  return ((__s8)value);
1015dde5845aSJiri Kosina 	case 16: return ((__s16)value);
1016dde5845aSJiri Kosina 	case 32: return ((__s32)value);
1017dde5845aSJiri Kosina 	}
1018dde5845aSJiri Kosina 	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
1019dde5845aSJiri Kosina }
1020dde5845aSJiri Kosina 
102177463838SBenjamin Tissoires s32 hid_snto32(__u32 value, unsigned n)
102277463838SBenjamin Tissoires {
102377463838SBenjamin Tissoires 	return snto32(value, n);
102477463838SBenjamin Tissoires }
102577463838SBenjamin Tissoires EXPORT_SYMBOL_GPL(hid_snto32);
102677463838SBenjamin Tissoires 
1027dde5845aSJiri Kosina /*
1028dde5845aSJiri Kosina  * Convert a signed 32-bit integer to a signed n-bit integer.
1029dde5845aSJiri Kosina  */
1030dde5845aSJiri Kosina 
1031dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n)
1032dde5845aSJiri Kosina {
1033dde5845aSJiri Kosina 	s32 a = value >> (n - 1);
1034dde5845aSJiri Kosina 	if (a && a != -1)
1035dde5845aSJiri Kosina 		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
1036dde5845aSJiri Kosina 	return value & ((1 << n) - 1);
1037dde5845aSJiri Kosina }
1038dde5845aSJiri Kosina 
1039dde5845aSJiri Kosina /*
1040dde5845aSJiri Kosina  * Extract/implement a data field from/to a little endian report (bit array).
1041dde5845aSJiri Kosina  *
1042dde5845aSJiri Kosina  * Code sort-of follows HID spec:
1043dde5845aSJiri Kosina  *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
1044dde5845aSJiri Kosina  *
1045dde5845aSJiri Kosina  * While the USB HID spec allows unlimited length bit fields in "report
1046dde5845aSJiri Kosina  * descriptors", most devices never use more than 16 bits.
1047dde5845aSJiri Kosina  * One model of UPS is claimed to report "LINEV" as a 32-bit field.
1048dde5845aSJiri Kosina  * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
1049dde5845aSJiri Kosina  */
1050dde5845aSJiri Kosina 
105116ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report,
10524291ee30SJoe Perches 		     unsigned offset, unsigned n)
1053dde5845aSJiri Kosina {
1054dde5845aSJiri Kosina 	u64 x;
1055dde5845aSJiri Kosina 
1056c4124c9bSJiri Kosina 	if (n > 32)
10574291ee30SJoe Perches 		hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
1058c4124c9bSJiri Kosina 			 n, current->comm);
1059dde5845aSJiri Kosina 
1060dde5845aSJiri Kosina 	report += offset >> 3;  /* adjust byte index */
1061dde5845aSJiri Kosina 	offset &= 7;            /* now only need bit offset into one byte */
1062c105068fSHarvey Harrison 	x = get_unaligned_le64(report);
1063dde5845aSJiri Kosina 	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
1064dde5845aSJiri Kosina 	return (u32) x;
1065dde5845aSJiri Kosina }
1066dde5845aSJiri Kosina 
1067dde5845aSJiri Kosina /*
1068dde5845aSJiri Kosina  * "implement" : set bits in a little endian bit stream.
1069dde5845aSJiri Kosina  * Same concepts as "extract" (see comments above).
1070dde5845aSJiri Kosina  * The data mangled in the bit stream remains in little endian
1071dde5845aSJiri Kosina  * order the whole time. It make more sense to talk about
1072dde5845aSJiri Kosina  * endianness of register values by considering a register
1073dde5845aSJiri Kosina  * a "cached" copy of the little endiad bit stream.
1074dde5845aSJiri Kosina  */
107516ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report,
10764291ee30SJoe Perches 		      unsigned offset, unsigned n, __u32 value)
1077dde5845aSJiri Kosina {
10786f0168d2SHarvey Harrison 	u64 x;
1079dde5845aSJiri Kosina 	u64 m = (1ULL << n) - 1;
1080dde5845aSJiri Kosina 
1081c4124c9bSJiri Kosina 	if (n > 32)
10824291ee30SJoe Perches 		hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
10834291ee30SJoe Perches 			 __func__, n, current->comm);
1084dde5845aSJiri Kosina 
1085c4124c9bSJiri Kosina 	if (value > m)
10864291ee30SJoe Perches 		hid_warn(hid, "%s() called with too large value %d! (%s)\n",
10874291ee30SJoe Perches 			 __func__, value, current->comm);
1088dde5845aSJiri Kosina 	WARN_ON(value > m);
1089dde5845aSJiri Kosina 	value &= m;
1090dde5845aSJiri Kosina 
1091dde5845aSJiri Kosina 	report += offset >> 3;
1092dde5845aSJiri Kosina 	offset &= 7;
1093dde5845aSJiri Kosina 
10946f0168d2SHarvey Harrison 	x = get_unaligned_le64(report);
10956f0168d2SHarvey Harrison 	x &= ~(m << offset);
10966f0168d2SHarvey Harrison 	x |= ((u64)value) << offset;
10976f0168d2SHarvey Harrison 	put_unaligned_le64(x, report);
1098dde5845aSJiri Kosina }
1099dde5845aSJiri Kosina 
1100dde5845aSJiri Kosina /*
1101dde5845aSJiri Kosina  * Search an array for a value.
1102dde5845aSJiri Kosina  */
1103dde5845aSJiri Kosina 
110416ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n)
1105dde5845aSJiri Kosina {
1106dde5845aSJiri Kosina 	while (n--) {
1107dde5845aSJiri Kosina 		if (*array++ == value)
1108dde5845aSJiri Kosina 			return 0;
1109dde5845aSJiri Kosina 	}
1110dde5845aSJiri Kosina 	return -1;
1111dde5845aSJiri Kosina }
1112dde5845aSJiri Kosina 
111385cdaf52SJiri Slaby /**
111485cdaf52SJiri Slaby  * hid_match_report - check if driver's raw_event should be called
111585cdaf52SJiri Slaby  *
111685cdaf52SJiri Slaby  * @hid: hid device
111785cdaf52SJiri Slaby  * @report_type: type to match against
111885cdaf52SJiri Slaby  *
111985cdaf52SJiri Slaby  * compare hid->driver->report_table->report_type to report->type
112085cdaf52SJiri Slaby  */
112185cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report)
1122dde5845aSJiri Kosina {
112385cdaf52SJiri Slaby 	const struct hid_report_id *id = hid->driver->report_table;
112485cdaf52SJiri Slaby 
112585cdaf52SJiri Slaby 	if (!id) /* NULL means all */
112685cdaf52SJiri Slaby 		return 1;
112785cdaf52SJiri Slaby 
112885cdaf52SJiri Slaby 	for (; id->report_type != HID_TERMINATOR; id++)
112985cdaf52SJiri Slaby 		if (id->report_type == HID_ANY_ID ||
113085cdaf52SJiri Slaby 				id->report_type == report->type)
113185cdaf52SJiri Slaby 			return 1;
113285cdaf52SJiri Slaby 	return 0;
113385cdaf52SJiri Slaby }
113485cdaf52SJiri Slaby 
113585cdaf52SJiri Slaby /**
113685cdaf52SJiri Slaby  * hid_match_usage - check if driver's event should be called
113785cdaf52SJiri Slaby  *
113885cdaf52SJiri Slaby  * @hid: hid device
113985cdaf52SJiri Slaby  * @usage: usage to match against
114085cdaf52SJiri Slaby  *
114185cdaf52SJiri Slaby  * compare hid->driver->usage_table->usage_{type,code} to
114285cdaf52SJiri Slaby  * usage->usage_{type,code}
114385cdaf52SJiri Slaby  */
114485cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
114585cdaf52SJiri Slaby {
114685cdaf52SJiri Slaby 	const struct hid_usage_id *id = hid->driver->usage_table;
114785cdaf52SJiri Slaby 
114885cdaf52SJiri Slaby 	if (!id) /* NULL means all */
114985cdaf52SJiri Slaby 		return 1;
115085cdaf52SJiri Slaby 
115185cdaf52SJiri Slaby 	for (; id->usage_type != HID_ANY_ID - 1; id++)
115285cdaf52SJiri Slaby 		if ((id->usage_hid == HID_ANY_ID ||
115385cdaf52SJiri Slaby 				id->usage_hid == usage->hid) &&
115485cdaf52SJiri Slaby 				(id->usage_type == HID_ANY_ID ||
115585cdaf52SJiri Slaby 				id->usage_type == usage->type) &&
115685cdaf52SJiri Slaby 				(id->usage_code == HID_ANY_ID ||
115785cdaf52SJiri Slaby 				 id->usage_code == usage->code))
115885cdaf52SJiri Slaby 			return 1;
115985cdaf52SJiri Slaby 	return 0;
116085cdaf52SJiri Slaby }
116185cdaf52SJiri Slaby 
116285cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field,
116385cdaf52SJiri Slaby 		struct hid_usage *usage, __s32 value, int interrupt)
116485cdaf52SJiri Slaby {
116585cdaf52SJiri Slaby 	struct hid_driver *hdrv = hid->driver;
116685cdaf52SJiri Slaby 	int ret;
116785cdaf52SJiri Slaby 
11689bfc8da0SHenrik Rydberg 	if (!list_empty(&hid->debug_list))
1169cd667ce2SJiri Kosina 		hid_dump_input(hid, usage, value);
117085cdaf52SJiri Slaby 
117185cdaf52SJiri Slaby 	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
117285cdaf52SJiri Slaby 		ret = hdrv->event(hid, field, usage, value);
117385cdaf52SJiri Slaby 		if (ret != 0) {
117485cdaf52SJiri Slaby 			if (ret < 0)
11758c3d52fcSJiri Kosina 				hid_err(hid, "%s's event failed with %d\n",
117685cdaf52SJiri Slaby 						hdrv->name, ret);
117785cdaf52SJiri Slaby 			return;
117885cdaf52SJiri Slaby 		}
117985cdaf52SJiri Slaby 	}
118085cdaf52SJiri Slaby 
1181dde5845aSJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1182dde5845aSJiri Kosina 		hidinput_hid_event(hid, field, usage, value);
1183aa938f79SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
1184aa938f79SJiri Kosina 		hid->hiddev_hid_event(hid, field, usage, value);
1185dde5845aSJiri Kosina }
1186dde5845aSJiri Kosina 
1187dde5845aSJiri Kosina /*
1188dde5845aSJiri Kosina  * Analyse a received field, and fetch the data from it. The field
1189dde5845aSJiri Kosina  * content is stored for next report processing (we do differential
1190dde5845aSJiri Kosina  * reporting to the layer).
1191dde5845aSJiri Kosina  */
1192dde5845aSJiri Kosina 
1193abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field,
1194abdff0f7SAdrian Bunk 			    __u8 *data, int interrupt)
1195dde5845aSJiri Kosina {
1196dde5845aSJiri Kosina 	unsigned n;
1197dde5845aSJiri Kosina 	unsigned count = field->report_count;
1198dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
1199dde5845aSJiri Kosina 	unsigned size = field->report_size;
1200dde5845aSJiri Kosina 	__s32 min = field->logical_minimum;
1201dde5845aSJiri Kosina 	__s32 max = field->logical_maximum;
1202dde5845aSJiri Kosina 	__s32 *value;
1203dde5845aSJiri Kosina 
1204a3789a17SJoe Perches 	value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
1205a3789a17SJoe Perches 	if (!value)
1206dde5845aSJiri Kosina 		return;
1207dde5845aSJiri Kosina 
1208dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1209dde5845aSJiri Kosina 
12104291ee30SJoe Perches 		value[n] = min < 0 ?
12114291ee30SJoe Perches 			snto32(extract(hid, data, offset + n * size, size),
12124291ee30SJoe Perches 			       size) :
12134291ee30SJoe Perches 			extract(hid, data, offset + n * size, size);
1214dde5845aSJiri Kosina 
12154291ee30SJoe Perches 		/* Ignore report if ErrorRollOver */
12164291ee30SJoe Perches 		if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
12174291ee30SJoe Perches 		    value[n] >= min && value[n] <= max &&
12184291ee30SJoe Perches 		    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
1219dde5845aSJiri Kosina 			goto exit;
1220dde5845aSJiri Kosina 	}
1221dde5845aSJiri Kosina 
1222dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1223dde5845aSJiri Kosina 
1224dde5845aSJiri Kosina 		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
1225dde5845aSJiri Kosina 			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
1226dde5845aSJiri Kosina 			continue;
1227dde5845aSJiri Kosina 		}
1228dde5845aSJiri Kosina 
1229dde5845aSJiri Kosina 		if (field->value[n] >= min && field->value[n] <= max
1230dde5845aSJiri Kosina 			&& field->usage[field->value[n] - min].hid
1231dde5845aSJiri Kosina 			&& search(value, field->value[n], count))
1232dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
1233dde5845aSJiri Kosina 
1234dde5845aSJiri Kosina 		if (value[n] >= min && value[n] <= max
1235dde5845aSJiri Kosina 			&& field->usage[value[n] - min].hid
1236dde5845aSJiri Kosina 			&& search(field->value, value[n], count))
1237dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
1238dde5845aSJiri Kosina 	}
1239dde5845aSJiri Kosina 
1240dde5845aSJiri Kosina 	memcpy(field->value, value, count * sizeof(__s32));
1241dde5845aSJiri Kosina exit:
1242dde5845aSJiri Kosina 	kfree(value);
1243dde5845aSJiri Kosina }
1244dde5845aSJiri Kosina 
1245dde5845aSJiri Kosina /*
1246dde5845aSJiri Kosina  * Output the field into the report.
1247dde5845aSJiri Kosina  */
1248dde5845aSJiri Kosina 
12494291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid,
12504291ee30SJoe Perches 			     struct hid_field *field, __u8 *data)
1251dde5845aSJiri Kosina {
1252dde5845aSJiri Kosina 	unsigned count = field->report_count;
1253dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
1254dde5845aSJiri Kosina 	unsigned size = field->report_size;
1255dde5845aSJiri Kosina 	unsigned n;
1256dde5845aSJiri Kosina 
1257dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1258dde5845aSJiri Kosina 		if (field->logical_minimum < 0)	/* signed values */
12594291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
12604291ee30SJoe Perches 				  s32ton(field->value[n], size));
1261dde5845aSJiri Kosina 		else				/* unsigned values */
12624291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
12634291ee30SJoe Perches 				  field->value[n]);
1264dde5845aSJiri Kosina 	}
1265dde5845aSJiri Kosina }
1266dde5845aSJiri Kosina 
1267dde5845aSJiri Kosina /*
126827ce4050SJiri Kosina  * Create a report. 'data' has to be allocated using
126927ce4050SJiri Kosina  * hid_alloc_report_buf() so that it has proper size.
1270dde5845aSJiri Kosina  */
1271dde5845aSJiri Kosina 
1272229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data)
1273dde5845aSJiri Kosina {
1274dde5845aSJiri Kosina 	unsigned n;
1275dde5845aSJiri Kosina 
1276dde5845aSJiri Kosina 	if (report->id > 0)
1277dde5845aSJiri Kosina 		*data++ = report->id;
1278dde5845aSJiri Kosina 
127975c28df8SPete Zaitcev 	memset(data, 0, ((report->size - 1) >> 3) + 1);
1280dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
12814291ee30SJoe Perches 		hid_output_field(report->device, report->field[n], data);
1282dde5845aSJiri Kosina }
1283229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report);
1284dde5845aSJiri Kosina 
1285dde5845aSJiri Kosina /*
128627ce4050SJiri Kosina  * Allocator for buffer that is going to be passed to hid_output_report()
128727ce4050SJiri Kosina  */
128827ce4050SJiri Kosina u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
128927ce4050SJiri Kosina {
129027ce4050SJiri Kosina 	/*
129127ce4050SJiri Kosina 	 * 7 extra bytes are necessary to achieve proper functionality
129227ce4050SJiri Kosina 	 * of implement() working on 8 byte chunks
129327ce4050SJiri Kosina 	 */
129427ce4050SJiri Kosina 
129519e4ec52SBenjamin Tissoires 	int len = hid_report_len(report) + 7;
129627ce4050SJiri Kosina 
129727ce4050SJiri Kosina 	return kmalloc(len, flags);
129827ce4050SJiri Kosina }
129927ce4050SJiri Kosina EXPORT_SYMBOL_GPL(hid_alloc_report_buf);
130027ce4050SJiri Kosina 
130127ce4050SJiri Kosina /*
1302dde5845aSJiri Kosina  * Set a field value. The report this field belongs to has to be
1303dde5845aSJiri Kosina  * created and transferred to the device, to set this value in the
1304dde5845aSJiri Kosina  * device.
1305dde5845aSJiri Kosina  */
1306dde5845aSJiri Kosina 
1307dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1308dde5845aSJiri Kosina {
1309be67b68dSKees Cook 	unsigned size;
1310be67b68dSKees Cook 
1311be67b68dSKees Cook 	if (!field)
1312be67b68dSKees Cook 		return -1;
1313be67b68dSKees Cook 
1314be67b68dSKees Cook 	size = field->report_size;
1315dde5845aSJiri Kosina 
1316cd667ce2SJiri Kosina 	hid_dump_input(field->report->device, field->usage + offset, value);
1317dde5845aSJiri Kosina 
1318dde5845aSJiri Kosina 	if (offset >= field->report_count) {
13198c3d52fcSJiri Kosina 		hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
13208c3d52fcSJiri Kosina 				offset, field->report_count);
1321dde5845aSJiri Kosina 		return -1;
1322dde5845aSJiri Kosina 	}
1323dde5845aSJiri Kosina 	if (field->logical_minimum < 0) {
1324dde5845aSJiri Kosina 		if (value != snto32(s32ton(value, size), size)) {
13258c3d52fcSJiri Kosina 			hid_err(field->report->device, "value %d is out of range\n", value);
1326dde5845aSJiri Kosina 			return -1;
1327dde5845aSJiri Kosina 		}
1328dde5845aSJiri Kosina 	}
1329dde5845aSJiri Kosina 	field->value[offset] = value;
1330dde5845aSJiri Kosina 	return 0;
1331dde5845aSJiri Kosina }
1332229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field);
1333dde5845aSJiri Kosina 
133485cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
133585cdaf52SJiri Slaby 		const u8 *data)
133685cdaf52SJiri Slaby {
133785cdaf52SJiri Slaby 	struct hid_report *report;
133885cdaf52SJiri Slaby 	unsigned int n = 0;	/* Normally report number is 0 */
133985cdaf52SJiri Slaby 
134085cdaf52SJiri Slaby 	/* Device uses numbered reports, data[0] is report number */
134185cdaf52SJiri Slaby 	if (report_enum->numbered)
134285cdaf52SJiri Slaby 		n = *data;
134385cdaf52SJiri Slaby 
134485cdaf52SJiri Slaby 	report = report_enum->report_id_hash[n];
134585cdaf52SJiri Slaby 	if (report == NULL)
134685cdaf52SJiri Slaby 		dbg_hid("undefined report_id %u received\n", n);
134785cdaf52SJiri Slaby 
134885cdaf52SJiri Slaby 	return report;
134985cdaf52SJiri Slaby }
135085cdaf52SJiri Slaby 
13514fa5a7f7SBenjamin Tissoires /*
13524fa5a7f7SBenjamin Tissoires  * Implement a generic .request() callback, using .raw_request()
13534fa5a7f7SBenjamin Tissoires  * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
13544fa5a7f7SBenjamin Tissoires  */
13554fa5a7f7SBenjamin Tissoires void __hid_request(struct hid_device *hid, struct hid_report *report,
13564fa5a7f7SBenjamin Tissoires 		int reqtype)
13574fa5a7f7SBenjamin Tissoires {
13584fa5a7f7SBenjamin Tissoires 	char *buf;
13594fa5a7f7SBenjamin Tissoires 	int ret;
13604fa5a7f7SBenjamin Tissoires 	int len;
13614fa5a7f7SBenjamin Tissoires 
13624fa5a7f7SBenjamin Tissoires 	buf = hid_alloc_report_buf(report, GFP_KERNEL);
13634fa5a7f7SBenjamin Tissoires 	if (!buf)
13644fa5a7f7SBenjamin Tissoires 		return;
13654fa5a7f7SBenjamin Tissoires 
13664fa5a7f7SBenjamin Tissoires 	len = hid_report_len(report);
13674fa5a7f7SBenjamin Tissoires 
13684fa5a7f7SBenjamin Tissoires 	if (reqtype == HID_REQ_SET_REPORT)
13694fa5a7f7SBenjamin Tissoires 		hid_output_report(report, buf);
13704fa5a7f7SBenjamin Tissoires 
13714fa5a7f7SBenjamin Tissoires 	ret = hid->ll_driver->raw_request(hid, report->id, buf, len,
13724fa5a7f7SBenjamin Tissoires 					  report->type, reqtype);
13734fa5a7f7SBenjamin Tissoires 	if (ret < 0) {
13744fa5a7f7SBenjamin Tissoires 		dbg_hid("unable to complete request: %d\n", ret);
13754fa5a7f7SBenjamin Tissoires 		goto out;
13764fa5a7f7SBenjamin Tissoires 	}
13774fa5a7f7SBenjamin Tissoires 
13784fa5a7f7SBenjamin Tissoires 	if (reqtype == HID_REQ_GET_REPORT)
13794fa5a7f7SBenjamin Tissoires 		hid_input_report(hid, report->type, buf, ret, 0);
13804fa5a7f7SBenjamin Tissoires 
13814fa5a7f7SBenjamin Tissoires out:
13824fa5a7f7SBenjamin Tissoires 	kfree(buf);
13834fa5a7f7SBenjamin Tissoires }
13844fa5a7f7SBenjamin Tissoires EXPORT_SYMBOL_GPL(__hid_request);
13854fa5a7f7SBenjamin Tissoires 
1386b6787242SJiri Kosina int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
138785cdaf52SJiri Slaby 		int interrupt)
1388aa8de2f0SJiri Kosina {
1389aa8de2f0SJiri Kosina 	struct hid_report_enum *report_enum = hid->report_enum + type;
1390aa8de2f0SJiri Kosina 	struct hid_report *report;
13916d85d037SBenjamin Tissoires 	struct hid_driver *hdrv;
139285cdaf52SJiri Slaby 	unsigned int a;
139385cdaf52SJiri Slaby 	int rsize, csize = size;
139485cdaf52SJiri Slaby 	u8 *cdata = data;
1395b6787242SJiri Kosina 	int ret = 0;
1396aa8de2f0SJiri Kosina 
139785cdaf52SJiri Slaby 	report = hid_get_report(report_enum, data);
139885cdaf52SJiri Slaby 	if (!report)
1399b6787242SJiri Kosina 		goto out;
1400aa8de2f0SJiri Kosina 
140185cdaf52SJiri Slaby 	if (report_enum->numbered) {
140285cdaf52SJiri Slaby 		cdata++;
140385cdaf52SJiri Slaby 		csize--;
1404aa8de2f0SJiri Kosina 	}
1405aa8de2f0SJiri Kosina 
1406aa8de2f0SJiri Kosina 	rsize = ((report->size - 1) >> 3) + 1;
1407aa8de2f0SJiri Kosina 
1408966922f2SArmando Visconti 	if (rsize > HID_MAX_BUFFER_SIZE)
1409966922f2SArmando Visconti 		rsize = HID_MAX_BUFFER_SIZE;
1410966922f2SArmando Visconti 
141185cdaf52SJiri Slaby 	if (csize < rsize) {
141285cdaf52SJiri Slaby 		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
141385cdaf52SJiri Slaby 				csize, rsize);
141485cdaf52SJiri Slaby 		memset(cdata + csize, 0, rsize - csize);
1415aa8de2f0SJiri Kosina 	}
1416aa8de2f0SJiri Kosina 
1417aa8de2f0SJiri Kosina 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1418aa8de2f0SJiri Kosina 		hid->hiddev_report_event(hid, report);
1419b6787242SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDRAW) {
1420b6787242SJiri Kosina 		ret = hidraw_report_event(hid, data, size);
1421b6787242SJiri Kosina 		if (ret)
1422b6787242SJiri Kosina 			goto out;
1423b6787242SJiri Kosina 	}
1424aa8de2f0SJiri Kosina 
1425cc6b54aaSBenjamin Tissoires 	if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) {
142685cdaf52SJiri Slaby 		for (a = 0; a < report->maxfield; a++)
142785cdaf52SJiri Slaby 			hid_input_field(hid, report->field[a], cdata, interrupt);
14286d85d037SBenjamin Tissoires 		hdrv = hid->driver;
14296d85d037SBenjamin Tissoires 		if (hdrv && hdrv->report)
14306d85d037SBenjamin Tissoires 			hdrv->report(hid, report);
1431b94e3c94SMatthieu CASTET 	}
1432aa8de2f0SJiri Kosina 
1433aa8de2f0SJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1434aa8de2f0SJiri Kosina 		hidinput_report_event(hid, report);
1435b6787242SJiri Kosina out:
1436b6787242SJiri Kosina 	return ret;
143785cdaf52SJiri Slaby }
143885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event);
143985cdaf52SJiri Slaby 
144085cdaf52SJiri Slaby /**
144185cdaf52SJiri Slaby  * hid_input_report - report data from lower layer (usb, bt...)
144285cdaf52SJiri Slaby  *
144385cdaf52SJiri Slaby  * @hid: hid device
144485cdaf52SJiri Slaby  * @type: HID report type (HID_*_REPORT)
144585cdaf52SJiri Slaby  * @data: report contents
144685cdaf52SJiri Slaby  * @size: size of data parameter
1447ff9b00a2SJiri Kosina  * @interrupt: distinguish between interrupt and control transfers
144885cdaf52SJiri Slaby  *
144985cdaf52SJiri Slaby  * This is data entry for lower layers.
145085cdaf52SJiri Slaby  */
145185cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
145285cdaf52SJiri Slaby {
145376c317d6SJulia Lawall 	struct hid_report_enum *report_enum;
145476c317d6SJulia Lawall 	struct hid_driver *hdrv;
145585cdaf52SJiri Slaby 	struct hid_report *report;
145645dc1ac7SJiri Kosina 	int ret = 0;
145785cdaf52SJiri Slaby 
14584ea54542SDavid Herrmann 	if (!hid)
145985cdaf52SJiri Slaby 		return -ENODEV;
14604ea54542SDavid Herrmann 
1461c849a614SAndrew de los Reyes 	if (down_trylock(&hid->driver_input_lock))
14624ea54542SDavid Herrmann 		return -EBUSY;
14634ea54542SDavid Herrmann 
14644ea54542SDavid Herrmann 	if (!hid->driver) {
14654ea54542SDavid Herrmann 		ret = -ENODEV;
14664ea54542SDavid Herrmann 		goto unlock;
14674ea54542SDavid Herrmann 	}
146876c317d6SJulia Lawall 	report_enum = hid->report_enum + type;
146976c317d6SJulia Lawall 	hdrv = hid->driver;
147085cdaf52SJiri Slaby 
147185cdaf52SJiri Slaby 	if (!size) {
147285cdaf52SJiri Slaby 		dbg_hid("empty report\n");
14734ea54542SDavid Herrmann 		ret = -1;
14744ea54542SDavid Herrmann 		goto unlock;
147585cdaf52SJiri Slaby 	}
147685cdaf52SJiri Slaby 
1477b94e3c94SMatthieu CASTET 	/* Avoid unnecessary overhead if debugfs is disabled */
1478a5f04b9dSBenjamin Tissoires 	if (!list_empty(&hid->debug_list))
1479a5f04b9dSBenjamin Tissoires 		hid_dump_report(hid, type, data, size);
1480b94e3c94SMatthieu CASTET 
1481f77e347bSJiri Kosina 	report = hid_get_report(report_enum, data);
1482f77e347bSJiri Kosina 
14834ea54542SDavid Herrmann 	if (!report) {
14844ea54542SDavid Herrmann 		ret = -1;
14854ea54542SDavid Herrmann 		goto unlock;
14864ea54542SDavid Herrmann 	}
1487f77e347bSJiri Kosina 
148885cdaf52SJiri Slaby 	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
148985cdaf52SJiri Slaby 		ret = hdrv->raw_event(hid, report, data, size);
1490556483e2SFelix Rueegg 		if (ret < 0)
14914ea54542SDavid Herrmann 			goto unlock;
14924ea54542SDavid Herrmann 	}
149385cdaf52SJiri Slaby 
1494b6787242SJiri Kosina 	ret = hid_report_raw_event(hid, type, data, size, interrupt);
1495aa8de2f0SJiri Kosina 
14964ea54542SDavid Herrmann unlock:
1497c849a614SAndrew de los Reyes 	up(&hid->driver_input_lock);
149845dc1ac7SJiri Kosina 	return ret;
1499aa8de2f0SJiri Kosina }
1500aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report);
1501aa8de2f0SJiri Kosina 
15020f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev,
15030f37cd03SJiri Kosina 		const struct hid_device_id *id)
15040f37cd03SJiri Kosina {
15057431fb76SHenrik Rydberg 	return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
15064d53b801SHenrik Rydberg 		(id->group == HID_GROUP_ANY || id->group == hdev->group) &&
15070f37cd03SJiri Kosina 		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
15080f37cd03SJiri Kosina 		(id->product == HID_ANY_ID || id->product == hdev->product);
15090f37cd03SJiri Kosina }
15100f37cd03SJiri Kosina 
1511bbc21cfdSJeremy Fitzhardinge const struct hid_device_id *hid_match_id(struct hid_device *hdev,
15120f37cd03SJiri Kosina 		const struct hid_device_id *id)
15130f37cd03SJiri Kosina {
15140f37cd03SJiri Kosina 	for (; id->bus; id++)
15150f37cd03SJiri Kosina 		if (hid_match_one_id(hdev, id))
15160f37cd03SJiri Kosina 			return id;
15170f37cd03SJiri Kosina 
15180f37cd03SJiri Kosina 	return NULL;
15190f37cd03SJiri Kosina }
15200f37cd03SJiri Kosina 
15210f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = {
1522c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1523c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
15240f37cd03SJiri Kosina 	{ }
15250f37cd03SJiri Kosina };
15260f37cd03SJiri Kosina 
15270f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev)
15280f37cd03SJiri Kosina {
15290f37cd03SJiri Kosina 	return !!hid_match_id(hdev, hid_hiddev_list);
15300f37cd03SJiri Kosina }
15310f37cd03SJiri Kosina 
15326d3bfb74SAlan Ott 
15336d3bfb74SAlan Ott static ssize_t
15346d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj,
15356d3bfb74SAlan Ott 		struct bin_attribute *attr,
15366d3bfb74SAlan Ott 		char *buf, loff_t off, size_t count)
15376d3bfb74SAlan Ott {
15386d3bfb74SAlan Ott 	struct device *dev = container_of(kobj, struct device, kobj);
15396d3bfb74SAlan Ott 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
15406d3bfb74SAlan Ott 
15416d3bfb74SAlan Ott 	if (off >= hdev->rsize)
15426d3bfb74SAlan Ott 		return 0;
15436d3bfb74SAlan Ott 
15446d3bfb74SAlan Ott 	if (off + count > hdev->rsize)
15456d3bfb74SAlan Ott 		count = hdev->rsize - off;
15466d3bfb74SAlan Ott 
15476d3bfb74SAlan Ott 	memcpy(buf, hdev->rdesc + off, count);
15486d3bfb74SAlan Ott 
15496d3bfb74SAlan Ott 	return count;
15506d3bfb74SAlan Ott }
15516d3bfb74SAlan Ott 
15526d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = {
15536d3bfb74SAlan Ott 	.attr = { .name = "report_descriptor", .mode = 0444 },
15546d3bfb74SAlan Ott 	.read = read_report_descriptor,
15556d3bfb74SAlan Ott 	.size = HID_MAX_DESCRIPTOR_SIZE,
15566d3bfb74SAlan Ott };
15576d3bfb74SAlan Ott 
155893c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
155993c10132SJiri Slaby {
156093c10132SJiri Slaby 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
156193c10132SJiri Slaby 		"Joystick", "Gamepad", "Keyboard", "Keypad",
156293c10132SJiri Slaby 		"Multi-Axis Controller"
156393c10132SJiri Slaby 	};
156493c10132SJiri Slaby 	const char *type, *bus;
156593c10132SJiri Slaby 	char buf[64];
156693c10132SJiri Slaby 	unsigned int i;
156793c10132SJiri Slaby 	int len;
15686d3bfb74SAlan Ott 	int ret;
156993c10132SJiri Slaby 
1570b5e5a37eSBastien Nocera 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1571b5e5a37eSBastien Nocera 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
15723a343ee4SDaniel Mack 	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
15733a343ee4SDaniel Mack 		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
157493c10132SJiri Slaby 	if (hdev->bus != BUS_USB)
157593c10132SJiri Slaby 		connect_mask &= ~HID_CONNECT_HIDDEV;
15760f37cd03SJiri Kosina 	if (hid_hiddev(hdev))
15770f37cd03SJiri Kosina 		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
157893c10132SJiri Slaby 
157993c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
158093c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
158193c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_INPUT;
1582b77c3920SBenjamin Tissoires 
158393c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
158493c10132SJiri Slaby 			!hdev->hiddev_connect(hdev,
158593c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDDEV_FORCE))
158693c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDDEV;
158793c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
158893c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDRAW;
158993c10132SJiri Slaby 
15907704ac93SBenjamin Tissoires 	if (connect_mask & HID_CONNECT_DRIVER)
15917704ac93SBenjamin Tissoires 		hdev->claimed |= HID_CLAIMED_DRIVER;
15927704ac93SBenjamin Tissoires 
15934bc19f62SDavid Herrmann 	/* Drivers with the ->raw_event callback set are not required to connect
15944bc19f62SDavid Herrmann 	 * to any other listener. */
15954bc19f62SDavid Herrmann 	if (!hdev->claimed && !hdev->driver->raw_event) {
15964bc19f62SDavid Herrmann 		hid_err(hdev, "device has no listeners, quitting\n");
159793c10132SJiri Slaby 		return -ENODEV;
159893c10132SJiri Slaby 	}
159993c10132SJiri Slaby 
160093c10132SJiri Slaby 	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
160193c10132SJiri Slaby 			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
160293c10132SJiri Slaby 		hdev->ff_init(hdev);
160393c10132SJiri Slaby 
160493c10132SJiri Slaby 	len = 0;
160593c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_INPUT)
160693c10132SJiri Slaby 		len += sprintf(buf + len, "input");
160793c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
160893c10132SJiri Slaby 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
160993c10132SJiri Slaby 				hdev->minor);
161093c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
161193c10132SJiri Slaby 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
161293c10132SJiri Slaby 				((struct hidraw *)hdev->hidraw)->minor);
161393c10132SJiri Slaby 
161493c10132SJiri Slaby 	type = "Device";
161593c10132SJiri Slaby 	for (i = 0; i < hdev->maxcollection; i++) {
161693c10132SJiri Slaby 		struct hid_collection *col = &hdev->collection[i];
161793c10132SJiri Slaby 		if (col->type == HID_COLLECTION_APPLICATION &&
161893c10132SJiri Slaby 		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
161993c10132SJiri Slaby 		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
162093c10132SJiri Slaby 			type = types[col->usage & 0xffff];
162193c10132SJiri Slaby 			break;
162293c10132SJiri Slaby 		}
162393c10132SJiri Slaby 	}
162493c10132SJiri Slaby 
162593c10132SJiri Slaby 	switch (hdev->bus) {
162693c10132SJiri Slaby 	case BUS_USB:
162793c10132SJiri Slaby 		bus = "USB";
162893c10132SJiri Slaby 		break;
162993c10132SJiri Slaby 	case BUS_BLUETOOTH:
163093c10132SJiri Slaby 		bus = "BLUETOOTH";
163193c10132SJiri Slaby 		break;
163293c10132SJiri Slaby 	default:
163393c10132SJiri Slaby 		bus = "<UNKNOWN>";
163493c10132SJiri Slaby 	}
163593c10132SJiri Slaby 
16366d3bfb74SAlan Ott 	ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
16376d3bfb74SAlan Ott 	if (ret)
16386d3bfb74SAlan Ott 		hid_warn(hdev,
16396d3bfb74SAlan Ott 			 "can't create sysfs report descriptor attribute err: %d\n", ret);
16406d3bfb74SAlan Ott 
16414291ee30SJoe Perches 	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
164293c10132SJiri Slaby 		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
164393c10132SJiri Slaby 		 type, hdev->name, hdev->phys);
164493c10132SJiri Slaby 
164593c10132SJiri Slaby 	return 0;
164693c10132SJiri Slaby }
164793c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect);
164893c10132SJiri Slaby 
1649c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev)
1650c4c259bcSJiri Kosina {
16516d3bfb74SAlan Ott 	device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1652c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_INPUT)
1653c4c259bcSJiri Kosina 		hidinput_disconnect(hdev);
1654c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1655c4c259bcSJiri Kosina 		hdev->hiddev_disconnect(hdev);
1656c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1657c4c259bcSJiri Kosina 		hidraw_disconnect(hdev);
16589c5c6ed7SBenjamin Tissoires 	hdev->claimed = 0;
1659c4c259bcSJiri Kosina }
1660c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect);
1661c4c259bcSJiri Kosina 
166200315e4fSJiri Kosina /*
166300315e4fSJiri Kosina  * A list of devices for which there is a specialized driver on HID bus.
166400315e4fSJiri Kosina  *
166500315e4fSJiri Kosina  * Please note that for multitouch devices (driven by hid-multitouch driver),
166600315e4fSJiri Kosina  * there is a proper autodetection and autoloading in place (based on presence
166700315e4fSJiri Kosina  * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
166800315e4fSJiri Kosina  * as we are doing the right thing in hid_scan_usage().
166983499b52SAlexander Holler  *
167083499b52SAlexander Holler  * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
167183499b52SAlexander Holler  * physical is found inside a usage page of type sensor, hid-sensor-hub will be
167283499b52SAlexander Holler  * used as a driver. See hid_scan_report().
167300315e4fSJiri Kosina  */
1674ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = {
167514a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
167614a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1677b7e1b203SLech Perczak 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1678c0dbcc33SSergei Kolzun 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1679e17f5d76STristan Rice 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
16808c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1681128537ceSMichael Poole 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1682a462230eSChase Douglas 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
16838c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
16848c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
16858c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
16868c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
16878c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
16888c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
16898c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
16908c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
16918c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
16928c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
16938c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1694fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1695fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1696fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
16978c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
16988c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
16998c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
17008c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
17018c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
17028c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
17039a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
17049a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
17059a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
17069a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
17079a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
1708ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1709ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1710ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
17118c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
17128c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
17138c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
17148c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
17158c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
17168c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1717a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1718a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1719a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
172099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
172199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
172299b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
172399b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
172499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
172599b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
172647340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
172747340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
172847340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1729213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1730213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1731213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
17324a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
17334a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
17344a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
1735f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1736f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1737f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
1738d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
1739d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
1740d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
1741b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
1742b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
1743b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
17448d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
17458d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
17468d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
17479d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
17489d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
17499d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
175023aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
175123aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
175223aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1753f9af7b9eSBen Hutchings 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
1754ad734bc1SAndreas Krist 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
1755bd4a7ce1SHuei-Horng Yo 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
17568c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
17578c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1758212da74dSJosenivaldo Benito Junior 	{ HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
1759b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1760*fc38a8a6SHuang Bo 	{ HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185BFM, 0x2208) },
1761*fc38a8a6SHuang Bo 	{ HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185PC, 0x5506) },
1762*fc38a8a6SHuang Bo 	{ HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2PC, 0x1850) },
1763*fc38a8a6SHuang Bo 	{ HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185V2BFM, 0x5500) },
1764bf280628SWayne Thomas 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1765c3dc66deSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
17663b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
17671ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1768fcfacfd3SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1769b9e4b1e0SDennis Kügler 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
17703596bb92SKeng-Yu Lin 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
17712d8767bbSCyrus Lien 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
17723a370ca1SDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
1773e932d817SDavid Barksdale 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
17740f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
17750f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1776e8d0eab4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
177776c9d8feSLionel Vaux 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
17780f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
17793f866fbdSRichard Walmsley 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1780e05eefb9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
178164b386eaSRichard Nauber 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1782d23efc19SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
1783d23efc19SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
178404561c5aSIgnaz Forster 	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
17851f243e30SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
17865181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1787578f3a35SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
17885181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
178942859e0bSLukasz Lubojanski 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1790949f8fefSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
17911e093206SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1792c2fd1a4eSCory Maccarrone 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1793d946e65eSAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
1794ff9bf5a2STom Harwood 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
179540d3597fSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
179640d3597fSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
1797274be3ebSKharlamov Alexey 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
1798f1a4914bSAnders F. U. Kiær 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
17997da7cbbbSAnders F. U. Kiær 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
18005df4eb05SJohn DeSilva 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
1801e917e98fSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
1802aaca9cc0SMichael Karcher 	{ HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
18034ddfe028SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
1804fdf93aa3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1805177900e8SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
18063685c18eSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
18074a2c94c9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_MANTICORE) },
18080adb9c2cSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
180979422741SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
181022ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
181122ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
181222ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
1813b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
181475b07022SChris Schlund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
181594723bfaSJamie Lentin #if IS_ENABLED(CONFIG_HID_LENOVO)
1816c1dcad2dSBernhard Seibold 	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
1817f3d4ff0eSJamie Lentin 	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) },
1818f3d4ff0eSJamie Lentin 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) },
1819aad932e7SAndres Freund #endif
18205f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
18215f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
18225f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
18235f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
18245844c1cdSDavid Dillow 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
18252f31c525SBenjamin Tissoires 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_T651) },
18265f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
18275f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
18285f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
18295f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
18305f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
18315f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
18325f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
18332c6118e4SHendrik Iben 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1834606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1835606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1836606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1837fd30ea8cSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1838606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
183974f292caSGary Stein 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1840606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1841606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1842bd04363dSElias Vanderstuyft 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL) },
18435623a24aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1844e00ddc9bSMichal Malý 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
1845243b706dSChristophe Borivant 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1846fdc6807fSPeter Gundermann 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
18470944e964SKonstantin Khlebnikov #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
1848534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
1849534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
18500944e964SKonstantin Khlebnikov #endif
185132c88cbcSSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1852606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
185324985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
185424985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1855236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1856236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
1857b580169aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
185878a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
185978a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
186089759e20SAdam Jiang 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
186178a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
186278a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1863f3b83d71SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
186478a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
18653faed1afSHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
1866be3b1634SAlan Wu 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3) },
18673b8006e5SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1868f471d948SJanne Kanniainen 	{ HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
186994011f93SRafi Rubin 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
18706e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
18716e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
18726e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
18736e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
18746e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
18756e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
18766e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
18776e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
18786e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
18796e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
18806e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
18816e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
18826e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
18836e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
18846e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
18856e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
18866e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
18876e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1888270fdc07SHerton Ronaldo Krzesinski 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1889cd9ec30dSJohnathon Harris 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
1890ffe51d0dSChristian Gmeiner 	{ HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_6000) },
18911e762532SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
18921a3f83f6SJD Cole 	{ HID_USB_DEVICE(USB_VENDOR_ID_PLANTRONICS, HID_ANY_ID) },
1893f6a04605STerry Lambert 	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
1894ca9bbdccSStefan Achatz #if IS_ENABLED(CONFIG_HID_ROCCAT)
1895e68cc603SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1896d41c2a70SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
1897e078809dSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKUFX) },
1898e078809dSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
189947dbdbffSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
19008936aa31SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
1901a4be0ed3SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
1902e078809dSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEXTD) },
19030e70f97fSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
19044424f616SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
1905cb7cf3daSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
19063fce2246SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
19076f3a1936SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK) },
19086f3a1936SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW) },
19096f3a1936SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO) },
19106a2a6390SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
1911ca9bbdccSStefan Achatz #endif
191237c492c8SHarald Brinkmann #if IS_ENABLED(CONFIG_HID_SAITEK)
19131e93674aSAndreas Hübner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
191437c492c8SHarald Brinkmann 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RAT7) },
191537c492c8SHarald Brinkmann 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_MMO7) },
19167bb9d643SVille Aakko 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_RAT9) },
191737c492c8SHarald Brinkmann #endif
1918980a3da6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1919b355850bSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1920d586dca0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
192168a49e51SFrank Praznik 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE) },
1922f04d5140SColin Leitner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
1923f04d5140SColin Leitner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
19245844c1cdSDavid Dillow 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
1925bd28ce00SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
192635dca5b4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1927f9ce7c28SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
19280bd88dd3SFrank Praznik 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
19290bd88dd3SFrank Praznik 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
1930cc6e0bbbSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1931c1e0ac19SFernando Luis Vázquez Cao 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
193275dbb953SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
193390231e7eSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
193430ba2fbdSVivien Didelot 	{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
1935daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1936daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
19377a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
19387a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1939daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
19403ee8f0a2SMarkus Rathgeb 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1941daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1942d65c3768SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1943740363fbSJiri Kosina 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
194444ea35c1SJarod Wilson 	{ HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
1945f14f526dSLev Babiev 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
194654001081SKees Bakker 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1947711a680eSBruno Premont 	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
194841fa9230SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1949f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1950f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1951f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
19526be914f1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1953d1257081SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
1954eb4e426aSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
1955fac733f0SJussi Kivilinna 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
195642fc04e5SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
1957ad395ccaSSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
19581bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
19591bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
19601bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
196172a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
196200e7f964SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
19634fdc18d1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
1964a786e83cSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
196572a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
19668f1acc32SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1967d2ee4dd9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
196874bc6953SStefan Kriwanek 	{ HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1969cb2c9e3fSOlivier Scherler 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
1970daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1971daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1972a9885c8fSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
19738c19a515SJiri Slaby 
197478a849a6SJiri Slaby 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
197502fb72a0SDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1976a33042faSDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
197785cdaf52SJiri Slaby 	{ }
197885cdaf52SJiri Slaby };
197985cdaf52SJiri Slaby 
19803a6f82f7SJiri Slaby struct hid_dynid {
19813a6f82f7SJiri Slaby 	struct list_head list;
19823a6f82f7SJiri Slaby 	struct hid_device_id id;
19833a6f82f7SJiri Slaby };
19843a6f82f7SJiri Slaby 
19853a6f82f7SJiri Slaby /**
19863a6f82f7SJiri Slaby  * store_new_id - add a new HID device ID to this driver and re-probe devices
19873a6f82f7SJiri Slaby  * @driver: target device driver
19883a6f82f7SJiri Slaby  * @buf: buffer for scanning device ID data
19893a6f82f7SJiri Slaby  * @count: input size
19903a6f82f7SJiri Slaby  *
19913a6f82f7SJiri Slaby  * Adds a new dynamic hid device ID to this driver,
19923a6f82f7SJiri Slaby  * and causes the driver to probe for all devices again.
19933a6f82f7SJiri Slaby  */
19943a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf,
19953a6f82f7SJiri Slaby 		size_t count)
19963a6f82f7SJiri Slaby {
19973a6f82f7SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
19983a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
19993a6f82f7SJiri Slaby 	__u32 bus, vendor, product;
20003a6f82f7SJiri Slaby 	unsigned long driver_data = 0;
20013a6f82f7SJiri Slaby 	int ret;
20023a6f82f7SJiri Slaby 
20033a6f82f7SJiri Slaby 	ret = sscanf(buf, "%x %x %x %lx",
20043a6f82f7SJiri Slaby 			&bus, &vendor, &product, &driver_data);
20053a6f82f7SJiri Slaby 	if (ret < 3)
20063a6f82f7SJiri Slaby 		return -EINVAL;
20073a6f82f7SJiri Slaby 
20083a6f82f7SJiri Slaby 	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
20093a6f82f7SJiri Slaby 	if (!dynid)
20103a6f82f7SJiri Slaby 		return -ENOMEM;
20113a6f82f7SJiri Slaby 
20123a6f82f7SJiri Slaby 	dynid->id.bus = bus;
20134d53b801SHenrik Rydberg 	dynid->id.group = HID_GROUP_ANY;
20143a6f82f7SJiri Slaby 	dynid->id.vendor = vendor;
20153a6f82f7SJiri Slaby 	dynid->id.product = product;
20163a6f82f7SJiri Slaby 	dynid->id.driver_data = driver_data;
20173a6f82f7SJiri Slaby 
20183a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
20193a6f82f7SJiri Slaby 	list_add_tail(&dynid->list, &hdrv->dyn_list);
20203a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
20213a6f82f7SJiri Slaby 
20223a6f82f7SJiri Slaby 	ret = driver_attach(&hdrv->driver);
20233a6f82f7SJiri Slaby 
20243a6f82f7SJiri Slaby 	return ret ? : count;
20253a6f82f7SJiri Slaby }
20263a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
20273a6f82f7SJiri Slaby 
20283a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv)
20293a6f82f7SJiri Slaby {
20303a6f82f7SJiri Slaby 	struct hid_dynid *dynid, *n;
20313a6f82f7SJiri Slaby 
20323a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
20333a6f82f7SJiri Slaby 	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
20343a6f82f7SJiri Slaby 		list_del(&dynid->list);
20353a6f82f7SJiri Slaby 		kfree(dynid);
20363a6f82f7SJiri Slaby 	}
20373a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
20383a6f82f7SJiri Slaby }
20393a6f82f7SJiri Slaby 
20403a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
20413a6f82f7SJiri Slaby 		struct hid_driver *hdrv)
20423a6f82f7SJiri Slaby {
20433a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
20443a6f82f7SJiri Slaby 
20453a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
20463a6f82f7SJiri Slaby 	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
20473a6f82f7SJiri Slaby 		if (hid_match_one_id(hdev, &dynid->id)) {
20483a6f82f7SJiri Slaby 			spin_unlock(&hdrv->dyn_lock);
20493a6f82f7SJiri Slaby 			return &dynid->id;
20503a6f82f7SJiri Slaby 		}
20513a6f82f7SJiri Slaby 	}
20523a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
20533a6f82f7SJiri Slaby 
20543a6f82f7SJiri Slaby 	return hid_match_id(hdev, hdrv->id_table);
20553a6f82f7SJiri Slaby }
20563a6f82f7SJiri Slaby 
205785cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv)
205885cdaf52SJiri Slaby {
205985cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
206085cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
206185cdaf52SJiri Slaby 
2062070748edSHenrik Rydberg 	return hid_match_device(hdev, hdrv) != NULL;
206385cdaf52SJiri Slaby }
206485cdaf52SJiri Slaby 
206585cdaf52SJiri Slaby static int hid_device_probe(struct device *dev)
206685cdaf52SJiri Slaby {
206785cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(dev->driver,
206885cdaf52SJiri Slaby 			struct hid_driver, driver);
206985cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
207085cdaf52SJiri Slaby 	const struct hid_device_id *id;
207185cdaf52SJiri Slaby 	int ret = 0;
207285cdaf52SJiri Slaby 
20734ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
20744ea54542SDavid Herrmann 		return -EINTR;
2075c849a614SAndrew de los Reyes 	if (down_interruptible(&hdev->driver_input_lock)) {
2076c849a614SAndrew de los Reyes 		ret = -EINTR;
2077c849a614SAndrew de los Reyes 		goto unlock_driver_lock;
2078c849a614SAndrew de los Reyes 	}
2079c849a614SAndrew de los Reyes 	hdev->io_started = false;
20804ea54542SDavid Herrmann 
208185cdaf52SJiri Slaby 	if (!hdev->driver) {
20823a6f82f7SJiri Slaby 		id = hid_match_device(hdev, hdrv);
2083ba623a77SDan Carpenter 		if (id == NULL) {
2084ba623a77SDan Carpenter 			ret = -ENODEV;
2085ba623a77SDan Carpenter 			goto unlock;
2086ba623a77SDan Carpenter 		}
2087c500c971SJiri Slaby 
208885cdaf52SJiri Slaby 		hdev->driver = hdrv;
2089c500c971SJiri Slaby 		if (hdrv->probe) {
2090c500c971SJiri Slaby 			ret = hdrv->probe(hdev, id);
2091c500c971SJiri Slaby 		} else { /* default probe */
2092a7197c2eSHenrik Rydberg 			ret = hid_open_report(hdev);
2093c500c971SJiri Slaby 			if (!ret)
209493c10132SJiri Slaby 				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
2095c500c971SJiri Slaby 		}
2096a7197c2eSHenrik Rydberg 		if (ret) {
2097a7197c2eSHenrik Rydberg 			hid_close_report(hdev);
2098c500c971SJiri Slaby 			hdev->driver = NULL;
209985cdaf52SJiri Slaby 		}
2100a7197c2eSHenrik Rydberg 	}
2101ba623a77SDan Carpenter unlock:
2102c849a614SAndrew de los Reyes 	if (!hdev->io_started)
2103c849a614SAndrew de los Reyes 		up(&hdev->driver_input_lock);
2104c849a614SAndrew de los Reyes unlock_driver_lock:
21054ea54542SDavid Herrmann 	up(&hdev->driver_lock);
210685cdaf52SJiri Slaby 	return ret;
210785cdaf52SJiri Slaby }
210885cdaf52SJiri Slaby 
210985cdaf52SJiri Slaby static int hid_device_remove(struct device *dev)
211085cdaf52SJiri Slaby {
211185cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
21124ea54542SDavid Herrmann 	struct hid_driver *hdrv;
2113c849a614SAndrew de los Reyes 	int ret = 0;
211485cdaf52SJiri Slaby 
21154ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
21164ea54542SDavid Herrmann 		return -EINTR;
2117c849a614SAndrew de los Reyes 	if (down_interruptible(&hdev->driver_input_lock)) {
2118c849a614SAndrew de los Reyes 		ret = -EINTR;
2119c849a614SAndrew de los Reyes 		goto unlock_driver_lock;
2120c849a614SAndrew de los Reyes 	}
2121c849a614SAndrew de los Reyes 	hdev->io_started = false;
21224ea54542SDavid Herrmann 
21234ea54542SDavid Herrmann 	hdrv = hdev->driver;
212485cdaf52SJiri Slaby 	if (hdrv) {
212585cdaf52SJiri Slaby 		if (hdrv->remove)
212685cdaf52SJiri Slaby 			hdrv->remove(hdev);
2127c500c971SJiri Slaby 		else /* default remove */
2128c500c971SJiri Slaby 			hid_hw_stop(hdev);
2129a7197c2eSHenrik Rydberg 		hid_close_report(hdev);
213085cdaf52SJiri Slaby 		hdev->driver = NULL;
213185cdaf52SJiri Slaby 	}
213285cdaf52SJiri Slaby 
2133c849a614SAndrew de los Reyes 	if (!hdev->io_started)
2134c849a614SAndrew de los Reyes 		up(&hdev->driver_input_lock);
2135c849a614SAndrew de los Reyes unlock_driver_lock:
21364ea54542SDavid Herrmann 	up(&hdev->driver_lock);
2137c849a614SAndrew de los Reyes 	return ret;
213885cdaf52SJiri Slaby }
213985cdaf52SJiri Slaby 
21404d53b801SHenrik Rydberg static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
21414d53b801SHenrik Rydberg 			     char *buf)
21424d53b801SHenrik Rydberg {
21434d53b801SHenrik Rydberg 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
21444d53b801SHenrik Rydberg 	int len;
21454d53b801SHenrik Rydberg 
21464d53b801SHenrik Rydberg 	len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
21474d53b801SHenrik Rydberg 		       hdev->bus, hdev->group, hdev->vendor, hdev->product);
21484d53b801SHenrik Rydberg 
21494d53b801SHenrik Rydberg 	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
21504d53b801SHenrik Rydberg }
21510d4260e0SGreg Kroah-Hartman static DEVICE_ATTR_RO(modalias);
21524d53b801SHenrik Rydberg 
21530d4260e0SGreg Kroah-Hartman static struct attribute *hid_dev_attrs[] = {
21540d4260e0SGreg Kroah-Hartman 	&dev_attr_modalias.attr,
21550d4260e0SGreg Kroah-Hartman 	NULL,
21564d53b801SHenrik Rydberg };
21570d4260e0SGreg Kroah-Hartman ATTRIBUTE_GROUPS(hid_dev);
21584d53b801SHenrik Rydberg 
215985cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
216085cdaf52SJiri Slaby {
216185cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
216285cdaf52SJiri Slaby 
216385cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
216485cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
216585cdaf52SJiri Slaby 		return -ENOMEM;
216685cdaf52SJiri Slaby 
216785cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
216885cdaf52SJiri Slaby 		return -ENOMEM;
216985cdaf52SJiri Slaby 
217085cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
217185cdaf52SJiri Slaby 		return -ENOMEM;
217285cdaf52SJiri Slaby 
217385cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
217485cdaf52SJiri Slaby 		return -ENOMEM;
217585cdaf52SJiri Slaby 
21764d53b801SHenrik Rydberg 	if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
21774d53b801SHenrik Rydberg 			   hdev->bus, hdev->group, hdev->vendor, hdev->product))
217885cdaf52SJiri Slaby 		return -ENOMEM;
217985cdaf52SJiri Slaby 
218085cdaf52SJiri Slaby 	return 0;
218185cdaf52SJiri Slaby }
218285cdaf52SJiri Slaby 
218385cdaf52SJiri Slaby static struct bus_type hid_bus_type = {
218485cdaf52SJiri Slaby 	.name		= "hid",
21850d4260e0SGreg Kroah-Hartman 	.dev_groups	= hid_dev_groups,
218685cdaf52SJiri Slaby 	.match		= hid_bus_match,
218785cdaf52SJiri Slaby 	.probe		= hid_device_probe,
218885cdaf52SJiri Slaby 	.remove		= hid_device_remove,
218985cdaf52SJiri Slaby 	.uevent		= hid_uevent,
219085cdaf52SJiri Slaby };
219185cdaf52SJiri Slaby 
2192bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */
2193d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = {
2194d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
2195d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
2196d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
2197d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
2198d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
2199d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
2200d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
2201d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
2202d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
2203d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
2204d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
2205d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
220677f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
220777f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
220862a56582SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
220911030183SHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
2210d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
2211d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
2212d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
2213adc23259SDinesh Ram 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) },
2214d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
2215d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
2216d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
22175f6108cfSAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
2218d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
2219d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
222073bc7d31SMelchior FRANZ 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
2221789aaa2eSDan Delaney 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
2222d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
222370c66567SPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
2224df506f2cSPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
2225b1807719SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
2226d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
2227d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
2228d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
2229d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
2230d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
2231d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
2232d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
2233d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
2234d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
2235d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
2236d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
2237d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
2238d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
2239d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
2240d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
2241d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
22428e2ce73eSHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
2243d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
2244d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
2245d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
2246d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
2247d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
2248d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
2249d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
2250d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
2251d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
2252d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
2253d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
2254d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
2255d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
2256d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
2257d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
2258d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
2259d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
2260d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
2261d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
2262d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
2263d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
2264d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
2265d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
2266d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
2267d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
2268d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
2269d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
2270d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
2271d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
2272d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
2273d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
2274d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
2275d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
2276d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
2277d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
2278d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
2279d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
2280d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
2281d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
2282d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
2283d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
2284d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
2285d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
2286d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
2287d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
2288d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
2289d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
229031b9779cSVincent Palatin 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) },
229131b9779cSVincent Palatin 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) },
229243c1a0a9SPatrick Plattes 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_GN9350E) },
2293d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
2294c91c21c5SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
2295d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
2296eb8141ccSLamarque Vieira Souza 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
2297d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
2298ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
2299d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
2300ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
2301d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
2302ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
2303ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
2304ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
2305ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
2306ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
2307ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
2308d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
2309d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
2310d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
2311ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
2312ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
2313ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
2314d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
2315d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
2316ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
2317d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
2318d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
2319d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
2320d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
2321d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
2322ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
2323ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
2324ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
2325ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
2326ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
2327ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
2328ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
23293ffb62cbSYuri Khan 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
2330d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
2331d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
2332d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
2333d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
2334d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
2335d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
2336d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
2337d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
2338d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
2339d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
2340d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
2341d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
2342d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
2343d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
2344d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
2345d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
2346d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
2347d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
2348d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
23494cfae3e8SHenning Glawe 	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
235035cfd1d9SMichael Tokarev 	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
23518491ee10SJan Steinhoff #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
23528491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
23538491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
23548491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
23558491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
23568491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
23578491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
23588491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
23598491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
23608491ee10SJan Steinhoff #endif
2361d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
2362d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
2363d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
2364d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
2365d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
2366d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
2367d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
2368d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
2369d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
2370759db9eaSChristian Vogel 	{ HID_USB_DEVICE(USB_VENDOR_ID_RISO_KAGAKU, USB_DEVICE_ID_RI_KA_WEBMAIL) },
2371d458a9dfSJiri Slaby 	{ }
2372d458a9dfSJiri Slaby };
2373d458a9dfSJiri Slaby 
2374b4d8e473SJiri Slaby /**
2375b4d8e473SJiri Slaby  * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
2376b4d8e473SJiri Slaby  *
2377b4d8e473SJiri Slaby  * There are composite devices for which we want to ignore only a certain
2378b4d8e473SJiri Slaby  * interface. This is a list of devices for which only the mouse interface will
2379b4d8e473SJiri Slaby  * be ignored. This allows a dedicated driver to take care of the interface.
2380b4d8e473SJiri Slaby  */
2381b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = {
2382b4d8e473SJiri Slaby 	/* appletouch driver */
2383b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
2384b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
2385b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
2386b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
2387b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
2388b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
2389b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
2390b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
2391b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
2392b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
2393b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
2394b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
2395b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
2396b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
2397b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
2398b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
2399b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
2400b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
2401b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
2402b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
2403ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
2404ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
2405ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
240699b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
240799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
240899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
240999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
241099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
241199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
241247340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
241347340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
241447340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
2415213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
2416213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
2417213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
24184b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
24194b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
24204b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
24214b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
24224b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
24234b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
2424b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
2425b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
2426b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
24278d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
24288d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
24298d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
24309d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
24319d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
24329d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
2433b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2434b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
2435b4d8e473SJiri Slaby 	{ }
2436b4d8e473SJiri Slaby };
2437b4d8e473SJiri Slaby 
24384529eefaSLamarque V. Souza bool hid_ignore(struct hid_device *hdev)
2439d458a9dfSJiri Slaby {
24404529eefaSLamarque V. Souza 	if (hdev->quirks & HID_QUIRK_NO_IGNORE)
24414529eefaSLamarque V. Souza 		return false;
24424529eefaSLamarque V. Souza 	if (hdev->quirks & HID_QUIRK_IGNORE)
24434529eefaSLamarque V. Souza 		return true;
24444529eefaSLamarque V. Souza 
2445d458a9dfSJiri Slaby 	switch (hdev->vendor) {
2446d458a9dfSJiri Slaby 	case USB_VENDOR_ID_CODEMERCS:
2447d458a9dfSJiri Slaby 		/* ignore all Code Mercenaries IOWarrior devices */
2448d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
2449d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
2450d458a9dfSJiri Slaby 			return true;
2451d458a9dfSJiri Slaby 		break;
2452d458a9dfSJiri Slaby 	case USB_VENDOR_ID_LOGITECH:
2453d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
2454d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
2455d458a9dfSJiri Slaby 			return true;
245665dd3b69SHans Verkuil 		/*
245765dd3b69SHans Verkuil 		 * The Keene FM transmitter USB device has the same USB ID as
245865dd3b69SHans Verkuil 		 * the Logitech AudioHub Speaker, but it should ignore the hid.
245965dd3b69SHans Verkuil 		 * Check if the name is that of the Keene device.
246065dd3b69SHans Verkuil 		 * For reference: the name of the AudioHub is
246165dd3b69SHans Verkuil 		 * "HOLTEK  AudioHub Speaker".
246265dd3b69SHans Verkuil 		 */
246365dd3b69SHans Verkuil 		if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
246465dd3b69SHans Verkuil 			!strcmp(hdev->name, "HOLTEK  B-LINK USB Audio  "))
246565dd3b69SHans Verkuil 				return true;
2466d458a9dfSJiri Slaby 		break;
246731f7fd79SJarod Wilson 	case USB_VENDOR_ID_SOUNDGRAPH:
246831f7fd79SJarod Wilson 		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
246931f7fd79SJarod Wilson 		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
247031f7fd79SJarod Wilson 			return true;
247131f7fd79SJarod Wilson 		break;
2472bba5394aSXing Wei 	case USB_VENDOR_ID_HANWANG:
2473bba5394aSXing Wei 		if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
2474bba5394aSXing Wei 		    hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
2475bba5394aSXing Wei 			return true;
2476bba5394aSXing Wei 		break;
24776dc1418eSTomoki Sekiyama 	case USB_VENDOR_ID_JESS:
24786dc1418eSTomoki Sekiyama 		if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
24796dc1418eSTomoki Sekiyama 				hdev->type == HID_TYPE_USBNONE)
24806dc1418eSTomoki Sekiyama 			return true;
24816dc1418eSTomoki Sekiyama 		break;
248230b6b7d8SIan Abbott 	case USB_VENDOR_ID_VELLEMAN:
248330b6b7d8SIan Abbott 		/* These are not HID devices.  They are handled by comedi. */
248430b6b7d8SIan Abbott 		if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
248530b6b7d8SIan Abbott 		     hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
248630b6b7d8SIan Abbott 		    (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
248730b6b7d8SIan Abbott 		     hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
248830b6b7d8SIan Abbott 			return true;
248930b6b7d8SIan Abbott 		break;
24905b4617d8SAlexey Klimov 	case USB_VENDOR_ID_ATMEL_V_USB:
24915b4617d8SAlexey Klimov 		/* Masterkit MA901 usb radio based on Atmel tiny85 chip and
24925b4617d8SAlexey Klimov 		 * it has the same USB ID as many Atmel V-USB devices. This
24935b4617d8SAlexey Klimov 		 * usb radio is handled by radio-ma901.c driver so we want
24945b4617d8SAlexey Klimov 		 * ignore the hid. Check the name, bus, product and ignore
24955b4617d8SAlexey Klimov 		 * if we have MA901 usb radio.
24965b4617d8SAlexey Klimov 		 */
24975b4617d8SAlexey Klimov 		if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
24985b4617d8SAlexey Klimov 			hdev->bus == BUS_USB &&
24995b4617d8SAlexey Klimov 			strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
25005b4617d8SAlexey Klimov 			return true;
25015b4617d8SAlexey Klimov 		break;
2502d458a9dfSJiri Slaby 	}
2503d458a9dfSJiri Slaby 
2504b4d8e473SJiri Slaby 	if (hdev->type == HID_TYPE_USBMOUSE &&
2505b4d8e473SJiri Slaby 			hid_match_id(hdev, hid_mouse_ignore_list))
2506b4d8e473SJiri Slaby 		return true;
2507b4d8e473SJiri Slaby 
2508d458a9dfSJiri Slaby 	return !!hid_match_id(hdev, hid_ignore_list);
2509d458a9dfSJiri Slaby }
25104529eefaSLamarque V. Souza EXPORT_SYMBOL_GPL(hid_ignore);
2511d458a9dfSJiri Slaby 
251285cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev)
251385cdaf52SJiri Slaby {
251485cdaf52SJiri Slaby 	static atomic_t id = ATOMIC_INIT(0);
251585cdaf52SJiri Slaby 	int ret;
251685cdaf52SJiri Slaby 
251785cdaf52SJiri Slaby 	if (WARN_ON(hdev->status & HID_STAT_ADDED))
251885cdaf52SJiri Slaby 		return -EBUSY;
251985cdaf52SJiri Slaby 
2520d458a9dfSJiri Slaby 	/* we need to kill them here, otherwise they will stay allocated to
2521d458a9dfSJiri Slaby 	 * wait for coming driver */
25224529eefaSLamarque V. Souza 	if (hid_ignore(hdev))
2523d458a9dfSJiri Slaby 		return -ENODEV;
2524d458a9dfSJiri Slaby 
2525a7197c2eSHenrik Rydberg 	/*
25263c86726cSBenjamin Tissoires 	 * Check for the mandatory transport channel.
25273c86726cSBenjamin Tissoires 	 */
25283c86726cSBenjamin Tissoires 	 if (!hdev->ll_driver->raw_request) {
25293c86726cSBenjamin Tissoires 		hid_err(hdev, "transport driver missing .raw_request()\n");
25303c86726cSBenjamin Tissoires 		return -EINVAL;
25313c86726cSBenjamin Tissoires 	 }
25323c86726cSBenjamin Tissoires 
25333c86726cSBenjamin Tissoires 	/*
2534a7197c2eSHenrik Rydberg 	 * Read the device report descriptor once and use as template
2535a7197c2eSHenrik Rydberg 	 * for the driver-specific modifications.
2536a7197c2eSHenrik Rydberg 	 */
2537a7197c2eSHenrik Rydberg 	ret = hdev->ll_driver->parse(hdev);
2538a7197c2eSHenrik Rydberg 	if (ret)
2539a7197c2eSHenrik Rydberg 		return ret;
2540a7197c2eSHenrik Rydberg 	if (!hdev->dev_rdesc)
2541a7197c2eSHenrik Rydberg 		return -ENODEV;
2542a7197c2eSHenrik Rydberg 
2543734c6609SHenrik Rydberg 	/*
2544734c6609SHenrik Rydberg 	 * Scan generic devices for group information
2545734c6609SHenrik Rydberg 	 */
2546734c6609SHenrik Rydberg 	if (hid_ignore_special_drivers ||
25479578f41aSBenjamin Tissoires 	    (!hdev->group &&
25489578f41aSBenjamin Tissoires 	     !hid_match_id(hdev, hid_have_special_driver))) {
2549734c6609SHenrik Rydberg 		ret = hid_scan_report(hdev);
2550734c6609SHenrik Rydberg 		if (ret)
2551734c6609SHenrik Rydberg 			hid_warn(hdev, "bad device descriptor (%d)\n", ret);
2552734c6609SHenrik Rydberg 	}
2553734c6609SHenrik Rydberg 
25546bbe586fSKay Sievers 	/* XXX hack, any other cleaner solution after the driver core
25556bbe586fSKay Sievers 	 * is converted to allow more than 20 bytes as the device name? */
25566bbe586fSKay Sievers 	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
255785cdaf52SJiri Slaby 		     hdev->vendor, hdev->product, atomic_inc_return(&id));
255885cdaf52SJiri Slaby 
25594da361b6SBruno Prémont 	hid_debug_register(hdev, dev_name(&hdev->dev));
256085cdaf52SJiri Slaby 	ret = device_add(&hdev->dev);
256185cdaf52SJiri Slaby 	if (!ret)
256285cdaf52SJiri Slaby 		hdev->status |= HID_STAT_ADDED;
25634da361b6SBruno Prémont 	else
25644da361b6SBruno Prémont 		hid_debug_unregister(hdev);
2565a635f9ddSJiri Kosina 
256685cdaf52SJiri Slaby 	return ret;
256785cdaf52SJiri Slaby }
256885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device);
256985cdaf52SJiri Slaby 
257085cdaf52SJiri Slaby /**
257185cdaf52SJiri Slaby  * hid_allocate_device - allocate new hid device descriptor
257285cdaf52SJiri Slaby  *
257385cdaf52SJiri Slaby  * Allocate and initialize hid device, so that hid_destroy_device might be
257485cdaf52SJiri Slaby  * used to free it.
257585cdaf52SJiri Slaby  *
257685cdaf52SJiri Slaby  * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
257785cdaf52SJiri Slaby  * error value.
257885cdaf52SJiri Slaby  */
257985cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void)
258085cdaf52SJiri Slaby {
258185cdaf52SJiri Slaby 	struct hid_device *hdev;
258285cdaf52SJiri Slaby 	int ret = -ENOMEM;
258385cdaf52SJiri Slaby 
258485cdaf52SJiri Slaby 	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
258585cdaf52SJiri Slaby 	if (hdev == NULL)
258685cdaf52SJiri Slaby 		return ERR_PTR(ret);
258785cdaf52SJiri Slaby 
258885cdaf52SJiri Slaby 	device_initialize(&hdev->dev);
258985cdaf52SJiri Slaby 	hdev->dev.release = hid_device_release;
259085cdaf52SJiri Slaby 	hdev->dev.bus = &hid_bus_type;
259185cdaf52SJiri Slaby 
2592a7197c2eSHenrik Rydberg 	hid_close_report(hdev);
259385cdaf52SJiri Slaby 
2594cd667ce2SJiri Kosina 	init_waitqueue_head(&hdev->debug_wait);
2595cd667ce2SJiri Kosina 	INIT_LIST_HEAD(&hdev->debug_list);
25961deb9d34SJiri Kosina 	spin_lock_init(&hdev->debug_list_lock);
25974ea54542SDavid Herrmann 	sema_init(&hdev->driver_lock, 1);
2598c849a614SAndrew de los Reyes 	sema_init(&hdev->driver_input_lock, 1);
2599cd667ce2SJiri Kosina 
260085cdaf52SJiri Slaby 	return hdev;
260185cdaf52SJiri Slaby }
260285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device);
260385cdaf52SJiri Slaby 
260485cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev)
260585cdaf52SJiri Slaby {
260685cdaf52SJiri Slaby 	if (hdev->status & HID_STAT_ADDED) {
260785cdaf52SJiri Slaby 		device_del(&hdev->dev);
2608a635f9ddSJiri Kosina 		hid_debug_unregister(hdev);
260985cdaf52SJiri Slaby 		hdev->status &= ~HID_STAT_ADDED;
261085cdaf52SJiri Slaby 	}
2611a7197c2eSHenrik Rydberg 	kfree(hdev->dev_rdesc);
2612a7197c2eSHenrik Rydberg 	hdev->dev_rdesc = NULL;
2613a7197c2eSHenrik Rydberg 	hdev->dev_rsize = 0;
261485cdaf52SJiri Slaby }
261585cdaf52SJiri Slaby 
261685cdaf52SJiri Slaby /**
261785cdaf52SJiri Slaby  * hid_destroy_device - free previously allocated device
261885cdaf52SJiri Slaby  *
261985cdaf52SJiri Slaby  * @hdev: hid device
262085cdaf52SJiri Slaby  *
262185cdaf52SJiri Slaby  * If you allocate hid_device through hid_allocate_device, you should ever
262285cdaf52SJiri Slaby  * free by this function.
262385cdaf52SJiri Slaby  */
262485cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev)
262585cdaf52SJiri Slaby {
262685cdaf52SJiri Slaby 	hid_remove_device(hdev);
262785cdaf52SJiri Slaby 	put_device(&hdev->dev);
262885cdaf52SJiri Slaby }
262985cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device);
263085cdaf52SJiri Slaby 
263185cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
263285cdaf52SJiri Slaby 		const char *mod_name)
263385cdaf52SJiri Slaby {
26343a6f82f7SJiri Slaby 	int ret;
26353a6f82f7SJiri Slaby 
263685cdaf52SJiri Slaby 	hdrv->driver.name = hdrv->name;
263785cdaf52SJiri Slaby 	hdrv->driver.bus = &hid_bus_type;
263885cdaf52SJiri Slaby 	hdrv->driver.owner = owner;
263985cdaf52SJiri Slaby 	hdrv->driver.mod_name = mod_name;
264085cdaf52SJiri Slaby 
26413a6f82f7SJiri Slaby 	INIT_LIST_HEAD(&hdrv->dyn_list);
26423a6f82f7SJiri Slaby 	spin_lock_init(&hdrv->dyn_lock);
26433a6f82f7SJiri Slaby 
26443a6f82f7SJiri Slaby 	ret = driver_register(&hdrv->driver);
26453a6f82f7SJiri Slaby 	if (ret)
26463a6f82f7SJiri Slaby 		return ret;
26473a6f82f7SJiri Slaby 
26483a6f82f7SJiri Slaby 	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
26493a6f82f7SJiri Slaby 	if (ret)
26503a6f82f7SJiri Slaby 		driver_unregister(&hdrv->driver);
26513a6f82f7SJiri Slaby 
26523a6f82f7SJiri Slaby 	return ret;
265385cdaf52SJiri Slaby }
265485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver);
265585cdaf52SJiri Slaby 
265685cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv)
265785cdaf52SJiri Slaby {
26583a6f82f7SJiri Slaby 	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
265985cdaf52SJiri Slaby 	driver_unregister(&hdrv->driver);
26603a6f82f7SJiri Slaby 	hid_free_dynids(hdrv);
266185cdaf52SJiri Slaby }
266285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver);
266385cdaf52SJiri Slaby 
26640361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid)
26650361a28dSOliver Neukum {
26660361a28dSOliver Neukum 	struct hid_input *hidinput;
26670361a28dSOliver Neukum 	int i;
26680361a28dSOliver Neukum 
2669e5288eb5SJiri Kosina 	if (!(hid->claimed & HID_CLAIMED_INPUT))
2670e5288eb5SJiri Kosina 		return 0;
2671e5288eb5SJiri Kosina 
26720361a28dSOliver Neukum 	list_for_each_entry(hidinput, &hid->inputs, list) {
26730361a28dSOliver Neukum 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
26740361a28dSOliver Neukum 			if (hidinput->input->key[i])
26750361a28dSOliver Neukum 				return 1;
26760361a28dSOliver Neukum 	}
26770361a28dSOliver Neukum 
26780361a28dSOliver Neukum 	return 0;
26790361a28dSOliver Neukum }
26800361a28dSOliver Neukum 
26810361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
26820361a28dSOliver Neukum 
268386166b7bSJiri Kosina static int __init hid_init(void)
268486166b7bSJiri Kosina {
268585cdaf52SJiri Slaby 	int ret;
268685cdaf52SJiri Slaby 
2687a635f9ddSJiri Kosina 	if (hid_debug)
26884291ee30SJoe Perches 		pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
26894291ee30SJoe Perches 			"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2690a635f9ddSJiri Kosina 
269185cdaf52SJiri Slaby 	ret = bus_register(&hid_bus_type);
269285cdaf52SJiri Slaby 	if (ret) {
26934291ee30SJoe Perches 		pr_err("can't register hid bus\n");
269485cdaf52SJiri Slaby 		goto err;
269585cdaf52SJiri Slaby 	}
269685cdaf52SJiri Slaby 
269785cdaf52SJiri Slaby 	ret = hidraw_init();
269885cdaf52SJiri Slaby 	if (ret)
269985cdaf52SJiri Slaby 		goto err_bus;
270085cdaf52SJiri Slaby 
2701a635f9ddSJiri Kosina 	hid_debug_init();
2702a635f9ddSJiri Kosina 
270385cdaf52SJiri Slaby 	return 0;
270485cdaf52SJiri Slaby err_bus:
270585cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
270685cdaf52SJiri Slaby err:
270785cdaf52SJiri Slaby 	return ret;
270886166b7bSJiri Kosina }
270986166b7bSJiri Kosina 
271086166b7bSJiri Kosina static void __exit hid_exit(void)
271186166b7bSJiri Kosina {
2712a635f9ddSJiri Kosina 	hid_debug_exit();
271386166b7bSJiri Kosina 	hidraw_exit();
271485cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
271586166b7bSJiri Kosina }
271686166b7bSJiri Kosina 
271786166b7bSJiri Kosina module_init(hid_init);
271886166b7bSJiri Kosina module_exit(hid_exit);
271986166b7bSJiri Kosina 
272088adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal");
272188adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik");
272288adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina");
2723aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
2724aa938f79SJiri Kosina 
2725