input.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. Linux Input drivers v1.0
  2. (c) 1999-2001 Vojtech Pavlik <vojtech@ucw.cz>
  3. Sponsored by SuSE
  4. ----------------------------------------------------------------------------
  5. 0. Disclaimer
  6. ~~~~~~~~~~~~~
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your option)
  10. any later version.
  11. This program is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. more details.
  15. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc., 59
  17. Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. Should you need to contact me, the author, you can do so either by e-mail
  19. - mail your message to <vojtech@ucw.cz>, or by paper mail: Vojtech Pavlik,
  20. Simunkova 1594, Prague 8, 182 00 Czech Republic
  21. For your convenience, the GNU General Public License version 2 is included
  22. in the package: See the file COPYING.
  23. 1. Introduction
  24. ~~~~~~~~~~~~~~~
  25. This is a collection of drivers that is designed to support all input
  26. devices under Linux. While it is currently used only on for USB input
  27. devices, future use (say 2.5/2.6) is expected to expand to replace
  28. most of the existing input system, which is why it lives in
  29. drivers/input/ instead of drivers/usb/.
  30. The centre of the input drivers is the input module, which must be
  31. loaded before any other of the input modules - it serves as a way of
  32. communication between two groups of modules:
  33. 1.1 Device drivers
  34. ~~~~~~~~~~~~~~~~~~
  35. These modules talk to the hardware (for example via USB), and provide
  36. events (keystrokes, mouse movements) to the input module.
  37. 1.2 Event handlers
  38. ~~~~~~~~~~~~~~~~~~
  39. These modules get events from input and pass them where needed via
  40. various interfaces - keystrokes to the kernel, mouse movements via a
  41. simulated PS/2 interface to GPM and X and so on.
  42. 2. Simple Usage
  43. ~~~~~~~~~~~~~~~
  44. For the most usual configuration, with one USB mouse and one USB keyboard,
  45. you'll have to load the following modules (or have them built in to the
  46. kernel):
  47. input
  48. mousedev
  49. keybdev
  50. usbcore
  51. uhci_hcd or ohci_hcd or ehci_hcd
  52. usbhid
  53. After this, the USB keyboard will work straight away, and the USB mouse
  54. will be available as a character device on major 13, minor 63:
  55. crw-r--r-- 1 root root 13, 63 Mar 28 22:45 mice
  56. This device has to be created.
  57. The commands to create it by hand are:
  58. cd /dev
  59. mkdir input
  60. mknod input/mice c 13 63
  61. After that you have to point GPM (the textmode mouse cut&paste tool) and
  62. XFree to this device to use it - GPM should be called like:
  63. gpm -t ps2 -m /dev/input/mice
  64. And in X:
  65. Section "Pointer"
  66. Protocol "ImPS/2"
  67. Device "/dev/input/mice"
  68. ZAxisMapping 4 5
  69. EndSection
  70. When you do all of the above, you can use your USB mouse and keyboard.
  71. 3. Detailed Description
  72. ~~~~~~~~~~~~~~~~~~~~~~~
  73. 3.1 Device drivers
  74. ~~~~~~~~~~~~~~~~~~
  75. Device drivers are the modules that generate events. The events are
  76. however not useful without being handled, so you also will need to use some
  77. of the modules from section 3.2.
  78. 3.1.1 usbhid
  79. ~~~~~~~~~~~~
  80. usbhid is the largest and most complex driver of the whole suite. It
  81. handles all HID devices, and because there is a very wide variety of them,
  82. and because the USB HID specification isn't simple, it needs to be this big.
  83. Currently, it handles USB mice, joysticks, gamepads, steering wheels
  84. keyboards, trackballs and digitizers.
  85. However, USB uses HID also for monitor controls, speaker controls, UPSs,
  86. LCDs and many other purposes.
  87. The monitor and speaker controls should be easy to add to the hid/input
  88. interface, but for the UPSs and LCDs it doesn't make much sense. For this,
  89. the hiddev interface was designed. See Documentation/hid/hiddev.txt
  90. for more information about it.
  91. The usage of the usbhid module is very simple, it takes no parameters,
  92. detects everything automatically and when a HID device is inserted, it
  93. detects it appropriately.
  94. However, because the devices vary wildly, you might happen to have a
  95. device that doesn't work well. In that case #define DEBUG at the beginning
  96. of hid-core.c and send me the syslog traces.
  97. 3.1.2 usbmouse
  98. ~~~~~~~~~~~~~~
  99. For embedded systems, for mice with broken HID descriptors and just any
  100. other use when the big usbhid wouldn't be a good choice, there is the
  101. usbmouse driver. It handles USB mice only. It uses a simpler HIDBP
  102. protocol. This also means the mice must support this simpler protocol. Not
  103. all do. If you don't have any strong reason to use this module, use usbhid
  104. instead.
  105. 3.1.3 usbkbd
  106. ~~~~~~~~~~~~
  107. Much like usbmouse, this module talks to keyboards with a simplified
  108. HIDBP protocol. It's smaller, but doesn't support any extra special keys.
  109. Use usbhid instead if there isn't any special reason to use this.
  110. 3.1.4 wacom
  111. ~~~~~~~~~~~
  112. This is a driver for Wacom Graphire and Intuos tablets. Not for Wacom
  113. PenPartner, that one is handled by the HID driver. Although the Intuos and
  114. Graphire tablets claim that they are HID tablets as well, they are not and
  115. thus need this specific driver.
  116. 3.1.5 iforce
  117. ~~~~~~~~~~~~
  118. A driver for I-Force joysticks and wheels, both over USB and RS232.
  119. It includes ForceFeedback support now, even though Immersion
  120. Corp. considers the protocol a trade secret and won't disclose a word
  121. about it.
  122. 3.2 Event handlers
  123. ~~~~~~~~~~~~~~~~~~
  124. Event handlers distribute the events from the devices to userland and
  125. kernel, as needed.
  126. 3.2.1 keybdev
  127. ~~~~~~~~~~~~~
  128. keybdev is currently a rather ugly hack that translates the input
  129. events into architecture-specific keyboard raw mode (Xlated AT Set2 on
  130. x86), and passes them into the handle_scancode function of the
  131. keyboard.c module. This works well enough on all architectures that
  132. keybdev can generate rawmode on, other architectures can be added to
  133. it.
  134. The right way would be to pass the events to keyboard.c directly,
  135. best if keyboard.c would itself be an event handler. This is done in
  136. the input patch, available on the webpage mentioned below.
  137. 3.2.2 mousedev
  138. ~~~~~~~~~~~~~~
  139. mousedev is also a hack to make programs that use mouse input
  140. work. It takes events from either mice or digitizers/tablets and makes
  141. a PS/2-style (a la /dev/psaux) mouse device available to the
  142. userland. Ideally, the programs could use a more reasonable interface,
  143. for example evdev
  144. Mousedev devices in /dev/input (as shown above) are:
  145. crw-r--r-- 1 root root 13, 32 Mar 28 22:45 mouse0
  146. crw-r--r-- 1 root root 13, 33 Mar 29 00:41 mouse1
  147. crw-r--r-- 1 root root 13, 34 Mar 29 00:41 mouse2
  148. crw-r--r-- 1 root root 13, 35 Apr 1 10:50 mouse3
  149. ...
  150. ...
  151. crw-r--r-- 1 root root 13, 62 Apr 1 10:50 mouse30
  152. crw-r--r-- 1 root root 13, 63 Apr 1 10:50 mice
  153. Each 'mouse' device is assigned to a single mouse or digitizer, except
  154. the last one - 'mice'. This single character device is shared by all
  155. mice and digitizers, and even if none are connected, the device is
  156. present. This is useful for hotplugging USB mice, so that programs
  157. can open the device even when no mice are present.
  158. CONFIG_INPUT_MOUSEDEV_SCREEN_[XY] in the kernel configuration are
  159. the size of your screen (in pixels) in XFree86. This is needed if you
  160. want to use your digitizer in X, because its movement is sent to X
  161. via a virtual PS/2 mouse and thus needs to be scaled
  162. accordingly. These values won't be used if you use a mouse only.
  163. Mousedev will generate either PS/2, ImPS/2 (Microsoft IntelliMouse) or
  164. ExplorerPS/2 (IntelliMouse Explorer) protocols, depending on what the
  165. program reading the data wishes. You can set GPM and X to any of
  166. these. You'll need ImPS/2 if you want to make use of a wheel on a USB
  167. mouse and ExplorerPS/2 if you want to use extra (up to 5) buttons.
  168. 3.2.3 joydev
  169. ~~~~~~~~~~~~
  170. Joydev implements v0.x and v1.x Linux joystick api, much like
  171. drivers/char/joystick/joystick.c used to in earlier versions. See
  172. joystick-api.txt in the Documentation subdirectory for details. As
  173. soon as any joystick is connected, it can be accessed in /dev/input
  174. on:
  175. crw-r--r-- 1 root root 13, 0 Apr 1 10:50 js0
  176. crw-r--r-- 1 root root 13, 1 Apr 1 10:50 js1
  177. crw-r--r-- 1 root root 13, 2 Apr 1 10:50 js2
  178. crw-r--r-- 1 root root 13, 3 Apr 1 10:50 js3
  179. ...
  180. And so on up to js31.
  181. 3.2.4 evdev
  182. ~~~~~~~~~~~
  183. evdev is the generic input event interface. It passes the events
  184. generated in the kernel straight to the program, with timestamps. The
  185. API is still evolving, but should be usable now. It's described in
  186. section 5.
  187. This should be the way for GPM and X to get keyboard and mouse
  188. events. It allows for multihead in X without any specific multihead
  189. kernel support. The event codes are the same on all architectures and
  190. are hardware independent.
  191. The devices are in /dev/input:
  192. crw-r--r-- 1 root root 13, 64 Apr 1 10:49 event0
  193. crw-r--r-- 1 root root 13, 65 Apr 1 10:50 event1
  194. crw-r--r-- 1 root root 13, 66 Apr 1 10:50 event2
  195. crw-r--r-- 1 root root 13, 67 Apr 1 10:50 event3
  196. ...
  197. And so on up to event31.
  198. 4. Verifying if it works
  199. ~~~~~~~~~~~~~~~~~~~~~~~~
  200. Typing a couple keys on the keyboard should be enough to check that
  201. a USB keyboard works and is correctly connected to the kernel keyboard
  202. driver.
  203. Doing a "cat /dev/input/mouse0" (c, 13, 32) will verify that a mouse
  204. is also emulated; characters should appear if you move it.
  205. You can test the joystick emulation with the 'jstest' utility,
  206. available in the joystick package (see Documentation/input/joystick.txt).
  207. You can test the event devices with the 'evtest' utility available
  208. in the LinuxConsole project CVS archive (see the URL below).
  209. 5. Event interface
  210. ~~~~~~~~~~~~~~~~~~
  211. Should you want to add event device support into any application (X, gpm,
  212. svgalib ...) I <vojtech@ucw.cz> will be happy to provide you any help I
  213. can. Here goes a description of the current state of things, which is going
  214. to be extended, but not changed incompatibly as time goes:
  215. You can use blocking and nonblocking reads, also select() on the
  216. /dev/input/eventX devices, and you'll always get a whole number of input
  217. events on a read. Their layout is:
  218. struct input_event {
  219. struct timeval time;
  220. unsigned short type;
  221. unsigned short code;
  222. unsigned int value;
  223. };
  224. 'time' is the timestamp, it returns the time at which the event happened.
  225. Type is for example EV_REL for relative moment, EV_KEY for a keypress or
  226. release. More types are defined in include/linux/input.h.
  227. 'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete
  228. list is in include/linux/input.h.
  229. 'value' is the value the event carries. Either a relative change for
  230. EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for
  231. release, 1 for keypress and 2 for autorepeat.