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 } 453dde5845aSJiri Kosina return 1; 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 && 73183499b52SAlexander Holler (item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL && 732fa79f5ecSMika Westerberg (hid->bus == BUS_USB || hid->bus == BUS_I2C)) 73383499b52SAlexander Holler hid->group = HID_GROUP_SENSOR_HUB; 734734c6609SHenrik Rydberg } 735734c6609SHenrik Rydberg 736734c6609SHenrik Rydberg return 0; 737734c6609SHenrik Rydberg } 738734c6609SHenrik Rydberg 73985cdaf52SJiri Slaby /** 74085cdaf52SJiri Slaby * hid_parse_report - parse device report 74185cdaf52SJiri Slaby * 74285cdaf52SJiri Slaby * @device: hid device 74385cdaf52SJiri Slaby * @start: report start 74485cdaf52SJiri Slaby * @size: report size 74585cdaf52SJiri Slaby * 746a7197c2eSHenrik Rydberg * Allocate the device report as read by the bus driver. This function should 747a7197c2eSHenrik Rydberg * only be called from parse() in ll drivers. 748a7197c2eSHenrik Rydberg */ 749a7197c2eSHenrik Rydberg int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size) 750a7197c2eSHenrik Rydberg { 751a7197c2eSHenrik Rydberg hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL); 752a7197c2eSHenrik Rydberg if (!hid->dev_rdesc) 753a7197c2eSHenrik Rydberg return -ENOMEM; 754a7197c2eSHenrik Rydberg hid->dev_rsize = size; 755a7197c2eSHenrik Rydberg return 0; 756a7197c2eSHenrik Rydberg } 757a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_parse_report); 758a7197c2eSHenrik Rydberg 759a7197c2eSHenrik Rydberg /** 760a7197c2eSHenrik Rydberg * hid_open_report - open a driver-specific device report 761a7197c2eSHenrik Rydberg * 762a7197c2eSHenrik Rydberg * @device: hid device 763a7197c2eSHenrik Rydberg * 764dde5845aSJiri Kosina * Parse a report description into a hid_device structure. Reports are 765dde5845aSJiri Kosina * enumerated, fields are attached to these reports. 76685cdaf52SJiri Slaby * 0 returned on success, otherwise nonzero error value. 767a7197c2eSHenrik Rydberg * 768a7197c2eSHenrik Rydberg * This function (or the equivalent hid_parse() macro) should only be 769a7197c2eSHenrik Rydberg * called from probe() in drivers, before starting the device. 770dde5845aSJiri Kosina */ 771a7197c2eSHenrik Rydberg int hid_open_report(struct hid_device *device) 772dde5845aSJiri Kosina { 773dde5845aSJiri Kosina struct hid_parser *parser; 774dde5845aSJiri Kosina struct hid_item item; 775a7197c2eSHenrik Rydberg unsigned int size; 776a7197c2eSHenrik Rydberg __u8 *start; 77786e6b77eSKevin Daughtridge __u8 *buf; 778dde5845aSJiri Kosina __u8 *end; 77985cdaf52SJiri Slaby int ret; 780dde5845aSJiri Kosina static int (*dispatch_type[])(struct hid_parser *parser, 781dde5845aSJiri Kosina struct hid_item *item) = { 782dde5845aSJiri Kosina hid_parser_main, 783dde5845aSJiri Kosina hid_parser_global, 784dde5845aSJiri Kosina hid_parser_local, 785dde5845aSJiri Kosina hid_parser_reserved 786dde5845aSJiri Kosina }; 787dde5845aSJiri Kosina 788a7197c2eSHenrik Rydberg if (WARN_ON(device->status & HID_STAT_PARSED)) 789a7197c2eSHenrik Rydberg return -EBUSY; 790a7197c2eSHenrik Rydberg 791a7197c2eSHenrik Rydberg start = device->dev_rdesc; 792a7197c2eSHenrik Rydberg if (WARN_ON(!start)) 793a7197c2eSHenrik Rydberg return -ENODEV; 794a7197c2eSHenrik Rydberg size = device->dev_rsize; 795a7197c2eSHenrik Rydberg 79686e6b77eSKevin Daughtridge buf = kmemdup(start, size, GFP_KERNEL); 79786e6b77eSKevin Daughtridge if (buf == NULL) 79885cdaf52SJiri Slaby return -ENOMEM; 79986e6b77eSKevin Daughtridge 80086e6b77eSKevin Daughtridge if (device->driver->report_fixup) 80186e6b77eSKevin Daughtridge start = device->driver->report_fixup(device, buf, &size); 80286e6b77eSKevin Daughtridge else 80386e6b77eSKevin Daughtridge start = buf; 80486e6b77eSKevin Daughtridge 80586e6b77eSKevin Daughtridge start = kmemdup(start, size, GFP_KERNEL); 80686e6b77eSKevin Daughtridge kfree(buf); 80786e6b77eSKevin Daughtridge if (start == NULL) 80886e6b77eSKevin Daughtridge return -ENOMEM; 80986e6b77eSKevin Daughtridge 81086e6b77eSKevin Daughtridge device->rdesc = start; 811dde5845aSJiri Kosina device->rsize = size; 812dde5845aSJiri Kosina 813fe258020SJoe Perches parser = vzalloc(sizeof(struct hid_parser)); 81485cdaf52SJiri Slaby if (!parser) { 81585cdaf52SJiri Slaby ret = -ENOMEM; 81685cdaf52SJiri Slaby goto err; 817dde5845aSJiri Kosina } 81885cdaf52SJiri Slaby 819dde5845aSJiri Kosina parser->device = device; 820dde5845aSJiri Kosina 821dde5845aSJiri Kosina end = start + size; 822a7197c2eSHenrik Rydberg 823a7197c2eSHenrik Rydberg device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, 824a7197c2eSHenrik Rydberg sizeof(struct hid_collection), GFP_KERNEL); 825a7197c2eSHenrik Rydberg if (!device->collection) { 826a7197c2eSHenrik Rydberg ret = -ENOMEM; 827a7197c2eSHenrik Rydberg goto err; 828a7197c2eSHenrik Rydberg } 829a7197c2eSHenrik Rydberg device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; 830a7197c2eSHenrik Rydberg 83185cdaf52SJiri Slaby ret = -EINVAL; 832dde5845aSJiri Kosina while ((start = fetch_item(start, end, &item)) != NULL) { 833dde5845aSJiri Kosina 834dde5845aSJiri Kosina if (item.format != HID_ITEM_FORMAT_SHORT) { 8358c3d52fcSJiri Kosina hid_err(device, "unexpected long global item\n"); 83685cdaf52SJiri Slaby goto err; 837dde5845aSJiri Kosina } 838dde5845aSJiri Kosina 839dde5845aSJiri Kosina if (dispatch_type[item.type](parser, &item)) { 8408c3d52fcSJiri Kosina hid_err(device, "item %u %u %u %u parsing failed\n", 8414291ee30SJoe Perches item.format, (unsigned)item.size, 8424291ee30SJoe Perches (unsigned)item.type, (unsigned)item.tag); 84385cdaf52SJiri Slaby goto err; 844dde5845aSJiri Kosina } 845dde5845aSJiri Kosina 846dde5845aSJiri Kosina if (start == end) { 847dde5845aSJiri Kosina if (parser->collection_stack_ptr) { 8488c3d52fcSJiri Kosina hid_err(device, "unbalanced collection at end of report description\n"); 84985cdaf52SJiri Slaby goto err; 850dde5845aSJiri Kosina } 851dde5845aSJiri Kosina if (parser->local.delimiter_depth) { 8528c3d52fcSJiri Kosina hid_err(device, "unbalanced delimiter at end of report description\n"); 85385cdaf52SJiri Slaby goto err; 854dde5845aSJiri Kosina } 85547a80edbSJiri Kosina vfree(parser); 856a7197c2eSHenrik Rydberg device->status |= HID_STAT_PARSED; 85785cdaf52SJiri Slaby return 0; 858dde5845aSJiri Kosina } 859dde5845aSJiri Kosina } 860dde5845aSJiri Kosina 8618c3d52fcSJiri Kosina hid_err(device, "item fetching failed at offset %d\n", (int)(end - start)); 86285cdaf52SJiri Slaby err: 86347a80edbSJiri Kosina vfree(parser); 864a7197c2eSHenrik Rydberg hid_close_report(device); 86585cdaf52SJiri Slaby return ret; 866dde5845aSJiri Kosina } 867a7197c2eSHenrik Rydberg EXPORT_SYMBOL_GPL(hid_open_report); 868dde5845aSJiri Kosina 869dde5845aSJiri Kosina /* 870dde5845aSJiri Kosina * Convert a signed n-bit integer to signed 32-bit integer. Common 871dde5845aSJiri Kosina * cases are done through the compiler, the screwed things has to be 872dde5845aSJiri Kosina * done by hand. 873dde5845aSJiri Kosina */ 874dde5845aSJiri Kosina 875dde5845aSJiri Kosina static s32 snto32(__u32 value, unsigned n) 876dde5845aSJiri Kosina { 877dde5845aSJiri Kosina switch (n) { 878dde5845aSJiri Kosina case 8: return ((__s8)value); 879dde5845aSJiri Kosina case 16: return ((__s16)value); 880dde5845aSJiri Kosina case 32: return ((__s32)value); 881dde5845aSJiri Kosina } 882dde5845aSJiri Kosina return value & (1 << (n - 1)) ? value | (-1 << n) : value; 883dde5845aSJiri Kosina } 884dde5845aSJiri Kosina 88577463838SBenjamin Tissoires s32 hid_snto32(__u32 value, unsigned n) 88677463838SBenjamin Tissoires { 88777463838SBenjamin Tissoires return snto32(value, n); 88877463838SBenjamin Tissoires } 88977463838SBenjamin Tissoires EXPORT_SYMBOL_GPL(hid_snto32); 89077463838SBenjamin Tissoires 891dde5845aSJiri Kosina /* 892dde5845aSJiri Kosina * Convert a signed 32-bit integer to a signed n-bit integer. 893dde5845aSJiri Kosina */ 894dde5845aSJiri Kosina 895dde5845aSJiri Kosina static u32 s32ton(__s32 value, unsigned n) 896dde5845aSJiri Kosina { 897dde5845aSJiri Kosina s32 a = value >> (n - 1); 898dde5845aSJiri Kosina if (a && a != -1) 899dde5845aSJiri Kosina return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; 900dde5845aSJiri Kosina return value & ((1 << n) - 1); 901dde5845aSJiri Kosina } 902dde5845aSJiri Kosina 903dde5845aSJiri Kosina /* 904dde5845aSJiri Kosina * Extract/implement a data field from/to a little endian report (bit array). 905dde5845aSJiri Kosina * 906dde5845aSJiri Kosina * Code sort-of follows HID spec: 907dde5845aSJiri Kosina * http://www.usb.org/developers/devclass_docs/HID1_11.pdf 908dde5845aSJiri Kosina * 909dde5845aSJiri Kosina * While the USB HID spec allows unlimited length bit fields in "report 910dde5845aSJiri Kosina * descriptors", most devices never use more than 16 bits. 911dde5845aSJiri Kosina * One model of UPS is claimed to report "LINEV" as a 32-bit field. 912dde5845aSJiri Kosina * Search linux-kernel and linux-usb-devel archives for "hid-core extract". 913dde5845aSJiri Kosina */ 914dde5845aSJiri Kosina 91516ee4cc8SJoe Perches static __u32 extract(const struct hid_device *hid, __u8 *report, 9164291ee30SJoe Perches unsigned offset, unsigned n) 917dde5845aSJiri Kosina { 918dde5845aSJiri Kosina u64 x; 919dde5845aSJiri Kosina 920c4124c9bSJiri Kosina if (n > 32) 9214291ee30SJoe Perches hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n", 922c4124c9bSJiri Kosina n, current->comm); 923dde5845aSJiri Kosina 924dde5845aSJiri Kosina report += offset >> 3; /* adjust byte index */ 925dde5845aSJiri Kosina offset &= 7; /* now only need bit offset into one byte */ 926c105068fSHarvey Harrison x = get_unaligned_le64(report); 927dde5845aSJiri Kosina x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */ 928dde5845aSJiri Kosina return (u32) x; 929dde5845aSJiri Kosina } 930dde5845aSJiri Kosina 931dde5845aSJiri Kosina /* 932dde5845aSJiri Kosina * "implement" : set bits in a little endian bit stream. 933dde5845aSJiri Kosina * Same concepts as "extract" (see comments above). 934dde5845aSJiri Kosina * The data mangled in the bit stream remains in little endian 935dde5845aSJiri Kosina * order the whole time. It make more sense to talk about 936dde5845aSJiri Kosina * endianness of register values by considering a register 937dde5845aSJiri Kosina * a "cached" copy of the little endiad bit stream. 938dde5845aSJiri Kosina */ 93916ee4cc8SJoe Perches static void implement(const struct hid_device *hid, __u8 *report, 9404291ee30SJoe Perches unsigned offset, unsigned n, __u32 value) 941dde5845aSJiri Kosina { 9426f0168d2SHarvey Harrison u64 x; 943dde5845aSJiri Kosina u64 m = (1ULL << n) - 1; 944dde5845aSJiri Kosina 945c4124c9bSJiri Kosina if (n > 32) 9464291ee30SJoe Perches hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n", 9474291ee30SJoe Perches __func__, n, current->comm); 948dde5845aSJiri Kosina 949c4124c9bSJiri Kosina if (value > m) 9504291ee30SJoe Perches hid_warn(hid, "%s() called with too large value %d! (%s)\n", 9514291ee30SJoe Perches __func__, value, current->comm); 952dde5845aSJiri Kosina WARN_ON(value > m); 953dde5845aSJiri Kosina value &= m; 954dde5845aSJiri Kosina 955dde5845aSJiri Kosina report += offset >> 3; 956dde5845aSJiri Kosina offset &= 7; 957dde5845aSJiri Kosina 9586f0168d2SHarvey Harrison x = get_unaligned_le64(report); 9596f0168d2SHarvey Harrison x &= ~(m << offset); 9606f0168d2SHarvey Harrison x |= ((u64)value) << offset; 9616f0168d2SHarvey Harrison put_unaligned_le64(x, report); 962dde5845aSJiri Kosina } 963dde5845aSJiri Kosina 964dde5845aSJiri Kosina /* 965dde5845aSJiri Kosina * Search an array for a value. 966dde5845aSJiri Kosina */ 967dde5845aSJiri Kosina 96816ee4cc8SJoe Perches static int search(__s32 *array, __s32 value, unsigned n) 969dde5845aSJiri Kosina { 970dde5845aSJiri Kosina while (n--) { 971dde5845aSJiri Kosina if (*array++ == value) 972dde5845aSJiri Kosina return 0; 973dde5845aSJiri Kosina } 974dde5845aSJiri Kosina return -1; 975dde5845aSJiri Kosina } 976dde5845aSJiri Kosina 97785cdaf52SJiri Slaby /** 97885cdaf52SJiri Slaby * hid_match_report - check if driver's raw_event should be called 97985cdaf52SJiri Slaby * 98085cdaf52SJiri Slaby * @hid: hid device 98185cdaf52SJiri Slaby * @report_type: type to match against 98285cdaf52SJiri Slaby * 98385cdaf52SJiri Slaby * compare hid->driver->report_table->report_type to report->type 98485cdaf52SJiri Slaby */ 98585cdaf52SJiri Slaby static int hid_match_report(struct hid_device *hid, struct hid_report *report) 986dde5845aSJiri Kosina { 98785cdaf52SJiri Slaby const struct hid_report_id *id = hid->driver->report_table; 98885cdaf52SJiri Slaby 98985cdaf52SJiri Slaby if (!id) /* NULL means all */ 99085cdaf52SJiri Slaby return 1; 99185cdaf52SJiri Slaby 99285cdaf52SJiri Slaby for (; id->report_type != HID_TERMINATOR; id++) 99385cdaf52SJiri Slaby if (id->report_type == HID_ANY_ID || 99485cdaf52SJiri Slaby id->report_type == report->type) 99585cdaf52SJiri Slaby return 1; 99685cdaf52SJiri Slaby return 0; 99785cdaf52SJiri Slaby } 99885cdaf52SJiri Slaby 99985cdaf52SJiri Slaby /** 100085cdaf52SJiri Slaby * hid_match_usage - check if driver's event should be called 100185cdaf52SJiri Slaby * 100285cdaf52SJiri Slaby * @hid: hid device 100385cdaf52SJiri Slaby * @usage: usage to match against 100485cdaf52SJiri Slaby * 100585cdaf52SJiri Slaby * compare hid->driver->usage_table->usage_{type,code} to 100685cdaf52SJiri Slaby * usage->usage_{type,code} 100785cdaf52SJiri Slaby */ 100885cdaf52SJiri Slaby static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage) 100985cdaf52SJiri Slaby { 101085cdaf52SJiri Slaby const struct hid_usage_id *id = hid->driver->usage_table; 101185cdaf52SJiri Slaby 101285cdaf52SJiri Slaby if (!id) /* NULL means all */ 101385cdaf52SJiri Slaby return 1; 101485cdaf52SJiri Slaby 101585cdaf52SJiri Slaby for (; id->usage_type != HID_ANY_ID - 1; id++) 101685cdaf52SJiri Slaby if ((id->usage_hid == HID_ANY_ID || 101785cdaf52SJiri Slaby id->usage_hid == usage->hid) && 101885cdaf52SJiri Slaby (id->usage_type == HID_ANY_ID || 101985cdaf52SJiri Slaby id->usage_type == usage->type) && 102085cdaf52SJiri Slaby (id->usage_code == HID_ANY_ID || 102185cdaf52SJiri Slaby id->usage_code == usage->code)) 102285cdaf52SJiri Slaby return 1; 102385cdaf52SJiri Slaby return 0; 102485cdaf52SJiri Slaby } 102585cdaf52SJiri Slaby 102685cdaf52SJiri Slaby static void hid_process_event(struct hid_device *hid, struct hid_field *field, 102785cdaf52SJiri Slaby struct hid_usage *usage, __s32 value, int interrupt) 102885cdaf52SJiri Slaby { 102985cdaf52SJiri Slaby struct hid_driver *hdrv = hid->driver; 103085cdaf52SJiri Slaby int ret; 103185cdaf52SJiri Slaby 10329bfc8da0SHenrik Rydberg if (!list_empty(&hid->debug_list)) 1033cd667ce2SJiri Kosina hid_dump_input(hid, usage, value); 103485cdaf52SJiri Slaby 103585cdaf52SJiri Slaby if (hdrv && hdrv->event && hid_match_usage(hid, usage)) { 103685cdaf52SJiri Slaby ret = hdrv->event(hid, field, usage, value); 103785cdaf52SJiri Slaby if (ret != 0) { 103885cdaf52SJiri Slaby if (ret < 0) 10398c3d52fcSJiri Kosina hid_err(hid, "%s's event failed with %d\n", 104085cdaf52SJiri Slaby hdrv->name, ret); 104185cdaf52SJiri Slaby return; 104285cdaf52SJiri Slaby } 104385cdaf52SJiri Slaby } 104485cdaf52SJiri Slaby 1045dde5845aSJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 1046dde5845aSJiri Kosina hidinput_hid_event(hid, field, usage, value); 1047aa938f79SJiri Kosina if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 1048aa938f79SJiri Kosina hid->hiddev_hid_event(hid, field, usage, value); 1049dde5845aSJiri Kosina } 1050dde5845aSJiri Kosina 1051dde5845aSJiri Kosina /* 1052dde5845aSJiri Kosina * Analyse a received field, and fetch the data from it. The field 1053dde5845aSJiri Kosina * content is stored for next report processing (we do differential 1054dde5845aSJiri Kosina * reporting to the layer). 1055dde5845aSJiri Kosina */ 1056dde5845aSJiri Kosina 1057abdff0f7SAdrian Bunk static void hid_input_field(struct hid_device *hid, struct hid_field *field, 1058abdff0f7SAdrian Bunk __u8 *data, int interrupt) 1059dde5845aSJiri Kosina { 1060dde5845aSJiri Kosina unsigned n; 1061dde5845aSJiri Kosina unsigned count = field->report_count; 1062dde5845aSJiri Kosina unsigned offset = field->report_offset; 1063dde5845aSJiri Kosina unsigned size = field->report_size; 1064dde5845aSJiri Kosina __s32 min = field->logical_minimum; 1065dde5845aSJiri Kosina __s32 max = field->logical_maximum; 1066dde5845aSJiri Kosina __s32 *value; 1067dde5845aSJiri Kosina 1068a3789a17SJoe Perches value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC); 1069a3789a17SJoe Perches if (!value) 1070dde5845aSJiri Kosina return; 1071dde5845aSJiri Kosina 1072dde5845aSJiri Kosina for (n = 0; n < count; n++) { 1073dde5845aSJiri Kosina 10744291ee30SJoe Perches value[n] = min < 0 ? 10754291ee30SJoe Perches snto32(extract(hid, data, offset + n * size, size), 10764291ee30SJoe Perches size) : 10774291ee30SJoe Perches extract(hid, data, offset + n * size, size); 1078dde5845aSJiri Kosina 10794291ee30SJoe Perches /* Ignore report if ErrorRollOver */ 10804291ee30SJoe Perches if (!(field->flags & HID_MAIN_ITEM_VARIABLE) && 10814291ee30SJoe Perches value[n] >= min && value[n] <= max && 10824291ee30SJoe Perches field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) 1083dde5845aSJiri Kosina goto exit; 1084dde5845aSJiri Kosina } 1085dde5845aSJiri Kosina 1086dde5845aSJiri Kosina for (n = 0; n < count; n++) { 1087dde5845aSJiri Kosina 1088dde5845aSJiri Kosina if (HID_MAIN_ITEM_VARIABLE & field->flags) { 1089dde5845aSJiri Kosina hid_process_event(hid, field, &field->usage[n], value[n], interrupt); 1090dde5845aSJiri Kosina continue; 1091dde5845aSJiri Kosina } 1092dde5845aSJiri Kosina 1093dde5845aSJiri Kosina if (field->value[n] >= min && field->value[n] <= max 1094dde5845aSJiri Kosina && field->usage[field->value[n] - min].hid 1095dde5845aSJiri Kosina && search(value, field->value[n], count)) 1096dde5845aSJiri Kosina hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt); 1097dde5845aSJiri Kosina 1098dde5845aSJiri Kosina if (value[n] >= min && value[n] <= max 1099dde5845aSJiri Kosina && field->usage[value[n] - min].hid 1100dde5845aSJiri Kosina && search(field->value, value[n], count)) 1101dde5845aSJiri Kosina hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt); 1102dde5845aSJiri Kosina } 1103dde5845aSJiri Kosina 1104dde5845aSJiri Kosina memcpy(field->value, value, count * sizeof(__s32)); 1105dde5845aSJiri Kosina exit: 1106dde5845aSJiri Kosina kfree(value); 1107dde5845aSJiri Kosina } 1108dde5845aSJiri Kosina 1109dde5845aSJiri Kosina /* 1110dde5845aSJiri Kosina * Output the field into the report. 1111dde5845aSJiri Kosina */ 1112dde5845aSJiri Kosina 11134291ee30SJoe Perches static void hid_output_field(const struct hid_device *hid, 11144291ee30SJoe Perches struct hid_field *field, __u8 *data) 1115dde5845aSJiri Kosina { 1116dde5845aSJiri Kosina unsigned count = field->report_count; 1117dde5845aSJiri Kosina unsigned offset = field->report_offset; 1118dde5845aSJiri Kosina unsigned size = field->report_size; 1119dde5845aSJiri Kosina unsigned n; 1120dde5845aSJiri Kosina 1121dde5845aSJiri Kosina for (n = 0; n < count; n++) { 1122dde5845aSJiri Kosina if (field->logical_minimum < 0) /* signed values */ 11234291ee30SJoe Perches implement(hid, data, offset + n * size, size, 11244291ee30SJoe Perches s32ton(field->value[n], size)); 1125dde5845aSJiri Kosina else /* unsigned values */ 11264291ee30SJoe Perches implement(hid, data, offset + n * size, size, 11274291ee30SJoe Perches field->value[n]); 1128dde5845aSJiri Kosina } 1129dde5845aSJiri Kosina } 1130dde5845aSJiri Kosina 1131dde5845aSJiri Kosina /* 1132dde5845aSJiri Kosina * Create a report. 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 /* 1149dde5845aSJiri Kosina * Set a field value. The report this field belongs to has to be 1150dde5845aSJiri Kosina * created and transferred to the device, to set this value in the 1151dde5845aSJiri Kosina * device. 1152dde5845aSJiri Kosina */ 1153dde5845aSJiri Kosina 1154dde5845aSJiri Kosina int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) 1155dde5845aSJiri Kosina { 1156dde5845aSJiri Kosina unsigned size = field->report_size; 1157dde5845aSJiri Kosina 1158cd667ce2SJiri Kosina hid_dump_input(field->report->device, field->usage + offset, value); 1159dde5845aSJiri Kosina 1160dde5845aSJiri Kosina if (offset >= field->report_count) { 11618c3d52fcSJiri Kosina hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n", 11628c3d52fcSJiri Kosina offset, field->report_count); 1163dde5845aSJiri Kosina return -1; 1164dde5845aSJiri Kosina } 1165dde5845aSJiri Kosina if (field->logical_minimum < 0) { 1166dde5845aSJiri Kosina if (value != snto32(s32ton(value, size), size)) { 11678c3d52fcSJiri Kosina hid_err(field->report->device, "value %d is out of range\n", value); 1168dde5845aSJiri Kosina return -1; 1169dde5845aSJiri Kosina } 1170dde5845aSJiri Kosina } 1171dde5845aSJiri Kosina field->value[offset] = value; 1172dde5845aSJiri Kosina return 0; 1173dde5845aSJiri Kosina } 1174229695e5SJiri Kosina EXPORT_SYMBOL_GPL(hid_set_field); 1175dde5845aSJiri Kosina 117685cdaf52SJiri Slaby static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, 117785cdaf52SJiri Slaby const u8 *data) 117885cdaf52SJiri Slaby { 117985cdaf52SJiri Slaby struct hid_report *report; 118085cdaf52SJiri Slaby unsigned int n = 0; /* Normally report number is 0 */ 118185cdaf52SJiri Slaby 118285cdaf52SJiri Slaby /* Device uses numbered reports, data[0] is report number */ 118385cdaf52SJiri Slaby if (report_enum->numbered) 118485cdaf52SJiri Slaby n = *data; 118585cdaf52SJiri Slaby 118685cdaf52SJiri Slaby report = report_enum->report_id_hash[n]; 118785cdaf52SJiri Slaby if (report == NULL) 118885cdaf52SJiri Slaby dbg_hid("undefined report_id %u received\n", n); 118985cdaf52SJiri Slaby 119085cdaf52SJiri Slaby return report; 119185cdaf52SJiri Slaby } 119285cdaf52SJiri Slaby 1193b6787242SJiri Kosina int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, 119485cdaf52SJiri Slaby int interrupt) 1195aa8de2f0SJiri Kosina { 1196aa8de2f0SJiri Kosina struct hid_report_enum *report_enum = hid->report_enum + type; 1197aa8de2f0SJiri Kosina struct hid_report *report; 11986d85d037SBenjamin Tissoires struct hid_driver *hdrv; 119985cdaf52SJiri Slaby unsigned int a; 120085cdaf52SJiri Slaby int rsize, csize = size; 120185cdaf52SJiri Slaby u8 *cdata = data; 1202b6787242SJiri Kosina int ret = 0; 1203aa8de2f0SJiri Kosina 120485cdaf52SJiri Slaby report = hid_get_report(report_enum, data); 120585cdaf52SJiri Slaby if (!report) 1206b6787242SJiri Kosina goto out; 1207aa8de2f0SJiri Kosina 120885cdaf52SJiri Slaby if (report_enum->numbered) { 120985cdaf52SJiri Slaby cdata++; 121085cdaf52SJiri Slaby csize--; 1211aa8de2f0SJiri Kosina } 1212aa8de2f0SJiri Kosina 1213aa8de2f0SJiri Kosina rsize = ((report->size - 1) >> 3) + 1; 1214aa8de2f0SJiri Kosina 1215966922f2SArmando Visconti if (rsize > HID_MAX_BUFFER_SIZE) 1216966922f2SArmando Visconti rsize = HID_MAX_BUFFER_SIZE; 1217966922f2SArmando Visconti 121885cdaf52SJiri Slaby if (csize < rsize) { 121985cdaf52SJiri Slaby dbg_hid("report %d is too short, (%d < %d)\n", report->id, 122085cdaf52SJiri Slaby csize, rsize); 122185cdaf52SJiri Slaby memset(cdata + csize, 0, rsize - csize); 1222aa8de2f0SJiri Kosina } 1223aa8de2f0SJiri Kosina 1224aa8de2f0SJiri Kosina if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) 1225aa8de2f0SJiri Kosina hid->hiddev_report_event(hid, report); 1226b6787242SJiri Kosina if (hid->claimed & HID_CLAIMED_HIDRAW) { 1227b6787242SJiri Kosina ret = hidraw_report_event(hid, data, size); 1228b6787242SJiri Kosina if (ret) 1229b6787242SJiri Kosina goto out; 1230b6787242SJiri Kosina } 1231aa8de2f0SJiri Kosina 1232b94e3c94SMatthieu CASTET if (hid->claimed != HID_CLAIMED_HIDRAW) { 123385cdaf52SJiri Slaby for (a = 0; a < report->maxfield; a++) 123485cdaf52SJiri Slaby hid_input_field(hid, report->field[a], cdata, interrupt); 12356d85d037SBenjamin Tissoires hdrv = hid->driver; 12366d85d037SBenjamin Tissoires if (hdrv && hdrv->report) 12376d85d037SBenjamin Tissoires hdrv->report(hid, report); 1238b94e3c94SMatthieu CASTET } 1239aa8de2f0SJiri Kosina 1240aa8de2f0SJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 1241aa8de2f0SJiri Kosina hidinput_report_event(hid, report); 1242b6787242SJiri Kosina out: 1243b6787242SJiri Kosina return ret; 124485cdaf52SJiri Slaby } 124585cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_report_raw_event); 124685cdaf52SJiri Slaby 124785cdaf52SJiri Slaby /** 124885cdaf52SJiri Slaby * hid_input_report - report data from lower layer (usb, bt...) 124985cdaf52SJiri Slaby * 125085cdaf52SJiri Slaby * @hid: hid device 125185cdaf52SJiri Slaby * @type: HID report type (HID_*_REPORT) 125285cdaf52SJiri Slaby * @data: report contents 125385cdaf52SJiri Slaby * @size: size of data parameter 1254ff9b00a2SJiri Kosina * @interrupt: distinguish between interrupt and control transfers 125585cdaf52SJiri Slaby * 125685cdaf52SJiri Slaby * This is data entry for lower layers. 125785cdaf52SJiri Slaby */ 125885cdaf52SJiri Slaby int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) 125985cdaf52SJiri Slaby { 126076c317d6SJulia Lawall struct hid_report_enum *report_enum; 126176c317d6SJulia Lawall struct hid_driver *hdrv; 126285cdaf52SJiri Slaby struct hid_report *report; 126345dc1ac7SJiri Kosina int ret = 0; 126485cdaf52SJiri Slaby 12654ea54542SDavid Herrmann if (!hid) 126685cdaf52SJiri Slaby return -ENODEV; 12674ea54542SDavid Herrmann 12684ea54542SDavid Herrmann if (down_trylock(&hid->driver_lock)) 12694ea54542SDavid Herrmann return -EBUSY; 12704ea54542SDavid Herrmann 12714ea54542SDavid Herrmann if (!hid->driver) { 12724ea54542SDavid Herrmann ret = -ENODEV; 12734ea54542SDavid Herrmann goto unlock; 12744ea54542SDavid Herrmann } 127576c317d6SJulia Lawall report_enum = hid->report_enum + type; 127676c317d6SJulia Lawall hdrv = hid->driver; 127785cdaf52SJiri Slaby 127885cdaf52SJiri Slaby if (!size) { 127985cdaf52SJiri Slaby dbg_hid("empty report\n"); 12804ea54542SDavid Herrmann ret = -1; 12814ea54542SDavid Herrmann goto unlock; 128285cdaf52SJiri Slaby } 128385cdaf52SJiri Slaby 1284b94e3c94SMatthieu CASTET /* Avoid unnecessary overhead if debugfs is disabled */ 1285*a5f04b9dSBenjamin Tissoires if (!list_empty(&hid->debug_list)) 1286*a5f04b9dSBenjamin Tissoires hid_dump_report(hid, type, data, size); 1287b94e3c94SMatthieu CASTET 1288f77e347bSJiri Kosina report = hid_get_report(report_enum, data); 1289f77e347bSJiri Kosina 12904ea54542SDavid Herrmann if (!report) { 12914ea54542SDavid Herrmann ret = -1; 12924ea54542SDavid Herrmann goto unlock; 12934ea54542SDavid Herrmann } 1294f77e347bSJiri Kosina 129585cdaf52SJiri Slaby if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { 129685cdaf52SJiri Slaby ret = hdrv->raw_event(hid, report, data, size); 12974ea54542SDavid Herrmann if (ret != 0) { 12984ea54542SDavid Herrmann ret = ret < 0 ? ret : 0; 12994ea54542SDavid Herrmann goto unlock; 13004ea54542SDavid Herrmann } 130185cdaf52SJiri Slaby } 130285cdaf52SJiri Slaby 1303b6787242SJiri Kosina ret = hid_report_raw_event(hid, type, data, size, interrupt); 1304aa8de2f0SJiri Kosina 13054ea54542SDavid Herrmann unlock: 13064ea54542SDavid Herrmann up(&hid->driver_lock); 130745dc1ac7SJiri Kosina return ret; 1308aa8de2f0SJiri Kosina } 1309aa8de2f0SJiri Kosina EXPORT_SYMBOL_GPL(hid_input_report); 1310aa8de2f0SJiri Kosina 13110f37cd03SJiri Kosina static bool hid_match_one_id(struct hid_device *hdev, 13120f37cd03SJiri Kosina const struct hid_device_id *id) 13130f37cd03SJiri Kosina { 13147431fb76SHenrik Rydberg return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) && 13154d53b801SHenrik Rydberg (id->group == HID_GROUP_ANY || id->group == hdev->group) && 13160f37cd03SJiri Kosina (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && 13170f37cd03SJiri Kosina (id->product == HID_ANY_ID || id->product == hdev->product); 13180f37cd03SJiri Kosina } 13190f37cd03SJiri Kosina 1320bbc21cfdSJeremy Fitzhardinge const struct hid_device_id *hid_match_id(struct hid_device *hdev, 13210f37cd03SJiri Kosina const struct hid_device_id *id) 13220f37cd03SJiri Kosina { 13230f37cd03SJiri Kosina for (; id->bus; id++) 13240f37cd03SJiri Kosina if (hid_match_one_id(hdev, id)) 13250f37cd03SJiri Kosina return id; 13260f37cd03SJiri Kosina 13270f37cd03SJiri Kosina return NULL; 13280f37cd03SJiri Kosina } 13290f37cd03SJiri Kosina 13300f37cd03SJiri Kosina static const struct hid_device_id hid_hiddev_list[] = { 1331c0bd6a42SRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) }, 1332c0bd6a42SRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) }, 13330f37cd03SJiri Kosina { } 13340f37cd03SJiri Kosina }; 13350f37cd03SJiri Kosina 13360f37cd03SJiri Kosina static bool hid_hiddev(struct hid_device *hdev) 13370f37cd03SJiri Kosina { 13380f37cd03SJiri Kosina return !!hid_match_id(hdev, hid_hiddev_list); 13390f37cd03SJiri Kosina } 13400f37cd03SJiri Kosina 13416d3bfb74SAlan Ott 13426d3bfb74SAlan Ott static ssize_t 13436d3bfb74SAlan Ott read_report_descriptor(struct file *filp, struct kobject *kobj, 13446d3bfb74SAlan Ott struct bin_attribute *attr, 13456d3bfb74SAlan Ott char *buf, loff_t off, size_t count) 13466d3bfb74SAlan Ott { 13476d3bfb74SAlan Ott struct device *dev = container_of(kobj, struct device, kobj); 13486d3bfb74SAlan Ott struct hid_device *hdev = container_of(dev, struct hid_device, dev); 13496d3bfb74SAlan Ott 13506d3bfb74SAlan Ott if (off >= hdev->rsize) 13516d3bfb74SAlan Ott return 0; 13526d3bfb74SAlan Ott 13536d3bfb74SAlan Ott if (off + count > hdev->rsize) 13546d3bfb74SAlan Ott count = hdev->rsize - off; 13556d3bfb74SAlan Ott 13566d3bfb74SAlan Ott memcpy(buf, hdev->rdesc + off, count); 13576d3bfb74SAlan Ott 13586d3bfb74SAlan Ott return count; 13596d3bfb74SAlan Ott } 13606d3bfb74SAlan Ott 13616d3bfb74SAlan Ott static struct bin_attribute dev_bin_attr_report_desc = { 13626d3bfb74SAlan Ott .attr = { .name = "report_descriptor", .mode = 0444 }, 13636d3bfb74SAlan Ott .read = read_report_descriptor, 13646d3bfb74SAlan Ott .size = HID_MAX_DESCRIPTOR_SIZE, 13656d3bfb74SAlan Ott }; 13666d3bfb74SAlan Ott 136793c10132SJiri Slaby int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 136893c10132SJiri Slaby { 136993c10132SJiri Slaby static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 137093c10132SJiri Slaby "Joystick", "Gamepad", "Keyboard", "Keypad", 137193c10132SJiri Slaby "Multi-Axis Controller" 137293c10132SJiri Slaby }; 137393c10132SJiri Slaby const char *type, *bus; 137493c10132SJiri Slaby char buf[64]; 137593c10132SJiri Slaby unsigned int i; 137693c10132SJiri Slaby int len; 13776d3bfb74SAlan Ott int ret; 137893c10132SJiri Slaby 1379b5e5a37eSBastien Nocera if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE) 1380b5e5a37eSBastien Nocera connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV); 13813a343ee4SDaniel Mack if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE) 13823a343ee4SDaniel Mack connect_mask |= HID_CONNECT_HIDINPUT_FORCE; 138393c10132SJiri Slaby if (hdev->bus != BUS_USB) 138493c10132SJiri Slaby connect_mask &= ~HID_CONNECT_HIDDEV; 13850f37cd03SJiri Kosina if (hid_hiddev(hdev)) 13860f37cd03SJiri Kosina connect_mask |= HID_CONNECT_HIDDEV_FORCE; 138793c10132SJiri Slaby 138893c10132SJiri Slaby if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, 138993c10132SJiri Slaby connect_mask & HID_CONNECT_HIDINPUT_FORCE)) 139093c10132SJiri Slaby hdev->claimed |= HID_CLAIMED_INPUT; 1391b77c3920SBenjamin Tissoires 139293c10132SJiri Slaby if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && 139393c10132SJiri Slaby !hdev->hiddev_connect(hdev, 139493c10132SJiri Slaby connect_mask & HID_CONNECT_HIDDEV_FORCE)) 139593c10132SJiri Slaby hdev->claimed |= HID_CLAIMED_HIDDEV; 139693c10132SJiri Slaby if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev)) 139793c10132SJiri Slaby hdev->claimed |= HID_CLAIMED_HIDRAW; 139893c10132SJiri Slaby 13994bc19f62SDavid Herrmann /* Drivers with the ->raw_event callback set are not required to connect 14004bc19f62SDavid Herrmann * to any other listener. */ 14014bc19f62SDavid Herrmann if (!hdev->claimed && !hdev->driver->raw_event) { 14024bc19f62SDavid Herrmann hid_err(hdev, "device has no listeners, quitting\n"); 140393c10132SJiri Slaby return -ENODEV; 140493c10132SJiri Slaby } 140593c10132SJiri Slaby 140693c10132SJiri Slaby if ((hdev->claimed & HID_CLAIMED_INPUT) && 140793c10132SJiri Slaby (connect_mask & HID_CONNECT_FF) && hdev->ff_init) 140893c10132SJiri Slaby hdev->ff_init(hdev); 140993c10132SJiri Slaby 141093c10132SJiri Slaby len = 0; 141193c10132SJiri Slaby if (hdev->claimed & HID_CLAIMED_INPUT) 141293c10132SJiri Slaby len += sprintf(buf + len, "input"); 141393c10132SJiri Slaby if (hdev->claimed & HID_CLAIMED_HIDDEV) 141493c10132SJiri Slaby len += sprintf(buf + len, "%shiddev%d", len ? "," : "", 141593c10132SJiri Slaby hdev->minor); 141693c10132SJiri Slaby if (hdev->claimed & HID_CLAIMED_HIDRAW) 141793c10132SJiri Slaby len += sprintf(buf + len, "%shidraw%d", len ? "," : "", 141893c10132SJiri Slaby ((struct hidraw *)hdev->hidraw)->minor); 141993c10132SJiri Slaby 142093c10132SJiri Slaby type = "Device"; 142193c10132SJiri Slaby for (i = 0; i < hdev->maxcollection; i++) { 142293c10132SJiri Slaby struct hid_collection *col = &hdev->collection[i]; 142393c10132SJiri Slaby if (col->type == HID_COLLECTION_APPLICATION && 142493c10132SJiri Slaby (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK && 142593c10132SJiri Slaby (col->usage & 0xffff) < ARRAY_SIZE(types)) { 142693c10132SJiri Slaby type = types[col->usage & 0xffff]; 142793c10132SJiri Slaby break; 142893c10132SJiri Slaby } 142993c10132SJiri Slaby } 143093c10132SJiri Slaby 143193c10132SJiri Slaby switch (hdev->bus) { 143293c10132SJiri Slaby case BUS_USB: 143393c10132SJiri Slaby bus = "USB"; 143493c10132SJiri Slaby break; 143593c10132SJiri Slaby case BUS_BLUETOOTH: 143693c10132SJiri Slaby bus = "BLUETOOTH"; 143793c10132SJiri Slaby break; 143893c10132SJiri Slaby default: 143993c10132SJiri Slaby bus = "<UNKNOWN>"; 144093c10132SJiri Slaby } 144193c10132SJiri Slaby 14426d3bfb74SAlan Ott ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 14436d3bfb74SAlan Ott if (ret) 14446d3bfb74SAlan Ott hid_warn(hdev, 14456d3bfb74SAlan Ott "can't create sysfs report descriptor attribute err: %d\n", ret); 14466d3bfb74SAlan Ott 14474291ee30SJoe Perches hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 144893c10132SJiri Slaby buf, bus, hdev->version >> 8, hdev->version & 0xff, 144993c10132SJiri Slaby type, hdev->name, hdev->phys); 145093c10132SJiri Slaby 145193c10132SJiri Slaby return 0; 145293c10132SJiri Slaby } 145393c10132SJiri Slaby EXPORT_SYMBOL_GPL(hid_connect); 145493c10132SJiri Slaby 1455c4c259bcSJiri Kosina void hid_disconnect(struct hid_device *hdev) 1456c4c259bcSJiri Kosina { 14576d3bfb74SAlan Ott device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1458c4c259bcSJiri Kosina if (hdev->claimed & HID_CLAIMED_INPUT) 1459c4c259bcSJiri Kosina hidinput_disconnect(hdev); 1460c4c259bcSJiri Kosina if (hdev->claimed & HID_CLAIMED_HIDDEV) 1461c4c259bcSJiri Kosina hdev->hiddev_disconnect(hdev); 1462c4c259bcSJiri Kosina if (hdev->claimed & HID_CLAIMED_HIDRAW) 1463c4c259bcSJiri Kosina hidraw_disconnect(hdev); 1464c4c259bcSJiri Kosina } 1465c4c259bcSJiri Kosina EXPORT_SYMBOL_GPL(hid_disconnect); 1466c4c259bcSJiri Kosina 146700315e4fSJiri Kosina /* 146800315e4fSJiri Kosina * A list of devices for which there is a specialized driver on HID bus. 146900315e4fSJiri Kosina * 147000315e4fSJiri Kosina * Please note that for multitouch devices (driven by hid-multitouch driver), 147100315e4fSJiri Kosina * there is a proper autodetection and autoloading in place (based on presence 147200315e4fSJiri Kosina * of HID_DG_CONTACTID), so those devices don't need to be added to this list, 147300315e4fSJiri Kosina * as we are doing the right thing in hid_scan_usage(). 147483499b52SAlexander Holler * 147583499b52SAlexander Holler * Autodetection for (USB) HID sensor hubs exists too. If a collection of type 147683499b52SAlexander Holler * physical is found inside a usage page of type sensor, hid-sensor-hub will be 147783499b52SAlexander Holler * used as a driver. See hid_scan_report(). 147800315e4fSJiri Kosina */ 1479ce06b9d6SDmitry Torokhov static const struct hid_device_id hid_have_special_driver[] = { 148014a21cd4SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 148114a21cd4SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1482b7e1b203SLech Perczak { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) }, 1483c0dbcc33SSergei Kolzun { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) }, 1484df9bcaceSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, 14858c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, 14868c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, 1487128537ceSMichael Poole { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) }, 1488a462230eSChase Douglas { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) }, 14898c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 14908c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 14918c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 14928c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 14938c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 14948c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 14958c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 14968c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 14978c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 14988c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 14998c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 1500fef3f571SRyan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) }, 1501fef3f571SRyan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) }, 1502fef3f571SRyan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) }, 15038c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) }, 15048c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) }, 15058c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) }, 15068c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 15078c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 15088c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 1509ee8a1a0aSJan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) }, 1510ee8a1a0aSJan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) }, 1511ee8a1a0aSJan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) }, 15128c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 15138c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 15148c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 15158c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 15168c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 15178c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 1518a96d6ef3SHenrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1519a96d6ef3SHenrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1520a96d6ef3SHenrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 152199b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) }, 152299b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) }, 152399b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) }, 152499b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 152599b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 152699b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 152747340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 152847340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 152947340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 1530213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) }, 1531213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) }, 1532213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) }, 15334a4c8799SDan Bastone { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) }, 15344a4c8799SDan Bastone { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) }, 15354a4c8799SDan Bastone { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) }, 1536f6f554f0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) }, 1537f6f554f0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) }, 1538f6f554f0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) }, 1539d762cc29SNobuhiro Iwamatsu { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) }, 1540d762cc29SNobuhiro Iwamatsu { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) }, 1541d762cc29SNobuhiro Iwamatsu { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) }, 1542b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) }, 1543b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) }, 1544b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) }, 15458d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) }, 15468d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) }, 15478d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) }, 154823aeb61eSChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 154923aeb61eSChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 155023aeb61eSChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1551f9af7b9eSBen Hutchings { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) }, 1552ad734bc1SAndreas Krist { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) }, 15538c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 15548c19a515SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1555212da74dSJosenivaldo Benito Junior { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) }, 1556b5635b12SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, 1557bf280628SWayne Thomas { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 1558c3dc66deSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) }, 15593b239cd7SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 15601ce31b25SRaphaël Doursenaud { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) }, 1561fcfacfd3SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 1562b9e4b1e0SDennis Kügler { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) }, 15633596bb92SKeng-Yu Lin { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, 15642d8767bbSCyrus Lien { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, 15653a370ca1SDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, 15660f221320SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, 15670f221320SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, 1568e8d0eab4SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, 156976c9d8feSLionel Vaux { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) }, 15700f221320SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, 15713f866fbdSRichard Walmsley { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, 1572e05eefb9SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) }, 157364b386eaSRichard Nauber { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, 157404561c5aSIgnaz Forster { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) }, 15751f243e30SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, 15765181e594SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, 1577578f3a35SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, 15785181e594SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, 157942859e0bSLukasz Lubojanski { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, 1580949f8fefSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, 15811e093206SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, 1582c2fd1a4eSCory Maccarrone { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, 1583d946e65eSAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) }, 1584ff9bf5a2STom Harwood { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) }, 1585aaca9cc0SMichael Karcher { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) }, 15864ddfe028SBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) }, 1587fdf93aa3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, 1588177900e8SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) }, 158979422741SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 159022ca20b2SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) }, 159122ca20b2SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) }, 159222ca20b2SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) }, 1593b5635b12SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 159475b07022SChris Schlund { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, 1595aad932e7SAndres Freund #if IS_ENABLED(CONFIG_HID_LENOVO_TPKBD) 1596c1dcad2dSBernhard Seibold { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) }, 1597aad932e7SAndres Freund #endif 15985f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, 15995f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, 16005f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, 16015f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, 16025844c1cdSDavid Dillow { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) }, 16035f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, 16045f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, 16055f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, 16065f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) }, 16075f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) }, 16085f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) }, 16095f22a799SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) }, 16102c6118e4SHendrik Iben { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) }, 1611606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, 1612606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, 1613606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, 1614fd30ea8cSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) }, 1615606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, 161674f292caSGary Stein { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) }, 1617606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, 1618606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, 16195623a24aSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) }, 1620e00ddc9bSMichal Malý { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) }, 1621243b706dSChristophe Borivant { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, 1622fdc6807fSPeter Gundermann { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) }, 16230944e964SKonstantin Khlebnikov #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ) 1624534a7b8eSNestor Lopez Casado { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) }, 1625534a7b8eSNestor Lopez Casado { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) }, 16260944e964SKonstantin Khlebnikov #endif 162732c88cbcSSimon Wood { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) }, 1628606bd0a8SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, 162924985cf6SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, 163024985cf6SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) }, 1631236db47cSBruno Prémont { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) }, 1632236db47cSBruno Prémont { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) }, 1633b580169aSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) }, 163478a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) }, 163578a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) }, 163678a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) }, 163778a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, 1638f3b83d71SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) }, 163978a849a6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 16403b8006e5SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, 164194011f93SRafi Rubin { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, 16426e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) }, 16436e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) }, 16446e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) }, 16456e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) }, 16466e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) }, 16476e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) }, 16486e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) }, 16496e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) }, 16506e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) }, 16516e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) }, 16526e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) }, 16536e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) }, 16546e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) }, 16556e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) }, 16566e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) }, 16576e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) }, 16586e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) }, 16596e32819eSmicki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) }, 1660270fdc07SHerton Ronaldo Krzesinski { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) }, 1661cd9ec30dSJohnathon Harris { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) }, 16621e762532SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 1663f6a04605STerry Lambert { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) }, 1664ca9bbdccSStefan Achatz #if IS_ENABLED(CONFIG_HID_ROCCAT) 166514bf62cdSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, 1666e68cc603SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) }, 1667d41c2a70SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) }, 166847dbdbffSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, 16690e70f97fSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) }, 16704424f616SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) }, 1671cb7cf3daSStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 16723fce2246SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) }, 16736a2a6390SStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) }, 1674ca9bbdccSStefan Achatz #endif 16751e93674aSAndreas Hübner { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) }, 1676980a3da6SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1677b355850bSDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, 1678d586dca0SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) }, 16795844c1cdSDavid Dillow { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) }, 1680bd28ce00SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 168135dca5b4SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) }, 1682f9ce7c28SBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1683cc6e0bbbSJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, 168475dbb953SSimon Wood { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) }, 168590231e7eSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, 168630ba2fbdSVivien Didelot { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) }, 1687daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, 1688daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, 16897a84b133SRuben Aos Garralda { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) }, 16907a84b133SRuben Aos Garralda { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) }, 1691daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, 16923ee8f0a2SMarkus Rathgeb { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) }, 1693daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, 1694d65c3768SSimon Wood { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) }, 1695740363fbSJiri Kosina { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) }, 169644ea35c1SJarod Wilson { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) }, 1697f14f526dSLev Babiev { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 169854001081SKees Bakker { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 1699711a680eSBruno Premont { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, 170041fa9230SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, 1701f8a489ccSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) }, 1702f8a489ccSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) }, 1703f8a489ccSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) }, 17046be914f1SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) }, 1705d1257081SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, 1706eb4e426aSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) }, 1707fac733f0SJussi Kivilinna { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, 170842fc04e5SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) }, 1709ad395ccaSSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) }, 17101bcc2067SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) }, 17111bcc2067SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) }, 17121bcc2067SSean Young { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) }, 1713ca2dcd40SBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 171478761ff9SPrzemo Firszt { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, 171572a46344SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) }, 171600e7f964SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) }, 17174fdc18d1SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) }, 1718a786e83cSNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) }, 171972a46344SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) }, 17208f1acc32SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, 1721d2ee4dd9SNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) }, 172274bc6953SStefan Kriwanek { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) }, 1723daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, 1724daedb3d6SAnssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, 1725a9885c8fSDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) }, 17268c19a515SJiri Slaby 172778a849a6SJiri Slaby { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, 172802fb72a0SDavid Herrmann { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) }, 172985cdaf52SJiri Slaby { } 173085cdaf52SJiri Slaby }; 173185cdaf52SJiri Slaby 17323a6f82f7SJiri Slaby struct hid_dynid { 17333a6f82f7SJiri Slaby struct list_head list; 17343a6f82f7SJiri Slaby struct hid_device_id id; 17353a6f82f7SJiri Slaby }; 17363a6f82f7SJiri Slaby 17373a6f82f7SJiri Slaby /** 17383a6f82f7SJiri Slaby * store_new_id - add a new HID device ID to this driver and re-probe devices 17393a6f82f7SJiri Slaby * @driver: target device driver 17403a6f82f7SJiri Slaby * @buf: buffer for scanning device ID data 17413a6f82f7SJiri Slaby * @count: input size 17423a6f82f7SJiri Slaby * 17433a6f82f7SJiri Slaby * Adds a new dynamic hid device ID to this driver, 17443a6f82f7SJiri Slaby * and causes the driver to probe for all devices again. 17453a6f82f7SJiri Slaby */ 17463a6f82f7SJiri Slaby static ssize_t store_new_id(struct device_driver *drv, const char *buf, 17473a6f82f7SJiri Slaby size_t count) 17483a6f82f7SJiri Slaby { 17493a6f82f7SJiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 17503a6f82f7SJiri Slaby struct hid_dynid *dynid; 17513a6f82f7SJiri Slaby __u32 bus, vendor, product; 17523a6f82f7SJiri Slaby unsigned long driver_data = 0; 17533a6f82f7SJiri Slaby int ret; 17543a6f82f7SJiri Slaby 17553a6f82f7SJiri Slaby ret = sscanf(buf, "%x %x %x %lx", 17563a6f82f7SJiri Slaby &bus, &vendor, &product, &driver_data); 17573a6f82f7SJiri Slaby if (ret < 3) 17583a6f82f7SJiri Slaby return -EINVAL; 17593a6f82f7SJiri Slaby 17603a6f82f7SJiri Slaby dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); 17613a6f82f7SJiri Slaby if (!dynid) 17623a6f82f7SJiri Slaby return -ENOMEM; 17633a6f82f7SJiri Slaby 17643a6f82f7SJiri Slaby dynid->id.bus = bus; 17654d53b801SHenrik Rydberg dynid->id.group = HID_GROUP_ANY; 17663a6f82f7SJiri Slaby dynid->id.vendor = vendor; 17673a6f82f7SJiri Slaby dynid->id.product = product; 17683a6f82f7SJiri Slaby dynid->id.driver_data = driver_data; 17693a6f82f7SJiri Slaby 17703a6f82f7SJiri Slaby spin_lock(&hdrv->dyn_lock); 17713a6f82f7SJiri Slaby list_add_tail(&dynid->list, &hdrv->dyn_list); 17723a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 17733a6f82f7SJiri Slaby 17743a6f82f7SJiri Slaby ret = driver_attach(&hdrv->driver); 17753a6f82f7SJiri Slaby 17763a6f82f7SJiri Slaby return ret ? : count; 17773a6f82f7SJiri Slaby } 17783a6f82f7SJiri Slaby static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 17793a6f82f7SJiri Slaby 17803a6f82f7SJiri Slaby static void hid_free_dynids(struct hid_driver *hdrv) 17813a6f82f7SJiri Slaby { 17823a6f82f7SJiri Slaby struct hid_dynid *dynid, *n; 17833a6f82f7SJiri Slaby 17843a6f82f7SJiri Slaby spin_lock(&hdrv->dyn_lock); 17853a6f82f7SJiri Slaby list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) { 17863a6f82f7SJiri Slaby list_del(&dynid->list); 17873a6f82f7SJiri Slaby kfree(dynid); 17883a6f82f7SJiri Slaby } 17893a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 17903a6f82f7SJiri Slaby } 17913a6f82f7SJiri Slaby 17923a6f82f7SJiri Slaby static const struct hid_device_id *hid_match_device(struct hid_device *hdev, 17933a6f82f7SJiri Slaby struct hid_driver *hdrv) 17943a6f82f7SJiri Slaby { 17953a6f82f7SJiri Slaby struct hid_dynid *dynid; 17963a6f82f7SJiri Slaby 17973a6f82f7SJiri Slaby spin_lock(&hdrv->dyn_lock); 17983a6f82f7SJiri Slaby list_for_each_entry(dynid, &hdrv->dyn_list, list) { 17993a6f82f7SJiri Slaby if (hid_match_one_id(hdev, &dynid->id)) { 18003a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 18013a6f82f7SJiri Slaby return &dynid->id; 18023a6f82f7SJiri Slaby } 18033a6f82f7SJiri Slaby } 18043a6f82f7SJiri Slaby spin_unlock(&hdrv->dyn_lock); 18053a6f82f7SJiri Slaby 18063a6f82f7SJiri Slaby return hid_match_id(hdev, hdrv->id_table); 18073a6f82f7SJiri Slaby } 18083a6f82f7SJiri Slaby 180985cdaf52SJiri Slaby static int hid_bus_match(struct device *dev, struct device_driver *drv) 181085cdaf52SJiri Slaby { 181185cdaf52SJiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 181285cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 181385cdaf52SJiri Slaby 1814070748edSHenrik Rydberg return hid_match_device(hdev, hdrv) != NULL; 181585cdaf52SJiri Slaby } 181685cdaf52SJiri Slaby 181785cdaf52SJiri Slaby static int hid_device_probe(struct device *dev) 181885cdaf52SJiri Slaby { 181985cdaf52SJiri Slaby struct hid_driver *hdrv = container_of(dev->driver, 182085cdaf52SJiri Slaby struct hid_driver, driver); 182185cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 182285cdaf52SJiri Slaby const struct hid_device_id *id; 182385cdaf52SJiri Slaby int ret = 0; 182485cdaf52SJiri Slaby 18254ea54542SDavid Herrmann if (down_interruptible(&hdev->driver_lock)) 18264ea54542SDavid Herrmann return -EINTR; 18274ea54542SDavid Herrmann 182885cdaf52SJiri Slaby if (!hdev->driver) { 18293a6f82f7SJiri Slaby id = hid_match_device(hdev, hdrv); 1830ba623a77SDan Carpenter if (id == NULL) { 1831ba623a77SDan Carpenter ret = -ENODEV; 1832ba623a77SDan Carpenter goto unlock; 1833ba623a77SDan Carpenter } 1834c500c971SJiri Slaby 183585cdaf52SJiri Slaby hdev->driver = hdrv; 1836c500c971SJiri Slaby if (hdrv->probe) { 1837c500c971SJiri Slaby ret = hdrv->probe(hdev, id); 1838c500c971SJiri Slaby } else { /* default probe */ 1839a7197c2eSHenrik Rydberg ret = hid_open_report(hdev); 1840c500c971SJiri Slaby if (!ret) 184193c10132SJiri Slaby ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 1842c500c971SJiri Slaby } 1843a7197c2eSHenrik Rydberg if (ret) { 1844a7197c2eSHenrik Rydberg hid_close_report(hdev); 1845c500c971SJiri Slaby hdev->driver = NULL; 184685cdaf52SJiri Slaby } 1847a7197c2eSHenrik Rydberg } 1848ba623a77SDan Carpenter unlock: 18494ea54542SDavid Herrmann up(&hdev->driver_lock); 185085cdaf52SJiri Slaby return ret; 185185cdaf52SJiri Slaby } 185285cdaf52SJiri Slaby 185385cdaf52SJiri Slaby static int hid_device_remove(struct device *dev) 185485cdaf52SJiri Slaby { 185585cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 18564ea54542SDavid Herrmann struct hid_driver *hdrv; 185785cdaf52SJiri Slaby 18584ea54542SDavid Herrmann if (down_interruptible(&hdev->driver_lock)) 18594ea54542SDavid Herrmann return -EINTR; 18604ea54542SDavid Herrmann 18614ea54542SDavid Herrmann hdrv = hdev->driver; 186285cdaf52SJiri Slaby if (hdrv) { 186385cdaf52SJiri Slaby if (hdrv->remove) 186485cdaf52SJiri Slaby hdrv->remove(hdev); 1865c500c971SJiri Slaby else /* default remove */ 1866c500c971SJiri Slaby hid_hw_stop(hdev); 1867a7197c2eSHenrik Rydberg hid_close_report(hdev); 186885cdaf52SJiri Slaby hdev->driver = NULL; 186985cdaf52SJiri Slaby } 187085cdaf52SJiri Slaby 18714ea54542SDavid Herrmann up(&hdev->driver_lock); 187285cdaf52SJiri Slaby return 0; 187385cdaf52SJiri Slaby } 187485cdaf52SJiri Slaby 18754d53b801SHenrik Rydberg static ssize_t modalias_show(struct device *dev, struct device_attribute *a, 18764d53b801SHenrik Rydberg char *buf) 18774d53b801SHenrik Rydberg { 18784d53b801SHenrik Rydberg struct hid_device *hdev = container_of(dev, struct hid_device, dev); 18794d53b801SHenrik Rydberg int len; 18804d53b801SHenrik Rydberg 18814d53b801SHenrik Rydberg len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n", 18824d53b801SHenrik Rydberg hdev->bus, hdev->group, hdev->vendor, hdev->product); 18834d53b801SHenrik Rydberg 18844d53b801SHenrik Rydberg return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; 18854d53b801SHenrik Rydberg } 18864d53b801SHenrik Rydberg 18874d53b801SHenrik Rydberg static struct device_attribute hid_dev_attrs[] = { 18884d53b801SHenrik Rydberg __ATTR_RO(modalias), 18894d53b801SHenrik Rydberg __ATTR_NULL, 18904d53b801SHenrik Rydberg }; 18914d53b801SHenrik Rydberg 189285cdaf52SJiri Slaby static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) 189385cdaf52SJiri Slaby { 189485cdaf52SJiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 189585cdaf52SJiri Slaby 189685cdaf52SJiri Slaby if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", 189785cdaf52SJiri Slaby hdev->bus, hdev->vendor, hdev->product)) 189885cdaf52SJiri Slaby return -ENOMEM; 189985cdaf52SJiri Slaby 190085cdaf52SJiri Slaby if (add_uevent_var(env, "HID_NAME=%s", hdev->name)) 190185cdaf52SJiri Slaby return -ENOMEM; 190285cdaf52SJiri Slaby 190385cdaf52SJiri Slaby if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys)) 190485cdaf52SJiri Slaby return -ENOMEM; 190585cdaf52SJiri Slaby 190685cdaf52SJiri Slaby if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq)) 190785cdaf52SJiri Slaby return -ENOMEM; 190885cdaf52SJiri Slaby 19094d53b801SHenrik Rydberg if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X", 19104d53b801SHenrik Rydberg hdev->bus, hdev->group, hdev->vendor, hdev->product)) 191185cdaf52SJiri Slaby return -ENOMEM; 191285cdaf52SJiri Slaby 191385cdaf52SJiri Slaby return 0; 191485cdaf52SJiri Slaby } 191585cdaf52SJiri Slaby 191685cdaf52SJiri Slaby static struct bus_type hid_bus_type = { 191785cdaf52SJiri Slaby .name = "hid", 19184d53b801SHenrik Rydberg .dev_attrs = hid_dev_attrs, 191985cdaf52SJiri Slaby .match = hid_bus_match, 192085cdaf52SJiri Slaby .probe = hid_device_probe, 192185cdaf52SJiri Slaby .remove = hid_device_remove, 192285cdaf52SJiri Slaby .uevent = hid_uevent, 192385cdaf52SJiri Slaby }; 192485cdaf52SJiri Slaby 1925bae7eb33SJiri Kosina /* a list of devices that shouldn't be handled by HID core at all */ 1926d458a9dfSJiri Slaby static const struct hid_device_id hid_ignore_list[] = { 1927d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) }, 1928d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) }, 1929d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) }, 1930d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) }, 1931d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) }, 1932d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) }, 1933d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) }, 1934d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) }, 1935d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) }, 1936d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, 1937d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, 1938d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, 193977f720b7SStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)}, 194077f720b7SStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)}, 194162a56582SAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, 194211030183SHans de Goede { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) }, 1943d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, 1944d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, 1945d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, 1946d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) }, 1947d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) }, 1948d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) }, 19495f6108cfSAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) }, 1950d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, 1951d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, 195273bc7d31SMelchior FRANZ { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) }, 1953789aaa2eSDan Delaney { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) }, 1954d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, 195570c66567SPetr Štetiar { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) }, 1956df506f2cSPetr Štetiar { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) }, 1957b1807719SBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) }, 1958d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, 1959d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, 1960d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, 1961d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, 1962d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) }, 1963d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) }, 1964d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) }, 1965d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) }, 1966d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) }, 1967d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) }, 1968d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) }, 1969d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) }, 1970d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) }, 1971d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) }, 1972d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) }, 1973d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) }, 19748e2ce73eSHans de Goede { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) }, 1975d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) }, 1976d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) }, 1977d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) }, 1978d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) }, 1979d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) }, 1980d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) }, 1981d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) }, 1982d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) }, 1983d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) }, 1984d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) }, 1985d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) }, 1986d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) }, 1987d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) }, 1988d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) }, 1989d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) }, 1990d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) }, 1991d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) }, 1992d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) }, 1993d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) }, 1994d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) }, 1995d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) }, 1996d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) }, 1997d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) }, 1998d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) }, 1999d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) }, 2000d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) }, 2001d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) }, 2002d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) }, 2003d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) }, 2004d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) }, 2005d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) }, 2006d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) }, 2007d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) }, 2008d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) }, 2009d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) }, 2010d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) }, 2011d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) }, 2012d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) }, 2013d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) }, 2014d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) }, 2015d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) }, 2016d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) }, 2017d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) }, 2018d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) }, 2019d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) }, 2020d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) }, 2021d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) }, 2022d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) }, 2023c91c21c5SAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) }, 2024d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) }, 2025eb8141ccSLamarque Vieira Souza { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) }, 2026d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, 2027ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) }, 2028d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, 2029ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) }, 2030d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, 2031ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) }, 2032ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) }, 2033ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) }, 2034ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) }, 2035ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) }, 2036ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) }, 2037d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 2038d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 2039d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 2040ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) }, 2041ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) }, 2042ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) }, 2043d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, 2044d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, 2045ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) }, 2046d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, 2047d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, 2048d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, 2049d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, 2050d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, 2051ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) }, 2052ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) }, 2053ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) }, 2054ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) }, 2055ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) }, 2056ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) }, 2057ce97cac8SMichael Hund { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) }, 20583ffb62cbSYuri Khan { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) }, 2059d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, 2060d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, 2061d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, 2062d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) }, 2063d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) }, 2064d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) }, 2065d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) }, 2066d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) }, 2067d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) }, 2068d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) }, 2069d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) }, 2070d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) }, 2071d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) }, 2072d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) }, 2073d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) }, 2074d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) }, 2075d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) }, 2076d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) }, 2077d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, 20784cfae3e8SHenning Glawe { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) }, 207935cfd1d9SMichael Tokarev { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, 20808491ee10SJan Steinhoff #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE) 20818491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) }, 20828491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) }, 20838491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) }, 20848491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) }, 20858491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) }, 20868491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) }, 20878491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) }, 20888491ee10SJan Steinhoff { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) }, 20898491ee10SJan Steinhoff #endif 2090d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, 2091d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, 2092d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, 2093d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, 2094d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) }, 2095d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) }, 2096d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) }, 2097d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) }, 2098d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) }, 2099d458a9dfSJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, 2100d458a9dfSJiri Slaby { } 2101d458a9dfSJiri Slaby }; 2102d458a9dfSJiri Slaby 2103b4d8e473SJiri Slaby /** 2104b4d8e473SJiri Slaby * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer 2105b4d8e473SJiri Slaby * 2106b4d8e473SJiri Slaby * There are composite devices for which we want to ignore only a certain 2107b4d8e473SJiri Slaby * interface. This is a list of devices for which only the mouse interface will 2108b4d8e473SJiri Slaby * be ignored. This allows a dedicated driver to take care of the interface. 2109b4d8e473SJiri Slaby */ 2110b4d8e473SJiri Slaby static const struct hid_device_id hid_mouse_ignore_list[] = { 2111b4d8e473SJiri Slaby /* appletouch driver */ 2112b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 2113b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 2114b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 2115b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 2116b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 2117b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 2118b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 2119b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 2120b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 2121b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 2122b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 2123b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 2124b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 2125b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 2126b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 2127b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 2128b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 2129b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 2130b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 2131b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 2132ac26fca3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 2133ac26fca3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 2134ac26fca3SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 213599b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) }, 213699b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) }, 213799b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) }, 213899b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 213999b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 214099b9f758SEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 214147340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 214247340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 214347340bd9SAndy Botting { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 2144213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) }, 2145213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) }, 2146213f9da8SGökçen Eraslan { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) }, 21474b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) }, 21484b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) }, 21494b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) }, 21504b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) }, 21514b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) }, 21524b086910SJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) }, 2153b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) }, 2154b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) }, 2155b2e6ad7dSRyan Bourgeois { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) }, 21568d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) }, 21578d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) }, 21588d80da90SDirk Hohndel { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) }, 2159b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 2160b4d8e473SJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 2161b4d8e473SJiri Slaby { } 2162b4d8e473SJiri Slaby }; 2163b4d8e473SJiri Slaby 21644529eefaSLamarque V. Souza bool hid_ignore(struct hid_device *hdev) 2165d458a9dfSJiri Slaby { 21664529eefaSLamarque V. Souza if (hdev->quirks & HID_QUIRK_NO_IGNORE) 21674529eefaSLamarque V. Souza return false; 21684529eefaSLamarque V. Souza if (hdev->quirks & HID_QUIRK_IGNORE) 21694529eefaSLamarque V. Souza return true; 21704529eefaSLamarque V. Souza 2171d458a9dfSJiri Slaby switch (hdev->vendor) { 2172d458a9dfSJiri Slaby case USB_VENDOR_ID_CODEMERCS: 2173d458a9dfSJiri Slaby /* ignore all Code Mercenaries IOWarrior devices */ 2174d458a9dfSJiri Slaby if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && 2175d458a9dfSJiri Slaby hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) 2176d458a9dfSJiri Slaby return true; 2177d458a9dfSJiri Slaby break; 2178d458a9dfSJiri Slaby case USB_VENDOR_ID_LOGITECH: 2179d458a9dfSJiri Slaby if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST && 2180d458a9dfSJiri Slaby hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST) 2181d458a9dfSJiri Slaby return true; 218265dd3b69SHans Verkuil /* 218365dd3b69SHans Verkuil * The Keene FM transmitter USB device has the same USB ID as 218465dd3b69SHans Verkuil * the Logitech AudioHub Speaker, but it should ignore the hid. 218565dd3b69SHans Verkuil * Check if the name is that of the Keene device. 218665dd3b69SHans Verkuil * For reference: the name of the AudioHub is 218765dd3b69SHans Verkuil * "HOLTEK AudioHub Speaker". 218865dd3b69SHans Verkuil */ 218965dd3b69SHans Verkuil if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB && 219065dd3b69SHans Verkuil !strcmp(hdev->name, "HOLTEK B-LINK USB Audio ")) 219165dd3b69SHans Verkuil return true; 2192d458a9dfSJiri Slaby break; 219331f7fd79SJarod Wilson case USB_VENDOR_ID_SOUNDGRAPH: 219431f7fd79SJarod Wilson if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST && 219531f7fd79SJarod Wilson hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST) 219631f7fd79SJarod Wilson return true; 219731f7fd79SJarod Wilson break; 2198bba5394aSXing Wei case USB_VENDOR_ID_HANWANG: 2199bba5394aSXing Wei if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST && 2200bba5394aSXing Wei hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST) 2201bba5394aSXing Wei return true; 2202bba5394aSXing Wei break; 22036dc1418eSTomoki Sekiyama case USB_VENDOR_ID_JESS: 22046dc1418eSTomoki Sekiyama if (hdev->product == USB_DEVICE_ID_JESS_YUREX && 22056dc1418eSTomoki Sekiyama hdev->type == HID_TYPE_USBNONE) 22066dc1418eSTomoki Sekiyama return true; 22076dc1418eSTomoki Sekiyama break; 2208729b814aSForest Bond case USB_VENDOR_ID_DWAV: 2209729b814aSForest Bond /* These are handled by usbtouchscreen. hdev->type is probably 2210729b814aSForest Bond * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match 2211729b814aSForest Bond * usbtouchscreen. */ 2212729b814aSForest Bond if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER || 2213729b814aSForest Bond hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) && 2214729b814aSForest Bond hdev->type != HID_TYPE_USBMOUSE) 2215729b814aSForest Bond return true; 2216729b814aSForest Bond break; 221730b6b7d8SIan Abbott case USB_VENDOR_ID_VELLEMAN: 221830b6b7d8SIan Abbott /* These are not HID devices. They are handled by comedi. */ 221930b6b7d8SIan Abbott if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST && 222030b6b7d8SIan Abbott hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) || 222130b6b7d8SIan Abbott (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST && 222230b6b7d8SIan Abbott hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST)) 222330b6b7d8SIan Abbott return true; 222430b6b7d8SIan Abbott break; 22255b4617d8SAlexey Klimov case USB_VENDOR_ID_ATMEL_V_USB: 22265b4617d8SAlexey Klimov /* Masterkit MA901 usb radio based on Atmel tiny85 chip and 22275b4617d8SAlexey Klimov * it has the same USB ID as many Atmel V-USB devices. This 22285b4617d8SAlexey Klimov * usb radio is handled by radio-ma901.c driver so we want 22295b4617d8SAlexey Klimov * ignore the hid. Check the name, bus, product and ignore 22305b4617d8SAlexey Klimov * if we have MA901 usb radio. 22315b4617d8SAlexey Klimov */ 22325b4617d8SAlexey Klimov if (hdev->product == USB_DEVICE_ID_ATMEL_V_USB && 22335b4617d8SAlexey Klimov hdev->bus == BUS_USB && 22345b4617d8SAlexey Klimov strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0) 22355b4617d8SAlexey Klimov return true; 22365b4617d8SAlexey Klimov break; 2237d458a9dfSJiri Slaby } 2238d458a9dfSJiri Slaby 2239b4d8e473SJiri Slaby if (hdev->type == HID_TYPE_USBMOUSE && 2240b4d8e473SJiri Slaby hid_match_id(hdev, hid_mouse_ignore_list)) 2241b4d8e473SJiri Slaby return true; 2242b4d8e473SJiri Slaby 2243d458a9dfSJiri Slaby return !!hid_match_id(hdev, hid_ignore_list); 2244d458a9dfSJiri Slaby } 22454529eefaSLamarque V. Souza EXPORT_SYMBOL_GPL(hid_ignore); 2246d458a9dfSJiri Slaby 224785cdaf52SJiri Slaby int hid_add_device(struct hid_device *hdev) 224885cdaf52SJiri Slaby { 224985cdaf52SJiri Slaby static atomic_t id = ATOMIC_INIT(0); 225085cdaf52SJiri Slaby int ret; 225185cdaf52SJiri Slaby 225285cdaf52SJiri Slaby if (WARN_ON(hdev->status & HID_STAT_ADDED)) 225385cdaf52SJiri Slaby return -EBUSY; 225485cdaf52SJiri Slaby 2255d458a9dfSJiri Slaby /* we need to kill them here, otherwise they will stay allocated to 2256d458a9dfSJiri Slaby * wait for coming driver */ 22574529eefaSLamarque V. Souza if (hid_ignore(hdev)) 2258d458a9dfSJiri Slaby return -ENODEV; 2259d458a9dfSJiri Slaby 2260a7197c2eSHenrik Rydberg /* 2261a7197c2eSHenrik Rydberg * Read the device report descriptor once and use as template 2262a7197c2eSHenrik Rydberg * for the driver-specific modifications. 2263a7197c2eSHenrik Rydberg */ 2264a7197c2eSHenrik Rydberg ret = hdev->ll_driver->parse(hdev); 2265a7197c2eSHenrik Rydberg if (ret) 2266a7197c2eSHenrik Rydberg return ret; 2267a7197c2eSHenrik Rydberg if (!hdev->dev_rdesc) 2268a7197c2eSHenrik Rydberg return -ENODEV; 2269a7197c2eSHenrik Rydberg 2270734c6609SHenrik Rydberg /* 2271734c6609SHenrik Rydberg * Scan generic devices for group information 2272734c6609SHenrik Rydberg */ 2273734c6609SHenrik Rydberg if (hid_ignore_special_drivers || 2274734c6609SHenrik Rydberg !hid_match_id(hdev, hid_have_special_driver)) { 2275734c6609SHenrik Rydberg ret = hid_scan_report(hdev); 2276734c6609SHenrik Rydberg if (ret) 2277734c6609SHenrik Rydberg hid_warn(hdev, "bad device descriptor (%d)\n", ret); 2278734c6609SHenrik Rydberg } 2279734c6609SHenrik Rydberg 22806bbe586fSKay Sievers /* XXX hack, any other cleaner solution after the driver core 22816bbe586fSKay Sievers * is converted to allow more than 20 bytes as the device name? */ 22826bbe586fSKay Sievers dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, 228385cdaf52SJiri Slaby hdev->vendor, hdev->product, atomic_inc_return(&id)); 228485cdaf52SJiri Slaby 22854da361b6SBruno Prémont hid_debug_register(hdev, dev_name(&hdev->dev)); 228685cdaf52SJiri Slaby ret = device_add(&hdev->dev); 228785cdaf52SJiri Slaby if (!ret) 228885cdaf52SJiri Slaby hdev->status |= HID_STAT_ADDED; 22894da361b6SBruno Prémont else 22904da361b6SBruno Prémont hid_debug_unregister(hdev); 2291a635f9ddSJiri Kosina 229285cdaf52SJiri Slaby return ret; 229385cdaf52SJiri Slaby } 229485cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_add_device); 229585cdaf52SJiri Slaby 229685cdaf52SJiri Slaby /** 229785cdaf52SJiri Slaby * hid_allocate_device - allocate new hid device descriptor 229885cdaf52SJiri Slaby * 229985cdaf52SJiri Slaby * Allocate and initialize hid device, so that hid_destroy_device might be 230085cdaf52SJiri Slaby * used to free it. 230185cdaf52SJiri Slaby * 230285cdaf52SJiri Slaby * New hid_device pointer is returned on success, otherwise ERR_PTR encoded 230385cdaf52SJiri Slaby * error value. 230485cdaf52SJiri Slaby */ 230585cdaf52SJiri Slaby struct hid_device *hid_allocate_device(void) 230685cdaf52SJiri Slaby { 230785cdaf52SJiri Slaby struct hid_device *hdev; 230885cdaf52SJiri Slaby int ret = -ENOMEM; 230985cdaf52SJiri Slaby 231085cdaf52SJiri Slaby hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); 231185cdaf52SJiri Slaby if (hdev == NULL) 231285cdaf52SJiri Slaby return ERR_PTR(ret); 231385cdaf52SJiri Slaby 231485cdaf52SJiri Slaby device_initialize(&hdev->dev); 231585cdaf52SJiri Slaby hdev->dev.release = hid_device_release; 231685cdaf52SJiri Slaby hdev->dev.bus = &hid_bus_type; 231785cdaf52SJiri Slaby 2318a7197c2eSHenrik Rydberg hid_close_report(hdev); 231985cdaf52SJiri Slaby 2320cd667ce2SJiri Kosina init_waitqueue_head(&hdev->debug_wait); 2321cd667ce2SJiri Kosina INIT_LIST_HEAD(&hdev->debug_list); 23224ea54542SDavid Herrmann sema_init(&hdev->driver_lock, 1); 2323cd667ce2SJiri Kosina 232485cdaf52SJiri Slaby return hdev; 232585cdaf52SJiri Slaby } 232685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_allocate_device); 232785cdaf52SJiri Slaby 232885cdaf52SJiri Slaby static void hid_remove_device(struct hid_device *hdev) 232985cdaf52SJiri Slaby { 233085cdaf52SJiri Slaby if (hdev->status & HID_STAT_ADDED) { 233185cdaf52SJiri Slaby device_del(&hdev->dev); 2332a635f9ddSJiri Kosina hid_debug_unregister(hdev); 233385cdaf52SJiri Slaby hdev->status &= ~HID_STAT_ADDED; 233485cdaf52SJiri Slaby } 2335a7197c2eSHenrik Rydberg kfree(hdev->dev_rdesc); 2336a7197c2eSHenrik Rydberg hdev->dev_rdesc = NULL; 2337a7197c2eSHenrik Rydberg hdev->dev_rsize = 0; 233885cdaf52SJiri Slaby } 233985cdaf52SJiri Slaby 234085cdaf52SJiri Slaby /** 234185cdaf52SJiri Slaby * hid_destroy_device - free previously allocated device 234285cdaf52SJiri Slaby * 234385cdaf52SJiri Slaby * @hdev: hid device 234485cdaf52SJiri Slaby * 234585cdaf52SJiri Slaby * If you allocate hid_device through hid_allocate_device, you should ever 234685cdaf52SJiri Slaby * free by this function. 234785cdaf52SJiri Slaby */ 234885cdaf52SJiri Slaby void hid_destroy_device(struct hid_device *hdev) 234985cdaf52SJiri Slaby { 235085cdaf52SJiri Slaby hid_remove_device(hdev); 235185cdaf52SJiri Slaby put_device(&hdev->dev); 235285cdaf52SJiri Slaby } 235385cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_destroy_device); 235485cdaf52SJiri Slaby 235585cdaf52SJiri Slaby int __hid_register_driver(struct hid_driver *hdrv, struct module *owner, 235685cdaf52SJiri Slaby const char *mod_name) 235785cdaf52SJiri Slaby { 23583a6f82f7SJiri Slaby int ret; 23593a6f82f7SJiri Slaby 236085cdaf52SJiri Slaby hdrv->driver.name = hdrv->name; 236185cdaf52SJiri Slaby hdrv->driver.bus = &hid_bus_type; 236285cdaf52SJiri Slaby hdrv->driver.owner = owner; 236385cdaf52SJiri Slaby hdrv->driver.mod_name = mod_name; 236485cdaf52SJiri Slaby 23653a6f82f7SJiri Slaby INIT_LIST_HEAD(&hdrv->dyn_list); 23663a6f82f7SJiri Slaby spin_lock_init(&hdrv->dyn_lock); 23673a6f82f7SJiri Slaby 23683a6f82f7SJiri Slaby ret = driver_register(&hdrv->driver); 23693a6f82f7SJiri Slaby if (ret) 23703a6f82f7SJiri Slaby return ret; 23713a6f82f7SJiri Slaby 23723a6f82f7SJiri Slaby ret = driver_create_file(&hdrv->driver, &driver_attr_new_id); 23733a6f82f7SJiri Slaby if (ret) 23743a6f82f7SJiri Slaby driver_unregister(&hdrv->driver); 23753a6f82f7SJiri Slaby 23763a6f82f7SJiri Slaby return ret; 237785cdaf52SJiri Slaby } 237885cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(__hid_register_driver); 237985cdaf52SJiri Slaby 238085cdaf52SJiri Slaby void hid_unregister_driver(struct hid_driver *hdrv) 238185cdaf52SJiri Slaby { 23823a6f82f7SJiri Slaby driver_remove_file(&hdrv->driver, &driver_attr_new_id); 238385cdaf52SJiri Slaby driver_unregister(&hdrv->driver); 23843a6f82f7SJiri Slaby hid_free_dynids(hdrv); 238585cdaf52SJiri Slaby } 238685cdaf52SJiri Slaby EXPORT_SYMBOL_GPL(hid_unregister_driver); 238785cdaf52SJiri Slaby 23880361a28dSOliver Neukum int hid_check_keys_pressed(struct hid_device *hid) 23890361a28dSOliver Neukum { 23900361a28dSOliver Neukum struct hid_input *hidinput; 23910361a28dSOliver Neukum int i; 23920361a28dSOliver Neukum 2393e5288eb5SJiri Kosina if (!(hid->claimed & HID_CLAIMED_INPUT)) 2394e5288eb5SJiri Kosina return 0; 2395e5288eb5SJiri Kosina 23960361a28dSOliver Neukum list_for_each_entry(hidinput, &hid->inputs, list) { 23970361a28dSOliver Neukum for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++) 23980361a28dSOliver Neukum if (hidinput->input->key[i]) 23990361a28dSOliver Neukum return 1; 24000361a28dSOliver Neukum } 24010361a28dSOliver Neukum 24020361a28dSOliver Neukum return 0; 24030361a28dSOliver Neukum } 24040361a28dSOliver Neukum 24050361a28dSOliver Neukum EXPORT_SYMBOL_GPL(hid_check_keys_pressed); 24060361a28dSOliver Neukum 240786166b7bSJiri Kosina static int __init hid_init(void) 240886166b7bSJiri Kosina { 240985cdaf52SJiri Slaby int ret; 241085cdaf52SJiri Slaby 2411a635f9ddSJiri Kosina if (hid_debug) 24124291ee30SJoe Perches pr_warn("hid_debug is now used solely for parser and driver debugging.\n" 24134291ee30SJoe Perches "debugfs is now used for inspecting the device (report descriptor, reports)\n"); 2414a635f9ddSJiri Kosina 241585cdaf52SJiri Slaby ret = bus_register(&hid_bus_type); 241685cdaf52SJiri Slaby if (ret) { 24174291ee30SJoe Perches pr_err("can't register hid bus\n"); 241885cdaf52SJiri Slaby goto err; 241985cdaf52SJiri Slaby } 242085cdaf52SJiri Slaby 242185cdaf52SJiri Slaby ret = hidraw_init(); 242285cdaf52SJiri Slaby if (ret) 242385cdaf52SJiri Slaby goto err_bus; 242485cdaf52SJiri Slaby 2425a635f9ddSJiri Kosina hid_debug_init(); 2426a635f9ddSJiri Kosina 242785cdaf52SJiri Slaby return 0; 242885cdaf52SJiri Slaby err_bus: 242985cdaf52SJiri Slaby bus_unregister(&hid_bus_type); 243085cdaf52SJiri Slaby err: 243185cdaf52SJiri Slaby return ret; 243286166b7bSJiri Kosina } 243386166b7bSJiri Kosina 243486166b7bSJiri Kosina static void __exit hid_exit(void) 243586166b7bSJiri Kosina { 2436a635f9ddSJiri Kosina hid_debug_exit(); 243786166b7bSJiri Kosina hidraw_exit(); 243885cdaf52SJiri Slaby bus_unregister(&hid_bus_type); 243986166b7bSJiri Kosina } 244086166b7bSJiri Kosina 244186166b7bSJiri Kosina module_init(hid_init); 244286166b7bSJiri Kosina module_exit(hid_exit); 244386166b7bSJiri Kosina 244488adb72bSJiri Kosina MODULE_AUTHOR("Andreas Gal"); 244588adb72bSJiri Kosina MODULE_AUTHOR("Vojtech Pavlik"); 244688adb72bSJiri Kosina MODULE_AUTHOR("Jiri Kosina"); 2447aa938f79SJiri Kosina MODULE_LICENSE(DRIVER_LICENSE); 2448aa938f79SJiri Kosina 2449