blob: 1fd5e331fa8d499aad6a19db0565db7676215bef [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
64 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
65 return NULL;
66
67 if (id != 0)
68 report_enum->numbered = 1;
69
70 report->id = id;
71 report->type = type;
72 report->size = 0;
73 report->device = device;
74 report_enum->report_id_hash[id] = report;
75
76 list_add_tail(&report->list, &report_enum->report_list);
77
78 return report;
79}
Michael Poole90a006a2010-01-24 22:32:29 -050080EXPORT_SYMBOL_GPL(hid_register_report);
Jiri Kosinadde58452006-12-08 18:40:44 +010081
82/*
83 * Register a new field for this report.
84 */
85
86static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
87{
88 struct hid_field *field;
89
90 if (report->maxfield == HID_MAX_FIELDS) {
Jiri Kosina58037eb2007-05-30 15:07:13 +020091 dbg_hid("too many fields in report\n");
Jiri Kosinadde58452006-12-08 18:40:44 +010092 return NULL;
93 }
94
95 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
96 + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
97
98 field->index = report->maxfield++;
99 report->field[field->index] = field;
100 field->usage = (struct hid_usage *)(field + 1);
Jiri Slaby282bfd42008-03-28 17:06:41 +0100101 field->value = (s32 *)(field->usage + usages);
Jiri Kosinadde58452006-12-08 18:40:44 +0100102 field->report = report;
103
104 return field;
105}
106
107/*
108 * Open a collection. The type/usage is pushed on the stack.
109 */
110
111static int open_collection(struct hid_parser *parser, unsigned type)
112{
113 struct hid_collection *collection;
114 unsigned usage;
115
116 usage = parser->local.usage[0];
117
118 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200119 dbg_hid("collection stack overflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100120 return -1;
121 }
122
123 if (parser->device->maxcollection == parser->device->collection_size) {
124 collection = kmalloc(sizeof(struct hid_collection) *
125 parser->device->collection_size * 2, GFP_KERNEL);
126 if (collection == NULL) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200127 dbg_hid("failed to reallocate collection array\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100128 return -1;
129 }
130 memcpy(collection, parser->device->collection,
131 sizeof(struct hid_collection) *
132 parser->device->collection_size);
133 memset(collection + parser->device->collection_size, 0,
134 sizeof(struct hid_collection) *
135 parser->device->collection_size);
136 kfree(parser->device->collection);
137 parser->device->collection = collection;
138 parser->device->collection_size *= 2;
139 }
140
141 parser->collection_stack[parser->collection_stack_ptr++] =
142 parser->device->maxcollection;
143
144 collection = parser->device->collection +
145 parser->device->maxcollection++;
146 collection->type = type;
147 collection->usage = usage;
148 collection->level = parser->collection_stack_ptr - 1;
149
150 if (type == HID_COLLECTION_APPLICATION)
151 parser->device->maxapplication++;
152
153 return 0;
154}
155
156/*
157 * Close a collection.
158 */
159
160static int close_collection(struct hid_parser *parser)
161{
162 if (!parser->collection_stack_ptr) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200163 dbg_hid("collection stack underflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100164 return -1;
165 }
166 parser->collection_stack_ptr--;
167 return 0;
168}
169
170/*
171 * Climb up the stack, search for the specified collection type
172 * and return the usage.
173 */
174
175static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
176{
177 int n;
178 for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
179 if (parser->device->collection[parser->collection_stack[n]].type == type)
180 return parser->device->collection[parser->collection_stack[n]].usage;
181 return 0; /* we know nothing about this usage type */
182}
183
184/*
185 * Add a usage to the temporary parser table.
186 */
187
188static int hid_add_usage(struct hid_parser *parser, unsigned usage)
189{
190 if (parser->local.usage_index >= HID_MAX_USAGES) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200191 dbg_hid("usage index exceeded\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100192 return -1;
193 }
194 parser->local.usage[parser->local.usage_index] = usage;
195 parser->local.collection_index[parser->local.usage_index] =
196 parser->collection_stack_ptr ?
197 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
198 parser->local.usage_index++;
199 return 0;
200}
201
202/*
203 * Register a new field for this report.
204 */
205
206static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
207{
208 struct hid_report *report;
209 struct hid_field *field;
210 int usages;
211 unsigned offset;
212 int i;
213
214 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200215 dbg_hid("hid_register_report failed\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100216 return -1;
217 }
218
219 if (parser->global.logical_maximum < parser->global.logical_minimum) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200220 dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
Jiri Kosinadde58452006-12-08 18:40:44 +0100221 return -1;
222 }
223
224 offset = report->size;
225 report->size += parser->global.report_size * parser->global.report_count;
226
227 if (!parser->local.usage_index) /* Ignore padding fields */
228 return 0;
229
230 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
231
232 if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
233 return 0;
234
235 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
236 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
237 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
238
239 for (i = 0; i < usages; i++) {
240 int j = i;
241 /* Duplicate the last usage we parsed if we have excess values */
242 if (i >= parser->local.usage_index)
243 j = parser->local.usage_index - 1;
244 field->usage[i].hid = parser->local.usage[j];
245 field->usage[i].collection_index =
246 parser->local.collection_index[j];
247 }
248
249 field->maxusage = usages;
250 field->flags = flags;
251 field->report_offset = offset;
252 field->report_type = report_type;
253 field->report_size = parser->global.report_size;
254 field->report_count = parser->global.report_count;
255 field->logical_minimum = parser->global.logical_minimum;
256 field->logical_maximum = parser->global.logical_maximum;
257 field->physical_minimum = parser->global.physical_minimum;
258 field->physical_maximum = parser->global.physical_maximum;
259 field->unit_exponent = parser->global.unit_exponent;
260 field->unit = parser->global.unit;
261
262 return 0;
263}
264
265/*
266 * Read data value from item.
267 */
268
269static u32 item_udata(struct hid_item *item)
270{
271 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200272 case 1: return item->data.u8;
273 case 2: return item->data.u16;
274 case 4: return item->data.u32;
Jiri Kosinadde58452006-12-08 18:40:44 +0100275 }
276 return 0;
277}
278
279static s32 item_sdata(struct hid_item *item)
280{
281 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200282 case 1: return item->data.s8;
283 case 2: return item->data.s16;
284 case 4: return item->data.s32;
Jiri Kosinadde58452006-12-08 18:40:44 +0100285 }
286 return 0;
287}
288
289/*
290 * Process a global item.
291 */
292
293static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
294{
295 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200296 case HID_GLOBAL_ITEM_TAG_PUSH:
Jiri Kosinadde58452006-12-08 18:40:44 +0100297
Jiri Slaby880d29f2008-06-18 23:55:41 +0200298 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
299 dbg_hid("global enviroment stack overflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100300 return -1;
Jiri Slaby880d29f2008-06-18 23:55:41 +0200301 }
302
303 memcpy(parser->global_stack + parser->global_stack_ptr++,
304 &parser->global, sizeof(struct hid_global));
305 return 0;
306
307 case HID_GLOBAL_ITEM_TAG_POP:
308
309 if (!parser->global_stack_ptr) {
310 dbg_hid("global enviroment stack underflow\n");
311 return -1;
312 }
313
314 memcpy(&parser->global, parser->global_stack +
315 --parser->global_stack_ptr, sizeof(struct hid_global));
316 return 0;
317
318 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
319 parser->global.usage_page = item_udata(item);
320 return 0;
321
322 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
323 parser->global.logical_minimum = item_sdata(item);
324 return 0;
325
326 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
327 if (parser->global.logical_minimum < 0)
328 parser->global.logical_maximum = item_sdata(item);
329 else
330 parser->global.logical_maximum = item_udata(item);
331 return 0;
332
333 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
334 parser->global.physical_minimum = item_sdata(item);
335 return 0;
336
337 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
338 if (parser->global.physical_minimum < 0)
339 parser->global.physical_maximum = item_sdata(item);
340 else
341 parser->global.physical_maximum = item_udata(item);
342 return 0;
343
344 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
345 parser->global.unit_exponent = item_sdata(item);
346 return 0;
347
348 case HID_GLOBAL_ITEM_TAG_UNIT:
349 parser->global.unit = item_udata(item);
350 return 0;
351
352 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
353 parser->global.report_size = item_udata(item);
354 if (parser->global.report_size > 32) {
355 dbg_hid("invalid report_size %d\n",
356 parser->global.report_size);
357 return -1;
358 }
359 return 0;
360
361 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
362 parser->global.report_count = item_udata(item);
363 if (parser->global.report_count > HID_MAX_USAGES) {
364 dbg_hid("invalid report_count %d\n",
365 parser->global.report_count);
366 return -1;
367 }
368 return 0;
369
370 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
371 parser->global.report_id = item_udata(item);
372 if (parser->global.report_id == 0) {
373 dbg_hid("report_id 0 is invalid\n");
374 return -1;
375 }
376 return 0;
377
378 default:
379 dbg_hid("unknown global tag 0x%x\n", item->tag);
380 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100381 }
382}
383
384/*
385 * Process a local item.
386 */
387
388static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
389{
390 __u32 data;
391 unsigned n;
392
Jiri Kosinadde58452006-12-08 18:40:44 +0100393 data = item_udata(item);
394
395 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200396 case HID_LOCAL_ITEM_TAG_DELIMITER:
Jiri Kosinadde58452006-12-08 18:40:44 +0100397
Jiri Slaby880d29f2008-06-18 23:55:41 +0200398 if (data) {
399 /*
400 * We treat items before the first delimiter
401 * as global to all usage sets (branch 0).
402 * In the moment we process only these global
403 * items and the first delimiter set.
404 */
405 if (parser->local.delimiter_depth != 0) {
406 dbg_hid("nested delimiters\n");
407 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100408 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200409 parser->local.delimiter_depth++;
410 parser->local.delimiter_branch++;
411 } else {
412 if (parser->local.delimiter_depth < 1) {
413 dbg_hid("bogus close delimiter\n");
414 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100415 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200416 parser->local.delimiter_depth--;
417 }
418 return 1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100419
Jiri Slaby880d29f2008-06-18 23:55:41 +0200420 case HID_LOCAL_ITEM_TAG_USAGE:
Jiri Kosinadde58452006-12-08 18:40:44 +0100421
Jiri Slaby880d29f2008-06-18 23:55:41 +0200422 if (parser->local.delimiter_branch > 1) {
423 dbg_hid("alternative usage ignored\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100424 return 0;
Jiri Slaby880d29f2008-06-18 23:55:41 +0200425 }
Jiri Kosinadde58452006-12-08 18:40:44 +0100426
Jiri Slaby880d29f2008-06-18 23:55:41 +0200427 if (item->size <= 2)
428 data = (parser->global.usage_page << 16) + data;
Jiri Kosinadde58452006-12-08 18:40:44 +0100429
Jiri Slaby880d29f2008-06-18 23:55:41 +0200430 return hid_add_usage(parser, data);
431
432 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
433
434 if (parser->local.delimiter_branch > 1) {
435 dbg_hid("alternative usage ignored\n");
436 return 0;
437 }
438
439 if (item->size <= 2)
440 data = (parser->global.usage_page << 16) + data;
441
442 parser->local.usage_minimum = data;
443 return 0;
444
445 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
446
447 if (parser->local.delimiter_branch > 1) {
448 dbg_hid("alternative usage ignored\n");
449 return 0;
450 }
451
452 if (item->size <= 2)
453 data = (parser->global.usage_page << 16) + data;
454
455 for (n = parser->local.usage_minimum; n <= data; n++)
456 if (hid_add_usage(parser, n)) {
457 dbg_hid("hid_add_usage failed\n");
458 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100459 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200460 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100461
Jiri Slaby880d29f2008-06-18 23:55:41 +0200462 default:
Jiri Kosinadde58452006-12-08 18:40:44 +0100463
Jiri Slaby880d29f2008-06-18 23:55:41 +0200464 dbg_hid("unknown local item tag 0x%x\n", item->tag);
465 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100466 }
467 return 0;
468}
469
470/*
471 * Process a main item.
472 */
473
474static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
475{
476 __u32 data;
477 int ret;
478
479 data = item_udata(item);
480
481 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200482 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
483 ret = open_collection(parser, data & 0xff);
484 break;
485 case HID_MAIN_ITEM_TAG_END_COLLECTION:
486 ret = close_collection(parser);
487 break;
488 case HID_MAIN_ITEM_TAG_INPUT:
489 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
490 break;
491 case HID_MAIN_ITEM_TAG_OUTPUT:
492 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
493 break;
494 case HID_MAIN_ITEM_TAG_FEATURE:
495 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
496 break;
497 default:
498 dbg_hid("unknown main item tag 0x%x\n", item->tag);
499 ret = 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100500 }
501
502 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
503
504 return ret;
505}
506
507/*
508 * Process a reserved item.
509 */
510
511static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
512{
Jiri Kosina58037eb2007-05-30 15:07:13 +0200513 dbg_hid("reserved item type, tag 0x%x\n", item->tag);
Jiri Kosinadde58452006-12-08 18:40:44 +0100514 return 0;
515}
516
517/*
518 * Free a report and all registered fields. The field->usage and
519 * field->value table's are allocated behind the field, so we need
520 * only to free(field) itself.
521 */
522
523static void hid_free_report(struct hid_report *report)
524{
525 unsigned n;
526
527 for (n = 0; n < report->maxfield; n++)
528 kfree(report->field[n]);
529 kfree(report);
530}
531
532/*
533 * Free a device structure, all reports, and all fields.
534 */
535
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200536static void hid_device_release(struct device *dev)
Jiri Kosinadde58452006-12-08 18:40:44 +0100537{
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200538 struct hid_device *device = container_of(dev, struct hid_device, dev);
539 unsigned i, j;
Jiri Kosinadde58452006-12-08 18:40:44 +0100540
541 for (i = 0; i < HID_REPORT_TYPES; i++) {
542 struct hid_report_enum *report_enum = device->report_enum + i;
543
544 for (j = 0; j < 256; j++) {
545 struct hid_report *report = report_enum->report_id_hash[j];
546 if (report)
547 hid_free_report(report);
548 }
549 }
550
551 kfree(device->rdesc);
Jiri Kosina767fe782007-01-24 23:05:07 +0100552 kfree(device->collection);
Jiri Kosinadde58452006-12-08 18:40:44 +0100553 kfree(device);
554}
555
556/*
557 * Fetch a report description item from the data stream. We support long
558 * items, though they are not used yet.
559 */
560
561static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
562{
563 u8 b;
564
565 if ((end - start) <= 0)
566 return NULL;
567
568 b = *start++;
569
570 item->type = (b >> 2) & 3;
571 item->tag = (b >> 4) & 15;
572
573 if (item->tag == HID_ITEM_TAG_LONG) {
574
575 item->format = HID_ITEM_FORMAT_LONG;
576
577 if ((end - start) < 2)
578 return NULL;
579
580 item->size = *start++;
581 item->tag = *start++;
582
583 if ((end - start) < item->size)
584 return NULL;
585
586 item->data.longdata = start;
587 start += item->size;
588 return start;
589 }
590
591 item->format = HID_ITEM_FORMAT_SHORT;
592 item->size = b & 3;
593
594 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200595 case 0:
596 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100597
Jiri Slaby880d29f2008-06-18 23:55:41 +0200598 case 1:
599 if ((end - start) < 1)
600 return NULL;
601 item->data.u8 = *start++;
602 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100603
Jiri Slaby880d29f2008-06-18 23:55:41 +0200604 case 2:
605 if ((end - start) < 2)
606 return NULL;
607 item->data.u16 = get_unaligned_le16(start);
608 start = (__u8 *)((__le16 *)start + 1);
609 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100610
Jiri Slaby880d29f2008-06-18 23:55:41 +0200611 case 3:
612 item->size++;
613 if ((end - start) < 4)
614 return NULL;
615 item->data.u32 = get_unaligned_le32(start);
616 start = (__u8 *)((__le32 *)start + 1);
617 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100618 }
619
620 return NULL;
621}
622
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200623/**
624 * hid_parse_report - parse device report
625 *
626 * @device: hid device
627 * @start: report start
628 * @size: report size
629 *
Jiri Kosinadde58452006-12-08 18:40:44 +0100630 * Parse a report description into a hid_device structure. Reports are
631 * enumerated, fields are attached to these reports.
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200632 * 0 returned on success, otherwise nonzero error value.
Jiri Kosinadde58452006-12-08 18:40:44 +0100633 */
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200634int hid_parse_report(struct hid_device *device, __u8 *start,
635 unsigned size)
Jiri Kosinadde58452006-12-08 18:40:44 +0100636{
Jiri Kosinadde58452006-12-08 18:40:44 +0100637 struct hid_parser *parser;
638 struct hid_item item;
639 __u8 *end;
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200640 int ret;
Jiri Kosinadde58452006-12-08 18:40:44 +0100641 static int (*dispatch_type[])(struct hid_parser *parser,
642 struct hid_item *item) = {
643 hid_parser_main,
644 hid_parser_global,
645 hid_parser_local,
646 hid_parser_reserved
647 };
648
Jiri Slabyc500c972008-05-16 11:49:16 +0200649 if (device->driver->report_fixup)
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400650 start = device->driver->report_fixup(device, start, &size);
Jiri Slabyc500c972008-05-16 11:49:16 +0200651
Julia Lawall1721a232010-05-15 23:19:30 +0200652 device->rdesc = kmemdup(start, size, GFP_KERNEL);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200653 if (device->rdesc == NULL)
654 return -ENOMEM;
Jiri Kosinadde58452006-12-08 18:40:44 +0100655 device->rsize = size;
656
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200657 parser = vmalloc(sizeof(struct hid_parser));
658 if (!parser) {
659 ret = -ENOMEM;
660 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100661 }
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200662
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100663 memset(parser, 0, sizeof(struct hid_parser));
Jiri Kosinadde58452006-12-08 18:40:44 +0100664 parser->device = device;
665
666 end = start + size;
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200667 ret = -EINVAL;
Jiri Kosinadde58452006-12-08 18:40:44 +0100668 while ((start = fetch_item(start, end, &item)) != NULL) {
669
670 if (item.format != HID_ITEM_FORMAT_SHORT) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200671 dbg_hid("unexpected long global item\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200672 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100673 }
674
675 if (dispatch_type[item.type](parser, &item)) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200676 dbg_hid("item %u %u %u %u parsing failed\n",
Joe Perches4291ee32010-12-09 19:29:03 -0800677 item.format, (unsigned)item.size,
678 (unsigned)item.type, (unsigned)item.tag);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200679 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100680 }
681
682 if (start == end) {
683 if (parser->collection_stack_ptr) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200684 dbg_hid("unbalanced collection at end of report description\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200685 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100686 }
687 if (parser->local.delimiter_depth) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200688 dbg_hid("unbalanced delimiter at end of report description\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200689 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100690 }
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100691 vfree(parser);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200692 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100693 }
694 }
695
Jiri Kosina58037eb2007-05-30 15:07:13 +0200696 dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200697err:
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100698 vfree(parser);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200699 return ret;
Jiri Kosinadde58452006-12-08 18:40:44 +0100700}
Jiri Kosina229695e2006-12-08 18:40:53 +0100701EXPORT_SYMBOL_GPL(hid_parse_report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100702
703/*
704 * Convert a signed n-bit integer to signed 32-bit integer. Common
705 * cases are done through the compiler, the screwed things has to be
706 * done by hand.
707 */
708
709static s32 snto32(__u32 value, unsigned n)
710{
711 switch (n) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200712 case 8: return ((__s8)value);
713 case 16: return ((__s16)value);
714 case 32: return ((__s32)value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100715 }
716 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
717}
718
719/*
720 * Convert a signed 32-bit integer to a signed n-bit integer.
721 */
722
723static u32 s32ton(__s32 value, unsigned n)
724{
725 s32 a = value >> (n - 1);
726 if (a && a != -1)
727 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
728 return value & ((1 << n) - 1);
729}
730
731/*
732 * Extract/implement a data field from/to a little endian report (bit array).
733 *
734 * Code sort-of follows HID spec:
735 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
736 *
737 * While the USB HID spec allows unlimited length bit fields in "report
738 * descriptors", most devices never use more than 16 bits.
739 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
740 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
741 */
742
Joe Perches4291ee32010-12-09 19:29:03 -0800743static __inline__ __u32 extract(const struct hid_device *hid, __u8 *report,
744 unsigned offset, unsigned n)
Jiri Kosinadde58452006-12-08 18:40:44 +0100745{
746 u64 x;
747
Jiri Kosinac4124c92007-11-30 11:12:58 +0100748 if (n > 32)
Joe Perches4291ee32010-12-09 19:29:03 -0800749 hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
750 n, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100751
752 report += offset >> 3; /* adjust byte index */
Jiri Kosina229695e2006-12-08 18:40:53 +0100753 offset &= 7; /* now only need bit offset into one byte */
Harvey Harrisonc1050682008-04-29 01:03:31 -0700754 x = get_unaligned_le64(report);
Jiri Kosina229695e2006-12-08 18:40:53 +0100755 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
Jiri Kosinadde58452006-12-08 18:40:44 +0100756 return (u32) x;
757}
758
759/*
760 * "implement" : set bits in a little endian bit stream.
761 * Same concepts as "extract" (see comments above).
762 * The data mangled in the bit stream remains in little endian
763 * order the whole time. It make more sense to talk about
764 * endianness of register values by considering a register
765 * a "cached" copy of the little endiad bit stream.
766 */
Joe Perches4291ee32010-12-09 19:29:03 -0800767static __inline__ void implement(const struct hid_device *hid, __u8 *report,
768 unsigned offset, unsigned n, __u32 value)
Jiri Kosinadde58452006-12-08 18:40:44 +0100769{
Harvey Harrison6f0168d2008-05-16 11:00:23 +0200770 u64 x;
Jiri Kosinadde58452006-12-08 18:40:44 +0100771 u64 m = (1ULL << n) - 1;
772
Jiri Kosinac4124c92007-11-30 11:12:58 +0100773 if (n > 32)
Joe Perches4291ee32010-12-09 19:29:03 -0800774 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
775 __func__, n, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100776
Jiri Kosinac4124c92007-11-30 11:12:58 +0100777 if (value > m)
Joe Perches4291ee32010-12-09 19:29:03 -0800778 hid_warn(hid, "%s() called with too large value %d! (%s)\n",
779 __func__, value, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100780 WARN_ON(value > m);
781 value &= m;
782
783 report += offset >> 3;
784 offset &= 7;
785
Harvey Harrison6f0168d2008-05-16 11:00:23 +0200786 x = get_unaligned_le64(report);
787 x &= ~(m << offset);
788 x |= ((u64)value) << offset;
789 put_unaligned_le64(x, report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100790}
791
792/*
793 * Search an array for a value.
794 */
795
796static __inline__ int search(__s32 *array, __s32 value, unsigned n)
797{
798 while (n--) {
799 if (*array++ == value)
800 return 0;
801 }
802 return -1;
803}
804
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200805/**
806 * hid_match_report - check if driver's raw_event should be called
807 *
808 * @hid: hid device
809 * @report_type: type to match against
810 *
811 * compare hid->driver->report_table->report_type to report->type
812 */
813static int hid_match_report(struct hid_device *hid, struct hid_report *report)
Jiri Kosinadde58452006-12-08 18:40:44 +0100814{
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200815 const struct hid_report_id *id = hid->driver->report_table;
816
817 if (!id) /* NULL means all */
818 return 1;
819
820 for (; id->report_type != HID_TERMINATOR; id++)
821 if (id->report_type == HID_ANY_ID ||
822 id->report_type == report->type)
823 return 1;
824 return 0;
825}
826
827/**
828 * hid_match_usage - check if driver's event should be called
829 *
830 * @hid: hid device
831 * @usage: usage to match against
832 *
833 * compare hid->driver->usage_table->usage_{type,code} to
834 * usage->usage_{type,code}
835 */
836static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
837{
838 const struct hid_usage_id *id = hid->driver->usage_table;
839
840 if (!id) /* NULL means all */
841 return 1;
842
843 for (; id->usage_type != HID_ANY_ID - 1; id++)
844 if ((id->usage_hid == HID_ANY_ID ||
845 id->usage_hid == usage->hid) &&
846 (id->usage_type == HID_ANY_ID ||
847 id->usage_type == usage->type) &&
848 (id->usage_code == HID_ANY_ID ||
849 id->usage_code == usage->code))
850 return 1;
851 return 0;
852}
853
854static void hid_process_event(struct hid_device *hid, struct hid_field *field,
855 struct hid_usage *usage, __s32 value, int interrupt)
856{
857 struct hid_driver *hdrv = hid->driver;
858 int ret;
859
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200860 hid_dump_input(hid, usage, value);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200861
862 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
863 ret = hdrv->event(hid, field, usage, value);
864 if (ret != 0) {
865 if (ret < 0)
866 dbg_hid("%s's event failed with %d\n",
867 hdrv->name, ret);
868 return;
869 }
870 }
871
Jiri Kosinadde58452006-12-08 18:40:44 +0100872 if (hid->claimed & HID_CLAIMED_INPUT)
873 hidinput_hid_event(hid, field, usage, value);
Jiri Kosinaaa938f72006-12-08 18:41:10 +0100874 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
875 hid->hiddev_hid_event(hid, field, usage, value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100876}
877
878/*
879 * Analyse a received field, and fetch the data from it. The field
880 * content is stored for next report processing (we do differential
881 * reporting to the layer).
882 */
883
Adrian Bunkabdff0f2008-03-31 01:53:56 +0200884static void hid_input_field(struct hid_device *hid, struct hid_field *field,
885 __u8 *data, int interrupt)
Jiri Kosinadde58452006-12-08 18:40:44 +0100886{
887 unsigned n;
888 unsigned count = field->report_count;
889 unsigned offset = field->report_offset;
890 unsigned size = field->report_size;
891 __s32 min = field->logical_minimum;
892 __s32 max = field->logical_maximum;
893 __s32 *value;
894
895 if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
896 return;
897
898 for (n = 0; n < count; n++) {
899
Joe Perches4291ee32010-12-09 19:29:03 -0800900 value[n] = min < 0 ?
901 snto32(extract(hid, data, offset + n * size, size),
902 size) :
903 extract(hid, data, offset + n * size, size);
Jiri Kosinadde58452006-12-08 18:40:44 +0100904
Joe Perches4291ee32010-12-09 19:29:03 -0800905 /* Ignore report if ErrorRollOver */
906 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
907 value[n] >= min && value[n] <= max &&
908 field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
909 goto exit;
Jiri Kosinadde58452006-12-08 18:40:44 +0100910 }
911
912 for (n = 0; n < count; n++) {
913
914 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
915 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
916 continue;
917 }
918
919 if (field->value[n] >= min && field->value[n] <= max
920 && field->usage[field->value[n] - min].hid
921 && search(value, field->value[n], count))
922 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
923
924 if (value[n] >= min && value[n] <= max
925 && field->usage[value[n] - min].hid
926 && search(field->value, value[n], count))
927 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
928 }
929
930 memcpy(field->value, value, count * sizeof(__s32));
931exit:
932 kfree(value);
933}
Jiri Kosinadde58452006-12-08 18:40:44 +0100934
935/*
936 * Output the field into the report.
937 */
938
Joe Perches4291ee32010-12-09 19:29:03 -0800939static void hid_output_field(const struct hid_device *hid,
940 struct hid_field *field, __u8 *data)
Jiri Kosinadde58452006-12-08 18:40:44 +0100941{
942 unsigned count = field->report_count;
943 unsigned offset = field->report_offset;
944 unsigned size = field->report_size;
945 unsigned n;
946
947 for (n = 0; n < count; n++) {
948 if (field->logical_minimum < 0) /* signed values */
Joe Perches4291ee32010-12-09 19:29:03 -0800949 implement(hid, data, offset + n * size, size,
950 s32ton(field->value[n], size));
Jiri Kosinadde58452006-12-08 18:40:44 +0100951 else /* unsigned values */
Joe Perches4291ee32010-12-09 19:29:03 -0800952 implement(hid, data, offset + n * size, size,
953 field->value[n]);
Jiri Kosinadde58452006-12-08 18:40:44 +0100954 }
955}
956
957/*
958 * Create a report.
959 */
960
Jiri Kosina229695e2006-12-08 18:40:53 +0100961void hid_output_report(struct hid_report *report, __u8 *data)
Jiri Kosinadde58452006-12-08 18:40:44 +0100962{
963 unsigned n;
964
965 if (report->id > 0)
966 *data++ = report->id;
967
Pete Zaitcev75c28df2010-04-12 12:16:11 -0600968 memset(data, 0, ((report->size - 1) >> 3) + 1);
Jiri Kosinadde58452006-12-08 18:40:44 +0100969 for (n = 0; n < report->maxfield; n++)
Joe Perches4291ee32010-12-09 19:29:03 -0800970 hid_output_field(report->device, report->field[n], data);
Jiri Kosinadde58452006-12-08 18:40:44 +0100971}
Jiri Kosina229695e2006-12-08 18:40:53 +0100972EXPORT_SYMBOL_GPL(hid_output_report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100973
974/*
975 * Set a field value. The report this field belongs to has to be
976 * created and transferred to the device, to set this value in the
977 * device.
978 */
979
980int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
981{
982 unsigned size = field->report_size;
983
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200984 hid_dump_input(field->report->device, field->usage + offset, value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100985
986 if (offset >= field->report_count) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200987 dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
Jiri Kosinadde58452006-12-08 18:40:44 +0100988 return -1;
989 }
990 if (field->logical_minimum < 0) {
991 if (value != snto32(s32ton(value, size), size)) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200992 dbg_hid("value %d is out of range\n", value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100993 return -1;
994 }
995 }
996 field->value[offset] = value;
997 return 0;
998}
Jiri Kosina229695e2006-12-08 18:40:53 +0100999EXPORT_SYMBOL_GPL(hid_set_field);
Jiri Kosinadde58452006-12-08 18:40:44 +01001000
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001001static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1002 const u8 *data)
1003{
1004 struct hid_report *report;
1005 unsigned int n = 0; /* Normally report number is 0 */
1006
1007 /* Device uses numbered reports, data[0] is report number */
1008 if (report_enum->numbered)
1009 n = *data;
1010
1011 report = report_enum->report_id_hash[n];
1012 if (report == NULL)
1013 dbg_hid("undefined report_id %u received\n", n);
1014
1015 return report;
1016}
1017
1018void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1019 int interrupt)
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001020{
1021 struct hid_report_enum *report_enum = hid->report_enum + type;
1022 struct hid_report *report;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001023 unsigned int a;
1024 int rsize, csize = size;
1025 u8 *cdata = data;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001026
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001027 report = hid_get_report(report_enum, data);
1028 if (!report)
1029 return;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001030
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001031 if (report_enum->numbered) {
1032 cdata++;
1033 csize--;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001034 }
1035
1036 rsize = ((report->size - 1) >> 3) + 1;
1037
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001038 if (csize < rsize) {
1039 dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1040 csize, rsize);
1041 memset(cdata + csize, 0, rsize - csize);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001042 }
1043
1044 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1045 hid->hiddev_report_event(hid, report);
Alan Ott5a38f2c2010-04-26 18:34:46 -04001046 if (hid->claimed & HID_CLAIMED_HIDRAW)
1047 hidraw_report_event(hid, data, size);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001048
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001049 for (a = 0; a < report->maxfield; a++)
1050 hid_input_field(hid, report->field[a], cdata, interrupt);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001051
1052 if (hid->claimed & HID_CLAIMED_INPUT)
1053 hidinput_report_event(hid, report);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001054}
1055EXPORT_SYMBOL_GPL(hid_report_raw_event);
1056
1057/**
1058 * hid_input_report - report data from lower layer (usb, bt...)
1059 *
1060 * @hid: hid device
1061 * @type: HID report type (HID_*_REPORT)
1062 * @data: report contents
1063 * @size: size of data parameter
Jiri Kosinaff9b00a2009-10-01 16:03:13 +02001064 * @interrupt: distinguish between interrupt and control transfers
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001065 *
1066 * This is data entry for lower layers.
1067 */
1068int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1069{
Julia Lawall76c317d2009-07-19 17:26:13 +02001070 struct hid_report_enum *report_enum;
1071 struct hid_driver *hdrv;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001072 struct hid_report *report;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001073 char *buf;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001074 unsigned int i;
1075 int ret;
1076
1077 if (!hid || !hid->driver)
1078 return -ENODEV;
Julia Lawall76c317d2009-07-19 17:26:13 +02001079 report_enum = hid->report_enum + type;
1080 hdrv = hid->driver;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001081
1082 if (!size) {
1083 dbg_hid("empty report\n");
1084 return -1;
1085 }
1086
Jiri Kosinad1ff6522009-09-15 11:59:49 +02001087 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001088
Jiri Kosinaf77e3472010-03-18 14:11:53 +01001089 if (!buf)
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001090 goto nomem;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001091
1092 /* dump the report */
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001093 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
Jiri Kosina1caea612010-03-18 12:09:53 +01001094 "\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001095 hid_debug_event(hid, buf);
Jiri Kosina1caea612010-03-18 12:09:53 +01001096
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001097 for (i = 0; i < size; i++) {
1098 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1099 " %02x", data[i]);
1100 hid_debug_event(hid, buf);
1101 }
1102 hid_debug_event(hid, "\n");
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001103 kfree(buf);
1104
1105nomem:
Jiri Kosinaf77e3472010-03-18 14:11:53 +01001106 report = hid_get_report(report_enum, data);
1107
1108 if (!report)
1109 return -1;
1110
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001111 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1112 ret = hdrv->raw_event(hid, report, data, size);
1113 if (ret != 0)
1114 return ret < 0 ? ret : 0;
1115 }
1116
1117 hid_report_raw_event(hid, type, data, size, interrupt);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001118
1119 return 0;
1120}
1121EXPORT_SYMBOL_GPL(hid_input_report);
1122
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001123static bool hid_match_one_id(struct hid_device *hdev,
1124 const struct hid_device_id *id)
1125{
1126 return id->bus == hdev->bus &&
1127 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1128 (id->product == HID_ANY_ID || id->product == hdev->product);
1129}
1130
1131static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1132 const struct hid_device_id *id)
1133{
1134 for (; id->bus; id++)
1135 if (hid_match_one_id(hdev, id))
1136 return id;
1137
1138 return NULL;
1139}
1140
1141static const struct hid_device_id hid_hiddev_list[] = {
Richard Hughesc0bd6a42008-08-27 11:19:37 +02001142 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1143 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001144 { }
1145};
1146
1147static bool hid_hiddev(struct hid_device *hdev)
1148{
1149 return !!hid_match_id(hdev, hid_hiddev_list);
1150}
1151
Jiri Slaby93c10132008-06-27 00:04:24 +02001152int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1153{
1154 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1155 "Joystick", "Gamepad", "Keyboard", "Keypad",
1156 "Multi-Axis Controller"
1157 };
1158 const char *type, *bus;
1159 char buf[64];
1160 unsigned int i;
1161 int len;
1162
Bastien Nocerab5e5a372010-04-16 17:19:50 +01001163 if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1164 connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
Daniel Mack3a343ee2010-07-12 19:28:27 +02001165 if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
1166 connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
Jiri Slaby93c10132008-06-27 00:04:24 +02001167 if (hdev->bus != BUS_USB)
1168 connect_mask &= ~HID_CONNECT_HIDDEV;
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001169 if (hid_hiddev(hdev))
1170 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
Jiri Slaby93c10132008-06-27 00:04:24 +02001171
1172 if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1173 connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1174 hdev->claimed |= HID_CLAIMED_INPUT;
1175 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1176 !hdev->hiddev_connect(hdev,
1177 connect_mask & HID_CONNECT_HIDDEV_FORCE))
1178 hdev->claimed |= HID_CLAIMED_HIDDEV;
1179 if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1180 hdev->claimed |= HID_CLAIMED_HIDRAW;
1181
1182 if (!hdev->claimed) {
Joe Perches4291ee32010-12-09 19:29:03 -08001183 hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
Jiri Slaby93c10132008-06-27 00:04:24 +02001184 return -ENODEV;
1185 }
1186
1187 if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1188 (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1189 hdev->ff_init(hdev);
1190
1191 len = 0;
1192 if (hdev->claimed & HID_CLAIMED_INPUT)
1193 len += sprintf(buf + len, "input");
1194 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1195 len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1196 hdev->minor);
1197 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1198 len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1199 ((struct hidraw *)hdev->hidraw)->minor);
1200
1201 type = "Device";
1202 for (i = 0; i < hdev->maxcollection; i++) {
1203 struct hid_collection *col = &hdev->collection[i];
1204 if (col->type == HID_COLLECTION_APPLICATION &&
1205 (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1206 (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1207 type = types[col->usage & 0xffff];
1208 break;
1209 }
1210 }
1211
1212 switch (hdev->bus) {
1213 case BUS_USB:
1214 bus = "USB";
1215 break;
1216 case BUS_BLUETOOTH:
1217 bus = "BLUETOOTH";
1218 break;
1219 default:
1220 bus = "<UNKNOWN>";
1221 }
1222
Joe Perches4291ee32010-12-09 19:29:03 -08001223 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1224 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1225 type, hdev->name, hdev->phys);
Jiri Slaby93c10132008-06-27 00:04:24 +02001226
1227 return 0;
1228}
1229EXPORT_SYMBOL_GPL(hid_connect);
1230
Jiri Kosinac4c259b2009-09-15 16:27:45 +02001231void hid_disconnect(struct hid_device *hdev)
1232{
1233 if (hdev->claimed & HID_CLAIMED_INPUT)
1234 hidinput_disconnect(hdev);
1235 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1236 hdev->hiddev_disconnect(hdev);
1237 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1238 hidraw_disconnect(hdev);
1239}
1240EXPORT_SYMBOL_GPL(hid_disconnect);
1241
Jiri Kosinabae7eb32009-01-28 23:06:37 +01001242/* a list of devices for which there is a specialized driver on HID bus */
Dmitry Torokhovce06b9d2010-11-28 16:37:14 +01001243static const struct hid_device_id hid_have_special_driver[] = {
Stephane Chattyb6353f42009-12-22 23:04:17 +01001244 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
Stephane Chatty6dec1432010-04-11 14:51:24 +02001245 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
Jiri Slaby14a21cd2008-06-23 23:31:09 +02001246 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1247 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
Lech Perczakb7e1b202010-09-16 23:19:33 +02001248 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +02001249#if defined(CONFIG_HID_ACRUX_FF) || defined(CONFIG_HID_ACRUX_FF_MODULE)
1250 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
1251#endif
Jiri Kosinadf9bcac2008-10-14 22:45:40 +02001252 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001253 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1254 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
Michael Poole128537c2010-02-06 12:24:36 -05001255 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
Chase Douglasa4622302010-08-31 21:56:23 -04001256 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1259 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1260 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1261 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1262 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1263 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1264 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1265 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1266 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1267 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
Ryan Finniefef3f572009-03-05 10:18:01 +01001268 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1269 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1270 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001271 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1272 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1273 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1274 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1275 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1276 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
Jan Scholzee8a1a02008-11-26 15:33:45 +01001277 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1278 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1279 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001280 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1281 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1282 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1283 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1284 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1285 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +01001286 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1287 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1288 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -04001289 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1290 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1291 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1292 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1293 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1294 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +01001295 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1296 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1297 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001298 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1299 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
Jiri Kosinaeaca1382010-09-08 14:31:47 +02001300 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
Roland Baumcec15a02010-09-08 14:27:55 +02001301 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
Jiri Slabyb5635b12008-06-24 23:24:57 +02001302 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
Wayne Thomasbf280622010-04-29 00:45:01 +02001303 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
Jiri Kosinac3dc66d2010-08-30 15:43:25 +02001304 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
Stephane Chatty36213e12010-04-15 00:28:11 +02001305 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
Stephane Chattyba4d8ab2010-04-22 23:24:36 +02001306 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
François Jaouen272036e2010-10-13 10:47:32 +02001307 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
Jiri Slaby3b239cd2008-06-24 20:42:25 +02001308 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
Raphaël Doursenaud1ce31b22010-04-08 13:40:52 +02001309 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
Jiri Slabyfcfacfd2008-06-24 22:48:52 +02001310 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
Dennis Küglerb9e4b1e2010-11-23 21:40:09 +01001311 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
Don Prince3a370ca2010-05-12 15:18:59 +02001312 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
Jiri Slaby0f221322008-06-23 22:54:08 +02001313 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1314 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
Jiri Kosinae8d0eab2009-12-02 22:54:11 +01001315 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
Jiri Slaby0f221322008-06-23 22:54:08 +02001316 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
Richard Walmsley3f866fb2009-03-04 22:12:04 +13001317 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
Stephane Chatty0c3910c2010-04-10 16:43:08 +02001318 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
Chris Ball83e44912010-08-16 16:01:28 +02001319 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) },
Richard Nauber64b386e2010-06-28 18:54:25 +02001320 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
Ignaz Forster04561c52010-11-01 15:13:37 -04001321 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
Jiri Slaby1f243e32008-06-24 21:11:21 +02001322 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
Jiri Kosina5181e592008-11-17 01:44:38 +01001323 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
Jiri Kosina578f3a32008-11-20 15:55:38 +01001324 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
Jiri Kosina5181e592008-11-17 01:44:38 +01001325 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
Lukasz Lubojanski42859e02008-12-11 22:07:59 +01001326 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
Jiri Slaby949f8fe2008-07-24 23:35:13 +02001327 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
Jiri Kosina1e093202008-10-17 11:52:23 +02001328 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
Cory Maccarronec2fd1a42010-05-22 13:00:28 -07001329 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
Jiri Kosinafdf93aa2009-03-04 16:09:40 +01001330 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
Jiri Kosina79422742009-03-11 11:43:27 +01001331 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
Jiri Slabyb5635b12008-06-24 23:24:57 +02001332 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001333 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1339 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001340 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001342 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
Hendrik Iben2c6118e2010-10-04 15:39:49 +02001344 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001345 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1346 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
Jiri Kosinafd30ea82009-06-23 12:11:31 +02001348 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001349 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
Gary Stein74f292c2010-01-13 00:25:58 +01001350 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001351 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1352 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
Christophe Borivant243b7062009-04-17 11:39:39 +02001353 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
Simon Wood32c88cb2010-09-22 13:19:42 +02001354 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001355 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
Jiri Kosina24985cf2009-11-13 10:45:53 +01001356 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
1357 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
Bruno Prémont236db472010-03-30 22:33:50 +02001358 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1359 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
Jiri Slaby78a849a2008-06-20 21:26:11 +02001360 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1361 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1362 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1363 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1364 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
Jiri Slaby3b8006e2008-06-25 00:07:50 +02001365 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
Rafi Rubin94011f92008-11-19 15:54:46 +01001366 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
micki6e328192010-06-19 11:37:29 +03001367 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
1368 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
1369 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
1370 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
1371 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
1372 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
1373 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
1374 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
1375 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
1376 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
1377 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
1378 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
1379 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
1380 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
1381 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
1382 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
1383 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
1384 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
Johnathon Harriscd9ec302010-01-21 14:36:52 +00001385 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
Jiri Slaby1e762532008-06-24 23:46:21 +02001386 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
Stephane Chatty49e47392010-01-13 00:29:16 +01001387 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
Alex Neblettf54405d2010-02-02 21:16:03 -08001388 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
Stefan Achatz14bf62c2010-03-18 16:19:43 +01001389 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
Stefan Achatzcb7cf3d2010-08-29 12:30:18 +02001390 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
Jiri Slaby980a3da2008-06-25 22:31:48 +02001391 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
Don Princeb3558502010-05-17 11:42:39 +01001392 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
Jiri Slabybd28ce02008-06-25 23:47:04 +02001393 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
Bastien Noceraf9ce7c22010-01-20 12:01:53 +00001394 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +02001395 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
Stephane Chattyd3fb5452010-01-04 12:04:08 +01001396 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
Pascal Auriel - Stantumb6dc7992010-10-01 16:01:28 +02001397 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) },
1398 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) },
Jiri Slaby90231e72008-06-23 21:56:07 +02001399 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001400 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1401 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
Ruben Aos Garralda7a84b132009-06-29 09:41:29 +02001402 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
1403 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001404 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
Markus Rathgeb3ee8f0a2010-03-13 17:29:43 +01001405 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001406 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
Lev Babievf14f5262009-01-04 00:36:56 +01001407 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
Kees Bakker54001082010-07-13 22:50:51 +02001408 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
Bruno Premont711a6802009-07-13 14:19:58 +02001409 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
Nikolai Kondrashov41fa9232010-08-23 15:09:01 +04001410 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
Nikolai Kondrashovf8a489c2010-08-09 20:44:17 +04001411 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
Jussi Kivilinnafac733f2009-05-13 11:54:38 +03001414 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
Bastien Noceraca2dcd42009-05-11 17:18:12 +02001415 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Nikolai Kondrashov72a46342010-08-20 19:21:11 +04001416 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
Nikolai Kondrashov00e7f962010-09-25 23:16:58 +04001417 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
Nikolai Kondrashov72a46342010-08-20 19:21:11 +04001418 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
Nikolai Kondrashov8f1acc32010-08-30 14:06:36 +04001419 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001420 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1421 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
Don Princea9885c82010-05-14 17:30:59 +01001422 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001423
Jiri Slaby78a849a2008-06-20 21:26:11 +02001424 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001425 { }
1426};
1427
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001428struct hid_dynid {
1429 struct list_head list;
1430 struct hid_device_id id;
1431};
1432
1433/**
1434 * store_new_id - add a new HID device ID to this driver and re-probe devices
1435 * @driver: target device driver
1436 * @buf: buffer for scanning device ID data
1437 * @count: input size
1438 *
1439 * Adds a new dynamic hid device ID to this driver,
1440 * and causes the driver to probe for all devices again.
1441 */
1442static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1443 size_t count)
1444{
1445 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1446 struct hid_dynid *dynid;
1447 __u32 bus, vendor, product;
1448 unsigned long driver_data = 0;
1449 int ret;
1450
1451 ret = sscanf(buf, "%x %x %x %lx",
1452 &bus, &vendor, &product, &driver_data);
1453 if (ret < 3)
1454 return -EINVAL;
1455
1456 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
1457 if (!dynid)
1458 return -ENOMEM;
1459
1460 dynid->id.bus = bus;
1461 dynid->id.vendor = vendor;
1462 dynid->id.product = product;
1463 dynid->id.driver_data = driver_data;
1464
1465 spin_lock(&hdrv->dyn_lock);
1466 list_add_tail(&dynid->list, &hdrv->dyn_list);
1467 spin_unlock(&hdrv->dyn_lock);
1468
1469 ret = 0;
1470 if (get_driver(&hdrv->driver)) {
1471 ret = driver_attach(&hdrv->driver);
1472 put_driver(&hdrv->driver);
1473 }
1474
1475 return ret ? : count;
1476}
1477static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
1478
1479static void hid_free_dynids(struct hid_driver *hdrv)
1480{
1481 struct hid_dynid *dynid, *n;
1482
1483 spin_lock(&hdrv->dyn_lock);
1484 list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
1485 list_del(&dynid->list);
1486 kfree(dynid);
1487 }
1488 spin_unlock(&hdrv->dyn_lock);
1489}
1490
1491static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
1492 struct hid_driver *hdrv)
1493{
1494 struct hid_dynid *dynid;
1495
1496 spin_lock(&hdrv->dyn_lock);
1497 list_for_each_entry(dynid, &hdrv->dyn_list, list) {
1498 if (hid_match_one_id(hdev, &dynid->id)) {
1499 spin_unlock(&hdrv->dyn_lock);
1500 return &dynid->id;
1501 }
1502 }
1503 spin_unlock(&hdrv->dyn_lock);
1504
1505 return hid_match_id(hdev, hdrv->id_table);
1506}
1507
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001508static int hid_bus_match(struct device *dev, struct device_driver *drv)
1509{
1510 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1511 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1512
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001513 if (!hid_match_device(hdev, hdrv))
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001514 return 0;
1515
Dmitry Torokhovce06b9d2010-11-28 16:37:14 +01001516 /* generic wants all that don't have specialized driver */
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001517 if (!strncmp(hdrv->name, "generic-", 8))
Dmitry Torokhovce06b9d2010-11-28 16:37:14 +01001518 return !hid_match_id(hdev, hid_have_special_driver);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001519
1520 return 1;
1521}
1522
1523static int hid_device_probe(struct device *dev)
1524{
1525 struct hid_driver *hdrv = container_of(dev->driver,
1526 struct hid_driver, driver);
1527 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1528 const struct hid_device_id *id;
1529 int ret = 0;
1530
1531 if (!hdev->driver) {
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001532 id = hid_match_device(hdev, hdrv);
Jiri Slabyc500c972008-05-16 11:49:16 +02001533 if (id == NULL)
1534 return -ENODEV;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001535
Jiri Slabyc500c972008-05-16 11:49:16 +02001536 hdev->driver = hdrv;
1537 if (hdrv->probe) {
1538 ret = hdrv->probe(hdev, id);
1539 } else { /* default probe */
1540 ret = hid_parse(hdev);
1541 if (!ret)
Jiri Slaby93c10132008-06-27 00:04:24 +02001542 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001543 }
Jiri Slabyc500c972008-05-16 11:49:16 +02001544 if (ret)
1545 hdev->driver = NULL;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001546 }
1547 return ret;
1548}
1549
1550static int hid_device_remove(struct device *dev)
1551{
1552 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1553 struct hid_driver *hdrv = hdev->driver;
1554
1555 if (hdrv) {
1556 if (hdrv->remove)
1557 hdrv->remove(hdev);
Jiri Slabyc500c972008-05-16 11:49:16 +02001558 else /* default remove */
1559 hid_hw_stop(hdev);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001560 hdev->driver = NULL;
1561 }
1562
1563 return 0;
1564}
1565
1566static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1567{
1568 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1569
1570 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1571 hdev->bus, hdev->vendor, hdev->product))
1572 return -ENOMEM;
1573
1574 if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1575 return -ENOMEM;
1576
1577 if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1578 return -ENOMEM;
1579
1580 if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1581 return -ENOMEM;
1582
1583 if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
1584 hdev->bus, hdev->vendor, hdev->product))
1585 return -ENOMEM;
1586
1587 return 0;
1588}
1589
1590static struct bus_type hid_bus_type = {
1591 .name = "hid",
1592 .match = hid_bus_match,
1593 .probe = hid_device_probe,
1594 .remove = hid_device_remove,
1595 .uevent = hid_uevent,
1596};
1597
Jiri Kosinabae7eb32009-01-28 23:06:37 +01001598/* a list of devices that shouldn't be handled by HID core at all */
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001599static const struct hid_device_id hid_ignore_list[] = {
1600 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1601 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1602 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1603 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1604 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1605 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1606 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1607 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1608 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1609 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1610 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1611 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
Stephane Chatty77f720b2010-02-06 15:17:13 +01001612 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1613 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
Alexey Klimov62a56582008-11-13 05:44:50 +03001614 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001615 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1616 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1617 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1618 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1619 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1620 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
Alexey Klimov5f6108c2008-12-08 12:40:14 +01001621 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001622 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1623 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1624 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
Petr Å tetiar70c66562009-12-09 22:09:53 +01001625 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
Petr Å tetiardf506f22010-06-28 09:38:54 -07001626 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001627 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1628 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1629 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1630 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1631 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1632 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1633 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1634 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1635 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1636 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1637 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1638 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1639 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1640 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1641 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1642 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1643 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1644 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1645 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1646 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1647 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1648 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1649 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1650 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1651 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1652 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1653 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1654 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1655 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1656 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1657 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1658 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1659 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1660 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1661 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1662 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1663 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1664 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1665 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1666 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1667 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1669 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1670 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1671 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1672 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1673 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1674 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1675 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1676 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1677 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1678 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1679 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1680 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1681 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1682 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1683 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1684 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1685 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1686 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1687 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1688 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1689 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1690 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1691 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
Tomoki Sekiyama6bc235a2010-09-29 12:16:50 +09001692 { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_JESS_YUREX) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001693 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
Alexey Klimovc91c21c2008-11-13 10:36:11 +01001694 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001695 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
Lamarque Vieira Souzaeb8141c2009-10-02 15:04:44 +02001696 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001697 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1698 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1699 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1700 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1701 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1702 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1703 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
1704 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1705 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1706 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1707 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1708 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1709 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1710 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1711 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1712 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001713 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1714 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1715 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1716 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1717 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1718 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1719 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1720 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1721 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1722 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1723 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1724 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1725 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1726 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1727 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1728 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1729 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
Henning Glawe4cfae3e2009-08-02 22:18:12 +02001730 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
Michael Tokarev35cfd1d2009-02-01 16:11:04 +01001731 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001732 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1733 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1734 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1735 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1736 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1737 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1738 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1739 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1740 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1741 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1742 { }
1743};
1744
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001745/**
1746 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1747 *
1748 * There are composite devices for which we want to ignore only a certain
1749 * interface. This is a list of devices for which only the mouse interface will
1750 * be ignored. This allows a dedicated driver to take care of the interface.
1751 */
1752static const struct hid_device_id hid_mouse_ignore_list[] = {
1753 /* appletouch driver */
1754 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1755 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1756 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1757 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1758 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1759 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1760 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1761 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1762 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1763 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1764 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1765 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1766 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1767 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1768 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1769 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1770 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1771 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1772 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1773 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
Jiri Kosinaac26fca2008-11-20 11:27:02 +01001774 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1775 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1776 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
Edgar (gimli) Hucek99b9f752010-11-03 10:36:18 -04001777 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
1778 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
1779 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
1780 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
1781 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
1782 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001783 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1784 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1785 { }
1786};
1787
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001788static bool hid_ignore(struct hid_device *hdev)
1789{
1790 switch (hdev->vendor) {
1791 case USB_VENDOR_ID_CODEMERCS:
1792 /* ignore all Code Mercenaries IOWarrior devices */
1793 if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1794 hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1795 return true;
1796 break;
1797 case USB_VENDOR_ID_LOGITECH:
1798 if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1799 hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1800 return true;
1801 break;
Jarod Wilson31f7fd72009-07-31 10:56:36 -04001802 case USB_VENDOR_ID_SOUNDGRAPH:
1803 if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
1804 hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
1805 return true;
1806 break;
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001807 }
1808
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001809 if (hdev->type == HID_TYPE_USBMOUSE &&
1810 hid_match_id(hdev, hid_mouse_ignore_list))
1811 return true;
1812
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001813 return !!hid_match_id(hdev, hid_ignore_list);
1814}
1815
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001816int hid_add_device(struct hid_device *hdev)
1817{
1818 static atomic_t id = ATOMIC_INIT(0);
1819 int ret;
1820
1821 if (WARN_ON(hdev->status & HID_STAT_ADDED))
1822 return -EBUSY;
1823
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001824 /* we need to kill them here, otherwise they will stay allocated to
1825 * wait for coming driver */
Jindrich Makovickae5a2a042010-06-03 12:50:42 +02001826 if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1827 && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001828 return -ENODEV;
1829
Kay Sievers6bbe5862008-10-31 00:12:32 +01001830 /* XXX hack, any other cleaner solution after the driver core
1831 * is converted to allow more than 20 bytes as the device name? */
1832 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
1833 hdev->vendor, hdev->product, atomic_inc_return(&id));
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001834
Bruno Prémont4da361b2010-03-15 14:55:40 +01001835 hid_debug_register(hdev, dev_name(&hdev->dev));
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001836 ret = device_add(&hdev->dev);
1837 if (!ret)
1838 hdev->status |= HID_STAT_ADDED;
Bruno Prémont4da361b2010-03-15 14:55:40 +01001839 else
1840 hid_debug_unregister(hdev);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001841
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001842 return ret;
1843}
1844EXPORT_SYMBOL_GPL(hid_add_device);
1845
1846/**
1847 * hid_allocate_device - allocate new hid device descriptor
1848 *
1849 * Allocate and initialize hid device, so that hid_destroy_device might be
1850 * used to free it.
1851 *
1852 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1853 * error value.
1854 */
1855struct hid_device *hid_allocate_device(void)
1856{
1857 struct hid_device *hdev;
1858 unsigned int i;
1859 int ret = -ENOMEM;
1860
1861 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
1862 if (hdev == NULL)
1863 return ERR_PTR(ret);
1864
1865 device_initialize(&hdev->dev);
1866 hdev->dev.release = hid_device_release;
1867 hdev->dev.bus = &hid_bus_type;
1868
1869 hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
1870 sizeof(struct hid_collection), GFP_KERNEL);
1871 if (hdev->collection == NULL)
1872 goto err;
1873 hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
1874
1875 for (i = 0; i < HID_REPORT_TYPES; i++)
1876 INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
1877
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001878 init_waitqueue_head(&hdev->debug_wait);
1879 INIT_LIST_HEAD(&hdev->debug_list);
1880
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001881 return hdev;
1882err:
1883 put_device(&hdev->dev);
1884 return ERR_PTR(ret);
1885}
1886EXPORT_SYMBOL_GPL(hid_allocate_device);
1887
1888static void hid_remove_device(struct hid_device *hdev)
1889{
1890 if (hdev->status & HID_STAT_ADDED) {
1891 device_del(&hdev->dev);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001892 hid_debug_unregister(hdev);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001893 hdev->status &= ~HID_STAT_ADDED;
1894 }
1895}
1896
1897/**
1898 * hid_destroy_device - free previously allocated device
1899 *
1900 * @hdev: hid device
1901 *
1902 * If you allocate hid_device through hid_allocate_device, you should ever
1903 * free by this function.
1904 */
1905void hid_destroy_device(struct hid_device *hdev)
1906{
1907 hid_remove_device(hdev);
1908 put_device(&hdev->dev);
1909}
1910EXPORT_SYMBOL_GPL(hid_destroy_device);
1911
1912int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
1913 const char *mod_name)
1914{
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001915 int ret;
1916
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001917 hdrv->driver.name = hdrv->name;
1918 hdrv->driver.bus = &hid_bus_type;
1919 hdrv->driver.owner = owner;
1920 hdrv->driver.mod_name = mod_name;
1921
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001922 INIT_LIST_HEAD(&hdrv->dyn_list);
1923 spin_lock_init(&hdrv->dyn_lock);
1924
1925 ret = driver_register(&hdrv->driver);
1926 if (ret)
1927 return ret;
1928
1929 ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
1930 if (ret)
1931 driver_unregister(&hdrv->driver);
1932
1933 return ret;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001934}
1935EXPORT_SYMBOL_GPL(__hid_register_driver);
1936
1937void hid_unregister_driver(struct hid_driver *hdrv)
1938{
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001939 driver_remove_file(&hdrv->driver, &driver_attr_new_id);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001940 driver_unregister(&hdrv->driver);
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001941 hid_free_dynids(hdrv);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001942}
1943EXPORT_SYMBOL_GPL(hid_unregister_driver);
1944
Oliver Neukum0361a282008-12-17 15:38:03 +01001945int hid_check_keys_pressed(struct hid_device *hid)
1946{
1947 struct hid_input *hidinput;
1948 int i;
1949
Jiri Kosinae5288eb2009-05-02 00:02:57 +02001950 if (!(hid->claimed & HID_CLAIMED_INPUT))
1951 return 0;
1952
Oliver Neukum0361a282008-12-17 15:38:03 +01001953 list_for_each_entry(hidinput, &hid->inputs, list) {
1954 for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
1955 if (hidinput->input->key[i])
1956 return 1;
1957 }
1958
1959 return 0;
1960}
1961
1962EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
1963
Jiri Kosina86166b72007-05-14 09:57:40 +02001964static int __init hid_init(void)
1965{
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001966 int ret;
1967
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001968 if (hid_debug)
Joe Perches4291ee32010-12-09 19:29:03 -08001969 pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
1970 "debugfs is now used for inspecting the device (report descriptor, reports)\n");
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001971
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001972 ret = bus_register(&hid_bus_type);
1973 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -08001974 pr_err("can't register hid bus\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001975 goto err;
1976 }
1977
1978 ret = hidraw_init();
1979 if (ret)
1980 goto err_bus;
1981
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001982 hid_debug_init();
1983
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001984 return 0;
1985err_bus:
1986 bus_unregister(&hid_bus_type);
1987err:
1988 return ret;
Jiri Kosina86166b72007-05-14 09:57:40 +02001989}
1990
1991static void __exit hid_exit(void)
1992{
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001993 hid_debug_exit();
Jiri Kosina86166b72007-05-14 09:57:40 +02001994 hidraw_exit();
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001995 bus_unregister(&hid_bus_type);
Jiri Kosina86166b72007-05-14 09:57:40 +02001996}
1997
1998module_init(hid_init);
1999module_exit(hid_exit);
2000
Jiri Kosina88adb722009-10-02 18:29:34 +02002001MODULE_AUTHOR("Andreas Gal");
2002MODULE_AUTHOR("Vojtech Pavlik");
2003MODULE_AUTHOR("Jiri Kosina");
Jiri Kosinaaa938f72006-12-08 18:41:10 +01002004MODULE_LICENSE(DRIVER_LICENSE);
2005