1dde5845aSJiri Kosina /* 2229695e5SJiri Kosina * HID support for Linux 3dde5845aSJiri Kosina * 4dde5845aSJiri Kosina * Copyright (c) 1999 Andreas Gal 5dde5845aSJiri Kosina * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 6dde5845aSJiri Kosina * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 76b1968d5SJiri Kosina * Copyright (c) 2006-2012 Jiri Kosina 8dde5845aSJiri Kosina */ 9dde5845aSJiri Kosina 10dde5845aSJiri Kosina /* 11dde5845aSJiri Kosina * This program is free software; you can redistribute it and/or modify it 12dde5845aSJiri Kosina * under the terms of the GNU General Public License as published by the Free 13dde5845aSJiri Kosina * Software Foundation; either version 2 of the License, or (at your option) 14dde5845aSJiri Kosina * any later version. 15dde5845aSJiri Kosina */ 16dde5845aSJiri Kosina 174291ee30SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 184291ee30SJoe Perches 19dde5845aSJiri Kosina #include <linux/module.h> 20dde5845aSJiri Kosina #include <linux/slab.h> 21dde5845aSJiri Kosina #include <linux/init.h> 22dde5845aSJiri Kosina #include <linux/kernel.h> 23dde5845aSJiri Kosina #include <linux/list.h> 24dde5845aSJiri Kosina #include <linux/mm.h> 25dde5845aSJiri Kosina #include <linux/spinlock.h> 26dde5845aSJiri Kosina #include <asm/unaligned.h> 27dde5845aSJiri Kosina #include <asm/byteorder.h> 28dde5845aSJiri Kosina #include <linux/input.h> 29dde5845aSJiri Kosina #include <linux/wait.h> 3047a80edbSJiri Kosina #include <linux/vmalloc.h> 31c4124c9bSJiri Kosina #include <linux/sched.h> 324ea54542SDavid Herrmann #include <linux/semaphore.h> 33dde5845aSJiri Kosina 34dde5845aSJiri Kosina #include <linux/hid.h> 35dde5845aSJiri Kosina #include <linux/hiddev.h> 36c080d89aSJiri Kosina #include <linux/hid-debug.h> 3786166b7bSJiri Kosina #include <linux/hidraw.h> 38dde5845aSJiri Kosina 395f22a799SJiri Slaby #include "hid-ids.h" 405f22a799SJiri Slaby 41dde5845aSJiri Kosina /* 42dde5845aSJiri Kosina * Version Information 43dde5845aSJiri Kosina */ 44dde5845aSJiri Kosina 4553149801SJiri Kosina #define DRIVER_DESC "HID core driver" 46dde5845aSJiri Kosina #define DRIVER_LICENSE "GPL" 47dde5845aSJiri Kosina 4858037eb9SJiri Kosina int hid_debug = 0; 49377e10fbSAnssi Hannula module_param_named(debug, hid_debug, int, 0600); 50cd667ce2SJiri Kosina MODULE_PARM_DESC(debug, "toggle HID debugging messages"); 5158037eb9SJiri Kosina EXPORT_SYMBOL_GPL(hid_debug); 5258037eb9SJiri Kosina 536b1968d5SJiri Kosina static int hid_ignore_special_drivers = 0; 546b1968d5SJiri Kosina module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600); 556b1968d5SJiri Kosina MODULE_PARM_DESC(debug, "Ignore any special drivers and handle all devices by generic driver"); 566b1968d5SJiri Kosina 57dde5845aSJiri Kosina /* 58dde5845aSJiri Kosina * Register a new report for a device. 59dde5845aSJiri Kosina */ 60dde5845aSJiri Kosina 6190a006abSMichael Poole struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) 62dde5845aSJiri Kosina { 63dde5845aSJiri Kosina struct hid_report_enum *report_enum = device->report_enum + type; 64dde5845aSJiri Kosina struct hid_report *report; 65dde5845aSJiri Kosina 66dde5845aSJiri Kosina if (report_enum->report_id_hash[id]) 67dde5845aSJiri Kosina return report_enum->report_id_hash[id]; 68dde5845aSJiri Kosina 69a3789a17SJoe Perches report = kzalloc(sizeof(struct hid_report), GFP_KERNEL); 70a3789a17SJoe Perches if (!report) 71dde5845aSJiri Kosina return NULL; 72dde5845aSJiri Kosina 73dde5845aSJiri Kosina if (id != 0) 74dde5845aSJiri Kosina report_enum->numbered = 1; 75dde5845aSJiri Kosina 76dde5845aSJiri Kosina report->id = id; 77dde5845aSJiri Kosina report->type = type; 78dde5845aSJiri Kosina report->size = 0; 79dde5845aSJiri Kosina report->device = device; 80dde5845aSJiri Kosina report_enum->report_id_hash[id] = report; 81dde5845aSJiri Kosina 82dde5845aSJiri Kosina list_add_tail(&report->list, &report_enum->report_list); 83dde5845aSJiri Kosina 84dde5845aSJiri Kosina return report; 85dde5845aSJiri Kosina } 8690a006abSMichael Poole EXPORT_SYMBOL_GPL(hid_register_report); 87dde5845aSJiri Kosina 88dde5845aSJiri Kosina /* 89dde5845aSJiri Kosina * Register a new field for this report. 90dde5845aSJiri Kosina */ 91dde5845aSJiri Kosina 92dde5845aSJiri Kosina static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values) 93dde5845aSJiri Kosina { 94dde5845aSJiri Kosina struct hid_field *field; 95f262d1faSBenjamin Tissoires int i; 96dde5845aSJiri Kosina 97dde5845aSJiri Kosina if (report->maxfield == HID_MAX_FIELDS) { 988c3d52fcSJiri Kosina hid_err(report->device, "too many fields in report\n"); 99dde5845aSJiri Kosina return NULL; 100dde5845aSJiri Kosina } 101dde5845aSJiri Kosina 102a3789a17SJoe Perches field = kzalloc((sizeof(struct hid_field) + 103a3789a17SJoe Perches usages * sizeof(struct hid_usage) + 104a3789a17SJoe Perches values * sizeof(unsigned)), GFP_KERNEL); 105a3789a17SJoe Perches if (!field) 106a3789a17SJoe Perches return NULL; 107dde5845aSJiri Kosina 108dde5845aSJiri Kosina field->index = report->maxfield++; 109dde5845aSJiri Kosina report->field[field->index] = field; 110dde5845aSJiri Kosina field->usage = (struct hid_usage *)(field + 1); 111282bfd4cSJiri Slaby field->value = (s32 *)(field->usage + usages); 112dde5845aSJiri Kosina field->report = report; 113dde5845aSJiri Kosina 114f262d1faSBenjamin Tissoires for (i = 0; i < usages; i++) 115f262d1faSBenjamin Tissoires field->usage[i].usage_index = i; 116f262d1faSBenjamin Tissoires 117dde5845aSJiri Kosina return field; 118dde5845aSJiri Kosina } 119dde5845aSJiri Kosina 120dde5845aSJiri Kosina /* 121dde5845aSJiri Kosina * Open a collection. The type/usage is pushed on the stack. 122dde5845aSJiri Kosina */ 123dde5845aSJiri Kosina 124dde5845aSJiri Kosina static int open_collection(struct hid_parser *parser, unsigned type) 125dde5845aSJiri Kosina { 126dde5845aSJiri Kosina struct hid_collection *collection; 127dde5845aSJiri Kosina unsigned usage; 128dde5845aSJiri Kosina 129dde5845aSJiri Kosina usage = parser->local.usage[0]; 130dde5845aSJiri Kosina 131dde5845aSJiri Kosina if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { 1328c3d52fcSJiri Kosina hid_err(parser->device, "collection stack overflow\n"); 133a6fbaacfSSachin Kamat return -EINVAL; 134dde5845aSJiri Kosina } 135dde5845aSJiri Kosina 136dde5845aSJiri Kosina if (parser->device->maxcollection == parser->device->collection_size) { 137dde5845aSJiri Kosina collection = kmalloc(sizeof(struct hid_collection) * 138dde5845aSJiri Kosina parser->device->collection_size * 2, GFP_KERNEL); 139dde5845aSJiri Kosina if (collection == NULL) { 1408c3d52fcSJiri Kosina hid_err(parser->device, "failed to reallocate collection array\n"); 141a6fbaacfSSachin Kamat return -ENOMEM; 142dde5845aSJiri Kosina } 143dde5845aSJiri Kosina memcpy(collection, parser->device->collection, 144dde5845aSJiri Kosina sizeof(struct hid_collection) * 145dde5845aSJiri Kosina parser->device->collection_size); 146dde5845aSJiri Kosina memset(collection + parser->device->collection_size, 0, 147dde5845aSJiri Kosina sizeof(struct hid_collection) * 148dde5845aSJiri Kosina parser->device->collection_size); 149dde5845aSJiri Kosina kfree(parser->device->collection); 150dde5845aSJiri Kosina parser->device->collection = collection; 151dde5845aSJiri Kosina parser->device->collection_size *= 2; 152dde5845aSJiri Kosina } 153dde5845aSJiri Kosina 154dde5845aSJiri Kosina parser->collection_stack[parser->collection_stack_ptr++] = 155dde5845aSJiri Kosina parser->device->maxcollection; 156dde5845aSJiri Kosina 157dde5845aSJiri Kosina collection = parser->device->collection + 158dde5845aSJiri Kosina parser->device->maxcollection++; 159dde5845aSJiri Kosina collection->type = type; 160dde5845aSJiri Kosina collection->usage = usage; 161dde5845aSJiri Kosina collection->level = parser->collection_stack_ptr - 1; 162dde5845aSJiri Kosina 163dde5845aSJiri Kosina if (type == HID_COLLECTION_APPLICATION) 164dde5845aSJiri Kosina parser->device->maxapplication++; 165dde5845aSJiri Kosina 166dde5845aSJiri Kosina return 0; 167dde5845aSJiri Kosina } 168dde5845aSJiri Kosina 169dde5845aSJiri Kosina /* 170dde5845aSJiri Kosina * Close a collection. 171dde5845aSJiri Kosina */ 172dde5845aSJiri Kosina 173dde5845aSJiri Kosina static int close_collection(struct hid_parser *parser) 174dde5845aSJiri Kosina { 175dde5845aSJiri Kosina if (!parser->collection_stack_ptr) { 1768c3d52fcSJiri Kosina hid_err(parser->device, "collection stack underflow\n"); 177a6fbaacfSSachin Kamat return -EINVAL; 178dde5845aSJiri Kosina } 179dde5845aSJiri Kosina parser->collection_stack_ptr--; 180dde5845aSJiri Kosina return 0; 181dde5845aSJiri Kosina } 182dde5845aSJiri Kosina 183dde5845aSJiri Kosina /* 184dde5845aSJiri Kosina * Climb up the stack, search for the specified collection type 185dde5845aSJiri Kosina * and return the usage. 186dde5845aSJiri Kosina */ 187dde5845aSJiri Kosina 188dde5845aSJiri Kosina static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) 189dde5845aSJiri Kosina { 190504499f2SJoe Perches struct hid_collection *collection = parser->device->collection; 191dde5845aSJiri Kosina int n; 192504499f2SJoe Perches 193504499f2SJoe Perches for (n = parser->collection_stack_ptr - 1; n >= 0; n--) { 194504499f2SJoe Perches unsigned index = parser->collection_stack[n]; 195504499f2SJoe Perches if (collection[index].type == type) 196504499f2SJoe Perches return collection[index].usage; 197504499f2SJoe Perches } 198dde5845aSJiri Kosina return 0; /* we know nothing about this usage type */ 199dde5845aSJiri Kosina } 200dde5845aSJiri Kosina 201dde5845aSJiri Kosina /* 202dde5845aSJiri Kosina * Add a usage to the temporary parser table. 203dde5845aSJiri Kosina */ 204dde5845aSJiri Kosina 205dde5845aSJiri Kosina static int hid_add_usage(struct hid_parser *parser, unsigned usage) 206dde5845aSJiri Kosina { 207dde5845aSJiri Kosina if (parser->local.usage_index >= HID_MAX_USAGES) { 2088c3d52fcSJiri Kosina hid_err(parser->device, "usage index exceeded\n"); 209dde5845aSJiri Kosina return -1; 210dde5845aSJiri Kosina } 211dde5845aSJiri Kosina parser->local.usage[parser->local.usage_index] = usage; 212dde5845aSJiri Kosina parser->local.collection_index[parser->local.usage_index] = 213dde5845aSJiri Kosina parser->collection_stack_ptr ? 214dde5845aSJiri Kosina parser->collection_stack[parser->collection_stack_ptr - 1] : 0; 215dde5845aSJiri Kosina parser->local.usage_index++; 216dde5845aSJiri Kosina return 0; 217dde5845aSJiri Kosina } 218dde5845aSJiri Kosina 219dde5845aSJiri Kosina /* 220dde5845aSJiri Kosina * Register a new field for this report. 221dde5845aSJiri Kosina */ 222dde5845aSJiri Kosina 223dde5845aSJiri Kosina static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags) 224dde5845aSJiri Kosina { 225dde5845aSJiri Kosina struct hid_report *report; 226dde5845aSJiri Kosina struct hid_field *field; 227dde5845aSJiri Kosina int usages; 228dde5845aSJiri Kosina unsigned offset; 229dde5845aSJiri Kosina int i; 230dde5845aSJiri Kosina 231a3789a17SJoe Perches report = hid_register_report(parser->device, report_type, parser->global.report_id); 232a3789a17SJoe Perches if (!report) { 2338c3d52fcSJiri Kosina hid_err(parser->device, "hid_register_report failed\n"); 234dde5845aSJiri Kosina return -1; 235dde5845aSJiri Kosina } 236dde5845aSJiri Kosina 237bb2e1976SJiri Kosina /* Handle both signed and unsigned cases properly */ 2380cd516c2Ssrinivas pandruvada if ((parser->global.logical_minimum < 0 && 2390cd516c2Ssrinivas pandruvada parser->global.logical_maximum < 2400cd516c2Ssrinivas pandruvada parser->global.logical_minimum) || 2410cd516c2Ssrinivas pandruvada (parser->global.logical_minimum >= 0 && 2420cd516c2Ssrinivas pandruvada (__u32)parser->global.logical_maximum < 2430cd516c2Ssrinivas pandruvada (__u32)parser->global.logical_minimum)) { 2440cd516c2Ssrinivas pandruvada dbg_hid("logical range invalid 0x%x 0x%x\n", 2450cd516c2Ssrinivas pandruvada parser->global.logical_minimum, 2460cd516c2Ssrinivas pandruvada parser->global.logical_maximum); 247dde5845aSJiri Kosina return -1; 248dde5845aSJiri Kosina } 249dde5845aSJiri Kosina 250dde5845aSJiri Kosina offset = report->size; 251dde5845aSJiri Kosina report->size += parser->global.report_size * parser->global.report_count; 252dde5845aSJiri Kosina 253dde5845aSJiri Kosina if (!parser->local.usage_index) /* Ignore padding fields */ 254dde5845aSJiri Kosina return 0; 255dde5845aSJiri Kosina 256dde5845aSJiri Kosina usages = max_t(int, parser->local.usage_index, parser->global.report_count); 257dde5845aSJiri Kosina 258a3789a17SJoe Perches field = hid_register_field(report, usages, parser->global.report_count); 259a3789a17SJoe Perches if (!field) 260dde5845aSJiri Kosina return 0; 261dde5845aSJiri Kosina 262dde5845aSJiri Kosina field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); 263dde5845aSJiri Kosina field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); 264dde5845aSJiri Kosina field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); 265dde5845aSJiri Kosina 266dde5845aSJiri Kosina for (i = 0; i < usages; i++) { 267dde5845aSJiri Kosina int j = i; 268dde5845aSJiri Kosina /* Duplicate the last usage we parsed if we have excess values */ 269dde5845aSJiri Kosina if (i >= parser->local.usage_index) 270dde5845aSJiri Kosina j = parser->local.usage_index - 1; 271dde5845aSJiri Kosina field->usage[i].hid = parser->local.usage[j]; 272dde5845aSJiri Kosina field->usage[i].collection_index = 273dde5845aSJiri Kosina parser->local.collection_index[j]; 274dde5845aSJiri Kosina } 275dde5845aSJiri Kosina 276dde5845aSJiri Kosina field->maxusage = usages; 277dde5845aSJiri Kosina field->flags = flags; 278dde5845aSJiri Kosina field->report_offset = offset; 279dde5845aSJiri Kosina field->report_type = report_type; 280dde5845aSJiri Kosina field->report_size = parser->global.report_size; 281dde5845aSJiri Kosina field->report_count = parser->global.report_count; 282dde5845aSJiri Kosina field->logical_minimum = parser->global.logical_minimum; 283dde5845aSJiri Kosina field->logical_maximum = parser->global.logical_maximum; 284dde5845aSJiri Kosina field->physical_minimum = parser->global.physical_minimum; 285dde5845aSJiri Kosina field->physical_maximum = parser->global.physical_maximum; 286dde5845aSJiri Kosina field->unit_exponent = parser->global.unit_exponent; 287dde5845aSJiri Kosina field->unit = parser->global.unit; 288dde5845aSJiri Kosina 289dde5845aSJiri Kosina return 0; 290dde5845aSJiri Kosina } 291dde5845aSJiri Kosina 292dde5845aSJiri Kosina /* 293dde5845aSJiri Kosina * Read data value from item. 294dde5845aSJiri Kosina */ 295dde5845aSJiri Kosina 296dde5845aSJiri Kosina static u32 item_udata(struct hid_item *item) 297dde5845aSJiri Kosina { 298dde5845aSJiri Kosina switch (item->size) { 299dde5845aSJiri Kosina case 1: return item->data.u8; 300dde5845aSJiri Kosina case 2: return item->data.u16; 301dde5845aSJiri Kosina case 4: return item->data.u32; 302dde5845aSJiri Kosina } 303dde5845aSJiri Kosina return 0; 304dde5845aSJiri Kosina } 305dde5845aSJiri Kosina 306dde5845aSJiri Kosina static s32 item_sdata(struct hid_item *item) 307dde5845aSJiri Kosina { 308dde5845aSJiri Kosina switch (item->size) { 309dde5845aSJiri Kosina case 1: return item->data.s8; 310dde5845aSJiri Kosina case 2: return item->data.s16; 311dde5845aSJiri Kosina case 4: return item->data.s32; 312dde5845aSJiri Kosina } 313dde5845aSJiri Kosina return 0; 314dde5845aSJiri Kosina } 315dde5845aSJiri Kosina 316dde5845aSJiri Kosina /* 317dde5845aSJiri Kosina * Process a global item. 318dde5845aSJiri Kosina */ 319dde5845aSJiri Kosina 320dde5845aSJiri Kosina static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) 321dde5845aSJiri Kosina { 32277463838SBenjamin Tissoires __u32 raw_value; 323dde5845aSJiri Kosina switch (item->tag) { 324dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_PUSH: 325dde5845aSJiri Kosina 326dde5845aSJiri Kosina if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { 3278c3d52fcSJiri Kosina hid_err(parser->device, "global environment stack overflow\n"); 328dde5845aSJiri Kosina return -1; 329dde5845aSJiri Kosina } 330dde5845aSJiri Kosina 331dde5845aSJiri Kosina memcpy(parser->global_stack + parser->global_stack_ptr++, 332dde5845aSJiri Kosina &parser->global, sizeof(struct hid_global)); 333dde5845aSJiri Kosina return 0; 334dde5845aSJiri Kosina 335dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_POP: 336dde5845aSJiri Kosina 337dde5845aSJiri Kosina if (!parser->global_stack_ptr) { 3388c3d52fcSJiri Kosina hid_err(parser->device, "global environment stack underflow\n"); 339dde5845aSJiri Kosina return -1; 340dde5845aSJiri Kosina } 341dde5845aSJiri Kosina 342880d29f1SJiri Slaby memcpy(&parser->global, parser->global_stack + 343880d29f1SJiri Slaby --parser->global_stack_ptr, sizeof(struct hid_global)); 344dde5845aSJiri Kosina return 0; 345dde5845aSJiri Kosina 346dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: 347dde5845aSJiri Kosina parser->global.usage_page = item_udata(item); 348dde5845aSJiri Kosina return 0; 349dde5845aSJiri Kosina 350dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: 351dde5845aSJiri Kosina parser->global.logical_minimum = item_sdata(item); 352dde5845aSJiri Kosina return 0; 353dde5845aSJiri Kosina 354dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: 355dde5845aSJiri Kosina if (parser->global.logical_minimum < 0) 356dde5845aSJiri Kosina parser->global.logical_maximum = item_sdata(item); 357dde5845aSJiri Kosina else 358dde5845aSJiri Kosina parser->global.logical_maximum = item_udata(item); 359dde5845aSJiri Kosina return 0; 360dde5845aSJiri Kosina 361dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: 362dde5845aSJiri Kosina parser->global.physical_minimum = item_sdata(item); 363dde5845aSJiri Kosina return 0; 364dde5845aSJiri Kosina 365dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: 366dde5845aSJiri Kosina if (parser->global.physical_minimum < 0) 367dde5845aSJiri Kosina parser->global.physical_maximum = item_sdata(item); 368dde5845aSJiri Kosina else 369dde5845aSJiri Kosina parser->global.physical_maximum = item_udata(item); 370dde5845aSJiri Kosina return 0; 371dde5845aSJiri Kosina 372dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: 37377463838SBenjamin Tissoires /* Units exponent negative numbers are given through a 37477463838SBenjamin Tissoires * two's complement. 37577463838SBenjamin Tissoires * See "6.2.2.7 Global Items" for more information. */ 37677463838SBenjamin Tissoires raw_value = item_udata(item); 37777463838SBenjamin Tissoires if (!(raw_value & 0xfffffff0)) 37877463838SBenjamin Tissoires parser->global.unit_exponent = hid_snto32(raw_value, 4); 37977463838SBenjamin Tissoires else 38077463838SBenjamin Tissoires parser->global.unit_exponent = raw_value; 381dde5845aSJiri Kosina return 0; 382dde5845aSJiri Kosina 383dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_UNIT: 384dde5845aSJiri Kosina parser->global.unit = item_udata(item); 385dde5845aSJiri Kosina return 0; 386dde5845aSJiri Kosina 387dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: 388880d29f1SJiri Slaby parser->global.report_size = item_udata(item); 38923408f95SMarek Vasut if (parser->global.report_size > 128) { 3908c3d52fcSJiri Kosina hid_err(parser->device, "invalid report_size %d\n", 391880d29f1SJiri Slaby parser->global.report_size); 392dde5845aSJiri Kosina return -1; 393dde5845aSJiri Kosina } 394dde5845aSJiri Kosina return 0; 395dde5845aSJiri Kosina 396dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: 397880d29f1SJiri Slaby parser->global.report_count = item_udata(item); 398880d29f1SJiri Slaby if (parser->global.report_count > HID_MAX_USAGES) { 3998c3d52fcSJiri Kosina hid_err(parser->device, "invalid report_count %d\n", 400880d29f1SJiri Slaby parser->global.report_count); 401dde5845aSJiri Kosina return -1; 402dde5845aSJiri Kosina } 403dde5845aSJiri Kosina return 0; 404dde5845aSJiri Kosina 405dde5845aSJiri Kosina case HID_GLOBAL_ITEM_TAG_REPORT_ID: 406880d29f1SJiri Slaby parser->global.report_id = item_udata(item); 407880d29f1SJiri Slaby if (parser->global.report_id == 0) { 4088c3d52fcSJiri Kosina hid_err(parser->device, "report_id 0 is invalid\n"); 409dde5845aSJiri Kosina return -1; 410dde5845aSJiri Kosina } 411dde5845aSJiri Kosina return 0; 412dde5845aSJiri Kosina 413dde5845aSJiri Kosina default: 4148c3d52fcSJiri Kosina hid_err(parser->device, "unknown global tag 0x%x\n", item->tag); 415dde5845aSJiri Kosina return -1; 416dde5845aSJiri Kosina } 417dde5845aSJiri Kosina } 418dde5845aSJiri Kosina 419dde5845aSJiri Kosina /* 420dde5845aSJiri Kosina * Process a local item. 421dde5845aSJiri Kosina */ 422dde5845aSJiri Kosina 423dde5845aSJiri Kosina static int hid_parser_local(struct hid_parser *parser, struct hid_item *item) 424dde5845aSJiri Kosina { 425dde5845aSJiri Kosina __u32 data; 426dde5845aSJiri Kosina unsigned n; 427dde5845aSJiri Kosina 428dde5845aSJiri Kosina data = item_udata(item); 429dde5845aSJiri Kosina 430dde5845aSJiri Kosina switch (item->tag) { 431dde5845aSJiri Kosina case HID_LOCAL_ITEM_TAG_DELIMITER: 432dde5845aSJiri Kosina 433dde5845aSJiri Kosina if (data) { 434dde5845aSJiri Kosina /* 435dde5845aSJiri Kosina * We treat items before the first delimiter 436dde5845aSJiri Kosina * as global to all usage sets (branch 0). 437dde5845aSJiri Kosina * In the moment we process only these global 438dde5845aSJiri Kosina * items and the first delimiter set. 439dde5845aSJiri Kosina */ 440dde5845aSJiri Kosina if (parser->local.delimiter_depth != 0) { 4418c3d52fcSJiri Kosina hid_err(parser->device, "nested delimiters\n"); 442dde5845aSJiri Kosina return -1; 443dde5845aSJiri Kosina } 444dde5845aSJiri Kosina parser->local.delimiter_depth++; 445dde5845aSJiri Kosina parser->local.delimiter_branch++; 446dde5845aSJiri Kosina } else { 447dde5845aSJiri Kosina if (parser->local.delimiter_depth < 1) { 4488c3d52fcSJiri Kosina hid_err(parser->device, "bogus close delimiter\n"); 449dde5845aSJiri Kosina return -1; 450dde5845aSJiri Kosina } 451dde5845aSJiri Kosina parser->local.delimiter_depth--; 452dde5845aSJiri Kosina } 45338ead6efSPaul Chavent return 0; 454dde5845aSJiri Kosina 455dde5845aSJiri Kosina case HID_LOCAL_ITEM_TAG_USAGE: 456dde5845aSJiri Kosina 457dde5845aSJiri Kosina if (parser->local.delimiter_branch > 1) { 45858037eb9SJiri Kosina dbg_hid("alternative usage ignored\n"); 459dde5845aSJiri Kosina return 0; 460dde5845aSJiri Kosina } 461dde5845aSJiri Kosina 462dde5845aSJiri Kosina if (item->size <= 2) 463dde5845aSJiri Kosina data = (parser->global.usage_page << 16) + data; 464dde5845aSJiri Kosina 465dde5845aSJiri Kosina return hid_add_usage(parser, data); 466dde5845aSJiri Kosina 467dde5845aSJiri Kosina case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: 468dde5845aSJiri Kosina 469dde5845aSJiri Kosina if (parser->local.delimiter_branch > 1) { 47058037eb9SJiri Kosina dbg_hid("alternative usage ignored\n"); 471dde5845aSJiri Kosina return 0; 472dde5845aSJiri Kosina } 473dde5845aSJiri Kosina 474dde5845aSJiri Kosina if (item->size <= 2) 475dde5845aSJiri Kosina data = (parser->global.usage_page << 16) + data; 476dde5845aSJiri Kosina 477dde5845aSJiri Kosina parser->local.usage_minimum = data; 478dde5845aSJiri Kosina return 0; 479dde5845aSJiri Kosina 480dde5845aSJiri Kosina case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: 481dde5845aSJiri Kosina 482dde5845aSJiri Kosina if (parser->local.delimiter_branch > 1) { 48358037eb9SJiri Kosina dbg_hid("alternative usage ignored\n"); 484dde5845aSJiri Kosina return 0; 485dde5845aSJiri Kosina } 486dde5845aSJiri Kosina 487dde5845aSJiri Kosina if (item->size <= 2) 488dde5845aSJiri Kosina data = (parser->global.usage_page << 16) + data; 489dde5845aSJiri Kosina 490dde5845aSJiri Kosina for (n = parser->local.usage_minimum; n <= data; n++) 491dde5845aSJiri Kosina if (hid_add_usage(parser, n)) { 49258037eb9SJiri Kosina dbg_hid("hid_add_usage failed\n"); 493dde5845aSJiri Kosina return -1; 494dde5845aSJiri Kosina } 495dde5845aSJiri Kosina return 0; 496dde5845aSJiri Kosina 497dde5845aSJiri Kosina default: 498dde5845aSJiri Kosina 49958037eb9SJiri Kosina dbg_hid("unknown local item tag 0x%x\n", item->tag); 500dde5845aSJiri Kosina return 0; 501dde5845aSJiri Kosina } 502dde5845aSJiri Kosina return 0; 503dde5845aSJiri Kosina } 504dde5845aSJiri Kosina 505dde5845aSJiri Kosina /* 506dde5845aSJiri Kosina * Process a main item. 507dde5845aSJiri Kosina */ 508dde5845aSJiri Kosina 509dde5845aSJiri Kosina static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) 510dde5845aSJiri Kosina { 511dde5845aSJiri Kosina __u32 data; 512dde5845aSJiri Kosina int ret; 513dde5845aSJiri Kosina 514dde5845aSJiri Kosina data = item_udata(item); 515dde5845aSJiri Kosina 516dde5845aSJiri Kosina switch (item->tag) { 517dde5845aSJiri Kosina case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: 518dde5845aSJiri Kosina ret = open_collection(parser, data & 0xff); 519dde5845aSJiri Kosina break; 520dde5845aSJiri Kosina case HID_MAIN_ITEM_TAG_END_COLLECTION: 521dde5845aSJiri Kosina ret = close_collection(parser); 522dde5845aSJiri Kosina break; 523dde5845aSJiri Kosina case HID_MAIN_ITEM_TAG_INPUT: 524dde5845aSJiri Kosina ret = hid_add_field(parser, HID_INPUT_REPORT, data); 525dde5845aSJiri Kosina break; 526dde5845aSJiri Kosina case HID_MAIN_ITEM_TAG_OUTPUT: 527dde5845aSJiri Kosina ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); 528dde5845aSJiri Kosina break; 529dde5845aSJiri Kosina case HID_MAIN_ITEM_TAG_FEATURE: 530dde5845aSJiri Kosina ret = hid_add_field(parser, HID_FEATURE_REPORT, data); 531dde5845aSJiri Kosina break; 532dde5845aSJiri Kosina default: 5338c3d52fcSJiri Kosina hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag); 534dde5845aSJiri Kosina ret = 0; 535dde5845aSJiri Kosina } 536dde5845aSJiri Kosina 537dde5845aSJiri Kosina memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ 538dde5845aSJiri Kosina 539dde5845aSJiri Kosina return ret; 540dde5845aSJiri Kosina } 541dde5845aSJiri Kosina 542dde5845aSJiri Kosina /* 543dde5845aSJiri Kosina * Process a reserved item. 544dde5845aSJiri Kosina */ 545dde5845aSJiri Kosina 546dde5845aSJiri Kosina static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item) 547dde5845aSJiri Kosina { 54858037eb9SJiri Kosina dbg_hid("reserved item type, tag 0x%x\n", item->tag); 549dde5845aSJiri Kosina return 0; 550dde5845aSJiri Kosina } 551dde5845aSJiri Kosina 552dde5845aSJiri Kosina /* 553dde5845aSJiri Kosina * Free a report and all registered fields. The field->usage and 554dde5845aSJiri Kosina * field->value table's are allocated behind the field, so we need 555dde5845aSJiri Kosina * only to free(field) itself. 556dde5845aSJiri Kosina */ 557dde5845aSJiri Kosina 558dde5845aSJiri Kosina static void hid_free_report(struct hid_report *report) 559dde5845aSJiri Kosina { 560dde5845aSJiri Kosina unsigned n; 561dde5845aSJiri Kosina 562dde5845aSJiri Kosina for (n = 0; n < report->maxfield; n++) 563dde5845aSJiri Kosina kfree(report->field[n]); 564dde5845aSJiri Kosina kfree(report); 565dde5845aSJiri Kosina } 566dde5845aSJiri Kosina 567dde5845aSJiri Kosina /* 568a7197c2eSHenrik Rydberg * Close report. This function returns the device 569a7197c2eSHenrik Rydberg * state to the point prior to hid_open_report(). 570dde5845aSJiri Kosina */ 571a7197c2eSHenrik Rydberg static void hid_close_report(struct hid_device *device) 572dde5845aSJiri Kosina { 573dde5845aSJiri Kosina unsigned i, j; 574dde5845aSJiri Kosina 575dde5845aSJiri Kosina for (i = 0; i < HID_REPORT_TYPES; i++) { 576dde5845aSJiri Kosina struct hid_report_enum *report_enum = device->report_enum + i; 577dde5845aSJiri Kosina 578dde5845aSJiri Kosina for (j = 0; j < 256; j++) { 579dde5845aSJiri Kosina struct hid_report *report = report_enum->report_id_hash[j]; 580dde5845aSJiri Kosina if (report) 581dde5845aSJiri Kosina hid_free_report(report); 582dde5845aSJiri Kosina } 583a7197c2eSHenrik Rydberg memset(report_enum, 0, sizeof(*report_enum)); 584a7197c2eSHenrik Rydberg INIT_LIST_HEAD(&report_enum->report_list); 585dde5845aSJiri Kosina } 586dde5845aSJiri Kosina 587dde5845aSJiri Kosina kfree(device->rdesc); 588a7197c2eSHenrik Rydberg device->rdesc = NULL; 589a7197c2eSHenrik Rydberg device->rsize = 0; 590a7197c2eSHenrik Rydberg 591767fe787SJiri Kosina kfree(device->collection); 592a7197c2eSHenrik Rydberg device->collection = NULL; 593a7197c2eSHenrik Rydberg device->collection_size = 0; 594a7197c2eSHenrik Rydberg device->maxcollection = 0; 595a7197c2eSHenrik Rydberg device->maxapplication = 0; 596a7197c2eSHenrik Rydberg 597a7197c2eSHenrik Rydberg device->status &= ~HID_STAT_PARSED; 598a7197c2eSHenrik Rydberg } 599a7197c2eSHenrik Rydberg 600a7197c2eSHenrik Rydberg /* 601a7197c2eSHenrik Rydberg * Free a device structure, all reports, and all fields. 602a7197c2eSHenrik Rydberg */ 603a7197c2eSHenrik Rydberg 604a7197c2eSHenrik Rydberg static void hid_device_release(struct device *dev) 605a7197c2eSHenrik Rydberg { 606a7197c2eSHenrik Rydberg struct hid_device *hid = container_of(dev, struct hid_device, dev); 607a7197c2eSHenrik Rydberg 608a7197c2eSHenrik Rydberg hid_close_report(hid); 609a7197c2eSHenrik Rydberg kfree(hid->dev_rdesc); 610a7197c2eSHenrik Rydberg kfree(hid); 611dde5845aSJiri Kosina } 612dde5845aSJiri Kosina 613dde5845aSJiri Kosina /* 614dde5845aSJiri Kosina * Fetch a report description item from the data stream. We support long 615dde5845aSJiri Kosina * items, though they are not used yet. 616dde5845aSJiri Kosina */ 617dde5845aSJiri Kosina 618dde5845aSJiri Kosina static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) 619dde5845aSJiri Kosina { 620dde5845aSJiri Kosina u8 b; 621dde5845aSJiri Kosina 622dde5845aSJiri Kosina if ((end - start) <= 0) 623dde5845aSJiri Kosina return NULL; 624dde5845aSJiri Kosina 625dde5845aSJiri Kosina b = *start++; 626dde5845aSJiri Kosina 627dde5845aSJiri Kosina item->type = (b >> 2) & 3; 628dde5845aSJiri Kosina item->tag = (b >> 4) & 15; 629dde5845aSJiri Kosina 630dde5845aSJiri Kosina if (item->tag == HID_ITEM_TAG_LONG) { 631dde5845aSJiri Kosina 632dde5845aSJiri Kosina item->format = HID_ITEM_FORMAT_LONG; 633dde5845aSJiri Kosina 634dde5845aSJiri Kosina if ((end - start) < 2) 635dde5845aSJiri Kosina return NULL; 636dde5845aSJiri Kosina 637dde5845aSJiri Kosina item->size = *start++; 638dde5845aSJiri Kosina item->tag = *start++; 639dde5845aSJiri Kosina 640dde5845aSJiri Kosina if ((end - start) < item->size) 641dde5845aSJiri Kosina return NULL; 642dde5845aSJiri Kosina 643dde5845aSJiri Kosina item->data.longdata = start; 644dde5845aSJiri Kosina start += item->size; 645dde5845aSJiri Kosina return start; 646dde5845aSJiri Kosina } 647dde5845aSJiri Kosina 648dde5845aSJiri Kosina item->format = HID_ITEM_FORMAT_SHORT; 649dde5845aSJiri Kosina item->size = b & 3; 650dde5845aSJiri Kosina 651dde5845aSJiri Kosina switch (item->size) { 652dde5845aSJiri Kosina case 0: 653dde5845aSJiri Kosina return start; 654dde5845aSJiri Kosina 655dde5845aSJiri Kosina case 1: 656dde5845aSJiri Kosina if ((end - start) < 1) 657dde5845aSJiri Kosina return NULL; 658dde5845aSJiri Kosina item->data.u8 = *start++; 659dde5845aSJiri Kosina return start; 660dde5845aSJiri Kosina 661dde5845aSJiri Kosina case 2: 662dde5845aSJiri Kosina if ((end - start) < 2) 663dde5845aSJiri Kosina return NULL; 664c105068fSHarvey Harrison item->data.u16 = get_unaligned_le16(start); 665dde5845aSJiri Kosina start = (__u8 *)((__le16 *)start + 1); 666dde5845aSJiri Kosina return start; 667dde5845aSJiri Kosina 668dde5845aSJiri Kosina case 3: 669dde5845aSJiri Kosina item->size++; 670dde5845aSJiri Kosina if ((end - start) < 4) 671dde5845aSJiri Kosina return NULL; 672c105068fSHarvey Harrison item->data.u32 = get_unaligned_le32(start); 673dde5845aSJiri Kosina start = (__u8 *)((__le32 *)start + 1); 674dde5845aSJiri Kosina return start; 675dde5845aSJiri Kosina } 676dde5845aSJiri Kosina 677dde5845aSJiri Kosina return NULL; 678dde5845aSJiri Kosina } 679dde5845aSJiri Kosina 680734c6609SHenrik Rydberg static void hid_scan_usage(struct hid_device *hid, u32 usage) 681734c6609SHenrik Rydberg { 6824fa3a583SHenrik Rydberg if (usage == HID_DG_CONTACTID) 6834fa3a583SHenrik Rydberg hid->group = HID_GROUP_MULTITOUCH; 684734c6609SHenrik Rydberg } 685734c6609SHenrik Rydberg 686734c6609SHenrik Rydberg /* 687734c6609SHenrik Rydberg * Scan a report descriptor before the device is added to the bus. 688734c6609SHenrik Rydberg * Sets device groups and other properties that determine what driver 689734c6609SHenrik Rydberg * to load. 690734c6609SHenrik Rydberg */ 691734c6609SHenrik Rydberg static int hid_scan_report(struct hid_device *hid) 692734c6609SHenrik Rydberg { 693734c6609SHenrik Rydberg unsigned int page = 0, delim = 0; 694734c6609SHenrik Rydberg __u8 *start = hid->dev_rdesc; 695734c6609SHenrik Rydberg __u8 *end = start + hid->dev_rsize; 696734c6609SHenrik Rydberg unsigned int u, u_min = 0, u_max = 0; 697734c6609SHenrik Rydberg struct hid_item item; 698734c6609SHenrik Rydberg 699734c6609SHenrik Rydberg hid->group = HID_GROUP_GENERIC; 700734c6609SHenrik Rydberg while ((start = fetch_item(start, end, &item)) != NULL) { 701734c6609SHenrik Rydberg if (item.format != HID_ITEM_FORMAT_SHORT) 702734c6609SHenrik Rydberg return -EINVAL; 703734c6609SHenrik Rydberg if (item.type == HID_ITEM_TYPE_GLOBAL) { 704734c6609SHenrik Rydberg if (item.tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE) 705734c6609SHenrik Rydberg page = item_udata(&item) << 16; 706734c6609SHenrik Rydberg } else if (item.type == HID_ITEM_TYPE_LOCAL) { 707734c6609SHenrik Rydberg if (delim > 1) 708734c6609SHenrik Rydberg break; 709734c6609SHenrik Rydberg u = item_udata(&item); 710734c6609SHenrik Rydberg if (item.size <= 2) 711734c6609SHenrik Rydberg u += page; 712734c6609SHenrik Rydberg switch (item.tag) { 713734c6609SHenrik Rydberg case HID_LOCAL_ITEM_TAG_DELIMITER: 714734c6609SHenrik Rydberg delim += !!u; 715734c6609SHenrik Rydberg break; 716734c6609SHenrik Rydberg case HID_LOCAL_ITEM_TAG_USAGE: 717734c6609SHenrik Rydberg hid_scan_usage(hid, u); 718734c6609SHenrik Rydberg break; 719734c6609SHenrik Rydberg case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: 720734c6609SHenrik Rydberg u_min = u; 721734c6609SHenrik Rydberg break; 722734c6609SHenrik Rydberg case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: 723734c6609SHenrik Rydberg u_max = u; 724734c6609SHenrik Rydberg for (u = u_min; u <= u_max; u++) 725734c6609SHenrik Rydberg hid_scan_usage(hid, u); 726734c6609SHenrik Rydberg break; 727734c6609SHenrik Rydberg } 72883499b52SAlexander Holler } else if (page == HID_UP_SENSOR && 72983499b52SAlexander Holler item.type == HID_ITEM_TYPE_MAIN && 73083499b52SAlexander Holler item.tag == HID_MAIN_ITEM_TAG_BEGIN_COLLECTION && 7316399f335SMika Westerberg (item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL) 73283499b52SAlexander Holler hid->group = HID_GROUP_SENSOR_HUB; 733734c6609SHenrik Rydberg } 734734c6609SHenrik Rydberg 735734c6609SHenrik Rydberg return 0; 736734c6609SHenrik Rydberg } 737734c6609SHenrik Rydberg 73885cdaf52SJiri Slaby /** 73985cdaf52SJiri Slaby * hid_parse_report - parse device report 74085cdaf52SJiri Slaby * 74185cdaf52SJiri Slaby * @device: hid device 74285cdaf52SJiri Slaby * @start: report start 74385cdaf52SJiri Slaby * @size: report size 74485cdaf52SJiri Slaby * 745a7197c2eSHenrik Rydberg * Allocate the device report as read by the bus driver. This function should 746a7197c2eSHenrik Rydberg * only be called from parse() in ll drivers. 747a7197c2eSHenrik Rydberg */ 748a7197c2eSHenrik Rydberg int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size) 749a7197c2eSHenrik Rydberg { 750a7197c2eSHenrik Rydberg hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL); 751a7197c2eSHenrik Rydberg if (!hid->dev_rdesc) 752a7197c2eSHenrik Rydberg return -ENOMEM; 753a7197c2eSHenrik Rydberg hid->dev_rsize = size; 754a7197c2eSHenrik Rydberg return 0; 755a7197c2eSHenrik Rydberg } 756a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_parse_report); 757a7197c2eSHenrik Rydberg 758a7197c2eSHenrik Rydberg /** 759a7197c2eSHenrik Rydberg * hid_open_report - open a driver-specific device report 760a7197c2eSHenrik Rydberg * 761a7197c2eSHenrik Rydberg * @device: hid device 762a7197c2eSHenrik Rydberg * 763dde5845aSJiri Kosina * Parse a report description into a hid_device structure. Reports are 764dde5845aSJiri Kosina * enumerated, fields are attached to these reports. 76585cdaf52SJiri Slaby * 0 returned on success, otherwise nonzero error value. 766a7197c2eSHenrik Rydberg * 767a7197c2eSHenrik Rydberg * This function (or the equivalent hid_parse() macro) should only be 768a7197c2eSHenrik Rydberg * called from probe() in drivers, before starting the device. 769dde5845aSJiri Kosina */ 770a7197c2eSHenrik Rydberg int hid_open_report(struct hid_device *device) 771dde5845aSJiri Kosina { 772dde5845aSJiri Kosina struct hid_parser *parser; 773dde5845aSJiri Kosina struct hid_item item; 774a7197c2eSHenrik Rydberg unsigned int size; 775a7197c2eSHenrik Rydberg __u8 *start; 77686e6b77eSKevin Daughtridge __u8 *buf; 777dde5845aSJiri Kosina __u8 *end; 77885cdaf52SJiri Slaby int ret; 779dde5845aSJiri Kosina static int (*dispatch_type[])(struct hid_parser *parser, 780dde5845aSJiri Kosina struct hid_item *item) = { 781dde5845aSJiri Kosina hid_parser_main, 782dde5845aSJiri Kosina hid_parser_global, 783dde5845aSJiri Kosina hid_parser_local, 784dde5845aSJiri Kosina hid_parser_reserved 785dde5845aSJiri Kosina }; 786dde5845aSJiri Kosina 787a7197c2eSHenrik Rydberg if (WARN_ON(device->status & HID_STAT_PARSED)) 788a7197c2eSHenrik Rydberg return -EBUSY; 789a7197c2eSHenrik Rydberg 790a7197c2eSHenrik Rydberg start = device->dev_rdesc; 791a7197c2eSHenrik Rydberg if (WARN_ON(!start)) 792a7197c2eSHenrik Rydberg return -ENODEV; 793a7197c2eSHenrik Rydberg size = device->dev_rsize; 794a7197c2eSHenrik Rydberg 79586e6b77eSKevin Daughtridge buf = kmemdup(start, size, GFP_KERNEL); 79686e6b77eSKevin Daughtridge if (buf == NULL) 79785cdaf52SJiri Slaby return -ENOMEM; 79886e6b77eSKevin Daughtridge 79986e6b77eSKevin Daughtridge if (device->driver->report_fixup) 80086e6b77eSKevin Daughtridge start = device->driver->report_fixup(device, buf, &size); 80186e6b77eSKevin Daughtridge else 80286e6b77eSKevin Daughtridge start = buf; 80386e6b77eSKevin Daughtridge 80486e6b77eSKevin Daughtridge start = kmemdup(start, size, GFP_KERNEL); 80586e6b77eSKevin Daughtridge kfree(buf); 80686e6b77eSKevin Daughtridge if (start == NULL) 80786e6b77eSKevin Daughtridge return -ENOMEM; 80886e6b77eSKevin Daughtridge 80986e6b77eSKevin Daughtridge device->rdesc = start; 810dde5845aSJiri Kosina device->rsize = size; 811dde5845aSJiri Kosina 812fe258020SJoe Perches parser = vzalloc(sizeof(struct hid_parser)); 81385cdaf52SJiri Slaby if (!parser) { 81485cdaf52SJiri Slaby ret = -ENOMEM; 81585cdaf52SJiri Slaby goto err; 816dde5845aSJiri Kosina } 81785cdaf52SJiri Slaby 818dde5845aSJiri Kosina parser->device = device; 819dde5845aSJiri Kosina 820dde5845aSJiri Kosina end = start + size; 821a7197c2eSHenrik Rydberg 822a7197c2eSHenrik Rydberg device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, 823a7197c2eSHenrik Rydberg sizeof(struct hid_collection), GFP_KERNEL); 824a7197c2eSHenrik Rydberg if (!device->collection) { 825a7197c2eSHenrik Rydberg ret = -ENOMEM; 826a7197c2eSHenrik Rydberg goto err; 827a7197c2eSHenrik Rydberg } 828a7197c2eSHenrik Rydberg device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; 829a7197c2eSHenrik Rydberg 83085cdaf52SJiri Slaby ret = -EINVAL; 831dde5845aSJiri Kosina while ((start = fetch_item(start, end, &item)) != NULL) { 832dde5845aSJiri Kosina 833dde5845aSJiri Kosina if (item.format != HID_ITEM_FORMAT_SHORT) { 8348c3d52fcSJiri Kosina hid_err(device, "unexpected long global item\n"); 83585cdaf52SJiri Slaby goto err; 836dde5845aSJiri Kosina } 837dde5845aSJiri Kosina 838dde5845aSJiri Kosina if (dispatch_type[item.type](parser, &item)) { 8398c3d52fcSJiri Kosina hid_err(device, "item %u %u %u %u parsing failed\n", 8404291ee30SJoe Perches item.format, (unsigned)item.size, 8414291ee30SJoe Perches (unsigned)item.type, (unsigned)item.tag); 84285cdaf52SJiri Slaby goto err; 843dde5845aSJiri Kosina } 844dde5845aSJiri Kosina 845dde5845aSJiri Kosina if (start == end) { 846dde5845aSJiri Kosina if (parser->collection_stack_ptr) { 8478c3d52fcSJiri Kosina hid_err(device, "unbalanced collection at end of report description\n"); 84885cdaf52SJiri Slaby goto err; 849dde5845aSJiri Kosina } 850dde5845aSJiri Kosina if (parser->local.delimiter_depth) { 8518c3d52fcSJiri Kosina hid_err(device, "unbalanced delimiter at end of report description\n"); 85285cdaf52SJiri Slaby goto err; 853dde5845aSJiri Kosina } 85447a80edbSJiri Kosina vfree(parser); 855a7197c2eSHenrik Rydberg device->status |= HID_STAT_PARSED; 85685cdaf52SJiri Slaby return 0; 857dde5845aSJiri Kosina } 858dde5845aSJiri Kosina } 859dde5845aSJiri Kosina 8608c3d52fcSJiri Kosina hid_err(device, "item fetching failed at offset %d\n", (int)(end - start)); 86185cdaf52SJiri Slaby err: 86247a80edbSJiri Kosina vfree(parser); 863a7197c2eSHenrik Rydberg hid_close_report(device); 86485cdaf52SJiri Slaby return ret; 865dde5845aSJiri Kosina } 866a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_open_report); 867dde5845aSJiri Kosina 868dde5845aSJiri Kosina /* 869dde5845aSJiri Kosina * Convert a signed n-bit integer to signed 32-bit integer. Common 870dde5845aSJiri Kosina * cases are done through the compiler, the screwed things has to be 871dde5845aSJiri Kosina * done by hand. 872dde5845aSJiri Kosina */ 873dde5845aSJiri Kosina 874dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n) 875dde5845aSJiri Kosina { 876dde5845aSJiri Kosina switch (n) { 877dde5845aSJiri Kosina case 8: return ((__s8)value); 878dde5845aSJiri Kosina case 16: return ((__s16)value); 879dde5845aSJiri Kosina case 32: return ((__s32)value); 880dde5845aSJiri Kosina } 881dde5845aSJiri Kosina return value & (1 << (n - 1)) ? value | (-1 << n) : value; 882dde5845aSJiri Kosina } 883dde5845aSJiri Kosina 88477463838SBenjamin Tissoires s32 hid_snto32(__u32 value, unsigned n) 88577463838SBenjamin Tissoires { 88677463838SBenjamin Tissoires return snto32(value, n); 88777463838SBenjamin Tissoires } 88877463838SBenjamin Tissoires EXPORT_SYMBOL_GPL(hid_snto32); 88977463838SBenjamin Tissoires 890dde5845aSJiri Kosina /* 891dde5845aSJiri Kosina * Convert a signed 32-bit integer to a signed n-bit integer. 892dde5845aSJiri Kosina */ 893dde5845aSJiri Kosina 894dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n) 895dde5845aSJiri Kosina { 896dde5845aSJiri Kosina s32 a = value >> (n - 1); 897dde5845aSJiri Kosina if (a && a != -1) 898dde5845aSJiri Kosina return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; 899dde5845aSJiri Kosina return value & ((1 << n) - 1); 900dde5845aSJiri Kosina } 901dde5845aSJiri Kosina 902dde5845aSJiri Kosina /* 903dde5845aSJiri Kosina * Extract/implement a data field from/to a little endian report (bit array). 904dde5845aSJiri Kosina * 905dde5845aSJiri Kosina * Code sort-of follows HID spec: 906dde5845aSJiri Kosina * http://www.usb.org/developers/devclass_docs/HID1_11.pdf 907dde5845aSJiri Kosina * 908dde5845aSJiri Kosina * While the USB HID spec allows unlimited length bit fields in "report 909dde5845aSJiri Kosina * descriptors", most devices never use more than 16 bits. 910dde5845aSJiri Kosina * One model of UPS is claimed to report "LINEV" as a 32-bit field. 911dde5845aSJiri Kosina * Search linux-kernel and linux-usb-devel archives for "hid-core extract". 912dde5845aSJiri Kosina */ 913dde5845aSJiri Kosina 91416ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report, 9154291ee30SJoe Perches unsigned offset, unsigned n) 916dde5845aSJiri Kosina { 917dde5845aSJiri Kosina u64 x; 918dde5845aSJiri Kosina 919c4124c9bSJiri Kosina if (n > 32) 9204291ee30SJoe Perches hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n", 921c4124c9bSJiri Kosina n, current->comm); 922dde5845aSJiri Kosina 923dde5845aSJiri Kosina report += offset >> 3; /* adjust byte index */ 924dde5845aSJiri Kosina offset &= 7; /* now only need bit offset into one byte */ 925c105068fSHarvey Harrison x = get_unaligned_le64(report); 926dde5845aSJiri Kosina x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */ 927dde5845aSJiri Kosina return (u32) x; 928dde5845aSJiri Kosina } 929dde5845aSJiri Kosina 930dde5845aSJiri Kosina /* 931dde5845aSJiri Kosina * "implement" : set bits in a little endian bit stream. 932dde5845aSJiri Kosina * Same concepts as "extract" (see comments above). 933dde5845aSJiri Kosina * The data mangled in the bit stream remains in little endian 934dde5845aSJiri Kosina * order the whole time. It make more sense to talk about 935dde5845aSJiri Kosina * endianness of register values by considering a register 936dde5845aSJiri Kosina * a "cached" copy of the little endiad bit stream. 937dde5845aSJiri Kosina */ 93816ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report, 9394291ee30SJoe Perches unsigned offset, unsigned n, __u32 value) 940dde5845aSJiri Kosina { 9416f0168d2SHarvey Harrison u64 x; 942dde5845aSJiri Kosina u64 m = (1ULL << n) - 1; 943dde5845aSJiri Kosina 944c4124c9bSJiri Kosina if (n > 32) 9454291ee30SJoe Perches hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n", 9464291ee30SJoe Perches __func__, n, current->comm); 947dde5845aSJiri Kosina 948c4124c9bSJiri Kosina if (value > m) 9494291ee30SJoe Perches hid_warn(hid, "%s() called with too large value %d! (%s)\n", 9504291ee30SJoe Perches __func__, value, current->comm); 951dde5845aSJiri Kosina WARN_ON(value > m); 952dde5845aSJiri Kosina value &= m; 953dde5845aSJiri Kosina 954dde5845aSJiri Kosina report += offset >> 3; 955dde5845aSJiri Kosina offset &= 7; 956dde5845aSJiri Kosina 9576f0168d2SHarvey Harrison x = get_unaligned_le64(report); 9586f0168d2SHarvey Harrison x &= ~(m << offset); 9596f0168d2SHarvey Harrison x |= ((u64)value) << offset; 9606f0168d2SHarvey Harrison put_unaligned_le64(x, report); 961dde5845aSJiri Kosina } 962dde5845aSJiri Kosina 963dde5845aSJiri Kosina /* 964dde5845aSJiri Kosina * Search an array for a value. 965dde5845aSJiri Kosina */ 966dde5845aSJiri Kosina 96716ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n) 968dde5845aSJiri Kosina { 969dde5845aSJiri Kosina while (n--) { 970dde5845aSJiri Kosina if (*array++ == value) 971dde5845aSJiri Kosina return 0; 972dde5845aSJiri Kosina } 973dde5845aSJiri Kosina return -1; 974dde5845aSJiri Kosina } 975dde5845aSJiri Kosina 97685cdaf52SJiri Slaby /** 97785cdaf52SJiri Slaby * hid_match_report - check if driver's raw_event should be called 97885cdaf52SJiri Slaby * 97985cdaf52SJiri Slaby * @hid: hid device 98085cdaf52SJiri Slaby * @report_type: type to match against 98185cdaf52SJiri Slaby * 98285cdaf52SJiri Slaby * compare hid->driver->report_table->report_type to report->type 98385cdaf52SJiri Slaby */ 98485cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report) 985dde5845aSJiri Kosina { 98685cdaf52SJiri Slaby const struct hid_report_id *id = hid->driver->report_table; 98785cdaf52SJiri Slaby 98885cdaf52SJiri Slaby if (!id) /* NULL means all */ 98985cdaf52SJiri Slaby return 1; 99085cdaf52SJiri Slaby 99185cdaf52SJiri Slaby for (; id->report_type != HID_TERMINATOR; id++) 99285cdaf52SJiri Slaby if (id->report_type == HID_ANY_ID || 99385cdaf52SJiri Slaby id->report_type == report->type) 99485cdaf52SJiri Slaby return 1; 99585cdaf52SJiri Slaby return 0; 99685cdaf52SJiri Slaby } 99785cdaf52SJiri Slaby 99885cdaf52SJiri Slaby /** 99985cdaf52SJiri Slaby * hid_match_usage - check if driver's event should be called 100085cdaf52SJiri Slaby * 100185cdaf52SJiri Slaby * @hid: hid device 100285cdaf52SJiri Slaby * @usage: usage to match against 100385cdaf52SJiri Slaby * 100485cdaf52SJiri Slaby * compare hid->driver->usage_table->usage_{type,code} to 100585cdaf52SJiri Slaby * usage->usage_{type,code} 100685cdaf52SJiri Slaby */ 100785cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage) 100885cdaf52SJiri Slaby { 100985cdaf52SJiri Slaby const struct hid_usage_id *id = hid->driver->usage_table; 101085cdaf52SJiri Slaby 101185cdaf52SJiri Slaby if (!id) /* NULL means all */ 101285cdaf52SJiri Slaby return 1; 101385cdaf52SJiri Slaby 101485cdaf52SJiri Slaby for (; id->usage_type != HID_ANY_ID - 1; id++) 101585cdaf52SJiri Slaby if ((id->usage_hid == HID_ANY_ID || 101685cdaf52SJiri Slaby id->usage_hid == usage->hid) && 101785cdaf52SJiri Slaby (id->usage_type == HID_ANY_ID || 101885cdaf52SJiri Slaby id->usage_type == usage->type) && 101985cdaf52SJiri Slaby (id->usage_code == HID_ANY_ID || 102085cdaf52SJiri Slaby id->usage_code == usage->code)) 102185cdaf52SJiri Slaby return 1; 102285cdaf52SJiri Slaby return 0; 102385cdaf52SJiri Slaby } 102485cdaf52SJiri Slaby 102585cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field, 102685cdaf52SJiri Slaby struct hid_usage *usage, __s32 value, int interrupt) 102785cdaf52SJiri Slaby { 102885cdaf52SJiri Slaby struct hid_driver *hdrv = hid->driver; 102985cdaf52SJiri Slaby int ret; 103085cdaf52SJiri Slaby 10319bfc8da0SHenrik Rydberg if (!list_empty(&hid->debug_list)) 1032cd667ce2SJiri Kosina hid_dump_input(hid, usage, value); 103385cdaf52SJiri Slaby 103485cdaf52SJiri Slaby if (hdrv && hdrv->event && hid_match_usage(hid, usage)) { 103585cdaf52SJiri Slaby ret = hdrv->event(hid, field, usage, value); 103685cdaf52SJiri Slaby if (ret != 0) { 103785cdaf52SJiri Slaby if (ret < 0) 10388c3d52fcSJiri Kosina hid_err(hid, "%s's event failed with %d\n", 103985cdaf52SJiri Slaby hdrv->name, ret); 104085cdaf52SJiri Slaby return; 104185cdaf52SJiri Slaby } 104285cdaf52SJiri Slaby } 104385cdaf52SJiri Slaby 1044dde5845aSJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 1045dde5845aSJiri Kosina hidinput_hid_event(hid, field, usage, value); 1046aa938f79SJiri Kosina if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 1047aa938f79SJiri Kosina hid->hiddev_hid_event(hid, field, usage, value); 1048dde5845aSJiri Kosina } 1049dde5845aSJiri Kosina 1050dde5845aSJiri Kosina /* 1051dde5845aSJiri Kosina * Analyse a received field, and fetch the data from it. The field 1052dde5845aSJiri Kosina * content is stored for next report processing (we do differential 1053dde5845aSJiri Kosina * reporting to the layer). 1054dde5845aSJiri Kosina */ 1055dde5845aSJiri Kosina 1056abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field, 1057abdff0f7SAdrian Bunk __u8 *data, int interrupt) 1058dde5845aSJiri Kosina { 1059dde5845aSJiri Kosina unsigned n; 1060dde5845aSJiri Kosina unsigned count = field->report_count; 1061dde5845aSJiri Kosina unsigned offset = field->report_offset; 1062dde5845aSJiri Kosina unsigned size = field->report_size; 1063dde5845aSJiri Kosina __s32 min = field->logical_minimum; 1064dde5845aSJiri Kosina __s32 max = field->logical_maximum; 1065dde5845aSJiri Kosina __s32 *value; 1066dde5845aSJiri Kosina 1067a3789a17SJoe Perches value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC); 1068a3789a17SJoe Perches if (!value) 1069dde5845aSJiri Kosina return; 1070dde5845aSJiri Kosina 1071dde5845aSJiri Kosina for (n = 0; n < count; n++) { 1072dde5845aSJiri Kosina 10734291ee30SJoe Perches value[n] = min < 0 ? 10744291ee30SJoe Perches snto32(extract(hid, data, offset + n * size, size), 10754291ee30SJoe Perches size) : 10764291ee30SJoe Perches extract(hid, data, offset + n * size, size); 1077dde5845aSJiri Kosina 10784291ee30SJoe Perches /* Ignore report if ErrorRollOver */ 10794291ee30SJoe Perches if (!(field->flags & HID_MAIN_ITEM_VARIABLE) && 10804291ee30SJoe Perches value[n] >= min && value[n] <= max && 10814291ee30SJoe Perches field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) 1082dde5845aSJiri Kosina goto exit; 1083dde5845aSJiri Kosina } 1084dde5845aSJiri Kosina 1085dde5845aSJiri Kosina for (n = 0; n < count; n++) { 1086dde5845aSJiri Kosina 1087dde5845aSJiri Kosina if (HID_MAIN_ITEM_VARIABLE & field->flags) { 1088dde5845aSJiri Kosina hid_process_event(hid, field, &field->usage[n], value[n], interrupt); 1089dde5845aSJiri Kosina continue; 1090dde5845aSJiri Kosina } 1091dde5845aSJiri Kosina 1092dde5845aSJiri Kosina if (field->value[n] >= min && field->value[n] <= max 1093dde5845aSJiri Kosina && field->usage[field->value[n] - min].hid 1094dde5845aSJiri Kosina && search(value, field->value[n], count)) 1095dde5845aSJiri Kosina hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt); 1096dde5845aSJiri Kosina 1097dde5845aSJiri Kosina if (value[n] >= min && value[n] <= max 1098dde5845aSJiri Kosina && field->usage[value[n] - min].hid 1099dde5845aSJiri Kosina && search(field->value, value[n], count)) 1100dde5845aSJiri Kosina hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt); 1101dde5845aSJiri Kosina } 1102dde5845aSJiri Kosina 1103dde5845aSJiri Kosina memcpy(field->value, value, count * sizeof(__s32)); 1104dde5845aSJiri Kosina exit: 1105dde5845aSJiri Kosina kfree(value); 1106dde5845aSJiri Kosina } 1107dde5845aSJiri Kosina 1108dde5845aSJiri Kosina /* 1109dde5845aSJiri Kosina * Output the field into the report. 1110dde5845aSJiri Kosina */ 1111dde5845aSJiri Kosina 11124291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid, 11134291ee30SJoe Perches struct hid_field *field, __u8 *data) 1114dde5845aSJiri Kosina { 1115dde5845aSJiri Kosina unsigned count = field->report_count; 1116dde5845aSJiri Kosina unsigned offset = field->report_offset; 1117dde5845aSJiri Kosina unsigned size = field->report_size; 1118dde5845aSJiri Kosina unsigned n; 1119dde5845aSJiri Kosina 1120dde5845aSJiri Kosina for (n = 0; n < count; n++) { 1121dde5845aSJiri Kosina if (field->logical_minimum < 0) /* signed values */ 11224291ee30SJoe Perches implement(hid, data, offset + n * size, size, 11234291ee30SJoe Perches s32ton(field->value[n], size)); 1124dde5845aSJiri Kosina else /* unsigned values */ 11254291ee30SJoe Perches implement(hid, data, offset + n * size, size, 11264291ee30SJoe Perches field->value[n]); 1127dde5845aSJiri Kosina } 1128dde5845aSJiri Kosina } 1129dde5845aSJiri Kosina 1130dde5845aSJiri Kosina /* 113127ce4050SJiri Kosina * Create a report. 'data' has to be allocated using 113227ce4050SJiri Kosina * hid_alloc_report_buf() so that it has proper size. 1133dde5845aSJiri Kosina */ 1134dde5845aSJiri Kosina 1135229695e5SJiri Kosina void hid_output_report(struct hid_report *report, __u8 *data) 1136dde5845aSJiri Kosina { 1137dde5845aSJiri Kosina unsigned n; 1138dde5845aSJiri Kosina 1139dde5845aSJiri Kosina if (report->id > 0) 1140dde5845aSJiri Kosina *data++ = report->id; 1141dde5845aSJiri Kosina 114275c28df8SPete Zaitcev memset(data, 0, ((report->size - 1) >> 3) + 1); 1143dde5845aSJiri Kosina for (n = 0; n < report->maxfield; n++) 11444291ee30SJoe Perches hid_output_field(report->device, report->field[n], data); 1145dde5845aSJiri Kosina } 1146229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_output_report); 1147dde5845aSJiri Kosina 1148dde5845aSJiri Kosina /* 114927ce4050SJiri Kosina * Allocator for buffer that is going to be passed to hid_output_report() 115027ce4050SJiri Kosina */ 115127ce4050SJiri Kosina u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags) 115227ce4050SJiri Kosina { 115327ce4050SJiri Kosina /* 115427ce4050SJiri Kosina * 7 extra bytes are necessary to achieve proper functionality 115527ce4050SJiri Kosina * of implement() working on 8 byte chunks 115627ce4050SJiri Kosina */ 115727ce4050SJiri Kosina 115827ce4050SJiri Kosina int len = ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7; 115927ce4050SJiri Kosina 116027ce4050SJiri Kosina return kmalloc(len, flags); 116127ce4050SJiri Kosina } 116227ce4050SJiri Kosina EXPORT_SYMBOL_GPL(hid_alloc_report_buf); 116327ce4050SJiri Kosina 116427ce4050SJiri Kosina /* 1165dde5845aSJiri Kosina * Set a field value. The report this field belongs to has to be 1166dde5845aSJiri Kosina * created and transferred to the device, to set this value in the 1167dde5845aSJiri Kosina * device. 1168dde5845aSJiri Kosina */ 1169dde5845aSJiri Kosina 1170dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) 1171dde5845aSJiri Kosina { 1172*be67b68dSKees Cook unsigned size; 1173*be67b68dSKees Cook 1174*be67b68dSKees Cook if (!field) 1175*be67b68dSKees Cook return -1; 1176*be67b68dSKees Cook 1177*be67b68dSKees Cook size = field->report_size; 1178dde5845aSJiri Kosina 1179cd667ce2SJiri Kosina hid_dump_input(field->report->device, field->usage + offset, value); 1180dde5845aSJiri Kosina 1181dde5845aSJiri Kosina if (offset >= field->report_count) { 11828c3d52fcSJiri Kosina hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n", 11838c3d52fcSJiri Kosina offset, field->report_count); 1184dde5845aSJiri Kosina return -1; 1185dde5845aSJiri Kosina } 1186dde5845aSJiri Kosina if (field->logical_minimum < 0) { 1187dde5845aSJiri Kosina if (value != snto32(s32ton(value, size), size)) { 11888c3d52fcSJiri Kosina hid_err(field->report->device, "value %d is out of range\n", value); 1189dde5845aSJiri Kosina return -1; 1190dde5845aSJiri Kosina } 1191dde5845aSJiri Kosina } 1192dde5845aSJiri Kosina field->value[offset] = value; 1193dde5845aSJiri Kosina return 0; 1194dde5845aSJiri Kosina } 1195229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field); 1196dde5845aSJiri Kosina 119785cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, 119885cdaf52SJiri Slaby const u8 *data) 119985cdaf52SJiri Slaby { 120085cdaf52SJiri Slaby struct hid_report *report; 120185cdaf52SJiri Slaby unsigned int n = 0; /* Normally report number is 0 */ 120285cdaf52SJiri Slaby 120385cdaf52SJiri Slaby /* Device uses numbered reports, data[0] is report number */ 120485cdaf52SJiri Slaby if (report_enum->numbered) 120585cdaf52SJiri Slaby n = *data; 120685cdaf52SJiri Slaby 120785cdaf52SJiri Slaby report = report_enum->report_id_hash[n]; 120885cdaf52SJiri Slaby if (report == NULL) 120985cdaf52SJiri Slaby dbg_hid("undefined report_id %u received\n", n); 121085cdaf52SJiri Slaby 121185cdaf52SJiri Slaby return report; 121285cdaf52SJiri Slaby } 121385cdaf52SJiri Slaby 1214b6787242SJiri Kosina int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, 121585cdaf52SJiri Slaby int interrupt) 1216aa8de2f0SJiri Kosina { 1217aa8de2f0SJiri Kosina struct hid_report_enum *report_enum = hid->report_enum + type; 1218aa8de2f0SJiri Kosina struct hid_report *report; 12196d85d037SBenjamin Tissoires struct hid_driver *hdrv; 122085cdaf52SJiri Slaby unsigned int a; 122185cdaf52SJiri Slaby int rsize, csize = size; 122285cdaf52SJiri Slaby u8 *cdata = data; 1223b6787242SJiri Kosina int ret = 0; 1224aa8de2f0SJiri Kosina 122585cdaf52SJiri Slaby report = hid_get_report(report_enum, data); 122685cdaf52SJiri Slaby if (!report) 1227b6787242SJiri Kosina goto out; 1228aa8de2f0SJiri Kosina 122985cdaf52SJiri Slaby if (report_enum->numbered) { 123085cdaf52SJiri Slaby cdata++; 123185cdaf52SJiri Slaby csize--; 1232aa8de2f0SJiri Kosina } 1233aa8de2f0SJiri Kosina 1234aa8de2f0SJiri Kosina rsize = ((report->size - 1) >> 3) + 1; 1235aa8de2f0SJiri Kosina 1236966922f2SArmando Visconti if (rsize > HID_MAX_BUFFER_SIZE) 1237966922f2SArmando Visconti rsize = HID_MAX_BUFFER_SIZE; 1238966922f2SArmando Visconti 123985cdaf52SJiri Slaby if (csize < rsize) { 124085cdaf52SJiri Slaby dbg_hid("report %d is too short, (%d < %d)\n", report->id, 124185cdaf52SJiri Slaby csize, rsize); 124285cdaf52SJiri Slaby memset(cdata + csize, 0, rsize - csize); 1243aa8de2f0SJiri Kosina } 1244aa8de2f0SJiri Kosina 1245aa8de2f0SJiri Kosina if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) 1246aa8de2f0SJiri Kosina hid->hiddev_report_event(hid, report); 1247b6787242SJiri Kosina if (hid->claimed & HID_CLAIMED_HIDRAW) { 1248b6787242SJiri Kosina ret = hidraw_report_event(hid, data, size); 1249b6787242SJiri Kosina if (ret) 1250b6787242SJiri Kosina goto out; 1251b6787242SJiri Kosina } 1252aa8de2f0SJiri Kosina 1253b94e3c94SMatthieu CASTET if (hid->claimed != HID_CLAIMED_HIDRAW) { 125485cdaf52SJiri Slaby for (a = 0; a < report->maxfield; a++) 125585cdaf52SJiri Slaby hid_input_field(hid, report->field[a], cdata, interrupt); 12566d85d037SBenjamin Tissoires hdrv = hid->driver; 12576d85d037SBenjamin Tissoires if (hdrv && hdrv->report) 12586d85d037SBenjamin Tissoires hdrv->report(hid, report); 1259b94e3c94SMatthieu CASTET } 1260aa8de2f0SJiri Kosina 1261aa8de2f0SJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 1262aa8de2f0SJiri Kosina hidinput_report_event(hid, report); 1263b6787242SJiri Kosina out: 1264b6787242SJiri Kosina return ret; 126585cdaf52SJiri Slaby } 126685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event); 126785cdaf52SJiri Slaby 126885cdaf52SJiri Slaby /** 126985cdaf52SJiri Slaby * hid_input_report - report data from lower layer (usb, bt...) 127085cdaf52SJiri Slaby * 127185cdaf52SJiri Slaby * @hid: hid device 127285cdaf52SJiri Slaby * @type: HID report type (HID_*_REPORT) 127385cdaf52SJiri Slaby * @data: report contents 127485cdaf52SJiri Slaby * @size: size of data parameter 1275ff9b00a2SJiri Kosina * @interrupt: distinguish between interrupt and control transfers 127685cdaf52SJiri Slaby * 127785cdaf52SJiri Slaby * This is data entry for lower layers. 127885cdaf52SJiri Slaby */ 127985cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) 128085cdaf52SJiri Slaby { 128176c317d6SJulia Lawall struct hid_report_enum *report_enum; 128276c317d6SJulia Lawall struct hid_driver *hdrv; 128385cdaf52SJiri Slaby struct hid_report *report; 128445dc1ac7SJiri Kosina int ret = 0; 128585cdaf52SJiri Slaby 12864ea54542SDavid Herrmann if (!hid) 128785cdaf52SJiri Slaby return -ENODEV; 12884ea54542SDavid Herrmann 1289c849a614SAndrew de los Reyes if (down_trylock(&hid->driver_input_lock)) 12904ea54542SDavid Herrmann return -EBUSY; 12914ea54542SDavid Herrmann 12924ea54542SDavid Herrmann if (!hid->driver) { 12934ea54542SDavid Herrmann ret = -ENODEV; 12944ea54542SDavid Herrmann goto unlock; 12954ea54542SDavid Herrmann } 129676c317d6SJulia Lawall report_enum = hid->report_enum + type; 129776c317d6SJulia Lawall hdrv = hid->driver; 129885cdaf52SJiri Slaby 129985cdaf52SJiri Slaby if (!size) { 130085cdaf52SJiri Slaby dbg_hid("empty report\n"); 13014ea54542SDavid Herrmann ret = -1; 13024ea54542SDavid Herrmann goto unlock; 130385cdaf52SJiri Slaby } 130485cdaf52SJiri Slaby 1305b94e3c94SMatthieu CASTET /* Avoid unnecessary overhead if debugfs is disabled */ 1306a5f04b9dSBenjamin Tissoires if (!list_empty(&hid->debug_list)) 1307a5f04b9dSBenjamin Tissoires hid_dump_report(hid, type, data, size); 1308b94e3c94SMatthieu CASTET 1309f77e347bSJiri Kosina report = hid_get_report(report_enum, data); 1310f77e347bSJiri Kosina 13114ea54542SDavid Herrmann if (!report) { 13124ea54542SDavid Herrmann ret = -1; 13134ea54542SDavid Herrmann goto unlock; 13144ea54542SDavid Herrmann } 1315f77e347bSJiri Kosina 131685cdaf52SJiri Slaby if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { 131785cdaf52SJiri Slaby ret = hdrv->raw_event(hid, report, data, size); 1318b1a1442aSJiri Kosina if (ret < 0) { 13194ea54542SDavid Herrmann ret = ret < 0 ? ret : 0; 13204ea54542SDavid Herrmann goto unlock; 13214ea54542SDavid Herrmann } 132285cdaf52SJiri Slaby } 132385cdaf52SJiri Slaby 1324b6787242SJiri Kosina ret = hid_report_raw_event(hid, type, data, size, interrupt); 1325aa8de2f0SJiri Kosina 13264ea54542SDavid Herrmann unlock: 1327c849a614SAndrew de los Reyes up(&hid->driver_input_lock); 132845dc1ac7SJiri Kosina return ret; 1329aa8de2f0SJiri Kosina } 1330aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report); 1331aa8de2f0SJiri Kosina 13320f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev, 13330f37cd03SJiri Kosina const struct hid_device_id *id) 13340f37cd03SJiri Kosina { 13357431fb76SHenrik Rydberg return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) && 13364d53b801SHenrik Rydberg (id->group == HID_GROUP_ANY || id->group == hdev->group) && 13370f37cd03SJiri Kosina (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && 13380f37cd03SJiri Kosina (id->product == HID_ANY_ID || id->product == hdev->product); 13390f37cd03SJiri Kosina } 13400f37cd03SJiri Kosina 1341bbc21cfdSJeremy Fitzhardinge const struct hid_device_id *hid_match_id(struct hid_device *hdev, 13420f37cd03SJiri Kosina const struct hid_device_id *id) 13430f37cd03SJiri Kosina { 13440f37cd03SJiri Kosina for (; id->bus; id++) 13450f37cd03SJiri Kosina if (hid_match_one_id(hdev, id)) 13460f37cd03SJiri Kosina return id; 13470f37cd03SJiri Kosina 13480f37cd03SJiri Kosina return NULL; 13490f37cd03SJiri Kosina } 13500f37cd03SJiri Kosina 13510f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = { 1352c0bd6a42SRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) }, 1353c0bd6a42SRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) }, 13540f37cd03SJiri Kosina { } 13550f37cd03SJiri Kosina }; 13560f37cd03SJiri Kosina 13570f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev) 13580f37cd03SJiri Kosina { 13590f37cd03SJiri Kosina return !!hid_match_id(hdev, hid_hiddev_list); 13600f37cd03SJiri Kosina } 13610f37cd03SJiri Kosina 13626d3bfb74SAlan Ott 13636d3bfb74SAlan Ott static ssize_t 13646d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj, 13656d3bfb74SAlan Ott struct bin_attribute *attr, 13666d3bfb74SAlan Ott char *buf, loff_t off, size_t count) 13676d3bfb74SAlan Ott { 13686d3bfb74SAlan Ott struct device *dev = container_of(kobj, struct device, kobj); 13696d3bfb74SAlan Ott struct hid_device *hdev = container_of(dev, struct hid_device, dev); 13706d3bfb74SAlan Ott 13716d3bfb74SAlan Ott if (off >= hdev->rsize) 13726d3bfb74SAlan Ott return 0; 13736d3bfb74SAlan Ott 13746d3bfb74SAlan Ott if (off + count > hdev->rsize) 13756d3bfb74SAlan Ott count = hdev->rsize - off; 13766d3bfb74SAlan Ott 13776d3bfb74SAlan Ott memcpy(buf, hdev->rdesc + off, count); 13786d3bfb74SAlan Ott 13796d3bfb74SAlan Ott return count; 13806d3bfb74SAlan Ott } 13816d3bfb74SAlan Ott 13826d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = { 13836d3bfb74SAlan Ott .attr = { .name = "report_descriptor", .mode = 0444 }, 13846d3bfb74SAlan Ott .read = read_report_descriptor, 13856d3bfb74SAlan Ott .size = HID_MAX_DESCRIPTOR_SIZE, 13866d3bfb74SAlan Ott }; 13876d3bfb74SAlan Ott 138893c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 138993c10132SJiri Slaby { 139093c10132SJiri Slaby static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 139193c10132SJiri Slaby "Joystick", "Gamepad", "Keyboard", "Keypad", 139293c10132SJiri Slaby "Multi-Axis Controller" 139393c10132SJiri Slaby }; 139493c10132SJiri Slaby const char *type, *bus; 139593c10132SJiri Slaby char buf[64]; 139693c10132SJiri Slaby unsigned int i; 139793c10132SJiri Slaby int len; 13986d3bfb74SAlan Ott int ret; 139993c10132SJiri Slaby 1400b5e5a37eSBastien Nocera if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE) 1401b5e5a37eSBastien Nocera connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV); 14023a343ee4SDaniel Mack if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE) 14033a343ee4SDaniel Mack connect_mask |= HID_CONNECT_HIDINPUT_FORCE; 140493c10132SJiri Slaby if (hdev->bus != BUS_USB) 140593c10132SJiri Slaby connect_mask &= ~HID_CONNECT_HIDDEV; 14060f37cd03SJiri Kosina if (hid_hiddev(hdev)) 14070f37cd03SJiri Kosina connect_mask |= HID_CONNECT_HIDDEV_FORCE; 140893c10132SJiri Slaby 140993c10132SJiri Slaby if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, 141093c10132SJiri Slaby connect_mask & HID_CONNECT_HIDINPUT_FORCE)) 141193c10132SJiri Slaby hdev->claimed |= HID_CLAIMED_INPUT; 1412b77c3920SBenjamin Tissoires 141393c10132SJiri Slaby if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && 141493c10132SJiri Slaby !hdev->hiddev_connect(hdev, 141593c10132SJiri Slaby connect_mask & HID_CONNECT_HIDDEV_FORCE)) 141693c10132SJiri Slaby hdev->claimed |= HID_CLAIMED_HIDDEV; 141793c10132SJiri Slaby if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev)) 141893c10132SJiri Slaby hdev->claimed |= HID_CLAIMED_HIDRAW; 141993c10132SJiri Slaby 14204bc19f62SDavid Herrmann /* Drivers with the ->raw_event callback set are not required to connect 14214bc19f62SDavid Herrmann * to any other listener. */ 14224bc19f62SDavid Herrmann if (!hdev->claimed && !hdev->driver->raw_event) { 14234bc19f62SDavid Herrmann hid_err(hdev, "device has no listeners, quitting\n"); 142493c10132SJiri Slaby return -ENODEV; 142593c10132SJiri Slaby } 142693c10132SJiri Slaby 142793c10132SJiri Slaby if ((hdev->claimed & HID_CLAIMED_INPUT) && 142893c10132SJiri Slaby (connect_mask & HID_CONNECT_FF) && hdev->ff_init) 142993c10132SJiri Slaby hdev->ff_init(hdev); 143093c10132SJiri Slaby 143193c10132SJiri Slaby len = 0; 143293c10132SJiri Slaby if (hdev->claimed & HID_CLAIMED_INPUT) 143393c10132SJiri Slaby len += sprintf(buf + len, "input"); 143493c10132SJiri Slaby if (hdev->claimed & HID_CLAIMED_HIDDEV) 143593c10132SJiri Slaby len += sprintf(buf + len, "%shiddev%d", len ? "," : "", 143693c10132SJiri Slaby hdev->minor); 143793c10132SJiri Slaby if (hdev->claimed & HID_CLAIMED_HIDRAW) 143893c10132SJiri Slaby len += sprintf(buf + len, "%shidraw%d", len ? "," : "", 143993c10132SJiri Slaby ((struct hidraw *)hdev->hidraw)->minor); 144093c10132SJiri Slaby 144193c10132SJiri Slaby type = "Device"; 144293c10132SJiri Slaby for (i = 0; i < hdev->maxcollection; i++) { 144393c10132SJiri Slaby struct hid_collection *col = &hdev->collection[i]; 144493c10132SJiri Slaby if (col->type == HID_COLLECTION_APPLICATION && 144593c10132SJiri Slaby (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK && 144693c10132SJiri Slaby (col->usage & 0xffff) < ARRAY_SIZE(types)) { 144793c10132SJiri Slaby type = types[col->usage & 0xffff]; 144893c10132SJiri Slaby break; 144993c10132SJiri Slaby } 145093c10132SJiri Slaby } 145193c10132SJiri Slaby 145293c10132SJiri Slaby switch (hdev->bus) { 145393c10132SJiri Slaby case BUS_USB: 145493c10132SJiri Slaby bus = "USB"; 145593c10132SJiri Slaby break; 145693c10132SJiri Slaby case BUS_BLUETOOTH: 145793c10132SJiri Slaby bus = "BLUETOOTH"; 145893c10132SJiri Slaby break; 145993c10132SJiri Slaby default: 146093c10132SJiri Slaby bus = "<UNKNOWN>"; 146193c10132SJiri Slaby } 146293c10132SJiri Slaby 14636d3bfb74SAlan Ott ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 14646d3bfb74SAlan Ott if (ret) 14656d3bfb74SAlan Ott hid_warn(hdev, 14666d3bfb74SAlan Ott "can't create sysfs report descriptor attribute err: %d\n", ret); 14676d3bfb74SAlan Ott 14684291ee30SJoe Perches hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 146993c10132SJiri Slaby buf, bus, hdev->version >> 8, hdev->version & 0xff, 147093c10132SJiri Slaby type, hdev->name, hdev->phys); 147193c10132SJiri Slaby 147293c10132SJiri Slaby return 0; 147393c10132SJiri Slaby } 147493c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect); 147593c10132SJiri Slaby 1476c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev) 1477c4c259bcSJiri Kosina { 14786d3bfb74SAlan Ott device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1479c4c259bcSJiri Kosina if (hdev->claimed & HID_CLAIMED_INPUT) 1480c4c259bcSJiri Kosina hidinput_disconnect(hdev); 1481c4c259bcSJiri Kosina if (hdev->claimed & HID_CLAIMED_HIDDEV) 1482c4c259bcSJiri Kosina hdev->hiddev_disconnect(hdev); 1483c4c259bcSJiri Kosina if (hdev->claimed & HID_CLAIMED_HIDRAW) 1484c4c259bcSJiri Kosina hidraw_disconnect(hdev); 1485c4c259bcSJiri Kosina } 1486c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect); 1487c4c259bcSJiri Kosina 148800315e4fSJiri Kosina /* 148900315e4fSJiri Kosina * A list of devices for which there is a specialized driver on HID bus. 149000315e4fSJiri Kosina * 149100315e4fSJiri Kosina * Please note that for multitouch devices (driven by hid-multitouch driver), 149200315e4fSJiri Kosina * there is a proper autodetection and autoloading in place (based on presence 149300315e4fSJiri Kosina * of HID_DG_CONTACTID), so those devices don't need to be added to this list, 149400315e4fSJiri Kosina * as we are doing the right thing in hid_scan_usage(). 149583499b52SAlexander Holler * 149683499b52SAlexander Holler * Autodetection for (USB) HID sensor hubs exists too. If a collection of type 149783499b52SAlexander Holler * physical is found inside a usage page of type sensor, hid-sensor-hub will be 149883499b52SAlexander Holler * used as a driver. See hid_scan_report(). 149900315e4fSJiri Kosina */ 1500ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = { 150114a21cd4SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 150214a21cd4SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1503b7e1b203SLech Perczak { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) }, 1504c0dbcc33SSergei Kolzun { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) }, 15058c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, 1506128537ceSMichael Poole { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) }, 1507a462230eSChase Douglas { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) }, 15088c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 15098c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 15108c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 15118c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 15128c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 15138c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 15148c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 15158c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 15168c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 15178c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 15188c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 1519fef3f571SRyan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) }, 1520fef3f571SRyan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) }, 1521fef3f571SRyan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) }, 15228c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) }, 15238c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) }, 15248c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) }, 15258c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 15268c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 15278c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 15289a4a5574SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) }, 15299a4a5574SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) }, 15309a4a5574SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL3) }, 15319a4a5574SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, 15329a4a5574SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) }, 1533ee8a1a0aSJan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) }, 1534ee8a1a0aSJan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) }, 1535ee8a1a0aSJan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) }, 15368c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 15378c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 15388c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 15398c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 15408c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 15418c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 1542a96d6ef3SHenrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1543a96d6ef3SHenrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1544a96d6ef3SHenrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 154599b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) }, 154699b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) }, 154799b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) }, 154899b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 154999b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 155099b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 155147340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 155247340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 155347340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 1554213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) }, 1555213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) }, 1556213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) }, 15574a4c8799SDan Bastone { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) }, 15584a4c8799SDan Bastone { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) }, 15594a4c8799SDan Bastone { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) }, 1560f6f554f0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) }, 1561f6f554f0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) }, 1562f6f554f0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) }, 1563d762cc29SNobuhiro Iwamatsu { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) }, 1564d762cc29SNobuhiro Iwamatsu { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) }, 1565d762cc29SNobuhiro Iwamatsu { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) }, 1566b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) }, 1567b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) }, 1568b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) }, 15698d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) }, 15708d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) }, 15718d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) }, 15729d9a04eeSDmitry Torokhov { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) }, 15739d9a04eeSDmitry Torokhov { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) }, 15749d9a04eeSDmitry Torokhov { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) }, 157523aeb61eSChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 157623aeb61eSChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 157723aeb61eSChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1578f9af7b9eSBen Hutchings { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) }, 1579ad734bc1SAndreas Krist { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) }, 15808c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 15818c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1582212da74dSJosenivaldo Benito Junior { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) }, 1583b5635b12SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, 1584bf280628SWayne Thomas { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 1585c3dc66deSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) }, 15863b239cd7SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 15871ce31b25SRaphaël Doursenaud { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) }, 1588fcfacfd3SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 1589b9e4b1e0SDennis Kügler { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) }, 15903596bb92SKeng-Yu Lin { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, 15912d8767bbSCyrus Lien { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, 15923a370ca1SDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, 15930f221320SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, 15940f221320SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, 1595e8d0eab4SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, 159676c9d8feSLionel Vaux { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) }, 15970f221320SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, 15983f866fbdSRichard Walmsley { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, 1599e05eefb9SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) }, 160064b386eaSRichard Nauber { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, 1601d23efc19SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) }, 1602d23efc19SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) }, 160304561c5aSIgnaz Forster { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) }, 16041f243e30SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, 16055181e594SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, 1606578f3a35SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, 16075181e594SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, 160842859e0bSLukasz Lubojanski { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, 1609949f8fefSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, 16101e093206SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, 1611c2fd1a4eSCory Maccarrone { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, 1612d946e65eSAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) }, 1613ff9bf5a2STom Harwood { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) }, 161440d3597fSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) }, 161540d3597fSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) }, 161668e353feSMartin Rusko { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_580) }, 1617aaca9cc0SMichael Karcher { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) }, 16184ddfe028SBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) }, 1619fdf93aa3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, 1620177900e8SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) }, 16213685c18eSBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) }, 16220adb9c2cSBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) }, 162379422741SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 162422ca20b2SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) }, 162522ca20b2SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) }, 162622ca20b2SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) }, 1627b5635b12SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 162875b07022SChris Schlund { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, 1629aad932e7SAndres Freund #if IS_ENABLED(CONFIG_HID_LENOVO_TPKBD) 1630c1dcad2dSBernhard Seibold { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) }, 1631aad932e7SAndres Freund #endif 16325f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, 16335f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, 16345f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, 16355f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, 16365844c1cdSDavid Dillow { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) }, 16375f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, 16385f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, 16395f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, 16405f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) }, 16415f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) }, 16425f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) }, 16435f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) }, 16442c6118e4SHendrik Iben { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) }, 1645606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, 1646606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, 1647606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, 1648fd30ea8cSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) }, 1649606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, 165074f292caSGary Stein { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) }, 1651606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, 1652606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, 16535623a24aSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) }, 1654e00ddc9bSMichal Malý { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) }, 1655243b706dSChristophe Borivant { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, 1656fdc6807fSPeter Gundermann { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) }, 16570944e964SKonstantin Khlebnikov #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ) 1658534a7b8eSNestor Lopez Casado { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) }, 1659534a7b8eSNestor Lopez Casado { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) }, 16600944e964SKonstantin Khlebnikov #endif 166132c88cbcSSimon Wood { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) }, 1662606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, 166324985cf6SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, 166424985cf6SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) }, 1665236db47cSBruno Prémont { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) }, 1666236db47cSBruno Prémont { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) }, 1667b580169aSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) }, 166878a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) }, 166978a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) }, 167089759e20SAdam Jiang { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) }, 167178a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) }, 167278a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, 1673f3b83d71SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) }, 167478a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 16753b8006e5SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, 167694011f93SRafi Rubin { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, 16776e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) }, 16786e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) }, 16796e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) }, 16806e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) }, 16816e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) }, 16826e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) }, 16836e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) }, 16846e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) }, 16856e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) }, 16866e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) }, 16876e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) }, 16886e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) }, 16896e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) }, 16906e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) }, 16916e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) }, 16926e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) }, 16936e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) }, 16946e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) }, 1695270fdc07SHerton Ronaldo Krzesinski { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) }, 1696cd9ec30dSJohnathon Harris { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) }, 16971e762532SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 1698f6a04605STerry Lambert { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) }, 1699ca9bbdccSStefan Achatz #if IS_ENABLED(CONFIG_HID_ROCCAT) 170014bf62cdSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, 1701e68cc603SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) }, 1702d41c2a70SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) }, 170347dbdbffSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, 17048936aa31SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) }, 1705a4be0ed3SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) }, 17060e70f97fSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) }, 17074424f616SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) }, 1708cb7cf3daSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 17093fce2246SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) }, 17106a2a6390SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) }, 1711ca9bbdccSStefan Achatz #endif 17121e93674aSAndreas Hübner { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) }, 1713980a3da6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1714b355850bSDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, 1715d586dca0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) }, 1716f04d5140SColin Leitner { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) }, 1717f04d5140SColin Leitner { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) }, 17185844c1cdSDavid Dillow { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) }, 1719bd28ce00SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 172035dca5b4SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) }, 1721f9ce7c28SBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1722cc6e0bbbSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, 1723c1e0ac19SFernando Luis Vázquez Cao { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) }, 172475dbb953SSimon Wood { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) }, 172590231e7eSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, 172630ba2fbdSVivien Didelot { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) }, 1727daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, 1728daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, 17297a84b133SRuben Aos Garralda { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) }, 17307a84b133SRuben Aos Garralda { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) }, 1731daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, 17323ee8f0a2SMarkus Rathgeb { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) }, 1733daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, 1734d65c3768SSimon Wood { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) }, 1735740363fbSJiri Kosina { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) }, 173644ea35c1SJarod Wilson { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) }, 1737f14f526dSLev Babiev { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 173854001081SKees Bakker { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 1739711a680eSBruno Premont { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, 174041fa9230SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, 1741f8a489ccSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) }, 1742f8a489ccSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) }, 1743f8a489ccSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) }, 17446be914f1SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) }, 1745d1257081SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, 1746eb4e426aSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) }, 1747fac733f0SJussi Kivilinna { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, 174842fc04e5SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) }, 1749ad395ccaSSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) }, 17501bcc2067SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) }, 17511bcc2067SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) }, 17521bcc2067SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) }, 1753ca2dcd40SBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 175478761ff9SPrzemo Firszt { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, 175572a46344SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) }, 175600e7f964SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) }, 17574fdc18d1SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) }, 1758a786e83cSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) }, 175972a46344SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) }, 17608f1acc32SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, 1761d2ee4dd9SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) }, 176274bc6953SStefan Kriwanek { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) }, 1763cb2c9e3fSOlivier Scherler { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) }, 1764daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, 1765daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, 1766a9885c8fSDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) }, 17678c19a515SJiri Slaby 176878a849a6SJiri Slaby { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, 176902fb72a0SDavid Herrmann { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) }, 1770a33042faSDavid Herrmann { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) }, 177185cdaf52SJiri Slaby { } 177285cdaf52SJiri Slaby }; 177385cdaf52SJiri Slaby 17743a6f82f7SJiri Slaby struct hid_dynid { 17753a6f82f7SJiri Slaby struct list_head list; 17763a6f82f7SJiri Slaby struct hid_device_id id; 17773a6f82f7SJiri Slaby }; 17783a6f82f7SJiri Slaby 17793a6f82f7SJiri Slaby /** 17803a6f82f7SJiri Slaby * store_new_id - add a new HID device ID to this driver and re-probe devices 17813a6f82f7SJiri Slaby * @driver: target device driver 17823a6f82f7SJiri Slaby * @buf: buffer for scanning device ID data 17833a6f82f7SJiri Slaby * @count: input size 17843a6f82f7SJiri Slaby * 17853a6f82f7SJiri Slaby * Adds a new dynamic hid device ID to this driver, 17863a6f82f7SJiri Slaby * and causes the driver to probe for all devices again. 17873a6f82f7SJiri Slaby */ 17883a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf, 17893a6f82f7SJiri Slaby size_t count) 17903a6f82f7SJiri Slaby { 17913a6f82f7SJiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 17923a6f82f7SJiri Slaby struct hid_dynid *dynid; 17933a6f82f7SJiri Slaby __u32 bus, vendor, product; 17943a6f82f7SJiri Slaby unsigned long driver_data = 0; 17953a6f82f7SJiri Slaby int ret; 17963a6f82f7SJiri Slaby 17973a6f82f7SJiri Slaby ret = sscanf(buf, "%x %x %x %lx", 17983a6f82f7SJiri Slaby &bus, &vendor, &product, &driver_data); 17993a6f82f7SJiri Slaby if (ret < 3) 18003a6f82f7SJiri Slaby return -EINVAL; 18013a6f82f7SJiri Slaby 18023a6f82f7SJiri Slaby dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); 18033a6f82f7SJiri Slaby if (!dynid) 18043a6f82f7SJiri Slaby return -ENOMEM; 18053a6f82f7SJiri Slaby 18063a6f82f7SJiri Slaby dynid->id.bus = bus; 18074d53b801SHenrik Rydberg dynid->id.group = HID_GROUP_ANY; 18083a6f82f7SJiri Slaby dynid->id.vendor = vendor; 18093a6f82f7SJiri Slaby dynid->id.product = product; 18103a6f82f7SJiri Slaby dynid->id.driver_data = driver_data; 18113a6f82f7SJiri Slaby 18123a6f82f7SJiri Slaby spin_lock(&hdrv->dyn_lock); 18133a6f82f7SJiri Slaby list_add_tail(&dynid->list, &hdrv->dyn_list); 18143a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 18153a6f82f7SJiri Slaby 18163a6f82f7SJiri Slaby ret = driver_attach(&hdrv->driver); 18173a6f82f7SJiri Slaby 18183a6f82f7SJiri Slaby return ret ? : count; 18193a6f82f7SJiri Slaby } 18203a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 18213a6f82f7SJiri Slaby 18223a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv) 18233a6f82f7SJiri Slaby { 18243a6f82f7SJiri Slaby struct hid_dynid *dynid, *n; 18253a6f82f7SJiri Slaby 18263a6f82f7SJiri Slaby spin_lock(&hdrv->dyn_lock); 18273a6f82f7SJiri Slaby list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) { 18283a6f82f7SJiri Slaby list_del(&dynid->list); 18293a6f82f7SJiri Slaby kfree(dynid); 18303a6f82f7SJiri Slaby } 18313a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 18323a6f82f7SJiri Slaby } 18333a6f82f7SJiri Slaby 18343a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev, 18353a6f82f7SJiri Slaby struct hid_driver *hdrv) 18363a6f82f7SJiri Slaby { 18373a6f82f7SJiri Slaby struct hid_dynid *dynid; 18383a6f82f7SJiri Slaby 18393a6f82f7SJiri Slaby spin_lock(&hdrv->dyn_lock); 18403a6f82f7SJiri Slaby list_for_each_entry(dynid, &hdrv->dyn_list, list) { 18413a6f82f7SJiri Slaby if (hid_match_one_id(hdev, &dynid->id)) { 18423a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 18433a6f82f7SJiri Slaby return &dynid->id; 18443a6f82f7SJiri Slaby } 18453a6f82f7SJiri Slaby } 18463a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 18473a6f82f7SJiri Slaby 18483a6f82f7SJiri Slaby return hid_match_id(hdev, hdrv->id_table); 18493a6f82f7SJiri Slaby } 18503a6f82f7SJiri Slaby 185185cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv) 185285cdaf52SJiri Slaby { 185385cdaf52SJiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 185485cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 185585cdaf52SJiri Slaby 1856070748edSHenrik Rydberg return hid_match_device(hdev, hdrv) != NULL; 185785cdaf52SJiri Slaby } 185885cdaf52SJiri Slaby 185985cdaf52SJiri Slaby static int hid_device_probe(struct device *dev) 186085cdaf52SJiri Slaby { 186185cdaf52SJiri Slaby struct hid_driver *hdrv = container_of(dev->driver, 186285cdaf52SJiri Slaby struct hid_driver, driver); 186385cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 186485cdaf52SJiri Slaby const struct hid_device_id *id; 186585cdaf52SJiri Slaby int ret = 0; 186685cdaf52SJiri Slaby 18674ea54542SDavid Herrmann if (down_interruptible(&hdev->driver_lock)) 18684ea54542SDavid Herrmann return -EINTR; 1869c849a614SAndrew de los Reyes if (down_interruptible(&hdev->driver_input_lock)) { 1870c849a614SAndrew de los Reyes ret = -EINTR; 1871c849a614SAndrew de los Reyes goto unlock_driver_lock; 1872c849a614SAndrew de los Reyes } 1873c849a614SAndrew de los Reyes hdev->io_started = false; 18744ea54542SDavid Herrmann 187585cdaf52SJiri Slaby if (!hdev->driver) { 18763a6f82f7SJiri Slaby id = hid_match_device(hdev, hdrv); 1877ba623a77SDan Carpenter if (id == NULL) { 1878ba623a77SDan Carpenter ret = -ENODEV; 1879ba623a77SDan Carpenter goto unlock; 1880ba623a77SDan Carpenter } 1881c500c971SJiri Slaby 188285cdaf52SJiri Slaby hdev->driver = hdrv; 1883c500c971SJiri Slaby if (hdrv->probe) { 1884c500c971SJiri Slaby ret = hdrv->probe(hdev, id); 1885c500c971SJiri Slaby } else { /* default probe */ 1886a7197c2eSHenrik Rydberg ret = hid_open_report(hdev); 1887c500c971SJiri Slaby if (!ret) 188893c10132SJiri Slaby ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 1889c500c971SJiri Slaby } 1890a7197c2eSHenrik Rydberg if (ret) { 1891a7197c2eSHenrik Rydberg hid_close_report(hdev); 1892c500c971SJiri Slaby hdev->driver = NULL; 189385cdaf52SJiri Slaby } 1894a7197c2eSHenrik Rydberg } 1895ba623a77SDan Carpenter unlock: 1896c849a614SAndrew de los Reyes if (!hdev->io_started) 1897c849a614SAndrew de los Reyes up(&hdev->driver_input_lock); 1898c849a614SAndrew de los Reyes unlock_driver_lock: 18994ea54542SDavid Herrmann up(&hdev->driver_lock); 190085cdaf52SJiri Slaby return ret; 190185cdaf52SJiri Slaby } 190285cdaf52SJiri Slaby 190385cdaf52SJiri Slaby static int hid_device_remove(struct device *dev) 190485cdaf52SJiri Slaby { 190585cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 19064ea54542SDavid Herrmann struct hid_driver *hdrv; 1907c849a614SAndrew de los Reyes int ret = 0; 190885cdaf52SJiri Slaby 19094ea54542SDavid Herrmann if (down_interruptible(&hdev->driver_lock)) 19104ea54542SDavid Herrmann return -EINTR; 1911c849a614SAndrew de los Reyes if (down_interruptible(&hdev->driver_input_lock)) { 1912c849a614SAndrew de los Reyes ret = -EINTR; 1913c849a614SAndrew de los Reyes goto unlock_driver_lock; 1914c849a614SAndrew de los Reyes } 1915c849a614SAndrew de los Reyes hdev->io_started = false; 19164ea54542SDavid Herrmann 19174ea54542SDavid Herrmann hdrv = hdev->driver; 191885cdaf52SJiri Slaby if (hdrv) { 191985cdaf52SJiri Slaby if (hdrv->remove) 192085cdaf52SJiri Slaby hdrv->remove(hdev); 1921c500c971SJiri Slaby else /* default remove */ 1922c500c971SJiri Slaby hid_hw_stop(hdev); 1923a7197c2eSHenrik Rydberg hid_close_report(hdev); 192485cdaf52SJiri Slaby hdev->driver = NULL; 192585cdaf52SJiri Slaby } 192685cdaf52SJiri Slaby 1927c849a614SAndrew de los Reyes if (!hdev->io_started) 1928c849a614SAndrew de los Reyes up(&hdev->driver_input_lock); 1929c849a614SAndrew de los Reyes unlock_driver_lock: 19304ea54542SDavid Herrmann up(&hdev->driver_lock); 1931c849a614SAndrew de los Reyes return ret; 193285cdaf52SJiri Slaby } 193385cdaf52SJiri Slaby 19344d53b801SHenrik Rydberg static ssize_t modalias_show(struct device *dev, struct device_attribute *a, 19354d53b801SHenrik Rydberg char *buf) 19364d53b801SHenrik Rydberg { 19374d53b801SHenrik Rydberg struct hid_device *hdev = container_of(dev, struct hid_device, dev); 19384d53b801SHenrik Rydberg int len; 19394d53b801SHenrik Rydberg 19404d53b801SHenrik Rydberg len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n", 19414d53b801SHenrik Rydberg hdev->bus, hdev->group, hdev->vendor, hdev->product); 19424d53b801SHenrik Rydberg 19434d53b801SHenrik Rydberg return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; 19444d53b801SHenrik Rydberg } 19454d53b801SHenrik Rydberg 19464d53b801SHenrik Rydberg static struct device_attribute hid_dev_attrs[] = { 19474d53b801SHenrik Rydberg __ATTR_RO(modalias), 19484d53b801SHenrik Rydberg __ATTR_NULL, 19494d53b801SHenrik Rydberg }; 19504d53b801SHenrik Rydberg 195185cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) 195285cdaf52SJiri Slaby { 195385cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 195485cdaf52SJiri Slaby 195585cdaf52SJiri Slaby if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", 195685cdaf52SJiri Slaby hdev->bus, hdev->vendor, hdev->product)) 195785cdaf52SJiri Slaby return -ENOMEM; 195885cdaf52SJiri Slaby 195985cdaf52SJiri Slaby if (add_uevent_var(env, "HID_NAME=%s", hdev->name)) 196085cdaf52SJiri Slaby return -ENOMEM; 196185cdaf52SJiri Slaby 196285cdaf52SJiri Slaby if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys)) 196385cdaf52SJiri Slaby return -ENOMEM; 196485cdaf52SJiri Slaby 196585cdaf52SJiri Slaby if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq)) 196685cdaf52SJiri Slaby return -ENOMEM; 196785cdaf52SJiri Slaby 19684d53b801SHenrik Rydberg if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X", 19694d53b801SHenrik Rydberg hdev->bus, hdev->group, hdev->vendor, hdev->product)) 197085cdaf52SJiri Slaby return -ENOMEM; 197185cdaf52SJiri Slaby 197285cdaf52SJiri Slaby return 0; 197385cdaf52SJiri Slaby } 197485cdaf52SJiri Slaby 197585cdaf52SJiri Slaby static struct bus_type hid_bus_type = { 197685cdaf52SJiri Slaby .name = "hid", 19774d53b801SHenrik Rydberg .dev_attrs = hid_dev_attrs, 197885cdaf52SJiri Slaby .match = hid_bus_match, 197985cdaf52SJiri Slaby .probe = hid_device_probe, 198085cdaf52SJiri Slaby .remove = hid_device_remove, 198185cdaf52SJiri Slaby .uevent = hid_uevent, 198285cdaf52SJiri Slaby }; 198385cdaf52SJiri Slaby 1984bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */ 1985d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = { 1986d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) }, 1987d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) }, 1988d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) }, 1989d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) }, 1990d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) }, 1991d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) }, 1992d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) }, 1993d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) }, 1994d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) }, 1995d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, 1996d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, 1997d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, 199877f720b7SStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)}, 199977f720b7SStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)}, 200062a56582SAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, 200111030183SHans de Goede { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) }, 2002d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, 2003d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, 2004d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, 2005d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) }, 2006d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) }, 2007d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) }, 20085f6108cfSAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) }, 2009d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, 2010d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, 201173bc7d31SMelchior FRANZ { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) }, 2012789aaa2eSDan Delaney { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) }, 2013d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, 201470c66567SPetr Štetiar { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) }, 2015df506f2cSPetr Štetiar { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) }, 2016b1807719SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) }, 2017d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, 2018d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, 2019d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, 2020d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, 2021d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) }, 2022d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) }, 2023d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) }, 2024d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) }, 2025d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) }, 2026d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) }, 2027d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) }, 2028d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) }, 2029d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) }, 2030d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) }, 2031d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) }, 2032d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) }, 20338e2ce73eSHans de Goede { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) }, 2034d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) }, 2035d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) }, 2036d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) }, 2037d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) }, 2038d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) }, 2039d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) }, 2040d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) }, 2041d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) }, 2042d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) }, 2043d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) }, 2044d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) }, 2045d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) }, 2046d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) }, 2047d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) }, 2048d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) }, 2049d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) }, 2050d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) }, 2051d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) }, 2052d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) }, 2053d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) }, 2054d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) }, 2055d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) }, 2056d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) }, 2057d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) }, 2058d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) }, 2059d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) }, 2060d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) }, 2061d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) }, 2062d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) }, 2063d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) }, 2064d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) }, 2065d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) }, 2066d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) }, 2067d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) }, 2068d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) }, 2069d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) }, 2070d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) }, 2071d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) }, 2072d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) }, 2073d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) }, 2074d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) }, 2075d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) }, 2076d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) }, 2077d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) }, 2078d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) }, 2079d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) }, 2080d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) }, 208131b9779cSVincent Palatin { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_410) }, 208231b9779cSVincent Palatin { HID_USB_DEVICE(USB_VENDOR_ID_JABRA, USB_DEVICE_ID_JABRA_SPEAK_510) }, 2083d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) }, 2084c91c21c5SAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) }, 2085d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) }, 2086eb8141ccSLamarque Vieira Souza { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) }, 2087d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, 2088ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) }, 2089d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, 2090ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) }, 2091d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, 2092ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) }, 2093ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) }, 2094ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) }, 2095ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) }, 2096ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) }, 2097ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) }, 2098d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 2099d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 2100d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 2101ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) }, 2102ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) }, 2103ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) }, 2104d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, 2105d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, 2106ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) }, 2107d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, 2108d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, 2109d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, 2110d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, 2111d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, 2112ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) }, 2113ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) }, 2114ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) }, 2115ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) }, 2116ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) }, 2117ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) }, 2118ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) }, 21193ffb62cbSYuri Khan { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) }, 2120d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, 2121d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, 2122d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, 2123d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) }, 2124d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) }, 2125d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) }, 2126d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) }, 2127d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) }, 2128d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) }, 2129d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) }, 2130d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) }, 2131d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) }, 2132d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) }, 2133d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) }, 2134d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) }, 2135d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) }, 2136d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) }, 2137d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) }, 2138d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, 21394cfae3e8SHenning Glawe { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) }, 214035cfd1d9SMichael Tokarev { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, 21418491ee10SJan Steinhoff #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE) 21428491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) }, 21438491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) }, 21448491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) }, 21458491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) }, 21468491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) }, 21478491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) }, 21488491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) }, 21498491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) }, 21508491ee10SJan Steinhoff #endif 2151d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, 2152d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, 2153d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, 2154d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, 2155d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) }, 2156d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) }, 2157d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) }, 2158d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) }, 2159d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) }, 2160d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, 2161d458a9dfSJiri Slaby { } 2162d458a9dfSJiri Slaby }; 2163d458a9dfSJiri Slaby 2164b4d8e473SJiri Slaby /** 2165b4d8e473SJiri Slaby * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer 2166b4d8e473SJiri Slaby * 2167b4d8e473SJiri Slaby * There are composite devices for which we want to ignore only a certain 2168b4d8e473SJiri Slaby * interface. This is a list of devices for which only the mouse interface will 2169b4d8e473SJiri Slaby * be ignored. This allows a dedicated driver to take care of the interface. 2170b4d8e473SJiri Slaby */ 2171b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = { 2172b4d8e473SJiri Slaby /* appletouch driver */ 2173b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 2174b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 2175b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 2176b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 2177b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 2178b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 2179b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 2180b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 2181b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 2182b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 2183b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 2184b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 2185b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 2186b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 2187b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 2188b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 2189b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 2190b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 2191b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 2192b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 2193ac26fca3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 2194ac26fca3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 2195ac26fca3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 219699b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) }, 219799b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) }, 219899b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) }, 219999b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 220099b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 220199b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 220247340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 220347340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 220447340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 2205213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) }, 2206213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) }, 2207213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) }, 22084b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) }, 22094b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) }, 22104b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) }, 22114b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) }, 22124b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) }, 22134b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) }, 2214b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) }, 2215b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) }, 2216b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) }, 22178d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) }, 22188d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) }, 22198d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) }, 22209d9a04eeSDmitry Torokhov { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI) }, 22219d9a04eeSDmitry Torokhov { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO) }, 22229d9a04eeSDmitry Torokhov { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS) }, 2223b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 2224b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 2225b4d8e473SJiri Slaby { } 2226b4d8e473SJiri Slaby }; 2227b4d8e473SJiri Slaby 22284529eefaSLamarque V. Souza bool hid_ignore(struct hid_device *hdev) 2229d458a9dfSJiri Slaby { 22304529eefaSLamarque V. Souza if (hdev->quirks & HID_QUIRK_NO_IGNORE) 22314529eefaSLamarque V. Souza return false; 22324529eefaSLamarque V. Souza if (hdev->quirks & HID_QUIRK_IGNORE) 22334529eefaSLamarque V. Souza return true; 22344529eefaSLamarque V. Souza 2235d458a9dfSJiri Slaby switch (hdev->vendor) { 2236d458a9dfSJiri Slaby case USB_VENDOR_ID_CODEMERCS: 2237d458a9dfSJiri Slaby /* ignore all Code Mercenaries IOWarrior devices */ 2238d458a9dfSJiri Slaby if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && 2239d458a9dfSJiri Slaby hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) 2240d458a9dfSJiri Slaby return true; 2241d458a9dfSJiri Slaby break; 2242d458a9dfSJiri Slaby case USB_VENDOR_ID_LOGITECH: 2243d458a9dfSJiri Slaby if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST && 2244d458a9dfSJiri Slaby hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST) 2245d458a9dfSJiri Slaby return true; 224665dd3b69SHans Verkuil /* 224765dd3b69SHans Verkuil * The Keene FM transmitter USB device has the same USB ID as 224865dd3b69SHans Verkuil * the Logitech AudioHub Speaker, but it should ignore the hid. 224965dd3b69SHans Verkuil * Check if the name is that of the Keene device. 225065dd3b69SHans Verkuil * For reference: the name of the AudioHub is 225165dd3b69SHans Verkuil * "HOLTEK AudioHub Speaker". 225265dd3b69SHans Verkuil */ 225365dd3b69SHans Verkuil if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB && 225465dd3b69SHans Verkuil !strcmp(hdev->name, "HOLTEK B-LINK USB Audio ")) 225565dd3b69SHans Verkuil return true; 2256d458a9dfSJiri Slaby break; 225731f7fd79SJarod Wilson case USB_VENDOR_ID_SOUNDGRAPH: 225831f7fd79SJarod Wilson if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST && 225931f7fd79SJarod Wilson hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST) 226031f7fd79SJarod Wilson return true; 226131f7fd79SJarod Wilson break; 2262bba5394aSXing Wei case USB_VENDOR_ID_HANWANG: 2263bba5394aSXing Wei if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST && 2264bba5394aSXing Wei hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST) 2265bba5394aSXing Wei return true; 2266bba5394aSXing Wei break; 22676dc1418eSTomoki Sekiyama case USB_VENDOR_ID_JESS: 22686dc1418eSTomoki Sekiyama if (hdev->product == USB_DEVICE_ID_JESS_YUREX && 22696dc1418eSTomoki Sekiyama hdev->type == HID_TYPE_USBNONE) 22706dc1418eSTomoki Sekiyama return true; 22716dc1418eSTomoki Sekiyama break; 2272729b814aSForest Bond case USB_VENDOR_ID_DWAV: 2273729b814aSForest Bond /* These are handled by usbtouchscreen. hdev->type is probably 2274729b814aSForest Bond * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match 2275729b814aSForest Bond * usbtouchscreen. */ 2276729b814aSForest Bond if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER || 2277729b814aSForest Bond hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) && 2278729b814aSForest Bond hdev->type != HID_TYPE_USBMOUSE) 2279729b814aSForest Bond return true; 2280729b814aSForest Bond break; 228130b6b7d8SIan Abbott case USB_VENDOR_ID_VELLEMAN: 228230b6b7d8SIan Abbott /* These are not HID devices. They are handled by comedi. */ 228330b6b7d8SIan Abbott if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST && 228430b6b7d8SIan Abbott hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) || 228530b6b7d8SIan Abbott (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST && 228630b6b7d8SIan Abbott hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST)) 228730b6b7d8SIan Abbott return true; 228830b6b7d8SIan Abbott break; 22895b4617d8SAlexey Klimov case USB_VENDOR_ID_ATMEL_V_USB: 22905b4617d8SAlexey Klimov /* Masterkit MA901 usb radio based on Atmel tiny85 chip and 22915b4617d8SAlexey Klimov * it has the same USB ID as many Atmel V-USB devices. This 22925b4617d8SAlexey Klimov * usb radio is handled by radio-ma901.c driver so we want 22935b4617d8SAlexey Klimov * ignore the hid. Check the name, bus, product and ignore 22945b4617d8SAlexey Klimov * if we have MA901 usb radio. 22955b4617d8SAlexey Klimov */ 22965b4617d8SAlexey Klimov if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB && 22975b4617d8SAlexey Klimov hdev->bus == BUS_USB && 22985b4617d8SAlexey Klimov strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0) 22995b4617d8SAlexey Klimov return true; 23005b4617d8SAlexey Klimov break; 2301d458a9dfSJiri Slaby } 2302d458a9dfSJiri Slaby 2303b4d8e473SJiri Slaby if (hdev->type == HID_TYPE_USBMOUSE && 2304b4d8e473SJiri Slaby hid_match_id(hdev, hid_mouse_ignore_list)) 2305b4d8e473SJiri Slaby return true; 2306b4d8e473SJiri Slaby 2307d458a9dfSJiri Slaby return !!hid_match_id(hdev, hid_ignore_list); 2308d458a9dfSJiri Slaby } 23094529eefaSLamarque V. Souza EXPORT_SYMBOL_GPL(hid_ignore); 2310d458a9dfSJiri Slaby 231185cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev) 231285cdaf52SJiri Slaby { 231385cdaf52SJiri Slaby static atomic_t id = ATOMIC_INIT(0); 231485cdaf52SJiri Slaby int ret; 231585cdaf52SJiri Slaby 231685cdaf52SJiri Slaby if (WARN_ON(hdev->status & HID_STAT_ADDED)) 231785cdaf52SJiri Slaby return -EBUSY; 231885cdaf52SJiri Slaby 2319d458a9dfSJiri Slaby /* we need to kill them here, otherwise they will stay allocated to 2320d458a9dfSJiri Slaby * wait for coming driver */ 23214529eefaSLamarque V. Souza if (hid_ignore(hdev)) 2322d458a9dfSJiri Slaby return -ENODEV; 2323d458a9dfSJiri Slaby 2324a7197c2eSHenrik Rydberg /* 2325a7197c2eSHenrik Rydberg * Read the device report descriptor once and use as template 2326a7197c2eSHenrik Rydberg * for the driver-specific modifications. 2327a7197c2eSHenrik Rydberg */ 2328a7197c2eSHenrik Rydberg ret = hdev->ll_driver->parse(hdev); 2329a7197c2eSHenrik Rydberg if (ret) 2330a7197c2eSHenrik Rydberg return ret; 2331a7197c2eSHenrik Rydberg if (!hdev->dev_rdesc) 2332a7197c2eSHenrik Rydberg return -ENODEV; 2333a7197c2eSHenrik Rydberg 2334734c6609SHenrik Rydberg /* 2335734c6609SHenrik Rydberg * Scan generic devices for group information 2336734c6609SHenrik Rydberg */ 2337734c6609SHenrik Rydberg if (hid_ignore_special_drivers || 2338734c6609SHenrik Rydberg !hid_match_id(hdev, hid_have_special_driver)) { 2339734c6609SHenrik Rydberg ret = hid_scan_report(hdev); 2340734c6609SHenrik Rydberg if (ret) 2341734c6609SHenrik Rydberg hid_warn(hdev, "bad device descriptor (%d)\n", ret); 2342734c6609SHenrik Rydberg } 2343734c6609SHenrik Rydberg 23446bbe586fSKay Sievers /* XXX hack, any other cleaner solution after the driver core 23456bbe586fSKay Sievers * is converted to allow more than 20 bytes as the device name? */ 23466bbe586fSKay Sievers dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, 234785cdaf52SJiri Slaby hdev->vendor, hdev->product, atomic_inc_return(&id)); 234885cdaf52SJiri Slaby 23494da361b6SBruno Prémont hid_debug_register(hdev, dev_name(&hdev->dev)); 235085cdaf52SJiri Slaby ret = device_add(&hdev->dev); 235185cdaf52SJiri Slaby if (!ret) 235285cdaf52SJiri Slaby hdev->status |= HID_STAT_ADDED; 23534da361b6SBruno Prémont else 23544da361b6SBruno Prémont hid_debug_unregister(hdev); 2355a635f9ddSJiri Kosina 235685cdaf52SJiri Slaby return ret; 235785cdaf52SJiri Slaby } 235885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device); 235985cdaf52SJiri Slaby 236085cdaf52SJiri Slaby /** 236185cdaf52SJiri Slaby * hid_allocate_device - allocate new hid device descriptor 236285cdaf52SJiri Slaby * 236385cdaf52SJiri Slaby * Allocate and initialize hid device, so that hid_destroy_device might be 236485cdaf52SJiri Slaby * used to free it. 236585cdaf52SJiri Slaby * 236685cdaf52SJiri Slaby * New hid_device pointer is returned on success, otherwise ERR_PTR encoded 236785cdaf52SJiri Slaby * error value. 236885cdaf52SJiri Slaby */ 236985cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void) 237085cdaf52SJiri Slaby { 237185cdaf52SJiri Slaby struct hid_device *hdev; 237285cdaf52SJiri Slaby int ret = -ENOMEM; 237385cdaf52SJiri Slaby 237485cdaf52SJiri Slaby hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); 237585cdaf52SJiri Slaby if (hdev == NULL) 237685cdaf52SJiri Slaby return ERR_PTR(ret); 237785cdaf52SJiri Slaby 237885cdaf52SJiri Slaby device_initialize(&hdev->dev); 237985cdaf52SJiri Slaby hdev->dev.release = hid_device_release; 238085cdaf52SJiri Slaby hdev->dev.bus = &hid_bus_type; 238185cdaf52SJiri Slaby 2382a7197c2eSHenrik Rydberg hid_close_report(hdev); 238385cdaf52SJiri Slaby 2384cd667ce2SJiri Kosina init_waitqueue_head(&hdev->debug_wait); 2385cd667ce2SJiri Kosina INIT_LIST_HEAD(&hdev->debug_list); 23861deb9d34SJiri Kosina spin_lock_init(&hdev->debug_list_lock); 23874ea54542SDavid Herrmann sema_init(&hdev->driver_lock, 1); 2388c849a614SAndrew de los Reyes sema_init(&hdev->driver_input_lock, 1); 2389cd667ce2SJiri Kosina 239085cdaf52SJiri Slaby return hdev; 239185cdaf52SJiri Slaby } 239285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device); 239385cdaf52SJiri Slaby 239485cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev) 239585cdaf52SJiri Slaby { 239685cdaf52SJiri Slaby if (hdev->status & HID_STAT_ADDED) { 239785cdaf52SJiri Slaby device_del(&hdev->dev); 2398a635f9ddSJiri Kosina hid_debug_unregister(hdev); 239985cdaf52SJiri Slaby hdev->status &= ~HID_STAT_ADDED; 240085cdaf52SJiri Slaby } 2401a7197c2eSHenrik Rydberg kfree(hdev->dev_rdesc); 2402a7197c2eSHenrik Rydberg hdev->dev_rdesc = NULL; 2403a7197c2eSHenrik Rydberg hdev->dev_rsize = 0; 240485cdaf52SJiri Slaby } 240585cdaf52SJiri Slaby 240685cdaf52SJiri Slaby /** 240785cdaf52SJiri Slaby * hid_destroy_device - free previously allocated device 240885cdaf52SJiri Slaby * 240985cdaf52SJiri Slaby * @hdev: hid device 241085cdaf52SJiri Slaby * 241185cdaf52SJiri Slaby * If you allocate hid_device through hid_allocate_device, you should ever 241285cdaf52SJiri Slaby * free by this function. 241385cdaf52SJiri Slaby */ 241485cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev) 241585cdaf52SJiri Slaby { 241685cdaf52SJiri Slaby hid_remove_device(hdev); 241785cdaf52SJiri Slaby put_device(&hdev->dev); 241885cdaf52SJiri Slaby } 241985cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device); 242085cdaf52SJiri Slaby 242185cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner, 242285cdaf52SJiri Slaby const char *mod_name) 242385cdaf52SJiri Slaby { 24243a6f82f7SJiri Slaby int ret; 24253a6f82f7SJiri Slaby 242685cdaf52SJiri Slaby hdrv->driver.name = hdrv->name; 242785cdaf52SJiri Slaby hdrv->driver.bus = &hid_bus_type; 242885cdaf52SJiri Slaby hdrv->driver.owner = owner; 242985cdaf52SJiri Slaby hdrv->driver.mod_name = mod_name; 243085cdaf52SJiri Slaby 24313a6f82f7SJiri Slaby INIT_LIST_HEAD(&hdrv->dyn_list); 24323a6f82f7SJiri Slaby spin_lock_init(&hdrv->dyn_lock); 24333a6f82f7SJiri Slaby 24343a6f82f7SJiri Slaby ret = driver_register(&hdrv->driver); 24353a6f82f7SJiri Slaby if (ret) 24363a6f82f7SJiri Slaby return ret; 24373a6f82f7SJiri Slaby 24383a6f82f7SJiri Slaby ret = driver_create_file(&hdrv->driver, &driver_attr_new_id); 24393a6f82f7SJiri Slaby if (ret) 24403a6f82f7SJiri Slaby driver_unregister(&hdrv->driver); 24413a6f82f7SJiri Slaby 24423a6f82f7SJiri Slaby return ret; 244385cdaf52SJiri Slaby } 244485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver); 244585cdaf52SJiri Slaby 244685cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv) 244785cdaf52SJiri Slaby { 24483a6f82f7SJiri Slaby driver_remove_file(&hdrv->driver, &driver_attr_new_id); 244985cdaf52SJiri Slaby driver_unregister(&hdrv->driver); 24503a6f82f7SJiri Slaby hid_free_dynids(hdrv); 245185cdaf52SJiri Slaby } 245285cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver); 245385cdaf52SJiri Slaby 24540361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid) 24550361a28dSOliver Neukum { 24560361a28dSOliver Neukum struct hid_input *hidinput; 24570361a28dSOliver Neukum int i; 24580361a28dSOliver Neukum 2459e5288eb5SJiri Kosina if (!(hid->claimed & HID_CLAIMED_INPUT)) 2460e5288eb5SJiri Kosina return 0; 2461e5288eb5SJiri Kosina 24620361a28dSOliver Neukum list_for_each_entry(hidinput, &hid->inputs, list) { 24630361a28dSOliver Neukum for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++) 24640361a28dSOliver Neukum if (hidinput->input->key[i]) 24650361a28dSOliver Neukum return 1; 24660361a28dSOliver Neukum } 24670361a28dSOliver Neukum 24680361a28dSOliver Neukum return 0; 24690361a28dSOliver Neukum } 24700361a28dSOliver Neukum 24710361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed); 24720361a28dSOliver Neukum 247386166b7bSJiri Kosina static int __init hid_init(void) 247486166b7bSJiri Kosina { 247585cdaf52SJiri Slaby int ret; 247685cdaf52SJiri Slaby 2477a635f9ddSJiri Kosina if (hid_debug) 24784291ee30SJoe Perches pr_warn("hid_debug is now used solely for parser and driver debugging.\n" 24794291ee30SJoe Perches "debugfs is now used for inspecting the device (report descriptor, reports)\n"); 2480a635f9ddSJiri Kosina 248185cdaf52SJiri Slaby ret = bus_register(&hid_bus_type); 248285cdaf52SJiri Slaby if (ret) { 24834291ee30SJoe Perches pr_err("can't register hid bus\n"); 248485cdaf52SJiri Slaby goto err; 248585cdaf52SJiri Slaby } 248685cdaf52SJiri Slaby 248785cdaf52SJiri Slaby ret = hidraw_init(); 248885cdaf52SJiri Slaby if (ret) 248985cdaf52SJiri Slaby goto err_bus; 249085cdaf52SJiri Slaby 2491a635f9ddSJiri Kosina hid_debug_init(); 2492a635f9ddSJiri Kosina 249385cdaf52SJiri Slaby return 0; 249485cdaf52SJiri Slaby err_bus: 249585cdaf52SJiri Slaby bus_unregister(&hid_bus_type); 249685cdaf52SJiri Slaby err: 249785cdaf52SJiri Slaby return ret; 249886166b7bSJiri Kosina } 249986166b7bSJiri Kosina 250086166b7bSJiri Kosina static void __exit hid_exit(void) 250186166b7bSJiri Kosina { 2502a635f9ddSJiri Kosina hid_debug_exit(); 250386166b7bSJiri Kosina hidraw_exit(); 250485cdaf52SJiri Slaby bus_unregister(&hid_bus_type); 250586166b7bSJiri Kosina } 250686166b7bSJiri Kosina 250786166b7bSJiri Kosina module_init(hid_init); 250886166b7bSJiri Kosina module_exit(hid_exit); 250986166b7bSJiri Kosina 251088adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal"); 251188adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik"); 251288adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina"); 2513aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE); 2514aa938f79SJiri Kosina 2515