input.h 16 KB

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