No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / isa / ess_isa.c
blob4e57ad4a444791b06ffea43625f24ef8181a488e
1 /* $NetBSD: ess_isa.c,v 1.22 2009/05/05 12:07:15 cegger Exp $ */
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams.
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 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: ess_isa.c,v 1.22 2009/05/05 12:07:15 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
39 #include <sys/cpu.h>
40 #include <sys/bus.h>
42 #include <dev/isa/isavar.h>
44 #include <dev/isa/essreg.h>
45 #include <dev/isa/essvar.h>
47 #include "joy_ess.h"
49 #ifdef ESS_ISA_DEBUG
50 #define DPRINTF(x) printf x
51 #else
52 #define DPRINTF(x) {}
53 #endif
55 int ess_isa_probe(device_t, cfdata_t, void *);
56 void ess_isa_attach(device_t, device_t, void *);
58 CFATTACH_DECL(ess_isa, sizeof(struct ess_softc),
59 ess_isa_probe, ess_isa_attach, NULL, NULL);
61 int
62 ess_isa_probe(device_t parent, cfdata_t match, void *aux)
64 int ret;
65 struct isa_attach_args *ia;
66 struct ess_softc probesc, *sc;
68 ia = aux;
69 sc= &probesc;
70 if (ia->ia_nio < 1)
71 return 0;
72 if (ia->ia_nirq < 1)
73 return 0;
74 if (ia->ia_ndrq < 1)
75 return 0;
77 if (ISA_DIRECT_CONFIG(ia))
78 return 0;
80 memset(sc, 0, sizeof *sc);
82 sc->sc_ic = ia->ia_ic;
83 sc->sc_iot = ia->ia_iot;
84 sc->sc_iobase = ia->ia_io[0].ir_addr;
85 if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0,
86 &sc->sc_ioh)) {
87 DPRINTF(("ess_isa_probe: Couldn't map I/O region at %x, "
88 "size %x\n", sc->sc_iobase, ESS_NPORT));
89 return 0;
92 sc->sc_audio1.irq = ia->ia_irq[0].ir_irq;
93 sc->sc_audio1.ist = IST_EDGE;
94 sc->sc_audio1.drq = ia->ia_drq[0].ir_drq;
95 sc->sc_audio2.irq = -1;
96 sc->sc_audio2.drq = (ia->ia_ndrq > 1) ? ia->ia_drq[1].ir_drq : -1;
98 ret = essmatch(sc);
100 bus_space_unmap(sc->sc_iot, sc->sc_ioh, ESS_NPORT);
102 if (ret) {
103 DPRINTF(("ess_isa_probe succeeded (score %d)\n", ret));
104 ia->ia_nio = 1;
105 ia->ia_io[0].ir_size = ESS_NPORT;
107 ia->ia_nirq = 1;
109 if (ia->ia_ndrq > 1 &&
110 ia->ia_drq[1].ir_drq != ISA_UNKNOWN_DRQ)
111 ia->ia_ndrq = 2;
112 else
113 ia->ia_ndrq = 1;
115 ia->ia_niomem = 0;
116 } else
117 DPRINTF(("ess_isa_probe failed\n"));
119 return ret;
122 void
123 ess_isa_attach(device_t parent, device_t self, void *aux)
125 struct ess_softc *sc;
126 struct isa_attach_args *ia;
127 int enablejoy;
129 sc = device_private(self);
130 ia = aux;
131 enablejoy = 0;
133 aprint_naive("\n");
134 aprint_normal("\n");
136 sc->sc_ic = ia->ia_ic;
137 sc->sc_iot = ia->ia_iot;
138 sc->sc_iobase = ia->ia_io[0].ir_addr;
139 if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0,
140 &sc->sc_ioh)) {
141 DPRINTF(("ess_isa_attach: Couldn't map I/O region at %x, "
142 "size %x\n", sc->sc_iobase, ESS_NPORT));
143 return;
146 sc->sc_audio1.irq = ia->ia_irq[0].ir_irq;
147 sc->sc_audio1.ist = IST_EDGE;
148 sc->sc_audio1.drq = ia->ia_drq[0].ir_drq;
149 sc->sc_audio2.irq = -1;
150 sc->sc_audio2.drq = ia->ia_ndrq > 1 ? ia->ia_drq[1].ir_drq : -1;
152 #if NJOY_ESS > 0
153 if (device_cfdata(self)->cf_flags & 1) {
154 sc->sc_joy_iot = ia->ia_iot;
155 if (!bus_space_map(sc->sc_joy_iot, 0x201, 1, 0,
156 &sc->sc_joy_ioh))
157 enablejoy = 1;
159 #endif
161 aprint_normal_dev(self, "");
163 essattach(sc, enablejoy);