xref: /openbmc/linux/drivers/hid/hid-core.c (revision cc6b54aa54bf40b762cab45a9fc8aa81653146eb)
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);
556b1968d5SJiri Kosina MODULE_PARM_DESC(debug, "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;
225*cc6b54aaSBenjamin Tissoires 	unsigned usages;
226dde5845aSJiri Kosina 	unsigned offset;
227*cc6b54aaSBenjamin 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 
254*cc6b54aaSBenjamin Tissoires 	usages = max_t(unsigned, parser->local.usage_index,
255*cc6b54aaSBenjamin 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++) {
266*cc6b54aaSBenjamin 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];
273*cc6b54aaSBenjamin 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 {
32277463838SBenjamin Tissoires 	__u32 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:
37377463838SBenjamin Tissoires 		/* Units exponent negative numbers are given through a
37477463838SBenjamin Tissoires 		 * two's complement.
37577463838SBenjamin Tissoires 		 * See "6.2.2.7 Global Items" for more information. */
37677463838SBenjamin Tissoires 		raw_value = item_udata(item);
37777463838SBenjamin Tissoires 		if (!(raw_value & 0xfffffff0))
37877463838SBenjamin Tissoires 			parser->global.unit_exponent = hid_snto32(raw_value, 4);
37977463838SBenjamin Tissoires 		else
38077463838SBenjamin Tissoires 			parser->global.unit_exponent = raw_value;
381dde5845aSJiri Kosina 		return 0;
382dde5845aSJiri Kosina 
383dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT:
384dde5845aSJiri Kosina 		parser->global.unit = item_udata(item);
385dde5845aSJiri Kosina 		return 0;
386dde5845aSJiri Kosina 
387dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
388880d29f1SJiri Slaby 		parser->global.report_size = item_udata(item);
38923408f95SMarek Vasut 		if (parser->global.report_size > 128) {
3908c3d52fcSJiri Kosina 			hid_err(parser->device, "invalid report_size %d\n",
391880d29f1SJiri Slaby 					parser->global.report_size);
392dde5845aSJiri Kosina 			return -1;
393dde5845aSJiri Kosina 		}
394dde5845aSJiri Kosina 		return 0;
395dde5845aSJiri Kosina 
396dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
397880d29f1SJiri Slaby 		parser->global.report_count = item_udata(item);
398880d29f1SJiri Slaby 		if (parser->global.report_count > HID_MAX_USAGES) {
3998c3d52fcSJiri Kosina 			hid_err(parser->device, "invalid report_count %d\n",
400880d29f1SJiri Slaby 					parser->global.report_count);
401dde5845aSJiri Kosina 			return -1;
402dde5845aSJiri Kosina 		}
403dde5845aSJiri Kosina 		return 0;
404dde5845aSJiri Kosina 
405dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
406880d29f1SJiri Slaby 		parser->global.report_id = item_udata(item);
40743622021SKees Cook 		if (parser->global.report_id == 0 ||
40843622021SKees Cook 		    parser->global.report_id >= HID_MAX_IDS) {
40943622021SKees Cook 			hid_err(parser->device, "report_id %u is invalid\n",
41043622021SKees Cook 				parser->global.report_id);
411dde5845aSJiri Kosina 			return -1;
412dde5845aSJiri Kosina 		}
413dde5845aSJiri Kosina 		return 0;
414dde5845aSJiri Kosina 
415dde5845aSJiri Kosina 	default:
4168c3d52fcSJiri Kosina 		hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
417dde5845aSJiri Kosina 		return -1;
418dde5845aSJiri Kosina 	}
419dde5845aSJiri Kosina }
420dde5845aSJiri Kosina 
421dde5845aSJiri Kosina /*
422dde5845aSJiri Kosina  * Process a local item.
423dde5845aSJiri Kosina  */
424dde5845aSJiri Kosina 
425dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
426dde5845aSJiri Kosina {
427dde5845aSJiri Kosina 	__u32 data;
428dde5845aSJiri Kosina 	unsigned n;
429dde5845aSJiri Kosina 
430dde5845aSJiri Kosina 	data = item_udata(item);
431dde5845aSJiri Kosina 
432dde5845aSJiri Kosina 	switch (item->tag) {
433dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_DELIMITER:
434dde5845aSJiri Kosina 
435dde5845aSJiri Kosina 		if (data) {
436dde5845aSJiri Kosina 			/*
437dde5845aSJiri Kosina 			 * We treat items before the first delimiter
438dde5845aSJiri Kosina 			 * as global to all usage sets (branch 0).
439dde5845aSJiri Kosina 			 * In the moment we process only these global
440dde5845aSJiri Kosina 			 * items and the first delimiter set.
441dde5845aSJiri Kosina 			 */
442dde5845aSJiri Kosina 			if (parser->local.delimiter_depth != 0) {
4438c3d52fcSJiri Kosina 				hid_err(parser->device, "nested delimiters\n");
444dde5845aSJiri Kosina 				return -1;
445dde5845aSJiri Kosina 			}
446dde5845aSJiri Kosina 			parser->local.delimiter_depth++;
447dde5845aSJiri Kosina 			parser->local.delimiter_branch++;
448dde5845aSJiri Kosina 		} else {
449dde5845aSJiri Kosina 			if (parser->local.delimiter_depth < 1) {
4508c3d52fcSJiri Kosina 				hid_err(parser->device, "bogus close delimiter\n");
451dde5845aSJiri Kosina 				return -1;
452dde5845aSJiri Kosina 			}
453dde5845aSJiri Kosina 			parser->local.delimiter_depth--;
454dde5845aSJiri Kosina 		}
45538ead6efSPaul Chavent 		return 0;
456dde5845aSJiri Kosina 
457dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE:
458dde5845aSJiri Kosina 
459dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
46058037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
461dde5845aSJiri Kosina 			return 0;
462dde5845aSJiri Kosina 		}
463dde5845aSJiri Kosina 
464dde5845aSJiri Kosina 		if (item->size <= 2)
465dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
466dde5845aSJiri Kosina 
467dde5845aSJiri Kosina 		return hid_add_usage(parser, data);
468dde5845aSJiri Kosina 
469dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
470dde5845aSJiri Kosina 
471dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
47258037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
473dde5845aSJiri Kosina 			return 0;
474dde5845aSJiri Kosina 		}
475dde5845aSJiri Kosina 
476dde5845aSJiri Kosina 		if (item->size <= 2)
477dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
478dde5845aSJiri Kosina 
479dde5845aSJiri Kosina 		parser->local.usage_minimum = data;
480dde5845aSJiri Kosina 		return 0;
481dde5845aSJiri Kosina 
482dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
483dde5845aSJiri Kosina 
484dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
48558037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
486dde5845aSJiri Kosina 			return 0;
487dde5845aSJiri Kosina 		}
488dde5845aSJiri Kosina 
489dde5845aSJiri Kosina 		if (item->size <= 2)
490dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
491dde5845aSJiri Kosina 
492dde5845aSJiri Kosina 		for (n = parser->local.usage_minimum; n <= data; n++)
493dde5845aSJiri Kosina 			if (hid_add_usage(parser, n)) {
49458037eb9SJiri Kosina 				dbg_hid("hid_add_usage failed\n");
495dde5845aSJiri Kosina 				return -1;
496dde5845aSJiri Kosina 			}
497dde5845aSJiri Kosina 		return 0;
498dde5845aSJiri Kosina 
499dde5845aSJiri Kosina 	default:
500dde5845aSJiri Kosina 
50158037eb9SJiri Kosina 		dbg_hid("unknown local item tag 0x%x\n", item->tag);
502dde5845aSJiri Kosina 		return 0;
503dde5845aSJiri Kosina 	}
504dde5845aSJiri Kosina 	return 0;
505dde5845aSJiri Kosina }
506dde5845aSJiri Kosina 
507dde5845aSJiri Kosina /*
508dde5845aSJiri Kosina  * Process a main item.
509dde5845aSJiri Kosina  */
510dde5845aSJiri Kosina 
511dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
512dde5845aSJiri Kosina {
513dde5845aSJiri Kosina 	__u32 data;
514dde5845aSJiri Kosina 	int ret;
515dde5845aSJiri Kosina 
516dde5845aSJiri Kosina 	data = item_udata(item);
517dde5845aSJiri Kosina 
518dde5845aSJiri Kosina 	switch (item->tag) {
519dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
520dde5845aSJiri Kosina 		ret = open_collection(parser, data & 0xff);
521dde5845aSJiri Kosina 		break;
522dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
523dde5845aSJiri Kosina 		ret = close_collection(parser);
524dde5845aSJiri Kosina 		break;
525dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_INPUT:
526dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
527dde5845aSJiri Kosina 		break;
528dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_OUTPUT:
529dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
530dde5845aSJiri Kosina 		break;
531dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_FEATURE:
532dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
533dde5845aSJiri Kosina 		break;
534dde5845aSJiri Kosina 	default:
5358c3d52fcSJiri Kosina 		hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag);
536dde5845aSJiri Kosina 		ret = 0;
537dde5845aSJiri Kosina 	}
538dde5845aSJiri Kosina 
539dde5845aSJiri Kosina 	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
540dde5845aSJiri Kosina 
541dde5845aSJiri Kosina 	return ret;
542dde5845aSJiri Kosina }
543dde5845aSJiri Kosina 
544dde5845aSJiri Kosina /*
545dde5845aSJiri Kosina  * Process a reserved item.
546dde5845aSJiri Kosina  */
547dde5845aSJiri Kosina 
548dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
549dde5845aSJiri Kosina {
55058037eb9SJiri Kosina 	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
551dde5845aSJiri Kosina 	return 0;
552dde5845aSJiri Kosina }
553dde5845aSJiri Kosina 
554dde5845aSJiri Kosina /*
555dde5845aSJiri Kosina  * Free a report and all registered fields. The field->usage and
556dde5845aSJiri Kosina  * field->value table's are allocated behind the field, so we need
557dde5845aSJiri Kosina  * only to free(field) itself.
558dde5845aSJiri Kosina  */
559dde5845aSJiri Kosina 
560dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report)
561dde5845aSJiri Kosina {
562dde5845aSJiri Kosina 	unsigned n;
563dde5845aSJiri Kosina 
564dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
565dde5845aSJiri Kosina 		kfree(report->field[n]);
566dde5845aSJiri Kosina 	kfree(report);
567dde5845aSJiri Kosina }
568dde5845aSJiri Kosina 
569dde5845aSJiri Kosina /*
570a7197c2eSHenrik Rydberg  * Close report. This function returns the device
571a7197c2eSHenrik Rydberg  * state to the point prior to hid_open_report().
572dde5845aSJiri Kosina  */
573a7197c2eSHenrik Rydberg static void hid_close_report(struct hid_device *device)
574dde5845aSJiri Kosina {
575dde5845aSJiri Kosina 	unsigned i, j;
576dde5845aSJiri Kosina 
577dde5845aSJiri Kosina 	for (i = 0; i < HID_REPORT_TYPES; i++) {
578dde5845aSJiri Kosina 		struct hid_report_enum *report_enum = device->report_enum + i;
579dde5845aSJiri Kosina 
58043622021SKees Cook 		for (j = 0; j < HID_MAX_IDS; j++) {
581dde5845aSJiri Kosina 			struct hid_report *report = report_enum->report_id_hash[j];
582dde5845aSJiri Kosina 			if (report)
583dde5845aSJiri Kosina 				hid_free_report(report);
584dde5845aSJiri Kosina 		}
585a7197c2eSHenrik Rydberg 		memset(report_enum, 0, sizeof(*report_enum));
586a7197c2eSHenrik Rydberg 		INIT_LIST_HEAD(&report_enum->report_list);
587dde5845aSJiri Kosina 	}
588dde5845aSJiri Kosina 
589dde5845aSJiri Kosina 	kfree(device->rdesc);
590a7197c2eSHenrik Rydberg 	device->rdesc = NULL;
591a7197c2eSHenrik Rydberg 	device->rsize = 0;
592a7197c2eSHenrik Rydberg 
593767fe787SJiri Kosina 	kfree(device->collection);
594a7197c2eSHenrik Rydberg 	device->collection = NULL;
595a7197c2eSHenrik Rydberg 	device->collection_size = 0;
596a7197c2eSHenrik Rydberg 	device->maxcollection = 0;
597a7197c2eSHenrik Rydberg 	device->maxapplication = 0;
598a7197c2eSHenrik Rydberg 
599a7197c2eSHenrik Rydberg 	device->status &= ~HID_STAT_PARSED;
600a7197c2eSHenrik Rydberg }
601a7197c2eSHenrik Rydberg 
602a7197c2eSHenrik Rydberg /*
603a7197c2eSHenrik Rydberg  * Free a device structure, all reports, and all fields.
604a7197c2eSHenrik Rydberg  */
605a7197c2eSHenrik Rydberg 
606a7197c2eSHenrik Rydberg static void hid_device_release(struct device *dev)
607a7197c2eSHenrik Rydberg {
608a7197c2eSHenrik Rydberg 	struct hid_device *hid = container_of(dev, struct hid_device, dev);
609a7197c2eSHenrik Rydberg 
610a7197c2eSHenrik Rydberg 	hid_close_report(hid);
611a7197c2eSHenrik Rydberg 	kfree(hid->dev_rdesc);
612a7197c2eSHenrik Rydberg 	kfree(hid);
613dde5845aSJiri Kosina }
614dde5845aSJiri Kosina 
615dde5845aSJiri Kosina /*
616dde5845aSJiri Kosina  * Fetch a report description item from the data stream. We support long
617dde5845aSJiri Kosina  * items, though they are not used yet.
618dde5845aSJiri Kosina  */
619dde5845aSJiri Kosina 
620dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
621dde5845aSJiri Kosina {
622dde5845aSJiri Kosina 	u8 b;
623dde5845aSJiri Kosina 
624dde5845aSJiri Kosina 	if ((end - start) <= 0)
625dde5845aSJiri Kosina 		return NULL;
626dde5845aSJiri Kosina 
627dde5845aSJiri Kosina 	b = *start++;
628dde5845aSJiri Kosina 
629dde5845aSJiri Kosina 	item->type = (b >> 2) & 3;
630dde5845aSJiri Kosina 	item->tag  = (b >> 4) & 15;
631dde5845aSJiri Kosina 
632dde5845aSJiri Kosina 	if (item->tag == HID_ITEM_TAG_LONG) {
633dde5845aSJiri Kosina 
634dde5845aSJiri Kosina 		item->format = HID_ITEM_FORMAT_LONG;
635dde5845aSJiri Kosina 
636dde5845aSJiri Kosina 		if ((end - start) < 2)
637dde5845aSJiri Kosina 			return NULL;
638dde5845aSJiri Kosina 
639dde5845aSJiri Kosina 		item->size = *start++;
640dde5845aSJiri Kosina 		item->tag  = *start++;
641dde5845aSJiri Kosina 
642dde5845aSJiri Kosina 		if ((end - start) < item->size)
643dde5845aSJiri Kosina 			return NULL;
644dde5845aSJiri Kosina 
645dde5845aSJiri Kosina 		item->data.longdata = start;
646dde5845aSJiri Kosina 		start += item->size;
647dde5845aSJiri Kosina 		return start;
648dde5845aSJiri Kosina 	}
649dde5845aSJiri Kosina 
650dde5845aSJiri Kosina 	item->format = HID_ITEM_FORMAT_SHORT;
651dde5845aSJiri Kosina 	item->size = b & 3;
652dde5845aSJiri Kosina 
653dde5845aSJiri Kosina 	switch (item->size) {
654dde5845aSJiri Kosina 	case 0:
655dde5845aSJiri Kosina 		return start;
656dde5845aSJiri Kosina 
657dde5845aSJiri Kosina 	case 1:
658dde5845aSJiri Kosina 		if ((end - start) < 1)
659dde5845aSJiri Kosina 			return NULL;
660dde5845aSJiri Kosina 		item->data.u8 = *start++;
661dde5845aSJiri Kosina 		return start;
662dde5845aSJiri Kosina 
663dde5845aSJiri Kosina 	case 2:
664dde5845aSJiri Kosina 		if ((end - start) < 2)
665dde5845aSJiri Kosina 			return NULL;
666c105068fSHarvey Harrison 		item->data.u16 = get_unaligned_le16(start);
667dde5845aSJiri Kosina 		start = (__u8 *)((__le16 *)start + 1);
668dde5845aSJiri Kosina 		return start;
669dde5845aSJiri Kosina 
670dde5845aSJiri Kosina 	case 3:
671dde5845aSJiri Kosina 		item->size++;
672dde5845aSJiri Kosina 		if ((end - start) < 4)
673dde5845aSJiri Kosina 			return NULL;
674c105068fSHarvey Harrison 		item->data.u32 = get_unaligned_le32(start);
675dde5845aSJiri Kosina 		start = (__u8 *)((__le32 *)start + 1);
676dde5845aSJiri Kosina 		return start;
677dde5845aSJiri Kosina 	}
678dde5845aSJiri Kosina 
679dde5845aSJiri Kosina 	return NULL;
680dde5845aSJiri Kosina }
681dde5845aSJiri Kosina 
6823dc8fc08SBenjamin Tissoires static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
683734c6609SHenrik Rydberg {
6843dc8fc08SBenjamin Tissoires 	struct hid_device *hid = parser->device;
6853dc8fc08SBenjamin Tissoires 
6864fa3a583SHenrik Rydberg 	if (usage == HID_DG_CONTACTID)
6874fa3a583SHenrik Rydberg 		hid->group = HID_GROUP_MULTITOUCH;
688734c6609SHenrik Rydberg }
689734c6609SHenrik Rydberg 
690f961bd35SBenjamin Tissoires static void hid_scan_feature_usage(struct hid_parser *parser, u32 usage)
691f961bd35SBenjamin Tissoires {
692f961bd35SBenjamin Tissoires 	if (usage == 0xff0000c5 && parser->global.report_count == 256 &&
693f961bd35SBenjamin Tissoires 	    parser->global.report_size == 8)
694f961bd35SBenjamin Tissoires 		parser->scan_flags |= HID_SCAN_FLAG_MT_WIN_8;
695f961bd35SBenjamin Tissoires }
696f961bd35SBenjamin Tissoires 
6973dc8fc08SBenjamin Tissoires static void hid_scan_collection(struct hid_parser *parser, unsigned type)
6983dc8fc08SBenjamin Tissoires {
6993dc8fc08SBenjamin Tissoires 	struct hid_device *hid = parser->device;
7003dc8fc08SBenjamin Tissoires 
7013dc8fc08SBenjamin Tissoires 	if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
7023dc8fc08SBenjamin Tissoires 	    type == HID_COLLECTION_PHYSICAL)
7033dc8fc08SBenjamin Tissoires 		hid->group = HID_GROUP_SENSOR_HUB;
7043dc8fc08SBenjamin Tissoires }
7053dc8fc08SBenjamin Tissoires 
7063dc8fc08SBenjamin Tissoires static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
7073dc8fc08SBenjamin Tissoires {
7083dc8fc08SBenjamin Tissoires 	__u32 data;
7093dc8fc08SBenjamin Tissoires 	int i;
7103dc8fc08SBenjamin Tissoires 
7113dc8fc08SBenjamin Tissoires 	data = item_udata(item);
7123dc8fc08SBenjamin Tissoires 
7133dc8fc08SBenjamin Tissoires 	switch (item->tag) {
7143dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
7153dc8fc08SBenjamin Tissoires 		hid_scan_collection(parser, data & 0xff);
7163dc8fc08SBenjamin Tissoires 		break;
7173dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
7183dc8fc08SBenjamin Tissoires 		break;
7193dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_INPUT:
7203dc8fc08SBenjamin Tissoires 		for (i = 0; i < parser->local.usage_index; i++)
7213dc8fc08SBenjamin Tissoires 			hid_scan_input_usage(parser, parser->local.usage[i]);
7223dc8fc08SBenjamin Tissoires 		break;
7233dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_OUTPUT:
7243dc8fc08SBenjamin Tissoires 		break;
7253dc8fc08SBenjamin Tissoires 	case HID_MAIN_ITEM_TAG_FEATURE:
726f961bd35SBenjamin Tissoires 		for (i = 0; i < parser->local.usage_index; i++)
727f961bd35SBenjamin Tissoires 			hid_scan_feature_usage(parser, parser->local.usage[i]);
7283dc8fc08SBenjamin Tissoires 		break;
7293dc8fc08SBenjamin Tissoires 	}
7303dc8fc08SBenjamin Tissoires 
7313dc8fc08SBenjamin Tissoires 	/* Reset the local parser environment */
7323dc8fc08SBenjamin Tissoires 	memset(&parser->local, 0, sizeof(parser->local));
7333dc8fc08SBenjamin Tissoires 
7343dc8fc08SBenjamin Tissoires 	return 0;
7353dc8fc08SBenjamin Tissoires }
7363dc8fc08SBenjamin Tissoires 
737734c6609SHenrik Rydberg /*
738734c6609SHenrik Rydberg  * Scan a report descriptor before the device is added to the bus.
739734c6609SHenrik Rydberg  * Sets device groups and other properties that determine what driver
740734c6609SHenrik Rydberg  * to load.
741734c6609SHenrik Rydberg  */
742734c6609SHenrik Rydberg static int hid_scan_report(struct hid_device *hid)
743734c6609SHenrik Rydberg {
7443dc8fc08SBenjamin Tissoires 	struct hid_parser *parser;
7453dc8fc08SBenjamin Tissoires 	struct hid_item item;
746734c6609SHenrik Rydberg 	__u8 *start = hid->dev_rdesc;
747734c6609SHenrik Rydberg 	__u8 *end = start + hid->dev_rsize;
7483dc8fc08SBenjamin Tissoires 	static int (*dispatch_type[])(struct hid_parser *parser,
7493dc8fc08SBenjamin Tissoires 				      struct hid_item *item) = {
7503dc8fc08SBenjamin Tissoires 		hid_scan_main,
7513dc8fc08SBenjamin Tissoires 		hid_parser_global,
7523dc8fc08SBenjamin Tissoires 		hid_parser_local,
7533dc8fc08SBenjamin Tissoires 		hid_parser_reserved
7543dc8fc08SBenjamin Tissoires 	};
755734c6609SHenrik Rydberg 
7563dc8fc08SBenjamin Tissoires 	parser = vzalloc(sizeof(struct hid_parser));
7573dc8fc08SBenjamin Tissoires 	if (!parser)
7583dc8fc08SBenjamin Tissoires 		return -ENOMEM;
7593dc8fc08SBenjamin Tissoires 
7603dc8fc08SBenjamin Tissoires 	parser->device = hid;
761734c6609SHenrik Rydberg 	hid->group = HID_GROUP_GENERIC;
762734c6609SHenrik Rydberg 
7633dc8fc08SBenjamin Tissoires 	/*
7643dc8fc08SBenjamin Tissoires 	 * The parsing is simpler than the one in hid_open_report() as we should
7653dc8fc08SBenjamin Tissoires 	 * be robust against hid errors. Those errors will be raised by
7663dc8fc08SBenjamin Tissoires 	 * hid_open_report() anyway.
7673dc8fc08SBenjamin Tissoires 	 */
7683dc8fc08SBenjamin Tissoires 	while ((start = fetch_item(start, end, &item)) != NULL)
7693dc8fc08SBenjamin Tissoires 		dispatch_type[item.type](parser, &item);
7703dc8fc08SBenjamin Tissoires 
771f961bd35SBenjamin Tissoires 	/*
772f961bd35SBenjamin Tissoires 	 * Handle special flags set during scanning.
773f961bd35SBenjamin Tissoires 	 */
774f961bd35SBenjamin Tissoires 	if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
775f961bd35SBenjamin Tissoires 	    (hid->group == HID_GROUP_MULTITOUCH))
776f961bd35SBenjamin Tissoires 		hid->group = HID_GROUP_MULTITOUCH_WIN_8;
777f961bd35SBenjamin Tissoires 
7783dc8fc08SBenjamin Tissoires 	vfree(parser);
779734c6609SHenrik Rydberg 	return 0;
780734c6609SHenrik Rydberg }
781734c6609SHenrik Rydberg 
78285cdaf52SJiri Slaby /**
78385cdaf52SJiri Slaby  * hid_parse_report - parse device report
78485cdaf52SJiri Slaby  *
78585cdaf52SJiri Slaby  * @device: hid device
78685cdaf52SJiri Slaby  * @start: report start
78785cdaf52SJiri Slaby  * @size: report size
78885cdaf52SJiri Slaby  *
789a7197c2eSHenrik Rydberg  * Allocate the device report as read by the bus driver. This function should
790a7197c2eSHenrik Rydberg  * only be called from parse() in ll drivers.
791a7197c2eSHenrik Rydberg  */
792a7197c2eSHenrik Rydberg int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
793a7197c2eSHenrik Rydberg {
794a7197c2eSHenrik Rydberg 	hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
795a7197c2eSHenrik Rydberg 	if (!hid->dev_rdesc)
796a7197c2eSHenrik Rydberg 		return -ENOMEM;
797a7197c2eSHenrik Rydberg 	hid->dev_rsize = size;
798a7197c2eSHenrik Rydberg 	return 0;
799a7197c2eSHenrik Rydberg }
800a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_parse_report);
801a7197c2eSHenrik Rydberg 
802331415ffSKees Cook static const char * const hid_report_names[] = {
803331415ffSKees Cook 	"HID_INPUT_REPORT",
804331415ffSKees Cook 	"HID_OUTPUT_REPORT",
805331415ffSKees Cook 	"HID_FEATURE_REPORT",
806331415ffSKees Cook };
807331415ffSKees Cook /**
808331415ffSKees Cook  * hid_validate_values - validate existing device report's value indexes
809331415ffSKees Cook  *
810331415ffSKees Cook  * @device: hid device
811331415ffSKees Cook  * @type: which report type to examine
812331415ffSKees Cook  * @id: which report ID to examine (0 for first)
813331415ffSKees Cook  * @field_index: which report field to examine
814331415ffSKees Cook  * @report_counts: expected number of values
815331415ffSKees Cook  *
816331415ffSKees Cook  * Validate the number of values in a given field of a given report, after
817331415ffSKees Cook  * parsing.
818331415ffSKees Cook  */
819331415ffSKees Cook struct hid_report *hid_validate_values(struct hid_device *hid,
820331415ffSKees Cook 				       unsigned int type, unsigned int id,
821331415ffSKees Cook 				       unsigned int field_index,
822331415ffSKees Cook 				       unsigned int report_counts)
823331415ffSKees Cook {
824331415ffSKees Cook 	struct hid_report *report;
825331415ffSKees Cook 
826331415ffSKees Cook 	if (type > HID_FEATURE_REPORT) {
827331415ffSKees Cook 		hid_err(hid, "invalid HID report type %u\n", type);
828331415ffSKees Cook 		return NULL;
829331415ffSKees Cook 	}
830331415ffSKees Cook 
831331415ffSKees Cook 	if (id >= HID_MAX_IDS) {
832331415ffSKees Cook 		hid_err(hid, "invalid HID report id %u\n", id);
833331415ffSKees Cook 		return NULL;
834331415ffSKees Cook 	}
835331415ffSKees Cook 
836331415ffSKees Cook 	/*
837331415ffSKees Cook 	 * Explicitly not using hid_get_report() here since it depends on
838331415ffSKees Cook 	 * ->numbered being checked, which may not always be the case when
839331415ffSKees Cook 	 * drivers go to access report values.
840331415ffSKees Cook 	 */
841331415ffSKees Cook 	report = hid->report_enum[type].report_id_hash[id];
842331415ffSKees Cook 	if (!report) {
843331415ffSKees Cook 		hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
844331415ffSKees Cook 		return NULL;
845331415ffSKees Cook 	}
846331415ffSKees Cook 	if (report->maxfield <= field_index) {
847331415ffSKees Cook 		hid_err(hid, "not enough fields in %s %u\n",
848331415ffSKees Cook 			hid_report_names[type], id);
849331415ffSKees Cook 		return NULL;
850331415ffSKees Cook 	}
851331415ffSKees Cook 	if (report->field[field_index]->report_count < report_counts) {
852331415ffSKees Cook 		hid_err(hid, "not enough values in %s %u field %u\n",
853331415ffSKees Cook 			hid_report_names[type], id, field_index);
854331415ffSKees Cook 		return NULL;
855331415ffSKees Cook 	}
856331415ffSKees Cook 	return report;
857331415ffSKees Cook }
858331415ffSKees Cook EXPORT_SYMBOL_GPL(hid_validate_values);
859331415ffSKees Cook 
860a7197c2eSHenrik Rydberg /**
861a7197c2eSHenrik Rydberg  * hid_open_report - open a driver-specific device report
862a7197c2eSHenrik Rydberg  *
863a7197c2eSHenrik Rydberg  * @device: hid device
864a7197c2eSHenrik Rydberg  *
865dde5845aSJiri Kosina  * Parse a report description into a hid_device structure. Reports are
866dde5845aSJiri Kosina  * enumerated, fields are attached to these reports.
86785cdaf52SJiri Slaby  * 0 returned on success, otherwise nonzero error value.
868a7197c2eSHenrik Rydberg  *
869a7197c2eSHenrik Rydberg  * This function (or the equivalent hid_parse() macro) should only be
870a7197c2eSHenrik Rydberg  * called from probe() in drivers, before starting the device.
871dde5845aSJiri Kosina  */
872a7197c2eSHenrik Rydberg int hid_open_report(struct hid_device *device)
873dde5845aSJiri Kosina {
874dde5845aSJiri Kosina 	struct hid_parser *parser;
875dde5845aSJiri Kosina 	struct hid_item item;
876a7197c2eSHenrik Rydberg 	unsigned int size;
877a7197c2eSHenrik Rydberg 	__u8 *start;
87886e6b77eSKevin Daughtridge 	__u8 *buf;
879dde5845aSJiri Kosina 	__u8 *end;
88085cdaf52SJiri Slaby 	int ret;
881dde5845aSJiri Kosina 	static int (*dispatch_type[])(struct hid_parser *parser,
882dde5845aSJiri Kosina 				      struct hid_item *item) = {
883dde5845aSJiri Kosina 		hid_parser_main,
884dde5845aSJiri Kosina 		hid_parser_global,
885dde5845aSJiri Kosina 		hid_parser_local,
886dde5845aSJiri Kosina 		hid_parser_reserved
887dde5845aSJiri Kosina 	};
888dde5845aSJiri Kosina 
889a7197c2eSHenrik Rydberg 	if (WARN_ON(device->status & HID_STAT_PARSED))
890a7197c2eSHenrik Rydberg 		return -EBUSY;
891a7197c2eSHenrik Rydberg 
892a7197c2eSHenrik Rydberg 	start = device->dev_rdesc;
893a7197c2eSHenrik Rydberg 	if (WARN_ON(!start))
894a7197c2eSHenrik Rydberg 		return -ENODEV;
895a7197c2eSHenrik Rydberg 	size = device->dev_rsize;
896a7197c2eSHenrik Rydberg 
89786e6b77eSKevin Daughtridge 	buf = kmemdup(start, size, GFP_KERNEL);
89886e6b77eSKevin Daughtridge 	if (buf == NULL)
89985cdaf52SJiri Slaby 		return -ENOMEM;
90086e6b77eSKevin Daughtridge 
90186e6b77eSKevin Daughtridge 	if (device->driver->report_fixup)
90286e6b77eSKevin Daughtridge 		start = device->driver->report_fixup(device, buf, &size);
90386e6b77eSKevin Daughtridge 	else
90486e6b77eSKevin Daughtridge 		start = buf;
90586e6b77eSKevin Daughtridge 
90686e6b77eSKevin Daughtridge 	start = kmemdup(start, size, GFP_KERNEL);
90786e6b77eSKevin Daughtridge 	kfree(buf);
90886e6b77eSKevin Daughtridge 	if (start == NULL)
90986e6b77eSKevin Daughtridge 		return -ENOMEM;
91086e6b77eSKevin Daughtridge 
91186e6b77eSKevin Daughtridge 	device->rdesc = start;
912dde5845aSJiri Kosina 	device->rsize = size;
913dde5845aSJiri Kosina 
914fe258020SJoe Perches 	parser = vzalloc(sizeof(struct hid_parser));
91585cdaf52SJiri Slaby 	if (!parser) {
91685cdaf52SJiri Slaby 		ret = -ENOMEM;
91785cdaf52SJiri Slaby 		goto err;
918dde5845aSJiri Kosina 	}
91985cdaf52SJiri Slaby 
920dde5845aSJiri Kosina 	parser->device = device;
921dde5845aSJiri Kosina 
922dde5845aSJiri Kosina 	end = start + size;
923a7197c2eSHenrik Rydberg 
924a7197c2eSHenrik Rydberg 	device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
925a7197c2eSHenrik Rydberg 				     sizeof(struct hid_collection), GFP_KERNEL);
926a7197c2eSHenrik Rydberg 	if (!device->collection) {
927a7197c2eSHenrik Rydberg 		ret = -ENOMEM;
928a7197c2eSHenrik Rydberg 		goto err;
929a7197c2eSHenrik Rydberg 	}
930a7197c2eSHenrik Rydberg 	device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
931a7197c2eSHenrik Rydberg 
93285cdaf52SJiri Slaby 	ret = -EINVAL;
933dde5845aSJiri Kosina 	while ((start = fetch_item(start, end, &item)) != NULL) {
934dde5845aSJiri Kosina 
935dde5845aSJiri Kosina 		if (item.format != HID_ITEM_FORMAT_SHORT) {
9368c3d52fcSJiri Kosina 			hid_err(device, "unexpected long global item\n");
93785cdaf52SJiri Slaby 			goto err;
938dde5845aSJiri Kosina 		}
939dde5845aSJiri Kosina 
940dde5845aSJiri Kosina 		if (dispatch_type[item.type](parser, &item)) {
9418c3d52fcSJiri Kosina 			hid_err(device, "item %u %u %u %u parsing failed\n",
9424291ee30SJoe Perches 				item.format, (unsigned)item.size,
9434291ee30SJoe Perches 				(unsigned)item.type, (unsigned)item.tag);
94485cdaf52SJiri Slaby 			goto err;
945dde5845aSJiri Kosina 		}
946dde5845aSJiri Kosina 
947dde5845aSJiri Kosina 		if (start == end) {
948dde5845aSJiri Kosina 			if (parser->collection_stack_ptr) {
9498c3d52fcSJiri Kosina 				hid_err(device, "unbalanced collection at end of report description\n");
95085cdaf52SJiri Slaby 				goto err;
951dde5845aSJiri Kosina 			}
952dde5845aSJiri Kosina 			if (parser->local.delimiter_depth) {
9538c3d52fcSJiri Kosina 				hid_err(device, "unbalanced delimiter at end of report description\n");
95485cdaf52SJiri Slaby 				goto err;
955dde5845aSJiri Kosina 			}
95647a80edbSJiri Kosina 			vfree(parser);
957a7197c2eSHenrik Rydberg 			device->status |= HID_STAT_PARSED;
95885cdaf52SJiri Slaby 			return 0;
959dde5845aSJiri Kosina 		}
960dde5845aSJiri Kosina 	}
961dde5845aSJiri Kosina 
9628c3d52fcSJiri Kosina 	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
96385cdaf52SJiri Slaby err:
96447a80edbSJiri Kosina 	vfree(parser);
965a7197c2eSHenrik Rydberg 	hid_close_report(device);
96685cdaf52SJiri Slaby 	return ret;
967dde5845aSJiri Kosina }
968a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_open_report);
969dde5845aSJiri Kosina 
970dde5845aSJiri Kosina /*
971dde5845aSJiri Kosina  * Convert a signed n-bit integer to signed 32-bit integer. Common
972dde5845aSJiri Kosina  * cases are done through the compiler, the screwed things has to be
973dde5845aSJiri Kosina  * done by hand.
974dde5845aSJiri Kosina  */
975dde5845aSJiri Kosina 
976dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n)
977dde5845aSJiri Kosina {
978dde5845aSJiri Kosina 	switch (n) {
979dde5845aSJiri Kosina 	case 8:  return ((__s8)value);
980dde5845aSJiri Kosina 	case 16: return ((__s16)value);
981dde5845aSJiri Kosina 	case 32: return ((__s32)value);
982dde5845aSJiri Kosina 	}
983dde5845aSJiri Kosina 	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
984dde5845aSJiri Kosina }
985dde5845aSJiri Kosina 
98677463838SBenjamin Tissoires s32 hid_snto32(__u32 value, unsigned n)
98777463838SBenjamin Tissoires {
98877463838SBenjamin Tissoires 	return snto32(value, n);
98977463838SBenjamin Tissoires }
99077463838SBenjamin Tissoires EXPORT_SYMBOL_GPL(hid_snto32);
99177463838SBenjamin Tissoires 
992dde5845aSJiri Kosina /*
993dde5845aSJiri Kosina  * Convert a signed 32-bit integer to a signed n-bit integer.
994dde5845aSJiri Kosina  */
995dde5845aSJiri Kosina 
996dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n)
997dde5845aSJiri Kosina {
998dde5845aSJiri Kosina 	s32 a = value >> (n - 1);
999dde5845aSJiri Kosina 	if (a && a != -1)
1000dde5845aSJiri Kosina 		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
1001dde5845aSJiri Kosina 	return value & ((1 << n) - 1);
1002dde5845aSJiri Kosina }
1003dde5845aSJiri Kosina 
1004dde5845aSJiri Kosina /*
1005dde5845aSJiri Kosina  * Extract/implement a data field from/to a little endian report (bit array).
1006dde5845aSJiri Kosina  *
1007dde5845aSJiri Kosina  * Code sort-of follows HID spec:
1008dde5845aSJiri Kosina  *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
1009dde5845aSJiri Kosina  *
1010dde5845aSJiri Kosina  * While the USB HID spec allows unlimited length bit fields in "report
1011dde5845aSJiri Kosina  * descriptors", most devices never use more than 16 bits.
1012dde5845aSJiri Kosina  * One model of UPS is claimed to report "LINEV" as a 32-bit field.
1013dde5845aSJiri Kosina  * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
1014dde5845aSJiri Kosina  */
1015dde5845aSJiri Kosina 
101616ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report,
10174291ee30SJoe Perches 		     unsigned offset, unsigned n)
1018dde5845aSJiri Kosina {
1019dde5845aSJiri Kosina 	u64 x;
1020dde5845aSJiri Kosina 
1021c4124c9bSJiri Kosina 	if (n > 32)
10224291ee30SJoe Perches 		hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
1023c4124c9bSJiri Kosina 			 n, current->comm);
1024dde5845aSJiri Kosina 
1025dde5845aSJiri Kosina 	report += offset >> 3;  /* adjust byte index */
1026dde5845aSJiri Kosina 	offset &= 7;            /* now only need bit offset into one byte */
1027c105068fSHarvey Harrison 	x = get_unaligned_le64(report);
1028dde5845aSJiri Kosina 	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
1029dde5845aSJiri Kosina 	return (u32) x;
1030dde5845aSJiri Kosina }
1031dde5845aSJiri Kosina 
1032dde5845aSJiri Kosina /*
1033dde5845aSJiri Kosina  * "implement" : set bits in a little endian bit stream.
1034dde5845aSJiri Kosina  * Same concepts as "extract" (see comments above).
1035dde5845aSJiri Kosina  * The data mangled in the bit stream remains in little endian
1036dde5845aSJiri Kosina  * order the whole time. It make more sense to talk about
1037dde5845aSJiri Kosina  * endianness of register values by considering a register
1038dde5845aSJiri Kosina  * a "cached" copy of the little endiad bit stream.
1039dde5845aSJiri Kosina  */
104016ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report,
10414291ee30SJoe Perches 		      unsigned offset, unsigned n, __u32 value)
1042dde5845aSJiri Kosina {
10436f0168d2SHarvey Harrison 	u64 x;
1044dde5845aSJiri Kosina 	u64 m = (1ULL << n) - 1;
1045dde5845aSJiri Kosina 
1046c4124c9bSJiri Kosina 	if (n > 32)
10474291ee30SJoe Perches 		hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
10484291ee30SJoe Perches 			 __func__, n, current->comm);
1049dde5845aSJiri Kosina 
1050c4124c9bSJiri Kosina 	if (value > m)
10514291ee30SJoe Perches 		hid_warn(hid, "%s() called with too large value %d! (%s)\n",
10524291ee30SJoe Perches 			 __func__, value, current->comm);
1053dde5845aSJiri Kosina 	WARN_ON(value > m);
1054dde5845aSJiri Kosina 	value &= m;
1055dde5845aSJiri Kosina 
1056dde5845aSJiri Kosina 	report += offset >> 3;
1057dde5845aSJiri Kosina 	offset &= 7;
1058dde5845aSJiri Kosina 
10596f0168d2SHarvey Harrison 	x = get_unaligned_le64(report);
10606f0168d2SHarvey Harrison 	x &= ~(m << offset);
10616f0168d2SHarvey Harrison 	x |= ((u64)value) << offset;
10626f0168d2SHarvey Harrison 	put_unaligned_le64(x, report);
1063dde5845aSJiri Kosina }
1064dde5845aSJiri Kosina 
1065dde5845aSJiri Kosina /*
1066dde5845aSJiri Kosina  * Search an array for a value.
1067dde5845aSJiri Kosina  */
1068dde5845aSJiri Kosina 
106916ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n)
1070dde5845aSJiri Kosina {
1071dde5845aSJiri Kosina 	while (n--) {
1072dde5845aSJiri Kosina 		if (*array++ == value)
1073dde5845aSJiri Kosina 			return 0;
1074dde5845aSJiri Kosina 	}
1075dde5845aSJiri Kosina 	return -1;
1076dde5845aSJiri Kosina }
1077dde5845aSJiri Kosina 
107885cdaf52SJiri Slaby /**
107985cdaf52SJiri Slaby  * hid_match_report - check if driver's raw_event should be called
108085cdaf52SJiri Slaby  *
108185cdaf52SJiri Slaby  * @hid: hid device
108285cdaf52SJiri Slaby  * @report_type: type to match against
108385cdaf52SJiri Slaby  *
108485cdaf52SJiri Slaby  * compare hid->driver->report_table->report_type to report->type
108585cdaf52SJiri Slaby  */
108685cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report)
1087dde5845aSJiri Kosina {
108885cdaf52SJiri Slaby 	const struct hid_report_id *id = hid->driver->report_table;
108985cdaf52SJiri Slaby 
109085cdaf52SJiri Slaby 	if (!id) /* NULL means all */
109185cdaf52SJiri Slaby 		return 1;
109285cdaf52SJiri Slaby 
109385cdaf52SJiri Slaby 	for (; id->report_type != HID_TERMINATOR; id++)
109485cdaf52SJiri Slaby 		if (id->report_type == HID_ANY_ID ||
109585cdaf52SJiri Slaby 				id->report_type == report->type)
109685cdaf52SJiri Slaby 			return 1;
109785cdaf52SJiri Slaby 	return 0;
109885cdaf52SJiri Slaby }
109985cdaf52SJiri Slaby 
110085cdaf52SJiri Slaby /**
110185cdaf52SJiri Slaby  * hid_match_usage - check if driver's event should be called
110285cdaf52SJiri Slaby  *
110385cdaf52SJiri Slaby  * @hid: hid device
110485cdaf52SJiri Slaby  * @usage: usage to match against
110585cdaf52SJiri Slaby  *
110685cdaf52SJiri Slaby  * compare hid->driver->usage_table->usage_{type,code} to
110785cdaf52SJiri Slaby  * usage->usage_{type,code}
110885cdaf52SJiri Slaby  */
110985cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
111085cdaf52SJiri Slaby {
111185cdaf52SJiri Slaby 	const struct hid_usage_id *id = hid->driver->usage_table;
111285cdaf52SJiri Slaby 
111385cdaf52SJiri Slaby 	if (!id) /* NULL means all */
111485cdaf52SJiri Slaby 		return 1;
111585cdaf52SJiri Slaby 
111685cdaf52SJiri Slaby 	for (; id->usage_type != HID_ANY_ID - 1; id++)
111785cdaf52SJiri Slaby 		if ((id->usage_hid == HID_ANY_ID ||
111885cdaf52SJiri Slaby 				id->usage_hid == usage->hid) &&
111985cdaf52SJiri Slaby 				(id->usage_type == HID_ANY_ID ||
112085cdaf52SJiri Slaby 				id->usage_type == usage->type) &&
112185cdaf52SJiri Slaby 				(id->usage_code == HID_ANY_ID ||
112285cdaf52SJiri Slaby 				 id->usage_code == usage->code))
112385cdaf52SJiri Slaby 			return 1;
112485cdaf52SJiri Slaby 	return 0;
112585cdaf52SJiri Slaby }
112685cdaf52SJiri Slaby 
112785cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field,
112885cdaf52SJiri Slaby 		struct hid_usage *usage, __s32 value, int interrupt)
112985cdaf52SJiri Slaby {
113085cdaf52SJiri Slaby 	struct hid_driver *hdrv = hid->driver;
113185cdaf52SJiri Slaby 	int ret;
113285cdaf52SJiri Slaby 
11339bfc8da0SHenrik Rydberg 	if (!list_empty(&hid->debug_list))
1134cd667ce2SJiri Kosina 		hid_dump_input(hid, usage, value);
113585cdaf52SJiri Slaby 
113685cdaf52SJiri Slaby 	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
113785cdaf52SJiri Slaby 		ret = hdrv->event(hid, field, usage, value);
113885cdaf52SJiri Slaby 		if (ret != 0) {
113985cdaf52SJiri Slaby 			if (ret < 0)
11408c3d52fcSJiri Kosina 				hid_err(hid, "%s's event failed with %d\n",
114185cdaf52SJiri Slaby 						hdrv->name, ret);
114285cdaf52SJiri Slaby 			return;
114385cdaf52SJiri Slaby 		}
114485cdaf52SJiri Slaby 	}
114585cdaf52SJiri Slaby 
1146dde5845aSJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1147dde5845aSJiri Kosina 		hidinput_hid_event(hid, field, usage, value);
1148aa938f79SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
1149aa938f79SJiri Kosina 		hid->hiddev_hid_event(hid, field, usage, value);
1150dde5845aSJiri Kosina }
1151dde5845aSJiri Kosina 
1152dde5845aSJiri Kosina /*
1153dde5845aSJiri Kosina  * Analyse a received field, and fetch the data from it. The field
1154dde5845aSJiri Kosina  * content is stored for next report processing (we do differential
1155dde5845aSJiri Kosina  * reporting to the layer).
1156dde5845aSJiri Kosina  */
1157dde5845aSJiri Kosina 
1158abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field,
1159abdff0f7SAdrian Bunk 			    __u8 *data, int interrupt)
1160dde5845aSJiri Kosina {
1161dde5845aSJiri Kosina 	unsigned n;
1162dde5845aSJiri Kosina 	unsigned count = field->report_count;
1163dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
1164dde5845aSJiri Kosina 	unsigned size = field->report_size;
1165dde5845aSJiri Kosina 	__s32 min = field->logical_minimum;
1166dde5845aSJiri Kosina 	__s32 max = field->logical_maximum;
1167dde5845aSJiri Kosina 	__s32 *value;
1168dde5845aSJiri Kosina 
1169a3789a17SJoe Perches 	value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
1170a3789a17SJoe Perches 	if (!value)
1171dde5845aSJiri Kosina 		return;
1172dde5845aSJiri Kosina 
1173dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1174dde5845aSJiri Kosina 
11754291ee30SJoe Perches 		value[n] = min < 0 ?
11764291ee30SJoe Perches 			snto32(extract(hid, data, offset + n * size, size),
11774291ee30SJoe Perches 			       size) :
11784291ee30SJoe Perches 			extract(hid, data, offset + n * size, size);
1179dde5845aSJiri Kosina 
11804291ee30SJoe Perches 		/* Ignore report if ErrorRollOver */
11814291ee30SJoe Perches 		if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
11824291ee30SJoe Perches 		    value[n] >= min && value[n] <= max &&
11834291ee30SJoe Perches 		    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
1184dde5845aSJiri Kosina 			goto exit;
1185dde5845aSJiri Kosina 	}
1186dde5845aSJiri Kosina 
1187dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1188dde5845aSJiri Kosina 
1189dde5845aSJiri Kosina 		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
1190dde5845aSJiri Kosina 			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
1191dde5845aSJiri Kosina 			continue;
1192dde5845aSJiri Kosina 		}
1193dde5845aSJiri Kosina 
1194dde5845aSJiri Kosina 		if (field->value[n] >= min && field->value[n] <= max
1195dde5845aSJiri Kosina 			&& field->usage[field->value[n] - min].hid
1196dde5845aSJiri Kosina 			&& search(value, field->value[n], count))
1197dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
1198dde5845aSJiri Kosina 
1199dde5845aSJiri Kosina 		if (value[n] >= min && value[n] <= max
1200dde5845aSJiri Kosina 			&& field->usage[value[n] - min].hid
1201dde5845aSJiri Kosina 			&& search(field->value, value[n], count))
1202dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
1203dde5845aSJiri Kosina 	}
1204dde5845aSJiri Kosina 
1205dde5845aSJiri Kosina 	memcpy(field->value, value, count * sizeof(__s32));
1206dde5845aSJiri Kosina exit:
1207dde5845aSJiri Kosina 	kfree(value);
1208dde5845aSJiri Kosina }
1209dde5845aSJiri Kosina 
1210dde5845aSJiri Kosina /*
1211dde5845aSJiri Kosina  * Output the field into the report.
1212dde5845aSJiri Kosina  */
1213dde5845aSJiri Kosina 
12144291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid,
12154291ee30SJoe Perches 			     struct hid_field *field, __u8 *data)
1216dde5845aSJiri Kosina {
1217dde5845aSJiri Kosina 	unsigned count = field->report_count;
1218dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
1219dde5845aSJiri Kosina 	unsigned size = field->report_size;
1220dde5845aSJiri Kosina 	unsigned n;
1221dde5845aSJiri Kosina 
1222dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1223dde5845aSJiri Kosina 		if (field->logical_minimum < 0)	/* signed values */
12244291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
12254291ee30SJoe Perches 				  s32ton(field->value[n], size));
1226dde5845aSJiri Kosina 		else				/* unsigned values */
12274291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
12284291ee30SJoe Perches 				  field->value[n]);
1229dde5845aSJiri Kosina 	}
1230dde5845aSJiri Kosina }
1231dde5845aSJiri Kosina 
1232dde5845aSJiri Kosina /*
123327ce4050SJiri Kosina  * Create a report. 'data' has to be allocated using
123427ce4050SJiri Kosina  * hid_alloc_report_buf() so that it has proper size.
1235dde5845aSJiri Kosina  */
1236dde5845aSJiri Kosina 
1237229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data)
1238dde5845aSJiri Kosina {
1239dde5845aSJiri Kosina 	unsigned n;
1240dde5845aSJiri Kosina 
1241dde5845aSJiri Kosina 	if (report->id > 0)
1242dde5845aSJiri Kosina 		*data++ = report->id;
1243dde5845aSJiri Kosina 
124475c28df8SPete Zaitcev 	memset(data, 0, ((report->size - 1) >> 3) + 1);
1245dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
12464291ee30SJoe Perches 		hid_output_field(report->device, report->field[n], data);
1247dde5845aSJiri Kosina }
1248229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report);
1249dde5845aSJiri Kosina 
1250dde5845aSJiri Kosina /*
125127ce4050SJiri Kosina  * Allocator for buffer that is going to be passed to hid_output_report()
125227ce4050SJiri Kosina  */
125327ce4050SJiri Kosina u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
125427ce4050SJiri Kosina {
125527ce4050SJiri Kosina 	/*
125627ce4050SJiri Kosina 	 * 7 extra bytes are necessary to achieve proper functionality
125727ce4050SJiri Kosina 	 * of implement() working on 8 byte chunks
125827ce4050SJiri Kosina 	 */
125927ce4050SJiri Kosina 
126027ce4050SJiri Kosina 	int len = ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7;
126127ce4050SJiri Kosina 
126227ce4050SJiri Kosina 	return kmalloc(len, flags);
126327ce4050SJiri Kosina }
126427ce4050SJiri Kosina EXPORT_SYMBOL_GPL(hid_alloc_report_buf);
126527ce4050SJiri Kosina 
126627ce4050SJiri Kosina /*
1267dde5845aSJiri Kosina  * Set a field value. The report this field belongs to has to be
1268dde5845aSJiri Kosina  * created and transferred to the device, to set this value in the
1269dde5845aSJiri Kosina  * device.
1270dde5845aSJiri Kosina  */
1271dde5845aSJiri Kosina 
1272dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1273dde5845aSJiri Kosina {
1274be67b68dSKees Cook 	unsigned size;
1275be67b68dSKees Cook 
1276be67b68dSKees Cook 	if (!field)
1277be67b68dSKees Cook 		return -1;
1278be67b68dSKees Cook 
1279be67b68dSKees Cook 	size = field->report_size;
1280dde5845aSJiri Kosina 
1281cd667ce2SJiri Kosina 	hid_dump_input(field->report->device, field->usage + offset, value);
1282dde5845aSJiri Kosina 
1283dde5845aSJiri Kosina 	if (offset >= field->report_count) {
12848c3d52fcSJiri Kosina 		hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
12858c3d52fcSJiri Kosina 				offset, field->report_count);
1286dde5845aSJiri Kosina 		return -1;
1287dde5845aSJiri Kosina 	}
1288dde5845aSJiri Kosina 	if (field->logical_minimum < 0) {
1289dde5845aSJiri Kosina 		if (value != snto32(s32ton(value, size), size)) {
12908c3d52fcSJiri Kosina 			hid_err(field->report->device, "value %d is out of range\n", value);
1291dde5845aSJiri Kosina 			return -1;
1292dde5845aSJiri Kosina 		}
1293dde5845aSJiri Kosina 	}
1294dde5845aSJiri Kosina 	field->value[offset] = value;
1295dde5845aSJiri Kosina 	return 0;
1296dde5845aSJiri Kosina }
1297229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field);
1298dde5845aSJiri Kosina 
129985cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
130085cdaf52SJiri Slaby 		const u8 *data)
130185cdaf52SJiri Slaby {
130285cdaf52SJiri Slaby 	struct hid_report *report;
130385cdaf52SJiri Slaby 	unsigned int n = 0;	/* Normally report number is 0 */
130485cdaf52SJiri Slaby 
130585cdaf52SJiri Slaby 	/* Device uses numbered reports, data[0] is report number */
130685cdaf52SJiri Slaby 	if (report_enum->numbered)
130785cdaf52SJiri Slaby 		n = *data;
130885cdaf52SJiri Slaby 
130985cdaf52SJiri Slaby 	report = report_enum->report_id_hash[n];
131085cdaf52SJiri Slaby 	if (report == NULL)
131185cdaf52SJiri Slaby 		dbg_hid("undefined report_id %u received\n", n);
131285cdaf52SJiri Slaby 
131385cdaf52SJiri Slaby 	return report;
131485cdaf52SJiri Slaby }
131585cdaf52SJiri Slaby 
1316b6787242SJiri Kosina int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
131785cdaf52SJiri Slaby 		int interrupt)
1318aa8de2f0SJiri Kosina {
1319aa8de2f0SJiri Kosina 	struct hid_report_enum *report_enum = hid->report_enum + type;
1320aa8de2f0SJiri Kosina 	struct hid_report *report;
13216d85d037SBenjamin Tissoires 	struct hid_driver *hdrv;
132285cdaf52SJiri Slaby 	unsigned int a;
132385cdaf52SJiri Slaby 	int rsize, csize = size;
132485cdaf52SJiri Slaby 	u8 *cdata = data;
1325b6787242SJiri Kosina 	int ret = 0;
1326aa8de2f0SJiri Kosina 
132785cdaf52SJiri Slaby 	report = hid_get_report(report_enum, data);
132885cdaf52SJiri Slaby 	if (!report)
1329b6787242SJiri Kosina 		goto out;
1330aa8de2f0SJiri Kosina 
133185cdaf52SJiri Slaby 	if (report_enum->numbered) {
133285cdaf52SJiri Slaby 		cdata++;
133385cdaf52SJiri Slaby 		csize--;
1334aa8de2f0SJiri Kosina 	}
1335aa8de2f0SJiri Kosina 
1336aa8de2f0SJiri Kosina 	rsize = ((report->size - 1) >> 3) + 1;
1337aa8de2f0SJiri Kosina 
1338966922f2SArmando Visconti 	if (rsize > HID_MAX_BUFFER_SIZE)
1339966922f2SArmando Visconti 		rsize = HID_MAX_BUFFER_SIZE;
1340966922f2SArmando Visconti 
134185cdaf52SJiri Slaby 	if (csize < rsize) {
134285cdaf52SJiri Slaby 		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
134385cdaf52SJiri Slaby 				csize, rsize);
134485cdaf52SJiri Slaby 		memset(cdata + csize, 0, rsize - csize);
1345aa8de2f0SJiri Kosina 	}
1346aa8de2f0SJiri Kosina 
1347aa8de2f0SJiri Kosina 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1348aa8de2f0SJiri Kosina 		hid->hiddev_report_event(hid, report);
1349b6787242SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDRAW) {
1350b6787242SJiri Kosina 		ret = hidraw_report_event(hid, data, size);
1351b6787242SJiri Kosina 		if (ret)
1352b6787242SJiri Kosina 			goto out;
1353b6787242SJiri Kosina 	}
1354aa8de2f0SJiri Kosina 
1355*cc6b54aaSBenjamin Tissoires 	if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) {
135685cdaf52SJiri Slaby 		for (a = 0; a < report->maxfield; a++)
135785cdaf52SJiri Slaby 			hid_input_field(hid, report->field[a], cdata, interrupt);
13586d85d037SBenjamin Tissoires 		hdrv = hid->driver;
13596d85d037SBenjamin Tissoires 		if (hdrv && hdrv->report)
13606d85d037SBenjamin Tissoires 			hdrv->report(hid, report);
1361b94e3c94SMatthieu CASTET 	}
1362aa8de2f0SJiri Kosina 
1363aa8de2f0SJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1364aa8de2f0SJiri Kosina 		hidinput_report_event(hid, report);
1365b6787242SJiri Kosina out:
1366b6787242SJiri Kosina 	return ret;
136785cdaf52SJiri Slaby }
136885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event);
136985cdaf52SJiri Slaby 
137085cdaf52SJiri Slaby /**
137185cdaf52SJiri Slaby  * hid_input_report - report data from lower layer (usb, bt...)
137285cdaf52SJiri Slaby  *
137385cdaf52SJiri Slaby  * @hid: hid device
137485cdaf52SJiri Slaby  * @type: HID report type (HID_*_REPORT)
137585cdaf52SJiri Slaby  * @data: report contents
137685cdaf52SJiri Slaby  * @size: size of data parameter
1377ff9b00a2SJiri Kosina  * @interrupt: distinguish between interrupt and control transfers
137885cdaf52SJiri Slaby  *
137985cdaf52SJiri Slaby  * This is data entry for lower layers.
138085cdaf52SJiri Slaby  */
138185cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
138285cdaf52SJiri Slaby {
138376c317d6SJulia Lawall 	struct hid_report_enum *report_enum;
138476c317d6SJulia Lawall 	struct hid_driver *hdrv;
138585cdaf52SJiri Slaby 	struct hid_report *report;
138645dc1ac7SJiri Kosina 	int ret = 0;
138785cdaf52SJiri Slaby 
13884ea54542SDavid Herrmann 	if (!hid)
138985cdaf52SJiri Slaby 		return -ENODEV;
13904ea54542SDavid Herrmann 
1391c849a614SAndrew de los Reyes 	if (down_trylock(&hid->driver_input_lock))
13924ea54542SDavid Herrmann 		return -EBUSY;
13934ea54542SDavid Herrmann 
13944ea54542SDavid Herrmann 	if (!hid->driver) {
13954ea54542SDavid Herrmann 		ret = -ENODEV;
13964ea54542SDavid Herrmann 		goto unlock;
13974ea54542SDavid Herrmann 	}
139876c317d6SJulia Lawall 	report_enum = hid->report_enum + type;
139976c317d6SJulia Lawall 	hdrv = hid->driver;
140085cdaf52SJiri Slaby 
140185cdaf52SJiri Slaby 	if (!size) {
140285cdaf52SJiri Slaby 		dbg_hid("empty report\n");
14034ea54542SDavid Herrmann 		ret = -1;
14044ea54542SDavid Herrmann 		goto unlock;
140585cdaf52SJiri Slaby 	}
140685cdaf52SJiri Slaby 
1407b94e3c94SMatthieu CASTET 	/* Avoid unnecessary overhead if debugfs is disabled */
1408a5f04b9dSBenjamin Tissoires 	if (!list_empty(&hid->debug_list))
1409a5f04b9dSBenjamin Tissoires 		hid_dump_report(hid, type, data, size);
1410b94e3c94SMatthieu CASTET 
1411f77e347bSJiri Kosina 	report = hid_get_report(report_enum, data);
1412f77e347bSJiri Kosina 
14134ea54542SDavid Herrmann 	if (!report) {
14144ea54542SDavid Herrmann 		ret = -1;
14154ea54542SDavid Herrmann 		goto unlock;
14164ea54542SDavid Herrmann 	}
1417f77e347bSJiri Kosina 
141885cdaf52SJiri Slaby 	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
141985cdaf52SJiri Slaby 		ret = hdrv->raw_event(hid, report, data, size);
1420b1a1442aSJiri Kosina 		if (ret < 0) {
14214ea54542SDavid Herrmann 			ret = ret < 0 ? ret : 0;
14224ea54542SDavid Herrmann 			goto unlock;
14234ea54542SDavid Herrmann 		}
142485cdaf52SJiri Slaby 	}
142585cdaf52SJiri Slaby 
1426b6787242SJiri Kosina 	ret = hid_report_raw_event(hid, type, data, size, interrupt);
1427aa8de2f0SJiri Kosina 
14284ea54542SDavid Herrmann unlock:
1429c849a614SAndrew de los Reyes 	up(&hid->driver_input_lock);
143045dc1ac7SJiri Kosina 	return ret;
1431aa8de2f0SJiri Kosina }
1432aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report);
1433aa8de2f0SJiri Kosina 
14340f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev,
14350f37cd03SJiri Kosina 		const struct hid_device_id *id)
14360f37cd03SJiri Kosina {
14377431fb76SHenrik Rydberg 	return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
14384d53b801SHenrik Rydberg 		(id->group == HID_GROUP_ANY || id->group == hdev->group) &&
14390f37cd03SJiri Kosina 		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
14400f37cd03SJiri Kosina 		(id->product == HID_ANY_ID || id->product == hdev->product);
14410f37cd03SJiri Kosina }
14420f37cd03SJiri Kosina 
1443bbc21cfdSJeremy Fitzhardinge const struct hid_device_id *hid_match_id(struct hid_device *hdev,
14440f37cd03SJiri Kosina 		const struct hid_device_id *id)
14450f37cd03SJiri Kosina {
14460f37cd03SJiri Kosina 	for (; id->bus; id++)
14470f37cd03SJiri Kosina 		if (hid_match_one_id(hdev, id))
14480f37cd03SJiri Kosina 			return id;
14490f37cd03SJiri Kosina 
14500f37cd03SJiri Kosina 	return NULL;
14510f37cd03SJiri Kosina }
14520f37cd03SJiri Kosina 
14530f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = {
1454c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1455c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
14560f37cd03SJiri Kosina 	{ }
14570f37cd03SJiri Kosina };
14580f37cd03SJiri Kosina 
14590f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev)
14600f37cd03SJiri Kosina {
14610f37cd03SJiri Kosina 	return !!hid_match_id(hdev, hid_hiddev_list);
14620f37cd03SJiri Kosina }
14630f37cd03SJiri Kosina 
14646d3bfb74SAlan Ott 
14656d3bfb74SAlan Ott static ssize_t
14666d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj,
14676d3bfb74SAlan Ott 		struct bin_attribute *attr,
14686d3bfb74SAlan Ott 		char *buf, loff_t off, size_t count)
14696d3bfb74SAlan Ott {
14706d3bfb74SAlan Ott 	struct device *dev = container_of(kobj, struct device, kobj);
14716d3bfb74SAlan Ott 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
14726d3bfb74SAlan Ott 
14736d3bfb74SAlan Ott 	if (off >= hdev->rsize)
14746d3bfb74SAlan Ott 		return 0;
14756d3bfb74SAlan Ott 
14766d3bfb74SAlan Ott 	if (off + count > hdev->rsize)
14776d3bfb74SAlan Ott 		count = hdev->rsize - off;
14786d3bfb74SAlan Ott 
14796d3bfb74SAlan Ott 	memcpy(buf, hdev->rdesc + off, count);
14806d3bfb74SAlan Ott 
14816d3bfb74SAlan Ott 	return count;
14826d3bfb74SAlan Ott }
14836d3bfb74SAlan Ott 
14846d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = {
14856d3bfb74SAlan Ott 	.attr = { .name = "report_descriptor", .mode = 0444 },
14866d3bfb74SAlan Ott 	.read = read_report_descriptor,
14876d3bfb74SAlan Ott 	.size = HID_MAX_DESCRIPTOR_SIZE,
14886d3bfb74SAlan Ott };
14896d3bfb74SAlan Ott 
149093c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
149193c10132SJiri Slaby {
149293c10132SJiri Slaby 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
149393c10132SJiri Slaby 		"Joystick", "Gamepad", "Keyboard", "Keypad",
149493c10132SJiri Slaby 		"Multi-Axis Controller"
149593c10132SJiri Slaby 	};
149693c10132SJiri Slaby 	const char *type, *bus;
149793c10132SJiri Slaby 	char buf[64];
149893c10132SJiri Slaby 	unsigned int i;
149993c10132SJiri Slaby 	int len;
15006d3bfb74SAlan Ott 	int ret;
150193c10132SJiri Slaby 
1502b5e5a37eSBastien Nocera 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1503b5e5a37eSBastien Nocera 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
15043a343ee4SDaniel Mack 	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
15053a343ee4SDaniel Mack 		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
150693c10132SJiri Slaby 	if (hdev->bus != BUS_USB)
150793c10132SJiri Slaby 		connect_mask &= ~HID_CONNECT_HIDDEV;
15080f37cd03SJiri Kosina 	if (hid_hiddev(hdev))
15090f37cd03SJiri Kosina 		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
151093c10132SJiri Slaby 
151193c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
151293c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
151393c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_INPUT;
1514b77c3920SBenjamin Tissoires 
151593c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
151693c10132SJiri Slaby 			!hdev->hiddev_connect(hdev,
151793c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDDEV_FORCE))
151893c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDDEV;
151993c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
152093c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDRAW;
152193c10132SJiri Slaby 
15224bc19f62SDavid Herrmann 	/* Drivers with the ->raw_event callback set are not required to connect
15234bc19f62SDavid Herrmann 	 * to any other listener. */
15244bc19f62SDavid Herrmann 	if (!hdev->claimed && !hdev->driver->raw_event) {
15254bc19f62SDavid Herrmann 		hid_err(hdev, "device has no listeners, quitting\n");
152693c10132SJiri Slaby 		return -ENODEV;
152793c10132SJiri Slaby 	}
152893c10132SJiri Slaby 
152993c10132SJiri Slaby 	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
153093c10132SJiri Slaby 			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
153193c10132SJiri Slaby 		hdev->ff_init(hdev);
153293c10132SJiri Slaby 
153393c10132SJiri Slaby 	len = 0;
153493c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_INPUT)
153593c10132SJiri Slaby 		len += sprintf(buf + len, "input");
153693c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
153793c10132SJiri Slaby 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
153893c10132SJiri Slaby 				hdev->minor);
153993c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
154093c10132SJiri Slaby 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
154193c10132SJiri Slaby 				((struct hidraw *)hdev->hidraw)->minor);
154293c10132SJiri Slaby 
154393c10132SJiri Slaby 	type = "Device";
154493c10132SJiri Slaby 	for (i = 0; i < hdev->maxcollection; i++) {
154593c10132SJiri Slaby 		struct hid_collection *col = &hdev->collection[i];
154693c10132SJiri Slaby 		if (col->type == HID_COLLECTION_APPLICATION &&
154793c10132SJiri Slaby 		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
154893c10132SJiri Slaby 		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
154993c10132SJiri Slaby 			type = types[col->usage & 0xffff];
155093c10132SJiri Slaby 			break;
155193c10132SJiri Slaby 		}
155293c10132SJiri Slaby 	}
155393c10132SJiri Slaby 
155493c10132SJiri Slaby 	switch (hdev->bus) {
155593c10132SJiri Slaby 	case BUS_USB:
155693c10132SJiri Slaby 		bus = "USB";
155793c10132SJiri Slaby 		break;
155893c10132SJiri Slaby 	case BUS_BLUETOOTH:
155993c10132SJiri Slaby 		bus = "BLUETOOTH";
156093c10132SJiri Slaby 		break;
156193c10132SJiri Slaby 	default:
156293c10132SJiri Slaby 		bus = "<UNKNOWN>";
156393c10132SJiri Slaby 	}
156493c10132SJiri Slaby 
15656d3bfb74SAlan Ott 	ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
15666d3bfb74SAlan Ott 	if (ret)
15676d3bfb74SAlan Ott 		hid_warn(hdev,
15686d3bfb74SAlan Ott 			 "can't create sysfs report descriptor attribute err: %d\n", ret);
15696d3bfb74SAlan Ott 
15704291ee30SJoe Perches 	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
157193c10132SJiri Slaby 		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
157293c10132SJiri Slaby 		 type, hdev->name, hdev->phys);
157393c10132SJiri Slaby 
157493c10132SJiri Slaby 	return 0;
157593c10132SJiri Slaby }
157693c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect);
157793c10132SJiri Slaby 
1578c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev)
1579c4c259bcSJiri Kosina {
15806d3bfb74SAlan Ott 	device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1581c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_INPUT)
1582c4c259bcSJiri Kosina 		hidinput_disconnect(hdev);
1583c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1584c4c259bcSJiri Kosina 		hdev->hiddev_disconnect(hdev);
1585c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1586c4c259bcSJiri Kosina 		hidraw_disconnect(hdev);
1587c4c259bcSJiri Kosina }
1588c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect);
1589c4c259bcSJiri Kosina 
159000315e4fSJiri Kosina /*
159100315e4fSJiri Kosina  * A list of devices for which there is a specialized driver on HID bus.
159200315e4fSJiri Kosina  *
159300315e4fSJiri Kosina  * Please note that for multitouch devices (driven by hid-multitouch driver),
159400315e4fSJiri Kosina  * there is a proper autodetection and autoloading in place (based on presence
159500315e4fSJiri Kosina  * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
159600315e4fSJiri Kosina  * as we are doing the right thing in hid_scan_usage().
159783499b52SAlexander Holler  *
159883499b52SAlexander Holler  * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
159983499b52SAlexander Holler  * physical is found inside a usage page of type sensor, hid-sensor-hub will be
160083499b52SAlexander Holler  * used as a driver. See hid_scan_report().
160100315e4fSJiri Kosina  */
1602ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = {
160314a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
160414a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1605b7e1b203SLech Perczak 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1606c0dbcc33SSergei Kolzun 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
16078c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1608128537ceSMichael Poole 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1609a462230eSChase Douglas 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
16108c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
16118c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
16128c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
16138c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
16148c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
16158c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
16168c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
16178c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
16188c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
16198c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
16208c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1621fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1622fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1623fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
16248c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
16258c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
16268c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
16278c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
16288c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
16298c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
16309a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
16319a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
16329a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
16339a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
16349a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
1635ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1636ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1637ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
16388c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
16398c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
16408c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
16418c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
16428c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
16438c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1644a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1645a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1646a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
164799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
164899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
164999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
165099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
165199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
165299b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
165347340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
165447340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
165547340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1656213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1657213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1658213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
16594a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
16604a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
16614a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
1662f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1663f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1664f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
1665d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
1666d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
1667d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
1668b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
1669b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
1670b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
16718d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
16728d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
16738d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
16749d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
16759d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
16769d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
167723aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
167823aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
167923aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1680f9af7b9eSBen Hutchings 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
1681ad734bc1SAndreas Krist 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
16828c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
16838c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1684212da74dSJosenivaldo Benito Junior 	{ HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
1685b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1686bf280628SWayne Thomas 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1687c3dc66deSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
16883b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
16891ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1690fcfacfd3SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1691b9e4b1e0SDennis Kügler 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
16923596bb92SKeng-Yu Lin 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
16932d8767bbSCyrus Lien 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
16943a370ca1SDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
16950f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
16960f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1697e8d0eab4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
169876c9d8feSLionel Vaux 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
16990f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
17003f866fbdSRichard Walmsley 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1701e05eefb9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
170264b386eaSRichard Nauber 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1703d23efc19SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
1704d23efc19SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
170504561c5aSIgnaz Forster 	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
17061f243e30SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
17075181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1708578f3a35SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
17095181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
171042859e0bSLukasz Lubojanski 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1711949f8fefSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
17121e093206SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1713c2fd1a4eSCory Maccarrone 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1714d946e65eSAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
1715ff9bf5a2STom Harwood 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
171640d3597fSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
171740d3597fSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
171868e353feSMartin Rusko 	{ HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_580) },
1719aaca9cc0SMichael Karcher 	{ HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
17204ddfe028SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
1721fdf93aa3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1722177900e8SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
17233685c18eSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
17240adb9c2cSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
172579422741SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
172622ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
172722ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
172822ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
1729b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
173075b07022SChris Schlund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
1731aad932e7SAndres Freund #if IS_ENABLED(CONFIG_HID_LENOVO_TPKBD)
1732c1dcad2dSBernhard Seibold 	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
1733aad932e7SAndres Freund #endif
17345f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
17355f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
17365f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
17375f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
17385844c1cdSDavid Dillow 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
17395f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
17405f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
17415f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
17425f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
17435f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
17445f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
17455f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
17462c6118e4SHendrik Iben 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1747606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1748606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1749606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1750fd30ea8cSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1751606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
175274f292caSGary Stein 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1753606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1754606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
17555623a24aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1756e00ddc9bSMichal Malý 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
1757243b706dSChristophe Borivant 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1758fdc6807fSPeter Gundermann 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
17590944e964SKonstantin Khlebnikov #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
1760534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
1761534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
17620944e964SKonstantin Khlebnikov #endif
176332c88cbcSSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1764606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
176524985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
176624985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1767236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1768236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
1769b580169aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
177078a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
177178a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
177289759e20SAdam Jiang 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
177378a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
177478a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1775f3b83d71SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
177678a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
17773b8006e5SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
177894011f93SRafi Rubin 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
17796e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
17806e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
17816e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
17826e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
17836e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
17846e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
17856e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
17866e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
17876e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
17886e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
17896e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
17906e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
17916e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
17926e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
17936e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
17946e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
17956e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
17966e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1797270fdc07SHerton Ronaldo Krzesinski 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1798cd9ec30dSJohnathon Harris 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
17991e762532SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1800f6a04605STerry Lambert 	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
1801ca9bbdccSStefan Achatz #if IS_ENABLED(CONFIG_HID_ROCCAT)
180214bf62cdSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1803e68cc603SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1804d41c2a70SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
180547dbdbffSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
18068936aa31SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
1807a4be0ed3SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
18080e70f97fSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
18094424f616SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
1810cb7cf3daSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
18113fce2246SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
18126a2a6390SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
1813ca9bbdccSStefan Achatz #endif
18141e93674aSAndreas Hübner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
1815980a3da6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1816b355850bSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1817d586dca0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1818f04d5140SColin Leitner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
1819f04d5140SColin Leitner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
18205844c1cdSDavid Dillow 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
1821bd28ce00SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
182235dca5b4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1823f9ce7c28SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1824cc6e0bbbSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1825c1e0ac19SFernando Luis Vázquez Cao 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
182675dbb953SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
182790231e7eSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
182830ba2fbdSVivien Didelot 	{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
1829daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1830daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
18317a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
18327a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1833daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
18343ee8f0a2SMarkus Rathgeb 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1835daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1836d65c3768SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1837740363fbSJiri Kosina 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
183844ea35c1SJarod Wilson 	{ HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
1839f14f526dSLev Babiev 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
184054001081SKees Bakker 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1841711a680eSBruno Premont 	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
184241fa9230SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1843f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1844f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1845f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
18466be914f1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1847d1257081SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
1848eb4e426aSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
1849fac733f0SJussi Kivilinna 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
185042fc04e5SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
1851ad395ccaSSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
18521bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
18531bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
18541bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
1855ca2dcd40SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
185678761ff9SPrzemo Firszt 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
185772a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
185800e7f964SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
18594fdc18d1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
1860a786e83cSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
186172a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
18628f1acc32SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1863d2ee4dd9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
186474bc6953SStefan Kriwanek 	{ HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1865cb2c9e3fSOlivier Scherler 	{ HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
1866daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1867daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1868a9885c8fSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
18698c19a515SJiri Slaby 
187078a849a6SJiri Slaby 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
187102fb72a0SDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1872a33042faSDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
187385cdaf52SJiri Slaby 	{ }
187485cdaf52SJiri Slaby };
187585cdaf52SJiri Slaby 
18763a6f82f7SJiri Slaby struct hid_dynid {
18773a6f82f7SJiri Slaby 	struct list_head list;
18783a6f82f7SJiri Slaby 	struct hid_device_id id;
18793a6f82f7SJiri Slaby };
18803a6f82f7SJiri Slaby 
18813a6f82f7SJiri Slaby /**
18823a6f82f7SJiri Slaby  * store_new_id - add a new HID device ID to this driver and re-probe devices
18833a6f82f7SJiri Slaby  * @driver: target device driver
18843a6f82f7SJiri Slaby  * @buf: buffer for scanning device ID data
18853a6f82f7SJiri Slaby  * @count: input size
18863a6f82f7SJiri Slaby  *
18873a6f82f7SJiri Slaby  * Adds a new dynamic hid device ID to this driver,
18883a6f82f7SJiri Slaby  * and causes the driver to probe for all devices again.
18893a6f82f7SJiri Slaby  */
18903a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf,
18913a6f82f7SJiri Slaby 		size_t count)
18923a6f82f7SJiri Slaby {
18933a6f82f7SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
18943a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
18953a6f82f7SJiri Slaby 	__u32 bus, vendor, product;
18963a6f82f7SJiri Slaby 	unsigned long driver_data = 0;
18973a6f82f7SJiri Slaby 	int ret;
18983a6f82f7SJiri Slaby 
18993a6f82f7SJiri Slaby 	ret = sscanf(buf, "%x %x %x %lx",
19003a6f82f7SJiri Slaby 			&bus, &vendor, &product, &driver_data);
19013a6f82f7SJiri Slaby 	if (ret < 3)
19023a6f82f7SJiri Slaby 		return -EINVAL;
19033a6f82f7SJiri Slaby 
19043a6f82f7SJiri Slaby 	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
19053a6f82f7SJiri Slaby 	if (!dynid)
19063a6f82f7SJiri Slaby 		return -ENOMEM;
19073a6f82f7SJiri Slaby 
19083a6f82f7SJiri Slaby 	dynid->id.bus = bus;
19094d53b801SHenrik Rydberg 	dynid->id.group = HID_GROUP_ANY;
19103a6f82f7SJiri Slaby 	dynid->id.vendor = vendor;
19113a6f82f7SJiri Slaby 	dynid->id.product = product;
19123a6f82f7SJiri Slaby 	dynid->id.driver_data = driver_data;
19133a6f82f7SJiri Slaby 
19143a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
19153a6f82f7SJiri Slaby 	list_add_tail(&dynid->list, &hdrv->dyn_list);
19163a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
19173a6f82f7SJiri Slaby 
19183a6f82f7SJiri Slaby 	ret = driver_attach(&hdrv->driver);
19193a6f82f7SJiri Slaby 
19203a6f82f7SJiri Slaby 	return ret ? : count;
19213a6f82f7SJiri Slaby }
19223a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
19233a6f82f7SJiri Slaby 
19243a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv)
19253a6f82f7SJiri Slaby {
19263a6f82f7SJiri Slaby 	struct hid_dynid *dynid, *n;
19273a6f82f7SJiri Slaby 
19283a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
19293a6f82f7SJiri Slaby 	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
19303a6f82f7SJiri Slaby 		list_del(&dynid->list);
19313a6f82f7SJiri Slaby 		kfree(dynid);
19323a6f82f7SJiri Slaby 	}
19333a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
19343a6f82f7SJiri Slaby }
19353a6f82f7SJiri Slaby 
19363a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
19373a6f82f7SJiri Slaby 		struct hid_driver *hdrv)
19383a6f82f7SJiri Slaby {
19393a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
19403a6f82f7SJiri Slaby 
19413a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
19423a6f82f7SJiri Slaby 	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
19433a6f82f7SJiri Slaby 		if (hid_match_one_id(hdev, &dynid->id)) {
19443a6f82f7SJiri Slaby 			spin_unlock(&hdrv->dyn_lock);
19453a6f82f7SJiri Slaby 			return &dynid->id;
19463a6f82f7SJiri Slaby 		}
19473a6f82f7SJiri Slaby 	}
19483a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
19493a6f82f7SJiri Slaby 
19503a6f82f7SJiri Slaby 	return hid_match_id(hdev, hdrv->id_table);
19513a6f82f7SJiri Slaby }
19523a6f82f7SJiri Slaby 
195385cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv)
195485cdaf52SJiri Slaby {
195585cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
195685cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
195785cdaf52SJiri Slaby 
1958070748edSHenrik Rydberg 	return hid_match_device(hdev, hdrv) != NULL;
195985cdaf52SJiri Slaby }
196085cdaf52SJiri Slaby 
196185cdaf52SJiri Slaby static int hid_device_probe(struct device *dev)
196285cdaf52SJiri Slaby {
196385cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(dev->driver,
196485cdaf52SJiri Slaby 			struct hid_driver, driver);
196585cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
196685cdaf52SJiri Slaby 	const struct hid_device_id *id;
196785cdaf52SJiri Slaby 	int ret = 0;
196885cdaf52SJiri Slaby 
19694ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
19704ea54542SDavid Herrmann 		return -EINTR;
1971c849a614SAndrew de los Reyes 	if (down_interruptible(&hdev->driver_input_lock)) {
1972c849a614SAndrew de los Reyes 		ret = -EINTR;
1973c849a614SAndrew de los Reyes 		goto unlock_driver_lock;
1974c849a614SAndrew de los Reyes 	}
1975c849a614SAndrew de los Reyes 	hdev->io_started = false;
19764ea54542SDavid Herrmann 
197785cdaf52SJiri Slaby 	if (!hdev->driver) {
19783a6f82f7SJiri Slaby 		id = hid_match_device(hdev, hdrv);
1979ba623a77SDan Carpenter 		if (id == NULL) {
1980ba623a77SDan Carpenter 			ret = -ENODEV;
1981ba623a77SDan Carpenter 			goto unlock;
1982ba623a77SDan Carpenter 		}
1983c500c971SJiri Slaby 
198485cdaf52SJiri Slaby 		hdev->driver = hdrv;
1985c500c971SJiri Slaby 		if (hdrv->probe) {
1986c500c971SJiri Slaby 			ret = hdrv->probe(hdev, id);
1987c500c971SJiri Slaby 		} else { /* default probe */
1988a7197c2eSHenrik Rydberg 			ret = hid_open_report(hdev);
1989c500c971SJiri Slaby 			if (!ret)
199093c10132SJiri Slaby 				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1991c500c971SJiri Slaby 		}
1992a7197c2eSHenrik Rydberg 		if (ret) {
1993a7197c2eSHenrik Rydberg 			hid_close_report(hdev);
1994c500c971SJiri Slaby 			hdev->driver = NULL;
199585cdaf52SJiri Slaby 		}
1996a7197c2eSHenrik Rydberg 	}
1997ba623a77SDan Carpenter unlock:
1998c849a614SAndrew de los Reyes 	if (!hdev->io_started)
1999c849a614SAndrew de los Reyes 		up(&hdev->driver_input_lock);
2000c849a614SAndrew de los Reyes unlock_driver_lock:
20014ea54542SDavid Herrmann 	up(&hdev->driver_lock);
200285cdaf52SJiri Slaby 	return ret;
200385cdaf52SJiri Slaby }
200485cdaf52SJiri Slaby 
200585cdaf52SJiri Slaby static int hid_device_remove(struct device *dev)
200685cdaf52SJiri Slaby {
200785cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
20084ea54542SDavid Herrmann 	struct hid_driver *hdrv;
2009c849a614SAndrew de los Reyes 	int ret = 0;
201085cdaf52SJiri Slaby 
20114ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
20124ea54542SDavid Herrmann 		return -EINTR;
2013c849a614SAndrew de los Reyes 	if (down_interruptible(&hdev->driver_input_lock)) {
2014c849a614SAndrew de los Reyes 		ret = -EINTR;
2015c849a614SAndrew de los Reyes 		goto unlock_driver_lock;
2016c849a614SAndrew de los Reyes 	}
2017c849a614SAndrew de los Reyes 	hdev->io_started = false;
20184ea54542SDavid Herrmann 
20194ea54542SDavid Herrmann 	hdrv = hdev->driver;
202085cdaf52SJiri Slaby 	if (hdrv) {
202185cdaf52SJiri Slaby 		if (hdrv->remove)
202285cdaf52SJiri Slaby 			hdrv->remove(hdev);
2023c500c971SJiri Slaby 		else /* default remove */
2024c500c971SJiri Slaby 			hid_hw_stop(hdev);
2025a7197c2eSHenrik Rydberg 		hid_close_report(hdev);
202685cdaf52SJiri Slaby 		hdev->driver = NULL;
202785cdaf52SJiri Slaby 	}
202885cdaf52SJiri Slaby 
2029c849a614SAndrew de los Reyes 	if (!hdev->io_started)
2030c849a614SAndrew de los Reyes 		up(&hdev->driver_input_lock);
2031c849a614SAndrew de los Reyes unlock_driver_lock:
20324ea54542SDavid Herrmann 	up(&hdev->driver_lock);
2033c849a614SAndrew de los Reyes 	return ret;
203485cdaf52SJiri Slaby }
203585cdaf52SJiri Slaby 
20364d53b801SHenrik Rydberg static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
20374d53b801SHenrik Rydberg 			     char *buf)
20384d53b801SHenrik Rydberg {
20394d53b801SHenrik Rydberg 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
20404d53b801SHenrik Rydberg 	int len;
20414d53b801SHenrik Rydberg 
20424d53b801SHenrik Rydberg 	len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
20434d53b801SHenrik Rydberg 		       hdev->bus, hdev->group, hdev->vendor, hdev->product);
20444d53b801SHenrik Rydberg 
20454d53b801SHenrik Rydberg 	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
20464d53b801SHenrik Rydberg }
20470d4260e0SGreg Kroah-Hartman static DEVICE_ATTR_RO(modalias);
20484d53b801SHenrik Rydberg 
20490d4260e0SGreg Kroah-Hartman static struct attribute *hid_dev_attrs[] = {
20500d4260e0SGreg Kroah-Hartman 	&dev_attr_modalias.attr,
20510d4260e0SGreg Kroah-Hartman 	NULL,
20524d53b801SHenrik Rydberg };
20530d4260e0SGreg Kroah-Hartman ATTRIBUTE_GROUPS(hid_dev);
20544d53b801SHenrik Rydberg 
205585cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
205685cdaf52SJiri Slaby {
205785cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
205885cdaf52SJiri Slaby 
205985cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
206085cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
206185cdaf52SJiri Slaby 		return -ENOMEM;
206285cdaf52SJiri Slaby 
206385cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
206485cdaf52SJiri Slaby 		return -ENOMEM;
206585cdaf52SJiri Slaby 
206685cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
206785cdaf52SJiri Slaby 		return -ENOMEM;
206885cdaf52SJiri Slaby 
206985cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
207085cdaf52SJiri Slaby 		return -ENOMEM;
207185cdaf52SJiri Slaby 
20724d53b801SHenrik Rydberg 	if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
20734d53b801SHenrik Rydberg 			   hdev->bus, hdev->group, hdev->vendor, hdev->product))
207485cdaf52SJiri Slaby 		return -ENOMEM;
207585cdaf52SJiri Slaby 
207685cdaf52SJiri Slaby 	return 0;
207785cdaf52SJiri Slaby }
207885cdaf52SJiri Slaby 
207985cdaf52SJiri Slaby static struct bus_type hid_bus_type = {
208085cdaf52SJiri Slaby 	.name		= "hid",
20810d4260e0SGreg Kroah-Hartman 	.dev_groups	= hid_dev_groups,
208285cdaf52SJiri Slaby 	.match		= hid_bus_match,
208385cdaf52SJiri Slaby 	.probe		= hid_device_probe,
208485cdaf52SJiri Slaby 	.remove		= hid_device_remove,
208585cdaf52SJiri Slaby 	.uevent		= hid_uevent,
208685cdaf52SJiri Slaby };
208785cdaf52SJiri Slaby 
2088bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */
2089d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = {
2090d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
2091d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
2092d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
2093d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
2094d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
2095d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
2096d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
2097d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
2098d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
2099d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
2100d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
2101d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
210277f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
210377f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
210462a56582SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
210511030183SHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
2106d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
2107d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
2108d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
2109d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
2110d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
2111d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
21125f6108cfSAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
2113d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
2114d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
211573bc7d31SMelchior FRANZ 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
2116789aaa2eSDan Delaney 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
2117d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
211870c66567SPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
2119df506f2cSPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
2120b1807719SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
2121d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
2122d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
2123d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
2124d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
2125d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
2126d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
2127d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
2128d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
2129d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
2130d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
2131d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
2132d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
2133d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
2134d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
2135d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
2136d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
21378e2ce73eSHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
2138d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
2139d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
2140d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
2141d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
2142d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
2143d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
2144d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
2145d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
2146d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
2147d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
2148d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
2149d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
2150d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
2151d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
2152d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
2153d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
2154d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
2155d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
2156d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
2157d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
2158d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
2159d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
2160d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
2161d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
2162d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
2163d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
2164d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
2165d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
2166d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
2167d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
2168d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
2169d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
2170d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
2171d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
2172d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
2173d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
2174d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
2175d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
2176d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
2177d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
2178d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
2179d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
2180d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
2181d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
2182d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
2183d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
2184d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
218531b9779cSVincent Palatin 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) },
218631b9779cSVincent Palatin 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) },
2187d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
2188c91c21c5SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
2189d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
2190eb8141ccSLamarque Vieira Souza 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
2191d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
2192ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
2193d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
2194ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
2195d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
2196ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
2197ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
2198ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
2199ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
2200ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
2201ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
2202d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
2203d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
2204d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
2205ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
2206ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
2207ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
2208d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
2209d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
2210ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
2211d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
2212d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
2213d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
2214d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
2215d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
2216ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
2217ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
2218ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
2219ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
2220ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
2221ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
2222ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
22233ffb62cbSYuri Khan 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
2224d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
2225d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
2226d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
2227d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
2228d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
2229d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
2230d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
2231d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
2232d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
2233d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
2234d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
2235d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
2236d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
2237d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
2238d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
2239d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
2240d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
2241d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
2242d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
22434cfae3e8SHenning Glawe 	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
224435cfd1d9SMichael Tokarev 	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
22458491ee10SJan Steinhoff #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
22468491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
22478491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
22488491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
22498491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
22508491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
22518491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
22528491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
22538491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
22548491ee10SJan Steinhoff #endif
2255d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
2256d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
2257d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
2258d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
2259d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
2260d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
2261d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
2262d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
2263d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
2264d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
2265d458a9dfSJiri Slaby 	{ }
2266d458a9dfSJiri Slaby };
2267d458a9dfSJiri Slaby 
2268b4d8e473SJiri Slaby /**
2269b4d8e473SJiri Slaby  * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
2270b4d8e473SJiri Slaby  *
2271b4d8e473SJiri Slaby  * There are composite devices for which we want to ignore only a certain
2272b4d8e473SJiri Slaby  * interface. This is a list of devices for which only the mouse interface will
2273b4d8e473SJiri Slaby  * be ignored. This allows a dedicated driver to take care of the interface.
2274b4d8e473SJiri Slaby  */
2275b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = {
2276b4d8e473SJiri Slaby 	/* appletouch driver */
2277b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
2278b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
2279b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
2280b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
2281b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
2282b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
2283b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
2284b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
2285b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
2286b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
2287b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
2288b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
2289b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
2290b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
2291b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
2292b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
2293b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
2294b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
2295b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
2296b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
2297ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
2298ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
2299ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
230099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
230199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
230299b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
230399b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
230499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
230599b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
230647340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
230747340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
230847340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
2309213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
2310213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
2311213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
23124b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
23134b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
23144b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
23154b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
23164b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
23174b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
2318b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
2319b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
2320b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
23218d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
23228d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
23238d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
23249d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) },
23259d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) },
23269d9a04eeSDmitry Torokhov 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) },
2327b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2328b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
2329b4d8e473SJiri Slaby 	{ }
2330b4d8e473SJiri Slaby };
2331b4d8e473SJiri Slaby 
23324529eefaSLamarque V. Souza bool hid_ignore(struct hid_device *hdev)
2333d458a9dfSJiri Slaby {
23344529eefaSLamarque V. Souza 	if (hdev->quirks & HID_QUIRK_NO_IGNORE)
23354529eefaSLamarque V. Souza 		return false;
23364529eefaSLamarque V. Souza 	if (hdev->quirks & HID_QUIRK_IGNORE)
23374529eefaSLamarque V. Souza 		return true;
23384529eefaSLamarque V. Souza 
2339d458a9dfSJiri Slaby 	switch (hdev->vendor) {
2340d458a9dfSJiri Slaby 	case USB_VENDOR_ID_CODEMERCS:
2341d458a9dfSJiri Slaby 		/* ignore all Code Mercenaries IOWarrior devices */
2342d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
2343d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
2344d458a9dfSJiri Slaby 			return true;
2345d458a9dfSJiri Slaby 		break;
2346d458a9dfSJiri Slaby 	case USB_VENDOR_ID_LOGITECH:
2347d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
2348d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
2349d458a9dfSJiri Slaby 			return true;
235065dd3b69SHans Verkuil 		/*
235165dd3b69SHans Verkuil 		 * The Keene FM transmitter USB device has the same USB ID as
235265dd3b69SHans Verkuil 		 * the Logitech AudioHub Speaker, but it should ignore the hid.
235365dd3b69SHans Verkuil 		 * Check if the name is that of the Keene device.
235465dd3b69SHans Verkuil 		 * For reference: the name of the AudioHub is
235565dd3b69SHans Verkuil 		 * "HOLTEK  AudioHub Speaker".
235665dd3b69SHans Verkuil 		 */
235765dd3b69SHans Verkuil 		if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
235865dd3b69SHans Verkuil 			!strcmp(hdev->name, "HOLTEK  B-LINK USB Audio  "))
235965dd3b69SHans Verkuil 				return true;
2360d458a9dfSJiri Slaby 		break;
236131f7fd79SJarod Wilson 	case USB_VENDOR_ID_SOUNDGRAPH:
236231f7fd79SJarod Wilson 		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
236331f7fd79SJarod Wilson 		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
236431f7fd79SJarod Wilson 			return true;
236531f7fd79SJarod Wilson 		break;
2366bba5394aSXing Wei 	case USB_VENDOR_ID_HANWANG:
2367bba5394aSXing Wei 		if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
2368bba5394aSXing Wei 		    hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
2369bba5394aSXing Wei 			return true;
2370bba5394aSXing Wei 		break;
23716dc1418eSTomoki Sekiyama 	case USB_VENDOR_ID_JESS:
23726dc1418eSTomoki Sekiyama 		if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
23736dc1418eSTomoki Sekiyama 				hdev->type == HID_TYPE_USBNONE)
23746dc1418eSTomoki Sekiyama 			return true;
23756dc1418eSTomoki Sekiyama 		break;
2376729b814aSForest Bond 	case USB_VENDOR_ID_DWAV:
2377729b814aSForest Bond 		/* These are handled by usbtouchscreen. hdev->type is probably
2378729b814aSForest Bond 		 * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match
2379729b814aSForest Bond 		 * usbtouchscreen. */
2380729b814aSForest Bond 		if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER ||
2381729b814aSForest Bond 		     hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) &&
2382729b814aSForest Bond 		    hdev->type != HID_TYPE_USBMOUSE)
2383729b814aSForest Bond 			return true;
2384729b814aSForest Bond 		break;
238530b6b7d8SIan Abbott 	case USB_VENDOR_ID_VELLEMAN:
238630b6b7d8SIan Abbott 		/* These are not HID devices.  They are handled by comedi. */
238730b6b7d8SIan Abbott 		if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
238830b6b7d8SIan Abbott 		     hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
238930b6b7d8SIan Abbott 		    (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
239030b6b7d8SIan Abbott 		     hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
239130b6b7d8SIan Abbott 			return true;
239230b6b7d8SIan Abbott 		break;
23935b4617d8SAlexey Klimov 	case USB_VENDOR_ID_ATMEL_V_USB:
23945b4617d8SAlexey Klimov 		/* Masterkit MA901 usb radio based on Atmel tiny85 chip and
23955b4617d8SAlexey Klimov 		 * it has the same USB ID as many Atmel V-USB devices. This
23965b4617d8SAlexey Klimov 		 * usb radio is handled by radio-ma901.c driver so we want
23975b4617d8SAlexey Klimov 		 * ignore the hid. Check the name, bus, product and ignore
23985b4617d8SAlexey Klimov 		 * if we have MA901 usb radio.
23995b4617d8SAlexey Klimov 		 */
24005b4617d8SAlexey Klimov 		if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
24015b4617d8SAlexey Klimov 			hdev->bus == BUS_USB &&
24025b4617d8SAlexey Klimov 			strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
24035b4617d8SAlexey Klimov 			return true;
24045b4617d8SAlexey Klimov 		break;
2405d458a9dfSJiri Slaby 	}
2406d458a9dfSJiri Slaby 
2407b4d8e473SJiri Slaby 	if (hdev->type == HID_TYPE_USBMOUSE &&
2408b4d8e473SJiri Slaby 			hid_match_id(hdev, hid_mouse_ignore_list))
2409b4d8e473SJiri Slaby 		return true;
2410b4d8e473SJiri Slaby 
2411d458a9dfSJiri Slaby 	return !!hid_match_id(hdev, hid_ignore_list);
2412d458a9dfSJiri Slaby }
24134529eefaSLamarque V. Souza EXPORT_SYMBOL_GPL(hid_ignore);
2414d458a9dfSJiri Slaby 
241585cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev)
241685cdaf52SJiri Slaby {
241785cdaf52SJiri Slaby 	static atomic_t id = ATOMIC_INIT(0);
241885cdaf52SJiri Slaby 	int ret;
241985cdaf52SJiri Slaby 
242085cdaf52SJiri Slaby 	if (WARN_ON(hdev->status & HID_STAT_ADDED))
242185cdaf52SJiri Slaby 		return -EBUSY;
242285cdaf52SJiri Slaby 
2423d458a9dfSJiri Slaby 	/* we need to kill them here, otherwise they will stay allocated to
2424d458a9dfSJiri Slaby 	 * wait for coming driver */
24254529eefaSLamarque V. Souza 	if (hid_ignore(hdev))
2426d458a9dfSJiri Slaby 		return -ENODEV;
2427d458a9dfSJiri Slaby 
2428a7197c2eSHenrik Rydberg 	/*
2429a7197c2eSHenrik Rydberg 	 * Read the device report descriptor once and use as template
2430a7197c2eSHenrik Rydberg 	 * for the driver-specific modifications.
2431a7197c2eSHenrik Rydberg 	 */
2432a7197c2eSHenrik Rydberg 	ret = hdev->ll_driver->parse(hdev);
2433a7197c2eSHenrik Rydberg 	if (ret)
2434a7197c2eSHenrik Rydberg 		return ret;
2435a7197c2eSHenrik Rydberg 	if (!hdev->dev_rdesc)
2436a7197c2eSHenrik Rydberg 		return -ENODEV;
2437a7197c2eSHenrik Rydberg 
2438734c6609SHenrik Rydberg 	/*
2439734c6609SHenrik Rydberg 	 * Scan generic devices for group information
2440734c6609SHenrik Rydberg 	 */
2441734c6609SHenrik Rydberg 	if (hid_ignore_special_drivers ||
2442734c6609SHenrik Rydberg 	    !hid_match_id(hdev, hid_have_special_driver)) {
2443734c6609SHenrik Rydberg 		ret = hid_scan_report(hdev);
2444734c6609SHenrik Rydberg 		if (ret)
2445734c6609SHenrik Rydberg 			hid_warn(hdev, "bad device descriptor (%d)\n", ret);
2446734c6609SHenrik Rydberg 	}
2447734c6609SHenrik Rydberg 
24486bbe586fSKay Sievers 	/* XXX hack, any other cleaner solution after the driver core
24496bbe586fSKay Sievers 	 * is converted to allow more than 20 bytes as the device name? */
24506bbe586fSKay Sievers 	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
245185cdaf52SJiri Slaby 		     hdev->vendor, hdev->product, atomic_inc_return(&id));
245285cdaf52SJiri Slaby 
24534da361b6SBruno Prémont 	hid_debug_register(hdev, dev_name(&hdev->dev));
245485cdaf52SJiri Slaby 	ret = device_add(&hdev->dev);
245585cdaf52SJiri Slaby 	if (!ret)
245685cdaf52SJiri Slaby 		hdev->status |= HID_STAT_ADDED;
24574da361b6SBruno Prémont 	else
24584da361b6SBruno Prémont 		hid_debug_unregister(hdev);
2459a635f9ddSJiri Kosina 
246085cdaf52SJiri Slaby 	return ret;
246185cdaf52SJiri Slaby }
246285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device);
246385cdaf52SJiri Slaby 
246485cdaf52SJiri Slaby /**
246585cdaf52SJiri Slaby  * hid_allocate_device - allocate new hid device descriptor
246685cdaf52SJiri Slaby  *
246785cdaf52SJiri Slaby  * Allocate and initialize hid device, so that hid_destroy_device might be
246885cdaf52SJiri Slaby  * used to free it.
246985cdaf52SJiri Slaby  *
247085cdaf52SJiri Slaby  * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
247185cdaf52SJiri Slaby  * error value.
247285cdaf52SJiri Slaby  */
247385cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void)
247485cdaf52SJiri Slaby {
247585cdaf52SJiri Slaby 	struct hid_device *hdev;
247685cdaf52SJiri Slaby 	int ret = -ENOMEM;
247785cdaf52SJiri Slaby 
247885cdaf52SJiri Slaby 	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
247985cdaf52SJiri Slaby 	if (hdev == NULL)
248085cdaf52SJiri Slaby 		return ERR_PTR(ret);
248185cdaf52SJiri Slaby 
248285cdaf52SJiri Slaby 	device_initialize(&hdev->dev);
248385cdaf52SJiri Slaby 	hdev->dev.release = hid_device_release;
248485cdaf52SJiri Slaby 	hdev->dev.bus = &hid_bus_type;
248585cdaf52SJiri Slaby 
2486a7197c2eSHenrik Rydberg 	hid_close_report(hdev);
248785cdaf52SJiri Slaby 
2488cd667ce2SJiri Kosina 	init_waitqueue_head(&hdev->debug_wait);
2489cd667ce2SJiri Kosina 	INIT_LIST_HEAD(&hdev->debug_list);
24901deb9d34SJiri Kosina 	spin_lock_init(&hdev->debug_list_lock);
24914ea54542SDavid Herrmann 	sema_init(&hdev->driver_lock, 1);
2492c849a614SAndrew de los Reyes 	sema_init(&hdev->driver_input_lock, 1);
2493cd667ce2SJiri Kosina 
249485cdaf52SJiri Slaby 	return hdev;
249585cdaf52SJiri Slaby }
249685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device);
249785cdaf52SJiri Slaby 
249885cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev)
249985cdaf52SJiri Slaby {
250085cdaf52SJiri Slaby 	if (hdev->status & HID_STAT_ADDED) {
250185cdaf52SJiri Slaby 		device_del(&hdev->dev);
2502a635f9ddSJiri Kosina 		hid_debug_unregister(hdev);
250385cdaf52SJiri Slaby 		hdev->status &= ~HID_STAT_ADDED;
250485cdaf52SJiri Slaby 	}
2505a7197c2eSHenrik Rydberg 	kfree(hdev->dev_rdesc);
2506a7197c2eSHenrik Rydberg 	hdev->dev_rdesc = NULL;
2507a7197c2eSHenrik Rydberg 	hdev->dev_rsize = 0;
250885cdaf52SJiri Slaby }
250985cdaf52SJiri Slaby 
251085cdaf52SJiri Slaby /**
251185cdaf52SJiri Slaby  * hid_destroy_device - free previously allocated device
251285cdaf52SJiri Slaby  *
251385cdaf52SJiri Slaby  * @hdev: hid device
251485cdaf52SJiri Slaby  *
251585cdaf52SJiri Slaby  * If you allocate hid_device through hid_allocate_device, you should ever
251685cdaf52SJiri Slaby  * free by this function.
251785cdaf52SJiri Slaby  */
251885cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev)
251985cdaf52SJiri Slaby {
252085cdaf52SJiri Slaby 	hid_remove_device(hdev);
252185cdaf52SJiri Slaby 	put_device(&hdev->dev);
252285cdaf52SJiri Slaby }
252385cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device);
252485cdaf52SJiri Slaby 
252585cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
252685cdaf52SJiri Slaby 		const char *mod_name)
252785cdaf52SJiri Slaby {
25283a6f82f7SJiri Slaby 	int ret;
25293a6f82f7SJiri Slaby 
253085cdaf52SJiri Slaby 	hdrv->driver.name = hdrv->name;
253185cdaf52SJiri Slaby 	hdrv->driver.bus = &hid_bus_type;
253285cdaf52SJiri Slaby 	hdrv->driver.owner = owner;
253385cdaf52SJiri Slaby 	hdrv->driver.mod_name = mod_name;
253485cdaf52SJiri Slaby 
25353a6f82f7SJiri Slaby 	INIT_LIST_HEAD(&hdrv->dyn_list);
25363a6f82f7SJiri Slaby 	spin_lock_init(&hdrv->dyn_lock);
25373a6f82f7SJiri Slaby 
25383a6f82f7SJiri Slaby 	ret = driver_register(&hdrv->driver);
25393a6f82f7SJiri Slaby 	if (ret)
25403a6f82f7SJiri Slaby 		return ret;
25413a6f82f7SJiri Slaby 
25423a6f82f7SJiri Slaby 	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
25433a6f82f7SJiri Slaby 	if (ret)
25443a6f82f7SJiri Slaby 		driver_unregister(&hdrv->driver);
25453a6f82f7SJiri Slaby 
25463a6f82f7SJiri Slaby 	return ret;
254785cdaf52SJiri Slaby }
254885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver);
254985cdaf52SJiri Slaby 
255085cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv)
255185cdaf52SJiri Slaby {
25523a6f82f7SJiri Slaby 	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
255385cdaf52SJiri Slaby 	driver_unregister(&hdrv->driver);
25543a6f82f7SJiri Slaby 	hid_free_dynids(hdrv);
255585cdaf52SJiri Slaby }
255685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver);
255785cdaf52SJiri Slaby 
25580361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid)
25590361a28dSOliver Neukum {
25600361a28dSOliver Neukum 	struct hid_input *hidinput;
25610361a28dSOliver Neukum 	int i;
25620361a28dSOliver Neukum 
2563e5288eb5SJiri Kosina 	if (!(hid->claimed & HID_CLAIMED_INPUT))
2564e5288eb5SJiri Kosina 		return 0;
2565e5288eb5SJiri Kosina 
25660361a28dSOliver Neukum 	list_for_each_entry(hidinput, &hid->inputs, list) {
25670361a28dSOliver Neukum 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
25680361a28dSOliver Neukum 			if (hidinput->input->key[i])
25690361a28dSOliver Neukum 				return 1;
25700361a28dSOliver Neukum 	}
25710361a28dSOliver Neukum 
25720361a28dSOliver Neukum 	return 0;
25730361a28dSOliver Neukum }
25740361a28dSOliver Neukum 
25750361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
25760361a28dSOliver Neukum 
257786166b7bSJiri Kosina static int __init hid_init(void)
257886166b7bSJiri Kosina {
257985cdaf52SJiri Slaby 	int ret;
258085cdaf52SJiri Slaby 
2581a635f9ddSJiri Kosina 	if (hid_debug)
25824291ee30SJoe Perches 		pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
25834291ee30SJoe Perches 			"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2584a635f9ddSJiri Kosina 
258585cdaf52SJiri Slaby 	ret = bus_register(&hid_bus_type);
258685cdaf52SJiri Slaby 	if (ret) {
25874291ee30SJoe Perches 		pr_err("can't register hid bus\n");
258885cdaf52SJiri Slaby 		goto err;
258985cdaf52SJiri Slaby 	}
259085cdaf52SJiri Slaby 
259185cdaf52SJiri Slaby 	ret = hidraw_init();
259285cdaf52SJiri Slaby 	if (ret)
259385cdaf52SJiri Slaby 		goto err_bus;
259485cdaf52SJiri Slaby 
2595a635f9ddSJiri Kosina 	hid_debug_init();
2596a635f9ddSJiri Kosina 
259785cdaf52SJiri Slaby 	return 0;
259885cdaf52SJiri Slaby err_bus:
259985cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
260085cdaf52SJiri Slaby err:
260185cdaf52SJiri Slaby 	return ret;
260286166b7bSJiri Kosina }
260386166b7bSJiri Kosina 
260486166b7bSJiri Kosina static void __exit hid_exit(void)
260586166b7bSJiri Kosina {
2606a635f9ddSJiri Kosina 	hid_debug_exit();
260786166b7bSJiri Kosina 	hidraw_exit();
260885cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
260986166b7bSJiri Kosina }
261086166b7bSJiri Kosina 
261186166b7bSJiri Kosina module_init(hid_init);
261286166b7bSJiri Kosina module_exit(hid_exit);
261386166b7bSJiri Kosina 
261488adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal");
261588adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik");
261688adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina");
2617aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
2618aa938f79SJiri Kosina 
2619