interwave.c revision 1.23.2.2 1 /* $NetBSD: interwave.c,v 1.23.2.2 2005/01/03 16:40:26 kent Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Author: Kari Mettinen
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: interwave.c,v 1.23.2.2 2005/01/03 16:40:26 kent Exp $");
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/errno.h>
44 #include <sys/ioctl.h>
45 #include <sys/syslog.h>
46 #include <sys/device.h>
47 #include <sys/proc.h>
48 #include <sys/buf.h>
49 #include <sys/fcntl.h>
50 #include <sys/malloc.h>
51 #include <sys/kernel.h>
52
53 #include <machine/cpu.h>
54 #include <machine/intr.h>
55 #include <machine/pio.h>
56 #include <sys/audioio.h>
57 #include <dev/audio_if.h>
58 #include <dev/mulaw.h>
59
60 #include <dev/isa/isavar.h>
61 #include <dev/isa/isadmavar.h>
62
63 #include <dev/ic/interwavereg.h>
64 #include <dev/ic/interwavevar.h>
65
66
67 static void iwreset __P((struct iw_softc *, int));
68
69 static int iw_set_speed __P((struct iw_softc *, u_long, char));
70 static u_long iw_set_format __P((struct iw_softc *, u_long, int));
71 static void iw_mixer_line_level __P((struct iw_softc *, int, int, int));
72 static void iw_trigger_dma __P((struct iw_softc *, u_char));
73 static void iw_stop_dma __P((struct iw_softc *, u_char, u_char));
74 static void iw_dma_count __P((struct iw_softc *, u_short, int));
75 static int iwintr __P((void *));
76 static void iw_meminit __P((struct iw_softc *));
77 static void iw_mempoke __P((struct iw_softc *, u_long, u_char));
78 static u_char iw_mempeek __P((struct iw_softc *, u_long));
79
80 #ifdef USE_WAVETABLE
81 static void iw_set_voice_place __P((struct iw_softc *, u_char, u_long));
82 static void iw_voice_pan __P((struct iw_softc *, u_char, u_short, u_short));
83 static void iw_voice_freq __P((struct iw_softc *, u_char, u_long));
84 static void iw_set_loopmode __P((struct iw_softc *, u_char, u_char, u_char));
85 static void iw_set_voice_pos __P((struct iw_softc *, u_short, u_long, u_long));
86 static void iw_start_voice __P((struct iw_softc *, u_char));
87 static void iw_play_voice __P((struct iw_softc *, u_long, u_long, u_short));
88 static void iw_stop_voice __P((struct iw_softc *, u_char));
89 static void iw_move_voice_end __P((struct iw_softc *, u_short, u_long));
90 static void iw_initvoices __P((struct iw_softc *));
91 #endif
92
93 struct audio_device iw_device = {
94 "Am78C201",
95 "0.1",
96 "guspnp"
97 };
98
99 #ifdef AUDIO_DEBUG
100 int iw_debug;
101 #define DPRINTF(p) if (iw_debug) printf p
102 #else
103 #define DPRINTF(p)
104 #endif
105
106 static int iw_cc = 1;
107 #ifdef DIAGNOSTIC
108 static int outputs = 0;
109 static int iw_ints = 0;
110 static int inputs = 0;
111 static int iw_inints = 0;
112 #endif
113
114 int
115 iwintr(arg)
116 void *arg;
117 {
118 struct iw_softc *sc = arg;
119 int val = 0;
120 u_char intrs = 0;
121
122 IW_READ_DIRECT_1(6, sc->p2xr_h, intrs); /* UISR */
123
124 /* codec ints */
125
126 /*
127 * The proper order to do this seems to be to read CSR3 to get the
128 * int cause and fifo over underrrun status, then deal with the ints
129 * (new DMA set up), and to clear ints by writing the respective bit
130 * to 0.
131 */
132
133 /* read what ints happened */
134
135 IW_READ_CODEC_1(CSR3I, intrs);
136
137 /* clear them */
138
139 IW_WRITE_DIRECT_1(2, sc->codec_index_h, 0x00);
140
141 /* and process them */
142
143 if (intrs & 0x20) {
144 #ifdef DIAGNOSTIC
145 iw_inints++;
146 #endif
147 if (sc->sc_recintr != 0)
148 sc->sc_recintr(sc->sc_recarg);
149 val = 1;
150 }
151 if (intrs & 0x10) {
152 #ifdef DIAGNOSTIC
153 iw_ints++;
154 #endif
155 if (sc->sc_playintr != 0)
156 sc->sc_playintr(sc->sc_playarg);
157 val = 1;
158 }
159 return val;
160
161 }
162
163 void
164 iwattach(sc)
165 struct iw_softc *sc;
166 {
167 int got_irq = 0;
168
169 DPRINTF(("iwattach sc %p\n", sc));
170
171 sc->cdatap = 1; /* relative offsets in region */
172 sc->csr1r = 2;
173 sc->cxdr = 3; /* CPDR or CRDR */
174
175 sc->gmxr = 0; /* sc->p3xr */
176 sc->gmxdr = 1; /* GMTDR or GMRDR */
177 sc->svsr = 2;
178 sc->igidxr = 3;
179 sc->i16dp = 4;
180 sc->i8dp = 5;
181 sc->lmbdr = 7;
182
183 sc->rec_precision = sc->play_precision = 8;
184 sc->rec_channels = sc->play_channels = 1;
185 sc->rec_encoding = sc->play_encoding = AUDIO_ENCODING_ULAW;
186 sc->sc_irate = 8000;
187 sc->sc_orate = 8000;
188
189 sc->sc_fullduplex = 1;
190
191 sc->sc_dma_flags = 0;
192
193 /*
194 * We can only use a few selected irqs, see if we got one from pnp
195 * code that suits us.
196 */
197
198 if (sc->sc_irq > 0) {
199 sc->sc_ih = isa_intr_establish(sc->sc_p2xr_ic,
200 sc->sc_irq,
201 IST_EDGE, IPL_AUDIO, iwintr, sc);
202 got_irq = 1;
203 }
204 if (!got_irq) {
205 printf("\niwattach: couldn't get a suitable irq\n");
206 return;
207 }
208 printf("\n");
209 iwreset(sc, 0);
210 iw_set_format(sc, AUDIO_ENCODING_ULAW, 0);
211 iw_set_format(sc, AUDIO_ENCODING_ULAW, 1);
212 printf("%s: interwave version %s\n",
213 sc->sc_dev.dv_xname, iw_device.version);
214 audio_attach_mi(sc->iw_hw_if, sc, &sc->sc_dev);
215 }
216
217 int
218 iwopen(sc, flags)
219 struct iw_softc *sc;
220 int flags;
221 {
222
223 DPRINTF(("iwopen: sc %p\n", sc));
224
225 #ifdef DIAGNOSTIC
226 outputs = 0;
227 iw_ints = 0;
228 inputs = 0;
229 iw_inints = 0;
230 #endif
231
232 iwreset(sc, 1);
233
234 return 0;
235 }
236
237
238
239 void
240 iwclose(addr)
241 void *addr;
242 {
243 DPRINTF(("iwclose sc %p\n", addr));
244
245 #ifdef DIAGNOSTIC
246 DPRINTF(("iwclose: outputs %d ints %d inputs %d in_ints %d\n",
247 outputs, iw_ints, inputs, iw_inints));
248 #endif
249 }
250
251 #define RAM_STEP 64*1024
252
253 static void
254 iw_mempoke(sc, addy, val)
255 struct iw_softc *sc;
256 u_long addy;
257 u_char val;
258 {
259 IW_WRITE_GENERAL_2(LMALI, (u_short) addy);
260 IW_WRITE_GENERAL_1(LMAHI, (u_char) (addy >> 16));
261
262 /* Write byte to LMBDR */
263 IW_WRITE_DIRECT_1(sc->p3xr + 7, sc->p3xr_h, val);
264 }
265
266 static u_char
267 iw_mempeek(sc, addy)
268 struct iw_softc *sc;
269 u_long addy;
270 {
271 u_char ret;
272
273 IW_WRITE_GENERAL_2(LMALI, (u_short) addy);
274 IW_WRITE_GENERAL_1(LMAHI, (u_char) (addy >> 16));
275
276 IW_READ_DIRECT_1(sc->p3xr + 7, sc->p3xr_h, ret);
277 return ret; /* return byte from LMBDR */
278 }
279
280 static void
281 iw_meminit(sc)
282 struct iw_softc *sc;
283 {
284 u_long bank[4] = {0L, 0L, 0L, 0L};
285 u_long addr = 0L, base = 0L, cnt = 0L;
286 u_char i, ram = 0 /* ,memval=0 */ ;
287 u_short lmcfi;
288 u_long temppi;
289 u_long *lpbanks = &temppi;
290
291 IW_WRITE_GENERAL_1(LDMACI, 0x00);
292
293 IW_READ_GENERAL_2(LMCFI, lmcfi); /* 0x52 */
294 lmcfi |= 0x0A0C;
295 IW_WRITE_GENERAL_2(LMCFI, lmcfi); /* max addr span */
296 IW_WRITE_GENERAL_1(LMCI, 0x00);
297
298 /* fifo addresses */
299
300 IW_WRITE_GENERAL_2(LMRFAI, ((4 * 1024 * 1024) >> 8));
301 IW_WRITE_GENERAL_2(LMPFAI, ((4 * 1024 * 1024 + 16 * 1024) >> 8));
302
303 IW_WRITE_GENERAL_2(LMFSI, 0x000);
304
305 IW_WRITE_GENERAL_2(LDICI, 0x0000);
306
307 while (addr < (16 * 1024 * 1024)) {
308 iw_mempoke(sc, addr, 0x00);
309 addr += RAM_STEP;
310 }
311
312 printf("%s:", sc->sc_dev.dv_xname);
313
314 for (i = 0; i < 4; i++) {
315 iw_mempoke(sc, base, 0xAA); /* mark start of bank */
316 iw_mempoke(sc, base + 1L, 0x55);
317 if (iw_mempeek(sc, base) == 0xAA &&
318 iw_mempeek(sc, base + 1L) == 0x55)
319 ram = 1;
320 if (ram) {
321 while (cnt < (4 * 1024 * 1024)) {
322 bank[i] += RAM_STEP;
323 cnt += RAM_STEP;
324 addr = base + cnt;
325 if (iw_mempeek(sc, addr) == 0xAA)
326 break;
327 }
328 }
329 if (lpbanks != NULL) {
330 *lpbanks = bank[i];
331 lpbanks++;
332 }
333 bank[i] = bank[i] >> 10;
334 printf("%s bank[%d]: %ldK", i ? "," : "", i, bank[i]);
335 base += 4 * 1024 * 1024;
336 cnt = 0L;
337 ram = 0;
338 }
339
340 printf("\n");
341
342 /*
343 * this is not really useful since GUS PnP supports memory
344 * configurations that aren't really supported by Interwave...beware
345 * of holes! Also, we don't use the memory for anything in this
346 * version of the driver.
347 *
348 * we've configured for 4M-4M-4M-4M
349 */
350 }
351
352
353 static
354 void
355 iwreset(sc, warm)
356 struct iw_softc *sc;
357 int warm;
358 {
359 u_char reg, cmode, val = 0, mixer_image = 0;
360
361 reg = 0; /* XXX gcc -Wall */
362
363 cmode = 0x6c; /* enhanced codec mode (full duplex) */
364
365 /* reset */
366
367 IW_WRITE_GENERAL_1(URSTI, 0x00);
368 delay(10);
369 IW_WRITE_GENERAL_1(URSTI, 0x07);
370 IW_WRITE_GENERAL_1(ICMPTI, 0x1f); /* disable DSP and uici and
371 * udci writes */
372 IW_WRITE_GENERAL_1(IDECI, 0x7f); /* enable ints to ISA and
373 * codec access */
374 IW_READ_GENERAL_1(IVERI, reg);
375 IW_WRITE_GENERAL_1(IVERI, reg | 0x01); /* hidden reg lock disable */
376 IW_WRITE_GENERAL_1(UASBCI, 0x00);
377
378 /* synth enhanced mode (default), 0 active voices, disable ints */
379
380 IW_WRITE_GENERAL_1(SGMI_WR, 0x01); /* enhanced mode, LFOs
381 * disabled */
382 for (val = 0; val < 32; val++) {
383 /* set each synth sound volume to 0 */
384 IW_WRITE_DIRECT_1(sc->p3xr + 2, sc->p3xr_h, val);
385 IW_WRITE_GENERAL_1(SVSI_WR, 0x00);
386 IW_WRITE_GENERAL_2(SASLI_WR, 0x0000);
387 IW_WRITE_GENERAL_2(SASHI_WR, 0x0000);
388 IW_WRITE_GENERAL_2(SAELI_WR, 0x0000);
389 IW_WRITE_GENERAL_2(SAEHI_WR, 0x0000);
390 IW_WRITE_GENERAL_2(SFCI_WR, 0x0000);
391 IW_WRITE_GENERAL_1(SACI_WR, 0x02);
392 IW_WRITE_GENERAL_1(SVSI_WR, 0x00);
393 IW_WRITE_GENERAL_1(SVEI_WR, 0x00);
394 IW_WRITE_GENERAL_2(SVLI_WR, 0x0000);
395 IW_WRITE_GENERAL_1(SVCI_WR, 0x02);
396 IW_WRITE_GENERAL_1(SMSI_WR, 0x02);
397 }
398
399 IW_WRITE_GENERAL_1(SAVI_WR, 0x00);
400
401 /* codec mode/init */
402
403 /* first change mode to 1 */
404
405 IW_WRITE_CODEC_1(CMODEI, 0x00);
406
407 /* and mode 3 */
408
409 IW_WRITE_CODEC_1(CMODEI, cmode);
410
411 IW_READ_CODEC_1(CMODEI, reg);
412
413 DPRINTF(("cmode %x\n", reg));
414
415 sc->revision = ((reg & 0x80) >> 3) | (reg & 0x0f);
416
417 IW_WRITE_DIRECT_1(sc->codec_index + 2, sc->p2xr_h, 0x00);
418
419 IW_WRITE_CODEC_1(CFIG1I | IW_MCE, 0x00); /* DMA 2 chan access */
420 IW_WRITE_CODEC_1(CEXTI, 0x00); /* disable ints for now */
421
422
423 IW_WRITE_CODEC_1(CLPCTI, 0x00); /* reset playback sample counters */
424 IW_WRITE_CODEC_1(CUPCTI, 0x00); /* always upper byte last */
425 IW_WRITE_CODEC_1(CFIG2I, 0x80); /* full voltage range, enable record
426 * and playback sample counters, and
427 * don't center output in case or
428 * FIFO underrun */
429 IW_WRITE_CODEC_1(CFIG3I, 0xc0); /* enable record/playback irq (still
430 * turned off from CEXTI), max DMA
431 * rate */
432 IW_WRITE_CODEC_1(CSR3I, 0x00); /* clear status 3 reg */
433
434
435 IW_WRITE_CODEC_1(CLRCTI, 0x00); /* reset record sample counters */
436 IW_WRITE_CODEC_1(CURCTI, 0x00); /* always upper byte last */
437
438
439 IW_READ_GENERAL_1(IVERI, reg);
440
441 sc->vers = reg >> 4;
442 if (!warm)
443 snprintf(iw_device.version, sizeof(iw_device.version), "%d.%d",
444 sc->vers, sc->revision);
445
446 IW_WRITE_GENERAL_1(IDECI, 0x7f); /* irqs and codec decode
447 * enable */
448
449
450 /* ports */
451
452 if (!warm) {
453 iw_mixer_line_level(sc, IW_LINE_OUT, 255, 255);
454 iw_mixer_line_level(sc, IW_LINE_IN, 0, 0);
455 iw_mixer_line_level(sc, IW_AUX1, 0, 0);
456 iw_mixer_line_level(sc, IW_AUX2, 200, 200); /* CD */
457 sc->sc_dac.off = 0;
458 iw_mixer_line_level(sc, IW_DAC, 200, 200);
459
460 iw_mixer_line_level(sc, IW_MIC_IN, 0, 0);
461 iw_mixer_line_level(sc, IW_REC, 0, 0);
462 iw_mixer_line_level(sc, IW_LOOPBACK, 0, 0);
463 iw_mixer_line_level(sc, IW_MONO_IN, 0, 0);
464
465 /* mem stuff */
466 iw_meminit(sc);
467
468 }
469 IW_WRITE_CODEC_1(CEXTI, 0x02); /* codec int enable */
470
471 /* clear _LDMACI */
472
473 IW_WRITE_GENERAL_1(LDMACI, 0x00);
474
475 /* enable mixer paths */
476 mixer_image = 0x0c;
477 IW_WRITE_DIRECT_1(sc->p2xr, sc->p2xr_h, mixer_image);
478 /*
479 * enable output, line in. disable mic in bit 0 = 0 -> line in on
480 * (from codec?) bit 1 = 0 -> output on bit 2 = 1 -> mic in on bit 3
481 * = 1 -> irq&drq pin enable bit 4 = 1 -> channel interrupts to chan
482 * 1 bit 5 = 1 -> enable midi loop back bit 6 = 0 -> irq latches
483 * URCR[2:0] bit 6 = 1 -> DMA latches URCR[2:0]
484 */
485
486
487 IW_READ_DIRECT_1(sc->p2xr, sc->p2xr_h, mixer_image);
488 #ifdef AUDIO_DEBUG
489 if (!warm)
490 DPRINTF(("mix image %x \n", mixer_image));
491 #endif
492 }
493
494 struct iw_codec_freq {
495 u_long freq;
496 u_char bits;
497 };
498
499 int
500 iw_set_speed(sc, freq, in)
501 struct iw_softc *sc;
502 u_long freq;
503 char in;
504 {
505 u_char var, cfig3, reg;
506
507 static struct iw_codec_freq iw_cf[17] = {
508 #define FREQ_1 24576000
509 #define FREQ_2 16934400
510 #define XTAL1 0
511 #define XTAL2 1
512 {5510, 0x00 | XTAL2}, {6620, 0x0E | XTAL2},
513 {8000, 0x00 | XTAL1}, {9600, 0x0E | XTAL1},
514 {11025, 0x02 | XTAL2}, {16000, 0x02 | XTAL1},
515 {18900, 0x04 | XTAL2}, {22050, 0x06 | XTAL2},
516 {27420, 0x04 | XTAL1}, {32000, 0x06 | XTAL1},
517 {33075, 0x0C | XTAL2}, {37800, 0x08 | XTAL2},
518 {38400, 0x0A | XTAL1}, {44100, 0x0A | XTAL2},
519 {44800, 0x08 | XTAL1}, {48000, 0x0C | XTAL1},
520 {48000, 0x0C | XTAL1} /* really a dummy for indexing later */
521 #undef XTAL1
522 #undef XTAL2
523 };
524
525 cfig3 = 0; /* XXX gcc -Wall */
526
527 /*
528 * if the frequency is between 3493Hz and 32KHz we can use a more
529 * accurate frequency than the ones listed above base on the formula
530 * FREQ/((16*(48+x))) where FREQ is either FREQ_1 (24576000Hz) or
531 * FREQ_2 (16934400Hz) and x is the value to be written to either
532 * CPVFI or CRVFI. To enable this option, bit 2 in CFIG3 needs to be
533 * set high
534 *
535 * NOT IMPLEMENTED!
536 *
537 * Note that if you have a 'bad' XTAL_1 (higher than 18.5 MHz), 44.8KHz
538 * and 38.4KHz modes will provide wrong frequencies to output.
539 */
540
541
542 if (freq > 48000)
543 freq = 48000;
544 if (freq < 5510)
545 freq = 5510;
546
547 /* reset CFIG3[2] */
548
549 IW_READ_CODEC_1(CFIG3I, cfig3);
550
551 cfig3 |= 0xc0; /* not full fifo treshhold */
552
553 DPRINTF(("cfig3i = %x -> ", cfig3));
554
555 cfig3 &= ~0x04;
556 IW_WRITE_CODEC_1(CFIG3I, cfig3);
557 IW_READ_CODEC_1(CFIG3I, cfig3);
558
559 DPRINTF(("%x\n", cfig3));
560
561 for (var = 0; var < 16; var++) /* select closest frequency */
562 if (freq <= iw_cf[var].freq)
563 break;
564 if (var != 16)
565 if (abs(freq - iw_cf[var].freq) > abs(iw_cf[var + 1].freq - freq))
566 var++;
567
568 if (in)
569 IW_WRITE_CODEC_1(CRDFI | IW_MCE, sc->recfmtbits | iw_cf[var].bits);
570 else
571 IW_WRITE_CODEC_1(CPDFI | IW_MCE, sc->playfmtbits | iw_cf[var].bits);
572 freq = iw_cf[var].freq;
573 DPRINTF(("setting %s frequency to %d bits %x \n",
574 in ? "in" : "out", (int) freq, iw_cf[var].bits));
575
576 IW_READ_CODEC_1(CPDFI, reg);
577
578 DPRINTF((" CPDFI %x ", reg));
579
580 IW_READ_CODEC_1(CRDFI, reg);
581
582 DPRINTF((" CRDFI %x ", reg));
583
584 return freq;
585 }
586
587 /* Encoding. */
588 int
589 iw_query_encoding(addr, fp)
590 void *addr;
591 struct audio_encoding *fp;
592 {
593 /*
594 * LINEAR, ALAW, ULAW, ADPCM in HW, we'll use linear unsigned
595 * hardware mode for all 8-bit modes due to buggy (?) codec.
596 */
597
598 /*
599 * except in wavetable synth. there we have only mu-law and 8 and 16
600 * bit linear data
601 */
602
603 switch (fp->index) {
604 case 0:
605 strcpy(fp->name, AudioEulinear);
606 fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
607 fp->precision = 8;
608 fp->flags = 0;
609 break;
610 case 1:
611 strcpy(fp->name, AudioEmulaw);
612 fp->encoding = AUDIO_ENCODING_ULAW;
613 fp->precision = 8;
614 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
615 break;
616 case 2:
617 strcpy(fp->name, AudioEalaw);
618 fp->encoding = AUDIO_ENCODING_ALAW;
619 fp->precision = 8;
620 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
621 break;
622 case 3:
623 strcpy(fp->name, AudioEadpcm);
624 fp->encoding = AUDIO_ENCODING_ADPCM;
625 fp->precision = 8; /* really 4 bit */
626 fp->flags = 0;
627 break;
628 case 4:
629 strcpy(fp->name, AudioEslinear_le);
630 fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
631 fp->precision = 16;
632 fp->flags = 0;
633 break;
634 case 5:
635 strcpy(fp->name, AudioEslinear_be);
636 fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
637 fp->precision = 16;
638 fp->flags = 0;
639 break;
640 default:
641 return (EINVAL);
642 /* NOTREACHED */
643 }
644 return (0);
645 }
646
647
648
649 u_long
650 iw_set_format(sc, precision, in)
651 struct iw_softc *sc;
652 u_long precision;
653 int in;
654 {
655 u_char data;
656 int encoding, channels;
657
658 encoding = in ? sc->rec_encoding : sc->play_encoding;
659 channels = in ? sc->rec_channels : sc->play_channels;
660
661 DPRINTF(("iw_set_format\n"));
662
663 switch (encoding) {
664 case AUDIO_ENCODING_ULAW:
665 data = 0x00;
666 break;
667
668 case AUDIO_ENCODING_ALAW:
669 data = 0x00;
670 break;
671
672 case AUDIO_ENCODING_SLINEAR_LE:
673 if (precision == 16)
674 data = 0x40; /* little endian. 0xc0 is big endian */
675 else
676 data = 0x00;
677 break;
678
679 case AUDIO_ENCODING_SLINEAR_BE:
680 if (precision == 16)
681 data = 0xc0;
682 else
683 data = 0x00;
684 break;
685
686 case AUDIO_ENCODING_ADPCM:
687 data = 0xa0;
688 break;
689
690 default:
691 return -1;
692 }
693
694 if (channels == 2)
695 data |= 0x10; /* stereo */
696
697 if (in) {
698 /* in */
699 sc->recfmtbits = data;
700 /* This will zero the normal codec frequency,
701 * iw_set_speed should always be called afterwards.
702 */
703 IW_WRITE_CODEC_1(CRDFI | IW_MCE, data);
704 } else {
705 /* out */
706 sc->playfmtbits = data;
707 IW_WRITE_CODEC_1(CPDFI | IW_MCE, data);
708 }
709
710 DPRINTF(("formatbits %s %x", in ? "in" : "out", data));
711
712 return encoding;
713 }
714
715
716
717 int
718 iw_set_params(addr, setmode, usemode, p, q, pfil, rfil)
719 void *addr;
720 int setmode;
721 int usemode;
722 audio_params_t *p;
723 audio_params_t *q;
724 stream_filter_list_t *pfil;
725 stream_filter_list_t *rfil;
726 {
727 audio_params_t phw, rhw;
728 struct iw_softc *sc = addr;
729 stream_filter_factory_t *swcode = NULL;
730
731 DPRINTF(("iw_setparams: code %d, prec %d, rate %d, chan %d\n",
732 (int) p->encoding, (int) p->precision, (int) p->sample_rate,
733 (int) p->channels));
734 phw = *p;
735 rhw = *q;
736 switch (p->encoding) {
737 case AUDIO_ENCODING_ULAW:
738 if (p->precision != 8)
739 return EINVAL;
740 phw.encoding = AUDIO_ENCODING_ULINEAR_LE;
741 rhw.encoding = AUDIO_ENCODING_ULINEAR_LE;
742 swcode = setmode & AUMODE_PLAY ? mulaw_to_linear8 : linear8_to_mulaw;
743 break;
744 case AUDIO_ENCODING_ALAW:
745 if (p->precision != 8)
746 return EINVAL;
747 phw.encoding = AUDIO_ENCODING_ULINEAR_LE;
748 rhw.encoding = AUDIO_ENCODING_ULINEAR_LE;
749 swcode = setmode & AUMODE_PLAY ? alaw_to_linear8 : linear8_to_alaw;
750 break;
751 case AUDIO_ENCODING_ADPCM:
752 if (p->precision != 8)
753 return EINVAL;
754 else
755 break;
756
757 case AUDIO_ENCODING_SLINEAR_LE:
758 case AUDIO_ENCODING_SLINEAR_BE:
759 if (p->precision != 8 && p->precision != 16)
760 return EINVAL;
761 else
762 break;
763
764 default:
765 return EINVAL;
766
767 }
768
769 if (setmode & AUMODE_PLAY) {
770 sc->play_channels = p->channels;
771 sc->play_encoding = p->encoding;
772 sc->play_precision = p->precision;
773 iw_set_format(sc, p->precision, 0);
774 q->sample_rate = p->sample_rate = sc->sc_orate =
775 iw_set_speed(sc, p->sample_rate, 0);
776 if (swcode != NULL) {
777 phw.sample_rate = p->sample_rate;
778 pfil->append(pfil, swcode, &phw);
779 }
780 } else {
781 #if 0
782 q->channels = sc->rec_channels = p->channels;
783 q->encoding = sc->rec_encoding = p->encoding;
784 q->precision = sc->rec_precision = p->precision;
785 #endif
786 sc->rec_channels = q->channels;
787 sc->rec_encoding = q->encoding;
788 sc->rec_precision = q->precision;
789
790 iw_set_format(sc, p->precision, 1);
791 q->sample_rate = sc->sc_irate =
792 iw_set_speed(sc, q->sample_rate, 1);
793 if (swcode != NULL) {
794 rhw.sample_rate = q->sample_rate;
795 rfil->append(rfil, swcode, &rhw);
796 }
797 }
798 return 0;
799 }
800
801
802 int
803 iw_round_blocksize(addr, blk)
804 void *addr;
805 int blk;
806 {
807 /* Round to a multiple of the biggest sample size. */
808 return blk &= -4;
809 }
810
811 void
812 iw_mixer_line_level(sc, line, levl, levr)
813 struct iw_softc *sc;
814 int line;
815 int levl, levr;
816 {
817 u_char gainl, gainr, attenl, attenr;
818
819 switch (line) {
820 case IW_REC:
821 gainl = sc->sc_recsrcbits | (levl >> 4);
822 gainr = sc->sc_recsrcbits | (levr >> 4);
823 DPRINTF(("recording with %x", gainl));
824 IW_WRITE_CODEC_1(CLICI, gainl);
825 IW_WRITE_CODEC_1(CRICI, gainr);
826 sc->sc_rec.voll = levl & 0xf0;
827 sc->sc_rec.volr = levr & 0xf0;
828 break;
829
830 case IW_AUX1:
831
832 gainl = (255 - levl) >> 3;
833 gainr = (255 - levr) >> 3;
834
835 /* mute if 0 level */
836 if (levl == 0)
837 gainl |= 0x80;
838 if (levr == 0)
839 gainr |= 0x80;
840
841 IW_WRITE_CODEC_1(IW_LEFT_AUX1_PORT, gainl);
842 IW_WRITE_CODEC_1(IW_RIGHT_AUX1_PORT, gainr);
843 sc->sc_aux1.voll = levl & 0xf8;
844 sc->sc_aux1.volr = levr & 0xf8;
845
846 break;
847
848 case IW_AUX2:
849
850 gainl = (255 - levl) >> 3;
851 gainr = (255 - levr) >> 3;
852
853 /* mute if 0 level */
854 if (levl == 0)
855 gainl |= 0x80;
856 if (levr == 0)
857 gainr |= 0x80;
858
859 IW_WRITE_CODEC_1(IW_LEFT_AUX2_PORT, gainl);
860 IW_WRITE_CODEC_1(IW_RIGHT_AUX2_PORT, gainr);
861 sc->sc_aux2.voll = levl & 0xf8;
862 sc->sc_aux2.volr = levr & 0xf8;
863 break;
864 case IW_DAC:
865 attenl = ((255 - levl) >> 2) | ((levl && !sc->sc_dac.off) ? 0 : 0x80);
866 attenr = ((255 - levr) >> 2) | ((levr && !sc->sc_dac.off) ? 0 : 0x80);
867 IW_WRITE_CODEC_1(CLDACI, attenl);
868 IW_WRITE_CODEC_1(CRDACI, attenr);
869 sc->sc_dac.voll = levl & 0xfc;
870 sc->sc_dac.volr = levr & 0xfc;
871 break;
872 case IW_LOOPBACK:
873 attenl = ((255 - levl) & 0xfc) | (levl ? 0x01 : 0);
874 IW_WRITE_CODEC_1(CLCI, attenl);
875 sc->sc_loopback.voll = levl & 0xfc;
876 break;
877 case IW_LINE_IN:
878 gainl = (levl >> 3) | (levl ? 0 : 0x80);
879 gainr = (levr >> 3) | (levr ? 0 : 0x80);
880 IW_WRITE_CODEC_1(CLLICI, gainl);
881 IW_WRITE_CODEC_1(CRLICI, gainr);
882 sc->sc_linein.voll = levl & 0xf8;
883 sc->sc_linein.volr = levr & 0xf8;
884 break;
885 case IW_MIC_IN:
886 gainl = ((255 - levl) >> 3) | (levl ? 0 : 0x80);
887 gainr = ((255 - levr) >> 3) | (levr ? 0 : 0x80);
888 IW_WRITE_CODEC_1(CLMICI, gainl);
889 IW_WRITE_CODEC_1(CRMICI, gainr);
890 sc->sc_mic.voll = levl & 0xf8;
891 sc->sc_mic.volr = levr & 0xf8;
892 break;
893 case IW_LINE_OUT:
894 attenl = ((255 - levl) >> 3) | (levl ? 0 : 0x80);
895 attenr = ((255 - levr) >> 3) | (levr ? 0 : 0x80);
896 IW_WRITE_CODEC_1(CLOAI, attenl);
897 IW_WRITE_CODEC_1(CROAI, attenr);
898 sc->sc_lineout.voll = levl & 0xf8;
899 sc->sc_lineout.volr = levr & 0xf8;
900 break;
901 case IW_MONO_IN:
902 attenl = ((255 - levl) >> 4) | (levl ? 0 : 0xc0); /* in/out mute */
903 IW_WRITE_CODEC_1(CMONOI, attenl);
904 sc->sc_monoin.voll = levl & 0xf0;
905 break;
906 }
907 }
908
909 int
910 iw_commit_settings(addr)
911 void *addr;
912 {
913 return 0;
914 }
915
916
917 void
918 iw_trigger_dma(sc, io)
919 struct iw_softc *sc;
920 u_char io;
921 {
922 u_char reg;
923 int s;
924
925 s = splaudio();
926
927 IW_READ_CODEC_1(CSR3I, reg);
928 IW_WRITE_CODEC_1(CSR3I, reg & ~(io == IW_DMA_PLAYBACK ? 0x10 : 0x20));
929
930 IW_READ_CODEC_1(CFIG1I, reg);
931
932 IW_WRITE_CODEC_1(CFIG1I, reg | io);
933
934 /* let the counter run */
935 IW_READ_CODEC_1(CFIG2I, reg);
936 IW_WRITE_CODEC_1(CFIG2I, reg & ~(io << 4));
937
938 splx(s);
939 }
940
941 void
942 iw_stop_dma(sc, io, hard)
943 struct iw_softc *sc;
944 u_char io, hard;
945 {
946 u_char reg;
947
948 /* just stop the counter, no need to flush the fifo */
949 IW_READ_CODEC_1(CFIG2I, reg);
950 IW_WRITE_CODEC_1(CFIG2I, (reg | (io << 4)));
951
952 if (hard) {
953 /* unless we're closing the device */
954 IW_READ_CODEC_1(CFIG1I, reg);
955 IW_WRITE_CODEC_1(CFIG1I, reg & ~io);
956 }
957 }
958
959 void
960 iw_dma_count(sc, count, io)
961 struct iw_softc *sc;
962 u_short count;
963 int io;
964 {
965 if (io == IW_DMA_PLAYBACK) {
966 IW_WRITE_CODEC_1(CLPCTI, (u_char) (count & 0x00ff));
967 IW_WRITE_CODEC_1(CUPCTI, (u_char) ((count >> 8) & 0x00ff));
968 } else {
969 IW_WRITE_CODEC_1(CLRCTI, (u_char) (count & 0x00ff));
970 IW_WRITE_CODEC_1(CURCTI, (u_char) ((count >> 8) & 0x00ff));
971 }
972 }
973
974 int
975 iw_init_output(addr, buf, cc)
976 void *addr;
977 void *buf;
978 int cc;
979 {
980 struct iw_softc *sc = (struct iw_softc *) addr;
981
982 DPRINTF(("iw_init_output\n"));
983
984 isa_dmastart(sc->sc_ic, sc->sc_playdrq, buf,
985 cc, NULL, DMAMODE_WRITE | DMAMODE_LOOP, BUS_DMA_NOWAIT);
986 return 0;
987 }
988
989 int
990 iw_init_input(addr, buf, cc)
991 void *addr;
992 void *buf;
993 int cc;
994 {
995 struct iw_softc *sc = (struct iw_softc *) addr;
996
997 DPRINTF(("iw_init_input\n"));
998
999 isa_dmastart(sc->sc_ic, sc->sc_recdrq, buf,
1000 cc, NULL, DMAMODE_READ | DMAMODE_LOOP, BUS_DMA_NOWAIT);
1001 return 0;
1002 }
1003
1004
1005 int
1006 iw_start_output(addr, p, cc, intr, arg)
1007 void *addr;
1008 void *p;
1009 int cc;
1010 void (*intr)__P((void *));
1011 void *arg;
1012 {
1013 struct iw_softc *sc = addr;
1014
1015 #ifdef DIAGNOSTIC
1016 if (!intr) {
1017 printf("iw_start_output: no callback!\n");
1018 return 1;
1019 }
1020 #endif
1021
1022 sc->sc_playintr = intr;
1023 sc->sc_playarg = arg;
1024 sc->sc_dma_flags |= DMAMODE_WRITE;
1025 sc->sc_playdma_bp = p;
1026
1027 isa_dmastart(sc->sc_ic, sc->sc_playdrq, sc->sc_playdma_bp,
1028 cc, NULL, DMAMODE_WRITE, BUS_DMA_NOWAIT);
1029
1030
1031 if (sc->play_encoding == AUDIO_ENCODING_ADPCM)
1032 cc >>= 2;
1033 if (sc->play_precision == 16)
1034 cc >>= 1;
1035
1036 if (sc->play_channels == 2 && sc->play_encoding != AUDIO_ENCODING_ADPCM)
1037 cc >>= 1;
1038
1039 cc -= iw_cc;
1040
1041 /* iw_dma_access(sc,1); */
1042 if (cc != sc->sc_playdma_cnt) {
1043 iw_dma_count(sc, (u_short) cc, IW_DMA_PLAYBACK);
1044 sc->sc_playdma_cnt = cc;
1045
1046 iw_trigger_dma(sc, IW_DMA_PLAYBACK);
1047 }
1048
1049 #ifdef DIAGNOSTIC
1050 if (outputs != iw_ints)
1051 printf("iw_start_output: out %d, int %d\n", outputs, iw_ints);
1052 outputs++;
1053 #endif
1054
1055 return 0;
1056 }
1057
1058
1059 int
1060 iw_start_input(addr, p, cc, intr, arg)
1061 void *addr;
1062 void *p;
1063 int cc;
1064 void (*intr)__P((void *));
1065 void *arg;
1066 {
1067 struct iw_softc *sc = addr;
1068
1069 #ifdef DIAGNOSTIC
1070 if (!intr) {
1071 printf("iw_start_input: no callback!\n");
1072 return 1;
1073 }
1074 #endif
1075
1076 sc->sc_recintr = intr;
1077 sc->sc_recarg = arg;
1078 sc->sc_dma_flags |= DMAMODE_READ;
1079 sc->sc_recdma_bp = p;
1080
1081 isa_dmastart(sc->sc_ic, sc->sc_recdrq, sc->sc_recdma_bp,
1082 cc, NULL, DMAMODE_READ, BUS_DMA_NOWAIT);
1083
1084
1085 if (sc->rec_encoding == AUDIO_ENCODING_ADPCM)
1086 cc >>= 2;
1087 if (sc->rec_precision == 16)
1088 cc >>= 1;
1089
1090 if (sc->rec_channels == 2 && sc->rec_encoding != AUDIO_ENCODING_ADPCM)
1091 cc >>= 1;
1092
1093 cc -= iw_cc;
1094
1095 /* iw_dma_access(sc,0); */
1096 if (sc->sc_recdma_cnt != cc) {
1097 iw_dma_count(sc, (u_short) cc, IW_DMA_RECORD);
1098 sc->sc_recdma_cnt = cc;
1099 /* iw_dma_ctrl(sc, IW_DMA_RECORD); */
1100 iw_trigger_dma(sc, IW_DMA_RECORD);
1101 }
1102
1103 #ifdef DIAGNOSTIC
1104 if ((inputs != iw_inints))
1105 printf("iw_start_input: in %d, inints %d\n", inputs, iw_inints);
1106 inputs++;
1107 #endif
1108
1109 return 0;
1110 }
1111
1112
1113 int
1114 iw_halt_output(addr)
1115 void *addr;
1116 {
1117 struct iw_softc *sc = addr;
1118
1119 iw_stop_dma(sc, IW_DMA_PLAYBACK, 0);
1120 return 0;
1121 }
1122
1123
1124 int
1125 iw_halt_input(addr)
1126 void *addr;
1127 {
1128 struct iw_softc *sc = addr;
1129
1130 iw_stop_dma(sc, IW_DMA_RECORD, 0);
1131 return 0;
1132 }
1133
1134
1135 int
1136 iw_speaker_ctl(addr, newstate)
1137 void *addr;
1138 int newstate;
1139 {
1140 struct iw_softc *sc = addr;
1141 u_char reg;
1142 if (newstate == SPKR_ON) {
1143 sc->sc_dac.off = 0;
1144 IW_READ_CODEC_1(CLDACI, reg);
1145 IW_WRITE_CODEC_1(CLDACI, reg & 0x7f);
1146 IW_READ_CODEC_1(CRDACI, reg);
1147 IW_WRITE_CODEC_1(CRDACI, reg & 0x7f);
1148 } else {
1149 /* SPKR_OFF */
1150 sc->sc_dac.off = 1;
1151 IW_READ_CODEC_1(CLDACI, reg);
1152 IW_WRITE_CODEC_1(CLDACI, reg | 0x80);
1153 IW_READ_CODEC_1(CRDACI, reg);
1154 IW_WRITE_CODEC_1(CRDACI, reg | 0x80);
1155 }
1156 return 0;
1157 }
1158
1159
1160 int
1161 iw_getdev(addr, retp)
1162 void *addr;
1163 struct audio_device *retp;
1164 {
1165 *retp = iw_device;
1166 return 0;
1167 }
1168
1169
1170 int
1171 iw_setfd(addr, flag)
1172 void *addr;
1173 int flag;
1174 {
1175 return 0;
1176 }
1177
1178
1179 /* Mixer (in/out ports) */
1180 int
1181 iw_set_port(addr, cp)
1182 void *addr;
1183 mixer_ctrl_t *cp;
1184 {
1185 struct iw_softc *sc = addr;
1186 u_char vall = 0, valr = 0;
1187 int error = EINVAL;
1188
1189 switch (cp->dev) {
1190 case IW_MIC_IN_LVL:
1191 if (cp->type == AUDIO_MIXER_VALUE) {
1192 error = 0;
1193 if (cp->un.value.num_channels == 1) {
1194 vall = valr = cp->un.value.level[0];
1195 } else {
1196 vall = cp->un.value.level[0];
1197 valr = cp->un.value.level[1];
1198 }
1199 sc->sc_mic.voll = vall;
1200 sc->sc_mic.volr = valr;
1201 iw_mixer_line_level(sc, IW_MIC_IN, vall, valr);
1202 }
1203 break;
1204 case IW_AUX1_LVL:
1205 if (cp->type == AUDIO_MIXER_VALUE) {
1206 error = 0;
1207 if (cp->un.value.num_channels == 1) {
1208 vall = valr = cp->un.value.level[0];
1209 } else {
1210 vall = cp->un.value.level[0];
1211 valr = cp->un.value.level[1];
1212 }
1213 sc->sc_aux1.voll = vall;
1214 sc->sc_aux1.volr = valr;
1215 iw_mixer_line_level(sc, IW_AUX1, vall, valr);
1216 }
1217 break;
1218 case IW_AUX2_LVL:
1219 if (cp->type == AUDIO_MIXER_VALUE) {
1220 error = 0;
1221 if (cp->un.value.num_channels == 1) {
1222 vall = valr = cp->un.value.level[0];
1223 } else {
1224 vall = cp->un.value.level[0];
1225 valr = cp->un.value.level[1];
1226 }
1227 sc->sc_aux2.voll = vall;
1228 sc->sc_aux2.volr = valr;
1229 iw_mixer_line_level(sc, IW_AUX2, vall, valr);
1230 }
1231 break;
1232 case IW_LINE_IN_LVL:
1233 if (cp->type == AUDIO_MIXER_VALUE) {
1234 error = 0;
1235 if (cp->un.value.num_channels == 1) {
1236 vall = valr = cp->un.value.level[0];
1237 } else {
1238 vall = cp->un.value.level[0];
1239 valr = cp->un.value.level[1];
1240 }
1241 sc->sc_linein.voll = vall;
1242 sc->sc_linein.volr = valr;
1243 iw_mixer_line_level(sc, IW_LINE_IN, vall, valr);
1244 }
1245 break;
1246 case IW_LINE_OUT_LVL:
1247 if (cp->type == AUDIO_MIXER_VALUE) {
1248 error = 0;
1249 if (cp->un.value.num_channels == 1) {
1250 vall = valr = cp->un.value.level[0];
1251 } else {
1252 vall = cp->un.value.level[0];
1253 valr = cp->un.value.level[1];
1254 }
1255 sc->sc_lineout.voll = vall;
1256 sc->sc_lineout.volr = valr;
1257 iw_mixer_line_level(sc, IW_LINE_OUT, vall, valr);
1258 }
1259 break;
1260 case IW_REC_LVL:
1261 if (cp->type == AUDIO_MIXER_VALUE) {
1262 error = 0;
1263 if (cp->un.value.num_channels == 1) {
1264 vall = valr = cp->un.value.level[0];
1265 } else {
1266 vall = cp->un.value.level[0];
1267 valr = cp->un.value.level[1];
1268 }
1269 sc->sc_rec.voll = vall;
1270 sc->sc_rec.volr = valr;
1271 iw_mixer_line_level(sc, IW_REC, vall, valr);
1272 }
1273 break;
1274
1275 case IW_DAC_LVL:
1276 if (cp->type == AUDIO_MIXER_VALUE) {
1277 error = 0;
1278 if (cp->un.value.num_channels == 1) {
1279 vall = valr = cp->un.value.level[0];
1280 } else {
1281 vall = cp->un.value.level[0];
1282 valr = cp->un.value.level[1];
1283 }
1284 sc->sc_dac.voll = vall;
1285 sc->sc_dac.volr = valr;
1286 iw_mixer_line_level(sc, IW_DAC, vall, valr);
1287 }
1288 break;
1289
1290 case IW_LOOPBACK_LVL:
1291 if (cp->type == AUDIO_MIXER_VALUE) {
1292 error = 0;
1293 if (cp->un.value.num_channels != 1) {
1294 return EINVAL;
1295 } else {
1296 valr = vall = cp->un.value.level[0];
1297 }
1298 sc->sc_loopback.voll = vall;
1299 sc->sc_loopback.volr = valr;
1300 iw_mixer_line_level(sc, IW_LOOPBACK, vall, valr);
1301 }
1302 break;
1303
1304 case IW_MONO_IN_LVL:
1305 if (cp->type == AUDIO_MIXER_VALUE) {
1306 error = 0;
1307 if (cp->un.value.num_channels != 1) {
1308 return EINVAL;
1309 } else {
1310 valr = vall = cp->un.value.level[0];
1311 }
1312 sc->sc_monoin.voll = vall;
1313 sc->sc_monoin.volr = valr;
1314 iw_mixer_line_level(sc, IW_MONO_IN, vall, valr);
1315 }
1316 break;
1317 case IW_RECORD_SOURCE:
1318 error = 0;
1319 sc->sc_recsrcbits = cp->un.ord << 6;
1320 DPRINTF(("record source %d bits %x\n", cp->un.ord, sc->sc_recsrcbits));
1321 iw_mixer_line_level(sc, IW_REC, sc->sc_rec.voll, sc->sc_rec.volr);
1322 break;
1323 }
1324
1325 return error;
1326 }
1327
1328
1329 int
1330 iw_get_port(addr, cp)
1331 void *addr;
1332 mixer_ctrl_t *cp;
1333 {
1334 struct iw_softc *sc = addr;
1335
1336 int error = EINVAL;
1337
1338 switch (cp->dev) {
1339 case IW_MIC_IN_LVL:
1340 if (cp->type == AUDIO_MIXER_VALUE) {
1341 cp->un.value.num_channels = 2;
1342 cp->un.value.level[0] = sc->sc_mic.voll;
1343 cp->un.value.level[1] = sc->sc_mic.volr;
1344 error = 0;
1345 }
1346 break;
1347 case IW_AUX1_LVL:
1348 if (cp->type == AUDIO_MIXER_VALUE) {
1349 cp->un.value.num_channels = 2;
1350 cp->un.value.level[0] = sc->sc_aux1.voll;
1351 cp->un.value.level[1] = sc->sc_aux1.volr;
1352 error = 0;
1353 }
1354 break;
1355 case IW_AUX2_LVL:
1356 if (cp->type == AUDIO_MIXER_VALUE) {
1357 cp->un.value.num_channels = 2;
1358 cp->un.value.level[0] = sc->sc_aux2.voll;
1359 cp->un.value.level[1] = sc->sc_aux2.volr;
1360 error = 0;
1361 }
1362 break;
1363 case IW_LINE_OUT_LVL:
1364 if (cp->type == AUDIO_MIXER_VALUE) {
1365 cp->un.value.num_channels = 2;
1366 cp->un.value.level[0] = sc->sc_lineout.voll;
1367 cp->un.value.level[1] = sc->sc_lineout.volr;
1368 error = 0;
1369 }
1370 break;
1371 case IW_LINE_IN_LVL:
1372 if (cp->type == AUDIO_MIXER_VALUE) {
1373 cp->un.value.num_channels = 2;
1374 cp->un.value.level[0] = sc->sc_linein.voll;
1375 cp->un.value.level[1] = sc->sc_linein.volr;
1376 error = 0;
1377 }
1378 case IW_REC_LVL:
1379 if (cp->type == AUDIO_MIXER_VALUE) {
1380 cp->un.value.num_channels = 2;
1381 cp->un.value.level[0] = sc->sc_rec.voll;
1382 cp->un.value.level[1] = sc->sc_rec.volr;
1383 error = 0;
1384 }
1385 break;
1386
1387 case IW_DAC_LVL:
1388 if (cp->type == AUDIO_MIXER_VALUE) {
1389 cp->un.value.num_channels = 2;
1390 cp->un.value.level[0] = sc->sc_dac.voll;
1391 cp->un.value.level[1] = sc->sc_dac.volr;
1392 error = 0;
1393 }
1394 break;
1395
1396 case IW_LOOPBACK_LVL:
1397 if (cp->type == AUDIO_MIXER_VALUE) {
1398 cp->un.value.num_channels = 1;
1399 cp->un.value.level[0] = sc->sc_loopback.voll;
1400 error = 0;
1401 }
1402 break;
1403
1404 case IW_MONO_IN_LVL:
1405 if (cp->type == AUDIO_MIXER_VALUE) {
1406 cp->un.value.num_channels = 1;
1407 cp->un.value.level[0] = sc->sc_monoin.voll;
1408 error = 0;
1409 }
1410 break;
1411 case IW_RECORD_SOURCE:
1412 cp->un.ord = sc->sc_recsrcbits >> 6;
1413 error = 0;
1414 break;
1415 }
1416
1417 return error;
1418 }
1419
1420
1421
1422 int
1423 iw_query_devinfo(addr, dip)
1424 void *addr;
1425 mixer_devinfo_t *dip;
1426 {
1427
1428 switch (dip->index) {
1429 case IW_MIC_IN_LVL: /* Microphone */
1430 dip->type = AUDIO_MIXER_VALUE;
1431 dip->mixer_class = IW_INPUT_CLASS;
1432 dip->prev = AUDIO_MIXER_LAST;
1433 dip->next = AUDIO_MIXER_LAST;
1434 strcpy(dip->label.name, AudioNmicrophone);
1435 dip->un.v.num_channels = 2;
1436 strcpy(dip->un.v.units.name, AudioNvolume);
1437 break;
1438 case IW_AUX1_LVL:
1439 dip->type = AUDIO_MIXER_VALUE;
1440 dip->mixer_class = IW_INPUT_CLASS;
1441 dip->prev = AUDIO_MIXER_LAST;
1442 dip->next = AUDIO_MIXER_LAST;
1443 strcpy(dip->label.name, AudioNline);
1444 dip->un.v.num_channels = 2;
1445 strcpy(dip->un.v.units.name, AudioNvolume);
1446 break;
1447 case IW_AUX2_LVL:
1448 dip->type = AUDIO_MIXER_VALUE;
1449 dip->mixer_class = IW_INPUT_CLASS;
1450 dip->prev = AUDIO_MIXER_LAST;
1451 dip->next = AUDIO_MIXER_LAST;
1452 strcpy(dip->label.name, AudioNcd);
1453 dip->un.v.num_channels = 2;
1454 strcpy(dip->un.v.units.name, AudioNvolume);
1455 break;
1456 case IW_LINE_OUT_LVL:
1457 dip->type = AUDIO_MIXER_VALUE;
1458 dip->mixer_class = IW_OUTPUT_CLASS;
1459 dip->prev = AUDIO_MIXER_LAST;
1460 dip->next = AUDIO_MIXER_LAST;
1461 strcpy(dip->label.name, AudioNline);
1462 dip->un.v.num_channels = 2;
1463 strcpy(dip->un.v.units.name, AudioNvolume);
1464 break;
1465 case IW_DAC_LVL:
1466 dip->type = AUDIO_MIXER_VALUE;
1467 dip->mixer_class = IW_OUTPUT_CLASS;
1468 dip->prev = AUDIO_MIXER_LAST;
1469 dip->next = AUDIO_MIXER_LAST;
1470 strcpy(dip->label.name, AudioNdac);
1471 dip->un.v.num_channels = 2;
1472 strcpy(dip->un.v.units.name, AudioNvolume);
1473 break;
1474 case IW_LINE_IN_LVL:
1475 dip->type = AUDIO_MIXER_VALUE;
1476 dip->mixer_class = IW_INPUT_CLASS;
1477 dip->prev = AUDIO_MIXER_LAST;
1478 dip->next = AUDIO_MIXER_LAST;
1479 strcpy(dip->label.name, AudioNinput);
1480 dip->un.v.num_channels = 2;
1481 strcpy(dip->un.v.units.name, AudioNvolume);
1482 break;
1483 case IW_MONO_IN_LVL:
1484 dip->type = AUDIO_MIXER_VALUE;
1485 dip->mixer_class = IW_INPUT_CLASS;
1486 dip->prev = AUDIO_MIXER_LAST;
1487 dip->next = AUDIO_MIXER_LAST;
1488 strcpy(dip->label.name, AudioNmono);
1489 dip->un.v.num_channels = 1;
1490 strcpy(dip->un.v.units.name, AudioNvolume);
1491 break;
1492
1493 case IW_REC_LVL: /* record level */
1494 dip->type = AUDIO_MIXER_VALUE;
1495 dip->mixer_class = IW_RECORD_CLASS;
1496 dip->prev = AUDIO_MIXER_LAST;
1497 dip->next = AUDIO_MIXER_LAST;
1498 strcpy(dip->label.name, AudioNrecord);
1499 dip->un.v.num_channels = 2;
1500 strcpy(dip->un.v.units.name, AudioNvolume);
1501 break;
1502
1503 case IW_LOOPBACK_LVL:
1504 dip->type = AUDIO_MIXER_VALUE;
1505 dip->mixer_class = IW_RECORD_CLASS;
1506 dip->prev = AUDIO_MIXER_LAST;
1507 dip->next = AUDIO_MIXER_LAST;
1508 strcpy(dip->label.name, "filter");
1509 dip->un.v.num_channels = 1;
1510 strcpy(dip->un.v.units.name, AudioNvolume);
1511 break;
1512
1513 case IW_RECORD_SOURCE:
1514 dip->mixer_class = IW_RECORD_CLASS;
1515 dip->type = AUDIO_MIXER_ENUM;
1516 dip->prev = AUDIO_MIXER_LAST;
1517 dip->next = AUDIO_MIXER_LAST;
1518 strcpy(dip->label.name, AudioNsource);
1519 dip->un.e.num_mem = 4;
1520 strcpy(dip->un.e.member[0].label.name, AudioNline);
1521 dip->un.e.member[0].ord = IW_LINE_IN_SRC;
1522 strcpy(dip->un.e.member[1].label.name, "aux1");
1523 dip->un.e.member[1].ord = IW_AUX1_SRC;
1524 strcpy(dip->un.e.member[2].label.name, AudioNmicrophone);
1525 dip->un.e.member[2].ord = IW_MIC_IN_SRC;
1526 strcpy(dip->un.e.member[3].label.name, AudioNmixerout);
1527 dip->un.e.member[3].ord = IW_MIX_OUT_SRC;
1528 break;
1529 case IW_INPUT_CLASS:
1530 dip->type = AUDIO_MIXER_CLASS;
1531 dip->mixer_class = IW_INPUT_CLASS;
1532 dip->next = dip->prev = AUDIO_MIXER_LAST;
1533 strcpy(dip->label.name, AudioCinputs);
1534 break;
1535 case IW_OUTPUT_CLASS:
1536 dip->type = AUDIO_MIXER_CLASS;
1537 dip->mixer_class = IW_OUTPUT_CLASS;
1538 dip->next = dip->prev = AUDIO_MIXER_LAST;
1539 strcpy(dip->label.name, AudioCoutputs);
1540 break;
1541 case IW_RECORD_CLASS: /* record source class */
1542 dip->type = AUDIO_MIXER_CLASS;
1543 dip->mixer_class = IW_RECORD_CLASS;
1544 dip->next = dip->prev = AUDIO_MIXER_LAST;
1545 strcpy(dip->label.name, AudioCrecord);
1546 return 0;
1547 default:
1548 return ENXIO;
1549 }
1550 return 0;
1551 }
1552
1553
1554 void *
1555 iw_malloc(addr, direction, size, pool, flags)
1556 void *addr;
1557 int direction;
1558 size_t size;
1559 struct malloc_type *pool;
1560 int flags;
1561 {
1562 struct iw_softc *sc = addr;
1563 int drq;
1564
1565 if (direction == AUMODE_PLAY)
1566 drq = sc->sc_playdrq;
1567 else
1568 drq = sc->sc_recdrq;
1569 return (isa_malloc(sc->sc_ic, drq, size, pool, flags));
1570 }
1571
1572 void
1573 iw_free(addr, ptr, pool)
1574 void *addr;
1575 void *ptr;
1576 struct malloc_type *pool;
1577 {
1578 isa_free(ptr, pool);
1579 }
1580
1581 size_t
1582 iw_round_buffersize(addr, direction, size)
1583 void *addr;
1584 int direction;
1585 size_t size;
1586 {
1587 struct iw_softc *sc = addr;
1588 bus_size_t maxsize;
1589
1590 if (direction == AUMODE_PLAY)
1591 maxsize = sc->sc_play_maxsize;
1592 else
1593 maxsize = sc->sc_rec_maxsize;
1594
1595 if (size > maxsize)
1596 size = maxsize;
1597 return (size);
1598 }
1599
1600 paddr_t
1601 iw_mappage(addr, mem, off, prot)
1602 void *addr;
1603 void *mem;
1604 off_t off;
1605 int prot;
1606 {
1607 return isa_mappage(mem, off, prot);
1608 }
1609
1610 int
1611 iw_get_props(addr)
1612 void *addr;
1613 {
1614 struct iw_softc *sc = addr;
1615 return AUDIO_PROP_MMAP |
1616 (sc->sc_fullduplex ? AUDIO_PROP_FULLDUPLEX : 0);
1617 }
1618