gus_isapnp.c revision 1.2 1 #include "guspnp.h"
2 #if NGUSPNP > 0
3
4 /* $NetBSD: gus_isapnp.c,v 1.2 1997/10/09 07:50:22 jtc Exp $ */
5
6 /*
7 * Copyright (c) 1997 The NetBSD Foundation, Inc.
8 * All rights reserved.
9 *
10 * Author: Kari Mettinen
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #include <sys/param.h>
42 #include <sys/fcntl.h>
43 #include <sys/vnode.h>
44 #include <sys/poll.h>
45 #include <sys/malloc.h>
46 #include <sys/select.h>
47 #include <sys/systm.h>
48 #include <sys/errno.h>
49 #include <sys/ioctl.h>
50 #include <sys/syslog.h>
51 #include <sys/device.h>
52 #include <sys/proc.h>
53
54 #include <machine/bus.h>
55
56 #include <sys/audioio.h>
57 #include <dev/audio_if.h>
58 #include <dev/audiovar.h>
59 #include <dev/mulaw.h>
60
61 #include <dev/isa/isavar.h>
62 #include <dev/isa/isadmavar.h>
63 #include <i386/isa/icu.h>
64
65 #include <dev/isapnp/isapnpreg.h>
66 #include <dev/isapnp/isapnpvar.h>
67
68
69 #include <dev/ic/interwavevar.h>
70 #include <dev/ic/interwavereg.h>
71
72
73 int gus_isapnp_match __P((struct device *, void *, void *));
74 void gus_isapnp_attach __P((struct device *, struct device *, void *));
75 static int gus_isapnp_open __P((void *, int));
76
77 static struct audio_hw_if guspnp_hw_if = {
78 gus_isapnp_open,
79 iwclose,
80 NULL,
81
82 iw_query_encoding,
83 iw_set_params,
84
85 iw_round_blocksize,
86
87 iw_set_out_port,
88 iw_get_out_port,
89 iw_set_in_port,
90 iw_get_in_port,
91
92 iw_commit_settings,
93
94 iw_init_output,
95 iw_init_input,
96 iw_start_output,
97 iw_start_input,
98 iw_halt_output,
99 iw_halt_input,
100 iw_cont_output,
101 iw_cont_input,
102
103 iw_speaker_ctl,
104
105 iw_getdev,
106 iw_setfd,
107 iw_set_port,
108 iw_get_port,
109 iw_query_devinfo,
110 iw_malloc,
111 iw_free,
112 iw_round,
113 iw_mappage,
114 iw_get_props,
115 };
116
117
118
119 struct cfattach guspnp_ca = {
120 sizeof(struct iw_softc), gus_isapnp_match, gus_isapnp_attach
121 };
122
123 struct cfdriver guspnp_cd = {
124 NULL, "guspnp", DV_DULL
125 };
126
127
128 /*
129 * Probe / attach routines.
130 */
131
132 /*
133 * Probe for the guspnp hardware.
134 *
135 * The thing has 5 separate devices on the card
136 */
137
138 static int gus_0 = 0; /* XXX what's this */
139
140 int
141 gus_isapnp_match(parent, match, aux)
142 struct device *parent;
143 void *match, *aux;
144 {
145 struct isapnp_attach_args *ipa = aux;
146
147 if (!strcmp(ipa->ipa_devlogic, "GRV0000")) {
148 gus_0 = 1;
149 return 1;
150 /* we'll add support for other logical devices later */
151 }
152 return 0;
153 }
154
155
156
157 /*
158 * Attach hardware to driver, attach hardware driver to audio
159 * pseudo-device driver.
160 */
161
162 static struct iw_softc *gussc;
163
164 void
165 gus_isapnp_attach(parent, self, aux)
166 struct device *parent, *self;
167 void *aux;
168 {
169 struct iw_softc *sc = (struct iw_softc *)self;
170 struct isapnp_attach_args *ipa = aux;
171
172 printf("\n");
173
174 if (!gus_0)
175 return;
176
177 gussc = sc;
178
179 sc->sc_iot = ipa->ipa_iot;
180
181 /* handle is the region base */
182
183 sc->dir_h = 0; /* XXXXX */
184 sc->p2xr = 0;
185 sc->p2xr_h = ipa->ipa_io[0].h;
186 sc->sc_p2xr_ic = ipa->ipa_ic;
187 sc->p3xr = 0;
188 sc->p3xr_h = ipa->ipa_io[1].h;
189 sc->sc_p3xr_ic = ipa->ipa_ic;
190 sc->codec_index = 0;
191 sc->codec_index_h = ipa->ipa_io[2].h;
192 sc->sc_irq = ipa->ipa_irq[0].num;
193 sc->sc_recdrq = ipa->ipa_drq[0].num;
194 sc->sc_playdrq = ipa->ipa_drq[1].num;
195
196 sc->sc_isa = parent->dv_parent;
197
198 /*
199 * Create our DMA maps.
200 */
201 if (sc->sc_playdrq != -1) {
202 if (isa_dmamap_create(sc->sc_isa, sc->sc_playdrq,
203 MAX_ISADMA, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
204 printf("%s: can't create map for drq %d\n",
205 sc->sc_dev.dv_xname, sc->sc_playdrq);
206 return;
207 }
208 }
209 if (sc->sc_recdrq != -1) {
210 if (isa_dmamap_create(sc->sc_isa, sc->sc_recdrq,
211 MAX_ISADMA, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
212 printf("%s: can't create map for drq %d\n",
213 sc->sc_dev.dv_xname, sc->sc_recdrq);
214 return;
215 }
216 }
217
218 /*
219 * isapnp is a child if isa, and we need isa for the dma
220 * routines.
221 */
222 sc->iw_cd = &guspnp_cd;
223 sc->iw_hw_if = &guspnp_hw_if;
224
225 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
226 printf("%s: error in region allocation\n",
227 sc->sc_dev.dv_xname);
228 return;
229 }
230
231 printf("%s: %s %s", sc->sc_dev.dv_xname, ipa->ipa_devident,
232 ipa->ipa_devclass);
233
234 iwattach(sc);
235 }
236
237 static
238 int
239 gus_isapnp_open(addr, flags)
240 void *addr;
241 int flags;
242 {
243 /* open hardware */
244 struct iw_softc *sc = (struct iw_softc *)addr;
245
246 if (!sc)
247 return ENXIO;
248
249 return iwopen(sc,flags);
250 }
251
252 #endif /* NGUSPNP */
253