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