xref: /openbmc/linux/drivers/hid/hid-core.c (revision 0adb9c2c5ed42f199cb2a630c37d18dee385fae2)
1dde5845aSJiri Kosina /*
2229695e5SJiri Kosina  *  HID support for Linux
3dde5845aSJiri Kosina  *
4dde5845aSJiri Kosina  *  Copyright (c) 1999 Andreas Gal
5dde5845aSJiri Kosina  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6dde5845aSJiri Kosina  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
76b1968d5SJiri Kosina  *  Copyright (c) 2006-2012 Jiri Kosina
8dde5845aSJiri Kosina  */
9dde5845aSJiri Kosina 
10dde5845aSJiri Kosina /*
11dde5845aSJiri Kosina  * This program is free software; you can redistribute it and/or modify it
12dde5845aSJiri Kosina  * under the terms of the GNU General Public License as published by the Free
13dde5845aSJiri Kosina  * Software Foundation; either version 2 of the License, or (at your option)
14dde5845aSJiri Kosina  * any later version.
15dde5845aSJiri Kosina  */
16dde5845aSJiri Kosina 
174291ee30SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
184291ee30SJoe Perches 
19dde5845aSJiri Kosina #include <linux/module.h>
20dde5845aSJiri Kosina #include <linux/slab.h>
21dde5845aSJiri Kosina #include <linux/init.h>
22dde5845aSJiri Kosina #include <linux/kernel.h>
23dde5845aSJiri Kosina #include <linux/list.h>
24dde5845aSJiri Kosina #include <linux/mm.h>
25dde5845aSJiri Kosina #include <linux/spinlock.h>
26dde5845aSJiri Kosina #include <asm/unaligned.h>
27dde5845aSJiri Kosina #include <asm/byteorder.h>
28dde5845aSJiri Kosina #include <linux/input.h>
29dde5845aSJiri Kosina #include <linux/wait.h>
3047a80edbSJiri Kosina #include <linux/vmalloc.h>
31c4124c9bSJiri Kosina #include <linux/sched.h>
324ea54542SDavid Herrmann #include <linux/semaphore.h>
33dde5845aSJiri Kosina 
34dde5845aSJiri Kosina #include <linux/hid.h>
35dde5845aSJiri Kosina #include <linux/hiddev.h>
36c080d89aSJiri Kosina #include <linux/hid-debug.h>
3786166b7bSJiri Kosina #include <linux/hidraw.h>
38dde5845aSJiri Kosina 
395f22a799SJiri Slaby #include "hid-ids.h"
405f22a799SJiri Slaby 
41dde5845aSJiri Kosina /*
42dde5845aSJiri Kosina  * Version Information
43dde5845aSJiri Kosina  */
44dde5845aSJiri Kosina 
4553149801SJiri Kosina #define DRIVER_DESC "HID core driver"
46dde5845aSJiri Kosina #define DRIVER_LICENSE "GPL"
47dde5845aSJiri Kosina 
4858037eb9SJiri Kosina int hid_debug = 0;
49377e10fbSAnssi Hannula module_param_named(debug, hid_debug, int, 0600);
50cd667ce2SJiri Kosina MODULE_PARM_DESC(debug, "toggle HID debugging messages");
5158037eb9SJiri Kosina EXPORT_SYMBOL_GPL(hid_debug);
5258037eb9SJiri Kosina 
536b1968d5SJiri Kosina static int hid_ignore_special_drivers = 0;
546b1968d5SJiri Kosina module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
556b1968d5SJiri Kosina MODULE_PARM_DESC(debug, "Ignore any special drivers and handle all devices by generic driver");
566b1968d5SJiri Kosina 
57dde5845aSJiri Kosina /*
58dde5845aSJiri Kosina  * Register a new report for a device.
59dde5845aSJiri Kosina  */
60dde5845aSJiri Kosina 
6190a006abSMichael Poole struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
62dde5845aSJiri Kosina {
63dde5845aSJiri Kosina 	struct hid_report_enum *report_enum = device->report_enum + type;
64dde5845aSJiri Kosina 	struct hid_report *report;
65dde5845aSJiri Kosina 
66dde5845aSJiri Kosina 	if (report_enum->report_id_hash[id])
67dde5845aSJiri Kosina 		return report_enum->report_id_hash[id];
68dde5845aSJiri Kosina 
69a3789a17SJoe Perches 	report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
70a3789a17SJoe Perches 	if (!report)
71dde5845aSJiri Kosina 		return NULL;
72dde5845aSJiri Kosina 
73dde5845aSJiri Kosina 	if (id != 0)
74dde5845aSJiri Kosina 		report_enum->numbered = 1;
75dde5845aSJiri Kosina 
76dde5845aSJiri Kosina 	report->id = id;
77dde5845aSJiri Kosina 	report->type = type;
78dde5845aSJiri Kosina 	report->size = 0;
79dde5845aSJiri Kosina 	report->device = device;
80dde5845aSJiri Kosina 	report_enum->report_id_hash[id] = report;
81dde5845aSJiri Kosina 
82dde5845aSJiri Kosina 	list_add_tail(&report->list, &report_enum->report_list);
83dde5845aSJiri Kosina 
84dde5845aSJiri Kosina 	return report;
85dde5845aSJiri Kosina }
8690a006abSMichael Poole EXPORT_SYMBOL_GPL(hid_register_report);
87dde5845aSJiri Kosina 
88dde5845aSJiri Kosina /*
89dde5845aSJiri Kosina  * Register a new field for this report.
90dde5845aSJiri Kosina  */
91dde5845aSJiri Kosina 
92dde5845aSJiri Kosina static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
93dde5845aSJiri Kosina {
94dde5845aSJiri Kosina 	struct hid_field *field;
95f262d1faSBenjamin Tissoires 	int i;
96dde5845aSJiri Kosina 
97dde5845aSJiri Kosina 	if (report->maxfield == HID_MAX_FIELDS) {
988c3d52fcSJiri Kosina 		hid_err(report->device, "too many fields in report\n");
99dde5845aSJiri Kosina 		return NULL;
100dde5845aSJiri Kosina 	}
101dde5845aSJiri Kosina 
102a3789a17SJoe Perches 	field = kzalloc((sizeof(struct hid_field) +
103a3789a17SJoe Perches 			 usages * sizeof(struct hid_usage) +
104a3789a17SJoe Perches 			 values * sizeof(unsigned)), GFP_KERNEL);
105a3789a17SJoe Perches 	if (!field)
106a3789a17SJoe Perches 		return NULL;
107dde5845aSJiri Kosina 
108dde5845aSJiri Kosina 	field->index = report->maxfield++;
109dde5845aSJiri Kosina 	report->field[field->index] = field;
110dde5845aSJiri Kosina 	field->usage = (struct hid_usage *)(field + 1);
111282bfd4cSJiri Slaby 	field->value = (s32 *)(field->usage + usages);
112dde5845aSJiri Kosina 	field->report = report;
113dde5845aSJiri Kosina 
114f262d1faSBenjamin Tissoires 	for (i = 0; i < usages; i++)
115f262d1faSBenjamin Tissoires 		field->usage[i].usage_index = i;
116f262d1faSBenjamin Tissoires 
117dde5845aSJiri Kosina 	return field;
118dde5845aSJiri Kosina }
119dde5845aSJiri Kosina 
120dde5845aSJiri Kosina /*
121dde5845aSJiri Kosina  * Open a collection. The type/usage is pushed on the stack.
122dde5845aSJiri Kosina  */
123dde5845aSJiri Kosina 
124dde5845aSJiri Kosina static int open_collection(struct hid_parser *parser, unsigned type)
125dde5845aSJiri Kosina {
126dde5845aSJiri Kosina 	struct hid_collection *collection;
127dde5845aSJiri Kosina 	unsigned usage;
128dde5845aSJiri Kosina 
129dde5845aSJiri Kosina 	usage = parser->local.usage[0];
130dde5845aSJiri Kosina 
131dde5845aSJiri Kosina 	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
1328c3d52fcSJiri Kosina 		hid_err(parser->device, "collection stack overflow\n");
133a6fbaacfSSachin Kamat 		return -EINVAL;
134dde5845aSJiri Kosina 	}
135dde5845aSJiri Kosina 
136dde5845aSJiri Kosina 	if (parser->device->maxcollection == parser->device->collection_size) {
137dde5845aSJiri Kosina 		collection = kmalloc(sizeof(struct hid_collection) *
138dde5845aSJiri Kosina 				parser->device->collection_size * 2, GFP_KERNEL);
139dde5845aSJiri Kosina 		if (collection == NULL) {
1408c3d52fcSJiri Kosina 			hid_err(parser->device, "failed to reallocate collection array\n");
141a6fbaacfSSachin Kamat 			return -ENOMEM;
142dde5845aSJiri Kosina 		}
143dde5845aSJiri Kosina 		memcpy(collection, parser->device->collection,
144dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
145dde5845aSJiri Kosina 			parser->device->collection_size);
146dde5845aSJiri Kosina 		memset(collection + parser->device->collection_size, 0,
147dde5845aSJiri Kosina 			sizeof(struct hid_collection) *
148dde5845aSJiri Kosina 			parser->device->collection_size);
149dde5845aSJiri Kosina 		kfree(parser->device->collection);
150dde5845aSJiri Kosina 		parser->device->collection = collection;
151dde5845aSJiri Kosina 		parser->device->collection_size *= 2;
152dde5845aSJiri Kosina 	}
153dde5845aSJiri Kosina 
154dde5845aSJiri Kosina 	parser->collection_stack[parser->collection_stack_ptr++] =
155dde5845aSJiri Kosina 		parser->device->maxcollection;
156dde5845aSJiri Kosina 
157dde5845aSJiri Kosina 	collection = parser->device->collection +
158dde5845aSJiri Kosina 		parser->device->maxcollection++;
159dde5845aSJiri Kosina 	collection->type = type;
160dde5845aSJiri Kosina 	collection->usage = usage;
161dde5845aSJiri Kosina 	collection->level = parser->collection_stack_ptr - 1;
162dde5845aSJiri Kosina 
163dde5845aSJiri Kosina 	if (type == HID_COLLECTION_APPLICATION)
164dde5845aSJiri Kosina 		parser->device->maxapplication++;
165dde5845aSJiri Kosina 
166dde5845aSJiri Kosina 	return 0;
167dde5845aSJiri Kosina }
168dde5845aSJiri Kosina 
169dde5845aSJiri Kosina /*
170dde5845aSJiri Kosina  * Close a collection.
171dde5845aSJiri Kosina  */
172dde5845aSJiri Kosina 
173dde5845aSJiri Kosina static int close_collection(struct hid_parser *parser)
174dde5845aSJiri Kosina {
175dde5845aSJiri Kosina 	if (!parser->collection_stack_ptr) {
1768c3d52fcSJiri Kosina 		hid_err(parser->device, "collection stack underflow\n");
177a6fbaacfSSachin Kamat 		return -EINVAL;
178dde5845aSJiri Kosina 	}
179dde5845aSJiri Kosina 	parser->collection_stack_ptr--;
180dde5845aSJiri Kosina 	return 0;
181dde5845aSJiri Kosina }
182dde5845aSJiri Kosina 
183dde5845aSJiri Kosina /*
184dde5845aSJiri Kosina  * Climb up the stack, search for the specified collection type
185dde5845aSJiri Kosina  * and return the usage.
186dde5845aSJiri Kosina  */
187dde5845aSJiri Kosina 
188dde5845aSJiri Kosina static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
189dde5845aSJiri Kosina {
190504499f2SJoe Perches 	struct hid_collection *collection = parser->device->collection;
191dde5845aSJiri Kosina 	int n;
192504499f2SJoe Perches 
193504499f2SJoe Perches 	for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
194504499f2SJoe Perches 		unsigned index = parser->collection_stack[n];
195504499f2SJoe Perches 		if (collection[index].type == type)
196504499f2SJoe Perches 			return collection[index].usage;
197504499f2SJoe Perches 	}
198dde5845aSJiri Kosina 	return 0; /* we know nothing about this usage type */
199dde5845aSJiri Kosina }
200dde5845aSJiri Kosina 
201dde5845aSJiri Kosina /*
202dde5845aSJiri Kosina  * Add a usage to the temporary parser table.
203dde5845aSJiri Kosina  */
204dde5845aSJiri Kosina 
205dde5845aSJiri Kosina static int hid_add_usage(struct hid_parser *parser, unsigned usage)
206dde5845aSJiri Kosina {
207dde5845aSJiri Kosina 	if (parser->local.usage_index >= HID_MAX_USAGES) {
2088c3d52fcSJiri Kosina 		hid_err(parser->device, "usage index exceeded\n");
209dde5845aSJiri Kosina 		return -1;
210dde5845aSJiri Kosina 	}
211dde5845aSJiri Kosina 	parser->local.usage[parser->local.usage_index] = usage;
212dde5845aSJiri Kosina 	parser->local.collection_index[parser->local.usage_index] =
213dde5845aSJiri Kosina 		parser->collection_stack_ptr ?
214dde5845aSJiri Kosina 		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
215dde5845aSJiri Kosina 	parser->local.usage_index++;
216dde5845aSJiri Kosina 	return 0;
217dde5845aSJiri Kosina }
218dde5845aSJiri Kosina 
219dde5845aSJiri Kosina /*
220dde5845aSJiri Kosina  * Register a new field for this report.
221dde5845aSJiri Kosina  */
222dde5845aSJiri Kosina 
223dde5845aSJiri Kosina static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
224dde5845aSJiri Kosina {
225dde5845aSJiri Kosina 	struct hid_report *report;
226dde5845aSJiri Kosina 	struct hid_field *field;
227dde5845aSJiri Kosina 	int usages;
228dde5845aSJiri Kosina 	unsigned offset;
229dde5845aSJiri Kosina 	int i;
230dde5845aSJiri Kosina 
231a3789a17SJoe Perches 	report = hid_register_report(parser->device, report_type, parser->global.report_id);
232a3789a17SJoe Perches 	if (!report) {
2338c3d52fcSJiri Kosina 		hid_err(parser->device, "hid_register_report failed\n");
234dde5845aSJiri Kosina 		return -1;
235dde5845aSJiri Kosina 	}
236dde5845aSJiri Kosina 
237bb2e1976SJiri Kosina 	/* Handle both signed and unsigned cases properly */
2380cd516c2Ssrinivas pandruvada 	if ((parser->global.logical_minimum < 0 &&
2390cd516c2Ssrinivas pandruvada 		parser->global.logical_maximum <
2400cd516c2Ssrinivas pandruvada 		parser->global.logical_minimum) ||
2410cd516c2Ssrinivas pandruvada 		(parser->global.logical_minimum >= 0 &&
2420cd516c2Ssrinivas pandruvada 		(__u32)parser->global.logical_maximum <
2430cd516c2Ssrinivas pandruvada 		(__u32)parser->global.logical_minimum)) {
2440cd516c2Ssrinivas pandruvada 		dbg_hid("logical range invalid 0x%x 0x%x\n",
2450cd516c2Ssrinivas pandruvada 			parser->global.logical_minimum,
2460cd516c2Ssrinivas pandruvada 			parser->global.logical_maximum);
247dde5845aSJiri Kosina 		return -1;
248dde5845aSJiri Kosina 	}
249dde5845aSJiri Kosina 
250dde5845aSJiri Kosina 	offset = report->size;
251dde5845aSJiri Kosina 	report->size += parser->global.report_size * parser->global.report_count;
252dde5845aSJiri Kosina 
253dde5845aSJiri Kosina 	if (!parser->local.usage_index) /* Ignore padding fields */
254dde5845aSJiri Kosina 		return 0;
255dde5845aSJiri Kosina 
256dde5845aSJiri Kosina 	usages = max_t(int, parser->local.usage_index, parser->global.report_count);
257dde5845aSJiri Kosina 
258a3789a17SJoe Perches 	field = hid_register_field(report, usages, parser->global.report_count);
259a3789a17SJoe Perches 	if (!field)
260dde5845aSJiri Kosina 		return 0;
261dde5845aSJiri Kosina 
262dde5845aSJiri Kosina 	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
263dde5845aSJiri Kosina 	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
264dde5845aSJiri Kosina 	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
265dde5845aSJiri Kosina 
266dde5845aSJiri Kosina 	for (i = 0; i < usages; i++) {
267dde5845aSJiri Kosina 		int j = i;
268dde5845aSJiri Kosina 		/* Duplicate the last usage we parsed if we have excess values */
269dde5845aSJiri Kosina 		if (i >= parser->local.usage_index)
270dde5845aSJiri Kosina 			j = parser->local.usage_index - 1;
271dde5845aSJiri Kosina 		field->usage[i].hid = parser->local.usage[j];
272dde5845aSJiri Kosina 		field->usage[i].collection_index =
273dde5845aSJiri Kosina 			parser->local.collection_index[j];
274dde5845aSJiri Kosina 	}
275dde5845aSJiri Kosina 
276dde5845aSJiri Kosina 	field->maxusage = usages;
277dde5845aSJiri Kosina 	field->flags = flags;
278dde5845aSJiri Kosina 	field->report_offset = offset;
279dde5845aSJiri Kosina 	field->report_type = report_type;
280dde5845aSJiri Kosina 	field->report_size = parser->global.report_size;
281dde5845aSJiri Kosina 	field->report_count = parser->global.report_count;
282dde5845aSJiri Kosina 	field->logical_minimum = parser->global.logical_minimum;
283dde5845aSJiri Kosina 	field->logical_maximum = parser->global.logical_maximum;
284dde5845aSJiri Kosina 	field->physical_minimum = parser->global.physical_minimum;
285dde5845aSJiri Kosina 	field->physical_maximum = parser->global.physical_maximum;
286dde5845aSJiri Kosina 	field->unit_exponent = parser->global.unit_exponent;
287dde5845aSJiri Kosina 	field->unit = parser->global.unit;
288dde5845aSJiri Kosina 
289dde5845aSJiri Kosina 	return 0;
290dde5845aSJiri Kosina }
291dde5845aSJiri Kosina 
292dde5845aSJiri Kosina /*
293dde5845aSJiri Kosina  * Read data value from item.
294dde5845aSJiri Kosina  */
295dde5845aSJiri Kosina 
296dde5845aSJiri Kosina static u32 item_udata(struct hid_item *item)
297dde5845aSJiri Kosina {
298dde5845aSJiri Kosina 	switch (item->size) {
299dde5845aSJiri Kosina 	case 1: return item->data.u8;
300dde5845aSJiri Kosina 	case 2: return item->data.u16;
301dde5845aSJiri Kosina 	case 4: return item->data.u32;
302dde5845aSJiri Kosina 	}
303dde5845aSJiri Kosina 	return 0;
304dde5845aSJiri Kosina }
305dde5845aSJiri Kosina 
306dde5845aSJiri Kosina static s32 item_sdata(struct hid_item *item)
307dde5845aSJiri Kosina {
308dde5845aSJiri Kosina 	switch (item->size) {
309dde5845aSJiri Kosina 	case 1: return item->data.s8;
310dde5845aSJiri Kosina 	case 2: return item->data.s16;
311dde5845aSJiri Kosina 	case 4: return item->data.s32;
312dde5845aSJiri Kosina 	}
313dde5845aSJiri Kosina 	return 0;
314dde5845aSJiri Kosina }
315dde5845aSJiri Kosina 
316dde5845aSJiri Kosina /*
317dde5845aSJiri Kosina  * Process a global item.
318dde5845aSJiri Kosina  */
319dde5845aSJiri Kosina 
320dde5845aSJiri Kosina static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
321dde5845aSJiri Kosina {
32277463838SBenjamin Tissoires 	__u32 raw_value;
323dde5845aSJiri Kosina 	switch (item->tag) {
324dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PUSH:
325dde5845aSJiri Kosina 
326dde5845aSJiri Kosina 		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
3278c3d52fcSJiri Kosina 			hid_err(parser->device, "global environment stack overflow\n");
328dde5845aSJiri Kosina 			return -1;
329dde5845aSJiri Kosina 		}
330dde5845aSJiri Kosina 
331dde5845aSJiri Kosina 		memcpy(parser->global_stack + parser->global_stack_ptr++,
332dde5845aSJiri Kosina 			&parser->global, sizeof(struct hid_global));
333dde5845aSJiri Kosina 		return 0;
334dde5845aSJiri Kosina 
335dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_POP:
336dde5845aSJiri Kosina 
337dde5845aSJiri Kosina 		if (!parser->global_stack_ptr) {
3388c3d52fcSJiri Kosina 			hid_err(parser->device, "global environment stack underflow\n");
339dde5845aSJiri Kosina 			return -1;
340dde5845aSJiri Kosina 		}
341dde5845aSJiri Kosina 
342880d29f1SJiri Slaby 		memcpy(&parser->global, parser->global_stack +
343880d29f1SJiri Slaby 			--parser->global_stack_ptr, sizeof(struct hid_global));
344dde5845aSJiri Kosina 		return 0;
345dde5845aSJiri Kosina 
346dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
347dde5845aSJiri Kosina 		parser->global.usage_page = item_udata(item);
348dde5845aSJiri Kosina 		return 0;
349dde5845aSJiri Kosina 
350dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
351dde5845aSJiri Kosina 		parser->global.logical_minimum = item_sdata(item);
352dde5845aSJiri Kosina 		return 0;
353dde5845aSJiri Kosina 
354dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
355dde5845aSJiri Kosina 		if (parser->global.logical_minimum < 0)
356dde5845aSJiri Kosina 			parser->global.logical_maximum = item_sdata(item);
357dde5845aSJiri Kosina 		else
358dde5845aSJiri Kosina 			parser->global.logical_maximum = item_udata(item);
359dde5845aSJiri Kosina 		return 0;
360dde5845aSJiri Kosina 
361dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
362dde5845aSJiri Kosina 		parser->global.physical_minimum = item_sdata(item);
363dde5845aSJiri Kosina 		return 0;
364dde5845aSJiri Kosina 
365dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
366dde5845aSJiri Kosina 		if (parser->global.physical_minimum < 0)
367dde5845aSJiri Kosina 			parser->global.physical_maximum = item_sdata(item);
368dde5845aSJiri Kosina 		else
369dde5845aSJiri Kosina 			parser->global.physical_maximum = item_udata(item);
370dde5845aSJiri Kosina 		return 0;
371dde5845aSJiri Kosina 
372dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
37377463838SBenjamin Tissoires 		/* Units exponent negative numbers are given through a
37477463838SBenjamin Tissoires 		 * two's complement.
37577463838SBenjamin Tissoires 		 * See "6.2.2.7 Global Items" for more information. */
37677463838SBenjamin Tissoires 		raw_value = item_udata(item);
37777463838SBenjamin Tissoires 		if (!(raw_value & 0xfffffff0))
37877463838SBenjamin Tissoires 			parser->global.unit_exponent = hid_snto32(raw_value, 4);
37977463838SBenjamin Tissoires 		else
38077463838SBenjamin Tissoires 			parser->global.unit_exponent = raw_value;
381dde5845aSJiri Kosina 		return 0;
382dde5845aSJiri Kosina 
383dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_UNIT:
384dde5845aSJiri Kosina 		parser->global.unit = item_udata(item);
385dde5845aSJiri Kosina 		return 0;
386dde5845aSJiri Kosina 
387dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
388880d29f1SJiri Slaby 		parser->global.report_size = item_udata(item);
38923408f95SMarek Vasut 		if (parser->global.report_size > 128) {
3908c3d52fcSJiri Kosina 			hid_err(parser->device, "invalid report_size %d\n",
391880d29f1SJiri Slaby 					parser->global.report_size);
392dde5845aSJiri Kosina 			return -1;
393dde5845aSJiri Kosina 		}
394dde5845aSJiri Kosina 		return 0;
395dde5845aSJiri Kosina 
396dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
397880d29f1SJiri Slaby 		parser->global.report_count = item_udata(item);
398880d29f1SJiri Slaby 		if (parser->global.report_count > HID_MAX_USAGES) {
3998c3d52fcSJiri Kosina 			hid_err(parser->device, "invalid report_count %d\n",
400880d29f1SJiri Slaby 					parser->global.report_count);
401dde5845aSJiri Kosina 			return -1;
402dde5845aSJiri Kosina 		}
403dde5845aSJiri Kosina 		return 0;
404dde5845aSJiri Kosina 
405dde5845aSJiri Kosina 	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
406880d29f1SJiri Slaby 		parser->global.report_id = item_udata(item);
407880d29f1SJiri Slaby 		if (parser->global.report_id == 0) {
4088c3d52fcSJiri Kosina 			hid_err(parser->device, "report_id 0 is invalid\n");
409dde5845aSJiri Kosina 			return -1;
410dde5845aSJiri Kosina 		}
411dde5845aSJiri Kosina 		return 0;
412dde5845aSJiri Kosina 
413dde5845aSJiri Kosina 	default:
4148c3d52fcSJiri Kosina 		hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
415dde5845aSJiri Kosina 		return -1;
416dde5845aSJiri Kosina 	}
417dde5845aSJiri Kosina }
418dde5845aSJiri Kosina 
419dde5845aSJiri Kosina /*
420dde5845aSJiri Kosina  * Process a local item.
421dde5845aSJiri Kosina  */
422dde5845aSJiri Kosina 
423dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
424dde5845aSJiri Kosina {
425dde5845aSJiri Kosina 	__u32 data;
426dde5845aSJiri Kosina 	unsigned n;
427dde5845aSJiri Kosina 
428dde5845aSJiri Kosina 	data = item_udata(item);
429dde5845aSJiri Kosina 
430dde5845aSJiri Kosina 	switch (item->tag) {
431dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_DELIMITER:
432dde5845aSJiri Kosina 
433dde5845aSJiri Kosina 		if (data) {
434dde5845aSJiri Kosina 			/*
435dde5845aSJiri Kosina 			 * We treat items before the first delimiter
436dde5845aSJiri Kosina 			 * as global to all usage sets (branch 0).
437dde5845aSJiri Kosina 			 * In the moment we process only these global
438dde5845aSJiri Kosina 			 * items and the first delimiter set.
439dde5845aSJiri Kosina 			 */
440dde5845aSJiri Kosina 			if (parser->local.delimiter_depth != 0) {
4418c3d52fcSJiri Kosina 				hid_err(parser->device, "nested delimiters\n");
442dde5845aSJiri Kosina 				return -1;
443dde5845aSJiri Kosina 			}
444dde5845aSJiri Kosina 			parser->local.delimiter_depth++;
445dde5845aSJiri Kosina 			parser->local.delimiter_branch++;
446dde5845aSJiri Kosina 		} else {
447dde5845aSJiri Kosina 			if (parser->local.delimiter_depth < 1) {
4488c3d52fcSJiri Kosina 				hid_err(parser->device, "bogus close delimiter\n");
449dde5845aSJiri Kosina 				return -1;
450dde5845aSJiri Kosina 			}
451dde5845aSJiri Kosina 			parser->local.delimiter_depth--;
452dde5845aSJiri Kosina 		}
45338ead6efSPaul Chavent 		return 0;
454dde5845aSJiri Kosina 
455dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE:
456dde5845aSJiri Kosina 
457dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
45858037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
459dde5845aSJiri Kosina 			return 0;
460dde5845aSJiri Kosina 		}
461dde5845aSJiri Kosina 
462dde5845aSJiri Kosina 		if (item->size <= 2)
463dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
464dde5845aSJiri Kosina 
465dde5845aSJiri Kosina 		return hid_add_usage(parser, data);
466dde5845aSJiri Kosina 
467dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
468dde5845aSJiri Kosina 
469dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
47058037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
471dde5845aSJiri Kosina 			return 0;
472dde5845aSJiri Kosina 		}
473dde5845aSJiri Kosina 
474dde5845aSJiri Kosina 		if (item->size <= 2)
475dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
476dde5845aSJiri Kosina 
477dde5845aSJiri Kosina 		parser->local.usage_minimum = data;
478dde5845aSJiri Kosina 		return 0;
479dde5845aSJiri Kosina 
480dde5845aSJiri Kosina 	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
481dde5845aSJiri Kosina 
482dde5845aSJiri Kosina 		if (parser->local.delimiter_branch > 1) {
48358037eb9SJiri Kosina 			dbg_hid("alternative usage ignored\n");
484dde5845aSJiri Kosina 			return 0;
485dde5845aSJiri Kosina 		}
486dde5845aSJiri Kosina 
487dde5845aSJiri Kosina 		if (item->size <= 2)
488dde5845aSJiri Kosina 			data = (parser->global.usage_page << 16) + data;
489dde5845aSJiri Kosina 
490dde5845aSJiri Kosina 		for (n = parser->local.usage_minimum; n <= data; n++)
491dde5845aSJiri Kosina 			if (hid_add_usage(parser, n)) {
49258037eb9SJiri Kosina 				dbg_hid("hid_add_usage failed\n");
493dde5845aSJiri Kosina 				return -1;
494dde5845aSJiri Kosina 			}
495dde5845aSJiri Kosina 		return 0;
496dde5845aSJiri Kosina 
497dde5845aSJiri Kosina 	default:
498dde5845aSJiri Kosina 
49958037eb9SJiri Kosina 		dbg_hid("unknown local item tag 0x%x\n", item->tag);
500dde5845aSJiri Kosina 		return 0;
501dde5845aSJiri Kosina 	}
502dde5845aSJiri Kosina 	return 0;
503dde5845aSJiri Kosina }
504dde5845aSJiri Kosina 
505dde5845aSJiri Kosina /*
506dde5845aSJiri Kosina  * Process a main item.
507dde5845aSJiri Kosina  */
508dde5845aSJiri Kosina 
509dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
510dde5845aSJiri Kosina {
511dde5845aSJiri Kosina 	__u32 data;
512dde5845aSJiri Kosina 	int ret;
513dde5845aSJiri Kosina 
514dde5845aSJiri Kosina 	data = item_udata(item);
515dde5845aSJiri Kosina 
516dde5845aSJiri Kosina 	switch (item->tag) {
517dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
518dde5845aSJiri Kosina 		ret = open_collection(parser, data & 0xff);
519dde5845aSJiri Kosina 		break;
520dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_END_COLLECTION:
521dde5845aSJiri Kosina 		ret = close_collection(parser);
522dde5845aSJiri Kosina 		break;
523dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_INPUT:
524dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
525dde5845aSJiri Kosina 		break;
526dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_OUTPUT:
527dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
528dde5845aSJiri Kosina 		break;
529dde5845aSJiri Kosina 	case HID_MAIN_ITEM_TAG_FEATURE:
530dde5845aSJiri Kosina 		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
531dde5845aSJiri Kosina 		break;
532dde5845aSJiri Kosina 	default:
5338c3d52fcSJiri Kosina 		hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag);
534dde5845aSJiri Kosina 		ret = 0;
535dde5845aSJiri Kosina 	}
536dde5845aSJiri Kosina 
537dde5845aSJiri Kosina 	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
538dde5845aSJiri Kosina 
539dde5845aSJiri Kosina 	return ret;
540dde5845aSJiri Kosina }
541dde5845aSJiri Kosina 
542dde5845aSJiri Kosina /*
543dde5845aSJiri Kosina  * Process a reserved item.
544dde5845aSJiri Kosina  */
545dde5845aSJiri Kosina 
546dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
547dde5845aSJiri Kosina {
54858037eb9SJiri Kosina 	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
549dde5845aSJiri Kosina 	return 0;
550dde5845aSJiri Kosina }
551dde5845aSJiri Kosina 
552dde5845aSJiri Kosina /*
553dde5845aSJiri Kosina  * Free a report and all registered fields. The field->usage and
554dde5845aSJiri Kosina  * field->value table's are allocated behind the field, so we need
555dde5845aSJiri Kosina  * only to free(field) itself.
556dde5845aSJiri Kosina  */
557dde5845aSJiri Kosina 
558dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report)
559dde5845aSJiri Kosina {
560dde5845aSJiri Kosina 	unsigned n;
561dde5845aSJiri Kosina 
562dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
563dde5845aSJiri Kosina 		kfree(report->field[n]);
564dde5845aSJiri Kosina 	kfree(report);
565dde5845aSJiri Kosina }
566dde5845aSJiri Kosina 
567dde5845aSJiri Kosina /*
568a7197c2eSHenrik Rydberg  * Close report. This function returns the device
569a7197c2eSHenrik Rydberg  * state to the point prior to hid_open_report().
570dde5845aSJiri Kosina  */
571a7197c2eSHenrik Rydberg static void hid_close_report(struct hid_device *device)
572dde5845aSJiri Kosina {
573dde5845aSJiri Kosina 	unsigned i, j;
574dde5845aSJiri Kosina 
575dde5845aSJiri Kosina 	for (i = 0; i < HID_REPORT_TYPES; i++) {
576dde5845aSJiri Kosina 		struct hid_report_enum *report_enum = device->report_enum + i;
577dde5845aSJiri Kosina 
578dde5845aSJiri Kosina 		for (j = 0; j < 256; j++) {
579dde5845aSJiri Kosina 			struct hid_report *report = report_enum->report_id_hash[j];
580dde5845aSJiri Kosina 			if (report)
581dde5845aSJiri Kosina 				hid_free_report(report);
582dde5845aSJiri Kosina 		}
583a7197c2eSHenrik Rydberg 		memset(report_enum, 0, sizeof(*report_enum));
584a7197c2eSHenrik Rydberg 		INIT_LIST_HEAD(&report_enum->report_list);
585dde5845aSJiri Kosina 	}
586dde5845aSJiri Kosina 
587dde5845aSJiri Kosina 	kfree(device->rdesc);
588a7197c2eSHenrik Rydberg 	device->rdesc = NULL;
589a7197c2eSHenrik Rydberg 	device->rsize = 0;
590a7197c2eSHenrik Rydberg 
591767fe787SJiri Kosina 	kfree(device->collection);
592a7197c2eSHenrik Rydberg 	device->collection = NULL;
593a7197c2eSHenrik Rydberg 	device->collection_size = 0;
594a7197c2eSHenrik Rydberg 	device->maxcollection = 0;
595a7197c2eSHenrik Rydberg 	device->maxapplication = 0;
596a7197c2eSHenrik Rydberg 
597a7197c2eSHenrik Rydberg 	device->status &= ~HID_STAT_PARSED;
598a7197c2eSHenrik Rydberg }
599a7197c2eSHenrik Rydberg 
600a7197c2eSHenrik Rydberg /*
601a7197c2eSHenrik Rydberg  * Free a device structure, all reports, and all fields.
602a7197c2eSHenrik Rydberg  */
603a7197c2eSHenrik Rydberg 
604a7197c2eSHenrik Rydberg static void hid_device_release(struct device *dev)
605a7197c2eSHenrik Rydberg {
606a7197c2eSHenrik Rydberg 	struct hid_device *hid = container_of(dev, struct hid_device, dev);
607a7197c2eSHenrik Rydberg 
608a7197c2eSHenrik Rydberg 	hid_close_report(hid);
609a7197c2eSHenrik Rydberg 	kfree(hid->dev_rdesc);
610a7197c2eSHenrik Rydberg 	kfree(hid);
611dde5845aSJiri Kosina }
612dde5845aSJiri Kosina 
613dde5845aSJiri Kosina /*
614dde5845aSJiri Kosina  * Fetch a report description item from the data stream. We support long
615dde5845aSJiri Kosina  * items, though they are not used yet.
616dde5845aSJiri Kosina  */
617dde5845aSJiri Kosina 
618dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
619dde5845aSJiri Kosina {
620dde5845aSJiri Kosina 	u8 b;
621dde5845aSJiri Kosina 
622dde5845aSJiri Kosina 	if ((end - start) <= 0)
623dde5845aSJiri Kosina 		return NULL;
624dde5845aSJiri Kosina 
625dde5845aSJiri Kosina 	b = *start++;
626dde5845aSJiri Kosina 
627dde5845aSJiri Kosina 	item->type = (b >> 2) & 3;
628dde5845aSJiri Kosina 	item->tag  = (b >> 4) & 15;
629dde5845aSJiri Kosina 
630dde5845aSJiri Kosina 	if (item->tag == HID_ITEM_TAG_LONG) {
631dde5845aSJiri Kosina 
632dde5845aSJiri Kosina 		item->format = HID_ITEM_FORMAT_LONG;
633dde5845aSJiri Kosina 
634dde5845aSJiri Kosina 		if ((end - start) < 2)
635dde5845aSJiri Kosina 			return NULL;
636dde5845aSJiri Kosina 
637dde5845aSJiri Kosina 		item->size = *start++;
638dde5845aSJiri Kosina 		item->tag  = *start++;
639dde5845aSJiri Kosina 
640dde5845aSJiri Kosina 		if ((end - start) < item->size)
641dde5845aSJiri Kosina 			return NULL;
642dde5845aSJiri Kosina 
643dde5845aSJiri Kosina 		item->data.longdata = start;
644dde5845aSJiri Kosina 		start += item->size;
645dde5845aSJiri Kosina 		return start;
646dde5845aSJiri Kosina 	}
647dde5845aSJiri Kosina 
648dde5845aSJiri Kosina 	item->format = HID_ITEM_FORMAT_SHORT;
649dde5845aSJiri Kosina 	item->size = b & 3;
650dde5845aSJiri Kosina 
651dde5845aSJiri Kosina 	switch (item->size) {
652dde5845aSJiri Kosina 	case 0:
653dde5845aSJiri Kosina 		return start;
654dde5845aSJiri Kosina 
655dde5845aSJiri Kosina 	case 1:
656dde5845aSJiri Kosina 		if ((end - start) < 1)
657dde5845aSJiri Kosina 			return NULL;
658dde5845aSJiri Kosina 		item->data.u8 = *start++;
659dde5845aSJiri Kosina 		return start;
660dde5845aSJiri Kosina 
661dde5845aSJiri Kosina 	case 2:
662dde5845aSJiri Kosina 		if ((end - start) < 2)
663dde5845aSJiri Kosina 			return NULL;
664c105068fSHarvey Harrison 		item->data.u16 = get_unaligned_le16(start);
665dde5845aSJiri Kosina 		start = (__u8 *)((__le16 *)start + 1);
666dde5845aSJiri Kosina 		return start;
667dde5845aSJiri Kosina 
668dde5845aSJiri Kosina 	case 3:
669dde5845aSJiri Kosina 		item->size++;
670dde5845aSJiri Kosina 		if ((end - start) < 4)
671dde5845aSJiri Kosina 			return NULL;
672c105068fSHarvey Harrison 		item->data.u32 = get_unaligned_le32(start);
673dde5845aSJiri Kosina 		start = (__u8 *)((__le32 *)start + 1);
674dde5845aSJiri Kosina 		return start;
675dde5845aSJiri Kosina 	}
676dde5845aSJiri Kosina 
677dde5845aSJiri Kosina 	return NULL;
678dde5845aSJiri Kosina }
679dde5845aSJiri Kosina 
680734c6609SHenrik Rydberg static void hid_scan_usage(struct hid_device *hid, u32 usage)
681734c6609SHenrik Rydberg {
6824fa3a583SHenrik Rydberg 	if (usage == HID_DG_CONTACTID)
6834fa3a583SHenrik Rydberg 		hid->group = HID_GROUP_MULTITOUCH;
684734c6609SHenrik Rydberg }
685734c6609SHenrik Rydberg 
686734c6609SHenrik Rydberg /*
687734c6609SHenrik Rydberg  * Scan a report descriptor before the device is added to the bus.
688734c6609SHenrik Rydberg  * Sets device groups and other properties that determine what driver
689734c6609SHenrik Rydberg  * to load.
690734c6609SHenrik Rydberg  */
691734c6609SHenrik Rydberg static int hid_scan_report(struct hid_device *hid)
692734c6609SHenrik Rydberg {
693734c6609SHenrik Rydberg 	unsigned int page = 0, delim = 0;
694734c6609SHenrik Rydberg 	__u8 *start = hid->dev_rdesc;
695734c6609SHenrik Rydberg 	__u8 *end = start + hid->dev_rsize;
696734c6609SHenrik Rydberg 	unsigned int u, u_min = 0, u_max = 0;
697734c6609SHenrik Rydberg 	struct hid_item item;
698734c6609SHenrik Rydberg 
699734c6609SHenrik Rydberg 	hid->group = HID_GROUP_GENERIC;
700734c6609SHenrik Rydberg 	while ((start = fetch_item(start, end, &item)) != NULL) {
701734c6609SHenrik Rydberg 		if (item.format != HID_ITEM_FORMAT_SHORT)
702734c6609SHenrik Rydberg 			return -EINVAL;
703734c6609SHenrik Rydberg 		if (item.type == HID_ITEM_TYPE_GLOBAL) {
704734c6609SHenrik Rydberg 			if (item.tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE)
705734c6609SHenrik Rydberg 				page = item_udata(&item) << 16;
706734c6609SHenrik Rydberg 		} else if (item.type == HID_ITEM_TYPE_LOCAL) {
707734c6609SHenrik Rydberg 			if (delim > 1)
708734c6609SHenrik Rydberg 				break;
709734c6609SHenrik Rydberg 			u = item_udata(&item);
710734c6609SHenrik Rydberg 			if (item.size <= 2)
711734c6609SHenrik Rydberg 				u += page;
712734c6609SHenrik Rydberg 			switch (item.tag) {
713734c6609SHenrik Rydberg 			case HID_LOCAL_ITEM_TAG_DELIMITER:
714734c6609SHenrik Rydberg 				delim += !!u;
715734c6609SHenrik Rydberg 				break;
716734c6609SHenrik Rydberg 			case HID_LOCAL_ITEM_TAG_USAGE:
717734c6609SHenrik Rydberg 				hid_scan_usage(hid, u);
718734c6609SHenrik Rydberg 				break;
719734c6609SHenrik Rydberg 			case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
720734c6609SHenrik Rydberg 				u_min = u;
721734c6609SHenrik Rydberg 				break;
722734c6609SHenrik Rydberg 			case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
723734c6609SHenrik Rydberg 				u_max = u;
724734c6609SHenrik Rydberg 				for (u = u_min; u <= u_max; u++)
725734c6609SHenrik Rydberg 					hid_scan_usage(hid, u);
726734c6609SHenrik Rydberg 				break;
727734c6609SHenrik Rydberg 			}
72883499b52SAlexander Holler 		} else if (page == HID_UP_SENSOR &&
72983499b52SAlexander Holler 			item.type == HID_ITEM_TYPE_MAIN &&
73083499b52SAlexander Holler 			item.tag == HID_MAIN_ITEM_TAG_BEGIN_COLLECTION &&
7316399f335SMika Westerberg 			(item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL)
73283499b52SAlexander Holler 			hid->group = HID_GROUP_SENSOR_HUB;
733734c6609SHenrik Rydberg 	}
734734c6609SHenrik Rydberg 
735734c6609SHenrik Rydberg 	return 0;
736734c6609SHenrik Rydberg }
737734c6609SHenrik Rydberg 
73885cdaf52SJiri Slaby /**
73985cdaf52SJiri Slaby  * hid_parse_report - parse device report
74085cdaf52SJiri Slaby  *
74185cdaf52SJiri Slaby  * @device: hid device
74285cdaf52SJiri Slaby  * @start: report start
74385cdaf52SJiri Slaby  * @size: report size
74485cdaf52SJiri Slaby  *
745a7197c2eSHenrik Rydberg  * Allocate the device report as read by the bus driver. This function should
746a7197c2eSHenrik Rydberg  * only be called from parse() in ll drivers.
747a7197c2eSHenrik Rydberg  */
748a7197c2eSHenrik Rydberg int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
749a7197c2eSHenrik Rydberg {
750a7197c2eSHenrik Rydberg 	hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
751a7197c2eSHenrik Rydberg 	if (!hid->dev_rdesc)
752a7197c2eSHenrik Rydberg 		return -ENOMEM;
753a7197c2eSHenrik Rydberg 	hid->dev_rsize = size;
754a7197c2eSHenrik Rydberg 	return 0;
755a7197c2eSHenrik Rydberg }
756a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_parse_report);
757a7197c2eSHenrik Rydberg 
758a7197c2eSHenrik Rydberg /**
759a7197c2eSHenrik Rydberg  * hid_open_report - open a driver-specific device report
760a7197c2eSHenrik Rydberg  *
761a7197c2eSHenrik Rydberg  * @device: hid device
762a7197c2eSHenrik Rydberg  *
763dde5845aSJiri Kosina  * Parse a report description into a hid_device structure. Reports are
764dde5845aSJiri Kosina  * enumerated, fields are attached to these reports.
76585cdaf52SJiri Slaby  * 0 returned on success, otherwise nonzero error value.
766a7197c2eSHenrik Rydberg  *
767a7197c2eSHenrik Rydberg  * This function (or the equivalent hid_parse() macro) should only be
768a7197c2eSHenrik Rydberg  * called from probe() in drivers, before starting the device.
769dde5845aSJiri Kosina  */
770a7197c2eSHenrik Rydberg int hid_open_report(struct hid_device *device)
771dde5845aSJiri Kosina {
772dde5845aSJiri Kosina 	struct hid_parser *parser;
773dde5845aSJiri Kosina 	struct hid_item item;
774a7197c2eSHenrik Rydberg 	unsigned int size;
775a7197c2eSHenrik Rydberg 	__u8 *start;
77686e6b77eSKevin Daughtridge 	__u8 *buf;
777dde5845aSJiri Kosina 	__u8 *end;
77885cdaf52SJiri Slaby 	int ret;
779dde5845aSJiri Kosina 	static int (*dispatch_type[])(struct hid_parser *parser,
780dde5845aSJiri Kosina 				      struct hid_item *item) = {
781dde5845aSJiri Kosina 		hid_parser_main,
782dde5845aSJiri Kosina 		hid_parser_global,
783dde5845aSJiri Kosina 		hid_parser_local,
784dde5845aSJiri Kosina 		hid_parser_reserved
785dde5845aSJiri Kosina 	};
786dde5845aSJiri Kosina 
787a7197c2eSHenrik Rydberg 	if (WARN_ON(device->status & HID_STAT_PARSED))
788a7197c2eSHenrik Rydberg 		return -EBUSY;
789a7197c2eSHenrik Rydberg 
790a7197c2eSHenrik Rydberg 	start = device->dev_rdesc;
791a7197c2eSHenrik Rydberg 	if (WARN_ON(!start))
792a7197c2eSHenrik Rydberg 		return -ENODEV;
793a7197c2eSHenrik Rydberg 	size = device->dev_rsize;
794a7197c2eSHenrik Rydberg 
79586e6b77eSKevin Daughtridge 	buf = kmemdup(start, size, GFP_KERNEL);
79686e6b77eSKevin Daughtridge 	if (buf == NULL)
79785cdaf52SJiri Slaby 		return -ENOMEM;
79886e6b77eSKevin Daughtridge 
79986e6b77eSKevin Daughtridge 	if (device->driver->report_fixup)
80086e6b77eSKevin Daughtridge 		start = device->driver->report_fixup(device, buf, &size);
80186e6b77eSKevin Daughtridge 	else
80286e6b77eSKevin Daughtridge 		start = buf;
80386e6b77eSKevin Daughtridge 
80486e6b77eSKevin Daughtridge 	start = kmemdup(start, size, GFP_KERNEL);
80586e6b77eSKevin Daughtridge 	kfree(buf);
80686e6b77eSKevin Daughtridge 	if (start == NULL)
80786e6b77eSKevin Daughtridge 		return -ENOMEM;
80886e6b77eSKevin Daughtridge 
80986e6b77eSKevin Daughtridge 	device->rdesc = start;
810dde5845aSJiri Kosina 	device->rsize = size;
811dde5845aSJiri Kosina 
812fe258020SJoe Perches 	parser = vzalloc(sizeof(struct hid_parser));
81385cdaf52SJiri Slaby 	if (!parser) {
81485cdaf52SJiri Slaby 		ret = -ENOMEM;
81585cdaf52SJiri Slaby 		goto err;
816dde5845aSJiri Kosina 	}
81785cdaf52SJiri Slaby 
818dde5845aSJiri Kosina 	parser->device = device;
819dde5845aSJiri Kosina 
820dde5845aSJiri Kosina 	end = start + size;
821a7197c2eSHenrik Rydberg 
822a7197c2eSHenrik Rydberg 	device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
823a7197c2eSHenrik Rydberg 				     sizeof(struct hid_collection), GFP_KERNEL);
824a7197c2eSHenrik Rydberg 	if (!device->collection) {
825a7197c2eSHenrik Rydberg 		ret = -ENOMEM;
826a7197c2eSHenrik Rydberg 		goto err;
827a7197c2eSHenrik Rydberg 	}
828a7197c2eSHenrik Rydberg 	device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
829a7197c2eSHenrik Rydberg 
83085cdaf52SJiri Slaby 	ret = -EINVAL;
831dde5845aSJiri Kosina 	while ((start = fetch_item(start, end, &item)) != NULL) {
832dde5845aSJiri Kosina 
833dde5845aSJiri Kosina 		if (item.format != HID_ITEM_FORMAT_SHORT) {
8348c3d52fcSJiri Kosina 			hid_err(device, "unexpected long global item\n");
83585cdaf52SJiri Slaby 			goto err;
836dde5845aSJiri Kosina 		}
837dde5845aSJiri Kosina 
838dde5845aSJiri Kosina 		if (dispatch_type[item.type](parser, &item)) {
8398c3d52fcSJiri Kosina 			hid_err(device, "item %u %u %u %u parsing failed\n",
8404291ee30SJoe Perches 				item.format, (unsigned)item.size,
8414291ee30SJoe Perches 				(unsigned)item.type, (unsigned)item.tag);
84285cdaf52SJiri Slaby 			goto err;
843dde5845aSJiri Kosina 		}
844dde5845aSJiri Kosina 
845dde5845aSJiri Kosina 		if (start == end) {
846dde5845aSJiri Kosina 			if (parser->collection_stack_ptr) {
8478c3d52fcSJiri Kosina 				hid_err(device, "unbalanced collection at end of report description\n");
84885cdaf52SJiri Slaby 				goto err;
849dde5845aSJiri Kosina 			}
850dde5845aSJiri Kosina 			if (parser->local.delimiter_depth) {
8518c3d52fcSJiri Kosina 				hid_err(device, "unbalanced delimiter at end of report description\n");
85285cdaf52SJiri Slaby 				goto err;
853dde5845aSJiri Kosina 			}
85447a80edbSJiri Kosina 			vfree(parser);
855a7197c2eSHenrik Rydberg 			device->status |= HID_STAT_PARSED;
85685cdaf52SJiri Slaby 			return 0;
857dde5845aSJiri Kosina 		}
858dde5845aSJiri Kosina 	}
859dde5845aSJiri Kosina 
8608c3d52fcSJiri Kosina 	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
86185cdaf52SJiri Slaby err:
86247a80edbSJiri Kosina 	vfree(parser);
863a7197c2eSHenrik Rydberg 	hid_close_report(device);
86485cdaf52SJiri Slaby 	return ret;
865dde5845aSJiri Kosina }
866a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_open_report);
867dde5845aSJiri Kosina 
868dde5845aSJiri Kosina /*
869dde5845aSJiri Kosina  * Convert a signed n-bit integer to signed 32-bit integer. Common
870dde5845aSJiri Kosina  * cases are done through the compiler, the screwed things has to be
871dde5845aSJiri Kosina  * done by hand.
872dde5845aSJiri Kosina  */
873dde5845aSJiri Kosina 
874dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n)
875dde5845aSJiri Kosina {
876dde5845aSJiri Kosina 	switch (n) {
877dde5845aSJiri Kosina 	case 8:  return ((__s8)value);
878dde5845aSJiri Kosina 	case 16: return ((__s16)value);
879dde5845aSJiri Kosina 	case 32: return ((__s32)value);
880dde5845aSJiri Kosina 	}
881dde5845aSJiri Kosina 	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
882dde5845aSJiri Kosina }
883dde5845aSJiri Kosina 
88477463838SBenjamin Tissoires s32 hid_snto32(__u32 value, unsigned n)
88577463838SBenjamin Tissoires {
88677463838SBenjamin Tissoires 	return snto32(value, n);
88777463838SBenjamin Tissoires }
88877463838SBenjamin Tissoires EXPORT_SYMBOL_GPL(hid_snto32);
88977463838SBenjamin Tissoires 
890dde5845aSJiri Kosina /*
891dde5845aSJiri Kosina  * Convert a signed 32-bit integer to a signed n-bit integer.
892dde5845aSJiri Kosina  */
893dde5845aSJiri Kosina 
894dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n)
895dde5845aSJiri Kosina {
896dde5845aSJiri Kosina 	s32 a = value >> (n - 1);
897dde5845aSJiri Kosina 	if (a && a != -1)
898dde5845aSJiri Kosina 		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
899dde5845aSJiri Kosina 	return value & ((1 << n) - 1);
900dde5845aSJiri Kosina }
901dde5845aSJiri Kosina 
902dde5845aSJiri Kosina /*
903dde5845aSJiri Kosina  * Extract/implement a data field from/to a little endian report (bit array).
904dde5845aSJiri Kosina  *
905dde5845aSJiri Kosina  * Code sort-of follows HID spec:
906dde5845aSJiri Kosina  *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
907dde5845aSJiri Kosina  *
908dde5845aSJiri Kosina  * While the USB HID spec allows unlimited length bit fields in "report
909dde5845aSJiri Kosina  * descriptors", most devices never use more than 16 bits.
910dde5845aSJiri Kosina  * One model of UPS is claimed to report "LINEV" as a 32-bit field.
911dde5845aSJiri Kosina  * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
912dde5845aSJiri Kosina  */
913dde5845aSJiri Kosina 
91416ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report,
9154291ee30SJoe Perches 		     unsigned offset, unsigned n)
916dde5845aSJiri Kosina {
917dde5845aSJiri Kosina 	u64 x;
918dde5845aSJiri Kosina 
919c4124c9bSJiri Kosina 	if (n > 32)
9204291ee30SJoe Perches 		hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
921c4124c9bSJiri Kosina 			 n, current->comm);
922dde5845aSJiri Kosina 
923dde5845aSJiri Kosina 	report += offset >> 3;  /* adjust byte index */
924dde5845aSJiri Kosina 	offset &= 7;            /* now only need bit offset into one byte */
925c105068fSHarvey Harrison 	x = get_unaligned_le64(report);
926dde5845aSJiri Kosina 	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
927dde5845aSJiri Kosina 	return (u32) x;
928dde5845aSJiri Kosina }
929dde5845aSJiri Kosina 
930dde5845aSJiri Kosina /*
931dde5845aSJiri Kosina  * "implement" : set bits in a little endian bit stream.
932dde5845aSJiri Kosina  * Same concepts as "extract" (see comments above).
933dde5845aSJiri Kosina  * The data mangled in the bit stream remains in little endian
934dde5845aSJiri Kosina  * order the whole time. It make more sense to talk about
935dde5845aSJiri Kosina  * endianness of register values by considering a register
936dde5845aSJiri Kosina  * a "cached" copy of the little endiad bit stream.
937dde5845aSJiri Kosina  */
93816ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report,
9394291ee30SJoe Perches 		      unsigned offset, unsigned n, __u32 value)
940dde5845aSJiri Kosina {
9416f0168d2SHarvey Harrison 	u64 x;
942dde5845aSJiri Kosina 	u64 m = (1ULL << n) - 1;
943dde5845aSJiri Kosina 
944c4124c9bSJiri Kosina 	if (n > 32)
9454291ee30SJoe Perches 		hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
9464291ee30SJoe Perches 			 __func__, n, current->comm);
947dde5845aSJiri Kosina 
948c4124c9bSJiri Kosina 	if (value > m)
9494291ee30SJoe Perches 		hid_warn(hid, "%s() called with too large value %d! (%s)\n",
9504291ee30SJoe Perches 			 __func__, value, current->comm);
951dde5845aSJiri Kosina 	WARN_ON(value > m);
952dde5845aSJiri Kosina 	value &= m;
953dde5845aSJiri Kosina 
954dde5845aSJiri Kosina 	report += offset >> 3;
955dde5845aSJiri Kosina 	offset &= 7;
956dde5845aSJiri Kosina 
9576f0168d2SHarvey Harrison 	x = get_unaligned_le64(report);
9586f0168d2SHarvey Harrison 	x &= ~(m << offset);
9596f0168d2SHarvey Harrison 	x |= ((u64)value) << offset;
9606f0168d2SHarvey Harrison 	put_unaligned_le64(x, report);
961dde5845aSJiri Kosina }
962dde5845aSJiri Kosina 
963dde5845aSJiri Kosina /*
964dde5845aSJiri Kosina  * Search an array for a value.
965dde5845aSJiri Kosina  */
966dde5845aSJiri Kosina 
96716ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n)
968dde5845aSJiri Kosina {
969dde5845aSJiri Kosina 	while (n--) {
970dde5845aSJiri Kosina 		if (*array++ == value)
971dde5845aSJiri Kosina 			return 0;
972dde5845aSJiri Kosina 	}
973dde5845aSJiri Kosina 	return -1;
974dde5845aSJiri Kosina }
975dde5845aSJiri Kosina 
97685cdaf52SJiri Slaby /**
97785cdaf52SJiri Slaby  * hid_match_report - check if driver's raw_event should be called
97885cdaf52SJiri Slaby  *
97985cdaf52SJiri Slaby  * @hid: hid device
98085cdaf52SJiri Slaby  * @report_type: type to match against
98185cdaf52SJiri Slaby  *
98285cdaf52SJiri Slaby  * compare hid->driver->report_table->report_type to report->type
98385cdaf52SJiri Slaby  */
98485cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report)
985dde5845aSJiri Kosina {
98685cdaf52SJiri Slaby 	const struct hid_report_id *id = hid->driver->report_table;
98785cdaf52SJiri Slaby 
98885cdaf52SJiri Slaby 	if (!id) /* NULL means all */
98985cdaf52SJiri Slaby 		return 1;
99085cdaf52SJiri Slaby 
99185cdaf52SJiri Slaby 	for (; id->report_type != HID_TERMINATOR; id++)
99285cdaf52SJiri Slaby 		if (id->report_type == HID_ANY_ID ||
99385cdaf52SJiri Slaby 				id->report_type == report->type)
99485cdaf52SJiri Slaby 			return 1;
99585cdaf52SJiri Slaby 	return 0;
99685cdaf52SJiri Slaby }
99785cdaf52SJiri Slaby 
99885cdaf52SJiri Slaby /**
99985cdaf52SJiri Slaby  * hid_match_usage - check if driver's event should be called
100085cdaf52SJiri Slaby  *
100185cdaf52SJiri Slaby  * @hid: hid device
100285cdaf52SJiri Slaby  * @usage: usage to match against
100385cdaf52SJiri Slaby  *
100485cdaf52SJiri Slaby  * compare hid->driver->usage_table->usage_{type,code} to
100585cdaf52SJiri Slaby  * usage->usage_{type,code}
100685cdaf52SJiri Slaby  */
100785cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
100885cdaf52SJiri Slaby {
100985cdaf52SJiri Slaby 	const struct hid_usage_id *id = hid->driver->usage_table;
101085cdaf52SJiri Slaby 
101185cdaf52SJiri Slaby 	if (!id) /* NULL means all */
101285cdaf52SJiri Slaby 		return 1;
101385cdaf52SJiri Slaby 
101485cdaf52SJiri Slaby 	for (; id->usage_type != HID_ANY_ID - 1; id++)
101585cdaf52SJiri Slaby 		if ((id->usage_hid == HID_ANY_ID ||
101685cdaf52SJiri Slaby 				id->usage_hid == usage->hid) &&
101785cdaf52SJiri Slaby 				(id->usage_type == HID_ANY_ID ||
101885cdaf52SJiri Slaby 				id->usage_type == usage->type) &&
101985cdaf52SJiri Slaby 				(id->usage_code == HID_ANY_ID ||
102085cdaf52SJiri Slaby 				 id->usage_code == usage->code))
102185cdaf52SJiri Slaby 			return 1;
102285cdaf52SJiri Slaby 	return 0;
102385cdaf52SJiri Slaby }
102485cdaf52SJiri Slaby 
102585cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field,
102685cdaf52SJiri Slaby 		struct hid_usage *usage, __s32 value, int interrupt)
102785cdaf52SJiri Slaby {
102885cdaf52SJiri Slaby 	struct hid_driver *hdrv = hid->driver;
102985cdaf52SJiri Slaby 	int ret;
103085cdaf52SJiri Slaby 
10319bfc8da0SHenrik Rydberg 	if (!list_empty(&hid->debug_list))
1032cd667ce2SJiri Kosina 		hid_dump_input(hid, usage, value);
103385cdaf52SJiri Slaby 
103485cdaf52SJiri Slaby 	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
103585cdaf52SJiri Slaby 		ret = hdrv->event(hid, field, usage, value);
103685cdaf52SJiri Slaby 		if (ret != 0) {
103785cdaf52SJiri Slaby 			if (ret < 0)
10388c3d52fcSJiri Kosina 				hid_err(hid, "%s's event failed with %d\n",
103985cdaf52SJiri Slaby 						hdrv->name, ret);
104085cdaf52SJiri Slaby 			return;
104185cdaf52SJiri Slaby 		}
104285cdaf52SJiri Slaby 	}
104385cdaf52SJiri Slaby 
1044dde5845aSJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1045dde5845aSJiri Kosina 		hidinput_hid_event(hid, field, usage, value);
1046aa938f79SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
1047aa938f79SJiri Kosina 		hid->hiddev_hid_event(hid, field, usage, value);
1048dde5845aSJiri Kosina }
1049dde5845aSJiri Kosina 
1050dde5845aSJiri Kosina /*
1051dde5845aSJiri Kosina  * Analyse a received field, and fetch the data from it. The field
1052dde5845aSJiri Kosina  * content is stored for next report processing (we do differential
1053dde5845aSJiri Kosina  * reporting to the layer).
1054dde5845aSJiri Kosina  */
1055dde5845aSJiri Kosina 
1056abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field,
1057abdff0f7SAdrian Bunk 			    __u8 *data, int interrupt)
1058dde5845aSJiri Kosina {
1059dde5845aSJiri Kosina 	unsigned n;
1060dde5845aSJiri Kosina 	unsigned count = field->report_count;
1061dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
1062dde5845aSJiri Kosina 	unsigned size = field->report_size;
1063dde5845aSJiri Kosina 	__s32 min = field->logical_minimum;
1064dde5845aSJiri Kosina 	__s32 max = field->logical_maximum;
1065dde5845aSJiri Kosina 	__s32 *value;
1066dde5845aSJiri Kosina 
1067a3789a17SJoe Perches 	value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
1068a3789a17SJoe Perches 	if (!value)
1069dde5845aSJiri Kosina 		return;
1070dde5845aSJiri Kosina 
1071dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1072dde5845aSJiri Kosina 
10734291ee30SJoe Perches 		value[n] = min < 0 ?
10744291ee30SJoe Perches 			snto32(extract(hid, data, offset + n * size, size),
10754291ee30SJoe Perches 			       size) :
10764291ee30SJoe Perches 			extract(hid, data, offset + n * size, size);
1077dde5845aSJiri Kosina 
10784291ee30SJoe Perches 		/* Ignore report if ErrorRollOver */
10794291ee30SJoe Perches 		if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
10804291ee30SJoe Perches 		    value[n] >= min && value[n] <= max &&
10814291ee30SJoe Perches 		    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
1082dde5845aSJiri Kosina 			goto exit;
1083dde5845aSJiri Kosina 	}
1084dde5845aSJiri Kosina 
1085dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1086dde5845aSJiri Kosina 
1087dde5845aSJiri Kosina 		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
1088dde5845aSJiri Kosina 			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
1089dde5845aSJiri Kosina 			continue;
1090dde5845aSJiri Kosina 		}
1091dde5845aSJiri Kosina 
1092dde5845aSJiri Kosina 		if (field->value[n] >= min && field->value[n] <= max
1093dde5845aSJiri Kosina 			&& field->usage[field->value[n] - min].hid
1094dde5845aSJiri Kosina 			&& search(value, field->value[n], count))
1095dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
1096dde5845aSJiri Kosina 
1097dde5845aSJiri Kosina 		if (value[n] >= min && value[n] <= max
1098dde5845aSJiri Kosina 			&& field->usage[value[n] - min].hid
1099dde5845aSJiri Kosina 			&& search(field->value, value[n], count))
1100dde5845aSJiri Kosina 				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
1101dde5845aSJiri Kosina 	}
1102dde5845aSJiri Kosina 
1103dde5845aSJiri Kosina 	memcpy(field->value, value, count * sizeof(__s32));
1104dde5845aSJiri Kosina exit:
1105dde5845aSJiri Kosina 	kfree(value);
1106dde5845aSJiri Kosina }
1107dde5845aSJiri Kosina 
1108dde5845aSJiri Kosina /*
1109dde5845aSJiri Kosina  * Output the field into the report.
1110dde5845aSJiri Kosina  */
1111dde5845aSJiri Kosina 
11124291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid,
11134291ee30SJoe Perches 			     struct hid_field *field, __u8 *data)
1114dde5845aSJiri Kosina {
1115dde5845aSJiri Kosina 	unsigned count = field->report_count;
1116dde5845aSJiri Kosina 	unsigned offset = field->report_offset;
1117dde5845aSJiri Kosina 	unsigned size = field->report_size;
1118dde5845aSJiri Kosina 	unsigned n;
1119dde5845aSJiri Kosina 
1120dde5845aSJiri Kosina 	for (n = 0; n < count; n++) {
1121dde5845aSJiri Kosina 		if (field->logical_minimum < 0)	/* signed values */
11224291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
11234291ee30SJoe Perches 				  s32ton(field->value[n], size));
1124dde5845aSJiri Kosina 		else				/* unsigned values */
11254291ee30SJoe Perches 			implement(hid, data, offset + n * size, size,
11264291ee30SJoe Perches 				  field->value[n]);
1127dde5845aSJiri Kosina 	}
1128dde5845aSJiri Kosina }
1129dde5845aSJiri Kosina 
1130dde5845aSJiri Kosina /*
1131dde5845aSJiri Kosina  * Create a report.
1132dde5845aSJiri Kosina  */
1133dde5845aSJiri Kosina 
1134229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data)
1135dde5845aSJiri Kosina {
1136dde5845aSJiri Kosina 	unsigned n;
1137dde5845aSJiri Kosina 
1138dde5845aSJiri Kosina 	if (report->id > 0)
1139dde5845aSJiri Kosina 		*data++ = report->id;
1140dde5845aSJiri Kosina 
114175c28df8SPete Zaitcev 	memset(data, 0, ((report->size - 1) >> 3) + 1);
1142dde5845aSJiri Kosina 	for (n = 0; n < report->maxfield; n++)
11434291ee30SJoe Perches 		hid_output_field(report->device, report->field[n], data);
1144dde5845aSJiri Kosina }
1145229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report);
1146dde5845aSJiri Kosina 
1147dde5845aSJiri Kosina /*
1148dde5845aSJiri Kosina  * Set a field value. The report this field belongs to has to be
1149dde5845aSJiri Kosina  * created and transferred to the device, to set this value in the
1150dde5845aSJiri Kosina  * device.
1151dde5845aSJiri Kosina  */
1152dde5845aSJiri Kosina 
1153dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1154dde5845aSJiri Kosina {
1155dde5845aSJiri Kosina 	unsigned size = field->report_size;
1156dde5845aSJiri Kosina 
1157cd667ce2SJiri Kosina 	hid_dump_input(field->report->device, field->usage + offset, value);
1158dde5845aSJiri Kosina 
1159dde5845aSJiri Kosina 	if (offset >= field->report_count) {
11608c3d52fcSJiri Kosina 		hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
11618c3d52fcSJiri Kosina 				offset, field->report_count);
1162dde5845aSJiri Kosina 		return -1;
1163dde5845aSJiri Kosina 	}
1164dde5845aSJiri Kosina 	if (field->logical_minimum < 0) {
1165dde5845aSJiri Kosina 		if (value != snto32(s32ton(value, size), size)) {
11668c3d52fcSJiri Kosina 			hid_err(field->report->device, "value %d is out of range\n", value);
1167dde5845aSJiri Kosina 			return -1;
1168dde5845aSJiri Kosina 		}
1169dde5845aSJiri Kosina 	}
1170dde5845aSJiri Kosina 	field->value[offset] = value;
1171dde5845aSJiri Kosina 	return 0;
1172dde5845aSJiri Kosina }
1173229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field);
1174dde5845aSJiri Kosina 
117585cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
117685cdaf52SJiri Slaby 		const u8 *data)
117785cdaf52SJiri Slaby {
117885cdaf52SJiri Slaby 	struct hid_report *report;
117985cdaf52SJiri Slaby 	unsigned int n = 0;	/* Normally report number is 0 */
118085cdaf52SJiri Slaby 
118185cdaf52SJiri Slaby 	/* Device uses numbered reports, data[0] is report number */
118285cdaf52SJiri Slaby 	if (report_enum->numbered)
118385cdaf52SJiri Slaby 		n = *data;
118485cdaf52SJiri Slaby 
118585cdaf52SJiri Slaby 	report = report_enum->report_id_hash[n];
118685cdaf52SJiri Slaby 	if (report == NULL)
118785cdaf52SJiri Slaby 		dbg_hid("undefined report_id %u received\n", n);
118885cdaf52SJiri Slaby 
118985cdaf52SJiri Slaby 	return report;
119085cdaf52SJiri Slaby }
119185cdaf52SJiri Slaby 
1192b6787242SJiri Kosina int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
119385cdaf52SJiri Slaby 		int interrupt)
1194aa8de2f0SJiri Kosina {
1195aa8de2f0SJiri Kosina 	struct hid_report_enum *report_enum = hid->report_enum + type;
1196aa8de2f0SJiri Kosina 	struct hid_report *report;
11976d85d037SBenjamin Tissoires 	struct hid_driver *hdrv;
119885cdaf52SJiri Slaby 	unsigned int a;
119985cdaf52SJiri Slaby 	int rsize, csize = size;
120085cdaf52SJiri Slaby 	u8 *cdata = data;
1201b6787242SJiri Kosina 	int ret = 0;
1202aa8de2f0SJiri Kosina 
120385cdaf52SJiri Slaby 	report = hid_get_report(report_enum, data);
120485cdaf52SJiri Slaby 	if (!report)
1205b6787242SJiri Kosina 		goto out;
1206aa8de2f0SJiri Kosina 
120785cdaf52SJiri Slaby 	if (report_enum->numbered) {
120885cdaf52SJiri Slaby 		cdata++;
120985cdaf52SJiri Slaby 		csize--;
1210aa8de2f0SJiri Kosina 	}
1211aa8de2f0SJiri Kosina 
1212aa8de2f0SJiri Kosina 	rsize = ((report->size - 1) >> 3) + 1;
1213aa8de2f0SJiri Kosina 
1214966922f2SArmando Visconti 	if (rsize > HID_MAX_BUFFER_SIZE)
1215966922f2SArmando Visconti 		rsize = HID_MAX_BUFFER_SIZE;
1216966922f2SArmando Visconti 
121785cdaf52SJiri Slaby 	if (csize < rsize) {
121885cdaf52SJiri Slaby 		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
121985cdaf52SJiri Slaby 				csize, rsize);
122085cdaf52SJiri Slaby 		memset(cdata + csize, 0, rsize - csize);
1221aa8de2f0SJiri Kosina 	}
1222aa8de2f0SJiri Kosina 
1223aa8de2f0SJiri Kosina 	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1224aa8de2f0SJiri Kosina 		hid->hiddev_report_event(hid, report);
1225b6787242SJiri Kosina 	if (hid->claimed & HID_CLAIMED_HIDRAW) {
1226b6787242SJiri Kosina 		ret = hidraw_report_event(hid, data, size);
1227b6787242SJiri Kosina 		if (ret)
1228b6787242SJiri Kosina 			goto out;
1229b6787242SJiri Kosina 	}
1230aa8de2f0SJiri Kosina 
1231b94e3c94SMatthieu CASTET 	if (hid->claimed != HID_CLAIMED_HIDRAW) {
123285cdaf52SJiri Slaby 		for (a = 0; a < report->maxfield; a++)
123385cdaf52SJiri Slaby 			hid_input_field(hid, report->field[a], cdata, interrupt);
12346d85d037SBenjamin Tissoires 		hdrv = hid->driver;
12356d85d037SBenjamin Tissoires 		if (hdrv && hdrv->report)
12366d85d037SBenjamin Tissoires 			hdrv->report(hid, report);
1237b94e3c94SMatthieu CASTET 	}
1238aa8de2f0SJiri Kosina 
1239aa8de2f0SJiri Kosina 	if (hid->claimed & HID_CLAIMED_INPUT)
1240aa8de2f0SJiri Kosina 		hidinput_report_event(hid, report);
1241b6787242SJiri Kosina out:
1242b6787242SJiri Kosina 	return ret;
124385cdaf52SJiri Slaby }
124485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event);
124585cdaf52SJiri Slaby 
124685cdaf52SJiri Slaby /**
124785cdaf52SJiri Slaby  * hid_input_report - report data from lower layer (usb, bt...)
124885cdaf52SJiri Slaby  *
124985cdaf52SJiri Slaby  * @hid: hid device
125085cdaf52SJiri Slaby  * @type: HID report type (HID_*_REPORT)
125185cdaf52SJiri Slaby  * @data: report contents
125285cdaf52SJiri Slaby  * @size: size of data parameter
1253ff9b00a2SJiri Kosina  * @interrupt: distinguish between interrupt and control transfers
125485cdaf52SJiri Slaby  *
125585cdaf52SJiri Slaby  * This is data entry for lower layers.
125685cdaf52SJiri Slaby  */
125785cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
125885cdaf52SJiri Slaby {
125976c317d6SJulia Lawall 	struct hid_report_enum *report_enum;
126076c317d6SJulia Lawall 	struct hid_driver *hdrv;
126185cdaf52SJiri Slaby 	struct hid_report *report;
126245dc1ac7SJiri Kosina 	int ret = 0;
126385cdaf52SJiri Slaby 
12644ea54542SDavid Herrmann 	if (!hid)
126585cdaf52SJiri Slaby 		return -ENODEV;
12664ea54542SDavid Herrmann 
1267c849a614SAndrew de los Reyes 	if (down_trylock(&hid->driver_input_lock))
12684ea54542SDavid Herrmann 		return -EBUSY;
12694ea54542SDavid Herrmann 
12704ea54542SDavid Herrmann 	if (!hid->driver) {
12714ea54542SDavid Herrmann 		ret = -ENODEV;
12724ea54542SDavid Herrmann 		goto unlock;
12734ea54542SDavid Herrmann 	}
127476c317d6SJulia Lawall 	report_enum = hid->report_enum + type;
127576c317d6SJulia Lawall 	hdrv = hid->driver;
127685cdaf52SJiri Slaby 
127785cdaf52SJiri Slaby 	if (!size) {
127885cdaf52SJiri Slaby 		dbg_hid("empty report\n");
12794ea54542SDavid Herrmann 		ret = -1;
12804ea54542SDavid Herrmann 		goto unlock;
128185cdaf52SJiri Slaby 	}
128285cdaf52SJiri Slaby 
1283b94e3c94SMatthieu CASTET 	/* Avoid unnecessary overhead if debugfs is disabled */
1284a5f04b9dSBenjamin Tissoires 	if (!list_empty(&hid->debug_list))
1285a5f04b9dSBenjamin Tissoires 		hid_dump_report(hid, type, data, size);
1286b94e3c94SMatthieu CASTET 
1287f77e347bSJiri Kosina 	report = hid_get_report(report_enum, data);
1288f77e347bSJiri Kosina 
12894ea54542SDavid Herrmann 	if (!report) {
12904ea54542SDavid Herrmann 		ret = -1;
12914ea54542SDavid Herrmann 		goto unlock;
12924ea54542SDavid Herrmann 	}
1293f77e347bSJiri Kosina 
129485cdaf52SJiri Slaby 	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
129585cdaf52SJiri Slaby 		ret = hdrv->raw_event(hid, report, data, size);
1296b1a1442aSJiri Kosina 		if (ret < 0) {
12974ea54542SDavid Herrmann 			ret = ret < 0 ? ret : 0;
12984ea54542SDavid Herrmann 			goto unlock;
12994ea54542SDavid Herrmann 		}
130085cdaf52SJiri Slaby 	}
130185cdaf52SJiri Slaby 
1302b6787242SJiri Kosina 	ret = hid_report_raw_event(hid, type, data, size, interrupt);
1303aa8de2f0SJiri Kosina 
13044ea54542SDavid Herrmann unlock:
1305c849a614SAndrew de los Reyes 	up(&hid->driver_input_lock);
130645dc1ac7SJiri Kosina 	return ret;
1307aa8de2f0SJiri Kosina }
1308aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report);
1309aa8de2f0SJiri Kosina 
13100f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev,
13110f37cd03SJiri Kosina 		const struct hid_device_id *id)
13120f37cd03SJiri Kosina {
13137431fb76SHenrik Rydberg 	return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
13144d53b801SHenrik Rydberg 		(id->group == HID_GROUP_ANY || id->group == hdev->group) &&
13150f37cd03SJiri Kosina 		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
13160f37cd03SJiri Kosina 		(id->product == HID_ANY_ID || id->product == hdev->product);
13170f37cd03SJiri Kosina }
13180f37cd03SJiri Kosina 
1319bbc21cfdSJeremy Fitzhardinge const struct hid_device_id *hid_match_id(struct hid_device *hdev,
13200f37cd03SJiri Kosina 		const struct hid_device_id *id)
13210f37cd03SJiri Kosina {
13220f37cd03SJiri Kosina 	for (; id->bus; id++)
13230f37cd03SJiri Kosina 		if (hid_match_one_id(hdev, id))
13240f37cd03SJiri Kosina 			return id;
13250f37cd03SJiri Kosina 
13260f37cd03SJiri Kosina 	return NULL;
13270f37cd03SJiri Kosina }
13280f37cd03SJiri Kosina 
13290f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = {
1330c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1331c0bd6a42SRichard Hughes 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
13320f37cd03SJiri Kosina 	{ }
13330f37cd03SJiri Kosina };
13340f37cd03SJiri Kosina 
13350f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev)
13360f37cd03SJiri Kosina {
13370f37cd03SJiri Kosina 	return !!hid_match_id(hdev, hid_hiddev_list);
13380f37cd03SJiri Kosina }
13390f37cd03SJiri Kosina 
13406d3bfb74SAlan Ott 
13416d3bfb74SAlan Ott static ssize_t
13426d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj,
13436d3bfb74SAlan Ott 		struct bin_attribute *attr,
13446d3bfb74SAlan Ott 		char *buf, loff_t off, size_t count)
13456d3bfb74SAlan Ott {
13466d3bfb74SAlan Ott 	struct device *dev = container_of(kobj, struct device, kobj);
13476d3bfb74SAlan Ott 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
13486d3bfb74SAlan Ott 
13496d3bfb74SAlan Ott 	if (off >= hdev->rsize)
13506d3bfb74SAlan Ott 		return 0;
13516d3bfb74SAlan Ott 
13526d3bfb74SAlan Ott 	if (off + count > hdev->rsize)
13536d3bfb74SAlan Ott 		count = hdev->rsize - off;
13546d3bfb74SAlan Ott 
13556d3bfb74SAlan Ott 	memcpy(buf, hdev->rdesc + off, count);
13566d3bfb74SAlan Ott 
13576d3bfb74SAlan Ott 	return count;
13586d3bfb74SAlan Ott }
13596d3bfb74SAlan Ott 
13606d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = {
13616d3bfb74SAlan Ott 	.attr = { .name = "report_descriptor", .mode = 0444 },
13626d3bfb74SAlan Ott 	.read = read_report_descriptor,
13636d3bfb74SAlan Ott 	.size = HID_MAX_DESCRIPTOR_SIZE,
13646d3bfb74SAlan Ott };
13656d3bfb74SAlan Ott 
136693c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
136793c10132SJiri Slaby {
136893c10132SJiri Slaby 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
136993c10132SJiri Slaby 		"Joystick", "Gamepad", "Keyboard", "Keypad",
137093c10132SJiri Slaby 		"Multi-Axis Controller"
137193c10132SJiri Slaby 	};
137293c10132SJiri Slaby 	const char *type, *bus;
137393c10132SJiri Slaby 	char buf[64];
137493c10132SJiri Slaby 	unsigned int i;
137593c10132SJiri Slaby 	int len;
13766d3bfb74SAlan Ott 	int ret;
137793c10132SJiri Slaby 
1378b5e5a37eSBastien Nocera 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1379b5e5a37eSBastien Nocera 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
13803a343ee4SDaniel Mack 	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
13813a343ee4SDaniel Mack 		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
138293c10132SJiri Slaby 	if (hdev->bus != BUS_USB)
138393c10132SJiri Slaby 		connect_mask &= ~HID_CONNECT_HIDDEV;
13840f37cd03SJiri Kosina 	if (hid_hiddev(hdev))
13850f37cd03SJiri Kosina 		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
138693c10132SJiri Slaby 
138793c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
138893c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
138993c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_INPUT;
1390b77c3920SBenjamin Tissoires 
139193c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
139293c10132SJiri Slaby 			!hdev->hiddev_connect(hdev,
139393c10132SJiri Slaby 				connect_mask & HID_CONNECT_HIDDEV_FORCE))
139493c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDDEV;
139593c10132SJiri Slaby 	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
139693c10132SJiri Slaby 		hdev->claimed |= HID_CLAIMED_HIDRAW;
139793c10132SJiri Slaby 
13984bc19f62SDavid Herrmann 	/* Drivers with the ->raw_event callback set are not required to connect
13994bc19f62SDavid Herrmann 	 * to any other listener. */
14004bc19f62SDavid Herrmann 	if (!hdev->claimed && !hdev->driver->raw_event) {
14014bc19f62SDavid Herrmann 		hid_err(hdev, "device has no listeners, quitting\n");
140293c10132SJiri Slaby 		return -ENODEV;
140393c10132SJiri Slaby 	}
140493c10132SJiri Slaby 
140593c10132SJiri Slaby 	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
140693c10132SJiri Slaby 			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
140793c10132SJiri Slaby 		hdev->ff_init(hdev);
140893c10132SJiri Slaby 
140993c10132SJiri Slaby 	len = 0;
141093c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_INPUT)
141193c10132SJiri Slaby 		len += sprintf(buf + len, "input");
141293c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
141393c10132SJiri Slaby 		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
141493c10132SJiri Slaby 				hdev->minor);
141593c10132SJiri Slaby 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
141693c10132SJiri Slaby 		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
141793c10132SJiri Slaby 				((struct hidraw *)hdev->hidraw)->minor);
141893c10132SJiri Slaby 
141993c10132SJiri Slaby 	type = "Device";
142093c10132SJiri Slaby 	for (i = 0; i < hdev->maxcollection; i++) {
142193c10132SJiri Slaby 		struct hid_collection *col = &hdev->collection[i];
142293c10132SJiri Slaby 		if (col->type == HID_COLLECTION_APPLICATION &&
142393c10132SJiri Slaby 		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
142493c10132SJiri Slaby 		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
142593c10132SJiri Slaby 			type = types[col->usage & 0xffff];
142693c10132SJiri Slaby 			break;
142793c10132SJiri Slaby 		}
142893c10132SJiri Slaby 	}
142993c10132SJiri Slaby 
143093c10132SJiri Slaby 	switch (hdev->bus) {
143193c10132SJiri Slaby 	case BUS_USB:
143293c10132SJiri Slaby 		bus = "USB";
143393c10132SJiri Slaby 		break;
143493c10132SJiri Slaby 	case BUS_BLUETOOTH:
143593c10132SJiri Slaby 		bus = "BLUETOOTH";
143693c10132SJiri Slaby 		break;
143793c10132SJiri Slaby 	default:
143893c10132SJiri Slaby 		bus = "<UNKNOWN>";
143993c10132SJiri Slaby 	}
144093c10132SJiri Slaby 
14416d3bfb74SAlan Ott 	ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
14426d3bfb74SAlan Ott 	if (ret)
14436d3bfb74SAlan Ott 		hid_warn(hdev,
14446d3bfb74SAlan Ott 			 "can't create sysfs report descriptor attribute err: %d\n", ret);
14456d3bfb74SAlan Ott 
14464291ee30SJoe Perches 	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
144793c10132SJiri Slaby 		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
144893c10132SJiri Slaby 		 type, hdev->name, hdev->phys);
144993c10132SJiri Slaby 
145093c10132SJiri Slaby 	return 0;
145193c10132SJiri Slaby }
145293c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect);
145393c10132SJiri Slaby 
1454c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev)
1455c4c259bcSJiri Kosina {
14566d3bfb74SAlan Ott 	device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1457c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_INPUT)
1458c4c259bcSJiri Kosina 		hidinput_disconnect(hdev);
1459c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1460c4c259bcSJiri Kosina 		hdev->hiddev_disconnect(hdev);
1461c4c259bcSJiri Kosina 	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1462c4c259bcSJiri Kosina 		hidraw_disconnect(hdev);
1463c4c259bcSJiri Kosina }
1464c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect);
1465c4c259bcSJiri Kosina 
146600315e4fSJiri Kosina /*
146700315e4fSJiri Kosina  * A list of devices for which there is a specialized driver on HID bus.
146800315e4fSJiri Kosina  *
146900315e4fSJiri Kosina  * Please note that for multitouch devices (driven by hid-multitouch driver),
147000315e4fSJiri Kosina  * there is a proper autodetection and autoloading in place (based on presence
147100315e4fSJiri Kosina  * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
147200315e4fSJiri Kosina  * as we are doing the right thing in hid_scan_usage().
147383499b52SAlexander Holler  *
147483499b52SAlexander Holler  * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
147583499b52SAlexander Holler  * physical is found inside a usage page of type sensor, hid-sensor-hub will be
147683499b52SAlexander Holler  * used as a driver. See hid_scan_report().
147700315e4fSJiri Kosina  */
1478ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = {
147914a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
148014a21cd4SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1481b7e1b203SLech Perczak 	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1482c0dbcc33SSergei Kolzun 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
14838c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1484128537ceSMichael Poole 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1485a462230eSChase Douglas 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
14868c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
14878c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
14888c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
14898c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
14908c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
14918c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
14928c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
14938c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
14948c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
14958c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
14968c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1497fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1498fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1499fef3f571SRyan Finnie 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
15008c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
15018c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
15028c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
15038c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
15048c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
15058c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
15069a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
15079a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
15089a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) },
15099a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
15109a4a5574SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) },
1511ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1512ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1513ee8a1a0aSJan Scholz 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
15148c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
15158c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
15168c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
15178c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
15188c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
15198c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1520a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1521a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1522a96d6ef3SHenrik Rydberg 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
152399b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
152499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
152599b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
152699b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
152799b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
152899b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
152947340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
153047340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
153147340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1532213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1533213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1534213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
15354a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
15364a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
15374a4c8799SDan Bastone 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
1538f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1539f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1540f6f554f0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
1541d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
1542d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
1543d762cc29SNobuhiro Iwamatsu 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
1544b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
1545b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
1546b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
15478d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
15488d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
15498d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
155023aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
155123aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
155223aeb61eSChristian Schuerer-Waldheim 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1553f9af7b9eSBen Hutchings 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
1554ad734bc1SAndreas Krist 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
15558c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
15568c19a515SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1557212da74dSJosenivaldo Benito Junior 	{ HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
1558b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1559bf280628SWayne Thomas 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1560c3dc66deSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
15613b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
15621ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1563fcfacfd3SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1564b9e4b1e0SDennis Kügler 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
15653596bb92SKeng-Yu Lin 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
15662d8767bbSCyrus Lien 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
15673a370ca1SDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
15680f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
15690f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1570e8d0eab4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
157176c9d8feSLionel Vaux 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
15720f221320SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
15733f866fbdSRichard Walmsley 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1574e05eefb9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
157564b386eaSRichard Nauber 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1576d23efc19SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
1577d23efc19SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
157804561c5aSIgnaz Forster 	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
15791f243e30SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
15805181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1581578f3a35SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
15825181e594SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
158342859e0bSLukasz Lubojanski 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1584949f8fefSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
15851e093206SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1586c2fd1a4eSCory Maccarrone 	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1587d946e65eSAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
1588ff9bf5a2STom Harwood 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
158940d3597fSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
159040d3597fSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
159168e353feSMartin Rusko 	{ HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_580) },
1592aaca9cc0SMichael Karcher 	{ HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
15934ddfe028SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
1594fdf93aa3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1595177900e8SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
15963685c18eSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
1597*0adb9c2cSBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
159879422741SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
159922ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
160022ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
160122ca20b2SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
1602b5635b12SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
160375b07022SChris Schlund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
1604aad932e7SAndres Freund #if IS_ENABLED(CONFIG_HID_LENOVO_TPKBD)
1605c1dcad2dSBernhard Seibold 	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
1606aad932e7SAndres Freund #endif
16075f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
16085f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
16095f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
16105f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
16115844c1cdSDavid Dillow 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
16125f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
16135f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
16145f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
16155f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
16165f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
16175f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
16185f22a799SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
16192c6118e4SHendrik Iben 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1620606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1621606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1622606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1623fd30ea8cSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1624606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
162574f292caSGary Stein 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1626606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1627606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
16285623a24aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
1629e00ddc9bSMichal Malý 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
1630243b706dSChristophe Borivant 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
1631fdc6807fSPeter Gundermann 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
16320944e964SKonstantin Khlebnikov #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
1633534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
1634534a7b8eSNestor Lopez Casado 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
16350944e964SKonstantin Khlebnikov #endif
163632c88cbcSSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1637606bd0a8SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
163824985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
163924985cf6SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1640236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1641236db47cSBruno Prémont 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
1642b580169aSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
164378a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
164478a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
164589759e20SAdam Jiang 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
164678a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
164778a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1648f3b83d71SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
164978a849a6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
16503b8006e5SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
165194011f93SRafi Rubin 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
16526e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
16536e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
16546e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
16556e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
16566e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
16576e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
16586e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
16596e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
16606e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
16616e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
16626e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
16636e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
16646e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
16656e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
16666e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
16676e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
16686e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
16696e32819eSmicki 	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1670270fdc07SHerton Ronaldo Krzesinski 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
1671cd9ec30dSJohnathon Harris 	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
16721e762532SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1673f6a04605STerry Lambert 	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
1674ca9bbdccSStefan Achatz #if IS_ENABLED(CONFIG_HID_ROCCAT)
167514bf62cdSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1676e68cc603SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1677d41c2a70SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
167847dbdbffSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
16798936aa31SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
16800e70f97fSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
16814424f616SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
1682cb7cf3daSStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
16833fce2246SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
16846a2a6390SStefan Achatz 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
1685ca9bbdccSStefan Achatz #endif
16861e93674aSAndreas Hübner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
1687980a3da6SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1688b355850bSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1689d586dca0SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
1690f04d5140SColin Leitner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
1691f04d5140SColin Leitner 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
16925844c1cdSDavid Dillow 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
1693bd28ce00SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
169435dca5b4SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
1695f9ce7c28SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1696cc6e0bbbSJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1697c1e0ac19SFernando Luis Vázquez Cao 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
169875dbb953SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
169990231e7eSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
170030ba2fbdSVivien Didelot 	{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
1701daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1702daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
17037a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
17047a84b133SRuben Aos Garralda 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1705daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
17063ee8f0a2SMarkus Rathgeb 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1707daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1708d65c3768SSimon Wood 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
1709740363fbSJiri Kosina 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
171044ea35c1SJarod Wilson 	{ HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
1711f14f526dSLev Babiev 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
171254001081SKees Bakker 	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1713711a680eSBruno Premont 	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
171441fa9230SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1715f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1716f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1717f8a489ccSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
17186be914f1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
1719d1257081SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
1720eb4e426aSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
1721fac733f0SJussi Kivilinna 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
172242fc04e5SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
1723ad395ccaSSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
17241bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
17251bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
17261bcc2067SSean Young 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
1727ca2dcd40SBastien Nocera 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
172878761ff9SPrzemo Firszt 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
172972a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
173000e7f964SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
17314fdc18d1SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
1732a786e83cSNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
173372a46344SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
17348f1acc32SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1735d2ee4dd9SNikolai Kondrashov 	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
173674bc6953SStefan Kriwanek 	{ HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1737daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1738daedb3d6SAnssi Hannula 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1739a9885c8fSDon Prince 	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
17408c19a515SJiri Slaby 
174178a849a6SJiri Slaby 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
174202fb72a0SDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1743a33042faSDavid Herrmann 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
174485cdaf52SJiri Slaby 	{ }
174585cdaf52SJiri Slaby };
174685cdaf52SJiri Slaby 
17473a6f82f7SJiri Slaby struct hid_dynid {
17483a6f82f7SJiri Slaby 	struct list_head list;
17493a6f82f7SJiri Slaby 	struct hid_device_id id;
17503a6f82f7SJiri Slaby };
17513a6f82f7SJiri Slaby 
17523a6f82f7SJiri Slaby /**
17533a6f82f7SJiri Slaby  * store_new_id - add a new HID device ID to this driver and re-probe devices
17543a6f82f7SJiri Slaby  * @driver: target device driver
17553a6f82f7SJiri Slaby  * @buf: buffer for scanning device ID data
17563a6f82f7SJiri Slaby  * @count: input size
17573a6f82f7SJiri Slaby  *
17583a6f82f7SJiri Slaby  * Adds a new dynamic hid device ID to this driver,
17593a6f82f7SJiri Slaby  * and causes the driver to probe for all devices again.
17603a6f82f7SJiri Slaby  */
17613a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf,
17623a6f82f7SJiri Slaby 		size_t count)
17633a6f82f7SJiri Slaby {
17643a6f82f7SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
17653a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
17663a6f82f7SJiri Slaby 	__u32 bus, vendor, product;
17673a6f82f7SJiri Slaby 	unsigned long driver_data = 0;
17683a6f82f7SJiri Slaby 	int ret;
17693a6f82f7SJiri Slaby 
17703a6f82f7SJiri Slaby 	ret = sscanf(buf, "%x %x %x %lx",
17713a6f82f7SJiri Slaby 			&bus, &vendor, &product, &driver_data);
17723a6f82f7SJiri Slaby 	if (ret < 3)
17733a6f82f7SJiri Slaby 		return -EINVAL;
17743a6f82f7SJiri Slaby 
17753a6f82f7SJiri Slaby 	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
17763a6f82f7SJiri Slaby 	if (!dynid)
17773a6f82f7SJiri Slaby 		return -ENOMEM;
17783a6f82f7SJiri Slaby 
17793a6f82f7SJiri Slaby 	dynid->id.bus = bus;
17804d53b801SHenrik Rydberg 	dynid->id.group = HID_GROUP_ANY;
17813a6f82f7SJiri Slaby 	dynid->id.vendor = vendor;
17823a6f82f7SJiri Slaby 	dynid->id.product = product;
17833a6f82f7SJiri Slaby 	dynid->id.driver_data = driver_data;
17843a6f82f7SJiri Slaby 
17853a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
17863a6f82f7SJiri Slaby 	list_add_tail(&dynid->list, &hdrv->dyn_list);
17873a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
17883a6f82f7SJiri Slaby 
17893a6f82f7SJiri Slaby 	ret = driver_attach(&hdrv->driver);
17903a6f82f7SJiri Slaby 
17913a6f82f7SJiri Slaby 	return ret ? : count;
17923a6f82f7SJiri Slaby }
17933a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
17943a6f82f7SJiri Slaby 
17953a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv)
17963a6f82f7SJiri Slaby {
17973a6f82f7SJiri Slaby 	struct hid_dynid *dynid, *n;
17983a6f82f7SJiri Slaby 
17993a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
18003a6f82f7SJiri Slaby 	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
18013a6f82f7SJiri Slaby 		list_del(&dynid->list);
18023a6f82f7SJiri Slaby 		kfree(dynid);
18033a6f82f7SJiri Slaby 	}
18043a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
18053a6f82f7SJiri Slaby }
18063a6f82f7SJiri Slaby 
18073a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
18083a6f82f7SJiri Slaby 		struct hid_driver *hdrv)
18093a6f82f7SJiri Slaby {
18103a6f82f7SJiri Slaby 	struct hid_dynid *dynid;
18113a6f82f7SJiri Slaby 
18123a6f82f7SJiri Slaby 	spin_lock(&hdrv->dyn_lock);
18133a6f82f7SJiri Slaby 	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
18143a6f82f7SJiri Slaby 		if (hid_match_one_id(hdev, &dynid->id)) {
18153a6f82f7SJiri Slaby 			spin_unlock(&hdrv->dyn_lock);
18163a6f82f7SJiri Slaby 			return &dynid->id;
18173a6f82f7SJiri Slaby 		}
18183a6f82f7SJiri Slaby 	}
18193a6f82f7SJiri Slaby 	spin_unlock(&hdrv->dyn_lock);
18203a6f82f7SJiri Slaby 
18213a6f82f7SJiri Slaby 	return hid_match_id(hdev, hdrv->id_table);
18223a6f82f7SJiri Slaby }
18233a6f82f7SJiri Slaby 
182485cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv)
182585cdaf52SJiri Slaby {
182685cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
182785cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
182885cdaf52SJiri Slaby 
1829070748edSHenrik Rydberg 	return hid_match_device(hdev, hdrv) != NULL;
183085cdaf52SJiri Slaby }
183185cdaf52SJiri Slaby 
183285cdaf52SJiri Slaby static int hid_device_probe(struct device *dev)
183385cdaf52SJiri Slaby {
183485cdaf52SJiri Slaby 	struct hid_driver *hdrv = container_of(dev->driver,
183585cdaf52SJiri Slaby 			struct hid_driver, driver);
183685cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
183785cdaf52SJiri Slaby 	const struct hid_device_id *id;
183885cdaf52SJiri Slaby 	int ret = 0;
183985cdaf52SJiri Slaby 
18404ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
18414ea54542SDavid Herrmann 		return -EINTR;
1842c849a614SAndrew de los Reyes 	if (down_interruptible(&hdev->driver_input_lock)) {
1843c849a614SAndrew de los Reyes 		ret = -EINTR;
1844c849a614SAndrew de los Reyes 		goto unlock_driver_lock;
1845c849a614SAndrew de los Reyes 	}
1846c849a614SAndrew de los Reyes 	hdev->io_started = false;
18474ea54542SDavid Herrmann 
184885cdaf52SJiri Slaby 	if (!hdev->driver) {
18493a6f82f7SJiri Slaby 		id = hid_match_device(hdev, hdrv);
1850ba623a77SDan Carpenter 		if (id == NULL) {
1851ba623a77SDan Carpenter 			ret = -ENODEV;
1852ba623a77SDan Carpenter 			goto unlock;
1853ba623a77SDan Carpenter 		}
1854c500c971SJiri Slaby 
185585cdaf52SJiri Slaby 		hdev->driver = hdrv;
1856c500c971SJiri Slaby 		if (hdrv->probe) {
1857c500c971SJiri Slaby 			ret = hdrv->probe(hdev, id);
1858c500c971SJiri Slaby 		} else { /* default probe */
1859a7197c2eSHenrik Rydberg 			ret = hid_open_report(hdev);
1860c500c971SJiri Slaby 			if (!ret)
186193c10132SJiri Slaby 				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1862c500c971SJiri Slaby 		}
1863a7197c2eSHenrik Rydberg 		if (ret) {
1864a7197c2eSHenrik Rydberg 			hid_close_report(hdev);
1865c500c971SJiri Slaby 			hdev->driver = NULL;
186685cdaf52SJiri Slaby 		}
1867a7197c2eSHenrik Rydberg 	}
1868ba623a77SDan Carpenter unlock:
1869c849a614SAndrew de los Reyes 	if (!hdev->io_started)
1870c849a614SAndrew de los Reyes 		up(&hdev->driver_input_lock);
1871c849a614SAndrew de los Reyes unlock_driver_lock:
18724ea54542SDavid Herrmann 	up(&hdev->driver_lock);
187385cdaf52SJiri Slaby 	return ret;
187485cdaf52SJiri Slaby }
187585cdaf52SJiri Slaby 
187685cdaf52SJiri Slaby static int hid_device_remove(struct device *dev)
187785cdaf52SJiri Slaby {
187885cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
18794ea54542SDavid Herrmann 	struct hid_driver *hdrv;
1880c849a614SAndrew de los Reyes 	int ret = 0;
188185cdaf52SJiri Slaby 
18824ea54542SDavid Herrmann 	if (down_interruptible(&hdev->driver_lock))
18834ea54542SDavid Herrmann 		return -EINTR;
1884c849a614SAndrew de los Reyes 	if (down_interruptible(&hdev->driver_input_lock)) {
1885c849a614SAndrew de los Reyes 		ret = -EINTR;
1886c849a614SAndrew de los Reyes 		goto unlock_driver_lock;
1887c849a614SAndrew de los Reyes 	}
1888c849a614SAndrew de los Reyes 	hdev->io_started = false;
18894ea54542SDavid Herrmann 
18904ea54542SDavid Herrmann 	hdrv = hdev->driver;
189185cdaf52SJiri Slaby 	if (hdrv) {
189285cdaf52SJiri Slaby 		if (hdrv->remove)
189385cdaf52SJiri Slaby 			hdrv->remove(hdev);
1894c500c971SJiri Slaby 		else /* default remove */
1895c500c971SJiri Slaby 			hid_hw_stop(hdev);
1896a7197c2eSHenrik Rydberg 		hid_close_report(hdev);
189785cdaf52SJiri Slaby 		hdev->driver = NULL;
189885cdaf52SJiri Slaby 	}
189985cdaf52SJiri Slaby 
1900c849a614SAndrew de los Reyes 	if (!hdev->io_started)
1901c849a614SAndrew de los Reyes 		up(&hdev->driver_input_lock);
1902c849a614SAndrew de los Reyes unlock_driver_lock:
19034ea54542SDavid Herrmann 	up(&hdev->driver_lock);
1904c849a614SAndrew de los Reyes 	return ret;
190585cdaf52SJiri Slaby }
190685cdaf52SJiri Slaby 
19074d53b801SHenrik Rydberg static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
19084d53b801SHenrik Rydberg 			     char *buf)
19094d53b801SHenrik Rydberg {
19104d53b801SHenrik Rydberg 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
19114d53b801SHenrik Rydberg 	int len;
19124d53b801SHenrik Rydberg 
19134d53b801SHenrik Rydberg 	len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
19144d53b801SHenrik Rydberg 		       hdev->bus, hdev->group, hdev->vendor, hdev->product);
19154d53b801SHenrik Rydberg 
19164d53b801SHenrik Rydberg 	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
19174d53b801SHenrik Rydberg }
19184d53b801SHenrik Rydberg 
19194d53b801SHenrik Rydberg static struct device_attribute hid_dev_attrs[] = {
19204d53b801SHenrik Rydberg 	__ATTR_RO(modalias),
19214d53b801SHenrik Rydberg 	__ATTR_NULL,
19224d53b801SHenrik Rydberg };
19234d53b801SHenrik Rydberg 
192485cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
192585cdaf52SJiri Slaby {
192685cdaf52SJiri Slaby 	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
192785cdaf52SJiri Slaby 
192885cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
192985cdaf52SJiri Slaby 			hdev->bus, hdev->vendor, hdev->product))
193085cdaf52SJiri Slaby 		return -ENOMEM;
193185cdaf52SJiri Slaby 
193285cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
193385cdaf52SJiri Slaby 		return -ENOMEM;
193485cdaf52SJiri Slaby 
193585cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
193685cdaf52SJiri Slaby 		return -ENOMEM;
193785cdaf52SJiri Slaby 
193885cdaf52SJiri Slaby 	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
193985cdaf52SJiri Slaby 		return -ENOMEM;
194085cdaf52SJiri Slaby 
19414d53b801SHenrik Rydberg 	if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
19424d53b801SHenrik Rydberg 			   hdev->bus, hdev->group, hdev->vendor, hdev->product))
194385cdaf52SJiri Slaby 		return -ENOMEM;
194485cdaf52SJiri Slaby 
194585cdaf52SJiri Slaby 	return 0;
194685cdaf52SJiri Slaby }
194785cdaf52SJiri Slaby 
194885cdaf52SJiri Slaby static struct bus_type hid_bus_type = {
194985cdaf52SJiri Slaby 	.name		= "hid",
19504d53b801SHenrik Rydberg 	.dev_attrs	= hid_dev_attrs,
195185cdaf52SJiri Slaby 	.match		= hid_bus_match,
195285cdaf52SJiri Slaby 	.probe		= hid_device_probe,
195385cdaf52SJiri Slaby 	.remove		= hid_device_remove,
195485cdaf52SJiri Slaby 	.uevent		= hid_uevent,
195585cdaf52SJiri Slaby };
195685cdaf52SJiri Slaby 
1957bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */
1958d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = {
1959d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1960d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1961d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1962d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1963d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1964d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1965d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1966d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1967d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1968d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1969d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1970d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
197177f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
197277f720b7SStephane Chatty 	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
197362a56582SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
197411030183SHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
1975d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1976d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1977d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1978d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1979d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1980d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
19815f6108cfSAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1982d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1983d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
198473bc7d31SMelchior FRANZ 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
1985789aaa2eSDan Delaney 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
1986d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
198770c66567SPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1988df506f2cSPetr Štetiar 	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1989b1807719SBenjamin Tissoires 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1990d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1991d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1992d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1993d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1994d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1995d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1996d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1997d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1998d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1999d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
2000d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
2001d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
2002d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
2003d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
2004d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
2005d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
20068e2ce73eSHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
2007d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
2008d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
2009d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
2010d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
2011d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
2012d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
2013d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
2014d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
2015d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
2016d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
2017d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
2018d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
2019d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
2020d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
2021d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
2022d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
2023d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
2024d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
2025d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
2026d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
2027d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
2028d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
2029d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
2030d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
2031d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
2032d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
2033d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
2034d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
2035d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
2036d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
2037d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
2038d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
2039d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
2040d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
2041d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
2042d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
2043d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
2044d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
2045d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
2046d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
2047d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
2048d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
2049d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
2050d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
2051d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
2052d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
2053d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
205431b9779cSVincent Palatin 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) },
205531b9779cSVincent Palatin 	{ HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) },
2056d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
2057c91c21c5SAlexey Klimov 	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
2058d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
2059eb8141ccSLamarque Vieira Souza 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
2060d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
2061ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
2062d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
2063ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
2064d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
2065ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
2066ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
2067ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
2068ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
2069ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
2070ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
2071d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
2072d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
2073d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
2074ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
2075ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
2076ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
2077d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
2078d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
2079ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
2080d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
2081d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
2082d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
2083d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
2084d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
2085ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
2086ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
2087ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
2088ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
2089ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
2090ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
2091ce97cac8SMichael Hund 	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
20923ffb62cbSYuri Khan 	{ HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
2093d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
2094d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
2095d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
2096d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
2097d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
2098d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
2099d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
2100d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
2101d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
2102d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
2103d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
2104d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
2105d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
2106d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
2107d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
2108d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
2109d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
2110d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
2111d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
21124cfae3e8SHenning Glawe 	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
211335cfd1d9SMichael Tokarev 	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
21148491ee10SJan Steinhoff #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
21158491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
21168491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
21178491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
21188491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
21198491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
21208491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
21218491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
21228491ee10SJan Steinhoff 	{ HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
21238491ee10SJan Steinhoff #endif
2124d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
2125d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
2126d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
2127d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
2128d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
2129d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
2130d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
2131d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
2132d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
2133d458a9dfSJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
2134d458a9dfSJiri Slaby 	{ }
2135d458a9dfSJiri Slaby };
2136d458a9dfSJiri Slaby 
2137b4d8e473SJiri Slaby /**
2138b4d8e473SJiri Slaby  * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
2139b4d8e473SJiri Slaby  *
2140b4d8e473SJiri Slaby  * There are composite devices for which we want to ignore only a certain
2141b4d8e473SJiri Slaby  * interface. This is a list of devices for which only the mouse interface will
2142b4d8e473SJiri Slaby  * be ignored. This allows a dedicated driver to take care of the interface.
2143b4d8e473SJiri Slaby  */
2144b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = {
2145b4d8e473SJiri Slaby 	/* appletouch driver */
2146b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
2147b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
2148b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
2149b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
2150b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
2151b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
2152b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
2153b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
2154b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
2155b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
2156b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
2157b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
2158b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
2159b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
2160b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
2161b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
2162b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
2163b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
2164b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
2165b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
2166ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
2167ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
2168ac26fca3SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
216999b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
217099b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
217199b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
217299b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
217399b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
217499b9f758SEdgar (gimli) Hucek 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
217547340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
217647340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
217747340bd9SAndy Botting 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
2178213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
2179213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
2180213f9da8SGökçen Eraslan 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
21814b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
21824b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
21834b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
21844b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
21854b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
21864b086910SJiri Kosina 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
2187b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
2188b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
2189b2e6ad7dSRyan Bourgeois 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
21908d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
21918d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
21928d80da90SDirk Hohndel 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
2193b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
2194b4d8e473SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
2195b4d8e473SJiri Slaby 	{ }
2196b4d8e473SJiri Slaby };
2197b4d8e473SJiri Slaby 
21984529eefaSLamarque V. Souza bool hid_ignore(struct hid_device *hdev)
2199d458a9dfSJiri Slaby {
22004529eefaSLamarque V. Souza 	if (hdev->quirks & HID_QUIRK_NO_IGNORE)
22014529eefaSLamarque V. Souza 		return false;
22024529eefaSLamarque V. Souza 	if (hdev->quirks & HID_QUIRK_IGNORE)
22034529eefaSLamarque V. Souza 		return true;
22044529eefaSLamarque V. Souza 
2205d458a9dfSJiri Slaby 	switch (hdev->vendor) {
2206d458a9dfSJiri Slaby 	case USB_VENDOR_ID_CODEMERCS:
2207d458a9dfSJiri Slaby 		/* ignore all Code Mercenaries IOWarrior devices */
2208d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
2209d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
2210d458a9dfSJiri Slaby 			return true;
2211d458a9dfSJiri Slaby 		break;
2212d458a9dfSJiri Slaby 	case USB_VENDOR_ID_LOGITECH:
2213d458a9dfSJiri Slaby 		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
2214d458a9dfSJiri Slaby 				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
2215d458a9dfSJiri Slaby 			return true;
221665dd3b69SHans Verkuil 		/*
221765dd3b69SHans Verkuil 		 * The Keene FM transmitter USB device has the same USB ID as
221865dd3b69SHans Verkuil 		 * the Logitech AudioHub Speaker, but it should ignore the hid.
221965dd3b69SHans Verkuil 		 * Check if the name is that of the Keene device.
222065dd3b69SHans Verkuil 		 * For reference: the name of the AudioHub is
222165dd3b69SHans Verkuil 		 * "HOLTEK  AudioHub Speaker".
222265dd3b69SHans Verkuil 		 */
222365dd3b69SHans Verkuil 		if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
222465dd3b69SHans Verkuil 			!strcmp(hdev->name, "HOLTEK  B-LINK USB Audio  "))
222565dd3b69SHans Verkuil 				return true;
2226d458a9dfSJiri Slaby 		break;
222731f7fd79SJarod Wilson 	case USB_VENDOR_ID_SOUNDGRAPH:
222831f7fd79SJarod Wilson 		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
222931f7fd79SJarod Wilson 		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
223031f7fd79SJarod Wilson 			return true;
223131f7fd79SJarod Wilson 		break;
2232bba5394aSXing Wei 	case USB_VENDOR_ID_HANWANG:
2233bba5394aSXing Wei 		if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
2234bba5394aSXing Wei 		    hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
2235bba5394aSXing Wei 			return true;
2236bba5394aSXing Wei 		break;
22376dc1418eSTomoki Sekiyama 	case USB_VENDOR_ID_JESS:
22386dc1418eSTomoki Sekiyama 		if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
22396dc1418eSTomoki Sekiyama 				hdev->type == HID_TYPE_USBNONE)
22406dc1418eSTomoki Sekiyama 			return true;
22416dc1418eSTomoki Sekiyama 		break;
2242729b814aSForest Bond 	case USB_VENDOR_ID_DWAV:
2243729b814aSForest Bond 		/* These are handled by usbtouchscreen. hdev->type is probably
2244729b814aSForest Bond 		 * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match
2245729b814aSForest Bond 		 * usbtouchscreen. */
2246729b814aSForest Bond 		if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER ||
2247729b814aSForest Bond 		     hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) &&
2248729b814aSForest Bond 		    hdev->type != HID_TYPE_USBMOUSE)
2249729b814aSForest Bond 			return true;
2250729b814aSForest Bond 		break;
225130b6b7d8SIan Abbott 	case USB_VENDOR_ID_VELLEMAN:
225230b6b7d8SIan Abbott 		/* These are not HID devices.  They are handled by comedi. */
225330b6b7d8SIan Abbott 		if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
225430b6b7d8SIan Abbott 		     hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
225530b6b7d8SIan Abbott 		    (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
225630b6b7d8SIan Abbott 		     hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
225730b6b7d8SIan Abbott 			return true;
225830b6b7d8SIan Abbott 		break;
22595b4617d8SAlexey Klimov 	case USB_VENDOR_ID_ATMEL_V_USB:
22605b4617d8SAlexey Klimov 		/* Masterkit MA901 usb radio based on Atmel tiny85 chip and
22615b4617d8SAlexey Klimov 		 * it has the same USB ID as many Atmel V-USB devices. This
22625b4617d8SAlexey Klimov 		 * usb radio is handled by radio-ma901.c driver so we want
22635b4617d8SAlexey Klimov 		 * ignore the hid. Check the name, bus, product and ignore
22645b4617d8SAlexey Klimov 		 * if we have MA901 usb radio.
22655b4617d8SAlexey Klimov 		 */
22665b4617d8SAlexey Klimov 		if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB &&
22675b4617d8SAlexey Klimov 			hdev->bus == BUS_USB &&
22685b4617d8SAlexey Klimov 			strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)
22695b4617d8SAlexey Klimov 			return true;
22705b4617d8SAlexey Klimov 		break;
2271d458a9dfSJiri Slaby 	}
2272d458a9dfSJiri Slaby 
2273b4d8e473SJiri Slaby 	if (hdev->type == HID_TYPE_USBMOUSE &&
2274b4d8e473SJiri Slaby 			hid_match_id(hdev, hid_mouse_ignore_list))
2275b4d8e473SJiri Slaby 		return true;
2276b4d8e473SJiri Slaby 
2277d458a9dfSJiri Slaby 	return !!hid_match_id(hdev, hid_ignore_list);
2278d458a9dfSJiri Slaby }
22794529eefaSLamarque V. Souza EXPORT_SYMBOL_GPL(hid_ignore);
2280d458a9dfSJiri Slaby 
228185cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev)
228285cdaf52SJiri Slaby {
228385cdaf52SJiri Slaby 	static atomic_t id = ATOMIC_INIT(0);
228485cdaf52SJiri Slaby 	int ret;
228585cdaf52SJiri Slaby 
228685cdaf52SJiri Slaby 	if (WARN_ON(hdev->status & HID_STAT_ADDED))
228785cdaf52SJiri Slaby 		return -EBUSY;
228885cdaf52SJiri Slaby 
2289d458a9dfSJiri Slaby 	/* we need to kill them here, otherwise they will stay allocated to
2290d458a9dfSJiri Slaby 	 * wait for coming driver */
22914529eefaSLamarque V. Souza 	if (hid_ignore(hdev))
2292d458a9dfSJiri Slaby 		return -ENODEV;
2293d458a9dfSJiri Slaby 
2294a7197c2eSHenrik Rydberg 	/*
2295a7197c2eSHenrik Rydberg 	 * Read the device report descriptor once and use as template
2296a7197c2eSHenrik Rydberg 	 * for the driver-specific modifications.
2297a7197c2eSHenrik Rydberg 	 */
2298a7197c2eSHenrik Rydberg 	ret = hdev->ll_driver->parse(hdev);
2299a7197c2eSHenrik Rydberg 	if (ret)
2300a7197c2eSHenrik Rydberg 		return ret;
2301a7197c2eSHenrik Rydberg 	if (!hdev->dev_rdesc)
2302a7197c2eSHenrik Rydberg 		return -ENODEV;
2303a7197c2eSHenrik Rydberg 
2304734c6609SHenrik Rydberg 	/*
2305734c6609SHenrik Rydberg 	 * Scan generic devices for group information
2306734c6609SHenrik Rydberg 	 */
2307734c6609SHenrik Rydberg 	if (hid_ignore_special_drivers ||
2308734c6609SHenrik Rydberg 	    !hid_match_id(hdev, hid_have_special_driver)) {
2309734c6609SHenrik Rydberg 		ret = hid_scan_report(hdev);
2310734c6609SHenrik Rydberg 		if (ret)
2311734c6609SHenrik Rydberg 			hid_warn(hdev, "bad device descriptor (%d)\n", ret);
2312734c6609SHenrik Rydberg 	}
2313734c6609SHenrik Rydberg 
23146bbe586fSKay Sievers 	/* XXX hack, any other cleaner solution after the driver core
23156bbe586fSKay Sievers 	 * is converted to allow more than 20 bytes as the device name? */
23166bbe586fSKay Sievers 	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
231785cdaf52SJiri Slaby 		     hdev->vendor, hdev->product, atomic_inc_return(&id));
231885cdaf52SJiri Slaby 
23194da361b6SBruno Prémont 	hid_debug_register(hdev, dev_name(&hdev->dev));
232085cdaf52SJiri Slaby 	ret = device_add(&hdev->dev);
232185cdaf52SJiri Slaby 	if (!ret)
232285cdaf52SJiri Slaby 		hdev->status |= HID_STAT_ADDED;
23234da361b6SBruno Prémont 	else
23244da361b6SBruno Prémont 		hid_debug_unregister(hdev);
2325a635f9ddSJiri Kosina 
232685cdaf52SJiri Slaby 	return ret;
232785cdaf52SJiri Slaby }
232885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device);
232985cdaf52SJiri Slaby 
233085cdaf52SJiri Slaby /**
233185cdaf52SJiri Slaby  * hid_allocate_device - allocate new hid device descriptor
233285cdaf52SJiri Slaby  *
233385cdaf52SJiri Slaby  * Allocate and initialize hid device, so that hid_destroy_device might be
233485cdaf52SJiri Slaby  * used to free it.
233585cdaf52SJiri Slaby  *
233685cdaf52SJiri Slaby  * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
233785cdaf52SJiri Slaby  * error value.
233885cdaf52SJiri Slaby  */
233985cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void)
234085cdaf52SJiri Slaby {
234185cdaf52SJiri Slaby 	struct hid_device *hdev;
234285cdaf52SJiri Slaby 	int ret = -ENOMEM;
234385cdaf52SJiri Slaby 
234485cdaf52SJiri Slaby 	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
234585cdaf52SJiri Slaby 	if (hdev == NULL)
234685cdaf52SJiri Slaby 		return ERR_PTR(ret);
234785cdaf52SJiri Slaby 
234885cdaf52SJiri Slaby 	device_initialize(&hdev->dev);
234985cdaf52SJiri Slaby 	hdev->dev.release = hid_device_release;
235085cdaf52SJiri Slaby 	hdev->dev.bus = &hid_bus_type;
235185cdaf52SJiri Slaby 
2352a7197c2eSHenrik Rydberg 	hid_close_report(hdev);
235385cdaf52SJiri Slaby 
2354cd667ce2SJiri Kosina 	init_waitqueue_head(&hdev->debug_wait);
2355cd667ce2SJiri Kosina 	INIT_LIST_HEAD(&hdev->debug_list);
23561deb9d34SJiri Kosina 	spin_lock_init(&hdev->debug_list_lock);
23574ea54542SDavid Herrmann 	sema_init(&hdev->driver_lock, 1);
2358c849a614SAndrew de los Reyes 	sema_init(&hdev->driver_input_lock, 1);
2359cd667ce2SJiri Kosina 
236085cdaf52SJiri Slaby 	return hdev;
236185cdaf52SJiri Slaby }
236285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device);
236385cdaf52SJiri Slaby 
236485cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev)
236585cdaf52SJiri Slaby {
236685cdaf52SJiri Slaby 	if (hdev->status & HID_STAT_ADDED) {
236785cdaf52SJiri Slaby 		device_del(&hdev->dev);
2368a635f9ddSJiri Kosina 		hid_debug_unregister(hdev);
236985cdaf52SJiri Slaby 		hdev->status &= ~HID_STAT_ADDED;
237085cdaf52SJiri Slaby 	}
2371a7197c2eSHenrik Rydberg 	kfree(hdev->dev_rdesc);
2372a7197c2eSHenrik Rydberg 	hdev->dev_rdesc = NULL;
2373a7197c2eSHenrik Rydberg 	hdev->dev_rsize = 0;
237485cdaf52SJiri Slaby }
237585cdaf52SJiri Slaby 
237685cdaf52SJiri Slaby /**
237785cdaf52SJiri Slaby  * hid_destroy_device - free previously allocated device
237885cdaf52SJiri Slaby  *
237985cdaf52SJiri Slaby  * @hdev: hid device
238085cdaf52SJiri Slaby  *
238185cdaf52SJiri Slaby  * If you allocate hid_device through hid_allocate_device, you should ever
238285cdaf52SJiri Slaby  * free by this function.
238385cdaf52SJiri Slaby  */
238485cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev)
238585cdaf52SJiri Slaby {
238685cdaf52SJiri Slaby 	hid_remove_device(hdev);
238785cdaf52SJiri Slaby 	put_device(&hdev->dev);
238885cdaf52SJiri Slaby }
238985cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device);
239085cdaf52SJiri Slaby 
239185cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
239285cdaf52SJiri Slaby 		const char *mod_name)
239385cdaf52SJiri Slaby {
23943a6f82f7SJiri Slaby 	int ret;
23953a6f82f7SJiri Slaby 
239685cdaf52SJiri Slaby 	hdrv->driver.name = hdrv->name;
239785cdaf52SJiri Slaby 	hdrv->driver.bus = &hid_bus_type;
239885cdaf52SJiri Slaby 	hdrv->driver.owner = owner;
239985cdaf52SJiri Slaby 	hdrv->driver.mod_name = mod_name;
240085cdaf52SJiri Slaby 
24013a6f82f7SJiri Slaby 	INIT_LIST_HEAD(&hdrv->dyn_list);
24023a6f82f7SJiri Slaby 	spin_lock_init(&hdrv->dyn_lock);
24033a6f82f7SJiri Slaby 
24043a6f82f7SJiri Slaby 	ret = driver_register(&hdrv->driver);
24053a6f82f7SJiri Slaby 	if (ret)
24063a6f82f7SJiri Slaby 		return ret;
24073a6f82f7SJiri Slaby 
24083a6f82f7SJiri Slaby 	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
24093a6f82f7SJiri Slaby 	if (ret)
24103a6f82f7SJiri Slaby 		driver_unregister(&hdrv->driver);
24113a6f82f7SJiri Slaby 
24123a6f82f7SJiri Slaby 	return ret;
241385cdaf52SJiri Slaby }
241485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver);
241585cdaf52SJiri Slaby 
241685cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv)
241785cdaf52SJiri Slaby {
24183a6f82f7SJiri Slaby 	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
241985cdaf52SJiri Slaby 	driver_unregister(&hdrv->driver);
24203a6f82f7SJiri Slaby 	hid_free_dynids(hdrv);
242185cdaf52SJiri Slaby }
242285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver);
242385cdaf52SJiri Slaby 
24240361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid)
24250361a28dSOliver Neukum {
24260361a28dSOliver Neukum 	struct hid_input *hidinput;
24270361a28dSOliver Neukum 	int i;
24280361a28dSOliver Neukum 
2429e5288eb5SJiri Kosina 	if (!(hid->claimed & HID_CLAIMED_INPUT))
2430e5288eb5SJiri Kosina 		return 0;
2431e5288eb5SJiri Kosina 
24320361a28dSOliver Neukum 	list_for_each_entry(hidinput, &hid->inputs, list) {
24330361a28dSOliver Neukum 		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
24340361a28dSOliver Neukum 			if (hidinput->input->key[i])
24350361a28dSOliver Neukum 				return 1;
24360361a28dSOliver Neukum 	}
24370361a28dSOliver Neukum 
24380361a28dSOliver Neukum 	return 0;
24390361a28dSOliver Neukum }
24400361a28dSOliver Neukum 
24410361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
24420361a28dSOliver Neukum 
244386166b7bSJiri Kosina static int __init hid_init(void)
244486166b7bSJiri Kosina {
244585cdaf52SJiri Slaby 	int ret;
244685cdaf52SJiri Slaby 
2447a635f9ddSJiri Kosina 	if (hid_debug)
24484291ee30SJoe Perches 		pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
24494291ee30SJoe Perches 			"debugfs is now used for inspecting the device (report descriptor, reports)\n");
2450a635f9ddSJiri Kosina 
245185cdaf52SJiri Slaby 	ret = bus_register(&hid_bus_type);
245285cdaf52SJiri Slaby 	if (ret) {
24534291ee30SJoe Perches 		pr_err("can't register hid bus\n");
245485cdaf52SJiri Slaby 		goto err;
245585cdaf52SJiri Slaby 	}
245685cdaf52SJiri Slaby 
245785cdaf52SJiri Slaby 	ret = hidraw_init();
245885cdaf52SJiri Slaby 	if (ret)
245985cdaf52SJiri Slaby 		goto err_bus;
246085cdaf52SJiri Slaby 
2461a635f9ddSJiri Kosina 	hid_debug_init();
2462a635f9ddSJiri Kosina 
246385cdaf52SJiri Slaby 	return 0;
246485cdaf52SJiri Slaby err_bus:
246585cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
246685cdaf52SJiri Slaby err:
246785cdaf52SJiri Slaby 	return ret;
246886166b7bSJiri Kosina }
246986166b7bSJiri Kosina 
247086166b7bSJiri Kosina static void __exit hid_exit(void)
247186166b7bSJiri Kosina {
2472a635f9ddSJiri Kosina 	hid_debug_exit();
247386166b7bSJiri Kosina 	hidraw_exit();
247485cdaf52SJiri Slaby 	bus_unregister(&hid_bus_type);
247586166b7bSJiri Kosina }
247686166b7bSJiri Kosina 
247786166b7bSJiri Kosina module_init(hid_init);
247886166b7bSJiri Kosina module_exit(hid_exit);
247986166b7bSJiri Kosina 
248088adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal");
248188adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik");
248288adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina");
2483aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
2484aa938f79SJiri Kosina 
2485