1 /* $NetBSD: ess_isa.c,v 1.24 2010/05/22 16:35:00 tsutsui Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams.
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 * 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.
18 *
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.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: ess_isa.c,v 1.24 2010/05/22 16:35:00 tsutsui Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38
39 #include <sys/cpu.h>
40 #include <sys/bus.h>
41
42 #include <dev/isa/isavar.h>
43
44 #include <dev/isa/essreg.h>
45 #include <dev/isa/essvar.h>
46
47 #include "joy_ess.h"
48
49 #ifdef ESS_ISA_DEBUG
50 #define DPRINTF(x) printf x
51 #else
52 #define DPRINTF(x) {}
53 #endif
54
55 int ess_isa_probe(device_t, cfdata_t, void *);
56 void ess_isa_attach(device_t, device_t, void *);
57
58 CFATTACH_DECL_NEW(ess_isa, sizeof(struct ess_softc),
59 ess_isa_probe, ess_isa_attach, NULL, NULL);
60
61 int
ess_isa_probe(device_t parent,cfdata_t match,void * aux)62 ess_isa_probe(device_t parent, cfdata_t match, void *aux)
63 {
64 int ret;
65 struct isa_attach_args *ia;
66 struct ess_softc probesc, *sc;
67
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;
76
77 if (ISA_DIRECT_CONFIG(ia))
78 return 0;
79
80 memset(sc, 0, sizeof *sc);
81
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;
90 }
91
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;
97
98 ret = essmatch(sc);
99
100 bus_space_unmap(sc->sc_iot, sc->sc_ioh, ESS_NPORT);
101
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;
106
107 ia->ia_nirq = 1;
108
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;
114
115 ia->ia_niomem = 0;
116 } else
117 DPRINTF(("ess_isa_probe failed\n"));
118
119 return ret;
120 }
121
122 void
ess_isa_attach(device_t parent,device_t self,void * aux)123 ess_isa_attach(device_t parent, device_t self, void *aux)
124 {
125 struct ess_softc *sc;
126 struct isa_attach_args *ia;
127 int enablejoy;
128
129 sc = device_private(self);
130
131 sc->sc_dev = self;
132 ia = aux;
133 enablejoy = 0;
134
135 aprint_naive("\n");
136 aprint_normal("\n");
137
138 sc->sc_ic = ia->ia_ic;
139 sc->sc_iot = ia->ia_iot;
140 sc->sc_iobase = ia->ia_io[0].ir_addr;
141 if (bus_space_map(sc->sc_iot, sc->sc_iobase, ESS_NPORT, 0,
142 &sc->sc_ioh)) {
143 DPRINTF(("ess_isa_attach: Couldn't map I/O region at %x, "
144 "size %x\n", sc->sc_iobase, ESS_NPORT));
145 return;
146 }
147
148 sc->sc_audio1.irq = ia->ia_irq[0].ir_irq;
149 sc->sc_audio1.ist = IST_EDGE;
150 sc->sc_audio1.drq = ia->ia_drq[0].ir_drq;
151 sc->sc_audio2.irq = -1;
152 sc->sc_audio2.drq = ia->ia_ndrq > 1 ? ia->ia_drq[1].ir_drq : -1;
153
154 #if NJOY_ESS > 0
155 if (device_cfdata(self)->cf_flags & 1) {
156 sc->sc_joy_iot = ia->ia_iot;
157 if (!bus_space_map(sc->sc_joy_iot, 0x201, 1, 0,
158 &sc->sc_joy_ioh))
159 enablejoy = 1;
160 }
161 #endif
162
163 aprint_normal_dev(self, "");
164
165 essattach(sc, enablejoy);
166 }
167