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