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