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