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