blob: ab4ae12e0a017430c8a618db570d45087eda156c [file] [log] [blame]
Jiri Kosinadde58452006-12-08 18:40:44 +01001/*
Jiri Kosina229695e2006-12-08 18:40:53 +01002 * HID support for Linux
Jiri Kosinadde58452006-12-08 18:40:44 +01003 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
Jiri Kosina7d39e842010-02-02 20:46:34 +01007 * Copyright (c) 2006-2010 Jiri Kosina
Jiri Kosinadde58452006-12-08 18:40:44 +01008 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 */
16
Joe Perches4291ee32010-12-09 19:29:03 -080017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Jiri Kosinadde58452006-12-08 18:40:44 +010019#include <linux/module.h>
20#include <linux/slab.h>
21#include <linux/init.h>
22#include <linux/kernel.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010023#include <linux/list.h>
24#include <linux/mm.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010025#include <linux/spinlock.h>
26#include <asm/unaligned.h>
27#include <asm/byteorder.h>
28#include <linux/input.h>
29#include <linux/wait.h>
Jiri Kosina47a80ed2007-03-12 14:55:12 +010030#include <linux/vmalloc.h>
Jiri Kosinac4124c92007-11-30 11:12:58 +010031#include <linux/sched.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010032
Jiri Kosinadde58452006-12-08 18:40:44 +010033#include <linux/hid.h>
34#include <linux/hiddev.h>
Jiri Kosinac080d892007-01-25 11:43:31 +010035#include <linux/hid-debug.h>
Jiri Kosina86166b72007-05-14 09:57:40 +020036#include <linux/hidraw.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010037
Jiri Slaby5f22a792008-05-16 11:49:19 +020038#include "hid-ids.h"
39
Jiri Kosinadde58452006-12-08 18:40:44 +010040/*
41 * Version Information
42 */
43
Jiri Kosina53149802007-01-09 13:24:25 +010044#define DRIVER_DESC "HID core driver"
Jiri Kosinadde58452006-12-08 18:40:44 +010045#define DRIVER_LICENSE "GPL"
46
Jiri Kosina58037eb2007-05-30 15:07:13 +020047int hid_debug = 0;
Anssi Hannula377e10f2008-03-22 23:50:13 +010048module_param_named(debug, hid_debug, int, 0600);
Jiri Kosinacd667ce2009-06-12 15:20:57 +020049MODULE_PARM_DESC(debug, "toggle HID debugging messages");
Jiri Kosina58037eb2007-05-30 15:07:13 +020050EXPORT_SYMBOL_GPL(hid_debug);
Jiri Kosina58037eb2007-05-30 15:07:13 +020051
Jiri Kosinadde58452006-12-08 18:40:44 +010052/*
Jiri Kosinadde58452006-12-08 18:40:44 +010053 * Register a new report for a device.
54 */
55
Michael Poole90a006a2010-01-24 22:32:29 -050056struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
Jiri Kosinadde58452006-12-08 18:40:44 +010057{
58 struct hid_report_enum *report_enum = device->report_enum + type;
59 struct hid_report *report;
60
61 if (report_enum->report_id_hash[id])
62 return report_enum->report_id_hash[id];
63
Joe Perchesa3789a172010-12-09 19:29:07 -080064 report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
65 if (!report)
Jiri Kosinadde58452006-12-08 18:40:44 +010066 return NULL;
67
68 if (id != 0)
69 report_enum->numbered = 1;
70
71 report->id = id;
72 report->type = type;
73 report->size = 0;
74 report->device = device;
75 report_enum->report_id_hash[id] = report;
76
77 list_add_tail(&report->list, &report_enum->report_list);
78
79 return report;
80}
Michael Poole90a006a2010-01-24 22:32:29 -050081EXPORT_SYMBOL_GPL(hid_register_report);
Jiri Kosinadde58452006-12-08 18:40:44 +010082
83/*
84 * Register a new field for this report.
85 */
86
87static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
88{
89 struct hid_field *field;
90
91 if (report->maxfield == HID_MAX_FIELDS) {
Jiri Kosina58037eb2007-05-30 15:07:13 +020092 dbg_hid("too many fields in report\n");
Jiri Kosinadde58452006-12-08 18:40:44 +010093 return NULL;
94 }
95
Joe Perchesa3789a172010-12-09 19:29:07 -080096 field = kzalloc((sizeof(struct hid_field) +
97 usages * sizeof(struct hid_usage) +
98 values * sizeof(unsigned)), GFP_KERNEL);
99 if (!field)
100 return NULL;
Jiri Kosinadde58452006-12-08 18:40:44 +0100101
102 field->index = report->maxfield++;
103 report->field[field->index] = field;
104 field->usage = (struct hid_usage *)(field + 1);
Jiri Slaby282bfd42008-03-28 17:06:41 +0100105 field->value = (s32 *)(field->usage + usages);
Jiri Kosinadde58452006-12-08 18:40:44 +0100106 field->report = report;
107
108 return field;
109}
110
111/*
112 * Open a collection. The type/usage is pushed on the stack.
113 */
114
115static int open_collection(struct hid_parser *parser, unsigned type)
116{
117 struct hid_collection *collection;
118 unsigned usage;
119
120 usage = parser->local.usage[0];
121
122 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200123 dbg_hid("collection stack overflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100124 return -1;
125 }
126
127 if (parser->device->maxcollection == parser->device->collection_size) {
128 collection = kmalloc(sizeof(struct hid_collection) *
129 parser->device->collection_size * 2, GFP_KERNEL);
130 if (collection == NULL) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200131 dbg_hid("failed to reallocate collection array\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100132 return -1;
133 }
134 memcpy(collection, parser->device->collection,
135 sizeof(struct hid_collection) *
136 parser->device->collection_size);
137 memset(collection + parser->device->collection_size, 0,
138 sizeof(struct hid_collection) *
139 parser->device->collection_size);
140 kfree(parser->device->collection);
141 parser->device->collection = collection;
142 parser->device->collection_size *= 2;
143 }
144
145 parser->collection_stack[parser->collection_stack_ptr++] =
146 parser->device->maxcollection;
147
148 collection = parser->device->collection +
149 parser->device->maxcollection++;
150 collection->type = type;
151 collection->usage = usage;
152 collection->level = parser->collection_stack_ptr - 1;
153
154 if (type == HID_COLLECTION_APPLICATION)
155 parser->device->maxapplication++;
156
157 return 0;
158}
159
160/*
161 * Close a collection.
162 */
163
164static int close_collection(struct hid_parser *parser)
165{
166 if (!parser->collection_stack_ptr) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200167 dbg_hid("collection stack underflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100168 return -1;
169 }
170 parser->collection_stack_ptr--;
171 return 0;
172}
173
174/*
175 * Climb up the stack, search for the specified collection type
176 * and return the usage.
177 */
178
179static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
180{
Joe Perches504499f2010-12-09 19:29:08 -0800181 struct hid_collection *collection = parser->device->collection;
Jiri Kosinadde58452006-12-08 18:40:44 +0100182 int n;
Joe Perches504499f2010-12-09 19:29:08 -0800183
184 for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
185 unsigned index = parser->collection_stack[n];
186 if (collection[index].type == type)
187 return collection[index].usage;
188 }
Jiri Kosinadde58452006-12-08 18:40:44 +0100189 return 0; /* we know nothing about this usage type */
190}
191
192/*
193 * Add a usage to the temporary parser table.
194 */
195
196static int hid_add_usage(struct hid_parser *parser, unsigned usage)
197{
198 if (parser->local.usage_index >= HID_MAX_USAGES) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200199 dbg_hid("usage index exceeded\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100200 return -1;
201 }
202 parser->local.usage[parser->local.usage_index] = usage;
203 parser->local.collection_index[parser->local.usage_index] =
204 parser->collection_stack_ptr ?
205 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
206 parser->local.usage_index++;
207 return 0;
208}
209
210/*
211 * Register a new field for this report.
212 */
213
214static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
215{
216 struct hid_report *report;
217 struct hid_field *field;
218 int usages;
219 unsigned offset;
220 int i;
221
Joe Perchesa3789a172010-12-09 19:29:07 -0800222 report = hid_register_report(parser->device, report_type, parser->global.report_id);
223 if (!report) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200224 dbg_hid("hid_register_report failed\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100225 return -1;
226 }
227
228 if (parser->global.logical_maximum < parser->global.logical_minimum) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200229 dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
Jiri Kosinadde58452006-12-08 18:40:44 +0100230 return -1;
231 }
232
233 offset = report->size;
234 report->size += parser->global.report_size * parser->global.report_count;
235
236 if (!parser->local.usage_index) /* Ignore padding fields */
237 return 0;
238
239 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
240
Joe Perchesa3789a172010-12-09 19:29:07 -0800241 field = hid_register_field(report, usages, parser->global.report_count);
242 if (!field)
Jiri Kosinadde58452006-12-08 18:40:44 +0100243 return 0;
244
245 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
246 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
247 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
248
249 for (i = 0; i < usages; i++) {
250 int j = i;
251 /* Duplicate the last usage we parsed if we have excess values */
252 if (i >= parser->local.usage_index)
253 j = parser->local.usage_index - 1;
254 field->usage[i].hid = parser->local.usage[j];
255 field->usage[i].collection_index =
256 parser->local.collection_index[j];
257 }
258
259 field->maxusage = usages;
260 field->flags = flags;
261 field->report_offset = offset;
262 field->report_type = report_type;
263 field->report_size = parser->global.report_size;
264 field->report_count = parser->global.report_count;
265 field->logical_minimum = parser->global.logical_minimum;
266 field->logical_maximum = parser->global.logical_maximum;
267 field->physical_minimum = parser->global.physical_minimum;
268 field->physical_maximum = parser->global.physical_maximum;
269 field->unit_exponent = parser->global.unit_exponent;
270 field->unit = parser->global.unit;
271
272 return 0;
273}
274
275/*
276 * Read data value from item.
277 */
278
279static u32 item_udata(struct hid_item *item)
280{
281 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200282 case 1: return item->data.u8;
283 case 2: return item->data.u16;
284 case 4: return item->data.u32;
Jiri Kosinadde58452006-12-08 18:40:44 +0100285 }
286 return 0;
287}
288
289static s32 item_sdata(struct hid_item *item)
290{
291 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200292 case 1: return item->data.s8;
293 case 2: return item->data.s16;
294 case 4: return item->data.s32;
Jiri Kosinadde58452006-12-08 18:40:44 +0100295 }
296 return 0;
297}
298
299/*
300 * Process a global item.
301 */
302
303static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
304{
305 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200306 case HID_GLOBAL_ITEM_TAG_PUSH:
Jiri Kosinadde58452006-12-08 18:40:44 +0100307
Jiri Slaby880d29f2008-06-18 23:55:41 +0200308 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300309 dbg_hid("global environment stack overflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100310 return -1;
Jiri Slaby880d29f2008-06-18 23:55:41 +0200311 }
312
313 memcpy(parser->global_stack + parser->global_stack_ptr++,
314 &parser->global, sizeof(struct hid_global));
315 return 0;
316
317 case HID_GLOBAL_ITEM_TAG_POP:
318
319 if (!parser->global_stack_ptr) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300320 dbg_hid("global environment stack underflow\n");
Jiri Slaby880d29f2008-06-18 23:55:41 +0200321 return -1;
322 }
323
324 memcpy(&parser->global, parser->global_stack +
325 --parser->global_stack_ptr, sizeof(struct hid_global));
326 return 0;
327
328 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
329 parser->global.usage_page = item_udata(item);
330 return 0;
331
332 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
333 parser->global.logical_minimum = item_sdata(item);
334 return 0;
335
336 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
337 if (parser->global.logical_minimum < 0)
338 parser->global.logical_maximum = item_sdata(item);
339 else
340 parser->global.logical_maximum = item_udata(item);
341 return 0;
342
343 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
344 parser->global.physical_minimum = item_sdata(item);
345 return 0;
346
347 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
348 if (parser->global.physical_minimum < 0)
349 parser->global.physical_maximum = item_sdata(item);
350 else
351 parser->global.physical_maximum = item_udata(item);
352 return 0;
353
354 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
355 parser->global.unit_exponent = item_sdata(item);
356 return 0;
357
358 case HID_GLOBAL_ITEM_TAG_UNIT:
359 parser->global.unit = item_udata(item);
360 return 0;
361
362 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
363 parser->global.report_size = item_udata(item);
364 if (parser->global.report_size > 32) {
365 dbg_hid("invalid report_size %d\n",
366 parser->global.report_size);
367 return -1;
368 }
369 return 0;
370
371 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
372 parser->global.report_count = item_udata(item);
373 if (parser->global.report_count > HID_MAX_USAGES) {
374 dbg_hid("invalid report_count %d\n",
375 parser->global.report_count);
376 return -1;
377 }
378 return 0;
379
380 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
381 parser->global.report_id = item_udata(item);
382 if (parser->global.report_id == 0) {
383 dbg_hid("report_id 0 is invalid\n");
384 return -1;
385 }
386 return 0;
387
388 default:
389 dbg_hid("unknown global tag 0x%x\n", item->tag);
390 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100391 }
392}
393
394/*
395 * Process a local item.
396 */
397
398static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
399{
400 __u32 data;
401 unsigned n;
402
Jiri Kosinadde58452006-12-08 18:40:44 +0100403 data = item_udata(item);
404
405 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200406 case HID_LOCAL_ITEM_TAG_DELIMITER:
Jiri Kosinadde58452006-12-08 18:40:44 +0100407
Jiri Slaby880d29f2008-06-18 23:55:41 +0200408 if (data) {
409 /*
410 * We treat items before the first delimiter
411 * as global to all usage sets (branch 0).
412 * In the moment we process only these global
413 * items and the first delimiter set.
414 */
415 if (parser->local.delimiter_depth != 0) {
416 dbg_hid("nested delimiters\n");
417 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100418 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200419 parser->local.delimiter_depth++;
420 parser->local.delimiter_branch++;
421 } else {
422 if (parser->local.delimiter_depth < 1) {
423 dbg_hid("bogus close delimiter\n");
424 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100425 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200426 parser->local.delimiter_depth--;
427 }
428 return 1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100429
Jiri Slaby880d29f2008-06-18 23:55:41 +0200430 case HID_LOCAL_ITEM_TAG_USAGE:
Jiri Kosinadde58452006-12-08 18:40:44 +0100431
Jiri Slaby880d29f2008-06-18 23:55:41 +0200432 if (parser->local.delimiter_branch > 1) {
433 dbg_hid("alternative usage ignored\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100434 return 0;
Jiri Slaby880d29f2008-06-18 23:55:41 +0200435 }
Jiri Kosinadde58452006-12-08 18:40:44 +0100436
Jiri Slaby880d29f2008-06-18 23:55:41 +0200437 if (item->size <= 2)
438 data = (parser->global.usage_page << 16) + data;
Jiri Kosinadde58452006-12-08 18:40:44 +0100439
Jiri Slaby880d29f2008-06-18 23:55:41 +0200440 return hid_add_usage(parser, data);
441
442 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
443
444 if (parser->local.delimiter_branch > 1) {
445 dbg_hid("alternative usage ignored\n");
446 return 0;
447 }
448
449 if (item->size <= 2)
450 data = (parser->global.usage_page << 16) + data;
451
452 parser->local.usage_minimum = data;
453 return 0;
454
455 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
456
457 if (parser->local.delimiter_branch > 1) {
458 dbg_hid("alternative usage ignored\n");
459 return 0;
460 }
461
462 if (item->size <= 2)
463 data = (parser->global.usage_page << 16) + data;
464
465 for (n = parser->local.usage_minimum; n <= data; n++)
466 if (hid_add_usage(parser, n)) {
467 dbg_hid("hid_add_usage failed\n");
468 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100469 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200470 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100471
Jiri Slaby880d29f2008-06-18 23:55:41 +0200472 default:
Jiri Kosinadde58452006-12-08 18:40:44 +0100473
Jiri Slaby880d29f2008-06-18 23:55:41 +0200474 dbg_hid("unknown local item tag 0x%x\n", item->tag);
475 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100476 }
477 return 0;
478}
479
480/*
481 * Process a main item.
482 */
483
484static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
485{
486 __u32 data;
487 int ret;
488
489 data = item_udata(item);
490
491 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200492 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
493 ret = open_collection(parser, data & 0xff);
494 break;
495 case HID_MAIN_ITEM_TAG_END_COLLECTION:
496 ret = close_collection(parser);
497 break;
498 case HID_MAIN_ITEM_TAG_INPUT:
499 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
500 break;
501 case HID_MAIN_ITEM_TAG_OUTPUT:
502 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
503 break;
504 case HID_MAIN_ITEM_TAG_FEATURE:
505 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
506 break;
507 default:
508 dbg_hid("unknown main item tag 0x%x\n", item->tag);
509 ret = 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100510 }
511
512 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
513
514 return ret;
515}
516
517/*
518 * Process a reserved item.
519 */
520
521static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
522{
Jiri Kosina58037eb2007-05-30 15:07:13 +0200523 dbg_hid("reserved item type, tag 0x%x\n", item->tag);
Jiri Kosinadde58452006-12-08 18:40:44 +0100524 return 0;
525}
526
527/*
528 * Free a report and all registered fields. The field->usage and
529 * field->value table's are allocated behind the field, so we need
530 * only to free(field) itself.
531 */
532
533static void hid_free_report(struct hid_report *report)
534{
535 unsigned n;
536
537 for (n = 0; n < report->maxfield; n++)
538 kfree(report->field[n]);
539 kfree(report);
540}
541
542/*
543 * Free a device structure, all reports, and all fields.
544 */
545
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200546static void hid_device_release(struct device *dev)
Jiri Kosinadde58452006-12-08 18:40:44 +0100547{
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200548 struct hid_device *device = container_of(dev, struct hid_device, dev);
549 unsigned i, j;
Jiri Kosinadde58452006-12-08 18:40:44 +0100550
551 for (i = 0; i < HID_REPORT_TYPES; i++) {
552 struct hid_report_enum *report_enum = device->report_enum + i;
553
554 for (j = 0; j < 256; j++) {
555 struct hid_report *report = report_enum->report_id_hash[j];
556 if (report)
557 hid_free_report(report);
558 }
559 }
560
561 kfree(device->rdesc);
Jiri Kosina767fe782007-01-24 23:05:07 +0100562 kfree(device->collection);
Jiri Kosinadde58452006-12-08 18:40:44 +0100563 kfree(device);
564}
565
566/*
567 * Fetch a report description item from the data stream. We support long
568 * items, though they are not used yet.
569 */
570
571static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
572{
573 u8 b;
574
575 if ((end - start) <= 0)
576 return NULL;
577
578 b = *start++;
579
580 item->type = (b >> 2) & 3;
581 item->tag = (b >> 4) & 15;
582
583 if (item->tag == HID_ITEM_TAG_LONG) {
584
585 item->format = HID_ITEM_FORMAT_LONG;
586
587 if ((end - start) < 2)
588 return NULL;
589
590 item->size = *start++;
591 item->tag = *start++;
592
593 if ((end - start) < item->size)
594 return NULL;
595
596 item->data.longdata = start;
597 start += item->size;
598 return start;
599 }
600
601 item->format = HID_ITEM_FORMAT_SHORT;
602 item->size = b & 3;
603
604 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200605 case 0:
606 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100607
Jiri Slaby880d29f2008-06-18 23:55:41 +0200608 case 1:
609 if ((end - start) < 1)
610 return NULL;
611 item->data.u8 = *start++;
612 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100613
Jiri Slaby880d29f2008-06-18 23:55:41 +0200614 case 2:
615 if ((end - start) < 2)
616 return NULL;
617 item->data.u16 = get_unaligned_le16(start);
618 start = (__u8 *)((__le16 *)start + 1);
619 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100620
Jiri Slaby880d29f2008-06-18 23:55:41 +0200621 case 3:
622 item->size++;
623 if ((end - start) < 4)
624 return NULL;
625 item->data.u32 = get_unaligned_le32(start);
626 start = (__u8 *)((__le32 *)start + 1);
627 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100628 }
629
630 return NULL;
631}
632
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200633/**
634 * hid_parse_report - parse device report
635 *
636 * @device: hid device
637 * @start: report start
638 * @size: report size
639 *
Jiri Kosinadde58452006-12-08 18:40:44 +0100640 * Parse a report description into a hid_device structure. Reports are
641 * enumerated, fields are attached to these reports.
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200642 * 0 returned on success, otherwise nonzero error value.
Jiri Kosinadde58452006-12-08 18:40:44 +0100643 */
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200644int hid_parse_report(struct hid_device *device, __u8 *start,
645 unsigned size)
Jiri Kosinadde58452006-12-08 18:40:44 +0100646{
Jiri Kosinadde58452006-12-08 18:40:44 +0100647 struct hid_parser *parser;
648 struct hid_item item;
649 __u8 *end;
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200650 int ret;
Jiri Kosinadde58452006-12-08 18:40:44 +0100651 static int (*dispatch_type[])(struct hid_parser *parser,
652 struct hid_item *item) = {
653 hid_parser_main,
654 hid_parser_global,
655 hid_parser_local,
656 hid_parser_reserved
657 };
658
Jiri Slabyc500c972008-05-16 11:49:16 +0200659 if (device->driver->report_fixup)
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400660 start = device->driver->report_fixup(device, start, &size);
Jiri Slabyc500c972008-05-16 11:49:16 +0200661
Julia Lawall1721a232010-05-15 23:19:30 +0200662 device->rdesc = kmemdup(start, size, GFP_KERNEL);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200663 if (device->rdesc == NULL)
664 return -ENOMEM;
Jiri Kosinadde58452006-12-08 18:40:44 +0100665 device->rsize = size;
666
Joe Perchesfe258022010-12-09 19:29:04 -0800667 parser = vzalloc(sizeof(struct hid_parser));
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200668 if (!parser) {
669 ret = -ENOMEM;
670 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100671 }
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200672
Jiri Kosinadde58452006-12-08 18:40:44 +0100673 parser->device = device;
674
675 end = start + size;
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200676 ret = -EINVAL;
Jiri Kosinadde58452006-12-08 18:40:44 +0100677 while ((start = fetch_item(start, end, &item)) != NULL) {
678
679 if (item.format != HID_ITEM_FORMAT_SHORT) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200680 dbg_hid("unexpected long global item\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200681 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100682 }
683
684 if (dispatch_type[item.type](parser, &item)) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200685 dbg_hid("item %u %u %u %u parsing failed\n",
Joe Perches4291ee32010-12-09 19:29:03 -0800686 item.format, (unsigned)item.size,
687 (unsigned)item.type, (unsigned)item.tag);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200688 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100689 }
690
691 if (start == end) {
692 if (parser->collection_stack_ptr) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200693 dbg_hid("unbalanced collection at end of report description\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200694 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100695 }
696 if (parser->local.delimiter_depth) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200697 dbg_hid("unbalanced delimiter at end of report description\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200698 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100699 }
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100700 vfree(parser);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200701 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100702 }
703 }
704
Jiri Kosina58037eb2007-05-30 15:07:13 +0200705 dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200706err:
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100707 vfree(parser);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200708 return ret;
Jiri Kosinadde58452006-12-08 18:40:44 +0100709}
Jiri Kosina229695e2006-12-08 18:40:53 +0100710EXPORT_SYMBOL_GPL(hid_parse_report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100711
712/*
713 * Convert a signed n-bit integer to signed 32-bit integer. Common
714 * cases are done through the compiler, the screwed things has to be
715 * done by hand.
716 */
717
718static s32 snto32(__u32 value, unsigned n)
719{
720 switch (n) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200721 case 8: return ((__s8)value);
722 case 16: return ((__s16)value);
723 case 32: return ((__s32)value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100724 }
725 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
726}
727
728/*
729 * Convert a signed 32-bit integer to a signed n-bit integer.
730 */
731
732static u32 s32ton(__s32 value, unsigned n)
733{
734 s32 a = value >> (n - 1);
735 if (a && a != -1)
736 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
737 return value & ((1 << n) - 1);
738}
739
740/*
741 * Extract/implement a data field from/to a little endian report (bit array).
742 *
743 * Code sort-of follows HID spec:
744 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
745 *
746 * While the USB HID spec allows unlimited length bit fields in "report
747 * descriptors", most devices never use more than 16 bits.
748 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
749 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
750 */
751
Joe Perches16ee4cc2010-12-09 19:29:05 -0800752static __u32 extract(const struct hid_device *hid, __u8 *report,
753 unsigned offset, unsigned n)
Jiri Kosinadde58452006-12-08 18:40:44 +0100754{
755 u64 x;
756
Jiri Kosinac4124c92007-11-30 11:12:58 +0100757 if (n > 32)
Joe Perches4291ee32010-12-09 19:29:03 -0800758 hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
759 n, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100760
761 report += offset >> 3; /* adjust byte index */
Jiri Kosina229695e2006-12-08 18:40:53 +0100762 offset &= 7; /* now only need bit offset into one byte */
Harvey Harrisonc1050682008-04-29 01:03:31 -0700763 x = get_unaligned_le64(report);
Jiri Kosina229695e2006-12-08 18:40:53 +0100764 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
Jiri Kosinadde58452006-12-08 18:40:44 +0100765 return (u32) x;
766}
767
768/*
769 * "implement" : set bits in a little endian bit stream.
770 * Same concepts as "extract" (see comments above).
771 * The data mangled in the bit stream remains in little endian
772 * order the whole time. It make more sense to talk about
773 * endianness of register values by considering a register
774 * a "cached" copy of the little endiad bit stream.
775 */
Joe Perches16ee4cc2010-12-09 19:29:05 -0800776static void implement(const struct hid_device *hid, __u8 *report,
777 unsigned offset, unsigned n, __u32 value)
Jiri Kosinadde58452006-12-08 18:40:44 +0100778{
Harvey Harrison6f0168d2008-05-16 11:00:23 +0200779 u64 x;
Jiri Kosinadde58452006-12-08 18:40:44 +0100780 u64 m = (1ULL << n) - 1;
781
Jiri Kosinac4124c92007-11-30 11:12:58 +0100782 if (n > 32)
Joe Perches4291ee32010-12-09 19:29:03 -0800783 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
784 __func__, n, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100785
Jiri Kosinac4124c92007-11-30 11:12:58 +0100786 if (value > m)
Joe Perches4291ee32010-12-09 19:29:03 -0800787 hid_warn(hid, "%s() called with too large value %d! (%s)\n",
788 __func__, value, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100789 WARN_ON(value > m);
790 value &= m;
791
792 report += offset >> 3;
793 offset &= 7;
794
Harvey Harrison6f0168d2008-05-16 11:00:23 +0200795 x = get_unaligned_le64(report);
796 x &= ~(m << offset);
797 x |= ((u64)value) << offset;
798 put_unaligned_le64(x, report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100799}
800
801/*
802 * Search an array for a value.
803 */
804
Joe Perches16ee4cc2010-12-09 19:29:05 -0800805static int search(__s32 *array, __s32 value, unsigned n)
Jiri Kosinadde58452006-12-08 18:40:44 +0100806{
807 while (n--) {
808 if (*array++ == value)
809 return 0;
810 }
811 return -1;
812}
813
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200814/**
815 * hid_match_report - check if driver's raw_event should be called
816 *
817 * @hid: hid device
818 * @report_type: type to match against
819 *
820 * compare hid->driver->report_table->report_type to report->type
821 */
822static int hid_match_report(struct hid_device *hid, struct hid_report *report)
Jiri Kosinadde58452006-12-08 18:40:44 +0100823{
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200824 const struct hid_report_id *id = hid->driver->report_table;
825
826 if (!id) /* NULL means all */
827 return 1;
828
829 for (; id->report_type != HID_TERMINATOR; id++)
830 if (id->report_type == HID_ANY_ID ||
831 id->report_type == report->type)
832 return 1;
833 return 0;
834}
835
836/**
837 * hid_match_usage - check if driver's event should be called
838 *
839 * @hid: hid device
840 * @usage: usage to match against
841 *
842 * compare hid->driver->usage_table->usage_{type,code} to
843 * usage->usage_{type,code}
844 */
845static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
846{
847 const struct hid_usage_id *id = hid->driver->usage_table;
848
849 if (!id) /* NULL means all */
850 return 1;
851
852 for (; id->usage_type != HID_ANY_ID - 1; id++)
853 if ((id->usage_hid == HID_ANY_ID ||
854 id->usage_hid == usage->hid) &&
855 (id->usage_type == HID_ANY_ID ||
856 id->usage_type == usage->type) &&
857 (id->usage_code == HID_ANY_ID ||
858 id->usage_code == usage->code))
859 return 1;
860 return 0;
861}
862
863static void hid_process_event(struct hid_device *hid, struct hid_field *field,
864 struct hid_usage *usage, __s32 value, int interrupt)
865{
866 struct hid_driver *hdrv = hid->driver;
867 int ret;
868
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200869 hid_dump_input(hid, usage, value);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200870
871 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
872 ret = hdrv->event(hid, field, usage, value);
873 if (ret != 0) {
874 if (ret < 0)
875 dbg_hid("%s's event failed with %d\n",
876 hdrv->name, ret);
877 return;
878 }
879 }
880
Jiri Kosinadde58452006-12-08 18:40:44 +0100881 if (hid->claimed & HID_CLAIMED_INPUT)
882 hidinput_hid_event(hid, field, usage, value);
Jiri Kosinaaa938f72006-12-08 18:41:10 +0100883 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
884 hid->hiddev_hid_event(hid, field, usage, value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100885}
886
887/*
888 * Analyse a received field, and fetch the data from it. The field
889 * content is stored for next report processing (we do differential
890 * reporting to the layer).
891 */
892
Adrian Bunkabdff0f2008-03-31 01:53:56 +0200893static void hid_input_field(struct hid_device *hid, struct hid_field *field,
894 __u8 *data, int interrupt)
Jiri Kosinadde58452006-12-08 18:40:44 +0100895{
896 unsigned n;
897 unsigned count = field->report_count;
898 unsigned offset = field->report_offset;
899 unsigned size = field->report_size;
900 __s32 min = field->logical_minimum;
901 __s32 max = field->logical_maximum;
902 __s32 *value;
903
Joe Perchesa3789a172010-12-09 19:29:07 -0800904 value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
905 if (!value)
Jiri Kosinadde58452006-12-08 18:40:44 +0100906 return;
907
908 for (n = 0; n < count; n++) {
909
Joe Perches4291ee32010-12-09 19:29:03 -0800910 value[n] = min < 0 ?
911 snto32(extract(hid, data, offset + n * size, size),
912 size) :
913 extract(hid, data, offset + n * size, size);
Jiri Kosinadde58452006-12-08 18:40:44 +0100914
Joe Perches4291ee32010-12-09 19:29:03 -0800915 /* Ignore report if ErrorRollOver */
916 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
917 value[n] >= min && value[n] <= max &&
918 field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
919 goto exit;
Jiri Kosinadde58452006-12-08 18:40:44 +0100920 }
921
922 for (n = 0; n < count; n++) {
923
924 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
925 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
926 continue;
927 }
928
929 if (field->value[n] >= min && field->value[n] <= max
930 && field->usage[field->value[n] - min].hid
931 && search(value, field->value[n], count))
932 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
933
934 if (value[n] >= min && value[n] <= max
935 && field->usage[value[n] - min].hid
936 && search(field->value, value[n], count))
937 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
938 }
939
940 memcpy(field->value, value, count * sizeof(__s32));
941exit:
942 kfree(value);
943}
Jiri Kosinadde58452006-12-08 18:40:44 +0100944
945/*
946 * Output the field into the report.
947 */
948
Joe Perches4291ee32010-12-09 19:29:03 -0800949static void hid_output_field(const struct hid_device *hid,
950 struct hid_field *field, __u8 *data)
Jiri Kosinadde58452006-12-08 18:40:44 +0100951{
952 unsigned count = field->report_count;
953 unsigned offset = field->report_offset;
954 unsigned size = field->report_size;
955 unsigned n;
956
957 for (n = 0; n < count; n++) {
958 if (field->logical_minimum < 0) /* signed values */
Joe Perches4291ee32010-12-09 19:29:03 -0800959 implement(hid, data, offset + n * size, size,
960 s32ton(field->value[n], size));
Jiri Kosinadde58452006-12-08 18:40:44 +0100961 else /* unsigned values */
Joe Perches4291ee32010-12-09 19:29:03 -0800962 implement(hid, data, offset + n * size, size,
963 field->value[n]);
Jiri Kosinadde58452006-12-08 18:40:44 +0100964 }
965}
966
967/*
968 * Create a report.
969 */
970
Jiri Kosina229695e2006-12-08 18:40:53 +0100971void hid_output_report(struct hid_report *report, __u8 *data)
Jiri Kosinadde58452006-12-08 18:40:44 +0100972{
973 unsigned n;
974
975 if (report->id > 0)
976 *data++ = report->id;
977
Pete Zaitcev75c28df2010-04-12 12:16:11 -0600978 memset(data, 0, ((report->size - 1) >> 3) + 1);
Jiri Kosinadde58452006-12-08 18:40:44 +0100979 for (n = 0; n < report->maxfield; n++)
Joe Perches4291ee32010-12-09 19:29:03 -0800980 hid_output_field(report->device, report->field[n], data);
Jiri Kosinadde58452006-12-08 18:40:44 +0100981}
Jiri Kosina229695e2006-12-08 18:40:53 +0100982EXPORT_SYMBOL_GPL(hid_output_report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100983
984/*
985 * Set a field value. The report this field belongs to has to be
986 * created and transferred to the device, to set this value in the
987 * device.
988 */
989
990int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
991{
992 unsigned size = field->report_size;
993
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200994 hid_dump_input(field->report->device, field->usage + offset, value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100995
996 if (offset >= field->report_count) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200997 dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
Jiri Kosinadde58452006-12-08 18:40:44 +0100998 return -1;
999 }
1000 if (field->logical_minimum < 0) {
1001 if (value != snto32(s32ton(value, size), size)) {
Jiri Kosina58037eb2007-05-30 15:07:13 +02001002 dbg_hid("value %d is out of range\n", value);
Jiri Kosinadde58452006-12-08 18:40:44 +01001003 return -1;
1004 }
1005 }
1006 field->value[offset] = value;
1007 return 0;
1008}
Jiri Kosina229695e2006-12-08 18:40:53 +01001009EXPORT_SYMBOL_GPL(hid_set_field);
Jiri Kosinadde58452006-12-08 18:40:44 +01001010
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001011static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1012 const u8 *data)
1013{
1014 struct hid_report *report;
1015 unsigned int n = 0; /* Normally report number is 0 */
1016
1017 /* Device uses numbered reports, data[0] is report number */
1018 if (report_enum->numbered)
1019 n = *data;
1020
1021 report = report_enum->report_id_hash[n];
1022 if (report == NULL)
1023 dbg_hid("undefined report_id %u received\n", n);
1024
1025 return report;
1026}
1027
1028void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1029 int interrupt)
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001030{
1031 struct hid_report_enum *report_enum = hid->report_enum + type;
1032 struct hid_report *report;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001033 unsigned int a;
1034 int rsize, csize = size;
1035 u8 *cdata = data;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001036
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001037 report = hid_get_report(report_enum, data);
1038 if (!report)
1039 return;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001040
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001041 if (report_enum->numbered) {
1042 cdata++;
1043 csize--;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001044 }
1045
1046 rsize = ((report->size - 1) >> 3) + 1;
1047
Armando Visconti966922f2011-05-19 21:41:22 +02001048 if (rsize > HID_MAX_BUFFER_SIZE)
1049 rsize = HID_MAX_BUFFER_SIZE;
1050
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001051 if (csize < rsize) {
1052 dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1053 csize, rsize);
1054 memset(cdata + csize, 0, rsize - csize);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001055 }
1056
1057 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1058 hid->hiddev_report_event(hid, report);
Alan Ott5a38f2c2010-04-26 18:34:46 -04001059 if (hid->claimed & HID_CLAIMED_HIDRAW)
1060 hidraw_report_event(hid, data, size);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001061
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001062 for (a = 0; a < report->maxfield; a++)
1063 hid_input_field(hid, report->field[a], cdata, interrupt);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001064
1065 if (hid->claimed & HID_CLAIMED_INPUT)
1066 hidinput_report_event(hid, report);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001067}
1068EXPORT_SYMBOL_GPL(hid_report_raw_event);
1069
1070/**
1071 * hid_input_report - report data from lower layer (usb, bt...)
1072 *
1073 * @hid: hid device
1074 * @type: HID report type (HID_*_REPORT)
1075 * @data: report contents
1076 * @size: size of data parameter
Jiri Kosinaff9b00a2009-10-01 16:03:13 +02001077 * @interrupt: distinguish between interrupt and control transfers
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001078 *
1079 * This is data entry for lower layers.
1080 */
1081int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1082{
Julia Lawall76c317d2009-07-19 17:26:13 +02001083 struct hid_report_enum *report_enum;
1084 struct hid_driver *hdrv;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001085 struct hid_report *report;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001086 char *buf;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001087 unsigned int i;
1088 int ret;
1089
1090 if (!hid || !hid->driver)
1091 return -ENODEV;
Julia Lawall76c317d2009-07-19 17:26:13 +02001092 report_enum = hid->report_enum + type;
1093 hdrv = hid->driver;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001094
1095 if (!size) {
1096 dbg_hid("empty report\n");
1097 return -1;
1098 }
1099
Jiri Kosinad1ff6522009-09-15 11:59:49 +02001100 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001101
Jiri Kosinaf77e3472010-03-18 14:11:53 +01001102 if (!buf)
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001103 goto nomem;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001104
1105 /* dump the report */
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001106 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
Jiri Kosina1caea612010-03-18 12:09:53 +01001107 "\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001108 hid_debug_event(hid, buf);
Jiri Kosina1caea612010-03-18 12:09:53 +01001109
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001110 for (i = 0; i < size; i++) {
1111 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1112 " %02x", data[i]);
1113 hid_debug_event(hid, buf);
1114 }
1115 hid_debug_event(hid, "\n");
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001116 kfree(buf);
1117
1118nomem:
Jiri Kosinaf77e3472010-03-18 14:11:53 +01001119 report = hid_get_report(report_enum, data);
1120
1121 if (!report)
1122 return -1;
1123
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001124 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1125 ret = hdrv->raw_event(hid, report, data, size);
1126 if (ret != 0)
1127 return ret < 0 ? ret : 0;
1128 }
1129
1130 hid_report_raw_event(hid, type, data, size, interrupt);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001131
1132 return 0;
1133}
1134EXPORT_SYMBOL_GPL(hid_input_report);
1135
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001136static bool hid_match_one_id(struct hid_device *hdev,
1137 const struct hid_device_id *id)
1138{
1139 return id->bus == hdev->bus &&
1140 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1141 (id->product == HID_ANY_ID || id->product == hdev->product);
1142}
1143
1144static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1145 const struct hid_device_id *id)
1146{
1147 for (; id->bus; id++)
1148 if (hid_match_one_id(hdev, id))
1149 return id;
1150
1151 return NULL;
1152}
1153
1154static const struct hid_device_id hid_hiddev_list[] = {
Richard Hughesc0bd6a42008-08-27 11:19:37 +02001155 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1156 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001157 { }
1158};
1159
1160static bool hid_hiddev(struct hid_device *hdev)
1161{
1162 return !!hid_match_id(hdev, hid_hiddev_list);
1163}
1164
Alan Ott6d3bfb72011-01-23 22:50:18 -05001165
1166static ssize_t
1167read_report_descriptor(struct file *filp, struct kobject *kobj,
1168 struct bin_attribute *attr,
1169 char *buf, loff_t off, size_t count)
1170{
1171 struct device *dev = container_of(kobj, struct device, kobj);
1172 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1173
1174 if (off >= hdev->rsize)
1175 return 0;
1176
1177 if (off + count > hdev->rsize)
1178 count = hdev->rsize - off;
1179
1180 memcpy(buf, hdev->rdesc + off, count);
1181
1182 return count;
1183}
1184
1185static struct bin_attribute dev_bin_attr_report_desc = {
1186 .attr = { .name = "report_descriptor", .mode = 0444 },
1187 .read = read_report_descriptor,
1188 .size = HID_MAX_DESCRIPTOR_SIZE,
1189};
1190
Jiri Slaby93c10132008-06-27 00:04:24 +02001191int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1192{
1193 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1194 "Joystick", "Gamepad", "Keyboard", "Keypad",
1195 "Multi-Axis Controller"
1196 };
1197 const char *type, *bus;
1198 char buf[64];
1199 unsigned int i;
1200 int len;
Alan Ott6d3bfb72011-01-23 22:50:18 -05001201 int ret;
Jiri Slaby93c10132008-06-27 00:04:24 +02001202
Bastien Nocerab5e5a372010-04-16 17:19:50 +01001203 if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1204 connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
Daniel Mack3a343ee2010-07-12 19:28:27 +02001205 if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
1206 connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
Jiri Slaby93c10132008-06-27 00:04:24 +02001207 if (hdev->bus != BUS_USB)
1208 connect_mask &= ~HID_CONNECT_HIDDEV;
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001209 if (hid_hiddev(hdev))
1210 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
Jiri Slaby93c10132008-06-27 00:04:24 +02001211
1212 if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1213 connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1214 hdev->claimed |= HID_CLAIMED_INPUT;
1215 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1216 !hdev->hiddev_connect(hdev,
1217 connect_mask & HID_CONNECT_HIDDEV_FORCE))
1218 hdev->claimed |= HID_CLAIMED_HIDDEV;
1219 if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1220 hdev->claimed |= HID_CLAIMED_HIDRAW;
1221
1222 if (!hdev->claimed) {
Joe Perches4291ee32010-12-09 19:29:03 -08001223 hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
Jiri Slaby93c10132008-06-27 00:04:24 +02001224 return -ENODEV;
1225 }
1226
1227 if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1228 (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1229 hdev->ff_init(hdev);
1230
1231 len = 0;
1232 if (hdev->claimed & HID_CLAIMED_INPUT)
1233 len += sprintf(buf + len, "input");
1234 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1235 len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1236 hdev->minor);
1237 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1238 len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1239 ((struct hidraw *)hdev->hidraw)->minor);
1240
1241 type = "Device";
1242 for (i = 0; i < hdev->maxcollection; i++) {
1243 struct hid_collection *col = &hdev->collection[i];
1244 if (col->type == HID_COLLECTION_APPLICATION &&
1245 (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1246 (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1247 type = types[col->usage & 0xffff];
1248 break;
1249 }
1250 }
1251
1252 switch (hdev->bus) {
1253 case BUS_USB:
1254 bus = "USB";
1255 break;
1256 case BUS_BLUETOOTH:
1257 bus = "BLUETOOTH";
1258 break;
1259 default:
1260 bus = "<UNKNOWN>";
1261 }
1262
Alan Ott6d3bfb72011-01-23 22:50:18 -05001263 ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1264 if (ret)
1265 hid_warn(hdev,
1266 "can't create sysfs report descriptor attribute err: %d\n", ret);
1267
Joe Perches4291ee32010-12-09 19:29:03 -08001268 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1269 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1270 type, hdev->name, hdev->phys);
Jiri Slaby93c10132008-06-27 00:04:24 +02001271
1272 return 0;
1273}
1274EXPORT_SYMBOL_GPL(hid_connect);
1275
Jiri Kosinac4c259b2009-09-15 16:27:45 +02001276void hid_disconnect(struct hid_device *hdev)
1277{
Alan Ott6d3bfb72011-01-23 22:50:18 -05001278 device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
Jiri Kosinac4c259b2009-09-15 16:27:45 +02001279 if (hdev->claimed & HID_CLAIMED_INPUT)
1280 hidinput_disconnect(hdev);
1281 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1282 hdev->hiddev_disconnect(hdev);
1283 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1284 hidraw_disconnect(hdev);
1285}
1286EXPORT_SYMBOL_GPL(hid_disconnect);
1287
Jiri Kosinabae7eb32009-01-28 23:06:37 +01001288/* a list of devices for which there is a specialized driver on HID bus */
Dmitry Torokhovce06b9d2010-11-28 16:37:14 +01001289static const struct hid_device_id hid_have_special_driver[] = {
Stephane Chattyb6353f42009-12-22 23:04:17 +01001290 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
Stephane Chatty6dec1432010-04-11 14:51:24 +02001291 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
Jiri Slaby14a21cd2008-06-23 23:31:09 +02001292 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1293 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
Lech Perczakb7e1b202010-09-16 23:19:33 +02001294 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +02001295 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
Benjamin Tissoirese6aac342011-05-19 14:18:13 +02001296 { HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, USB_DEVICE_ID_ACTIONSTAR_1011) },
Jiri Kosinadf9bcac2008-10-14 22:45:40 +02001297 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001298 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1299 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
Michael Poole128537c2010-02-06 12:24:36 -05001300 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
Chase Douglasa4622302010-08-31 21:56:23 -04001301 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001302 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1303 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1304 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1305 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1306 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1307 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1308 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1309 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1310 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1311 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1312 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
Ryan Finniefef3f572009-03-05 10:18:01 +01001313 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1314 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1315 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001316 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1317 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1318 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1319 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1320 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1321 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
Jan Scholzee8a1a02008-11-26 15:33:45 +01001322 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1323 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1324 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001325 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1327 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1328 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1330 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +01001331 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1332 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1333 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -04001334 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1339 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
Andy Botting47340bd2011-03-12 20:27:22 -08001340 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +01001343 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1344 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1345 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001346 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
Jiri Kosinaeaca1382010-09-08 14:31:47 +02001348 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
Roland Baumcec15a02010-09-08 14:27:55 +02001349 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
Jiri Slabyb5635b12008-06-24 23:24:57 +02001350 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
Wayne Thomasbf280622010-04-29 00:45:01 +02001351 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
Jiri Kosinac3dc66d2010-08-30 15:43:25 +02001352 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001353 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
Stephane Chatty36213e12010-04-15 00:28:11 +02001354 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
Benjamin Tissoiresbc5ab082011-01-08 12:15:41 +01001355 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) },
Stephane Chattyba4d8ab2010-04-22 23:24:36 +02001356 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
François Jaouen272036e2010-10-13 10:47:32 +02001357 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
Jiri Slaby3b239cd2008-06-24 20:42:25 +02001358 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
Raphaël Doursenaud1ce31b22010-04-08 13:40:52 +02001359 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
Jiri Slabyfcfacfd2008-06-24 22:48:52 +02001360 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
Dennis Küglerb9e4b1e2010-11-23 21:40:09 +01001361 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
Austin Zhang942fd422011-05-28 02:03:47 +08001362 { HID_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT, USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
Don Prince3a370ca2010-05-12 15:18:59 +02001363 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
Benjamin Tissoires79603dc2011-05-19 14:18:14 +02001364 { HID_USB_DEVICE(USB_VENDOR_ID_CVTOUCH, USB_DEVICE_ID_CVTOUCH_SCREEN) },
Jiri Slaby0f221322008-06-23 22:54:08 +02001365 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1366 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
Jiri Kosinae8d0eab2009-12-02 22:54:11 +01001367 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
Jiri Slaby0f221322008-06-23 22:54:08 +02001368 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
Benjamin Tissoiresa3b5e572011-01-07 23:46:30 +01001369 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
Richard Walmsley3f866fb2009-03-04 22:12:04 +13001370 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
Nikolai Kondrashove05eefb2011-01-28 14:50:52 +03001371 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
Stephane Chatty0c3910c2010-04-10 16:43:08 +02001372 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
Chris Ball83e44912010-08-16 16:01:28 +02001373 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
Henrik Rydberg4e93db22010-11-29 07:27:49 +01001374 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) },
Richard Nauber28906ad2010-12-14 22:36:18 +01001375 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) },
Andy Ross4dd295a2010-12-16 15:53:19 -08001376 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) },
Richard Nauber64b386e2010-06-28 18:54:25 +02001377 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
Benjamin Tissoiresc04abee2011-05-19 11:37:29 +02001378 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) },
Ignaz Forster04561c52010-11-01 15:13:37 -04001379 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
Jiri Slaby1f243e32008-06-24 21:11:21 +02001380 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
Jiri Kosina5181e592008-11-17 01:44:38 +01001381 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
Jiri Kosina578f3a32008-11-20 15:55:38 +01001382 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
Benjamin Tissoires5572da02011-01-07 23:47:27 +01001383 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) },
Benjamin Tissoiresee0fbd12011-05-19 14:18:15 +02001384 { HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, USB_DEVICE_ID_GOODTOUCH_000f) },
Jiri Kosina5181e592008-11-17 01:44:38 +01001385 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
Lukasz Lubojanski42859e02008-12-11 22:07:59 +01001386 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
Jiri Slaby949f8fe2008-07-24 23:35:13 +02001387 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
Jiri Kosina1e093202008-10-17 11:52:23 +02001388 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
Cory Maccarronec2fd1a42010-05-22 13:00:28 -07001389 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
Benjamin Tissoires5519cab2011-01-07 23:45:50 +01001390 { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
Anssi Hannulad946e652011-06-27 00:07:31 +03001391 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
Austin Zhang4e61f0d2011-05-09 23:54:14 +08001392 { HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
Benjamin Tissoiresb2e76172011-02-15 15:33:48 +01001393 { HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
Jiri Kosinafdf93aa2009-03-04 16:09:40 +01001394 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
Jiri Kosina177900e2011-02-17 15:12:45 +01001395 { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
Jiri Kosina79422742009-03-11 11:43:27 +01001396 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
Jiri Slabyb5635b12008-06-24 23:24:57 +02001397 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
Chris Schlund75b07022011-02-03 16:41:47 +01001398 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001399 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1400 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1401 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1402 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1403 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1404 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1405 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001406 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1407 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001408 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1409 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
Hendrik Iben2c6118e2010-10-04 15:39:49 +02001410 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001411 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
Jiri Kosinafd30ea82009-06-23 12:11:31 +02001414 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001415 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
Gary Stein74f292c2010-01-13 00:25:58 +01001416 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001417 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1418 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
Jiri Kosina5623a242011-03-17 00:43:23 +01001419 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
Christophe Borivant243b7062009-04-17 11:39:39 +02001420 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
Peter Gundermannfdc68072011-05-03 10:15:03 +02001421 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
Nestor Lopez Casado534a7b82011-09-15 11:34:49 +02001422 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
1423 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
Simon Wood32c88cb2010-09-22 13:19:42 +02001424 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001425 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
Jiri Kosina24985cf2009-11-13 10:45:53 +01001426 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
1427 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
Benjamin Tissoiresdf167c42011-05-18 15:27:24 +02001428 { HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH) },
Benjamin Tissoiresc3ead6d2011-06-21 15:01:55 +02001429 { HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
Bruno Prémont236db472010-03-30 22:33:50 +02001430 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1431 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
Jiri Kosinab5801692011-07-22 12:11:15 +02001432 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
Jiri Slaby78a849a2008-06-20 21:26:11 +02001433 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1434 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1435 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1436 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
Jiri Kosinaf3b83d72011-06-13 23:08:18 +03001437 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
Jiri Slaby78a849a2008-06-20 21:26:11 +02001438 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
Jiri Slaby3b8006e2008-06-25 00:07:50 +02001439 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
Rafi Rubin94011f92008-11-19 15:54:46 +01001440 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
micki6e328192010-06-19 11:37:29 +03001441 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
1442 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
1443 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
1444 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
1445 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
1446 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
1447 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
1448 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
1449 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
1450 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
1451 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
1452 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
1453 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
1454 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
1455 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
1456 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
1457 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
1458 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
Herton Ronaldo Krzesinski270fdc02011-03-16 14:13:53 -03001459 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
Johnathon Harriscd9ec302010-01-21 14:36:52 +00001460 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
John Sung6ab3a9a2011-04-21 16:21:52 +02001461 { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) },
Jiri Slaby1e762532008-06-24 23:46:21 +02001462 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
Stephane Chatty49e47392010-01-13 00:29:16 +01001463 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
Alex Neblettf54405d2010-02-02 21:16:03 -08001464 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
Stefan Achatz14bf62c2010-03-18 16:19:43 +01001465 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
Stefan Achatze68cc602011-01-06 09:00:34 +01001466 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
Stefan Achatz47dbdbf2010-11-26 19:57:42 +00001467 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
Stefan Achatz0e70f972011-01-30 13:38:24 +01001468 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
Stefan Achatzcb7cf3d2010-08-29 12:30:18 +02001469 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
Stefan Achatz3fce2242011-03-23 18:11:36 +01001470 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
Jiri Slaby980a3da2008-06-25 22:31:48 +02001471 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
Don Princeb3558502010-05-17 11:42:39 +01001472 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
Jiri Kosinad586dca2011-03-21 13:54:22 +01001473 { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
Jiri Slabybd28ce02008-06-25 23:47:04 +02001474 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
Jiri Kosina35dca5b2011-04-28 15:43:13 +02001475 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
Bastien Noceraf9ce7c22010-01-20 12:01:53 +00001476 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +02001477 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
Stephane Chattyd3fb5452010-01-04 12:04:08 +01001478 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
Pascal Auriel - Stantumb6dc7992010-10-01 16:01:28 +02001479 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1480 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
Jiri Slaby90231e72008-06-23 21:56:07 +02001481 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001482 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1483 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
Ruben Aos Garralda7a84b132009-06-29 09:41:29 +02001484 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
1485 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001486 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
Markus Rathgeb3ee8f0a2010-03-13 17:29:43 +01001487 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001488 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
Simon Woodd65c3762010-11-29 17:41:23 +01001489 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
Lev Babievf14f5262009-01-04 00:36:56 +01001490 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
Kees Bakker54001082010-07-13 22:50:51 +02001491 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
Benjamin Tissoires5e74e562011-05-19 14:18:16 +02001492 { HID_USB_DEVICE(USB_VENDOR_ID_TOUCH_INTL, USB_DEVICE_ID_TOUCH_INTL_MULTI_TOUCH) },
Bruno Premont711a6802009-07-13 14:19:58 +02001493 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
Benjamin Tissoiresc64f6f92011-01-08 12:15:42 +01001494 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) },
Nikolai Kondrashov41fa9232010-08-23 15:09:01 +04001495 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001496 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1497 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1498 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
Nikolai Kondrashov6be914f2011-07-06 09:23:41 +03001499 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
Benjamin Tissoires617b64f2011-05-19 14:18:17 +02001500 { HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0709) },
1501 { HID_USB_DEVICE(USB_VENDOR_ID_UNITEC, USB_DEVICE_ID_UNITEC_USB_TOUCH_0A19) },
Jussi Kivilinnafac733f2009-05-13 11:54:38 +03001502 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
Bastien Noceraca2dcd42009-05-11 17:18:12 +02001503 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Nikolai Kondrashov72a46342010-08-20 19:21:11 +04001504 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
Nikolai Kondrashov00e7f962010-09-25 23:16:58 +04001505 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
Nikolai Kondrashov72a46342010-08-20 19:21:11 +04001506 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
Nikolai Kondrashov8f1acc32010-08-30 14:06:36 +04001507 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
ice chienbc8a2a92011-07-15 16:58:06 +08001508 { HID_USB_DEVICE(USB_VENDOR_ID_XAT, USB_DEVICE_ID_XAT_CSR) },
Stefan Kriwanek74bc6952011-05-27 18:40:29 +02001509 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001510 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1511 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
Don Princea9885c82010-05-14 17:30:59 +01001512 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001513
Jiri Slaby78a849a2008-06-20 21:26:11 +02001514 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
David Herrmann02fb72a2011-07-05 13:45:09 +02001515 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001516 { }
1517};
1518
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001519struct hid_dynid {
1520 struct list_head list;
1521 struct hid_device_id id;
1522};
1523
1524/**
1525 * store_new_id - add a new HID device ID to this driver and re-probe devices
1526 * @driver: target device driver
1527 * @buf: buffer for scanning device ID data
1528 * @count: input size
1529 *
1530 * Adds a new dynamic hid device ID to this driver,
1531 * and causes the driver to probe for all devices again.
1532 */
1533static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1534 size_t count)
1535{
1536 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1537 struct hid_dynid *dynid;
1538 __u32 bus, vendor, product;
1539 unsigned long driver_data = 0;
1540 int ret;
1541
1542 ret = sscanf(buf, "%x %x %x %lx",
1543 &bus, &vendor, &product, &driver_data);
1544 if (ret < 3)
1545 return -EINVAL;
1546
1547 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
1548 if (!dynid)
1549 return -ENOMEM;
1550
1551 dynid->id.bus = bus;
1552 dynid->id.vendor = vendor;
1553 dynid->id.product = product;
1554 dynid->id.driver_data = driver_data;
1555
1556 spin_lock(&hdrv->dyn_lock);
1557 list_add_tail(&dynid->list, &hdrv->dyn_list);
1558 spin_unlock(&hdrv->dyn_lock);
1559
1560 ret = 0;
1561 if (get_driver(&hdrv->driver)) {
1562 ret = driver_attach(&hdrv->driver);
1563 put_driver(&hdrv->driver);
1564 }
1565
1566 return ret ? : count;
1567}
1568static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
1569
1570static void hid_free_dynids(struct hid_driver *hdrv)
1571{
1572 struct hid_dynid *dynid, *n;
1573
1574 spin_lock(&hdrv->dyn_lock);
1575 list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
1576 list_del(&dynid->list);
1577 kfree(dynid);
1578 }
1579 spin_unlock(&hdrv->dyn_lock);
1580}
1581
1582static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
1583 struct hid_driver *hdrv)
1584{
1585 struct hid_dynid *dynid;
1586
1587 spin_lock(&hdrv->dyn_lock);
1588 list_for_each_entry(dynid, &hdrv->dyn_list, list) {
1589 if (hid_match_one_id(hdev, &dynid->id)) {
1590 spin_unlock(&hdrv->dyn_lock);
1591 return &dynid->id;
1592 }
1593 }
1594 spin_unlock(&hdrv->dyn_lock);
1595
1596 return hid_match_id(hdev, hdrv->id_table);
1597}
1598
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001599static int hid_bus_match(struct device *dev, struct device_driver *drv)
1600{
1601 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1602 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1603
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001604 if (!hid_match_device(hdev, hdrv))
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001605 return 0;
1606
Dmitry Torokhovce06b9d2010-11-28 16:37:14 +01001607 /* generic wants all that don't have specialized driver */
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001608 if (!strncmp(hdrv->name, "generic-", 8))
Dmitry Torokhovce06b9d2010-11-28 16:37:14 +01001609 return !hid_match_id(hdev, hid_have_special_driver);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001610
1611 return 1;
1612}
1613
1614static int hid_device_probe(struct device *dev)
1615{
1616 struct hid_driver *hdrv = container_of(dev->driver,
1617 struct hid_driver, driver);
1618 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1619 const struct hid_device_id *id;
1620 int ret = 0;
1621
1622 if (!hdev->driver) {
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001623 id = hid_match_device(hdev, hdrv);
Jiri Slabyc500c972008-05-16 11:49:16 +02001624 if (id == NULL)
1625 return -ENODEV;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001626
Jiri Slabyc500c972008-05-16 11:49:16 +02001627 hdev->driver = hdrv;
1628 if (hdrv->probe) {
1629 ret = hdrv->probe(hdev, id);
1630 } else { /* default probe */
1631 ret = hid_parse(hdev);
1632 if (!ret)
Jiri Slaby93c10132008-06-27 00:04:24 +02001633 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001634 }
Jiri Slabyc500c972008-05-16 11:49:16 +02001635 if (ret)
1636 hdev->driver = NULL;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001637 }
1638 return ret;
1639}
1640
1641static int hid_device_remove(struct device *dev)
1642{
1643 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1644 struct hid_driver *hdrv = hdev->driver;
1645
1646 if (hdrv) {
1647 if (hdrv->remove)
1648 hdrv->remove(hdev);
Jiri Slabyc500c972008-05-16 11:49:16 +02001649 else /* default remove */
1650 hid_hw_stop(hdev);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001651 hdev->driver = NULL;
1652 }
1653
1654 return 0;
1655}
1656
1657static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1658{
1659 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1660
1661 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1662 hdev->bus, hdev->vendor, hdev->product))
1663 return -ENOMEM;
1664
1665 if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1666 return -ENOMEM;
1667
1668 if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1669 return -ENOMEM;
1670
1671 if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1672 return -ENOMEM;
1673
1674 if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
1675 hdev->bus, hdev->vendor, hdev->product))
1676 return -ENOMEM;
1677
1678 return 0;
1679}
1680
1681static struct bus_type hid_bus_type = {
1682 .name = "hid",
1683 .match = hid_bus_match,
1684 .probe = hid_device_probe,
1685 .remove = hid_device_remove,
1686 .uevent = hid_uevent,
1687};
1688
Jiri Kosinabae7eb32009-01-28 23:06:37 +01001689/* a list of devices that shouldn't be handled by HID core at all */
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001690static const struct hid_device_id hid_ignore_list[] = {
1691 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1692 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1693 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1694 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1695 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1696 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1697 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1698 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1699 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1700 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1701 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1702 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
Stephane Chatty77f720b2010-02-06 15:17:13 +01001703 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1704 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
Alexey Klimov62a56582008-11-13 05:44:50 +03001705 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001706 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1707 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1708 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1709 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1710 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1711 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
Alexey Klimov5f6108c2008-12-08 12:40:14 +01001712 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001713 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1714 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
Melchior FRANZ73bc7d32010-12-22 02:04:33 +01001715 { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001716 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
Petr Å tetiar70c66562009-12-09 22:09:53 +01001717 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
Petr Å tetiardf506f22010-06-28 09:38:54 -07001718 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001719 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1720 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1721 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1722 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1723 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1724 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1725 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1726 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1727 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1728 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1729 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1730 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1731 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1732 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1733 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1734 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1735 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1736 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1737 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1738 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1739 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1740 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1741 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1742 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1743 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1744 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1745 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1746 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1747 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1748 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1749 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1750 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1751 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1752 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1753 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1754 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1755 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1756 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1757 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1758 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1759 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1760 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1761 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1762 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1763 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1764 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1765 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1766 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1767 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1768 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1769 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1770 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1771 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1772 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1773 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1774 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1775 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1776 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1777 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1778 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1779 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1780 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1781 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1782 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1783 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
Alexey Klimovc91c21c2008-11-13 10:36:11 +01001784 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001785 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
Lamarque Vieira Souzaeb8141c2009-10-02 15:04:44 +02001786 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001787 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
Michael Hundce97cac2011-05-03 10:12:00 -07001788 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001789 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
Michael Hundce97cac2011-05-03 10:12:00 -07001790 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001791 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
Michael Hundce97cac2011-05-03 10:12:00 -07001792 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
1793 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
1794 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
1795 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
1796 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
1797 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001798 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1799 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1800 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
Michael Hundce97cac2011-05-03 10:12:00 -07001801 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
1802 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
1803 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001804 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1805 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
Michael Hundce97cac2011-05-03 10:12:00 -07001806 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001807 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1808 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1809 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1810 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1811 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
Michael Hundce97cac2011-05-03 10:12:00 -07001812 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
1813 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
1814 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
1815 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
1816 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
1817 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
1818 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001819 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1820 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001821 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1822 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1823 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1824 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1825 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1826 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1827 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1828 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1829 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1830 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1831 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1832 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1833 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1834 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1835 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1836 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1837 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
Henning Glawe4cfae3e2009-08-02 22:18:12 +02001838 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
Michael Tokarev35cfd1d2009-02-01 16:11:04 +01001839 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001840 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1841 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1842 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1843 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1844 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1845 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1846 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1847 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1848 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1849 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1850 { }
1851};
1852
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001853/**
1854 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1855 *
1856 * There are composite devices for which we want to ignore only a certain
1857 * interface. This is a list of devices for which only the mouse interface will
1858 * be ignored. This allows a dedicated driver to take care of the interface.
1859 */
1860static const struct hid_device_id hid_mouse_ignore_list[] = {
1861 /* appletouch driver */
1862 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1863 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1864 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1865 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1866 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1867 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1868 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1869 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1870 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1871 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1872 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1873 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1874 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1875 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1876 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1877 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1878 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1879 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1880 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1881 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
Jiri Kosinaac26fca2008-11-20 11:27:02 +01001882 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1883 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1884 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -04001885 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1886 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1887 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1888 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1889 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1890 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
Andy Botting47340bd2011-03-12 20:27:22 -08001891 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1892 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1893 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001894 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1895 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1896 { }
1897};
1898
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001899static bool hid_ignore(struct hid_device *hdev)
1900{
1901 switch (hdev->vendor) {
1902 case USB_VENDOR_ID_CODEMERCS:
1903 /* ignore all Code Mercenaries IOWarrior devices */
1904 if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1905 hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1906 return true;
1907 break;
1908 case USB_VENDOR_ID_LOGITECH:
1909 if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1910 hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1911 return true;
1912 break;
Jarod Wilson31f7fd72009-07-31 10:56:36 -04001913 case USB_VENDOR_ID_SOUNDGRAPH:
1914 if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
1915 hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
1916 return true;
1917 break;
Xing Weibba53942010-09-01 23:25:35 -07001918 case USB_VENDOR_ID_HANWANG:
1919 if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
1920 hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
1921 return true;
1922 break;
Tomoki Sekiyama6dc14182011-05-23 15:45:44 -07001923 case USB_VENDOR_ID_JESS:
1924 if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
1925 hdev->type == HID_TYPE_USBNONE)
1926 return true;
1927 break;
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001928 }
1929
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001930 if (hdev->type == HID_TYPE_USBMOUSE &&
1931 hid_match_id(hdev, hid_mouse_ignore_list))
1932 return true;
1933
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001934 return !!hid_match_id(hdev, hid_ignore_list);
1935}
1936
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001937int hid_add_device(struct hid_device *hdev)
1938{
1939 static atomic_t id = ATOMIC_INIT(0);
1940 int ret;
1941
1942 if (WARN_ON(hdev->status & HID_STAT_ADDED))
1943 return -EBUSY;
1944
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001945 /* we need to kill them here, otherwise they will stay allocated to
1946 * wait for coming driver */
Jindrich Makovickae5a2a042010-06-03 12:50:42 +02001947 if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1948 && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001949 return -ENODEV;
1950
Kay Sievers6bbe5862008-10-31 00:12:32 +01001951 /* XXX hack, any other cleaner solution after the driver core
1952 * is converted to allow more than 20 bytes as the device name? */
1953 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
1954 hdev->vendor, hdev->product, atomic_inc_return(&id));
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001955
Bruno Prémont4da361b2010-03-15 14:55:40 +01001956 hid_debug_register(hdev, dev_name(&hdev->dev));
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001957 ret = device_add(&hdev->dev);
1958 if (!ret)
1959 hdev->status |= HID_STAT_ADDED;
Bruno Prémont4da361b2010-03-15 14:55:40 +01001960 else
1961 hid_debug_unregister(hdev);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001962
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001963 return ret;
1964}
1965EXPORT_SYMBOL_GPL(hid_add_device);
1966
1967/**
1968 * hid_allocate_device - allocate new hid device descriptor
1969 *
1970 * Allocate and initialize hid device, so that hid_destroy_device might be
1971 * used to free it.
1972 *
1973 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1974 * error value.
1975 */
1976struct hid_device *hid_allocate_device(void)
1977{
1978 struct hid_device *hdev;
1979 unsigned int i;
1980 int ret = -ENOMEM;
1981
1982 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
1983 if (hdev == NULL)
1984 return ERR_PTR(ret);
1985
1986 device_initialize(&hdev->dev);
1987 hdev->dev.release = hid_device_release;
1988 hdev->dev.bus = &hid_bus_type;
1989
1990 hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
1991 sizeof(struct hid_collection), GFP_KERNEL);
1992 if (hdev->collection == NULL)
1993 goto err;
1994 hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
1995
1996 for (i = 0; i < HID_REPORT_TYPES; i++)
1997 INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
1998
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001999 init_waitqueue_head(&hdev->debug_wait);
2000 INIT_LIST_HEAD(&hdev->debug_list);
2001
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002002 return hdev;
2003err:
2004 put_device(&hdev->dev);
2005 return ERR_PTR(ret);
2006}
2007EXPORT_SYMBOL_GPL(hid_allocate_device);
2008
2009static void hid_remove_device(struct hid_device *hdev)
2010{
2011 if (hdev->status & HID_STAT_ADDED) {
2012 device_del(&hdev->dev);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02002013 hid_debug_unregister(hdev);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002014 hdev->status &= ~HID_STAT_ADDED;
2015 }
2016}
2017
2018/**
2019 * hid_destroy_device - free previously allocated device
2020 *
2021 * @hdev: hid device
2022 *
2023 * If you allocate hid_device through hid_allocate_device, you should ever
2024 * free by this function.
2025 */
2026void hid_destroy_device(struct hid_device *hdev)
2027{
2028 hid_remove_device(hdev);
2029 put_device(&hdev->dev);
2030}
2031EXPORT_SYMBOL_GPL(hid_destroy_device);
2032
2033int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
2034 const char *mod_name)
2035{
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01002036 int ret;
2037
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002038 hdrv->driver.name = hdrv->name;
2039 hdrv->driver.bus = &hid_bus_type;
2040 hdrv->driver.owner = owner;
2041 hdrv->driver.mod_name = mod_name;
2042
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01002043 INIT_LIST_HEAD(&hdrv->dyn_list);
2044 spin_lock_init(&hdrv->dyn_lock);
2045
2046 ret = driver_register(&hdrv->driver);
2047 if (ret)
2048 return ret;
2049
2050 ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
2051 if (ret)
2052 driver_unregister(&hdrv->driver);
2053
2054 return ret;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002055}
2056EXPORT_SYMBOL_GPL(__hid_register_driver);
2057
2058void hid_unregister_driver(struct hid_driver *hdrv)
2059{
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01002060 driver_remove_file(&hdrv->driver, &driver_attr_new_id);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002061 driver_unregister(&hdrv->driver);
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01002062 hid_free_dynids(hdrv);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002063}
2064EXPORT_SYMBOL_GPL(hid_unregister_driver);
2065
Oliver Neukum0361a282008-12-17 15:38:03 +01002066int hid_check_keys_pressed(struct hid_device *hid)
2067{
2068 struct hid_input *hidinput;
2069 int i;
2070
Jiri Kosinae5288eb2009-05-02 00:02:57 +02002071 if (!(hid->claimed & HID_CLAIMED_INPUT))
2072 return 0;
2073
Oliver Neukum0361a282008-12-17 15:38:03 +01002074 list_for_each_entry(hidinput, &hid->inputs, list) {
2075 for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
2076 if (hidinput->input->key[i])
2077 return 1;
2078 }
2079
2080 return 0;
2081}
2082
2083EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
2084
Jiri Kosina86166b72007-05-14 09:57:40 +02002085static int __init hid_init(void)
2086{
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002087 int ret;
2088
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02002089 if (hid_debug)
Joe Perches4291ee32010-12-09 19:29:03 -08002090 pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
2091 "debugfs is now used for inspecting the device (report descriptor, reports)\n");
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02002092
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002093 ret = bus_register(&hid_bus_type);
2094 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -08002095 pr_err("can't register hid bus\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002096 goto err;
2097 }
2098
2099 ret = hidraw_init();
2100 if (ret)
2101 goto err_bus;
2102
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02002103 hid_debug_init();
2104
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002105 return 0;
2106err_bus:
2107 bus_unregister(&hid_bus_type);
2108err:
2109 return ret;
Jiri Kosina86166b72007-05-14 09:57:40 +02002110}
2111
2112static void __exit hid_exit(void)
2113{
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02002114 hid_debug_exit();
Jiri Kosina86166b72007-05-14 09:57:40 +02002115 hidraw_exit();
Jiri Slaby85cdaf52008-05-16 11:49:15 +02002116 bus_unregister(&hid_bus_type);
Jiri Kosina86166b72007-05-14 09:57:40 +02002117}
2118
2119module_init(hid_init);
2120module_exit(hid_exit);
2121
Jiri Kosina88adb722009-10-02 18:29:34 +02002122MODULE_AUTHOR("Andreas Gal");
2123MODULE_AUTHOR("Vojtech Pavlik");
2124MODULE_AUTHOR("Jiri Kosina");
Jiri Kosinaaa938f72006-12-08 18:41:10 +01002125MODULE_LICENSE(DRIVER_LICENSE);
2126