sb.c revision 1.71 1 /* $NetBSD: sb.c,v 1.71 2001/10/03 00:04:51 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1991-1993 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the Computer Systems
18 * Engineering Group at Lawrence Berkeley Laboratory.
19 * 4. Neither the name of the University nor of the Laboratory may be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37 #include "midi.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/errno.h>
42 #include <sys/ioctl.h>
43 #include <sys/syslog.h>
44 #include <sys/device.h>
45 #include <sys/proc.h>
46
47 #include <machine/cpu.h>
48 #include <machine/intr.h>
49 #include <machine/bus.h>
50
51 #include <sys/audioio.h>
52 #include <dev/audio_if.h>
53 #include <dev/midi_if.h>
54
55 #include <dev/midi_if.h>
56
57 #include <dev/isa/isavar.h>
58 #include <dev/isa/isadmavar.h>
59
60 #include <dev/isa/sbreg.h>
61 #include <dev/isa/sbvar.h>
62 #include <dev/isa/sbdspvar.h>
63
64 #if NMPU > 0
65 struct midi_hw_if sb_midi_hw_if = {
66 sbdsp_midi_open,
67 sbdsp_midi_close,
68 sbdsp_midi_output,
69 sbdsp_midi_getinfo,
70 0, /* ioctl */
71 };
72 #endif
73
74 struct audio_device sb_device = {
75 "SoundBlaster",
76 "x",
77 "sb"
78 };
79
80 int sb_getdev __P((void *, struct audio_device *));
81
82 /*
83 * Define our interface to the higher level audio driver.
84 */
85
86 struct audio_hw_if sb_hw_if = {
87 sbdsp_open,
88 sbdsp_close,
89 0,
90 sbdsp_query_encoding,
91 sbdsp_set_params,
92 sbdsp_round_blocksize,
93 0,
94 0,
95 0,
96 0,
97 0,
98 sbdsp_halt_output,
99 sbdsp_halt_input,
100 sbdsp_speaker_ctl,
101 sb_getdev,
102 0,
103 sbdsp_mixer_set_port,
104 sbdsp_mixer_get_port,
105 sbdsp_mixer_query_devinfo,
106 sb_malloc,
107 sb_free,
108 sb_round_buffersize,
109 sb_mappage,
110 sbdsp_get_props,
111 sbdsp_trigger_output,
112 sbdsp_trigger_input,
113 0,
114 };
115
116 /*
117 * Probe / attach routines.
118 */
119
120
121 int
122 sbmatch(sc)
123 struct sbdsp_softc *sc;
124 {
125 static u_char drq_conf[8] = {
126 0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
127 };
128
129 static u_char irq_conf[11] = {
130 -1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
131 };
132
133 if (sbdsp_probe(sc) == 0)
134 return 0;
135
136 /*
137 * Cannot auto-discover DMA channel.
138 */
139 if (ISSBPROCLASS(sc)) {
140 if (!SBP_DRQ_VALID(sc->sc_drq8)) {
141 printf("%s: configured dma chan %d invalid\n",
142 sc->sc_dev.dv_xname, sc->sc_drq8);
143 return 0;
144 }
145 } else {
146 if (!SB_DRQ_VALID(sc->sc_drq8)) {
147 printf("%s: configured dma chan %d invalid\n",
148 sc->sc_dev.dv_xname, sc->sc_drq8);
149 return 0;
150 }
151 }
152
153 if (0 <= sc->sc_drq16 && sc->sc_drq16 <= 3)
154 /*
155 * XXX Some ViBRA16 cards seem to have two 8 bit DMA
156 * channels. I've no clue how to use them, so ignore
157 * one of them for now. -- augustss (at) netbsd.org
158 */
159 sc->sc_drq16 = -1;
160
161 if (ISSB16CLASS(sc)) {
162 if (sc->sc_drq16 == -1)
163 sc->sc_drq16 = sc->sc_drq8;
164 if (!SB16_DRQ_VALID(sc->sc_drq16)) {
165 printf("%s: configured dma chan %d invalid\n",
166 sc->sc_dev.dv_xname, sc->sc_drq16);
167 return 0;
168 }
169 } else
170 sc->sc_drq16 = sc->sc_drq8;
171
172 if (ISSBPROCLASS(sc)) {
173 if (!SBP_IRQ_VALID(sc->sc_irq)) {
174 printf("%s: configured irq %d invalid\n",
175 sc->sc_dev.dv_xname, sc->sc_irq);
176 return 0;
177 }
178 } else {
179 if (!SB_IRQ_VALID(sc->sc_irq)) {
180 printf("%s: configured irq %d invalid\n",
181 sc->sc_dev.dv_xname, sc->sc_irq);
182 return 0;
183 }
184 }
185
186 if (ISSB16CLASS(sc) && !(sc->sc_quirks & SB_QUIRK_NO_INIT_DRQ)) {
187 int w, r;
188 #if 0
189 printf("%s: old drq conf %02x\n", sc->sc_dev.dv_xname,
190 sbdsp_mix_read(sc, SBP_SET_DRQ));
191 printf("%s: try drq conf %02x\n", sc->sc_dev.dv_xname,
192 drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
193 #endif
194 w = drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8];
195 sbdsp_mix_write(sc, SBP_SET_DRQ, w);
196 r = sbdsp_mix_read(sc, SBP_SET_DRQ) & 0xeb;
197 if (r != w) {
198 printf("%s: setting drq mask %02x failed, got %02x\n",
199 sc->sc_dev.dv_xname, w, r);
200 return 0;
201 }
202 #if 0
203 printf("%s: new drq conf %02x\n", sc->sc_dev.dv_xname,
204 sbdsp_mix_read(sc, SBP_SET_DRQ));
205 #endif
206
207 #if 0
208 printf("%s: old irq conf %02x\n", sc->sc_dev.dv_xname,
209 sbdsp_mix_read(sc, SBP_SET_IRQ));
210 printf("%s: try irq conf %02x\n", sc->sc_dev.dv_xname,
211 irq_conf[sc->sc_irq]);
212 #endif
213 w = irq_conf[sc->sc_irq];
214 sbdsp_mix_write(sc, SBP_SET_IRQ, w);
215 r = sbdsp_mix_read(sc, SBP_SET_IRQ) & 0x0f;
216 if (r != w) {
217 printf("%s: setting irq mask %02x failed, got %02x\n",
218 sc->sc_dev.dv_xname, w, r);
219 return 0;
220 }
221 #if 0
222 printf("%s: new irq conf %02x\n", sc->sc_dev.dv_xname,
223 sbdsp_mix_read(sc, SBP_SET_IRQ));
224 #endif
225 }
226
227 return 1;
228 }
229
230
231 void
232 sbattach(sc)
233 struct sbdsp_softc *sc;
234 {
235 struct audio_attach_args arg;
236
237 sbdsp_attach(sc);
238
239 audio_attach_mi(&sb_hw_if, sc, &sc->sc_dev);
240
241 #if NMPU > 0
242 if (sc->sc_hasmpu) {
243 arg.type = AUDIODEV_TYPE_MPU;
244 arg.hwif = 0;
245 arg.hdl = 0;
246 sc->sc_mpudev = config_found(&sc->sc_dev, &arg, audioprint);
247 } else {
248 midi_attach_mi(&sb_midi_hw_if, sc, &sc->sc_dev);
249 }
250 #endif
251
252 if (sc->sc_model >= SB_20) {
253 arg.type = AUDIODEV_TYPE_OPL;
254 arg.hwif = 0;
255 arg.hdl = 0;
256 (void)config_found(&sc->sc_dev, &arg, audioprint);
257 }
258 }
259
260 /*
261 * Various routines to interface to higher level audio driver
262 */
263
264 int
265 sb_getdev(addr, retp)
266 void *addr;
267 struct audio_device *retp;
268 {
269 struct sbdsp_softc *sc = addr;
270 static char *names[] = SB_NAMES;
271 char *config;
272
273 if (sc->sc_model == SB_JAZZ)
274 strncpy(retp->name, "MV Jazz16", sizeof(retp->name));
275 else
276 strncpy(retp->name, "SoundBlaster", sizeof(retp->name));
277 sprintf(retp->version, "%d.%02d",
278 SBVER_MAJOR(sc->sc_version),
279 SBVER_MINOR(sc->sc_version));
280 if (0 <= sc->sc_model && sc->sc_model < sizeof names / sizeof names[0])
281 config = names[sc->sc_model];
282 else
283 config = "??";
284 strncpy(retp->config, config, sizeof(retp->config));
285
286 return 0;
287 }
288