interwave.c revision 1.24 1 /* $NetBSD: interwave.c,v 1.24 2005/01/10 22:01:37 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.24 2005/01/10 22:01:37 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, mode, param)
804 void *addr;
805 int blk;
806 int mode;
807 const audio_params_t *param;
808 {
809 /* Round to a multiple of the biggest sample size. */
810 return blk &= -4;
811 }
812
813 void
814 iw_mixer_line_level(sc, line, levl, levr)
815 struct iw_softc *sc;
816 int line;
817 int levl, levr;
818 {
819 u_char gainl, gainr, attenl, attenr;
820
821 switch (line) {
822 case IW_REC:
823 gainl = sc->sc_recsrcbits | (levl >> 4);
824 gainr = sc->sc_recsrcbits | (levr >> 4);
825 DPRINTF(("recording with %x", gainl));
826 IW_WRITE_CODEC_1(CLICI, gainl);
827 IW_WRITE_CODEC_1(CRICI, gainr);
828 sc->sc_rec.voll = levl & 0xf0;
829 sc->sc_rec.volr = levr & 0xf0;
830 break;
831
832 case IW_AUX1:
833
834 gainl = (255 - levl) >> 3;
835 gainr = (255 - levr) >> 3;
836
837 /* mute if 0 level */
838 if (levl == 0)
839 gainl |= 0x80;
840 if (levr == 0)
841 gainr |= 0x80;
842
843 IW_WRITE_CODEC_1(IW_LEFT_AUX1_PORT, gainl);
844 IW_WRITE_CODEC_1(IW_RIGHT_AUX1_PORT, gainr);
845 sc->sc_aux1.voll = levl & 0xf8;
846 sc->sc_aux1.volr = levr & 0xf8;
847
848 break;
849
850 case IW_AUX2:
851
852 gainl = (255 - levl) >> 3;
853 gainr = (255 - levr) >> 3;
854
855 /* mute if 0 level */
856 if (levl == 0)
857 gainl |= 0x80;
858 if (levr == 0)
859 gainr |= 0x80;
860
861 IW_WRITE_CODEC_1(IW_LEFT_AUX2_PORT, gainl);
862 IW_WRITE_CODEC_1(IW_RIGHT_AUX2_PORT, gainr);
863 sc->sc_aux2.voll = levl & 0xf8;
864 sc->sc_aux2.volr = levr & 0xf8;
865 break;
866 case IW_DAC:
867 attenl = ((255 - levl) >> 2) | ((levl && !sc->sc_dac.off) ? 0 : 0x80);
868 attenr = ((255 - levr) >> 2) | ((levr && !sc->sc_dac.off) ? 0 : 0x80);
869 IW_WRITE_CODEC_1(CLDACI, attenl);
870 IW_WRITE_CODEC_1(CRDACI, attenr);
871 sc->sc_dac.voll = levl & 0xfc;
872 sc->sc_dac.volr = levr & 0xfc;
873 break;
874 case IW_LOOPBACK:
875 attenl = ((255 - levl) & 0xfc) | (levl ? 0x01 : 0);
876 IW_WRITE_CODEC_1(CLCI, attenl);
877 sc->sc_loopback.voll = levl & 0xfc;
878 break;
879 case IW_LINE_IN:
880 gainl = (levl >> 3) | (levl ? 0 : 0x80);
881 gainr = (levr >> 3) | (levr ? 0 : 0x80);
882 IW_WRITE_CODEC_1(CLLICI, gainl);
883 IW_WRITE_CODEC_1(CRLICI, gainr);
884 sc->sc_linein.voll = levl & 0xf8;
885 sc->sc_linein.volr = levr & 0xf8;
886 break;
887 case IW_MIC_IN:
888 gainl = ((255 - levl) >> 3) | (levl ? 0 : 0x80);
889 gainr = ((255 - levr) >> 3) | (levr ? 0 : 0x80);
890 IW_WRITE_CODEC_1(CLMICI, gainl);
891 IW_WRITE_CODEC_1(CRMICI, gainr);
892 sc->sc_mic.voll = levl & 0xf8;
893 sc->sc_mic.volr = levr & 0xf8;
894 break;
895 case IW_LINE_OUT:
896 attenl = ((255 - levl) >> 3) | (levl ? 0 : 0x80);
897 attenr = ((255 - levr) >> 3) | (levr ? 0 : 0x80);
898 IW_WRITE_CODEC_1(CLOAI, attenl);
899 IW_WRITE_CODEC_1(CROAI, attenr);
900 sc->sc_lineout.voll = levl & 0xf8;
901 sc->sc_lineout.volr = levr & 0xf8;
902 break;
903 case IW_MONO_IN:
904 attenl = ((255 - levl) >> 4) | (levl ? 0 : 0xc0); /* in/out mute */
905 IW_WRITE_CODEC_1(CMONOI, attenl);
906 sc->sc_monoin.voll = levl & 0xf0;
907 break;
908 }
909 }
910
911 int
912 iw_commit_settings(addr)
913 void *addr;
914 {
915 return 0;
916 }
917
918
919 void
920 iw_trigger_dma(sc, io)
921 struct iw_softc *sc;
922 u_char io;
923 {
924 u_char reg;
925 int s;
926
927 s = splaudio();
928
929 IW_READ_CODEC_1(CSR3I, reg);
930 IW_WRITE_CODEC_1(CSR3I, reg & ~(io == IW_DMA_PLAYBACK ? 0x10 : 0x20));
931
932 IW_READ_CODEC_1(CFIG1I, reg);
933
934 IW_WRITE_CODEC_1(CFIG1I, reg | io);
935
936 /* let the counter run */
937 IW_READ_CODEC_1(CFIG2I, reg);
938 IW_WRITE_CODEC_1(CFIG2I, reg & ~(io << 4));
939
940 splx(s);
941 }
942
943 void
944 iw_stop_dma(sc, io, hard)
945 struct iw_softc *sc;
946 u_char io, hard;
947 {
948 u_char reg;
949
950 /* just stop the counter, no need to flush the fifo */
951 IW_READ_CODEC_1(CFIG2I, reg);
952 IW_WRITE_CODEC_1(CFIG2I, (reg | (io << 4)));
953
954 if (hard) {
955 /* unless we're closing the device */
956 IW_READ_CODEC_1(CFIG1I, reg);
957 IW_WRITE_CODEC_1(CFIG1I, reg & ~io);
958 }
959 }
960
961 void
962 iw_dma_count(sc, count, io)
963 struct iw_softc *sc;
964 u_short count;
965 int io;
966 {
967 if (io == IW_DMA_PLAYBACK) {
968 IW_WRITE_CODEC_1(CLPCTI, (u_char) (count & 0x00ff));
969 IW_WRITE_CODEC_1(CUPCTI, (u_char) ((count >> 8) & 0x00ff));
970 } else {
971 IW_WRITE_CODEC_1(CLRCTI, (u_char) (count & 0x00ff));
972 IW_WRITE_CODEC_1(CURCTI, (u_char) ((count >> 8) & 0x00ff));
973 }
974 }
975
976 int
977 iw_init_output(addr, buf, cc)
978 void *addr;
979 void *buf;
980 int cc;
981 {
982 struct iw_softc *sc = (struct iw_softc *) addr;
983
984 DPRINTF(("iw_init_output\n"));
985
986 isa_dmastart(sc->sc_ic, sc->sc_playdrq, buf,
987 cc, NULL, DMAMODE_WRITE | DMAMODE_LOOP, BUS_DMA_NOWAIT);
988 return 0;
989 }
990
991 int
992 iw_init_input(addr, buf, cc)
993 void *addr;
994 void *buf;
995 int cc;
996 {
997 struct iw_softc *sc = (struct iw_softc *) addr;
998
999 DPRINTF(("iw_init_input\n"));
1000
1001 isa_dmastart(sc->sc_ic, sc->sc_recdrq, buf,
1002 cc, NULL, DMAMODE_READ | DMAMODE_LOOP, BUS_DMA_NOWAIT);
1003 return 0;
1004 }
1005
1006
1007 int
1008 iw_start_output(addr, p, cc, intr, arg)
1009 void *addr;
1010 void *p;
1011 int cc;
1012 void (*intr)__P((void *));
1013 void *arg;
1014 {
1015 struct iw_softc *sc = addr;
1016
1017 #ifdef DIAGNOSTIC
1018 if (!intr) {
1019 printf("iw_start_output: no callback!\n");
1020 return 1;
1021 }
1022 #endif
1023
1024 sc->sc_playintr = intr;
1025 sc->sc_playarg = arg;
1026 sc->sc_dma_flags |= DMAMODE_WRITE;
1027 sc->sc_playdma_bp = p;
1028
1029 isa_dmastart(sc->sc_ic, sc->sc_playdrq, sc->sc_playdma_bp,
1030 cc, NULL, DMAMODE_WRITE, BUS_DMA_NOWAIT);
1031
1032
1033 if (sc->play_encoding == AUDIO_ENCODING_ADPCM)
1034 cc >>= 2;
1035 if (sc->play_precision == 16)
1036 cc >>= 1;
1037
1038 if (sc->play_channels == 2 && sc->play_encoding != AUDIO_ENCODING_ADPCM)
1039 cc >>= 1;
1040
1041 cc -= iw_cc;
1042
1043 /* iw_dma_access(sc,1); */
1044 if (cc != sc->sc_playdma_cnt) {
1045 iw_dma_count(sc, (u_short) cc, IW_DMA_PLAYBACK);
1046 sc->sc_playdma_cnt = cc;
1047
1048 iw_trigger_dma(sc, IW_DMA_PLAYBACK);
1049 }
1050
1051 #ifdef DIAGNOSTIC
1052 if (outputs != iw_ints)
1053 printf("iw_start_output: out %d, int %d\n", outputs, iw_ints);
1054 outputs++;
1055 #endif
1056
1057 return 0;
1058 }
1059
1060
1061 int
1062 iw_start_input(addr, p, cc, intr, arg)
1063 void *addr;
1064 void *p;
1065 int cc;
1066 void (*intr)__P((void *));
1067 void *arg;
1068 {
1069 struct iw_softc *sc = addr;
1070
1071 #ifdef DIAGNOSTIC
1072 if (!intr) {
1073 printf("iw_start_input: no callback!\n");
1074 return 1;
1075 }
1076 #endif
1077
1078 sc->sc_recintr = intr;
1079 sc->sc_recarg = arg;
1080 sc->sc_dma_flags |= DMAMODE_READ;
1081 sc->sc_recdma_bp = p;
1082
1083 isa_dmastart(sc->sc_ic, sc->sc_recdrq, sc->sc_recdma_bp,
1084 cc, NULL, DMAMODE_READ, BUS_DMA_NOWAIT);
1085
1086
1087 if (sc->rec_encoding == AUDIO_ENCODING_ADPCM)
1088 cc >>= 2;
1089 if (sc->rec_precision == 16)
1090 cc >>= 1;
1091
1092 if (sc->rec_channels == 2 && sc->rec_encoding != AUDIO_ENCODING_ADPCM)
1093 cc >>= 1;
1094
1095 cc -= iw_cc;
1096
1097 /* iw_dma_access(sc,0); */
1098 if (sc->sc_recdma_cnt != cc) {
1099 iw_dma_count(sc, (u_short) cc, IW_DMA_RECORD);
1100 sc->sc_recdma_cnt = cc;
1101 /* iw_dma_ctrl(sc, IW_DMA_RECORD); */
1102 iw_trigger_dma(sc, IW_DMA_RECORD);
1103 }
1104
1105 #ifdef DIAGNOSTIC
1106 if ((inputs != iw_inints))
1107 printf("iw_start_input: in %d, inints %d\n", inputs, iw_inints);
1108 inputs++;
1109 #endif
1110
1111 return 0;
1112 }
1113
1114
1115 int
1116 iw_halt_output(addr)
1117 void *addr;
1118 {
1119 struct iw_softc *sc = addr;
1120
1121 iw_stop_dma(sc, IW_DMA_PLAYBACK, 0);
1122 return 0;
1123 }
1124
1125
1126 int
1127 iw_halt_input(addr)
1128 void *addr;
1129 {
1130 struct iw_softc *sc = addr;
1131
1132 iw_stop_dma(sc, IW_DMA_RECORD, 0);
1133 return 0;
1134 }
1135
1136
1137 int
1138 iw_speaker_ctl(addr, newstate)
1139 void *addr;
1140 int newstate;
1141 {
1142 struct iw_softc *sc = addr;
1143 u_char reg;
1144 if (newstate == SPKR_ON) {
1145 sc->sc_dac.off = 0;
1146 IW_READ_CODEC_1(CLDACI, reg);
1147 IW_WRITE_CODEC_1(CLDACI, reg & 0x7f);
1148 IW_READ_CODEC_1(CRDACI, reg);
1149 IW_WRITE_CODEC_1(CRDACI, reg & 0x7f);
1150 } else {
1151 /* SPKR_OFF */
1152 sc->sc_dac.off = 1;
1153 IW_READ_CODEC_1(CLDACI, reg);
1154 IW_WRITE_CODEC_1(CLDACI, reg | 0x80);
1155 IW_READ_CODEC_1(CRDACI, reg);
1156 IW_WRITE_CODEC_1(CRDACI, reg | 0x80);
1157 }
1158 return 0;
1159 }
1160
1161
1162 int
1163 iw_getdev(addr, retp)
1164 void *addr;
1165 struct audio_device *retp;
1166 {
1167 *retp = iw_device;
1168 return 0;
1169 }
1170
1171
1172 int
1173 iw_setfd(addr, flag)
1174 void *addr;
1175 int flag;
1176 {
1177 return 0;
1178 }
1179
1180
1181 /* Mixer (in/out ports) */
1182 int
1183 iw_set_port(addr, cp)
1184 void *addr;
1185 mixer_ctrl_t *cp;
1186 {
1187 struct iw_softc *sc = addr;
1188 u_char vall = 0, valr = 0;
1189 int error = EINVAL;
1190
1191 switch (cp->dev) {
1192 case IW_MIC_IN_LVL:
1193 if (cp->type == AUDIO_MIXER_VALUE) {
1194 error = 0;
1195 if (cp->un.value.num_channels == 1) {
1196 vall = valr = cp->un.value.level[0];
1197 } else {
1198 vall = cp->un.value.level[0];
1199 valr = cp->un.value.level[1];
1200 }
1201 sc->sc_mic.voll = vall;
1202 sc->sc_mic.volr = valr;
1203 iw_mixer_line_level(sc, IW_MIC_IN, vall, valr);
1204 }
1205 break;
1206 case IW_AUX1_LVL:
1207 if (cp->type == AUDIO_MIXER_VALUE) {
1208 error = 0;
1209 if (cp->un.value.num_channels == 1) {
1210 vall = valr = cp->un.value.level[0];
1211 } else {
1212 vall = cp->un.value.level[0];
1213 valr = cp->un.value.level[1];
1214 }
1215 sc->sc_aux1.voll = vall;
1216 sc->sc_aux1.volr = valr;
1217 iw_mixer_line_level(sc, IW_AUX1, vall, valr);
1218 }
1219 break;
1220 case IW_AUX2_LVL:
1221 if (cp->type == AUDIO_MIXER_VALUE) {
1222 error = 0;
1223 if (cp->un.value.num_channels == 1) {
1224 vall = valr = cp->un.value.level[0];
1225 } else {
1226 vall = cp->un.value.level[0];
1227 valr = cp->un.value.level[1];
1228 }
1229 sc->sc_aux2.voll = vall;
1230 sc->sc_aux2.volr = valr;
1231 iw_mixer_line_level(sc, IW_AUX2, vall, valr);
1232 }
1233 break;
1234 case IW_LINE_IN_LVL:
1235 if (cp->type == AUDIO_MIXER_VALUE) {
1236 error = 0;
1237 if (cp->un.value.num_channels == 1) {
1238 vall = valr = cp->un.value.level[0];
1239 } else {
1240 vall = cp->un.value.level[0];
1241 valr = cp->un.value.level[1];
1242 }
1243 sc->sc_linein.voll = vall;
1244 sc->sc_linein.volr = valr;
1245 iw_mixer_line_level(sc, IW_LINE_IN, vall, valr);
1246 }
1247 break;
1248 case IW_LINE_OUT_LVL:
1249 if (cp->type == AUDIO_MIXER_VALUE) {
1250 error = 0;
1251 if (cp->un.value.num_channels == 1) {
1252 vall = valr = cp->un.value.level[0];
1253 } else {
1254 vall = cp->un.value.level[0];
1255 valr = cp->un.value.level[1];
1256 }
1257 sc->sc_lineout.voll = vall;
1258 sc->sc_lineout.volr = valr;
1259 iw_mixer_line_level(sc, IW_LINE_OUT, vall, valr);
1260 }
1261 break;
1262 case IW_REC_LVL:
1263 if (cp->type == AUDIO_MIXER_VALUE) {
1264 error = 0;
1265 if (cp->un.value.num_channels == 1) {
1266 vall = valr = cp->un.value.level[0];
1267 } else {
1268 vall = cp->un.value.level[0];
1269 valr = cp->un.value.level[1];
1270 }
1271 sc->sc_rec.voll = vall;
1272 sc->sc_rec.volr = valr;
1273 iw_mixer_line_level(sc, IW_REC, vall, valr);
1274 }
1275 break;
1276
1277 case IW_DAC_LVL:
1278 if (cp->type == AUDIO_MIXER_VALUE) {
1279 error = 0;
1280 if (cp->un.value.num_channels == 1) {
1281 vall = valr = cp->un.value.level[0];
1282 } else {
1283 vall = cp->un.value.level[0];
1284 valr = cp->un.value.level[1];
1285 }
1286 sc->sc_dac.voll = vall;
1287 sc->sc_dac.volr = valr;
1288 iw_mixer_line_level(sc, IW_DAC, vall, valr);
1289 }
1290 break;
1291
1292 case IW_LOOPBACK_LVL:
1293 if (cp->type == AUDIO_MIXER_VALUE) {
1294 error = 0;
1295 if (cp->un.value.num_channels != 1) {
1296 return EINVAL;
1297 } else {
1298 valr = vall = cp->un.value.level[0];
1299 }
1300 sc->sc_loopback.voll = vall;
1301 sc->sc_loopback.volr = valr;
1302 iw_mixer_line_level(sc, IW_LOOPBACK, vall, valr);
1303 }
1304 break;
1305
1306 case IW_MONO_IN_LVL:
1307 if (cp->type == AUDIO_MIXER_VALUE) {
1308 error = 0;
1309 if (cp->un.value.num_channels != 1) {
1310 return EINVAL;
1311 } else {
1312 valr = vall = cp->un.value.level[0];
1313 }
1314 sc->sc_monoin.voll = vall;
1315 sc->sc_monoin.volr = valr;
1316 iw_mixer_line_level(sc, IW_MONO_IN, vall, valr);
1317 }
1318 break;
1319 case IW_RECORD_SOURCE:
1320 error = 0;
1321 sc->sc_recsrcbits = cp->un.ord << 6;
1322 DPRINTF(("record source %d bits %x\n", cp->un.ord, sc->sc_recsrcbits));
1323 iw_mixer_line_level(sc, IW_REC, sc->sc_rec.voll, sc->sc_rec.volr);
1324 break;
1325 }
1326
1327 return error;
1328 }
1329
1330
1331 int
1332 iw_get_port(addr, cp)
1333 void *addr;
1334 mixer_ctrl_t *cp;
1335 {
1336 struct iw_softc *sc = addr;
1337
1338 int error = EINVAL;
1339
1340 switch (cp->dev) {
1341 case IW_MIC_IN_LVL:
1342 if (cp->type == AUDIO_MIXER_VALUE) {
1343 cp->un.value.num_channels = 2;
1344 cp->un.value.level[0] = sc->sc_mic.voll;
1345 cp->un.value.level[1] = sc->sc_mic.volr;
1346 error = 0;
1347 }
1348 break;
1349 case IW_AUX1_LVL:
1350 if (cp->type == AUDIO_MIXER_VALUE) {
1351 cp->un.value.num_channels = 2;
1352 cp->un.value.level[0] = sc->sc_aux1.voll;
1353 cp->un.value.level[1] = sc->sc_aux1.volr;
1354 error = 0;
1355 }
1356 break;
1357 case IW_AUX2_LVL:
1358 if (cp->type == AUDIO_MIXER_VALUE) {
1359 cp->un.value.num_channels = 2;
1360 cp->un.value.level[0] = sc->sc_aux2.voll;
1361 cp->un.value.level[1] = sc->sc_aux2.volr;
1362 error = 0;
1363 }
1364 break;
1365 case IW_LINE_OUT_LVL:
1366 if (cp->type == AUDIO_MIXER_VALUE) {
1367 cp->un.value.num_channels = 2;
1368 cp->un.value.level[0] = sc->sc_lineout.voll;
1369 cp->un.value.level[1] = sc->sc_lineout.volr;
1370 error = 0;
1371 }
1372 break;
1373 case IW_LINE_IN_LVL:
1374 if (cp->type == AUDIO_MIXER_VALUE) {
1375 cp->un.value.num_channels = 2;
1376 cp->un.value.level[0] = sc->sc_linein.voll;
1377 cp->un.value.level[1] = sc->sc_linein.volr;
1378 error = 0;
1379 }
1380 case IW_REC_LVL:
1381 if (cp->type == AUDIO_MIXER_VALUE) {
1382 cp->un.value.num_channels = 2;
1383 cp->un.value.level[0] = sc->sc_rec.voll;
1384 cp->un.value.level[1] = sc->sc_rec.volr;
1385 error = 0;
1386 }
1387 break;
1388
1389 case IW_DAC_LVL:
1390 if (cp->type == AUDIO_MIXER_VALUE) {
1391 cp->un.value.num_channels = 2;
1392 cp->un.value.level[0] = sc->sc_dac.voll;
1393 cp->un.value.level[1] = sc->sc_dac.volr;
1394 error = 0;
1395 }
1396 break;
1397
1398 case IW_LOOPBACK_LVL:
1399 if (cp->type == AUDIO_MIXER_VALUE) {
1400 cp->un.value.num_channels = 1;
1401 cp->un.value.level[0] = sc->sc_loopback.voll;
1402 error = 0;
1403 }
1404 break;
1405
1406 case IW_MONO_IN_LVL:
1407 if (cp->type == AUDIO_MIXER_VALUE) {
1408 cp->un.value.num_channels = 1;
1409 cp->un.value.level[0] = sc->sc_monoin.voll;
1410 error = 0;
1411 }
1412 break;
1413 case IW_RECORD_SOURCE:
1414 cp->un.ord = sc->sc_recsrcbits >> 6;
1415 error = 0;
1416 break;
1417 }
1418
1419 return error;
1420 }
1421
1422
1423
1424 int
1425 iw_query_devinfo(addr, dip)
1426 void *addr;
1427 mixer_devinfo_t *dip;
1428 {
1429
1430 switch (dip->index) {
1431 case IW_MIC_IN_LVL: /* Microphone */
1432 dip->type = AUDIO_MIXER_VALUE;
1433 dip->mixer_class = IW_INPUT_CLASS;
1434 dip->prev = AUDIO_MIXER_LAST;
1435 dip->next = AUDIO_MIXER_LAST;
1436 strcpy(dip->label.name, AudioNmicrophone);
1437 dip->un.v.num_channels = 2;
1438 strcpy(dip->un.v.units.name, AudioNvolume);
1439 break;
1440 case IW_AUX1_LVL:
1441 dip->type = AUDIO_MIXER_VALUE;
1442 dip->mixer_class = IW_INPUT_CLASS;
1443 dip->prev = AUDIO_MIXER_LAST;
1444 dip->next = AUDIO_MIXER_LAST;
1445 strcpy(dip->label.name, AudioNline);
1446 dip->un.v.num_channels = 2;
1447 strcpy(dip->un.v.units.name, AudioNvolume);
1448 break;
1449 case IW_AUX2_LVL:
1450 dip->type = AUDIO_MIXER_VALUE;
1451 dip->mixer_class = IW_INPUT_CLASS;
1452 dip->prev = AUDIO_MIXER_LAST;
1453 dip->next = AUDIO_MIXER_LAST;
1454 strcpy(dip->label.name, AudioNcd);
1455 dip->un.v.num_channels = 2;
1456 strcpy(dip->un.v.units.name, AudioNvolume);
1457 break;
1458 case IW_LINE_OUT_LVL:
1459 dip->type = AUDIO_MIXER_VALUE;
1460 dip->mixer_class = IW_OUTPUT_CLASS;
1461 dip->prev = AUDIO_MIXER_LAST;
1462 dip->next = AUDIO_MIXER_LAST;
1463 strcpy(dip->label.name, AudioNline);
1464 dip->un.v.num_channels = 2;
1465 strcpy(dip->un.v.units.name, AudioNvolume);
1466 break;
1467 case IW_DAC_LVL:
1468 dip->type = AUDIO_MIXER_VALUE;
1469 dip->mixer_class = IW_OUTPUT_CLASS;
1470 dip->prev = AUDIO_MIXER_LAST;
1471 dip->next = AUDIO_MIXER_LAST;
1472 strcpy(dip->label.name, AudioNdac);
1473 dip->un.v.num_channels = 2;
1474 strcpy(dip->un.v.units.name, AudioNvolume);
1475 break;
1476 case IW_LINE_IN_LVL:
1477 dip->type = AUDIO_MIXER_VALUE;
1478 dip->mixer_class = IW_INPUT_CLASS;
1479 dip->prev = AUDIO_MIXER_LAST;
1480 dip->next = AUDIO_MIXER_LAST;
1481 strcpy(dip->label.name, AudioNinput);
1482 dip->un.v.num_channels = 2;
1483 strcpy(dip->un.v.units.name, AudioNvolume);
1484 break;
1485 case IW_MONO_IN_LVL:
1486 dip->type = AUDIO_MIXER_VALUE;
1487 dip->mixer_class = IW_INPUT_CLASS;
1488 dip->prev = AUDIO_MIXER_LAST;
1489 dip->next = AUDIO_MIXER_LAST;
1490 strcpy(dip->label.name, AudioNmono);
1491 dip->un.v.num_channels = 1;
1492 strcpy(dip->un.v.units.name, AudioNvolume);
1493 break;
1494
1495 case IW_REC_LVL: /* record level */
1496 dip->type = AUDIO_MIXER_VALUE;
1497 dip->mixer_class = IW_RECORD_CLASS;
1498 dip->prev = AUDIO_MIXER_LAST;
1499 dip->next = AUDIO_MIXER_LAST;
1500 strcpy(dip->label.name, AudioNrecord);
1501 dip->un.v.num_channels = 2;
1502 strcpy(dip->un.v.units.name, AudioNvolume);
1503 break;
1504
1505 case IW_LOOPBACK_LVL:
1506 dip->type = AUDIO_MIXER_VALUE;
1507 dip->mixer_class = IW_RECORD_CLASS;
1508 dip->prev = AUDIO_MIXER_LAST;
1509 dip->next = AUDIO_MIXER_LAST;
1510 strcpy(dip->label.name, "filter");
1511 dip->un.v.num_channels = 1;
1512 strcpy(dip->un.v.units.name, AudioNvolume);
1513 break;
1514
1515 case IW_RECORD_SOURCE:
1516 dip->mixer_class = IW_RECORD_CLASS;
1517 dip->type = AUDIO_MIXER_ENUM;
1518 dip->prev = AUDIO_MIXER_LAST;
1519 dip->next = AUDIO_MIXER_LAST;
1520 strcpy(dip->label.name, AudioNsource);
1521 dip->un.e.num_mem = 4;
1522 strcpy(dip->un.e.member[0].label.name, AudioNline);
1523 dip->un.e.member[0].ord = IW_LINE_IN_SRC;
1524 strcpy(dip->un.e.member[1].label.name, "aux1");
1525 dip->un.e.member[1].ord = IW_AUX1_SRC;
1526 strcpy(dip->un.e.member[2].label.name, AudioNmicrophone);
1527 dip->un.e.member[2].ord = IW_MIC_IN_SRC;
1528 strcpy(dip->un.e.member[3].label.name, AudioNmixerout);
1529 dip->un.e.member[3].ord = IW_MIX_OUT_SRC;
1530 break;
1531 case IW_INPUT_CLASS:
1532 dip->type = AUDIO_MIXER_CLASS;
1533 dip->mixer_class = IW_INPUT_CLASS;
1534 dip->next = dip->prev = AUDIO_MIXER_LAST;
1535 strcpy(dip->label.name, AudioCinputs);
1536 break;
1537 case IW_OUTPUT_CLASS:
1538 dip->type = AUDIO_MIXER_CLASS;
1539 dip->mixer_class = IW_OUTPUT_CLASS;
1540 dip->next = dip->prev = AUDIO_MIXER_LAST;
1541 strcpy(dip->label.name, AudioCoutputs);
1542 break;
1543 case IW_RECORD_CLASS: /* record source class */
1544 dip->type = AUDIO_MIXER_CLASS;
1545 dip->mixer_class = IW_RECORD_CLASS;
1546 dip->next = dip->prev = AUDIO_MIXER_LAST;
1547 strcpy(dip->label.name, AudioCrecord);
1548 return 0;
1549 default:
1550 return ENXIO;
1551 }
1552 return 0;
1553 }
1554
1555
1556 void *
1557 iw_malloc(addr, direction, size, pool, flags)
1558 void *addr;
1559 int direction;
1560 size_t size;
1561 struct malloc_type *pool;
1562 int flags;
1563 {
1564 struct iw_softc *sc = addr;
1565 int drq;
1566
1567 if (direction == AUMODE_PLAY)
1568 drq = sc->sc_playdrq;
1569 else
1570 drq = sc->sc_recdrq;
1571 return (isa_malloc(sc->sc_ic, drq, size, pool, flags));
1572 }
1573
1574 void
1575 iw_free(addr, ptr, pool)
1576 void *addr;
1577 void *ptr;
1578 struct malloc_type *pool;
1579 {
1580 isa_free(ptr, pool);
1581 }
1582
1583 size_t
1584 iw_round_buffersize(addr, direction, size)
1585 void *addr;
1586 int direction;
1587 size_t size;
1588 {
1589 struct iw_softc *sc = addr;
1590 bus_size_t maxsize;
1591
1592 if (direction == AUMODE_PLAY)
1593 maxsize = sc->sc_play_maxsize;
1594 else
1595 maxsize = sc->sc_rec_maxsize;
1596
1597 if (size > maxsize)
1598 size = maxsize;
1599 return (size);
1600 }
1601
1602 paddr_t
1603 iw_mappage(addr, mem, off, prot)
1604 void *addr;
1605 void *mem;
1606 off_t off;
1607 int prot;
1608 {
1609 return isa_mappage(mem, off, prot);
1610 }
1611
1612 int
1613 iw_get_props(addr)
1614 void *addr;
1615 {
1616 struct iw_softc *sc = addr;
1617 return AUDIO_PROP_MMAP |
1618 (sc->sc_fullduplex ? AUDIO_PROP_FULLDUPLEX : 0);
1619 }
1620