Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 1 | /* |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 2 | * HID support for Linux |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 3 | * |
| 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 Kosina | f142b3a4 | 2007-04-16 11:29:28 +0200 | [diff] [blame] | 7 | * Copyright (c) 2006-2007 Jiri Kosina |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 8 | */ |
| 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 Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 21 | #include <linux/list.h> |
| 22 | #include <linux/mm.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 23 | #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 Kosina | 47a80ed | 2007-03-12 14:55:12 +0100 | [diff] [blame] | 28 | #include <linux/vmalloc.h> |
Jiri Kosina | c4124c9 | 2007-11-30 11:12:58 +0100 | [diff] [blame] | 29 | #include <linux/sched.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 30 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 31 | #include <linux/hid.h> |
| 32 | #include <linux/hiddev.h> |
Jiri Kosina | c080d89 | 2007-01-25 11:43:31 +0100 | [diff] [blame] | 33 | #include <linux/hid-debug.h> |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 34 | #include <linux/hidraw.h> |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 35 | |
Jiri Slaby | 5f22a79 | 2008-05-16 11:49:19 +0200 | [diff] [blame] | 36 | #include "hid-ids.h" |
| 37 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 38 | /* |
| 39 | * Version Information |
| 40 | */ |
| 41 | |
Jiri Kosina | 5314980 | 2007-01-09 13:24:25 +0100 | [diff] [blame] | 42 | #define DRIVER_DESC "HID core driver" |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 43 | #define DRIVER_LICENSE "GPL" |
| 44 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 45 | int hid_debug = 0; |
Anssi Hannula | 377e10f | 2008-03-22 23:50:13 +0100 | [diff] [blame] | 46 | module_param_named(debug, hid_debug, int, 0600); |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 47 | MODULE_PARM_DESC(debug, "toggle HID debugging messages"); |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 48 | EXPORT_SYMBOL_GPL(hid_debug); |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 49 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 50 | /* |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 51 | * Register a new report for a device. |
| 52 | */ |
| 53 | |
| 54 | static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) |
| 55 | { |
| 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 | } |
| 78 | |
| 79 | /* |
| 80 | * Register a new field for this report. |
| 81 | */ |
| 82 | |
| 83 | static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values) |
| 84 | { |
| 85 | struct hid_field *field; |
| 86 | |
| 87 | if (report->maxfield == HID_MAX_FIELDS) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 88 | dbg_hid("too many fields in report\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 89 | return NULL; |
| 90 | } |
| 91 | |
| 92 | if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage) |
| 93 | + values * sizeof(unsigned), GFP_KERNEL))) return NULL; |
| 94 | |
| 95 | field->index = report->maxfield++; |
| 96 | report->field[field->index] = field; |
| 97 | field->usage = (struct hid_usage *)(field + 1); |
Jiri Slaby | 282bfd4 | 2008-03-28 17:06:41 +0100 | [diff] [blame] | 98 | field->value = (s32 *)(field->usage + usages); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 99 | field->report = report; |
| 100 | |
| 101 | return field; |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * Open a collection. The type/usage is pushed on the stack. |
| 106 | */ |
| 107 | |
| 108 | static int open_collection(struct hid_parser *parser, unsigned type) |
| 109 | { |
| 110 | struct hid_collection *collection; |
| 111 | unsigned usage; |
| 112 | |
| 113 | usage = parser->local.usage[0]; |
| 114 | |
| 115 | if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 116 | dbg_hid("collection stack overflow\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | if (parser->device->maxcollection == parser->device->collection_size) { |
| 121 | collection = kmalloc(sizeof(struct hid_collection) * |
| 122 | parser->device->collection_size * 2, GFP_KERNEL); |
| 123 | if (collection == NULL) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 124 | dbg_hid("failed to reallocate collection array\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 125 | return -1; |
| 126 | } |
| 127 | memcpy(collection, parser->device->collection, |
| 128 | sizeof(struct hid_collection) * |
| 129 | parser->device->collection_size); |
| 130 | memset(collection + parser->device->collection_size, 0, |
| 131 | sizeof(struct hid_collection) * |
| 132 | parser->device->collection_size); |
| 133 | kfree(parser->device->collection); |
| 134 | parser->device->collection = collection; |
| 135 | parser->device->collection_size *= 2; |
| 136 | } |
| 137 | |
| 138 | parser->collection_stack[parser->collection_stack_ptr++] = |
| 139 | parser->device->maxcollection; |
| 140 | |
| 141 | collection = parser->device->collection + |
| 142 | parser->device->maxcollection++; |
| 143 | collection->type = type; |
| 144 | collection->usage = usage; |
| 145 | collection->level = parser->collection_stack_ptr - 1; |
| 146 | |
| 147 | if (type == HID_COLLECTION_APPLICATION) |
| 148 | parser->device->maxapplication++; |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Close a collection. |
| 155 | */ |
| 156 | |
| 157 | static int close_collection(struct hid_parser *parser) |
| 158 | { |
| 159 | if (!parser->collection_stack_ptr) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 160 | dbg_hid("collection stack underflow\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 161 | return -1; |
| 162 | } |
| 163 | parser->collection_stack_ptr--; |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Climb up the stack, search for the specified collection type |
| 169 | * and return the usage. |
| 170 | */ |
| 171 | |
| 172 | static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) |
| 173 | { |
| 174 | int n; |
| 175 | for (n = parser->collection_stack_ptr - 1; n >= 0; n--) |
| 176 | if (parser->device->collection[parser->collection_stack[n]].type == type) |
| 177 | return parser->device->collection[parser->collection_stack[n]].usage; |
| 178 | return 0; /* we know nothing about this usage type */ |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Add a usage to the temporary parser table. |
| 183 | */ |
| 184 | |
| 185 | static int hid_add_usage(struct hid_parser *parser, unsigned usage) |
| 186 | { |
| 187 | if (parser->local.usage_index >= HID_MAX_USAGES) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 188 | dbg_hid("usage index exceeded\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 189 | return -1; |
| 190 | } |
| 191 | parser->local.usage[parser->local.usage_index] = usage; |
| 192 | parser->local.collection_index[parser->local.usage_index] = |
| 193 | parser->collection_stack_ptr ? |
| 194 | parser->collection_stack[parser->collection_stack_ptr - 1] : 0; |
| 195 | parser->local.usage_index++; |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Register a new field for this report. |
| 201 | */ |
| 202 | |
| 203 | static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags) |
| 204 | { |
| 205 | struct hid_report *report; |
| 206 | struct hid_field *field; |
| 207 | int usages; |
| 208 | unsigned offset; |
| 209 | int i; |
| 210 | |
| 211 | if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 212 | dbg_hid("hid_register_report failed\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 213 | return -1; |
| 214 | } |
| 215 | |
| 216 | if (parser->global.logical_maximum < parser->global.logical_minimum) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 217 | dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | offset = report->size; |
| 222 | report->size += parser->global.report_size * parser->global.report_count; |
| 223 | |
| 224 | if (!parser->local.usage_index) /* Ignore padding fields */ |
| 225 | return 0; |
| 226 | |
| 227 | usages = max_t(int, parser->local.usage_index, parser->global.report_count); |
| 228 | |
| 229 | if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL) |
| 230 | return 0; |
| 231 | |
| 232 | field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); |
| 233 | field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); |
| 234 | field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); |
| 235 | |
| 236 | for (i = 0; i < usages; i++) { |
| 237 | int j = i; |
| 238 | /* Duplicate the last usage we parsed if we have excess values */ |
| 239 | if (i >= parser->local.usage_index) |
| 240 | j = parser->local.usage_index - 1; |
| 241 | field->usage[i].hid = parser->local.usage[j]; |
| 242 | field->usage[i].collection_index = |
| 243 | parser->local.collection_index[j]; |
| 244 | } |
| 245 | |
| 246 | field->maxusage = usages; |
| 247 | field->flags = flags; |
| 248 | field->report_offset = offset; |
| 249 | field->report_type = report_type; |
| 250 | field->report_size = parser->global.report_size; |
| 251 | field->report_count = parser->global.report_count; |
| 252 | field->logical_minimum = parser->global.logical_minimum; |
| 253 | field->logical_maximum = parser->global.logical_maximum; |
| 254 | field->physical_minimum = parser->global.physical_minimum; |
| 255 | field->physical_maximum = parser->global.physical_maximum; |
| 256 | field->unit_exponent = parser->global.unit_exponent; |
| 257 | field->unit = parser->global.unit; |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * Read data value from item. |
| 264 | */ |
| 265 | |
| 266 | static u32 item_udata(struct hid_item *item) |
| 267 | { |
| 268 | switch (item->size) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 269 | case 1: return item->data.u8; |
| 270 | case 2: return item->data.u16; |
| 271 | case 4: return item->data.u32; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 272 | } |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static s32 item_sdata(struct hid_item *item) |
| 277 | { |
| 278 | switch (item->size) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 279 | case 1: return item->data.s8; |
| 280 | case 2: return item->data.s16; |
| 281 | case 4: return item->data.s32; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 282 | } |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * Process a global item. |
| 288 | */ |
| 289 | |
| 290 | static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) |
| 291 | { |
| 292 | switch (item->tag) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 293 | case HID_GLOBAL_ITEM_TAG_PUSH: |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 294 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 295 | if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { |
| 296 | dbg_hid("global enviroment stack overflow\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 297 | return -1; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | memcpy(parser->global_stack + parser->global_stack_ptr++, |
| 301 | &parser->global, sizeof(struct hid_global)); |
| 302 | return 0; |
| 303 | |
| 304 | case HID_GLOBAL_ITEM_TAG_POP: |
| 305 | |
| 306 | if (!parser->global_stack_ptr) { |
| 307 | dbg_hid("global enviroment stack underflow\n"); |
| 308 | return -1; |
| 309 | } |
| 310 | |
| 311 | memcpy(&parser->global, parser->global_stack + |
| 312 | --parser->global_stack_ptr, sizeof(struct hid_global)); |
| 313 | return 0; |
| 314 | |
| 315 | case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: |
| 316 | parser->global.usage_page = item_udata(item); |
| 317 | return 0; |
| 318 | |
| 319 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: |
| 320 | parser->global.logical_minimum = item_sdata(item); |
| 321 | return 0; |
| 322 | |
| 323 | case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: |
| 324 | if (parser->global.logical_minimum < 0) |
| 325 | parser->global.logical_maximum = item_sdata(item); |
| 326 | else |
| 327 | parser->global.logical_maximum = item_udata(item); |
| 328 | return 0; |
| 329 | |
| 330 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: |
| 331 | parser->global.physical_minimum = item_sdata(item); |
| 332 | return 0; |
| 333 | |
| 334 | case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: |
| 335 | if (parser->global.physical_minimum < 0) |
| 336 | parser->global.physical_maximum = item_sdata(item); |
| 337 | else |
| 338 | parser->global.physical_maximum = item_udata(item); |
| 339 | return 0; |
| 340 | |
| 341 | case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: |
| 342 | parser->global.unit_exponent = item_sdata(item); |
| 343 | return 0; |
| 344 | |
| 345 | case HID_GLOBAL_ITEM_TAG_UNIT: |
| 346 | parser->global.unit = item_udata(item); |
| 347 | return 0; |
| 348 | |
| 349 | case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: |
| 350 | parser->global.report_size = item_udata(item); |
| 351 | if (parser->global.report_size > 32) { |
| 352 | dbg_hid("invalid report_size %d\n", |
| 353 | parser->global.report_size); |
| 354 | return -1; |
| 355 | } |
| 356 | return 0; |
| 357 | |
| 358 | case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: |
| 359 | parser->global.report_count = item_udata(item); |
| 360 | if (parser->global.report_count > HID_MAX_USAGES) { |
| 361 | dbg_hid("invalid report_count %d\n", |
| 362 | parser->global.report_count); |
| 363 | return -1; |
| 364 | } |
| 365 | return 0; |
| 366 | |
| 367 | case HID_GLOBAL_ITEM_TAG_REPORT_ID: |
| 368 | parser->global.report_id = item_udata(item); |
| 369 | if (parser->global.report_id == 0) { |
| 370 | dbg_hid("report_id 0 is invalid\n"); |
| 371 | return -1; |
| 372 | } |
| 373 | return 0; |
| 374 | |
| 375 | default: |
| 376 | dbg_hid("unknown global tag 0x%x\n", item->tag); |
| 377 | return -1; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Process a local item. |
| 383 | */ |
| 384 | |
| 385 | static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) |
| 386 | { |
| 387 | __u32 data; |
| 388 | unsigned n; |
| 389 | |
Jiri Kosina | 722612c | 2010-01-05 11:45:52 +0100 | [diff] [blame] | 390 | /* Local delimiter could have value 0, which allows size to be 0 */ |
| 391 | if (item->size == 0 && item->tag != HID_LOCAL_ITEM_TAG_DELIMITER) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 392 | dbg_hid("item data expected for local item\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 393 | return -1; |
| 394 | } |
| 395 | |
| 396 | data = item_udata(item); |
| 397 | |
| 398 | switch (item->tag) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 399 | case HID_LOCAL_ITEM_TAG_DELIMITER: |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 400 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 401 | if (data) { |
| 402 | /* |
| 403 | * We treat items before the first delimiter |
| 404 | * as global to all usage sets (branch 0). |
| 405 | * In the moment we process only these global |
| 406 | * items and the first delimiter set. |
| 407 | */ |
| 408 | if (parser->local.delimiter_depth != 0) { |
| 409 | dbg_hid("nested delimiters\n"); |
| 410 | return -1; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 411 | } |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 412 | parser->local.delimiter_depth++; |
| 413 | parser->local.delimiter_branch++; |
| 414 | } else { |
| 415 | if (parser->local.delimiter_depth < 1) { |
| 416 | dbg_hid("bogus close delimiter\n"); |
| 417 | return -1; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 418 | } |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 419 | parser->local.delimiter_depth--; |
| 420 | } |
| 421 | return 1; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 422 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 423 | case HID_LOCAL_ITEM_TAG_USAGE: |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 424 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 425 | if (parser->local.delimiter_branch > 1) { |
| 426 | dbg_hid("alternative usage ignored\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 427 | return 0; |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 428 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 429 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 430 | if (item->size <= 2) |
| 431 | data = (parser->global.usage_page << 16) + data; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 432 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 433 | return hid_add_usage(parser, data); |
| 434 | |
| 435 | case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: |
| 436 | |
| 437 | if (parser->local.delimiter_branch > 1) { |
| 438 | dbg_hid("alternative usage ignored\n"); |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | if (item->size <= 2) |
| 443 | data = (parser->global.usage_page << 16) + data; |
| 444 | |
| 445 | parser->local.usage_minimum = data; |
| 446 | return 0; |
| 447 | |
| 448 | case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: |
| 449 | |
| 450 | if (parser->local.delimiter_branch > 1) { |
| 451 | dbg_hid("alternative usage ignored\n"); |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | if (item->size <= 2) |
| 456 | data = (parser->global.usage_page << 16) + data; |
| 457 | |
| 458 | for (n = parser->local.usage_minimum; n <= data; n++) |
| 459 | if (hid_add_usage(parser, n)) { |
| 460 | dbg_hid("hid_add_usage failed\n"); |
| 461 | return -1; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 462 | } |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 463 | return 0; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 464 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 465 | default: |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 466 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 467 | dbg_hid("unknown local item tag 0x%x\n", item->tag); |
| 468 | return 0; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 469 | } |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * Process a main item. |
| 475 | */ |
| 476 | |
| 477 | static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) |
| 478 | { |
| 479 | __u32 data; |
| 480 | int ret; |
| 481 | |
| 482 | data = item_udata(item); |
| 483 | |
| 484 | switch (item->tag) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 485 | case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: |
| 486 | ret = open_collection(parser, data & 0xff); |
| 487 | break; |
| 488 | case HID_MAIN_ITEM_TAG_END_COLLECTION: |
| 489 | ret = close_collection(parser); |
| 490 | break; |
| 491 | case HID_MAIN_ITEM_TAG_INPUT: |
| 492 | ret = hid_add_field(parser, HID_INPUT_REPORT, data); |
| 493 | break; |
| 494 | case HID_MAIN_ITEM_TAG_OUTPUT: |
| 495 | ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); |
| 496 | break; |
| 497 | case HID_MAIN_ITEM_TAG_FEATURE: |
| 498 | ret = hid_add_field(parser, HID_FEATURE_REPORT, data); |
| 499 | break; |
| 500 | default: |
| 501 | dbg_hid("unknown main item tag 0x%x\n", item->tag); |
| 502 | ret = 0; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ |
| 506 | |
| 507 | return ret; |
| 508 | } |
| 509 | |
| 510 | /* |
| 511 | * Process a reserved item. |
| 512 | */ |
| 513 | |
| 514 | static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item) |
| 515 | { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 516 | dbg_hid("reserved item type, tag 0x%x\n", item->tag); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * Free a report and all registered fields. The field->usage and |
| 522 | * field->value table's are allocated behind the field, so we need |
| 523 | * only to free(field) itself. |
| 524 | */ |
| 525 | |
| 526 | static void hid_free_report(struct hid_report *report) |
| 527 | { |
| 528 | unsigned n; |
| 529 | |
| 530 | for (n = 0; n < report->maxfield; n++) |
| 531 | kfree(report->field[n]); |
| 532 | kfree(report); |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Free a device structure, all reports, and all fields. |
| 537 | */ |
| 538 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 539 | static void hid_device_release(struct device *dev) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 540 | { |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 541 | struct hid_device *device = container_of(dev, struct hid_device, dev); |
| 542 | unsigned i, j; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 543 | |
| 544 | for (i = 0; i < HID_REPORT_TYPES; i++) { |
| 545 | struct hid_report_enum *report_enum = device->report_enum + i; |
| 546 | |
| 547 | for (j = 0; j < 256; j++) { |
| 548 | struct hid_report *report = report_enum->report_id_hash[j]; |
| 549 | if (report) |
| 550 | hid_free_report(report); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | kfree(device->rdesc); |
Jiri Kosina | 767fe78 | 2007-01-24 23:05:07 +0100 | [diff] [blame] | 555 | kfree(device->collection); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 556 | kfree(device); |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Fetch a report description item from the data stream. We support long |
| 561 | * items, though they are not used yet. |
| 562 | */ |
| 563 | |
| 564 | static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) |
| 565 | { |
| 566 | u8 b; |
| 567 | |
| 568 | if ((end - start) <= 0) |
| 569 | return NULL; |
| 570 | |
| 571 | b = *start++; |
| 572 | |
| 573 | item->type = (b >> 2) & 3; |
| 574 | item->tag = (b >> 4) & 15; |
| 575 | |
| 576 | if (item->tag == HID_ITEM_TAG_LONG) { |
| 577 | |
| 578 | item->format = HID_ITEM_FORMAT_LONG; |
| 579 | |
| 580 | if ((end - start) < 2) |
| 581 | return NULL; |
| 582 | |
| 583 | item->size = *start++; |
| 584 | item->tag = *start++; |
| 585 | |
| 586 | if ((end - start) < item->size) |
| 587 | return NULL; |
| 588 | |
| 589 | item->data.longdata = start; |
| 590 | start += item->size; |
| 591 | return start; |
| 592 | } |
| 593 | |
| 594 | item->format = HID_ITEM_FORMAT_SHORT; |
| 595 | item->size = b & 3; |
| 596 | |
| 597 | switch (item->size) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 598 | case 0: |
| 599 | return start; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 600 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 601 | case 1: |
| 602 | if ((end - start) < 1) |
| 603 | return NULL; |
| 604 | item->data.u8 = *start++; |
| 605 | return start; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 606 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 607 | case 2: |
| 608 | if ((end - start) < 2) |
| 609 | return NULL; |
| 610 | item->data.u16 = get_unaligned_le16(start); |
| 611 | start = (__u8 *)((__le16 *)start + 1); |
| 612 | return start; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 613 | |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 614 | case 3: |
| 615 | item->size++; |
| 616 | if ((end - start) < 4) |
| 617 | return NULL; |
| 618 | item->data.u32 = get_unaligned_le32(start); |
| 619 | start = (__u8 *)((__le32 *)start + 1); |
| 620 | return start; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | return NULL; |
| 624 | } |
| 625 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 626 | /** |
| 627 | * hid_parse_report - parse device report |
| 628 | * |
| 629 | * @device: hid device |
| 630 | * @start: report start |
| 631 | * @size: report size |
| 632 | * |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 633 | * Parse a report description into a hid_device structure. Reports are |
| 634 | * enumerated, fields are attached to these reports. |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 635 | * 0 returned on success, otherwise nonzero error value. |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 636 | */ |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 637 | int hid_parse_report(struct hid_device *device, __u8 *start, |
| 638 | unsigned size) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 639 | { |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 640 | struct hid_parser *parser; |
| 641 | struct hid_item item; |
| 642 | __u8 *end; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 643 | int ret; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 644 | static int (*dispatch_type[])(struct hid_parser *parser, |
| 645 | struct hid_item *item) = { |
| 646 | hid_parser_main, |
| 647 | hid_parser_global, |
| 648 | hid_parser_local, |
| 649 | hid_parser_reserved |
| 650 | }; |
| 651 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 652 | if (device->driver->report_fixup) |
| 653 | device->driver->report_fixup(device, start, size); |
| 654 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 655 | device->rdesc = kmalloc(size, GFP_KERNEL); |
| 656 | if (device->rdesc == NULL) |
| 657 | return -ENOMEM; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 658 | memcpy(device->rdesc, start, size); |
| 659 | device->rsize = size; |
| 660 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 661 | parser = vmalloc(sizeof(struct hid_parser)); |
| 662 | if (!parser) { |
| 663 | ret = -ENOMEM; |
| 664 | goto err; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 665 | } |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 666 | |
Jiri Kosina | 47a80ed | 2007-03-12 14:55:12 +0100 | [diff] [blame] | 667 | memset(parser, 0, sizeof(struct hid_parser)); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 668 | parser->device = device; |
| 669 | |
| 670 | end = start + size; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 671 | ret = -EINVAL; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 672 | while ((start = fetch_item(start, end, &item)) != NULL) { |
| 673 | |
| 674 | if (item.format != HID_ITEM_FORMAT_SHORT) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 675 | dbg_hid("unexpected long global item\n"); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 676 | goto err; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | if (dispatch_type[item.type](parser, &item)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 680 | dbg_hid("item %u %u %u %u parsing failed\n", |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 681 | item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 682 | goto err; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | if (start == end) { |
| 686 | if (parser->collection_stack_ptr) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 687 | dbg_hid("unbalanced collection at end of report description\n"); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 688 | goto err; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 689 | } |
| 690 | if (parser->local.delimiter_depth) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 691 | dbg_hid("unbalanced delimiter at end of report description\n"); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 692 | goto err; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 693 | } |
Jiri Kosina | 47a80ed | 2007-03-12 14:55:12 +0100 | [diff] [blame] | 694 | vfree(parser); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 695 | return 0; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 699 | dbg_hid("item fetching failed at offset %d\n", (int)(end - start)); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 700 | err: |
Jiri Kosina | 47a80ed | 2007-03-12 14:55:12 +0100 | [diff] [blame] | 701 | vfree(parser); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 702 | return ret; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 703 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 704 | EXPORT_SYMBOL_GPL(hid_parse_report); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 705 | |
| 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 | |
| 712 | static s32 snto32(__u32 value, unsigned n) |
| 713 | { |
| 714 | switch (n) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 715 | case 8: return ((__s8)value); |
| 716 | case 16: return ((__s16)value); |
| 717 | case 32: return ((__s32)value); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 718 | } |
| 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 | |
| 726 | static 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 | |
| 746 | static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) |
| 747 | { |
| 748 | u64 x; |
| 749 | |
Jiri Kosina | c4124c9 | 2007-11-30 11:12:58 +0100 | [diff] [blame] | 750 | if (n > 32) |
| 751 | printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n", |
| 752 | n, current->comm); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 753 | |
| 754 | report += offset >> 3; /* adjust byte index */ |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 755 | offset &= 7; /* now only need bit offset into one byte */ |
Harvey Harrison | c105068 | 2008-04-29 01:03:31 -0700 | [diff] [blame] | 756 | x = get_unaligned_le64(report); |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 757 | x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */ |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 758 | 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 | */ |
| 769 | static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) |
| 770 | { |
Harvey Harrison | 6f0168d | 2008-05-16 11:00:23 +0200 | [diff] [blame] | 771 | u64 x; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 772 | u64 m = (1ULL << n) - 1; |
| 773 | |
Jiri Kosina | c4124c9 | 2007-11-30 11:12:58 +0100 | [diff] [blame] | 774 | if (n > 32) |
| 775 | printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n", |
| 776 | n, current->comm); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 777 | |
Jiri Kosina | c4124c9 | 2007-11-30 11:12:58 +0100 | [diff] [blame] | 778 | if (value > m) |
| 779 | printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n", |
| 780 | value, current->comm); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 781 | WARN_ON(value > m); |
| 782 | value &= m; |
| 783 | |
| 784 | report += offset >> 3; |
| 785 | offset &= 7; |
| 786 | |
Harvey Harrison | 6f0168d | 2008-05-16 11:00:23 +0200 | [diff] [blame] | 787 | x = get_unaligned_le64(report); |
| 788 | x &= ~(m << offset); |
| 789 | x |= ((u64)value) << offset; |
| 790 | put_unaligned_le64(x, report); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | /* |
| 794 | * Search an array for a value. |
| 795 | */ |
| 796 | |
| 797 | static __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 Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 806 | /** |
| 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 | */ |
| 814 | static int hid_match_report(struct hid_device *hid, struct hid_report *report) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 815 | { |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 816 | 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 | */ |
| 837 | static 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 | |
| 855 | static 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 Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 861 | hid_dump_input(hid, usage, value); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 862 | |
| 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 Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 873 | if (hid->claimed & HID_CLAIMED_INPUT) |
| 874 | hidinput_hid_event(hid, field, usage, value); |
Jiri Kosina | aa938f7 | 2006-12-08 18:41:10 +0100 | [diff] [blame] | 875 | if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) |
| 876 | hid->hiddev_hid_event(hid, field, usage, value); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 877 | } |
| 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 Bunk | abdff0f | 2008-03-31 01:53:56 +0200 | [diff] [blame] | 885 | static void hid_input_field(struct hid_device *hid, struct hid_field *field, |
| 886 | __u8 *data, int interrupt) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 887 | { |
| 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)); |
| 929 | exit: |
| 930 | kfree(value); |
| 931 | } |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 932 | |
| 933 | /* |
| 934 | * Output the field into the report. |
| 935 | */ |
| 936 | |
| 937 | static 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; |
Simon Budig | 46386b5 | 2007-03-12 13:52:04 +0100 | [diff] [blame] | 942 | unsigned bitsused = offset + count * size; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 943 | unsigned n; |
| 944 | |
Simon Budig | 46386b5 | 2007-03-12 13:52:04 +0100 | [diff] [blame] | 945 | /* make sure the unused bits in the last byte are zeros */ |
| 946 | if (count > 0 && size > 0 && (bitsused % 8) != 0) |
| 947 | data[(bitsused-1)/8] &= (1 << (bitsused % 8)) - 1; |
| 948 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 949 | for (n = 0; n < count; n++) { |
| 950 | if (field->logical_minimum < 0) /* signed values */ |
| 951 | implement(data, offset + n * size, size, s32ton(field->value[n], size)); |
| 952 | else /* unsigned values */ |
| 953 | implement(data, offset + n * size, size, field->value[n]); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | /* |
| 958 | * Create a report. |
| 959 | */ |
| 960 | |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 961 | void hid_output_report(struct hid_report *report, __u8 *data) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 962 | { |
| 963 | unsigned n; |
| 964 | |
| 965 | if (report->id > 0) |
| 966 | *data++ = report->id; |
| 967 | |
| 968 | for (n = 0; n < report->maxfield; n++) |
| 969 | hid_output_field(report->field[n], data); |
| 970 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 971 | EXPORT_SYMBOL_GPL(hid_output_report); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 972 | |
| 973 | /* |
| 974 | * Set a field value. The report this field belongs to has to be |
| 975 | * created and transferred to the device, to set this value in the |
| 976 | * device. |
| 977 | */ |
| 978 | |
| 979 | int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) |
| 980 | { |
| 981 | unsigned size = field->report_size; |
| 982 | |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 983 | hid_dump_input(field->report->device, field->usage + offset, value); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 984 | |
| 985 | if (offset >= field->report_count) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 986 | dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 987 | return -1; |
| 988 | } |
| 989 | if (field->logical_minimum < 0) { |
| 990 | if (value != snto32(s32ton(value, size), size)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 991 | dbg_hid("value %d is out of range\n", value); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 992 | return -1; |
| 993 | } |
| 994 | } |
| 995 | field->value[offset] = value; |
| 996 | return 0; |
| 997 | } |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 998 | EXPORT_SYMBOL_GPL(hid_set_field); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 999 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1000 | static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, |
| 1001 | const u8 *data) |
| 1002 | { |
| 1003 | struct hid_report *report; |
| 1004 | unsigned int n = 0; /* Normally report number is 0 */ |
| 1005 | |
| 1006 | /* Device uses numbered reports, data[0] is report number */ |
| 1007 | if (report_enum->numbered) |
| 1008 | n = *data; |
| 1009 | |
| 1010 | report = report_enum->report_id_hash[n]; |
| 1011 | if (report == NULL) |
| 1012 | dbg_hid("undefined report_id %u received\n", n); |
| 1013 | |
| 1014 | return report; |
| 1015 | } |
| 1016 | |
| 1017 | void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, |
| 1018 | int interrupt) |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1019 | { |
| 1020 | struct hid_report_enum *report_enum = hid->report_enum + type; |
| 1021 | struct hid_report *report; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1022 | unsigned int a; |
| 1023 | int rsize, csize = size; |
| 1024 | u8 *cdata = data; |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1025 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1026 | report = hid_get_report(report_enum, data); |
| 1027 | if (!report) |
| 1028 | return; |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1029 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1030 | if (report_enum->numbered) { |
| 1031 | cdata++; |
| 1032 | csize--; |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | rsize = ((report->size - 1) >> 3) + 1; |
| 1036 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1037 | if (csize < rsize) { |
| 1038 | dbg_hid("report %d is too short, (%d < %d)\n", report->id, |
| 1039 | csize, rsize); |
| 1040 | memset(cdata + csize, 0, rsize - csize); |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) |
| 1044 | hid->hiddev_report_event(hid, report); |
Jiri Kosina | b54ec3c | 2008-03-28 14:11:22 +0100 | [diff] [blame] | 1045 | if (hid->claimed & HID_CLAIMED_HIDRAW) { |
| 1046 | /* numbered reports need to be passed with the report num */ |
| 1047 | if (report_enum->numbered) |
| 1048 | hidraw_report_event(hid, data - 1, size + 1); |
| 1049 | else |
| 1050 | hidraw_report_event(hid, data, size); |
| 1051 | } |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1052 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1053 | for (a = 0; a < report->maxfield; a++) |
| 1054 | hid_input_field(hid, report->field[a], cdata, interrupt); |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1055 | |
| 1056 | if (hid->claimed & HID_CLAIMED_INPUT) |
| 1057 | hidinput_report_event(hid, report); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1058 | } |
| 1059 | EXPORT_SYMBOL_GPL(hid_report_raw_event); |
| 1060 | |
| 1061 | /** |
| 1062 | * hid_input_report - report data from lower layer (usb, bt...) |
| 1063 | * |
| 1064 | * @hid: hid device |
| 1065 | * @type: HID report type (HID_*_REPORT) |
| 1066 | * @data: report contents |
| 1067 | * @size: size of data parameter |
Jiri Kosina | ff9b00a | 2009-10-01 16:03:13 +0200 | [diff] [blame] | 1068 | * @interrupt: distinguish between interrupt and control transfers |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1069 | * |
| 1070 | * This is data entry for lower layers. |
| 1071 | */ |
| 1072 | int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) |
| 1073 | { |
Julia Lawall | 76c317d | 2009-07-19 17:26:13 +0200 | [diff] [blame] | 1074 | struct hid_report_enum *report_enum; |
| 1075 | struct hid_driver *hdrv; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1076 | struct hid_report *report; |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 1077 | char *buf; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1078 | unsigned int i; |
| 1079 | int ret; |
| 1080 | |
| 1081 | if (!hid || !hid->driver) |
| 1082 | return -ENODEV; |
Julia Lawall | 76c317d | 2009-07-19 17:26:13 +0200 | [diff] [blame] | 1083 | report_enum = hid->report_enum + type; |
| 1084 | hdrv = hid->driver; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1085 | |
| 1086 | if (!size) { |
| 1087 | dbg_hid("empty report\n"); |
| 1088 | return -1; |
| 1089 | } |
| 1090 | |
Jiri Kosina | d1ff652 | 2009-09-15 11:59:49 +0200 | [diff] [blame] | 1091 | buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC); |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 1092 | |
| 1093 | if (!buf) { |
| 1094 | report = hid_get_report(report_enum, data); |
| 1095 | goto nomem; |
| 1096 | } |
| 1097 | |
| 1098 | snprintf(buf, HID_DEBUG_BUFSIZE - 1, |
| 1099 | "\nreport (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un"); |
| 1100 | hid_debug_event(hid, buf); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1101 | |
| 1102 | report = hid_get_report(report_enum, data); |
Jiri Kosina | 55dba52 | 2009-06-26 10:50:12 +0200 | [diff] [blame] | 1103 | if (!report) { |
| 1104 | kfree(buf); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1105 | return -1; |
Jiri Kosina | 55dba52 | 2009-06-26 10:50:12 +0200 | [diff] [blame] | 1106 | } |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1107 | |
| 1108 | /* dump the report */ |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 1109 | snprintf(buf, HID_DEBUG_BUFSIZE - 1, |
| 1110 | "report %d (size %u) = ", report->id, size); |
| 1111 | hid_debug_event(hid, buf); |
| 1112 | for (i = 0; i < size; i++) { |
| 1113 | snprintf(buf, HID_DEBUG_BUFSIZE - 1, |
| 1114 | " %02x", data[i]); |
| 1115 | hid_debug_event(hid, buf); |
| 1116 | } |
| 1117 | hid_debug_event(hid, "\n"); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1118 | |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 1119 | kfree(buf); |
| 1120 | |
| 1121 | nomem: |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1122 | if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { |
| 1123 | ret = hdrv->raw_event(hid, report, data, size); |
| 1124 | if (ret != 0) |
| 1125 | return ret < 0 ? ret : 0; |
| 1126 | } |
| 1127 | |
| 1128 | hid_report_raw_event(hid, type, data, size, interrupt); |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | EXPORT_SYMBOL_GPL(hid_input_report); |
| 1133 | |
Jiri Kosina | 0f37cd0 | 2008-08-20 19:13:52 +0200 | [diff] [blame] | 1134 | static bool hid_match_one_id(struct hid_device *hdev, |
| 1135 | const struct hid_device_id *id) |
| 1136 | { |
| 1137 | return id->bus == hdev->bus && |
| 1138 | (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && |
| 1139 | (id->product == HID_ANY_ID || id->product == hdev->product); |
| 1140 | } |
| 1141 | |
| 1142 | static const struct hid_device_id *hid_match_id(struct hid_device *hdev, |
| 1143 | const struct hid_device_id *id) |
| 1144 | { |
| 1145 | for (; id->bus; id++) |
| 1146 | if (hid_match_one_id(hdev, id)) |
| 1147 | return id; |
| 1148 | |
| 1149 | return NULL; |
| 1150 | } |
| 1151 | |
| 1152 | static const struct hid_device_id hid_hiddev_list[] = { |
Richard Hughes | c0bd6a4 | 2008-08-27 11:19:37 +0200 | [diff] [blame] | 1153 | { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) }, |
| 1154 | { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) }, |
Jiri Kosina | 0f37cd0 | 2008-08-20 19:13:52 +0200 | [diff] [blame] | 1155 | { } |
| 1156 | }; |
| 1157 | |
| 1158 | static bool hid_hiddev(struct hid_device *hdev) |
| 1159 | { |
| 1160 | return !!hid_match_id(hdev, hid_hiddev_list); |
| 1161 | } |
| 1162 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 1163 | int hid_connect(struct hid_device *hdev, unsigned int connect_mask) |
| 1164 | { |
| 1165 | static const char *types[] = { "Device", "Pointer", "Mouse", "Device", |
| 1166 | "Joystick", "Gamepad", "Keyboard", "Keypad", |
| 1167 | "Multi-Axis Controller" |
| 1168 | }; |
| 1169 | const char *type, *bus; |
| 1170 | char buf[64]; |
| 1171 | unsigned int i; |
| 1172 | int len; |
| 1173 | |
| 1174 | if (hdev->bus != BUS_USB) |
| 1175 | connect_mask &= ~HID_CONNECT_HIDDEV; |
Jiri Kosina | 0f37cd0 | 2008-08-20 19:13:52 +0200 | [diff] [blame] | 1176 | if (hid_hiddev(hdev)) |
| 1177 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 1178 | |
| 1179 | if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, |
| 1180 | connect_mask & HID_CONNECT_HIDINPUT_FORCE)) |
| 1181 | hdev->claimed |= HID_CLAIMED_INPUT; |
| 1182 | if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && |
| 1183 | !hdev->hiddev_connect(hdev, |
| 1184 | connect_mask & HID_CONNECT_HIDDEV_FORCE)) |
| 1185 | hdev->claimed |= HID_CLAIMED_HIDDEV; |
| 1186 | if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev)) |
| 1187 | hdev->claimed |= HID_CLAIMED_HIDRAW; |
| 1188 | |
| 1189 | if (!hdev->claimed) { |
| 1190 | dev_err(&hdev->dev, "claimed by neither input, hiddev nor " |
| 1191 | "hidraw\n"); |
| 1192 | return -ENODEV; |
| 1193 | } |
| 1194 | |
| 1195 | if ((hdev->claimed & HID_CLAIMED_INPUT) && |
| 1196 | (connect_mask & HID_CONNECT_FF) && hdev->ff_init) |
| 1197 | hdev->ff_init(hdev); |
| 1198 | |
| 1199 | len = 0; |
| 1200 | if (hdev->claimed & HID_CLAIMED_INPUT) |
| 1201 | len += sprintf(buf + len, "input"); |
| 1202 | if (hdev->claimed & HID_CLAIMED_HIDDEV) |
| 1203 | len += sprintf(buf + len, "%shiddev%d", len ? "," : "", |
| 1204 | hdev->minor); |
| 1205 | if (hdev->claimed & HID_CLAIMED_HIDRAW) |
| 1206 | len += sprintf(buf + len, "%shidraw%d", len ? "," : "", |
| 1207 | ((struct hidraw *)hdev->hidraw)->minor); |
| 1208 | |
| 1209 | type = "Device"; |
| 1210 | for (i = 0; i < hdev->maxcollection; i++) { |
| 1211 | struct hid_collection *col = &hdev->collection[i]; |
| 1212 | if (col->type == HID_COLLECTION_APPLICATION && |
| 1213 | (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK && |
| 1214 | (col->usage & 0xffff) < ARRAY_SIZE(types)) { |
| 1215 | type = types[col->usage & 0xffff]; |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | switch (hdev->bus) { |
| 1221 | case BUS_USB: |
| 1222 | bus = "USB"; |
| 1223 | break; |
| 1224 | case BUS_BLUETOOTH: |
| 1225 | bus = "BLUETOOTH"; |
| 1226 | break; |
| 1227 | default: |
| 1228 | bus = "<UNKNOWN>"; |
| 1229 | } |
| 1230 | |
| 1231 | dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n", |
| 1232 | buf, bus, hdev->version >> 8, hdev->version & 0xff, |
| 1233 | type, hdev->name, hdev->phys); |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | EXPORT_SYMBOL_GPL(hid_connect); |
| 1238 | |
Jiri Kosina | c4c259b | 2009-09-15 16:27:45 +0200 | [diff] [blame] | 1239 | void hid_disconnect(struct hid_device *hdev) |
| 1240 | { |
| 1241 | if (hdev->claimed & HID_CLAIMED_INPUT) |
| 1242 | hidinput_disconnect(hdev); |
| 1243 | if (hdev->claimed & HID_CLAIMED_HIDDEV) |
| 1244 | hdev->hiddev_disconnect(hdev); |
| 1245 | if (hdev->claimed & HID_CLAIMED_HIDRAW) |
| 1246 | hidraw_disconnect(hdev); |
| 1247 | } |
| 1248 | EXPORT_SYMBOL_GPL(hid_disconnect); |
| 1249 | |
Jiri Kosina | bae7eb3 | 2009-01-28 23:06:37 +0100 | [diff] [blame] | 1250 | /* a list of devices for which there is a specialized driver on HID bus */ |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1251 | static const struct hid_device_id hid_blacklist[] = { |
Stephane Chatty | b6353f4 | 2009-12-22 23:04:17 +0100 | [diff] [blame] | 1252 | { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) }, |
Jiri Slaby | 14a21cd | 2008-06-23 23:31:09 +0200 | [diff] [blame] | 1253 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, |
| 1254 | { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, |
Jiri Kosina | df9bcac | 2008-10-14 22:45:40 +0200 | [diff] [blame] | 1255 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 1256 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, |
| 1257 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, |
| 1258 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, |
| 1259 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, |
| 1260 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, |
| 1261 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, |
| 1262 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, |
| 1263 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, |
| 1264 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, |
| 1265 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, |
| 1266 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, |
| 1267 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, |
| 1268 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, |
Ryan Finnie | fef3f57 | 2009-03-05 10:18:01 +0100 | [diff] [blame] | 1269 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) }, |
| 1270 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) }, |
| 1271 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 1272 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) }, |
| 1273 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) }, |
| 1274 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) }, |
| 1275 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, |
| 1276 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, |
| 1277 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, |
Jan Scholz | ee8a1a0 | 2008-11-26 15:33:45 +0100 | [diff] [blame] | 1278 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) }, |
| 1279 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) }, |
| 1280 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 1281 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, |
| 1282 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, |
| 1283 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, |
| 1284 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, |
| 1285 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, |
| 1286 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, |
Henrik Rydberg | a96d6ef | 2008-11-04 20:03:45 +0100 | [diff] [blame] | 1287 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, |
| 1288 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, |
| 1289 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 1290 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, |
| 1291 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 1292 | { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 1293 | { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, |
Jiri Slaby | fcfacfd | 2008-06-24 22:48:52 +0200 | [diff] [blame] | 1294 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, |
Jiri Slaby | 0f22132 | 2008-06-23 22:54:08 +0200 | [diff] [blame] | 1295 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, |
| 1296 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, |
Jiri Kosina | e8d0eab | 2009-12-02 22:54:11 +0100 | [diff] [blame] | 1297 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, |
Jiri Slaby | 0f22132 | 2008-06-23 22:54:08 +0200 | [diff] [blame] | 1298 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, |
Richard Walmsley | 3f866fb | 2009-03-04 22:12:04 +1300 | [diff] [blame] | 1299 | { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, |
Jiri Slaby | 1f243e3 | 2008-06-24 21:11:21 +0200 | [diff] [blame] | 1300 | { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, |
Jiri Kosina | 5181e59 | 2008-11-17 01:44:38 +0100 | [diff] [blame] | 1301 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, |
Jiri Kosina | 578f3a3 | 2008-11-20 15:55:38 +0100 | [diff] [blame] | 1302 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, |
Jiri Kosina | 5181e59 | 2008-11-17 01:44:38 +0100 | [diff] [blame] | 1303 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 1304 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, |
Jiri Slaby | 949f8fe | 2008-07-24 23:35:13 +0200 | [diff] [blame] | 1305 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, |
Jiri Kosina | 1e09320 | 2008-10-17 11:52:23 +0200 | [diff] [blame] | 1306 | { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, |
Jiri Kosina | fdf93aa | 2009-03-04 16:09:40 +0100 | [diff] [blame] | 1307 | { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, |
Jiri Kosina | 7942274 | 2009-03-11 11:43:27 +0100 | [diff] [blame] | 1308 | { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 1309 | { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, |
Jiri Slaby | 5f22a79 | 2008-05-16 11:49:19 +0200 | [diff] [blame] | 1310 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, |
| 1311 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, |
| 1312 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, |
| 1313 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, |
| 1314 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, |
| 1315 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, |
| 1316 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, |
Jiri Slaby | 5f22a79 | 2008-05-16 11:49:19 +0200 | [diff] [blame] | 1317 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) }, |
| 1318 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) }, |
Jiri Slaby | 5f22a79 | 2008-05-16 11:49:19 +0200 | [diff] [blame] | 1319 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) }, |
| 1320 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) }, |
Jiri Slaby | 606bd0a | 2008-07-04 23:06:45 +0200 | [diff] [blame] | 1321 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, |
| 1322 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, |
| 1323 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, |
Jiri Kosina | fd30ea8 | 2009-06-23 12:11:31 +0200 | [diff] [blame] | 1324 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) }, |
Jiri Slaby | 606bd0a | 2008-07-04 23:06:45 +0200 | [diff] [blame] | 1325 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, |
Gary Stein | 74f292c | 2010-01-13 00:25:58 +0100 | [diff] [blame] | 1326 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) }, |
Jiri Slaby | 606bd0a | 2008-07-04 23:06:45 +0200 | [diff] [blame] | 1327 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, |
| 1328 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, |
Christophe Borivant | 243b706 | 2009-04-17 11:39:39 +0200 | [diff] [blame] | 1329 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, |
Jiri Slaby | 606bd0a | 2008-07-04 23:06:45 +0200 | [diff] [blame] | 1330 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, |
Jiri Kosina | 24985cf | 2009-11-13 10:45:53 +0100 | [diff] [blame] | 1331 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, |
| 1332 | { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 1333 | { 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 Slaby | 3b8006e | 2008-06-25 00:07:50 +0200 | [diff] [blame] | 1338 | { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, |
Rafi Rubin | 94011f9 | 2008-11-19 15:54:46 +0100 | [diff] [blame] | 1339 | { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, |
Jiri Slaby | 1e76253 | 2008-06-24 23:46:21 +0200 | [diff] [blame] | 1340 | { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, |
Stephane Chatty | 49e4739 | 2010-01-13 00:29:16 +0100 | [diff] [blame^] | 1341 | { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, |
Jiri Slaby | 980a3da | 2008-06-25 22:31:48 +0200 | [diff] [blame] | 1342 | { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1343 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1344 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, |
Stephane Chatty | d3fb545 | 2010-01-04 12:04:08 +0100 | [diff] [blame] | 1345 | { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) }, |
Jiri Slaby | 90231e7 | 2008-06-23 21:56:07 +0200 | [diff] [blame] | 1346 | { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, |
Anssi Hannula | daedb3d | 2009-02-14 11:45:05 +0200 | [diff] [blame] | 1347 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, |
| 1348 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, |
Ruben Aos Garralda | 7a84b13 | 2009-06-29 09:41:29 +0200 | [diff] [blame] | 1349 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) }, |
| 1350 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) }, |
Anssi Hannula | daedb3d | 2009-02-14 11:45:05 +0200 | [diff] [blame] | 1351 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, |
| 1352 | { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, |
Lev Babiev | f14f526 | 2009-01-04 00:36:56 +0100 | [diff] [blame] | 1353 | { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, |
Bruno Premont | 711a680 | 2009-07-13 14:19:58 +0200 | [diff] [blame] | 1354 | { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 1355 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 1356 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, |
Anssi Hannula | daedb3d | 2009-02-14 11:45:05 +0200 | [diff] [blame] | 1357 | { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, |
| 1358 | { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, |
Jiri Slaby | 8c19a51 | 2008-06-18 23:36:49 +0200 | [diff] [blame] | 1359 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 1360 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1361 | { } |
| 1362 | }; |
| 1363 | |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1364 | struct hid_dynid { |
| 1365 | struct list_head list; |
| 1366 | struct hid_device_id id; |
| 1367 | }; |
| 1368 | |
| 1369 | /** |
| 1370 | * store_new_id - add a new HID device ID to this driver and re-probe devices |
| 1371 | * @driver: target device driver |
| 1372 | * @buf: buffer for scanning device ID data |
| 1373 | * @count: input size |
| 1374 | * |
| 1375 | * Adds a new dynamic hid device ID to this driver, |
| 1376 | * and causes the driver to probe for all devices again. |
| 1377 | */ |
| 1378 | static ssize_t store_new_id(struct device_driver *drv, const char *buf, |
| 1379 | size_t count) |
| 1380 | { |
| 1381 | struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); |
| 1382 | struct hid_dynid *dynid; |
| 1383 | __u32 bus, vendor, product; |
| 1384 | unsigned long driver_data = 0; |
| 1385 | int ret; |
| 1386 | |
| 1387 | ret = sscanf(buf, "%x %x %x %lx", |
| 1388 | &bus, &vendor, &product, &driver_data); |
| 1389 | if (ret < 3) |
| 1390 | return -EINVAL; |
| 1391 | |
| 1392 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 1393 | if (!dynid) |
| 1394 | return -ENOMEM; |
| 1395 | |
| 1396 | dynid->id.bus = bus; |
| 1397 | dynid->id.vendor = vendor; |
| 1398 | dynid->id.product = product; |
| 1399 | dynid->id.driver_data = driver_data; |
| 1400 | |
| 1401 | spin_lock(&hdrv->dyn_lock); |
| 1402 | list_add_tail(&dynid->list, &hdrv->dyn_list); |
| 1403 | spin_unlock(&hdrv->dyn_lock); |
| 1404 | |
| 1405 | ret = 0; |
| 1406 | if (get_driver(&hdrv->driver)) { |
| 1407 | ret = driver_attach(&hdrv->driver); |
| 1408 | put_driver(&hdrv->driver); |
| 1409 | } |
| 1410 | |
| 1411 | return ret ? : count; |
| 1412 | } |
| 1413 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); |
| 1414 | |
| 1415 | static void hid_free_dynids(struct hid_driver *hdrv) |
| 1416 | { |
| 1417 | struct hid_dynid *dynid, *n; |
| 1418 | |
| 1419 | spin_lock(&hdrv->dyn_lock); |
| 1420 | list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) { |
| 1421 | list_del(&dynid->list); |
| 1422 | kfree(dynid); |
| 1423 | } |
| 1424 | spin_unlock(&hdrv->dyn_lock); |
| 1425 | } |
| 1426 | |
| 1427 | static const struct hid_device_id *hid_match_device(struct hid_device *hdev, |
| 1428 | struct hid_driver *hdrv) |
| 1429 | { |
| 1430 | struct hid_dynid *dynid; |
| 1431 | |
| 1432 | spin_lock(&hdrv->dyn_lock); |
| 1433 | list_for_each_entry(dynid, &hdrv->dyn_list, list) { |
| 1434 | if (hid_match_one_id(hdev, &dynid->id)) { |
| 1435 | spin_unlock(&hdrv->dyn_lock); |
| 1436 | return &dynid->id; |
| 1437 | } |
| 1438 | } |
| 1439 | spin_unlock(&hdrv->dyn_lock); |
| 1440 | |
| 1441 | return hid_match_id(hdev, hdrv->id_table); |
| 1442 | } |
| 1443 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1444 | static int hid_bus_match(struct device *dev, struct device_driver *drv) |
| 1445 | { |
| 1446 | struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); |
| 1447 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 1448 | |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1449 | if (!hid_match_device(hdev, hdrv)) |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1450 | return 0; |
| 1451 | |
| 1452 | /* generic wants all non-blacklisted */ |
| 1453 | if (!strncmp(hdrv->name, "generic-", 8)) |
| 1454 | return !hid_match_id(hdev, hid_blacklist); |
| 1455 | |
| 1456 | return 1; |
| 1457 | } |
| 1458 | |
| 1459 | static int hid_device_probe(struct device *dev) |
| 1460 | { |
| 1461 | struct hid_driver *hdrv = container_of(dev->driver, |
| 1462 | struct hid_driver, driver); |
| 1463 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 1464 | const struct hid_device_id *id; |
| 1465 | int ret = 0; |
| 1466 | |
| 1467 | if (!hdev->driver) { |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1468 | id = hid_match_device(hdev, hdrv); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1469 | if (id == NULL) |
| 1470 | return -ENODEV; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1471 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1472 | hdev->driver = hdrv; |
| 1473 | if (hdrv->probe) { |
| 1474 | ret = hdrv->probe(hdev, id); |
| 1475 | } else { /* default probe */ |
| 1476 | ret = hid_parse(hdev); |
| 1477 | if (!ret) |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 1478 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1479 | } |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1480 | if (ret) |
| 1481 | hdev->driver = NULL; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1482 | } |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
| 1486 | static int hid_device_remove(struct device *dev) |
| 1487 | { |
| 1488 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 1489 | struct hid_driver *hdrv = hdev->driver; |
| 1490 | |
| 1491 | if (hdrv) { |
| 1492 | if (hdrv->remove) |
| 1493 | hdrv->remove(hdev); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1494 | else /* default remove */ |
| 1495 | hid_hw_stop(hdev); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1496 | hdev->driver = NULL; |
| 1497 | } |
| 1498 | |
| 1499 | return 0; |
| 1500 | } |
| 1501 | |
| 1502 | static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 1503 | { |
| 1504 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 1505 | |
| 1506 | if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", |
| 1507 | hdev->bus, hdev->vendor, hdev->product)) |
| 1508 | return -ENOMEM; |
| 1509 | |
| 1510 | if (add_uevent_var(env, "HID_NAME=%s", hdev->name)) |
| 1511 | return -ENOMEM; |
| 1512 | |
| 1513 | if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys)) |
| 1514 | return -ENOMEM; |
| 1515 | |
| 1516 | if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq)) |
| 1517 | return -ENOMEM; |
| 1518 | |
| 1519 | if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X", |
| 1520 | hdev->bus, hdev->vendor, hdev->product)) |
| 1521 | return -ENOMEM; |
| 1522 | |
| 1523 | return 0; |
| 1524 | } |
| 1525 | |
| 1526 | static struct bus_type hid_bus_type = { |
| 1527 | .name = "hid", |
| 1528 | .match = hid_bus_match, |
| 1529 | .probe = hid_device_probe, |
| 1530 | .remove = hid_device_remove, |
| 1531 | .uevent = hid_uevent, |
| 1532 | }; |
| 1533 | |
Jiri Kosina | bae7eb3 | 2009-01-28 23:06:37 +0100 | [diff] [blame] | 1534 | /* a list of devices that shouldn't be handled by HID core at all */ |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1535 | static const struct hid_device_id hid_ignore_list[] = { |
| 1536 | { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) }, |
| 1537 | { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) }, |
| 1538 | { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) }, |
| 1539 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) }, |
| 1540 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) }, |
| 1541 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) }, |
| 1542 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) }, |
| 1543 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) }, |
| 1544 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) }, |
| 1545 | { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, |
| 1546 | { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, |
| 1547 | { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, |
| 1548 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)}, |
Jiri Kosina | ac2d989 | 2008-10-20 12:37:43 +0200 | [diff] [blame] | 1549 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM2)}, |
Alexey Klimov | 62a5658 | 2008-11-13 05:44:50 +0300 | [diff] [blame] | 1550 | { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1551 | { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, |
| 1552 | { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, |
| 1553 | { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, |
| 1554 | { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) }, |
| 1555 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) }, |
| 1556 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) }, |
Alexey Klimov | 5f6108c | 2008-12-08 12:40:14 +0100 | [diff] [blame] | 1557 | { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) }, |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1558 | { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, |
| 1559 | { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, |
| 1560 | { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, |
| 1561 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) }, |
| 1562 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, |
| 1563 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) }, |
| 1564 | { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, |
| 1565 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, |
| 1566 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, |
| 1567 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) }, |
| 1568 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) }, |
| 1569 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) }, |
| 1570 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) }, |
| 1571 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) }, |
| 1572 | { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) }, |
| 1573 | { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) }, |
| 1574 | { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) }, |
| 1575 | { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) }, |
| 1576 | { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) }, |
| 1577 | { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) }, |
| 1578 | { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) }, |
| 1579 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) }, |
| 1580 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) }, |
| 1581 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) }, |
| 1582 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) }, |
| 1583 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) }, |
| 1584 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) }, |
| 1585 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) }, |
| 1586 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) }, |
| 1587 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) }, |
| 1588 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) }, |
| 1589 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) }, |
| 1590 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) }, |
| 1591 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) }, |
| 1592 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) }, |
| 1593 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) }, |
| 1594 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) }, |
| 1595 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) }, |
| 1596 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) }, |
| 1597 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) }, |
| 1598 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) }, |
| 1599 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) }, |
| 1600 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) }, |
| 1601 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) }, |
| 1602 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) }, |
| 1603 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) }, |
| 1604 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) }, |
| 1605 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) }, |
| 1606 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) }, |
| 1607 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) }, |
| 1608 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) }, |
| 1609 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) }, |
| 1610 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) }, |
| 1611 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) }, |
| 1612 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) }, |
| 1613 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) }, |
| 1614 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) }, |
| 1615 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) }, |
| 1616 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) }, |
| 1617 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) }, |
| 1618 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) }, |
| 1619 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) }, |
| 1620 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) }, |
| 1621 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) }, |
| 1622 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) }, |
| 1623 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) }, |
| 1624 | { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) }, |
| 1625 | { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) }, |
| 1626 | { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) }, |
Alexey Klimov | c91c21c | 2008-11-13 10:36:11 +0100 | [diff] [blame] | 1627 | { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) }, |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1628 | { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) }, |
Lamarque Vieira Souza | eb8141c | 2009-10-02 15:04:44 +0200 | [diff] [blame] | 1629 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) }, |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1630 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, |
| 1631 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, |
| 1632 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, |
| 1633 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, |
| 1634 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, |
| 1635 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, |
| 1636 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) }, |
| 1637 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, |
| 1638 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, |
| 1639 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, |
| 1640 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, |
| 1641 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, |
| 1642 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, |
| 1643 | { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, |
| 1644 | { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, |
| 1645 | { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1646 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, |
| 1647 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) }, |
| 1648 | { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) }, |
| 1649 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) }, |
| 1650 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) }, |
| 1651 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) }, |
| 1652 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) }, |
| 1653 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) }, |
| 1654 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) }, |
| 1655 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) }, |
| 1656 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) }, |
| 1657 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) }, |
| 1658 | { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) }, |
| 1659 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) }, |
| 1660 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) }, |
| 1661 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) }, |
| 1662 | { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, |
Henning Glawe | 4cfae3e | 2009-08-02 22:18:12 +0200 | [diff] [blame] | 1663 | { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) }, |
Michael Tokarev | 35cfd1d | 2009-02-01 16:11:04 +0100 | [diff] [blame] | 1664 | { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, |
Remi Cattiau | d1d3a5f | 2008-09-09 01:39:33 +0200 | [diff] [blame] | 1665 | { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY1) }, |
| 1666 | { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY2) }, |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1667 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, |
| 1668 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, |
| 1669 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, |
| 1670 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, |
| 1671 | { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) }, |
| 1672 | { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) }, |
| 1673 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) }, |
| 1674 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) }, |
| 1675 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) }, |
| 1676 | { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, |
| 1677 | { } |
| 1678 | }; |
| 1679 | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 1680 | /** |
| 1681 | * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer |
| 1682 | * |
| 1683 | * There are composite devices for which we want to ignore only a certain |
| 1684 | * interface. This is a list of devices for which only the mouse interface will |
| 1685 | * be ignored. This allows a dedicated driver to take care of the interface. |
| 1686 | */ |
| 1687 | static const struct hid_device_id hid_mouse_ignore_list[] = { |
| 1688 | /* appletouch driver */ |
| 1689 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, |
| 1690 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, |
| 1691 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, |
| 1692 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, |
| 1693 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, |
| 1694 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, |
| 1695 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, |
| 1696 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, |
| 1697 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, |
| 1698 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, |
| 1699 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, |
| 1700 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, |
| 1701 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, |
| 1702 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, |
| 1703 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, |
| 1704 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, |
| 1705 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, |
| 1706 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, |
| 1707 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, |
| 1708 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, |
Jiri Kosina | ac26fca | 2008-11-20 11:27:02 +0100 | [diff] [blame] | 1709 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, |
| 1710 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, |
| 1711 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 1712 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, |
| 1713 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, |
| 1714 | { } |
| 1715 | }; |
| 1716 | |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1717 | static bool hid_ignore(struct hid_device *hdev) |
| 1718 | { |
| 1719 | switch (hdev->vendor) { |
| 1720 | case USB_VENDOR_ID_CODEMERCS: |
| 1721 | /* ignore all Code Mercenaries IOWarrior devices */ |
| 1722 | if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && |
| 1723 | hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) |
| 1724 | return true; |
| 1725 | break; |
| 1726 | case USB_VENDOR_ID_LOGITECH: |
| 1727 | if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST && |
| 1728 | hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST) |
| 1729 | return true; |
| 1730 | break; |
Jarod Wilson | 31f7fd7 | 2009-07-31 10:56:36 -0400 | [diff] [blame] | 1731 | case USB_VENDOR_ID_SOUNDGRAPH: |
| 1732 | if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST && |
| 1733 | hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST) |
| 1734 | return true; |
| 1735 | break; |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1736 | } |
| 1737 | |
Jiri Slaby | b4d8e47 | 2008-10-22 14:47:18 +0200 | [diff] [blame] | 1738 | if (hdev->type == HID_TYPE_USBMOUSE && |
| 1739 | hid_match_id(hdev, hid_mouse_ignore_list)) |
| 1740 | return true; |
| 1741 | |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1742 | return !!hid_match_id(hdev, hid_ignore_list); |
| 1743 | } |
| 1744 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1745 | int hid_add_device(struct hid_device *hdev) |
| 1746 | { |
| 1747 | static atomic_t id = ATOMIC_INIT(0); |
| 1748 | int ret; |
| 1749 | |
| 1750 | if (WARN_ON(hdev->status & HID_STAT_ADDED)) |
| 1751 | return -EBUSY; |
| 1752 | |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1753 | /* we need to kill them here, otherwise they will stay allocated to |
| 1754 | * wait for coming driver */ |
| 1755 | if (hid_ignore(hdev)) |
| 1756 | return -ENODEV; |
| 1757 | |
Kay Sievers | 6bbe586 | 2008-10-31 00:12:32 +0100 | [diff] [blame] | 1758 | /* XXX hack, any other cleaner solution after the driver core |
| 1759 | * is converted to allow more than 20 bytes as the device name? */ |
| 1760 | dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, |
| 1761 | hdev->vendor, hdev->product, atomic_inc_return(&id)); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1762 | |
| 1763 | ret = device_add(&hdev->dev); |
| 1764 | if (!ret) |
| 1765 | hdev->status |= HID_STAT_ADDED; |
| 1766 | |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 1767 | hid_debug_register(hdev, dev_name(&hdev->dev)); |
| 1768 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1769 | return ret; |
| 1770 | } |
| 1771 | EXPORT_SYMBOL_GPL(hid_add_device); |
| 1772 | |
| 1773 | /** |
| 1774 | * hid_allocate_device - allocate new hid device descriptor |
| 1775 | * |
| 1776 | * Allocate and initialize hid device, so that hid_destroy_device might be |
| 1777 | * used to free it. |
| 1778 | * |
| 1779 | * New hid_device pointer is returned on success, otherwise ERR_PTR encoded |
| 1780 | * error value. |
| 1781 | */ |
| 1782 | struct hid_device *hid_allocate_device(void) |
| 1783 | { |
| 1784 | struct hid_device *hdev; |
| 1785 | unsigned int i; |
| 1786 | int ret = -ENOMEM; |
| 1787 | |
| 1788 | hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); |
| 1789 | if (hdev == NULL) |
| 1790 | return ERR_PTR(ret); |
| 1791 | |
| 1792 | device_initialize(&hdev->dev); |
| 1793 | hdev->dev.release = hid_device_release; |
| 1794 | hdev->dev.bus = &hid_bus_type; |
| 1795 | |
| 1796 | hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, |
| 1797 | sizeof(struct hid_collection), GFP_KERNEL); |
| 1798 | if (hdev->collection == NULL) |
| 1799 | goto err; |
| 1800 | hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS; |
| 1801 | |
| 1802 | for (i = 0; i < HID_REPORT_TYPES; i++) |
| 1803 | INIT_LIST_HEAD(&hdev->report_enum[i].report_list); |
| 1804 | |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 1805 | init_waitqueue_head(&hdev->debug_wait); |
| 1806 | INIT_LIST_HEAD(&hdev->debug_list); |
| 1807 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1808 | return hdev; |
| 1809 | err: |
| 1810 | put_device(&hdev->dev); |
| 1811 | return ERR_PTR(ret); |
| 1812 | } |
| 1813 | EXPORT_SYMBOL_GPL(hid_allocate_device); |
| 1814 | |
| 1815 | static void hid_remove_device(struct hid_device *hdev) |
| 1816 | { |
| 1817 | if (hdev->status & HID_STAT_ADDED) { |
| 1818 | device_del(&hdev->dev); |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 1819 | hid_debug_unregister(hdev); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1820 | hdev->status &= ~HID_STAT_ADDED; |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | /** |
| 1825 | * hid_destroy_device - free previously allocated device |
| 1826 | * |
| 1827 | * @hdev: hid device |
| 1828 | * |
| 1829 | * If you allocate hid_device through hid_allocate_device, you should ever |
| 1830 | * free by this function. |
| 1831 | */ |
| 1832 | void hid_destroy_device(struct hid_device *hdev) |
| 1833 | { |
| 1834 | hid_remove_device(hdev); |
| 1835 | put_device(&hdev->dev); |
| 1836 | } |
| 1837 | EXPORT_SYMBOL_GPL(hid_destroy_device); |
| 1838 | |
| 1839 | int __hid_register_driver(struct hid_driver *hdrv, struct module *owner, |
| 1840 | const char *mod_name) |
| 1841 | { |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1842 | int ret; |
| 1843 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1844 | hdrv->driver.name = hdrv->name; |
| 1845 | hdrv->driver.bus = &hid_bus_type; |
| 1846 | hdrv->driver.owner = owner; |
| 1847 | hdrv->driver.mod_name = mod_name; |
| 1848 | |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1849 | INIT_LIST_HEAD(&hdrv->dyn_list); |
| 1850 | spin_lock_init(&hdrv->dyn_lock); |
| 1851 | |
| 1852 | ret = driver_register(&hdrv->driver); |
| 1853 | if (ret) |
| 1854 | return ret; |
| 1855 | |
| 1856 | ret = driver_create_file(&hdrv->driver, &driver_attr_new_id); |
| 1857 | if (ret) |
| 1858 | driver_unregister(&hdrv->driver); |
| 1859 | |
| 1860 | return ret; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1861 | } |
| 1862 | EXPORT_SYMBOL_GPL(__hid_register_driver); |
| 1863 | |
| 1864 | void hid_unregister_driver(struct hid_driver *hdrv) |
| 1865 | { |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1866 | driver_remove_file(&hdrv->driver, &driver_attr_new_id); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1867 | driver_unregister(&hdrv->driver); |
Jiri Slaby | 3a6f82f | 2008-11-24 16:20:09 +0100 | [diff] [blame] | 1868 | hid_free_dynids(hdrv); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1869 | } |
| 1870 | EXPORT_SYMBOL_GPL(hid_unregister_driver); |
| 1871 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1872 | int hid_check_keys_pressed(struct hid_device *hid) |
| 1873 | { |
| 1874 | struct hid_input *hidinput; |
| 1875 | int i; |
| 1876 | |
Jiri Kosina | e5288eb | 2009-05-02 00:02:57 +0200 | [diff] [blame] | 1877 | if (!(hid->claimed & HID_CLAIMED_INPUT)) |
| 1878 | return 0; |
| 1879 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1880 | list_for_each_entry(hidinput, &hid->inputs, list) { |
| 1881 | for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++) |
| 1882 | if (hidinput->input->key[i]) |
| 1883 | return 1; |
| 1884 | } |
| 1885 | |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
| 1889 | EXPORT_SYMBOL_GPL(hid_check_keys_pressed); |
| 1890 | |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1891 | static int __init hid_init(void) |
| 1892 | { |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1893 | int ret; |
| 1894 | |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 1895 | if (hid_debug) |
Jiri Kosina | cd667ce | 2009-06-12 15:20:57 +0200 | [diff] [blame] | 1896 | printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n" |
| 1897 | "HID: debugfs is now used for inspecting the device (report descriptor, reports)\n"); |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 1898 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1899 | ret = bus_register(&hid_bus_type); |
| 1900 | if (ret) { |
| 1901 | printk(KERN_ERR "HID: can't register hid bus\n"); |
| 1902 | goto err; |
| 1903 | } |
| 1904 | |
| 1905 | ret = hidraw_init(); |
| 1906 | if (ret) |
| 1907 | goto err_bus; |
| 1908 | |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 1909 | hid_debug_init(); |
| 1910 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1911 | return 0; |
| 1912 | err_bus: |
| 1913 | bus_unregister(&hid_bus_type); |
| 1914 | err: |
| 1915 | return ret; |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | static void __exit hid_exit(void) |
| 1919 | { |
Jiri Kosina | a635f9d | 2009-06-12 15:20:55 +0200 | [diff] [blame] | 1920 | hid_debug_exit(); |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1921 | hidraw_exit(); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1922 | bus_unregister(&hid_bus_type); |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | module_init(hid_init); |
| 1926 | module_exit(hid_exit); |
| 1927 | |
Jiri Kosina | 88adb72 | 2009-10-02 18:29:34 +0200 | [diff] [blame] | 1928 | MODULE_AUTHOR("Andreas Gal"); |
| 1929 | MODULE_AUTHOR("Vojtech Pavlik"); |
| 1930 | MODULE_AUTHOR("Jiri Kosina"); |
Jiri Kosina | aa938f7 | 2006-12-08 18:41:10 +0100 | [diff] [blame] | 1931 | MODULE_LICENSE(DRIVER_LICENSE); |
| 1932 | |