Import 2.3.47pre4
[davej-history.git] / drivers / usb / hid.h
blob2449039b81518428c9c47b571b00121a95c601a2
1 #ifndef __HID_H
2 #define __HID_H
4 /*
5 * drivers/usb/hid.h Version 0.8
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 * This is the global enviroment of the parser. This information is
183 * persistent for main-items. The global enviroment can be saved and
184 * restored with PUSH/POP statements.
187 struct hid_global {
188 unsigned usage_page;
189 __s32 logical_minimum;
190 __s32 logical_maximum;
191 __s32 physical_minimum;
192 __s32 physical_maximum;
193 unsigned unit_exponent;
194 unsigned unit;
195 unsigned report_id;
196 unsigned report_size;
197 unsigned report_count;
201 * This is the local enviroment. It is resistent up the the next main-item.
204 #define MAX_USAGES 512
206 struct hid_local {
207 unsigned usage[MAX_USAGES]; /* usage array */
208 unsigned usage_index;
209 unsigned usage_minimum;
210 unsigned delimiter_depth;
211 unsigned delimiter_branch;
215 * This is the collection stack. We climb up the stack to determine
216 * application and function of each field.
219 struct hid_collection {
220 unsigned type;
221 unsigned usage;
224 struct hid_usage {
225 unsigned hid; /* hid usage code */
226 __u16 code; /* input driver code */
227 __u8 type; /* input driver type */
228 __u8 hat; /* hat switch fun */
231 struct hid_field {
232 unsigned physical; /* physical usage for this field */
233 unsigned logical; /* logical usage for this field */
234 struct hid_usage *usage; /* usage table for this function */
235 unsigned maxusage; /* maximum usage index */
236 unsigned flags; /* main-item flags (i.e. volatile,array,constant) */
237 unsigned report_offset; /* bit offset in the report */
238 unsigned report_size; /* size of this field in the report */
239 unsigned report_count; /* number of this field in the report */
240 unsigned report_type; /* (input,output,feature) */
241 __s32 *value; /* last known value(s) */
242 __s32 logical_minimum;
243 __s32 logical_maximum;
244 __s32 physical_minimum;
245 __s32 physical_maximum;
246 unsigned unit_exponent;
247 unsigned unit;
248 struct hid_report *report; /* associated report */
251 #define HID_MAX_FIELDS 64
253 struct hid_report {
254 struct list_head list;
255 unsigned id; /* id of this report */
256 unsigned type; /* report type */
257 struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */
258 unsigned maxfield; /* maximum valid field index */
259 unsigned size; /* size of the report (bits) */
260 struct hid_device *device; /* associated device */
263 struct hid_report_enum {
264 unsigned numbered;
265 struct list_head report_list;
266 struct hid_report *report_id_hash[256];
269 #define HID_REPORT_TYPES 3
271 struct hid_device { /* device report descriptor */
272 __u8 *rdesc;
273 unsigned rsize;
274 unsigned application; /* HID application, i.e. Digitizer */
275 unsigned version; /* HID version */
276 unsigned country; /* HID country */
277 struct hid_report_enum report_enum[HID_REPORT_TYPES];
279 struct usb_device *dev; /* USB device */
280 int ifnum; /* USB interface number */
282 char buffer[32]; /* Receive buffer */
283 char bufout[32]; /* Transmit buffer */
284 devrequest dr; /* Startup packet */
285 struct urb urb; /* USB URB structure */
286 struct urb urbout; /* Output URB */
287 struct input_dev input; /* input device structure */
290 #define HID_GLOBAL_STACK_SIZE 4
291 #define HID_COLLECTION_STACK_SIZE 4
293 struct hid_parser {
294 struct hid_global global;
295 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE];
296 unsigned global_stack_ptr;
297 struct hid_local local;
298 struct hid_collection collection_stack[HID_COLLECTION_STACK_SIZE];
299 unsigned collection_stack_ptr;
300 struct hid_device *device;
303 struct hid_class_descriptor {
304 __u8 bDescriptorType;
305 __u16 wDescriptorLength;
306 } __attribute__ ((packed));
308 struct hid_descriptor {
309 __u8 bLength;
310 __u8 bDescriptorType;
311 __u16 bcdHID;
312 __u8 bCountryCode;
313 __u8 bNumDescriptors;
315 struct hid_class_descriptor desc[1];
316 } __attribute__ ((packed));
319 #endif