No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / isa / joy_isa.c
blob3e2461f4e308b160a917817cbf8c553d02bad2e1
1 /* $NetBSD: joy_isa.c,v 1.11 2007/10/19 12:00:20 ad Exp $ */
3 /*-
4 * Copyright (c) 1995 Jean-Marc Zucconi
5 * All rights reserved.
7 * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr>. Additional
8 * modification by Jason R. Thorpe <thorpej@NetBSD.org>.
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
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.
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: joy_isa.c,v 1.11 2007/10/19 12:00:20 ad Exp $");
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/device.h>
43 #include <sys/bus.h>
45 #include <dev/isa/isavar.h>
47 #include <dev/ic/joyvar.h>
49 #define JOY_NPORTS 1
51 static int joy_isa_probe(device_t, cfdata_t, void *);
52 static void joy_isa_attach(device_t, device_t, void *);
54 CFATTACH_DECL_NEW(joy_isa, sizeof(struct joy_softc),
55 joy_isa_probe, joy_isa_attach, NULL, NULL);
57 static int
58 joy_isa_probe(device_t parent, cfdata_t match, void *aux)
60 struct isa_attach_args *ia = aux;
61 bus_space_tag_t iot = ia->ia_iot;
62 bus_space_handle_t ioh;
63 int rval = 0;
65 if (ia->ia_nio < 1)
66 return 0;
68 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
69 return 0;
71 if (bus_space_map(iot, ia->ia_io[0].ir_addr, JOY_NPORTS, 0, &ioh))
72 return 0;
74 #ifdef WANT_JOYSTICK_CONNECTED
75 bus_space_write_1(iot, ioh, 0, 0xff);
76 DELAY(10000); /* 10 ms delay */
77 if ((bus_space_read_1(iot, ioh, 0) & 0x0f) != 0x0f)
78 rval = 1;
79 #else
80 rval = 1;
81 #endif
83 bus_space_unmap(iot, ioh, JOY_NPORTS);
85 if (rval) {
86 ia->ia_nio = 1;
87 ia->ia_io[0].ir_size = JOY_NPORTS;
89 ia->ia_niomem = 0;
90 ia->ia_nirq = 0;
91 ia->ia_ndrq = 0;
93 return rval;
96 static void
97 joy_isa_attach(device_t parent, device_t self, void *aux)
99 struct joy_softc *sc = device_private(self);
100 struct isa_attach_args *ia = aux;
102 aprint_normal("\n");
104 sc->sc_iot = ia->ia_iot;
105 sc->sc_dev = self;
107 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, JOY_NPORTS, 0,
108 &sc->sc_ioh)) {
109 aprint_error_dev(self, "can't map i/o space\n");
110 return;
113 joyattach(sc);