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