diff options
author | imp <imp@FreeBSD.org> | 2001-12-05 09:08:23 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2001-12-05 09:08:23 +0000 |
commit | c2b70c92371ece231b5d2030bfd73468f2bf449a (patch) | |
tree | cbc178e54a7a0885bb00ddf5752118e43c8d7469 | |
parent | 245b70f5f23c00c22be16d3394387fef335178c3 (diff) | |
download | FreeBSD-src-c2b70c92371ece231b5d2030bfd73468f2bf449a.zip FreeBSD-src-c2b70c92371ece231b5d2030bfd73468f2bf449a.tar.gz |
Split joystick driver into ISA and PC Card front ends.
Similar code was submitted in PR 5559 by Takeshi OHASHI-san, but the
PC Card system has changed much since then, so this is a fresh
implementation.
PR: i386/5559
Submitted by: Takeshi OHASHI
-rw-r--r-- | sys/dev/joy/joy.c | 270 | ||||
-rw-r--r-- | sys/dev/joy/joy_isa.c | 83 | ||||
-rw-r--r-- | sys/dev/joy/joy_pccard.c | 72 | ||||
-rw-r--r-- | sys/dev/joy/joyvar.h | 45 |
4 files changed, 322 insertions, 148 deletions
diff --git a/sys/dev/joy/joy.c b/sys/dev/joy/joy.c index 0f3f11d..967e6bd 100644 --- a/sys/dev/joy/joy.c +++ b/sys/dev/joy/joy.c @@ -40,9 +40,7 @@ #include <sys/rman.h> #include <sys/time.h> #include <sys/joystick.h> - -#include <isa/isavar.h> -#include "isa_if.h" +#include <dev/joy/joyvar.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. @@ -60,19 +58,9 @@ #define JOY_TIMEOUT 2000 /* 2 milliseconds */ #endif -struct joy_softc { - bus_space_tag_t bt; - bus_space_handle_t port; - int x_off[2], y_off[2]; - int timeout[2]; -}; - #define JOY_SOFTC(unit) (struct joy_softc *) \ devclass_get_softc(joy_devclass,(unit)) -static int joy_probe (device_t); -static int joy_attach (device_t); - #define CDEV_MAJOR 51 static d_open_t joyopen; static d_close_t joyclose; @@ -97,179 +85,165 @@ static struct cdevsw joy_cdevsw = { devclass_t joy_devclass; -static struct isa_pnp_id joy_ids[] = { - {0x0100630e, "CSC0001 PnP Joystick"}, /* CSC0001 */ - {0x0101630e, "CSC0101 PnP Joystick"}, /* CSC0101 */ - {0x01100002, "ALS0110 PnP Joystick"}, /* @P@1001 */ - {0x01200002, "ALS0120 PnP Joystick"}, /* @P@2001 */ - {0x01007316, "ESS0001 PnP Joystick"}, /* ESS0001 */ - {0x2fb0d041, "Generic PnP Joystick"}, /* PNPb02f */ - {0x2200a865, "YMH0022 PnP Joystick"}, /* YMH0022 */ - {0x82719304, NULL}, /* ADS7182 */ - {0} -}; - -static int -joy_probe (device_t dev) +int +joy_probe(device_t dev) { - if (ISA_PNP_PROBE(device_get_parent(dev), dev, joy_ids) == ENXIO) - return ENXIO; #ifdef WANT_JOYSTICK_CONNECTED #ifdef notyet - outb (dev->id_iobase, 0xff); - DELAY (10000); /* 10 ms delay */ - return (inb (dev->id_iobase) & 0x0f) != 0x0f; + outb(dev->id_iobase, 0xff); + DELAY(10000); /* 10 ms delay */ + return (inb(dev->id_iobase) & 0x0f) != 0x0f; +#else + return (0); #endif #else - return 0; + return (0); #endif } -static int -joy_attach (device_t dev) +int +joy_attach(device_t dev) { - int unit = device_get_unit(dev); - int rid = 0; - 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); - 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); - return 0; + int unit = device_get_unit(dev); + struct joy_softc *joy = device_get_softc(dev); + + joy->rid = 0; + joy->res = bus_alloc_resource(dev, SYS_RES_IOPORT, &joy->rid, 0, ~0, 1, + RF_ACTIVE); + if (joy->res == NULL) + return ENXIO; + joy->bt = rman_get_bustag(joy->res); + joy->port = rman_get_bushandle(joy->res); + joy->timeout[0] = joy->timeout[1] = 0; + joy->d = make_dev(&joy_cdevsw, 0, 0, 0, 0600, "joy%d", unit); + return (0); } -static device_method_t joy_methods[] = { - DEVMETHOD(device_probe, joy_probe), - DEVMETHOD(device_attach, joy_attach), - { 0, 0 } -}; +int +joy_detach(device_t dev) +{ + struct joy_softc *joy = device_get_softc(dev); -static driver_t joy_isa_driver = { - "joy", - joy_methods, - sizeof (struct joy_softc) -}; + if (joy->res != NULL) + bus_release_resource(dev, SYS_RES_IOPORT, joy->rid, joy->res); + if (joy->d) + destroy_dev(joy->d); + return (0); +} -DRIVER_MODULE(joy, isa, joy_isa_driver, joy_devclass, 0, 0); -DRIVER_MODULE(joy, acpi, joy_isa_driver, joy_devclass, 0, 0); static int joyopen(dev_t dev, int flags, int fmt, struct thread *td) { - int i = joypart (dev); - struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); - - if (joy->timeout[i]) - return EBUSY; - joy->x_off[i] = joy->y_off[i] = 0; - joy->timeout[i] = JOY_TIMEOUT; - return 0; + int i = joypart (dev); + struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); + + if (joy->timeout[i]) + return (EBUSY); + joy->x_off[i] = joy->y_off[i] = 0; + joy->timeout[i] = JOY_TIMEOUT; + return (0); } static int joyclose(dev_t dev, int flags, int fmt, struct thread *td) { - int i = joypart (dev); - struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); + int i = joypart (dev); + struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); - joy->timeout[i] = 0; - return 0; + joy->timeout[i] = 0; + return (0); } static int joyread(dev_t dev, struct uio *uio, int flag) { - struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); - bus_space_handle_t port = joy->port; - bus_space_tag_t bt = joy->bt; - struct timespec t, start, end; - int state = 0; - struct timespec x, y; - struct joystick c; + struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); + bus_space_handle_t port = joy->port; + bus_space_tag_t bt = joy->bt; + struct timespec t, start, end; + int state = 0; + struct timespec x, y; + struct joystick c; #ifndef i386 - int s; + int s; - s = splhigh(); + s = splhigh(); #else - disable_intr (); + disable_intr (); #endif - bus_space_write_1 (bt, port, 0, 0xff); - nanotime(&start); - end.tv_sec = 0; - end.tv_nsec = joy->timeout[joypart(dev)] * 1000; - timespecadd(&end, &start); - t = start; - timespecclear(&x); - timespecclear(&y); - while (timespeccmp(&t, &end, <)) { - state = bus_space_read_1 (bt, port, 0); - if (joypart(dev) == 1) - state >>= 2; - nanotime(&t); - if (!timespecisset(&x) && !(state & 0x01)) - x = t; - if (!timespecisset(&y) && !(state & 0x02)) - y = t; - if (timespecisset(&x) && timespecisset(&y)) - break; - } + bus_space_write_1 (bt, port, 0, 0xff); + nanotime(&start); + end.tv_sec = 0; + end.tv_nsec = joy->timeout[joypart(dev)] * 1000; + timespecadd(&end, &start); + t = start; + timespecclear(&x); + timespecclear(&y); + while (timespeccmp(&t, &end, <)) { + state = bus_space_read_1 (bt, port, 0); + if (joypart(dev) == 1) + state >>= 2; + nanotime(&t); + if (!timespecisset(&x) && !(state & 0x01)) + x = t; + if (!timespecisset(&y) && !(state & 0x02)) + y = t; + if (timespecisset(&x) && timespecisset(&y)) + break; + } #ifndef i386 - splx(s); + splx(s); #else - enable_intr (); + enable_intr (); #endif - if (timespecisset(&x)) { - timespecsub(&x, &start); - c.x = joy->x_off[joypart(dev)] + x.tv_nsec / 1000; - } else - c.x = 0x80000000; - if (timespecisset(&y)) { - timespecsub(&y, &start); - c.y = joy->y_off[joypart(dev)] + y.tv_nsec / 1000; - } else - c.y = 0x80000000; - state >>= 4; - c.b1 = ~state & 1; - c.b2 = ~(state >> 1) & 1; - return uiomove ((caddr_t)&c, sizeof(struct joystick), uio); + if (timespecisset(&x)) { + timespecsub(&x, &start); + c.x = joy->x_off[joypart(dev)] + x.tv_nsec / 1000; + } else + c.x = 0x80000000; + if (timespecisset(&y)) { + timespecsub(&y, &start); + c.y = joy->y_off[joypart(dev)] + y.tv_nsec / 1000; + } else + c.y = 0x80000000; + state >>= 4; + c.b1 = ~state & 1; + c.b2 = ~(state >> 1) & 1; + return (uiomove((caddr_t)&c, sizeof(struct joystick), uio)); } static int joyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td) { - struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); - int i = joypart (dev); - int x; - - switch (cmd) { - case JOY_SETTIMEOUT: - x = *(int *) data; - if (x < 1 || x > 10000) /* 10ms maximum! */ - return EINVAL; - joy->timeout[i] = x; - break; - case JOY_GETTIMEOUT: - *(int *) data = joy->timeout[i]; - break; - case JOY_SET_X_OFFSET: - joy->x_off[i] = *(int *) data; - break; - case JOY_SET_Y_OFFSET: - joy->y_off[i] = *(int *) data; - break; - case JOY_GET_X_OFFSET: - *(int *) data = joy->x_off[i]; - break; - case JOY_GET_Y_OFFSET: - *(int *) data = joy->y_off[i]; - break; - default: - return ENXIO; - } - return 0; + struct joy_softc *joy = JOY_SOFTC(UNIT(dev)); + int i = joypart (dev); + int x; + + switch (cmd) { + case JOY_SETTIMEOUT: + x = *(int *) data; + if (x < 1 || x > 10000) /* 10ms maximum! */ + return EINVAL; + joy->timeout[i] = x; + break; + case JOY_GETTIMEOUT: + *(int *) data = joy->timeout[i]; + break; + case JOY_SET_X_OFFSET: + joy->x_off[i] = *(int *) data; + break; + case JOY_SET_Y_OFFSET: + joy->y_off[i] = *(int *) data; + break; + case JOY_GET_X_OFFSET: + *(int *) data = joy->x_off[i]; + break; + case JOY_GET_Y_OFFSET: + *(int *) data = joy->y_off[i]; + break; + default: + return (ENOTTY); + } + return (0); } diff --git a/sys/dev/joy/joy_isa.c b/sys/dev/joy/joy_isa.c new file mode 100644 index 0000000..c45c7a2 --- /dev/null +++ b/sys/dev/joy/joy_isa.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * 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. + * + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/conf.h> +#include <sys/uio.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/bus.h> +#include <machine/bus.h> +#include <machine/resource.h> +#include <sys/rman.h> +#include <sys/time.h> +#include <dev/joy/joyvar.h> + +#include <isa/isavar.h> +#include "isa_if.h" + +static int joy_isa_probe (device_t); + +static struct isa_pnp_id joy_ids[] = { + {0x0100630e, "CSC0001 PnP Joystick"}, /* CSC0001 */ + {0x0101630e, "CSC0101 PnP Joystick"}, /* CSC0101 */ + {0x01100002, "ALS0110 PnP Joystick"}, /* @P@1001 */ + {0x01200002, "ALS0120 PnP Joystick"}, /* @P@2001 */ + {0x01007316, "ESS0001 PnP Joystick"}, /* ESS0001 */ + {0x2fb0d041, "Generic PnP Joystick"}, /* PNPb02f */ + {0x2200a865, "YMH0022 PnP Joystick"}, /* YMH0022 */ + {0x82719304, NULL}, /* ADS7182 */ + {0} +}; + +static int +joy_isa_probe(device_t dev) +{ + if (ISA_PNP_PROBE(device_get_parent(dev), dev, joy_ids) == ENXIO) + return ENXIO; + return (joy_probe(dev)); +} + +static device_method_t joy_methods[] = { + DEVMETHOD(device_probe, joy_isa_probe), + DEVMETHOD(device_attach, joy_attach), + DEVMETHOD(device_detach, joy_detach), + { 0, 0 } +}; + +static driver_t joy_isa_driver = { + "joy", + joy_methods, + sizeof (struct joy_softc) +}; + +DRIVER_MODULE(joy, isa, joy_isa_driver, joy_devclass, 0, 0); +DRIVER_MODULE(joy, acpi, joy_isa_driver, joy_devclass, 0, 0); diff --git a/sys/dev/joy/joy_pccard.c b/sys/dev/joy/joy_pccard.c new file mode 100644 index 0000000..45f94a8 --- /dev/null +++ b/sys/dev/joy/joy_pccard.c @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * 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. + * + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/bus.h> +#include <machine/bus.h> +#include <machine/resource.h> +#include <sys/rman.h> +#include <dev/joy/joyvar.h> + +#include <dev/pccard/pccardreg.h> +#include <dev/pccard/pccardvar.h> +#include <dev/pccard/pccarddevs.h> + +static int +joy_pccard_match(device_t dev) +{ + /* For the moment, don't match anything :-) */ + + return(ENXIO); +} + +static device_method_t joy_pccard_methods[] = { + DEVMETHOD(device_probe, pccard_compat_probe), + DEVMETHOD(device_attach, pccard_compat_attach), + DEVMETHOD(device_detach, joy_detach), + + /* Card interface */ + DEVMETHOD(card_compat_match, joy_pccard_match), + DEVMETHOD(card_compat_probe, joy_probe), + DEVMETHOD(card_compat_attach, joy_attach), + + { 0, 0 } +}; + +static driver_t joy_pccard_driver = { + "joy", + joy_pccard_methods, + sizeof (struct joy_softc) +}; + +DRIVER_MODULE(joy, pccard, joy_pccard_driver, joy_devclass, 0, 0); diff --git a/sys/dev/joy/joyvar.h b/sys/dev/joy/joyvar.h new file mode 100644 index 0000000..cbae134 --- /dev/null +++ b/sys/dev/joy/joyvar.h @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * All rights reserved. + * + * 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. + * + * $FreeBSD$ + */ + +struct joy_softc { + bus_space_tag_t bt; + bus_space_handle_t port; + int x_off[2], y_off[2]; + int timeout[2]; + struct resource *res; + int rid; + dev_t d; +}; + +int joy_probe(device_t); +int joy_attach(device_t); +int joy_detach(device_t); + +extern devclass_t joy_devclass; |