Import 2.4.0-test5pre2
[davej-history.git] / drivers / usb / hid.h
blob88ab5eacade3cdd50c6772ba0af9c0cedde02475
1 #ifndef __HID_H
2 #define __HID_H
4 /*
5 * $Id: hid.h,v 1.4 2000/05/29 09:01:52 vojtech Exp $
7 * Copyright (c) 1999 Andreas Gal
8 * Copyright (c) 2000 Vojtech Pavlik
10 * Sponsored by SuSE
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * Should you need to contact me, the author, you can do so either by
29 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
30 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
33 #include <linux/types.h>
34 #include <linux/malloc.h>
35 #include <linux/list.h>
38 * USB HID (Human Interface Device) interface class code
41 #define USB_INTERFACE_CLASS_HID 3
44 * We parse each description item into this structure. Short items data
45 * values are expanded to 32-bit signed int, long items contain a pointer
46 * into the data area.
49 struct hid_item {
50 unsigned format;
51 __u8 size;
52 __u8 type;
53 __u8 tag;
54 union {
55 __u8 u8;
56 __s8 s8;
57 __u16 u16;
58 __s16 s16;
59 __u32 u32;
60 __s32 s32;
61 __u8 *longdata;
62 } data;
66 * HID report item format
69 #define HID_ITEM_FORMAT_SHORT 0
70 #define HID_ITEM_FORMAT_LONG 1
73 * Special tag indicating long items
76 #define HID_ITEM_TAG_LONG 15
79 * HID report descriptor item type (prefix bit 2,3)
82 #define HID_ITEM_TYPE_MAIN 0
83 #define HID_ITEM_TYPE_GLOBAL 1
84 #define HID_ITEM_TYPE_LOCAL 2
85 #define HID_ITEM_TYPE_RESERVED 3
88 * HID report descriptor main item tags
91 #define HID_MAIN_ITEM_TAG_INPUT 8
92 #define HID_MAIN_ITEM_TAG_OUTPUT 9
93 #define HID_MAIN_ITEM_TAG_FEATURE 11
94 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
95 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
98 * HID report descriptor main item contents
101 #define HID_MAIN_ITEM_CONSTANT 0x001
102 #define HID_MAIN_ITEM_VARIABLE 0x002
103 #define HID_MAIN_ITEM_RELATIVE 0x004
104 #define HID_MAIN_ITEM_WRAP 0x008
105 #define HID_MAIN_ITEM_NONLINEAR 0x010
106 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
107 #define HID_MAIN_ITEM_NULL_STATE 0x040
108 #define HID_MAIN_ITEM_VOLATILE 0x080
109 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
112 * HID report descriptor collection item types
115 #define HID_COLLECTION_PHYSICAL 0
116 #define HID_COLLECTION_APPLICATION 1
117 #define HID_COLLECTION_LOGICAL 2
120 * HID report descriptor global item tags
123 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
124 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
125 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
126 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
127 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
128 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
129 #define HID_GLOBAL_ITEM_TAG_UNIT 6
130 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
131 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
132 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
133 #define HID_GLOBAL_ITEM_TAG_PUSH 10
134 #define HID_GLOBAL_ITEM_TAG_POP 11
137 * HID report descriptor local item tags
140 #define HID_LOCAL_ITEM_TAG_USAGE 0
141 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
142 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
143 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
144 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
145 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
146 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
147 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
148 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
149 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
152 * HID usage tables
155 #define HID_USAGE_PAGE 0xffff0000
157 #define HID_UP_GENDESK 0x00010000
158 #define HID_UP_KEYBOARD 0x00070000
159 #define HID_UP_LED 0x00080000
160 #define HID_UP_BUTTON 0x00090000
161 #define HID_UP_CONSUMER 0x000c0000
162 #define HID_UP_DIGITIZER 0x000d0000
163 #define HID_UP_PID 0x000f0000
165 #define HID_USAGE 0x0000ffff
167 #define HID_GD_POINTER 0x00010001
168 #define HID_GD_MOUSE 0x00010002
169 #define HID_GD_JOYSTICK 0x00010004
170 #define HID_GD_GAMEPAD 0x00010005
171 #define HID_GD_HATSWITCH 0x00010039
174 * HID report types --- Ouch! HID spec says 1 2 3!
177 #define HID_INPUT_REPORT 0
178 #define HID_OUTPUT_REPORT 1
179 #define HID_FEATURE_REPORT 2
182 * HID device quirks.
185 #define HID_QUIRK_INVERT 0x01
186 #define HID_QUIRK_NOTOUCH 0x02
189 * This is the global enviroment of the parser. This information is
190 * persistent for main-items. The global enviroment can be saved and
191 * restored with PUSH/POP statements.
194 struct hid_global {
195 unsigned usage_page;
196 __s32 logical_minimum;
197 __s32 logical_maximum;
198 __s32 physical_minimum;
199 __s32 physical_maximum;
200 unsigned unit_exponent;
201 unsigned unit;
202 unsigned report_id;
203 unsigned report_size;
204 unsigned report_count;
208 * This is the local enviroment. It is resistent up the the next main-item.
211 #define MAX_USAGES 1024
213 struct hid_local {
214 unsigned usage[MAX_USAGES]; /* usage array */
215 unsigned usage_index;
216 unsigned usage_minimum;
217 unsigned delimiter_depth;
218 unsigned delimiter_branch;
222 * This is the collection stack. We climb up the stack to determine
223 * application and function of each field.
226 struct hid_collection {
227 unsigned type;
228 unsigned usage;
231 struct hid_usage {
232 unsigned hid; /* hid usage code */
233 __u16 code; /* input driver code */
234 __u8 type; /* input driver type */
235 __u8 hat; /* hat switch fun */
238 struct hid_field {
239 unsigned physical; /* physical usage for this field */
240 unsigned logical; /* logical usage for this field */
241 struct hid_usage *usage; /* usage table for this function */
242 unsigned maxusage; /* maximum usage index */
243 unsigned flags; /* main-item flags (i.e. volatile,array,constant) */
244 unsigned report_offset; /* bit offset in the report */
245 unsigned report_size; /* size of this field in the report */
246 unsigned report_count; /* number of this field in the report */
247 unsigned report_type; /* (input,output,feature) */
248 __s32 *value; /* last known value(s) */
249 __s32 logical_minimum;
250 __s32 logical_maximum;
251 __s32 physical_minimum;
252 __s32 physical_maximum;
253 unsigned unit_exponent;
254 unsigned unit;
255 struct hid_report *report; /* associated report */
258 #define HID_MAX_FIELDS 64
260 struct hid_report {
261 struct list_head list;
262 unsigned id; /* id of this report */
263 unsigned type; /* report type */
264 struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */
265 unsigned maxfield; /* maximum valid field index */
266 unsigned size; /* size of the report (bits) */
267 struct hid_device *device; /* associated device */
270 struct hid_report_enum {
271 unsigned numbered;
272 struct list_head report_list;
273 struct hid_report *report_id_hash[256];
276 #define HID_REPORT_TYPES 3
278 struct hid_device { /* device report descriptor */
279 __u8 *rdesc;
280 unsigned rsize;
281 unsigned application; /* HID application, i.e. Digitizer */
282 unsigned version; /* HID version */
283 unsigned country; /* HID country */
284 struct hid_report_enum report_enum[HID_REPORT_TYPES];
286 struct usb_device *dev; /* USB device */
287 int ifnum; /* USB interface number */
289 char buffer[32]; /* Receive buffer */
290 char bufout[32]; /* Transmit buffer */
291 devrequest dr; /* Startup packet */
292 struct urb urb; /* USB URB structure */
293 struct urb urbout; /* Output URB */
294 struct input_dev input; /* input device structure */
295 int open; /* is the device open by input? */
296 int quirks; /* Various nasty tricks the device can pull on us */
297 char name[128]; /* Device name */
300 #define HID_GLOBAL_STACK_SIZE 4
301 #define HID_COLLECTION_STACK_SIZE 4
303 struct hid_parser {
304 struct hid_global global;
305 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE];
306 unsigned global_stack_ptr;
307 struct hid_local local;
308 struct hid_collection collection_stack[HID_COLLECTION_STACK_SIZE];
309 unsigned collection_stack_ptr;
310 struct hid_device *device;
313 struct hid_class_descriptor {
314 __u8 bDescriptorType;
315 __u16 wDescriptorLength;
316 } __attribute__ ((packed));
318 struct hid_descriptor {
319 __u8 bLength;
320 __u8 bDescriptorType;
321 __u16 bcdHID;
322 __u8 bCountryCode;
323 __u8 bNumDescriptors;
325 struct hid_class_descriptor desc[1];
326 } __attribute__ ((packed));
329 #endif