Linux joystick mini howto Version 0.08

Linux joystick mini howto Version 0.08

Post by Mike Dia » Sat, 20 Oct 2001 02:32:57

Linux Joystick Mini Howto

Mike Diack with help from a cast of many!


Revision History

0.08    18  Oct  2001 Updated to talk of the recent kernels (see section 6)
0.07     2  Oct  2001 Updated to speak a bit more about 2.4.10,
                      Mandrake 8.1 (final) and analog problems.
0.06     26 Sept 2001 Updated again to include a lsmod output
                      (possibly to help trouble shoot) from a 2.4.10
                      kernel system. See section 3
0.05     25 Sept 2001 Updated following trials of kernel 2.4.10
                      (running with Mandrake 8.1 release candidate 1)
                      Made comments about devfs and encouraged users
                      to upgrade to kernel 2.4.10 or later.
0.04     11 Sept 2001 Added ref to news groups
0.03     10 Sept 2001 Updates from Geoff Reidy (analog stuff)
0.02     24 June 2001 Updates from Donald Wilson and updates
                      following trial of the latest 2.4 patches,
                      fleshed out a few bits (kernel 2.4 sign on etc)
0.01     21 June 2001 Initial version - A messy braindump!

Upcoming plans/to do list

Geoff Reidy
Donald Wilson
Vojtech Pavlik (of course!)

Obtaining the latest version of the document

For the time being, the latest version of this document
can always be found on Usenet, in the comp.os.linux.hardware
group. Searching via is good.


This document was initially developed by me as a means of capturing
my own feedback and lessons learnt while trying to install support
under Linux for my Gravis XTerminator joystick. I found (at the
time at least), no prior "howto" type document, so following
comments from a few people decided to begin one.

I must acknowledge the help of Vojtech, the author of the joystick
subsystem and many other people.

All contributions/feedback much welcomed.

These documents are intended to supplement the joystick.txt and other
files in the main kernel source tree's documentation area.

This document assumes a reasonable level of knowledge, and presumes
that you are familiar with configuring, building and installing
kernels and loading/unloading modules.
Details of this can be found elsewhere (see the relevant howtos etc)

Please not also, that the kernel 2.2 and 2.4 joystick implementations
work slightly differently and must also be compiled and installed
differently. In particular the 2.4 implementation has changed over
time. Details of both are shown below.

IMPORTANT NOTE: Joystick support in the 2.4 series of kernels was broken
between 2.4.3 and 2.4.9 (there were fixes by Alan Cox). For the most part
it's now fixed in 2.4.10 final (and some others, but see section 6),
though there are problems in that kernel
for analog joysticks (Alan Cox has patches available in his 2.4.10-ac series).
In summary, it's recommended that kernel 2.4 users, move straight to kernel
2.4.10 (or maybe 2.4.13 pre at the time of writing)


(At the moment, due to lack of any prior feedback), this document
is substantially based on my own experiences with my Gravis joystick
and a SB PCI 128 soundcard (and an AWE 64 soundcard before that!), and
with Mandrake 7.2 and Mandrake 8 and 8.1 with kernels 2.2.18, 2.2.19 amd
2.4.2 and the 2.4 kernel series right up to the recent 2.4.10 final and
2.4.11 and 2.4.12 final (AVOID!) and 2.4.13 pre-releases.

The document also touches on my first experiences of the new 2.4.10
kernel (and later kernels) (which have a large number of joystick updates)
on Mandrake Linux 8.1 final.

I'm looking (following feedback from other joystick users) to greatly
expand the scope of this. Please contribute via the email address

Onto the body of the document:


1) Howto compile your kernel to support joysticks
2) Getting the joystick support loaded and in use once compiled
3) How to see whether joystick support seems to be loaded ok
4) The /dev file settings required by the joysticks
5) Miscellaneous info/hints/tips
6) Recent Kernel 2.4 Joystick Updates (2.4.10 onwards)

1) Howto compile your kernel to support joysticks:

Detailed below are the menuconfig kernel settings I used to compile
joysticks (as modules) for both the 2.2.x and 2.4.x kernels:

Compiling For 2.2 kernels

In the 'Character Devices' section, turn on Joystick Support as
modules (M).
Turn on the joystick type, in our case 'Gravis GrIP' as a module (M).
(I'm told by Geoff Reidy, to add analog support, select analog
as a module instead)
Compile the kernel and install everything.

The 1.2.15 joy-gravis.c file in the 2.2.x kernel series (certainly
as recently as 2.2.20 pre 3) could give some problems (not at the
stage) but if failure occurs, try editting joy-gravis.c with the
patch from Vojtech Pavlik:

