1 | /* |
2 | * Copyright (c) 1999-2002 Vojtech Pavlik |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify it |
5 | * under the terms of the GNU General Public License version 2 as published by |
6 | * the Free Software Foundation. |
7 | */ |
8 | #ifndef _INPUT_H |
9 | #define _INPUT_H |
10 | |
11 | |
12 | #include <sys/time.h> |
13 | #include <sys/ioctl.h> |
14 | #include <sys/types.h> |
15 | #include <linux/types.h> |
16 | |
17 | #include "input-event-codes.h" |
18 | |
19 | /* |
20 | * The event structure itself |
21 | */ |
22 | |
23 | struct input_event { |
24 | struct timeval time; |
25 | __u16 type; |
26 | __u16 code; |
27 | __s32 value; |
28 | }; |
29 | |
30 | /* |
31 | * Protocol version. |
32 | */ |
33 | |
34 | #define EV_VERSION 0x010001 |
35 | |
36 | /* |
37 | * IOCTLs (0x00 - 0x7f) |
38 | */ |
39 | |
40 | struct input_id { |
41 | __u16 bustype; |
42 | __u16 vendor; |
43 | __u16 product; |
44 | __u16 version; |
45 | }; |
46 | |
47 | /** |
48 | * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls |
49 | * @value: latest reported value for the axis. |
50 | * @minimum: specifies minimum value for the axis. |
51 | * @maximum: specifies maximum value for the axis. |
52 | * @fuzz: specifies fuzz value that is used to filter noise from |
53 | * the event stream. |
54 | * @flat: values that are within this value will be discarded by |
55 | * joydev interface and reported as 0 instead. |
56 | * @resolution: specifies resolution for the values reported for |
57 | * the axis. |
58 | * |
59 | * Note that input core does not clamp reported values to the |
60 | * [minimum, maximum] limits, such task is left to userspace. |
61 | * |
62 | * The default resolution for main axes (ABS_X, ABS_Y, ABS_Z) |
63 | * is reported in units per millimeter (units/mm), resolution |
64 | * for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported |
65 | * in units per radian. |
66 | * When INPUT_PROP_ACCELEROMETER is set the resolution changes. |
67 | * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in |
68 | * in units per g (units/g) and in units per degree per second |
69 | * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ). |
70 | */ |
71 | struct input_absinfo { |
72 | __s32 value; |
73 | __s32 minimum; |
74 | __s32 maximum; |
75 | __s32 fuzz; |
76 | __s32 flat; |
77 | __s32 resolution; |
78 | }; |
79 | |
80 | /** |
81 | * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls |
82 | * @scancode: scancode represented in machine-endian form. |
83 | * @len: length of the scancode that resides in @scancode buffer. |
84 | * @index: index in the keymap, may be used instead of scancode |
85 | * @flags: allows to specify how kernel should handle the request. For |
86 | * example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel |
87 | * should perform lookup in keymap by @index instead of @scancode |
88 | * @keycode: key code assigned to this scancode |
89 | * |
90 | * The structure is used to retrieve and modify keymap data. Users have |
91 | * option of performing lookup either by @scancode itself or by @index |
92 | * in keymap entry. EVIOCGKEYCODE will also return scancode or index |
93 | * (depending on which element was used to perform lookup). |
94 | */ |
95 | struct input_keymap_entry { |
96 | #define INPUT_KEYMAP_BY_INDEX (1 << 0) |
97 | __u8 flags; |
98 | __u8 len; |
99 | __u16 index; |
100 | __u32 keycode; |
101 | __u8 scancode[32]; |
102 | }; |
103 | |
104 | struct input_mask { |
105 | __u32 type; |
106 | __u32 codes_size; |
107 | __u64 codes_ptr; |
108 | }; |
109 | |
110 | #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ |
111 | #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ |
112 | #define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ |
113 | #define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ |
114 | |
115 | #define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */ |
116 | #define EVIOCGKEYCODE_V2 _IOR('E', 0x04, struct input_keymap_entry) |
117 | #define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */ |
118 | #define EVIOCSKEYCODE_V2 _IOW('E', 0x04, struct input_keymap_entry) |
119 | |
120 | #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ |
121 | #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ |
122 | #define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */ |
123 | #define EVIOCGPROP(len) _IOC(_IOC_READ, 'E', 0x09, len) /* get device properties */ |
124 | |
125 | /** |
126 | * EVIOCGMTSLOTS(len) - get MT slot values |
127 | * @len: size of the data buffer in bytes |
128 | * |
129 | * The ioctl buffer argument should be binary equivalent to |
130 | * |
131 | * struct input_mt_request_layout { |
132 | * __u32 code; |
133 | * __s32 values[num_slots]; |
134 | * }; |
135 | * |
136 | * where num_slots is the (arbitrary) number of MT slots to extract. |
137 | * |
138 | * The ioctl size argument (len) is the size of the buffer, which |
139 | * should satisfy len = (num_slots + 1) * sizeof(__s32). If len is |
140 | * too small to fit all available slots, the first num_slots are |
141 | * returned. |
142 | * |
143 | * Before the call, code is set to the wanted ABS_MT event type. On |
144 | * return, values[] is filled with the slot values for the specified |
145 | * ABS_MT code. |
146 | * |
147 | * If the request code is not an ABS_MT value, -EINVAL is returned. |
148 | */ |
149 | #define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len) |
150 | |
151 | #define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global key state */ |
152 | #define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */ |
153 | #define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */ |
154 | #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */ |
155 | |
156 | #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + (ev), len) /* get event bits */ |
157 | #define EVIOCGABS(abs) _IOR('E', 0x40 + (abs), struct input_absinfo) /* get abs value/limits */ |
158 | #define EVIOCSABS(abs) _IOW('E', 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */ |
159 | |
160 | #define EVIOCSFF _IOW('E', 0x80, struct ff_effect) /* send a force effect to a force feedback device */ |
161 | #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ |
162 | #define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */ |
163 | |
164 | #define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */ |
165 | #define EVIOCREVOKE _IOW('E', 0x91, int) /* Revoke device access */ |
166 | |
167 | /** |
168 | * EVIOCGMASK - Retrieve current event mask |
169 | * |
170 | * This ioctl allows user to retrieve the current event mask for specific |
171 | * event type. The argument must be of type "struct input_mask" and |
172 | * specifies the event type to query, the address of the receive buffer and |
173 | * the size of the receive buffer. |
174 | * |
175 | * The event mask is a per-client mask that specifies which events are |
176 | * forwarded to the client. Each event code is represented by a single bit |
177 | * in the event mask. If the bit is set, the event is passed to the client |
178 | * normally. Otherwise, the event is filtered and will never be queued on |
179 | * the client's receive buffer. |
180 | * |
181 | * Event masks do not affect global state of the input device. They only |
182 | * affect the file descriptor they are applied to. |
183 | * |
184 | * The default event mask for a client has all bits set, i.e. all events |
185 | * are forwarded to the client. If the kernel is queried for an unknown |
186 | * event type or if the receive buffer is larger than the number of |
187 | * event codes known to the kernel, the kernel returns all zeroes for those |
188 | * codes. |
189 | * |
190 | * At maximum, codes_size bytes are copied. |
191 | * |
192 | * This ioctl may fail with ENODEV in case the file is revoked, EFAULT |
193 | * if the receive-buffer points to invalid memory, or EINVAL if the kernel |
194 | * does not implement the ioctl. |
195 | */ |
196 | #define EVIOCGMASK _IOR('E', 0x92, struct input_mask) /* Get event-masks */ |
197 | |
198 | /** |
199 | * EVIOCSMASK - Set event mask |
200 | * |
201 | * This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the |
202 | * current event mask, this changes the client's event mask for a specific |
203 | * type. See EVIOCGMASK for a description of event-masks and the |
204 | * argument-type. |
205 | * |
206 | * This ioctl provides full forward compatibility. If the passed event type |
207 | * is unknown to the kernel, or if the number of event codes specified in |
208 | * the mask is bigger than what is known to the kernel, the ioctl is still |
209 | * accepted and applied. However, any unknown codes are left untouched and |
210 | * stay cleared. That means, the kernel always filters unknown codes |
211 | * regardless of what the client requests. If the new mask doesn't cover |
212 | * all known event-codes, all remaining codes are automatically cleared and |
213 | * thus filtered. |
214 | * |
215 | * This ioctl may fail with ENODEV in case the file is revoked. EFAULT is |
216 | * returned if the receive-buffer points to invalid memory. EINVAL is returned |
217 | * if the kernel does not implement the ioctl. |
218 | */ |
219 | #define EVIOCSMASK _IOW('E', 0x93, struct input_mask) /* Set event-masks */ |
220 | |
221 | #define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */ |
222 | |
223 | /* |
224 | * IDs. |
225 | */ |
226 | |
227 | #define ID_BUS 0 |
228 | #define ID_VENDOR 1 |
229 | #define ID_PRODUCT 2 |
230 | #define ID_VERSION 3 |
231 | |
232 | #define BUS_PCI 0x01 |
233 | #define BUS_ISAPNP 0x02 |
234 | #define BUS_USB 0x03 |
235 | #define BUS_HIL 0x04 |
236 | #define BUS_BLUETOOTH 0x05 |
237 | #define BUS_VIRTUAL 0x06 |
238 | |
239 | #define BUS_ISA 0x10 |
240 | #define BUS_I8042 0x11 |
241 | #define BUS_XTKBD 0x12 |
242 | #define BUS_RS232 0x13 |
243 | #define BUS_GAMEPORT 0x14 |
244 | #define BUS_PARPORT 0x15 |
245 | #define BUS_AMIGA 0x16 |
246 | #define BUS_ADB 0x17 |
247 | #define BUS_I2C 0x18 |
248 | #define BUS_HOST 0x19 |
249 | #define BUS_GSC 0x1A |
250 | #define BUS_ATARI 0x1B |
251 | #define BUS_SPI 0x1C |
252 | #define BUS_RMI 0x1D |
253 | #define BUS_CEC 0x1E |
254 | #define BUS_INTEL_ISHTP 0x1F |
255 | |
256 | /* |
257 | * MT_TOOL types |
258 | */ |
259 | #define MT_TOOL_FINGER 0 |
260 | #define MT_TOOL_PEN 1 |
261 | #define MT_TOOL_PALM 2 |
262 | #define MT_TOOL_MAX 2 |
263 | |
264 | /* |
265 | * Values describing the status of a force-feedback effect |
266 | */ |
267 | #define FF_STATUS_STOPPED 0x00 |
268 | #define FF_STATUS_PLAYING 0x01 |
269 | #define FF_STATUS_MAX 0x01 |
270 | |
271 | /* |
272 | * Structures used in ioctls to upload effects to a device |
273 | * They are pieces of a bigger structure (called ff_effect) |
274 | */ |
275 | |
276 | /* |
277 | * All duration values are expressed in ms. Values above 32767 ms (0x7fff) |
278 | * should not be used and have unspecified results. |
279 | */ |
280 | |
281 | /** |
282 | * struct ff_replay - defines scheduling of the force-feedback effect |
283 | * @length: duration of the effect |
284 | * @delay: delay before effect should start playing |
285 | */ |
286 | struct ff_replay { |
287 | __u16 length; |
288 | __u16 delay; |
289 | }; |
290 | |
291 | /** |
292 | * struct ff_trigger - defines what triggers the force-feedback effect |
293 | * @button: number of the button triggering the effect |
294 | * @interval: controls how soon the effect can be re-triggered |
295 | */ |
296 | struct ff_trigger { |
297 | __u16 button; |
298 | __u16 interval; |
299 | }; |
300 | |
301 | /** |
302 | * struct ff_envelope - generic force-feedback effect envelope |
303 | * @attack_length: duration of the attack (ms) |
304 | * @attack_level: level at the beginning of the attack |
305 | * @fade_length: duration of fade (ms) |
306 | * @fade_level: level at the end of fade |
307 | * |
308 | * The @attack_level and @fade_level are absolute values; when applying |
309 | * envelope force-feedback core will convert to positive/negative |
310 | * value based on polarity of the default level of the effect. |
311 | * Valid range for the attack and fade levels is 0x0000 - 0x7fff |
312 | */ |
313 | struct ff_envelope { |
314 | __u16 attack_length; |
315 | __u16 attack_level; |
316 | __u16 fade_length; |
317 | __u16 fade_level; |
318 | }; |
319 | |
320 | /** |
321 | * struct ff_constant_effect - defines parameters of a constant force-feedback effect |
322 | * @level: strength of the effect; may be negative |
323 | * @envelope: envelope data |
324 | */ |
325 | struct ff_constant_effect { |
326 | __s16 level; |
327 | struct ff_envelope envelope; |
328 | }; |
329 | |
330 | /** |
331 | * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect |
332 | * @start_level: beginning strength of the effect; may be negative |
333 | * @end_level: final strength of the effect; may be negative |
334 | * @envelope: envelope data |
335 | */ |
336 | struct ff_ramp_effect { |
337 | __s16 start_level; |
338 | __s16 end_level; |
339 | struct ff_envelope envelope; |
340 | }; |
341 | |
342 | /** |
343 | * struct ff_condition_effect - defines a spring or friction force-feedback effect |
344 | * @right_saturation: maximum level when joystick moved all way to the right |
345 | * @left_saturation: same for the left side |
346 | * @right_coeff: controls how fast the force grows when the joystick moves |
347 | * to the right |
348 | * @left_coeff: same for the left side |
349 | * @deadband: size of the dead zone, where no force is produced |
350 | * @center: position of the dead zone |
351 | */ |
352 | struct ff_condition_effect { |
353 | __u16 right_saturation; |
354 | __u16 left_saturation; |
355 | |
356 | __s16 right_coeff; |
357 | __s16 left_coeff; |
358 | |
359 | __u16 deadband; |
360 | __s16 center; |
361 | }; |
362 | |
363 | /** |
364 | * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect |
365 | * @waveform: kind of the effect (wave) |
366 | * @period: period of the wave (ms) |
367 | * @magnitude: peak value |
368 | * @offset: mean value of the wave (roughly) |
369 | * @phase: 'horizontal' shift |
370 | * @envelope: envelope data |
371 | * @custom_len: number of samples (FF_CUSTOM only) |
372 | * @custom_data: buffer of samples (FF_CUSTOM only) |
373 | * |
374 | * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP, |
375 | * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined |
376 | * for the time being as no driver supports it yet. |
377 | * |
378 | * Note: the data pointed by custom_data is copied by the driver. |
379 | * You can therefore dispose of the memory after the upload/update. |
380 | */ |
381 | struct ff_periodic_effect { |
382 | __u16 waveform; |
383 | __u16 period; |
384 | __s16 magnitude; |
385 | __s16 offset; |
386 | __u16 phase; |
387 | |
388 | struct ff_envelope envelope; |
389 | |
390 | __u32 custom_len; |
391 | __s16 *custom_data; |
392 | }; |
393 | |
394 | /** |
395 | * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect |
396 | * @strong_magnitude: magnitude of the heavy motor |
397 | * @weak_magnitude: magnitude of the light one |
398 | * |
399 | * Some rumble pads have two motors of different weight. Strong_magnitude |
400 | * represents the magnitude of the vibration generated by the heavy one. |
401 | */ |
402 | struct ff_rumble_effect { |
403 | __u16 strong_magnitude; |
404 | __u16 weak_magnitude; |
405 | }; |
406 | |
407 | /** |
408 | * struct ff_effect - defines force feedback effect |
409 | * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING, |
410 | * FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM) |
411 | * @id: an unique id assigned to an effect |
412 | * @direction: direction of the effect |
413 | * @trigger: trigger conditions (struct ff_trigger) |
414 | * @replay: scheduling of the effect (struct ff_replay) |
415 | * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect, |
416 | * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further |
417 | * defining effect parameters |
418 | * |
419 | * This structure is sent through ioctl from the application to the driver. |
420 | * To create a new effect application should set its @id to -1; the kernel |
421 | * will return assigned @id which can later be used to update or delete |
422 | * this effect. |
423 | * |
424 | * Direction of the effect is encoded as follows: |
425 | * 0 deg -> 0x0000 (down) |
426 | * 90 deg -> 0x4000 (left) |
427 | * 180 deg -> 0x8000 (up) |
428 | * 270 deg -> 0xC000 (right) |
429 | */ |
430 | struct ff_effect { |
431 | __u16 type; |
432 | __s16 id; |
433 | __u16 direction; |
434 | struct ff_trigger trigger; |
435 | struct ff_replay replay; |
436 | |
437 | union { |
438 | struct ff_constant_effect constant; |
439 | struct ff_ramp_effect ramp; |
440 | struct ff_periodic_effect periodic; |
441 | struct ff_condition_effect condition[2]; /* One for each axis */ |
442 | struct ff_rumble_effect rumble; |
443 | } u; |
444 | }; |
445 | |
446 | /* |
447 | * Force feedback effect types |
448 | */ |
449 | |
450 | #define FF_RUMBLE 0x50 |
451 | #define FF_PERIODIC 0x51 |
452 | #define FF_CONSTANT 0x52 |
453 | #define FF_SPRING 0x53 |
454 | #define FF_FRICTION 0x54 |
455 | #define FF_DAMPER 0x55 |
456 | #define FF_INERTIA 0x56 |
457 | #define FF_RAMP 0x57 |
458 | |
459 | #define FF_EFFECT_MIN FF_RUMBLE |
460 | #define FF_EFFECT_MAX FF_RAMP |
461 | |
462 | /* |
463 | * Force feedback periodic effect types |
464 | */ |
465 | |
466 | #define FF_SQUARE 0x58 |
467 | #define FF_TRIANGLE 0x59 |
468 | #define FF_SINE 0x5a |
469 | #define FF_SAW_UP 0x5b |
470 | #define FF_SAW_DOWN 0x5c |
471 | #define FF_CUSTOM 0x5d |
472 | |
473 | #define FF_WAVEFORM_MIN FF_SQUARE |
474 | #define FF_WAVEFORM_MAX FF_CUSTOM |
475 | |
476 | /* |
477 | * Set ff device properties |
478 | */ |
479 | |
480 | #define FF_GAIN 0x60 |
481 | #define FF_AUTOCENTER 0x61 |
482 | |
483 | /* |
484 | * ff->playback(effect_id = FF_GAIN) is the first effect_id to |
485 | * cause a collision with another ff method, in this case ff->set_gain(). |
486 | * Therefore the greatest safe value for effect_id is FF_GAIN - 1, |
487 | * and thus the total number of effects should never exceed FF_GAIN. |
488 | */ |
489 | #define FF_MAX_EFFECTS FF_GAIN |
490 | |
491 | #define FF_MAX 0x7f |
492 | #define FF_CNT (FF_MAX+1) |
493 | |
494 | #endif /* _INPUT_H */ |
495 | |