Debian Codegraph @

contrib/freebsd/include/linux/input.h

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