Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Dec 2002 19:50:54 +0000
From:      Richard Airlie <kaneda@darq.net>
To:        freebsd-hackers@freebsd.org
Subject:   joystick driver doesn't allow for anything but joy0
Message-ID:  <20021217195054.C10658@phear.darq.net>

next in thread | raw e-mail | index | archive | help

--IS0zKkzwUGydFO0o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,
Recently I have spent some time trying to get my 3-axis 4 button joystick
working in FreeBSD. My joystick is a standard analogue stick, connected to
the game port (ISA 0x201).  I came across a few problems with this
configuration and had to make some changes to get things to work (patch
attached). Essentially I'm looking for any comments on these changes.. is
this a reasonable/useful fix? 

Briefly, the two stumbling blocks I encountered: 
1) It is not possible to have both joy0 and joy1 at port IO_GAME, because
joy_attach() in joy.c calls bus_alloc_resource with RF_ACTIVE. If I change this
to RF_ACTIVE|RF_SHAREABLE then both joy0 and joy1 can share the resource.

2) In joy_attach(), the call to make_dev always uses 0 as the minor device
number, meaning that only joy0 ever gets attached.

The other thing I changed was to wait for the 4 bits corresponding to the 4
joystick axes to go low before starting timing them.. this seemed to be
necessary for me, and I can explain why if anyone is interested.

This patch applies to 4.7-STABLE, though the code in current looks much the
same. I have no previous experience with the FreeBSD kernel.. so it would be
useful to know if these changes are not good :)

regards,
Richard.

--IS0zKkzwUGydFO0o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="joy.c_patch"

--- usr/src/sys/isa/joy.c	Tue Dec 17 10:50:50 2002
+++ /home/kaneda/joy_fix.c	Tue Dec 17 10:52:44 2002
@@ -134,13 +134,13 @@
     struct resource *res;
     struct joy_softc *joy = device_get_softc(dev);
 
-    res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
+    res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE|RF_SHAREABLE);
     if (res == NULL)
         return ENXIO;
     joy->bt = rman_get_bustag(res);
     joy->port = rman_get_bushandle(res);
     joy->timeout[0] = joy->timeout[1] = 0;
-    make_dev(&joy_cdevsw, 0, 0, 0, 0600, "joy%d", unit);
+    make_dev(&joy_cdevsw, unit, 0, 0, 0600, "joy%d", unit);
     return 0;
 }
 
@@ -198,6 +198,12 @@
 #else
     disable_intr ();
 #endif
+    nanotime(&t);
+    end.tv_sec = 0;
+    end.tv_nsec = joy->timeout[joypart(dev)] * 1000;
+    timespecadd(&end, &t);
+    for( ; timespeccmp(&t, &end, <) && (bus_space_read_1(bt, port, 0) & 0x0f); nanotime(&t) );
+
     bus_space_write_1 (bt, port, 0, 0xff);
     nanotime(&start);
     end.tv_sec = 0;

--IS0zKkzwUGydFO0o--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021217195054.C10658>