5 * $Id: hid.h,v 1.24 2001/12/27 10:37:41 vojtech Exp $
7 * Copyright (c) 1999 Andreas Gal
8 * Copyright (c) 2000-2001 Vojtech Pavlik
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Should you need to contact me, the author, you can do so either by
27 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
28 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
31 #include <linux/types.h>
32 #include <linux/slab.h>
33 #include <linux/list.h>
36 * USB HID (Human Interface Device) interface class code
39 #define USB_INTERFACE_CLASS_HID 3
45 #define HID_REQ_GET_REPORT 0x01
46 #define HID_REQ_GET_IDLE 0x02
47 #define HID_REQ_GET_PROTOCOL 0x03
48 #define HID_REQ_SET_REPORT 0x09
49 #define HID_REQ_SET_IDLE 0x0A
50 #define HID_REQ_SET_PROTOCOL 0x0B
53 * HID class descriptor types
56 #define HID_DT_HID (USB_TYPE_CLASS | 0x01)
57 #define HID_DT_REPORT (USB_TYPE_CLASS | 0x02)
58 #define HID_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
61 * We parse each description item into this structure. Short items data
62 * values are expanded to 32-bit signed int, long items contain a pointer
83 * HID report item format
86 #define HID_ITEM_FORMAT_SHORT 0
87 #define HID_ITEM_FORMAT_LONG 1
90 * Special tag indicating long items
93 #define HID_ITEM_TAG_LONG 15
96 * HID report descriptor item type (prefix bit 2,3)
99 #define HID_ITEM_TYPE_MAIN 0
100 #define HID_ITEM_TYPE_GLOBAL 1
101 #define HID_ITEM_TYPE_LOCAL 2
102 #define HID_ITEM_TYPE_RESERVED 3
105 * HID report descriptor main item tags
108 #define HID_MAIN_ITEM_TAG_INPUT 8
109 #define HID_MAIN_ITEM_TAG_OUTPUT 9
110 #define HID_MAIN_ITEM_TAG_FEATURE 11
111 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
112 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
115 * HID report descriptor main item contents
118 #define HID_MAIN_ITEM_CONSTANT 0x001
119 #define HID_MAIN_ITEM_VARIABLE 0x002
120 #define HID_MAIN_ITEM_RELATIVE 0x004
121 #define HID_MAIN_ITEM_WRAP 0x008
122 #define HID_MAIN_ITEM_NONLINEAR 0x010
123 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
124 #define HID_MAIN_ITEM_NULL_STATE 0x040
125 #define HID_MAIN_ITEM_VOLATILE 0x080
126 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
129 * HID report descriptor collection item types
132 #define HID_COLLECTION_PHYSICAL 0
133 #define HID_COLLECTION_APPLICATION 1
134 #define HID_COLLECTION_LOGICAL 2
137 * HID report descriptor global item tags
140 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
141 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
142 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
143 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
144 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
145 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
146 #define HID_GLOBAL_ITEM_TAG_UNIT 6
147 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
148 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
149 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
150 #define HID_GLOBAL_ITEM_TAG_PUSH 10
151 #define HID_GLOBAL_ITEM_TAG_POP 11
154 * HID report descriptor local item tags
157 #define HID_LOCAL_ITEM_TAG_USAGE 0
158 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
159 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
160 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
161 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
162 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
163 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
164 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
165 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
166 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
172 #define HID_USAGE_PAGE 0xffff0000
174 #define HID_UP_GENDESK 0x00010000
175 #define HID_UP_KEYBOARD 0x00070000
176 #define HID_UP_LED 0x00080000
177 #define HID_UP_BUTTON 0x00090000
178 #define HID_UP_ORDINAL 0x000a0000
179 #define HID_UP_CONSUMER 0x000c0000
180 #define HID_UP_DIGITIZER 0x000d0000
181 #define HID_UP_PID 0x000f0000
182 #define HID_UP_HPVENDOR 0xff7f0000
184 #define HID_USAGE 0x0000ffff
186 #define HID_GD_POINTER 0x00010001
187 #define HID_GD_MOUSE 0x00010002
188 #define HID_GD_JOYSTICK 0x00010004
189 #define HID_GD_GAMEPAD 0x00010005
190 #define HID_GD_HATSWITCH 0x00010039
193 * HID report types --- Ouch! HID spec says 1 2 3!
196 #define HID_INPUT_REPORT 0
197 #define HID_OUTPUT_REPORT 1
198 #define HID_FEATURE_REPORT 2
204 #define HID_QUIRK_INVERT 0x001
205 #define HID_QUIRK_NOTOUCH 0x002
206 #define HID_QUIRK_IGNORE 0x004
207 #define HID_QUIRK_NOGET 0x008
208 #define HID_QUIRK_HIDDEV 0x010
209 #define HID_QUIRK_BADPAD 0x020
210 #define HID_QUIRK_MULTI_INPUT 0x040
211 #define HID_QUIRK_2WHEEL_MOUSE_HACK_BACK 0x080
212 #define HID_QUIRK_2WHEEL_MOUSE_HACK_EXTRA 0x100
213 #define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200
216 * This is the global environment of the parser. This information is
217 * persistent for main-items. The global environment can be saved and
218 * restored with PUSH/POP statements.
223 __s32 logical_minimum;
224 __s32 logical_maximum;
225 __s32 physical_minimum;
226 __s32 physical_maximum;
230 unsigned report_size;
231 unsigned report_count;
235 * This is the local environment. It is persistent up the next main-item.
238 #define HID_MAX_DESCRIPTOR_SIZE 4096
239 #define HID_MAX_USAGES 1024
240 #define HID_DEFAULT_NUM_COLLECTIONS 16
243 unsigned usage[HID_MAX_USAGES]; /* usage array */
244 unsigned collection_index[HID_MAX_USAGES]; /* collection index array */
245 unsigned usage_index;
246 unsigned usage_minimum;
247 unsigned delimiter_depth;
248 unsigned delimiter_branch;
252 * This is the collection stack. We climb up the stack to determine
253 * application and function of each field.
256 struct hid_collection {
263 unsigned hid; /* hid usage code */
264 unsigned collection_index; /* index into collection array */
265 __u16 code; /* input driver code */
266 __u8 type; /* input driver type */
267 __s8 hat_min; /* hat switch fun */
268 __s8 hat_max; /* ditto */
272 unsigned physical; /* physical usage for this field */
273 unsigned logical; /* logical usage for this field */
274 unsigned application; /* application usage for this field */
275 struct hid_usage *usage; /* usage table for this function */
276 unsigned maxusage; /* maximum usage index */
277 unsigned flags; /* main-item flags (i.e. volatile,array,constant) */
278 unsigned report_offset; /* bit offset in the report */
279 unsigned report_size; /* size of this field in the report */
280 unsigned report_count; /* number of this field in the report */
281 unsigned report_type; /* (input,output,feature) */
282 __s32 *value; /* last known value(s) */
283 __s32 logical_minimum;
284 __s32 logical_maximum;
285 __s32 physical_minimum;
286 __s32 physical_maximum;
289 struct hid_report *report; /* associated report */
290 unsigned index; /* index into report->field[] */
293 #define HID_MAX_FIELDS 64
296 struct list_head list;
297 unsigned id; /* id of this report */
298 unsigned type; /* report type */
299 struct hid_field *field[HID_MAX_FIELDS]; /* fields of the report */
300 unsigned maxfield; /* maximum valid field index */
301 unsigned size; /* size of the report (bits) */
302 struct hid_device *device; /* associated device */
305 struct hid_report_enum {
307 struct list_head report_list;
308 struct hid_report *report_id_hash[256];
311 #define HID_REPORT_TYPES 3
313 #define HID_BUFFER_SIZE 64 /* use 64 for compatibility with all possible packetlen */
314 #define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */
315 #define HID_OUTPUT_FIFO_SIZE 64
317 struct hid_control_fifo {
319 struct hid_report *report;
322 #define HID_CLAIMED_INPUT 1
323 #define HID_CLAIMED_HIDDEV 2
325 #define HID_CTRL_RUNNING 1
326 #define HID_OUT_RUNNING 2
329 struct list_head list;
330 struct hid_report *report;
331 struct input_dev input;
334 struct hid_device { /* device report descriptor */
337 struct hid_collection *collection; /* List of HID collections */
338 unsigned collection_size; /* Number of allocated hid_collections */
339 unsigned maxcollection; /* Number of parsed collections */
340 unsigned maxapplication; /* Number of applications */
341 unsigned version; /* HID version */
342 unsigned country; /* HID country */
343 struct hid_report_enum report_enum[HID_REPORT_TYPES];
345 struct usb_device *dev; /* USB device */
346 struct usb_interface *intf; /* USB interface */
347 int ifnum; /* USB interface number */
349 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
351 struct urb *urbin; /* Input URB */
352 char *inbuf; /* Input buffer */
353 dma_addr_t inbuf_dma; /* Input buffer dma */
355 struct urb *urbctrl; /* Control URB */
356 struct usb_ctrlrequest *cr; /* Control request struct */
357 dma_addr_t cr_dma; /* Control request struct dma */
358 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
359 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
360 char *ctrlbuf; /* Control buffer */
361 dma_addr_t ctrlbuf_dma; /* Control buffer dma */
362 spinlock_t ctrllock; /* Control fifo spinlock */
364 struct urb *urbout; /* Output URB */
365 struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
366 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
367 char *outbuf; /* Output buffer */
368 dma_addr_t outbuf_dma; /* Output buffer dma */
369 spinlock_t outlock; /* Output fifo spinlock */
371 unsigned claimed; /* Claimed by hidinput, hiddev? */
372 unsigned quirks; /* Various quirks the device can pull on us */
374 struct list_head inputs; /* The list of inputs */
375 void *hiddev; /* The hiddev structure */
376 int minor; /* Hiddev minor number */
378 wait_queue_head_t wait; /* For sleeping */
380 int open; /* is the device open by anyone? */
381 char name[128]; /* Device name */
382 char phys[64]; /* Device physical location */
383 char uniq[64]; /* Device unique identifier (serial #) */
385 void *ff_private; /* Private data for the force-feedback driver */
386 void (*ff_exit)(struct hid_device*); /* Called by hid_exit_ff(hid) */
387 int (*ff_event)(struct hid_device *hid, struct input_dev *input,
388 unsigned int type, unsigned int code, int value);
391 #define HID_GLOBAL_STACK_SIZE 4
392 #define HID_COLLECTION_STACK_SIZE 4
395 struct hid_global global;
396 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE];
397 unsigned global_stack_ptr;
398 struct hid_local local;
399 unsigned collection_stack[HID_COLLECTION_STACK_SIZE];
400 unsigned collection_stack_ptr;
401 struct hid_device *device;
404 struct hid_class_descriptor {
405 __u8 bDescriptorType;
406 __u16 wDescriptorLength;
407 } __attribute__ ((packed));
409 struct hid_descriptor {
411 __u8 bDescriptorType;
414 __u8 bNumDescriptors;
416 struct hid_class_descriptor desc[1];
417 } __attribute__ ((packed));
420 #include "hid-debug.h"
422 #define hid_dump_input(a,b) do { } while (0)
423 #define hid_dump_device(c) do { } while (0)
424 #define hid_dump_field(a,b) do { } while (0)
425 #define resolv_usage(a) do { } while (0)
430 #ifdef CONFIG_USB_HIDINPUT
431 /* Applications from HID Usage Tables 4/8/99 Version 1.1 */
432 /* We ignore a few input applications that are not widely used */
433 #define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || ( a == 0x00010080) || ( a == 0x000c0001))
434 extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32, struct pt_regs *regs);
435 extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report);
436 extern int hidinput_connect(struct hid_device *);
437 extern void hidinput_disconnect(struct hid_device *);
439 #define IS_INPUT_APPLICATION(a) (0)
440 static inline void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, struct pt_regs *regs) { }
441 static inline void hidinput_report_event(struct hid_device *hid, struct hid_report *report) { }
442 static inline int hidinput_connect(struct hid_device *hid) { return -ENODEV; }
443 static inline void hidinput_disconnect(struct hid_device *hid) { }
446 int hid_open(struct hid_device *);
447 void hid_close(struct hid_device *);
448 int hid_find_field(struct hid_device *, unsigned int, unsigned int, struct hid_field **);
449 int hid_set_field(struct hid_field *, unsigned, __s32);
450 void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir);
451 void hid_init_reports(struct hid_device *hid);
452 int hid_find_report_by_usage(struct hid_device *hid, __u32 wanted_usage, struct hid_report **report, int type);
453 int hid_wait_io(struct hid_device* hid);
457 int hid_ff_init(struct hid_device *hid);
459 static inline int hid_ff_init(struct hid_device *hid) { return -1; }
461 static inline void hid_ff_exit(struct hid_device *hid)
466 static inline int hid_ff_event(struct hid_device *hid, struct input_dev *input,
467 unsigned int type, unsigned int code, int value)
470 return hid->ff_event(hid, input, type, code, value);