(NB. If failure occurs, you are liable to see something similar to the
following when the joystick module is loaded:
/lib/modules/2.2.20-pre3/misc/joy-gravis.o:init_module:Device or
resource busy)

Vojtech's patch for joy-gravis.c

Change lines 132 and 138 from:
p = t = (p - t) << 2;

to become:


Compiling for 2.4 kernels

Building for early 2.4.x kernels (roughly 2.4.0 to 2.4.2)

Initial note: Unless you have a compelling reason, I'd suggest
an upgrade to kernel version 2.4.10 or later....

In the 'Input Core Support' section, build in (*) the Input Core
Support. Add modular (M) support for Joystick and Event Interface

In the 'Character Devices' section, select 'Joystick support' as a
built in (*) and in the gameport support subsection of this,
activate modular (M) support for ns558 gameports. (This is necessary
so that the soundcard's gameport is operational).

Below this in 'game port joysticks', select the required joystick
(Gravis GrIP joysticks and gamepads, in my case) and build it as a
module (M).

Building for the current 2.4 kernel (2.4.10 and later)

See the section:
6) Recent Kernel 2.4 Joystick Updates (2.4.10 onwards)

2) Getting the joystick support loaded and in use once compiled

Again because of the differences between the kernels, different
are needed:

You will need to run these commands as root, but can log off from root

Kernel 2.2

For 2.2, I use the following commands:

rmmod es1371
modprobe es1371 joystick=0x200
modprobe joy-gravis

This unloads the soundcard, then reloads it again, specifying the
port address the joystick driver should connect to.

(According to Geoff Reidy, the process for analog joysticks is exactly
the same, but do a modprobe joy-analog instead)

Kernel 2.4

For kernels up to 2.4.3 etc

Kernel 2.4 subdivides the joystick support into more subsystems than
2.2 and is thus slightly more long winded to load:

rmmod es1371
modprobe es1371 joystick=0x200
modprobe joydev
modprobe ns558
modprobe grip

This reloads the soundcard (as for kernel 2.2), then loads the
joystick support, the gameport support (ns558) and finally the specific
joystick driver for my Gravis joystick (grip)

NOTE 1: It's possible to simplify this arrangement by telling the
soundcard where to find the joystick gameport immediately (preventing the need
to do the unload and reload seen above). For my es1371 card, this was
achieved by adding another line to /etc/modules.conf:
options es1371 joystick=0x200

NOTE 2: For kernels 2.4.10 and later, try:
(the ns558 module is replaced by the gameport module in such newer kernels)
(by the way, on my system, modprobe'ing es1371 autoloaded gameport, but
I *HAD* to modprobe input specifically).

They were tried with success with kernel 2.4.10 final with and without
devfs under Mandrake Linux 8.1 (final). NB. For once, Mandrake's standard
kernel also seems to handle joysticks well in Mandrake 8.1

rmmod es1371
rmmod gameport
modprobe es1371 joystick=0x200
modprobe input
modprobe joydev
modprobe grip

3) How to see whether joystick support seems to be loaded ok

It can be helpful to see what modules are loaded. To do this you need
to run lsmod as root. NOTE: These lsmod results are based on Mike Diack
running these tests for his SB PCI 128 soundcard and Gravis XTerminator

Under kernel 2.4.9 and earlier you'd expect to see the following modules loaded
(amongst others) for joystick support:

gameport   (used by grip and ns558)

Under kernel 2.4.10 (?and later?) you'd expect to see the following modules
loaded (amongst others) for joystick support:

The output of an lsmod (cropped to just include soundcard and
joystick related modules) for a SB PCI 128 soundcard and Gravis
Xterminator joystick (grip driver)

NOTE: Soundcard modules are: es1371, ac97_codec, soundcore

Module                  Size  Used by
grip                    3872   0  (unused)
joydev                  5744   0  (unused)
input                   3424   0  [grip joydev]
es1371                 26496   0  (unused)
gameport                1552   0  [grip es1371]
soundcore               3664   4  [es1371]
ac97_codec              9376   0  [es1371]

Under kernel 2.2.x you'd expect to see the following modules loaded
(amongst others) for joystick support:

joy-gravis         (OR: joy-analog etc!)
joystick   (used by joy-gravis)

You can also look at the boot messages (via dmesg):

Under kernel 2.2.x look for something like:

js:Joystick driver v1.2.15 (c) 1999 Vojtech Pavlik
js0: Gravis Xterminator at 0x201

Under kernel 2.4.x look for something like:
input0: Gravis Xterminator Digital on gameport 0.0

