xref: /openbmc/linux/drivers/hid/hid-core.c (revision b9e4b1e0cd401e915e3ba97afc152946f78f9f0b)
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 
17dde5845aSJiri Kosina #include <linux/module.h>
18dde5845aSJiri Kosina #include <linux/slab.h>
19dde5845aSJiri Kosina #include <linux/init.h>
20dde5845aSJiri Kosina #include <linux/kernel.h>
21dde5845aSJiri Kosina #include <linux/list.h>
22dde5845aSJiri Kosina #include <linux/mm.h>
23dde5845aSJiri Kosina #include <linux/spinlock.h>
24dde5845aSJiri Kosina #include <asm/unaligned.h>
25dde5845aSJiri Kosina #include <asm/byteorder.h>
26dde5845aSJiri Kosina #include <linux/input.h>
27dde5845aSJiri Kosina #include <linux/wait.h>
2847a80edbSJiri Kosina #include <linux/vmalloc.h>
29c4124c9bSJiri Kosina #include <linux/sched.h>
30dde5845aSJiri Kosina 
31dde5845aSJiri Kosina #include <linux/hid.h>
32dde5845aSJiri Kosina #include <linux/hiddev.h>
33c080d89aSJiri Kosina #include <linux/hid-debug.h>
3486166b7bSJiri Kosina #include <linux/hidraw.h>
35dde5845aSJiri Kosina 
365f22a799SJiri Slaby #include "hid-ids.h"
375f22a799SJiri Slaby 
38dde5845aSJiri Kosina /*
39dde5845aSJiri Kosina  * Version Information
40dde5845aSJiri Kosina  */
41dde5845aSJiri Kosina 
4253149801SJiri Kosina #define DRIVER_DESC "HID core driver"
43dde5845aSJiri Kosina #define DRIVER_LICENSE "GPL"
44dde5845aSJiri Kosina 
4558037eb9SJiri Kosina int hid_debug = 0;
46377e10fbSAnssi Hannula module_param_named(debug, hid_debug, int, 0600);
47cd667ce2SJiri Kosina MODULE_PARM_DESC(debug, "toggle HID debugging messages");
4858037eb9SJiri Kosina EXPORT_SYMBOL_GPL(hid_debug);
4958037eb9SJiri Kosina 
50dde5845aSJiri Kosina /*
51dde5845aSJiri Kosina  * Register a new report for a device.
52dde5845aSJiri Kosina  */
53dde5845aSJiri Kosina 
5490a006abSMichael Poole struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
55dde5845aSJiri Kosina {
56dde5845aSJiri Kosina 	struct hid_report_enum *report_enum = device->report_enum + type;
57dde5845aSJiri Kosina 	struct hid_report *report;
58dde5845aSJiri Kosina 
59dde5845aSJiri Kosina 	if (report_enum->report_id_hash[id])
60dde5845aSJiri Kosina 		return report_enum->report_id_hash[id];
61dde5845aSJiri Kosina 
62dde5845aSJiri Kosina 	if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
63dde5845aSJiri Kosina 		return NULL;
64dde5845aSJiri Kosina 
65dde5845aSJiri Kosina 	if (id != 0)
66dde5845aSJiri Kosina 		report_enum->numbered = 1;
67dde5845aSJiri Kosina 
68dde5845aSJiri Kosina 	report->id = id;
69dde5845aSJiri Kosina 	report->type = type;
70dde5845aSJiri Kosina 	report->size = 0;
71dde5845aSJiri Kosina 	report->device = device;
72dde5845aSJiri Kosina 	report_enum->report_id_hash[id] = report;
73dde5845aSJiri Kosina 
74dde5845aSJiri Kosina 	list_add_tail(&report->list, &report_enum->report_list);
75dde5845aSJiri Kosina 
76dde5845aSJiri Kosina 	return report;
77dde5845aSJiri Kosina }
7890a006abSMichael Poole EXPORT_SYMBOL_GPL(hid_register_report);
79dde5845aSJiri Kosina 
80dde5845aSJiri Kosina /*
81dde5845aSJiri Kosina  * Register a new field for this report.
82dde5845aSJiri Kosina  */
83dde5845aSJiri Kosina 
84dde5845aSJiri Kosina static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
85dde5845aSJiri Kosina {
86dde5845aSJiri Kosina 	struct hid_field *field;
87dde5845aSJiri Kosina 
88dde5845aSJiri Kosina 	if (report->maxfield == HID_MAX_FIELDS) {
8958037eb9SJiri Kosina 		dbg_hid("too many fields in report\n");
90dde5845aSJiri Kosina 		return NULL;
91dde5845aSJiri Kosina 	}
92dde5845aSJiri Kosina 
93dde5845aSJiri Kosina 	if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
94dde5845aSJiri Kosina 		+ values * sizeof(unsigned), GFP_KERNEL))) return NULL;
95dde5845aSJiri Kosina 
96dde5845aSJiri Kosina 	field->index = report->maxfield++;
97dde5845aSJiri Kosina 	report->field[field->index] = field;
98dde5845aSJiri Kosina 	field->usage = (struct hid_usage *)(field + 1);
99282bfd4cSJiri Slaby 	field->value = (s32 *)(field->usage + usages);
100dde5845aSJiri Kosina 	field->report = report;
101dde5845aSJiri Kosina 
102dde5845aSJiri Kosina 	return field;
103dde5845aSJiri Kosina }
104dde5845aSJiri Kosina 
105dde5845aSJiri Kosina /*
106dde5845aSJiri Kosina  * Open a collection. The type/usage is pushed on the stack.
107dde5845aSJiri Kosina  */
108dde5845aSJiri Kosina 
109dde5845aSJiri Kosina static int open_collection(struct hid_parser *parser, unsigned type)
110dde5845aSJiri Kosina {
111dde5845aSJiri Kosina 	struct hid_collection *collection;
112dde5845aSJiri Kosina 	unsigned usage;
113dde5845aSJiri Kosina 
114dde5845aSJiri Kosina 	usage = parser->local.usage[0];
115dde5845aSJiri Kosina 
116dde5845aSJiri Kosina 	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
11758037eb9SJiri Kosina 		dbg_hid("collection stack overflow\n");
118dde5845aSJiri Kosina 		return -1;
119dde5845aSJiri Kosina 	}
120dde5845aSJiri Kosina 
121dde5845aSJiri Kosina 	if (parser->device->maxcollection == parser->device->collection_size) {
122dde5845aSJiri Kosina 		collection = kmalloc(sizeof(struct hid_collection) *
123dde5845aSJiri Kosina 				parser->device->collection_size * 2, GFP_KERNEL);
124dde5845aSJiri Kosina 		if (collection == NULL) {
12558037eb9SJiri Kosina 			dbg_hid("failed to reallocate collection array\n");
126dde5845aSJiri Kosina 			return -1;
127dde5845aSJiri Kosina 		}
128dde5845aSJiri Kosina 		memcpy(collection, parser->device->collection,
129dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
130dde5845aSJiri Kosina 			parser->device->collection_size);
131dde5845aSJiri Kosina 		memset(collection + parser->device->collection_size, 0,
132dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
133dde5845aSJiri Kosina 			parser->device->collection_size);
134dde5845aSJiri Kosina 		kfree(parser->device->collection);
135dde5845aSJiri Kosina 		parser->device->collection = collection;
136dde5845aSJiri Kosina 		parser->device->collection_size *= 2;
137dde5845aSJiri Kosina 	}
138dde5845aSJiri Kosina 
139dde5845aSJiri Kosina 	parser->collection_stack[parser->collection_stack_ptr++] =
140dde5845aSJiri Kosina 		parser->device->maxcollection;
141dde5845aSJiri Kosina 
142dde5845aSJiri Kosina 	collection = parser->device->collection +
143dde5845aSJiri Kosina 		parser->device->maxcollection++;
144dde5845aSJiri Kosina 	collection->type = type;
145dde5845aSJiri Kosina 	collection->usage = usage;
146dde5845aSJiri Kosina 	collection->level = parser->collection_stack_ptr - 1;
147dde5845aSJiri Kosina 
148dde5845aSJiri Kosina 	if (type == HID_COLLECTION_APPLICATION)
149dde5845aSJiri Kosina 		parser->device->maxapplication++;
150dde5845aSJiri Kosina 
151dde5845aSJiri Kosina 	return 0;
152dde5845aSJiri Kosina }
153dde5845aSJiri Kosina 
154dde5845aSJiri Kosina /*
155dde5845aSJiri Kosina  * Close a collection.
156dde5845aSJiri Kosina  */
157dde5845aSJiri Kosina 
158dde5845aSJiri Kosina static int close_collection(struct hid_parser *parser)
159dde5845aSJiri Kosina {
160dde5845aSJiri Kosina 	if (!parser->collection_stack_ptr) {
16158037eb9SJiri Kosina 		dbg_hid("collection stack underflow\n");
162dde5845aSJiri Kosina 		return -1;
163dde5845aSJiri Kosina 	}
164dde5845aSJiri Kosina 	parser->collection_stack_ptr--;
165dde5845aSJiri Kosina 	return 0;
166dde5845aSJiri Kosina }
167dde5845aSJiri Kosina 
168dde5845aSJiri Kosina /*
169dde5845aSJiri Kosina  * Climb up the stack, search for the specified collection type
170dde5845aSJiri Kosina  * and return the usage.
171dde5845aSJiri Kosina  */
172dde5845aSJiri Kosina 
173dde5845aSJiri Kosina static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
174dde5845aSJiri Kosina {
175dde5845aSJiri Kosina 	int n;
176dde5845aSJiri Kosina 	for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
177dde5845aSJiri Kosina 		if (parser->device->collection[parser->collection_stack[n]].type == type)
178dde5845aSJiri Kosina 			return parser->device->collection[parser->collection_stack[n]].usage;
179dde5845aSJiri Kosina 	return 0; /* we know nothing about this usage type */
180dde5845aSJiri Kosina }
181dde5845aSJiri Kosina 
182dde5845aSJiri Kosina /*
183dde5845aSJiri Kosina  * Add a usage to the temporary parser table.
184dde5845aSJiri Kosina  */
185dde5845aSJiri Kosina 
186dde5845aSJiri Kosina static int hid_add_usage(struct hid_parser *parser, unsigned usage)
187dde5845aSJiri Kosina {
188dde5845aSJiri Kosina 	if (parser->local.usage_index >= HID_MAX_USAGES) {
18958037eb9SJiri Kosina 		dbg_hid("usage index exceeded\n");
190dde5845aSJiri Kosina 		return -1;
191dde5845aSJiri Kosina 	}
192dde5845aSJiri Kosina 	parser->local.usage[parser->local.usage_index] = usage;
193dde5845aSJiri Kosina 	parser->local.collection_index[parser->local.usage_index] =
194dde5845aSJiri Kosina 		parser->collection_stack_ptr ?
195dde5845aSJiri Kosina 		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
196dde5845aSJiri Kosina 	parser->local.usage_index++;
197dde5845aSJiri Kosina 	return 0;
198dde5845aSJiri Kosina }
199dde5845aSJiri Kosina 
200dde5845aSJiri Kosina /*
201dde5845aSJiri Kosina  * Register a new field for this report.
202dde5845aSJiri Kosina  */
203dde5845aSJiri Kosina 
204dde5845aSJiri Kosina static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
205dde5845aSJiri Kosina {
206dde5845aSJiri Kosina 	struct hid_report *report;
207dde5845aSJiri Kosina 	struct hid_field *field;
208dde5845aSJiri Kosina 	int usages;
209dde5845aSJiri Kosina 	unsigned offset;
210dde5845aSJiri Kosina 	int i;
211dde5845aSJiri Kosina 
212dde5845aSJiri Kosina 	if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
21358037eb9SJiri Kosina 		dbg_hid("hid_register_report failed\n");
214dde5845aSJiri Kosina 		return -1;
215dde5845aSJiri Kosina 	}
216dde5845aSJiri Kosina 
217dde5845aSJiri Kosina 	if (parser->global.logical_maximum < parser->global.logical_minimum) {
21858037eb9SJiri Kosina 		dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
219dde5845aSJiri Kosina 		return -1;
220dde5845aSJiri Kosina 	}
221dde5845aSJiri Kosina 
222dde5845aSJiri Kosina 	offset = report->size;
223dde5845aSJiri Kosina 	report->size += parser->global.report_size * parser->global.report_count;
224dde5845aSJiri Kosina 
225dde5845aSJiri Kosina 	if (!parser->local.usage_index) /* Ignore padding fields */
226dde5845aSJiri Kosina 		return 0;
227dde5845aSJiri Kosina 
228dde5845aSJiri Kosina 	usages = max_t(int, parser->local.usage_index, parser->global.report_count);
229dde5845aSJiri Kosina 
230dde5845aSJiri Kosina 	if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
231dde5845aSJiri Kosina 		return 0;
232dde5845aSJiri Kosina 
233dde5845aSJiri Kosina 	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
234dde5845aSJiri Kosina 	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
235dde5845aSJiri Kosina 	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
236dde5845aSJiri Kosina 
237dde5845aSJiri Kosina 	for (i = 0; i < usages; i++) {
238dde5845aSJiri Kosina 		int j = i;
239dde5845aSJiri Kosina 		/* Duplicate the last usage we parsed if we have excess values */
240dde5845aSJiri Kosina 		if (i >= parser->local.usage_index)
241dde5845aSJiri Kosina 			j = parser->local.usage_index - 1;
242dde5845aSJiri Kosina 		field->usage[i].hid = parser->local.usage[j];
243dde5845aSJiri Kosina 		field->usage[i].collection_index =
244dde5845aSJiri Kosina 			parser->local.collection_index[j];
245dde5845aSJiri Kosina 	}
246dde5845aSJiri Kosina 
247dde5845aSJiri Kosina 	field->maxusage = usages;
248dde5845aSJiri Kosina 	field->flags = flags;
249dde5845aSJiri Kosina 	field->report_offset = offset;
250dde5845aSJiri Kosina 	field->report_type = report_type;
251dde5845aSJiri Kosina 	field->report_size = parser->global.report_size;
252dde5845aSJiri Kosina 	field->report_count = parser->global.report_count;
253dde5845aSJiri Kosina 	field->logical_minimum = parser->global.logical_minimum;
254dde5845aSJiri Kosina 	field->logical_maximum = parser->global.logical_maximum;
255dde5845aSJiri Kosina 	field->physical_minimum = parser->global.physical_minimum;
256dde5845aSJiri Kosina 	field->physical_maximum = parser->global.physical_maximum;
257dde5845aSJiri Kosina 	field->unit_exponent = parser->global.unit_exponent;
258dde5845aSJiri Kosina 	field->unit = parser->global.unit;
259dde5845aSJiri Kosina 
260dde5845aSJiri Kosina 	return 0;
261dde5845aSJiri Kosina }
262dde5845aSJiri Kosina 
263dde5845aSJiri Kosina /*
264dde5845aSJiri Kosina  * Read data value from item.
265dde5845aSJiri Kosina  */
266dde5845aSJiri Kosina 
267dde5845aSJiri Kosina static u32 item_udata(struct hid_item *item)
268dde5845aSJiri Kosina {
269dde5845aSJiri Kosina 	switch (item->size) {
270dde5845aSJiri Kosina 	case 1: return item->data.u8;
271dde5845aSJiri Kosina 	case 2: return item->data.u16;
272dde5845aSJiri Kosina 	case 4: return item->data.u32;
273dde5845aSJiri Kosina 	}
274dde5845aSJiri Kosina 	return 0;
275dde5845aSJiri Kosina }
276dde5845aSJiri Kosina 
277dde5845aSJiri Kosina static s32 item_sdata(struct hid_item *item)
278dde5845aSJiri Kosina {
279dde5845aSJiri Kosina 	switch (item->size) {
280dde5845aSJiri Kosina 	case 1: return item->data.s8;
281dde5845aSJiri Kosina 	case 2: return item->data.s16;
282dde5845aSJiri Kosina 	case 4: return item->data.s32;
283dde5845aSJiri Kosina 	}
284dde5845aSJiri Kosina 	return 0;
285dde5845aSJiri Kosina }
286dde5845aSJiri Kosina 
287dde5845aSJiri Kosina /*
288dde5845aSJiri Kosina  * Process a global item.
289dde5845aSJiri Kosina  */
290dde5845aSJiri Kosina 
291dde5845aSJiri Kosina static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
292dde5845aSJiri Kosina {
293dde5845aSJiri Kosina 	switch (item->tag) {
294dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PUSH:
295dde5845aSJiri Kosina 
296dde5845aSJiri Kosina 		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
29758037eb9SJiri Kosina 			dbg_hid("global enviroment stack overflow\n");
298dde5845aSJiri Kosina 			return -1;
299dde5845aSJiri Kosina 		}
300dde5845aSJiri Kosina 
301dde5845aSJiri Kosina 		memcpy(parser->global_stack + parser->global_stack_ptr++,
302dde5845aSJiri Kosina 			&parser->global, sizeof(struct hid_global));
303dde5845aSJiri Kosina 		return 0;
304dde5845aSJiri Kosina 
305dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_POP:
306dde5845aSJiri Kosina 
307dde5845aSJiri Kosina 		if (!parser->global_stack_ptr) {
30858037eb9SJiri Kosina 			dbg_hid("global enviroment stack underflow\n");
309dde5845aSJiri Kosina 			return -1;
310dde5845aSJiri Kosina 		}
311dde5845aSJiri Kosina 
312880d29f1SJiri Slaby 		memcpy(&parser->global, parser->global_stack +
313880d29f1SJiri Slaby 			--parser->global_stack_ptr, sizeof(struct hid_global));
314dde5845aSJiri Kosina 		return 0;
315dde5845aSJiri Kosina 
316dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
317dde5845aSJiri Kosina 		parser->global.usage_page = item_udata(item);
318dde5845aSJiri Kosina 		return 0;
319dde5845aSJiri Kosina 
320dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
321dde5845aSJiri Kosina 		parser->global.logical_minimum = item_sdata(item);
322dde5845aSJiri Kosina 		return 0;
323dde5845aSJiri Kosina 
324dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
325dde5845aSJiri Kosina 		if (parser->global.logical_minimum < 0)
326dde5845aSJiri Kosina 			parser->global.logical_maximum = item_sdata(item);
327dde5845aSJiri Kosina 		else
328dde5845aSJiri Kosina 			parser->global.logical_maximum = item_udata(item);
329dde5845aSJiri Kosina 		return 0;
330dde5845aSJiri Kosina 
331dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
332dde5845aSJiri Kosina 		parser->global.physical_minimum = item_sdata(item);
333dde5845aSJiri Kosina 		return 0;
334dde5845aSJiri Kosina 
335dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
336dde5845aSJiri Kosina 		if (parser->global.physical_minimum < 0)
337dde5845aSJiri Kosina 			parser->global.physical_maximum = item_sdata(item);
338dde5845aSJiri Kosina 		else
339dde5845aSJiri Kosina 			parser->global.physical_maximum = item_udata(item);
340dde5845aSJiri Kosina 		return 0;
341dde5845aSJiri Kosina 
342dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
343dde5845aSJiri Kosina 		parser->global.unit_exponent = item_sdata(item);
344dde5845aSJiri Kosina 		return 0;
345dde5845aSJiri Kosina 
346dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT:
347dde5845aSJiri Kosina 		parser->global.unit = item_udata(item);
348dde5845aSJiri Kosina 		return 0;
349dde5845aSJiri Kosina 
350dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
351880d29f1SJiri Slaby 		parser->global.report_size = item_udata(item);
352880d29f1SJiri Slaby 		if (parser->global.report_size > 32) {
353880d29f1SJiri Slaby 			dbg_hid("invalid report_size %d\n",
354880d29f1SJiri Slaby 					parser->global.report_size);
355dde5845aSJiri Kosina 			return -1;
356dde5845aSJiri Kosina 		}
357dde5845aSJiri Kosina 		return 0;
358dde5845aSJiri Kosina 
359dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
360880d29f1SJiri Slaby 		parser->global.report_count = item_udata(item);
361880d29f1SJiri Slaby 		if (parser->global.report_count > HID_MAX_USAGES) {
362880d29f1SJiri Slaby 			dbg_hid("invalid report_count %d\n",
363880d29f1SJiri Slaby 					parser->global.report_count);
364dde5845aSJiri Kosina 			return -1;
365dde5845aSJiri Kosina 		}
366dde5845aSJiri Kosina 		return 0;
367dde5845aSJiri Kosina 
368dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
369880d29f1SJiri Slaby 		parser->global.report_id = item_udata(item);
370880d29f1SJiri Slaby 		if (parser->global.report_id == 0) {
37158037eb9SJiri Kosina 			dbg_hid("report_id 0 is invalid\n");
372dde5845aSJiri Kosina 			return -1;
373dde5845aSJiri Kosina 		}
374dde5845aSJiri Kosina 		return 0;
375dde5845aSJiri Kosina 
376dde5845aSJiri Kosina 	default:
37758037eb9SJiri Kosina 		dbg_hid("unknown global tag 0x%x\n", item->tag);
378dde5845aSJiri Kosina 		return -1;
379dde5845aSJiri Kosina 	}
380dde5845aSJiri Kosina }
381dde5845aSJiri Kosina 
382dde5845aSJiri Kosina /*
383dde5845aSJiri Kosina  * Process a local item.
384dde5845aSJiri Kosina  */
385dde5845aSJiri Kosina 
386dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
387dde5845aSJiri Kosina {
388dde5845aSJiri Kosina 	__u32 data;
389dde5845aSJiri Kosina 	unsigned n;
390dde5845aSJiri Kosina 
391dde5845aSJiri Kosina 	data = item_udata(item);
392dde5845aSJiri Kosina 
393dde5845aSJiri Kosina 	switch (item->tag) {
394dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_DELIMITER:
395dde5845aSJiri Kosina 
396dde5845aSJiri Kosina 		if (data) {
397dde5845aSJiri Kosina 			/*
398dde5845aSJiri Kosina 			 * We treat items before the first delimiter
399dde5845aSJiri Kosina 			 * as global to all usage sets (branch 0).
400dde5845aSJiri Kosina 			 * In the moment we process only these global
401dde5845aSJiri Kosina 			 * items and the first delimiter set.
402dde5845aSJiri Kosina 			 */
403dde5845aSJiri Kosina 			if (parser->local.delimiter_depth != 0) {
40458037eb9SJiri Kosina 				dbg_hid("nested delimiters\n");
405dde5845aSJiri Kosina 				return -1;
406dde5845aSJiri Kosina 			}
407dde5845aSJiri Kosina 			parser->local.delimiter_depth++;
408dde5845aSJiri Kosina 			parser->local.delimiter_branch++;
409dde5845aSJiri Kosina 		} else {
410dde5845aSJiri Kosina 			if (parser->local.delimiter_depth < 1) {
41158037eb9SJiri Kosina 				dbg_hid("bogus close delimiter\n");
412dde5845aSJiri Kosina 				return -1;
413dde5845aSJiri Kosina 			}
414dde5845aSJiri Kosina 			parser->local.delimiter_depth--;
415dde5845aSJiri Kosina 		}
416dde5845aSJiri Kosina 		return 1;
417dde5845aSJiri Kosina 
418dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE:
419dde5845aSJiri Kosina 
420dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
42158037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
422dde5845aSJiri Kosina 			return 0;
423dde5845aSJiri Kosina 		}
424dde5845aSJiri Kosina 
425dde5845aSJiri Kosina 		if (item->size <= 2)
426dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
427dde5845aSJiri Kosina 
428dde5845aSJiri Kosina 		return hid_add_usage(parser, data);
429dde5845aSJiri Kosina 
430dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
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 		parser->local.usage_minimum = data;
441dde5845aSJiri Kosina 		return 0;
442dde5845aSJiri Kosina 
443dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
444dde5845aSJiri Kosina 
445dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
44658037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
447dde5845aSJiri Kosina 			return 0;
448dde5845aSJiri Kosina 		}
449dde5845aSJiri Kosina 
450dde5845aSJiri Kosina 		if (item->size <= 2)
451dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
452dde5845aSJiri Kosina 
453dde5845aSJiri Kosina 		for (n = parser->local.usage_minimum; n <= data; n++)
454dde5845aSJiri Kosina 			if (hid_add_usage(parser, n)) {
45558037eb9SJiri Kosina 				dbg_hid("hid_add_usage failed\n");
456dde5845aSJiri Kosina 				return -1;
457dde5845aSJiri Kosina 			}
458dde5845aSJiri Kosina 		return 0;
459dde5845aSJiri Kosina 
460dde5845aSJiri Kosina 	default:
461dde5845aSJiri Kosina 
46258037eb9SJiri Kosina 		dbg_hid("unknown local item tag 0x%x\n", item->tag);
463dde5845aSJiri Kosina 		return 0;
464dde5845aSJiri Kosina 	}
465dde5845aSJiri Kosina 	return 0;
466dde5845aSJiri Kosina }
467dde5845aSJiri Kosina 
468dde5845aSJiri Kosina /*
469dde5845aSJiri Kosina  * Process a main item.
470dde5845aSJiri Kosina  */
471dde5845aSJiri Kosina 
472dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
473dde5845aSJiri Kosina {
474dde5845aSJiri Kosina 	__u32 data;
475dde5845aSJiri Kosina 	int ret;
476dde5845aSJiri Kosina 
477dde5845aSJiri Kosina 	data = item_udata(item);
478dde5845aSJiri Kosina 
479dde5845aSJiri Kosina 	switch (item->tag) {
480dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
481dde5845aSJiri Kosina 		ret = open_collection(parser, data & 0xff);
482dde5845aSJiri Kosina 		break;
483dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
484dde5845aSJiri Kosina 		ret = close_collection(parser);
485dde5845aSJiri Kosina 		break;
486dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_INPUT:
487dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
488dde5845aSJiri Kosina 		break;
489dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_OUTPUT:
490dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
491dde5845aSJiri Kosina 		break;
492dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_FEATURE:
493dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
494dde5845aSJiri Kosina 		break;
495dde5845aSJiri Kosina 	default:
49658037eb9SJiri Kosina 		dbg_hid("unknown main item tag 0x%x\n", item->tag);
497dde5845aSJiri Kosina 		ret = 0;
498dde5845aSJiri Kosina 	}
499dde5845aSJiri Kosina 
500dde5845aSJiri Kosina 	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
501dde5845aSJiri Kosina 
502dde5845aSJiri Kosina 	return ret;
503dde5845aSJiri Kosina }
504dde5845aSJiri Kosina 
505dde5845aSJiri Kosina /*
506dde5845aSJiri Kosina  * Process a reserved item.
507dde5845aSJiri Kosina  */
508dde5845aSJiri Kosina 
509dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
510dde5845aSJiri Kosina {
51158037eb9SJiri Kosina 	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
512dde5845aSJiri Kosina 	return 0;
513dde5845aSJiri Kosina }
514dde5845aSJiri Kosina 
515dde5845aSJiri Kosina /*
516dde5845aSJiri Kosina  * Free a report and all registered fields. The field->usage and
517dde5845aSJiri Kosina  * field->value table's are allocated behind the field, so we need
518dde5845aSJiri Kosina  * only to free(field) itself.
519dde5845aSJiri Kosina  */
520dde5845aSJiri Kosina 
521dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report)
522dde5845aSJiri Kosina {
523dde5845aSJiri Kosina 	unsigned n;
524dde5845aSJiri Kosina 
525dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
526dde5845aSJiri Kosina 		kfree(report->field[n]);
527dde5845aSJiri Kosina 	kfree(report);
528dde5845aSJiri Kosina }
529dde5845aSJiri Kosina 
530dde5845aSJiri Kosina /*
531dde5845aSJiri Kosina  * Free a device structure, all reports, and all fields.
532dde5845aSJiri Kosina  */
533dde5845aSJiri Kosina 
53485cdaf52SJiri Slaby static void hid_device_release(struct device *dev)
535dde5845aSJiri Kosina {
53685cdaf52SJiri Slaby 	struct hid_device *device = container_of(dev, struct hid_device, dev);
537dde5845aSJiri Kosina 	unsigned i, j;
538dde5845aSJiri Kosina 
539dde5845aSJiri Kosina 	for (i = 0; i < HID_REPORT_TYPES; i++) {
540dde5845aSJiri Kosina 		struct hid_report_enum *report_enum = device->report_enum + i;
541dde5845aSJiri Kosina 
542dde5845aSJiri Kosina 		for (j = 0; j < 256; j++) {
543dde5845aSJiri Kosina 			struct hid_report *report = report_enum->report_id_hash[j];
544dde5845aSJiri Kosina 			if (report)
545dde5845aSJiri Kosina 				hid_free_report(report);
546dde5845aSJiri Kosina 		}
547dde5845aSJiri Kosina 	}
548dde5845aSJiri Kosina 
549dde5845aSJiri Kosina 	kfree(device->rdesc);
550767fe787SJiri Kosina 	kfree(device->collection);
551dde5845aSJiri Kosina 	kfree(device);
552dde5845aSJiri Kosina }
553dde5845aSJiri Kosina 
554dde5845aSJiri Kosina /*
555dde5845aSJiri Kosina  * Fetch a report description item from the data stream. We support long
556dde5845aSJiri Kosina  * items, though they are not used yet.
557dde5845aSJiri Kosina  */
558dde5845aSJiri Kosina 
559dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
560dde5845aSJiri Kosina {
561dde5845aSJiri Kosina 	u8 b;
562dde5845aSJiri Kosina 
563dde5845aSJiri Kosina 	if ((end - start) <= 0)
564dde5845aSJiri Kosina 		return NULL;
565dde5845aSJiri Kosina 
566dde5845aSJiri Kosina 	b = *start++;
567dde5845aSJiri Kosina 
568dde5845aSJiri Kosina 	item->type = (b >> 2) & 3;
569dde5845aSJiri Kosina 	item->tag  = (b >> 4) & 15;
570dde5845aSJiri Kosina 
571dde5845aSJiri Kosina 	if (item->tag == HID_ITEM_TAG_LONG) {
572dde5845aSJiri Kosina 
573dde5845aSJiri Kosina 		item->format = HID_ITEM_FORMAT_LONG;
574dde5845aSJiri Kosina 
575dde5845aSJiri Kosina 		if ((end - start) < 2)
576dde5845aSJiri Kosina 			return NULL;
577dde5845aSJiri Kosina 
578dde5845aSJiri Kosina 		item->size = *start++;
579dde5845aSJiri Kosina 		item->tag  = *start++;
580dde5845aSJiri Kosina 
581dde5845aSJiri Kosina 		if ((end - start) < item->size)
582dde5845aSJiri Kosina 			return NULL;
583dde5845aSJiri Kosina 
584dde5845aSJiri Kosina 		item->data.longdata = start;
585dde5845aSJiri Kosina 		start += item->size;
586dde5845aSJiri Kosina 		return start;
587dde5845aSJiri Kosina 	}
588dde5845aSJiri Kosina 
589dde5845aSJiri Kosina 	item->format = HID_ITEM_FORMAT_SHORT;
590dde5845aSJiri Kosina 	item->size = b & 3;
591dde5845aSJiri Kosina 
592dde5845aSJiri Kosina 	switch (item->size) {
593dde5845aSJiri Kosina 	case 0:
594dde5845aSJiri Kosina 		return start;
595dde5845aSJiri Kosina 
596dde5845aSJiri Kosina 	case 1:
597dde5845aSJiri Kosina 		if ((end - start) < 1)
598dde5845aSJiri Kosina 			return NULL;
599dde5845aSJiri Kosina 		item->data.u8 = *start++;
600dde5845aSJiri Kosina 		return start;
601dde5845aSJiri Kosina 
602dde5845aSJiri Kosina 	case 2:
603dde5845aSJiri Kosina 		if ((end - start) < 2)
604dde5845aSJiri Kosina 			return NULL;
605c105068fSHarvey Harrison 		item->data.u16 = get_unaligned_le16(start);
606dde5845aSJiri Kosina 		start = (__u8 *)((__le16 *)start + 1);
607dde5845aSJiri Kosina 		return start;
608dde5845aSJiri Kosina 
609dde5845aSJiri Kosina 	case 3:
610dde5845aSJiri Kosina 		item->size++;
611dde5845aSJiri Kosina 		if ((end - start) < 4)
612dde5845aSJiri Kosina 			return NULL;
613c105068fSHarvey Harrison 		item->data.u32 = get_unaligned_le32(start);
614dde5845aSJiri Kosina 		start = (__u8 *)((__le32 *)start + 1);
615dde5845aSJiri Kosina 		return start;
616dde5845aSJiri Kosina 	}
617dde5845aSJiri Kosina 
618dde5845aSJiri Kosina 	return NULL;
619dde5845aSJiri Kosina }
620dde5845aSJiri Kosina 
62185cdaf52SJiri Slaby /**
62285cdaf52SJiri Slaby  * hid_parse_report - parse device report
62385cdaf52SJiri Slaby  *
62485cdaf52SJiri Slaby  * @device: hid device
62585cdaf52SJiri Slaby  * @start: report start
62685cdaf52SJiri Slaby  * @size: report size
62785cdaf52SJiri Slaby  *
628dde5845aSJiri Kosina  * Parse a report description into a hid_device structure. Reports are
629dde5845aSJiri Kosina  * enumerated, fields are attached to these reports.
63085cdaf52SJiri Slaby  * 0 returned on success, otherwise nonzero error value.
631dde5845aSJiri Kosina  */
63285cdaf52SJiri Slaby int hid_parse_report(struct hid_device *device, __u8 *start,
63385cdaf52SJiri Slaby 		unsigned size)
634dde5845aSJiri Kosina {
635dde5845aSJiri Kosina 	struct hid_parser *parser;
636dde5845aSJiri Kosina 	struct hid_item item;
637dde5845aSJiri Kosina 	__u8 *end;
63885cdaf52SJiri Slaby 	int ret;
639dde5845aSJiri Kosina 	static int (*dispatch_type[])(struct hid_parser *parser,
640dde5845aSJiri Kosina 				      struct hid_item *item) = {
641dde5845aSJiri Kosina 		hid_parser_main,
642dde5845aSJiri Kosina 		hid_parser_global,
643dde5845aSJiri Kosina 		hid_parser_local,
644dde5845aSJiri Kosina 		hid_parser_reserved
645dde5845aSJiri Kosina 	};
646dde5845aSJiri Kosina 
647c500c971SJiri Slaby 	if (device->driver->report_fixup)
64873e4008dSNikolai Kondrashov 		start = device->driver->report_fixup(device, start, &size);
649c500c971SJiri Slaby 
6501721a238SJulia Lawall 	device->rdesc = kmemdup(start, size, GFP_KERNEL);
65185cdaf52SJiri Slaby 	if (device->rdesc == NULL)
65285cdaf52SJiri Slaby 		return -ENOMEM;
653dde5845aSJiri Kosina 	device->rsize = size;
654dde5845aSJiri Kosina 
65585cdaf52SJiri Slaby 	parser = vmalloc(sizeof(struct hid_parser));
65685cdaf52SJiri Slaby 	if (!parser) {
65785cdaf52SJiri Slaby 		ret = -ENOMEM;
65885cdaf52SJiri Slaby 		goto err;
659dde5845aSJiri Kosina 	}
66085cdaf52SJiri Slaby 
66147a80edbSJiri Kosina 	memset(parser, 0, sizeof(struct hid_parser));
662dde5845aSJiri Kosina 	parser->device = device;
663dde5845aSJiri Kosina 
664dde5845aSJiri Kosina 	end = start + size;
66585cdaf52SJiri Slaby 	ret = -EINVAL;
666dde5845aSJiri Kosina 	while ((start = fetch_item(start, end, &item)) != NULL) {
667dde5845aSJiri Kosina 
668dde5845aSJiri Kosina 		if (item.format != HID_ITEM_FORMAT_SHORT) {
66958037eb9SJiri Kosina 			dbg_hid("unexpected long global item\n");
67085cdaf52SJiri Slaby 			goto err;
671dde5845aSJiri Kosina 		}
672dde5845aSJiri Kosina 
673dde5845aSJiri Kosina 		if (dispatch_type[item.type](parser, &item)) {
67458037eb9SJiri Kosina 			dbg_hid("item %u %u %u %u parsing failed\n",
675dde5845aSJiri Kosina 				item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
67685cdaf52SJiri Slaby 			goto err;
677dde5845aSJiri Kosina 		}
678dde5845aSJiri Kosina 
679dde5845aSJiri Kosina 		if (start == end) {
680dde5845aSJiri Kosina 			if (parser->collection_stack_ptr) {
68158037eb9SJiri Kosina 				dbg_hid("unbalanced collection at end of report description\n");
68285cdaf52SJiri Slaby 				goto err;
683dde5845aSJiri Kosina 			}
684dde5845aSJiri Kosina 			if (parser->local.delimiter_depth) {
68558037eb9SJiri Kosina 				dbg_hid("unbalanced delimiter at end of report description\n");
68685cdaf52SJiri Slaby 				goto err;
687dde5845aSJiri Kosina 			}
68847a80edbSJiri Kosina 			vfree(parser);
68985cdaf52SJiri Slaby 			return 0;
690dde5845aSJiri Kosina 		}
691dde5845aSJiri Kosina 	}
692dde5845aSJiri Kosina 
69358037eb9SJiri Kosina 	dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
69485cdaf52SJiri Slaby err:
69547a80edbSJiri Kosina 	vfree(parser);
69685cdaf52SJiri Slaby 	return ret;
697dde5845aSJiri Kosina }
698229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_parse_report);
699dde5845aSJiri Kosina 
700dde5845aSJiri Kosina /*
701dde5845aSJiri Kosina  * Convert a signed n-bit integer to signed 32-bit integer. Common
702dde5845aSJiri Kosina  * cases are done through the compiler, the screwed things has to be
703dde5845aSJiri Kosina  * done by hand.
704dde5845aSJiri Kosina  */
705dde5845aSJiri Kosina 
706dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n)
707dde5845aSJiri Kosina {
708dde5845aSJiri Kosina 	switch (n) {
709dde5845aSJiri Kosina 	case 8:  return ((__s8)value);
710dde5845aSJiri Kosina 	case 16: return ((__s16)value);
711dde5845aSJiri Kosina 	case 32: return ((__s32)value);
712dde5845aSJiri Kosina 	}
713dde5845aSJiri Kosina 	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
714dde5845aSJiri Kosina }
715dde5845aSJiri Kosina 
716dde5845aSJiri Kosina /*
717dde5845aSJiri Kosina  * Convert a signed 32-bit integer to a signed n-bit integer.
718dde5845aSJiri Kosina  */
719dde5845aSJiri Kosina 
720dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n)
721dde5845aSJiri Kosina {
722dde5845aSJiri Kosina 	s32 a = value >> (n - 1);
723dde5845aSJiri Kosina 	if (a && a != -1)
724dde5845aSJiri Kosina 		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
725dde5845aSJiri Kosina 	return value & ((1 << n) - 1);
726dde5845aSJiri Kosina }
727dde5845aSJiri Kosina 
728dde5845aSJiri Kosina /*
729dde5845aSJiri Kosina  * Extract/implement a data field from/to a little endian report (bit array).
730dde5845aSJiri Kosina  *
731dde5845aSJiri Kosina  * Code sort-of follows HID spec:
732dde5845aSJiri Kosina  *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
733dde5845aSJiri Kosina  *
734dde5845aSJiri Kosina  * While the USB HID spec allows unlimited length bit fields in "report
735dde5845aSJiri Kosina  * descriptors", most devices never use more than 16 bits.
736dde5845aSJiri Kosina  * One model of UPS is claimed to report "LINEV" as a 32-bit field.
737dde5845aSJiri Kosina  * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
738dde5845aSJiri Kosina  */
739dde5845aSJiri Kosina 
740dde5845aSJiri Kosina static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
741dde5845aSJiri Kosina {
742dde5845aSJiri Kosina 	u64 x;
743dde5845aSJiri Kosina 
744c4124c9bSJiri Kosina 	if (n > 32)
745c4124c9bSJiri Kosina 		printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n",
746c4124c9bSJiri Kosina 				n, current->comm);
747dde5845aSJiri Kosina 
748dde5845aSJiri Kosina 	report += offset >> 3;  /* adjust byte index */
749dde5845aSJiri Kosina 	offset &= 7;            /* now only need bit offset into one byte */
750c105068fSHarvey Harrison 	x = get_unaligned_le64(report);
751dde5845aSJiri Kosina 	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
752dde5845aSJiri Kosina 	return (u32) x;
753dde5845aSJiri Kosina }
754dde5845aSJiri Kosina 
755dde5845aSJiri Kosina /*
756dde5845aSJiri Kosina  * "implement" : set bits in a little endian bit stream.
757dde5845aSJiri Kosina  * Same concepts as "extract" (see comments above).
758dde5845aSJiri Kosina  * The data mangled in the bit stream remains in little endian
759dde5845aSJiri Kosina  * order the whole time. It make more sense to talk about
760dde5845aSJiri Kosina  * endianness of register values by considering a register
761dde5845aSJiri Kosina  * a "cached" copy of the little endiad bit stream.
762dde5845aSJiri Kosina  */
763dde5845aSJiri Kosina static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
764dde5845aSJiri Kosina {
7656f0168d2SHarvey Harrison 	u64 x;
766dde5845aSJiri Kosina 	u64 m = (1ULL << n) - 1;
767dde5845aSJiri Kosina 
768c4124c9bSJiri Kosina 	if (n > 32)
769c4124c9bSJiri Kosina 		printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n",
770c4124c9bSJiri Kosina 				n, current->comm);
771dde5845aSJiri Kosina 
772c4124c9bSJiri Kosina 	if (value > m)
773c4124c9bSJiri Kosina 		printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n",
774c4124c9bSJiri Kosina 				value, current->comm);
775dde5845aSJiri Kosina 	WARN_ON(value > m);
776dde5845aSJiri Kosina 	value &= m;
777dde5845aSJiri Kosina 
778dde5845aSJiri Kosina 	report += offset >> 3;
779dde5845aSJiri Kosina 	offset &= 7;
780dde5845aSJiri Kosina 
7816f0168d2SHarvey Harrison 	x = get_unaligned_le64(report);
7826f0168d2SHarvey Harrison 	x &= ~(m << offset);
7836f0168d2SHarvey Harrison 	x |= ((u64)value) << offset;
7846f0168d2SHarvey Harrison 	put_unaligned_le64(x, report);
785dde5845aSJiri Kosina }
786dde5845aSJiri Kosina 
787dde5845aSJiri Kosina /*
788dde5845aSJiri Kosina  * Search an array for a value.
789dde5845aSJiri Kosina  */
790dde5845aSJiri Kosina 
791dde5845aSJiri Kosina static __inline__ int search(__s32 *array, __s32 value, unsigned n)
792dde5845aSJiri Kosina {
793dde5845aSJiri Kosina 	while (n--) {
794dde5845aSJiri Kosina 		if (*array++ == value)
795dde5845aSJiri Kosina 			return 0;
796dde5845aSJiri Kosina 	}
797dde5845aSJiri Kosina 	return -1;
798dde5845aSJiri Kosina }
799dde5845aSJiri Kosina 
80085cdaf52SJiri Slaby /**
80185cdaf52SJiri Slaby  * hid_match_report - check if driver's raw_event should be called
80285cdaf52SJiri Slaby  *
80385cdaf52SJiri Slaby  * @hid: hid device
80485cdaf52SJiri Slaby  * @report_type: type to match against
80585cdaf52SJiri Slaby  *
80685cdaf52SJiri Slaby  * compare hid->driver->report_table->report_type to report->type
80785cdaf52SJiri Slaby  */
80885cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report)
809dde5845aSJiri Kosina {
81085cdaf52SJiri Slaby 	const struct hid_report_id *id = hid->driver->report_table;
81185cdaf52SJiri Slaby 
81285cdaf52SJiri Slaby 	if (!id) /* NULL means all */
81385cdaf52SJiri Slaby 		return 1;
81485cdaf52SJiri Slaby 
81585cdaf52SJiri Slaby 	for (; id->report_type != HID_TERMINATOR; id++)
81685cdaf52SJiri Slaby 		if (id->report_type == HID_ANY_ID ||
81785cdaf52SJiri Slaby 				id->report_type == report->type)
81885cdaf52SJiri Slaby 			return 1;
81985cdaf52SJiri Slaby 	return 0;
82085cdaf52SJiri Slaby }
82185cdaf52SJiri Slaby 
82285cdaf52SJiri Slaby /**
82385cdaf52SJiri Slaby  * hid_match_usage - check if driver's event should be called
82485cdaf52SJiri Slaby  *
82585cdaf52SJiri Slaby  * @hid: hid device
82685cdaf52SJiri Slaby  * @usage: usage to match against
82785cdaf52SJiri Slaby  *
82885cdaf52SJiri Slaby  * compare hid->driver->usage_table->usage_{type,code} to
82985cdaf52SJiri Slaby  * usage->usage_{type,code}
83085cdaf52SJiri Slaby  */
83185cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
83285cdaf52SJiri Slaby {
83385cdaf52SJiri Slaby 	const struct hid_usage_id *id = hid->driver->usage_table;
83485cdaf52SJiri Slaby 
83585cdaf52SJiri Slaby 	if (!id) /* NULL means all */
83685cdaf52SJiri Slaby 		return 1;
83785cdaf52SJiri Slaby 
83885cdaf52SJiri Slaby 	for (; id->usage_type != HID_ANY_ID - 1; id++)
83985cdaf52SJiri Slaby 		if ((id->usage_hid == HID_ANY_ID ||
84085cdaf52SJiri Slaby 				id->usage_hid == usage->hid) &&
84185cdaf52SJiri Slaby 				(id->usage_type == HID_ANY_ID ||
84285cdaf52SJiri Slaby 				id->usage_type == usage->type) &&
84385cdaf52SJiri Slaby 				(id->usage_code == HID_ANY_ID ||
84485cdaf52SJiri Slaby 				 id->usage_code == usage->code))
84585cdaf52SJiri Slaby 			return 1;
84685cdaf52SJiri Slaby 	return 0;
84785cdaf52SJiri Slaby }
84885cdaf52SJiri Slaby 
84985cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field,
85085cdaf52SJiri Slaby 		struct hid_usage *usage, __s32 value, int interrupt)
85185cdaf52SJiri Slaby {
85285cdaf52SJiri Slaby 	struct hid_driver *hdrv = hid->driver;
85385cdaf52SJiri Slaby 	int ret;
85485cdaf52SJiri Slaby 
855cd667ce2SJiri Kosina 	hid_dump_input(hid, usage, value);
85685cdaf52SJiri Slaby 
85785cdaf52SJiri Slaby 	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
85885cdaf52SJiri Slaby 		ret = hdrv->event(hid, field, usage, value);
85985cdaf52SJiri Slaby 		if (ret != 0) {
86085cdaf52SJiri Slaby 			if (ret < 0)
86185cdaf52SJiri Slaby 				dbg_hid("%s's event failed with %d\n",
86285cdaf52SJiri Slaby 						hdrv->name, ret);
86385cdaf52SJiri Slaby 			return;
86485cdaf52SJiri Slaby 		}
86585cdaf52SJiri Slaby 	}
86685cdaf52SJiri Slaby 
867dde5845aSJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
868dde5845aSJiri Kosina 		hidinput_hid_event(hid, field, usage, value);
869aa938f79SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
870aa938f79SJiri Kosina 		hid->hiddev_hid_event(hid, field, usage, value);
871dde5845aSJiri Kosina }
872dde5845aSJiri Kosina 
873dde5845aSJiri Kosina /*
874dde5845aSJiri Kosina  * Analyse a received field, and fetch the data from it. The field
875dde5845aSJiri Kosina  * content is stored for next report processing (we do differential
876dde5845aSJiri Kosina  * reporting to the layer).
877dde5845aSJiri Kosina  */
878dde5845aSJiri Kosina 
879abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field,
880abdff0f7SAdrian Bunk 			    __u8 *data, int interrupt)
881dde5845aSJiri Kosina {
882dde5845aSJiri Kosina 	unsigned n;
883dde5845aSJiri Kosina 	unsigned count = field->report_count;
884dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
885dde5845aSJiri Kosina 	unsigned size = field->report_size;
886dde5845aSJiri Kosina 	__s32 min = field->logical_minimum;
887dde5845aSJiri Kosina 	__s32 max = field->logical_maximum;
888dde5845aSJiri Kosina 	__s32 *value;
889dde5845aSJiri Kosina 
890dde5845aSJiri Kosina 	if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
891dde5845aSJiri Kosina 		return;
892dde5845aSJiri Kosina 
893dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
894dde5845aSJiri Kosina 
895dde5845aSJiri Kosina 			value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
896dde5845aSJiri Kosina 						    extract(data, offset + n * size, size);
897dde5845aSJiri Kosina 
898dde5845aSJiri Kosina 			if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
899dde5845aSJiri Kosina 			    && value[n] >= min && value[n] <= max
900dde5845aSJiri Kosina 			    && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
901dde5845aSJiri Kosina 				goto exit;
902dde5845aSJiri Kosina 	}
903dde5845aSJiri Kosina 
904dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
905dde5845aSJiri Kosina 
906dde5845aSJiri Kosina 		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
907dde5845aSJiri Kosina 			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
908dde5845aSJiri Kosina 			continue;
909dde5845aSJiri Kosina 		}
910dde5845aSJiri Kosina 
911dde5845aSJiri Kosina 		if (field->value[n] >= min && field->value[n] <= max
912dde5845aSJiri Kosina 			&& field->usage[field->value[n] - min].hid
913dde5845aSJiri Kosina 			&& search(value, field->value[n], count))
914dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
915dde5845aSJiri Kosina 
916dde5845aSJiri Kosina 		if (value[n] >= min && value[n] <= max
917dde5845aSJiri Kosina 			&& field->usage[value[n] - min].hid
918dde5845aSJiri Kosina 			&& search(field->value, value[n], count))
919dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
920dde5845aSJiri Kosina 	}
921dde5845aSJiri Kosina 
922dde5845aSJiri Kosina 	memcpy(field->value, value, count * sizeof(__s32));
923dde5845aSJiri Kosina exit:
924dde5845aSJiri Kosina 	kfree(value);
925dde5845aSJiri Kosina }
926dde5845aSJiri Kosina 
927dde5845aSJiri Kosina /*
928dde5845aSJiri Kosina  * Output the field into the report.
929dde5845aSJiri Kosina  */
930dde5845aSJiri Kosina 
931dde5845aSJiri Kosina static void hid_output_field(struct hid_field *field, __u8 *data)
932dde5845aSJiri Kosina {
933dde5845aSJiri Kosina 	unsigned count = field->report_count;
934dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
935dde5845aSJiri Kosina 	unsigned size = field->report_size;
936dde5845aSJiri Kosina 	unsigned n;
937dde5845aSJiri Kosina 
938dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
939dde5845aSJiri Kosina 		if (field->logical_minimum < 0)	/* signed values */
940dde5845aSJiri Kosina 			implement(data, offset + n * size, size, s32ton(field->value[n], size));
941dde5845aSJiri Kosina 		else				/* unsigned values */
942dde5845aSJiri Kosina 			implement(data, offset + n * size, size, field->value[n]);
943dde5845aSJiri Kosina 	}
944dde5845aSJiri Kosina }
945dde5845aSJiri Kosina 
946dde5845aSJiri Kosina /*
947dde5845aSJiri Kosina  * Create a report.
948dde5845aSJiri Kosina  */
949dde5845aSJiri Kosina 
950229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data)
951dde5845aSJiri Kosina {
952dde5845aSJiri Kosina 	unsigned n;
953dde5845aSJiri Kosina 
954dde5845aSJiri Kosina 	if (report->id > 0)
955dde5845aSJiri Kosina 		*data++ = report->id;
956dde5845aSJiri Kosina 
95775c28df8SPete Zaitcev 	memset(data, 0, ((report->size - 1) >> 3) + 1);
958dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
959dde5845aSJiri Kosina 		hid_output_field(report->field[n], data);
960dde5845aSJiri Kosina }
961229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report);
962dde5845aSJiri Kosina 
963dde5845aSJiri Kosina /*
964dde5845aSJiri Kosina  * Set a field value. The report this field belongs to has to be
965dde5845aSJiri Kosina  * created and transferred to the device, to set this value in the
966dde5845aSJiri Kosina  * device.
967dde5845aSJiri Kosina  */
968dde5845aSJiri Kosina 
969dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
970dde5845aSJiri Kosina {
971dde5845aSJiri Kosina 	unsigned size = field->report_size;
972dde5845aSJiri Kosina 
973cd667ce2SJiri Kosina 	hid_dump_input(field->report->device, field->usage + offset, value);
974dde5845aSJiri Kosina 
975dde5845aSJiri Kosina 	if (offset >= field->report_count) {
97658037eb9SJiri Kosina 		dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
977dde5845aSJiri Kosina 		return -1;
978dde5845aSJiri Kosina 	}
979dde5845aSJiri Kosina 	if (field->logical_minimum < 0) {
980dde5845aSJiri Kosina 		if (value != snto32(s32ton(value, size), size)) {
98158037eb9SJiri Kosina 			dbg_hid("value %d is out of range\n", value);
982dde5845aSJiri Kosina 			return -1;
983dde5845aSJiri Kosina 		}
984dde5845aSJiri Kosina 	}
985dde5845aSJiri Kosina 	field->value[offset] = value;
986dde5845aSJiri Kosina 	return 0;
987dde5845aSJiri Kosina }
988229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field);
989dde5845aSJiri Kosina 
99085cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
99185cdaf52SJiri Slaby 		const u8 *data)
99285cdaf52SJiri Slaby {
99385cdaf52SJiri Slaby 	struct hid_report *report;
99485cdaf52SJiri Slaby 	unsigned int n = 0;	/* Normally report number is 0 */
99585cdaf52SJiri Slaby 
99685cdaf52SJiri Slaby 	/* Device uses numbered reports, data[0] is report number */
99785cdaf52SJiri Slaby 	if (report_enum->numbered)
99885cdaf52SJiri Slaby 		n = *data;
99985cdaf52SJiri Slaby 
100085cdaf52SJiri Slaby 	report = report_enum->report_id_hash[n];
100185cdaf52SJiri Slaby 	if (report == NULL)
100285cdaf52SJiri Slaby 		dbg_hid("undefined report_id %u received\n", n);
100385cdaf52SJiri Slaby 
100485cdaf52SJiri Slaby 	return report;
100585cdaf52SJiri Slaby }
100685cdaf52SJiri Slaby 
100785cdaf52SJiri Slaby void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
100885cdaf52SJiri Slaby 		int interrupt)
1009aa8de2f0SJiri Kosina {
1010aa8de2f0SJiri Kosina 	struct hid_report_enum *report_enum = hid->report_enum + type;
1011aa8de2f0SJiri Kosina 	struct hid_report *report;
101285cdaf52SJiri Slaby 	unsigned int a;
101385cdaf52SJiri Slaby 	int rsize, csize = size;
101485cdaf52SJiri Slaby 	u8 *cdata = data;
1015aa8de2f0SJiri Kosina 
101685cdaf52SJiri Slaby 	report = hid_get_report(report_enum, data);
101785cdaf52SJiri Slaby 	if (!report)
101885cdaf52SJiri Slaby 		return;
1019aa8de2f0SJiri Kosina 
102085cdaf52SJiri Slaby 	if (report_enum->numbered) {
102185cdaf52SJiri Slaby 		cdata++;
102285cdaf52SJiri Slaby 		csize--;
1023aa8de2f0SJiri Kosina 	}
1024aa8de2f0SJiri Kosina 
1025aa8de2f0SJiri Kosina 	rsize = ((report->size - 1) >> 3) + 1;
1026aa8de2f0SJiri Kosina 
102785cdaf52SJiri Slaby 	if (csize < rsize) {
102885cdaf52SJiri Slaby 		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
102985cdaf52SJiri Slaby 				csize, rsize);
103085cdaf52SJiri Slaby 		memset(cdata + csize, 0, rsize - csize);
1031aa8de2f0SJiri Kosina 	}
1032aa8de2f0SJiri Kosina 
1033aa8de2f0SJiri Kosina 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1034aa8de2f0SJiri Kosina 		hid->hiddev_report_event(hid, report);
10355a38f2c7SAlan Ott 	if (hid->claimed & HID_CLAIMED_HIDRAW)
103686166b7bSJiri Kosina 		hidraw_report_event(hid, data, size);
1037aa8de2f0SJiri Kosina 
103885cdaf52SJiri Slaby 	for (a = 0; a < report->maxfield; a++)
103985cdaf52SJiri Slaby 		hid_input_field(hid, report->field[a], cdata, interrupt);
1040aa8de2f0SJiri Kosina 
1041aa8de2f0SJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1042aa8de2f0SJiri Kosina 		hidinput_report_event(hid, report);
104385cdaf52SJiri Slaby }
104485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event);
104585cdaf52SJiri Slaby 
104685cdaf52SJiri Slaby /**
104785cdaf52SJiri Slaby  * hid_input_report - report data from lower layer (usb, bt...)
104885cdaf52SJiri Slaby  *
104985cdaf52SJiri Slaby  * @hid: hid device
105085cdaf52SJiri Slaby  * @type: HID report type (HID_*_REPORT)
105185cdaf52SJiri Slaby  * @data: report contents
105285cdaf52SJiri Slaby  * @size: size of data parameter
1053ff9b00a2SJiri Kosina  * @interrupt: distinguish between interrupt and control transfers
105485cdaf52SJiri Slaby  *
105585cdaf52SJiri Slaby  * This is data entry for lower layers.
105685cdaf52SJiri Slaby  */
105785cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
105885cdaf52SJiri Slaby {
105976c317d6SJulia Lawall 	struct hid_report_enum *report_enum;
106076c317d6SJulia Lawall 	struct hid_driver *hdrv;
106185cdaf52SJiri Slaby 	struct hid_report *report;
1062cd667ce2SJiri Kosina 	char *buf;
106385cdaf52SJiri Slaby 	unsigned int i;
106485cdaf52SJiri Slaby 	int ret;
106585cdaf52SJiri Slaby 
106685cdaf52SJiri Slaby 	if (!hid || !hid->driver)
106785cdaf52SJiri Slaby 		return -ENODEV;
106876c317d6SJulia Lawall 	report_enum = hid->report_enum + type;
106976c317d6SJulia Lawall 	hdrv = hid->driver;
107085cdaf52SJiri Slaby 
107185cdaf52SJiri Slaby 	if (!size) {
107285cdaf52SJiri Slaby 		dbg_hid("empty report\n");
107385cdaf52SJiri Slaby 		return -1;
107485cdaf52SJiri Slaby 	}
107585cdaf52SJiri Slaby 
1076d1ff6522SJiri Kosina 	buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1077cd667ce2SJiri Kosina 
1078f77e347bSJiri Kosina 	if (!buf)
1079cd667ce2SJiri Kosina 		goto nomem;
108085cdaf52SJiri Slaby 
108185cdaf52SJiri Slaby 	/* dump the report */
1082cd667ce2SJiri Kosina 	snprintf(buf, HID_DEBUG_BUFSIZE - 1,
10831caea61eSJiri Kosina 			"\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
1084cd667ce2SJiri Kosina 	hid_debug_event(hid, buf);
10851caea61eSJiri Kosina 
1086cd667ce2SJiri Kosina 	for (i = 0; i < size; i++) {
1087cd667ce2SJiri Kosina 		snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1088cd667ce2SJiri Kosina 				" %02x", data[i]);
1089cd667ce2SJiri Kosina 		hid_debug_event(hid, buf);
1090cd667ce2SJiri Kosina 	}
1091cd667ce2SJiri Kosina 	hid_debug_event(hid, "\n");
1092cd667ce2SJiri Kosina 	kfree(buf);
1093cd667ce2SJiri Kosina 
1094cd667ce2SJiri Kosina nomem:
1095f77e347bSJiri Kosina 	report = hid_get_report(report_enum, data);
1096f77e347bSJiri Kosina 
1097f77e347bSJiri Kosina 	if (!report)
1098f77e347bSJiri Kosina 		return -1;
1099f77e347bSJiri Kosina 
110085cdaf52SJiri Slaby 	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
110185cdaf52SJiri Slaby 		ret = hdrv->raw_event(hid, report, data, size);
110285cdaf52SJiri Slaby 		if (ret != 0)
110385cdaf52SJiri Slaby 			return ret < 0 ? ret : 0;
110485cdaf52SJiri Slaby 	}
110585cdaf52SJiri Slaby 
110685cdaf52SJiri Slaby 	hid_report_raw_event(hid, type, data, size, interrupt);
1107aa8de2f0SJiri Kosina 
1108aa8de2f0SJiri Kosina 	return 0;
1109aa8de2f0SJiri Kosina }
1110aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report);
1111aa8de2f0SJiri Kosina 
11120f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev,
11130f37cd03SJiri Kosina 		const struct hid_device_id *id)
11140f37cd03SJiri Kosina {
11150f37cd03SJiri Kosina 	return id->bus == hdev->bus &&
11160f37cd03SJiri Kosina 		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
11170f37cd03SJiri Kosina 		(id->product == HID_ANY_ID || id->product == hdev->product);
11180f37cd03SJiri Kosina }
11190f37cd03SJiri Kosina 
11200f37cd03SJiri Kosina static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
11210f37cd03SJiri Kosina 		const struct hid_device_id *id)
11220f37cd03SJiri Kosina {
11230f37cd03SJiri Kosina 	for (; id->bus; id++)
11240f37cd03SJiri Kosina 		if (hid_match_one_id(hdev, id))
11250f37cd03SJiri Kosina 			return id;
11260f37cd03SJiri Kosina 
11270f37cd03SJiri Kosina 	return NULL;
11280f37cd03SJiri Kosina }
11290f37cd03SJiri Kosina 
11300f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = {
1131c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1132c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
11330f37cd03SJiri Kosina 	{ }
11340f37cd03SJiri Kosina };
11350f37cd03SJiri Kosina 
11360f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev)
11370f37cd03SJiri Kosina {
11380f37cd03SJiri Kosina 	return !!hid_match_id(hdev, hid_hiddev_list);
11390f37cd03SJiri Kosina }
11400f37cd03SJiri Kosina 
114193c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
114293c10132SJiri Slaby {
114393c10132SJiri Slaby 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
114493c10132SJiri Slaby 		"Joystick", "Gamepad", "Keyboard", "Keypad",
114593c10132SJiri Slaby 		"Multi-Axis Controller"
114693c10132SJiri Slaby 	};
114793c10132SJiri Slaby 	const char *type, *bus;
114893c10132SJiri Slaby 	char buf[64];
114993c10132SJiri Slaby 	unsigned int i;
115093c10132SJiri Slaby 	int len;
115193c10132SJiri Slaby 
1152b5e5a37eSBastien Nocera 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1153b5e5a37eSBastien Nocera 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
11543a343ee4SDaniel Mack 	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
11553a343ee4SDaniel Mack 		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
115693c10132SJiri Slaby 	if (hdev->bus != BUS_USB)
115793c10132SJiri Slaby 		connect_mask &= ~HID_CONNECT_HIDDEV;
11580f37cd03SJiri Kosina 	if (hid_hiddev(hdev))
11590f37cd03SJiri Kosina 		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
116093c10132SJiri Slaby 
116193c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
116293c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
116393c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_INPUT;
116493c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
116593c10132SJiri Slaby 			!hdev->hiddev_connect(hdev,
116693c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDDEV_FORCE))
116793c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDDEV;
116893c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
116993c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDRAW;
117093c10132SJiri Slaby 
117193c10132SJiri Slaby 	if (!hdev->claimed) {
117293c10132SJiri Slaby 		dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
117393c10132SJiri Slaby 				"hidraw\n");
117493c10132SJiri Slaby 		return -ENODEV;
117593c10132SJiri Slaby 	}
117693c10132SJiri Slaby 
117793c10132SJiri Slaby 	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
117893c10132SJiri Slaby 			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
117993c10132SJiri Slaby 		hdev->ff_init(hdev);
118093c10132SJiri Slaby 
118193c10132SJiri Slaby 	len = 0;
118293c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_INPUT)
118393c10132SJiri Slaby 		len += sprintf(buf + len, "input");
118493c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
118593c10132SJiri Slaby 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
118693c10132SJiri Slaby 				hdev->minor);
118793c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
118893c10132SJiri Slaby 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
118993c10132SJiri Slaby 				((struct hidraw *)hdev->hidraw)->minor);
119093c10132SJiri Slaby 
119193c10132SJiri Slaby 	type = "Device";
119293c10132SJiri Slaby 	for (i = 0; i < hdev->maxcollection; i++) {
119393c10132SJiri Slaby 		struct hid_collection *col = &hdev->collection[i];
119493c10132SJiri Slaby 		if (col->type == HID_COLLECTION_APPLICATION &&
119593c10132SJiri Slaby 		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
119693c10132SJiri Slaby 		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
119793c10132SJiri Slaby 			type = types[col->usage & 0xffff];
119893c10132SJiri Slaby 			break;
119993c10132SJiri Slaby 		}
120093c10132SJiri Slaby 	}
120193c10132SJiri Slaby 
120293c10132SJiri Slaby 	switch (hdev->bus) {
120393c10132SJiri Slaby 	case BUS_USB:
120493c10132SJiri Slaby 		bus = "USB";
120593c10132SJiri Slaby 		break;
120693c10132SJiri Slaby 	case BUS_BLUETOOTH:
120793c10132SJiri Slaby 		bus = "BLUETOOTH";
120893c10132SJiri Slaby 		break;
120993c10132SJiri Slaby 	default:
121093c10132SJiri Slaby 		bus = "<UNKNOWN>";
121193c10132SJiri Slaby 	}
121293c10132SJiri Slaby 
121393c10132SJiri Slaby 	dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
121493c10132SJiri Slaby 			buf, bus, hdev->version >> 8, hdev->version & 0xff,
121593c10132SJiri Slaby 			type, hdev->name, hdev->phys);
121693c10132SJiri Slaby 
121793c10132SJiri Slaby 	return 0;
121893c10132SJiri Slaby }
121993c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect);
122093c10132SJiri Slaby 
1221c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev)
1222c4c259bcSJiri Kosina {
1223c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_INPUT)
1224c4c259bcSJiri Kosina 		hidinput_disconnect(hdev);
1225c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1226c4c259bcSJiri Kosina 		hdev->hiddev_disconnect(hdev);
1227c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1228c4c259bcSJiri Kosina 		hidraw_disconnect(hdev);
1229c4c259bcSJiri Kosina }
1230c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect);
1231c4c259bcSJiri Kosina 
1232bae7eb33SJiri Kosina /* a list of devices for which there is a specialized driver on HID bus */
123385cdaf52SJiri Slaby static const struct hid_device_id hid_blacklist[] = {
1234b6353f4fSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
12356dec143aSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
123614a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
123714a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1238b7e1b203SLech Perczak 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1239c0dbcc33SSergei Kolzun #if defined(CONFIG_HID_ACRUX_FF) || defined(CONFIG_HID_ACRUX_FF_MODULE)
1240c0dbcc33SSergei Kolzun 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1241c0dbcc33SSergei Kolzun #endif
1242df9bcaceSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
12438c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
12448c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1245128537ceSMichael Poole 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1246a462230eSChase Douglas 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
12478c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
12488c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
12498c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
12508c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
12518c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
12528c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
12538c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
12548c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
12558c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
12568c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
12578c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1258fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1259fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1260fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
12618c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
12628c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
12638c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
12648c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
12658c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
12668c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1267ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1268ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1269ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
12708c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
12718c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
12728c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
12738c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
12748c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
12758c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1276a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1277a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1278a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
127999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
128099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
128199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
128299b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
128399b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
128499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
128523aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
128623aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
128723aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
12888c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
12898c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1290eaca1386SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1291cec15a0eSRoland Baum 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1292b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1293bf280628SWayne Thomas 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1294c3dc66deSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
129536213e1eSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1296ba4d8abbSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1297272036edSFrançois Jaouen 	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
12983b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
12991ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1300fcfacfd3SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1301*b9e4b1e0SDennis Kügler 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
13023a370ca1SDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
13030f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
13040f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1305e8d0eab4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
13060f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
13073f866fbdSRichard Walmsley 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
13080c3910c2SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
130983e44918SChris Ball 	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
131064b386eaSRichard Nauber 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
131104561c5aSIgnaz Forster 	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
13121f243e30SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
13135181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1314578f3a35SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
13155181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
131642859e0bSLukasz Lubojanski 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1317949f8fefSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
13181e093206SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1319c2fd1a4eSCory Maccarrone 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1320fdf93aa3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
132179422741SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1322b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
13235f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
13245f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
13255f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
13265f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
13275f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
13285f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
13295f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
13305f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
13315f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
13325f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
13335f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
13342c6118e4SHendrik Iben 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1335606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1336606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1337606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1338fd30ea8cSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1339606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
134074f292caSGary Stein 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1341606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1342606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1343243b706dSChristophe Borivant 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
134432c88cbcSSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1345606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
134624985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
134724985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1348236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1349236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
135078a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
135178a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
135278a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
135378a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
135478a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
13553b8006e5SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
135694011f93SRafi Rubin 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
13576e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
13586e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
13596e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
13606e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
13616e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
13626e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
13636e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
13646e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
13656e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
13666e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
13676e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
13686e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
13696e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
13706e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
13716e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
13726e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
13736e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
13746e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1375cd9ec30dSJohnathon Harris 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
13761e762532SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
137749e4739aSStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1378f54405dbSAlex Neblett 	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
137914bf62cdSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1380cb7cf3daSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
1381980a3da6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1382b355850bSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1383bd28ce00SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1384f9ce7c28SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1385cc6e0bbbSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1386d3fb5454SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1387b6dc7992SPascal Auriel - Stantum 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1388b6dc7992SPascal Auriel - Stantum 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
138990231e7eSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1390daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1391daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
13927a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
13937a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1394daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
13953ee8f0a2SMarkus Rathgeb 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1396daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1397f14f526dSLev Babiev 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
139854001081SKees Bakker 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1399711a680eSBruno Premont 	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
140041fa9230SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1401f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1402f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1403f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
1404fac733f0SJussi Kivilinna 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1405ca2dcd40SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
140672a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
140700e7f964SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
140872a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
14098f1acc32SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1410daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1411daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1412a9885c8fSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
14138c19a515SJiri Slaby 
141478a849a6SJiri Slaby 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
141585cdaf52SJiri Slaby 	{ }
141685cdaf52SJiri Slaby };
141785cdaf52SJiri Slaby 
14183a6f82f7SJiri Slaby struct hid_dynid {
14193a6f82f7SJiri Slaby 	struct list_head list;
14203a6f82f7SJiri Slaby 	struct hid_device_id id;
14213a6f82f7SJiri Slaby };
14223a6f82f7SJiri Slaby 
14233a6f82f7SJiri Slaby /**
14243a6f82f7SJiri Slaby  * store_new_id - add a new HID device ID to this driver and re-probe devices
14253a6f82f7SJiri Slaby  * @driver: target device driver
14263a6f82f7SJiri Slaby  * @buf: buffer for scanning device ID data
14273a6f82f7SJiri Slaby  * @count: input size
14283a6f82f7SJiri Slaby  *
14293a6f82f7SJiri Slaby  * Adds a new dynamic hid device ID to this driver,
14303a6f82f7SJiri Slaby  * and causes the driver to probe for all devices again.
14313a6f82f7SJiri Slaby  */
14323a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf,
14333a6f82f7SJiri Slaby 		size_t count)
14343a6f82f7SJiri Slaby {
14353a6f82f7SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
14363a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
14373a6f82f7SJiri Slaby 	__u32 bus, vendor, product;
14383a6f82f7SJiri Slaby 	unsigned long driver_data = 0;
14393a6f82f7SJiri Slaby 	int ret;
14403a6f82f7SJiri Slaby 
14413a6f82f7SJiri Slaby 	ret = sscanf(buf, "%x %x %x %lx",
14423a6f82f7SJiri Slaby 			&bus, &vendor, &product, &driver_data);
14433a6f82f7SJiri Slaby 	if (ret < 3)
14443a6f82f7SJiri Slaby 		return -EINVAL;
14453a6f82f7SJiri Slaby 
14463a6f82f7SJiri Slaby 	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
14473a6f82f7SJiri Slaby 	if (!dynid)
14483a6f82f7SJiri Slaby 		return -ENOMEM;
14493a6f82f7SJiri Slaby 
14503a6f82f7SJiri Slaby 	dynid->id.bus = bus;
14513a6f82f7SJiri Slaby 	dynid->id.vendor = vendor;
14523a6f82f7SJiri Slaby 	dynid->id.product = product;
14533a6f82f7SJiri Slaby 	dynid->id.driver_data = driver_data;
14543a6f82f7SJiri Slaby 
14553a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
14563a6f82f7SJiri Slaby 	list_add_tail(&dynid->list, &hdrv->dyn_list);
14573a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
14583a6f82f7SJiri Slaby 
14593a6f82f7SJiri Slaby 	ret = 0;
14603a6f82f7SJiri Slaby 	if (get_driver(&hdrv->driver)) {
14613a6f82f7SJiri Slaby 		ret = driver_attach(&hdrv->driver);
14623a6f82f7SJiri Slaby 		put_driver(&hdrv->driver);
14633a6f82f7SJiri Slaby 	}
14643a6f82f7SJiri Slaby 
14653a6f82f7SJiri Slaby 	return ret ? : count;
14663a6f82f7SJiri Slaby }
14673a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
14683a6f82f7SJiri Slaby 
14693a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv)
14703a6f82f7SJiri Slaby {
14713a6f82f7SJiri Slaby 	struct hid_dynid *dynid, *n;
14723a6f82f7SJiri Slaby 
14733a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
14743a6f82f7SJiri Slaby 	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
14753a6f82f7SJiri Slaby 		list_del(&dynid->list);
14763a6f82f7SJiri Slaby 		kfree(dynid);
14773a6f82f7SJiri Slaby 	}
14783a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
14793a6f82f7SJiri Slaby }
14803a6f82f7SJiri Slaby 
14813a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
14823a6f82f7SJiri Slaby 		struct hid_driver *hdrv)
14833a6f82f7SJiri Slaby {
14843a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
14853a6f82f7SJiri Slaby 
14863a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
14873a6f82f7SJiri Slaby 	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
14883a6f82f7SJiri Slaby 		if (hid_match_one_id(hdev, &dynid->id)) {
14893a6f82f7SJiri Slaby 			spin_unlock(&hdrv->dyn_lock);
14903a6f82f7SJiri Slaby 			return &dynid->id;
14913a6f82f7SJiri Slaby 		}
14923a6f82f7SJiri Slaby 	}
14933a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
14943a6f82f7SJiri Slaby 
14953a6f82f7SJiri Slaby 	return hid_match_id(hdev, hdrv->id_table);
14963a6f82f7SJiri Slaby }
14973a6f82f7SJiri Slaby 
149885cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv)
149985cdaf52SJiri Slaby {
150085cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
150185cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
150285cdaf52SJiri Slaby 
15033a6f82f7SJiri Slaby 	if (!hid_match_device(hdev, hdrv))
150485cdaf52SJiri Slaby 		return 0;
150585cdaf52SJiri Slaby 
150685cdaf52SJiri Slaby 	/* generic wants all non-blacklisted */
150785cdaf52SJiri Slaby 	if (!strncmp(hdrv->name, "generic-", 8))
150885cdaf52SJiri Slaby 		return !hid_match_id(hdev, hid_blacklist);
150985cdaf52SJiri Slaby 
151085cdaf52SJiri Slaby 	return 1;
151185cdaf52SJiri Slaby }
151285cdaf52SJiri Slaby 
151385cdaf52SJiri Slaby static int hid_device_probe(struct device *dev)
151485cdaf52SJiri Slaby {
151585cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(dev->driver,
151685cdaf52SJiri Slaby 			struct hid_driver, driver);
151785cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
151885cdaf52SJiri Slaby 	const struct hid_device_id *id;
151985cdaf52SJiri Slaby 	int ret = 0;
152085cdaf52SJiri Slaby 
152185cdaf52SJiri Slaby 	if (!hdev->driver) {
15223a6f82f7SJiri Slaby 		id = hid_match_device(hdev, hdrv);
1523c500c971SJiri Slaby 		if (id == NULL)
1524c500c971SJiri Slaby 			return -ENODEV;
1525c500c971SJiri Slaby 
152685cdaf52SJiri Slaby 		hdev->driver = hdrv;
1527c500c971SJiri Slaby 		if (hdrv->probe) {
1528c500c971SJiri Slaby 			ret = hdrv->probe(hdev, id);
1529c500c971SJiri Slaby 		} else { /* default probe */
1530c500c971SJiri Slaby 			ret = hid_parse(hdev);
1531c500c971SJiri Slaby 			if (!ret)
153293c10132SJiri Slaby 				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1533c500c971SJiri Slaby 		}
1534c500c971SJiri Slaby 		if (ret)
1535c500c971SJiri Slaby 			hdev->driver = NULL;
153685cdaf52SJiri Slaby 	}
153785cdaf52SJiri Slaby 	return ret;
153885cdaf52SJiri Slaby }
153985cdaf52SJiri Slaby 
154085cdaf52SJiri Slaby static int hid_device_remove(struct device *dev)
154185cdaf52SJiri Slaby {
154285cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
154385cdaf52SJiri Slaby 	struct hid_driver *hdrv = hdev->driver;
154485cdaf52SJiri Slaby 
154585cdaf52SJiri Slaby 	if (hdrv) {
154685cdaf52SJiri Slaby 		if (hdrv->remove)
154785cdaf52SJiri Slaby 			hdrv->remove(hdev);
1548c500c971SJiri Slaby 		else /* default remove */
1549c500c971SJiri Slaby 			hid_hw_stop(hdev);
155085cdaf52SJiri Slaby 		hdev->driver = NULL;
155185cdaf52SJiri Slaby 	}
155285cdaf52SJiri Slaby 
155385cdaf52SJiri Slaby 	return 0;
155485cdaf52SJiri Slaby }
155585cdaf52SJiri Slaby 
155685cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
155785cdaf52SJiri Slaby {
155885cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
155985cdaf52SJiri Slaby 
156085cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
156185cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
156285cdaf52SJiri Slaby 		return -ENOMEM;
156385cdaf52SJiri Slaby 
156485cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
156585cdaf52SJiri Slaby 		return -ENOMEM;
156685cdaf52SJiri Slaby 
156785cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
156885cdaf52SJiri Slaby 		return -ENOMEM;
156985cdaf52SJiri Slaby 
157085cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
157185cdaf52SJiri Slaby 		return -ENOMEM;
157285cdaf52SJiri Slaby 
157385cdaf52SJiri Slaby 	if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
157485cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
157585cdaf52SJiri Slaby 		return -ENOMEM;
157685cdaf52SJiri Slaby 
157785cdaf52SJiri Slaby 	return 0;
157885cdaf52SJiri Slaby }
157985cdaf52SJiri Slaby 
158085cdaf52SJiri Slaby static struct bus_type hid_bus_type = {
158185cdaf52SJiri Slaby 	.name		= "hid",
158285cdaf52SJiri Slaby 	.match		= hid_bus_match,
158385cdaf52SJiri Slaby 	.probe		= hid_device_probe,
158485cdaf52SJiri Slaby 	.remove		= hid_device_remove,
158585cdaf52SJiri Slaby 	.uevent		= hid_uevent,
158685cdaf52SJiri Slaby };
158785cdaf52SJiri Slaby 
1588bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */
1589d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = {
1590d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1591d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1592d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1593d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1594d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1595d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1596d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1597d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1598d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1599d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1600d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1601d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
160277f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
160377f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
160462a56582SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1605d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1606d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1607d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1608d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1609d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1610d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
16115f6108cfSAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1612d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1613d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1614d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
161570c66567SPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1616df506f2cSPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1617d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1618d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1619d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1620d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1621d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1622d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1623d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1624d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1625d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1626d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1627d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1628d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1629d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1630d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1631d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1632d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1633d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1634d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1635d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1636d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1637d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1638d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1639d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1640d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1641d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1642d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1643d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1644d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1645d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1646d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1647d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1648d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1649d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1650d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1651d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1652d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1653d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1654d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1655d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1656d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1657d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1658d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1659d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1660d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1661d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1662d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1663d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1664d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1665d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1666d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1667d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1668d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1669d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1670d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1671d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1672d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1673d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1674d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1675d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1676d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1677d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1678d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1679d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1680d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1681d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
16826bc235a2STomoki Sekiyama 	{ HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_JESS_YUREX) },
1683d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1684c91c21c5SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1685d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1686eb8141ccSLamarque Vieira Souza 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1687d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1688d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1689d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1690d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1691d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1692d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1693d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
1694d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1695d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1696d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1697d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1698d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1699d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1700d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1701d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1702d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1703d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1704d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1705d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1706d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1707d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1708d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1709d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1710d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1711d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1712d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1713d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1714d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1715d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1716d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1717d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1718d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1719d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
17204cfae3e8SHenning Glawe 	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
172135cfd1d9SMichael Tokarev 	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1722d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1723d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1724d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1725d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1726d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1727d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1728d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1729d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1730d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1731d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1732d458a9dfSJiri Slaby 	{ }
1733d458a9dfSJiri Slaby };
1734d458a9dfSJiri Slaby 
1735b4d8e473SJiri Slaby /**
1736b4d8e473SJiri Slaby  * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1737b4d8e473SJiri Slaby  *
1738b4d8e473SJiri Slaby  * There are composite devices for which we want to ignore only a certain
1739b4d8e473SJiri Slaby  * interface. This is a list of devices for which only the mouse interface will
1740b4d8e473SJiri Slaby  * be ignored. This allows a dedicated driver to take care of the interface.
1741b4d8e473SJiri Slaby  */
1742b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = {
1743b4d8e473SJiri Slaby 	/* appletouch driver */
1744b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1745b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1746b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1747b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1748b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1749b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1750b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1751b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1752b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1753b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1754b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1755b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1756b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1757b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1758b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1759b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1760b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1761b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1762b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1763b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1764ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1765ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1766ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
176799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
176899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
176999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
177099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
177199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
177299b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1773b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1774b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1775b4d8e473SJiri Slaby 	{ }
1776b4d8e473SJiri Slaby };
1777b4d8e473SJiri Slaby 
1778d458a9dfSJiri Slaby static bool hid_ignore(struct hid_device *hdev)
1779d458a9dfSJiri Slaby {
1780d458a9dfSJiri Slaby 	switch (hdev->vendor) {
1781d458a9dfSJiri Slaby 	case USB_VENDOR_ID_CODEMERCS:
1782d458a9dfSJiri Slaby 		/* ignore all Code Mercenaries IOWarrior devices */
1783d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1784d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1785d458a9dfSJiri Slaby 			return true;
1786d458a9dfSJiri Slaby 		break;
1787d458a9dfSJiri Slaby 	case USB_VENDOR_ID_LOGITECH:
1788d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1789d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1790d458a9dfSJiri Slaby 			return true;
1791d458a9dfSJiri Slaby 		break;
179231f7fd79SJarod Wilson 	case USB_VENDOR_ID_SOUNDGRAPH:
179331f7fd79SJarod Wilson 		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
179431f7fd79SJarod Wilson 		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
179531f7fd79SJarod Wilson 			return true;
179631f7fd79SJarod Wilson 		break;
1797d458a9dfSJiri Slaby 	}
1798d458a9dfSJiri Slaby 
1799b4d8e473SJiri Slaby 	if (hdev->type == HID_TYPE_USBMOUSE &&
1800b4d8e473SJiri Slaby 			hid_match_id(hdev, hid_mouse_ignore_list))
1801b4d8e473SJiri Slaby 		return true;
1802b4d8e473SJiri Slaby 
1803d458a9dfSJiri Slaby 	return !!hid_match_id(hdev, hid_ignore_list);
1804d458a9dfSJiri Slaby }
1805d458a9dfSJiri Slaby 
180685cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev)
180785cdaf52SJiri Slaby {
180885cdaf52SJiri Slaby 	static atomic_t id = ATOMIC_INIT(0);
180985cdaf52SJiri Slaby 	int ret;
181085cdaf52SJiri Slaby 
181185cdaf52SJiri Slaby 	if (WARN_ON(hdev->status & HID_STAT_ADDED))
181285cdaf52SJiri Slaby 		return -EBUSY;
181385cdaf52SJiri Slaby 
1814d458a9dfSJiri Slaby 	/* we need to kill them here, otherwise they will stay allocated to
1815d458a9dfSJiri Slaby 	 * wait for coming driver */
1816e5a2a04cSJindrich Makovicka 	if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1817e5a2a04cSJindrich Makovicka             && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
1818d458a9dfSJiri Slaby 		return -ENODEV;
1819d458a9dfSJiri Slaby 
18206bbe586fSKay Sievers 	/* XXX hack, any other cleaner solution after the driver core
18216bbe586fSKay Sievers 	 * is converted to allow more than 20 bytes as the device name? */
18226bbe586fSKay Sievers 	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
182385cdaf52SJiri Slaby 		     hdev->vendor, hdev->product, atomic_inc_return(&id));
182485cdaf52SJiri Slaby 
18254da361b6SBruno Prémont 	hid_debug_register(hdev, dev_name(&hdev->dev));
182685cdaf52SJiri Slaby 	ret = device_add(&hdev->dev);
182785cdaf52SJiri Slaby 	if (!ret)
182885cdaf52SJiri Slaby 		hdev->status |= HID_STAT_ADDED;
18294da361b6SBruno Prémont 	else
18304da361b6SBruno Prémont 		hid_debug_unregister(hdev);
1831a635f9ddSJiri Kosina 
183285cdaf52SJiri Slaby 	return ret;
183385cdaf52SJiri Slaby }
183485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device);
183585cdaf52SJiri Slaby 
183685cdaf52SJiri Slaby /**
183785cdaf52SJiri Slaby  * hid_allocate_device - allocate new hid device descriptor
183885cdaf52SJiri Slaby  *
183985cdaf52SJiri Slaby  * Allocate and initialize hid device, so that hid_destroy_device might be
184085cdaf52SJiri Slaby  * used to free it.
184185cdaf52SJiri Slaby  *
184285cdaf52SJiri Slaby  * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
184385cdaf52SJiri Slaby  * error value.
184485cdaf52SJiri Slaby  */
184585cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void)
184685cdaf52SJiri Slaby {
184785cdaf52SJiri Slaby 	struct hid_device *hdev;
184885cdaf52SJiri Slaby 	unsigned int i;
184985cdaf52SJiri Slaby 	int ret = -ENOMEM;
185085cdaf52SJiri Slaby 
185185cdaf52SJiri Slaby 	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
185285cdaf52SJiri Slaby 	if (hdev == NULL)
185385cdaf52SJiri Slaby 		return ERR_PTR(ret);
185485cdaf52SJiri Slaby 
185585cdaf52SJiri Slaby 	device_initialize(&hdev->dev);
185685cdaf52SJiri Slaby 	hdev->dev.release = hid_device_release;
185785cdaf52SJiri Slaby 	hdev->dev.bus = &hid_bus_type;
185885cdaf52SJiri Slaby 
185985cdaf52SJiri Slaby 	hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
186085cdaf52SJiri Slaby 			sizeof(struct hid_collection), GFP_KERNEL);
186185cdaf52SJiri Slaby 	if (hdev->collection == NULL)
186285cdaf52SJiri Slaby 		goto err;
186385cdaf52SJiri Slaby 	hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
186485cdaf52SJiri Slaby 
186585cdaf52SJiri Slaby 	for (i = 0; i < HID_REPORT_TYPES; i++)
186685cdaf52SJiri Slaby 		INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
186785cdaf52SJiri Slaby 
1868cd667ce2SJiri Kosina 	init_waitqueue_head(&hdev->debug_wait);
1869cd667ce2SJiri Kosina 	INIT_LIST_HEAD(&hdev->debug_list);
1870cd667ce2SJiri Kosina 
187185cdaf52SJiri Slaby 	return hdev;
187285cdaf52SJiri Slaby err:
187385cdaf52SJiri Slaby 	put_device(&hdev->dev);
187485cdaf52SJiri Slaby 	return ERR_PTR(ret);
187585cdaf52SJiri Slaby }
187685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device);
187785cdaf52SJiri Slaby 
187885cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev)
187985cdaf52SJiri Slaby {
188085cdaf52SJiri Slaby 	if (hdev->status & HID_STAT_ADDED) {
188185cdaf52SJiri Slaby 		device_del(&hdev->dev);
1882a635f9ddSJiri Kosina 		hid_debug_unregister(hdev);
188385cdaf52SJiri Slaby 		hdev->status &= ~HID_STAT_ADDED;
188485cdaf52SJiri Slaby 	}
188585cdaf52SJiri Slaby }
188685cdaf52SJiri Slaby 
188785cdaf52SJiri Slaby /**
188885cdaf52SJiri Slaby  * hid_destroy_device - free previously allocated device
188985cdaf52SJiri Slaby  *
189085cdaf52SJiri Slaby  * @hdev: hid device
189185cdaf52SJiri Slaby  *
189285cdaf52SJiri Slaby  * If you allocate hid_device through hid_allocate_device, you should ever
189385cdaf52SJiri Slaby  * free by this function.
189485cdaf52SJiri Slaby  */
189585cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev)
189685cdaf52SJiri Slaby {
189785cdaf52SJiri Slaby 	hid_remove_device(hdev);
189885cdaf52SJiri Slaby 	put_device(&hdev->dev);
189985cdaf52SJiri Slaby }
190085cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device);
190185cdaf52SJiri Slaby 
190285cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
190385cdaf52SJiri Slaby 		const char *mod_name)
190485cdaf52SJiri Slaby {
19053a6f82f7SJiri Slaby 	int ret;
19063a6f82f7SJiri Slaby 
190785cdaf52SJiri Slaby 	hdrv->driver.name = hdrv->name;
190885cdaf52SJiri Slaby 	hdrv->driver.bus = &hid_bus_type;
190985cdaf52SJiri Slaby 	hdrv->driver.owner = owner;
191085cdaf52SJiri Slaby 	hdrv->driver.mod_name = mod_name;
191185cdaf52SJiri Slaby 
19123a6f82f7SJiri Slaby 	INIT_LIST_HEAD(&hdrv->dyn_list);
19133a6f82f7SJiri Slaby 	spin_lock_init(&hdrv->dyn_lock);
19143a6f82f7SJiri Slaby 
19153a6f82f7SJiri Slaby 	ret = driver_register(&hdrv->driver);
19163a6f82f7SJiri Slaby 	if (ret)
19173a6f82f7SJiri Slaby 		return ret;
19183a6f82f7SJiri Slaby 
19193a6f82f7SJiri Slaby 	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
19203a6f82f7SJiri Slaby 	if (ret)
19213a6f82f7SJiri Slaby 		driver_unregister(&hdrv->driver);
19223a6f82f7SJiri Slaby 
19233a6f82f7SJiri Slaby 	return ret;
192485cdaf52SJiri Slaby }
192585cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver);
192685cdaf52SJiri Slaby 
192785cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv)
192885cdaf52SJiri Slaby {
19293a6f82f7SJiri Slaby 	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
193085cdaf52SJiri Slaby 	driver_unregister(&hdrv->driver);
19313a6f82f7SJiri Slaby 	hid_free_dynids(hdrv);
193285cdaf52SJiri Slaby }
193385cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver);
193485cdaf52SJiri Slaby 
19350361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid)
19360361a28dSOliver Neukum {
19370361a28dSOliver Neukum 	struct hid_input *hidinput;
19380361a28dSOliver Neukum 	int i;
19390361a28dSOliver Neukum 
1940e5288eb5SJiri Kosina 	if (!(hid->claimed & HID_CLAIMED_INPUT))
1941e5288eb5SJiri Kosina 		return 0;
1942e5288eb5SJiri Kosina 
19430361a28dSOliver Neukum 	list_for_each_entry(hidinput, &hid->inputs, list) {
19440361a28dSOliver Neukum 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
19450361a28dSOliver Neukum 			if (hidinput->input->key[i])
19460361a28dSOliver Neukum 				return 1;
19470361a28dSOliver Neukum 	}
19480361a28dSOliver Neukum 
19490361a28dSOliver Neukum 	return 0;
19500361a28dSOliver Neukum }
19510361a28dSOliver Neukum 
19520361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
19530361a28dSOliver Neukum 
195486166b7bSJiri Kosina static int __init hid_init(void)
195586166b7bSJiri Kosina {
195685cdaf52SJiri Slaby 	int ret;
195785cdaf52SJiri Slaby 
1958a635f9ddSJiri Kosina 	if (hid_debug)
1959cd667ce2SJiri Kosina 		printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
1960cd667ce2SJiri Kosina 				"HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
1961a635f9ddSJiri Kosina 
196285cdaf52SJiri Slaby 	ret = bus_register(&hid_bus_type);
196385cdaf52SJiri Slaby 	if (ret) {
196485cdaf52SJiri Slaby 		printk(KERN_ERR "HID: can't register hid bus\n");
196585cdaf52SJiri Slaby 		goto err;
196685cdaf52SJiri Slaby 	}
196785cdaf52SJiri Slaby 
196885cdaf52SJiri Slaby 	ret = hidraw_init();
196985cdaf52SJiri Slaby 	if (ret)
197085cdaf52SJiri Slaby 		goto err_bus;
197185cdaf52SJiri Slaby 
1972a635f9ddSJiri Kosina 	hid_debug_init();
1973a635f9ddSJiri Kosina 
197485cdaf52SJiri Slaby 	return 0;
197585cdaf52SJiri Slaby err_bus:
197685cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
197785cdaf52SJiri Slaby err:
197885cdaf52SJiri Slaby 	return ret;
197986166b7bSJiri Kosina }
198086166b7bSJiri Kosina 
198186166b7bSJiri Kosina static void __exit hid_exit(void)
198286166b7bSJiri Kosina {
1983a635f9ddSJiri Kosina 	hid_debug_exit();
198486166b7bSJiri Kosina 	hidraw_exit();
198585cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
198686166b7bSJiri Kosina }
198786166b7bSJiri Kosina 
198886166b7bSJiri Kosina module_init(hid_init);
198986166b7bSJiri Kosina module_exit(hid_exit);
199086166b7bSJiri Kosina 
199188adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal");
199288adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik");
199388adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina");
1994aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
1995aa938f79SJiri Kosina 
1996