1dd873966SEric Auger /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22fe7c318SGerd Hoffmann /*
32fe7c318SGerd Hoffmann  * Copyright (c) 1999-2002 Vojtech Pavlik
42fe7c318SGerd Hoffmann  *
52fe7c318SGerd Hoffmann  * This program is free software; you can redistribute it and/or modify it
62fe7c318SGerd Hoffmann  * under the terms of the GNU General Public License version 2 as published by
72fe7c318SGerd Hoffmann  * the Free Software Foundation.
82fe7c318SGerd Hoffmann  */
92fe7c318SGerd Hoffmann #ifndef _INPUT_H
102fe7c318SGerd Hoffmann #define _INPUT_H
112fe7c318SGerd Hoffmann 
122fe7c318SGerd Hoffmann 
132fe7c318SGerd Hoffmann #include <sys/time.h>
142fe7c318SGerd Hoffmann #include <sys/types.h>
152fe7c318SGerd Hoffmann #include "standard-headers/linux/types.h"
162fe7c318SGerd Hoffmann 
17fff02bc0SPaolo Bonzini #include "standard-headers/linux/input-event-codes.h"
182fe7c318SGerd Hoffmann 
192fe7c318SGerd Hoffmann /*
202fe7c318SGerd Hoffmann  * The event structure itself
219f2d175dSPaolo Bonzini  * Note that __USE_TIME_BITS64 is defined by libc based on
229f2d175dSPaolo Bonzini  * application's request to use 64 bit time_t.
232fe7c318SGerd Hoffmann  */
242fe7c318SGerd Hoffmann 
252fe7c318SGerd Hoffmann struct input_event {
269f2d175dSPaolo Bonzini #if (HOST_LONG_BITS != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL)
272fe7c318SGerd Hoffmann 	struct timeval time;
289f2d175dSPaolo Bonzini #define input_event_sec time.tv_sec
299f2d175dSPaolo Bonzini #define input_event_usec time.tv_usec
309f2d175dSPaolo Bonzini #else
31*65a6d8ddSPeter Maydell 	unsigned long __sec;
32*65a6d8ddSPeter Maydell 	unsigned long __usec;
339f2d175dSPaolo Bonzini #define input_event_sec  __sec
349f2d175dSPaolo Bonzini #define input_event_usec __usec
359f2d175dSPaolo Bonzini #endif
362fe7c318SGerd Hoffmann 	uint16_t type;
372fe7c318SGerd Hoffmann 	uint16_t code;
382fe7c318SGerd Hoffmann 	int32_t value;
392fe7c318SGerd Hoffmann };
402fe7c318SGerd Hoffmann 
412fe7c318SGerd Hoffmann /*
422fe7c318SGerd Hoffmann  * Protocol version.
432fe7c318SGerd Hoffmann  */
442fe7c318SGerd Hoffmann 
452fe7c318SGerd Hoffmann #define EV_VERSION		0x010001
462fe7c318SGerd Hoffmann 
472fe7c318SGerd Hoffmann /*
482fe7c318SGerd Hoffmann  * IOCTLs (0x00 - 0x7f)
492fe7c318SGerd Hoffmann  */
502fe7c318SGerd Hoffmann 
512fe7c318SGerd Hoffmann struct input_id {
522fe7c318SGerd Hoffmann 	uint16_t bustype;
532fe7c318SGerd Hoffmann 	uint16_t vendor;
542fe7c318SGerd Hoffmann 	uint16_t product;
552fe7c318SGerd Hoffmann 	uint16_t version;
562fe7c318SGerd Hoffmann };
572fe7c318SGerd Hoffmann 
582fe7c318SGerd Hoffmann /**
592fe7c318SGerd Hoffmann  * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
602fe7c318SGerd Hoffmann  * @value: latest reported value for the axis.
612fe7c318SGerd Hoffmann  * @minimum: specifies minimum value for the axis.
622fe7c318SGerd Hoffmann  * @maximum: specifies maximum value for the axis.
632fe7c318SGerd Hoffmann  * @fuzz: specifies fuzz value that is used to filter noise from
642fe7c318SGerd Hoffmann  *	the event stream.
652fe7c318SGerd Hoffmann  * @flat: values that are within this value will be discarded by
662fe7c318SGerd Hoffmann  *	joydev interface and reported as 0 instead.
672fe7c318SGerd Hoffmann  * @resolution: specifies resolution for the values reported for
682fe7c318SGerd Hoffmann  *	the axis.
692fe7c318SGerd Hoffmann  *
702fe7c318SGerd Hoffmann  * Note that input core does not clamp reported values to the
712fe7c318SGerd Hoffmann  * [minimum, maximum] limits, such task is left to userspace.
722fe7c318SGerd Hoffmann  *
7374c98e20SCornelia Huck  * The default resolution for main axes (ABS_X, ABS_Y, ABS_Z)
7474c98e20SCornelia Huck  * is reported in units per millimeter (units/mm), resolution
7574c98e20SCornelia Huck  * for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported
7674c98e20SCornelia Huck  * in units per radian.
7774c98e20SCornelia Huck  * When INPUT_PROP_ACCELEROMETER is set the resolution changes.
7874c98e20SCornelia Huck  * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in
7974c98e20SCornelia Huck  * in units per g (units/g) and in units per degree per second
8074c98e20SCornelia Huck  * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ).
812fe7c318SGerd Hoffmann  */
822fe7c318SGerd Hoffmann struct input_absinfo {
832fe7c318SGerd Hoffmann 	int32_t value;
842fe7c318SGerd Hoffmann 	int32_t minimum;
852fe7c318SGerd Hoffmann 	int32_t maximum;
862fe7c318SGerd Hoffmann 	int32_t fuzz;
872fe7c318SGerd Hoffmann 	int32_t flat;
882fe7c318SGerd Hoffmann 	int32_t resolution;
892fe7c318SGerd Hoffmann };
902fe7c318SGerd Hoffmann 
912fe7c318SGerd Hoffmann /**
922fe7c318SGerd Hoffmann  * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
932fe7c318SGerd Hoffmann  * @scancode: scancode represented in machine-endian form.
942fe7c318SGerd Hoffmann  * @len: length of the scancode that resides in @scancode buffer.
952fe7c318SGerd Hoffmann  * @index: index in the keymap, may be used instead of scancode
962fe7c318SGerd Hoffmann  * @flags: allows to specify how kernel should handle the request. For
972fe7c318SGerd Hoffmann  *	example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
982fe7c318SGerd Hoffmann  *	should perform lookup in keymap by @index instead of @scancode
992fe7c318SGerd Hoffmann  * @keycode: key code assigned to this scancode
1002fe7c318SGerd Hoffmann  *
1012fe7c318SGerd Hoffmann  * The structure is used to retrieve and modify keymap data. Users have
1022fe7c318SGerd Hoffmann  * option of performing lookup either by @scancode itself or by @index
1032fe7c318SGerd Hoffmann  * in keymap entry. EVIOCGKEYCODE will also return scancode or index
1042fe7c318SGerd Hoffmann  * (depending on which element was used to perform lookup).
1052fe7c318SGerd Hoffmann  */
1062fe7c318SGerd Hoffmann struct input_keymap_entry {
1072fe7c318SGerd Hoffmann #define INPUT_KEYMAP_BY_INDEX	(1 << 0)
1082fe7c318SGerd Hoffmann 	uint8_t  flags;
1092fe7c318SGerd Hoffmann 	uint8_t  len;
1102fe7c318SGerd Hoffmann 	uint16_t index;
1112fe7c318SGerd Hoffmann 	uint32_t keycode;
1122fe7c318SGerd Hoffmann 	uint8_t  scancode[32];
1132fe7c318SGerd Hoffmann };
1142fe7c318SGerd Hoffmann 
115fff02bc0SPaolo Bonzini struct input_mask {
116fff02bc0SPaolo Bonzini 	uint32_t type;
117fff02bc0SPaolo Bonzini 	uint32_t codes_size;
118fff02bc0SPaolo Bonzini 	uint64_t codes_ptr;
119fff02bc0SPaolo Bonzini };
120fff02bc0SPaolo Bonzini 
1212fe7c318SGerd Hoffmann #define EVIOCGVERSION		_IOR('E', 0x01, int)			/* get driver version */
1222fe7c318SGerd Hoffmann #define EVIOCGID		_IOR('E', 0x02, struct input_id)	/* get device ID */
1232fe7c318SGerd Hoffmann #define EVIOCGREP		_IOR('E', 0x03, unsigned int[2])	/* get repeat settings */
1242fe7c318SGerd Hoffmann #define EVIOCSREP		_IOW('E', 0x03, unsigned int[2])	/* set repeat settings */
1252fe7c318SGerd Hoffmann 
1262fe7c318SGerd Hoffmann #define EVIOCGKEYCODE		_IOR('E', 0x04, unsigned int[2])        /* get keycode */
1272fe7c318SGerd Hoffmann #define EVIOCGKEYCODE_V2	_IOR('E', 0x04, struct input_keymap_entry)
1282fe7c318SGerd Hoffmann #define EVIOCSKEYCODE		_IOW('E', 0x04, unsigned int[2])        /* set keycode */
1292fe7c318SGerd Hoffmann #define EVIOCSKEYCODE_V2	_IOW('E', 0x04, struct input_keymap_entry)
1302fe7c318SGerd Hoffmann 
1312fe7c318SGerd Hoffmann #define EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, len)		/* get device name */
1322fe7c318SGerd Hoffmann #define EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, len)		/* get physical location */
1332fe7c318SGerd Hoffmann #define EVIOCGUNIQ(len)		_IOC(_IOC_READ, 'E', 0x08, len)		/* get unique identifier */
1342fe7c318SGerd Hoffmann #define EVIOCGPROP(len)		_IOC(_IOC_READ, 'E', 0x09, len)		/* get device properties */
1352fe7c318SGerd Hoffmann 
1362fe7c318SGerd Hoffmann /**
1372fe7c318SGerd Hoffmann  * EVIOCGMTSLOTS(len) - get MT slot values
1382fe7c318SGerd Hoffmann  * @len: size of the data buffer in bytes
1392fe7c318SGerd Hoffmann  *
1402fe7c318SGerd Hoffmann  * The ioctl buffer argument should be binary equivalent to
1412fe7c318SGerd Hoffmann  *
1422fe7c318SGerd Hoffmann  * struct input_mt_request_layout {
1432fe7c318SGerd Hoffmann  *	uint32_t code;
1442fe7c318SGerd Hoffmann  *	int32_t values[num_slots];
1452fe7c318SGerd Hoffmann  * };
1462fe7c318SGerd Hoffmann  *
1472fe7c318SGerd Hoffmann  * where num_slots is the (arbitrary) number of MT slots to extract.
1482fe7c318SGerd Hoffmann  *
1492fe7c318SGerd Hoffmann  * The ioctl size argument (len) is the size of the buffer, which
1502fe7c318SGerd Hoffmann  * should satisfy len = (num_slots + 1) * sizeof(int32_t).  If len is
1512fe7c318SGerd Hoffmann  * too small to fit all available slots, the first num_slots are
1522fe7c318SGerd Hoffmann  * returned.
1532fe7c318SGerd Hoffmann  *
1542fe7c318SGerd Hoffmann  * Before the call, code is set to the wanted ABS_MT event type. On
1552fe7c318SGerd Hoffmann  * return, values[] is filled with the slot values for the specified
1562fe7c318SGerd Hoffmann  * ABS_MT code.
1572fe7c318SGerd Hoffmann  *
1582fe7c318SGerd Hoffmann  * If the request code is not an ABS_MT value, -EINVAL is returned.
1592fe7c318SGerd Hoffmann  */
1602fe7c318SGerd Hoffmann #define EVIOCGMTSLOTS(len)	_IOC(_IOC_READ, 'E', 0x0a, len)
1612fe7c318SGerd Hoffmann 
1622fe7c318SGerd Hoffmann #define EVIOCGKEY(len)		_IOC(_IOC_READ, 'E', 0x18, len)		/* get global key state */
1632fe7c318SGerd Hoffmann #define EVIOCGLED(len)		_IOC(_IOC_READ, 'E', 0x19, len)		/* get all LEDs */
1642fe7c318SGerd Hoffmann #define EVIOCGSND(len)		_IOC(_IOC_READ, 'E', 0x1a, len)		/* get all sounds status */
1652fe7c318SGerd Hoffmann #define EVIOCGSW(len)		_IOC(_IOC_READ, 'E', 0x1b, len)		/* get all switch states */
1662fe7c318SGerd Hoffmann 
1672fe7c318SGerd Hoffmann #define EVIOCGBIT(ev,len)	_IOC(_IOC_READ, 'E', 0x20 + (ev), len)	/* get event bits */
1682fe7c318SGerd Hoffmann #define EVIOCGABS(abs)		_IOR('E', 0x40 + (abs), struct input_absinfo)	/* get abs value/limits */
1692fe7c318SGerd Hoffmann #define EVIOCSABS(abs)		_IOW('E', 0xc0 + (abs), struct input_absinfo)	/* set abs value/limits */
1702fe7c318SGerd Hoffmann 
171fff02bc0SPaolo Bonzini #define EVIOCSFF		_IOW('E', 0x80, struct ff_effect)	/* send a force effect to a force feedback device */
1722fe7c318SGerd Hoffmann #define EVIOCRMFF		_IOW('E', 0x81, int)			/* Erase a force effect */
1732fe7c318SGerd Hoffmann #define EVIOCGEFFECTS		_IOR('E', 0x84, int)			/* Report number of effects playable at the same time */
1742fe7c318SGerd Hoffmann 
1752fe7c318SGerd Hoffmann #define EVIOCGRAB		_IOW('E', 0x90, int)			/* Grab/Release device */
1762fe7c318SGerd Hoffmann #define EVIOCREVOKE		_IOW('E', 0x91, int)			/* Revoke device access */
1772fe7c318SGerd Hoffmann 
178fff02bc0SPaolo Bonzini /**
179fff02bc0SPaolo Bonzini  * EVIOCGMASK - Retrieve current event mask
1802fe7c318SGerd Hoffmann  *
181fff02bc0SPaolo Bonzini  * This ioctl allows user to retrieve the current event mask for specific
182fff02bc0SPaolo Bonzini  * event type. The argument must be of type "struct input_mask" and
183fff02bc0SPaolo Bonzini  * specifies the event type to query, the address of the receive buffer and
184fff02bc0SPaolo Bonzini  * the size of the receive buffer.
185fff02bc0SPaolo Bonzini  *
186fff02bc0SPaolo Bonzini  * The event mask is a per-client mask that specifies which events are
187fff02bc0SPaolo Bonzini  * forwarded to the client. Each event code is represented by a single bit
188fff02bc0SPaolo Bonzini  * in the event mask. If the bit is set, the event is passed to the client
189fff02bc0SPaolo Bonzini  * normally. Otherwise, the event is filtered and will never be queued on
190fff02bc0SPaolo Bonzini  * the client's receive buffer.
191fff02bc0SPaolo Bonzini  *
192fff02bc0SPaolo Bonzini  * Event masks do not affect global state of the input device. They only
193fff02bc0SPaolo Bonzini  * affect the file descriptor they are applied to.
194fff02bc0SPaolo Bonzini  *
195fff02bc0SPaolo Bonzini  * The default event mask for a client has all bits set, i.e. all events
196fff02bc0SPaolo Bonzini  * are forwarded to the client. If the kernel is queried for an unknown
197fff02bc0SPaolo Bonzini  * event type or if the receive buffer is larger than the number of
198fff02bc0SPaolo Bonzini  * event codes known to the kernel, the kernel returns all zeroes for those
199fff02bc0SPaolo Bonzini  * codes.
200fff02bc0SPaolo Bonzini  *
201fff02bc0SPaolo Bonzini  * At maximum, codes_size bytes are copied.
202fff02bc0SPaolo Bonzini  *
203fff02bc0SPaolo Bonzini  * This ioctl may fail with ENODEV in case the file is revoked, EFAULT
204fff02bc0SPaolo Bonzini  * if the receive-buffer points to invalid memory, or EINVAL if the kernel
205fff02bc0SPaolo Bonzini  * does not implement the ioctl.
2062fe7c318SGerd Hoffmann  */
207fff02bc0SPaolo Bonzini #define EVIOCGMASK		_IOR('E', 0x92, struct input_mask)	/* Get event-masks */
2082fe7c318SGerd Hoffmann 
209fff02bc0SPaolo Bonzini /**
210fff02bc0SPaolo Bonzini  * EVIOCSMASK - Set event mask
211fff02bc0SPaolo Bonzini  *
212fff02bc0SPaolo Bonzini  * This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the
213fff02bc0SPaolo Bonzini  * current event mask, this changes the client's event mask for a specific
214fff02bc0SPaolo Bonzini  * type.  See EVIOCGMASK for a description of event-masks and the
215fff02bc0SPaolo Bonzini  * argument-type.
216fff02bc0SPaolo Bonzini  *
217fff02bc0SPaolo Bonzini  * This ioctl provides full forward compatibility. If the passed event type
218fff02bc0SPaolo Bonzini  * is unknown to the kernel, or if the number of event codes specified in
219fff02bc0SPaolo Bonzini  * the mask is bigger than what is known to the kernel, the ioctl is still
220fff02bc0SPaolo Bonzini  * accepted and applied. However, any unknown codes are left untouched and
221fff02bc0SPaolo Bonzini  * stay cleared. That means, the kernel always filters unknown codes
222fff02bc0SPaolo Bonzini  * regardless of what the client requests.  If the new mask doesn't cover
223fff02bc0SPaolo Bonzini  * all known event-codes, all remaining codes are automatically cleared and
224fff02bc0SPaolo Bonzini  * thus filtered.
225fff02bc0SPaolo Bonzini  *
226fff02bc0SPaolo Bonzini  * This ioctl may fail with ENODEV in case the file is revoked. EFAULT is
227fff02bc0SPaolo Bonzini  * returned if the receive-buffer points to invalid memory. EINVAL is returned
228fff02bc0SPaolo Bonzini  * if the kernel does not implement the ioctl.
2292fe7c318SGerd Hoffmann  */
230fff02bc0SPaolo Bonzini #define EVIOCSMASK		_IOW('E', 0x93, struct input_mask)	/* Set event-masks */
2312fe7c318SGerd Hoffmann 
232fff02bc0SPaolo Bonzini #define EVIOCSCLOCKID		_IOW('E', 0xa0, int)			/* Set clockid to be used for timestamps */
2332fe7c318SGerd Hoffmann 
2342fe7c318SGerd Hoffmann /*
2352fe7c318SGerd Hoffmann  * IDs.
2362fe7c318SGerd Hoffmann  */
2372fe7c318SGerd Hoffmann 
2382fe7c318SGerd Hoffmann #define ID_BUS			0
2392fe7c318SGerd Hoffmann #define ID_VENDOR		1
2402fe7c318SGerd Hoffmann #define ID_PRODUCT		2
2412fe7c318SGerd Hoffmann #define ID_VERSION		3
2422fe7c318SGerd Hoffmann 
2432fe7c318SGerd Hoffmann #define BUS_PCI			0x01
2442fe7c318SGerd Hoffmann #define BUS_ISAPNP		0x02
2452fe7c318SGerd Hoffmann #define BUS_USB			0x03
2462fe7c318SGerd Hoffmann #define BUS_HIL			0x04
2472fe7c318SGerd Hoffmann #define BUS_BLUETOOTH		0x05
2482fe7c318SGerd Hoffmann #define BUS_VIRTUAL		0x06
2492fe7c318SGerd Hoffmann 
2502fe7c318SGerd Hoffmann #define BUS_ISA			0x10
2512fe7c318SGerd Hoffmann #define BUS_I8042		0x11
2522fe7c318SGerd Hoffmann #define BUS_XTKBD		0x12
2532fe7c318SGerd Hoffmann #define BUS_RS232		0x13
2542fe7c318SGerd Hoffmann #define BUS_GAMEPORT		0x14
2552fe7c318SGerd Hoffmann #define BUS_PARPORT		0x15
2562fe7c318SGerd Hoffmann #define BUS_AMIGA		0x16
2572fe7c318SGerd Hoffmann #define BUS_ADB			0x17
2582fe7c318SGerd Hoffmann #define BUS_I2C			0x18
2592fe7c318SGerd Hoffmann #define BUS_HOST		0x19
2602fe7c318SGerd Hoffmann #define BUS_GSC			0x1A
2612fe7c318SGerd Hoffmann #define BUS_ATARI		0x1B
2622fe7c318SGerd Hoffmann #define BUS_SPI			0x1C
263b89485a5SPaolo Bonzini #define BUS_RMI			0x1D
264dbdfea92SCornelia Huck #define BUS_CEC			0x1E
265bc204035SMarcelo Tosatti #define BUS_INTEL_ISHTP		0x1F
2662fe7c318SGerd Hoffmann 
2672fe7c318SGerd Hoffmann /*
2682fe7c318SGerd Hoffmann  * MT_TOOL types
2692fe7c318SGerd Hoffmann  */
2702fe7c318SGerd Hoffmann #define MT_TOOL_FINGER		0
2712fe7c318SGerd Hoffmann #define MT_TOOL_PEN		1
27225b8b39bSAlexey Kardashevskiy #define MT_TOOL_PALM		2
27325b8b39bSAlexey Kardashevskiy #define MT_TOOL_MAX		2
2742fe7c318SGerd Hoffmann 
2752fe7c318SGerd Hoffmann /*
2762fe7c318SGerd Hoffmann  * Values describing the status of a force-feedback effect
2772fe7c318SGerd Hoffmann  */
2782fe7c318SGerd Hoffmann #define FF_STATUS_STOPPED	0x00
2792fe7c318SGerd Hoffmann #define FF_STATUS_PLAYING	0x01
2802fe7c318SGerd Hoffmann #define FF_STATUS_MAX		0x01
2812fe7c318SGerd Hoffmann 
2822fe7c318SGerd Hoffmann /*
2832fe7c318SGerd Hoffmann  * Structures used in ioctls to upload effects to a device
2842fe7c318SGerd Hoffmann  * They are pieces of a bigger structure (called ff_effect)
2852fe7c318SGerd Hoffmann  */
2862fe7c318SGerd Hoffmann 
2872fe7c318SGerd Hoffmann /*
2882fe7c318SGerd Hoffmann  * All duration values are expressed in ms. Values above 32767 ms (0x7fff)
2892fe7c318SGerd Hoffmann  * should not be used and have unspecified results.
2902fe7c318SGerd Hoffmann  */
2912fe7c318SGerd Hoffmann 
2922fe7c318SGerd Hoffmann /**
2932fe7c318SGerd Hoffmann  * struct ff_replay - defines scheduling of the force-feedback effect
2942fe7c318SGerd Hoffmann  * @length: duration of the effect
2952fe7c318SGerd Hoffmann  * @delay: delay before effect should start playing
2962fe7c318SGerd Hoffmann  */
2972fe7c318SGerd Hoffmann struct ff_replay {
2982fe7c318SGerd Hoffmann 	uint16_t length;
2992fe7c318SGerd Hoffmann 	uint16_t delay;
3002fe7c318SGerd Hoffmann };
3012fe7c318SGerd Hoffmann 
3022fe7c318SGerd Hoffmann /**
3032fe7c318SGerd Hoffmann  * struct ff_trigger - defines what triggers the force-feedback effect
3042fe7c318SGerd Hoffmann  * @button: number of the button triggering the effect
3052fe7c318SGerd Hoffmann  * @interval: controls how soon the effect can be re-triggered
3062fe7c318SGerd Hoffmann  */
3072fe7c318SGerd Hoffmann struct ff_trigger {
3082fe7c318SGerd Hoffmann 	uint16_t button;
3092fe7c318SGerd Hoffmann 	uint16_t interval;
3102fe7c318SGerd Hoffmann };
3112fe7c318SGerd Hoffmann 
3122fe7c318SGerd Hoffmann /**
3132fe7c318SGerd Hoffmann  * struct ff_envelope - generic force-feedback effect envelope
3142fe7c318SGerd Hoffmann  * @attack_length: duration of the attack (ms)
3152fe7c318SGerd Hoffmann  * @attack_level: level at the beginning of the attack
3162fe7c318SGerd Hoffmann  * @fade_length: duration of fade (ms)
3172fe7c318SGerd Hoffmann  * @fade_level: level at the end of fade
3182fe7c318SGerd Hoffmann  *
3192fe7c318SGerd Hoffmann  * The @attack_level and @fade_level are absolute values; when applying
3202fe7c318SGerd Hoffmann  * envelope force-feedback core will convert to positive/negative
3212fe7c318SGerd Hoffmann  * value based on polarity of the default level of the effect.
3222fe7c318SGerd Hoffmann  * Valid range for the attack and fade levels is 0x0000 - 0x7fff
3232fe7c318SGerd Hoffmann  */
3242fe7c318SGerd Hoffmann struct ff_envelope {
3252fe7c318SGerd Hoffmann 	uint16_t attack_length;
3262fe7c318SGerd Hoffmann 	uint16_t attack_level;
3272fe7c318SGerd Hoffmann 	uint16_t fade_length;
3282fe7c318SGerd Hoffmann 	uint16_t fade_level;
3292fe7c318SGerd Hoffmann };
3302fe7c318SGerd Hoffmann 
3312fe7c318SGerd Hoffmann /**
3322fe7c318SGerd Hoffmann  * struct ff_constant_effect - defines parameters of a constant force-feedback effect
3332fe7c318SGerd Hoffmann  * @level: strength of the effect; may be negative
3342fe7c318SGerd Hoffmann  * @envelope: envelope data
3352fe7c318SGerd Hoffmann  */
3362fe7c318SGerd Hoffmann struct ff_constant_effect {
3372fe7c318SGerd Hoffmann 	int16_t level;
3382fe7c318SGerd Hoffmann 	struct ff_envelope envelope;
3392fe7c318SGerd Hoffmann };
3402fe7c318SGerd Hoffmann 
3412fe7c318SGerd Hoffmann /**
3422fe7c318SGerd Hoffmann  * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
3432fe7c318SGerd Hoffmann  * @start_level: beginning strength of the effect; may be negative
3442fe7c318SGerd Hoffmann  * @end_level: final strength of the effect; may be negative
3452fe7c318SGerd Hoffmann  * @envelope: envelope data
3462fe7c318SGerd Hoffmann  */
3472fe7c318SGerd Hoffmann struct ff_ramp_effect {
3482fe7c318SGerd Hoffmann 	int16_t start_level;
3492fe7c318SGerd Hoffmann 	int16_t end_level;
3502fe7c318SGerd Hoffmann 	struct ff_envelope envelope;
3512fe7c318SGerd Hoffmann };
3522fe7c318SGerd Hoffmann 
3532fe7c318SGerd Hoffmann /**
3542fe7c318SGerd Hoffmann  * struct ff_condition_effect - defines a spring or friction force-feedback effect
3552fe7c318SGerd Hoffmann  * @right_saturation: maximum level when joystick moved all way to the right
3562fe7c318SGerd Hoffmann  * @left_saturation: same for the left side
3572fe7c318SGerd Hoffmann  * @right_coeff: controls how fast the force grows when the joystick moves
3582fe7c318SGerd Hoffmann  *	to the right
3592fe7c318SGerd Hoffmann  * @left_coeff: same for the left side
3602fe7c318SGerd Hoffmann  * @deadband: size of the dead zone, where no force is produced
3612fe7c318SGerd Hoffmann  * @center: position of the dead zone
3622fe7c318SGerd Hoffmann  */
3632fe7c318SGerd Hoffmann struct ff_condition_effect {
3642fe7c318SGerd Hoffmann 	uint16_t right_saturation;
3652fe7c318SGerd Hoffmann 	uint16_t left_saturation;
3662fe7c318SGerd Hoffmann 
3672fe7c318SGerd Hoffmann 	int16_t right_coeff;
3682fe7c318SGerd Hoffmann 	int16_t left_coeff;
3692fe7c318SGerd Hoffmann 
3702fe7c318SGerd Hoffmann 	uint16_t deadband;
3712fe7c318SGerd Hoffmann 	int16_t center;
3722fe7c318SGerd Hoffmann };
3732fe7c318SGerd Hoffmann 
3742fe7c318SGerd Hoffmann /**
3752fe7c318SGerd Hoffmann  * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
3762fe7c318SGerd Hoffmann  * @waveform: kind of the effect (wave)
3772fe7c318SGerd Hoffmann  * @period: period of the wave (ms)
3782fe7c318SGerd Hoffmann  * @magnitude: peak value
3792fe7c318SGerd Hoffmann  * @offset: mean value of the wave (roughly)
3802fe7c318SGerd Hoffmann  * @phase: 'horizontal' shift
3812fe7c318SGerd Hoffmann  * @envelope: envelope data
3822fe7c318SGerd Hoffmann  * @custom_len: number of samples (FF_CUSTOM only)
3832fe7c318SGerd Hoffmann  * @custom_data: buffer of samples (FF_CUSTOM only)
3842fe7c318SGerd Hoffmann  *
3852fe7c318SGerd Hoffmann  * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
3862fe7c318SGerd Hoffmann  * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
3872fe7c318SGerd Hoffmann  * for the time being as no driver supports it yet.
3882fe7c318SGerd Hoffmann  *
3892fe7c318SGerd Hoffmann  * Note: the data pointed by custom_data is copied by the driver.
3902fe7c318SGerd Hoffmann  * You can therefore dispose of the memory after the upload/update.
3912fe7c318SGerd Hoffmann  */
3922fe7c318SGerd Hoffmann struct ff_periodic_effect {
3932fe7c318SGerd Hoffmann 	uint16_t waveform;
3942fe7c318SGerd Hoffmann 	uint16_t period;
3952fe7c318SGerd Hoffmann 	int16_t magnitude;
3962fe7c318SGerd Hoffmann 	int16_t offset;
3972fe7c318SGerd Hoffmann 	uint16_t phase;
3982fe7c318SGerd Hoffmann 
3992fe7c318SGerd Hoffmann 	struct ff_envelope envelope;
4002fe7c318SGerd Hoffmann 
4012fe7c318SGerd Hoffmann 	uint32_t custom_len;
4022fe7c318SGerd Hoffmann 	int16_t *custom_data;
4032fe7c318SGerd Hoffmann };
4042fe7c318SGerd Hoffmann 
4052fe7c318SGerd Hoffmann /**
4062fe7c318SGerd Hoffmann  * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
4072fe7c318SGerd Hoffmann  * @strong_magnitude: magnitude of the heavy motor
4082fe7c318SGerd Hoffmann  * @weak_magnitude: magnitude of the light one
4092fe7c318SGerd Hoffmann  *
4102fe7c318SGerd Hoffmann  * Some rumble pads have two motors of different weight. Strong_magnitude
4112fe7c318SGerd Hoffmann  * represents the magnitude of the vibration generated by the heavy one.
4122fe7c318SGerd Hoffmann  */
4132fe7c318SGerd Hoffmann struct ff_rumble_effect {
4142fe7c318SGerd Hoffmann 	uint16_t strong_magnitude;
4152fe7c318SGerd Hoffmann 	uint16_t weak_magnitude;
4162fe7c318SGerd Hoffmann };
4172fe7c318SGerd Hoffmann 
4182fe7c318SGerd Hoffmann /**
4192fe7c318SGerd Hoffmann  * struct ff_effect - defines force feedback effect
4202fe7c318SGerd Hoffmann  * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
4212fe7c318SGerd Hoffmann  *	FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
4222fe7c318SGerd Hoffmann  * @id: an unique id assigned to an effect
4232fe7c318SGerd Hoffmann  * @direction: direction of the effect
4242fe7c318SGerd Hoffmann  * @trigger: trigger conditions (struct ff_trigger)
4252fe7c318SGerd Hoffmann  * @replay: scheduling of the effect (struct ff_replay)
4262fe7c318SGerd Hoffmann  * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
4272fe7c318SGerd Hoffmann  *	ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
4282fe7c318SGerd Hoffmann  *	defining effect parameters
4292fe7c318SGerd Hoffmann  *
4302fe7c318SGerd Hoffmann  * This structure is sent through ioctl from the application to the driver.
4312fe7c318SGerd Hoffmann  * To create a new effect application should set its @id to -1; the kernel
4322fe7c318SGerd Hoffmann  * will return assigned @id which can later be used to update or delete
4332fe7c318SGerd Hoffmann  * this effect.
4342fe7c318SGerd Hoffmann  *
4352fe7c318SGerd Hoffmann  * Direction of the effect is encoded as follows:
4362fe7c318SGerd Hoffmann  *	0 deg -> 0x0000 (down)
4372fe7c318SGerd Hoffmann  *	90 deg -> 0x4000 (left)
4382fe7c318SGerd Hoffmann  *	180 deg -> 0x8000 (up)
4392fe7c318SGerd Hoffmann  *	270 deg -> 0xC000 (right)
4402fe7c318SGerd Hoffmann  */
4412fe7c318SGerd Hoffmann struct ff_effect {
4422fe7c318SGerd Hoffmann 	uint16_t type;
4432fe7c318SGerd Hoffmann 	int16_t id;
4442fe7c318SGerd Hoffmann 	uint16_t direction;
4452fe7c318SGerd Hoffmann 	struct ff_trigger trigger;
4462fe7c318SGerd Hoffmann 	struct ff_replay replay;
4472fe7c318SGerd Hoffmann 
4482fe7c318SGerd Hoffmann 	union {
4492fe7c318SGerd Hoffmann 		struct ff_constant_effect constant;
4502fe7c318SGerd Hoffmann 		struct ff_ramp_effect ramp;
4512fe7c318SGerd Hoffmann 		struct ff_periodic_effect periodic;
4522fe7c318SGerd Hoffmann 		struct ff_condition_effect condition[2]; /* One for each axis */
4532fe7c318SGerd Hoffmann 		struct ff_rumble_effect rumble;
4542fe7c318SGerd Hoffmann 	} u;
4552fe7c318SGerd Hoffmann };
4562fe7c318SGerd Hoffmann 
4572fe7c318SGerd Hoffmann /*
4582fe7c318SGerd Hoffmann  * Force feedback effect types
4592fe7c318SGerd Hoffmann  */
4602fe7c318SGerd Hoffmann 
4612fe7c318SGerd Hoffmann #define FF_RUMBLE	0x50
4622fe7c318SGerd Hoffmann #define FF_PERIODIC	0x51
4632fe7c318SGerd Hoffmann #define FF_CONSTANT	0x52
4642fe7c318SGerd Hoffmann #define FF_SPRING	0x53
4652fe7c318SGerd Hoffmann #define FF_FRICTION	0x54
4662fe7c318SGerd Hoffmann #define FF_DAMPER	0x55
4672fe7c318SGerd Hoffmann #define FF_INERTIA	0x56
4682fe7c318SGerd Hoffmann #define FF_RAMP		0x57
4692fe7c318SGerd Hoffmann 
4702fe7c318SGerd Hoffmann #define FF_EFFECT_MIN	FF_RUMBLE
4712fe7c318SGerd Hoffmann #define FF_EFFECT_MAX	FF_RAMP
4722fe7c318SGerd Hoffmann 
4732fe7c318SGerd Hoffmann /*
4742fe7c318SGerd Hoffmann  * Force feedback periodic effect types
4752fe7c318SGerd Hoffmann  */
4762fe7c318SGerd Hoffmann 
4772fe7c318SGerd Hoffmann #define FF_SQUARE	0x58
4782fe7c318SGerd Hoffmann #define FF_TRIANGLE	0x59
4792fe7c318SGerd Hoffmann #define FF_SINE		0x5a
4802fe7c318SGerd Hoffmann #define FF_SAW_UP	0x5b
4812fe7c318SGerd Hoffmann #define FF_SAW_DOWN	0x5c
4822fe7c318SGerd Hoffmann #define FF_CUSTOM	0x5d
4832fe7c318SGerd Hoffmann 
4842fe7c318SGerd Hoffmann #define FF_WAVEFORM_MIN	FF_SQUARE
4852fe7c318SGerd Hoffmann #define FF_WAVEFORM_MAX	FF_CUSTOM
4862fe7c318SGerd Hoffmann 
4872fe7c318SGerd Hoffmann /*
4882fe7c318SGerd Hoffmann  * Set ff device properties
4892fe7c318SGerd Hoffmann  */
4902fe7c318SGerd Hoffmann 
4912fe7c318SGerd Hoffmann #define FF_GAIN		0x60
4922fe7c318SGerd Hoffmann #define FF_AUTOCENTER	0x61
4932fe7c318SGerd Hoffmann 
494fff02bc0SPaolo Bonzini /*
495fff02bc0SPaolo Bonzini  * ff->playback(effect_id = FF_GAIN) is the first effect_id to
496fff02bc0SPaolo Bonzini  * cause a collision with another ff method, in this case ff->set_gain().
497fff02bc0SPaolo Bonzini  * Therefore the greatest safe value for effect_id is FF_GAIN - 1,
498fff02bc0SPaolo Bonzini  * and thus the total number of effects should never exceed FF_GAIN.
499fff02bc0SPaolo Bonzini  */
500fff02bc0SPaolo Bonzini #define FF_MAX_EFFECTS	FF_GAIN
501fff02bc0SPaolo Bonzini 
5022fe7c318SGerd Hoffmann #define FF_MAX		0x7f
5032fe7c318SGerd Hoffmann #define FF_CNT		(FF_MAX+1)
5042fe7c318SGerd Hoffmann 
5052fe7c318SGerd Hoffmann #endif /* _INPUT_H */
506