added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.git] / include / linux / hiddev.h
1 #ifndef _HIDDEV_H
2 #define _HIDDEV_H
3
4 /*
5  * $Id: hiddev.h,v 1.1.1.1 2005/04/11 02:51:02 jack Exp $
6  *
7  *  Copyright (c) 1999-2000 Vojtech Pavlik
8  *
9  *  Sponsored by SuSE
10  */
11
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or 
16  * (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  * 
27  * Should you need to contact me, the author, you can do so either by
28  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
29  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
30  */
31
32 /*
33  * The event structure itself
34  */
35
36 struct hiddev_event {
37         unsigned hid;
38         signed int value;
39 };
40
41 struct hiddev_devinfo {
42         unsigned int bustype;
43         unsigned int busnum;
44         unsigned int devnum;
45         unsigned int ifnum;
46         short vendor;
47         short product;
48         short version;
49         unsigned num_applications;
50 };
51
52 #define HID_STRING_SIZE 256
53 struct hiddev_string_descriptor {
54         int index;
55         char value[HID_STRING_SIZE];
56 };
57
58 struct hiddev_report_info {
59         unsigned report_type;
60         unsigned report_id;
61         unsigned num_fields;
62 };
63
64 /* To do a GUSAGE/SUSAGE, fill in at least usage_code,  report_type and 
65  * report_id.  Set report_id to REPORT_ID_UNKNOWN if the rest of the fields 
66  * are unknown.  Otherwise use a usage_ref struct filled in from a previous 
67  * successful GUSAGE/SUSAGE call to save time.  To actually send a value
68  * to the device, perform a SUSAGE first, followed by a SREPORT.  If an
69  * INITREPORT is done, a GREPORT isn't necessary before a GUSAGE.
70  */
71 #define HID_REPORT_ID_UNKNOWN 0xffffffff
72 #define HID_REPORT_ID_FIRST   0x00000100
73 #define HID_REPORT_ID_NEXT    0x00000200
74 #define HID_REPORT_ID_MASK    0x000000ff
75 #define HID_REPORT_ID_MAX     0x000000ff
76
77 #define HID_REPORT_TYPE_INPUT   1
78 #define HID_REPORT_TYPE_OUTPUT  2
79 #define HID_REPORT_TYPE_FEATURE 3
80 #define HID_REPORT_TYPE_MIN     1
81 #define HID_REPORT_TYPE_MAX     3
82
83 struct hiddev_field_info {
84         unsigned report_type;
85         unsigned report_id;
86         unsigned field_index;
87         unsigned maxusage;
88         unsigned flags;
89         unsigned physical;              /* physical usage for this field */
90         unsigned logical;               /* logical usage for this field */
91         unsigned application;           /* application usage for this field */
92         __s32 logical_minimum;
93         __s32 logical_maximum;
94         __s32 physical_minimum;
95         __s32 physical_maximum;
96         unsigned unit_exponent;
97         unsigned unit;
98 };
99
100 /* Fill in report_type, report_id and field_index to get the information on a
101  * field.
102  */
103 #define HID_FIELD_CONSTANT              0x001
104 #define HID_FIELD_VARIABLE              0x002
105 #define HID_FIELD_RELATIVE              0x004
106 #define HID_FIELD_WRAP                  0x008   
107 #define HID_FIELD_NONLINEAR             0x010
108 #define HID_FIELD_NO_PREFERRED          0x020
109 #define HID_FIELD_NULL_STATE            0x040
110 #define HID_FIELD_VOLATILE              0x080
111 #define HID_FIELD_BUFFERED_BYTE         0x100
112
113 struct hiddev_usage_ref {
114         unsigned report_type;
115         unsigned report_id;
116         unsigned field_index;
117         unsigned usage_index;
118         unsigned usage_code;
119         __s32 value;
120 };
121
122
123 /*
124  * Protocol version.
125  */
126
127 #define HID_VERSION             0x010002
128
129 /*
130  * IOCTLs (0x00 - 0x7f)
131  */
132
133 #define HIDIOCGVERSION          _IOR('H', 0x01, int)
134 #define HIDIOCAPPLICATION       _IO('H', 0x02)
135 #define HIDIOCGDEVINFO          _IOR('H', 0x03, struct hiddev_devinfo)
136 #define HIDIOCGSTRING           _IOR('H', 0x04, struct hiddev_string_descriptor)
137 #define HIDIOCINITREPORT        _IO('H', 0x05)
138 #define HIDIOCGNAME(len)        _IOC(_IOC_READ, 'H', 0x06, len)
139 #define HIDIOCGREPORT           _IOW('H', 0x07, struct hiddev_report_info)
140 #define HIDIOCSREPORT           _IOW('H', 0x08, struct hiddev_report_info)
141 #define HIDIOCGREPORTINFO       _IOWR('H', 0x09, struct hiddev_report_info)
142 #define HIDIOCGFIELDINFO        _IOWR('H', 0x0A, struct hiddev_field_info)
143 #define HIDIOCGUSAGE            _IOWR('H', 0x0B, struct hiddev_usage_ref)
144 #define HIDIOCSUSAGE            _IOW('H', 0x0C, struct hiddev_usage_ref)
145 #define HIDIOCGUCODE            _IOWR('H', 0x0D, struct hiddev_usage_ref)
146
147 /* To traverse the input report descriptor info for a HID device, perform the 
148  * following:
149  *
150  *  rinfo.report_type = HID_REPORT_TYPE_INPUT;
151  *  rinfo.report_id = HID_REPORT_ID_FIRST;
152  *  ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
153  *
154  *  while (ret >= 0) {
155  *      for (i = 0; i < rinfo.num_fields; i++) { 
156  *          finfo.report_type = rinfo.report_type;
157  *          finfo.report_id = rinfo.report_id;
158  *          finfo.field_index = i;
159  *          ioctl(fd, HIDIOCGFIELDINFO, &finfo);
160  *          for (j = 0; j < finfo.maxusage; j++) {
161  *              uref.field_index = i;
162  *              uref.usage_index = j;
163  *              ioctl(fd, HIDIOCGUCODE, &uref);
164  *              ioctl(fd, HIDIOCGUSAGE, &uref);
165  *          }
166  *      }
167  *      uref.report_id |= HID_REPORT_ID_NEXT;
168  *      ret = ioctl(fd, HIDIOCGREPORTINFO, &uref);
169  *  }
170  */
171
172
173 #ifdef __KERNEL__
174
175 /*
176  * In-kernel definitions.
177  */
178
179 #ifdef CONFIG_USB_HIDDEV
180 int hiddev_connect(struct hid_device *);
181 void hiddev_disconnect(struct hid_device *);
182 void hiddev_hid_event(struct hid_device *, unsigned int usage, int value);
183 int __init hiddev_init(void);
184 void __exit hiddev_exit(void);
185 #else
186 static inline int hiddev_connect(struct hid_device *hid) { return -1; }
187 static inline void hiddev_disconnect(struct hid_device *hid) { }
188 static inline void hiddev_hid_event(struct hid_device *hid, unsigned int usage, int value) { }
189 static inline int hiddev_init(void) { return 0; }
190 static inline void hiddev_exit(void) { }
191 #endif
192
193 #endif
194 #endif