blob: 866e54ec5fb2eed324a122fda7b05944b36392c0 [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
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010021#include <linux/list.h>
22#include <linux/mm.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010023#include <linux/spinlock.h>
24#include <asm/unaligned.h>
25#include <asm/byteorder.h>
26#include <linux/input.h>
27#include <linux/wait.h>
Jiri Kosina47a80ed2007-03-12 14:55:12 +010028#include <linux/vmalloc.h>
Jiri Kosinac4124c92007-11-30 11:12:58 +010029#include <linux/sched.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010030
Jiri Kosinadde58452006-12-08 18:40:44 +010031#include <linux/hid.h>
32#include <linux/hiddev.h>
Jiri Kosinac080d892007-01-25 11:43:31 +010033#include <linux/hid-debug.h>
Jiri Kosina86166b72007-05-14 09:57:40 +020034#include <linux/hidraw.h>
Jiri Kosinadde58452006-12-08 18:40:44 +010035
Jiri Slaby5f22a792008-05-16 11:49:19 +020036#include "hid-ids.h"
37
Jiri Kosinadde58452006-12-08 18:40:44 +010038/*
39 * Version Information
40 */
41
Jiri Kosina53149802007-01-09 13:24:25 +010042#define DRIVER_DESC "HID core driver"
Jiri Kosinadde58452006-12-08 18:40:44 +010043#define DRIVER_LICENSE "GPL"
44
Jiri Kosina58037eb2007-05-30 15:07:13 +020045int hid_debug = 0;
Anssi Hannula377e10f2008-03-22 23:50:13 +010046module_param_named(debug, hid_debug, int, 0600);
Jiri Kosinacd667ce2009-06-12 15:20:57 +020047MODULE_PARM_DESC(debug, "toggle HID debugging messages");
Jiri Kosina58037eb2007-05-30 15:07:13 +020048EXPORT_SYMBOL_GPL(hid_debug);
Jiri Kosina58037eb2007-05-30 15:07:13 +020049
Jiri Kosinadde58452006-12-08 18:40:44 +010050/*
Jiri Kosinadde58452006-12-08 18:40:44 +010051 * Register a new report for a device.
52 */
53
Michael Poole90a006a2010-01-24 22:32:29 -050054struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
Jiri Kosinadde58452006-12-08 18:40:44 +010055{
56 struct hid_report_enum *report_enum = device->report_enum + type;
57 struct hid_report *report;
58
59 if (report_enum->report_id_hash[id])
60 return report_enum->report_id_hash[id];
61
62 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
63 return NULL;
64
65 if (id != 0)
66 report_enum->numbered = 1;
67
68 report->id = id;
69 report->type = type;
70 report->size = 0;
71 report->device = device;
72 report_enum->report_id_hash[id] = report;
73
74 list_add_tail(&report->list, &report_enum->report_list);
75
76 return report;
77}
Michael Poole90a006a2010-01-24 22:32:29 -050078EXPORT_SYMBOL_GPL(hid_register_report);
Jiri Kosinadde58452006-12-08 18:40:44 +010079
80/*
81 * Register a new field for this report.
82 */
83
84static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
85{
86 struct hid_field *field;
87
88 if (report->maxfield == HID_MAX_FIELDS) {
Jiri Kosina58037eb2007-05-30 15:07:13 +020089 dbg_hid("too many fields in report\n");
Jiri Kosinadde58452006-12-08 18:40:44 +010090 return NULL;
91 }
92
93 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
94 + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
95
96 field->index = report->maxfield++;
97 report->field[field->index] = field;
98 field->usage = (struct hid_usage *)(field + 1);
Jiri Slaby282bfd42008-03-28 17:06:41 +010099 field->value = (s32 *)(field->usage + usages);
Jiri Kosinadde58452006-12-08 18:40:44 +0100100 field->report = report;
101
102 return field;
103}
104
105/*
106 * Open a collection. The type/usage is pushed on the stack.
107 */
108
109static int open_collection(struct hid_parser *parser, unsigned type)
110{
111 struct hid_collection *collection;
112 unsigned usage;
113
114 usage = parser->local.usage[0];
115
116 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200117 dbg_hid("collection stack overflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100118 return -1;
119 }
120
121 if (parser->device->maxcollection == parser->device->collection_size) {
122 collection = kmalloc(sizeof(struct hid_collection) *
123 parser->device->collection_size * 2, GFP_KERNEL);
124 if (collection == NULL) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200125 dbg_hid("failed to reallocate collection array\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100126 return -1;
127 }
128 memcpy(collection, parser->device->collection,
129 sizeof(struct hid_collection) *
130 parser->device->collection_size);
131 memset(collection + parser->device->collection_size, 0,
132 sizeof(struct hid_collection) *
133 parser->device->collection_size);
134 kfree(parser->device->collection);
135 parser->device->collection = collection;
136 parser->device->collection_size *= 2;
137 }
138
139 parser->collection_stack[parser->collection_stack_ptr++] =
140 parser->device->maxcollection;
141
142 collection = parser->device->collection +
143 parser->device->maxcollection++;
144 collection->type = type;
145 collection->usage = usage;
146 collection->level = parser->collection_stack_ptr - 1;
147
148 if (type == HID_COLLECTION_APPLICATION)
149 parser->device->maxapplication++;
150
151 return 0;
152}
153
154/*
155 * Close a collection.
156 */
157
158static int close_collection(struct hid_parser *parser)
159{
160 if (!parser->collection_stack_ptr) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200161 dbg_hid("collection stack underflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100162 return -1;
163 }
164 parser->collection_stack_ptr--;
165 return 0;
166}
167
168/*
169 * Climb up the stack, search for the specified collection type
170 * and return the usage.
171 */
172
173static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
174{
175 int n;
176 for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
177 if (parser->device->collection[parser->collection_stack[n]].type == type)
178 return parser->device->collection[parser->collection_stack[n]].usage;
179 return 0; /* we know nothing about this usage type */
180}
181
182/*
183 * Add a usage to the temporary parser table.
184 */
185
186static int hid_add_usage(struct hid_parser *parser, unsigned usage)
187{
188 if (parser->local.usage_index >= HID_MAX_USAGES) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200189 dbg_hid("usage index exceeded\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100190 return -1;
191 }
192 parser->local.usage[parser->local.usage_index] = usage;
193 parser->local.collection_index[parser->local.usage_index] =
194 parser->collection_stack_ptr ?
195 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
196 parser->local.usage_index++;
197 return 0;
198}
199
200/*
201 * Register a new field for this report.
202 */
203
204static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
205{
206 struct hid_report *report;
207 struct hid_field *field;
208 int usages;
209 unsigned offset;
210 int i;
211
212 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200213 dbg_hid("hid_register_report failed\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100214 return -1;
215 }
216
217 if (parser->global.logical_maximum < parser->global.logical_minimum) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200218 dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum);
Jiri Kosinadde58452006-12-08 18:40:44 +0100219 return -1;
220 }
221
222 offset = report->size;
223 report->size += parser->global.report_size * parser->global.report_count;
224
225 if (!parser->local.usage_index) /* Ignore padding fields */
226 return 0;
227
228 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
229
230 if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
231 return 0;
232
233 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
234 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
235 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
236
237 for (i = 0; i < usages; i++) {
238 int j = i;
239 /* Duplicate the last usage we parsed if we have excess values */
240 if (i >= parser->local.usage_index)
241 j = parser->local.usage_index - 1;
242 field->usage[i].hid = parser->local.usage[j];
243 field->usage[i].collection_index =
244 parser->local.collection_index[j];
245 }
246
247 field->maxusage = usages;
248 field->flags = flags;
249 field->report_offset = offset;
250 field->report_type = report_type;
251 field->report_size = parser->global.report_size;
252 field->report_count = parser->global.report_count;
253 field->logical_minimum = parser->global.logical_minimum;
254 field->logical_maximum = parser->global.logical_maximum;
255 field->physical_minimum = parser->global.physical_minimum;
256 field->physical_maximum = parser->global.physical_maximum;
257 field->unit_exponent = parser->global.unit_exponent;
258 field->unit = parser->global.unit;
259
260 return 0;
261}
262
263/*
264 * Read data value from item.
265 */
266
267static u32 item_udata(struct hid_item *item)
268{
269 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200270 case 1: return item->data.u8;
271 case 2: return item->data.u16;
272 case 4: return item->data.u32;
Jiri Kosinadde58452006-12-08 18:40:44 +0100273 }
274 return 0;
275}
276
277static s32 item_sdata(struct hid_item *item)
278{
279 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200280 case 1: return item->data.s8;
281 case 2: return item->data.s16;
282 case 4: return item->data.s32;
Jiri Kosinadde58452006-12-08 18:40:44 +0100283 }
284 return 0;
285}
286
287/*
288 * Process a global item.
289 */
290
291static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
292{
293 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200294 case HID_GLOBAL_ITEM_TAG_PUSH:
Jiri Kosinadde58452006-12-08 18:40:44 +0100295
Jiri Slaby880d29f2008-06-18 23:55:41 +0200296 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
297 dbg_hid("global enviroment stack overflow\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100298 return -1;
Jiri Slaby880d29f2008-06-18 23:55:41 +0200299 }
300
301 memcpy(parser->global_stack + parser->global_stack_ptr++,
302 &parser->global, sizeof(struct hid_global));
303 return 0;
304
305 case HID_GLOBAL_ITEM_TAG_POP:
306
307 if (!parser->global_stack_ptr) {
308 dbg_hid("global enviroment stack underflow\n");
309 return -1;
310 }
311
312 memcpy(&parser->global, parser->global_stack +
313 --parser->global_stack_ptr, sizeof(struct hid_global));
314 return 0;
315
316 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
317 parser->global.usage_page = item_udata(item);
318 return 0;
319
320 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
321 parser->global.logical_minimum = item_sdata(item);
322 return 0;
323
324 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
325 if (parser->global.logical_minimum < 0)
326 parser->global.logical_maximum = item_sdata(item);
327 else
328 parser->global.logical_maximum = item_udata(item);
329 return 0;
330
331 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
332 parser->global.physical_minimum = item_sdata(item);
333 return 0;
334
335 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
336 if (parser->global.physical_minimum < 0)
337 parser->global.physical_maximum = item_sdata(item);
338 else
339 parser->global.physical_maximum = item_udata(item);
340 return 0;
341
342 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
343 parser->global.unit_exponent = item_sdata(item);
344 return 0;
345
346 case HID_GLOBAL_ITEM_TAG_UNIT:
347 parser->global.unit = item_udata(item);
348 return 0;
349
350 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
351 parser->global.report_size = item_udata(item);
352 if (parser->global.report_size > 32) {
353 dbg_hid("invalid report_size %d\n",
354 parser->global.report_size);
355 return -1;
356 }
357 return 0;
358
359 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
360 parser->global.report_count = item_udata(item);
361 if (parser->global.report_count > HID_MAX_USAGES) {
362 dbg_hid("invalid report_count %d\n",
363 parser->global.report_count);
364 return -1;
365 }
366 return 0;
367
368 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
369 parser->global.report_id = item_udata(item);
370 if (parser->global.report_id == 0) {
371 dbg_hid("report_id 0 is invalid\n");
372 return -1;
373 }
374 return 0;
375
376 default:
377 dbg_hid("unknown global tag 0x%x\n", item->tag);
378 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100379 }
380}
381
382/*
383 * Process a local item.
384 */
385
386static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
387{
388 __u32 data;
389 unsigned n;
390
Jiri Kosina722612c2010-01-05 11:45:52 +0100391 /* Local delimiter could have value 0, which allows size to be 0 */
392 if (item->size == 0 && item->tag != HID_LOCAL_ITEM_TAG_DELIMITER) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200393 dbg_hid("item data expected for local item\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100394 return -1;
395 }
396
397 data = item_udata(item);
398
399 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200400 case HID_LOCAL_ITEM_TAG_DELIMITER:
Jiri Kosinadde58452006-12-08 18:40:44 +0100401
Jiri Slaby880d29f2008-06-18 23:55:41 +0200402 if (data) {
403 /*
404 * We treat items before the first delimiter
405 * as global to all usage sets (branch 0).
406 * In the moment we process only these global
407 * items and the first delimiter set.
408 */
409 if (parser->local.delimiter_depth != 0) {
410 dbg_hid("nested delimiters\n");
411 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100412 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200413 parser->local.delimiter_depth++;
414 parser->local.delimiter_branch++;
415 } else {
416 if (parser->local.delimiter_depth < 1) {
417 dbg_hid("bogus close delimiter\n");
418 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100419 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200420 parser->local.delimiter_depth--;
421 }
422 return 1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100423
Jiri Slaby880d29f2008-06-18 23:55:41 +0200424 case HID_LOCAL_ITEM_TAG_USAGE:
Jiri Kosinadde58452006-12-08 18:40:44 +0100425
Jiri Slaby880d29f2008-06-18 23:55:41 +0200426 if (parser->local.delimiter_branch > 1) {
427 dbg_hid("alternative usage ignored\n");
Jiri Kosinadde58452006-12-08 18:40:44 +0100428 return 0;
Jiri Slaby880d29f2008-06-18 23:55:41 +0200429 }
Jiri Kosinadde58452006-12-08 18:40:44 +0100430
Jiri Slaby880d29f2008-06-18 23:55:41 +0200431 if (item->size <= 2)
432 data = (parser->global.usage_page << 16) + data;
Jiri Kosinadde58452006-12-08 18:40:44 +0100433
Jiri Slaby880d29f2008-06-18 23:55:41 +0200434 return hid_add_usage(parser, data);
435
436 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
437
438 if (parser->local.delimiter_branch > 1) {
439 dbg_hid("alternative usage ignored\n");
440 return 0;
441 }
442
443 if (item->size <= 2)
444 data = (parser->global.usage_page << 16) + data;
445
446 parser->local.usage_minimum = data;
447 return 0;
448
449 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
450
451 if (parser->local.delimiter_branch > 1) {
452 dbg_hid("alternative usage ignored\n");
453 return 0;
454 }
455
456 if (item->size <= 2)
457 data = (parser->global.usage_page << 16) + data;
458
459 for (n = parser->local.usage_minimum; n <= data; n++)
460 if (hid_add_usage(parser, n)) {
461 dbg_hid("hid_add_usage failed\n");
462 return -1;
Jiri Kosinadde58452006-12-08 18:40:44 +0100463 }
Jiri Slaby880d29f2008-06-18 23:55:41 +0200464 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100465
Jiri Slaby880d29f2008-06-18 23:55:41 +0200466 default:
Jiri Kosinadde58452006-12-08 18:40:44 +0100467
Jiri Slaby880d29f2008-06-18 23:55:41 +0200468 dbg_hid("unknown local item tag 0x%x\n", item->tag);
469 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100470 }
471 return 0;
472}
473
474/*
475 * Process a main item.
476 */
477
478static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
479{
480 __u32 data;
481 int ret;
482
483 data = item_udata(item);
484
485 switch (item->tag) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200486 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
487 ret = open_collection(parser, data & 0xff);
488 break;
489 case HID_MAIN_ITEM_TAG_END_COLLECTION:
490 ret = close_collection(parser);
491 break;
492 case HID_MAIN_ITEM_TAG_INPUT:
493 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
494 break;
495 case HID_MAIN_ITEM_TAG_OUTPUT:
496 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
497 break;
498 case HID_MAIN_ITEM_TAG_FEATURE:
499 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
500 break;
501 default:
502 dbg_hid("unknown main item tag 0x%x\n", item->tag);
503 ret = 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100504 }
505
506 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
507
508 return ret;
509}
510
511/*
512 * Process a reserved item.
513 */
514
515static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
516{
Jiri Kosina58037eb2007-05-30 15:07:13 +0200517 dbg_hid("reserved item type, tag 0x%x\n", item->tag);
Jiri Kosinadde58452006-12-08 18:40:44 +0100518 return 0;
519}
520
521/*
522 * Free a report and all registered fields. The field->usage and
523 * field->value table's are allocated behind the field, so we need
524 * only to free(field) itself.
525 */
526
527static void hid_free_report(struct hid_report *report)
528{
529 unsigned n;
530
531 for (n = 0; n < report->maxfield; n++)
532 kfree(report->field[n]);
533 kfree(report);
534}
535
536/*
537 * Free a device structure, all reports, and all fields.
538 */
539
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200540static void hid_device_release(struct device *dev)
Jiri Kosinadde58452006-12-08 18:40:44 +0100541{
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200542 struct hid_device *device = container_of(dev, struct hid_device, dev);
543 unsigned i, j;
Jiri Kosinadde58452006-12-08 18:40:44 +0100544
545 for (i = 0; i < HID_REPORT_TYPES; i++) {
546 struct hid_report_enum *report_enum = device->report_enum + i;
547
548 for (j = 0; j < 256; j++) {
549 struct hid_report *report = report_enum->report_id_hash[j];
550 if (report)
551 hid_free_report(report);
552 }
553 }
554
555 kfree(device->rdesc);
Jiri Kosina767fe782007-01-24 23:05:07 +0100556 kfree(device->collection);
Jiri Kosinadde58452006-12-08 18:40:44 +0100557 kfree(device);
558}
559
560/*
561 * Fetch a report description item from the data stream. We support long
562 * items, though they are not used yet.
563 */
564
565static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
566{
567 u8 b;
568
569 if ((end - start) <= 0)
570 return NULL;
571
572 b = *start++;
573
574 item->type = (b >> 2) & 3;
575 item->tag = (b >> 4) & 15;
576
577 if (item->tag == HID_ITEM_TAG_LONG) {
578
579 item->format = HID_ITEM_FORMAT_LONG;
580
581 if ((end - start) < 2)
582 return NULL;
583
584 item->size = *start++;
585 item->tag = *start++;
586
587 if ((end - start) < item->size)
588 return NULL;
589
590 item->data.longdata = start;
591 start += item->size;
592 return start;
593 }
594
595 item->format = HID_ITEM_FORMAT_SHORT;
596 item->size = b & 3;
597
598 switch (item->size) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200599 case 0:
600 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100601
Jiri Slaby880d29f2008-06-18 23:55:41 +0200602 case 1:
603 if ((end - start) < 1)
604 return NULL;
605 item->data.u8 = *start++;
606 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100607
Jiri Slaby880d29f2008-06-18 23:55:41 +0200608 case 2:
609 if ((end - start) < 2)
610 return NULL;
611 item->data.u16 = get_unaligned_le16(start);
612 start = (__u8 *)((__le16 *)start + 1);
613 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100614
Jiri Slaby880d29f2008-06-18 23:55:41 +0200615 case 3:
616 item->size++;
617 if ((end - start) < 4)
618 return NULL;
619 item->data.u32 = get_unaligned_le32(start);
620 start = (__u8 *)((__le32 *)start + 1);
621 return start;
Jiri Kosinadde58452006-12-08 18:40:44 +0100622 }
623
624 return NULL;
625}
626
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200627/**
628 * hid_parse_report - parse device report
629 *
630 * @device: hid device
631 * @start: report start
632 * @size: report size
633 *
Jiri Kosinadde58452006-12-08 18:40:44 +0100634 * Parse a report description into a hid_device structure. Reports are
635 * enumerated, fields are attached to these reports.
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200636 * 0 returned on success, otherwise nonzero error value.
Jiri Kosinadde58452006-12-08 18:40:44 +0100637 */
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200638int hid_parse_report(struct hid_device *device, __u8 *start,
639 unsigned size)
Jiri Kosinadde58452006-12-08 18:40:44 +0100640{
Jiri Kosinadde58452006-12-08 18:40:44 +0100641 struct hid_parser *parser;
642 struct hid_item item;
643 __u8 *end;
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200644 int ret;
Jiri Kosinadde58452006-12-08 18:40:44 +0100645 static int (*dispatch_type[])(struct hid_parser *parser,
646 struct hid_item *item) = {
647 hid_parser_main,
648 hid_parser_global,
649 hid_parser_local,
650 hid_parser_reserved
651 };
652
Jiri Slabyc500c972008-05-16 11:49:16 +0200653 if (device->driver->report_fixup)
654 device->driver->report_fixup(device, start, size);
655
Julia Lawall1721a232010-05-15 23:19:30 +0200656 device->rdesc = kmemdup(start, size, GFP_KERNEL);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200657 if (device->rdesc == NULL)
658 return -ENOMEM;
Jiri Kosinadde58452006-12-08 18:40:44 +0100659 device->rsize = size;
660
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200661 parser = vmalloc(sizeof(struct hid_parser));
662 if (!parser) {
663 ret = -ENOMEM;
664 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100665 }
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200666
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100667 memset(parser, 0, sizeof(struct hid_parser));
Jiri Kosinadde58452006-12-08 18:40:44 +0100668 parser->device = device;
669
670 end = start + size;
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200671 ret = -EINVAL;
Jiri Kosinadde58452006-12-08 18:40:44 +0100672 while ((start = fetch_item(start, end, &item)) != NULL) {
673
674 if (item.format != HID_ITEM_FORMAT_SHORT) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200675 dbg_hid("unexpected long global item\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200676 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100677 }
678
679 if (dispatch_type[item.type](parser, &item)) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200680 dbg_hid("item %u %u %u %u parsing failed\n",
Jiri Kosinadde58452006-12-08 18:40:44 +0100681 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200682 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100683 }
684
685 if (start == end) {
686 if (parser->collection_stack_ptr) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200687 dbg_hid("unbalanced collection at end of report description\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200688 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100689 }
690 if (parser->local.delimiter_depth) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200691 dbg_hid("unbalanced delimiter at end of report description\n");
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200692 goto err;
Jiri Kosinadde58452006-12-08 18:40:44 +0100693 }
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100694 vfree(parser);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200695 return 0;
Jiri Kosinadde58452006-12-08 18:40:44 +0100696 }
697 }
698
Jiri Kosina58037eb2007-05-30 15:07:13 +0200699 dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200700err:
Jiri Kosina47a80ed2007-03-12 14:55:12 +0100701 vfree(parser);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200702 return ret;
Jiri Kosinadde58452006-12-08 18:40:44 +0100703}
Jiri Kosina229695e2006-12-08 18:40:53 +0100704EXPORT_SYMBOL_GPL(hid_parse_report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100705
706/*
707 * Convert a signed n-bit integer to signed 32-bit integer. Common
708 * cases are done through the compiler, the screwed things has to be
709 * done by hand.
710 */
711
712static s32 snto32(__u32 value, unsigned n)
713{
714 switch (n) {
Jiri Slaby880d29f2008-06-18 23:55:41 +0200715 case 8: return ((__s8)value);
716 case 16: return ((__s16)value);
717 case 32: return ((__s32)value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100718 }
719 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
720}
721
722/*
723 * Convert a signed 32-bit integer to a signed n-bit integer.
724 */
725
726static u32 s32ton(__s32 value, unsigned n)
727{
728 s32 a = value >> (n - 1);
729 if (a && a != -1)
730 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
731 return value & ((1 << n) - 1);
732}
733
734/*
735 * Extract/implement a data field from/to a little endian report (bit array).
736 *
737 * Code sort-of follows HID spec:
738 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
739 *
740 * While the USB HID spec allows unlimited length bit fields in "report
741 * descriptors", most devices never use more than 16 bits.
742 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
743 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
744 */
745
746static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
747{
748 u64 x;
749
Jiri Kosinac4124c92007-11-30 11:12:58 +0100750 if (n > 32)
751 printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n",
752 n, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100753
754 report += offset >> 3; /* adjust byte index */
Jiri Kosina229695e2006-12-08 18:40:53 +0100755 offset &= 7; /* now only need bit offset into one byte */
Harvey Harrisonc1050682008-04-29 01:03:31 -0700756 x = get_unaligned_le64(report);
Jiri Kosina229695e2006-12-08 18:40:53 +0100757 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
Jiri Kosinadde58452006-12-08 18:40:44 +0100758 return (u32) x;
759}
760
761/*
762 * "implement" : set bits in a little endian bit stream.
763 * Same concepts as "extract" (see comments above).
764 * The data mangled in the bit stream remains in little endian
765 * order the whole time. It make more sense to talk about
766 * endianness of register values by considering a register
767 * a "cached" copy of the little endiad bit stream.
768 */
769static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
770{
Harvey Harrison6f0168d2008-05-16 11:00:23 +0200771 u64 x;
Jiri Kosinadde58452006-12-08 18:40:44 +0100772 u64 m = (1ULL << n) - 1;
773
Jiri Kosinac4124c92007-11-30 11:12:58 +0100774 if (n > 32)
775 printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n",
776 n, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100777
Jiri Kosinac4124c92007-11-30 11:12:58 +0100778 if (value > m)
779 printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n",
780 value, current->comm);
Jiri Kosinadde58452006-12-08 18:40:44 +0100781 WARN_ON(value > m);
782 value &= m;
783
784 report += offset >> 3;
785 offset &= 7;
786
Harvey Harrison6f0168d2008-05-16 11:00:23 +0200787 x = get_unaligned_le64(report);
788 x &= ~(m << offset);
789 x |= ((u64)value) << offset;
790 put_unaligned_le64(x, report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100791}
792
793/*
794 * Search an array for a value.
795 */
796
797static __inline__ int search(__s32 *array, __s32 value, unsigned n)
798{
799 while (n--) {
800 if (*array++ == value)
801 return 0;
802 }
803 return -1;
804}
805
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200806/**
807 * hid_match_report - check if driver's raw_event should be called
808 *
809 * @hid: hid device
810 * @report_type: type to match against
811 *
812 * compare hid->driver->report_table->report_type to report->type
813 */
814static int hid_match_report(struct hid_device *hid, struct hid_report *report)
Jiri Kosinadde58452006-12-08 18:40:44 +0100815{
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200816 const struct hid_report_id *id = hid->driver->report_table;
817
818 if (!id) /* NULL means all */
819 return 1;
820
821 for (; id->report_type != HID_TERMINATOR; id++)
822 if (id->report_type == HID_ANY_ID ||
823 id->report_type == report->type)
824 return 1;
825 return 0;
826}
827
828/**
829 * hid_match_usage - check if driver's event should be called
830 *
831 * @hid: hid device
832 * @usage: usage to match against
833 *
834 * compare hid->driver->usage_table->usage_{type,code} to
835 * usage->usage_{type,code}
836 */
837static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
838{
839 const struct hid_usage_id *id = hid->driver->usage_table;
840
841 if (!id) /* NULL means all */
842 return 1;
843
844 for (; id->usage_type != HID_ANY_ID - 1; id++)
845 if ((id->usage_hid == HID_ANY_ID ||
846 id->usage_hid == usage->hid) &&
847 (id->usage_type == HID_ANY_ID ||
848 id->usage_type == usage->type) &&
849 (id->usage_code == HID_ANY_ID ||
850 id->usage_code == usage->code))
851 return 1;
852 return 0;
853}
854
855static void hid_process_event(struct hid_device *hid, struct hid_field *field,
856 struct hid_usage *usage, __s32 value, int interrupt)
857{
858 struct hid_driver *hdrv = hid->driver;
859 int ret;
860
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200861 hid_dump_input(hid, usage, value);
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200862
863 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
864 ret = hdrv->event(hid, field, usage, value);
865 if (ret != 0) {
866 if (ret < 0)
867 dbg_hid("%s's event failed with %d\n",
868 hdrv->name, ret);
869 return;
870 }
871 }
872
Jiri Kosinadde58452006-12-08 18:40:44 +0100873 if (hid->claimed & HID_CLAIMED_INPUT)
874 hidinput_hid_event(hid, field, usage, value);
Jiri Kosinaaa938f72006-12-08 18:41:10 +0100875 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
876 hid->hiddev_hid_event(hid, field, usage, value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100877}
878
879/*
880 * Analyse a received field, and fetch the data from it. The field
881 * content is stored for next report processing (we do differential
882 * reporting to the layer).
883 */
884
Adrian Bunkabdff0f2008-03-31 01:53:56 +0200885static void hid_input_field(struct hid_device *hid, struct hid_field *field,
886 __u8 *data, int interrupt)
Jiri Kosinadde58452006-12-08 18:40:44 +0100887{
888 unsigned n;
889 unsigned count = field->report_count;
890 unsigned offset = field->report_offset;
891 unsigned size = field->report_size;
892 __s32 min = field->logical_minimum;
893 __s32 max = field->logical_maximum;
894 __s32 *value;
895
896 if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
897 return;
898
899 for (n = 0; n < count; n++) {
900
901 value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
902 extract(data, offset + n * size, size);
903
904 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
905 && value[n] >= min && value[n] <= max
906 && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
907 goto exit;
908 }
909
910 for (n = 0; n < count; n++) {
911
912 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
913 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
914 continue;
915 }
916
917 if (field->value[n] >= min && field->value[n] <= max
918 && field->usage[field->value[n] - min].hid
919 && search(value, field->value[n], count))
920 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
921
922 if (value[n] >= min && value[n] <= max
923 && field->usage[value[n] - min].hid
924 && search(field->value, value[n], count))
925 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
926 }
927
928 memcpy(field->value, value, count * sizeof(__s32));
929exit:
930 kfree(value);
931}
Jiri Kosinadde58452006-12-08 18:40:44 +0100932
933/*
934 * Output the field into the report.
935 */
936
937static void hid_output_field(struct hid_field *field, __u8 *data)
938{
939 unsigned count = field->report_count;
940 unsigned offset = field->report_offset;
941 unsigned size = field->report_size;
942 unsigned n;
943
944 for (n = 0; n < count; n++) {
945 if (field->logical_minimum < 0) /* signed values */
946 implement(data, offset + n * size, size, s32ton(field->value[n], size));
947 else /* unsigned values */
948 implement(data, offset + n * size, size, field->value[n]);
949 }
950}
951
952/*
953 * Create a report.
954 */
955
Jiri Kosina229695e2006-12-08 18:40:53 +0100956void hid_output_report(struct hid_report *report, __u8 *data)
Jiri Kosinadde58452006-12-08 18:40:44 +0100957{
958 unsigned n;
959
960 if (report->id > 0)
961 *data++ = report->id;
962
Pete Zaitcev75c28df2010-04-12 12:16:11 -0600963 memset(data, 0, ((report->size - 1) >> 3) + 1);
Jiri Kosinadde58452006-12-08 18:40:44 +0100964 for (n = 0; n < report->maxfield; n++)
965 hid_output_field(report->field[n], data);
966}
Jiri Kosina229695e2006-12-08 18:40:53 +0100967EXPORT_SYMBOL_GPL(hid_output_report);
Jiri Kosinadde58452006-12-08 18:40:44 +0100968
969/*
970 * Set a field value. The report this field belongs to has to be
971 * created and transferred to the device, to set this value in the
972 * device.
973 */
974
975int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
976{
977 unsigned size = field->report_size;
978
Jiri Kosinacd667ce2009-06-12 15:20:57 +0200979 hid_dump_input(field->report->device, field->usage + offset, value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100980
981 if (offset >= field->report_count) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200982 dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count);
Jiri Kosinadde58452006-12-08 18:40:44 +0100983 return -1;
984 }
985 if (field->logical_minimum < 0) {
986 if (value != snto32(s32ton(value, size), size)) {
Jiri Kosina58037eb2007-05-30 15:07:13 +0200987 dbg_hid("value %d is out of range\n", value);
Jiri Kosinadde58452006-12-08 18:40:44 +0100988 return -1;
989 }
990 }
991 field->value[offset] = value;
992 return 0;
993}
Jiri Kosina229695e2006-12-08 18:40:53 +0100994EXPORT_SYMBOL_GPL(hid_set_field);
Jiri Kosinadde58452006-12-08 18:40:44 +0100995
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200996static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
997 const u8 *data)
998{
999 struct hid_report *report;
1000 unsigned int n = 0; /* Normally report number is 0 */
1001
1002 /* Device uses numbered reports, data[0] is report number */
1003 if (report_enum->numbered)
1004 n = *data;
1005
1006 report = report_enum->report_id_hash[n];
1007 if (report == NULL)
1008 dbg_hid("undefined report_id %u received\n", n);
1009
1010 return report;
1011}
1012
1013void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1014 int interrupt)
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001015{
1016 struct hid_report_enum *report_enum = hid->report_enum + type;
1017 struct hid_report *report;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001018 unsigned int a;
1019 int rsize, csize = size;
1020 u8 *cdata = data;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001021
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001022 report = hid_get_report(report_enum, data);
1023 if (!report)
1024 return;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001025
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001026 if (report_enum->numbered) {
1027 cdata++;
1028 csize--;
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001029 }
1030
1031 rsize = ((report->size - 1) >> 3) + 1;
1032
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001033 if (csize < rsize) {
1034 dbg_hid("report %d is too short, (%d < %d)\n", report->id,
1035 csize, rsize);
1036 memset(cdata + csize, 0, rsize - csize);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001037 }
1038
1039 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
1040 hid->hiddev_report_event(hid, report);
Alan Ott5a38f2c2010-04-26 18:34:46 -04001041 if (hid->claimed & HID_CLAIMED_HIDRAW)
1042 hidraw_report_event(hid, data, size);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001043
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001044 for (a = 0; a < report->maxfield; a++)
1045 hid_input_field(hid, report->field[a], cdata, interrupt);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001046
1047 if (hid->claimed & HID_CLAIMED_INPUT)
1048 hidinput_report_event(hid, report);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001049}
1050EXPORT_SYMBOL_GPL(hid_report_raw_event);
1051
1052/**
1053 * hid_input_report - report data from lower layer (usb, bt...)
1054 *
1055 * @hid: hid device
1056 * @type: HID report type (HID_*_REPORT)
1057 * @data: report contents
1058 * @size: size of data parameter
Jiri Kosinaff9b00a2009-10-01 16:03:13 +02001059 * @interrupt: distinguish between interrupt and control transfers
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001060 *
1061 * This is data entry for lower layers.
1062 */
1063int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1064{
Julia Lawall76c317d2009-07-19 17:26:13 +02001065 struct hid_report_enum *report_enum;
1066 struct hid_driver *hdrv;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001067 struct hid_report *report;
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001068 char *buf;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001069 unsigned int i;
1070 int ret;
1071
1072 if (!hid || !hid->driver)
1073 return -ENODEV;
Julia Lawall76c317d2009-07-19 17:26:13 +02001074 report_enum = hid->report_enum + type;
1075 hdrv = hid->driver;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001076
1077 if (!size) {
1078 dbg_hid("empty report\n");
1079 return -1;
1080 }
1081
Jiri Kosinad1ff6522009-09-15 11:59:49 +02001082 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001083
Jiri Kosinaf77e3472010-03-18 14:11:53 +01001084 if (!buf)
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001085 goto nomem;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001086
1087 /* dump the report */
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001088 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
Jiri Kosina1caea612010-03-18 12:09:53 +01001089 "\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001090 hid_debug_event(hid, buf);
Jiri Kosina1caea612010-03-18 12:09:53 +01001091
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001092 for (i = 0; i < size; i++) {
1093 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
1094 " %02x", data[i]);
1095 hid_debug_event(hid, buf);
1096 }
1097 hid_debug_event(hid, "\n");
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001098 kfree(buf);
1099
1100nomem:
Jiri Kosinaf77e3472010-03-18 14:11:53 +01001101 report = hid_get_report(report_enum, data);
1102
1103 if (!report)
1104 return -1;
1105
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001106 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1107 ret = hdrv->raw_event(hid, report, data, size);
1108 if (ret != 0)
1109 return ret < 0 ? ret : 0;
1110 }
1111
1112 hid_report_raw_event(hid, type, data, size, interrupt);
Jiri Kosinaaa8de2f2006-12-08 18:41:17 +01001113
1114 return 0;
1115}
1116EXPORT_SYMBOL_GPL(hid_input_report);
1117
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001118static bool hid_match_one_id(struct hid_device *hdev,
1119 const struct hid_device_id *id)
1120{
1121 return id->bus == hdev->bus &&
1122 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1123 (id->product == HID_ANY_ID || id->product == hdev->product);
1124}
1125
1126static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1127 const struct hid_device_id *id)
1128{
1129 for (; id->bus; id++)
1130 if (hid_match_one_id(hdev, id))
1131 return id;
1132
1133 return NULL;
1134}
1135
1136static const struct hid_device_id hid_hiddev_list[] = {
Richard Hughesc0bd6a42008-08-27 11:19:37 +02001137 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1138 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001139 { }
1140};
1141
1142static bool hid_hiddev(struct hid_device *hdev)
1143{
1144 return !!hid_match_id(hdev, hid_hiddev_list);
1145}
1146
Jiri Slaby93c10132008-06-27 00:04:24 +02001147int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1148{
1149 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1150 "Joystick", "Gamepad", "Keyboard", "Keypad",
1151 "Multi-Axis Controller"
1152 };
1153 const char *type, *bus;
1154 char buf[64];
1155 unsigned int i;
1156 int len;
1157
Bastien Nocerab5e5a372010-04-16 17:19:50 +01001158 if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
1159 connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
Jiri Slaby93c10132008-06-27 00:04:24 +02001160 if (hdev->bus != BUS_USB)
1161 connect_mask &= ~HID_CONNECT_HIDDEV;
Jiri Kosina0f37cd02008-08-20 19:13:52 +02001162 if (hid_hiddev(hdev))
1163 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
Jiri Slaby93c10132008-06-27 00:04:24 +02001164
1165 if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1166 connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1167 hdev->claimed |= HID_CLAIMED_INPUT;
1168 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1169 !hdev->hiddev_connect(hdev,
1170 connect_mask & HID_CONNECT_HIDDEV_FORCE))
1171 hdev->claimed |= HID_CLAIMED_HIDDEV;
1172 if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1173 hdev->claimed |= HID_CLAIMED_HIDRAW;
1174
1175 if (!hdev->claimed) {
1176 dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
1177 "hidraw\n");
1178 return -ENODEV;
1179 }
1180
1181 if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1182 (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1183 hdev->ff_init(hdev);
1184
1185 len = 0;
1186 if (hdev->claimed & HID_CLAIMED_INPUT)
1187 len += sprintf(buf + len, "input");
1188 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1189 len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1190 hdev->minor);
1191 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1192 len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1193 ((struct hidraw *)hdev->hidraw)->minor);
1194
1195 type = "Device";
1196 for (i = 0; i < hdev->maxcollection; i++) {
1197 struct hid_collection *col = &hdev->collection[i];
1198 if (col->type == HID_COLLECTION_APPLICATION &&
1199 (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1200 (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1201 type = types[col->usage & 0xffff];
1202 break;
1203 }
1204 }
1205
1206 switch (hdev->bus) {
1207 case BUS_USB:
1208 bus = "USB";
1209 break;
1210 case BUS_BLUETOOTH:
1211 bus = "BLUETOOTH";
1212 break;
1213 default:
1214 bus = "<UNKNOWN>";
1215 }
1216
1217 dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1218 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1219 type, hdev->name, hdev->phys);
1220
1221 return 0;
1222}
1223EXPORT_SYMBOL_GPL(hid_connect);
1224
Jiri Kosinac4c259b2009-09-15 16:27:45 +02001225void hid_disconnect(struct hid_device *hdev)
1226{
1227 if (hdev->claimed & HID_CLAIMED_INPUT)
1228 hidinput_disconnect(hdev);
1229 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1230 hdev->hiddev_disconnect(hdev);
1231 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1232 hidraw_disconnect(hdev);
1233}
1234EXPORT_SYMBOL_GPL(hid_disconnect);
1235
Jiri Kosinabae7eb32009-01-28 23:06:37 +01001236/* a list of devices for which there is a specialized driver on HID bus */
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001237static const struct hid_device_id hid_blacklist[] = {
Stephane Chattyb6353f42009-12-22 23:04:17 +01001238 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
Stephane Chatty6dec1432010-04-11 14:51:24 +02001239 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) },
Jiri Slaby14a21cd2008-06-23 23:31:09 +02001240 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1241 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
Jiri Kosinadf9bcac2008-10-14 22:45:40 +02001242 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001243 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1244 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
Michael Poole128537c2010-02-06 12:24:36 -05001245 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001246 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1247 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1248 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1249 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1250 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1251 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1252 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1253 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1254 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1255 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1256 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
Ryan Finniefef3f572009-03-05 10:18:01 +01001257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
1259 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001260 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1261 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1262 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1263 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1264 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1265 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
Jan Scholzee8a1a02008-11-26 15:33:45 +01001266 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1267 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1268 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001269 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1270 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1271 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1272 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1273 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1274 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
Henrik Rydberga96d6ef2008-11-04 20:03:45 +01001275 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1276 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1277 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
Christian Schuerer-Waldheim23aeb612010-01-06 14:49:57 +01001278 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1279 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1280 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001281 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1282 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
Jiri Slabyb5635b12008-06-24 23:24:57 +02001283 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
Wayne Thomasbf280622010-04-29 00:45:01 +02001284 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
Stephane Chatty36213e12010-04-15 00:28:11 +02001285 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
Stephane Chattyba4d8ab2010-04-22 23:24:36 +02001286 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
Jiri Slaby3b239cd2008-06-24 20:42:25 +02001287 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
Raphaël Doursenaud1ce31b22010-04-08 13:40:52 +02001288 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
Jiri Slabyfcfacfd2008-06-24 22:48:52 +02001289 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
Don Prince3a370ca2010-05-12 15:18:59 +02001290 { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
Jiri Slaby0f221322008-06-23 22:54:08 +02001291 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1292 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
Jiri Kosinae8d0eab2009-12-02 22:54:11 +01001293 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
Jiri Slaby0f221322008-06-23 22:54:08 +02001294 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
Richard Walmsley3f866fb2009-03-04 22:12:04 +13001295 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
Stephane Chatty0c3910c2010-04-10 16:43:08 +02001296 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) },
Jiri Slaby1f243e32008-06-24 21:11:21 +02001297 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
Jiri Kosina5181e592008-11-17 01:44:38 +01001298 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
Jiri Kosina578f3a32008-11-20 15:55:38 +01001299 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
Jiri Kosina5181e592008-11-17 01:44:38 +01001300 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
Lukasz Lubojanski42859e02008-12-11 22:07:59 +01001301 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
Jiri Slaby949f8fe2008-07-24 23:35:13 +02001302 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
Jiri Kosina1e093202008-10-17 11:52:23 +02001303 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
Cory Maccarronec2fd1a42010-05-22 13:00:28 -07001304 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
Jiri Kosinafdf93aa2009-03-04 16:09:40 +01001305 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
Jiri Kosina79422742009-03-11 11:43:27 +01001306 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
Jiri Slabyb5635b12008-06-24 23:24:57 +02001307 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001308 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1309 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1310 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1311 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1312 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1313 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1314 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001315 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1316 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
Jiri Slaby5f22a792008-05-16 11:49:19 +02001317 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1318 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001319 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1320 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1321 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
Jiri Kosinafd30ea82009-06-23 12:11:31 +02001322 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001323 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
Gary Stein74f292c2010-01-13 00:25:58 +01001324 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001325 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
Christophe Borivant243b7062009-04-17 11:39:39 +02001327 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
Jiri Slaby606bd0a2008-07-04 23:06:45 +02001328 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
Jiri Kosina24985cf2009-11-13 10:45:53 +01001329 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
1330 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
Bruno Prémont236db472010-03-30 22:33:50 +02001331 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
1332 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
Jiri Slaby78a849a682008-06-20 21:26:11 +02001333 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1334 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1335 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1336 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1337 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
Jiri Slaby3b8006e2008-06-25 00:07:50 +02001338 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
Rafi Rubin94011f92008-11-19 15:54:46 +01001339 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
micki6e328192010-06-19 11:37:29 +03001340 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
1344 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
1345 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
1346 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
1348 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
1349 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
1350 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
1351 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
1352 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
1353 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
1354 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
1355 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
1356 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
1357 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
Johnathon Harriscd9ec302010-01-21 14:36:52 +00001358 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
Jiri Slaby1e762532008-06-24 23:46:21 +02001359 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
Stephane Chatty49e47392010-01-13 00:29:16 +01001360 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
Alex Neblettf54405d2010-02-02 21:16:03 -08001361 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
Stefan Achatz14bf62c2010-03-18 16:19:43 +01001362 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
Jiri Slaby980a3da2008-06-25 22:31:48 +02001363 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
Don Princeb3558502010-05-17 11:42:39 +01001364 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
Jiri Slabybd28ce02008-06-25 23:47:04 +02001365 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
Bastien Noceraf9ce7c22010-01-20 12:01:53 +00001366 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +02001367 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
Stephane Chattyd3fb5452010-01-04 12:04:08 +01001368 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
Jiri Slaby90231e72008-06-23 21:56:07 +02001369 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001370 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1371 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
Ruben Aos Garralda7a84b132009-06-29 09:41:29 +02001372 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
1373 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001374 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
Markus Rathgeb3ee8f0a2010-03-13 17:29:43 +01001375 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001376 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
Lev Babievf14f5262009-01-04 00:36:56 +01001377 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
Bruno Premont711a6802009-07-13 14:19:58 +02001378 { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
Jussi Kivilinnafac733f2009-05-13 11:54:38 +03001379 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
Bastien Noceraca2dcd42009-05-11 17:18:12 +02001380 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Jiri Kosina96a78132010-04-23 00:22:07 +02001381 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Anssi Hannuladaedb3d2009-02-14 11:45:05 +02001382 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1383 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
Don Princea9885c82010-05-14 17:30:59 +01001384 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
Jiri Slaby8c19a512008-06-18 23:36:49 +02001385
Jiri Slaby78a849a682008-06-20 21:26:11 +02001386 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001387 { }
1388};
1389
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001390struct hid_dynid {
1391 struct list_head list;
1392 struct hid_device_id id;
1393};
1394
1395/**
1396 * store_new_id - add a new HID device ID to this driver and re-probe devices
1397 * @driver: target device driver
1398 * @buf: buffer for scanning device ID data
1399 * @count: input size
1400 *
1401 * Adds a new dynamic hid device ID to this driver,
1402 * and causes the driver to probe for all devices again.
1403 */
1404static ssize_t store_new_id(struct device_driver *drv, const char *buf,
1405 size_t count)
1406{
1407 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1408 struct hid_dynid *dynid;
1409 __u32 bus, vendor, product;
1410 unsigned long driver_data = 0;
1411 int ret;
1412
1413 ret = sscanf(buf, "%x %x %x %lx",
1414 &bus, &vendor, &product, &driver_data);
1415 if (ret < 3)
1416 return -EINVAL;
1417
1418 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
1419 if (!dynid)
1420 return -ENOMEM;
1421
1422 dynid->id.bus = bus;
1423 dynid->id.vendor = vendor;
1424 dynid->id.product = product;
1425 dynid->id.driver_data = driver_data;
1426
1427 spin_lock(&hdrv->dyn_lock);
1428 list_add_tail(&dynid->list, &hdrv->dyn_list);
1429 spin_unlock(&hdrv->dyn_lock);
1430
1431 ret = 0;
1432 if (get_driver(&hdrv->driver)) {
1433 ret = driver_attach(&hdrv->driver);
1434 put_driver(&hdrv->driver);
1435 }
1436
1437 return ret ? : count;
1438}
1439static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
1440
1441static void hid_free_dynids(struct hid_driver *hdrv)
1442{
1443 struct hid_dynid *dynid, *n;
1444
1445 spin_lock(&hdrv->dyn_lock);
1446 list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
1447 list_del(&dynid->list);
1448 kfree(dynid);
1449 }
1450 spin_unlock(&hdrv->dyn_lock);
1451}
1452
1453static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
1454 struct hid_driver *hdrv)
1455{
1456 struct hid_dynid *dynid;
1457
1458 spin_lock(&hdrv->dyn_lock);
1459 list_for_each_entry(dynid, &hdrv->dyn_list, list) {
1460 if (hid_match_one_id(hdev, &dynid->id)) {
1461 spin_unlock(&hdrv->dyn_lock);
1462 return &dynid->id;
1463 }
1464 }
1465 spin_unlock(&hdrv->dyn_lock);
1466
1467 return hid_match_id(hdev, hdrv->id_table);
1468}
1469
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001470static int hid_bus_match(struct device *dev, struct device_driver *drv)
1471{
1472 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1473 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1474
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001475 if (!hid_match_device(hdev, hdrv))
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001476 return 0;
1477
1478 /* generic wants all non-blacklisted */
1479 if (!strncmp(hdrv->name, "generic-", 8))
1480 return !hid_match_id(hdev, hid_blacklist);
1481
1482 return 1;
1483}
1484
1485static int hid_device_probe(struct device *dev)
1486{
1487 struct hid_driver *hdrv = container_of(dev->driver,
1488 struct hid_driver, driver);
1489 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1490 const struct hid_device_id *id;
1491 int ret = 0;
1492
1493 if (!hdev->driver) {
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001494 id = hid_match_device(hdev, hdrv);
Jiri Slabyc500c972008-05-16 11:49:16 +02001495 if (id == NULL)
1496 return -ENODEV;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001497
Jiri Slabyc500c972008-05-16 11:49:16 +02001498 hdev->driver = hdrv;
1499 if (hdrv->probe) {
1500 ret = hdrv->probe(hdev, id);
1501 } else { /* default probe */
1502 ret = hid_parse(hdev);
1503 if (!ret)
Jiri Slaby93c10132008-06-27 00:04:24 +02001504 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001505 }
Jiri Slabyc500c972008-05-16 11:49:16 +02001506 if (ret)
1507 hdev->driver = NULL;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001508 }
1509 return ret;
1510}
1511
1512static int hid_device_remove(struct device *dev)
1513{
1514 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1515 struct hid_driver *hdrv = hdev->driver;
1516
1517 if (hdrv) {
1518 if (hdrv->remove)
1519 hdrv->remove(hdev);
Jiri Slabyc500c972008-05-16 11:49:16 +02001520 else /* default remove */
1521 hid_hw_stop(hdev);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001522 hdev->driver = NULL;
1523 }
1524
1525 return 0;
1526}
1527
1528static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1529{
1530 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1531
1532 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1533 hdev->bus, hdev->vendor, hdev->product))
1534 return -ENOMEM;
1535
1536 if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1537 return -ENOMEM;
1538
1539 if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1540 return -ENOMEM;
1541
1542 if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1543 return -ENOMEM;
1544
1545 if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
1546 hdev->bus, hdev->vendor, hdev->product))
1547 return -ENOMEM;
1548
1549 return 0;
1550}
1551
1552static struct bus_type hid_bus_type = {
1553 .name = "hid",
1554 .match = hid_bus_match,
1555 .probe = hid_device_probe,
1556 .remove = hid_device_remove,
1557 .uevent = hid_uevent,
1558};
1559
Jiri Kosinabae7eb32009-01-28 23:06:37 +01001560/* a list of devices that shouldn't be handled by HID core at all */
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001561static const struct hid_device_id hid_ignore_list[] = {
1562 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1563 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1564 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1565 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1566 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1567 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1568 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1569 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1570 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1571 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1572 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1573 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
Stephane Chatty77f720b2010-02-06 15:17:13 +01001574 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT)},
1575 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1576 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
Alexey Klimov62a56582008-11-13 05:44:50 +03001577 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001578 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1579 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1580 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1581 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1582 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1583 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
Alexey Klimov5f6108c2008-12-08 12:40:14 +01001584 { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001585 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1586 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1587 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
Petr Å tetiar70c66562009-12-09 22:09:53 +01001588 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001589 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1590 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1591 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1592 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1593 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1594 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1595 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1596 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1597 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1598 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1599 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1600 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1601 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1602 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1603 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1604 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1605 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1606 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1607 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1608 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1609 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1610 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1611 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1612 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1613 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1614 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1615 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1616 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1617 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1618 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1619 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1620 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1621 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1622 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1623 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1624 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1625 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1626 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1627 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1628 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1629 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1630 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1631 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1632 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1633 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1634 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1635 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1636 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1637 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1638 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1639 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1640 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1641 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1642 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1643 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1644 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1645 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1646 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1647 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1648 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1649 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1650 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1651 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1652 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1653 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1654 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
Alexey Klimovc91c21c2008-11-13 10:36:11 +01001655 { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001656 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
Lamarque Vieira Souzaeb8141c2009-10-02 15:04:44 +02001657 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001658 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1659 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1660 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1661 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1662 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1663 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1664 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
1665 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1666 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1667 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1669 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1670 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1671 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1672 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1673 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001674 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1675 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1676 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1677 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1678 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1679 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1680 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1681 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1682 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1683 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1684 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1685 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1686 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1687 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1688 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1689 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1690 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
Henning Glawe4cfae3e2009-08-02 22:18:12 +02001691 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
Michael Tokarev35cfd1d2009-02-01 16:11:04 +01001692 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001693 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1694 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1695 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1696 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1697 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1698 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1699 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1700 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1701 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1702 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1703 { }
1704};
1705
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001706/**
1707 * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
1708 *
1709 * There are composite devices for which we want to ignore only a certain
1710 * interface. This is a list of devices for which only the mouse interface will
1711 * be ignored. This allows a dedicated driver to take care of the interface.
1712 */
1713static const struct hid_device_id hid_mouse_ignore_list[] = {
1714 /* appletouch driver */
1715 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1716 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1717 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1718 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1719 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1720 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1721 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1722 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1723 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1724 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1725 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1726 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1727 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1728 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1729 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1730 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1731 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1732 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1733 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1734 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
Jiri Kosinaac26fca2008-11-20 11:27:02 +01001735 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
1736 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
1737 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001738 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1739 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1740 { }
1741};
1742
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001743static bool hid_ignore(struct hid_device *hdev)
1744{
1745 switch (hdev->vendor) {
1746 case USB_VENDOR_ID_CODEMERCS:
1747 /* ignore all Code Mercenaries IOWarrior devices */
1748 if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1749 hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1750 return true;
1751 break;
1752 case USB_VENDOR_ID_LOGITECH:
1753 if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1754 hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1755 return true;
1756 break;
Jarod Wilson31f7fd72009-07-31 10:56:36 -04001757 case USB_VENDOR_ID_SOUNDGRAPH:
1758 if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
1759 hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
1760 return true;
1761 break;
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001762 }
1763
Jiri Slabyb4d8e472008-10-22 14:47:18 +02001764 if (hdev->type == HID_TYPE_USBMOUSE &&
1765 hid_match_id(hdev, hid_mouse_ignore_list))
1766 return true;
1767
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001768 return !!hid_match_id(hdev, hid_ignore_list);
1769}
1770
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001771int hid_add_device(struct hid_device *hdev)
1772{
1773 static atomic_t id = ATOMIC_INIT(0);
1774 int ret;
1775
1776 if (WARN_ON(hdev->status & HID_STAT_ADDED))
1777 return -EBUSY;
1778
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001779 /* we need to kill them here, otherwise they will stay allocated to
1780 * wait for coming driver */
Jindrich Makovickae5a2a042010-06-03 12:50:42 +02001781 if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
1782 && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
Jiri Slabyd458a9d2008-05-16 11:49:20 +02001783 return -ENODEV;
1784
Kay Sievers6bbe5862008-10-31 00:12:32 +01001785 /* XXX hack, any other cleaner solution after the driver core
1786 * is converted to allow more than 20 bytes as the device name? */
1787 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
1788 hdev->vendor, hdev->product, atomic_inc_return(&id));
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001789
Bruno Prémont4da361b2010-03-15 14:55:40 +01001790 hid_debug_register(hdev, dev_name(&hdev->dev));
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001791 ret = device_add(&hdev->dev);
1792 if (!ret)
1793 hdev->status |= HID_STAT_ADDED;
Bruno Prémont4da361b2010-03-15 14:55:40 +01001794 else
1795 hid_debug_unregister(hdev);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001796
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001797 return ret;
1798}
1799EXPORT_SYMBOL_GPL(hid_add_device);
1800
1801/**
1802 * hid_allocate_device - allocate new hid device descriptor
1803 *
1804 * Allocate and initialize hid device, so that hid_destroy_device might be
1805 * used to free it.
1806 *
1807 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1808 * error value.
1809 */
1810struct hid_device *hid_allocate_device(void)
1811{
1812 struct hid_device *hdev;
1813 unsigned int i;
1814 int ret = -ENOMEM;
1815
1816 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
1817 if (hdev == NULL)
1818 return ERR_PTR(ret);
1819
1820 device_initialize(&hdev->dev);
1821 hdev->dev.release = hid_device_release;
1822 hdev->dev.bus = &hid_bus_type;
1823
1824 hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
1825 sizeof(struct hid_collection), GFP_KERNEL);
1826 if (hdev->collection == NULL)
1827 goto err;
1828 hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
1829
1830 for (i = 0; i < HID_REPORT_TYPES; i++)
1831 INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
1832
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001833 init_waitqueue_head(&hdev->debug_wait);
1834 INIT_LIST_HEAD(&hdev->debug_list);
1835
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001836 return hdev;
1837err:
1838 put_device(&hdev->dev);
1839 return ERR_PTR(ret);
1840}
1841EXPORT_SYMBOL_GPL(hid_allocate_device);
1842
1843static void hid_remove_device(struct hid_device *hdev)
1844{
1845 if (hdev->status & HID_STAT_ADDED) {
1846 device_del(&hdev->dev);
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001847 hid_debug_unregister(hdev);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001848 hdev->status &= ~HID_STAT_ADDED;
1849 }
1850}
1851
1852/**
1853 * hid_destroy_device - free previously allocated device
1854 *
1855 * @hdev: hid device
1856 *
1857 * If you allocate hid_device through hid_allocate_device, you should ever
1858 * free by this function.
1859 */
1860void hid_destroy_device(struct hid_device *hdev)
1861{
1862 hid_remove_device(hdev);
1863 put_device(&hdev->dev);
1864}
1865EXPORT_SYMBOL_GPL(hid_destroy_device);
1866
1867int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
1868 const char *mod_name)
1869{
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001870 int ret;
1871
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001872 hdrv->driver.name = hdrv->name;
1873 hdrv->driver.bus = &hid_bus_type;
1874 hdrv->driver.owner = owner;
1875 hdrv->driver.mod_name = mod_name;
1876
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001877 INIT_LIST_HEAD(&hdrv->dyn_list);
1878 spin_lock_init(&hdrv->dyn_lock);
1879
1880 ret = driver_register(&hdrv->driver);
1881 if (ret)
1882 return ret;
1883
1884 ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
1885 if (ret)
1886 driver_unregister(&hdrv->driver);
1887
1888 return ret;
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001889}
1890EXPORT_SYMBOL_GPL(__hid_register_driver);
1891
1892void hid_unregister_driver(struct hid_driver *hdrv)
1893{
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001894 driver_remove_file(&hdrv->driver, &driver_attr_new_id);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001895 driver_unregister(&hdrv->driver);
Jiri Slaby3a6f82f2008-11-24 16:20:09 +01001896 hid_free_dynids(hdrv);
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001897}
1898EXPORT_SYMBOL_GPL(hid_unregister_driver);
1899
Oliver Neukum0361a282008-12-17 15:38:03 +01001900int hid_check_keys_pressed(struct hid_device *hid)
1901{
1902 struct hid_input *hidinput;
1903 int i;
1904
Jiri Kosinae5288eb2009-05-02 00:02:57 +02001905 if (!(hid->claimed & HID_CLAIMED_INPUT))
1906 return 0;
1907
Oliver Neukum0361a282008-12-17 15:38:03 +01001908 list_for_each_entry(hidinput, &hid->inputs, list) {
1909 for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
1910 if (hidinput->input->key[i])
1911 return 1;
1912 }
1913
1914 return 0;
1915}
1916
1917EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
1918
Jiri Kosina86166b72007-05-14 09:57:40 +02001919static int __init hid_init(void)
1920{
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001921 int ret;
1922
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001923 if (hid_debug)
Jiri Kosinacd667ce2009-06-12 15:20:57 +02001924 printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
1925 "HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001926
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001927 ret = bus_register(&hid_bus_type);
1928 if (ret) {
1929 printk(KERN_ERR "HID: can't register hid bus\n");
1930 goto err;
1931 }
1932
1933 ret = hidraw_init();
1934 if (ret)
1935 goto err_bus;
1936
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001937 hid_debug_init();
1938
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001939 return 0;
1940err_bus:
1941 bus_unregister(&hid_bus_type);
1942err:
1943 return ret;
Jiri Kosina86166b72007-05-14 09:57:40 +02001944}
1945
1946static void __exit hid_exit(void)
1947{
Jiri Kosinaa635f9d2009-06-12 15:20:55 +02001948 hid_debug_exit();
Jiri Kosina86166b72007-05-14 09:57:40 +02001949 hidraw_exit();
Jiri Slaby85cdaf52008-05-16 11:49:15 +02001950 bus_unregister(&hid_bus_type);
Jiri Kosina86166b72007-05-14 09:57:40 +02001951}
1952
1953module_init(hid_init);
1954module_exit(hid_exit);
1955
Jiri Kosina88adb722009-10-02 18:29:34 +02001956MODULE_AUTHOR("Andreas Gal");
1957MODULE_AUTHOR("Vojtech Pavlik");
1958MODULE_AUTHOR("Jiri Kosina");
Jiri Kosinaaa938f72006-12-08 18:41:10 +01001959MODULE_LICENSE(DRIVER_LICENSE);
1960