diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-06-02 18:46:38 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-06-02 18:46:38 +0000 |
commit | affd68ab87952b3348adfda93dd8d7eff067cd6b (patch) | |
tree | 644021bfd29567d39c933a34a0cc0a76e08574ba /sys/arch/i386/isa | |
parent | eecbed65eb0e5455c06818223d7b571108327990 (diff) |
untested isapnp joystick driver
Diffstat (limited to 'sys/arch/i386/isa')
-rw-r--r-- | sys/arch/i386/isa/joy.c | 89 | ||||
-rw-r--r-- | sys/arch/i386/isa/joy_isa.c | 92 | ||||
-rw-r--r-- | sys/arch/i386/isa/joy_isapnp.c | 81 | ||||
-rw-r--r-- | sys/arch/i386/isa/joyreg.h | 69 |
4 files changed, 247 insertions, 84 deletions
diff --git a/sys/arch/i386/isa/joy.c b/sys/arch/i386/isa/joy.c index dc4196591b2..641ec0fc09f 100644 --- a/sys/arch/i386/isa/joy.c +++ b/sys/arch/i386/isa/joy.c @@ -46,93 +46,14 @@ #include <dev/isa/isavar.h> #include <dev/isa/isareg.h> #include <i386/isa/timerreg.h> +#include <i386/isa/joyreg.h> - -/* - * The game port can manage 4 buttons and 4 variable resistors (usually 2 - * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201. - * Getting the state of the buttons is done by reading the game port; - * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2) - * to bits 0-3. If button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5, - * 6, 7) is set to 0 to get the value of a resistor, write the value 0xff - * at port and wait until the corresponding bit returns to 0. - */ - -/* - * The formulae below only work if u is ``not too large''. See also - * the discussion in microtime.s - */ -#define USEC2TICKS(u) (((u) * 19549) >> 14) -#define TICKS2USEC(u) (((u) * 3433) >> 12) - - -#define JOYPART(d) (minor(d) & 1) -#define JOYUNIT(d) minor(d) >> 1 & 3 - -#ifndef JOY_TIMEOUT -#define JOY_TIMEOUT 2000 /* 2 milliseconds */ -#endif - -#define JOY_NPORTS 1 - -struct joy_softc { - struct device sc_dev; - int port; - int x_off[2], y_off[2]; - int timeout[2]; -}; - -int joyprobe __P((struct device *, void *, void *)); -void joyattach __P((struct device *, struct device *, void *)); -int joyopen __P((dev_t, int, int, struct proc *)); -int joyclose __P((dev_t, int, int, struct proc *)); -static int get_tick __P((void)); - -struct cfattach joy_ca = { - sizeof(struct joy_softc), joyprobe, joyattach -}; +static int joy_get_tick __P((void)); struct cfdriver joy_cd = { NULL, "joy", DV_DULL }; - -int -joyprobe(parent, match, aux) - struct device *parent; - void *match, *aux; -{ - struct isa_attach_args *ia = aux; -#ifdef WANT_JOYSTICK_CONNECTED - int iobase = ia->ia_iobase; - - outb(iobase, 0xff); - DELAY(10000); /* 10 ms delay */ - return (inb(iobase) & 0x0f) != 0x0f; -#else - ia->ia_iosize = JOY_NPORTS; - ia->ia_msize = 0; - return 1; -#endif -} - -void -joyattach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct joy_softc *sc = (void *) self; - struct isa_attach_args *ia = aux; - int iobase = ia->ia_iobase; - - sc->port = iobase; - sc->timeout[0] = sc->timeout[1] = 0; - outb(iobase, 0xff); - DELAY(10000); /* 10 ms delay */ - printf(": joystick%sconnected\n", - (inb(iobase) & 0x0f) == 0x0f ? " not " : " "); -} - int joyopen(dev, flag, mode, p) dev_t dev; @@ -185,14 +106,14 @@ joyread(dev, uio, flag) disable_intr(); outb(port, 0xff); - t0 = get_tick(); + t0 = joy_get_tick(); t1 = t0; i = USEC2TICKS(sc->timeout[JOYPART(dev)]); while (t0 - t1 < i) { state = inb(port); if (JOYPART(dev) == 1) state >>= 2; - t1 = get_tick(); + t1 = joy_get_tick(); if (t1 > t0) t1 -= TIMER_FREQ / hz; if (!x && !(state & 0x01)) @@ -253,7 +174,7 @@ joyioctl(dev, cmd, data, flag, p) } static int -get_tick() +joy_get_tick() { int low, high; diff --git a/sys/arch/i386/isa/joy_isa.c b/sys/arch/i386/isa/joy_isa.c new file mode 100644 index 00000000000..773ed7404a2 --- /dev/null +++ b/sys/arch/i386/isa/joy_isa.c @@ -0,0 +1,92 @@ +/* $NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp $ */ + +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/device.h> +#include <sys/errno.h> + +#include <machine/cpu.h> +#include <machine/pio.h> +#include <machine/cpufunc.h> +#include <machine/joystick.h> +#include <machine/conf.h> + +#include <dev/isa/isavar.h> +#include <dev/isa/isareg.h> +#include <i386/isa/timerreg.h> +#include <i386/isa/joyreg.h> + +int joy_isa_probe __P((struct device *, void *, void *)); +void joy_isa_attach __P((struct device *, struct device *, void *)); + +struct cfattach joy_isa_ca = { + sizeof(struct joy_softc), joy_isa_probe, joy_isa_attach +}; + +int +joy_isa_probe(parent, match, aux) + struct device *parent; + void *match, *aux; +{ + struct isa_attach_args *ia = aux; +#ifdef WANT_JOYSTICK_CONNECTED + int iobase = ia->ia_iobase; + + outb(iobase, 0xff); + DELAY(10000); /* 10 ms delay */ + return (inb(iobase) & 0x0f) != 0x0f; +#else + ia->ia_iosize = JOY_NPORTS; + ia->ia_msize = 0; + return 1; +#endif +} + +void +joy_isa_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct joy_softc *sc = (void *) self; + struct isa_attach_args *ia = aux; + int iobase = ia->ia_iobase; + + sc->port = iobase; + sc->timeout[0] = sc->timeout[1] = 0; + outb(iobase, 0xff); + DELAY(10000); /* 10 ms delay */ + printf(": joystick%sconnected\n", + (inb(iobase) & 0x0f) == 0x0f ? " not " : " "); +} diff --git a/sys/arch/i386/isa/joy_isapnp.c b/sys/arch/i386/isa/joy_isapnp.c new file mode 100644 index 00000000000..b343150e716 --- /dev/null +++ b/sys/arch/i386/isa/joy_isapnp.c @@ -0,0 +1,81 @@ +/* $NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp $ */ + +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/device.h> +#include <sys/errno.h> + +#include <machine/cpu.h> +#include <machine/pio.h> +#include <machine/cpufunc.h> +#include <machine/joystick.h> +#include <machine/conf.h> + +#include <dev/isa/isavar.h> +#include <dev/isa/isareg.h> +#include <i386/isa/timerreg.h> +#include <i386/isa/joyreg.h> + +int joy_isapnp_probe __P((struct device *, void *, void *)); +void joy_isapnp_attach __P((struct device *, struct device *, void *)); + +struct cfattach joy_isapnp_ca = { + sizeof(struct joy_softc), joy_isapnp_probe, joy_isapnp_attach +}; + +int +joy_isapnp_probe(parent, match, aux) + struct device *parent; + void *match, *aux; +{ + return (1); +} + +void +joy_isapnp_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct joy_softc *sc = (void *) self; + struct isa_attach_args *ia = aux; + int iobase = ia->ipa_io[0].base; + + sc->port = iobase; + sc->timeout[0] = sc->timeout[1] = 0; + outb(iobase, 0xff); + DELAY(10000); /* 10 ms delay */ + printf(": joystick%sconnected\n", + (inb(iobase) & 0x0f) == 0x0f ? " not " : " "); +} diff --git a/sys/arch/i386/isa/joyreg.h b/sys/arch/i386/isa/joyreg.h new file mode 100644 index 00000000000..fbd2bf6b003 --- /dev/null +++ b/sys/arch/i386/isa/joyreg.h @@ -0,0 +1,69 @@ +/* $NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp $ */ + +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + * The game port can manage 4 buttons and 4 variable resistors (usually 2 + * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201. + * Getting the state of the buttons is done by reading the game port; + * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2) + * to bits 0-3. If button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5, + * 6, 7) is set to 0 to get the value of a resistor, write the value 0xff + * at port and wait until the corresponding bit returns to 0. + */ + +/* + * The formulae below only work if u is ``not too large''. See also + * the discussion in microtime.s + */ +#define USEC2TICKS(u) (((u) * 19549) >> 14) +#define TICKS2USEC(u) (((u) * 3433) >> 12) + + +#define JOYPART(d) (minor(d) & 1) +#define JOYUNIT(d) minor(d) >> 1 & 3 + +#ifndef JOY_TIMEOUT +#define JOY_TIMEOUT 2000 /* 2 milliseconds */ +#endif + +#define JOY_NPORTS 1 + +struct joy_softc { + struct device sc_dev; + int port; + int x_off[2], y_off[2]; + int timeout[2]; +}; + +int joyopen __P((dev_t, int, int, struct proc *)); +int joyclose __P((dev_t, int, int, struct proc *)); |