hid-core.c revision ca2dcd40f54c8928b3994712a6cadd2078a087fa
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 7f142b3a4f64eca235f5890d9cecb68482f62ed26Jiri Kosina * Copyright (c) 2006-2007 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 17dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/module.h> 18dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/slab.h> 19dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/init.h> 20dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/kernel.h> 21dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/list.h> 22dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/mm.h> 23dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/spinlock.h> 24dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <asm/unaligned.h> 25dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <asm/byteorder.h> 26dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/input.h> 27dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/wait.h> 2847a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina#include <linux/vmalloc.h> 29c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina#include <linux/sched.h> 30dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 31dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/hid.h> 32dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#include <linux/hiddev.h> 33c080d89ad91e98fec0e8fc5f448a1ad899bd85c7Jiri Kosina#include <linux/hid-debug.h> 3486166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina#include <linux/hidraw.h> 35dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 365f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby#include "hid-ids.h" 375f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby 38dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 39dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Version Information 40dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 41dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 42dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#define DRIVER_VERSION "v2.6" 43f142b3a4f64eca235f5890d9cecb68482f62ed26Jiri Kosina#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina" 44531498013163c72cee8540e98e12c0c430c7fe87Jiri Kosina#define DRIVER_DESC "HID core driver" 45dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina#define DRIVER_LICENSE "GPL" 46dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 4758037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina#ifdef CONFIG_HID_DEBUG 4858037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosinaint hid_debug = 0; 49377e10fbb4ef219f540d06796e9fb0d3ec35a58fAnssi Hannulamodule_param_named(debug, hid_debug, int, 0600); 50377e10fbb4ef219f540d06796e9fb0d3ec35a58fAnssi HannulaMODULE_PARM_DESC(debug, "HID debugging (0=off, 1=probing info, 2=continuous data dumping)"); 5158037eb961f859607b161c50d9d4ecb374de1e8fJiri KosinaEXPORT_SYMBOL_GPL(hid_debug); 5258037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina#endif 5358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina 54dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 55dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new report for a device. 56dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 57dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 58dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) 59dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 60dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report_enum *report_enum = device->report_enum + type; 61dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report *report; 62dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 63dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report_enum->report_id_hash[id]) 64dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return report_enum->report_id_hash[id]; 65dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 66dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL))) 67dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 68dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 69dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (id != 0) 70dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report_enum->numbered = 1; 71dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 72dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->id = id; 73dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->type = type; 74dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->size = 0; 75dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->device = device; 76dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report_enum->report_id_hash[id] = report; 77dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 78dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina list_add_tail(&report->list, &report_enum->report_list); 79dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 80dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return report; 81dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 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 96dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage) 97dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina + values * sizeof(unsigned), GFP_KERNEL))) return NULL; 98dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 99dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->index = report->maxfield++; 100dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->field[field->index] = field; 101dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->usage = (struct hid_usage *)(field + 1); 102282bfd4cbcc2bbeb1a2cad1f42debd378e0b5ac9Jiri Slaby field->value = (s32 *)(field->usage + usages); 103dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report = report; 104dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 105dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return field; 106dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 107dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 108dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 109dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Open a collection. The type/usage is pushed on the stack. 110dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 111dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 112dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int open_collection(struct hid_parser *parser, unsigned type) 113dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 114dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_collection *collection; 115dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned usage; 116dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 117dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina usage = parser->local.usage[0]; 118dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 119dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { 12058037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("collection stack overflow\n"); 121dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 122dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 123dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 124dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->device->maxcollection == parser->device->collection_size) { 125dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection = kmalloc(sizeof(struct hid_collection) * 126dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size * 2, GFP_KERNEL); 127dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (collection == NULL) { 12858037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("failed to reallocate collection array\n"); 129dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 130dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 131dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memcpy(collection, parser->device->collection, 132dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina sizeof(struct hid_collection) * 133dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size); 134dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memset(collection + parser->device->collection_size, 0, 135dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina sizeof(struct hid_collection) * 136dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size); 137dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(parser->device->collection); 138dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection = collection; 139dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->collection_size *= 2; 140dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 141dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 142dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack[parser->collection_stack_ptr++] = 143dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->maxcollection; 144dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 145dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection = parser->device->collection + 146dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->maxcollection++; 147dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection->type = type; 148dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection->usage = usage; 149dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina collection->level = parser->collection_stack_ptr - 1; 150dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 151dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (type == HID_COLLECTION_APPLICATION) 152dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device->maxapplication++; 153dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 154dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 155dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 156dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 157dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 158dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Close a collection. 159dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 160dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 161dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int close_collection(struct hid_parser *parser) 162dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 163dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!parser->collection_stack_ptr) { 16458037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("collection stack underflow\n"); 165dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 166dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 167dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack_ptr--; 168dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 169dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 170dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 171dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 172dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Climb up the stack, search for the specified collection type 173dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * and return the usage. 174dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 175dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 176dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type) 177dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 178dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int n; 179dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = parser->collection_stack_ptr - 1; n >= 0; n--) 180dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->device->collection[parser->collection_stack[n]].type == type) 181dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return parser->device->collection[parser->collection_stack[n]].usage; 182dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; /* we know nothing about this usage type */ 183dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 184dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 185dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 186dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Add a usage to the temporary parser table. 187dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 188dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 189dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_add_usage(struct hid_parser *parser, unsigned usage) 190dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 191dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->local.usage_index >= HID_MAX_USAGES) { 19258037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("usage index exceeded\n"); 193dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 194dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 195dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.usage[parser->local.usage_index] = usage; 196dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.collection_index[parser->local.usage_index] = 197dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack_ptr ? 198dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->collection_stack[parser->collection_stack_ptr - 1] : 0; 199dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.usage_index++; 200dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 201dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 202dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 203dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 204dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Register a new field for this report. 205dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 206dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 207dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags) 208dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 209dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report *report; 210dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_field *field; 211dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int usages; 212dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned offset; 213dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int i; 214dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 215dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) { 21658037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("hid_register_report failed\n"); 217dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 218dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 219dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 220dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->global.logical_maximum < parser->global.logical_minimum) { 22158037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("logical range invalid %d %d\n", parser->global.logical_minimum, parser->global.logical_maximum); 222dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 223dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 224dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 225dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina offset = report->size; 226dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report->size += parser->global.report_size * parser->global.report_count; 227dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 228dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!parser->local.usage_index) /* Ignore padding fields */ 229dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 230dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 231dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina usages = max_t(int, parser->local.usage_index, parser->global.report_count); 232dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 233dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL) 234dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 235dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 236dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL); 237dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL); 238dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION); 239dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 240dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (i = 0; i < usages; i++) { 241dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int j = i; 242dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina /* Duplicate the last usage we parsed if we have excess values */ 243dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (i >= parser->local.usage_index) 244dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina j = parser->local.usage_index - 1; 245dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->usage[i].hid = parser->local.usage[j]; 246dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->usage[i].collection_index = 247dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->local.collection_index[j]; 248dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 249dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 250dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->maxusage = usages; 251dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->flags = flags; 252dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_offset = offset; 253dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_type = report_type; 254dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_size = parser->global.report_size; 255dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->report_count = parser->global.report_count; 256dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->logical_minimum = parser->global.logical_minimum; 257dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->logical_maximum = parser->global.logical_maximum; 258dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->physical_minimum = parser->global.physical_minimum; 259dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->physical_maximum = parser->global.physical_maximum; 260dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->unit_exponent = parser->global.unit_exponent; 261dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->unit = parser->global.unit; 262dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 263dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 264dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 265dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 266dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 267dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Read data value from item. 268dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 269dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 270dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u32 item_udata(struct hid_item *item) 271dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 272dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->size) { 273880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 1: return item->data.u8; 274880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 2: return item->data.u16; 275880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 4: return item->data.u32; 276dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 277dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 278dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 279dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 280dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic s32 item_sdata(struct hid_item *item) 281dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 282dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->size) { 283880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 1: return item->data.s8; 284880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 2: return item->data.s16; 285880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 4: return item->data.s32; 286dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 287dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 288dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 289dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 290dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 291dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a global item. 292dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 293dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 294dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_global(struct hid_parser *parser, struct hid_item *item) 295dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 296dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->tag) { 297880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_PUSH: 298dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 299880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { 300880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("global enviroment stack overflow\n"); 301880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 302880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 303dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 304880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby memcpy(parser->global_stack + parser->global_stack_ptr++, 305880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby &parser->global, sizeof(struct hid_global)); 306880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 307dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 308880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_POP: 309dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 310880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (!parser->global_stack_ptr) { 311880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("global enviroment stack underflow\n"); 312880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 313880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 314dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 315880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby memcpy(&parser->global, parser->global_stack + 316880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby --parser->global_stack_ptr, sizeof(struct hid_global)); 317880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 318dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 319880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: 320880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.usage_page = item_udata(item); 321880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 322dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 323880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: 324880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.logical_minimum = item_sdata(item); 325880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 326dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 327880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: 328880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.logical_minimum < 0) 329880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.logical_maximum = item_sdata(item); 330880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby else 331880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.logical_maximum = item_udata(item); 332880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 333dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 334880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: 335880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.physical_minimum = item_sdata(item); 336880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 337dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 338880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: 339880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.physical_minimum < 0) 340880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.physical_maximum = item_sdata(item); 341880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby else 342880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.physical_maximum = item_udata(item); 343880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 344dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 345880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: 346880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.unit_exponent = item_sdata(item); 347880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 348dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 349880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_UNIT: 350880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.unit = item_udata(item); 351880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 352dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 353880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: 354880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_size = item_udata(item); 355880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.report_size > 32) { 356880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("invalid report_size %d\n", 357880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_size); 358880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 359880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 360880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 361dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 362880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: 363880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_count = item_udata(item); 364880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.report_count > HID_MAX_USAGES) { 365880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("invalid report_count %d\n", 366880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_count); 367880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 368880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 369880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 370dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 371880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_GLOBAL_ITEM_TAG_REPORT_ID: 372880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->global.report_id = item_udata(item); 373880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->global.report_id == 0) { 374880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("report_id 0 is invalid\n"); 375dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 376880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 377880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 378880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 379880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby default: 380880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("unknown global tag 0x%x\n", item->tag); 381880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 382dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 383dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 384dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 385dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 386dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a local item. 387dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 388dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 389dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_local(struct hid_parser *parser, struct hid_item *item) 390dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 391dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __u32 data; 392dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 393dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 394dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (item->size == 0) { 39558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("item data expected for local item\n"); 396dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 397dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 398dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 399dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina data = item_udata(item); 400dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 401dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->tag) { 402880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_DELIMITER: 403880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 404880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (data) { 405880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby /* 406880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * We treat items before the first delimiter 407880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * as global to all usage sets (branch 0). 408880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * In the moment we process only these global 409880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby * items and the first delimiter set. 410880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby */ 411880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_depth != 0) { 412880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("nested delimiters\n"); 413880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 414dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 415880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.delimiter_depth++; 416880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.delimiter_branch++; 417880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } else { 418880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_depth < 1) { 419880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("bogus close delimiter\n"); 420880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 421dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 422880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.delimiter_depth--; 423880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 424880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 1; 425dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 426880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_USAGE: 427dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 428880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_branch > 1) { 429880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("alternative usage ignored\n"); 430880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 431880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 432dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 433880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (item->size <= 2) 434880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby data = (parser->global.usage_page << 16) + data; 435dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 436880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return hid_add_usage(parser, data); 437dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 438880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: 439dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 440880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_branch > 1) { 441880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("alternative usage ignored\n"); 442dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 443880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 444dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 445880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (item->size <= 2) 446880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby data = (parser->global.usage_page << 16) + data; 447dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 448880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby parser->local.usage_minimum = data; 449880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 450dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 451880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: 452dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 453880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (parser->local.delimiter_branch > 1) { 454880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("alternative usage ignored\n"); 455dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 456880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 457dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 458880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (item->size <= 2) 459880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby data = (parser->global.usage_page << 16) + data; 460dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 461880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby for (n = parser->local.usage_minimum; n <= data; n++) 462880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if (hid_add_usage(parser, n)) { 463880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("hid_add_usage failed\n"); 464880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return -1; 465880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby } 466880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 467880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 468880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby default: 469880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 470880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("unknown local item tag 0x%x\n", item->tag); 471880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return 0; 472dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 473dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 474dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 475dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 476dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 477dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a main item. 478dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 479dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 480dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_main(struct hid_parser *parser, struct hid_item *item) 481dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 482dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __u32 data; 483dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina int ret; 484dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 485dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina data = item_udata(item); 486dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 487dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->tag) { 488880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: 489880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = open_collection(parser, data & 0xff); 490880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 491880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_END_COLLECTION: 492880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = close_collection(parser); 493880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 494880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_INPUT: 495880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = hid_add_field(parser, HID_INPUT_REPORT, data); 496880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 497880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_OUTPUT: 498880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); 499880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 500880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case HID_MAIN_ITEM_TAG_FEATURE: 501880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = hid_add_field(parser, HID_FEATURE_REPORT, data); 502880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby break; 503880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby default: 504880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby dbg_hid("unknown main item tag 0x%x\n", item->tag); 505880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby ret = 0; 506dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 507dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 508dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ 509dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 510dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return ret; 511dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 512dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 513dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 514dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Process a reserved item. 515dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 516dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 517dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item) 518dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 51958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("reserved item type, tag 0x%x\n", item->tag); 520dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 521dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 522dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 523dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 524dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Free a report and all registered fields. The field->usage and 525dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * field->value table's are allocated behind the field, so we need 526dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * only to free(field) itself. 527dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 528dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 529dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic void hid_free_report(struct hid_report *report) 530dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 531dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 532dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 533dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < report->maxfield; n++) 534dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(report->field[n]); 535dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(report); 536dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 537dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 538dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 539dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Free a device structure, all reports, and all fields. 540dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 541dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 54285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_device_release(struct device *dev) 543dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 54485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *device = container_of(dev, struct hid_device, dev); 54585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned i, j; 546dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 547dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (i = 0; i < HID_REPORT_TYPES; i++) { 548dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report_enum *report_enum = device->report_enum + i; 549dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 550dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (j = 0; j < 256; j++) { 551dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_report *report = report_enum->report_id_hash[j]; 552dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report) 553dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_free_report(report); 554dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 555dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 556dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 557dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(device->rdesc); 558767fe7877c2928b5633992ee60a49ad4516dc2afJiri Kosina kfree(device->collection); 559dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(device); 560dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 561dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 562dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 563dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Fetch a report description item from the data stream. We support long 564dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * items, though they are not used yet. 565dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 566dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 567dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) 568dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 569dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina u8 b; 570dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 571dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((end - start) <= 0) 572dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 573dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 574dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina b = *start++; 575dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 576dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->type = (b >> 2) & 3; 577dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->tag = (b >> 4) & 15; 578dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 579dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (item->tag == HID_ITEM_TAG_LONG) { 580dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 581dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->format = HID_ITEM_FORMAT_LONG; 582dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 583dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((end - start) < 2) 584dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 585dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 586dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->size = *start++; 587dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->tag = *start++; 588dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 589dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if ((end - start) < item->size) 590dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 591dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 592dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->data.longdata = start; 593dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina start += item->size; 594dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return start; 595dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 596dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 597dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->format = HID_ITEM_FORMAT_SHORT; 598dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item->size = b & 3; 599dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 600dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (item->size) { 601880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 0: 602880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 603dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 604880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 1: 605880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if ((end - start) < 1) 606880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return NULL; 607880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->data.u8 = *start++; 608880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 609880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 610880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 2: 611880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if ((end - start) < 2) 612880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return NULL; 613880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->data.u16 = get_unaligned_le16(start); 614880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby start = (__u8 *)((__le16 *)start + 1); 615880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 616880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby 617880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 3: 618880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->size++; 619880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby if ((end - start) < 4) 620880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return NULL; 621880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby item->data.u32 = get_unaligned_le32(start); 622880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby start = (__u8 *)((__le32 *)start + 1); 623880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby return start; 624dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 625dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 626dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return NULL; 627dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 628dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 62985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 63085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_parse_report - parse device report 63185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 63285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @device: hid device 63385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @start: report start 63485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @size: report size 63585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 636dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Parse a report description into a hid_device structure. Reports are 637dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * enumerated, fields are attached to these reports. 63885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 0 returned on success, otherwise nonzero error value. 639dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 64085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_parse_report(struct hid_device *device, __u8 *start, 64185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned size) 642dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 643dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_parser *parser; 644dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_item item; 645dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __u8 *end; 64685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 647dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina static int (*dispatch_type[])(struct hid_parser *parser, 648dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina struct hid_item *item) = { 649dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_main, 650dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_global, 651dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_local, 652dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_parser_reserved 653dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina }; 654dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 655c500c9714011edab021591340042787722db9cf0Jiri Slaby if (device->driver->report_fixup) 656c500c9714011edab021591340042787722db9cf0Jiri Slaby device->driver->report_fixup(device, start, size); 657c500c9714011edab021591340042787722db9cf0Jiri Slaby 65885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby device->rdesc = kmalloc(size, GFP_KERNEL); 65985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (device->rdesc == NULL) 66085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 661dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memcpy(device->rdesc, start, size); 662dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina device->rsize = size; 663dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 66485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby parser = vmalloc(sizeof(struct hid_parser)); 66585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!parser) { 66685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = -ENOMEM; 66785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 668dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 66985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 67047a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina memset(parser, 0, sizeof(struct hid_parser)); 671dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina parser->device = device; 672dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 673dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina end = start + size; 67485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = -EINVAL; 675dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina while ((start = fetch_item(start, end, &item)) != NULL) { 676dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 677dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (item.format != HID_ITEM_FORMAT_SHORT) { 67858037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("unexpected long global item\n"); 67985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 680dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 681dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 682dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (dispatch_type[item.type](parser, &item)) { 68358037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("item %u %u %u %u parsing failed\n", 684dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); 68585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 686dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 687dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 688dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (start == end) { 689dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->collection_stack_ptr) { 69058037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("unbalanced collection at end of report description\n"); 69185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 692dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 693dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (parser->local.delimiter_depth) { 69458037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("unbalanced delimiter at end of report description\n"); 69585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 696dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 69747a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina vfree(parser); 69885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 699dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 700dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 701dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 70258037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("item fetching failed at offset %d\n", (int)(end - start)); 70385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr: 70447a80edb1d80ae644ea374a016c8e68d43d2671fJiri Kosina vfree(parser); 70585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 706dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 707229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_parse_report); 708dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 709dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 710dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Convert a signed n-bit integer to signed 32-bit integer. Common 711dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * cases are done through the compiler, the screwed things has to be 712dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * done by hand. 713dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 714dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 715dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic s32 snto32(__u32 value, unsigned n) 716dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 717dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina switch (n) { 718880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 8: return ((__s8)value); 719880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 16: return ((__s16)value); 720880d29f109428be1d027adf919a7457d8fe41fd3Jiri Slaby case 32: return ((__s32)value); 721dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 722dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return value & (1 << (n - 1)) ? value | (-1 << n) : value; 723dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 724dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 725dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 726dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Convert a signed 32-bit integer to a signed n-bit integer. 727dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 728dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 729dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic u32 s32ton(__s32 value, unsigned n) 730dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 731dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina s32 a = value >> (n - 1); 732dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (a && a != -1) 733dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; 734dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return value & ((1 << n) - 1); 735dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 736dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 737dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 738dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Extract/implement a data field from/to a little endian report (bit array). 739dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * 740dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Code sort-of follows HID spec: 741dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * http://www.usb.org/developers/devclass_docs/HID1_11.pdf 742dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * 743dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * While the USB HID spec allows unlimited length bit fields in "report 744dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * descriptors", most devices never use more than 16 bits. 745dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * One model of UPS is claimed to report "LINEV" as a 32-bit field. 746dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Search linux-kernel and linux-usb-devel archives for "hid-core extract". 747dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 748dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 749dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) 750dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 751dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina u64 x; 752dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 753c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina if (n > 32) 754c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n", 755c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina n, current->comm); 756dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 757dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report += offset >> 3; /* adjust byte index */ 758229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina offset &= 7; /* now only need bit offset into one byte */ 759c105068f2b35343eecf2bf16ee29a362b6121fa3Harvey Harrison x = get_unaligned_le64(report); 760229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosina x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */ 761dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return (u32) x; 762dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 763dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 764dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 765dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * "implement" : set bits in a little endian bit stream. 766dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Same concepts as "extract" (see comments above). 767dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * The data mangled in the bit stream remains in little endian 768dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * order the whole time. It make more sense to talk about 769dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * endianness of register values by considering a register 770dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * a "cached" copy of the little endiad bit stream. 771dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 772dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) 773dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 7746f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison u64 x; 775dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina u64 m = (1ULL << n) - 1; 776dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 777c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina if (n > 32) 778c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n", 779c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina n, current->comm); 780dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 781c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina if (value > m) 782c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n", 783c4124c9b68bf8ecf1e8afedad3a22e18666cb6f3Jiri Kosina value, current->comm); 784dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina WARN_ON(value > m); 785dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina value &= m; 786dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 787dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina report += offset >> 3; 788dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina offset &= 7; 789dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 7906f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison x = get_unaligned_le64(report); 7916f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison x &= ~(m << offset); 7926f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison x |= ((u64)value) << offset; 7936f0168d2dacd7972d887e1ca27943ef8af7512a5Harvey Harrison put_unaligned_le64(x, report); 794dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 795dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 796dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 797dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Search an array for a value. 798dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 799dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 800dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic __inline__ int search(__s32 *array, __s32 value, unsigned n) 801dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 802dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina while (n--) { 803dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (*array++ == value) 804dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 805dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 806dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 807dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 808dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 80985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 81085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_match_report - check if driver's raw_event should be called 81185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 81285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device 81385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @report_type: type to match against 81485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 81585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * compare hid->driver->report_table->report_type to report->type 81685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 81785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_match_report(struct hid_device *hid, struct hid_report *report) 818dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 81985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const struct hid_report_id *id = hid->driver->report_table; 82085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 82185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!id) /* NULL means all */ 82285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 82385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 82485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (; id->report_type != HID_TERMINATOR; id++) 82585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (id->report_type == HID_ANY_ID || 82685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->report_type == report->type) 82785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 82885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 82985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 83085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 83185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 83285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_match_usage - check if driver's event should be called 83385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 83485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device 83585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @usage: usage to match against 83685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 83785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * compare hid->driver->usage_table->usage_{type,code} to 83885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * usage->usage_{type,code} 83985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 84085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_match_usage(struct hid_device *hid, struct hid_usage *usage) 84185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 84285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const struct hid_usage_id *id = hid->driver->usage_table; 84385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 84485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!id) /* NULL means all */ 84585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 84685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 84785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (; id->usage_type != HID_ANY_ID - 1; id++) 84885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if ((id->usage_hid == HID_ANY_ID || 84985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->usage_hid == usage->hid) && 85085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby (id->usage_type == HID_ANY_ID || 85185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->usage_type == usage->type) && 85285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby (id->usage_code == HID_ANY_ID || 85385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby id->usage_code == usage->code)) 85485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 85585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 85685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 85785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 85885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_process_event(struct hid_device *hid, struct hid_field *field, 85985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_usage *usage, __s32 value, int interrupt) 86085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 86185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = hid->driver; 86285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 86385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 864dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_dump_input(usage, value); 86585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 86685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv && hdrv->event && hid_match_usage(hid, usage)) { 86785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = hdrv->event(hid, field, usage, value); 86885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret != 0) { 86985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret < 0) 87085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("%s's event failed with %d\n", 87185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->name, ret); 87285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return; 87385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 87485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 87585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 876dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 877dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hidinput_hid_event(hid, field, usage, value); 878aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 879aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina hid->hiddev_hid_event(hid, field, usage, value); 880dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 881dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 882dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 883dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Analyse a received field, and fetch the data from it. The field 884dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * content is stored for next report processing (we do differential 885dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * reporting to the layer). 886dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 887dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 888abdff0f7749a6696ba2a4238b675cbc55abcdb7aAdrian Bunkstatic void hid_input_field(struct hid_device *hid, struct hid_field *field, 889abdff0f7749a6696ba2a4238b675cbc55abcdb7aAdrian Bunk __u8 *data, int interrupt) 890dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 891dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 892dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned count = field->report_count; 893dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned offset = field->report_offset; 894dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned size = field->report_size; 895dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __s32 min = field->logical_minimum; 896dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __s32 max = field->logical_maximum; 897dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina __s32 *value; 898dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 899dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC))) 900dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return; 901dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 902dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < count; n++) { 903dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 904dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) : 905dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina extract(data, offset + n * size, size); 906dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 907dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */ 908dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && value[n] >= min && value[n] <= max 909dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) 910dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina goto exit; 911dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 912dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 913dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < count; n++) { 914dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 915dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (HID_MAIN_ITEM_VARIABLE & field->flags) { 916dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_process_event(hid, field, &field->usage[n], value[n], interrupt); 917dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina continue; 918dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 919dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 920dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (field->value[n] >= min && field->value[n] <= max 921dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && field->usage[field->value[n] - min].hid 922dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && search(value, field->value[n], count)) 923dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt); 924dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 925dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (value[n] >= min && value[n] <= max 926dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && field->usage[value[n] - min].hid 927dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina && search(field->value, value[n], count)) 928dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt); 929dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 930dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 931dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina memcpy(field->value, value, count * sizeof(__s32)); 932dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinaexit: 933dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina kfree(value); 934dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 935dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 936dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 937dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Output the field into the report. 938dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 939dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 940dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinastatic void hid_output_field(struct hid_field *field, __u8 *data) 941dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 942dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned count = field->report_count; 943dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned offset = field->report_offset; 944dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned size = field->report_size; 94546386b587086c8d2698222a031bf749688464032Simon Budig unsigned bitsused = offset + count * size; 946dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 947dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 94846386b587086c8d2698222a031bf749688464032Simon Budig /* make sure the unused bits in the last byte are zeros */ 94946386b587086c8d2698222a031bf749688464032Simon Budig if (count > 0 && size > 0 && (bitsused % 8) != 0) 95046386b587086c8d2698222a031bf749688464032Simon Budig data[(bitsused-1)/8] &= (1 << (bitsused % 8)) - 1; 95146386b587086c8d2698222a031bf749688464032Simon Budig 952dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < count; n++) { 953dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (field->logical_minimum < 0) /* signed values */ 954dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina implement(data, offset + n * size, size, s32ton(field->value[n], size)); 955dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina else /* unsigned values */ 956dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina implement(data, offset + n * size, size, field->value[n]); 957dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 958dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 959dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 960dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 961dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Create a report. 962dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 963dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 964229695e51efc4ed5e04ab471c82591d0f432909dJiri Kosinavoid hid_output_report(struct hid_report *report, __u8 *data) 965dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 966dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned n; 967dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 968dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (report->id > 0) 969dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina *data++ = report->id; 970dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 971dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina for (n = 0; n < report->maxfield; n++) 972dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_output_field(report->field[n], data); 973dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 974229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_output_report); 975dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 976dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina/* 977dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * Set a field value. The report this field belongs to has to be 978dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * created and transferred to the device, to set this value in the 979dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina * device. 980dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina */ 981dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 982dde5845a529ff753364a6d1aea61180946270bfaJiri Kosinaint hid_set_field(struct hid_field *field, unsigned offset, __s32 value) 983dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina{ 984dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina unsigned size = field->report_size; 985dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 986dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_dump_input(field->usage + offset, value); 987dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 988dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (offset >= field->report_count) { 98958037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("offset (%d) exceeds report_count (%d)\n", offset, field->report_count); 990dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina hid_dump_field(field, 8); 991dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 992dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 993dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (field->logical_minimum < 0) { 994dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina if (value != snto32(s32ton(value, size), size)) { 99558037eb961f859607b161c50d9d4ecb374de1e8fJiri Kosina dbg_hid("value %d is out of range\n", value); 996dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return -1; 997dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 998dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina } 999dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina field->value[offset] = value; 1000dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina return 0; 1001dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina} 1002229695e51efc4ed5e04ab471c82591d0f432909dJiri KosinaEXPORT_SYMBOL_GPL(hid_set_field); 1003dde5845a529ff753364a6d1aea61180946270bfaJiri Kosina 100485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic struct hid_report *hid_get_report(struct hid_report_enum *report_enum, 100585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const u8 *data) 1006aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina{ 1007aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina struct hid_report *report; 100885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int n = 0; /* Normally report number is 0 */ 1009aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 101085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby /* Device uses numbered reports, data[0] is report number */ 101185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (report_enum->numbered) 101285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby n = *data; 1013aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 101485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby report = report_enum->report_id_hash[n]; 101585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (report == NULL) 101685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("undefined report_id %u received\n", n); 1017aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 101885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return report; 101985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 1020aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 102185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, 102285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int interrupt) 102385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 102485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report_enum *report_enum = hid->report_enum + type; 102585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report *report; 102685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int a; 102785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int rsize, csize = size; 102885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby u8 *cdata = data; 1029aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 103085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby report = hid_get_report(report_enum, data); 103185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!report) 103285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return; 1033aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 103485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (report_enum->numbered) { 103585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby cdata++; 103685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby csize--; 1037aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina } 1038aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1039aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina rsize = ((report->size - 1) >> 3) + 1; 1040aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 104185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (csize < rsize) { 104285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("report %d is too short, (%d < %d)\n", report->id, 104385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby csize, rsize); 104485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby memset(cdata + csize, 0, rsize - csize); 1045aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina } 1046aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1047aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) 1048aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina hid->hiddev_report_event(hid, report); 1049b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina if (hid->claimed & HID_CLAIMED_HIDRAW) { 1050b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina /* numbered reports need to be passed with the report num */ 1051b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina if (report_enum->numbered) 1052b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina hidraw_report_event(hid, data - 1, size + 1); 1053b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina else 1054b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina hidraw_report_event(hid, data, size); 1055b54ec3c13cf77d21bab25d8bb117f642561fdf4fJiri Kosina } 1056aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 105785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (a = 0; a < report->maxfield; a++) 105885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hid_input_field(hid, report->field[a], cdata, interrupt); 1059aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1060aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina if (hid->claimed & HID_CLAIMED_INPUT) 1061aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina hidinput_report_event(hid, report); 106285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 106385cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_report_raw_event); 106485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 106585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 106685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_input_report - report data from lower layer (usb, bt...) 106785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 106885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hid: hid device 106985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @type: HID report type (HID_*_REPORT) 107085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @data: report contents 107185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @size: size of data parameter 107285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @interrupt: called from atomic? 107385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 107485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * This is data entry for lower layers. 107585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 107685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) 107785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 107885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report_enum *report_enum = hid->report_enum + type; 107985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = hid->driver; 108085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_report *report; 108185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int i; 108285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 108385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 108485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!hid || !hid->driver) 108585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENODEV; 108685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 108785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!size) { 108885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("empty report\n"); 108985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -1; 109085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 109185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 109285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un"); 109385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 109485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby report = hid_get_report(report_enum, data); 109585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!report) 109685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -1; 109785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 109885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby /* dump the report */ 109985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid("report %d (size %u) = ", report->id, size); 110085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (i = 0; i < size; i++) 110185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid_line(" %02x", data[i]); 110285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby dbg_hid_line("\n"); 110385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 110485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { 110585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = hdrv->raw_event(hid, report, data, size); 110685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret != 0) 110785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret < 0 ? ret : 0; 110885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 110985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 111085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hid_report_raw_event(hid, type, data, size, interrupt); 1111aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 1112aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina return 0; 1113aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina} 1114aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri KosinaEXPORT_SYMBOL_GPL(hid_input_report); 1115aa8de2f038baec993f07ef66fb3e94481d1ec22bJiri Kosina 11160f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic bool hid_match_one_id(struct hid_device *hdev, 11170f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina const struct hid_device_id *id) 11180f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{ 11190f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return id->bus == hdev->bus && 11200f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) && 11210f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina (id->product == HID_ANY_ID || id->product == hdev->product); 11220f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina} 11230f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11240f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic const struct hid_device_id *hid_match_id(struct hid_device *hdev, 11250f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina const struct hid_device_id *id) 11260f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{ 11270f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina for (; id->bus; id++) 11280f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina if (hid_match_one_id(hdev, id)) 11290f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return id; 11300f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11310f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return NULL; 11320f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina} 11330f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11340f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic const struct hid_device_id hid_hiddev_list[] = { 1135c0bd6a429819f794f626f9e73be4564e18e132dbRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) }, 1136c0bd6a429819f794f626f9e73be4564e18e132dbRichard Hughes { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) }, 11370f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina { } 11380f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina}; 11390f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 11400f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosinastatic bool hid_hiddev(struct hid_device *hdev) 11410f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina{ 11420f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina return !!hid_match_id(hdev, hid_hiddev_list); 11430f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina} 11440f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina 114593c10132a7ac160df3175b53f7ee857625412165Jiri Slabyint hid_connect(struct hid_device *hdev, unsigned int connect_mask) 114693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby{ 114793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 114893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby "Joystick", "Gamepad", "Keyboard", "Keypad", 114993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby "Multi-Axis Controller" 115093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby }; 115193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby const char *type, *bus; 115293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby char buf[64]; 115393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby unsigned int i; 115493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby int len; 115593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 115693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->bus != BUS_USB) 115793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby connect_mask &= ~HID_CONNECT_HIDDEV; 11580f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina if (hid_hiddev(hdev)) 11590f37cd0306463ad35f958d8f74a2b00e5b190b4bJiri Kosina connect_mask |= HID_CONNECT_HIDDEV_FORCE; 116093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 116193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, 116293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby connect_mask & HID_CONNECT_HIDINPUT_FORCE)) 116393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->claimed |= HID_CLAIMED_INPUT; 116493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && 116593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby !hdev->hiddev_connect(hdev, 116693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby connect_mask & HID_CONNECT_HIDDEV_FORCE)) 116793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->claimed |= HID_CLAIMED_HIDDEV; 116893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev)) 116993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->claimed |= HID_CLAIMED_HIDRAW; 117093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 117193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (!hdev->claimed) { 117293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby dev_err(&hdev->dev, "claimed by neither input, hiddev nor " 117393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby "hidraw\n"); 117493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby return -ENODEV; 117593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 117693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 117793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if ((hdev->claimed & HID_CLAIMED_INPUT) && 117893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby (connect_mask & HID_CONNECT_FF) && hdev->ff_init) 117993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->ff_init(hdev); 118093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 118193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len = 0; 118293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->claimed & HID_CLAIMED_INPUT) 118393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len += sprintf(buf + len, "input"); 118493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->claimed & HID_CLAIMED_HIDDEV) 118593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len += sprintf(buf + len, "%shiddev%d", len ? "," : "", 118693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby hdev->minor); 118793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (hdev->claimed & HID_CLAIMED_HIDRAW) 118893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby len += sprintf(buf + len, "%shidraw%d", len ? "," : "", 118993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby ((struct hidraw *)hdev->hidraw)->minor); 119093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 119193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby type = "Device"; 119293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby for (i = 0; i < hdev->maxcollection; i++) { 119393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby struct hid_collection *col = &hdev->collection[i]; 119493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby if (col->type == HID_COLLECTION_APPLICATION && 119593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK && 119693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby (col->usage & 0xffff) < ARRAY_SIZE(types)) { 119793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby type = types[col->usage & 0xffff]; 119893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby break; 119993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 120093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 120193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 120293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby switch (hdev->bus) { 120393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby case BUS_USB: 120493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby bus = "USB"; 120593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby break; 120693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby case BUS_BLUETOOTH: 120793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby bus = "BLUETOOTH"; 120893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby break; 120993c10132a7ac160df3175b53f7ee857625412165Jiri Slaby default: 121093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby bus = "<UNKNOWN>"; 121193c10132a7ac160df3175b53f7ee857625412165Jiri Slaby } 121293c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 121393c10132a7ac160df3175b53f7ee857625412165Jiri Slaby dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 121493c10132a7ac160df3175b53f7ee857625412165Jiri Slaby buf, bus, hdev->version >> 8, hdev->version & 0xff, 121593c10132a7ac160df3175b53f7ee857625412165Jiri Slaby type, hdev->name, hdev->phys); 121693c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 121793c10132a7ac160df3175b53f7ee857625412165Jiri Slaby return 0; 121893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby} 121993c10132a7ac160df3175b53f7ee857625412165Jiri SlabyEXPORT_SYMBOL_GPL(hid_connect); 122093c10132a7ac160df3175b53f7ee857625412165Jiri Slaby 1221bae7eb33b25387fdc7ccae08768bef1f9484a5b0Jiri Kosina/* a list of devices for which there is a specialized driver on HID bus */ 122285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic const struct hid_device_id hid_blacklist[] = { 122314a21cd459f97e3b3cc4fcde48fc5bcdb81d097eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 122414a21cd459f97e3b3cc4fcde48fc5bcdb81d097eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1225df9bcace7b1c29e9be1c13b034ff04f4f4c90edeJiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, 12268c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, 12278c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, 12288c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 12298c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 12308c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 12318c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 12328c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 12338c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 12348c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 12358c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 12368c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 12378c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 12388c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 1239fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) }, 1240fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) }, 1241fef3f571ecc2a82395c531d97b3f71a59e04e946Ryan Finnie { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) }, 12428c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) }, 12438c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) }, 12448c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) }, 12458c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 12468c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 12478c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 1248ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) }, 1249ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) }, 1250ee8a1a0a1a5817accd03ced7e7ffde3a4430f485Jan Scholz { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) }, 12518c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 12528c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 12538c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 12548c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 12558c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 12568c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 1257a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1258a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1259a96d6ef34751093797c3a6c6080733dd7af23d35Henrik Rydberg { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 12608c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 12618c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1262b5635b129b3ca3a9c879a36f58f5b8c4903d267aJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, 12633b239cd739a9499da08326356add3d9d992c7911Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 1264fcfacfd3594d5d2fa99fb5e7d33dee3904b1a156Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 12650f2213208f8da51bcb665309e3468f000489c04fJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, 12660f2213208f8da51bcb665309e3468f000489c04fJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, 12670f2213208f8da51bcb665309e3468f000489c04fJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) }, 12683f866fbd52d1863db5c07700e560aef22c4fdc01Richard Walmsley { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, 12691f243e302cea1561ac881eb5d27041c5342beba4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, 12705181e594512faeac7d7fd9620ce91105f45bf643Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) }, 1271578f3a35fecabff49bad808c5301313f785b5462Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) }, 12725181e594512faeac7d7fd9620ce91105f45bf643Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) }, 127342859e0bd21daba9974757fcfe4a4dde265fe28dLukasz Lubojanski { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) }, 1274949f8fef77186c7361d22e1ea6f42c76ceda42b0Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) }, 12751e093206734568e780c2717da1c89b97e9471954Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, 1276fdf93aa33268889e126aa677f2072238bd76adb0Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, 1277794227415f8f5f395a9ed4269a4ee7a3c34f66a5Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 1278b5635b129b3ca3a9c879a36f58f5b8c4903d267aJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 12795f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) }, 12805f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) }, 12815f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) }, 12825f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) }, 12835f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) }, 12845f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) }, 12855f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) }, 12865f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) }, 12875f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) }, 12885f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) }, 12895f22a7992349c5ca3842190be52d5e9a1dd7adf4Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) }, 1290606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, 1291606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, 1292606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, 1293606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, 1294606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, 1295606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, 1296243b706d8a71364ad6080328d45b73516c8af5f3Christophe Borivant { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, 1297606bd0a8616a0e59021cb2997e942513f24f641dJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, 129878a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) }, 129978a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) }, 130078a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) }, 130178a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, 130278a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 13033b8006e51038ef263a0404756d9e190c9a9f74d5Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, 130494011f93f2cd7410401e22390cf7a14fe5495a22Rafi Rubin { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, 13051e76253220dbe66e048e55680266dd1f4af0be85Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 1306980a3da6acdd577ee3ae192e868dc52fe4b7f2e5Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1307bd28ce008bdc68ef5902f68d2d62cbb7fa78c415Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1308cc6e0bbb47f02fd36cd55b3189c0c79079096ab8Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, 130990231e7eaf752856a2c13f786f36ec7f641bad28Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, 1310daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, 1311daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, 1312daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) }, 1313daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) }, 1314f14f526d02b14fd0b8c1ac4ec413e4577ad5f62eLev Babiev { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 1315ca2dcd40f54c8928b3994712a6cadd2078a087faBastien Nocera { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 1316daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, 1317daedb3d6a91f9626ab4c921378ac52e44de833d5Anssi Hannula { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, 13188c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby 13198c19a51591d06f5226499972567f528cf6066bb7Jiri Slaby { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c) }, 132078a849a682a1d5ee7b7187b08abdc48656326a4eJiri Slaby { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, 132185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby { } 132285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}; 132385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 13243a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystruct hid_dynid { 13253a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct list_head list; 13263a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_device_id id; 13273a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby}; 13283a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13293a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby/** 13303a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * store_new_id - add a new HID device ID to this driver and re-probe devices 13313a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @driver: target device driver 13323a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @buf: buffer for scanning device ID data 13333a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * @count: input size 13343a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * 13353a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * Adds a new dynamic hid device ID to this driver, 13363a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby * and causes the driver to probe for all devices again. 13373a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby */ 13383a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic ssize_t store_new_id(struct device_driver *drv, const char *buf, 13393a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby size_t count) 13403a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{ 13413a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 13423a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_dynid *dynid; 13433a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby __u32 bus, vendor, product; 13443a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby unsigned long driver_data = 0; 13453a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby int ret; 13463a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13473a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = sscanf(buf, "%x %x %x %lx", 13483a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby &bus, &vendor, &product, &driver_data); 13493a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (ret < 3) 13503a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return -EINVAL; 13513a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13523a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); 13533a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (!dynid) 13543a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return -ENOMEM; 13553a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13563a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.bus = bus; 13573a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.vendor = vendor; 13583a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.product = product; 13593a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby dynid->id.driver_data = driver_data; 13603a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13613a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock(&hdrv->dyn_lock); 13623a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_add_tail(&dynid->list, &hdrv->dyn_list); 13633a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 13643a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13653a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = 0; 13663a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (get_driver(&hdrv->driver)) { 13673a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = driver_attach(&hdrv->driver); 13683a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby put_driver(&hdrv->driver); 13693a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 13703a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13713a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return ret ? : count; 13723a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby} 13733a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 13743a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13753a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic void hid_free_dynids(struct hid_driver *hdrv) 13763a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{ 13773a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_dynid *dynid, *n; 13783a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13793a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock(&hdrv->dyn_lock); 13803a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) { 13813a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_del(&dynid->list); 13823a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby kfree(dynid); 13833a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 13843a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 13853a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby} 13863a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13873a6f82f7a22cf19687f556997c6978b31c109360Jiri Slabystatic const struct hid_device_id *hid_match_device(struct hid_device *hdev, 13883a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_driver *hdrv) 13893a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby{ 13903a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby struct hid_dynid *dynid; 13913a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 13923a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock(&hdrv->dyn_lock); 13933a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby list_for_each_entry(dynid, &hdrv->dyn_list, list) { 13943a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (hid_match_one_id(hdev, &dynid->id)) { 13953a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 13963a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return &dynid->id; 13973a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 13983a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby } 13993a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_unlock(&hdrv->dyn_lock); 14003a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 14013a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return hid_match_id(hdev, hdrv->id_table); 14023a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby} 14033a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 140485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_bus_match(struct device *dev, struct device_driver *drv) 140585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 140685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); 140785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 140885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 14093a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (!hid_match_device(hdev, hdrv)) 141085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 141185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 141285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby /* generic wants all non-blacklisted */ 141385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!strncmp(hdrv->name, "generic-", 8)) 141485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return !hid_match_id(hdev, hid_blacklist); 141585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 141685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 1; 141785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 141885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 141985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_device_probe(struct device *dev) 142085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 142185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = container_of(dev->driver, 142285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver, driver); 142385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 142485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const struct hid_device_id *id; 142585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret = 0; 142685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 142785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!hdev->driver) { 14283a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby id = hid_match_device(hdev, hdrv); 1429c500c9714011edab021591340042787722db9cf0Jiri Slaby if (id == NULL) 1430c500c9714011edab021591340042787722db9cf0Jiri Slaby return -ENODEV; 143185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1432c500c9714011edab021591340042787722db9cf0Jiri Slaby hdev->driver = hdrv; 1433c500c9714011edab021591340042787722db9cf0Jiri Slaby if (hdrv->probe) { 1434c500c9714011edab021591340042787722db9cf0Jiri Slaby ret = hdrv->probe(hdev, id); 1435c500c9714011edab021591340042787722db9cf0Jiri Slaby } else { /* default probe */ 1436c500c9714011edab021591340042787722db9cf0Jiri Slaby ret = hid_parse(hdev); 1437c500c9714011edab021591340042787722db9cf0Jiri Slaby if (!ret) 143893c10132a7ac160df3175b53f7ee857625412165Jiri Slaby ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 143985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 1440c500c9714011edab021591340042787722db9cf0Jiri Slaby if (ret) 1441c500c9714011edab021591340042787722db9cf0Jiri Slaby hdev->driver = NULL; 144285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 144385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 144485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 144585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 144685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_device_remove(struct device *dev) 144785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 144885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 144985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_driver *hdrv = hdev->driver; 145085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 145185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv) { 145285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdrv->remove) 145385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->remove(hdev); 1454c500c9714011edab021591340042787722db9cf0Jiri Slaby else /* default remove */ 1455c500c9714011edab021591340042787722db9cf0Jiri Slaby hid_hw_stop(hdev); 145685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->driver = NULL; 145785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 145885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 145985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 146085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 146185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 146285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic int hid_uevent(struct device *dev, struct kobj_uevent_env *env) 146385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 146485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev = container_of(dev, struct hid_device, dev); 146585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 146685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", 146785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->bus, hdev->vendor, hdev->product)) 146885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 146985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 147085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_NAME=%s", hdev->name)) 147185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 147285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 147385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys)) 147485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 147585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 147685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq)) 147785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 147885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 147985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X", 148085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->bus, hdev->vendor, hdev->product)) 148185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -ENOMEM; 148285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 148385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 148485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 148585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 148685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic struct bus_type hid_bus_type = { 148785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .name = "hid", 148885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .match = hid_bus_match, 148985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .probe = hid_device_probe, 149085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .remove = hid_device_remove, 149185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby .uevent = hid_uevent, 149285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby}; 149385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1494bae7eb33b25387fdc7ccae08768bef1f9484a5b0Jiri Kosina/* a list of devices that shouldn't be handled by HID core at all */ 1495d458a9dfc4de24870b8c747484b1988726534beeJiri Slabystatic const struct hid_device_id hid_ignore_list[] = { 1496d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) }, 1497d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) }, 1498d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) }, 1499d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) }, 1500d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) }, 1501d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) }, 1502d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) }, 1503d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) }, 1504d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) }, 1505d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, 1506d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, 1507d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, 1508d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)}, 1509ac2d98998c32fcdc8d8919b7a4536a7945fd0422Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM2)}, 151062a56582e01b1c5139b235004548e233201df9aaAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, 1511d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, 1512d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, 1513d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, 1514d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) }, 1515d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) }, 1516d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) }, 15175f6108cf9be4a77d6bee96750aa4fe18b6b97deeAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) }, 1518d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, 1519d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, 1520d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, 1521d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) }, 1522d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, 1523d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) }, 1524d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, 1525d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, 1526d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, 1527d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) }, 1528d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) }, 1529d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) }, 1530d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) }, 1531d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) }, 1532d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) }, 1533d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) }, 1534d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) }, 1535d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) }, 1536d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) }, 1537d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) }, 1538d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) }, 1539d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) }, 1540d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) }, 1541d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) }, 1542d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) }, 1543d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) }, 1544d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) }, 1545d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) }, 1546d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) }, 1547d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) }, 1548d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) }, 1549d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) }, 1550d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) }, 1551d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) }, 1552d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) }, 1553d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) }, 1554d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) }, 1555d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) }, 1556d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) }, 1557d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) }, 1558d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) }, 1559d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) }, 1560d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) }, 1561d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) }, 1562d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) }, 1563d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) }, 1564d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) }, 1565d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) }, 1566d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) }, 1567d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) }, 1568d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) }, 1569d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) }, 1570d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) }, 1571d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) }, 1572d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) }, 1573d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) }, 1574d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) }, 1575d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) }, 1576d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) }, 1577d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) }, 1578d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) }, 1579d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) }, 1580d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) }, 1581d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) }, 1582d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) }, 1583d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) }, 1584d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) }, 1585d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) }, 1586d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) }, 1587c91c21c5a6facddce936d82e5bc0c655d04288aaAlexey Klimov { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) }, 1588d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) }, 1589d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, 1590d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, 1591d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, 1592d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) }, 1593d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) }, 1594d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) }, 1595d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) }, 1596d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) }, 1597d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) }, 1598d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) }, 1599d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) }, 1600d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) }, 1601d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) }, 1602d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) }, 1603d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, 1604d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, 1605d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, 1606d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) }, 1607d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) }, 1608d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) }, 1609d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) }, 1610d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) }, 1611d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) }, 1612d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) }, 1613d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) }, 1614d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) }, 1615d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) }, 1616d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) }, 1617d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) }, 1618d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) }, 1619d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) }, 1620d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) }, 1621d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, 162235cfd1d964f3c2420862f2167a0eb85ff1208999Michael Tokarev { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, 1623d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD) }, 162424c88eb671b437d700fbfa7aa79adeb9690db1ebJarod Wilson { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD2) }, 162524c88eb671b437d700fbfa7aa79adeb9690db1ebJarod Wilson { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD3) }, 1626656f1fb90aa2261daa316c0dd8f75e3420f81e9eJarod Wilson { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD4) }, 1627656f1fb90aa2261daa316c0dd8f75e3420f81e9eJarod Wilson { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD5) }, 1628d1d3a5f6eaee337d793ab9ac28e696f0262c3c8aRemi Cattiau { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY1) }, 1629d1d3a5f6eaee337d793ab9ac28e696f0262c3c8aRemi Cattiau { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY2) }, 1630d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, 1631d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, 1632d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, 1633d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, 1634d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) }, 1635d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) }, 1636d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) }, 1637d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) }, 1638d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) }, 1639d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, 1640d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby { } 1641d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby}; 1642d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 1643b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby/** 1644b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer 1645b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * 1646b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * There are composite devices for which we want to ignore only a certain 1647b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * interface. This is a list of devices for which only the mouse interface will 1648b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby * be ignored. This allows a dedicated driver to take care of the interface. 1649b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby */ 1650b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slabystatic const struct hid_device_id hid_mouse_ignore_list[] = { 1651b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby /* appletouch driver */ 1652b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 1653b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 1654b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 1655b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) }, 1656b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) }, 1657b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) }, 1658b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) }, 1659b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) }, 1660b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) }, 1661b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) }, 1662b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) }, 1663b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) }, 1664b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) }, 1665b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) }, 1666b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) }, 1667b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) }, 1668b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) }, 1669b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) }, 1670b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) }, 1671b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) }, 1672ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) }, 1673ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) }, 1674ac26fca3e14c8882e382daa7e96ab73e0186cf03Jiri Kosina { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) }, 1675b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1676b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1677b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby { } 1678b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby}; 1679b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby 1680d458a9dfc4de24870b8c747484b1988726534beeJiri Slabystatic bool hid_ignore(struct hid_device *hdev) 1681d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby{ 1682d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby switch (hdev->vendor) { 1683d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby case USB_VENDOR_ID_CODEMERCS: 1684d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby /* ignore all Code Mercenaries IOWarrior devices */ 1685d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST && 1686d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST) 1687d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return true; 1688d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby break; 1689d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby case USB_VENDOR_ID_LOGITECH: 1690d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST && 1691d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST) 1692d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return true; 1693d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby break; 1694d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby } 1695d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 1696b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby if (hdev->type == HID_TYPE_USBMOUSE && 1697b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby hid_match_id(hdev, hid_mouse_ignore_list)) 1698b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby return true; 1699b4d8e4736c94e78fd846dca0c95a3a0710582584Jiri Slaby 1700d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return !!hid_match_id(hdev, hid_ignore_list); 1701d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby} 1702d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 170385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint hid_add_device(struct hid_device *hdev) 170485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 170585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby static atomic_t id = ATOMIC_INIT(0); 170685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 170785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 170885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (WARN_ON(hdev->status & HID_STAT_ADDED)) 170985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return -EBUSY; 171085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 1711d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby /* we need to kill them here, otherwise they will stay allocated to 1712d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby * wait for coming driver */ 1713d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby if (hid_ignore(hdev)) 1714d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby return -ENODEV; 1715d458a9dfc4de24870b8c747484b1988726534beeJiri Slaby 17166bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers /* XXX hack, any other cleaner solution after the driver core 17176bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers * is converted to allow more than 20 bytes as the device name? */ 17186bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, 17196bbe586fd4d94439f3960e200056ff057f7db5c6Kay Sievers hdev->vendor, hdev->product, atomic_inc_return(&id)); 172085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 172185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = device_add(&hdev->dev); 172285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (!ret) 172385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->status |= HID_STAT_ADDED; 172485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 172585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 172685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 172785cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_add_device); 172885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 172985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 173085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_allocate_device - allocate new hid device descriptor 173185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 173285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * Allocate and initialize hid device, so that hid_destroy_device might be 173385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * used to free it. 173485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 173585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * New hid_device pointer is returned on success, otherwise ERR_PTR encoded 173685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * error value. 173785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 173885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystruct hid_device *hid_allocate_device(void) 173985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 174085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby struct hid_device *hdev; 174185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby unsigned int i; 174285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret = -ENOMEM; 174385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 174485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); 174585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdev == NULL) 174685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ERR_PTR(ret); 174785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 174885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby device_initialize(&hdev->dev); 174985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->dev.release = hid_device_release; 175085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->dev.bus = &hid_bus_type; 175185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 175285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, 175385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby sizeof(struct hid_collection), GFP_KERNEL); 175485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdev->collection == NULL) 175585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 175685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS; 175785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 175885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby for (i = 0; i < HID_REPORT_TYPES; i++) 175985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby INIT_LIST_HEAD(&hdev->report_enum[i].report_list); 176085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 176185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return hdev; 176285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr: 176385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby put_device(&hdev->dev); 176485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ERR_PTR(ret); 176585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 176685cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_allocate_device); 176785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 176885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabystatic void hid_remove_device(struct hid_device *hdev) 176985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 177085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (hdev->status & HID_STAT_ADDED) { 177185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby device_del(&hdev->dev); 177285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdev->status &= ~HID_STAT_ADDED; 177385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 177485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 177585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 177685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby/** 177785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * hid_destroy_device - free previously allocated device 177885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 177985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * @hdev: hid device 178085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * 178185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * If you allocate hid_device through hid_allocate_device, you should ever 178285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby * free by this function. 178385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby */ 178485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_destroy_device(struct hid_device *hdev) 178585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 178685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hid_remove_device(hdev); 178785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby put_device(&hdev->dev); 178885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 178985cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_destroy_device); 179085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 179185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyint __hid_register_driver(struct hid_driver *hdrv, struct module *owner, 179285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby const char *mod_name) 179385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 17943a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby int ret; 17953a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 179685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.name = hdrv->name; 179785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.bus = &hid_bus_type; 179885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.owner = owner; 179985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby hdrv->driver.mod_name = mod_name; 180085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 18013a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby INIT_LIST_HEAD(&hdrv->dyn_list); 18023a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby spin_lock_init(&hdrv->dyn_lock); 18033a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 18043a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = driver_register(&hdrv->driver); 18053a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (ret) 18063a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return ret; 18073a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 18083a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby ret = driver_create_file(&hdrv->driver, &driver_attr_new_id); 18093a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby if (ret) 18103a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby driver_unregister(&hdrv->driver); 18113a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby 18123a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby return ret; 181385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 181485cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(__hid_register_driver); 181585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 181685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyvoid hid_unregister_driver(struct hid_driver *hdrv) 181785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby{ 18183a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby driver_remove_file(&hdrv->driver, &driver_attr_new_id); 181985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby driver_unregister(&hdrv->driver); 18203a6f82f7a22cf19687f556997c6978b31c109360Jiri Slaby hid_free_dynids(hdrv); 182185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby} 182285cdaf524b7ddab627e7d15405693f2511ef7505Jiri SlabyEXPORT_SYMBOL_GPL(hid_unregister_driver); 182385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 18240361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukumint hid_check_keys_pressed(struct hid_device *hid) 18250361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum{ 18260361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum struct hid_input *hidinput; 18270361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum int i; 18280361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 1829e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina if (!(hid->claimed & HID_CLAIMED_INPUT)) 1830e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina return 0; 1831e5288eb5ea89bd82d897cb687348bc608278f920Jiri Kosina 18320361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum list_for_each_entry(hidinput, &hid->inputs, list) { 18330361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++) 18340361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum if (hidinput->input->key[i]) 18350361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum return 1; 18360361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum } 18370361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 18380361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum return 0; 18390361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum} 18400361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 18410361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver NeukumEXPORT_SYMBOL_GPL(hid_check_keys_pressed); 18420361a28d3f9a4315a100c7b37ba0b55cfe15fe07Oliver Neukum 184386166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinastatic int __init hid_init(void) 184486166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina{ 184585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby int ret; 184685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 184785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = bus_register(&hid_bus_type); 184885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret) { 184985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby printk(KERN_ERR "HID: can't register hid bus\n"); 185085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err; 185185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby } 185285cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 185385cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby ret = hidraw_init(); 185485cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby if (ret) 185585cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby goto err_bus; 185685cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby 185785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return 0; 185885cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr_bus: 185985cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby bus_unregister(&hid_bus_type); 186085cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slabyerr: 186185cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby return ret; 186286166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina} 186386166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina 186486166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinastatic void __exit hid_exit(void) 186586166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina{ 186686166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina hidraw_exit(); 186785cdaf524b7ddab627e7d15405693f2511ef7505Jiri Slaby bus_unregister(&hid_bus_type); 186886166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina} 186986166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina 187086166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinamodule_init(hid_init); 187186166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosinamodule_exit(hid_exit); 187286166b7bcda0bcb53525114fa1c87ac432be478eJiri Kosina 1873aa938f7974b82cfd9ee955031987344f332b7c77Jiri KosinaMODULE_LICENSE(DRIVER_LICENSE); 1874aa938f7974b82cfd9ee955031987344f332b7c77Jiri Kosina 1875