sbdsp.c revision 1.54 1 /* $NetBSD: sbdsp.c,v 1.54 1997/05/27 23:37:53 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 /*
38 * SoundBlaster Pro code provided by John Kohl, based on lots of
39 * information he gleaned from Steve Haehnichen <steve (at) vigra.com>'s
40 * SBlast driver for 386BSD and DOS driver code from Daniel Sachs
41 * <sachs (at) meibm15.cen.uiuc.edu>.
42 * Lots of rewrites by Lennart Augustsson <augustss (at) cs.chalmers.se>
43 * with information from SB "Hardware Programming Guide" and the
44 * Linux drivers.
45 */
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/errno.h>
50 #include <sys/ioctl.h>
51 #include <sys/syslog.h>
52 #include <sys/device.h>
53 #include <sys/proc.h>
54 #include <sys/buf.h>
55 #include <vm/vm.h>
56
57 #include <machine/cpu.h>
58 #include <machine/intr.h>
59 #include <machine/pio.h>
60
61 #include <sys/audioio.h>
62 #include <dev/audio_if.h>
63 #include <dev/mulaw.h>
64
65 #include <dev/isa/isavar.h>
66 #include <dev/isa/isadmavar.h>
67
68 #include <dev/isa/sbreg.h>
69 #include <dev/isa/sbdspvar.h>
70
71 #ifdef AUDIO_DEBUG
72 extern void Dprintf __P((const char *, ...));
73 #define DPRINTF(x) if (sbdspdebug) Dprintf x
74 int sbdspdebug = 0;
75 #else
76 #define DPRINTF(x)
77 #endif
78
79 #ifndef SBDSP_NPOLL
80 #define SBDSP_NPOLL 3000
81 #endif
82
83 struct {
84 int wdsp;
85 int rdsp;
86 int wmidi;
87 } sberr;
88
89 /*
90 * Time constant routines follow. See SBK, section 12.
91 * Although they don't come out and say it (in the docs),
92 * the card clearly uses a 1MHz countdown timer, as the
93 * low-speed formula (p. 12-4) is:
94 * tc = 256 - 10^6 / sr
95 * In high-speed mode, the constant is the upper byte of a 16-bit counter,
96 * and a 256MHz clock is used:
97 * tc = 65536 - 256 * 10^ 6 / sr
98 * Since we can only use the upper byte of the HS TC, the two formulae
99 * are equivalent. (Why didn't they say so?) E.g.,
100 * (65536 - 256 * 10 ^ 6 / x) >> 8 = 256 - 10^6 / x
101 *
102 * The crossover point (from low- to high-speed modes) is different
103 * for the SBPRO and SB20. The table on p. 12-5 gives the following data:
104 *
105 * SBPRO SB20
106 * ----- --------
107 * input ls min 4 KHz 4 KHz
108 * input ls max 23 KHz 13 KHz
109 * input hs max 44.1 KHz 15 KHz
110 * output ls min 4 KHz 4 KHz
111 * output ls max 23 KHz 23 KHz
112 * output hs max 44.1 KHz 44.1 KHz
113 */
114 /* XXX Should we round the tc?
115 #define SB_RATE_TO_TC(x) (((65536 - 256 * 1000000 / (x)) + 128) >> 8)
116 */
117 #define SB_RATE_TO_TC(x) (256 - 1000000 / (x))
118 #define SB_TC_TO_RATE(tc) (1000000 / (256 - (tc)))
119
120 struct sbmode {
121 short model;
122 u_char channels;
123 u_char precision;
124 u_short lowrate, highrate;
125 u_char cmd;
126 short cmdchan;
127 };
128 static struct sbmode sbpmodes[] = {
129 { SB_1, 1, 8, 4000, 22727, SB_DSP_WDMA },
130 { SB_20, 1, 8, 4000, 22727, SB_DSP_WDMA_LOOP },
131 { SB_2x, 1, 8, 4000, 22727, SB_DSP_WDMA_LOOP },
132 { SB_2x, 1, 8, 22727, 45454, SB_DSP_HS_OUTPUT },
133 { SB_PRO, 1, 8, 4000, 22727, SB_DSP_WDMA_LOOP },
134 { SB_PRO, 1, 8, 22727, 45454, SB_DSP_HS_OUTPUT },
135 { SB_PRO, 2, 8, 11025, 22727, SB_DSP_HS_OUTPUT },
136 { SB_JAZZ, 1, 8, 4000, 22727, SB_DSP_WDMA_LOOP, SB_DSP_RECORD_MONO },
137 { SB_JAZZ, 1, 8, 22727, 45454, SB_DSP_HS_OUTPUT, SB_DSP_RECORD_MONO },
138 { SB_JAZZ, 2, 8, 11025, 22727, SB_DSP_HS_OUTPUT, SB_DSP_RECORD_STEREO },
139 { SB_JAZZ, 1, 16, 4000, 22727, SB_DSP_WDMA_LOOP, JAZZ16_RECORD_MONO },
140 { SB_JAZZ, 1, 16, 22727, 45454, SB_DSP_HS_OUTPUT, JAZZ16_RECORD_MONO },
141 { SB_JAZZ, 2, 16, 11025, 22727, SB_DSP_HS_OUTPUT, JAZZ16_RECORD_STEREO },
142 { SB_16, 1, 8, 5000, 45000, SB_DSP16_WDMA_8 },
143 { SB_16, 2, 8, 5000, 45000, SB_DSP16_WDMA_8 },
144 { SB_16, 1, 16, 5000, 45000, SB_DSP16_WDMA_16 },
145 { SB_16, 2, 16, 5000, 45000, SB_DSP16_WDMA_16 },
146 { -1 }
147 };
148 static struct sbmode sbrmodes[] = {
149 { SB_1, 1, 8, 4000, 12987, SB_DSP_RDMA },
150 { SB_20, 1, 8, 4000, 12987, SB_DSP_RDMA_LOOP },
151 { SB_2x, 1, 8, 4000, 12987, SB_DSP_RDMA_LOOP },
152 { SB_2x, 1, 8, 12987, 14925, SB_DSP_HS_INPUT },
153 { SB_PRO, 1, 8, 4000, 22727, SB_DSP_RDMA_LOOP, SB_DSP_RECORD_MONO },
154 { SB_PRO, 1, 8, 22727, 45454, SB_DSP_HS_INPUT, SB_DSP_RECORD_MONO },
155 { SB_PRO, 2, 8, 11025, 22727, SB_DSP_HS_INPUT, SB_DSP_RECORD_STEREO },
156 { SB_JAZZ, 1, 8, 4000, 22727, SB_DSP_RDMA_LOOP, SB_DSP_RECORD_MONO },
157 { SB_JAZZ, 1, 8, 22727, 45454, SB_DSP_HS_INPUT, SB_DSP_RECORD_MONO },
158 { SB_JAZZ, 2, 8, 11025, 22727, SB_DSP_HS_INPUT, SB_DSP_RECORD_STEREO },
159 { SB_JAZZ, 1, 16, 4000, 22727, SB_DSP_RDMA_LOOP, JAZZ16_RECORD_MONO },
160 { SB_JAZZ, 1, 16, 22727, 45454, SB_DSP_HS_INPUT, JAZZ16_RECORD_MONO },
161 { SB_JAZZ, 2, 16, 11025, 22727, SB_DSP_HS_INPUT, JAZZ16_RECORD_STEREO },
162 { SB_16, 1, 8, 5000, 45000, SB_DSP16_RDMA_8 },
163 { SB_16, 2, 8, 5000, 45000, SB_DSP16_RDMA_8 },
164 { SB_16, 1, 16, 5000, 45000, SB_DSP16_RDMA_16 },
165 { SB_16, 2, 16, 5000, 45000, SB_DSP16_RDMA_16 },
166 { -1 }
167 };
168
169 void sbversion __P((struct sbdsp_softc *));
170 void sbdsp_jazz16_probe __P((struct sbdsp_softc *));
171 void sbdsp_set_mixer_gain __P((struct sbdsp_softc *sc, int port));
172 int sbdsp16_wait __P((struct sbdsp_softc *));
173 void sbdsp_to __P((void *));
174 void sbdsp_pause __P((struct sbdsp_softc *));
175 int sbdsp_set_timeconst __P((struct sbdsp_softc *, int));
176 int sbdsp16_set_rate __P((struct sbdsp_softc *, int, int));
177 int sbdsp_set_in_ports __P((struct sbdsp_softc *, int));
178 void sbdsp_set_ifilter __P((void *, int));
179 int sbdsp_get_ifilter __P((void *));
180
181 #ifdef AUDIO_DEBUG
182 void sb_printsc __P((struct sbdsp_softc *));
183
184 void
185 sb_printsc(sc)
186 struct sbdsp_softc *sc;
187 {
188 int i;
189
190 printf("open %d dmachan %d/%d/%d iobase 0x%x irq %d\n",
191 (int)sc->sc_open, sc->dmachan, sc->sc_drq8, sc->sc_drq16,
192 sc->sc_iobase, sc->sc_irq);
193 printf("irate %d itc %x orate %d otc %x\n",
194 sc->sc_irate, sc->sc_itc,
195 sc->sc_orate, sc->sc_otc);
196 printf("outport %u inport %u spkron %u nintr %lu\n",
197 sc->out_port, sc->in_port, sc->spkr_state, sc->sc_interrupts);
198 printf("intr %p arg %p\n",
199 sc->sc_intr, sc->sc_arg);
200 printf("gain:");
201 for (i = 0; i < SB_NDEVS; i++)
202 printf(" %u,%u", sc->gain[i][SB_LEFT], sc->gain[i][SB_RIGHT]);
203 printf("\n");
204 }
205 #endif /* AUDIO_DEBUG */
206
207 /*
208 * Probe / attach routines.
209 */
210
211 /*
212 * Probe for the soundblaster hardware.
213 */
214 int
215 sbdsp_probe(sc)
216 struct sbdsp_softc *sc;
217 {
218
219 if (sbdsp_reset(sc) < 0) {
220 DPRINTF(("sbdsp: couldn't reset card\n"));
221 return 0;
222 }
223 /* if flags set, go and probe the jazz16 stuff */
224 if (sc->sc_dev.dv_cfdata->cf_flags & 1)
225 sbdsp_jazz16_probe(sc);
226 else
227 sbversion(sc);
228 if (sc->sc_model == SB_UNK) {
229 /* Unknown SB model found. */
230 DPRINTF(("sbdsp: unknown SB model found\n"));
231 return 0;
232 }
233 return 1;
234 }
235
236 /*
237 * Try add-on stuff for Jazz16.
238 */
239 void
240 sbdsp_jazz16_probe(sc)
241 struct sbdsp_softc *sc;
242 {
243 static u_char jazz16_irq_conf[16] = {
244 -1, -1, 0x02, 0x03,
245 -1, 0x01, -1, 0x04,
246 -1, 0x02, 0x05, -1,
247 -1, -1, -1, 0x06};
248 static u_char jazz16_drq_conf[8] = {
249 -1, 0x01, -1, 0x02,
250 -1, 0x03, -1, 0x04};
251
252 bus_space_tag_t iot = sc->sc_iot;
253 bus_space_handle_t ioh;
254
255 sbversion(sc);
256
257 DPRINTF(("jazz16 probe\n"));
258
259 if (bus_space_map(iot, JAZZ16_CONFIG_PORT, 1, 0, &ioh)) {
260 DPRINTF(("bus map failed\n"));
261 return;
262 }
263
264 if (jazz16_drq_conf[sc->sc_drq8] == (u_char)-1 ||
265 jazz16_irq_conf[sc->sc_irq] == (u_char)-1) {
266 DPRINTF(("drq/irq check failed\n"));
267 goto done; /* give up, we can't do it. */
268 }
269
270 bus_space_write_1(iot, ioh, 0, JAZZ16_WAKEUP);
271 delay(10000); /* delay 10 ms */
272 bus_space_write_1(iot, ioh, 0, JAZZ16_SETBASE);
273 bus_space_write_1(iot, ioh, 0, sc->sc_iobase & 0x70);
274
275 if (sbdsp_reset(sc) < 0) {
276 DPRINTF(("sbdsp_reset check failed\n"));
277 goto done; /* XXX? what else could we do? */
278 }
279
280 if (sbdsp_wdsp(sc, JAZZ16_READ_VER)) {
281 DPRINTF(("read16 setup failed\n"));
282 goto done;
283 }
284
285 if (sbdsp_rdsp(sc) != JAZZ16_VER_JAZZ) {
286 DPRINTF(("read16 failed\n"));
287 goto done;
288 }
289
290 /* XXX set both 8 & 16-bit drq to same channel, it works fine. */
291 sc->sc_drq16 = sc->sc_drq8;
292 if (sbdsp_wdsp(sc, JAZZ16_SET_DMAINTR) ||
293 sbdsp_wdsp(sc, (jazz16_drq_conf[sc->sc_drq16] << 4) |
294 jazz16_drq_conf[sc->sc_drq8]) ||
295 sbdsp_wdsp(sc, jazz16_irq_conf[sc->sc_irq])) {
296 DPRINTF(("sbdsp: can't write jazz16 probe stuff\n"));
297 } else {
298 DPRINTF(("jazz16 detected!\n"));
299 sc->sc_model = SB_JAZZ;
300 sc->sc_mixer_model = SBM_CT1345; /* XXX really? */
301 }
302
303 done:
304 bus_space_unmap(iot, ioh, 1);
305 }
306
307 /*
308 * Attach hardware to driver, attach hardware driver to audio
309 * pseudo-device driver .
310 */
311 void
312 sbdsp_attach(sc)
313 struct sbdsp_softc *sc;
314 {
315 struct audio_params xparams;
316 int i;
317 u_int v;
318
319 sbdsp_set_params(sc, AUMODE_RECORD, &audio_default, &xparams);
320 sbdsp_set_params(sc, AUMODE_PLAY, &audio_default, &xparams);
321
322 sbdsp_set_in_port(sc, SB_MIC_VOL);
323 sbdsp_set_out_port(sc, SB_MASTER_VOL);
324
325 if (sc->sc_mixer_model != SBM_NONE) {
326 /* Reset the mixer.*/
327 sbdsp_mix_write(sc, SBP_MIX_RESET, SBP_MIX_RESET);
328 /* And set our own default values */
329 for (i = 0; i < SB_NDEVS; i++) {
330 switch(i) {
331 case SB_MIC_VOL:
332 case SB_LINE_IN_VOL:
333 v = 0;
334 break;
335 case SB_BASS:
336 case SB_TREBLE:
337 v = SB_ADJUST_GAIN(sc, AUDIO_MAX_GAIN/2);
338 break;
339 default:
340 v = SB_ADJUST_GAIN(sc, AUDIO_MAX_GAIN * 3 / 4);
341 break;
342 }
343 sc->gain[i][SB_LEFT] = sc->gain[i][SB_RIGHT] = v;
344 sbdsp_set_mixer_gain(sc, i);
345 }
346 sc->in_filter = 0; /* no filters turned on, please */
347 }
348
349 printf(": dsp v%d.%02d%s\n",
350 SBVER_MAJOR(sc->sc_version), SBVER_MINOR(sc->sc_version),
351 sc->sc_model == SB_JAZZ ? ": <Jazz16>" : "");
352 }
353
354 void
355 sbdsp_mix_write(sc, mixerport, val)
356 struct sbdsp_softc *sc;
357 int mixerport;
358 int val;
359 {
360 bus_space_tag_t iot = sc->sc_iot;
361 bus_space_handle_t ioh = sc->sc_ioh;
362 int s;
363
364 s = splaudio();
365 bus_space_write_1(iot, ioh, SBP_MIXER_ADDR, mixerport);
366 delay(20);
367 bus_space_write_1(iot, ioh, SBP_MIXER_DATA, val);
368 delay(30);
369 splx(s);
370 }
371
372 int
373 sbdsp_mix_read(sc, mixerport)
374 struct sbdsp_softc *sc;
375 int mixerport;
376 {
377 bus_space_tag_t iot = sc->sc_iot;
378 bus_space_handle_t ioh = sc->sc_ioh;
379 int val;
380 int s;
381
382 s = splaudio();
383 bus_space_write_1(iot, ioh, SBP_MIXER_ADDR, mixerport);
384 delay(20);
385 val = bus_space_read_1(iot, ioh, SBP_MIXER_DATA);
386 delay(30);
387 splx(s);
388 return val;
389 }
390
391 /*
392 * Various routines to interface to higher level audio driver
393 */
394
395 int
396 sbdsp_query_encoding(addr, fp)
397 void *addr;
398 struct audio_encoding *fp;
399 {
400 struct sbdsp_softc *sc = addr;
401 int emul;
402
403 emul = ISSB16CLASS(sc) ? 0 : AUDIO_ENCODINGFLAG_EMULATED;
404
405 switch (fp->index) {
406 case 0:
407 strcpy(fp->name, AudioEulinear);
408 fp->encoding = AUDIO_ENCODING_ULINEAR;
409 fp->precision = 8;
410 fp->flags = 0;
411 return 0;
412 case 1:
413 strcpy(fp->name, AudioEmulaw);
414 fp->encoding = AUDIO_ENCODING_ULAW;
415 fp->precision = 8;
416 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
417 return 0;
418 case 2:
419 strcpy(fp->name, AudioElinear);
420 fp->encoding = AUDIO_ENCODING_LINEAR;
421 fp->precision = 8;
422 fp->flags = emul;
423 return 0;
424 }
425 if (!ISSB16CLASS(sc) && sc->sc_model != SB_JAZZ)
426 return EINVAL;
427
428 switch(fp->index) {
429 case 3:
430 strcpy(fp->name, AudioElinear_le);
431 fp->encoding = AUDIO_ENCODING_LINEAR_LE;
432 fp->precision = 16;
433 fp->flags = 0;
434 return 0;
435 case 4:
436 strcpy(fp->name, AudioEulinear_le);
437 fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
438 fp->precision = 16;
439 fp->flags = emul;
440 return 0;
441 case 5:
442 strcpy(fp->name, AudioElinear_be);
443 fp->encoding = AUDIO_ENCODING_LINEAR_BE;
444 fp->precision = 16;
445 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
446 return 0;
447 case 6:
448 strcpy(fp->name, AudioEulinear_be);
449 fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
450 fp->precision = 16;
451 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
452 return 0;
453 default:
454 return EINVAL;
455 }
456 return 0;
457 }
458
459 int
460 sbdsp_set_params(addr, mode, p, q)
461 void *addr;
462 int mode;
463 struct audio_params *p, *q;
464 {
465 struct sbdsp_softc *sc = addr;
466 struct sbmode *m;
467 u_int rate, tc = 1, bmode = -1;
468 void (*swcode) __P((void *, u_char *buf, int cnt));
469
470 for(m = mode == AUMODE_PLAY ? sbpmodes : sbrmodes;
471 m->model != -1; m++) {
472 if (sc->sc_model == m->model &&
473 p->channels == m->channels &&
474 p->precision == m->precision &&
475 p->sample_rate >= m->lowrate &&
476 p->sample_rate < m->highrate)
477 break;
478 }
479 if (m->model == -1)
480 return EINVAL;
481 rate = p->sample_rate;
482 swcode = 0;
483 if (m->model == SB_16) {
484 switch (p->encoding) {
485 case AUDIO_ENCODING_LINEAR_BE:
486 if (p->precision == 16)
487 swcode = swap_bytes;
488 /* fall into */
489 case AUDIO_ENCODING_LINEAR_LE:
490 bmode = 0x10;
491 break;
492 case AUDIO_ENCODING_ULINEAR_BE:
493 if (p->precision == 16)
494 swcode = swap_bytes;
495 /* fall into */
496 case AUDIO_ENCODING_ULINEAR_LE:
497 bmode = 0;
498 break;
499 case AUDIO_ENCODING_ULAW:
500 swcode = mode == AUMODE_PLAY ?
501 mulaw_to_ulinear8 : ulinear8_to_mulaw;
502 bmode = 0;
503 break;
504 default:
505 return EINVAL;
506 }
507 if (p->channels == 2)
508 bmode |= 0x20;
509 } else if (m->model == SB_JAZZ && m->precision == 16) {
510 switch (p->encoding) {
511 case AUDIO_ENCODING_LINEAR_LE:
512 break;
513 case AUDIO_ENCODING_ULINEAR_LE:
514 swcode = change_sign16;
515 break;
516 case AUDIO_ENCODING_LINEAR_BE:
517 swcode = swap_bytes;
518 break;
519 case AUDIO_ENCODING_ULINEAR_BE:
520 swcode = mode == AUMODE_PLAY ?
521 swap_bytes_change_sign16 : change_sign16_swap_bytes;
522 break;
523 case AUDIO_ENCODING_ULAW:
524 swcode = mode == AUMODE_PLAY ?
525 mulaw_to_ulinear8 : ulinear8_to_mulaw;
526 break;
527 default:
528 return EINVAL;
529 }
530 } else {
531 switch (p->encoding) {
532 case AUDIO_ENCODING_LINEAR_BE:
533 case AUDIO_ENCODING_LINEAR_LE:
534 swcode = change_sign8;
535 break;
536 case AUDIO_ENCODING_ULINEAR_BE:
537 case AUDIO_ENCODING_ULINEAR_LE:
538 break;
539 case AUDIO_ENCODING_ULAW:
540 swcode = mode == AUMODE_PLAY ?
541 mulaw_to_ulinear8 : ulinear8_to_mulaw;
542 break;
543 default:
544 return EINVAL;
545 }
546 tc = SB_RATE_TO_TC(p->sample_rate * p->channels);
547 p->sample_rate = SB_TC_TO_RATE(tc) / p->channels;
548 }
549
550 if (mode == AUMODE_PLAY) {
551 sc->sc_orate = rate;
552 sc->sc_otc = tc;
553 sc->sc_omodep = m;
554 sc->sc_obmode = bmode;
555 } else {
556 sc->sc_irate = rate;
557 sc->sc_itc = tc;
558 sc->sc_imodep = m;
559 sc->sc_ibmode = bmode;
560 }
561
562 p->sw_code = swcode;
563
564 /* Update setting for the other mode. */
565 q->encoding = p->encoding;
566 q->channels = p->channels;
567 q->precision = p->precision;
568
569 /*
570 * XXX
571 * Should wait for chip to be idle.
572 */
573 sc->sc_dmadir = SB_DMA_NONE;
574
575 DPRINTF(("set_params: model=%d, rate=%ld, prec=%d, chan=%d, enc=%d -> tc=%02x, cmd=%02x, bmode=%02x, cmdchan=%02x, swcode=%p\n",
576 sc->sc_model, p->sample_rate, p->precision, p->channels,
577 p->encoding, tc, m->cmd, bmode, m->cmdchan, swcode));
578
579 return 0;
580 }
581
582 void
583 sbdsp_set_ifilter(addr, which)
584 void *addr;
585 int which;
586 {
587 struct sbdsp_softc *sc = addr;
588 int mixval;
589
590 mixval = sbdsp_mix_read(sc, SBP_INFILTER) & ~SBP_IFILTER_MASK;
591 switch (which) {
592 case 0:
593 mixval |= SBP_FILTER_OFF;
594 break;
595 case SB_TREBLE:
596 mixval |= SBP_FILTER_ON | SBP_IFILTER_HIGH;
597 break;
598 case SB_BASS:
599 mixval |= SBP_FILTER_ON | SBP_IFILTER_LOW;
600 break;
601 default:
602 return;
603 }
604 sc->in_filter = mixval & SBP_IFILTER_MASK;
605 sbdsp_mix_write(sc, SBP_INFILTER, mixval);
606 }
607
608 int
609 sbdsp_get_ifilter(addr)
610 void *addr;
611 {
612 struct sbdsp_softc *sc = addr;
613
614 sc->in_filter =
615 sbdsp_mix_read(sc, SBP_INFILTER) & SBP_IFILTER_MASK;
616 switch (sc->in_filter) {
617 case SBP_FILTER_ON|SBP_IFILTER_HIGH:
618 return SB_TREBLE;
619 case SBP_FILTER_ON|SBP_IFILTER_LOW:
620 return SB_BASS;
621 default:
622 return 0;
623 }
624 }
625
626 int
627 sbdsp_set_out_port(addr, port)
628 void *addr;
629 int port;
630 {
631 struct sbdsp_softc *sc = addr;
632
633 sc->out_port = port; /* Just record it */
634
635 return 0;
636 }
637
638 int
639 sbdsp_get_out_port(addr)
640 void *addr;
641 {
642 struct sbdsp_softc *sc = addr;
643
644 return sc->out_port;
645 }
646
647
648 int
649 sbdsp_set_in_port(addr, port)
650 void *addr;
651 int port;
652 {
653 return sbdsp_set_in_ports(addr, 1 << port);
654 }
655
656 int
657 sbdsp_set_in_ports(sc, mask)
658 struct sbdsp_softc *sc;
659 int mask;
660 {
661 int bitsl, bitsr;
662 int sbport;
663 int i;
664
665 DPRINTF(("sbdsp_set_in_ports: model=%d, mask=%x\n",
666 sc->sc_mixer_model, mask));
667
668 switch(sc->sc_mixer_model) {
669 case SBM_NONE:
670 return EINVAL;
671 case SBM_CT1335:
672 if (mask != (1 << SB_MIC_VOL))
673 return EINVAL;
674 break;
675 case SBM_CT1345:
676 switch (mask) {
677 case 1 << SB_MIC_VOL:
678 sbport = SBP_FROM_MIC;
679 break;
680 case 1 << SB_LINE_IN_VOL:
681 sbport = SBP_FROM_LINE;
682 break;
683 case 1 << SB_CD_VOL:
684 sbport = SBP_FROM_CD;
685 break;
686 default:
687 return EINVAL;
688 }
689 sbdsp_mix_write(sc, SBP_RECORD_SOURCE,
690 SBP_RECORD_FROM(sbport, SBP_FILTER_OFF, SBP_IFILTER_HIGH));
691 break;
692 case SBM_CT1745:
693 if (mask & ~((1<<SB_MIDI_VOL) | (1<<SB_LINE_IN_VOL) |
694 (1<<SB_CD_VOL) | (1<<SB_MIC_VOL)))
695 return EINVAL;
696 bitsr = 0;
697 if (mask & SB_MIDI_VOL) bitsr |= SBP_MIDI_SRC_R;
698 if (mask & SB_LINE_IN_VOL) bitsr |= SBP_LINE_SRC_R;
699 if (mask & SB_CD_VOL) bitsr |= SBP_CD_SRC_R;
700 bitsl = SB_SRC_R_TO_L(bitsr);
701 if (mask & SB_MIC_VOL) {
702 bitsl |= SBP_MIC_SRC;
703 bitsr |= SBP_MIC_SRC;
704 }
705 sbdsp_mix_write(sc, SBP_RECORD_SOURCE_L, bitsl);
706 sbdsp_mix_write(sc, SBP_RECORD_SOURCE_R, bitsr);
707 break;
708 }
709
710 sc->in_mask = mask;
711
712 /* XXX
713 * We have to fake a single port since the upper layer
714 * expects one.
715 */
716 for(i = 0; i < SB_NPORT; i++) {
717 if (mask & (1 << i)) {
718 sc->in_port = i;
719 break;
720 }
721 }
722 return 0;
723 }
724
725 int
726 sbdsp_get_in_port(addr)
727 void *addr;
728 {
729 struct sbdsp_softc *sc = addr;
730
731 return sc->in_port;
732 }
733
734
735 int
736 sbdsp_speaker_ctl(addr, newstate)
737 void *addr;
738 int newstate;
739 {
740 struct sbdsp_softc *sc = addr;
741
742 if ((newstate == SPKR_ON) &&
743 (sc->spkr_state == SPKR_OFF)) {
744 sbdsp_spkron(sc);
745 sc->spkr_state = SPKR_ON;
746 }
747 if ((newstate == SPKR_OFF) &&
748 (sc->spkr_state == SPKR_ON)) {
749 sbdsp_spkroff(sc);
750 sc->spkr_state = SPKR_OFF;
751 }
752 return 0;
753 }
754
755 int
756 sbdsp_round_blocksize(addr, blk)
757 void *addr;
758 int blk;
759 {
760 if (blk > NBPG/3)
761 blk = NBPG/3; /* XXX allow at least 3 blocks */
762
763 /* Round to a multiple of the biggest sample size. */
764 blk &= -4;
765
766 return blk;
767 }
768
769 int
770 sbdsp_commit_settings(addr)
771 void *addr;
772 {
773 return 0;
774 }
775
776 int
777 sbdsp_open(sc, dev, flags)
778 struct sbdsp_softc *sc;
779 dev_t dev;
780 int flags;
781 {
782 DPRINTF(("sbdsp_open: sc=%p\n", sc));
783
784 if (sc->sc_open != 0 || sbdsp_reset(sc) != 0)
785 return ENXIO;
786
787 sc->sc_open = 1;
788 sc->sc_mintr = 0;
789 if (ISSBPRO(sc) &&
790 sbdsp_wdsp(sc, SB_DSP_RECORD_MONO) < 0) {
791 DPRINTF(("sbdsp_open: can't set mono mode\n"));
792 /* we'll readjust when it's time for DMA. */
793 }
794
795 /*
796 * Leave most things as they were; users must change things if
797 * the previous process didn't leave it they way they wanted.
798 * Looked at another way, it's easy to set up a configuration
799 * in one program and leave it for another to inherit.
800 */
801 DPRINTF(("sbdsp_open: opened\n"));
802
803 return 0;
804 }
805
806 void
807 sbdsp_close(addr)
808 void *addr;
809 {
810 struct sbdsp_softc *sc = addr;
811
812 DPRINTF(("sbdsp_close: sc=%p\n", sc));
813
814 sc->sc_open = 0;
815 sbdsp_spkroff(sc);
816 sc->spkr_state = SPKR_OFF;
817 sc->sc_intr = 0;
818 sc->sc_mintr = 0;
819 sbdsp_haltdma(sc);
820
821 DPRINTF(("sbdsp_close: closed\n"));
822 }
823
824 /*
825 * Lower-level routines
826 */
827
828 /*
829 * Reset the card.
830 * Return non-zero if the card isn't detected.
831 */
832 int
833 sbdsp_reset(sc)
834 struct sbdsp_softc *sc;
835 {
836 bus_space_tag_t iot = sc->sc_iot;
837 bus_space_handle_t ioh = sc->sc_ioh;
838
839 sc->sc_intr = 0;
840 if (sc->sc_dmadir != SB_DMA_NONE) {
841 isa_dmaabort(sc->dmachan);
842 sc->sc_dmadir = SB_DMA_NONE;
843 }
844
845 /*
846 * See SBK, section 11.3.
847 * We pulse a reset signal into the card.
848 * Gee, what a brilliant hardware design.
849 */
850 bus_space_write_1(iot, ioh, SBP_DSP_RESET, 1);
851 delay(10);
852 bus_space_write_1(iot, ioh, SBP_DSP_RESET, 0);
853 delay(30);
854 if (sbdsp_rdsp(sc) != SB_MAGIC)
855 return -1;
856
857 return 0;
858 }
859
860 int
861 sbdsp16_wait(sc)
862 struct sbdsp_softc *sc;
863 {
864 bus_space_tag_t iot = sc->sc_iot;
865 bus_space_handle_t ioh = sc->sc_ioh;
866 int i;
867 u_char x;
868
869 for (i = SBDSP_NPOLL; --i >= 0; ) {
870 x = bus_space_read_1(iot, ioh, SBP_DSP_WSTAT);
871 delay(10);
872 if ((x & SB_DSP_BUSY) == 0)
873 continue;
874 return 0;
875 }
876 ++sberr.wdsp;
877 return -1;
878 }
879
880 /*
881 * Write a byte to the dsp.
882 * XXX We are at the mercy of the card as we use a
883 * polling loop and wait until it can take the byte.
884 */
885 int
886 sbdsp_wdsp(sc, v)
887 struct sbdsp_softc *sc;
888 int v;
889 {
890 bus_space_tag_t iot = sc->sc_iot;
891 bus_space_handle_t ioh = sc->sc_ioh;
892 int i;
893 u_char x;
894
895 for (i = SBDSP_NPOLL; --i >= 0; ) {
896 x = bus_space_read_1(iot, ioh, SBP_DSP_WSTAT);
897 delay(10);
898 if ((x & SB_DSP_BUSY) != 0)
899 continue;
900 bus_space_write_1(iot, ioh, SBP_DSP_WRITE, v);
901 delay(10);
902 return 0;
903 }
904 ++sberr.wdsp;
905 return -1;
906 }
907
908 /*
909 * Read a byte from the DSP, using polling.
910 */
911 int
912 sbdsp_rdsp(sc)
913 struct sbdsp_softc *sc;
914 {
915 bus_space_tag_t iot = sc->sc_iot;
916 bus_space_handle_t ioh = sc->sc_ioh;
917 int i;
918 u_char x;
919
920 for (i = SBDSP_NPOLL; --i >= 0; ) {
921 x = bus_space_read_1(iot, ioh, SBP_DSP_RSTAT);
922 delay(10);
923 if ((x & SB_DSP_READY) == 0)
924 continue;
925 x = bus_space_read_1(iot, ioh, SBP_DSP_READ);
926 delay(10);
927 return x;
928 }
929 ++sberr.rdsp;
930 return -1;
931 }
932
933 /*
934 * Doing certain things (like toggling the speaker) make
935 * the SB hardware go away for a while, so pause a little.
936 */
937 void
938 sbdsp_to(arg)
939 void *arg;
940 {
941 wakeup(arg);
942 }
943
944 void
945 sbdsp_pause(sc)
946 struct sbdsp_softc *sc;
947 {
948 extern int hz;
949
950 timeout(sbdsp_to, sbdsp_to, hz/8);
951 (void)tsleep(sbdsp_to, PWAIT, "sbpause", 0);
952 }
953
954 /*
955 * Turn on the speaker. The SBK documention says this operation
956 * can take up to 1/10 of a second. Higher level layers should
957 * probably let the task sleep for this amount of time after
958 * calling here. Otherwise, things might not work (because
959 * sbdsp_wdsp() and sbdsp_rdsp() will probably timeout.)
960 *
961 * These engineers had their heads up their ass when
962 * they designed this card.
963 */
964 void
965 sbdsp_spkron(sc)
966 struct sbdsp_softc *sc;
967 {
968 (void)sbdsp_wdsp(sc, SB_DSP_SPKR_ON);
969 sbdsp_pause(sc);
970 }
971
972 /*
973 * Turn off the speaker; see comment above.
974 */
975 void
976 sbdsp_spkroff(sc)
977 struct sbdsp_softc *sc;
978 {
979 (void)sbdsp_wdsp(sc, SB_DSP_SPKR_OFF);
980 sbdsp_pause(sc);
981 }
982
983 /*
984 * Read the version number out of the card. Return major code
985 * in high byte, and minor code in low byte.
986 */
987 void
988 sbversion(sc)
989 struct sbdsp_softc *sc;
990 {
991 int v;
992
993 sc->sc_model = SB_UNK;
994 sc->sc_version = 0;
995 if (sbdsp_wdsp(sc, SB_DSP_VERSION) < 0)
996 return;
997 v = sbdsp_rdsp(sc) << 8;
998 v |= sbdsp_rdsp(sc);
999 if (v < 0)
1000 return;
1001 sc->sc_version = v;
1002 switch(SBVER_MAJOR(v)) {
1003 case 1:
1004 sc->sc_mixer_model = SBM_NONE;
1005 sc->sc_model = SB_1;
1006 break;
1007 case 2:
1008 /* Some SB2 have a mixer, some don't. */
1009 sbdsp_mix_write(sc, SBP_1335_MASTER_VOL, 0x04);
1010 sbdsp_mix_write(sc, SBP_1335_MIDI_VOL, 0x06);
1011 /* Check if we can read back the mixer values. */
1012 if ((sbdsp_mix_read(sc, SBP_1335_MASTER_VOL) & 0x0e) == 0x04 &&
1013 (sbdsp_mix_read(sc, SBP_1335_MIDI_VOL) & 0x0e) == 0x06)
1014 sc->sc_mixer_model = SBM_CT1335;
1015 else
1016 sc->sc_mixer_model = SBM_NONE;
1017 if (SBVER_MINOR(v) == 0)
1018 sc->sc_model = SB_20;
1019 else
1020 sc->sc_model = SB_2x;
1021 break;
1022 case 3:
1023 sc->sc_mixer_model = SBM_CT1345;
1024 sc->sc_model = SB_PRO;
1025 break;
1026 case 4:
1027 sc->sc_mixer_model = SBM_CT1745;
1028 sc->sc_model = SB_16;
1029 break;
1030 }
1031 }
1032
1033 /*
1034 * Halt a DMA in progress. A low-speed transfer can be
1035 * resumed with sbdsp_contdma().
1036 */
1037 int
1038 sbdsp_haltdma(addr)
1039 void *addr;
1040 {
1041 struct sbdsp_softc *sc = addr;
1042
1043 DPRINTF(("sbdsp_haltdma: sc=%p\n", sc));
1044
1045 sbdsp_reset(sc);
1046 return 0;
1047 }
1048
1049 int
1050 sbdsp_contdma(addr)
1051 void *addr;
1052 {
1053 struct sbdsp_softc *sc = addr;
1054
1055 DPRINTF(("sbdsp_contdma: sc=%p\n", sc));
1056
1057 /* XXX how do we reinitialize the DMA controller state? do we care? */
1058 (void)sbdsp_wdsp(sc, SB_DSP_CONT);
1059 return 0;
1060 }
1061
1062 int
1063 sbdsp_set_timeconst(sc, tc)
1064 struct sbdsp_softc *sc;
1065 int tc;
1066 {
1067 DPRINTF(("sbdsp_set_timeconst: sc=%p tc=%d\n", sc, tc));
1068
1069 if (sbdsp_wdsp(sc, SB_DSP_TIMECONST) < 0 ||
1070 sbdsp_wdsp(sc, tc) < 0)
1071 return EIO;
1072
1073 return 0;
1074 }
1075
1076 int
1077 sbdsp16_set_rate(sc, cmd, rate)
1078 struct sbdsp_softc *sc;
1079 int cmd, rate;
1080 {
1081 DPRINTF(("sbdsp16_set_rate: sc=%p rate=%d\n", sc, rate));
1082
1083 if (sbdsp_wdsp(sc, cmd) < 0 ||
1084 sbdsp_wdsp(sc, rate >> 8) < 0 ||
1085 sbdsp_wdsp(sc, rate) < 0)
1086 return EIO;
1087 return 0;
1088 }
1089
1090 int
1091 sbdsp_dma_input(addr, p, cc, intr, arg)
1092 void *addr;
1093 void *p;
1094 int cc;
1095 void (*intr) __P((void *));
1096 void *arg;
1097 {
1098 struct sbdsp_softc *sc = addr;
1099 int loop = sc->sc_model != SB_1;
1100 int stereo = sc->sc_imodep->channels == 2;
1101 int filter;
1102
1103 #ifdef AUDIO_DEBUG
1104 if (sbdspdebug > 1)
1105 Dprintf("sbdsp_dma_input: cc=%d 0x%x (0x%x)\n", cc, intr, arg);
1106 #endif
1107 #ifdef DIAGNOSTIC
1108 if (sc->sc_imodep->channels == 2 && (cc & 1)) {
1109 DPRINTF(("stereo record odd bytes (%d)\n", cc));
1110 return EIO;
1111 }
1112 #endif
1113
1114 if (sc->sc_dmadir != SB_DMA_IN) {
1115 if (ISSBPRO(sc)) {
1116 if (sbdsp_wdsp(sc, sc->sc_imodep->cmdchan) < 0)
1117 goto badmode;
1118 filter = stereo ? SBP_FILTER_OFF : sc->in_filter;
1119 sbdsp_mix_write(sc, SBP_INFILTER,
1120 (sbdsp_mix_read(sc, SBP_INFILTER) &
1121 ~SBP_IFILTER_MASK) | filter);
1122 }
1123
1124 if (ISSB16CLASS(sc)) {
1125 if (sbdsp16_set_rate(sc, SB_DSP16_INPUTRATE,
1126 sc->sc_irate))
1127 goto giveup;
1128 } else {
1129 if (sbdsp_set_timeconst(sc, sc->sc_itc))
1130 goto giveup;
1131 }
1132
1133 sc->sc_dmadir = SB_DMA_IN;
1134 sc->dmaflags = DMAMODE_READ;
1135 if (loop)
1136 sc->dmaflags |= DMAMODE_LOOP;
1137 } else {
1138 /* If already started; just return. */
1139 if (loop)
1140 return 0;
1141 }
1142
1143 sc->dmaaddr = p;
1144 sc->dmacnt = loop ? (NBPG/cc)*cc : cc;
1145 sc->dmachan = sc->sc_imodep->precision == 16 ? sc->sc_drq16 : sc->sc_drq8;
1146 #ifdef AUDIO_DEBUG
1147 if (sbdspdebug > 1)
1148 Dprintf("sbdsp_dma_input: dmastart %x %p %d %d\n",
1149 sc->dmaflags, sc->dmaaddr, sc->dmacnt, sc->dmachan);
1150 #endif
1151 isa_dmastart(sc->dmaflags, sc->dmaaddr, sc->dmacnt, sc->dmachan);
1152 sc->sc_intr = intr;
1153 sc->sc_arg = arg;
1154
1155 if (sc->sc_imodep->precision == 16)
1156 cc >>= 1;
1157 --cc;
1158 if (ISSB16CLASS(sc)) {
1159 if (sbdsp_wdsp(sc, sc->sc_imodep->cmd) < 0 ||
1160 sbdsp_wdsp(sc, sc->sc_ibmode) < 0 ||
1161 sbdsp16_wait(sc) ||
1162 sbdsp_wdsp(sc, cc) < 0 ||
1163 sbdsp_wdsp(sc, cc >> 8) < 0) {
1164 DPRINTF(("sbdsp_dma_input: SB16 DMA start failed\n"));
1165 goto giveup;
1166 }
1167 } else {
1168 if (loop) {
1169 DPRINTF(("sbdsp_dma_input: set blocksize=%d\n", cc));
1170 if (sbdsp_wdsp(sc, SB_DSP_BLOCKSIZE) < 0 ||
1171 sbdsp_wdsp(sc, cc) < 0 ||
1172 sbdsp_wdsp(sc, cc >> 8) < 0) {
1173 DPRINTF(("sbdsp_dma_input: SB2 DMA start failed\n"));
1174 goto giveup;
1175 }
1176 if (sbdsp_wdsp(sc, sc->sc_imodep->cmd) < 0) {
1177 DPRINTF(("sbdsp_dma_input: SB2 DMA restart failed\n"));
1178 goto giveup;
1179 }
1180 } else {
1181 if (sbdsp_wdsp(sc, sc->sc_imodep->cmd) < 0 ||
1182 sbdsp_wdsp(sc, cc) < 0 ||
1183 sbdsp_wdsp(sc, cc >> 8) < 0) {
1184 DPRINTF(("sbdsp_dma_input: SB1 DMA start failed\n"));
1185 goto giveup;
1186 }
1187 }
1188 }
1189 return 0;
1190
1191 giveup:
1192 sbdsp_reset(sc);
1193 return EIO;
1194
1195 badmode:
1196 DPRINTF(("sbdsp_dma_input: can't set mode\n"));
1197 return EIO;
1198 }
1199
1200 int
1201 sbdsp_dma_output(addr, p, cc, intr, arg)
1202 void *addr;
1203 void *p;
1204 int cc;
1205 void (*intr) __P((void *));
1206 void *arg;
1207 {
1208 struct sbdsp_softc *sc = addr;
1209 int loop = sc->sc_model != SB_1;
1210 int stereo = sc->sc_omodep->channels == 2;
1211 int cmd;
1212
1213 #ifdef AUDIO_DEBUG
1214 if (sbdspdebug > 1)
1215 Dprintf("sbdsp_dma_output: cc=%d 0x%x (0x%x)\n", cc, intr, arg);
1216 #endif
1217 #ifdef DIAGNOSTIC
1218 if (sc->sc_omodep->channels == 2 && (cc & 1)) {
1219 DPRINTF(("stereo playback odd bytes (%d)\n", cc));
1220 return EIO;
1221 }
1222 #endif
1223
1224 if (sc->sc_dmadir != SB_DMA_OUT) {
1225 if (ISSBPRO(sc)) {
1226 /* make sure we re-set stereo mixer bit when we start
1227 output. */
1228 sbdsp_mix_write(sc, SBP_STEREO,
1229 (sbdsp_mix_read(sc, SBP_STEREO) & ~SBP_PLAYMODE_MASK) |
1230 (stereo ? SBP_PLAYMODE_STEREO : SBP_PLAYMODE_MONO));
1231 cmd = sc->sc_omodep->cmdchan;
1232 if (cmd && sbdsp_wdsp(sc, cmd) < 0)
1233 goto badmode;
1234 }
1235
1236 if (ISSB16CLASS(sc)) {
1237 if (sbdsp16_set_rate(sc, SB_DSP16_OUTPUTRATE,
1238 sc->sc_orate))
1239 goto giveup;
1240 } else {
1241 if (sbdsp_set_timeconst(sc, sc->sc_otc))
1242 goto giveup;
1243 }
1244
1245 sc->sc_dmadir = SB_DMA_OUT;
1246 sc->dmaflags = DMAMODE_WRITE;
1247 if (loop)
1248 sc->dmaflags |= DMAMODE_LOOP;
1249 } else {
1250 /* Already started; just return. */
1251 if (loop)
1252 return 0;
1253 }
1254
1255 sc->dmaaddr = p;
1256 sc->dmacnt = loop ? (NBPG/cc)*cc : cc;
1257 sc->dmachan = sc->sc_omodep->precision == 16 ? sc->sc_drq16 : sc->sc_drq8;
1258 #ifdef AUDIO_DEBUG
1259 if (sbdspdebug > 1)
1260 Dprintf("sbdsp_dma_output: dmastart %x %p %d %d\n",
1261 sc->dmaflags, sc->dmaaddr, sc->dmacnt, sc->dmachan);
1262 #endif
1263 isa_dmastart(sc->dmaflags, sc->dmaaddr, sc->dmacnt, sc->dmachan);
1264 sc->sc_intr = intr;
1265 sc->sc_arg = arg;
1266
1267 if (sc->sc_omodep->precision == 16)
1268 cc >>= 1;
1269 --cc;
1270 if (ISSB16CLASS(sc)) {
1271 if (sbdsp_wdsp(sc, sc->sc_omodep->cmd) < 0 ||
1272 sbdsp_wdsp(sc, sc->sc_obmode) < 0 ||
1273 sbdsp16_wait(sc) ||
1274 sbdsp_wdsp(sc, cc) < 0 ||
1275 sbdsp_wdsp(sc, cc >> 8) < 0) {
1276 DPRINTF(("sbdsp_dma_output: SB16 DMA start failed\n"));
1277 goto giveup;
1278 }
1279 } else {
1280 if (loop) {
1281 DPRINTF(("sbdsp_dma_output: set blocksize=%d\n", cc));
1282 if (sbdsp_wdsp(sc, SB_DSP_BLOCKSIZE) < 0 ||
1283 sbdsp_wdsp(sc, cc) < 0 ||
1284 sbdsp_wdsp(sc, cc >> 8) < 0) {
1285 DPRINTF(("sbdsp_dma_output: SB2 DMA blocksize failed\n"));
1286 goto giveup;
1287 }
1288 if (sbdsp_wdsp(sc, sc->sc_omodep->cmd) < 0) {
1289 DPRINTF(("sbdsp_dma_output: SB2 DMA start failed\n"));
1290 goto giveup;
1291 }
1292 } else {
1293 if (sbdsp_wdsp(sc, sc->sc_omodep->cmd) < 0 ||
1294 sbdsp_wdsp(sc, cc) < 0 ||
1295 sbdsp_wdsp(sc, cc >> 8) < 0) {
1296 DPRINTF(("sbdsp_dma_output: SB1 DMA start failed\n"));
1297 goto giveup;
1298 }
1299 }
1300 }
1301 return 0;
1302
1303 giveup:
1304 sbdsp_reset(sc);
1305 return EIO;
1306
1307 badmode:
1308 DPRINTF(("sbdsp_dma_output: can't set mode\n"));
1309 return EIO;
1310 }
1311
1312 /*
1313 * Only the DSP unit on the sound blaster generates interrupts.
1314 * There are three cases of interrupt: reception of a midi byte
1315 * (when mode is enabled), completion of dma transmission, or
1316 * completion of a dma reception. The three modes are mutually
1317 * exclusive so we know a priori which event has occurred.
1318 */
1319 int
1320 sbdsp_intr(arg)
1321 void *arg;
1322 {
1323 struct sbdsp_softc *sc = arg;
1324 int loop = sc->sc_model != SB_1;
1325 u_char irq;
1326
1327 #ifdef AUDIO_DEBUG
1328 if (sbdspdebug > 1)
1329 Dprintf("sbdsp_intr: intr=0x%x\n", sc->sc_intr);
1330 #endif
1331 if (ISSB16CLASS(sc)) {
1332 irq = sbdsp_mix_read(sc, SBP_IRQ_STATUS);
1333 if ((irq & (SBP_IRQ_DMA8 | SBP_IRQ_DMA16)) == 0)
1334 return 0;
1335 } else {
1336 if (!loop && !isa_dmafinished(sc->dmachan))
1337 return 0;
1338 irq = SBP_IRQ_DMA8;
1339 }
1340 sc->sc_interrupts++;
1341 delay(10); /* XXX why? */
1342 #if 0
1343 if (sc->sc_mintr != 0) {
1344 x = sbdsp_rdsp(sc);
1345 (*sc->sc_mintr)(sc->sc_arg, x);
1346 } else
1347 #endif
1348 if (sc->sc_intr != 0) {
1349 /* clear interrupt */
1350 if (irq & SBP_IRQ_DMA8)
1351 bus_space_read_1(sc->sc_iot, sc->sc_ioh, SBP_DSP_IRQACK8);
1352 if (irq & SBP_IRQ_DMA16)
1353 bus_space_read_1(sc->sc_iot, sc->sc_ioh, SBP_DSP_IRQACK16);
1354 if (!loop)
1355 isa_dmadone(sc->dmaflags, sc->dmaaddr, sc->dmacnt,
1356 sc->dmachan);
1357 (*sc->sc_intr)(sc->sc_arg);
1358 } else {
1359 return 0;
1360 }
1361 return 1;
1362 }
1363
1364 #if 0
1365 /*
1366 * Enter midi uart mode and arrange for read interrupts
1367 * to vector to `intr'. This puts the card in a mode
1368 * which allows only midi I/O; the card must be reset
1369 * to leave this mode. Unfortunately, the card does not
1370 * use transmit interrupts, so bytes must be output
1371 * using polling. To keep the polling overhead to a
1372 * minimum, output should be driven off a timer.
1373 * This is a little tricky since only 320us separate
1374 * consecutive midi bytes.
1375 */
1376 void
1377 sbdsp_set_midi_mode(sc, intr, arg)
1378 struct sbdsp_softc *sc;
1379 void (*intr)();
1380 void *arg;
1381 {
1382
1383 sbdsp_wdsp(sc, SB_MIDI_UART_INTR);
1384 sc->sc_mintr = intr;
1385 sc->sc_intr = 0;
1386 sc->sc_arg = arg;
1387 }
1388
1389 /*
1390 * Write a byte to the midi port, when in midi uart mode.
1391 */
1392 void
1393 sbdsp_midi_output(sc, v)
1394 struct sbdsp_softc *sc;
1395 int v;
1396 {
1397
1398 if (sbdsp_wdsp(sc, v) < 0)
1399 ++sberr.wmidi;
1400 }
1401 #endif
1402
1403 int
1404 sbdsp_setfd(addr, flag)
1405 void *addr;
1406 int flag;
1407 {
1408 /* Can't do full-duplex */
1409 return ENOTTY;
1410 }
1411
1412 void
1413 sbdsp_set_mixer_gain(sc, port)
1414 struct sbdsp_softc *sc;
1415 int port;
1416 {
1417 int src, gain;
1418
1419 switch(sc->sc_mixer_model) {
1420 case SBM_NONE:
1421 return;
1422 case SBM_CT1335:
1423 gain = SB_1335_GAIN(sc->gain[port][SB_LEFT]);
1424 switch(port) {
1425 case SB_MASTER_VOL:
1426 src = SBP_1335_MASTER_VOL;
1427 break;
1428 case SB_MIDI_VOL:
1429 src = SBP_1335_MIDI_VOL;
1430 break;
1431 case SB_CD_VOL:
1432 src = SBP_1335_CD_VOL;
1433 break;
1434 case SB_VOICE_VOL:
1435 src = SBP_1335_VOICE_VOL;
1436 gain = SB_1335_MASTER_GAIN(sc->gain[port][SB_LEFT]);
1437 break;
1438 default:
1439 return;
1440 }
1441 sbdsp_mix_write(sc, src, gain);
1442 break;
1443 case SBM_CT1345:
1444 gain = SB_STEREO_GAIN(sc->gain[port][SB_LEFT],
1445 sc->gain[port][SB_RIGHT]);
1446 switch (port) {
1447 case SB_MIC_VOL:
1448 src = SBP_MIC_VOL;
1449 gain = SB_MIC_GAIN(sc->gain[port][SB_LEFT]);
1450 break;
1451 case SB_MASTER_VOL:
1452 src = SBP_MASTER_VOL;
1453 break;
1454 case SB_LINE_IN_VOL:
1455 src = SBP_LINE_VOL;
1456 break;
1457 case SB_VOICE_VOL:
1458 src = SBP_VOICE_VOL;
1459 break;
1460 case SB_MIDI_VOL:
1461 src = SBP_MIDI_VOL;
1462 break;
1463 case SB_CD_VOL:
1464 src = SBP_CD_VOL;
1465 break;
1466 default:
1467 return;
1468 }
1469 sbdsp_mix_write(sc, src, gain);
1470 break;
1471 case SBM_CT1745:
1472 switch (port) {
1473 case SB_MIC_VOL:
1474 src = SB16P_MIC_L;
1475 break;
1476 case SB_MASTER_VOL:
1477 src = SB16P_MASTER_L;
1478 break;
1479 case SB_LINE_IN_VOL:
1480 src = SB16P_LINE_L;
1481 break;
1482 case SB_VOICE_VOL:
1483 src = SB16P_VOICE_L;
1484 break;
1485 case SB_MIDI_VOL:
1486 src = SB16P_MIDI_L;
1487 break;
1488 case SB_CD_VOL:
1489 src = SB16P_CD_L;
1490 break;
1491 case SB_INPUT_GAIN:
1492 src = SB16P_INPUT_GAIN_L;
1493 break;
1494 case SB_OUTPUT_GAIN:
1495 src = SB16P_OUTPUT_GAIN_L;
1496 break;
1497 case SB_TREBLE:
1498 src = SB16P_TREBLE_L;
1499 break;
1500 case SB_BASS:
1501 src = SB16P_BASS_L;
1502 break;
1503 case SB_PCSPEAKER:
1504 sbdsp_mix_write(sc, SB16P_PCSPEAKER, sc->gain[port][SB_LEFT]);
1505 return;
1506 default:
1507 return;
1508 }
1509 sbdsp_mix_write(sc, src, sc->gain[port][SB_LEFT]);
1510 sbdsp_mix_write(sc, SB16P_L_TO_R(src), sc->gain[port][SB_RIGHT]);
1511 break;
1512 }
1513 }
1514
1515 int
1516 sbdsp_mixer_set_port(addr, cp)
1517 void *addr;
1518 mixer_ctrl_t *cp;
1519 {
1520 struct sbdsp_softc *sc = addr;
1521 int lgain, rgain;
1522
1523 DPRINTF(("sbdsp_mixer_set_port: port=%d num_channels=%d\n", cp->dev,
1524 cp->un.value.num_channels));
1525
1526 if (sc->sc_mixer_model == SBM_NONE)
1527 return EINVAL;
1528
1529 switch (cp->dev) {
1530 case SB_TREBLE:
1531 case SB_BASS:
1532 if (sc->sc_mixer_model == SBM_CT1345) {
1533 if (cp->type != AUDIO_MIXER_ENUM)
1534 return EINVAL;
1535 switch (cp->dev) {
1536 case SB_TREBLE:
1537 sbdsp_set_ifilter(addr, cp->un.ord ? SB_TREBLE : 0);
1538 return 0;
1539 case SB_BASS:
1540 sbdsp_set_ifilter(addr, cp->un.ord ? SB_BASS : 0);
1541 return 0;
1542 }
1543 }
1544 case SB_PCSPEAKER:
1545 case SB_INPUT_GAIN:
1546 case SB_OUTPUT_GAIN:
1547 if (sc->sc_mixer_model != SBM_CT1745)
1548 return EINVAL;
1549 case SB_MIC_VOL:
1550 case SB_LINE_IN_VOL:
1551 if (sc->sc_mixer_model == SBM_CT1335)
1552 return EINVAL;
1553 case SB_VOICE_VOL:
1554 case SB_MIDI_VOL:
1555 case SB_CD_VOL:
1556 case SB_MASTER_VOL:
1557 if (cp->type != AUDIO_MIXER_VALUE)
1558 return EINVAL;
1559
1560 /*
1561 * All the mixer ports are stereo except for the microphone.
1562 * If we get a single-channel gain value passed in, then we
1563 * duplicate it to both left and right channels.
1564 */
1565
1566 switch (cp->dev) {
1567 case SB_MIC_VOL:
1568 if (cp->un.value.num_channels != 1)
1569 return EINVAL;
1570
1571 lgain = rgain = SB_ADJUST_MIC_GAIN(sc,
1572 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
1573 break;
1574 case SB_PCSPEAKER:
1575 if (cp->un.value.num_channels != 1)
1576 return EINVAL;
1577 /* fall into */
1578 case SB_INPUT_GAIN:
1579 case SB_OUTPUT_GAIN:
1580 lgain = rgain = SB_ADJUST_2_GAIN(sc,
1581 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
1582 break;
1583 default:
1584 switch (cp->un.value.num_channels) {
1585 case 1:
1586 lgain = rgain = SB_ADJUST_GAIN(sc,
1587 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
1588 break;
1589 case 2:
1590 if (sc->sc_mixer_model == SBM_CT1335)
1591 return EINVAL;
1592 lgain = SB_ADJUST_GAIN(sc,
1593 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]);
1594 rgain = SB_ADJUST_GAIN(sc,
1595 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
1596 break;
1597 default:
1598 return EINVAL;
1599 }
1600 break;
1601 }
1602 sc->gain[cp->dev][SB_LEFT] = lgain;
1603 sc->gain[cp->dev][SB_RIGHT] = rgain;
1604
1605 sbdsp_set_mixer_gain(sc, cp->dev);
1606 break;
1607
1608 case SB_RECORD_SOURCE:
1609 if (sc->sc_mixer_model == SBM_CT1745) {
1610 if (cp->type != AUDIO_MIXER_SET)
1611 return EINVAL;
1612 return sbdsp_set_in_ports(sc, cp->un.mask);
1613 } else {
1614 if (cp->type != AUDIO_MIXER_ENUM)
1615 return EINVAL;
1616 return sbdsp_set_in_port(sc, cp->un.ord);
1617 }
1618 break;
1619
1620 case SB_AGC:
1621 if (sc->sc_mixer_model != SBM_CT1745 || cp->type != AUDIO_MIXER_ENUM)
1622 return EINVAL;
1623 sbdsp_mix_write(sc, SB16P_AGC, cp->un.ord & 1);
1624 break;
1625
1626 default:
1627 return EINVAL;
1628 }
1629
1630 return 0;
1631 }
1632
1633 int
1634 sbdsp_mixer_get_port(addr, cp)
1635 void *addr;
1636 mixer_ctrl_t *cp;
1637 {
1638 struct sbdsp_softc *sc = addr;
1639
1640 DPRINTF(("sbdsp_mixer_get_port: port=%d\n", cp->dev));
1641
1642 if (sc->sc_mixer_model == SBM_NONE)
1643 return EINVAL;
1644
1645 switch (cp->dev) {
1646 case SB_TREBLE:
1647 case SB_BASS:
1648 if (sc->sc_mixer_model == SBM_CT1345) {
1649 switch (cp->dev) {
1650 case SB_TREBLE:
1651 cp->un.ord = sbdsp_get_ifilter(addr) == SB_TREBLE;
1652 return 0;
1653 case SB_BASS:
1654 cp->un.ord = sbdsp_get_ifilter(addr) == SB_BASS;
1655 return 0;
1656 }
1657 }
1658 case SB_PCSPEAKER:
1659 case SB_INPUT_GAIN:
1660 case SB_OUTPUT_GAIN:
1661 if (sc->sc_mixer_model != SBM_CT1745)
1662 return EINVAL;
1663 case SB_MIC_VOL:
1664 case SB_LINE_IN_VOL:
1665 if (sc->sc_mixer_model == SBM_CT1335)
1666 return EINVAL;
1667 case SB_VOICE_VOL:
1668 case SB_MIDI_VOL:
1669 case SB_CD_VOL:
1670 case SB_MASTER_VOL:
1671 switch (cp->dev) {
1672 case SB_MIC_VOL:
1673 case SB_PCSPEAKER:
1674 if (cp->un.value.num_channels != 1)
1675 return EINVAL;
1676 /* fall into */
1677 default:
1678 switch (cp->un.value.num_channels) {
1679 case 1:
1680 cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
1681 sc->gain[cp->dev][SB_LEFT];
1682 break;
1683 case 2:
1684 cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
1685 sc->gain[cp->dev][SB_LEFT];
1686 cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
1687 sc->gain[cp->dev][SB_RIGHT];
1688 break;
1689 default:
1690 return EINVAL;
1691 }
1692 break;
1693 }
1694 break;
1695
1696 case SB_RECORD_SOURCE:
1697 if (sc->sc_mixer_model == SBM_CT1745)
1698 cp->un.mask = sc->in_mask;
1699 else
1700 cp->un.ord = sc->in_port;
1701 break;
1702
1703 case SB_AGC:
1704 if (sc->sc_mixer_model != SBM_CT1745)
1705 return EINVAL;
1706 cp->un.ord = sbdsp_mix_read(sc, SB16P_AGC);
1707 break;
1708
1709 default:
1710 return EINVAL;
1711 }
1712
1713 return 0;
1714 }
1715
1716 int
1717 sbdsp_mixer_query_devinfo(addr, dip)
1718 void *addr;
1719 mixer_devinfo_t *dip;
1720 {
1721 struct sbdsp_softc *sc = addr;
1722 int chan, class;
1723
1724 DPRINTF(("sbdsp_mixer_query_devinfo: model=%d index=%d\n",
1725 sc->sc_mixer_model, dip->index));
1726
1727 if (sc->sc_mixer_model == SBM_NONE)
1728 return ENXIO;
1729
1730 chan = sc->sc_mixer_model == SBM_CT1335 ? 1 : 2;
1731 class = sc->sc_mixer_model == SBM_CT1745 ? SB_INPUT_CLASS : SB_OUTPUT_CLASS;
1732
1733 switch (dip->index) {
1734 case SB_MASTER_VOL:
1735 dip->type = AUDIO_MIXER_VALUE;
1736 dip->mixer_class = SB_OUTPUT_CLASS;
1737 dip->prev = dip->next = AUDIO_MIXER_LAST;
1738 strcpy(dip->label.name, AudioNmaster);
1739 dip->un.v.num_channels = chan;
1740 strcpy(dip->un.v.units.name, AudioNvolume);
1741 return 0;
1742 case SB_MIDI_VOL:
1743 dip->type = AUDIO_MIXER_VALUE;
1744 dip->mixer_class = class;
1745 dip->prev = AUDIO_MIXER_LAST;
1746 dip->next = AUDIO_MIXER_LAST;
1747 strcpy(dip->label.name, AudioNfmsynth);
1748 dip->un.v.num_channels = chan;
1749 strcpy(dip->un.v.units.name, AudioNvolume);
1750 return 0;
1751 case SB_CD_VOL:
1752 dip->type = AUDIO_MIXER_VALUE;
1753 dip->mixer_class = class;
1754 dip->prev = AUDIO_MIXER_LAST;
1755 dip->next = AUDIO_MIXER_LAST;
1756 strcpy(dip->label.name, AudioNcd);
1757 dip->un.v.num_channels = chan;
1758 strcpy(dip->un.v.units.name, AudioNvolume);
1759 return 0;
1760 case SB_VOICE_VOL:
1761 dip->type = AUDIO_MIXER_VALUE;
1762 dip->mixer_class = class;
1763 dip->prev = AUDIO_MIXER_LAST;
1764 dip->next = AUDIO_MIXER_LAST;
1765 strcpy(dip->label.name, AudioNdac);
1766 dip->un.v.num_channels = chan;
1767 strcpy(dip->un.v.units.name, AudioNvolume);
1768 return 0;
1769 case SB_OUTPUT_CLASS:
1770 dip->type = AUDIO_MIXER_CLASS;
1771 dip->mixer_class = SB_OUTPUT_CLASS;
1772 dip->next = dip->prev = AUDIO_MIXER_LAST;
1773 strcpy(dip->label.name, AudioCOutputs);
1774 return 0;
1775 }
1776
1777 if (sc->sc_mixer_model == SBM_CT1335)
1778 return ENXIO;
1779
1780 switch (dip->index) {
1781 case SB_MIC_VOL:
1782 dip->type = AUDIO_MIXER_VALUE;
1783 dip->mixer_class = class;
1784 dip->prev = AUDIO_MIXER_LAST;
1785 dip->next = AUDIO_MIXER_LAST;
1786 strcpy(dip->label.name, AudioNmicrophone);
1787 dip->un.v.num_channels = 1;
1788 strcpy(dip->un.v.units.name, AudioNvolume);
1789 return 0;
1790
1791 case SB_LINE_IN_VOL:
1792 dip->type = AUDIO_MIXER_VALUE;
1793 dip->mixer_class = class;
1794 dip->prev = AUDIO_MIXER_LAST;
1795 dip->next = AUDIO_MIXER_LAST;
1796 strcpy(dip->label.name, AudioNline);
1797 dip->un.v.num_channels = 2;
1798 strcpy(dip->un.v.units.name, AudioNvolume);
1799 return 0;
1800
1801 case SB_RECORD_SOURCE:
1802 dip->mixer_class = SB_RECORD_CLASS;
1803 dip->prev = dip->next = AUDIO_MIXER_LAST;
1804 strcpy(dip->label.name, AudioNsource);
1805 if (sc->sc_mixer_model == SBM_CT1745) {
1806 dip->type = AUDIO_MIXER_SET;
1807 dip->un.s.num_mem = 4;
1808 strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
1809 dip->un.s.member[0].mask = 1 << SB_MIC_VOL;
1810 strcpy(dip->un.s.member[1].label.name, AudioNcd);
1811 dip->un.s.member[1].mask = 1 << SB_CD_VOL;
1812 strcpy(dip->un.s.member[2].label.name, AudioNline);
1813 dip->un.s.member[2].mask = 1 << SB_LINE_IN_VOL;
1814 strcpy(dip->un.s.member[3].label.name, AudioNfmsynth);
1815 dip->un.s.member[3].mask = 1 << SB_MIDI_VOL;
1816 } else {
1817 dip->type = AUDIO_MIXER_ENUM;
1818 dip->un.e.num_mem = 3;
1819 strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
1820 dip->un.e.member[0].ord = SB_MIC_VOL;
1821 strcpy(dip->un.e.member[1].label.name, AudioNcd);
1822 dip->un.e.member[1].ord = SB_CD_VOL;
1823 strcpy(dip->un.e.member[2].label.name, AudioNline);
1824 dip->un.e.member[2].ord = SB_LINE_IN_VOL;
1825 }
1826 return 0;
1827
1828 case SB_BASS:
1829 dip->prev = dip->next = AUDIO_MIXER_LAST;
1830 strcpy(dip->label.name, AudioNbass);
1831 if (sc->sc_mixer_model == SBM_CT1745) {
1832 dip->type = AUDIO_MIXER_VALUE;
1833 dip->mixer_class = SB_EQUALIZATION_CLASS;
1834 dip->un.v.num_channels = 2;
1835 strcpy(dip->un.v.units.name, AudioNbass);
1836 } else {
1837 dip->type = AUDIO_MIXER_ENUM;
1838 dip->mixer_class = SB_INPUT_CLASS;
1839 dip->un.e.num_mem = 2;
1840 strcpy(dip->un.e.member[0].label.name, AudioNoff);
1841 dip->un.e.member[0].ord = 0;
1842 strcpy(dip->un.e.member[1].label.name, AudioNon);
1843 dip->un.e.member[1].ord = 1;
1844 }
1845 return 0;
1846
1847 case SB_TREBLE:
1848 dip->prev = dip->next = AUDIO_MIXER_LAST;
1849 strcpy(dip->label.name, AudioNtreble);
1850 if (sc->sc_mixer_model == SBM_CT1745) {
1851 dip->type = AUDIO_MIXER_VALUE;
1852 dip->mixer_class = SB_EQUALIZATION_CLASS;
1853 dip->un.v.num_channels = 2;
1854 strcpy(dip->un.v.units.name, AudioNtreble);
1855 } else {
1856 dip->type = AUDIO_MIXER_ENUM;
1857 dip->mixer_class = SB_INPUT_CLASS;
1858 dip->un.e.num_mem = 2;
1859 strcpy(dip->un.e.member[0].label.name, AudioNoff);
1860 dip->un.e.member[0].ord = 0;
1861 strcpy(dip->un.e.member[1].label.name, AudioNon);
1862 dip->un.e.member[1].ord = 1;
1863 }
1864 return 0;
1865
1866 case SB_RECORD_CLASS: /* record source class */
1867 dip->type = AUDIO_MIXER_CLASS;
1868 dip->mixer_class = SB_RECORD_CLASS;
1869 dip->next = dip->prev = AUDIO_MIXER_LAST;
1870 strcpy(dip->label.name, AudioCRecord);
1871 return 0;
1872
1873 }
1874
1875 if (sc->sc_mixer_model == SBM_CT1345)
1876 return ENXIO;
1877
1878 switch(dip->index) {
1879 case SB_PCSPEAKER:
1880 dip->type = AUDIO_MIXER_VALUE;
1881 dip->mixer_class = SB_INPUT_CLASS;
1882 dip->prev = dip->next = AUDIO_MIXER_LAST;
1883 strcpy(dip->label.name, "pc_speaker");
1884 dip->un.v.num_channels = 1;
1885 strcpy(dip->un.v.units.name, AudioNvolume);
1886 return 0;
1887
1888 case SB_INPUT_GAIN:
1889 dip->type = AUDIO_MIXER_VALUE;
1890 dip->mixer_class = SB_INPUT_CLASS;
1891 dip->prev = dip->next = AUDIO_MIXER_LAST;
1892 strcpy(dip->label.name, AudioNinput);
1893 dip->un.v.num_channels = 2;
1894 strcpy(dip->un.v.units.name, AudioNvolume);
1895 return 0;
1896
1897 case SB_OUTPUT_GAIN:
1898 dip->type = AUDIO_MIXER_VALUE;
1899 dip->mixer_class = SB_OUTPUT_CLASS;
1900 dip->prev = dip->next = AUDIO_MIXER_LAST;
1901 strcpy(dip->label.name, AudioNoutput);
1902 dip->un.v.num_channels = 2;
1903 strcpy(dip->un.v.units.name, AudioNvolume);
1904 return 0;
1905
1906 case SB_AGC:
1907 dip->type = AUDIO_MIXER_ENUM;
1908 dip->mixer_class = SB_INPUT_CLASS;
1909 dip->prev = dip->next = AUDIO_MIXER_LAST;
1910 strcpy(dip->label.name, "AGC");
1911 dip->un.e.num_mem = 2;
1912 strcpy(dip->un.e.member[0].label.name, AudioNoff);
1913 dip->un.e.member[0].ord = 0;
1914 strcpy(dip->un.e.member[1].label.name, AudioNon);
1915 dip->un.e.member[1].ord = 1;
1916 return 0;
1917
1918 case SB_INPUT_CLASS:
1919 dip->type = AUDIO_MIXER_CLASS;
1920 dip->mixer_class = SB_INPUT_CLASS;
1921 dip->next = dip->prev = AUDIO_MIXER_LAST;
1922 strcpy(dip->label.name, AudioCInputs);
1923 return 0;
1924
1925 case SB_EQUALIZATION_CLASS:
1926 dip->type = AUDIO_MIXER_CLASS;
1927 dip->mixer_class = SB_EQUALIZATION_CLASS;
1928 dip->next = dip->prev = AUDIO_MIXER_LAST;
1929 strcpy(dip->label.name, AudioCEqualization);
1930 return 0;
1931 }
1932
1933 return ENXIO;
1934 }
1935