gus_isapnp.c revision 1.5 1 #include "guspnp.h"
2 #if NGUSPNP > 0
3
4 /* $NetBSD: gus_isapnp.c,v 1.5 1997/11/30 15:13:31 drochner 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 #ifdef __BROKEN_INDIRECT_CONFIG
74 int gus_isapnp_match __P((struct device *, void *, void *));
75 #else
76 int gus_isapnp_match __P((struct device *, struct cfdata *, void *));
77 #endif
78 void gus_isapnp_attach __P((struct device *, struct device *, void *));
79 static int gus_isapnp_open __P((void *, int));
80
81 static struct audio_hw_if guspnp_hw_if = {
82 gus_isapnp_open,
83 iwclose,
84 NULL,
85
86 iw_query_encoding,
87 iw_set_params,
88
89 iw_round_blocksize,
90
91 iw_commit_settings,
92
93 iw_init_output,
94 iw_init_input,
95 iw_start_output,
96 iw_start_input,
97 iw_halt_output,
98 iw_halt_input,
99
100 iw_speaker_ctl,
101
102 iw_getdev,
103 iw_setfd,
104 iw_set_port,
105 iw_get_port,
106 iw_query_devinfo,
107 iw_malloc,
108 iw_free,
109 iw_round,
110 iw_mappage,
111 iw_get_props,
112 };
113
114
115
116 struct cfattach guspnp_ca = {
117 sizeof(struct iw_softc), gus_isapnp_match, gus_isapnp_attach
118 };
119
120 struct cfdriver guspnp_cd = {
121 NULL, "guspnp", DV_DULL
122 };
123
124
125 /*
126 * Probe / attach routines.
127 */
128
129 /*
130 * Probe for the guspnp hardware.
131 *
132 * The thing has 5 separate devices on the card
133 */
134
135 static int gus_0 = 0; /* XXX what's this */
136
137 int
138 gus_isapnp_match(parent, match, aux)
139 struct device *parent;
140 #ifdef __BROKEN_INDIRECT_CONFIG
141 void *match;
142 #else
143 struct cfdata *match;
144 #endif
145 void *aux;
146 {
147 struct isapnp_attach_args *ipa = aux;
148
149 if (!strcmp(ipa->ipa_devlogic, "GRV0000")) {
150 gus_0 = 1;
151 return 1;
152 /* we'll add support for other logical devices later */
153 }
154 return 0;
155 }
156
157
158
159 /*
160 * Attach hardware to driver, attach hardware driver to audio
161 * pseudo-device driver.
162 */
163
164 static struct iw_softc *gussc;
165
166 void
167 gus_isapnp_attach(parent, self, aux)
168 struct device *parent, *self;
169 void *aux;
170 {
171 struct iw_softc *sc = (struct iw_softc *)self;
172 struct isapnp_attach_args *ipa = aux;
173
174 printf("\n");
175
176 if (!gus_0)
177 return;
178
179 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
180 printf("%s: error in region allocation\n",
181 sc->sc_dev.dv_xname);
182 return;
183 }
184
185 gussc = sc;
186
187 sc->sc_iot = ipa->ipa_iot;
188
189 /* handle is the region base */
190
191 sc->dir_h = 0; /* XXXXX */
192 sc->p2xr = 0;
193 sc->p2xr_h = ipa->ipa_io[0].h;
194 sc->sc_p2xr_ic = ipa->ipa_ic;
195 sc->p3xr = 0;
196 sc->p3xr_h = ipa->ipa_io[1].h;
197 sc->sc_p3xr_ic = ipa->ipa_ic;
198 sc->codec_index = 0;
199 sc->codec_index_h = ipa->ipa_io[2].h;
200 sc->sc_irq = ipa->ipa_irq[0].num;
201 sc->sc_recdrq = ipa->ipa_drq[0].num;
202 sc->sc_playdrq = ipa->ipa_drq[1].num;
203
204 sc->sc_isa = parent->dv_parent;
205
206 /*
207 * Create our DMA maps.
208 */
209 if (sc->sc_playdrq != -1) {
210 if (isa_dmamap_create(sc->sc_isa, sc->sc_playdrq,
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_playdrq);
214 return;
215 }
216 }
217 if (sc->sc_recdrq != -1) {
218 if (isa_dmamap_create(sc->sc_isa, sc->sc_recdrq,
219 MAX_ISADMA, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
220 printf("%s: can't create map for drq %d\n",
221 sc->sc_dev.dv_xname, sc->sc_recdrq);
222 return;
223 }
224 }
225
226 /*
227 * isapnp is a child if isa, and we need isa for the dma
228 * routines.
229 */
230 sc->iw_cd = &guspnp_cd;
231 sc->iw_hw_if = &guspnp_hw_if;
232
233 printf("%s: %s %s", sc->sc_dev.dv_xname, ipa->ipa_devident,
234 ipa->ipa_devclass);
235
236 iwattach(sc);
237 }
238
239 static
240 int
241 gus_isapnp_open(addr, flags)
242 void *addr;
243 int flags;
244 {
245 /* open hardware */
246 struct iw_softc *sc = (struct iw_softc *)addr;
247
248 if (!sc)
249 return ENXIO;
250
251 return iwopen(sc,flags);
252 }
253
254 #endif /* NGUSPNP */
255