4) The /dev file settings required by the joysticks

Kernel 2.2 and 2.4 both use different device files for the kernel
to use for interfacing the joystick device drivers. They use different
device filenames and device numbers (note: these are device numbers,
not file names).

Kernel 2.2 uses device files: /dev/js0, /dev/js1, /dev/js2, /dev/js3

Kernel 2.4 uses device files: /dev/input/js0, /dev/input/js1 .....
up to /dev/input/js9

0 is the first joystick.

Kernel 2.2 uses device number 15, where as Kernel 2.4 uses device
number 13.

As examples, doing an ls -l might show the following:

On a 2.2 system:

crw------- 1 mike root 15, 0 Sep 27 11:31 js0

On a 2.4 system

crw-rw---- 1 mike root 13, 0 Sep 27 11:31 js0

A hint here, if you run into problems, it may be worth changing the
of the device files to be owned by you rather than root.


The following is taken from the kernel source joystick.txt file and is
written for the 2.4 kernel (note however that the use of symbolic
to /dev/js0 etc renders the use of such a set of device files in
with the 2.2 kernel (due to the differing major device numbers):

For applications to be able to use the joysticks, in you don't use
devfs, you'll have to manually create these nodes in /dev:

cd /dev
rm js*
mkdir input
mknod input/js0 c 13 0
mknod input/js1 c 13 1
mknod input/js2 c 13 2
mknod input/js3 c 13 3
ln -s input/js0 js0
ln -s input/js1 js1
ln -s input/js2 js2
ln -s input/js3 js3

For testing with inpututils it's also convenient to create these:

mknod input/event0 c 13 64
mknod input/event1 c 13 65
mknod input/event2 c 13 66
mknod input/event3 c 13 67

Currently, I've had some success with Mandrake 8.1, which allows
devfs support to be activated at boot time (LILO parameter), running
both with and without devfs. Mandrake 8.1 claims to be the first
distribution that is using devfs by default.

5) Miscellaneous info/hints/tips

Q: I can't get the joystick support to load once compiled:
A: Check that your device settings look sane (see section 4), then try
   reloading the modules (section 2).

Q: How to get my joystick working under XMAME, the emulator?
A: Ensure that you set the appropriate options in the XMAME makefile.
   Kernel 2.2 joystick support should work well, but if you are
   running a Kernel 2.4 system, you will need to get a new (c. version 0.37
   beta 13 ish) or newer version of Xmame, which allows you to use a command line
   specifier to tell MAME which device file is used for the joysticks.
   (By default MAME looks for the joysticks in the 2.2 kernel

Q: I've noticed an oddity with joystick support in XMAME whereby joystick
   axes don't work the first time you start XMame per session, but are fine
A: Upgrade to the newest joystick drivers, 2.4.10 etc, the problem is gone
   in these (reason for it was unknown).

6) Recent Kernel 2.4 Joystick Updates (2.4.10 onwards)

The changes to joystick support introduced around about Alan Cox's
kernel 2.4.5ac8 to address some of the problems that got introduced
in the kernel around version 2.4.3, were merged in late Sept 2001
back into the main 2.4.x kernel as of version 2.4.10 final.

Thus previous recommendations in this document to use Alan's
patches are now obsolete, providing you are using kernel 2.4.10
(or later) as I'd recommend.

These necessitate (at least in my case), the following compilation
steps if you are to compile kernel 2.4.10 or later, rather than
an earlier 2.4.x kernel

NB That said, 2.4.10 final kernel has problems with analog joysticks,
which Alan Cox is addressing in his 2.4.10-ac kernel tree.

In the 'make menuconfig' stage of kernel settings configuration, I
the following steps for my PB PCI 128 and GRIP joystick.

a) Turn on input core support as a built in (*)
b) Add modular (M) joystick support
c) Add modular (M) event support
d) In the character devices, section for joysticks, select gameport
   as a module (M)
e) Select the specific gameport required (in my case, 'Classic ISA/PnP
   and select this as a module (M) also.
f) Select the required joystick support (in my case, 'Gravis GrIP') as
a module (M)
g) Build the kernel and modules.

Status of the most recent 2.4.x kernels wih respect to joysticks

2.4.10 - Seems good, but there are apparently problems with the analog driver
2.4.11 - Seems good - BUT DON'T USE - has a symlink bug, capable of file damage
2.4.12 - Won't compile without a patch for parport(!). Also on my Gravis GRIP
         based system - the joystick always veers left (avoid).
2.4.13pre - Based on my checks of 2.4.13 pre 4, this looks good. All of the recent
            bugfixes of 2.4.11/12 and the gravis support is working again.