Home | History | Annotate | Line # | Download | only in isa
joy_isa.c revision 1.1.4.3
      1  1.1.4.3  nathanw /*	$NetBSD: joy_isa.c,v 1.1.4.3 2002/10/18 02:42:24 nathanw Exp $	*/
      2  1.1.4.2  nathanw 
      3  1.1.4.2  nathanw /*-
      4  1.1.4.2  nathanw  * Copyright (c) 1995 Jean-Marc Zucconi
      5  1.1.4.2  nathanw  * All rights reserved.
      6  1.1.4.2  nathanw  *
      7  1.1.4.2  nathanw  * Ported to NetBSD by Matthieu Herrb <matthieu (at) laas.fr>.  Additional
      8  1.1.4.2  nathanw  * modification by Jason R. Thorpe <thorpej (at) NetBSD.ORG>.
      9  1.1.4.2  nathanw  *
     10  1.1.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.1.4.2  nathanw  * are met:
     13  1.1.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  nathanw  *    notice, this list of conditions and the following disclaimer
     15  1.1.4.2  nathanw  *    in this position and unchanged.
     16  1.1.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     18  1.1.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     19  1.1.4.2  nathanw  * 3. The name of the author may not be used to endorse or promote products
     20  1.1.4.2  nathanw  *    derived from this software without specific prior written permission
     21  1.1.4.2  nathanw  *
     22  1.1.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1.4.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1.4.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1.4.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1.4.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1.4.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1.4.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1.4.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1.4.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1.4.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1.4.2  nathanw  *
     33  1.1.4.2  nathanw  */
     34  1.1.4.2  nathanw 
     35  1.1.4.2  nathanw #include <sys/cdefs.h>
     36  1.1.4.3  nathanw __KERNEL_RCSID(0, "$NetBSD: joy_isa.c,v 1.1.4.3 2002/10/18 02:42:24 nathanw Exp $");
     37  1.1.4.2  nathanw 
     38  1.1.4.2  nathanw #include <sys/param.h>
     39  1.1.4.2  nathanw #include <sys/systm.h>
     40  1.1.4.2  nathanw #include <sys/kernel.h>
     41  1.1.4.2  nathanw #include <sys/device.h>
     42  1.1.4.2  nathanw 
     43  1.1.4.2  nathanw #include <machine/bus.h>
     44  1.1.4.2  nathanw 
     45  1.1.4.2  nathanw #include <dev/isa/isavar.h>
     46  1.1.4.2  nathanw 
     47  1.1.4.2  nathanw #include <dev/ic/joyvar.h>
     48  1.1.4.2  nathanw 
     49  1.1.4.2  nathanw #define JOY_NPORTS    1
     50  1.1.4.2  nathanw 
     51  1.1.4.2  nathanw int	joy_isa_probe __P((struct device *, struct cfdata *, void *));
     52  1.1.4.2  nathanw void	joy_isa_attach __P((struct device *, struct device *, void *));
     53  1.1.4.2  nathanw 
     54  1.1.4.3  nathanw CFATTACH_DECL(joy_isa, sizeof(struct joy_softc),
     55  1.1.4.3  nathanw     joy_isa_probe, joy_isa_attach, NULL, NULL);
     56  1.1.4.2  nathanw 
     57  1.1.4.2  nathanw int
     58  1.1.4.2  nathanw joy_isa_probe(parent, match, aux)
     59  1.1.4.2  nathanw 	struct device *parent;
     60  1.1.4.2  nathanw 	struct cfdata *match;
     61  1.1.4.2  nathanw 	void *aux;
     62  1.1.4.2  nathanw {
     63  1.1.4.2  nathanw 	struct isa_attach_args *ia = aux;
     64  1.1.4.2  nathanw 	bus_space_tag_t iot = ia->ia_iot;
     65  1.1.4.2  nathanw 	bus_space_handle_t ioh;
     66  1.1.4.2  nathanw 	int rval = 0;
     67  1.1.4.2  nathanw 
     68  1.1.4.2  nathanw 	if (ia->ia_nio < 1)
     69  1.1.4.2  nathanw 		return (0);
     70  1.1.4.2  nathanw 
     71  1.1.4.2  nathanw 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
     72  1.1.4.2  nathanw 		return (0);
     73  1.1.4.2  nathanw 
     74  1.1.4.2  nathanw 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, JOY_NPORTS, 0, &ioh))
     75  1.1.4.2  nathanw 		return (0);
     76  1.1.4.2  nathanw 
     77  1.1.4.2  nathanw #ifdef WANT_JOYSTICK_CONNECTED
     78  1.1.4.2  nathanw 	bus_space_write_1(iot, ioh, 0, 0xff);
     79  1.1.4.2  nathanw 	DELAY(10000);		/* 10 ms delay */
     80  1.1.4.2  nathanw 	if ((bus_space_read_1(iot, ioh, 0) & 0x0f) != 0x0f)
     81  1.1.4.2  nathanw 		rval = 1;
     82  1.1.4.2  nathanw #else
     83  1.1.4.2  nathanw 	rval = 1;
     84  1.1.4.2  nathanw #endif
     85  1.1.4.2  nathanw 
     86  1.1.4.2  nathanw 	bus_space_unmap(iot, ioh, JOY_NPORTS);
     87  1.1.4.2  nathanw 
     88  1.1.4.2  nathanw 	if (rval) {
     89  1.1.4.2  nathanw 		ia->ia_nio = 1;
     90  1.1.4.2  nathanw 		ia->ia_io[0].ir_size = JOY_NPORTS;
     91  1.1.4.2  nathanw 
     92  1.1.4.2  nathanw 		ia->ia_niomem = 0;
     93  1.1.4.2  nathanw 		ia->ia_nirq = 0;
     94  1.1.4.2  nathanw 		ia->ia_ndrq = 0;
     95  1.1.4.2  nathanw 	}
     96  1.1.4.2  nathanw 	return (rval);
     97  1.1.4.2  nathanw }
     98  1.1.4.2  nathanw 
     99  1.1.4.2  nathanw void
    100  1.1.4.2  nathanw joy_isa_attach(parent, self, aux)
    101  1.1.4.2  nathanw 	struct device *parent, *self;
    102  1.1.4.2  nathanw 	void *aux;
    103  1.1.4.2  nathanw {
    104  1.1.4.2  nathanw 	struct joy_softc *sc = (struct joy_softc *) self;
    105  1.1.4.2  nathanw 	struct isa_attach_args *ia = aux;
    106  1.1.4.2  nathanw 
    107  1.1.4.2  nathanw 	printf("\n");
    108  1.1.4.2  nathanw 
    109  1.1.4.2  nathanw 	sc->sc_iot = ia->ia_iot;
    110  1.1.4.2  nathanw 
    111  1.1.4.2  nathanw 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, JOY_NPORTS, 0,
    112  1.1.4.2  nathanw 	    &sc->sc_ioh)) {
    113  1.1.4.2  nathanw 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    114  1.1.4.2  nathanw 		return;
    115  1.1.4.2  nathanw 	}
    116  1.1.4.2  nathanw 
    117  1.1.4.2  nathanw 	joyattach(sc);
    118  1.1.4.2  nathanw }
    119