sb.c revision 1.46 1 /* $NetBSD: sb.c,v 1.46 1997/05/09 22:16:40 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 <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/syslog.h>
42 #include <sys/device.h>
43 #include <sys/proc.h>
44
45 #include <machine/cpu.h>
46 #include <machine/intr.h>
47 #include <machine/pio.h>
48
49 #include <sys/audioio.h>
50 #include <dev/audio_if.h>
51
52 #include <dev/isa/isavar.h>
53 #include <dev/isa/isadmavar.h>
54
55 #include <dev/isa/sbreg.h>
56 #include <dev/isa/sbvar.h>
57 #include <dev/isa/sbdspvar.h>
58
59 struct sb_softc {
60 struct device sc_dev; /* base device */
61 struct isadev sc_id; /* ISA device */
62 void *sc_ih; /* interrupt vectoring */
63
64 struct sbdsp_softc sc_sbdsp;
65 };
66
67 struct cfdriver sb_cd = {
68 NULL, "sb", DV_DULL
69 };
70
71 struct audio_device sb_device = {
72 "SoundBlaster",
73 "x",
74 "sb"
75 };
76
77 int sbopen __P((dev_t, int));
78 int sb_getdev __P((void *, struct audio_device *));
79
80 /*
81 * Define our interface to the higher level audio driver.
82 */
83
84 struct audio_hw_if sb_hw_if = {
85 sbopen,
86 sbdsp_close,
87 NULL,
88 sbdsp_query_encoding,
89 sbdsp_set_params,
90 sbdsp_round_blocksize,
91 sbdsp_set_out_port,
92 sbdsp_get_out_port,
93 sbdsp_set_in_port,
94 sbdsp_get_in_port,
95 sbdsp_commit_settings,
96 sbdsp_dma_output,
97 sbdsp_dma_input,
98 sbdsp_haltdma,
99 sbdsp_haltdma,
100 sbdsp_contdma,
101 sbdsp_contdma,
102 sbdsp_speaker_ctl,
103 sb_getdev,
104 sbdsp_setfd,
105 sbdsp_mixer_set_port,
106 sbdsp_mixer_get_port,
107 sbdsp_mixer_query_devinfo,
108 0, /* not full-duplex */
109 0
110 };
111
112 /*
113 * Probe / attach routines.
114 */
115
116
117 int
118 sbmatch(sc)
119 struct sbdsp_softc *sc;
120 {
121 static u_char drq_conf[8] = {
122 0x01, 0x02, -1, 0x08, -1, 0x20, 0x40, 0x80
123 };
124
125 static u_char irq_conf[11] = {
126 -1, -1, 0x01, -1, -1, 0x02, -1, 0x04, -1, 0x01, 0x08
127 };
128
129 if (sbdsp_probe(sc) == 0)
130 return 0;
131
132 /*
133 * Cannot auto-discover DMA channel.
134 */
135 if (ISSBPROCLASS(sc)) {
136 if (!SBP_DRQ_VALID(sc->sc_drq8)) {
137 printf("%s: configured dma chan %d invalid\n",
138 sc->sc_dev.dv_xname, sc->sc_drq8);
139 return 0;
140 }
141 } else {
142 if (!SB_DRQ_VALID(sc->sc_drq8)) {
143 printf("%s: configured dma chan %d invalid\n",
144 sc->sc_dev.dv_xname, sc->sc_drq8);
145 return 0;
146 }
147 }
148
149 if (ISSB16CLASS(sc)) {
150 if (sc->sc_drq16 == -1)
151 sc->sc_drq16 = sc->sc_drq8;
152 if (!SB16_DRQ_VALID(sc->sc_drq16)) {
153 printf("%s: configured dma chan %d invalid\n",
154 sc->sc_dev.dv_xname, sc->sc_drq16);
155 return 0;
156 }
157 } else
158 sc->sc_drq16 = sc->sc_drq8;
159
160 #ifdef NEWCONFIG
161 /*
162 * If the IRQ wasn't compiled in, auto-detect it.
163 */
164 if (sc->sc_irq == IRQUNK) {
165 sc->sc_irq = isa_discoverintr(sbforceintr, sc);
166 sbdsp_reset(sc);
167 if (ISSBPROCLASS(sc)) {
168 if (!SBP_IRQ_VALID(sc->sc_irq)) {
169 printf("%s: couldn't auto-detect interrupt\n",
170 sc->sc_dev.dv_xname);
171 return 0;
172 }
173 }
174 else {
175 if (!SB_IRQ_VALID(sc->sc_irq)) {
176 printf("%s: couldn't auto-detect interrupt\n");
177 sc->sc_dev.dv_xname);
178 return 0;
179 }
180 }
181 } else
182 #endif
183 if (ISSBPROCLASS(sc)) {
184 if (!SBP_IRQ_VALID(sc->sc_irq)) {
185 printf("%s: configured irq %d invalid\n",
186 sc->sc_dev.dv_xname, sc->sc_irq);
187 return 0;
188 }
189 } else {
190 if (!SB_IRQ_VALID(sc->sc_irq)) {
191 printf("%s: configured irq %d invalid\n",
192 sc->sc_dev.dv_xname, sc->sc_irq);
193 return 0;
194 }
195 }
196
197 if (ISSB16CLASS(sc)) {
198 #if 0
199 printf("%s: old drq conf %02x\n", sc->sc_dev.dv_xname,
200 sbdsp_mix_read(sc, SBP_SET_DRQ));
201 printf("%s: try drq conf %02x\n", sc->sc_dev.dv_xname,
202 drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
203 #endif
204 sbdsp_mix_write(sc, SBP_SET_DRQ,
205 drq_conf[sc->sc_drq16] | drq_conf[sc->sc_drq8]);
206 #if 0
207 printf("%s: new drq conf %02x\n", sc->sc_dev.dv_xname,
208 sbdsp_mix_read(sc, SBP_SET_DRQ));
209 #endif
210
211 #if 0
212 printf("%s: old irq conf %02x\n", sc->sc_dev.dv_xname,
213 sbdsp_mix_read(sc, SBP_SET_IRQ));
214 printf("%s: try irq conf %02x\n", sc->sc_dev.dv_xname,
215 irq_conf[sc->sc_irq]);
216 #endif
217 sbdsp_mix_write(sc, SBP_SET_IRQ,
218 irq_conf[sc->sc_irq]);
219 #if 0
220 printf("%s: new irq conf %02x\n", sc->sc_dev.dv_xname,
221 sbdsp_mix_read(sc, SBP_SET_IRQ));
222 #endif
223 }
224
225 return 1;
226 }
227
228
229 void
230 sbattach(sc)
231 struct sbdsp_softc *sc;
232 {
233 int error;
234
235 sc->sc_ih = isa_intr_establish(sc->sc_ic, sc->sc_irq, IST_EDGE,
236 IPL_AUDIO, sbdsp_intr, sc);
237
238 sbdsp_attach(sc);
239
240 if ((error = audio_hardware_attach(&sb_hw_if, sc)) != 0)
241 printf("%s: could not attach to audio device driver (%d)\n",
242 sc->sc_dev.dv_xname, error);
243 }
244
245 #ifdef NEWCONFIG
246 void
247 sbforceintr(aux)
248 void *aux;
249 {
250 static char dmabuf;
251 struct sbdsp_softc *sc = aux;
252
253 /*
254 * Set up a DMA read of one byte.
255 * XXX Note that at this point we haven't called
256 * at_setup_dmachan(). This is okay because it just
257 * allocates a buffer in case it needs to make a copy,
258 * and it won't need to make a copy for a 1 byte buffer.
259 * (I think that calling at_setup_dmachan() should be optional;
260 * if you don't call it, it will be called the first time
261 * it is needed (and you pay the latency). Also, you might
262 * never need the buffer anyway.)
263 */
264 at_dma(DMAMODE_READ, &dmabuf, 1, sc->sc_drq8);
265 if (sbdsp_wdsp(sc, SB_DSP_RDMA) == 0) {
266 (void)sbdsp_wdsp(sc, 0);
267 (void)sbdsp_wdsp(sc, 0);
268 }
269 }
270 #endif
271
272
273 /*
274 * Various routines to interface to higher level audio driver
275 */
276
277 int
278 sbopen(dev, flags)
279 dev_t dev;
280 int flags;
281 {
282 struct sbdsp_softc *sc;
283 int unit = AUDIOUNIT(dev);
284
285 if (unit >= sb_cd.cd_ndevs)
286 return ENODEV;
287
288 sc = sb_cd.cd_devs[unit];
289 if (!sc)
290 return ENXIO;
291
292 return sbdsp_open(sc, dev, flags);
293 }
294
295 int
296 sb_getdev(addr, retp)
297 void *addr;
298 struct audio_device *retp;
299 {
300 struct sbdsp_softc *sc = addr;
301
302 if (sc->sc_model & MODEL_JAZZ16)
303 strncpy(retp->name, "MV Jazz16", sizeof(retp->name));
304 else
305 strncpy(retp->name, "SoundBlaster", sizeof(retp->name));
306 sprintf(retp->version, "%d.%02d",
307 SBVER_MAJOR(sc->sc_model),
308 SBVER_MINOR(sc->sc_model));
309 strncpy(retp->config, "sb", sizeof(retp->config));
310
311 return 0;
312 }
313