hid-core.c revision 99b9f758bbc904f22faffcf4d83205f4a5e7bc0c
1dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
2229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina *  HID support for Linux
3dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *
4dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *  Copyright (c) 1999 Andreas Gal
5dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
77d39e849912f0c3c8c6fc94be7bf7d120b1ee0baJiri Kosina *  Copyright (c) 2006-2010 Jiri Kosina
8dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
9dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
10dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
11dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * This program is free software; you can redistribute it and/or modify it
12dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * under the terms of the GNU General Public License as published by the Free
13dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Software Foundation; either version 2 of the License, or (at your option)
14dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * any later version.
15dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
16dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
17dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/module.h>
18dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/slab.h>
19dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/init.h>
20dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/kernel.h>
21dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/list.h>
22dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/mm.h>
23dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/spinlock.h>
24dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <asm/unaligned.h>
25dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <asm/byteorder.h>
26dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/input.h>
27dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/wait.h>
2847a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina#include <linux/vmalloc.h>
29c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina#include <linux/sched.h>
30dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
31dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/hid.h>
32dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/hiddev.h>
33c080d89ad91e98fec0e8fc5f448a1ad899bd85c7Jiri Kosina#include <linux/hid-debug.h>
3486166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina#include <linux/hidraw.h>
35dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
365f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby#include "hid-ids.h"
375f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby
38dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
39dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Version Information
40dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
41dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
42531498013163c72cee8540e98e12c0c430c7fe87Jiri Kosina#define DRIVER_DESC "HID core driver"
43dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#define DRIVER_LICENSE "GPL"
44dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
4558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosinaint hid_debug = 0;
46377e10fbb4ef219f540d06796e9fb0d3ec35a58fAnssi Hannulamodule_param_named(debug, hid_debug, int, 0600);
47cd667ce24796700e1a0e6e7528efc61c96ff832eJiri KosinaMODULE_PARM_DESC(debug, "toggle HID debugging messages");
4858037eb961f859607b161c50d9d4ecb374de1e8fJiri KosinaEXPORT_SYMBOL_GPL(hid_debug);
4958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina
50dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
51dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new report for a device.
52dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
53dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
5490a006abf8015c8cab893555244d8fc673b24839Michael Poolestruct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
55dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
56dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_report_enum *report_enum = device->report_enum + type;
57dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_report *report;
58dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
59dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (report_enum->report_id_hash[id])
60dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return report_enum->report_id_hash[id];
61dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
62dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
63dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return NULL;
64dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
65dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (id != 0)
66dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		report_enum->numbered = 1;
67dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
68dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report->id = id;
69dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report->type = type;
70dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report->size = 0;
71dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report->device = device;
72dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report_enum->report_id_hash[id] = report;
73dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
74dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	list_add_tail(&report->list, &report_enum->report_list);
75dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
76dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return report;
77dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
7890a006abf8015c8cab893555244d8fc673b24839Michael PooleEXPORT_SYMBOL_GPL(hid_register_report);
79dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
80dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
81dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new field for this report.
82dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
83dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
84dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
85dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
86dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_field *field;
87dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
88dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (report->maxfield == HID_MAX_FIELDS) {
8958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("too many fields in report\n");
90dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return NULL;
91dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
92dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
93dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
94dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		+ values * sizeof(unsigned), GFP_KERNEL))) return NULL;
95dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
96dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->index = report->maxfield++;
97dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report->field[field->index] = field;
98dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->usage = (struct hid_usage *)(field + 1);
99282bfd4cbcc2bbeb1a2cad1f42debd378e0b5ac9Jiri Slaby	field->value = (s32 *)(field->usage + usages);
100dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->report = report;
101dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
102dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return field;
103dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
104dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
105dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
106dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Open a collection. The type/usage is pushed on the stack.
107dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
108dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
109dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int open_collection(struct hid_parser *parser, unsigned type)
110dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
111dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_collection *collection;
112dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned usage;
113dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
114dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	usage = parser->local.usage[0];
115dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
116dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
11758037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("collection stack overflow\n");
118dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return -1;
119dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
120dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
121dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (parser->device->maxcollection == parser->device->collection_size) {
122dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		collection = kmalloc(sizeof(struct hid_collection) *
123dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				parser->device->collection_size * 2, GFP_KERNEL);
124dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (collection == NULL) {
12558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina			dbg_hid("failed to reallocate collection array\n");
126dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return -1;
127dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
128dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		memcpy(collection, parser->device->collection,
129dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			sizeof(struct hid_collection) *
130dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			parser->device->collection_size);
131dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		memset(collection + parser->device->collection_size, 0,
132dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			sizeof(struct hid_collection) *
133dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			parser->device->collection_size);
134dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		kfree(parser->device->collection);
135dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->device->collection = collection;
136dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->device->collection_size *= 2;
137dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
138dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
139dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	parser->collection_stack[parser->collection_stack_ptr++] =
140dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->device->maxcollection;
141dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
142dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	collection = parser->device->collection +
143dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->device->maxcollection++;
144dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	collection->type = type;
145dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	collection->usage = usage;
146dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	collection->level = parser->collection_stack_ptr - 1;
147dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
148dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (type == HID_COLLECTION_APPLICATION)
149dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->device->maxapplication++;
150dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
151dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
152dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
153dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
154dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
155dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Close a collection.
156dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
157dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
158dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int close_collection(struct hid_parser *parser)
159dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
160dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (!parser->collection_stack_ptr) {
16158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("collection stack underflow\n");
162dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return -1;
163dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
164dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	parser->collection_stack_ptr--;
165dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
166dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
167dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
168dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
169dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Climb up the stack, search for the specified collection type
170dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * and return the usage.
171dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
172dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
173dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
174dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
175dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	int n;
176dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
177dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (parser->device->collection[parser->collection_stack[n]].type == type)
178dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return parser->device->collection[parser->collection_stack[n]].usage;
179dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0; /* we know nothing about this usage type */
180dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
181dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
182dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
183dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Add a usage to the temporary parser table.
184dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
185dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
186dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_add_usage(struct hid_parser *parser, unsigned usage)
187dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
188dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (parser->local.usage_index >= HID_MAX_USAGES) {
18958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("usage index exceeded\n");
190dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return -1;
191dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
192dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	parser->local.usage[parser->local.usage_index] = usage;
193dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	parser->local.collection_index[parser->local.usage_index] =
194dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->collection_stack_ptr ?
195dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
196dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	parser->local.usage_index++;
197dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
198dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
199dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
200dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
201dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new field for this report.
202dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
203dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
204dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
205dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
206dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_report *report;
207dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_field *field;
208dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	int usages;
209dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned offset;
210dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	int i;
211dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
212dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
21358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("hid_register_report failed\n");
214dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return -1;
215dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
216dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
217dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (parser->global.logical_maximum < parser->global.logical_minimum) {
21858037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
219dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return -1;
220dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
221dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
222dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	offset = report->size;
223dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report->size += parser->global.report_size * parser->global.report_count;
224dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
225dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (!parser->local.usage_index) /* Ignore padding fields */
226dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return 0;
227dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
228dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	usages = max_t(int, parser->local.usage_index, parser->global.report_count);
229dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
230dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
231dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return 0;
232dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
233dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
234dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
235dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
236dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
237dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (i = 0; i < usages; i++) {
238dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		int j = i;
239dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		/* Duplicate the last usage we parsed if we have excess values */
240dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (i >= parser->local.usage_index)
241dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			j = parser->local.usage_index - 1;
242dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		field->usage[i].hid = parser->local.usage[j];
243dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		field->usage[i].collection_index =
244dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			parser->local.collection_index[j];
245dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
246dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
247dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->maxusage = usages;
248dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->flags = flags;
249dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->report_offset = offset;
250dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->report_type = report_type;
251dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->report_size = parser->global.report_size;
252dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->report_count = parser->global.report_count;
253dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->logical_minimum = parser->global.logical_minimum;
254dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->logical_maximum = parser->global.logical_maximum;
255dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->physical_minimum = parser->global.physical_minimum;
256dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->physical_maximum = parser->global.physical_maximum;
257dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->unit_exponent = parser->global.unit_exponent;
258dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->unit = parser->global.unit;
259dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
260dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
261dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
262dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
263dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
264dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Read data value from item.
265dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
266dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
267dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u32 item_udata(struct hid_item *item)
268dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
269dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (item->size) {
270880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 1: return item->data.u8;
271880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 2: return item->data.u16;
272880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 4: return item->data.u32;
273dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
274dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
275dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
276dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
277dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic s32 item_sdata(struct hid_item *item)
278dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
279dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (item->size) {
280880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 1: return item->data.s8;
281880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 2: return item->data.s16;
282880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 4: return item->data.s32;
283dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
284dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
285dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
286dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
287dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
288dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a global item.
289dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
290dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
291dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
292dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
293dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (item->tag) {
294880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_PUSH:
295dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
296880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
297880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("global enviroment stack overflow\n");
298880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return -1;
299880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
300dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
301880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		memcpy(parser->global_stack + parser->global_stack_ptr++,
302880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			&parser->global, sizeof(struct hid_global));
303880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
304dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
305880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_POP:
306dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
307880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (!parser->global_stack_ptr) {
308880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("global enviroment stack underflow\n");
309880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return -1;
310880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
311dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
312880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		memcpy(&parser->global, parser->global_stack +
313880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			--parser->global_stack_ptr, sizeof(struct hid_global));
314880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
315dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
316880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
317880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.usage_page = item_udata(item);
318880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
319dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
320880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
321880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.logical_minimum = item_sdata(item);
322880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
323dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
324880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
325880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->global.logical_minimum < 0)
326880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->global.logical_maximum = item_sdata(item);
327880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		else
328880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->global.logical_maximum = item_udata(item);
329880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
330dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
331880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
332880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.physical_minimum = item_sdata(item);
333880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
334dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
335880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
336880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->global.physical_minimum < 0)
337880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->global.physical_maximum = item_sdata(item);
338880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		else
339880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->global.physical_maximum = item_udata(item);
340880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
341dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
342880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
343880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.unit_exponent = item_sdata(item);
344880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
345dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
346880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_UNIT:
347880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.unit = item_udata(item);
348880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
349dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
350880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
351880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.report_size = item_udata(item);
352880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->global.report_size > 32) {
353880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("invalid report_size %d\n",
354880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby					parser->global.report_size);
355880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return -1;
356880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
357880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
358dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
359880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
360880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.report_count = item_udata(item);
361880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->global.report_count > HID_MAX_USAGES) {
362880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("invalid report_count %d\n",
363880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby					parser->global.report_count);
364880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return -1;
365880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
366880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
367dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
368880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_GLOBAL_ITEM_TAG_REPORT_ID:
369880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->global.report_id = item_udata(item);
370880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->global.report_id == 0) {
371880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("report_id 0 is invalid\n");
372dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return -1;
373880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
374880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
375880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby
376880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	default:
377880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		dbg_hid("unknown global tag 0x%x\n", item->tag);
378880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return -1;
379dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
380dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
381dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
382dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
383dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a local item.
384dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
385dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
386dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
387dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
388dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	__u32 data;
389dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned n;
390dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
391dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	data = item_udata(item);
392dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
393dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (item->tag) {
394880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_LOCAL_ITEM_TAG_DELIMITER:
395880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby
396880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (data) {
397880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			/*
398880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			 * We treat items before the first delimiter
399880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			 * as global to all usage sets (branch 0).
400880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			 * In the moment we process only these global
401880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			 * items and the first delimiter set.
402880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			 */
403880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			if (parser->local.delimiter_depth != 0) {
404880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby				dbg_hid("nested delimiters\n");
405880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby				return -1;
406dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			}
407880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->local.delimiter_depth++;
408880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->local.delimiter_branch++;
409880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		} else {
410880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			if (parser->local.delimiter_depth < 1) {
411880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby				dbg_hid("bogus close delimiter\n");
412880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby				return -1;
413dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			}
414880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			parser->local.delimiter_depth--;
415880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
416880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 1;
417dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
418880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_LOCAL_ITEM_TAG_USAGE:
419dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
420880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->local.delimiter_branch > 1) {
421880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("alternative usage ignored\n");
422880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return 0;
423880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
424dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
425880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (item->size <= 2)
426880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			data = (parser->global.usage_page << 16) + data;
427dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
428880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return hid_add_usage(parser, data);
429dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
430880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
431dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
432880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->local.delimiter_branch > 1) {
433880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("alternative usage ignored\n");
434dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return 0;
435880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
436dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
437880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (item->size <= 2)
438880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			data = (parser->global.usage_page << 16) + data;
439dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
440880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		parser->local.usage_minimum = data;
441880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
442dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
443880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
444dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
445880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (parser->local.delimiter_branch > 1) {
446880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			dbg_hid("alternative usage ignored\n");
447dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return 0;
448880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		}
449dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
450880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if (item->size <= 2)
451880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			data = (parser->global.usage_page << 16) + data;
452dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
453880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		for (n = parser->local.usage_minimum; n <= data; n++)
454880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			if (hid_add_usage(parser, n)) {
455880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby				dbg_hid("hid_add_usage failed\n");
456880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby				return -1;
457880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			}
458880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
459880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby
460880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	default:
461880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby
462880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		dbg_hid("unknown local item tag 0x%x\n", item->tag);
463880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return 0;
464dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
465dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
466dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
467dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
468dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
469dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a main item.
470dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
471dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
472dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
473dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
474dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	__u32 data;
475dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	int ret;
476dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
477dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	data = item_udata(item);
478dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
479dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (item->tag) {
480880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
481880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		ret = open_collection(parser, data & 0xff);
482880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		break;
483880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_MAIN_ITEM_TAG_END_COLLECTION:
484880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		ret = close_collection(parser);
485880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		break;
486880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_MAIN_ITEM_TAG_INPUT:
487880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		ret = hid_add_field(parser, HID_INPUT_REPORT, data);
488880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		break;
489880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_MAIN_ITEM_TAG_OUTPUT:
490880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
491880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		break;
492880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case HID_MAIN_ITEM_TAG_FEATURE:
493880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
494880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		break;
495880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	default:
496880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		dbg_hid("unknown main item tag 0x%x\n", item->tag);
497880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		ret = 0;
498dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
499dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
500dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	memset(&parser->local, 0, sizeof(parser->local));	/* Reset the local parser environment */
501dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
502dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return ret;
503dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
504dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
505dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
506dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a reserved item.
507dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
508dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
509dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
510dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
51158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina	dbg_hid("reserved item type, tag 0x%x\n", item->tag);
512dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
513dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
514dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
515dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
516dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Free a report and all registered fields. The field->usage and
517dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * field->value table's are allocated behind the field, so we need
518dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * only to free(field) itself.
519dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
520dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
521dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic void hid_free_report(struct hid_report *report)
522dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
523dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned n;
524dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
525dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (n = 0; n < report->maxfield; n++)
526dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		kfree(report->field[n]);
527dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	kfree(report);
528dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
529dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
530dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
531dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Free a device structure, all reports, and all fields.
532dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
533dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
53485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_device_release(struct device *dev)
535dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
53685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_device *device = container_of(dev, struct hid_device, dev);
53785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	unsigned i, j;
538dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
539dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (i = 0; i < HID_REPORT_TYPES; i++) {
540dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		struct hid_report_enum *report_enum = device->report_enum + i;
541dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
542dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		for (j = 0; j < 256; j++) {
543dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			struct hid_report *report = report_enum->report_id_hash[j];
544dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			if (report)
545dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				hid_free_report(report);
546dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
547dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
548dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
549dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	kfree(device->rdesc);
550767fe7877c2928b5633992ee60a49ad4516dc2afJiri Kosina	kfree(device->collection);
551dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	kfree(device);
552dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
553dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
554dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
555dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Fetch a report description item from the data stream. We support long
556dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * items, though they are not used yet.
557dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
558dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
559dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
560dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
561dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	u8 b;
562dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
563dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if ((end - start) <= 0)
564dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return NULL;
565dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
566dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	b = *start++;
567dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
568dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	item->type = (b >> 2) & 3;
569dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	item->tag  = (b >> 4) & 15;
570dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
571dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (item->tag == HID_ITEM_TAG_LONG) {
572dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
573dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		item->format = HID_ITEM_FORMAT_LONG;
574dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
575dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if ((end - start) < 2)
576dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return NULL;
577dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
578dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		item->size = *start++;
579dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		item->tag  = *start++;
580dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
581dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if ((end - start) < item->size)
582dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return NULL;
583dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
584dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		item->data.longdata = start;
585dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		start += item->size;
586dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return start;
587dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
588dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
589dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	item->format = HID_ITEM_FORMAT_SHORT;
590dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	item->size = b & 3;
591dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
592dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (item->size) {
593880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 0:
594880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return start;
595dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
596880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 1:
597880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if ((end - start) < 1)
598880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return NULL;
599880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		item->data.u8 = *start++;
600880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return start;
601880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby
602880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 2:
603880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if ((end - start) < 2)
604880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return NULL;
605880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		item->data.u16 = get_unaligned_le16(start);
606880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		start = (__u8 *)((__le16 *)start + 1);
607880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return start;
608880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby
609880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 3:
610880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		item->size++;
611880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		if ((end - start) < 4)
612880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby			return NULL;
613880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		item->data.u32 = get_unaligned_le32(start);
614880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		start = (__u8 *)((__le32 *)start + 1);
615880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby		return start;
616dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
617dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
618dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return NULL;
619dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
620dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
62185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/**
62285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_parse_report - parse device report
62385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
62485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @device: hid device
62585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @start: report start
62685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @size: report size
62785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
628dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Parse a report description into a hid_device structure. Reports are
629dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * enumerated, fields are attached to these reports.
63085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 0 returned on success, otherwise nonzero error value.
631dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
63285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_parse_report(struct hid_device *device, __u8 *start,
63385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		unsigned size)
634dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
635dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_parser *parser;
636dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	struct hid_item item;
637dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	__u8 *end;
63885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret;
639dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	static int (*dispatch_type[])(struct hid_parser *parser,
640dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				      struct hid_item *item) = {
641dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		hid_parser_main,
642dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		hid_parser_global,
643dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		hid_parser_local,
644dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		hid_parser_reserved
645dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	};
646dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
647c500c9714011edab021591340042787722db9cf0Jiri Slaby	if (device->driver->report_fixup)
64873e4008ddddc84d5f2499c17012b340a0dae153eNikolai Kondrashov		start = device->driver->report_fixup(device, start, &size);
649c500c9714011edab021591340042787722db9cf0Jiri Slaby
6501721a238ba5df9e870ed952464d38714261f5be9Julia Lawall	device->rdesc = kmemdup(start, size, GFP_KERNEL);
65185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (device->rdesc == NULL)
65285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENOMEM;
653dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	device->rsize = size;
654dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
65585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	parser = vmalloc(sizeof(struct hid_parser));
65685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!parser) {
65785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		ret = -ENOMEM;
65885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		goto err;
659dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
66085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
66147a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina	memset(parser, 0, sizeof(struct hid_parser));
662dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	parser->device = device;
663dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
664dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	end = start + size;
66585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	ret = -EINVAL;
666dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	while ((start = fetch_item(start, end, &item)) != NULL) {
667dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
668dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (item.format != HID_ITEM_FORMAT_SHORT) {
66958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina			dbg_hid("unexpected long global item\n");
67085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			goto err;
671dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
672dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
673dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (dispatch_type[item.type](parser, &item)) {
67458037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina			dbg_hid("item %u %u %u %u parsing failed\n",
675dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
67685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			goto err;
677dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
678dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
679dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (start == end) {
680dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			if (parser->collection_stack_ptr) {
68158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina				dbg_hid("unbalanced collection at end of report description\n");
68285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				goto err;
683dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			}
684dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			if (parser->local.delimiter_depth) {
68558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina				dbg_hid("unbalanced delimiter at end of report description\n");
68685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				goto err;
687dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			}
68847a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina			vfree(parser);
68985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			return 0;
690dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
691dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
692dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
69358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina	dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
69485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr:
69547a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina	vfree(parser);
69685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return ret;
697dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
698229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_parse_report);
699dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
700dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
701dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Convert a signed n-bit integer to signed 32-bit integer. Common
702dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * cases are done through the compiler, the screwed things has to be
703dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * done by hand.
704dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
705dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
706dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic s32 snto32(__u32 value, unsigned n)
707dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
708dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	switch (n) {
709880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 8:  return ((__s8)value);
710880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 16: return ((__s16)value);
711880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby	case 32: return ((__s32)value);
712dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
713dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return value & (1 << (n - 1)) ? value | (-1 << n) : value;
714dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
715dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
716dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
717dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Convert a signed 32-bit integer to a signed n-bit integer.
718dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
719dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
720dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u32 s32ton(__s32 value, unsigned n)
721dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
722dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	s32 a = value >> (n - 1);
723dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (a && a != -1)
724dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
725dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return value & ((1 << n) - 1);
726dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
727dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
728dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
729dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Extract/implement a data field from/to a little endian report (bit array).
730dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *
731dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Code sort-of follows HID spec:
732dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *     http://www.usb.org/developers/devclass_docs/HID1_11.pdf
733dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *
734dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * While the USB HID spec allows unlimited length bit fields in "report
735dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * descriptors", most devices never use more than 16 bits.
736dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * One model of UPS is claimed to report "LINEV" as a 32-bit field.
737dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
738dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
739dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
740dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
741dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
742dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	u64 x;
743dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
744c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina	if (n > 32)
745c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina		printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n",
746c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina				n, current->comm);
747dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
748dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report += offset >> 3;  /* adjust byte index */
749229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina	offset &= 7;            /* now only need bit offset into one byte */
750c105068f2b35343eecf2bf16ee29a362b6121fa3Harvey Harrison	x = get_unaligned_le64(report);
751229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina	x = (x >> offset) & ((1ULL << n) - 1);  /* extract bit field */
752dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return (u32) x;
753dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
754dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
755dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
756dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * "implement" : set bits in a little endian bit stream.
757dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Same concepts as "extract" (see comments above).
758dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * The data mangled in the bit stream remains in little endian
759dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * order the whole time. It make more sense to talk about
760dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * endianness of register values by considering a register
761dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * a "cached" copy of the little endiad bit stream.
762dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
763dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
764dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
7656f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison	u64 x;
766dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	u64 m = (1ULL << n) - 1;
767dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
768c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina	if (n > 32)
769c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina		printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n",
770c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina				n, current->comm);
771dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
772c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina	if (value > m)
773c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina		printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n",
774c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina				value, current->comm);
775dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	WARN_ON(value > m);
776dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	value &= m;
777dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
778dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	report += offset >> 3;
779dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	offset &= 7;
780dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
7816f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison	x = get_unaligned_le64(report);
7826f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison	x &= ~(m << offset);
7836f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison	x |= ((u64)value) << offset;
7846f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison	put_unaligned_le64(x, report);
785dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
786dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
787dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
788dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Search an array for a value.
789dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
790dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
791dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic __inline__ int search(__s32 *array, __s32 value, unsigned n)
792dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
793dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	while (n--) {
794dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (*array++ == value)
795dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return 0;
796dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
797dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return -1;
798dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
799dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
80085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/**
80185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_match_report - check if driver's raw_event should be called
80285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
80385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device
80485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @report_type: type to match against
80585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
80685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * compare hid->driver->report_table->report_type to report->type
80785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */
80885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_match_report(struct hid_device *hid, struct hid_report *report)
809dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
81085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	const struct hid_report_id *id = hid->driver->report_table;
81185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
81285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!id) /* NULL means all */
81385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return 1;
81485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
81585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	for (; id->report_type != HID_TERMINATOR; id++)
81685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		if (id->report_type == HID_ANY_ID ||
81785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				id->report_type == report->type)
81885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			return 1;
81985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return 0;
82085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
82185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
82285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/**
82385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_match_usage - check if driver's event should be called
82485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
82585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device
82685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @usage: usage to match against
82785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
82885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * compare hid->driver->usage_table->usage_{type,code} to
82985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * usage->usage_{type,code}
83085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */
83185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
83285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
83385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	const struct hid_usage_id *id = hid->driver->usage_table;
83485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
83585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!id) /* NULL means all */
83685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return 1;
83785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
83885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	for (; id->usage_type != HID_ANY_ID - 1; id++)
83985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		if ((id->usage_hid == HID_ANY_ID ||
84085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				id->usage_hid == usage->hid) &&
84185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				(id->usage_type == HID_ANY_ID ||
84285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				id->usage_type == usage->type) &&
84385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				(id->usage_code == HID_ANY_ID ||
84485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				 id->usage_code == usage->code))
84585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			return 1;
84685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return 0;
84785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
84885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
84985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_process_event(struct hid_device *hid, struct hid_field *field,
85085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		struct hid_usage *usage, __s32 value, int interrupt)
85185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
85285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_driver *hdrv = hid->driver;
85385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret;
85485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
855cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	hid_dump_input(hid, usage, value);
85685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
85785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
85885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		ret = hdrv->event(hid, field, usage, value);
85985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		if (ret != 0) {
86085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			if (ret < 0)
86185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				dbg_hid("%s's event failed with %d\n",
86285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby						hdrv->name, ret);
86385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			return;
86485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		}
86585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
86685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
867dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (hid->claimed & HID_CLAIMED_INPUT)
868dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		hidinput_hid_event(hid, field, usage, value);
869aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina	if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
870aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina		hid->hiddev_hid_event(hid, field, usage, value);
871dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
872dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
873dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
874dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Analyse a received field, and fetch the data from it. The field
875dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * content is stored for next report processing (we do differential
876dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * reporting to the layer).
877dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
878dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
879abdff0f7749a6696ba2a4238b675cbc55abcdb7aAdrian Bunkstatic void hid_input_field(struct hid_device *hid, struct hid_field *field,
880abdff0f7749a6696ba2a4238b675cbc55abcdb7aAdrian Bunk			    __u8 *data, int interrupt)
881dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
882dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned n;
883dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned count = field->report_count;
884dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned offset = field->report_offset;
885dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned size = field->report_size;
886dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	__s32 min = field->logical_minimum;
887dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	__s32 max = field->logical_maximum;
888dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	__s32 *value;
889dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
890dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
891dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return;
892dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
893dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (n = 0; n < count; n++) {
894dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
895dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
896dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina						    extract(data, offset + n * size, size);
897dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
898dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
899dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			    && value[n] >= min && value[n] <= max
900dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			    && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
901dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				goto exit;
902dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
903dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
904dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (n = 0; n < count; n++) {
905dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
906dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (HID_MAIN_ITEM_VARIABLE & field->flags) {
907dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
908dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			continue;
909dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
910dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
911dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (field->value[n] >= min && field->value[n] <= max
912dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			&& field->usage[field->value[n] - min].hid
913dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			&& search(value, field->value[n], count))
914dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
915dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
916dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (value[n] >= min && value[n] <= max
917dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			&& field->usage[value[n] - min].hid
918dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			&& search(field->value, value[n], count))
919dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina				hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
920dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
921dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
922dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	memcpy(field->value, value, count * sizeof(__s32));
923dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinaexit:
924dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	kfree(value);
925dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
926dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
927dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
928dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Output the field into the report.
929dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
930dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
931dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic void hid_output_field(struct hid_field *field, __u8 *data)
932dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
933dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned count = field->report_count;
934dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned offset = field->report_offset;
935dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned size = field->report_size;
936dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned n;
937dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
938dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (n = 0; n < count; n++) {
939dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (field->logical_minimum < 0)	/* signed values */
940dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			implement(data, offset + n * size, size, s32ton(field->value[n], size));
941dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		else				/* unsigned values */
942dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			implement(data, offset + n * size, size, field->value[n]);
943dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
944dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
945dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
946dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
947dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Create a report.
948dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
949dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
950229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosinavoid hid_output_report(struct hid_report *report, __u8 *data)
951dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
952dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned n;
953dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
954dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (report->id > 0)
955dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		*data++ = report->id;
956dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
95775c28df87eb6d8e1389af67f26fbe2394e28385ePete Zaitcev	memset(data, 0, ((report->size - 1) >> 3) + 1);
958dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	for (n = 0; n < report->maxfield; n++)
959dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		hid_output_field(report->field[n], data);
960dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
961229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_output_report);
962dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
963dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/*
964dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Set a field value. The report this field belongs to has to be
965dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * created and transferred to the device, to set this value in the
966dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * device.
967dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */
968dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
969dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinaint hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
970dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{
971dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	unsigned size = field->report_size;
972dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
973cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	hid_dump_input(field->report->device, field->usage + offset, value);
974dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
975dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (offset >= field->report_count) {
97658037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina		dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
977dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		return -1;
978dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
979dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	if (field->logical_minimum < 0) {
980dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		if (value != snto32(s32ton(value, size), size)) {
98158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina			dbg_hid("value %d is out of range\n", value);
982dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina			return -1;
983dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina		}
984dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	}
985dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	field->value[offset] = value;
986dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina	return 0;
987dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina}
988229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_set_field);
989dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina
99085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
99185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		const u8 *data)
992aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina{
993aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	struct hid_report *report;
99485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	unsigned int n = 0;	/* Normally report number is 0 */
995aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
99685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	/* Device uses numbered reports, data[0] is report number */
99785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (report_enum->numbered)
99885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		n = *data;
999aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
100085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	report = report_enum->report_id_hash[n];
100185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (report == NULL)
100285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		dbg_hid("undefined report_id %u received\n", n);
1003aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
100485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return report;
100585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
1006aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
100785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
100885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		int interrupt)
100985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
101085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_report_enum *report_enum = hid->report_enum + type;
101185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_report *report;
101285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	unsigned int a;
101385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int rsize, csize = size;
101485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	u8 *cdata = data;
1015aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
101685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	report = hid_get_report(report_enum, data);
101785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!report)
101885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return;
1019aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
102085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (report_enum->numbered) {
102185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		cdata++;
102285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		csize--;
1023aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	}
1024aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
1025aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	rsize = ((report->size - 1) >> 3) + 1;
1026aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
102785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (csize < rsize) {
102885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		dbg_hid("report %d is too short, (%d < %d)\n", report->id,
102985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby				csize, rsize);
103085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		memset(cdata + csize, 0, rsize - csize);
1031aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	}
1032aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
1033aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1034aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina		hid->hiddev_report_event(hid, report);
10355a38f2c7c4dd53d5be097930902c108e362584a3Alan Ott	if (hid->claimed & HID_CLAIMED_HIDRAW)
10365a38f2c7c4dd53d5be097930902c108e362584a3Alan Ott		hidraw_report_event(hid, data, size);
1037aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
103885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	for (a = 0; a < report->maxfield; a++)
103985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		hid_input_field(hid, report->field[a], cdata, interrupt);
1040aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
1041aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	if (hid->claimed & HID_CLAIMED_INPUT)
1042aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina		hidinput_report_event(hid, report);
104385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
104485cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_report_raw_event);
104585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
104685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/**
104785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_input_report - report data from lower layer (usb, bt...)
104885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
104985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device
105085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @type: HID report type (HID_*_REPORT)
105185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @data: report contents
105285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @size: size of data parameter
1053ff9b00a226ccea66e6ce70e9083c42f5b6001f73Jiri Kosina * @interrupt: distinguish between interrupt and control transfers
105485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
105585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * This is data entry for lower layers.
105685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */
105785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
105885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
105976c317d6e5cb7f58541879006d39774596962715Julia Lawall	struct hid_report_enum *report_enum;
106076c317d6e5cb7f58541879006d39774596962715Julia Lawall	struct hid_driver *hdrv;
106185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_report *report;
1062cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	char *buf;
106385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	unsigned int i;
106485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret;
106585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
106685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!hid || !hid->driver)
106785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENODEV;
106876c317d6e5cb7f58541879006d39774596962715Julia Lawall	report_enum = hid->report_enum + type;
106976c317d6e5cb7f58541879006d39774596962715Julia Lawall	hdrv = hid->driver;
107085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
107185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!size) {
107285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		dbg_hid("empty report\n");
107385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -1;
107485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
107585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1076d1ff65226c5afe55f9af38a439058f41b71e114fJiri Kosina	buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
1077cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina
1078f77e347bd44e3640bdc56003b7402c63ddb1241dJiri Kosina	if (!buf)
1079cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina		goto nomem;
108085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
108185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	/* dump the report */
1082cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	snprintf(buf, HID_DEBUG_BUFSIZE - 1,
10831caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina			"\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
1084cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	hid_debug_event(hid, buf);
10851caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina
1086cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	for (i = 0; i < size; i++) {
1087cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina		snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1088cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina				" %02x", data[i]);
1089cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina		hid_debug_event(hid, buf);
1090cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	}
1091cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	hid_debug_event(hid, "\n");
1092cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	kfree(buf);
109385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1094cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosinanomem:
10951caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina	report = hid_get_report(report_enum, data);
10961caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina
1097f77e347bd44e3640bdc56003b7402c63ddb1241dJiri Kosina	if (!report)
10981caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina		return -1;
109985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
110085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
110185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		ret = hdrv->raw_event(hid, report, data, size);
110285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		if (ret != 0)
110385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			return ret < 0 ? ret : 0;
110485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
110585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
110685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hid_report_raw_event(hid, type, data, size, interrupt);
1107aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
1108aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina	return 0;
1109aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina}
1110aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri KosinaEXPORT_SYMBOL_GPL(hid_input_report);
1111aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina
11120f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic bool hid_match_one_id(struct hid_device *hdev,
11130f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina		const struct hid_device_id *id)
11140f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{
11150f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina	return id->bus == hdev->bus &&
11160f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina		(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
11170f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina		(id->product == HID_ANY_ID || id->product == hdev->product);
11180f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina}
11190f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina
11200f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic const struct hid_device_id *hid_match_id(struct hid_device *hdev,
11210f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina		const struct hid_device_id *id)
11220f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{
11230f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina	for (; id->bus; id++)
11240f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina		if (hid_match_one_id(hdev, id))
11250f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina			return id;
11260f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina
11270f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina	return NULL;
11280f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina}
11290f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina
11300f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic const struct hid_device_id hid_hiddev_list[] = {
1131c0bd6a429819f794f626f9e73be4564e18e132dbRichard Hughes	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1132c0bd6a429819f794f626f9e73be4564e18e132dbRichard Hughes	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
11330f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina	{ }
11340f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina};
11350f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina
11360f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic bool hid_hiddev(struct hid_device *hdev)
11370f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{
11380f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina	return !!hid_match_id(hdev, hid_hiddev_list);
11390f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina}
11400f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina
114193c10132a7ac160df3175b53f7ee857625412165Jiri Slabyint hid_connect(struct hid_device *hdev, unsigned int connect_mask)
114293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby{
114393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
114493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		"Joystick", "Gamepad", "Keyboard", "Keypad",
114593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		"Multi-Axis Controller"
114693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	};
114793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	const char *type, *bus;
114893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	char buf[64];
114993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	unsigned int i;
115093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	int len;
115193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
1152b5e5a37e36cd4d355b875665312d7aaae4e5833cBastien Nocera	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1153b5e5a37e36cd4d355b875665312d7aaae4e5833cBastien Nocera		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
11543a343ee4509c982552b35fbc99d3213f3bb1acdeDaniel Mack	if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
11553a343ee4509c982552b35fbc99d3213f3bb1acdeDaniel Mack		connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
115693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if (hdev->bus != BUS_USB)
115793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		connect_mask &= ~HID_CONNECT_HIDDEV;
11580f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina	if (hid_hiddev(hdev))
11590f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina		connect_mask |= HID_CONNECT_HIDDEV_FORCE;
116093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
116193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
116293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby				connect_mask & HID_CONNECT_HIDINPUT_FORCE))
116393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		hdev->claimed |= HID_CLAIMED_INPUT;
116493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
116593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby			!hdev->hiddev_connect(hdev,
116693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby				connect_mask & HID_CONNECT_HIDDEV_FORCE))
116793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		hdev->claimed |= HID_CLAIMED_HIDDEV;
116893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
116993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		hdev->claimed |= HID_CLAIMED_HIDRAW;
117093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
117193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if (!hdev->claimed) {
117293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
117393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby				"hidraw\n");
117493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		return -ENODEV;
117593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	}
117693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
117793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if ((hdev->claimed & HID_CLAIMED_INPUT) &&
117893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby			(connect_mask & HID_CONNECT_FF) && hdev->ff_init)
117993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		hdev->ff_init(hdev);
118093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
118193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	len = 0;
118293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if (hdev->claimed & HID_CLAIMED_INPUT)
118393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		len += sprintf(buf + len, "input");
118493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if (hdev->claimed & HID_CLAIMED_HIDDEV)
118593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
118693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby				hdev->minor);
118793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	if (hdev->claimed & HID_CLAIMED_HIDRAW)
118893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
118993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby				((struct hidraw *)hdev->hidraw)->minor);
119093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
119193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	type = "Device";
119293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	for (i = 0; i < hdev->maxcollection; i++) {
119393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		struct hid_collection *col = &hdev->collection[i];
119493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		if (col->type == HID_COLLECTION_APPLICATION &&
119593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		   (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
119693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		   (col->usage & 0xffff) < ARRAY_SIZE(types)) {
119793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby			type = types[col->usage & 0xffff];
119893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby			break;
119993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		}
120093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	}
120193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
120293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	switch (hdev->bus) {
120393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	case BUS_USB:
120493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		bus = "USB";
120593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		break;
120693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	case BUS_BLUETOOTH:
120793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		bus = "BLUETOOTH";
120893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		break;
120993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	default:
121093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby		bus = "<UNKNOWN>";
121193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	}
121293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
121393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
121493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby			buf, bus, hdev->version >> 8, hdev->version & 0xff,
121593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby			type, hdev->name, hdev->phys);
121693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
121793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby	return 0;
121893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby}
121993c10132a7ac160df3175b53f7ee857625412165Jiri SlabyEXPORT_SYMBOL_GPL(hid_connect);
122093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby
1221c4c259bcc27c4242b012106afdba183622b1735fJiri Kosinavoid hid_disconnect(struct hid_device *hdev)
1222c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina{
1223c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina	if (hdev->claimed & HID_CLAIMED_INPUT)
1224c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina		hidinput_disconnect(hdev);
1225c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina	if (hdev->claimed & HID_CLAIMED_HIDDEV)
1226c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina		hdev->hiddev_disconnect(hdev);
1227c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina	if (hdev->claimed & HID_CLAIMED_HIDRAW)
1228c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina		hidraw_disconnect(hdev);
1229c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina}
1230c4c259bcc27c4242b012106afdba183622b1735fJiri KosinaEXPORT_SYMBOL_GPL(hid_disconnect);
1231c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina
1232bae7eb33b25387fdc7ccae08768bef1f9484a5b0Jiri Kosina/* a list of devices for which there is a specialized driver on HID bus */
123385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic const struct hid_device_id hid_blacklist[] = {
1234b6353f4f36f03a12edaf3fa5365b475a28106035Stephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
12356dec143a50c01ca0cc0afcbf5ea4bb8e87981edfStephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
123614a21cd459f97e3b3cc4fcde48fc5bcdb81d097eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
123714a21cd459f97e3b3cc4fcde48fc5bcdb81d097eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1238b7e1b2039de3a028fba46fbaca58a45c23a417ecLech Perczak	{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
1239c0dbcc33c652a0646542560de29a1c3f1ab7169fSergei Kolzun#if defined(CONFIG_HID_ACRUX_FF) || defined(CONFIG_HID_ACRUX_FF_MODULE)
1240c0dbcc33c652a0646542560de29a1c3f1ab7169fSergei Kolzun	{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1241c0dbcc33c652a0646542560de29a1c3f1ab7169fSergei Kolzun#endif
1242df9bcace7b1c29e9be1c13b034ff04f4f4c90edeJiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
12438c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
12448c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1245128537cea464d919febeaea2000e256749f317ebMichael Poole	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1246a462230e16acc8664145216da3c928d03556691aChase Douglas	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
12478c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
12488c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
12498c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
12508c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
12518c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
12528c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
12538c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
12548c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
12558c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
12568c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
12578c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1258fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1259fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1260fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
12618c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
12628c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
12638c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
12648c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
12658c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
12668c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1267ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1268ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1269ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
12708c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
12718c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
12728c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
12738c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
12748c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
12758c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1276a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1277a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1278a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
127999b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
128099b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
128199b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
128299b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
128399b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
128499b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
128523aeb61e7e1f02fb0f3b8f9e798e75537ca1731dChristian Schuerer-Waldheim	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
128623aeb61e7e1f02fb0f3b8f9e798e75537ca1731dChristian Schuerer-Waldheim	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
128723aeb61e7e1f02fb0f3b8f9e798e75537ca1731dChristian Schuerer-Waldheim	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
12888c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
12898c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1290eaca1386207a9e0314647d3a88967acb17cc30e3Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1291cec15a0ece19116b6c2c53fedf9696c20124d491Roland Baum	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1292b5635b129b3ca3a9c879a36f58f5b8c4903d267aJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1293bf280628fca93c4c341587ec914863dcc395af72Wayne Thomas	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1294c3dc66de59531c921c4638b1285075ea1c831186Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
129536213e1e40fb863e2e8ef607b2958504b48f6b8eStephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1296ba4d8abb31def963f49b7c239a8acce57fe1d1ccStephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1297272036edb77e5967c175ac48b8c88e9b3358285fFrançois Jaouen	{ HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
12983b239cd739a9499da08326356add3d9d992c7911Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
12991ce31b255cf8b06470dfbd469055b6fd8d2274bcRaphaël Doursenaud	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1300fcfacfd3594d5d2fa99fb5e7d33dee3904b1a156Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
13013a370ca1dcf8c80aff7a0a21d6b0f50ca2a151e9Don Prince	{ HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
13020f2213208f8da51bcb665309e3468f000489c04fJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
13030f2213208f8da51bcb665309e3468f000489c04fJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1304e8d0eab4d9eda9f5e97852f780f020bfb134f9f0Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
13050f2213208f8da51bcb665309e3468f000489c04fJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
13063f866fbd52d1863db5c07700e560aef22c4fdc01Richard Walmsley	{ HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
13070c3910c255d3f9caeef4ebad5d5a1156a2d33f69Stephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
130883e4491818040ae6b2d9fc60434616304a101d39Chris Ball	{ HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
130964b386ea16112564e0b93473e2c347125effb6b2Richard Nauber	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
131004561c5aa243c98cae93cde27e05740df787e692Ignaz Forster	{ HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
13111f243e302cea1561ac881eb5d27041c5342beba4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
13125181e594512faeac7d7fd9620ce91105f45bf643Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1313578f3a35fecabff49bad808c5301313f785b5462Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
13145181e594512faeac7d7fd9620ce91105f45bf643Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
131542859e0bd21daba9974757fcfe4a4dde265fe28dLukasz Lubojanski	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
1316949f8fef77186c7361d22e1ea6f42c76ceda42b0Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
13171e093206734568e780c2717da1c89b97e9471954Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1318c2fd1a4ebf9127c280d227acb635eb1df213439cCory Maccarrone	{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1319fdf93aa33268889e126aa677f2072238bd76adb0Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1320794227415f8f5f395a9ed4269a4ee7a3c34f66a5Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1321b5635b129b3ca3a9c879a36f58f5b8c4903d267aJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
13225f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
13235f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
13245f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
13255f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
13265f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
13275f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
13285f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
13295f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
13305f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
13315f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
13325f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
13332c6118e43040034d80894daeba41960bf0035b31Hendrik Iben	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
1334606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1335606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1336606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1337fd30ea8c871552ddd6a5e1c0886de8fef4df53bcJiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1338606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
133974f292ca8c7a2b9370f80d97a49e48174f4c7635Gary Stein	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1340606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1341606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1342243b706d8a71364ad6080328d45b73516c8af5f3Christophe Borivant	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
134332c88cbc3080f43c429f6456aa9cd845e37f3778Simon Wood	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
1344606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
134524985cf68612a5617d396b0b188cec807641cde1Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
134624985cf68612a5617d396b0b188cec807641cde1Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
1347236db47c2b3b69464d50c695ab2ddd516cf64520Bruno Prémont	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1348236db47c2b3b69464d50c695ab2ddd516cf64520Bruno Prémont	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
134978a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
135078a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
135178a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
135278a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
135378a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
13543b8006e51038ef263a0404756d9e190c9a9f74d5Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
135594011f93f2cd7410401e22390cf7a14fe5495a22Rafi Rubin	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
13566e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
13576e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
13586e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
13596e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
13606e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
13616e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
13626e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
13636e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
13646e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
13656e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
13666e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
13676e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
13686e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
13696e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
13706e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
13716e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
13726e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
13736e32819e12ffbd507eced11a1871700a387d5407micki	{ HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
1374cd9ec30da58bcd8ab154eba9eb54d16c67e7ef3bJohnathon Harris	{ HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
13751e76253220dbe66e048e55680266dd1f4af0be85Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
137649e4739a0cf681cbfe08c72232c1dcc130b66ddeStephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1377f54405db66fbec11679241daefd16fd8291a5762Alex Neblett	{ HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
137814bf62cde79423a02a590e02664ed29a36facec1Stefan Achatz	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1379cb7cf3da0daa9830e00640da8f7d2380f4b4de42Stefan Achatz	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
1380980a3da6acdd577ee3ae192e868dc52fe4b7f2e5Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1381b355850ba383232d4e0e357c1cda8cb7bfcc60bcDon Prince	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
1382bd28ce008bdc68ef5902f68d2d62cbb7fa78c415Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1383f9ce7c283c16538955d5d094101889792bcde109Bastien Nocera	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1384cc6e0bbb47f02fd36cd55b3189c0c79079096ab8Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1385d3fb5454a8474d5d22c8f8fe4d043b05732d91d5Stephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1386b6dc79929fa18a97bbc08400db72405ad835622fPascal Auriel - Stantum	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1387b6dc79929fa18a97bbc08400db72405ad835622fPascal Auriel - Stantum	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
138890231e7eaf752856a2c13f786f36ec7f641bad28Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1389daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1390daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
13917a84b1336a145d683fb8cdfd6c2c67545a58b126Ruben Aos Garralda	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
13927a84b1336a145d683fb8cdfd6c2c67545a58b126Ruben Aos Garralda	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
1393daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
13943ee8f0a2b1c81f0472b25d40aa5c1c7c6a0edc2aMarkus Rathgeb	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
1395daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1396f14f526d02b14fd0b8c1ac4ec413e4577ad5f62eLev Babiev	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
1397540010812179a16d3d00fb8363bb06ee83af25b8Kees Bakker	{ HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
1398711a680e35059bc5c7c28d3c4bd0bebd3b7bb6eeBruno Premont	{ HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
139941fa92302be7fa37c5c38e17e2097d3e5e9da13aNikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
1400f8a489cc5f7adafa9f1420279be793de0fba481cNikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1401f8a489cc5f7adafa9f1420279be793de0fba481cNikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1402f8a489cc5f7adafa9f1420279be793de0fba481cNikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
1403fac733f029251a393c42a8313432f2d9fe43bb83Jussi Kivilinna	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
1404ca2dcd40f54c8928b3994712a6cadd2078a087faBastien Nocera	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
140572a46344867111c3e019b169ddfa9e1a1f55c759Nikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
140600e7f9649b3061281fe4b463263da26155dc9be4Nikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
140772a46344867111c3e019b169ddfa9e1a1f55c759Nikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
14088f1acc32bbdb1784bcb0be98fb02f4b20e6f328fNikolai Kondrashov	{ HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1409daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1410daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula	{ HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1411a9885c8f7bf62e251fc178f838b9f0ee897c158aDon Prince	{ HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
14128c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby
141378a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
141485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	{ }
141585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby};
141685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
14173a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystruct hid_dynid {
14183a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	struct list_head list;
14193a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	struct hid_device_id id;
14203a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby};
14213a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14223a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby/**
14233a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * store_new_id - add a new HID device ID to this driver and re-probe devices
14243a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @driver: target device driver
14253a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @buf: buffer for scanning device ID data
14263a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @count: input size
14273a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby *
14283a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * Adds a new dynamic hid device ID to this driver,
14293a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * and causes the driver to probe for all devices again.
14303a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby */
14313a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic ssize_t store_new_id(struct device_driver *drv, const char *buf,
14323a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		size_t count)
14333a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{
14343a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
14353a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	struct hid_dynid *dynid;
14363a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	__u32 bus, vendor, product;
14373a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	unsigned long driver_data = 0;
14383a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	int ret;
14393a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14403a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	ret = sscanf(buf, "%x %x %x %lx",
14413a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby			&bus, &vendor, &product, &driver_data);
14423a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	if (ret < 3)
14433a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		return -EINVAL;
14443a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14453a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
14463a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	if (!dynid)
14473a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		return -ENOMEM;
14483a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14493a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	dynid->id.bus = bus;
14503a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	dynid->id.vendor = vendor;
14513a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	dynid->id.product = product;
14523a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	dynid->id.driver_data = driver_data;
14533a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14543a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_lock(&hdrv->dyn_lock);
14553a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	list_add_tail(&dynid->list, &hdrv->dyn_list);
14563a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_unlock(&hdrv->dyn_lock);
14573a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14583a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	ret = 0;
14593a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	if (get_driver(&hdrv->driver)) {
14603a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		ret = driver_attach(&hdrv->driver);
14613a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		put_driver(&hdrv->driver);
14623a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	}
14633a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14643a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	return ret ? : count;
14653a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby}
14663a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
14673a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14683a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic void hid_free_dynids(struct hid_driver *hdrv)
14693a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{
14703a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	struct hid_dynid *dynid, *n;
14713a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14723a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_lock(&hdrv->dyn_lock);
14733a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
14743a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		list_del(&dynid->list);
14753a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		kfree(dynid);
14763a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	}
14773a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_unlock(&hdrv->dyn_lock);
14783a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby}
14793a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14803a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic const struct hid_device_id *hid_match_device(struct hid_device *hdev,
14813a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		struct hid_driver *hdrv)
14823a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{
14833a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	struct hid_dynid *dynid;
14843a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14853a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_lock(&hdrv->dyn_lock);
14863a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	list_for_each_entry(dynid, &hdrv->dyn_list, list) {
14873a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		if (hid_match_one_id(hdev, &dynid->id)) {
14883a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby			spin_unlock(&hdrv->dyn_lock);
14893a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby			return &dynid->id;
14903a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		}
14913a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	}
14923a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_unlock(&hdrv->dyn_lock);
14933a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
14943a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	return hid_match_id(hdev, hdrv->id_table);
14953a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby}
14963a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
149785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_bus_match(struct device *dev, struct device_driver *drv)
149885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
149985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
150085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
150185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
15023a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	if (!hid_match_device(hdev, hdrv))
150385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return 0;
150485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
150585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	/* generic wants all non-blacklisted */
150685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!strncmp(hdrv->name, "generic-", 8))
150785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return !hid_match_id(hdev, hid_blacklist);
150885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
150985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return 1;
151085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
151185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
151285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_device_probe(struct device *dev)
151385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
151485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_driver *hdrv = container_of(dev->driver,
151585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			struct hid_driver, driver);
151685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
151785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	const struct hid_device_id *id;
151885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret = 0;
151985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
152085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!hdev->driver) {
15213a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		id = hid_match_device(hdev, hdrv);
1522c500c9714011edab021591340042787722db9cf0Jiri Slaby		if (id == NULL)
1523c500c9714011edab021591340042787722db9cf0Jiri Slaby			return -ENODEV;
152485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1525c500c9714011edab021591340042787722db9cf0Jiri Slaby		hdev->driver = hdrv;
1526c500c9714011edab021591340042787722db9cf0Jiri Slaby		if (hdrv->probe) {
1527c500c9714011edab021591340042787722db9cf0Jiri Slaby			ret = hdrv->probe(hdev, id);
1528c500c9714011edab021591340042787722db9cf0Jiri Slaby		} else { /* default probe */
1529c500c9714011edab021591340042787722db9cf0Jiri Slaby			ret = hid_parse(hdev);
1530c500c9714011edab021591340042787722db9cf0Jiri Slaby			if (!ret)
153193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby				ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
153285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		}
1533c500c9714011edab021591340042787722db9cf0Jiri Slaby		if (ret)
1534c500c9714011edab021591340042787722db9cf0Jiri Slaby			hdev->driver = NULL;
153585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
153685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return ret;
153785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
153885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
153985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_device_remove(struct device *dev)
154085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
154185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
154285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_driver *hdrv = hdev->driver;
154385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
154485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (hdrv) {
154585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		if (hdrv->remove)
154685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			hdrv->remove(hdev);
1547c500c9714011edab021591340042787722db9cf0Jiri Slaby		else /* default remove */
1548c500c9714011edab021591340042787722db9cf0Jiri Slaby			hid_hw_stop(hdev);
154985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		hdev->driver = NULL;
155085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
155185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
155285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return 0;
155385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
155485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
155585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
155685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
155785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
155885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
155985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
156085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			hdev->bus, hdev->vendor, hdev->product))
156185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENOMEM;
156285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
156385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
156485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENOMEM;
156585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
156685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
156785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENOMEM;
156885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
156985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
157085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENOMEM;
157185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
157285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
157385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			hdev->bus, hdev->vendor, hdev->product))
157485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -ENOMEM;
157585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
157685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return 0;
157785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
157885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
157985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic struct bus_type hid_bus_type = {
158085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	.name		= "hid",
158185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	.match		= hid_bus_match,
158285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	.probe		= hid_device_probe,
158385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	.remove		= hid_device_remove,
158485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	.uevent		= hid_uevent,
158585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby};
158685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1587bae7eb33b25387fdc7ccae08768bef1f9484a5b0Jiri Kosina/* a list of devices that shouldn't be handled by HID core at all */
1588d458a9dfc4de24870b8c747484b1988726534beeJiri Slabystatic const struct hid_device_id hid_ignore_list[] = {
1589d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1590d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1591d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1592d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1593d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1594d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1595d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1596d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1597d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1598d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1599d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1600d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
160177f720b71d88a3cbf574c113566a31c93099f97dStephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
160277f720b71d88a3cbf574c113566a31c93099f97dStephane Chatty	{ HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
160362a56582e01b1c5139b235004548e233201df9aaAlexey Klimov	{ HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1604d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1605d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1606d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1607d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1608d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1609d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
16105f6108cf9be4a77d6bee96750aa4fe18b6b97deeAlexey Klimov	{ HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
1611d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1612d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1613d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
161470c66567d1e41d8b2186a2d198997a1c8d79c0c4Petr Å tetiar	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1615df506f2c0023380ffa67a946fa36eee4150773a3Petr Å tetiar	{ HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1616d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1617d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1618d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1619d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1620d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1621d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1622d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1623d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1624d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1625d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1626d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1627d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1628d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1629d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1630d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1631d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1632d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1633d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1634d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1635d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1636d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1637d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1638d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1639d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1640d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1641d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1642d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1643d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1644d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1645d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1646d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1647d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1648d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1649d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1650d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1651d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1652d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1653d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1654d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1655d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1656d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1657d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1658d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1659d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1660d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1661d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1662d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1663d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1664d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1665d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1666d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1667d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1668d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1669d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1670d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1671d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1672d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1673d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1674d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1675d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1676d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1677d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1678d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1679d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1680d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
16816bc235a2e24a5ef677daee3fd4f74f6cd643e23cTomoki Sekiyama	{ HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_JESS_YUREX) },
1682d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1683c91c21c5a6facddce936d82e5bc0c655d04288aaAlexey Klimov	{ HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
1684d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1685eb8141ccd32d422fa11c6e2108cae4c40456d811Lamarque Vieira Souza	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
1686d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1687d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1688d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1689d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1690d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1691d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1692d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
1693d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1694d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1695d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1696d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1697d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1698d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1699d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1700d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1701d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1702d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1703d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1704d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1705d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1706d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1707d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1708d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1709d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1710d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1711d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1712d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1713d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1714d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1715d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1716d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1717d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1718d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
17194cfae3e80431fd113f0f4a8e1d4fff84aafe045cHenning Glawe	{ HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
172035cfd1d964f3c2420862f2167a0eb85ff1208999Michael Tokarev	{ HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1721d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1722d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1723d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1724d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1725d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1726d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1727d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1728d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1729d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1730d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1731d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	{ }
1732d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby};
1733d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby
1734b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby/**
1735b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1736b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby *
1737b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * There are composite devices for which we want to ignore only a certain
1738b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * interface. This is a list of devices for which only the mouse interface will
1739b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * be ignored. This allows a dedicated driver to take care of the interface.
1740b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby */
1741b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slabystatic const struct hid_device_id hid_mouse_ignore_list[] = {
1742b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	/* appletouch driver */
1743b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1744b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1745b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1746b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1747b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1748b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1749b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1750b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1751b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1752b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1753b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1754b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1755b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1756b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1757b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1758b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1759b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1760b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1761b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1762b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1763ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1764ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1765ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
176699b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
176799b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
176899b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
176999b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
177099b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
177199b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
1772b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1773b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1774b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	{ }
1775b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby};
1776b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby
1777d458a9dfc4de24870b8c747484b1988726534beeJiri Slabystatic bool hid_ignore(struct hid_device *hdev)
1778d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby{
1779d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	switch (hdev->vendor) {
1780d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	case USB_VENDOR_ID_CODEMERCS:
1781d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby		/* ignore all Code Mercenaries IOWarrior devices */
1782d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby		if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1783d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby				hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1784d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby			return true;
1785d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby		break;
1786d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	case USB_VENDOR_ID_LOGITECH:
1787d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby		if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1788d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby				hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1789d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby			return true;
1790d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby		break;
179131f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson	case USB_VENDOR_ID_SOUNDGRAPH:
179231f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson		if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
179331f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson		    hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
179431f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson			return true;
179531f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson		break;
1796d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	}
1797d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby
1798b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby	if (hdev->type == HID_TYPE_USBMOUSE &&
1799b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby			hid_match_id(hdev, hid_mouse_ignore_list))
1800b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby		return true;
1801b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby
1802d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	return !!hid_match_id(hdev, hid_ignore_list);
1803d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby}
1804d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby
180585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_add_device(struct hid_device *hdev)
180685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
180785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	static atomic_t id = ATOMIC_INIT(0);
180885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret;
180985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
181085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (WARN_ON(hdev->status & HID_STAT_ADDED))
181185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return -EBUSY;
181285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1813d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	/* we need to kill them here, otherwise they will stay allocated to
1814d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby	 * wait for coming driver */
1815e5a2a04c264e693eafcc78fec5add34c9e15e471Jindrich Makovicka	if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1816e5a2a04c264e693eafcc78fec5add34c9e15e471Jindrich Makovicka            && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
1817d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby		return -ENODEV;
1818d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby
18196bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers	/* XXX hack, any other cleaner solution after the driver core
18206bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers	 * is converted to allow more than 20 bytes as the device name? */
18216bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers	dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
18226bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers		     hdev->vendor, hdev->product, atomic_inc_return(&id));
182385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
18244da361b69102cdffe73006771eae7504d2cb8736Bruno Prémont	hid_debug_register(hdev, dev_name(&hdev->dev));
182585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	ret = device_add(&hdev->dev);
182685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (!ret)
182785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		hdev->status |= HID_STAT_ADDED;
18284da361b69102cdffe73006771eae7504d2cb8736Bruno Prémont	else
18294da361b69102cdffe73006771eae7504d2cb8736Bruno Prémont		hid_debug_unregister(hdev);
1830a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina
183185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return ret;
183285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
183385cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_add_device);
183485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
183585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/**
183685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_allocate_device - allocate new hid device descriptor
183785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
183885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * Allocate and initialize hid device, so that hid_destroy_device might be
183985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * used to free it.
184085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
184185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
184285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * error value.
184385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */
184485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystruct hid_device *hid_allocate_device(void)
184585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
184685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	struct hid_device *hdev;
184785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	unsigned int i;
184885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret = -ENOMEM;
184985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
185085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
185185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (hdev == NULL)
185285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		return ERR_PTR(ret);
185385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
185485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	device_initialize(&hdev->dev);
185585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdev->dev.release = hid_device_release;
185685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdev->dev.bus = &hid_bus_type;
185785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
185885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
185985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby			sizeof(struct hid_collection), GFP_KERNEL);
186085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (hdev->collection == NULL)
186185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		goto err;
186285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
186385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
186485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	for (i = 0; i < HID_REPORT_TYPES; i++)
186585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
186685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1867cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	init_waitqueue_head(&hdev->debug_wait);
1868cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina	INIT_LIST_HEAD(&hdev->debug_list);
1869cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina
187085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return hdev;
187185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr:
187285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	put_device(&hdev->dev);
187385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return ERR_PTR(ret);
187485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
187585cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_allocate_device);
187685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
187785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_remove_device(struct hid_device *hdev)
187885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
187985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (hdev->status & HID_STAT_ADDED) {
188085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		device_del(&hdev->dev);
1881a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina		hid_debug_unregister(hdev);
188285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		hdev->status &= ~HID_STAT_ADDED;
188385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
188485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
188585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
188685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/**
188785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_destroy_device - free previously allocated device
188885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
188985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hdev: hid device
189085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby *
189185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * If you allocate hid_device through hid_allocate_device, you should ever
189285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * free by this function.
189385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */
189485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_destroy_device(struct hid_device *hdev)
189585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
189685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hid_remove_device(hdev);
189785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	put_device(&hdev->dev);
189885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
189985cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_destroy_device);
190085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
190185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
190285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		const char *mod_name)
190385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
19043a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	int ret;
19053a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
190685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdrv->driver.name = hdrv->name;
190785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdrv->driver.bus = &hid_bus_type;
190885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdrv->driver.owner = owner;
190985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	hdrv->driver.mod_name = mod_name;
191085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
19113a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	INIT_LIST_HEAD(&hdrv->dyn_list);
19123a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	spin_lock_init(&hdrv->dyn_lock);
19133a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
19143a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	ret = driver_register(&hdrv->driver);
19153a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	if (ret)
19163a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		return ret;
19173a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
19183a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
19193a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	if (ret)
19203a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby		driver_unregister(&hdrv->driver);
19213a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby
19223a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	return ret;
192385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
192485cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(__hid_register_driver);
192585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
192685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_unregister_driver(struct hid_driver *hdrv)
192785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{
19283a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	driver_remove_file(&hdrv->driver, &driver_attr_new_id);
192985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	driver_unregister(&hdrv->driver);
19303a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby	hid_free_dynids(hdrv);
193185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}
193285cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_unregister_driver);
193385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
19340361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukumint hid_check_keys_pressed(struct hid_device *hid)
19350361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum{
19360361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum	struct hid_input *hidinput;
19370361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum	int i;
19380361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum
1939e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina	if (!(hid->claimed & HID_CLAIMED_INPUT))
1940e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina		return 0;
1941e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina
19420361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum	list_for_each_entry(hidinput, &hid->inputs, list) {
19430361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum		for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
19440361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum			if (hidinput->input->key[i])
19450361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum				return 1;
19460361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum	}
19470361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum
19480361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum	return 0;
19490361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum}
19500361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum
19510361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver NeukumEXPORT_SYMBOL_GPL(hid_check_keys_pressed);
19520361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum
195386166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinastatic int __init hid_init(void)
195486166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina{
195585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	int ret;
195685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1957a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina	if (hid_debug)
1958cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina		printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
1959cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina				"HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
1960a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina
196185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	ret = bus_register(&hid_bus_type);
196285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (ret) {
196385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		printk(KERN_ERR "HID: can't register hid bus\n");
196485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		goto err;
196585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	}
196685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
196785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	ret = hidraw_init();
196885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	if (ret)
196985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby		goto err_bus;
197085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby
1971a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina	hid_debug_init();
1972a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina
197385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return 0;
197485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr_bus:
197585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	bus_unregister(&hid_bus_type);
197685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr:
197785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	return ret;
197886166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina}
197986166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina
198086166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinastatic void __exit hid_exit(void)
198186166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina{
1982a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina	hid_debug_exit();
198386166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina	hidraw_exit();
198485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby	bus_unregister(&hid_bus_type);
198586166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina}
198686166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina
198786166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinamodule_init(hid_init);
198886166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinamodule_exit(hid_exit);
198986166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina
199088adb72bcf3b1cc6b440fda9fa97bc2151245fc5Jiri KosinaMODULE_AUTHOR("Andreas Gal");
199188adb72bcf3b1cc6b440fda9fa97bc2151245fc5Jiri KosinaMODULE_AUTHOR("Vojtech Pavlik");
199288adb72bcf3b1cc6b440fda9fa97bc2151245fc5Jiri KosinaMODULE_AUTHOR("Jiri Kosina");
1993aa938f7974b82cfd9ee955031987344f332b7c77Jiri KosinaMODULE_LICENSE(DRIVER_LICENSE);
1994aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina
1995