xref: /openbmc/linux/drivers/hid/hid-core.c (revision 6dc1418e13144162e8bc4858789010d8f0e1e65c)
1dde5845aSJiri Kosina /*
2229695e5SJiri Kosina  *  HID support for Linux
3dde5845aSJiri Kosina  *
4dde5845aSJiri Kosina  *  Copyright (c) 1999 Andreas Gal
5dde5845aSJiri Kosina  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6dde5845aSJiri Kosina  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
77d39e849SJiri Kosina  *  Copyright (c) 2006-2010 Jiri Kosina
8dde5845aSJiri Kosina  */
9dde5845aSJiri Kosina 
10dde5845aSJiri Kosina /*
11dde5845aSJiri Kosina  * This program is free software; you can redistribute it and/or modify it
12dde5845aSJiri Kosina  * under the terms of the GNU General Public License as published by the Free
13dde5845aSJiri Kosina  * Software Foundation; either version 2 of the License, or (at your option)
14dde5845aSJiri Kosina  * any later version.
15dde5845aSJiri Kosina  */
16dde5845aSJiri Kosina 
174291ee30SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
184291ee30SJoe Perches 
19dde5845aSJiri Kosina #include <linux/module.h>
20dde5845aSJiri Kosina #include <linux/slab.h>
21dde5845aSJiri Kosina #include <linux/init.h>
22dde5845aSJiri Kosina #include <linux/kernel.h>
23dde5845aSJiri Kosina #include <linux/list.h>
24dde5845aSJiri Kosina #include <linux/mm.h>
25dde5845aSJiri Kosina #include <linux/spinlock.h>
26dde5845aSJiri Kosina #include <asm/unaligned.h>
27dde5845aSJiri Kosina #include <asm/byteorder.h>
28dde5845aSJiri Kosina #include <linux/input.h>
29dde5845aSJiri Kosina #include <linux/wait.h>
3047a80edbSJiri Kosina #include <linux/vmalloc.h>
31c4124c9bSJiri Kosina #include <linux/sched.h>
32dde5845aSJiri Kosina 
33dde5845aSJiri Kosina #include <linux/hid.h>
34dde5845aSJiri Kosina #include <linux/hiddev.h>
35c080d89aSJiri Kosina #include <linux/hid-debug.h>
3686166b7bSJiri Kosina #include <linux/hidraw.h>
37dde5845aSJiri Kosina 
385f22a799SJiri Slaby #include "hid-ids.h"
395f22a799SJiri Slaby 
40dde5845aSJiri Kosina /*
41dde5845aSJiri Kosina  * Version Information
42dde5845aSJiri Kosina  */
43dde5845aSJiri Kosina 
4453149801SJiri Kosina #define DRIVER_DESC "HID core driver"
45dde5845aSJiri Kosina #define DRIVER_LICENSE "GPL"
46dde5845aSJiri Kosina 
4758037eb9SJiri Kosina int hid_debug = 0;
48377e10fbSAnssi Hannula module_param_named(debug, hid_debug, int, 0600);
49cd667ce2SJiri Kosina MODULE_PARM_DESC(debug, "toggle HID debugging messages");
5058037eb9SJiri Kosina EXPORT_SYMBOL_GPL(hid_debug);
5158037eb9SJiri Kosina 
52dde5845aSJiri Kosina /*
53dde5845aSJiri Kosina  * Register a new report for a device.
54dde5845aSJiri Kosina  */
55dde5845aSJiri Kosina 
5690a006abSMichael Poole struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
57dde5845aSJiri Kosina {
58dde5845aSJiri Kosina 	struct hid_report_enum *report_enum = device->report_enum + type;
59dde5845aSJiri Kosina 	struct hid_report *report;
60dde5845aSJiri Kosina 
61dde5845aSJiri Kosina 	if (report_enum->report_id_hash[id])
62dde5845aSJiri Kosina 		return report_enum->report_id_hash[id];
63dde5845aSJiri Kosina 
64a3789a17SJoe Perches 	report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
65a3789a17SJoe Perches 	if (!report)
66dde5845aSJiri Kosina 		return NULL;
67dde5845aSJiri Kosina 
68dde5845aSJiri Kosina 	if (id != 0)
69dde5845aSJiri Kosina 		report_enum->numbered = 1;
70dde5845aSJiri Kosina 
71dde5845aSJiri Kosina 	report->id = id;
72dde5845aSJiri Kosina 	report->type = type;
73dde5845aSJiri Kosina 	report->size = 0;
74dde5845aSJiri Kosina 	report->device = device;
75dde5845aSJiri Kosina 	report_enum->report_id_hash[id] = report;
76dde5845aSJiri Kosina 
77dde5845aSJiri Kosina 	list_add_tail(&report->list, &report_enum->report_list);
78dde5845aSJiri Kosina 
79dde5845aSJiri Kosina 	return report;
80dde5845aSJiri Kosina }
8190a006abSMichael Poole EXPORT_SYMBOL_GPL(hid_register_report);
82dde5845aSJiri Kosina 
83dde5845aSJiri Kosina /*
84dde5845aSJiri Kosina  * Register a new field for this report.
85dde5845aSJiri Kosina  */
86dde5845aSJiri Kosina 
87dde5845aSJiri Kosina static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
88dde5845aSJiri Kosina {
89dde5845aSJiri Kosina 	struct hid_field *field;
90dde5845aSJiri Kosina 
91dde5845aSJiri Kosina 	if (report->maxfield == HID_MAX_FIELDS) {
9258037eb9SJiri Kosina 		dbg_hid("too many fields in report\n");
93dde5845aSJiri Kosina 		return NULL;
94dde5845aSJiri Kosina 	}
95dde5845aSJiri Kosina 
96a3789a17SJoe Perches 	field = kzalloc((sizeof(struct hid_field) +
97a3789a17SJoe Perches 			 usages * sizeof(struct hid_usage) +
98a3789a17SJoe Perches 			 values * sizeof(unsigned)), GFP_KERNEL);
99a3789a17SJoe Perches 	if (!field)
100a3789a17SJoe Perches 		return NULL;
101dde5845aSJiri Kosina 
102dde5845aSJiri Kosina 	field->index = report->maxfield++;
103dde5845aSJiri Kosina 	report->field[field->index] = field;
104dde5845aSJiri Kosina 	field->usage = (struct hid_usage *)(field + 1);
105282bfd4cSJiri Slaby 	field->value = (s32 *)(field->usage + usages);
106dde5845aSJiri Kosina 	field->report = report;
107dde5845aSJiri Kosina 
108dde5845aSJiri Kosina 	return field;
109dde5845aSJiri Kosina }
110dde5845aSJiri Kosina 
111dde5845aSJiri Kosina /*
112dde5845aSJiri Kosina  * Open a collection. The type/usage is pushed on the stack.
113dde5845aSJiri Kosina  */
114dde5845aSJiri Kosina 
115dde5845aSJiri Kosina static int open_collection(struct hid_parser *parser, unsigned type)
116dde5845aSJiri Kosina {
117dde5845aSJiri Kosina 	struct hid_collection *collection;
118dde5845aSJiri Kosina 	unsigned usage;
119dde5845aSJiri Kosina 
120dde5845aSJiri Kosina 	usage = parser->local.usage[0];
121dde5845aSJiri Kosina 
122dde5845aSJiri Kosina 	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
12358037eb9SJiri Kosina 		dbg_hid("collection stack overflow\n");
124dde5845aSJiri Kosina 		return -1;
125dde5845aSJiri Kosina 	}
126dde5845aSJiri Kosina 
127dde5845aSJiri Kosina 	if (parser->device->maxcollection == parser->device->collection_size) {
128dde5845aSJiri Kosina 		collection = kmalloc(sizeof(struct hid_collection) *
129dde5845aSJiri Kosina 				parser->device->collection_size * 2, GFP_KERNEL);
130dde5845aSJiri Kosina 		if (collection == NULL) {
13158037eb9SJiri Kosina 			dbg_hid("failed to reallocate collection array\n");
132dde5845aSJiri Kosina 			return -1;
133dde5845aSJiri Kosina 		}
134dde5845aSJiri Kosina 		memcpy(collection, parser->device->collection,
135dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
136dde5845aSJiri Kosina 			parser->device->collection_size);
137dde5845aSJiri Kosina 		memset(collection + parser->device->collection_size, 0,
138dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
139dde5845aSJiri Kosina 			parser->device->collection_size);
140dde5845aSJiri Kosina 		kfree(parser->device->collection);
141dde5845aSJiri Kosina 		parser->device->collection = collection;
142dde5845aSJiri Kosina 		parser->device->collection_size *= 2;
143dde5845aSJiri Kosina 	}
144dde5845aSJiri Kosina 
145dde5845aSJiri Kosina 	parser->collection_stack[parser->collection_stack_ptr++] =
146dde5845aSJiri Kosina 		parser->device->maxcollection;
147dde5845aSJiri Kosina 
148dde5845aSJiri Kosina 	collection = parser->device->collection +
149dde5845aSJiri Kosina 		parser->device->maxcollection++;
150dde5845aSJiri Kosina 	collection->type = type;
151dde5845aSJiri Kosina 	collection->usage = usage;
152dde5845aSJiri Kosina 	collection->level = parser->collection_stack_ptr - 1;
153dde5845aSJiri Kosina 
154dde5845aSJiri Kosina 	if (type == HID_COLLECTION_APPLICATION)
155dde5845aSJiri Kosina 		parser->device->maxapplication++;
156dde5845aSJiri Kosina 
157dde5845aSJiri Kosina 	return 0;
158dde5845aSJiri Kosina }
159dde5845aSJiri Kosina 
160dde5845aSJiri Kosina /*
161dde5845aSJiri Kosina  * Close a collection.
162dde5845aSJiri Kosina  */
163dde5845aSJiri Kosina 
164dde5845aSJiri Kosina static int close_collection(struct hid_parser *parser)
165dde5845aSJiri Kosina {
166dde5845aSJiri Kosina 	if (!parser->collection_stack_ptr) {
16758037eb9SJiri Kosina 		dbg_hid("collection stack underflow\n");
168dde5845aSJiri Kosina 		return -1;
169dde5845aSJiri Kosina 	}
170dde5845aSJiri Kosina 	parser->collection_stack_ptr--;
171dde5845aSJiri Kosina 	return 0;
172dde5845aSJiri Kosina }
173dde5845aSJiri Kosina 
174dde5845aSJiri Kosina /*
175dde5845aSJiri Kosina  * Climb up the stack, search for the specified collection type
176dde5845aSJiri Kosina  * and return the usage.
177dde5845aSJiri Kosina  */
178dde5845aSJiri Kosina 
179dde5845aSJiri Kosina static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
180dde5845aSJiri Kosina {
181504499f2SJoe Perches 	struct hid_collection *collection = parser->device->collection;
182dde5845aSJiri Kosina 	int n;
183504499f2SJoe Perches 
184504499f2SJoe Perches 	for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
185504499f2SJoe Perches 		unsigned index = parser->collection_stack[n];
186504499f2SJoe Perches 		if (collection[index].type == type)
187504499f2SJoe Perches 			return collection[index].usage;
188504499f2SJoe Perches 	}
189dde5845aSJiri Kosina 	return 0; /* we know nothing about this usage type */
190dde5845aSJiri Kosina }
191dde5845aSJiri Kosina 
192dde5845aSJiri Kosina /*
193dde5845aSJiri Kosina  * Add a usage to the temporary parser table.
194dde5845aSJiri Kosina  */
195dde5845aSJiri Kosina 
196dde5845aSJiri Kosina static int hid_add_usage(struct hid_parser *parser, unsigned usage)
197dde5845aSJiri Kosina {
198dde5845aSJiri Kosina 	if (parser->local.usage_index >= HID_MAX_USAGES) {
19958037eb9SJiri Kosina 		dbg_hid("usage index exceeded\n");
200dde5845aSJiri Kosina 		return -1;
201dde5845aSJiri Kosina 	}
202dde5845aSJiri Kosina 	parser->local.usage[parser->local.usage_index] = usage;
203dde5845aSJiri Kosina 	parser->local.collection_index[parser->local.usage_index] =
204dde5845aSJiri Kosina 		parser->collection_stack_ptr ?
205dde5845aSJiri Kosina 		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
206dde5845aSJiri Kosina 	parser->local.usage_index++;
207dde5845aSJiri Kosina 	return 0;
208dde5845aSJiri Kosina }
209dde5845aSJiri Kosina 
210dde5845aSJiri Kosina /*
211dde5845aSJiri Kosina  * Register a new field for this report.
212dde5845aSJiri Kosina  */
213dde5845aSJiri Kosina 
214dde5845aSJiri Kosina static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
215dde5845aSJiri Kosina {
216dde5845aSJiri Kosina 	struct hid_report *report;
217dde5845aSJiri Kosina 	struct hid_field *field;
218dde5845aSJiri Kosina 	int usages;
219dde5845aSJiri Kosina 	unsigned offset;
220dde5845aSJiri Kosina 	int i;
221dde5845aSJiri Kosina 
222a3789a17SJoe Perches 	report = hid_register_report(parser->device, report_type, parser->global.report_id);
223a3789a17SJoe Perches 	if (!report) {
22458037eb9SJiri Kosina 		dbg_hid("hid_register_report failed\n");
225dde5845aSJiri Kosina 		return -1;
226dde5845aSJiri Kosina 	}
227dde5845aSJiri Kosina 
228dde5845aSJiri Kosina 	if (parser->global.logical_maximum < parser->global.logical_minimum) {
22958037eb9SJiri Kosina 		dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
230dde5845aSJiri Kosina 		return -1;
231dde5845aSJiri Kosina 	}
232dde5845aSJiri Kosina 
233dde5845aSJiri Kosina 	offset = report->size;
234dde5845aSJiri Kosina 	report->size += parser->global.report_size * parser->global.report_count;
235dde5845aSJiri Kosina 
236dde5845aSJiri Kosina 	if (!parser->local.usage_index) /* Ignore padding fields */
237dde5845aSJiri Kosina 		return 0;
238dde5845aSJiri Kosina 
239dde5845aSJiri Kosina 	usages = max_t(int, parser->local.usage_index, parser->global.report_count);
240dde5845aSJiri Kosina 
241a3789a17SJoe Perches 	field = hid_register_field(report, usages, parser->global.report_count);
242a3789a17SJoe Perches 	if (!field)
243dde5845aSJiri Kosina 		return 0;
244dde5845aSJiri Kosina 
245dde5845aSJiri Kosina 	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
246dde5845aSJiri Kosina 	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
247dde5845aSJiri Kosina 	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
248dde5845aSJiri Kosina 
249dde5845aSJiri Kosina 	for (i = 0; i < usages; i++) {
250dde5845aSJiri Kosina 		int j = i;
251dde5845aSJiri Kosina 		/* Duplicate the last usage we parsed if we have excess values */
252dde5845aSJiri Kosina 		if (i >= parser->local.usage_index)
253dde5845aSJiri Kosina 			j = parser->local.usage_index - 1;
254dde5845aSJiri Kosina 		field->usage[i].hid = parser->local.usage[j];
255dde5845aSJiri Kosina 		field->usage[i].collection_index =
256dde5845aSJiri Kosina 			parser->local.collection_index[j];
257dde5845aSJiri Kosina 	}
258dde5845aSJiri Kosina 
259dde5845aSJiri Kosina 	field->maxusage = usages;
260dde5845aSJiri Kosina 	field->flags = flags;
261dde5845aSJiri Kosina 	field->report_offset = offset;
262dde5845aSJiri Kosina 	field->report_type = report_type;
263dde5845aSJiri Kosina 	field->report_size = parser->global.report_size;
264dde5845aSJiri Kosina 	field->report_count = parser->global.report_count;
265dde5845aSJiri Kosina 	field->logical_minimum = parser->global.logical_minimum;
266dde5845aSJiri Kosina 	field->logical_maximum = parser->global.logical_maximum;
267dde5845aSJiri Kosina 	field->physical_minimum = parser->global.physical_minimum;
268dde5845aSJiri Kosina 	field->physical_maximum = parser->global.physical_maximum;
269dde5845aSJiri Kosina 	field->unit_exponent = parser->global.unit_exponent;
270dde5845aSJiri Kosina 	field->unit = parser->global.unit;
271dde5845aSJiri Kosina 
272dde5845aSJiri Kosina 	return 0;
273dde5845aSJiri Kosina }
274dde5845aSJiri Kosina 
275dde5845aSJiri Kosina /*
276dde5845aSJiri Kosina  * Read data value from item.
277dde5845aSJiri Kosina  */
278dde5845aSJiri Kosina 
279dde5845aSJiri Kosina static u32 item_udata(struct hid_item *item)
280dde5845aSJiri Kosina {
281dde5845aSJiri Kosina 	switch (item->size) {
282dde5845aSJiri Kosina 	case 1: return item->data.u8;
283dde5845aSJiri Kosina 	case 2: return item->data.u16;
284dde5845aSJiri Kosina 	case 4: return item->data.u32;
285dde5845aSJiri Kosina 	}
286dde5845aSJiri Kosina 	return 0;
287dde5845aSJiri Kosina }
288dde5845aSJiri Kosina 
289dde5845aSJiri Kosina static s32 item_sdata(struct hid_item *item)
290dde5845aSJiri Kosina {
291dde5845aSJiri Kosina 	switch (item->size) {
292dde5845aSJiri Kosina 	case 1: return item->data.s8;
293dde5845aSJiri Kosina 	case 2: return item->data.s16;
294dde5845aSJiri Kosina 	case 4: return item->data.s32;
295dde5845aSJiri Kosina 	}
296dde5845aSJiri Kosina 	return 0;
297dde5845aSJiri Kosina }
298dde5845aSJiri Kosina 
299dde5845aSJiri Kosina /*
300dde5845aSJiri Kosina  * Process a global item.
301dde5845aSJiri Kosina  */
302dde5845aSJiri Kosina 
303dde5845aSJiri Kosina static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
304dde5845aSJiri Kosina {
305dde5845aSJiri Kosina 	switch (item->tag) {
306dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PUSH:
307dde5845aSJiri Kosina 
308dde5845aSJiri Kosina 		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
30925985edcSLucas De Marchi 			dbg_hid("global environment stack overflow\n");
310dde5845aSJiri Kosina 			return -1;
311dde5845aSJiri Kosina 		}
312dde5845aSJiri Kosina 
313dde5845aSJiri Kosina 		memcpy(parser->global_stack + parser->global_stack_ptr++,
314dde5845aSJiri Kosina 			&parser->global, sizeof(struct hid_global));
315dde5845aSJiri Kosina 		return 0;
316dde5845aSJiri Kosina 
317dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_POP:
318dde5845aSJiri Kosina 
319dde5845aSJiri Kosina 		if (!parser->global_stack_ptr) {
32025985edcSLucas De Marchi 			dbg_hid("global environment stack underflow\n");
321dde5845aSJiri Kosina 			return -1;
322dde5845aSJiri Kosina 		}
323dde5845aSJiri Kosina 
324880d29f1SJiri Slaby 		memcpy(&parser->global, parser->global_stack +
325880d29f1SJiri Slaby 			--parser->global_stack_ptr, sizeof(struct hid_global));
326dde5845aSJiri Kosina 		return 0;
327dde5845aSJiri Kosina 
328dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
329dde5845aSJiri Kosina 		parser->global.usage_page = item_udata(item);
330dde5845aSJiri Kosina 		return 0;
331dde5845aSJiri Kosina 
332dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
333dde5845aSJiri Kosina 		parser->global.logical_minimum = item_sdata(item);
334dde5845aSJiri Kosina 		return 0;
335dde5845aSJiri Kosina 
336dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
337dde5845aSJiri Kosina 		if (parser->global.logical_minimum < 0)
338dde5845aSJiri Kosina 			parser->global.logical_maximum = item_sdata(item);
339dde5845aSJiri Kosina 		else
340dde5845aSJiri Kosina 			parser->global.logical_maximum = item_udata(item);
341dde5845aSJiri Kosina 		return 0;
342dde5845aSJiri Kosina 
343dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
344dde5845aSJiri Kosina 		parser->global.physical_minimum = item_sdata(item);
345dde5845aSJiri Kosina 		return 0;
346dde5845aSJiri Kosina 
347dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
348dde5845aSJiri Kosina 		if (parser->global.physical_minimum < 0)
349dde5845aSJiri Kosina 			parser->global.physical_maximum = item_sdata(item);
350dde5845aSJiri Kosina 		else
351dde5845aSJiri Kosina 			parser->global.physical_maximum = item_udata(item);
352dde5845aSJiri Kosina 		return 0;
353dde5845aSJiri Kosina 
354dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
355dde5845aSJiri Kosina 		parser->global.unit_exponent = item_sdata(item);
356dde5845aSJiri Kosina 		return 0;
357dde5845aSJiri Kosina 
358dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT:
359dde5845aSJiri Kosina 		parser->global.unit = item_udata(item);
360dde5845aSJiri Kosina 		return 0;
361dde5845aSJiri Kosina 
362dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
363880d29f1SJiri Slaby 		parser->global.report_size = item_udata(item);
364880d29f1SJiri Slaby 		if (parser->global.report_size > 32) {
365880d29f1SJiri Slaby 			dbg_hid("invalid report_size %d\n",
366880d29f1SJiri Slaby 					parser->global.report_size);
367dde5845aSJiri Kosina 			return -1;
368dde5845aSJiri Kosina 		}
369dde5845aSJiri Kosina 		return 0;
370dde5845aSJiri Kosina 
371dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
372880d29f1SJiri Slaby 		parser->global.report_count = item_udata(item);
373880d29f1SJiri Slaby 		if (parser->global.report_count > HID_MAX_USAGES) {
374880d29f1SJiri Slaby 			dbg_hid("invalid report_count %d\n",
375880d29f1SJiri Slaby 					parser->global.report_count);
376dde5845aSJiri Kosina 			return -1;
377dde5845aSJiri Kosina 		}
378dde5845aSJiri Kosina 		return 0;
379dde5845aSJiri Kosina 
380dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
381880d29f1SJiri Slaby 		parser->global.report_id = item_udata(item);
382880d29f1SJiri Slaby 		if (parser->global.report_id == 0) {
38358037eb9SJiri Kosina 			dbg_hid("report_id 0 is invalid\n");
384dde5845aSJiri Kosina 			return -1;
385dde5845aSJiri Kosina 		}
386dde5845aSJiri Kosina 		return 0;
387dde5845aSJiri Kosina 
388dde5845aSJiri Kosina 	default:
38958037eb9SJiri Kosina 		dbg_hid("unknown global tag 0x%x\n", item->tag);
390dde5845aSJiri Kosina 		return -1;
391dde5845aSJiri Kosina 	}
392dde5845aSJiri Kosina }
393dde5845aSJiri Kosina 
394dde5845aSJiri Kosina /*
395dde5845aSJiri Kosina  * Process a local item.
396dde5845aSJiri Kosina  */
397dde5845aSJiri Kosina 
398dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
399dde5845aSJiri Kosina {
400dde5845aSJiri Kosina 	__u32 data;
401dde5845aSJiri Kosina 	unsigned n;
402dde5845aSJiri Kosina 
403dde5845aSJiri Kosina 	data = item_udata(item);
404dde5845aSJiri Kosina 
405dde5845aSJiri Kosina 	switch (item->tag) {
406dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_DELIMITER:
407dde5845aSJiri Kosina 
408dde5845aSJiri Kosina 		if (data) {
409dde5845aSJiri Kosina 			/*
410dde5845aSJiri Kosina 			 * We treat items before the first delimiter
411dde5845aSJiri Kosina 			 * as global to all usage sets (branch 0).
412dde5845aSJiri Kosina 			 * In the moment we process only these global
413dde5845aSJiri Kosina 			 * items and the first delimiter set.
414dde5845aSJiri Kosina 			 */
415dde5845aSJiri Kosina 			if (parser->local.delimiter_depth != 0) {
41658037eb9SJiri Kosina 				dbg_hid("nested delimiters\n");
417dde5845aSJiri Kosina 				return -1;
418dde5845aSJiri Kosina 			}
419dde5845aSJiri Kosina 			parser->local.delimiter_depth++;
420dde5845aSJiri Kosina 			parser->local.delimiter_branch++;
421dde5845aSJiri Kosina 		} else {
422dde5845aSJiri Kosina 			if (parser->local.delimiter_depth < 1) {
42358037eb9SJiri Kosina 				dbg_hid("bogus close delimiter\n");
424dde5845aSJiri Kosina 				return -1;
425dde5845aSJiri Kosina 			}
426dde5845aSJiri Kosina 			parser->local.delimiter_depth--;
427dde5845aSJiri Kosina 		}
428dde5845aSJiri Kosina 		return 1;
429dde5845aSJiri Kosina 
430dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE:
431dde5845aSJiri Kosina 
432dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
43358037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
434dde5845aSJiri Kosina 			return 0;
435dde5845aSJiri Kosina 		}
436dde5845aSJiri Kosina 
437dde5845aSJiri Kosina 		if (item->size <= 2)
438dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
439dde5845aSJiri Kosina 
440dde5845aSJiri Kosina 		return hid_add_usage(parser, data);
441dde5845aSJiri Kosina 
442dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
443dde5845aSJiri Kosina 
444dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
44558037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
446dde5845aSJiri Kosina 			return 0;
447dde5845aSJiri Kosina 		}
448dde5845aSJiri Kosina 
449dde5845aSJiri Kosina 		if (item->size <= 2)
450dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
451dde5845aSJiri Kosina 
452dde5845aSJiri Kosina 		parser->local.usage_minimum = data;
453dde5845aSJiri Kosina 		return 0;
454dde5845aSJiri Kosina 
455dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
456dde5845aSJiri Kosina 
457dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
45858037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
459dde5845aSJiri Kosina 			return 0;
460dde5845aSJiri Kosina 		}
461dde5845aSJiri Kosina 
462dde5845aSJiri Kosina 		if (item->size <= 2)
463dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
464dde5845aSJiri Kosina 
465dde5845aSJiri Kosina 		for (n = parser->local.usage_minimum; n <= data; n++)
466dde5845aSJiri Kosina 			if (hid_add_usage(parser, n)) {
46758037eb9SJiri Kosina 				dbg_hid("hid_add_usage failed\n");
468dde5845aSJiri Kosina 				return -1;
469dde5845aSJiri Kosina 			}
470dde5845aSJiri Kosina 		return 0;
471dde5845aSJiri Kosina 
472dde5845aSJiri Kosina 	default:
473dde5845aSJiri Kosina 
47458037eb9SJiri Kosina 		dbg_hid("unknown local item tag 0x%x\n", item->tag);
475dde5845aSJiri Kosina 		return 0;
476dde5845aSJiri Kosina 	}
477dde5845aSJiri Kosina 	return 0;
478dde5845aSJiri Kosina }
479dde5845aSJiri Kosina 
480dde5845aSJiri Kosina /*
481dde5845aSJiri Kosina  * Process a main item.
482dde5845aSJiri Kosina  */
483dde5845aSJiri Kosina 
484dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
485dde5845aSJiri Kosina {
486dde5845aSJiri Kosina 	__u32 data;
487dde5845aSJiri Kosina 	int ret;
488dde5845aSJiri Kosina 
489dde5845aSJiri Kosina 	data = item_udata(item);
490dde5845aSJiri Kosina 
491dde5845aSJiri Kosina 	switch (item->tag) {
492dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
493dde5845aSJiri Kosina 		ret = open_collection(parser, data & 0xff);
494dde5845aSJiri Kosina 		break;
495dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
496dde5845aSJiri Kosina 		ret = close_collection(parser);
497dde5845aSJiri Kosina 		break;
498dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_INPUT:
499dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
500dde5845aSJiri Kosina 		break;
501dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_OUTPUT:
502dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
503dde5845aSJiri Kosina 		break;
504dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_FEATURE:
505dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
506dde5845aSJiri Kosina 		break;
507dde5845aSJiri Kosina 	default:
50858037eb9SJiri Kosina 		dbg_hid("unknown main item tag 0x%x\n", item->tag);
509dde5845aSJiri Kosina 		ret = 0;
510dde5845aSJiri Kosina 	}
511dde5845aSJiri Kosina 
512dde5845aSJiri Kosina 	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
513dde5845aSJiri Kosina 
514dde5845aSJiri Kosina 	return ret;
515dde5845aSJiri Kosina }
516dde5845aSJiri Kosina 
517dde5845aSJiri Kosina /*
518dde5845aSJiri Kosina  * Process a reserved item.
519dde5845aSJiri Kosina  */
520dde5845aSJiri Kosina 
521dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
522dde5845aSJiri Kosina {
52358037eb9SJiri Kosina 	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
524dde5845aSJiri Kosina 	return 0;
525dde5845aSJiri Kosina }
526dde5845aSJiri Kosina 
527dde5845aSJiri Kosina /*
528dde5845aSJiri Kosina  * Free a report and all registered fields. The field->usage and
529dde5845aSJiri Kosina  * field->value table's are allocated behind the field, so we need
530dde5845aSJiri Kosina  * only to free(field) itself.
531dde5845aSJiri Kosina  */
532dde5845aSJiri Kosina 
533dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report)
534dde5845aSJiri Kosina {
535dde5845aSJiri Kosina 	unsigned n;
536dde5845aSJiri Kosina 
537dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
538dde5845aSJiri Kosina 		kfree(report->field[n]);
539dde5845aSJiri Kosina 	kfree(report);
540dde5845aSJiri Kosina }
541dde5845aSJiri Kosina 
542dde5845aSJiri Kosina /*
543dde5845aSJiri Kosina  * Free a device structure, all reports, and all fields.
544dde5845aSJiri Kosina  */
545dde5845aSJiri Kosina 
54685cdaf52SJiri Slaby static void hid_device_release(struct device *dev)
547dde5845aSJiri Kosina {
54885cdaf52SJiri Slaby 	struct hid_device *device = container_of(dev, struct hid_device, dev);
549dde5845aSJiri Kosina 	unsigned i, j;
550dde5845aSJiri Kosina 
551dde5845aSJiri Kosina 	for (i = 0; i < HID_REPORT_TYPES; i++) {
552dde5845aSJiri Kosina 		struct hid_report_enum *report_enum = device->report_enum + i;
553dde5845aSJiri Kosina 
554dde5845aSJiri Kosina 		for (j = 0; j < 256; j++) {
555dde5845aSJiri Kosina 			struct hid_report *report = report_enum->report_id_hash[j];
556dde5845aSJiri Kosina 			if (report)
557dde5845aSJiri Kosina 				hid_free_report(report);
558dde5845aSJiri Kosina 		}
559dde5845aSJiri Kosina 	}
560dde5845aSJiri Kosina 
561dde5845aSJiri Kosina 	kfree(device->rdesc);
562767fe787SJiri Kosina 	kfree(device->collection);
563dde5845aSJiri Kosina 	kfree(device);
564dde5845aSJiri Kosina }
565dde5845aSJiri Kosina 
566dde5845aSJiri Kosina /*
567dde5845aSJiri Kosina  * Fetch a report description item from the data stream. We support long
568dde5845aSJiri Kosina  * items, though they are not used yet.
569dde5845aSJiri Kosina  */
570dde5845aSJiri Kosina 
571dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
572dde5845aSJiri Kosina {
573dde5845aSJiri Kosina 	u8 b;
574dde5845aSJiri Kosina 
575dde5845aSJiri Kosina 	if ((end - start) <= 0)
576dde5845aSJiri Kosina 		return NULL;
577dde5845aSJiri Kosina 
578dde5845aSJiri Kosina 	b = *start++;
579dde5845aSJiri Kosina 
580dde5845aSJiri Kosina 	item->type = (b >> 2) & 3;
581dde5845aSJiri Kosina 	item->tag  = (b >> 4) & 15;
582dde5845aSJiri Kosina 
583dde5845aSJiri Kosina 	if (item->tag == HID_ITEM_TAG_LONG) {
584dde5845aSJiri Kosina 
585dde5845aSJiri Kosina 		item->format = HID_ITEM_FORMAT_LONG;
586dde5845aSJiri Kosina 
587dde5845aSJiri Kosina 		if ((end - start) < 2)
588dde5845aSJiri Kosina 			return NULL;
589dde5845aSJiri Kosina 
590dde5845aSJiri Kosina 		item->size = *start++;
591dde5845aSJiri Kosina 		item->tag  = *start++;
592dde5845aSJiri Kosina 
593dde5845aSJiri Kosina 		if ((end - start) < item->size)
594dde5845aSJiri Kosina 			return NULL;
595dde5845aSJiri Kosina 
596dde5845aSJiri Kosina 		item->data.longdata = start;
597dde5845aSJiri Kosina 		start += item->size;
598dde5845aSJiri Kosina 		return start;
599dde5845aSJiri Kosina 	}
600dde5845aSJiri Kosina 
601dde5845aSJiri Kosina 	item->format = HID_ITEM_FORMAT_SHORT;
602dde5845aSJiri Kosina 	item->size = b & 3;
603dde5845aSJiri Kosina 
604dde5845aSJiri Kosina 	switch (item->size) {
605dde5845aSJiri Kosina 	case 0:
606dde5845aSJiri Kosina 		return start;
607dde5845aSJiri Kosina 
608dde5845aSJiri Kosina 	case 1:
609dde5845aSJiri Kosina 		if ((end - start) < 1)
610dde5845aSJiri Kosina 			return NULL;
611dde5845aSJiri Kosina 		item->data.u8 = *start++;
612dde5845aSJiri Kosina 		return start;
613dde5845aSJiri Kosina 
614dde5845aSJiri Kosina 	case 2:
615dde5845aSJiri Kosina 		if ((end - start) < 2)
616dde5845aSJiri Kosina 			return NULL;
617c105068fSHarvey Harrison 		item->data.u16 = get_unaligned_le16(start);
618dde5845aSJiri Kosina 		start = (__u8 *)((__le16 *)start + 1);
619dde5845aSJiri Kosina 		return start;
620dde5845aSJiri Kosina 
621dde5845aSJiri Kosina 	case 3:
622dde5845aSJiri Kosina 		item->size++;
623dde5845aSJiri Kosina 		if ((end - start) < 4)
624dde5845aSJiri Kosina 			return NULL;
625c105068fSHarvey Harrison 		item->data.u32 = get_unaligned_le32(start);
626dde5845aSJiri Kosina 		start = (__u8 *)((__le32 *)start + 1);
627dde5845aSJiri Kosina 		return start;
628dde5845aSJiri Kosina 	}
629dde5845aSJiri Kosina 
630dde5845aSJiri Kosina 	return NULL;
631dde5845aSJiri Kosina }
632dde5845aSJiri Kosina 
63385cdaf52SJiri Slaby /**
63485cdaf52SJiri Slaby  * hid_parse_report - parse device report
63585cdaf52SJiri Slaby  *
63685cdaf52SJiri Slaby  * @device: hid device
63785cdaf52SJiri Slaby  * @start: report start
63885cdaf52SJiri Slaby  * @size: report size
63985cdaf52SJiri Slaby  *
640dde5845aSJiri Kosina  * Parse a report description into a hid_device structure. Reports are
641dde5845aSJiri Kosina  * enumerated, fields are attached to these reports.
64285cdaf52SJiri Slaby  * 0 returned on success, otherwise nonzero error value.
643dde5845aSJiri Kosina  */
64485cdaf52SJiri Slaby int hid_parse_report(struct hid_device *device, __u8 *start,
64585cdaf52SJiri Slaby 		unsigned size)
646dde5845aSJiri Kosina {
647dde5845aSJiri Kosina 	struct hid_parser *parser;
648dde5845aSJiri Kosina 	struct hid_item item;
649dde5845aSJiri Kosina 	__u8 *end;
65085cdaf52SJiri Slaby 	int ret;
651dde5845aSJiri Kosina 	static int (*dispatch_type[])(struct hid_parser *parser,
652dde5845aSJiri Kosina 				      struct hid_item *item) = {
653dde5845aSJiri Kosina 		hid_parser_main,
654dde5845aSJiri Kosina 		hid_parser_global,
655dde5845aSJiri Kosina 		hid_parser_local,
656dde5845aSJiri Kosina 		hid_parser_reserved
657dde5845aSJiri Kosina 	};
658dde5845aSJiri Kosina 
659c500c971SJiri Slaby 	if (device->driver->report_fixup)
66073e4008dSNikolai Kondrashov 		start = device->driver->report_fixup(device, start, &size);
661c500c971SJiri Slaby 
6621721a238SJulia Lawall 	device->rdesc = kmemdup(start, size, GFP_KERNEL);
66385cdaf52SJiri Slaby 	if (device->rdesc == NULL)
66485cdaf52SJiri Slaby 		return -ENOMEM;
665dde5845aSJiri Kosina 	device->rsize = size;
666dde5845aSJiri Kosina 
667fe258020SJoe Perches 	parser = vzalloc(sizeof(struct hid_parser));
66885cdaf52SJiri Slaby 	if (!parser) {
66985cdaf52SJiri Slaby 		ret = -ENOMEM;
67085cdaf52SJiri Slaby 		goto err;
671dde5845aSJiri Kosina 	}
67285cdaf52SJiri Slaby 
673dde5845aSJiri Kosina 	parser->device = device;
674dde5845aSJiri Kosina 
675dde5845aSJiri Kosina 	end = start + size;
67685cdaf52SJiri Slaby 	ret = -EINVAL;
677dde5845aSJiri Kosina 	while ((start = fetch_item(start, end, &item)) != NULL) {
678dde5845aSJiri Kosina 
679dde5845aSJiri Kosina 		if (item.format != HID_ITEM_FORMAT_SHORT) {
68058037eb9SJiri Kosina 			dbg_hid("unexpected long global item\n");
68185cdaf52SJiri Slaby 			goto err;
682dde5845aSJiri Kosina 		}
683dde5845aSJiri Kosina 
684dde5845aSJiri Kosina 		if (dispatch_type[item.type](parser, &item)) {
68558037eb9SJiri Kosina 			dbg_hid("item %u %u %u %u parsing failed\n",
6864291ee30SJoe Perches 				item.format, (unsigned)item.size,
6874291ee30SJoe Perches 				(unsigned)item.type, (unsigned)item.tag);
68885cdaf52SJiri Slaby 			goto err;
689dde5845aSJiri Kosina 		}
690dde5845aSJiri Kosina 
691dde5845aSJiri Kosina 		if (start == end) {
692dde5845aSJiri Kosina 			if (parser->collection_stack_ptr) {
69358037eb9SJiri Kosina 				dbg_hid("unbalanced collection at end of report description\n");
69485cdaf52SJiri Slaby 				goto err;
695dde5845aSJiri Kosina 			}
696dde5845aSJiri Kosina 			if (parser->local.delimiter_depth) {
69758037eb9SJiri Kosina 				dbg_hid("unbalanced delimiter at end of report description\n");
69885cdaf52SJiri Slaby 				goto err;
699dde5845aSJiri Kosina 			}
70047a80edbSJiri Kosina 			vfree(parser);
70185cdaf52SJiri Slaby 			return 0;
702dde5845aSJiri Kosina 		}
703dde5845aSJiri Kosina 	}
704dde5845aSJiri Kosina 
70558037eb9SJiri Kosina 	dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
70685cdaf52SJiri Slaby err:
70747a80edbSJiri Kosina 	vfree(parser);
70885cdaf52SJiri Slaby 	return ret;
709dde5845aSJiri Kosina }
710229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_parse_report);
711dde5845aSJiri Kosina 
712dde5845aSJiri Kosina /*
713dde5845aSJiri Kosina  * Convert a signed n-bit integer to signed 32-bit integer. Common
714dde5845aSJiri Kosina  * cases are done through the compiler, the screwed things has to be
715dde5845aSJiri Kosina  * done by hand.
716dde5845aSJiri Kosina  */
717dde5845aSJiri Kosina 
718dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n)
719dde5845aSJiri Kosina {
720dde5845aSJiri Kosina 	switch (n) {
721dde5845aSJiri Kosina 	case 8:  return ((__s8)value);
722dde5845aSJiri Kosina 	case 16: return ((__s16)value);
723dde5845aSJiri Kosina 	case 32: return ((__s32)value);
724dde5845aSJiri Kosina 	}
725dde5845aSJiri Kosina 	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
726dde5845aSJiri Kosina }
727dde5845aSJiri Kosina 
728dde5845aSJiri Kosina /*
729dde5845aSJiri Kosina  * Convert a signed 32-bit integer to a signed n-bit integer.
730dde5845aSJiri Kosina  */
731dde5845aSJiri Kosina 
732dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n)
733dde5845aSJiri Kosina {
734dde5845aSJiri Kosina 	s32 a = value >> (n - 1);
735dde5845aSJiri Kosina 	if (a && a != -1)
736dde5845aSJiri Kosina 		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
737dde5845aSJiri Kosina 	return value & ((1 << n) - 1);
738dde5845aSJiri Kosina }
739dde5845aSJiri Kosina 
740dde5845aSJiri Kosina /*
741dde5845aSJiri Kosina  * Extract/implement a data field from/to a little endian report (bit array).
742dde5845aSJiri Kosina  *
743dde5845aSJiri Kosina  * Code sort-of follows HID spec:
744dde5845aSJiri Kosina  *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
745dde5845aSJiri Kosina  *
746dde5845aSJiri Kosina  * While the USB HID spec allows unlimited length bit fields in "report
747dde5845aSJiri Kosina  * descriptors", most devices never use more than 16 bits.
748dde5845aSJiri Kosina  * One model of UPS is claimed to report "LINEV" as a 32-bit field.
749dde5845aSJiri Kosina  * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
750dde5845aSJiri Kosina  */
751dde5845aSJiri Kosina 
75216ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report,
7534291ee30SJoe Perches 		     unsigned offset, unsigned n)
754dde5845aSJiri Kosina {
755dde5845aSJiri Kosina 	u64 x;
756dde5845aSJiri Kosina 
757c4124c9bSJiri Kosina 	if (n > 32)
7584291ee30SJoe Perches 		hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
759c4124c9bSJiri Kosina 			 n, current->comm);
760dde5845aSJiri Kosina 
761dde5845aSJiri Kosina 	report += offset >> 3;  /* adjust byte index */
762dde5845aSJiri Kosina 	offset &= 7;            /* now only need bit offset into one byte */
763c105068fSHarvey Harrison 	x = get_unaligned_le64(report);
764dde5845aSJiri Kosina 	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
765dde5845aSJiri Kosina 	return (u32) x;
766dde5845aSJiri Kosina }
767dde5845aSJiri Kosina 
768dde5845aSJiri Kosina /*
769dde5845aSJiri Kosina  * "implement" : set bits in a little endian bit stream.
770dde5845aSJiri Kosina  * Same concepts as "extract" (see comments above).
771dde5845aSJiri Kosina  * The data mangled in the bit stream remains in little endian
772dde5845aSJiri Kosina  * order the whole time. It make more sense to talk about
773dde5845aSJiri Kosina  * endianness of register values by considering a register
774dde5845aSJiri Kosina  * a "cached" copy of the little endiad bit stream.
775dde5845aSJiri Kosina  */
77616ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report,
7774291ee30SJoe Perches 		      unsigned offset, unsigned n, __u32 value)
778dde5845aSJiri Kosina {
7796f0168d2SHarvey Harrison 	u64 x;
780dde5845aSJiri Kosina 	u64 m = (1ULL << n) - 1;
781dde5845aSJiri Kosina 
782c4124c9bSJiri Kosina 	if (n > 32)
7834291ee30SJoe Perches 		hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
7844291ee30SJoe Perches 			 __func__, n, current->comm);
785dde5845aSJiri Kosina 
786c4124c9bSJiri Kosina 	if (value > m)
7874291ee30SJoe Perches 		hid_warn(hid, "%s() called with too large value %d! (%s)\n",
7884291ee30SJoe Perches 			 __func__, value, current->comm);
789dde5845aSJiri Kosina 	WARN_ON(value > m);
790dde5845aSJiri Kosina 	value &= m;
791dde5845aSJiri Kosina 
792dde5845aSJiri Kosina 	report += offset >> 3;
793dde5845aSJiri Kosina 	offset &= 7;
794dde5845aSJiri Kosina 
7956f0168d2SHarvey Harrison 	x = get_unaligned_le64(report);
7966f0168d2SHarvey Harrison 	x &= ~(m << offset);
7976f0168d2SHarvey Harrison 	x |= ((u64)value) << offset;
7986f0168d2SHarvey Harrison 	put_unaligned_le64(x, report);
799dde5845aSJiri Kosina }
800dde5845aSJiri Kosina 
801dde5845aSJiri Kosina /*
802dde5845aSJiri Kosina  * Search an array for a value.
803dde5845aSJiri Kosina  */
804dde5845aSJiri Kosina 
80516ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n)
806dde5845aSJiri Kosina {
807dde5845aSJiri Kosina 	while (n--) {
808dde5845aSJiri Kosina 		if (*array++ == value)
809dde5845aSJiri Kosina 			return 0;
810dde5845aSJiri Kosina 	}
811dde5845aSJiri Kosina 	return -1;
812dde5845aSJiri Kosina }
813dde5845aSJiri Kosina 
81485cdaf52SJiri Slaby /**
81585cdaf52SJiri Slaby  * hid_match_report - check if driver's raw_event should be called
81685cdaf52SJiri Slaby  *
81785cdaf52SJiri Slaby  * @hid: hid device
81885cdaf52SJiri Slaby  * @report_type: type to match against
81985cdaf52SJiri Slaby  *
82085cdaf52SJiri Slaby  * compare hid->driver->report_table->report_type to report->type
82185cdaf52SJiri Slaby  */
82285cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report)
823dde5845aSJiri Kosina {
82485cdaf52SJiri Slaby 	const struct hid_report_id *id = hid->driver->report_table;
82585cdaf52SJiri Slaby 
82685cdaf52SJiri Slaby 	if (!id) /* NULL means all */
82785cdaf52SJiri Slaby 		return 1;
82885cdaf52SJiri Slaby 
82985cdaf52SJiri Slaby 	for (; id->report_type != HID_TERMINATOR; id++)
83085cdaf52SJiri Slaby 		if (id->report_type == HID_ANY_ID ||
83185cdaf52SJiri Slaby 				id->report_type == report->type)
83285cdaf52SJiri Slaby 			return 1;
83385cdaf52SJiri Slaby 	return 0;
83485cdaf52SJiri Slaby }
83585cdaf52SJiri Slaby 
83685cdaf52SJiri Slaby /**
83785cdaf52SJiri Slaby  * hid_match_usage - check if driver's event should be called
83885cdaf52SJiri Slaby  *
83985cdaf52SJiri Slaby  * @hid: hid device
84085cdaf52SJiri Slaby  * @usage: usage to match against
84185cdaf52SJiri Slaby  *
84285cdaf52SJiri Slaby  * compare hid->driver->usage_table->usage_{type,code} to
84385cdaf52SJiri Slaby  * usage->usage_{type,code}
84485cdaf52SJiri Slaby  */
84585cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
84685cdaf52SJiri Slaby {
84785cdaf52SJiri Slaby 	const struct hid_usage_id *id = hid->driver->usage_table;
84885cdaf52SJiri Slaby 
84985cdaf52SJiri Slaby 	if (!id) /* NULL means all */
85085cdaf52SJiri Slaby 		return 1;
85185cdaf52SJiri Slaby 
85285cdaf52SJiri Slaby 	for (; id->usage_type != HID_ANY_ID - 1; id++)
85385cdaf52SJiri Slaby 		if ((id->usage_hid == HID_ANY_ID ||
85485cdaf52SJiri Slaby 				id->usage_hid == usage->hid) &&
85585cdaf52SJiri Slaby 				(id->usage_type == HID_ANY_ID ||
85685cdaf52SJiri Slaby 				id->usage_type == usage->type) &&
85785cdaf52SJiri Slaby 				(id->usage_code == HID_ANY_ID ||
85885cdaf52SJiri Slaby 				 id->usage_code == usage->code))
85985cdaf52SJiri Slaby 			return 1;
86085cdaf52SJiri Slaby 	return 0;
86185cdaf52SJiri Slaby }
86285cdaf52SJiri Slaby 
86385cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field,
86485cdaf52SJiri Slaby 		struct hid_usage *usage, __s32 value, int interrupt)
86585cdaf52SJiri Slaby {
86685cdaf52SJiri Slaby 	struct hid_driver *hdrv = hid->driver;
86785cdaf52SJiri Slaby 	int ret;
86885cdaf52SJiri Slaby 
869cd667ce2SJiri Kosina 	hid_dump_input(hid, usage, value);
87085cdaf52SJiri Slaby 
87185cdaf52SJiri Slaby 	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
87285cdaf52SJiri Slaby 		ret = hdrv->event(hid, field, usage, value);
87385cdaf52SJiri Slaby 		if (ret != 0) {
87485cdaf52SJiri Slaby 			if (ret < 0)
87585cdaf52SJiri Slaby 				dbg_hid("%s's event failed with %d\n",
87685cdaf52SJiri Slaby 						hdrv->name, ret);
87785cdaf52SJiri Slaby 			return;
87885cdaf52SJiri Slaby 		}
87985cdaf52SJiri Slaby 	}
88085cdaf52SJiri Slaby 
881dde5845aSJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
882dde5845aSJiri Kosina 		hidinput_hid_event(hid, field, usage, value);
883aa938f79SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
884aa938f79SJiri Kosina 		hid->hiddev_hid_event(hid, field, usage, value);
885dde5845aSJiri Kosina }
886dde5845aSJiri Kosina 
887dde5845aSJiri Kosina /*
888dde5845aSJiri Kosina  * Analyse a received field, and fetch the data from it. The field
889dde5845aSJiri Kosina  * content is stored for next report processing (we do differential
890dde5845aSJiri Kosina  * reporting to the layer).
891dde5845aSJiri Kosina  */
892dde5845aSJiri Kosina 
893abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field,
894abdff0f7SAdrian Bunk 			    __u8 *data, int interrupt)
895dde5845aSJiri Kosina {
896dde5845aSJiri Kosina 	unsigned n;
897dde5845aSJiri Kosina 	unsigned count = field->report_count;
898dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
899dde5845aSJiri Kosina 	unsigned size = field->report_size;
900dde5845aSJiri Kosina 	__s32 min = field->logical_minimum;
901dde5845aSJiri Kosina 	__s32 max = field->logical_maximum;
902dde5845aSJiri Kosina 	__s32 *value;
903dde5845aSJiri Kosina 
904a3789a17SJoe Perches 	value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
905a3789a17SJoe Perches 	if (!value)
906dde5845aSJiri Kosina 		return;
907dde5845aSJiri Kosina 
908dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
909dde5845aSJiri Kosina 
9104291ee30SJoe Perches 		value[n] = min < 0 ?
9114291ee30SJoe Perches 			snto32(extract(hid, data, offset + n * size, size),
9124291ee30SJoe Perches 			       size) :
9134291ee30SJoe Perches 			extract(hid, data, offset + n * size, size);
914dde5845aSJiri Kosina 
9154291ee30SJoe Perches 		/* Ignore report if ErrorRollOver */
9164291ee30SJoe Perches 		if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
9174291ee30SJoe Perches 		    value[n] >= min && value[n] <= max &&
9184291ee30SJoe Perches 		    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
919dde5845aSJiri Kosina 			goto exit;
920dde5845aSJiri Kosina 	}
921dde5845aSJiri Kosina 
922dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
923dde5845aSJiri Kosina 
924dde5845aSJiri Kosina 		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
925dde5845aSJiri Kosina 			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
926dde5845aSJiri Kosina 			continue;
927dde5845aSJiri Kosina 		}
928dde5845aSJiri Kosina 
929dde5845aSJiri Kosina 		if (field->value[n] >= min && field->value[n] <= max
930dde5845aSJiri Kosina 			&& field->usage[field->value[n] - min].hid
931dde5845aSJiri Kosina 			&& search(value, field->value[n], count))
932dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
933dde5845aSJiri Kosina 
934dde5845aSJiri Kosina 		if (value[n] >= min && value[n] <= max
935dde5845aSJiri Kosina 			&& field->usage[value[n] - min].hid
936dde5845aSJiri Kosina 			&& search(field->value, value[n], count))
937dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
938dde5845aSJiri Kosina 	}
939dde5845aSJiri Kosina 
940dde5845aSJiri Kosina 	memcpy(field->value, value, count * sizeof(__s32));
941dde5845aSJiri Kosina exit:
942dde5845aSJiri Kosina 	kfree(value);
943dde5845aSJiri Kosina }
944dde5845aSJiri Kosina 
945dde5845aSJiri Kosina /*
946dde5845aSJiri Kosina  * Output the field into the report.
947dde5845aSJiri Kosina  */
948dde5845aSJiri Kosina 
9494291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid,
9504291ee30SJoe Perches 			     struct hid_field *field, __u8 *data)
951dde5845aSJiri Kosina {
952dde5845aSJiri Kosina 	unsigned count = field->report_count;
953dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
954dde5845aSJiri Kosina 	unsigned size = field->report_size;
955dde5845aSJiri Kosina 	unsigned n;
956dde5845aSJiri Kosina 
957dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
958dde5845aSJiri Kosina 		if (field->logical_minimum < 0)	/* signed values */
9594291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
9604291ee30SJoe Perches 				  s32ton(field->value[n], size));
961dde5845aSJiri Kosina 		else				/* unsigned values */
9624291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
9634291ee30SJoe Perches 				  field->value[n]);
964dde5845aSJiri Kosina 	}
965dde5845aSJiri Kosina }
966dde5845aSJiri Kosina 
967dde5845aSJiri Kosina /*
968dde5845aSJiri Kosina  * Create a report.
969dde5845aSJiri Kosina  */
970dde5845aSJiri Kosina 
971229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data)
972dde5845aSJiri Kosina {
973dde5845aSJiri Kosina 	unsigned n;
974dde5845aSJiri Kosina 
975dde5845aSJiri Kosina 	if (report->id > 0)
976dde5845aSJiri Kosina 		*data++ = report->id;
977dde5845aSJiri Kosina 
97875c28df8SPete Zaitcev 	memset(data, 0, ((report->size - 1) >> 3) + 1);
979dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
9804291ee30SJoe Perches 		hid_output_field(report->device, report->field[n], data);
981dde5845aSJiri Kosina }
982229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report);
983dde5845aSJiri Kosina 
984dde5845aSJiri Kosina /*
985dde5845aSJiri Kosina  * Set a field value. The report this field belongs to has to be
986dde5845aSJiri Kosina  * created and transferred to the device, to set this value in the
987dde5845aSJiri Kosina  * device.
988dde5845aSJiri Kosina  */
989dde5845aSJiri Kosina 
990dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
991dde5845aSJiri Kosina {
992dde5845aSJiri Kosina 	unsigned size = field->report_size;
993dde5845aSJiri Kosina 
994cd667ce2SJiri Kosina 	hid_dump_input(field->report->device, field->usage + offset, value);
995dde5845aSJiri Kosina 
996dde5845aSJiri Kosina 	if (offset >= field->report_count) {
99758037eb9SJiri Kosina 		dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
998dde5845aSJiri Kosina 		return -1;
999dde5845aSJiri Kosina 	}
1000dde5845aSJiri Kosina 	if (field->logical_minimum < 0) {
1001dde5845aSJiri Kosina 		if (value != snto32(s32ton(value, size), size)) {
100258037eb9SJiri Kosina 			dbg_hid("value %d is out of range\n", value);
1003dde5845aSJiri Kosina 			return -1;
1004dde5845aSJiri Kosina 		}
1005dde5845aSJiri Kosina 	}
1006dde5845aSJiri Kosina 	field->value[offset] = value;
1007dde5845aSJiri Kosina 	return 0;
1008dde5845aSJiri Kosina }
1009229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field);
1010dde5845aSJiri Kosina 
101185cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
101285cdaf52SJiri Slaby 		const u8 *data)
101385cdaf52SJiri Slaby {
101485cdaf52SJiri Slaby 	struct hid_report *report;
101585cdaf52SJiri Slaby 	unsigned int n = 0;	/* Normally report number is 0 */
101685cdaf52SJiri Slaby 
101785cdaf52SJiri Slaby 	/* Device uses numbered reports, data[0] is report number */
101885cdaf52SJiri Slaby 	if (report_enum->numbered)
101985cdaf52SJiri Slaby 		n = *data;
102085cdaf52SJiri Slaby 
102185cdaf52SJiri Slaby 	report = report_enum->report_id_hash[n];
102285cdaf52SJiri Slaby 	if (report == NULL)
102385cdaf52SJiri Slaby 		dbg_hid("undefined report_id %u received\n", n);
102485cdaf52SJiri Slaby 
102585cdaf52SJiri Slaby 	return report;
102685cdaf52SJiri Slaby }
102785cdaf52SJiri Slaby 
102885cdaf52SJiri Slaby void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
102985cdaf52SJiri Slaby 		int interrupt)
1030aa8de2f0SJiri Kosina {
1031aa8de2f0SJiri Kosina 	struct hid_report_enum *report_enum = hid->report_enum + type;
1032aa8de2f0SJiri Kosina 	struct hid_report *report;
103385cdaf52SJiri Slaby 	unsigned int a;
103485cdaf52SJiri Slaby 	int rsize, csize = size;
103585cdaf52SJiri Slaby 	u8 *cdata = data;
1036aa8de2f0SJiri Kosina 
103785cdaf52SJiri Slaby 	report = hid_get_report(report_enum, data);
103885cdaf52SJiri Slaby 	if (!report)
103985cdaf52SJiri Slaby 		return;
1040aa8de2f0SJiri Kosina 
104185cdaf52SJiri Slaby 	if (report_enum->numbered) {
104285cdaf52SJiri Slaby 		cdata++;
104385cdaf52SJiri Slaby 		csize--;
1044aa8de2f0SJiri Kosina 	}
1045aa8de2f0SJiri Kosina 
1046aa8de2f0SJiri Kosina 	rsize = ((report->size - 1) >> 3) + 1;
1047aa8de2f0SJiri Kosina 
1048966922f2SArmando Visconti 	if (rsize > HID_MAX_BUFFER_SIZE)
1049966922f2SArmando Visconti 		rsize = HID_MAX_BUFFER_SIZE;
1050966922f2SArmando Visconti 
105185cdaf52SJiri Slaby 	if (csize < rsize) {
105285cdaf52SJiri Slaby 		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
105385cdaf52SJiri Slaby 				csize, rsize);
105485cdaf52SJiri Slaby 		memset(cdata + csize, 0, rsize - csize);
1055aa8de2f0SJiri Kosina 	}
1056aa8de2f0SJiri Kosina 
1057aa8de2f0SJiri Kosina 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1058aa8de2f0SJiri Kosina 		hid->hiddev_report_event(hid, report);
10595a38f2c7SAlan Ott 	if (hid->claimed & HID_CLAIMED_HIDRAW)
106086166b7bSJiri Kosina 		hidraw_report_event(hid, data, size);
1061aa8de2f0SJiri Kosina 
106285cdaf52SJiri Slaby 	for (a = 0; a < report->maxfield; a++)
106385cdaf52SJiri Slaby 		hid_input_field(hid, report->field[a], cdata, interrupt);
1064aa8de2f0SJiri Kosina 
1065aa8de2f0SJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1066aa8de2f0SJiri Kosina 		hidinput_report_event(hid, report);
106785cdaf52SJiri Slaby }
106885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event);
106985cdaf52SJiri Slaby 
107085cdaf52SJiri Slaby /**
107185cdaf52SJiri Slaby  * hid_input_report - report data from lower layer (usb, bt...)
107285cdaf52SJiri Slaby  *
107385cdaf52SJiri Slaby  * @hid: hid device
107485cdaf52SJiri Slaby  * @type: HID report type (HID_*_REPORT)
107585cdaf52SJiri Slaby  * @data: report contents
107685cdaf52SJiri Slaby  * @size: size of data parameter
1077ff9b00a2SJiri Kosina  * @interrupt: distinguish between interrupt and control transfers
107885cdaf52SJiri Slaby  *
107985cdaf52SJiri Slaby  * This is data entry for lower layers.
108085cdaf52SJiri Slaby  */
108185cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
108285cdaf52SJiri Slaby {
108376c317d6SJulia Lawall 	struct hid_report_enum *report_enum;
108476c317d6SJulia Lawall 	struct hid_driver *hdrv;
108585cdaf52SJiri Slaby 	struct hid_report *report;
1086cd667ce2SJiri Kosina 	char *buf;
108785cdaf52SJiri Slaby 	unsigned int i;
108885cdaf52SJiri Slaby 	int ret;
108985cdaf52SJiri Slaby 
109085cdaf52SJiri Slaby 	if (!hid || !hid->driver)
109185cdaf52SJiri Slaby 		return -ENODEV;
109276c317d6SJulia Lawall 	report_enum = hid->report_enum + type;
109376c317d6SJulia Lawall 	hdrv = hid->driver;
109485cdaf52SJiri Slaby 
109585cdaf52SJiri Slaby 	if (!size) {
109685cdaf52SJiri Slaby 		dbg_hid("empty report\n");
109785cdaf52SJiri Slaby 		return -1;
109885cdaf52SJiri Slaby 	}
109985cdaf52SJiri Slaby 
1100d1ff6522SJiri Kosina 	buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1101cd667ce2SJiri Kosina 
1102f77e347bSJiri Kosina 	if (!buf)
1103cd667ce2SJiri Kosina 		goto nomem;
110485cdaf52SJiri Slaby 
110585cdaf52SJiri Slaby 	/* dump the report */
1106cd667ce2SJiri Kosina 	snprintf(buf, HID_DEBUG_BUFSIZE - 1,
11071caea61eSJiri Kosina 			"\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
1108cd667ce2SJiri Kosina 	hid_debug_event(hid, buf);
11091caea61eSJiri Kosina 
1110cd667ce2SJiri Kosina 	for (i = 0; i < size; i++) {
1111cd667ce2SJiri Kosina 		snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1112cd667ce2SJiri Kosina 				" %02x", data[i]);
1113cd667ce2SJiri Kosina 		hid_debug_event(hid, buf);
1114cd667ce2SJiri Kosina 	}
1115cd667ce2SJiri Kosina 	hid_debug_event(hid, "\n");
1116cd667ce2SJiri Kosina 	kfree(buf);
1117cd667ce2SJiri Kosina 
1118cd667ce2SJiri Kosina nomem:
1119f77e347bSJiri Kosina 	report = hid_get_report(report_enum, data);
1120f77e347bSJiri Kosina 
1121f77e347bSJiri Kosina 	if (!report)
1122f77e347bSJiri Kosina 		return -1;
1123f77e347bSJiri Kosina 
112485cdaf52SJiri Slaby 	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
112585cdaf52SJiri Slaby 		ret = hdrv->raw_event(hid, report, data, size);
112685cdaf52SJiri Slaby 		if (ret != 0)
112785cdaf52SJiri Slaby 			return ret < 0 ? ret : 0;
112885cdaf52SJiri Slaby 	}
112985cdaf52SJiri Slaby 
113085cdaf52SJiri Slaby 	hid_report_raw_event(hid, type, data, size, interrupt);
1131aa8de2f0SJiri Kosina 
1132aa8de2f0SJiri Kosina 	return 0;
1133aa8de2f0SJiri Kosina }
1134aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report);
1135aa8de2f0SJiri Kosina 
11360f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev,
11370f37cd03SJiri Kosina 		const struct hid_device_id *id)
11380f37cd03SJiri Kosina {
11390f37cd03SJiri Kosina 	return id->bus == hdev->bus &&
11400f37cd03SJiri Kosina 		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
11410f37cd03SJiri Kosina 		(id->product == HID_ANY_ID || id->product == hdev->product);
11420f37cd03SJiri Kosina }
11430f37cd03SJiri Kosina 
11440f37cd03SJiri Kosina static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
11450f37cd03SJiri Kosina 		const struct hid_device_id *id)
11460f37cd03SJiri Kosina {
11470f37cd03SJiri Kosina 	for (; id->bus; id++)
11480f37cd03SJiri Kosina 		if (hid_match_one_id(hdev, id))
11490f37cd03SJiri Kosina 			return id;
11500f37cd03SJiri Kosina 
11510f37cd03SJiri Kosina 	return NULL;
11520f37cd03SJiri Kosina }
11530f37cd03SJiri Kosina 
11540f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = {
1155c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1156c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
11570f37cd03SJiri Kosina 	{ }
11580f37cd03SJiri Kosina };
11590f37cd03SJiri Kosina 
11600f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev)
11610f37cd03SJiri Kosina {
11620f37cd03SJiri Kosina 	return !!hid_match_id(hdev, hid_hiddev_list);
11630f37cd03SJiri Kosina }
11640f37cd03SJiri Kosina 
11656d3bfb74SAlan Ott 
11666d3bfb74SAlan Ott static ssize_t
11676d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj,
11686d3bfb74SAlan Ott 		struct bin_attribute *attr,
11696d3bfb74SAlan Ott 		char *buf, loff_t off, size_t count)
11706d3bfb74SAlan Ott {
11716d3bfb74SAlan Ott 	struct device *dev = container_of(kobj, struct device, kobj);
11726d3bfb74SAlan Ott 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
11736d3bfb74SAlan Ott 
11746d3bfb74SAlan Ott 	if (off >= hdev->rsize)
11756d3bfb74SAlan Ott 		return 0;
11766d3bfb74SAlan Ott 
11776d3bfb74SAlan Ott 	if (off + count > hdev->rsize)
11786d3bfb74SAlan Ott 		count = hdev->rsize - off;
11796d3bfb74SAlan Ott 
11806d3bfb74SAlan Ott 	memcpy(buf, hdev->rdesc + off, count);
11816d3bfb74SAlan Ott 
11826d3bfb74SAlan Ott 	return count;
11836d3bfb74SAlan Ott }
11846d3bfb74SAlan Ott 
11856d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = {
11866d3bfb74SAlan Ott 	.attr = { .name = "report_descriptor", .mode = 0444 },
11876d3bfb74SAlan Ott 	.read = read_report_descriptor,
11886d3bfb74SAlan Ott 	.size = HID_MAX_DESCRIPTOR_SIZE,
11896d3bfb74SAlan Ott };
11906d3bfb74SAlan Ott 
119193c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
119293c10132SJiri Slaby {
119393c10132SJiri Slaby 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
119493c10132SJiri Slaby 		"Joystick", "Gamepad", "Keyboard", "Keypad",
119593c10132SJiri Slaby 		"Multi-Axis Controller"
119693c10132SJiri Slaby 	};
119793c10132SJiri Slaby 	const char *type, *bus;
119893c10132SJiri Slaby 	char buf[64];
119993c10132SJiri Slaby 	unsigned int i;
120093c10132SJiri Slaby 	int len;
12016d3bfb74SAlan Ott 	int ret;
120293c10132SJiri Slaby 
1203b5e5a37eSBastien Nocera 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1204b5e5a37eSBastien Nocera 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
12053a343ee4SDaniel Mack 	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
12063a343ee4SDaniel Mack 		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
120793c10132SJiri Slaby 	if (hdev->bus != BUS_USB)
120893c10132SJiri Slaby 		connect_mask &= ~HID_CONNECT_HIDDEV;
12090f37cd03SJiri Kosina 	if (hid_hiddev(hdev))
12100f37cd03SJiri Kosina 		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
121193c10132SJiri Slaby 
121293c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
121393c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
121493c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_INPUT;
121593c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
121693c10132SJiri Slaby 			!hdev->hiddev_connect(hdev,
121793c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDDEV_FORCE))
121893c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDDEV;
121993c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
122093c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDRAW;
122193c10132SJiri Slaby 
122293c10132SJiri Slaby 	if (!hdev->claimed) {
12234291ee30SJoe Perches 		hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
122493c10132SJiri Slaby 		return -ENODEV;
122593c10132SJiri Slaby 	}
122693c10132SJiri Slaby 
122793c10132SJiri Slaby 	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
122893c10132SJiri Slaby 			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
122993c10132SJiri Slaby 		hdev->ff_init(hdev);
123093c10132SJiri Slaby 
123193c10132SJiri Slaby 	len = 0;
123293c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_INPUT)
123393c10132SJiri Slaby 		len += sprintf(buf + len, "input");
123493c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
123593c10132SJiri Slaby 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
123693c10132SJiri Slaby 				hdev->minor);
123793c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
123893c10132SJiri Slaby 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
123993c10132SJiri Slaby 				((struct hidraw *)hdev->hidraw)->minor);
124093c10132SJiri Slaby 
124193c10132SJiri Slaby 	type = "Device";
124293c10132SJiri Slaby 	for (i = 0; i < hdev->maxcollection; i++) {
124393c10132SJiri Slaby 		struct hid_collection *col = &hdev->collection[i];
124493c10132SJiri Slaby 		if (col->type == HID_COLLECTION_APPLICATION &&
124593c10132SJiri Slaby 		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
124693c10132SJiri Slaby 		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
124793c10132SJiri Slaby 			type = types[col->usage & 0xffff];
124893c10132SJiri Slaby 			break;
124993c10132SJiri Slaby 		}
125093c10132SJiri Slaby 	}
125193c10132SJiri Slaby 
125293c10132SJiri Slaby 	switch (hdev->bus) {
125393c10132SJiri Slaby 	case BUS_USB:
125493c10132SJiri Slaby 		bus = "USB";
125593c10132SJiri Slaby 		break;
125693c10132SJiri Slaby 	case BUS_BLUETOOTH:
125793c10132SJiri Slaby 		bus = "BLUETOOTH";
125893c10132SJiri Slaby 		break;
125993c10132SJiri Slaby 	default:
126093c10132SJiri Slaby 		bus = "<UNKNOWN>";
126193c10132SJiri Slaby 	}
126293c10132SJiri Slaby 
12636d3bfb74SAlan Ott 	ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
12646d3bfb74SAlan Ott 	if (ret)
12656d3bfb74SAlan Ott 		hid_warn(hdev,
12666d3bfb74SAlan Ott 			 "can't create sysfs report descriptor attribute err: %d\n", ret);
12676d3bfb74SAlan Ott 
12684291ee30SJoe Perches 	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
126993c10132SJiri Slaby 		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
127093c10132SJiri Slaby 		 type, hdev->name, hdev->phys);
127193c10132SJiri Slaby 
127293c10132SJiri Slaby 	return 0;
127393c10132SJiri Slaby }
127493c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect);
127593c10132SJiri Slaby 
1276c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev)
1277c4c259bcSJiri Kosina {
12786d3bfb74SAlan Ott 	device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1279c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_INPUT)
1280c4c259bcSJiri Kosina 		hidinput_disconnect(hdev);
1281c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1282c4c259bcSJiri Kosina 		hdev->hiddev_disconnect(hdev);
1283c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1284c4c259bcSJiri Kosina 		hidraw_disconnect(hdev);
1285c4c259bcSJiri Kosina }
1286c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect);
1287c4c259bcSJiri Kosina 
1288bae7eb33SJiri Kosina /* a list of devices for which there is a specialized driver on HID bus */
1289ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = {
1290b6353f4fSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
12916dec143aSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
129214a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
129314a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1294b7e1b203SLech Perczak 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1295c0dbcc33SSergei Kolzun 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1296e6aac342SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, USB_DEVICE_ID_ACTIONSTAR_1011) },
1297df9bcaceSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
12988c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
12998c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1300128537ceSMichael Poole 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1301a462230eSChase Douglas 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
13028c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
13038c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
13048c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
13058c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
13068c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
13078c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
13088c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
13098c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
13108c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
13118c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
13128c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1313fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1314fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1315fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
13168c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
13178c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
13188c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
13198c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
13208c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
13218c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1322ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1323ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1324ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
13258c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
13268c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
13278c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
13288c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
13298c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
13308c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1331a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1332a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1333a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
133499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
133599b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
133699b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
133799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
133899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
133999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
134047340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
134147340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
134247340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
134323aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
134423aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
134523aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
13468c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
13478c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1348eaca1386SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1349cec15a0eSRoland Baum 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1350b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1351bf280628SWayne Thomas 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1352c3dc66deSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
13535519cab4SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
135436213e1eSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1355bc5ab083SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
1356ba4d8abbSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1357272036edSFrançois Jaouen 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
13583b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
13591ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1360fcfacfd3SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1361b9e4b1e0SDennis Kügler 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
13623a370ca1SDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
136379603dc9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, USB_DEVICE_ID_CVTOUCH_SCREEN) },
13640f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
13650f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1366e8d0eab4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
13670f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1368a3b5e577SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
13693f866fbdSRichard Walmsley 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1370e05eefb9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
13710c3910c2SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
137283e44918SChris Ball 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
13734e93db23SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) },
137428906ad6SRichard Nauber 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) },
13754dd295a7SAndy Ross 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) },
137664b386eaSRichard Nauber 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1377c04abeefSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) },
137804561c5aSIgnaz Forster 	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
13791f243e30SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
13805181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1381578f3a35SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
13825572da08SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
1383ee0fbd14SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, USB_DEVICE_ID_GOODTOUCH_000f) },
13845181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
138542859e0bSLukasz Lubojanski 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1386949f8fefSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
13871e093206SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1388c2fd1a4eSCory Maccarrone 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
13895519cab4SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
13904e61f0d7SAustin Zhang 	{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
1391b2e7617eSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
1392fdf93aa3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1393177900e8SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
139479422741SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1395b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
139675b07022SChris Schlund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
13975f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
13985f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
13995f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
14005f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
14015f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
14025f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
14035f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
14045f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
14055f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
14065f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
14075f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
14082c6118e4SHendrik Iben 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1409606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1410606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1411606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1412fd30ea8cSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1413606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
141474f292caSGary Stein 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1415606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1416606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
14175623a24aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1418243b706dSChristophe Borivant 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1419fdc6807fSPeter Gundermann 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
142032c88cbcSSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1421606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
142224985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
142324985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1424df167c4aSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH) },
1425236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1426236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
142778a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
142878a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
142978a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
143078a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
143178a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
14323b8006e5SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
143394011f93SRafi Rubin 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
14346e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
14356e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
14366e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
14376e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
14386e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
14396e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
14406e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
14416e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
14426e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
14436e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
14446e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
14456e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
14466e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
14476e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
14486e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
14496e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
14506e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
14516e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1452270fdc07SHerton Ronaldo Krzesinski 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1453cd9ec30dSJohnathon Harris 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
14546ab3a9a6SJohn Sung 	{ HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) },
14551e762532SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
145649e4739aSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1457f54405dbSAlex Neblett 	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
145814bf62cdSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1459e68cc603SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
146047dbdbffSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
14610e70f97fSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
1462cb7cf3daSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
14633fce2246SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
1464980a3da6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1465b355850bSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1466d586dca0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1467bd28ce00SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
146835dca5b4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1469f9ce7c28SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1470cc6e0bbbSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1471d3fb5454SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1472b6dc7992SPascal Auriel - Stantum 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1473b6dc7992SPascal Auriel - Stantum 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
147490231e7eSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1475daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1476daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
14777a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
14787a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1479daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
14803ee8f0a2SMarkus Rathgeb 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1481daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1482d65c3768SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1483f14f526dSLev Babiev 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
148454001081SKees Bakker 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
14855e74e56dSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
1486711a680eSBruno Premont 	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
1487c64f6f93SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
148841fa9230SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1489f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1490f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1491f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
1492617b64f9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1493617b64f9SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
1494fac733f0SJussi Kivilinna 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1495ca2dcd40SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
149672a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
149700e7f964SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
149872a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
14998f1acc32SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1500daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1501daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1502a9885c8fSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
15038c19a515SJiri Slaby 
150478a849a6SJiri Slaby 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
150585cdaf52SJiri Slaby 	{ }
150685cdaf52SJiri Slaby };
150785cdaf52SJiri Slaby 
15083a6f82f7SJiri Slaby struct hid_dynid {
15093a6f82f7SJiri Slaby 	struct list_head list;
15103a6f82f7SJiri Slaby 	struct hid_device_id id;
15113a6f82f7SJiri Slaby };
15123a6f82f7SJiri Slaby 
15133a6f82f7SJiri Slaby /**
15143a6f82f7SJiri Slaby  * store_new_id - add a new HID device ID to this driver and re-probe devices
15153a6f82f7SJiri Slaby  * @driver: target device driver
15163a6f82f7SJiri Slaby  * @buf: buffer for scanning device ID data
15173a6f82f7SJiri Slaby  * @count: input size
15183a6f82f7SJiri Slaby  *
15193a6f82f7SJiri Slaby  * Adds a new dynamic hid device ID to this driver,
15203a6f82f7SJiri Slaby  * and causes the driver to probe for all devices again.
15213a6f82f7SJiri Slaby  */
15223a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf,
15233a6f82f7SJiri Slaby 		size_t count)
15243a6f82f7SJiri Slaby {
15253a6f82f7SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
15263a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
15273a6f82f7SJiri Slaby 	__u32 bus, vendor, product;
15283a6f82f7SJiri Slaby 	unsigned long driver_data = 0;
15293a6f82f7SJiri Slaby 	int ret;
15303a6f82f7SJiri Slaby 
15313a6f82f7SJiri Slaby 	ret = sscanf(buf, "%x %x %x %lx",
15323a6f82f7SJiri Slaby 			&bus, &vendor, &product, &driver_data);
15333a6f82f7SJiri Slaby 	if (ret < 3)
15343a6f82f7SJiri Slaby 		return -EINVAL;
15353a6f82f7SJiri Slaby 
15363a6f82f7SJiri Slaby 	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
15373a6f82f7SJiri Slaby 	if (!dynid)
15383a6f82f7SJiri Slaby 		return -ENOMEM;
15393a6f82f7SJiri Slaby 
15403a6f82f7SJiri Slaby 	dynid->id.bus = bus;
15413a6f82f7SJiri Slaby 	dynid->id.vendor = vendor;
15423a6f82f7SJiri Slaby 	dynid->id.product = product;
15433a6f82f7SJiri Slaby 	dynid->id.driver_data = driver_data;
15443a6f82f7SJiri Slaby 
15453a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
15463a6f82f7SJiri Slaby 	list_add_tail(&dynid->list, &hdrv->dyn_list);
15473a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
15483a6f82f7SJiri Slaby 
15493a6f82f7SJiri Slaby 	ret = 0;
15503a6f82f7SJiri Slaby 	if (get_driver(&hdrv->driver)) {
15513a6f82f7SJiri Slaby 		ret = driver_attach(&hdrv->driver);
15523a6f82f7SJiri Slaby 		put_driver(&hdrv->driver);
15533a6f82f7SJiri Slaby 	}
15543a6f82f7SJiri Slaby 
15553a6f82f7SJiri Slaby 	return ret ? : count;
15563a6f82f7SJiri Slaby }
15573a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
15583a6f82f7SJiri Slaby 
15593a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv)
15603a6f82f7SJiri Slaby {
15613a6f82f7SJiri Slaby 	struct hid_dynid *dynid, *n;
15623a6f82f7SJiri Slaby 
15633a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
15643a6f82f7SJiri Slaby 	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
15653a6f82f7SJiri Slaby 		list_del(&dynid->list);
15663a6f82f7SJiri Slaby 		kfree(dynid);
15673a6f82f7SJiri Slaby 	}
15683a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
15693a6f82f7SJiri Slaby }
15703a6f82f7SJiri Slaby 
15713a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
15723a6f82f7SJiri Slaby 		struct hid_driver *hdrv)
15733a6f82f7SJiri Slaby {
15743a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
15753a6f82f7SJiri Slaby 
15763a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
15773a6f82f7SJiri Slaby 	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
15783a6f82f7SJiri Slaby 		if (hid_match_one_id(hdev, &dynid->id)) {
15793a6f82f7SJiri Slaby 			spin_unlock(&hdrv->dyn_lock);
15803a6f82f7SJiri Slaby 			return &dynid->id;
15813a6f82f7SJiri Slaby 		}
15823a6f82f7SJiri Slaby 	}
15833a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
15843a6f82f7SJiri Slaby 
15853a6f82f7SJiri Slaby 	return hid_match_id(hdev, hdrv->id_table);
15863a6f82f7SJiri Slaby }
15873a6f82f7SJiri Slaby 
158885cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv)
158985cdaf52SJiri Slaby {
159085cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
159185cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
159285cdaf52SJiri Slaby 
15933a6f82f7SJiri Slaby 	if (!hid_match_device(hdev, hdrv))
159485cdaf52SJiri Slaby 		return 0;
159585cdaf52SJiri Slaby 
1596ce06b9d6SDmitry Torokhov 	/* generic wants all that don't have specialized driver */
159785cdaf52SJiri Slaby 	if (!strncmp(hdrv->name, "generic-", 8))
1598ce06b9d6SDmitry Torokhov 		return !hid_match_id(hdev, hid_have_special_driver);
159985cdaf52SJiri Slaby 
160085cdaf52SJiri Slaby 	return 1;
160185cdaf52SJiri Slaby }
160285cdaf52SJiri Slaby 
160385cdaf52SJiri Slaby static int hid_device_probe(struct device *dev)
160485cdaf52SJiri Slaby {
160585cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(dev->driver,
160685cdaf52SJiri Slaby 			struct hid_driver, driver);
160785cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
160885cdaf52SJiri Slaby 	const struct hid_device_id *id;
160985cdaf52SJiri Slaby 	int ret = 0;
161085cdaf52SJiri Slaby 
161185cdaf52SJiri Slaby 	if (!hdev->driver) {
16123a6f82f7SJiri Slaby 		id = hid_match_device(hdev, hdrv);
1613c500c971SJiri Slaby 		if (id == NULL)
1614c500c971SJiri Slaby 			return -ENODEV;
1615c500c971SJiri Slaby 
161685cdaf52SJiri Slaby 		hdev->driver = hdrv;
1617c500c971SJiri Slaby 		if (hdrv->probe) {
1618c500c971SJiri Slaby 			ret = hdrv->probe(hdev, id);
1619c500c971SJiri Slaby 		} else { /* default probe */
1620c500c971SJiri Slaby 			ret = hid_parse(hdev);
1621c500c971SJiri Slaby 			if (!ret)
162293c10132SJiri Slaby 				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1623c500c971SJiri Slaby 		}
1624c500c971SJiri Slaby 		if (ret)
1625c500c971SJiri Slaby 			hdev->driver = NULL;
162685cdaf52SJiri Slaby 	}
162785cdaf52SJiri Slaby 	return ret;
162885cdaf52SJiri Slaby }
162985cdaf52SJiri Slaby 
163085cdaf52SJiri Slaby static int hid_device_remove(struct device *dev)
163185cdaf52SJiri Slaby {
163285cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
163385cdaf52SJiri Slaby 	struct hid_driver *hdrv = hdev->driver;
163485cdaf52SJiri Slaby 
163585cdaf52SJiri Slaby 	if (hdrv) {
163685cdaf52SJiri Slaby 		if (hdrv->remove)
163785cdaf52SJiri Slaby 			hdrv->remove(hdev);
1638c500c971SJiri Slaby 		else /* default remove */
1639c500c971SJiri Slaby 			hid_hw_stop(hdev);
164085cdaf52SJiri Slaby 		hdev->driver = NULL;
164185cdaf52SJiri Slaby 	}
164285cdaf52SJiri Slaby 
164385cdaf52SJiri Slaby 	return 0;
164485cdaf52SJiri Slaby }
164585cdaf52SJiri Slaby 
164685cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
164785cdaf52SJiri Slaby {
164885cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
164985cdaf52SJiri Slaby 
165085cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
165185cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
165285cdaf52SJiri Slaby 		return -ENOMEM;
165385cdaf52SJiri Slaby 
165485cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
165585cdaf52SJiri Slaby 		return -ENOMEM;
165685cdaf52SJiri Slaby 
165785cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
165885cdaf52SJiri Slaby 		return -ENOMEM;
165985cdaf52SJiri Slaby 
166085cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
166185cdaf52SJiri Slaby 		return -ENOMEM;
166285cdaf52SJiri Slaby 
166385cdaf52SJiri Slaby 	if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
166485cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
166585cdaf52SJiri Slaby 		return -ENOMEM;
166685cdaf52SJiri Slaby 
166785cdaf52SJiri Slaby 	return 0;
166885cdaf52SJiri Slaby }
166985cdaf52SJiri Slaby 
167085cdaf52SJiri Slaby static struct bus_type hid_bus_type = {
167185cdaf52SJiri Slaby 	.name		= "hid",
167285cdaf52SJiri Slaby 	.match		= hid_bus_match,
167385cdaf52SJiri Slaby 	.probe		= hid_device_probe,
167485cdaf52SJiri Slaby 	.remove		= hid_device_remove,
167585cdaf52SJiri Slaby 	.uevent		= hid_uevent,
167685cdaf52SJiri Slaby };
167785cdaf52SJiri Slaby 
1678bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */
1679d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = {
1680d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1681d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1682d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1683d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1684d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1685d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1686d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1687d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1688d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1689d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1690d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1691d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
169277f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
169377f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
169462a56582SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1695d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1696d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1697d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1698d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1699d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1700d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
17015f6108cfSAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1702d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1703d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
170473bc7d31SMelchior FRANZ 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
1705d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
170670c66567SPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1707df506f2cSPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1708d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1709d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1710d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1711d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1712d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1713d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1714d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1715d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1716d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1717d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1718d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1719d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1720d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1721d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1722d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1723d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1724d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1725d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1726d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1727d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1728d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1729d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1730d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1731d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1732d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1733d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1734d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1735d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1736d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1737d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1738d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1739d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1740d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1741d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1742d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1743d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1744d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1745d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1746d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1747d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1748d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1749d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1750d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1751d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1752d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1753d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1754d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1755d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1756d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1757d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1758d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1759d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1760d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1761d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1762d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1763d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1764d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1765d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1766d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1767d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1768d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1769d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1770d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1771d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1772d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1773c91c21c5SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1774d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1775eb8141ccSLamarque Vieira Souza 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1776d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1777ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
1778d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1779ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
1780d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1781ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
1782ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
1783ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
1784ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
1785ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
1786ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
1787d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1788d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1789d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1790ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
1791ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
1792ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
1793d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1794d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1795ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
1796d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1797d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1798d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1799d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1800d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1801ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
1802ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
1803ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
1804ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
1805ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
1806ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
1807ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
1808d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1809d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1810d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1811d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1812d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1813d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1814d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1815d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1816d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1817d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1818d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1819d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1820d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1821d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1822d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1823d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1824d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1825d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1826d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
18274cfae3e8SHenning Glawe 	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
182835cfd1d9SMichael Tokarev 	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1829d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1830d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1831d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1832d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1833d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1834d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1835d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1836d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1837d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1838d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1839d458a9dfSJiri Slaby 	{ }
1840d458a9dfSJiri Slaby };
1841d458a9dfSJiri Slaby 
1842b4d8e473SJiri Slaby /**
1843b4d8e473SJiri Slaby  * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1844b4d8e473SJiri Slaby  *
1845b4d8e473SJiri Slaby  * There are composite devices for which we want to ignore only a certain
1846b4d8e473SJiri Slaby  * interface. This is a list of devices for which only the mouse interface will
1847b4d8e473SJiri Slaby  * be ignored. This allows a dedicated driver to take care of the interface.
1848b4d8e473SJiri Slaby  */
1849b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = {
1850b4d8e473SJiri Slaby 	/* appletouch driver */
1851b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1852b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1853b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1854b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1855b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1856b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1857b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1858b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1859b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1860b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1861b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1862b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1863b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1864b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1865b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1866b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1867b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1868b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1869b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1870b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1871ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1872ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1873ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
187499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
187599b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
187699b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
187799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
187899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
187999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
188047340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
188147340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
188247340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1883b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1884b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1885b4d8e473SJiri Slaby 	{ }
1886b4d8e473SJiri Slaby };
1887b4d8e473SJiri Slaby 
1888d458a9dfSJiri Slaby static bool hid_ignore(struct hid_device *hdev)
1889d458a9dfSJiri Slaby {
1890d458a9dfSJiri Slaby 	switch (hdev->vendor) {
1891d458a9dfSJiri Slaby 	case USB_VENDOR_ID_CODEMERCS:
1892d458a9dfSJiri Slaby 		/* ignore all Code Mercenaries IOWarrior devices */
1893d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1894d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1895d458a9dfSJiri Slaby 			return true;
1896d458a9dfSJiri Slaby 		break;
1897d458a9dfSJiri Slaby 	case USB_VENDOR_ID_LOGITECH:
1898d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1899d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1900d458a9dfSJiri Slaby 			return true;
1901d458a9dfSJiri Slaby 		break;
190231f7fd79SJarod Wilson 	case USB_VENDOR_ID_SOUNDGRAPH:
190331f7fd79SJarod Wilson 		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
190431f7fd79SJarod Wilson 		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
190531f7fd79SJarod Wilson 			return true;
190631f7fd79SJarod Wilson 		break;
1907bba5394aSXing Wei 	case USB_VENDOR_ID_HANWANG:
1908bba5394aSXing Wei 		if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
1909bba5394aSXing Wei 		    hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
1910bba5394aSXing Wei 			return true;
1911bba5394aSXing Wei 		break;
1912*6dc1418eSTomoki Sekiyama 	case USB_VENDOR_ID_JESS:
1913*6dc1418eSTomoki Sekiyama 		if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
1914*6dc1418eSTomoki Sekiyama 				hdev->type == HID_TYPE_USBNONE)
1915*6dc1418eSTomoki Sekiyama 			return true;
1916*6dc1418eSTomoki Sekiyama 	break;
1917d458a9dfSJiri Slaby 	}
1918d458a9dfSJiri Slaby 
1919b4d8e473SJiri Slaby 	if (hdev->type == HID_TYPE_USBMOUSE &&
1920b4d8e473SJiri Slaby 			hid_match_id(hdev, hid_mouse_ignore_list))
1921b4d8e473SJiri Slaby 		return true;
1922b4d8e473SJiri Slaby 
1923d458a9dfSJiri Slaby 	return !!hid_match_id(hdev, hid_ignore_list);
1924d458a9dfSJiri Slaby }
1925d458a9dfSJiri Slaby 
192685cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev)
192785cdaf52SJiri Slaby {
192885cdaf52SJiri Slaby 	static atomic_t id = ATOMIC_INIT(0);
192985cdaf52SJiri Slaby 	int ret;
193085cdaf52SJiri Slaby 
193185cdaf52SJiri Slaby 	if (WARN_ON(hdev->status & HID_STAT_ADDED))
193285cdaf52SJiri Slaby 		return -EBUSY;
193385cdaf52SJiri Slaby 
1934d458a9dfSJiri Slaby 	/* we need to kill them here, otherwise they will stay allocated to
1935d458a9dfSJiri Slaby 	 * wait for coming driver */
1936e5a2a04cSJindrich Makovicka 	if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1937e5a2a04cSJindrich Makovicka             && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
1938d458a9dfSJiri Slaby 		return -ENODEV;
1939d458a9dfSJiri Slaby 
19406bbe586fSKay Sievers 	/* XXX hack, any other cleaner solution after the driver core
19416bbe586fSKay Sievers 	 * is converted to allow more than 20 bytes as the device name? */
19426bbe586fSKay Sievers 	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
194385cdaf52SJiri Slaby 		     hdev->vendor, hdev->product, atomic_inc_return(&id));
194485cdaf52SJiri Slaby 
19454da361b6SBruno Prémont 	hid_debug_register(hdev, dev_name(&hdev->dev));
194685cdaf52SJiri Slaby 	ret = device_add(&hdev->dev);
194785cdaf52SJiri Slaby 	if (!ret)
194885cdaf52SJiri Slaby 		hdev->status |= HID_STAT_ADDED;
19494da361b6SBruno Prémont 	else
19504da361b6SBruno Prémont 		hid_debug_unregister(hdev);
1951a635f9ddSJiri Kosina 
195285cdaf52SJiri Slaby 	return ret;
195385cdaf52SJiri Slaby }
195485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device);
195585cdaf52SJiri Slaby 
195685cdaf52SJiri Slaby /**
195785cdaf52SJiri Slaby  * hid_allocate_device - allocate new hid device descriptor
195885cdaf52SJiri Slaby  *
195985cdaf52SJiri Slaby  * Allocate and initialize hid device, so that hid_destroy_device might be
196085cdaf52SJiri Slaby  * used to free it.
196185cdaf52SJiri Slaby  *
196285cdaf52SJiri Slaby  * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
196385cdaf52SJiri Slaby  * error value.
196485cdaf52SJiri Slaby  */
196585cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void)
196685cdaf52SJiri Slaby {
196785cdaf52SJiri Slaby 	struct hid_device *hdev;
196885cdaf52SJiri Slaby 	unsigned int i;
196985cdaf52SJiri Slaby 	int ret = -ENOMEM;
197085cdaf52SJiri Slaby 
197185cdaf52SJiri Slaby 	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
197285cdaf52SJiri Slaby 	if (hdev == NULL)
197385cdaf52SJiri Slaby 		return ERR_PTR(ret);
197485cdaf52SJiri Slaby 
197585cdaf52SJiri Slaby 	device_initialize(&hdev->dev);
197685cdaf52SJiri Slaby 	hdev->dev.release = hid_device_release;
197785cdaf52SJiri Slaby 	hdev->dev.bus = &hid_bus_type;
197885cdaf52SJiri Slaby 
197985cdaf52SJiri Slaby 	hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
198085cdaf52SJiri Slaby 			sizeof(struct hid_collection), GFP_KERNEL);
198185cdaf52SJiri Slaby 	if (hdev->collection == NULL)
198285cdaf52SJiri Slaby 		goto err;
198385cdaf52SJiri Slaby 	hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
198485cdaf52SJiri Slaby 
198585cdaf52SJiri Slaby 	for (i = 0; i < HID_REPORT_TYPES; i++)
198685cdaf52SJiri Slaby 		INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
198785cdaf52SJiri Slaby 
1988cd667ce2SJiri Kosina 	init_waitqueue_head(&hdev->debug_wait);
1989cd667ce2SJiri Kosina 	INIT_LIST_HEAD(&hdev->debug_list);
1990cd667ce2SJiri Kosina 
199185cdaf52SJiri Slaby 	return hdev;
199285cdaf52SJiri Slaby err:
199385cdaf52SJiri Slaby 	put_device(&hdev->dev);
199485cdaf52SJiri Slaby 	return ERR_PTR(ret);
199585cdaf52SJiri Slaby }
199685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device);
199785cdaf52SJiri Slaby 
199885cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev)
199985cdaf52SJiri Slaby {
200085cdaf52SJiri Slaby 	if (hdev->status & HID_STAT_ADDED) {
200185cdaf52SJiri Slaby 		device_del(&hdev->dev);
2002a635f9ddSJiri Kosina 		hid_debug_unregister(hdev);
200385cdaf52SJiri Slaby 		hdev->status &= ~HID_STAT_ADDED;
200485cdaf52SJiri Slaby 	}
200585cdaf52SJiri Slaby }
200685cdaf52SJiri Slaby 
200785cdaf52SJiri Slaby /**
200885cdaf52SJiri Slaby  * hid_destroy_device - free previously allocated device
200985cdaf52SJiri Slaby  *
201085cdaf52SJiri Slaby  * @hdev: hid device
201185cdaf52SJiri Slaby  *
201285cdaf52SJiri Slaby  * If you allocate hid_device through hid_allocate_device, you should ever
201385cdaf52SJiri Slaby  * free by this function.
201485cdaf52SJiri Slaby  */
201585cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev)
201685cdaf52SJiri Slaby {
201785cdaf52SJiri Slaby 	hid_remove_device(hdev);
201885cdaf52SJiri Slaby 	put_device(&hdev->dev);
201985cdaf52SJiri Slaby }
202085cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device);
202185cdaf52SJiri Slaby 
202285cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
202385cdaf52SJiri Slaby 		const char *mod_name)
202485cdaf52SJiri Slaby {
20253a6f82f7SJiri Slaby 	int ret;
20263a6f82f7SJiri Slaby 
202785cdaf52SJiri Slaby 	hdrv->driver.name = hdrv->name;
202885cdaf52SJiri Slaby 	hdrv->driver.bus = &hid_bus_type;
202985cdaf52SJiri Slaby 	hdrv->driver.owner = owner;
203085cdaf52SJiri Slaby 	hdrv->driver.mod_name = mod_name;
203185cdaf52SJiri Slaby 
20323a6f82f7SJiri Slaby 	INIT_LIST_HEAD(&hdrv->dyn_list);
20333a6f82f7SJiri Slaby 	spin_lock_init(&hdrv->dyn_lock);
20343a6f82f7SJiri Slaby 
20353a6f82f7SJiri Slaby 	ret = driver_register(&hdrv->driver);
20363a6f82f7SJiri Slaby 	if (ret)
20373a6f82f7SJiri Slaby 		return ret;
20383a6f82f7SJiri Slaby 
20393a6f82f7SJiri Slaby 	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
20403a6f82f7SJiri Slaby 	if (ret)
20413a6f82f7SJiri Slaby 		driver_unregister(&hdrv->driver);
20423a6f82f7SJiri Slaby 
20433a6f82f7SJiri Slaby 	return ret;
204485cdaf52SJiri Slaby }
204585cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver);
204685cdaf52SJiri Slaby 
204785cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv)
204885cdaf52SJiri Slaby {
20493a6f82f7SJiri Slaby 	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
205085cdaf52SJiri Slaby 	driver_unregister(&hdrv->driver);
20513a6f82f7SJiri Slaby 	hid_free_dynids(hdrv);
205285cdaf52SJiri Slaby }
205385cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver);
205485cdaf52SJiri Slaby 
20550361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid)
20560361a28dSOliver Neukum {
20570361a28dSOliver Neukum 	struct hid_input *hidinput;
20580361a28dSOliver Neukum 	int i;
20590361a28dSOliver Neukum 
2060e5288eb5SJiri Kosina 	if (!(hid->claimed & HID_CLAIMED_INPUT))
2061e5288eb5SJiri Kosina 		return 0;
2062e5288eb5SJiri Kosina 
20630361a28dSOliver Neukum 	list_for_each_entry(hidinput, &hid->inputs, list) {
20640361a28dSOliver Neukum 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
20650361a28dSOliver Neukum 			if (hidinput->input->key[i])
20660361a28dSOliver Neukum 				return 1;
20670361a28dSOliver Neukum 	}
20680361a28dSOliver Neukum 
20690361a28dSOliver Neukum 	return 0;
20700361a28dSOliver Neukum }
20710361a28dSOliver Neukum 
20720361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
20730361a28dSOliver Neukum 
207486166b7bSJiri Kosina static int __init hid_init(void)
207586166b7bSJiri Kosina {
207685cdaf52SJiri Slaby 	int ret;
207785cdaf52SJiri Slaby 
2078a635f9ddSJiri Kosina 	if (hid_debug)
20794291ee30SJoe Perches 		pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
20804291ee30SJoe Perches 			"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2081a635f9ddSJiri Kosina 
208285cdaf52SJiri Slaby 	ret = bus_register(&hid_bus_type);
208385cdaf52SJiri Slaby 	if (ret) {
20844291ee30SJoe Perches 		pr_err("can't register hid bus\n");
208585cdaf52SJiri Slaby 		goto err;
208685cdaf52SJiri Slaby 	}
208785cdaf52SJiri Slaby 
208885cdaf52SJiri Slaby 	ret = hidraw_init();
208985cdaf52SJiri Slaby 	if (ret)
209085cdaf52SJiri Slaby 		goto err_bus;
209185cdaf52SJiri Slaby 
2092a635f9ddSJiri Kosina 	hid_debug_init();
2093a635f9ddSJiri Kosina 
209485cdaf52SJiri Slaby 	return 0;
209585cdaf52SJiri Slaby err_bus:
209685cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
209785cdaf52SJiri Slaby err:
209885cdaf52SJiri Slaby 	return ret;
209986166b7bSJiri Kosina }
210086166b7bSJiri Kosina 
210186166b7bSJiri Kosina static void __exit hid_exit(void)
210286166b7bSJiri Kosina {
2103a635f9ddSJiri Kosina 	hid_debug_exit();
210486166b7bSJiri Kosina 	hidraw_exit();
210585cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
210686166b7bSJiri Kosina }
210786166b7bSJiri Kosina 
210886166b7bSJiri Kosina module_init(hid_init);
210986166b7bSJiri Kosina module_exit(hid_exit);
211086166b7bSJiri Kosina 
211188adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal");
211288adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik");
211388adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina");
2114aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
2115aa938f79SJiri Kosina 
2116