hid-core.c revision d586dca06adddc6cee7177b013ee93eaffc9fe0e
1dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 2229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina * HID support for Linux 3dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * 4dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Copyright (c) 1999 Andreas Gal 5dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 6dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 77d39e849912f0c3c8c6fc94be7bf7d120b1ee0baJiri Kosina * Copyright (c) 2006-2010 Jiri Kosina 8dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 9dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 10dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 11dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * This program is free software; you can redistribute it and/or modify it 12dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * under the terms of the GNU General Public License as published by the Free 13dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Software Foundation; either version 2 of the License, or (at your option) 14dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * any later version. 15dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 16dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 174291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 184291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches 19dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/module.h> 20dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/slab.h> 21dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/init.h> 22dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/kernel.h> 23dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/list.h> 24dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/mm.h> 25dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/spinlock.h> 26dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <asm/unaligned.h> 27dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <asm/byteorder.h> 28dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/input.h> 29dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/wait.h> 3047a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina#include <linux/vmalloc.h> 31c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina#include <linux/sched.h> 32dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 33dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/hid.h> 34dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/hiddev.h> 35c080d89ad91e98fec0e8fc5f448a1ad899bd85c7Jiri Kosina#include <linux/hid-debug.h> 3686166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina#include <linux/hidraw.h> 37dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 385f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby#include "hid-ids.h" 395f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby 40dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 41dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Version Information 42dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 43dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 44531498013163c72cee8540e98e12c0c430c7fe87Jiri Kosina#define DRIVER_DESC "HID core driver" 45dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#define DRIVER_LICENSE "GPL" 46dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 4758037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosinaint hid_debug = 0; 48377e10fbb4ef219f540d06796e9fb0d3ec35a58fAnssi Hannulamodule_param_named(debug, hid_debug, int, 0600); 49cd667ce24796700e1a0e6e7528efc61c96ff832eJiri KosinaMODULE_PARM_DESC(debug, "toggle HID debugging messages"); 5058037eb961f859607b161c50d9d4ecb374de1e8fJiri KosinaEXPORT_SYMBOL_GPL(hid_debug); 5158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina 52dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 53dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new report for a device. 54dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 55dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 5690a006abf8015c8cab893555244d8fc673b24839Michael Poolestruct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) 57dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 58dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report_enum *report_enum = device->report_enum + type; 59dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report *report; 60dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 61dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report_enum->report_id_hash[id]) 62dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return report_enum->report_id_hash[id]; 63dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 64a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches report = kzalloc(sizeof(struct hid_report), GFP_KERNEL); 65a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches if (!report) 66dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 67dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 68dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (id != 0) 69dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report_enum->numbered = 1; 70dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 71dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->id = id; 72dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->type = type; 73dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->size = 0; 74dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->device = device; 75dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report_enum->report_id_hash[id] = report; 76dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 77dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina list_add_tail(&report->list, &report_enum->report_list); 78dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 79dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return report; 80dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 8190a006abf8015c8cab893555244d8fc673b24839Michael PooleEXPORT_SYMBOL_GPL(hid_register_report); 82dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 83dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 84dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new field for this report. 85dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 86dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 87dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values) 88dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 89dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_field *field; 90dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 91dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report->maxfield == HID_MAX_FIELDS) { 9258037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("too many fields in report\n"); 93dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 94dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 95dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 96a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches field = kzalloc((sizeof(struct hid_field) + 97a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches usages * sizeof(struct hid_usage) + 98a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches values * sizeof(unsigned)), GFP_KERNEL); 99a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches if (!field) 100a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches return NULL; 101dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 102dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->index = report->maxfield++; 103dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->field[field->index] = field; 104dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->usage = (struct hid_usage *)(field + 1); 105282bfd4cbcc2bbeb1a2cad1f42debd378e0b5ac9Jiri Slaby field->value = (s32 *)(field->usage + usages); 106dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report = report; 107dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 108dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return field; 109dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 110dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 111dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 112dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Open a collection. The type/usage is pushed on the stack. 113dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 114dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 115dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int open_collection(struct hid_parser *parser, unsigned type) 116dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 117dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_collection *collection; 118dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned usage; 119dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 120dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina usage = parser->local.usage[0]; 121dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 122dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { 12358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("collection stack overflow\n"); 124dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 125dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 126dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 127dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->device->maxcollection == parser->device->collection_size) { 128dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection = kmalloc(sizeof(struct hid_collection) * 129dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size * 2, GFP_KERNEL); 130dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (collection == NULL) { 13158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("failed to reallocate collection array\n"); 132dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 133dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 134dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memcpy(collection, parser->device->collection, 135dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina sizeof(struct hid_collection) * 136dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size); 137dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memset(collection + parser->device->collection_size, 0, 138dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina sizeof(struct hid_collection) * 139dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size); 140dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(parser->device->collection); 141dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection = collection; 142dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size *= 2; 143dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 144dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 145dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack[parser->collection_stack_ptr++] = 146dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->maxcollection; 147dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 148dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection = parser->device->collection + 149dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->maxcollection++; 150dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection->type = type; 151dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection->usage = usage; 152dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection->level = parser->collection_stack_ptr - 1; 153dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 154dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (type == HID_COLLECTION_APPLICATION) 155dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->maxapplication++; 156dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 157dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 158dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 159dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 160dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 161dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Close a collection. 162dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 163dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 164dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int close_collection(struct hid_parser *parser) 165dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 166dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!parser->collection_stack_ptr) { 16758037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("collection stack underflow\n"); 168dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 169dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 170dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack_ptr--; 171dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 172dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 173dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 174dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 175dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Climb up the stack, search for the specified collection type 176dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * and return the usage. 177dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 178dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 179dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) 180dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 181504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches struct hid_collection *collection = parser->device->collection; 182dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int n; 183504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches 184504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches for (n = parser->collection_stack_ptr - 1; n >= 0; n--) { 185504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches unsigned index = parser->collection_stack[n]; 186504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches if (collection[index].type == type) 187504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches return collection[index].usage; 188504499f22c08a03e2e19dc88d31aa0ecd2ac815eJoe Perches } 189dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; /* we know nothing about this usage type */ 190dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 191dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 192dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 193dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Add a usage to the temporary parser table. 194dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 195dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 196dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_add_usage(struct hid_parser *parser, unsigned usage) 197dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 198dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->local.usage_index >= HID_MAX_USAGES) { 19958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("usage index exceeded\n"); 200dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 201dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 202dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.usage[parser->local.usage_index] = usage; 203dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.collection_index[parser->local.usage_index] = 204dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack_ptr ? 205dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack[parser->collection_stack_ptr - 1] : 0; 206dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.usage_index++; 207dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 208dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 209dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 210dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 211dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new field for this report. 212dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 213dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 214dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags) 215dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 216dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report *report; 217dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_field *field; 218dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int usages; 219dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned offset; 220dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int i; 221dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 222a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches report = hid_register_report(parser->device, report_type, parser->global.report_id); 223a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches if (!report) { 22458037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("hid_register_report failed\n"); 225dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 226dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 227dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 228dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->global.logical_maximum < parser->global.logical_minimum) { 22958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum); 230dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 231dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 232dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 233dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina offset = report->size; 234dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->size += parser->global.report_size * parser->global.report_count; 235dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 236dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!parser->local.usage_index) /* Ignore padding fields */ 237dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 238dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 239dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina usages = max_t(int, parser->local.usage_index, parser->global.report_count); 240dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 241a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches field = hid_register_field(report, usages, parser->global.report_count); 242a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches if (!field) 243dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 244dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 245dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); 246dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); 247dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); 248dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 249dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (i = 0; i < usages; i++) { 250dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int j = i; 251dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina /* Duplicate the last usage we parsed if we have excess values */ 252dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (i >= parser->local.usage_index) 253dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina j = parser->local.usage_index - 1; 254dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->usage[i].hid = parser->local.usage[j]; 255dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->usage[i].collection_index = 256dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.collection_index[j]; 257dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 258dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 259dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->maxusage = usages; 260dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->flags = flags; 261dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_offset = offset; 262dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_type = report_type; 263dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_size = parser->global.report_size; 264dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_count = parser->global.report_count; 265dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->logical_minimum = parser->global.logical_minimum; 266dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->logical_maximum = parser->global.logical_maximum; 267dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->physical_minimum = parser->global.physical_minimum; 268dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->physical_maximum = parser->global.physical_maximum; 269dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->unit_exponent = parser->global.unit_exponent; 270dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->unit = parser->global.unit; 271dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 272dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 273dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 274dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 275dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 276dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Read data value from item. 277dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 278dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 279dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u32 item_udata(struct hid_item *item) 280dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 281dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->size) { 282880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 1: return item->data.u8; 283880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 2: return item->data.u16; 284880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 4: return item->data.u32; 285dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 286dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 287dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 288dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 289dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic s32 item_sdata(struct hid_item *item) 290dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 291dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->size) { 292880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 1: return item->data.s8; 293880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 2: return item->data.s16; 294880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 4: return item->data.s32; 295dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 296dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 297dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 298dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 299dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 300dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a global item. 301dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 302dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 303dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_global(struct hid_parser *parser, struct hid_item *item) 304dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 305dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->tag) { 306880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_PUSH: 307dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 308880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { 309880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("global enviroment stack overflow\n"); 310880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 311880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 312dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 313880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby memcpy(parser->global_stack + parser->global_stack_ptr++, 314880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby &parser->global, sizeof(struct hid_global)); 315880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 316dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 317880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_POP: 318dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 319880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (!parser->global_stack_ptr) { 320880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("global enviroment stack underflow\n"); 321880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 322880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 323dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 324880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby memcpy(&parser->global, parser->global_stack + 325880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby --parser->global_stack_ptr, sizeof(struct hid_global)); 326880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 327dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 328880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: 329880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.usage_page = item_udata(item); 330880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 331dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 332880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: 333880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.logical_minimum = item_sdata(item); 334880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 335dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 336880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: 337880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.logical_minimum < 0) 338880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.logical_maximum = item_sdata(item); 339880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby else 340880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.logical_maximum = item_udata(item); 341880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 342dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 343880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: 344880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.physical_minimum = item_sdata(item); 345880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 346dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 347880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: 348880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.physical_minimum < 0) 349880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.physical_maximum = item_sdata(item); 350880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby else 351880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.physical_maximum = item_udata(item); 352880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 353dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 354880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: 355880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.unit_exponent = item_sdata(item); 356880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 357dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 358880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_UNIT: 359880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.unit = item_udata(item); 360880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 361dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 362880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: 363880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_size = item_udata(item); 364880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.report_size > 32) { 365880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("invalid report_size %d\n", 366880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_size); 367880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 368880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 369880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 370dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 371880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: 372880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_count = item_udata(item); 373880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.report_count > HID_MAX_USAGES) { 374880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("invalid report_count %d\n", 375880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_count); 376880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 377880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 378880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 379dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 380880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_REPORT_ID: 381880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_id = item_udata(item); 382880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.report_id == 0) { 383880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("report_id 0 is invalid\n"); 384dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 385880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 386880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 387880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 388880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby default: 389880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("unknown global tag 0x%x\n", item->tag); 390880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 391dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 392dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 393dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 394dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 395dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a local item. 396dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 397dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 398dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_local(struct hid_parser *parser, struct hid_item *item) 399dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 400dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __u32 data; 401dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 402dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 403dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina data = item_udata(item); 404dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 405dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->tag) { 406880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_DELIMITER: 407880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 408880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (data) { 409880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby /* 410880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * We treat items before the first delimiter 411880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * as global to all usage sets (branch 0). 412880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * In the moment we process only these global 413880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * items and the first delimiter set. 414880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby */ 415880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_depth != 0) { 416880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("nested delimiters\n"); 417880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 418dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 419880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.delimiter_depth++; 420880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.delimiter_branch++; 421880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } else { 422880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_depth < 1) { 423880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("bogus close delimiter\n"); 424880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 425dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 426880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.delimiter_depth--; 427880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 428880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 1; 429dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 430880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_USAGE: 431dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 432880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_branch > 1) { 433880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("alternative usage ignored\n"); 434880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 435880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 436dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 437880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (item->size <= 2) 438880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby data = (parser->global.usage_page << 16) + data; 439dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 440880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return hid_add_usage(parser, data); 441dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 442880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: 443dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 444880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_branch > 1) { 445880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("alternative usage ignored\n"); 446dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 447880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 448dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 449880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (item->size <= 2) 450880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby data = (parser->global.usage_page << 16) + data; 451dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 452880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.usage_minimum = data; 453880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 454dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 455880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: 456dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 457880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_branch > 1) { 458880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("alternative usage ignored\n"); 459dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 460880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 461dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 462880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (item->size <= 2) 463880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby data = (parser->global.usage_page << 16) + data; 464dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 465880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby for (n = parser->local.usage_minimum; n <= data; n++) 466880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (hid_add_usage(parser, n)) { 467880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("hid_add_usage failed\n"); 468880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 469880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 470880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 471880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 472880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby default: 473880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 474880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("unknown local item tag 0x%x\n", item->tag); 475880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 476dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 477dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 478dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 479dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 480dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 481dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a main item. 482dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 483dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 484dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_main(struct hid_parser *parser, struct hid_item *item) 485dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 486dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __u32 data; 487dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int ret; 488dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 489dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina data = item_udata(item); 490dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 491dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->tag) { 492880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: 493880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = open_collection(parser, data & 0xff); 494880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 495880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_END_COLLECTION: 496880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = close_collection(parser); 497880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 498880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_INPUT: 499880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = hid_add_field(parser, HID_INPUT_REPORT, data); 500880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 501880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_OUTPUT: 502880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); 503880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 504880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_FEATURE: 505880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = hid_add_field(parser, HID_FEATURE_REPORT, data); 506880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 507880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby default: 508880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("unknown main item tag 0x%x\n", item->tag); 509880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = 0; 510dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 511dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 512dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ 513dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 514dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return ret; 515dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 516dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 517dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 518dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a reserved item. 519dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 520dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 521dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item) 522dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 52358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("reserved item type, tag 0x%x\n", item->tag); 524dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 525dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 526dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 527dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 528dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Free a report and all registered fields. The field->usage and 529dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * field->value table's are allocated behind the field, so we need 530dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * only to free(field) itself. 531dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 532dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 533dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic void hid_free_report(struct hid_report *report) 534dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 535dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 536dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 537dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < report->maxfield; n++) 538dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(report->field[n]); 539dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(report); 540dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 541dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 542dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 543dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Free a device structure, all reports, and all fields. 544dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 545dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 54685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_device_release(struct device *dev) 547dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 54885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *device = container_of(dev, struct hid_device, dev); 54985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned i, j; 550dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 551dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (i = 0; i < HID_REPORT_TYPES; i++) { 552dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report_enum *report_enum = device->report_enum + i; 553dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 554dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (j = 0; j < 256; j++) { 555dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report *report = report_enum->report_id_hash[j]; 556dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report) 557dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_free_report(report); 558dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 559dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 560dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 561dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(device->rdesc); 562767fe7877c2928b5633992ee60a49ad4516dc2afJiri Kosina kfree(device->collection); 563dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(device); 564dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 565dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 566dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 567dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Fetch a report description item from the data stream. We support long 568dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * items, though they are not used yet. 569dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 570dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 571dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) 572dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 573dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina u8 b; 574dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 575dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((end - start) <= 0) 576dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 577dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 578dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina b = *start++; 579dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 580dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->type = (b >> 2) & 3; 581dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->tag = (b >> 4) & 15; 582dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 583dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (item->tag == HID_ITEM_TAG_LONG) { 584dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 585dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->format = HID_ITEM_FORMAT_LONG; 586dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 587dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((end - start) < 2) 588dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 589dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 590dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->size = *start++; 591dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->tag = *start++; 592dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 593dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((end - start) < item->size) 594dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 595dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 596dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->data.longdata = start; 597dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina start += item->size; 598dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return start; 599dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 600dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 601dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->format = HID_ITEM_FORMAT_SHORT; 602dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->size = b & 3; 603dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 604dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->size) { 605880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 0: 606880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 607dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 608880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 1: 609880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if ((end - start) < 1) 610880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return NULL; 611880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->data.u8 = *start++; 612880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 613880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 614880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 2: 615880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if ((end - start) < 2) 616880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return NULL; 617880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->data.u16 = get_unaligned_le16(start); 618880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby start = (__u8 *)((__le16 *)start + 1); 619880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 620880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 621880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 3: 622880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->size++; 623880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if ((end - start) < 4) 624880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return NULL; 625880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->data.u32 = get_unaligned_le32(start); 626880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby start = (__u8 *)((__le32 *)start + 1); 627880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 628dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 629dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 630dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 631dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 632dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 63385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 63485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_parse_report - parse device report 63585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 63685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @device: hid device 63785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @start: report start 63885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @size: report size 63985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 640dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Parse a report description into a hid_device structure. Reports are 641dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * enumerated, fields are attached to these reports. 64285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 0 returned on success, otherwise nonzero error value. 643dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 64485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_parse_report(struct hid_device *device, __u8 *start, 64585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned size) 646dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 647dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_parser *parser; 648dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_item item; 649dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __u8 *end; 65085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 651dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina static int (*dispatch_type[])(struct hid_parser *parser, 652dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_item *item) = { 653dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_main, 654dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_global, 655dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_local, 656dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_reserved 657dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina }; 658dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 659c500c9714011edab021591340042787722db9cf0Jiri Slaby if (device->driver->report_fixup) 66073e4008ddddc84d5f2499c17012b340a0dae153eNikolai Kondrashov start = device->driver->report_fixup(device, start, &size); 661c500c9714011edab021591340042787722db9cf0Jiri Slaby 6621721a238ba5df9e870ed952464d38714261f5be9Julia Lawall device->rdesc = kmemdup(start, size, GFP_KERNEL); 66385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (device->rdesc == NULL) 66485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 665dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina device->rsize = size; 666dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 667fe2580204d8bbcd18540736a283ed0b784c6a024Joe Perches parser = vzalloc(sizeof(struct hid_parser)); 66885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!parser) { 66985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = -ENOMEM; 67085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 671dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 67285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 673dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device = device; 674dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 675dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina end = start + size; 67685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = -EINVAL; 677dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina while ((start = fetch_item(start, end, &item)) != NULL) { 678dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 679dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (item.format != HID_ITEM_FORMAT_SHORT) { 68058037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("unexpected long global item\n"); 68185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 682dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 683dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 684dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (dispatch_type[item.type](parser, &item)) { 68558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("item %u %u %u %u parsing failed\n", 6864291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches item.format, (unsigned)item.size, 6874291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches (unsigned)item.type, (unsigned)item.tag); 68885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 689dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 690dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 691dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (start == end) { 692dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->collection_stack_ptr) { 69358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("unbalanced collection at end of report description\n"); 69485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 695dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 696dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->local.delimiter_depth) { 69758037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("unbalanced delimiter at end of report description\n"); 69885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 699dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 70047a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina vfree(parser); 70185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 702dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 703dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 704dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 70558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("item fetching failed at offset %d\n", (int)(end - start)); 70685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr: 70747a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina vfree(parser); 70885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 709dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 710229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_parse_report); 711dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 712dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 713dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Convert a signed n-bit integer to signed 32-bit integer. Common 714dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * cases are done through the compiler, the screwed things has to be 715dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * done by hand. 716dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 717dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 718dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic s32 snto32(__u32 value, unsigned n) 719dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 720dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (n) { 721880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 8: return ((__s8)value); 722880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 16: return ((__s16)value); 723880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 32: return ((__s32)value); 724dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 725dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return value & (1 << (n - 1)) ? value | (-1 << n) : value; 726dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 727dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 728dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 729dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Convert a signed 32-bit integer to a signed n-bit integer. 730dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 731dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 732dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u32 s32ton(__s32 value, unsigned n) 733dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 734dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina s32 a = value >> (n - 1); 735dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (a && a != -1) 736dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; 737dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return value & ((1 << n) - 1); 738dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 739dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 740dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 741dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Extract/implement a data field from/to a little endian report (bit array). 742dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * 743dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Code sort-of follows HID spec: 744dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * http://www.usb.org/developers/devclass_docs/HID1_11.pdf 745dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * 746dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * While the USB HID spec allows unlimited length bit fields in "report 747dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * descriptors", most devices never use more than 16 bits. 748dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * One model of UPS is claimed to report "LINEV" as a 32-bit field. 749dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Search linux-kernel and linux-usb-devel archives for "hid-core extract". 750dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 751dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 75216ee4cc82b5dbb81a5dbfedcdb268b9467fe4605Joe Perchesstatic __u32 extract(const struct hid_device *hid, __u8 *report, 75316ee4cc82b5dbb81a5dbfedcdb268b9467fe4605Joe Perches unsigned offset, unsigned n) 754dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 755dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina u64 x; 756dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 757c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina if (n > 32) 7584291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n", 7594291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches n, current->comm); 760dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 761dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report += offset >> 3; /* adjust byte index */ 762229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina offset &= 7; /* now only need bit offset into one byte */ 763c105068f2b35343eecf2bf16ee29a362b6121fa3Harvey Harrison x = get_unaligned_le64(report); 764229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */ 765dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return (u32) x; 766dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 767dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 768dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 769dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * "implement" : set bits in a little endian bit stream. 770dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Same concepts as "extract" (see comments above). 771dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * The data mangled in the bit stream remains in little endian 772dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * order the whole time. It make more sense to talk about 773dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * endianness of register values by considering a register 774dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * a "cached" copy of the little endiad bit stream. 775dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 77616ee4cc82b5dbb81a5dbfedcdb268b9467fe4605Joe Perchesstatic void implement(const struct hid_device *hid, __u8 *report, 77716ee4cc82b5dbb81a5dbfedcdb268b9467fe4605Joe Perches unsigned offset, unsigned n, __u32 value) 778dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 7796f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison u64 x; 780dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina u64 m = (1ULL << n) - 1; 781dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 782c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina if (n > 32) 7834291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n", 7844291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches __func__, n, current->comm); 785dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 786c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina if (value > m) 7874291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches hid_warn(hid, "%s() called with too large value %d! (%s)\n", 7884291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches __func__, value, current->comm); 789dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina WARN_ON(value > m); 790dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina value &= m; 791dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 792dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report += offset >> 3; 793dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina offset &= 7; 794dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 7956f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison x = get_unaligned_le64(report); 7966f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison x &= ~(m << offset); 7976f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison x |= ((u64)value) << offset; 7986f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison put_unaligned_le64(x, report); 799dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 800dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 801dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 802dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Search an array for a value. 803dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 804dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 80516ee4cc82b5dbb81a5dbfedcdb268b9467fe4605Joe Perchesstatic int search(__s32 *array, __s32 value, unsigned n) 806dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 807dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina while (n--) { 808dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (*array++ == value) 809dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 810dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 811dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 812dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 813dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 81485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 81585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_match_report - check if driver's raw_event should be called 81685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 81785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device 81885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @report_type: type to match against 81985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 82085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * compare hid->driver->report_table->report_type to report->type 82185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 82285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_match_report(struct hid_device *hid, struct hid_report *report) 823dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 82485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const struct hid_report_id *id = hid->driver->report_table; 82585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 82685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!id) /* NULL means all */ 82785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 82885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 82985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (; id->report_type != HID_TERMINATOR; id++) 83085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (id->report_type == HID_ANY_ID || 83185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->report_type == report->type) 83285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 83385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 83485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 83585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 83685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 83785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_match_usage - check if driver's event should be called 83885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 83985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device 84085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @usage: usage to match against 84185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 84285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * compare hid->driver->usage_table->usage_{type,code} to 84385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * usage->usage_{type,code} 84485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 84585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_match_usage(struct hid_device *hid, struct hid_usage *usage) 84685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 84785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const struct hid_usage_id *id = hid->driver->usage_table; 84885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 84985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!id) /* NULL means all */ 85085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 85185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 85285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (; id->usage_type != HID_ANY_ID - 1; id++) 85385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if ((id->usage_hid == HID_ANY_ID || 85485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->usage_hid == usage->hid) && 85585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby (id->usage_type == HID_ANY_ID || 85685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->usage_type == usage->type) && 85785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby (id->usage_code == HID_ANY_ID || 85885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->usage_code == usage->code)) 85985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 86085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 86185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 86285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 86385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_process_event(struct hid_device *hid, struct hid_field *field, 86485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_usage *usage, __s32 value, int interrupt) 86585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 86685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = hid->driver; 86785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 86885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 869cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina hid_dump_input(hid, usage, value); 87085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 87185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv && hdrv->event && hid_match_usage(hid, usage)) { 87285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = hdrv->event(hid, field, usage, value); 87385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret != 0) { 87485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret < 0) 87585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("%s's event failed with %d\n", 87685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->name, ret); 87785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return; 87885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 87985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 88085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 881dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 882dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hidinput_hid_event(hid, field, usage, value); 883aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 884aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina hid->hiddev_hid_event(hid, field, usage, value); 885dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 886dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 887dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 888dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Analyse a received field, and fetch the data from it. The field 889dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * content is stored for next report processing (we do differential 890dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * reporting to the layer). 891dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 892dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 893abdff0f7749a6696ba2a4238b675cbc55abcdb7aAdrian Bunkstatic void hid_input_field(struct hid_device *hid, struct hid_field *field, 894abdff0f7749a6696ba2a4238b675cbc55abcdb7aAdrian Bunk __u8 *data, int interrupt) 895dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 896dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 897dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned count = field->report_count; 898dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned offset = field->report_offset; 899dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned size = field->report_size; 900dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __s32 min = field->logical_minimum; 901dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __s32 max = field->logical_maximum; 902dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __s32 *value; 903dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 904a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC); 905a3789a1783d37f2772ba5046b26416c98dfe1bfaJoe Perches if (!value) 906dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return; 907dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 908dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < count; n++) { 909dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 9104291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches value[n] = min < 0 ? 9114291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches snto32(extract(hid, data, offset + n * size, size), 9124291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches size) : 9134291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches extract(hid, data, offset + n * size, size); 914dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 9154291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches /* Ignore report if ErrorRollOver */ 9164291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches if (!(field->flags & HID_MAIN_ITEM_VARIABLE) && 9174291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches value[n] >= min && value[n] <= max && 9184291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) 9194291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches goto exit; 920dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 921dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 922dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < count; n++) { 923dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 924dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (HID_MAIN_ITEM_VARIABLE & field->flags) { 925dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_process_event(hid, field, &field->usage[n], value[n], interrupt); 926dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina continue; 927dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 928dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 929dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (field->value[n] >= min && field->value[n] <= max 930dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && field->usage[field->value[n] - min].hid 931dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && search(value, field->value[n], count)) 932dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt); 933dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 934dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (value[n] >= min && value[n] <= max 935dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && field->usage[value[n] - min].hid 936dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && search(field->value, value[n], count)) 937dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt); 938dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 939dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 940dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memcpy(field->value, value, count * sizeof(__s32)); 941dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinaexit: 942dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(value); 943dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 944dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 945dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 946dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Output the field into the report. 947dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 948dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 9494291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perchesstatic void hid_output_field(const struct hid_device *hid, 9504291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches struct hid_field *field, __u8 *data) 951dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 952dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned count = field->report_count; 953dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned offset = field->report_offset; 954dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned size = field->report_size; 955dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 956dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 957dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < count; n++) { 958dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (field->logical_minimum < 0) /* signed values */ 9594291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches implement(hid, data, offset + n * size, size, 9604291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches s32ton(field->value[n], size)); 961dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina else /* unsigned values */ 9624291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches implement(hid, data, offset + n * size, size, 9634291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches field->value[n]); 964dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 965dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 966dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 967dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 968dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Create a report. 969dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 970dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 971229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosinavoid hid_output_report(struct hid_report *report, __u8 *data) 972dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 973dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 974dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 975dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report->id > 0) 976dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *data++ = report->id; 977dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 97875c28df87eb6d8e1389af67f26fbe2394e28385ePete Zaitcev memset(data, 0, ((report->size - 1) >> 3) + 1); 979dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < report->maxfield; n++) 9804291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches hid_output_field(report->device, report->field[n], data); 981dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 982229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_output_report); 983dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 984dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 985dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Set a field value. The report this field belongs to has to be 986dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * created and transferred to the device, to set this value in the 987dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * device. 988dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 989dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 990dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinaint hid_set_field(struct hid_field *field, unsigned offset, __s32 value) 991dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 992dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned size = field->report_size; 993dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 994cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina hid_dump_input(field->report->device, field->usage + offset, value); 995dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 996dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (offset >= field->report_count) { 99758037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count); 998dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 999dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 1000dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (field->logical_minimum < 0) { 1001dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (value != snto32(s32ton(value, size), size)) { 100258037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("value %d is out of range\n", value); 1003dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 1004dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 1005dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 1006dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->value[offset] = value; 1007dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 1008dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 1009229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_set_field); 1010dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 101185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic struct hid_report *hid_get_report(struct hid_report_enum *report_enum, 101285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const u8 *data) 1013aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina{ 1014aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina struct hid_report *report; 101585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int n = 0; /* Normally report number is 0 */ 1016aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 101785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby /* Device uses numbered reports, data[0] is report number */ 101885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (report_enum->numbered) 101985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby n = *data; 1020aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 102185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby report = report_enum->report_id_hash[n]; 102285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (report == NULL) 102385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("undefined report_id %u received\n", n); 1024aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 102585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return report; 102685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 1027aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 102885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, 102985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int interrupt) 103085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 103185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report_enum *report_enum = hid->report_enum + type; 103285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report *report; 103385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int a; 103485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int rsize, csize = size; 103585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby u8 *cdata = data; 1036aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 103785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby report = hid_get_report(report_enum, data); 103885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!report) 103985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return; 1040aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 104185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (report_enum->numbered) { 104285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby cdata++; 104385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby csize--; 1044aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina } 1045aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1046aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina rsize = ((report->size - 1) >> 3) + 1; 1047aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 104885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (csize < rsize) { 104985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("report %d is too short, (%d < %d)\n", report->id, 105085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby csize, rsize); 105185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby memset(cdata + csize, 0, rsize - csize); 1052aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina } 1053aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1054aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) 1055aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina hid->hiddev_report_event(hid, report); 10565a38f2c7c4dd53d5be097930902c108e362584a3Alan Ott if (hid->claimed & HID_CLAIMED_HIDRAW) 10575a38f2c7c4dd53d5be097930902c108e362584a3Alan Ott hidraw_report_event(hid, data, size); 1058aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 105985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (a = 0; a < report->maxfield; a++) 106085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hid_input_field(hid, report->field[a], cdata, interrupt); 1061aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1062aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 1063aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina hidinput_report_event(hid, report); 106485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 106585cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_report_raw_event); 106685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 106785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 106885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_input_report - report data from lower layer (usb, bt...) 106985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 107085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device 107185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @type: HID report type (HID_*_REPORT) 107285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @data: report contents 107385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @size: size of data parameter 1074ff9b00a226ccea66e6ce70e9083c42f5b6001f73Jiri Kosina * @interrupt: distinguish between interrupt and control transfers 107585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 107685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * This is data entry for lower layers. 107785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 107885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) 107985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 108076c317d6e5cb7f58541879006d39774596962715Julia Lawall struct hid_report_enum *report_enum; 108176c317d6e5cb7f58541879006d39774596962715Julia Lawall struct hid_driver *hdrv; 108285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report *report; 1083cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina char *buf; 108485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int i; 108585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 108685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 108785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!hid || !hid->driver) 108885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENODEV; 108976c317d6e5cb7f58541879006d39774596962715Julia Lawall report_enum = hid->report_enum + type; 109076c317d6e5cb7f58541879006d39774596962715Julia Lawall hdrv = hid->driver; 109185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 109285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!size) { 109385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("empty report\n"); 109485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -1; 109585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 109685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1097d1ff65226c5afe55f9af38a439058f41b71e114fJiri Kosina buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC); 1098cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina 1099f77e347bd44e3640bdc56003b7402c63ddb1241dJiri Kosina if (!buf) 1100cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina goto nomem; 110185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 110285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby /* dump the report */ 1103cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina snprintf(buf, HID_DEBUG_BUFSIZE - 1, 11041caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina "\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un"); 1105cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina hid_debug_event(hid, buf); 11061caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina 1107cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina for (i = 0; i < size; i++) { 1108cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina snprintf(buf, HID_DEBUG_BUFSIZE - 1, 1109cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina " %02x", data[i]); 1110cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina hid_debug_event(hid, buf); 1111cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina } 1112cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina hid_debug_event(hid, "\n"); 1113cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina kfree(buf); 111485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1115cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosinanomem: 11161caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina report = hid_get_report(report_enum, data); 11171caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina 1118f77e347bd44e3640bdc56003b7402c63ddb1241dJiri Kosina if (!report) 11191caea61eda5c4d446147aa0e712ba395bb6b81c3Jiri Kosina return -1; 112085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 112185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { 112285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = hdrv->raw_event(hid, report, data, size); 112385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret != 0) 112485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret < 0 ? ret : 0; 112585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 112685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 112785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hid_report_raw_event(hid, type, data, size, interrupt); 1128aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1129aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina return 0; 1130aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina} 1131aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri KosinaEXPORT_SYMBOL_GPL(hid_input_report); 1132aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 11330f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic bool hid_match_one_id(struct hid_device *hdev, 11340f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina const struct hid_device_id *id) 11350f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{ 11360f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return id->bus == hdev->bus && 11370f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && 11380f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina (id->product == HID_ANY_ID || id->product == hdev->product); 11390f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina} 11400f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11410f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic const struct hid_device_id *hid_match_id(struct hid_device *hdev, 11420f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina const struct hid_device_id *id) 11430f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{ 11440f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina for (; id->bus; id++) 11450f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina if (hid_match_one_id(hdev, id)) 11460f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return id; 11470f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11480f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return NULL; 11490f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina} 11500f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11510f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic const struct hid_device_id hid_hiddev_list[] = { 1152c0bd6a429819f794f626f9e73be4564e18e132dbRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) }, 1153c0bd6a429819f794f626f9e73be4564e18e132dbRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) }, 11540f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina { } 11550f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina}; 11560f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11570f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic bool hid_hiddev(struct hid_device *hdev) 11580f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{ 11590f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return !!hid_match_id(hdev, hid_hiddev_list); 11600f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina} 11610f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11626d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 11636d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ottstatic ssize_t 11646d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ottread_report_descriptor(struct file *filp, struct kobject *kobj, 11656d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott struct bin_attribute *attr, 11666d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott char *buf, loff_t off, size_t count) 11676d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott{ 11686d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott struct device *dev = container_of(kobj, struct device, kobj); 11696d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott struct hid_device *hdev = container_of(dev, struct hid_device, dev); 11706d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 11716d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott if (off >= hdev->rsize) 11726d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott return 0; 11736d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 11746d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott if (off + count > hdev->rsize) 11756d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott count = hdev->rsize - off; 11766d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 11776d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott memcpy(buf, hdev->rdesc + off, count); 11786d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 11796d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott return count; 11806d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott} 11816d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 11826d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ottstatic struct bin_attribute dev_bin_attr_report_desc = { 11836d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott .attr = { .name = "report_descriptor", .mode = 0444 }, 11846d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott .read = read_report_descriptor, 11856d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott .size = HID_MAX_DESCRIPTOR_SIZE, 11866d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott}; 11876d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 118893c10132a7ac160df3175b53f7ee857625412165Jiri Slabyint hid_connect(struct hid_device *hdev, unsigned int connect_mask) 118993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby{ 119093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 119193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby "Joystick", "Gamepad", "Keyboard", "Keypad", 119293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby "Multi-Axis Controller" 119393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby }; 119493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby const char *type, *bus; 119593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby char buf[64]; 119693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby unsigned int i; 119793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby int len; 11986d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott int ret; 119993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 1200b5e5a37e36cd4d355b875665312d7aaae4e5833cBastien Nocera if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE) 1201b5e5a37e36cd4d355b875665312d7aaae4e5833cBastien Nocera connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV); 12023a343ee4509c982552b35fbc99d3213f3bb1acdeDaniel Mack if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE) 12033a343ee4509c982552b35fbc99d3213f3bb1acdeDaniel Mack connect_mask |= HID_CONNECT_HIDINPUT_FORCE; 120493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->bus != BUS_USB) 120593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby connect_mask &= ~HID_CONNECT_HIDDEV; 12060f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina if (hid_hiddev(hdev)) 12070f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina connect_mask |= HID_CONNECT_HIDDEV_FORCE; 120893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 120993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, 121093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby connect_mask & HID_CONNECT_HIDINPUT_FORCE)) 121193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->claimed |= HID_CLAIMED_INPUT; 121293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && 121393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby !hdev->hiddev_connect(hdev, 121493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby connect_mask & HID_CONNECT_HIDDEV_FORCE)) 121593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->claimed |= HID_CLAIMED_HIDDEV; 121693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev)) 121793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->claimed |= HID_CLAIMED_HIDRAW; 121893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 121993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (!hdev->claimed) { 12204291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n"); 122193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby return -ENODEV; 122293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 122393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 122493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((hdev->claimed & HID_CLAIMED_INPUT) && 122593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby (connect_mask & HID_CONNECT_FF) && hdev->ff_init) 122693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->ff_init(hdev); 122793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 122893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len = 0; 122993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->claimed & HID_CLAIMED_INPUT) 123093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len += sprintf(buf + len, "input"); 123193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->claimed & HID_CLAIMED_HIDDEV) 123293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len += sprintf(buf + len, "%shiddev%d", len ? "," : "", 123393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->minor); 123493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->claimed & HID_CLAIMED_HIDRAW) 123593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len += sprintf(buf + len, "%shidraw%d", len ? "," : "", 123693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby ((struct hidraw *)hdev->hidraw)->minor); 123793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 123893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby type = "Device"; 123993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby for (i = 0; i < hdev->maxcollection; i++) { 124093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby struct hid_collection *col = &hdev->collection[i]; 124193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (col->type == HID_COLLECTION_APPLICATION && 124293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK && 124393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby (col->usage & 0xffff) < ARRAY_SIZE(types)) { 124493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby type = types[col->usage & 0xffff]; 124593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby break; 124693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 124793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 124893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 124993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby switch (hdev->bus) { 125093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby case BUS_USB: 125193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby bus = "USB"; 125293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby break; 125393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby case BUS_BLUETOOTH: 125493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby bus = "BLUETOOTH"; 125593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby break; 125693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby default: 125793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby bus = "<UNKNOWN>"; 125893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 125993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 12606d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 12616d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott if (ret) 12626d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott hid_warn(hdev, 12636d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott "can't create sysfs report descriptor attribute err: %d\n", ret); 12646d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott 12654291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 12664291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches buf, bus, hdev->version >> 8, hdev->version & 0xff, 12674291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches type, hdev->name, hdev->phys); 126893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 126993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby return 0; 127093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby} 127193c10132a7ac160df3175b53f7ee857625412165Jiri SlabyEXPORT_SYMBOL_GPL(hid_connect); 127293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 1273c4c259bcc27c4242b012106afdba183622b1735fJiri Kosinavoid hid_disconnect(struct hid_device *hdev) 1274c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina{ 12756d3bfb74341c2c1454fcf5ec9c4dd707011f78e5Alan Ott device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1276c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina if (hdev->claimed & HID_CLAIMED_INPUT) 1277c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina hidinput_disconnect(hdev); 1278c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina if (hdev->claimed & HID_CLAIMED_HIDDEV) 1279c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina hdev->hiddev_disconnect(hdev); 1280c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina if (hdev->claimed & HID_CLAIMED_HIDRAW) 1281c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina hidraw_disconnect(hdev); 1282c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina} 1283c4c259bcc27c4242b012106afdba183622b1735fJiri KosinaEXPORT_SYMBOL_GPL(hid_disconnect); 1284c4c259bcc27c4242b012106afdba183622b1735fJiri Kosina 1285bae7eb33b25387fdc7ccae08768bef1f9484a5b0Jiri Kosina/* a list of devices for which there is a specialized driver on HID bus */ 1286ce06b9d6d33fd2ed799b6e825d68fe95077da354Dmitry Torokhovstatic const struct hid_device_id hid_have_special_driver[] = { 1287b6353f4f36f03a12edaf3fa5365b475a28106035Stephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) }, 12886dec143a50c01ca0cc0afcbf5ea4bb8e87981edfStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M2256) }, 128914a21cd459f97e3b3cc4fcde48fc5bcdb81d097eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 129014a21cd459f97e3b3cc4fcde48fc5bcdb81d097eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1291b7e1b2039de3a028fba46fbaca58a45c23a417ecLech Perczak { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) }, 1292c0dbcc33c652a0646542560de29a1c3f1ab7169fSergei Kolzun { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) }, 1293df9bcace7b1c29e9be1c13b034ff04f4f4c90edeJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, 12948c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, 12958c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, 1296128537cea464d919febeaea2000e256749f317ebMichael Poole { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) }, 1297a462230e16acc8664145216da3c928d03556691aChase Douglas { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) }, 12988c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 12998c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 13008c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 13018c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 13028c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 13038c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 13048c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 13058c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 13068c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 13078c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 13088c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 1309fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) }, 1310fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) }, 1311fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) }, 13128c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) }, 13138c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) }, 13148c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) }, 13158c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 13168c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 13178c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 1318ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) }, 1319ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) }, 1320ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) }, 13218c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 13228c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 13238c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 13248c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 13258c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 13268c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 1327a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1328a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1329a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 133099b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) }, 133199b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) }, 133299b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) }, 133399b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 133499b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 133599b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 133623aeb61e7e1f02fb0f3b8f9e798e75537ca1731dChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 133723aeb61e7e1f02fb0f3b8f9e798e75537ca1731dChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 133823aeb61e7e1f02fb0f3b8f9e798e75537ca1731dChristian Schuerer-Waldheim { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 13398c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 13408c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1341eaca1386207a9e0314647d3a88967acb17cc30e3Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) }, 1342cec15a0ece19116b6c2c53fedf9696c20124d491Roland Baum { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) }, 1343b5635b129b3ca3a9c879a36f58f5b8c4903d267aJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, 1344bf280628fca93c4c341587ec914863dcc395af72Wayne Thomas { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 1345c3dc66de59531c921c4638b1285075ea1c831186Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) }, 13465519cab477b61326963c8d523520db0342862b63Benjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) }, 134736213e1e40fb863e2e8ef607b2958504b48f6b8eStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, 1348bc5ab083a68bfec212780281f8e57d871d8882a0Benjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_10_1) }, 1349ba4d8abb31def963f49b7c239a8acce57fe1d1ccStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, 1350272036edb77e5967c175ac48b8c88e9b3358285fFrançois Jaouen { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) }, 13513b239cd739a9499da08326356add3d9d992c7911Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 13521ce31b255cf8b06470dfbd469055b6fd8d2274bcRaphaël Doursenaud { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) }, 1353fcfacfd3594d5d2fa99fb5e7d33dee3904b1a156Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 1354b9e4b1e0cd401e915e3ba97afc152946f78f9f0bDennis Kügler { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) }, 13553a370ca1dcf8c80aff7a0a21d6b0f50ca2a151e9Don Prince { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, 13560f2213208f8da51bcb665309e3468f000489c04fJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, 13570f2213208f8da51bcb665309e3468f000489c04fJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, 1358e8d0eab4d9eda9f5e97852f780f020bfb134f9f0Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, 13590f2213208f8da51bcb665309e3468f000489c04fJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, 1360a3b5e577d96bfccbc41ebf4df784e3a153072273Benjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) }, 13613f866fbd52d1863db5c07700e560aef22c4fdc01Richard Walmsley { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, 1362e05eefb9be109e6cbbfd362b49ee83397130a7e4Nikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) }, 13630c3910c255d3f9caeef4ebad5d5a1156a2d33f69Stephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) }, 136483e4491818040ae6b2d9fc60434616304a101d39Chris Ball { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) }, 13654e93db23bf95cd763c9182b5d6187412fe6ce747Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) }, 136628906ad6d7c8a8090f720cf7c39461df0b1460f6Richard Nauber { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) }, 13674dd295a73e80b55c3fec25555bf0a5d253023740Andy Ross { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) }, 136864b386ea16112564e0b93473e2c347125effb6b2Richard Nauber { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, 136904561c5aa243c98cae93cde27e05740df787e692Ignaz Forster { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) }, 13701f243e302cea1561ac881eb5d27041c5342beba4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, 13715181e594512faeac7d7fd9620ce91105f45bf643Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, 1372578f3a35fecabff49bad808c5301313f785b5462Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, 13735572da08a784621f2ab4fdc8dc65471261871795Benjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS) }, 13745181e594512faeac7d7fd9620ce91105f45bf643Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, 137542859e0bd21daba9974757fcfe4a4dde265fe28dLukasz Lubojanski { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, 1376949f8fef77186c7361d22e1ea6f42c76ceda42b0Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, 13771e093206734568e780c2717da1c89b97e9471954Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, 1378c2fd1a4ebf9127c280d227acb635eb1df213439cCory Maccarrone { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, 13795519cab477b61326963c8d523520db0342862b63Benjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) }, 1380b2e7617e09a8e774d7819c629a0989cbddb5d1abBenjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) }, 1381fdf93aa33268889e126aa677f2072238bd76adb0Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, 1382177900e8c9ab28cdf097314fe7dd3877774df97dJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) }, 1383794227415f8f5f395a9ed4269a4ee7a3c34f66a5Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 1384b5635b129b3ca3a9c879a36f58f5b8c4903d267aJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 138575b07022462fc33d6be15669ad604118653210a9Chris Schlund { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, 13865f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, 13875f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, 13885f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, 13895f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, 13905f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, 13915f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, 13925f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, 13935f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) }, 13945f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) }, 13955f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) }, 13965f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) }, 13972c6118e43040034d80894daeba41960bf0035b31Hendrik Iben { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) }, 1398606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, 1399606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, 1400606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, 1401fd30ea8c871552ddd6a5e1c0886de8fef4df53bcJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) }, 1402606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, 140374f292ca8c7a2b9370f80d97a49e48174f4c7635Gary Stein { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) }, 1404606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, 1405606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, 14065623a24a80814fe471e777f12b9dbbb0f77e002eJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) }, 1407243b706d8a71364ad6080328d45b73516c8af5f3Christophe Borivant { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, 140832c88cbc3080f43c429f6456aa9cd845e37f3778Simon Wood { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) }, 1409606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, 141024985cf68612a5617d396b0b188cec807641cde1Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, 141124985cf68612a5617d396b0b188cec807641cde1Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) }, 1412236db47c2b3b69464d50c695ab2ddd516cf64520Bruno Prémont { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) }, 1413236db47c2b3b69464d50c695ab2ddd516cf64520Bruno Prémont { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) }, 141478a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) }, 141578a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) }, 141678a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) }, 141778a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, 141878a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 14193b8006e51038ef263a0404756d9e190c9a9f74d5Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, 142094011f93f2cd7410401e22390cf7a14fe5495a22Rafi Rubin { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, 14216e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) }, 14226e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) }, 14236e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) }, 14246e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) }, 14256e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) }, 14266e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) }, 14276e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) }, 14286e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) }, 14296e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) }, 14306e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) }, 14316e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) }, 14326e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) }, 14336e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) }, 14346e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) }, 14356e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) }, 14366e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) }, 14376e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) }, 14386e32819e12ffbd507eced11a1871700a387d5407micki { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) }, 1439270fdc0748bd3f7b625caff985f2fcf8e2185ec7Herton Ronaldo Krzesinski { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) }, 1440cd9ec30da58bcd8ab154eba9eb54d16c67e7ef3bJohnathon Harris { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) }, 14411e76253220dbe66e048e55680266dd1f4af0be85Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 144249e4739a0cf681cbfe08c72232c1dcc130b66ddeStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, 1443f54405db66fbec11679241daefd16fd8291a5762Alex Neblett { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) }, 144414bf62cde79423a02a590e02664ed29a36facec1Stefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, 1445e68cc603b063416c85f3e408184219fb71d4a9ffStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) }, 144647dbdbffe15b9582a41727766d43f1d4208e977eStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, 14470e70f97f257edcef4daa92ab9371a9aac0c851edStefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) }, 1448cb7cf3da0daa9830e00640da8f7d2380f4b4de42Stefan Achatz { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 1449980a3da6acdd577ee3ae192e868dc52fe4b7f2e5Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1450b355850ba383232d4e0e357c1cda8cb7bfcc60bcDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) }, 1451d586dca06adddc6cee7177b013ee93eaffc9fe0eJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) }, 1452bd28ce008bdc68ef5902f68d2d62cbb7fa78c415Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1453f9ce7c283c16538955d5d094101889792bcde109Bastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1454cc6e0bbb47f02fd36cd55b3189c0c79079096ab8Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, 1455d3fb5454a8474d5d22c8f8fe4d043b05732d91d5Stephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) }, 1456b6dc79929fa18a97bbc08400db72405ad835622fPascal Auriel - Stantum { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM, USB_DEVICE_ID_MTP_STM) }, 1457b6dc79929fa18a97bbc08400db72405ad835622fPascal Auriel - Stantum { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_SITRONIX, USB_DEVICE_ID_MTP_SITRONIX) }, 145890231e7eaf752856a2c13f786f36ec7f641bad28Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, 1459daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, 1460daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, 14617a84b1336a145d683fb8cdfd6c2c67545a58b126Ruben Aos Garralda { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) }, 14627a84b1336a145d683fb8cdfd6c2c67545a58b126Ruben Aos Garralda { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) }, 1463daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, 14643ee8f0a2b1c81f0472b25d40aa5c1c7c6a0edc2aMarkus Rathgeb { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) }, 1465daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, 1466d65c3768afb47fb93c43fbfcafef53502edaaa85Simon Wood { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) }, 1467f14f526d02b14fd0b8c1ac4ec413e4577ad5f62eLev Babiev { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 1468540010812179a16d3d00fb8363bb06ee83af25b8Kees Bakker { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 1469711a680e35059bc5c7c28d3c4bd0bebd3b7bb6eeBruno Premont { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, 1470c64f6f934c7490faff76faf96217066a1b3570a0Benjamin Tissoires { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART) }, 147141fa92302be7fa37c5c38e17e2097d3e5e9da13aNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, 1472f8a489cc5f7adafa9f1420279be793de0fba481cNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) }, 1473f8a489cc5f7adafa9f1420279be793de0fba481cNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) }, 1474f8a489cc5f7adafa9f1420279be793de0fba481cNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) }, 1475fac733f029251a393c42a8313432f2d9fe43bb83Jussi Kivilinna { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, 1476ca2dcd40f54c8928b3994712a6cadd2078a087faBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 147772a46344867111c3e019b169ddfa9e1a1f55c759Nikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) }, 147800e7f9649b3061281fe4b463263da26155dc9be4Nikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) }, 147972a46344867111c3e019b169ddfa9e1a1f55c759Nikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) }, 14808f1acc32bbdb1784bcb0be98fb02f4b20e6f328fNikolai Kondrashov { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, 1481daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, 1482daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, 1483a9885c8f7bf62e251fc178f838b9f0ee897c158aDon Prince { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) }, 14848c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby 148578a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, 148685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby { } 148785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}; 148885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 14893a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystruct hid_dynid { 14903a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct list_head list; 14913a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_device_id id; 14923a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby}; 14933a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 14943a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby/** 14953a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * store_new_id - add a new HID device ID to this driver and re-probe devices 14963a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @driver: target device driver 14973a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @buf: buffer for scanning device ID data 14983a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @count: input size 14993a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * 15003a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * Adds a new dynamic hid device ID to this driver, 15013a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * and causes the driver to probe for all devices again. 15023a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby */ 15033a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic ssize_t store_new_id(struct device_driver *drv, const char *buf, 15043a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby size_t count) 15053a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{ 15063a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 15073a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_dynid *dynid; 15083a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby __u32 bus, vendor, product; 15093a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby unsigned long driver_data = 0; 15103a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby int ret; 15113a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15123a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = sscanf(buf, "%x %x %x %lx", 15133a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby &bus, &vendor, &product, &driver_data); 15143a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (ret < 3) 15153a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return -EINVAL; 15163a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15173a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); 15183a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (!dynid) 15193a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return -ENOMEM; 15203a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15213a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.bus = bus; 15223a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.vendor = vendor; 15233a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.product = product; 15243a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.driver_data = driver_data; 15253a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15263a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock(&hdrv->dyn_lock); 15273a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_add_tail(&dynid->list, &hdrv->dyn_list); 15283a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 15293a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15303a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = 0; 15313a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (get_driver(&hdrv->driver)) { 15323a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = driver_attach(&hdrv->driver); 15333a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby put_driver(&hdrv->driver); 15343a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 15353a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15363a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return ret ? : count; 15373a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby} 15383a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 15393a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15403a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic void hid_free_dynids(struct hid_driver *hdrv) 15413a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{ 15423a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_dynid *dynid, *n; 15433a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15443a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock(&hdrv->dyn_lock); 15453a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) { 15463a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_del(&dynid->list); 15473a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby kfree(dynid); 15483a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 15493a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 15503a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby} 15513a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15523a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic const struct hid_device_id *hid_match_device(struct hid_device *hdev, 15533a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_driver *hdrv) 15543a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{ 15553a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_dynid *dynid; 15563a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15573a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock(&hdrv->dyn_lock); 15583a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_for_each_entry(dynid, &hdrv->dyn_list, list) { 15593a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (hid_match_one_id(hdev, &dynid->id)) { 15603a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 15613a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return &dynid->id; 15623a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 15633a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 15643a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 15653a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 15663a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return hid_match_id(hdev, hdrv->id_table); 15673a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby} 15683a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 156985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_bus_match(struct device *dev, struct device_driver *drv) 157085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 157185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 157285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 157385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 15743a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (!hid_match_device(hdev, hdrv)) 157585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 157685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1577ce06b9d6d33fd2ed799b6e825d68fe95077da354Dmitry Torokhov /* generic wants all that don't have specialized driver */ 157885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!strncmp(hdrv->name, "generic-", 8)) 1579ce06b9d6d33fd2ed799b6e825d68fe95077da354Dmitry Torokhov return !hid_match_id(hdev, hid_have_special_driver); 158085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 158185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 158285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 158385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 158485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_device_probe(struct device *dev) 158585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 158685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = container_of(dev->driver, 158785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver, driver); 158885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 158985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const struct hid_device_id *id; 159085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret = 0; 159185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 159285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!hdev->driver) { 15933a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby id = hid_match_device(hdev, hdrv); 1594c500c9714011edab021591340042787722db9cf0Jiri Slaby if (id == NULL) 1595c500c9714011edab021591340042787722db9cf0Jiri Slaby return -ENODEV; 159685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1597c500c9714011edab021591340042787722db9cf0Jiri Slaby hdev->driver = hdrv; 1598c500c9714011edab021591340042787722db9cf0Jiri Slaby if (hdrv->probe) { 1599c500c9714011edab021591340042787722db9cf0Jiri Slaby ret = hdrv->probe(hdev, id); 1600c500c9714011edab021591340042787722db9cf0Jiri Slaby } else { /* default probe */ 1601c500c9714011edab021591340042787722db9cf0Jiri Slaby ret = hid_parse(hdev); 1602c500c9714011edab021591340042787722db9cf0Jiri Slaby if (!ret) 160393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 160485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 1605c500c9714011edab021591340042787722db9cf0Jiri Slaby if (ret) 1606c500c9714011edab021591340042787722db9cf0Jiri Slaby hdev->driver = NULL; 160785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 160885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 160985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 161085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 161185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_device_remove(struct device *dev) 161285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 161385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 161485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = hdev->driver; 161585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 161685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv) { 161785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv->remove) 161885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->remove(hdev); 1619c500c9714011edab021591340042787722db9cf0Jiri Slaby else /* default remove */ 1620c500c9714011edab021591340042787722db9cf0Jiri Slaby hid_hw_stop(hdev); 162185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->driver = NULL; 162285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 162385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 162485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 162585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 162685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 162785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_uevent(struct device *dev, struct kobj_uevent_env *env) 162885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 162985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 163085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 163185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", 163285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->bus, hdev->vendor, hdev->product)) 163385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 163485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 163585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_NAME=%s", hdev->name)) 163685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 163785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 163885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys)) 163985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 164085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 164185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq)) 164285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 164385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 164485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X", 164585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->bus, hdev->vendor, hdev->product)) 164685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 164785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 164885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 164985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 165085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 165185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic struct bus_type hid_bus_type = { 165285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .name = "hid", 165385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .match = hid_bus_match, 165485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .probe = hid_device_probe, 165585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .remove = hid_device_remove, 165685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .uevent = hid_uevent, 165785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}; 165885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1659bae7eb33b25387fdc7ccae08768bef1f9484a5b0Jiri Kosina/* a list of devices that shouldn't be handled by HID core at all */ 1660d458a9dfc4de24870b8c747484b1988726534beeJiri Slabystatic const struct hid_device_id hid_ignore_list[] = { 1661d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) }, 1662d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) }, 1663d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) }, 1664d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) }, 1665d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) }, 1666d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) }, 1667d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) }, 1668d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) }, 1669d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) }, 1670d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, 1671d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, 1672d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, 167377f720b71d88a3cbf574c113566a31c93099f97dStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)}, 167477f720b71d88a3cbf574c113566a31c93099f97dStephane Chatty { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)}, 167562a56582e01b1c5139b235004548e233201df9aaAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, 1676d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, 1677d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, 1678d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, 1679d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) }, 1680d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) }, 1681d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) }, 16825f6108cf9be4a77d6bee96750aa4fe18b6b97deeAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) }, 1683d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, 1684d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, 168573bc7d315f56e260071bdb5f15e25b53bddc1402Melchior FRANZ { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) }, 1686d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, 168770c66567d1e41d8b2186a2d198997a1c8d79c0c4Petr Štetiar { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) }, 1688df506f2c0023380ffa67a946fa36eee4150773a3Petr Štetiar { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) }, 1689d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, 1690d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) }, 1691d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, 1692d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, 1693d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, 1694d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) }, 1695d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) }, 1696d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) }, 1697d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) }, 1698d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) }, 1699d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) }, 1700d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) }, 1701d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) }, 1702d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) }, 1703d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) }, 1704d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) }, 1705d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) }, 1706d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) }, 1707d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) }, 1708d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) }, 1709d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) }, 1710d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) }, 1711d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) }, 1712d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) }, 1713d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) }, 1714d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) }, 1715d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) }, 1716d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) }, 1717d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) }, 1718d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) }, 1719d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) }, 1720d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) }, 1721d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) }, 1722d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) }, 1723d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) }, 1724d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) }, 1725d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) }, 1726d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) }, 1727d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) }, 1728d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) }, 1729d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) }, 1730d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) }, 1731d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) }, 1732d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) }, 1733d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) }, 1734d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) }, 1735d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) }, 1736d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) }, 1737d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) }, 1738d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) }, 1739d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) }, 1740d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) }, 1741d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) }, 1742d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) }, 1743d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) }, 1744d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) }, 1745d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) }, 1746d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) }, 1747d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) }, 1748d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) }, 1749d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) }, 1750d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) }, 1751d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) }, 1752d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) }, 17536bc235a2e24a5ef677daee3fd4f74f6cd643e23cTomoki Sekiyama { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_JESS_YUREX) }, 1754d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) }, 1755c91c21c5a6facddce936d82e5bc0c655d04288aaAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) }, 1756d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) }, 1757eb8141ccd32d422fa11c6e2108cae4c40456d811Lamarque Vieira Souza { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) }, 1758d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, 1759d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, 1760d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, 1761d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 1762d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 1763d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 1764d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) }, 1765d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, 1766d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, 1767d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, 1768d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, 1769d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, 1770d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, 1771d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, 1772d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, 1773d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, 1774d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, 1775d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) }, 1776d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) }, 1777d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) }, 1778d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) }, 1779d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) }, 1780d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) }, 1781d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) }, 1782d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) }, 1783d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) }, 1784d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) }, 1785d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) }, 1786d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) }, 1787d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) }, 1788d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) }, 1789d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) }, 1790d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, 17914cfae3e80431fd113f0f4a8e1d4fff84aafe045cHenning Glawe { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) }, 179235cfd1d964f3c2420862f2167a0eb85ff1208999Michael Tokarev { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, 1793d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, 1794d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, 1795d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, 1796d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, 1797d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) }, 1798d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) }, 1799d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) }, 1800d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) }, 1801d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) }, 1802d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, 1803d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { } 1804d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby}; 1805d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 1806b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby/** 1807b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer 1808b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * 1809b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * There are composite devices for which we want to ignore only a certain 1810b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * interface. This is a list of devices for which only the mouse interface will 1811b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * be ignored. This allows a dedicated driver to take care of the interface. 1812b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby */ 1813b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slabystatic const struct hid_device_id hid_mouse_ignore_list[] = { 1814b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby /* appletouch driver */ 1815b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 1816b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 1817b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 1818b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 1819b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 1820b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 1821b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 1822b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 1823b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 1824b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 1825b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 1826b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 1827b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 1828b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 1829b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 1830b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 1831b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 1832b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 1833b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 1834b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 1835ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1836ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1837ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 183899b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) }, 183999b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) }, 184099b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) }, 184199b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) }, 184299b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) }, 184399b9f758bbc904f22faffcf4d83205f4a5e7bc0cEdgar (gimli) Hucek { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) }, 1844b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1845b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1846b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { } 1847b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby}; 1848b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby 1849d458a9dfc4de24870b8c747484b1988726534beeJiri Slabystatic bool hid_ignore(struct hid_device *hdev) 1850d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby{ 1851d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby switch (hdev->vendor) { 1852d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby case USB_VENDOR_ID_CODEMERCS: 1853d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby /* ignore all Code Mercenaries IOWarrior devices */ 1854d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && 1855d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) 1856d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return true; 1857d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby break; 1858d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby case USB_VENDOR_ID_LOGITECH: 1859d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST && 1860d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST) 1861d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return true; 1862d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby break; 186331f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson case USB_VENDOR_ID_SOUNDGRAPH: 186431f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST && 186531f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST) 186631f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson return true; 186731f7fd795d17b264c3c05e4a976f963012c17c68Jarod Wilson break; 1868bba5394ad3bd23fff6987fc8bc3aaf9d12433c63Xing Wei case USB_VENDOR_ID_HANWANG: 1869bba5394ad3bd23fff6987fc8bc3aaf9d12433c63Xing Wei if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST && 1870bba5394ad3bd23fff6987fc8bc3aaf9d12433c63Xing Wei hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST) 1871bba5394ad3bd23fff6987fc8bc3aaf9d12433c63Xing Wei return true; 1872bba5394ad3bd23fff6987fc8bc3aaf9d12433c63Xing Wei break; 1873d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby } 1874d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 1875b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby if (hdev->type == HID_TYPE_USBMOUSE && 1876b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby hid_match_id(hdev, hid_mouse_ignore_list)) 1877b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby return true; 1878b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby 1879d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return !!hid_match_id(hdev, hid_ignore_list); 1880d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby} 1881d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 188285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_add_device(struct hid_device *hdev) 188385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 188485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby static atomic_t id = ATOMIC_INIT(0); 188585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 188685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 188785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (WARN_ON(hdev->status & HID_STAT_ADDED)) 188885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -EBUSY; 188985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1890d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby /* we need to kill them here, otherwise they will stay allocated to 1891d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby * wait for coming driver */ 1892e5a2a04c264e693eafcc78fec5add34c9e15e471Jindrich Makovicka if (!(hdev->quirks & HID_QUIRK_NO_IGNORE) 1893e5a2a04c264e693eafcc78fec5add34c9e15e471Jindrich Makovicka && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE))) 1894d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return -ENODEV; 1895d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 18966bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers /* XXX hack, any other cleaner solution after the driver core 18976bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers * is converted to allow more than 20 bytes as the device name? */ 18986bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, 18996bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers hdev->vendor, hdev->product, atomic_inc_return(&id)); 190085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 19014da361b69102cdffe73006771eae7504d2cb8736Bruno Prémont hid_debug_register(hdev, dev_name(&hdev->dev)); 190285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = device_add(&hdev->dev); 190385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!ret) 190485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->status |= HID_STAT_ADDED; 19054da361b69102cdffe73006771eae7504d2cb8736Bruno Prémont else 19064da361b69102cdffe73006771eae7504d2cb8736Bruno Prémont hid_debug_unregister(hdev); 1907a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina 190885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 190985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 191085cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_add_device); 191185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 191285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 191385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_allocate_device - allocate new hid device descriptor 191485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 191585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * Allocate and initialize hid device, so that hid_destroy_device might be 191685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * used to free it. 191785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 191885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * New hid_device pointer is returned on success, otherwise ERR_PTR encoded 191985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * error value. 192085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 192185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystruct hid_device *hid_allocate_device(void) 192285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 192385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev; 192485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int i; 192585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret = -ENOMEM; 192685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 192785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); 192885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdev == NULL) 192985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ERR_PTR(ret); 193085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 193185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby device_initialize(&hdev->dev); 193285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->dev.release = hid_device_release; 193385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->dev.bus = &hid_bus_type; 193485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 193585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, 193685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby sizeof(struct hid_collection), GFP_KERNEL); 193785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdev->collection == NULL) 193885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 193985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS; 194085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 194185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (i = 0; i < HID_REPORT_TYPES; i++) 194285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby INIT_LIST_HEAD(&hdev->report_enum[i].report_list); 194385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1944cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina init_waitqueue_head(&hdev->debug_wait); 1945cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina INIT_LIST_HEAD(&hdev->debug_list); 1946cd667ce24796700e1a0e6e7528efc61c96ff832eJiri Kosina 194785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return hdev; 194885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr: 194985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby put_device(&hdev->dev); 195085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ERR_PTR(ret); 195185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 195285cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_allocate_device); 195385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 195485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_remove_device(struct hid_device *hdev) 195585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 195685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdev->status & HID_STAT_ADDED) { 195785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby device_del(&hdev->dev); 1958a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina hid_debug_unregister(hdev); 195985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->status &= ~HID_STAT_ADDED; 196085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 196185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 196285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 196385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 196485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_destroy_device - free previously allocated device 196585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 196685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hdev: hid device 196785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 196885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * If you allocate hid_device through hid_allocate_device, you should ever 196985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * free by this function. 197085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 197185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_destroy_device(struct hid_device *hdev) 197285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 197385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hid_remove_device(hdev); 197485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby put_device(&hdev->dev); 197585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 197685cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_destroy_device); 197785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 197885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint __hid_register_driver(struct hid_driver *hdrv, struct module *owner, 197985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const char *mod_name) 198085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 19813a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby int ret; 19823a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 198385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.name = hdrv->name; 198485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.bus = &hid_bus_type; 198585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.owner = owner; 198685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.mod_name = mod_name; 198785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 19883a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby INIT_LIST_HEAD(&hdrv->dyn_list); 19893a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock_init(&hdrv->dyn_lock); 19903a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 19913a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = driver_register(&hdrv->driver); 19923a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (ret) 19933a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return ret; 19943a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 19953a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = driver_create_file(&hdrv->driver, &driver_attr_new_id); 19963a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (ret) 19973a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby driver_unregister(&hdrv->driver); 19983a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 19993a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return ret; 200085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 200185cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(__hid_register_driver); 200285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 200385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_unregister_driver(struct hid_driver *hdrv) 200485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 20053a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby driver_remove_file(&hdrv->driver, &driver_attr_new_id); 200685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby driver_unregister(&hdrv->driver); 20073a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby hid_free_dynids(hdrv); 200885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 200985cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_unregister_driver); 201085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 20110361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukumint hid_check_keys_pressed(struct hid_device *hid) 20120361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum{ 20130361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum struct hid_input *hidinput; 20140361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum int i; 20150361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 2016e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina if (!(hid->claimed & HID_CLAIMED_INPUT)) 2017e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina return 0; 2018e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina 20190361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum list_for_each_entry(hidinput, &hid->inputs, list) { 20200361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++) 20210361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum if (hidinput->input->key[i]) 20220361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum return 1; 20230361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum } 20240361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 20250361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum return 0; 20260361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum} 20270361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 20280361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver NeukumEXPORT_SYMBOL_GPL(hid_check_keys_pressed); 20290361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 203086166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinastatic int __init hid_init(void) 203186166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina{ 203285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 203385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 2034a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina if (hid_debug) 20354291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches pr_warn("hid_debug is now used solely for parser and driver debugging.\n" 20364291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches "debugfs is now used for inspecting the device (report descriptor, reports)\n"); 2037a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina 203885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = bus_register(&hid_bus_type); 203985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret) { 20404291ee305e9bb0699504a66f0e2b7aefcf0512a5Joe Perches pr_err("can't register hid bus\n"); 204185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 204285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 204385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 204485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = hidraw_init(); 204585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret) 204685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err_bus; 204785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 2048a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina hid_debug_init(); 2049a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina 205085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 205185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr_bus: 205285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby bus_unregister(&hid_bus_type); 205385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr: 205485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 205586166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina} 205686166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina 205786166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinastatic void __exit hid_exit(void) 205886166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina{ 2059a635f9dd83f3382577f4544a96df12356e951a40Jiri Kosina hid_debug_exit(); 206086166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina hidraw_exit(); 206185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby bus_unregister(&hid_bus_type); 206286166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina} 206386166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina 206486166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinamodule_init(hid_init); 206586166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinamodule_exit(hid_exit); 206686166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina 206788adb72bcf3b1cc6b440fda9fa97bc2151245fc5Jiri KosinaMODULE_AUTHOR("Andreas Gal"); 206888adb72bcf3b1cc6b440fda9fa97bc2151245fc5Jiri KosinaMODULE_AUTHOR("Vojtech Pavlik"); 206988adb72bcf3b1cc6b440fda9fa97bc2151245fc5Jiri KosinaMODULE_AUTHOR("Jiri Kosina"); 2070aa938f7974b82cfd9ee955031987344f332b7c77Jiri KosinaMODULE_LICENSE(DRIVER_LICENSE); 2071aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina 2072