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 313 /* 314 * MT_TOOL types 315 */ 316 #define MT_TOOL_FINGER 0x00 317 #define MT_TOOL_PEN 0x01 318 #define MT_TOOL_PALM 0x02 319 #define MT_TOOL_DIAL 0x0a 320 #define MT_TOOL_MAX 0x0f 321 322 /* 323 * Values describing the status of a force-feedback effect 324 */ 325 #define FF_STATUS_STOPPED 0x00 326 #define FF_STATUS_PLAYING 0x01 327 #define FF_STATUS_MAX 0x01 328 329 /* 330 * Structures used in ioctls to upload effects to a device 331 * They are pieces of a bigger structure (called ff_effect) 332 */ 333 334 /* 335 * All duration values are expressed in ms. Values above 32767 ms (0x7fff) 336 * should not be used and have unspecified results. 337 */ 338 339 /** 340 * struct ff_replay - defines scheduling of the force-feedback effect 341 * @length: duration of the effect 342 * @delay: delay before effect should start playing 343 */ 344 struct ff_replay { 345 __u16 length; 346 __u16 delay; 347 }; 348 349 /** 350 * struct ff_trigger - defines what triggers the force-feedback effect 351 * @button: number of the button triggering the effect 352 * @interval: controls how soon the effect can be re-triggered 353 */ 354 struct ff_trigger { 355 __u16 button; 356 __u16 interval; 357 }; 358 359 /** 360 * struct ff_envelope - generic force-feedback effect envelope 361 * @attack_length: duration of the attack (ms) 362 * @attack_level: level at the beginning of the attack 363 * @fade_length: duration of fade (ms) 364 * @fade_level: level at the end of fade 365 * 366 * The @attack_level and @fade_level are absolute values; when applying 367 * envelope force-feedback core will convert to positive/negative 368 * value based on polarity of the default level of the effect. 369 * Valid range for the attack and fade levels is 0x0000 - 0x7fff 370 */ 371 struct ff_envelope { 372 __u16 attack_length; 373 __u16 attack_level; 374 __u16 fade_length; 375 __u16 fade_level; 376 }; 377 378 /** 379 * struct ff_constant_effect - defines parameters of a constant force-feedback effect 380 * @level: strength of the effect; may be negative 381 * @envelope: envelope data 382 */ 383 struct ff_constant_effect { 384 __s16 level; 385 struct ff_envelope envelope; 386 }; 387 388 /** 389 * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect 390 * @start_level: beginning strength of the effect; may be negative 391 * @end_level: final strength of the effect; may be negative 392 * @envelope: envelope data 393 */ 394 struct ff_ramp_effect { 395 __s16 start_level; 396 __s16 end_level; 397 struct ff_envelope envelope; 398 }; 399 400 /** 401 * struct ff_condition_effect - defines a spring or friction force-feedback effect 402 * @right_saturation: maximum level when joystick moved all way to the right 403 * @left_saturation: same for the left side 404 * @right_coeff: controls how fast the force grows when the joystick moves 405 * to the right 406 * @left_coeff: same for the left side 407 * @deadband: size of the dead zone, where no force is produced 408 * @center: position of the dead zone 409 */ 410 struct ff_condition_effect { 411 __u16 right_saturation; 412 __u16 left_saturation; 413 414 __s16 right_coeff; 415 __s16 left_coeff; 416 417 __u16 deadband; 418 __s16 center; 419 }; 420 421 /** 422 * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect 423 * @waveform: kind of the effect (wave) 424 * @period: period of the wave (ms) 425 * @magnitude: peak value 426 * @offset: mean value of the wave (roughly) 427 * @phase: 'horizontal' shift 428 * @envelope: envelope data 429 * @custom_len: number of samples (FF_CUSTOM only) 430 * @custom_data: buffer of samples (FF_CUSTOM only) 431 * 432 * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP, 433 * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined 434 * for the time being as no driver supports it yet. 435 * 436 * Note: the data pointed by custom_data is copied by the driver. 437 * You can therefore dispose of the memory after the upload/update. 438 */ 439 struct ff_periodic_effect { 440 __u16 waveform; 441 __u16 period; 442 __s16 magnitude; 443 __s16 offset; 444 __u16 phase; 445 446 struct ff_envelope envelope; 447 448 __u32 custom_len; 449 __s16 *custom_data; 450 }; 451 452 /** 453 * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect 454 * @strong_magnitude: magnitude of the heavy motor 455 * @weak_magnitude: magnitude of the light one 456 * 457 * Some rumble pads have two motors of different weight. Strong_magnitude 458 * represents the magnitude of the vibration generated by the heavy one. 459 */ 460 struct ff_rumble_effect { 461 __u16 strong_magnitude; 462 __u16 weak_magnitude; 463 }; 464 465 /** 466 * struct ff_effect - defines force feedback effect 467 * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING, 468 * FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM) 469 * @id: an unique id assigned to an effect 470 * @direction: direction of the effect 471 * @trigger: trigger conditions (struct ff_trigger) 472 * @replay: scheduling of the effect (struct ff_replay) 473 * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect, 474 * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further 475 * defining effect parameters 476 * 477 * This structure is sent through ioctl from the application to the driver. 478 * To create a new effect application should set its @id to -1; the kernel 479 * will return assigned @id which can later be used to update or delete 480 * this effect. 481 * 482 * Direction of the effect is encoded as follows: 483 * 0 deg -> 0x0000 (down) 484 * 90 deg -> 0x4000 (left) 485 * 180 deg -> 0x8000 (up) 486 * 270 deg -> 0xC000 (right) 487 */ 488 struct ff_effect { 489 __u16 type; 490 __s16 id; 491 __u16 direction; 492 struct ff_trigger trigger; 493 struct ff_replay replay; 494 495 union { 496 struct ff_constant_effect constant; 497 struct ff_ramp_effect ramp; 498 struct ff_periodic_effect periodic; 499 struct ff_condition_effect condition[2]; /* One for each axis */ 500 struct ff_rumble_effect rumble; 501 } u; 502 }; 503 504 /* 505 * Force feedback effect types 506 */ 507 508 #define FF_RUMBLE 0x50 509 #define FF_PERIODIC 0x51 510 #define FF_CONSTANT 0x52 511 #define FF_SPRING 0x53 512 #define FF_FRICTION 0x54 513 #define FF_DAMPER 0x55 514 #define FF_INERTIA 0x56 515 #define FF_RAMP 0x57 516 517 #define FF_EFFECT_MIN FF_RUMBLE 518 #define FF_EFFECT_MAX FF_RAMP 519 520 /* 521 * Force feedback periodic effect types 522 */ 523 524 #define FF_SQUARE 0x58 525 #define FF_TRIANGLE 0x59 526 #define FF_SINE 0x5a 527 #define FF_SAW_UP 0x5b 528 #define FF_SAW_DOWN 0x5c 529 #define FF_CUSTOM 0x5d 530 531 #define FF_WAVEFORM_MIN FF_SQUARE 532 #define FF_WAVEFORM_MAX FF_CUSTOM 533 534 /* 535 * Set ff device properties 536 */ 537 538 #define FF_GAIN 0x60 539 #define FF_AUTOCENTER 0x61 540 541 /* 542 * ff->playback(effect_id = FF_GAIN) is the first effect_id to 543 * cause a collision with another ff method, in this case ff->set_gain(). 544 * Therefore the greatest safe value for effect_id is FF_GAIN - 1, 545 * and thus the total number of effects should never exceed FF_GAIN. 546 */ 547 #define FF_MAX_EFFECTS FF_GAIN 548 549 #define FF_MAX 0x7f 550 #define FF_CNT (FF_MAX+1) 551 552 #endif /* _INPUT_H */ 553