Merge git://git.kernel.org/pub/scm/linux/kernel/git/agk/linux-2.6-dm
[linux-2.6/sactl.git] / include / linux / hiddev.h
blobc760ae0eb6a12b8842297388d2d86ec14f20291c
1 #ifndef _HIDDEV_H
2 #define _HIDDEV_H
4 /*
5 * Copyright (c) 1999-2000 Vojtech Pavlik
7 * Sponsored by SuSE
8 */
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Should you need to contact me, the author, you can do so either by
26 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
27 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
31 * The event structure itself
34 struct hiddev_event {
35 unsigned hid;
36 signed int value;
39 struct hiddev_devinfo {
40 __u32 bustype;
41 __u32 busnum;
42 __u32 devnum;
43 __u32 ifnum;
44 __s16 vendor;
45 __s16 product;
46 __s16 version;
47 __u32 num_applications;
50 struct hiddev_collection_info {
51 __u32 index;
52 __u32 type;
53 __u32 usage;
54 __u32 level;
57 #define HID_STRING_SIZE 256
58 struct hiddev_string_descriptor {
59 __s32 index;
60 char value[HID_STRING_SIZE];
63 struct hiddev_report_info {
64 __u32 report_type;
65 __u32 report_id;
66 __u32 num_fields;
69 /* To do a GUSAGE/SUSAGE, fill in at least usage_code, report_type and
70 * report_id. Set report_id to REPORT_ID_UNKNOWN if the rest of the fields
71 * are unknown. Otherwise use a usage_ref struct filled in from a previous
72 * successful GUSAGE call to save time. To actually send a value to the
73 * device, perform a SUSAGE first, followed by a SREPORT. An INITREPORT or a
74 * GREPORT isn't necessary for a GUSAGE to return valid data.
76 #define HID_REPORT_ID_UNKNOWN 0xffffffff
77 #define HID_REPORT_ID_FIRST 0x00000100
78 #define HID_REPORT_ID_NEXT 0x00000200
79 #define HID_REPORT_ID_MASK 0x000000ff
80 #define HID_REPORT_ID_MAX 0x000000ff
82 #define HID_REPORT_TYPE_INPUT 1
83 #define HID_REPORT_TYPE_OUTPUT 2
84 #define HID_REPORT_TYPE_FEATURE 3
85 #define HID_REPORT_TYPE_MIN 1
86 #define HID_REPORT_TYPE_MAX 3
88 struct hiddev_field_info {
89 __u32 report_type;
90 __u32 report_id;
91 __u32 field_index;
92 __u32 maxusage;
93 __u32 flags;
94 __u32 physical; /* physical usage for this field */
95 __u32 logical; /* logical usage for this field */
96 __u32 application; /* application usage for this field */
97 __s32 logical_minimum;
98 __s32 logical_maximum;
99 __s32 physical_minimum;
100 __s32 physical_maximum;
101 __u32 unit_exponent;
102 __u32 unit;
105 /* Fill in report_type, report_id and field_index to get the information on a
106 * field.
108 #define HID_FIELD_CONSTANT 0x001
109 #define HID_FIELD_VARIABLE 0x002
110 #define HID_FIELD_RELATIVE 0x004
111 #define HID_FIELD_WRAP 0x008
112 #define HID_FIELD_NONLINEAR 0x010
113 #define HID_FIELD_NO_PREFERRED 0x020
114 #define HID_FIELD_NULL_STATE 0x040
115 #define HID_FIELD_VOLATILE 0x080
116 #define HID_FIELD_BUFFERED_BYTE 0x100
118 struct hiddev_usage_ref {
119 __u32 report_type;
120 __u32 report_id;
121 __u32 field_index;
122 __u32 usage_index;
123 __u32 usage_code;
124 __s32 value;
127 /* hiddev_usage_ref_multi is used for sending multiple bytes to a control.
128 * It really manifests itself as setting the value of consecutive usages */
129 #define HID_MAX_MULTI_USAGES 1024
130 struct hiddev_usage_ref_multi {
131 struct hiddev_usage_ref uref;
132 __u32 num_values;
133 __s32 values[HID_MAX_MULTI_USAGES];
136 /* FIELD_INDEX_NONE is returned in read() data from the kernel when flags
137 * is set to (HIDDEV_FLAG_UREF | HIDDEV_FLAG_REPORT) and a new report has
138 * been sent by the device
140 #define HID_FIELD_INDEX_NONE 0xffffffff
143 * Protocol version.
146 #define HID_VERSION 0x010004
149 * IOCTLs (0x00 - 0x7f)
152 #define HIDIOCGVERSION _IOR('H', 0x01, int)
153 #define HIDIOCAPPLICATION _IO('H', 0x02)
154 #define HIDIOCGDEVINFO _IOR('H', 0x03, struct hiddev_devinfo)
155 #define HIDIOCGSTRING _IOR('H', 0x04, struct hiddev_string_descriptor)
156 #define HIDIOCINITREPORT _IO('H', 0x05)
157 #define HIDIOCGNAME(len) _IOC(_IOC_READ, 'H', 0x06, len)
158 #define HIDIOCGREPORT _IOW('H', 0x07, struct hiddev_report_info)
159 #define HIDIOCSREPORT _IOW('H', 0x08, struct hiddev_report_info)
160 #define HIDIOCGREPORTINFO _IOWR('H', 0x09, struct hiddev_report_info)
161 #define HIDIOCGFIELDINFO _IOWR('H', 0x0A, struct hiddev_field_info)
162 #define HIDIOCGUSAGE _IOWR('H', 0x0B, struct hiddev_usage_ref)
163 #define HIDIOCSUSAGE _IOW('H', 0x0C, struct hiddev_usage_ref)
164 #define HIDIOCGUCODE _IOWR('H', 0x0D, struct hiddev_usage_ref)
165 #define HIDIOCGFLAG _IOR('H', 0x0E, int)
166 #define HIDIOCSFLAG _IOW('H', 0x0F, int)
167 #define HIDIOCGCOLLECTIONINDEX _IOW('H', 0x10, struct hiddev_usage_ref)
168 #define HIDIOCGCOLLECTIONINFO _IOWR('H', 0x11, struct hiddev_collection_info)
169 #define HIDIOCGPHYS(len) _IOC(_IOC_READ, 'H', 0x12, len)
171 /* For writing/reading to multiple/consecutive usages */
172 #define HIDIOCGUSAGES _IOWR('H', 0x13, struct hiddev_usage_ref_multi)
173 #define HIDIOCSUSAGES _IOW('H', 0x14, struct hiddev_usage_ref_multi)
176 * Flags to be used in HIDIOCSFLAG
178 #define HIDDEV_FLAG_UREF 0x1
179 #define HIDDEV_FLAG_REPORT 0x2
180 #define HIDDEV_FLAGS 0x3
182 /* To traverse the input report descriptor info for a HID device, perform the
183 * following:
185 * rinfo.report_type = HID_REPORT_TYPE_INPUT;
186 * rinfo.report_id = HID_REPORT_ID_FIRST;
187 * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
189 * while (ret >= 0) {
190 * for (i = 0; i < rinfo.num_fields; i++) {
191 * finfo.report_type = rinfo.report_type;
192 * finfo.report_id = rinfo.report_id;
193 * finfo.field_index = i;
194 * ioctl(fd, HIDIOCGFIELDINFO, &finfo);
195 * for (j = 0; j < finfo.maxusage; j++) {
196 * uref.report_type = rinfo.report_type;
197 * uref.report_id = rinfo.report_id;
198 * uref.field_index = i;
199 * uref.usage_index = j;
200 * ioctl(fd, HIDIOCGUCODE, &uref);
201 * ioctl(fd, HIDIOCGUSAGE, &uref);
204 * rinfo.report_id |= HID_REPORT_ID_NEXT;
205 * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
210 #ifdef __KERNEL__
213 * In-kernel definitions.
216 struct hid_device;
217 struct hid_usage;
218 struct hid_field;
219 struct hid_report;
221 #ifdef CONFIG_USB_HIDDEV
222 int hiddev_connect(struct hid_device *hid, unsigned int force);
223 void hiddev_disconnect(struct hid_device *);
224 void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
225 struct hid_usage *usage, __s32 value);
226 void hiddev_report_event(struct hid_device *hid, struct hid_report *report);
227 int __init hiddev_init(void);
228 void hiddev_exit(void);
229 #else
230 static inline int hiddev_connect(struct hid_device *hid,
231 unsigned int force)
232 { return -1; }
233 static inline void hiddev_disconnect(struct hid_device *hid) { }
234 static inline void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
235 struct hid_usage *usage, __s32 value) { }
236 static inline void hiddev_report_event(struct hid_device *hid, struct hid_report *report) { }
237 static inline int hiddev_init(void) { return 0; }
238 static inline void hiddev_exit(void) { }
239 #endif
241 #endif
242 #endif