xref: /OK3568_Linux_fs/kernel/Documentation/input/input.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. include:: <isonum.txt>
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun============
4*4882a593SmuzhiyunIntroduction
5*4882a593Smuzhiyun============
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun:Copyright: |copy| 1999-2001 Vojtech Pavlik <vojtech@ucw.cz> - Sponsored by SuSE
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunArchitecture
10*4882a593Smuzhiyun============
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunInput subsystem  a collection of drivers that is designed to support
13*4882a593Smuzhiyunall input devices under Linux. Most of the drivers reside in
14*4882a593Smuzhiyundrivers/input, although quite a few live in drivers/hid and
15*4882a593Smuzhiyundrivers/platform.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunThe core of the input subsystem is the input module, which must be
18*4882a593Smuzhiyunloaded before any other of the input modules - it serves as a way of
19*4882a593Smuzhiyuncommunication between two groups of modules:
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunDevice drivers
22*4882a593Smuzhiyun--------------
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunThese modules talk to the hardware (for example via USB), and provide
25*4882a593Smuzhiyunevents (keystrokes, mouse movements) to the input module.
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunEvent handlers
28*4882a593Smuzhiyun--------------
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunThese modules get events from input core and pass them where needed
31*4882a593Smuzhiyunvia various interfaces - keystrokes to the kernel, mouse movements via
32*4882a593Smuzhiyuna simulated PS/2 interface to GPM and X, and so on.
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunSimple Usage
35*4882a593Smuzhiyun============
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunFor the most usual configuration, with one USB mouse and one USB keyboard,
38*4882a593Smuzhiyunyou'll have to load the following modules (or have them built in to the
39*4882a593Smuzhiyunkernel)::
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun	input
42*4882a593Smuzhiyun	mousedev
43*4882a593Smuzhiyun	usbcore
44*4882a593Smuzhiyun	uhci_hcd or ohci_hcd or ehci_hcd
45*4882a593Smuzhiyun	usbhid
46*4882a593Smuzhiyun	hid_generic
47*4882a593Smuzhiyun
48*4882a593SmuzhiyunAfter this, the USB keyboard will work straight away, and the USB mouse
49*4882a593Smuzhiyunwill be available as a character device on major 13, minor 63::
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  63 Mar 28 22:45 mice
52*4882a593Smuzhiyun
53*4882a593SmuzhiyunThis device usually created automatically by the system. The commands
54*4882a593Smuzhiyunto create it by hand are::
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun	cd /dev
57*4882a593Smuzhiyun	mkdir input
58*4882a593Smuzhiyun	mknod input/mice c 13 63
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunAfter that you have to point GPM (the textmode mouse cut&paste tool) and
61*4882a593SmuzhiyunXFree to this device to use it - GPM should be called like::
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun	gpm -t ps2 -m /dev/input/mice
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunAnd in X::
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun	Section "Pointer"
68*4882a593Smuzhiyun	    Protocol    "ImPS/2"
69*4882a593Smuzhiyun	    Device      "/dev/input/mice"
70*4882a593Smuzhiyun	    ZAxisMapping 4 5
71*4882a593Smuzhiyun	EndSection
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunWhen you do all of the above, you can use your USB mouse and keyboard.
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunDetailed Description
76*4882a593Smuzhiyun====================
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunEvent handlers
79*4882a593Smuzhiyun--------------
80*4882a593Smuzhiyun
81*4882a593SmuzhiyunEvent handlers distribute the events from the devices to userspace and
82*4882a593Smuzhiyunin-kernel consumers, as needed.
83*4882a593Smuzhiyun
84*4882a593Smuzhiyunevdev
85*4882a593Smuzhiyun~~~~~
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun``evdev`` is the generic input event interface. It passes the events
88*4882a593Smuzhiyungenerated in the kernel straight to the program, with timestamps. The
89*4882a593Smuzhiyunevent codes are the same on all architectures and are hardware
90*4882a593Smuzhiyunindependent.
91*4882a593Smuzhiyun
92*4882a593SmuzhiyunThis is the preferred interface for userspace to consume user
93*4882a593Smuzhiyuninput, and all clients are encouraged to use it.
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunSee :ref:`event-interface` for notes on API.
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunThe devices are in /dev/input::
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  64 Apr  1 10:49 event0
100*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  65 Apr  1 10:50 event1
101*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  66 Apr  1 10:50 event2
102*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  67 Apr  1 10:50 event3
103*4882a593Smuzhiyun	...
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunThere are two ranges of minors: 64 through 95 is the static legacy
106*4882a593Smuzhiyunrange. If there are more than 32 input devices in a system, additional
107*4882a593Smuzhiyunevdev nodes are created with minors starting with 256.
108*4882a593Smuzhiyun
109*4882a593Smuzhiyunkeyboard
110*4882a593Smuzhiyun~~~~~~~~
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun``keyboard`` is in-kernel input handler and is a part of VT code. It
113*4882a593Smuzhiyunconsumes keyboard keystrokes and handles user input for VT consoles.
114*4882a593Smuzhiyun
115*4882a593Smuzhiyunmousedev
116*4882a593Smuzhiyun~~~~~~~~
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun``mousedev`` is a hack to make legacy programs that use mouse input
119*4882a593Smuzhiyunwork. It takes events from either mice or digitizers/tablets and makes
120*4882a593Smuzhiyuna PS/2-style (a la /dev/psaux) mouse device available to the
121*4882a593Smuzhiyunuserland.
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunMousedev devices in /dev/input (as shown above) are::
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  32 Mar 28 22:45 mouse0
126*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  33 Mar 29 00:41 mouse1
127*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  34 Mar 29 00:41 mouse2
128*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  35 Apr  1 10:50 mouse3
129*4882a593Smuzhiyun	...
130*4882a593Smuzhiyun	...
131*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  62 Apr  1 10:50 mouse30
132*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,  63 Apr  1 10:50 mice
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunEach ``mouse`` device is assigned to a single mouse or digitizer, except
135*4882a593Smuzhiyunthe last one - ``mice``. This single character device is shared by all
136*4882a593Smuzhiyunmice and digitizers, and even if none are connected, the device is
137*4882a593Smuzhiyunpresent.  This is useful for hotplugging USB mice, so that older programs
138*4882a593Smuzhiyunthat do not handle hotplug can open the device even when no mice are
139*4882a593Smuzhiyunpresent.
140*4882a593Smuzhiyun
141*4882a593SmuzhiyunCONFIG_INPUT_MOUSEDEV_SCREEN_[XY] in the kernel configuration are
142*4882a593Smuzhiyunthe size of your screen (in pixels) in XFree86. This is needed if you
143*4882a593Smuzhiyunwant to use your digitizer in X, because its movement is sent to X
144*4882a593Smuzhiyunvia a virtual PS/2 mouse and thus needs to be scaled
145*4882a593Smuzhiyunaccordingly. These values won't be used if you use a mouse only.
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunMousedev will generate either PS/2, ImPS/2 (Microsoft IntelliMouse) or
148*4882a593SmuzhiyunExplorerPS/2 (IntelliMouse Explorer) protocols, depending on what the
149*4882a593Smuzhiyunprogram reading the data wishes. You can set GPM and X to any of
150*4882a593Smuzhiyunthese. You'll need ImPS/2 if you want to make use of a wheel on a USB
151*4882a593Smuzhiyunmouse and ExplorerPS/2 if you want to use extra (up to 5) buttons.
152*4882a593Smuzhiyun
153*4882a593Smuzhiyunjoydev
154*4882a593Smuzhiyun~~~~~~
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun``joydev`` implements v0.x and v1.x Linux joystick API. See
157*4882a593Smuzhiyun:ref:`joystick-api` for details.
158*4882a593Smuzhiyun
159*4882a593SmuzhiyunAs soon as any joystick is connected, it can be accessed in /dev/input on::
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,   0 Apr  1 10:50 js0
162*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,   1 Apr  1 10:50 js1
163*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,   2 Apr  1 10:50 js2
164*4882a593Smuzhiyun	crw-r--r--   1 root     root      13,   3 Apr  1 10:50 js3
165*4882a593Smuzhiyun	...
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunAnd so on up to js31 in legacy range, and additional nodes with minors
168*4882a593Smuzhiyunabove 256 if there are more joystick devices.
169*4882a593Smuzhiyun
170*4882a593SmuzhiyunDevice drivers
171*4882a593Smuzhiyun--------------
172*4882a593Smuzhiyun
173*4882a593SmuzhiyunDevice drivers are the modules that generate events.
174*4882a593Smuzhiyun
175*4882a593Smuzhiyunhid-generic
176*4882a593Smuzhiyun~~~~~~~~~~~
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun``hid-generic`` is one of the largest and most complex driver of the
179*4882a593Smuzhiyunwhole suite. It handles all HID devices, and because there is a very
180*4882a593Smuzhiyunwide variety of them, and because the USB HID specification isn't
181*4882a593Smuzhiyunsimple, it needs to be this big.
182*4882a593Smuzhiyun
183*4882a593SmuzhiyunCurrently, it handles USB mice, joysticks, gamepads, steering wheels
184*4882a593Smuzhiyunkeyboards, trackballs and digitizers.
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunHowever, USB uses HID also for monitor controls, speaker controls, UPSs,
187*4882a593SmuzhiyunLCDs and many other purposes.
188*4882a593Smuzhiyun
189*4882a593SmuzhiyunThe monitor and speaker controls should be easy to add to the hid/input
190*4882a593Smuzhiyuninterface, but for the UPSs and LCDs it doesn't make much sense. For this,
191*4882a593Smuzhiyunthe hiddev interface was designed. See Documentation/hid/hiddev.rst
192*4882a593Smuzhiyunfor more information about it.
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunThe usage of the usbhid module is very simple, it takes no parameters,
195*4882a593Smuzhiyundetects everything automatically and when a HID device is inserted, it
196*4882a593Smuzhiyundetects it appropriately.
197*4882a593Smuzhiyun
198*4882a593SmuzhiyunHowever, because the devices vary wildly, you might happen to have a
199*4882a593Smuzhiyundevice that doesn't work well. In that case #define DEBUG at the beginning
200*4882a593Smuzhiyunof hid-core.c and send me the syslog traces.
201*4882a593Smuzhiyun
202*4882a593Smuzhiyunusbmouse
203*4882a593Smuzhiyun~~~~~~~~
204*4882a593Smuzhiyun
205*4882a593SmuzhiyunFor embedded systems, for mice with broken HID descriptors and just any
206*4882a593Smuzhiyunother use when the big usbhid wouldn't be a good choice, there is the
207*4882a593Smuzhiyunusbmouse driver. It handles USB mice only. It uses a simpler HIDBP
208*4882a593Smuzhiyunprotocol. This also means the mice must support this simpler protocol. Not
209*4882a593Smuzhiyunall do. If you don't have any strong reason to use this module, use usbhid
210*4882a593Smuzhiyuninstead.
211*4882a593Smuzhiyun
212*4882a593Smuzhiyunusbkbd
213*4882a593Smuzhiyun~~~~~~
214*4882a593Smuzhiyun
215*4882a593SmuzhiyunMuch like usbmouse, this module talks to keyboards with a simplified
216*4882a593SmuzhiyunHIDBP protocol. It's smaller, but doesn't support any extra special keys.
217*4882a593SmuzhiyunUse usbhid instead if there isn't any special reason to use this.
218*4882a593Smuzhiyun
219*4882a593Smuzhiyunpsmouse
220*4882a593Smuzhiyun~~~~~~~
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunThis is driver for all flavors of pointing devices using PS/2
223*4882a593Smuzhiyunprotocol, including Synaptics and ALPS touchpads, Intellimouse
224*4882a593SmuzhiyunExplorer devices, Logitech PS/2 mice and so on.
225*4882a593Smuzhiyun
226*4882a593Smuzhiyunatkbd
227*4882a593Smuzhiyun~~~~~
228*4882a593Smuzhiyun
229*4882a593SmuzhiyunThis is driver for PS/2 (AT) keyboards.
230*4882a593Smuzhiyun
231*4882a593Smuzhiyuniforce
232*4882a593Smuzhiyun~~~~~~
233*4882a593Smuzhiyun
234*4882a593SmuzhiyunA driver for I-Force joysticks and wheels, both over USB and RS232.
235*4882a593SmuzhiyunIt includes Force Feedback support now, even though Immersion
236*4882a593SmuzhiyunCorp. considers the protocol a trade secret and won't disclose a word
237*4882a593Smuzhiyunabout it.
238*4882a593Smuzhiyun
239*4882a593SmuzhiyunVerifying if it works
240*4882a593Smuzhiyun=====================
241*4882a593Smuzhiyun
242*4882a593SmuzhiyunTyping a couple keys on the keyboard should be enough to check that
243*4882a593Smuzhiyuna keyboard works and is correctly connected to the kernel keyboard
244*4882a593Smuzhiyundriver.
245*4882a593Smuzhiyun
246*4882a593SmuzhiyunDoing a ``cat /dev/input/mouse0`` (c, 13, 32) will verify that a mouse
247*4882a593Smuzhiyunis also emulated; characters should appear if you move it.
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunYou can test the joystick emulation with the ``jstest`` utility,
250*4882a593Smuzhiyunavailable in the joystick package (see :ref:`joystick-doc`).
251*4882a593Smuzhiyun
252*4882a593SmuzhiyunYou can test the event devices with the ``evtest`` utility.
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun.. _event-interface:
255*4882a593Smuzhiyun
256*4882a593SmuzhiyunEvent interface
257*4882a593Smuzhiyun===============
258*4882a593Smuzhiyun
259*4882a593SmuzhiyunYou can use blocking and nonblocking reads, and also select() on the
260*4882a593Smuzhiyun/dev/input/eventX devices, and you'll always get a whole number of input
261*4882a593Smuzhiyunevents on a read. Their layout is::
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun    struct input_event {
264*4882a593Smuzhiyun	    struct timeval time;
265*4882a593Smuzhiyun	    unsigned short type;
266*4882a593Smuzhiyun	    unsigned short code;
267*4882a593Smuzhiyun	    unsigned int value;
268*4882a593Smuzhiyun    };
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun``time`` is the timestamp, it returns the time at which the event happened.
271*4882a593SmuzhiyunType is for example EV_REL for relative moment, EV_KEY for a keypress or
272*4882a593Smuzhiyunrelease. More types are defined in include/uapi/linux/input-event-codes.h.
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun``code`` is event code, for example REL_X or KEY_BACKSPACE, again a complete
275*4882a593Smuzhiyunlist is in include/uapi/linux/input-event-codes.h.
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun``value`` is the value the event carries. Either a relative change for
278*4882a593SmuzhiyunEV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for
279*4882a593Smuzhiyunrelease, 1 for keypress and 2 for autorepeat.
280*4882a593Smuzhiyun
281*4882a593SmuzhiyunSee :ref:`input-event-codes` for more information about various even codes.
282