input.rst 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. .. include:: <isonum.txt>
  2. ============
  3. Introduction
  4. ============
  5. :Copyright: |copy| 1999-2001 Vojtech Pavlik <[email protected]> - Sponsored by SuSE
  6. Architecture
  7. ============
  8. Input subsystem is a collection of drivers that is designed to support
  9. all input devices under Linux. Most of the drivers reside in
  10. drivers/input, although quite a few live in drivers/hid and
  11. drivers/platform.
  12. The core of the input subsystem is the input module, which must be
  13. loaded before any other of the input modules - it serves as a way of
  14. communication between two groups of modules:
  15. Device drivers
  16. --------------
  17. These modules talk to the hardware (for example via USB), and provide
  18. events (keystrokes, mouse movements) to the input module.
  19. Event handlers
  20. --------------
  21. These modules get events from input core and pass them where needed
  22. via various interfaces - keystrokes to the kernel, mouse movements via
  23. a simulated PS/2 interface to GPM and X, and so on.
  24. Simple Usage
  25. ============
  26. For the most usual configuration, with one USB mouse and one USB keyboard,
  27. you'll have to load the following modules (or have them built in to the
  28. kernel)::
  29. input
  30. mousedev
  31. usbcore
  32. uhci_hcd or ohci_hcd or ehci_hcd
  33. usbhid
  34. hid_generic
  35. After this, the USB keyboard will work straight away, and the USB mouse
  36. will be available as a character device on major 13, minor 63::
  37. crw-r--r-- 1 root root 13, 63 Mar 28 22:45 mice
  38. This device is usually created automatically by the system. The commands
  39. to create it by hand are::
  40. cd /dev
  41. mkdir input
  42. mknod input/mice c 13 63
  43. After that you have to point GPM (the textmode mouse cut&paste tool) and
  44. XFree to this device to use it - GPM should be called like::
  45. gpm -t ps2 -m /dev/input/mice
  46. And in X::
  47. Section "Pointer"
  48. Protocol "ImPS/2"
  49. Device "/dev/input/mice"
  50. ZAxisMapping 4 5
  51. EndSection
  52. When you do all of the above, you can use your USB mouse and keyboard.
  53. Detailed Description
  54. ====================
  55. Event handlers
  56. --------------
  57. Event handlers distribute the events from the devices to userspace and
  58. in-kernel consumers, as needed.
  59. evdev
  60. ~~~~~
  61. ``evdev`` is the generic input event interface. It passes the events
  62. generated in the kernel straight to the program, with timestamps. The
  63. event codes are the same on all architectures and are hardware
  64. independent.
  65. This is the preferred interface for userspace to consume user
  66. input, and all clients are encouraged to use it.
  67. See :ref:`event-interface` for notes on API.
  68. The devices are in /dev/input::
  69. crw-r--r-- 1 root root 13, 64 Apr 1 10:49 event0
  70. crw-r--r-- 1 root root 13, 65 Apr 1 10:50 event1
  71. crw-r--r-- 1 root root 13, 66 Apr 1 10:50 event2
  72. crw-r--r-- 1 root root 13, 67 Apr 1 10:50 event3
  73. ...
  74. There are two ranges of minors: 64 through 95 is the static legacy
  75. range. If there are more than 32 input devices in a system, additional
  76. evdev nodes are created with minors starting with 256.
  77. keyboard
  78. ~~~~~~~~
  79. ``keyboard`` is in-kernel input handler and is a part of VT code. It
  80. consumes keyboard keystrokes and handles user input for VT consoles.
  81. mousedev
  82. ~~~~~~~~
  83. ``mousedev`` is a hack to make legacy programs that use mouse input
  84. work. It takes events from either mice or digitizers/tablets and makes
  85. a PS/2-style (a la /dev/psaux) mouse device available to the
  86. userland.
  87. Mousedev devices in /dev/input (as shown above) are::
  88. crw-r--r-- 1 root root 13, 32 Mar 28 22:45 mouse0
  89. crw-r--r-- 1 root root 13, 33 Mar 29 00:41 mouse1
  90. crw-r--r-- 1 root root 13, 34 Mar 29 00:41 mouse2
  91. crw-r--r-- 1 root root 13, 35 Apr 1 10:50 mouse3
  92. ...
  93. ...
  94. crw-r--r-- 1 root root 13, 62 Apr 1 10:50 mouse30
  95. crw-r--r-- 1 root root 13, 63 Apr 1 10:50 mice
  96. Each ``mouse`` device is assigned to a single mouse or digitizer, except
  97. the last one - ``mice``. This single character device is shared by all
  98. mice and digitizers, and even if none are connected, the device is
  99. present. This is useful for hotplugging USB mice, so that older programs
  100. that do not handle hotplug can open the device even when no mice are
  101. present.
  102. CONFIG_INPUT_MOUSEDEV_SCREEN_[XY] in the kernel configuration are
  103. the size of your screen (in pixels) in XFree86. This is needed if you
  104. want to use your digitizer in X, because its movement is sent to X
  105. via a virtual PS/2 mouse and thus needs to be scaled
  106. accordingly. These values won't be used if you use a mouse only.
  107. Mousedev will generate either PS/2, ImPS/2 (Microsoft IntelliMouse) or
  108. ExplorerPS/2 (IntelliMouse Explorer) protocols, depending on what the
  109. program reading the data wishes. You can set GPM and X to any of
  110. these. You'll need ImPS/2 if you want to make use of a wheel on a USB
  111. mouse and ExplorerPS/2 if you want to use extra (up to 5) buttons.
  112. joydev
  113. ~~~~~~
  114. ``joydev`` implements v0.x and v1.x Linux joystick API. See
  115. :ref:`joystick-api` for details.
  116. As soon as any joystick is connected, it can be accessed in /dev/input on::
  117. crw-r--r-- 1 root root 13, 0 Apr 1 10:50 js0
  118. crw-r--r-- 1 root root 13, 1 Apr 1 10:50 js1
  119. crw-r--r-- 1 root root 13, 2 Apr 1 10:50 js2
  120. crw-r--r-- 1 root root 13, 3 Apr 1 10:50 js3
  121. ...
  122. And so on up to js31 in legacy range, and additional nodes with minors
  123. above 256 if there are more joystick devices.
  124. Device drivers
  125. --------------
  126. Device drivers are the modules that generate events.
  127. hid-generic
  128. ~~~~~~~~~~~
  129. ``hid-generic`` is one of the largest and most complex driver of the
  130. whole suite. It handles all HID devices, and because there is a very
  131. wide variety of them, and because the USB HID specification isn't
  132. simple, it needs to be this big.
  133. Currently, it handles USB mice, joysticks, gamepads, steering wheels,
  134. keyboards, trackballs and digitizers.
  135. However, USB uses HID also for monitor controls, speaker controls, UPSs,
  136. LCDs and many other purposes.
  137. The monitor and speaker controls should be easy to add to the hid/input
  138. interface, but for the UPSs and LCDs it doesn't make much sense. For this,
  139. the hiddev interface was designed. See Documentation/hid/hiddev.rst
  140. for more information about it.
  141. The usage of the usbhid module is very simple, it takes no parameters,
  142. detects everything automatically and when a HID device is inserted, it
  143. detects it appropriately.
  144. However, because the devices vary wildly, you might happen to have a
  145. device that doesn't work well. In that case #define DEBUG at the beginning
  146. of hid-core.c and send me the syslog traces.
  147. usbmouse
  148. ~~~~~~~~
  149. For embedded systems, for mice with broken HID descriptors and just any
  150. other use when the big usbhid wouldn't be a good choice, there is the
  151. usbmouse driver. It handles USB mice only. It uses a simpler HIDBP
  152. protocol. This also means the mice must support this simpler protocol. Not
  153. all do. If you don't have any strong reason to use this module, use usbhid
  154. instead.
  155. usbkbd
  156. ~~~~~~
  157. Much like usbmouse, this module talks to keyboards with a simplified
  158. HIDBP protocol. It's smaller, but doesn't support any extra special keys.
  159. Use usbhid instead if there isn't any special reason to use this.
  160. psmouse
  161. ~~~~~~~
  162. This is driver for all flavors of pointing devices using PS/2
  163. protocol, including Synaptics and ALPS touchpads, Intellimouse
  164. Explorer devices, Logitech PS/2 mice and so on.
  165. atkbd
  166. ~~~~~
  167. This is driver for PS/2 (AT) keyboards.
  168. iforce
  169. ~~~~~~
  170. A driver for I-Force joysticks and wheels, both over USB and RS232.
  171. It includes Force Feedback support now, even though Immersion
  172. Corp. considers the protocol a trade secret and won't disclose a word
  173. about it.
  174. Verifying if it works
  175. =====================
  176. Typing a couple keys on the keyboard should be enough to check that
  177. a keyboard works and is correctly connected to the kernel keyboard
  178. driver.
  179. Doing a ``cat /dev/input/mouse0`` (c, 13, 32) will verify that a mouse
  180. is also emulated; characters should appear if you move it.
  181. You can test the joystick emulation with the ``jstest`` utility,
  182. available in the joystick package (see :ref:`joystick-doc`).
  183. You can test the event devices with the ``evtest`` utility.
  184. .. _event-interface:
  185. Event interface
  186. ===============
  187. You can use blocking and nonblocking reads, and also select() on the
  188. /dev/input/eventX devices, and you'll always get a whole number of input
  189. events on a read. Their layout is::
  190. struct input_event {
  191. struct timeval time;
  192. unsigned short type;
  193. unsigned short code;
  194. unsigned int value;
  195. };
  196. ``time`` is the timestamp, it returns the time at which the event happened.
  197. Type is for example EV_REL for relative movement, EV_KEY for a keypress or
  198. release. More types are defined in include/uapi/linux/input-event-codes.h.
  199. ``code`` is event code, for example REL_X or KEY_BACKSPACE, again a complete
  200. list is in include/uapi/linux/input-event-codes.h.
  201. ``value`` is the value the event carries. Either a relative change for
  202. EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for
  203. release, 1 for keypress and 2 for autorepeat.
  204. See :ref:`input-event-codes` for more information about various even codes.