Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * Copyright (c) 1999-2002 Vojtech Pavlik
0004  *
0005  * This program is free software; you can redistribute it and/or modify it
0006  * under the terms of the GNU General Public License version 2 as published by
0007  * the Free Software Foundation.
0008  */
0009 #ifndef _UAPI_INPUT_H
0010 #define _UAPI_INPUT_H
0011 
0012 
0013 #ifndef __KERNEL__
0014 #include <sys/time.h>
0015 #include <sys/ioctl.h>
0016 #include <sys/types.h>
0017 #include <linux/types.h>
0018 #endif
0019 
0020 #include "input-event-codes.h"
0021 
0022 /*
0023  * The event structure itself
0024  * Note that __USE_TIME_BITS64 is defined by libc based on
0025  * application's request to use 64 bit time_t.
0026  */
0027 
0028 struct input_event {
0029 #if (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL__)
0030     struct timeval time;
0031 #define input_event_sec time.tv_sec
0032 #define input_event_usec time.tv_usec
0033 #else
0034     __kernel_ulong_t __sec;
0035 #if defined(__sparc__) && defined(__arch64__)
0036     unsigned int __usec;
0037     unsigned int __pad;
0038 #else
0039     __kernel_ulong_t __usec;
0040 #endif
0041 #define input_event_sec  __sec
0042 #define input_event_usec __usec
0043 #endif
0044     __u16 type;
0045     __u16 code;
0046     __s32 value;
0047 };
0048 
0049 /*
0050  * Protocol version.
0051  */
0052 
0053 #define EV_VERSION      0x010001
0054 
0055 /*
0056  * IOCTLs (0x00 - 0x7f)
0057  */
0058 
0059 struct input_id {
0060     __u16 bustype;
0061     __u16 vendor;
0062     __u16 product;
0063     __u16 version;
0064 };
0065 
0066 /**
0067  * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
0068  * @value: latest reported value for the axis.
0069  * @minimum: specifies minimum value for the axis.
0070  * @maximum: specifies maximum value for the axis.
0071  * @fuzz: specifies fuzz value that is used to filter noise from
0072  *  the event stream.
0073  * @flat: values that are within this value will be discarded by
0074  *  joydev interface and reported as 0 instead.
0075  * @resolution: specifies resolution for the values reported for
0076  *  the axis.
0077  *
0078  * Note that input core does not clamp reported values to the
0079  * [minimum, maximum] limits, such task is left to userspace.
0080  *
0081  * The default resolution for main axes (ABS_X, ABS_Y, ABS_Z,
0082  * ABS_MT_POSITION_X, ABS_MT_POSITION_Y) is reported in units
0083  * per millimeter (units/mm), resolution for rotational axes
0084  * (ABS_RX, ABS_RY, ABS_RZ) is reported in units per radian.
0085  * The resolution for the size axes (ABS_MT_TOUCH_MAJOR,
0086  * ABS_MT_TOUCH_MINOR, ABS_MT_WIDTH_MAJOR, ABS_MT_WIDTH_MINOR)
0087  * is reported in units per millimeter (units/mm).
0088  * When INPUT_PROP_ACCELEROMETER is set the resolution changes.
0089  * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in
0090  * units per g (units/g) and in units per degree per second
0091  * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ).
0092  */
0093 struct input_absinfo {
0094     __s32 value;
0095     __s32 minimum;
0096     __s32 maximum;
0097     __s32 fuzz;
0098     __s32 flat;
0099     __s32 resolution;
0100 };
0101 
0102 /**
0103  * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
0104  * @scancode: scancode represented in machine-endian form.
0105  * @len: length of the scancode that resides in @scancode buffer.
0106  * @index: index in the keymap, may be used instead of scancode
0107  * @flags: allows to specify how kernel should handle the request. For
0108  *  example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
0109  *  should perform lookup in keymap by @index instead of @scancode
0110  * @keycode: key code assigned to this scancode
0111  *
0112  * The structure is used to retrieve and modify keymap data. Users have
0113  * option of performing lookup either by @scancode itself or by @index
0114  * in keymap entry. EVIOCGKEYCODE will also return scancode or index
0115  * (depending on which element was used to perform lookup).
0116  */
0117 struct input_keymap_entry {
0118 #define INPUT_KEYMAP_BY_INDEX   (1 << 0)
0119     __u8  flags;
0120     __u8  len;
0121     __u16 index;
0122     __u32 keycode;
0123     __u8  scancode[32];
0124 };
0125 
0126 struct input_mask {
0127     __u32 type;
0128     __u32 codes_size;
0129     __u64 codes_ptr;
0130 };
0131 
0132 #define EVIOCGVERSION       _IOR('E', 0x01, int)            /* get driver version */
0133 #define EVIOCGID        _IOR('E', 0x02, struct input_id)    /* get device ID */
0134 #define EVIOCGREP       _IOR('E', 0x03, unsigned int[2])    /* get repeat settings */
0135 #define EVIOCSREP       _IOW('E', 0x03, unsigned int[2])    /* set repeat settings */
0136 
0137 #define EVIOCGKEYCODE       _IOR('E', 0x04, unsigned int[2])        /* get keycode */
0138 #define EVIOCGKEYCODE_V2    _IOR('E', 0x04, struct input_keymap_entry)
0139 #define EVIOCSKEYCODE       _IOW('E', 0x04, unsigned int[2])        /* set keycode */
0140 #define EVIOCSKEYCODE_V2    _IOW('E', 0x04, struct input_keymap_entry)
0141 
0142 #define EVIOCGNAME(len)     _IOC(_IOC_READ, 'E', 0x06, len)     /* get device name */
0143 #define EVIOCGPHYS(len)     _IOC(_IOC_READ, 'E', 0x07, len)     /* get physical location */
0144 #define EVIOCGUNIQ(len)     _IOC(_IOC_READ, 'E', 0x08, len)     /* get unique identifier */
0145 #define EVIOCGPROP(len)     _IOC(_IOC_READ, 'E', 0x09, len)     /* get device properties */
0146 
0147 /**
0148  * EVIOCGMTSLOTS(len) - get MT slot values
0149  * @len: size of the data buffer in bytes
0150  *
0151  * The ioctl buffer argument should be binary equivalent to
0152  *
0153  * struct input_mt_request_layout {
0154  *  __u32 code;
0155  *  __s32 values[num_slots];
0156  * };
0157  *
0158  * where num_slots is the (arbitrary) number of MT slots to extract.
0159  *
0160  * The ioctl size argument (len) is the size of the buffer, which
0161  * should satisfy len = (num_slots + 1) * sizeof(__s32).  If len is
0162  * too small to fit all available slots, the first num_slots are
0163  * returned.
0164  *
0165  * Before the call, code is set to the wanted ABS_MT event type. On
0166  * return, values[] is filled with the slot values for the specified
0167  * ABS_MT code.
0168  *
0169  * If the request code is not an ABS_MT value, -EINVAL is returned.
0170  */
0171 #define EVIOCGMTSLOTS(len)  _IOC(_IOC_READ, 'E', 0x0a, len)
0172 
0173 #define EVIOCGKEY(len)      _IOC(_IOC_READ, 'E', 0x18, len)     /* get global key state */
0174 #define EVIOCGLED(len)      _IOC(_IOC_READ, 'E', 0x19, len)     /* get all LEDs */
0175 #define EVIOCGSND(len)      _IOC(_IOC_READ, 'E', 0x1a, len)     /* get all sounds status */
0176 #define EVIOCGSW(len)       _IOC(_IOC_READ, 'E', 0x1b, len)     /* get all switch states */
0177 
0178 #define EVIOCGBIT(ev,len)   _IOC(_IOC_READ, 'E', 0x20 + (ev), len)  /* get event bits */
0179 #define EVIOCGABS(abs)      _IOR('E', 0x40 + (abs), struct input_absinfo)   /* get abs value/limits */
0180 #define EVIOCSABS(abs)      _IOW('E', 0xc0 + (abs), struct input_absinfo)   /* set abs value/limits */
0181 
0182 #define EVIOCSFF        _IOW('E', 0x80, struct ff_effect)   /* send a force effect to a force feedback device */
0183 #define EVIOCRMFF       _IOW('E', 0x81, int)            /* Erase a force effect */
0184 #define EVIOCGEFFECTS       _IOR('E', 0x84, int)            /* Report number of effects playable at the same time */
0185 
0186 #define EVIOCGRAB       _IOW('E', 0x90, int)            /* Grab/Release device */
0187 #define EVIOCREVOKE     _IOW('E', 0x91, int)            /* Revoke device access */
0188 
0189 /**
0190  * EVIOCGMASK - Retrieve current event mask
0191  *
0192  * This ioctl allows user to retrieve the current event mask for specific
0193  * event type. The argument must be of type "struct input_mask" and
0194  * specifies the event type to query, the address of the receive buffer and
0195  * the size of the receive buffer.
0196  *
0197  * The event mask is a per-client mask that specifies which events are
0198  * forwarded to the client. Each event code is represented by a single bit
0199  * in the event mask. If the bit is set, the event is passed to the client
0200  * normally. Otherwise, the event is filtered and will never be queued on
0201  * the client's receive buffer.
0202  *
0203  * Event masks do not affect global state of the input device. They only
0204  * affect the file descriptor they are applied to.
0205  *
0206  * The default event mask for a client has all bits set, i.e. all events
0207  * are forwarded to the client. If the kernel is queried for an unknown
0208  * event type or if the receive buffer is larger than the number of
0209  * event codes known to the kernel, the kernel returns all zeroes for those
0210  * codes.
0211  *
0212  * At maximum, codes_size bytes are copied.
0213  *
0214  * This ioctl may fail with ENODEV in case the file is revoked, EFAULT
0215  * if the receive-buffer points to invalid memory, or EINVAL if the kernel
0216  * does not implement the ioctl.
0217  */
0218 #define EVIOCGMASK      _IOR('E', 0x92, struct input_mask)  /* Get event-masks */
0219 
0220 /**
0221  * EVIOCSMASK - Set event mask
0222  *
0223  * This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the
0224  * current event mask, this changes the client's event mask for a specific
0225  * type.  See EVIOCGMASK for a description of event-masks and the
0226  * argument-type.
0227  *
0228  * This ioctl provides full forward compatibility. If the passed event type
0229  * is unknown to the kernel, or if the number of event codes specified in
0230  * the mask is bigger than what is known to the kernel, the ioctl is still
0231  * accepted and applied. However, any unknown codes are left untouched and
0232  * stay cleared. That means, the kernel always filters unknown codes
0233  * regardless of what the client requests.  If the new mask doesn't cover
0234  * all known event-codes, all remaining codes are automatically cleared and
0235  * thus filtered.
0236  *
0237  * This ioctl may fail with ENODEV in case the file is revoked. EFAULT is
0238  * returned if the receive-buffer points to invalid memory. EINVAL is returned
0239  * if the kernel does not implement the ioctl.
0240  */
0241 #define EVIOCSMASK      _IOW('E', 0x93, struct input_mask)  /* Set event-masks */
0242 
0243 #define EVIOCSCLOCKID       _IOW('E', 0xa0, int)            /* Set clockid to be used for timestamps */
0244 
0245 /*
0246  * IDs.
0247  */
0248 
0249 #define ID_BUS          0
0250 #define ID_VENDOR       1
0251 #define ID_PRODUCT      2
0252 #define ID_VERSION      3
0253 
0254 #define BUS_PCI         0x01
0255 #define BUS_ISAPNP      0x02
0256 #define BUS_USB         0x03
0257 #define BUS_HIL         0x04
0258 #define BUS_BLUETOOTH       0x05
0259 #define BUS_VIRTUAL     0x06
0260 
0261 #define BUS_ISA         0x10
0262 #define BUS_I8042       0x11
0263 #define BUS_XTKBD       0x12
0264 #define BUS_RS232       0x13
0265 #define BUS_GAMEPORT        0x14
0266 #define BUS_PARPORT     0x15
0267 #define BUS_AMIGA       0x16
0268 #define BUS_ADB         0x17
0269 #define BUS_I2C         0x18
0270 #define BUS_HOST        0x19
0271 #define BUS_GSC         0x1A
0272 #define BUS_ATARI       0x1B
0273 #define BUS_SPI         0x1C
0274 #define BUS_RMI         0x1D
0275 #define BUS_CEC         0x1E
0276 #define BUS_INTEL_ISHTP     0x1F
0277 #define BUS_AMD_SFH     0x20
0278 
0279 /*
0280  * MT_TOOL types
0281  */
0282 #define MT_TOOL_FINGER      0x00
0283 #define MT_TOOL_PEN     0x01
0284 #define MT_TOOL_PALM        0x02
0285 #define MT_TOOL_DIAL        0x0a
0286 #define MT_TOOL_MAX     0x0f
0287 
0288 /*
0289  * Values describing the status of a force-feedback effect
0290  */
0291 #define FF_STATUS_STOPPED   0x00
0292 #define FF_STATUS_PLAYING   0x01
0293 #define FF_STATUS_MAX       0x01
0294 
0295 /*
0296  * Structures used in ioctls to upload effects to a device
0297  * They are pieces of a bigger structure (called ff_effect)
0298  */
0299 
0300 /*
0301  * All duration values are expressed in ms. Values above 32767 ms (0x7fff)
0302  * should not be used and have unspecified results.
0303  */
0304 
0305 /**
0306  * struct ff_replay - defines scheduling of the force-feedback effect
0307  * @length: duration of the effect
0308  * @delay: delay before effect should start playing
0309  */
0310 struct ff_replay {
0311     __u16 length;
0312     __u16 delay;
0313 };
0314 
0315 /**
0316  * struct ff_trigger - defines what triggers the force-feedback effect
0317  * @button: number of the button triggering the effect
0318  * @interval: controls how soon the effect can be re-triggered
0319  */
0320 struct ff_trigger {
0321     __u16 button;
0322     __u16 interval;
0323 };
0324 
0325 /**
0326  * struct ff_envelope - generic force-feedback effect envelope
0327  * @attack_length: duration of the attack (ms)
0328  * @attack_level: level at the beginning of the attack
0329  * @fade_length: duration of fade (ms)
0330  * @fade_level: level at the end of fade
0331  *
0332  * The @attack_level and @fade_level are absolute values; when applying
0333  * envelope force-feedback core will convert to positive/negative
0334  * value based on polarity of the default level of the effect.
0335  * Valid range for the attack and fade levels is 0x0000 - 0x7fff
0336  */
0337 struct ff_envelope {
0338     __u16 attack_length;
0339     __u16 attack_level;
0340     __u16 fade_length;
0341     __u16 fade_level;
0342 };
0343 
0344 /**
0345  * struct ff_constant_effect - defines parameters of a constant force-feedback effect
0346  * @level: strength of the effect; may be negative
0347  * @envelope: envelope data
0348  */
0349 struct ff_constant_effect {
0350     __s16 level;
0351     struct ff_envelope envelope;
0352 };
0353 
0354 /**
0355  * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
0356  * @start_level: beginning strength of the effect; may be negative
0357  * @end_level: final strength of the effect; may be negative
0358  * @envelope: envelope data
0359  */
0360 struct ff_ramp_effect {
0361     __s16 start_level;
0362     __s16 end_level;
0363     struct ff_envelope envelope;
0364 };
0365 
0366 /**
0367  * struct ff_condition_effect - defines a spring or friction force-feedback effect
0368  * @right_saturation: maximum level when joystick moved all way to the right
0369  * @left_saturation: same for the left side
0370  * @right_coeff: controls how fast the force grows when the joystick moves
0371  *  to the right
0372  * @left_coeff: same for the left side
0373  * @deadband: size of the dead zone, where no force is produced
0374  * @center: position of the dead zone
0375  */
0376 struct ff_condition_effect {
0377     __u16 right_saturation;
0378     __u16 left_saturation;
0379 
0380     __s16 right_coeff;
0381     __s16 left_coeff;
0382 
0383     __u16 deadband;
0384     __s16 center;
0385 };
0386 
0387 /**
0388  * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
0389  * @waveform: kind of the effect (wave)
0390  * @period: period of the wave (ms)
0391  * @magnitude: peak value
0392  * @offset: mean value of the wave (roughly)
0393  * @phase: 'horizontal' shift
0394  * @envelope: envelope data
0395  * @custom_len: number of samples (FF_CUSTOM only)
0396  * @custom_data: buffer of samples (FF_CUSTOM only)
0397  *
0398  * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
0399  * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
0400  * for the time being as no driver supports it yet.
0401  *
0402  * Note: the data pointed by custom_data is copied by the driver.
0403  * You can therefore dispose of the memory after the upload/update.
0404  */
0405 struct ff_periodic_effect {
0406     __u16 waveform;
0407     __u16 period;
0408     __s16 magnitude;
0409     __s16 offset;
0410     __u16 phase;
0411 
0412     struct ff_envelope envelope;
0413 
0414     __u32 custom_len;
0415     __s16 __user *custom_data;
0416 };
0417 
0418 /**
0419  * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
0420  * @strong_magnitude: magnitude of the heavy motor
0421  * @weak_magnitude: magnitude of the light one
0422  *
0423  * Some rumble pads have two motors of different weight. Strong_magnitude
0424  * represents the magnitude of the vibration generated by the heavy one.
0425  */
0426 struct ff_rumble_effect {
0427     __u16 strong_magnitude;
0428     __u16 weak_magnitude;
0429 };
0430 
0431 /**
0432  * struct ff_effect - defines force feedback effect
0433  * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
0434  *  FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
0435  * @id: an unique id assigned to an effect
0436  * @direction: direction of the effect
0437  * @trigger: trigger conditions (struct ff_trigger)
0438  * @replay: scheduling of the effect (struct ff_replay)
0439  * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
0440  *  ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
0441  *  defining effect parameters
0442  *
0443  * This structure is sent through ioctl from the application to the driver.
0444  * To create a new effect application should set its @id to -1; the kernel
0445  * will return assigned @id which can later be used to update or delete
0446  * this effect.
0447  *
0448  * Direction of the effect is encoded as follows:
0449  *  0 deg -> 0x0000 (down)
0450  *  90 deg -> 0x4000 (left)
0451  *  180 deg -> 0x8000 (up)
0452  *  270 deg -> 0xC000 (right)
0453  */
0454 struct ff_effect {
0455     __u16 type;
0456     __s16 id;
0457     __u16 direction;
0458     struct ff_trigger trigger;
0459     struct ff_replay replay;
0460 
0461     union {
0462         struct ff_constant_effect constant;
0463         struct ff_ramp_effect ramp;
0464         struct ff_periodic_effect periodic;
0465         struct ff_condition_effect condition[2]; /* One for each axis */
0466         struct ff_rumble_effect rumble;
0467     } u;
0468 };
0469 
0470 /*
0471  * Force feedback effect types
0472  */
0473 
0474 #define FF_RUMBLE   0x50
0475 #define FF_PERIODIC 0x51
0476 #define FF_CONSTANT 0x52
0477 #define FF_SPRING   0x53
0478 #define FF_FRICTION 0x54
0479 #define FF_DAMPER   0x55
0480 #define FF_INERTIA  0x56
0481 #define FF_RAMP     0x57
0482 
0483 #define FF_EFFECT_MIN   FF_RUMBLE
0484 #define FF_EFFECT_MAX   FF_RAMP
0485 
0486 /*
0487  * Force feedback periodic effect types
0488  */
0489 
0490 #define FF_SQUARE   0x58
0491 #define FF_TRIANGLE 0x59
0492 #define FF_SINE     0x5a
0493 #define FF_SAW_UP   0x5b
0494 #define FF_SAW_DOWN 0x5c
0495 #define FF_CUSTOM   0x5d
0496 
0497 #define FF_WAVEFORM_MIN FF_SQUARE
0498 #define FF_WAVEFORM_MAX FF_CUSTOM
0499 
0500 /*
0501  * Set ff device properties
0502  */
0503 
0504 #define FF_GAIN     0x60
0505 #define FF_AUTOCENTER   0x61
0506 
0507 /*
0508  * ff->playback(effect_id = FF_GAIN) is the first effect_id to
0509  * cause a collision with another ff method, in this case ff->set_gain().
0510  * Therefore the greatest safe value for effect_id is FF_GAIN - 1,
0511  * and thus the total number of effects should never exceed FF_GAIN.
0512  */
0513 #define FF_MAX_EFFECTS  FF_GAIN
0514 
0515 #define FF_MAX      0x7f
0516 #define FF_CNT      (FF_MAX+1)
0517 
0518 #endif /* _UAPI_INPUT_H */