interwave.c revision 1.21 1 /* $NetBSD: interwave.c,v 1.21 2004/07/09 01:13:53 mycroft 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.21 2004/07/09 01:13:53 mycroft 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 int s;
223
224 s = splaudio();
225 if (sc->sc_open) {
226 splx(s);
227 DPRINTF(("iwopen: open %x sc %p\n", sc->sc_open, sc));
228 return EBUSY;
229 } else
230 sc->sc_open = 1;
231 splx(s);
232
233 DPRINTF(("iwopen: open %x sc %p\n", sc->sc_open, sc));
234
235 #ifdef DIAGNOSTIC
236 outputs = 0;
237 iw_ints = 0;
238 inputs = 0;
239 iw_inints = 0;
240 #endif
241
242 iwreset(sc, 1);
243
244 /* READ/WRITE or both */
245
246 if (flags == FWRITE) {
247 sc->sc_mode |= IW_WRITE;
248 sc->sc_playdma_cnt = 0;
249 sc->sc_playintr = 0;
250 }
251 if (flags == FREAD) {
252 sc->sc_mode |= IW_READ;
253 sc->sc_recdma_cnt = 0;
254 sc->sc_recintr = 0;
255 }
256
257 return 0;
258 }
259
260
261
262 void
263 iwclose(addr)
264 void *addr;
265 {
266 struct iw_softc *sc = addr;
267
268 DPRINTF(("iwclose sc %p\n", sc));
269
270 #ifdef DIAGNOSTIC
271 DPRINTF(("iwclose: outputs %d ints %d inputs %d in_ints %d\n",
272 outputs, iw_ints, inputs, iw_inints));
273 #endif
274
275 /* close hardware */
276 sc->sc_open = 0;
277 sc->sc_flags = 0;
278 sc->sc_mode = 0;
279 }
280
281 #define RAM_STEP 64*1024
282
283 static void
284 iw_mempoke(sc, addy, val)
285 struct iw_softc *sc;
286 u_long addy;
287 u_char val;
288 {
289 IW_WRITE_GENERAL_2(LMALI, (u_short) addy);
290 IW_WRITE_GENERAL_1(LMAHI, (u_char) (addy >> 16));
291
292 /* Write byte to LMBDR */
293 IW_WRITE_DIRECT_1(sc->p3xr + 7, sc->p3xr_h, val);
294 }
295
296 static u_char
297 iw_mempeek(sc, addy)
298 struct iw_softc *sc;
299 u_long addy;
300 {
301 u_char ret;
302
303 IW_WRITE_GENERAL_2(LMALI, (u_short) addy);
304 IW_WRITE_GENERAL_1(LMAHI, (u_char) (addy >> 16));
305
306 IW_READ_DIRECT_1(sc->p3xr + 7, sc->p3xr_h, ret);
307 return ret; /* return byte from LMBDR */
308 }
309
310 static void
311 iw_meminit(sc)
312 struct iw_softc *sc;
313 {
314 u_long bank[4] = {0L, 0L, 0L, 0L};
315 u_long addr = 0L, base = 0L, cnt = 0L;
316 u_char i, ram = 0 /* ,memval=0 */ ;
317 u_short lmcfi;
318 u_long temppi;
319 u_long *lpbanks = &temppi;
320
321 IW_WRITE_GENERAL_1(LDMACI, 0x00);
322
323 IW_READ_GENERAL_2(LMCFI, lmcfi); /* 0x52 */
324 lmcfi |= 0x0A0C;
325 IW_WRITE_GENERAL_2(LMCFI, lmcfi); /* max addr span */
326 IW_WRITE_GENERAL_1(LMCI, 0x00);
327
328 /* fifo addresses */
329
330 IW_WRITE_GENERAL_2(LMRFAI, ((4 * 1024 * 1024) >> 8));
331 IW_WRITE_GENERAL_2(LMPFAI, ((4 * 1024 * 1024 + 16 * 1024) >> 8));
332
333 IW_WRITE_GENERAL_2(LMFSI, 0x000);
334
335 IW_WRITE_GENERAL_2(LDICI, 0x0000);
336
337 while (addr < (16 * 1024 * 1024)) {
338 iw_mempoke(sc, addr, 0x00);
339 addr += RAM_STEP;
340 }
341
342 printf("%s:", sc->sc_dev.dv_xname);
343
344 for (i = 0; i < 4; i++) {
345 iw_mempoke(sc, base, 0xAA); /* mark start of bank */
346 iw_mempoke(sc, base + 1L, 0x55);
347 if (iw_mempeek(sc, base) == 0xAA &&
348 iw_mempeek(sc, base + 1L) == 0x55)
349 ram = 1;
350 if (ram) {
351 while (cnt < (4 * 1024 * 1024)) {
352 bank[i] += RAM_STEP;
353 cnt += RAM_STEP;
354 addr = base + cnt;
355 if (iw_mempeek(sc, addr) == 0xAA)
356 break;
357 }
358 }
359 if (lpbanks != NULL) {
360 *lpbanks = bank[i];
361 lpbanks++;
362 }
363 bank[i] = bank[i] >> 10;
364 printf("%s bank[%d]: %ldK", i ? "," : "", i, bank[i]);
365 base += 4 * 1024 * 1024;
366 cnt = 0L;
367 ram = 0;
368 }
369
370 printf("\n");
371
372 /*
373 * this is not really useful since GUS PnP supports memory
374 * configurations that aren't really supported by Interwave...beware
375 * of holes! Also, we don't use the memory for anything in this
376 * version of the driver.
377 *
378 * we've configured for 4M-4M-4M-4M
379 */
380 }
381
382
383 static
384 void
385 iwreset(sc, warm)
386 struct iw_softc *sc;
387 int warm;
388 {
389 u_char reg, cmode, val = 0, mixer_image = 0;
390
391 reg = 0; /* XXX gcc -Wall */
392
393 cmode = 0x6c; /* enhanced codec mode (full duplex) */
394
395 /* reset */
396
397 IW_WRITE_GENERAL_1(URSTI, 0x00);
398 delay(10);
399 IW_WRITE_GENERAL_1(URSTI, 0x07);
400 IW_WRITE_GENERAL_1(ICMPTI, 0x1f); /* disable DSP and uici and
401 * udci writes */
402 IW_WRITE_GENERAL_1(IDECI, 0x7f); /* enable ints to ISA and
403 * codec access */
404 IW_READ_GENERAL_1(IVERI, reg);
405 IW_WRITE_GENERAL_1(IVERI, reg | 0x01); /* hidden reg lock disable */
406 IW_WRITE_GENERAL_1(UASBCI, 0x00);
407
408 /* synth enhanced mode (default), 0 active voices, disable ints */
409
410 IW_WRITE_GENERAL_1(SGMI_WR, 0x01); /* enhanced mode, LFOs
411 * disabled */
412 for (val = 0; val < 32; val++) {
413 /* set each synth sound volume to 0 */
414 IW_WRITE_DIRECT_1(sc->p3xr + 2, sc->p3xr_h, val);
415 IW_WRITE_GENERAL_1(SVSI_WR, 0x00);
416 IW_WRITE_GENERAL_2(SASLI_WR, 0x0000);
417 IW_WRITE_GENERAL_2(SASHI_WR, 0x0000);
418 IW_WRITE_GENERAL_2(SAELI_WR, 0x0000);
419 IW_WRITE_GENERAL_2(SAEHI_WR, 0x0000);
420 IW_WRITE_GENERAL_2(SFCI_WR, 0x0000);
421 IW_WRITE_GENERAL_1(SACI_WR, 0x02);
422 IW_WRITE_GENERAL_1(SVSI_WR, 0x00);
423 IW_WRITE_GENERAL_1(SVEI_WR, 0x00);
424 IW_WRITE_GENERAL_2(SVLI_WR, 0x0000);
425 IW_WRITE_GENERAL_1(SVCI_WR, 0x02);
426 IW_WRITE_GENERAL_1(SMSI_WR, 0x02);
427 }
428
429 IW_WRITE_GENERAL_1(SAVI_WR, 0x00);
430
431 /* codec mode/init */
432
433 /* first change mode to 1 */
434
435 IW_WRITE_CODEC_1(CMODEI, 0x00);
436
437 /* and mode 3 */
438
439 IW_WRITE_CODEC_1(CMODEI, cmode);
440
441 IW_READ_CODEC_1(CMODEI, reg);
442
443 DPRINTF(("cmode %x\n", reg));
444
445 sc->revision = ((reg & 0x80) >> 3) | (reg & 0x0f);
446
447 IW_WRITE_DIRECT_1(sc->codec_index + 2, sc->p2xr_h, 0x00);
448
449 IW_WRITE_CODEC_1(CFIG1I | IW_MCE, 0x00); /* DMA 2 chan access */
450 IW_WRITE_CODEC_1(CEXTI, 0x00); /* disable ints for now */
451
452
453 IW_WRITE_CODEC_1(CLPCTI, 0x00); /* reset playback sample counters */
454 IW_WRITE_CODEC_1(CUPCTI, 0x00); /* always upper byte last */
455 IW_WRITE_CODEC_1(CFIG2I, 0x80); /* full voltage range, enable record
456 * and playback sample counters, and
457 * don't center output in case or
458 * FIFO underrun */
459 IW_WRITE_CODEC_1(CFIG3I, 0xc0); /* enable record/playback irq (still
460 * turned off from CEXTI), max DMA
461 * rate */
462 IW_WRITE_CODEC_1(CSR3I, 0x00); /* clear status 3 reg */
463
464
465 IW_WRITE_CODEC_1(CLRCTI, 0x00); /* reset record sample counters */
466 IW_WRITE_CODEC_1(CURCTI, 0x00); /* always upper byte last */
467
468
469 IW_READ_GENERAL_1(IVERI, reg);
470
471 sc->vers = reg >> 4;
472 if (!warm)
473 snprintf(iw_device.version, sizeof(iw_device.version), "%d.%d",
474 sc->vers, sc->revision);
475
476 IW_WRITE_GENERAL_1(IDECI, 0x7f); /* irqs and codec decode
477 * enable */
478
479
480 /* ports */
481
482 if (!warm) {
483 iw_mixer_line_level(sc, IW_LINE_OUT, 255, 255);
484 iw_mixer_line_level(sc, IW_LINE_IN, 0, 0);
485 iw_mixer_line_level(sc, IW_AUX1, 0, 0);
486 iw_mixer_line_level(sc, IW_AUX2, 200, 200); /* CD */
487 sc->sc_dac.off = 0;
488 iw_mixer_line_level(sc, IW_DAC, 200, 200);
489
490 iw_mixer_line_level(sc, IW_MIC_IN, 0, 0);
491 iw_mixer_line_level(sc, IW_REC, 0, 0);
492 iw_mixer_line_level(sc, IW_LOOPBACK, 0, 0);
493 iw_mixer_line_level(sc, IW_MONO_IN, 0, 0);
494
495 /* mem stuff */
496 iw_meminit(sc);
497
498 }
499 IW_WRITE_CODEC_1(CEXTI, 0x02); /* codec int enable */
500
501 /* clear _LDMACI */
502
503 IW_WRITE_GENERAL_1(LDMACI, 0x00);
504
505 /* enable mixer paths */
506 mixer_image = 0x0c;
507 IW_WRITE_DIRECT_1(sc->p2xr, sc->p2xr_h, mixer_image);
508 /*
509 * enable output, line in. disable mic in bit 0 = 0 -> line in on
510 * (from codec?) bit 1 = 0 -> output on bit 2 = 1 -> mic in on bit 3
511 * = 1 -> irq&drq pin enable bit 4 = 1 -> channel interrupts to chan
512 * 1 bit 5 = 1 -> enable midi loop back bit 6 = 0 -> irq latches
513 * URCR[2:0] bit 6 = 1 -> DMA latches URCR[2:0]
514 */
515
516
517 IW_READ_DIRECT_1(sc->p2xr, sc->p2xr_h, mixer_image);
518 #ifdef AUDIO_DEBUG
519 if (!warm)
520 DPRINTF(("mix image %x \n", mixer_image));
521 #endif
522 }
523
524 struct iw_codec_freq {
525 u_long freq;
526 u_char bits;
527 };
528
529 int
530 iw_set_speed(sc, freq, in)
531 struct iw_softc *sc;
532 u_long freq;
533 char in;
534 {
535 u_char var, cfig3, reg;
536
537 static struct iw_codec_freq iw_cf[17] = {
538 #define FREQ_1 24576000
539 #define FREQ_2 16934400
540 #define XTAL1 0
541 #define XTAL2 1
542 {5510, 0x00 | XTAL2}, {6620, 0x0E | XTAL2},
543 {8000, 0x00 | XTAL1}, {9600, 0x0E | XTAL1},
544 {11025, 0x02 | XTAL2}, {16000, 0x02 | XTAL1},
545 {18900, 0x04 | XTAL2}, {22050, 0x06 | XTAL2},
546 {27420, 0x04 | XTAL1}, {32000, 0x06 | XTAL1},
547 {33075, 0x0C | XTAL2}, {37800, 0x08 | XTAL2},
548 {38400, 0x0A | XTAL1}, {44100, 0x0A | XTAL2},
549 {44800, 0x08 | XTAL1}, {48000, 0x0C | XTAL1},
550 {48000, 0x0C | XTAL1} /* really a dummy for indexing later */
551 #undef XTAL1
552 #undef XTAL2
553 };
554
555 cfig3 = 0; /* XXX gcc -Wall */
556
557 /*
558 * if the frequency is between 3493Hz and 32KHz we can use a more
559 * accurate frequency than the ones listed above base on the formula
560 * FREQ/((16*(48+x))) where FREQ is either FREQ_1 (24576000Hz) or
561 * FREQ_2 (16934400Hz) and x is the value to be written to either
562 * CPVFI or CRVFI. To enable this option, bit 2 in CFIG3 needs to be
563 * set high
564 *
565 * NOT IMPLEMENTED!
566 *
567 * Note that if you have a 'bad' XTAL_1 (higher than 18.5 MHz), 44.8KHz
568 * and 38.4KHz modes will provide wrong frequencies to output.
569 */
570
571
572 if (freq > 48000)
573 freq = 48000;
574 if (freq < 5510)
575 freq = 5510;
576
577 /* reset CFIG3[2] */
578
579 IW_READ_CODEC_1(CFIG3I, cfig3);
580
581 cfig3 |= 0xc0; /* not full fifo treshhold */
582
583 DPRINTF(("cfig3i = %x -> ", cfig3));
584
585 cfig3 &= ~0x04;
586 IW_WRITE_CODEC_1(CFIG3I, cfig3);
587 IW_READ_CODEC_1(CFIG3I, cfig3);
588
589 DPRINTF(("%x\n", cfig3));
590
591 for (var = 0; var < 16; var++) /* select closest frequency */
592 if (freq <= iw_cf[var].freq)
593 break;
594 if (var != 16)
595 if (abs(freq - iw_cf[var].freq) > abs(iw_cf[var + 1].freq - freq))
596 var++;
597
598 if (in)
599 IW_WRITE_CODEC_1(CRDFI | IW_MCE, sc->recfmtbits | iw_cf[var].bits);
600 else
601 IW_WRITE_CODEC_1(CPDFI | IW_MCE, sc->playfmtbits | iw_cf[var].bits);
602 freq = iw_cf[var].freq;
603 DPRINTF(("setting %s frequency to %d bits %x \n",
604 in ? "in" : "out", (int) freq, iw_cf[var].bits));
605
606 IW_READ_CODEC_1(CPDFI, reg);
607
608 DPRINTF((" CPDFI %x ", reg));
609
610 IW_READ_CODEC_1(CRDFI, reg);
611
612 DPRINTF((" CRDFI %x ", reg));
613
614 return freq;
615 }
616
617 /* Encoding. */
618 int
619 iw_query_encoding(addr, fp)
620 void *addr;
621 struct audio_encoding *fp;
622 {
623 /*
624 * LINEAR, ALAW, ULAW, ADPCM in HW, we'll use linear unsigned
625 * hardware mode for all 8-bit modes due to buggy (?) codec.
626 */
627
628 /*
629 * except in wavetable synth. there we have only mu-law and 8 and 16
630 * bit linear data
631 */
632
633 switch (fp->index) {
634 case 0:
635 strcpy(fp->name, AudioEulinear);
636 fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
637 fp->precision = 8;
638 fp->flags = 0;
639 break;
640 case 1:
641 strcpy(fp->name, AudioEmulaw);
642 fp->encoding = AUDIO_ENCODING_ULAW;
643 fp->precision = 8;
644 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
645 break;
646 case 2:
647 strcpy(fp->name, AudioEalaw);
648 fp->encoding = AUDIO_ENCODING_ALAW;
649 fp->precision = 8;
650 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
651 break;
652 case 3:
653 strcpy(fp->name, AudioEadpcm);
654 fp->encoding = AUDIO_ENCODING_ADPCM;
655 fp->precision = 8; /* really 4 bit */
656 fp->flags = 0;
657 break;
658 case 4:
659 strcpy(fp->name, AudioEslinear_le);
660 fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
661 fp->precision = 16;
662 fp->flags = 0;
663 break;
664 case 5:
665 strcpy(fp->name, AudioEslinear_be);
666 fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
667 fp->precision = 16;
668 fp->flags = 0;
669 break;
670 default:
671 return (EINVAL);
672 /* NOTREACHED */
673 }
674 return (0);
675 }
676
677
678
679 u_long
680 iw_set_format(sc, precision, in)
681 struct iw_softc *sc;
682 u_long precision;
683 int in;
684 {
685 u_char data;
686 int encoding, channels;
687
688 encoding = in ? sc->rec_encoding : sc->play_encoding;
689 channels = in ? sc->rec_channels : sc->play_channels;
690
691 DPRINTF(("iw_set_format\n"));
692
693 switch (encoding) {
694 case AUDIO_ENCODING_ULAW:
695 data = 0x00;
696 break;
697
698 case AUDIO_ENCODING_ALAW:
699 data = 0x00;
700 break;
701
702 case AUDIO_ENCODING_SLINEAR_LE:
703 if (precision == 16)
704 data = 0x40; /* little endian. 0xc0 is big endian */
705 else
706 data = 0x00;
707 break;
708
709 case AUDIO_ENCODING_SLINEAR_BE:
710 if (precision == 16)
711 data = 0xc0;
712 else
713 data = 0x00;
714 break;
715
716 case AUDIO_ENCODING_ADPCM:
717 data = 0xa0;
718 break;
719
720 default:
721 return -1;
722 }
723
724 if (channels == 2)
725 data |= 0x10; /* stereo */
726
727 if (in) {
728 /* in */
729 sc->recfmtbits = data;
730 /* This will zero the normal codec frequency,
731 * iw_set_speed should always be called afterwards.
732 */
733 IW_WRITE_CODEC_1(CRDFI | IW_MCE, data);
734 } else {
735 /* out */
736 sc->playfmtbits = data;
737 IW_WRITE_CODEC_1(CPDFI | IW_MCE, data);
738 }
739
740 DPRINTF(("formatbits %s %x", in ? "in" : "out", data));
741
742 return encoding;
743 }
744
745
746
747 int
748 iw_set_params(addr, setmode, usemode, p, q)
749 void *addr;
750 int setmode;
751 int usemode;
752 struct audio_params *p;
753 struct audio_params *q;
754 {
755 struct iw_softc *sc = addr;
756 void (*swcode)__P((void *, u_char * buf, int cnt)) = NULL;
757 int factor = 1;
758 DPRINTF(("iw_setparams: code %d, prec %d, rate %d, chan %d\n",
759 (int) p->encoding, (int) p->precision, (int) p->sample_rate,
760 (int) p->channels));
761
762
763 switch (p->encoding) {
764 case AUDIO_ENCODING_ULAW:
765 if (p->precision != 8)
766 return EINVAL;
767 swcode = setmode & AUMODE_PLAY ? mulaw_to_ulinear8 : ulinear8_to_mulaw;
768 factor = 1;
769 break;
770 case AUDIO_ENCODING_ALAW:
771 if (p->precision != 8)
772 return EINVAL;
773 swcode = setmode & AUMODE_PLAY ? alaw_to_ulinear8 : ulinear8_to_alaw;
774 factor = 1;
775 break;
776 case AUDIO_ENCODING_ADPCM:
777 if (p->precision != 8)
778 return EINVAL;
779 else
780 break;
781
782 case AUDIO_ENCODING_SLINEAR_LE:
783 case AUDIO_ENCODING_SLINEAR_BE:
784 if (p->precision != 8 && p->precision != 16)
785 return EINVAL;
786 else
787 break;
788
789 default:
790 return EINVAL;
791
792 }
793
794 if (setmode & AUMODE_PLAY) {
795 sc->play_channels = p->channels;
796 sc->play_encoding = p->encoding;
797 sc->play_precision = p->precision;
798 p->factor = factor;
799 p->sw_code = swcode;
800 iw_set_format(sc, p->precision, 0);
801 q->sample_rate = p->sample_rate = sc->sc_orate =
802 iw_set_speed(sc, p->sample_rate, 0);
803 } else {
804 #if 0
805 q->channels = sc->rec_channels = p->channels;
806 q->encoding = sc->rec_encoding = p->encoding;
807 q->precision = sc->rec_precision = p->precision;
808 #endif
809 sc->rec_channels = q->channels;
810 sc->rec_encoding = q->encoding;
811 sc->rec_precision = q->precision;
812 q->factor = factor;
813 q->sw_code = swcode;
814
815 iw_set_format(sc, p->precision, 1);
816 q->sample_rate = sc->sc_irate =
817 iw_set_speed(sc, q->sample_rate, 1);
818 }
819 return 0;
820 }
821
822
823 int
824 iw_round_blocksize(addr, blk)
825 void *addr;
826 int blk;
827 {
828 /* Round to a multiple of the biggest sample size. */
829 return blk &= -4;
830 }
831
832 void
833 iw_mixer_line_level(sc, line, levl, levr)
834 struct iw_softc *sc;
835 int line;
836 int levl, levr;
837 {
838 u_char gainl, gainr, attenl, attenr;
839
840 switch (line) {
841 case IW_REC:
842 gainl = sc->sc_recsrcbits | (levl >> 4);
843 gainr = sc->sc_recsrcbits | (levr >> 4);
844 DPRINTF(("recording with %x", gainl));
845 IW_WRITE_CODEC_1(CLICI, gainl);
846 IW_WRITE_CODEC_1(CRICI, gainr);
847 sc->sc_rec.voll = levl & 0xf0;
848 sc->sc_rec.volr = levr & 0xf0;
849 break;
850
851 case IW_AUX1:
852
853 gainl = (255 - levl) >> 3;
854 gainr = (255 - levr) >> 3;
855
856 /* mute if 0 level */
857 if (levl == 0)
858 gainl |= 0x80;
859 if (levr == 0)
860 gainr |= 0x80;
861
862 IW_WRITE_CODEC_1(IW_LEFT_AUX1_PORT, gainl);
863 IW_WRITE_CODEC_1(IW_RIGHT_AUX1_PORT, gainr);
864 sc->sc_aux1.voll = levl & 0xf8;
865 sc->sc_aux1.volr = levr & 0xf8;
866
867 break;
868
869 case IW_AUX2:
870
871 gainl = (255 - levl) >> 3;
872 gainr = (255 - levr) >> 3;
873
874 /* mute if 0 level */
875 if (levl == 0)
876 gainl |= 0x80;
877 if (levr == 0)
878 gainr |= 0x80;
879
880 IW_WRITE_CODEC_1(IW_LEFT_AUX2_PORT, gainl);
881 IW_WRITE_CODEC_1(IW_RIGHT_AUX2_PORT, gainr);
882 sc->sc_aux2.voll = levl & 0xf8;
883 sc->sc_aux2.volr = levr & 0xf8;
884 break;
885 case IW_DAC:
886 attenl = ((255 - levl) >> 2) | ((levl && !sc->sc_dac.off) ? 0 : 0x80);
887 attenr = ((255 - levr) >> 2) | ((levr && !sc->sc_dac.off) ? 0 : 0x80);
888 IW_WRITE_CODEC_1(CLDACI, attenl);
889 IW_WRITE_CODEC_1(CRDACI, attenr);
890 sc->sc_dac.voll = levl & 0xfc;
891 sc->sc_dac.volr = levr & 0xfc;
892 break;
893 case IW_LOOPBACK:
894 attenl = ((255 - levl) & 0xfc) | (levl ? 0x01 : 0);
895 IW_WRITE_CODEC_1(CLCI, attenl);
896 sc->sc_loopback.voll = levl & 0xfc;
897 break;
898 case IW_LINE_IN:
899 gainl = (levl >> 3) | (levl ? 0 : 0x80);
900 gainr = (levr >> 3) | (levr ? 0 : 0x80);
901 IW_WRITE_CODEC_1(CLLICI, gainl);
902 IW_WRITE_CODEC_1(CRLICI, gainr);
903 sc->sc_linein.voll = levl & 0xf8;
904 sc->sc_linein.volr = levr & 0xf8;
905 break;
906 case IW_MIC_IN:
907 gainl = ((255 - levl) >> 3) | (levl ? 0 : 0x80);
908 gainr = ((255 - levr) >> 3) | (levr ? 0 : 0x80);
909 IW_WRITE_CODEC_1(CLMICI, gainl);
910 IW_WRITE_CODEC_1(CRMICI, gainr);
911 sc->sc_mic.voll = levl & 0xf8;
912 sc->sc_mic.volr = levr & 0xf8;
913 break;
914 case IW_LINE_OUT:
915 attenl = ((255 - levl) >> 3) | (levl ? 0 : 0x80);
916 attenr = ((255 - levr) >> 3) | (levr ? 0 : 0x80);
917 IW_WRITE_CODEC_1(CLOAI, attenl);
918 IW_WRITE_CODEC_1(CROAI, attenr);
919 sc->sc_lineout.voll = levl & 0xf8;
920 sc->sc_lineout.volr = levr & 0xf8;
921 break;
922 case IW_MONO_IN:
923 attenl = ((255 - levl) >> 4) | (levl ? 0 : 0xc0); /* in/out mute */
924 IW_WRITE_CODEC_1(CMONOI, attenl);
925 sc->sc_monoin.voll = levl & 0xf0;
926 break;
927 }
928 }
929
930 int
931 iw_commit_settings(addr)
932 void *addr;
933 {
934 return 0;
935 }
936
937
938 void
939 iw_trigger_dma(sc, io)
940 struct iw_softc *sc;
941 u_char io;
942 {
943 u_char reg;
944 int s;
945
946 s = splaudio();
947
948 IW_READ_CODEC_1(CSR3I, reg);
949 IW_WRITE_CODEC_1(CSR3I, reg & ~(io == IW_DMA_PLAYBACK ? 0x10 : 0x20));
950
951 IW_READ_CODEC_1(CFIG1I, reg);
952
953 IW_WRITE_CODEC_1(CFIG1I, reg | io);
954
955 /* let the counter run */
956 IW_READ_CODEC_1(CFIG2I, reg);
957 IW_WRITE_CODEC_1(CFIG2I, reg & ~(io << 4));
958
959 splx(s);
960 }
961
962 void
963 iw_stop_dma(sc, io, hard)
964 struct iw_softc *sc;
965 u_char io, hard;
966 {
967 u_char reg;
968
969 /* just stop the counter, no need to flush the fifo */
970 IW_READ_CODEC_1(CFIG2I, reg);
971 IW_WRITE_CODEC_1(CFIG2I, (reg | (io << 4)));
972
973 if (hard) {
974 /* unless we're closing the device */
975 IW_READ_CODEC_1(CFIG1I, reg);
976 IW_WRITE_CODEC_1(CFIG1I, reg & ~io);
977 }
978 }
979
980 void
981 iw_dma_count(sc, count, io)
982 struct iw_softc *sc;
983 u_short count;
984 int io;
985 {
986 if (io == IW_DMA_PLAYBACK) {
987 IW_WRITE_CODEC_1(CLPCTI, (u_char) (count & 0x00ff));
988 IW_WRITE_CODEC_1(CUPCTI, (u_char) ((count >> 8) & 0x00ff));
989 } else {
990 IW_WRITE_CODEC_1(CLRCTI, (u_char) (count & 0x00ff));
991 IW_WRITE_CODEC_1(CURCTI, (u_char) ((count >> 8) & 0x00ff));
992 }
993 }
994
995 int
996 iw_init_output(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_output\n"));
1004
1005 isa_dmastart(sc->sc_ic, sc->sc_playdrq, buf,
1006 cc, NULL, DMAMODE_WRITE | DMAMODE_LOOP, BUS_DMA_NOWAIT);
1007 return 0;
1008 }
1009
1010 int
1011 iw_init_input(addr, buf, cc)
1012 void *addr;
1013 void *buf;
1014 int cc;
1015 {
1016 struct iw_softc *sc = (struct iw_softc *) addr;
1017
1018 DPRINTF(("iw_init_input\n"));
1019
1020 isa_dmastart(sc->sc_ic, sc->sc_recdrq, buf,
1021 cc, NULL, DMAMODE_READ | DMAMODE_LOOP, BUS_DMA_NOWAIT);
1022 return 0;
1023 }
1024
1025
1026 int
1027 iw_start_output(addr, p, cc, intr, arg)
1028 void *addr;
1029 void *p;
1030 int cc;
1031 void (*intr)__P((void *));
1032 void *arg;
1033 {
1034 struct iw_softc *sc = addr;
1035
1036 #ifdef DIAGNOSTIC
1037 if (!intr) {
1038 printf("iw_start_output: no callback!\n");
1039 return 1;
1040 }
1041 #endif
1042
1043 sc->sc_playintr = intr;
1044 sc->sc_playarg = arg;
1045 sc->sc_dma_flags |= DMAMODE_WRITE;
1046 sc->sc_playdma_bp = p;
1047
1048 isa_dmastart(sc->sc_ic, sc->sc_playdrq, sc->sc_playdma_bp,
1049 cc, NULL, DMAMODE_WRITE, BUS_DMA_NOWAIT);
1050
1051
1052 if (sc->play_encoding == AUDIO_ENCODING_ADPCM)
1053 cc >>= 2;
1054 if (sc->play_precision == 16)
1055 cc >>= 1;
1056
1057 if (sc->play_channels == 2 && sc->play_encoding != AUDIO_ENCODING_ADPCM)
1058 cc >>= 1;
1059
1060 cc -= iw_cc;
1061
1062 /* iw_dma_access(sc,1); */
1063 if (cc != sc->sc_playdma_cnt) {
1064 iw_dma_count(sc, (u_short) cc, IW_DMA_PLAYBACK);
1065 sc->sc_playdma_cnt = cc;
1066
1067 iw_trigger_dma(sc, IW_DMA_PLAYBACK);
1068 }
1069
1070 #ifdef DIAGNOSTIC
1071 if (outputs != iw_ints)
1072 printf("iw_start_output: out %d, int %d\n", outputs, iw_ints);
1073 outputs++;
1074 #endif
1075
1076 return 0;
1077 }
1078
1079
1080 int
1081 iw_start_input(addr, p, cc, intr, arg)
1082 void *addr;
1083 void *p;
1084 int cc;
1085 void (*intr)__P((void *));
1086 void *arg;
1087 {
1088 struct iw_softc *sc = addr;
1089
1090 #ifdef DIAGNOSTIC
1091 if (!intr) {
1092 printf("iw_start_input: no callback!\n");
1093 return 1;
1094 }
1095 #endif
1096
1097 sc->sc_recintr = intr;
1098 sc->sc_recarg = arg;
1099 sc->sc_dma_flags |= DMAMODE_READ;
1100 sc->sc_recdma_bp = p;
1101
1102 isa_dmastart(sc->sc_ic, sc->sc_recdrq, sc->sc_recdma_bp,
1103 cc, NULL, DMAMODE_READ, BUS_DMA_NOWAIT);
1104
1105
1106 if (sc->rec_encoding == AUDIO_ENCODING_ADPCM)
1107 cc >>= 2;
1108 if (sc->rec_precision == 16)
1109 cc >>= 1;
1110
1111 if (sc->rec_channels == 2 && sc->rec_encoding != AUDIO_ENCODING_ADPCM)
1112 cc >>= 1;
1113
1114 cc -= iw_cc;
1115
1116 /* iw_dma_access(sc,0); */
1117 if (sc->sc_recdma_cnt != cc) {
1118 iw_dma_count(sc, (u_short) cc, IW_DMA_RECORD);
1119 sc->sc_recdma_cnt = cc;
1120 /* iw_dma_ctrl(sc, IW_DMA_RECORD); */
1121 iw_trigger_dma(sc, IW_DMA_RECORD);
1122 }
1123
1124 #ifdef DIAGNOSTIC
1125 if ((inputs != iw_inints))
1126 printf("iw_start_input: in %d, inints %d\n", inputs, iw_inints);
1127 inputs++;
1128 #endif
1129
1130 return 0;
1131 }
1132
1133
1134 int
1135 iw_halt_output(addr)
1136 void *addr;
1137 {
1138 struct iw_softc *sc = addr;
1139
1140 iw_stop_dma(sc, IW_DMA_PLAYBACK, 0);
1141 return 0;
1142 }
1143
1144
1145 int
1146 iw_halt_input(addr)
1147 void *addr;
1148 {
1149 struct iw_softc *sc = addr;
1150
1151 iw_stop_dma(sc, IW_DMA_RECORD, 0);
1152 return 0;
1153 }
1154
1155
1156 int
1157 iw_speaker_ctl(addr, newstate)
1158 void *addr;
1159 int newstate;
1160 {
1161 struct iw_softc *sc = addr;
1162 u_char reg;
1163 if (newstate == SPKR_ON) {
1164 sc->sc_dac.off = 0;
1165 IW_READ_CODEC_1(CLDACI, reg);
1166 IW_WRITE_CODEC_1(CLDACI, reg & 0x7f);
1167 IW_READ_CODEC_1(CRDACI, reg);
1168 IW_WRITE_CODEC_1(CRDACI, reg & 0x7f);
1169 } else {
1170 /* SPKR_OFF */
1171 sc->sc_dac.off = 1;
1172 IW_READ_CODEC_1(CLDACI, reg);
1173 IW_WRITE_CODEC_1(CLDACI, reg | 0x80);
1174 IW_READ_CODEC_1(CRDACI, reg);
1175 IW_WRITE_CODEC_1(CRDACI, reg | 0x80);
1176 }
1177 return 0;
1178 }
1179
1180
1181 int
1182 iw_getdev(addr, retp)
1183 void *addr;
1184 struct audio_device *retp;
1185 {
1186 *retp = iw_device;
1187 return 0;
1188 }
1189
1190
1191 int
1192 iw_setfd(addr, flag)
1193 void *addr;
1194 int flag;
1195 {
1196 return 0;
1197 }
1198
1199
1200 /* Mixer (in/out ports) */
1201 int
1202 iw_set_port(addr, cp)
1203 void *addr;
1204 mixer_ctrl_t *cp;
1205 {
1206 struct iw_softc *sc = addr;
1207 u_char vall = 0, valr = 0;
1208 int error = EINVAL;
1209
1210 switch (cp->dev) {
1211 case IW_MIC_IN_LVL:
1212 if (cp->type == AUDIO_MIXER_VALUE) {
1213 error = 0;
1214 if (cp->un.value.num_channels == 1) {
1215 vall = valr = cp->un.value.level[0];
1216 } else {
1217 vall = cp->un.value.level[0];
1218 valr = cp->un.value.level[1];
1219 }
1220 sc->sc_mic.voll = vall;
1221 sc->sc_mic.volr = valr;
1222 iw_mixer_line_level(sc, IW_MIC_IN, vall, valr);
1223 }
1224 break;
1225 case IW_AUX1_LVL:
1226 if (cp->type == AUDIO_MIXER_VALUE) {
1227 error = 0;
1228 if (cp->un.value.num_channels == 1) {
1229 vall = valr = cp->un.value.level[0];
1230 } else {
1231 vall = cp->un.value.level[0];
1232 valr = cp->un.value.level[1];
1233 }
1234 sc->sc_aux1.voll = vall;
1235 sc->sc_aux1.volr = valr;
1236 iw_mixer_line_level(sc, IW_AUX1, vall, valr);
1237 }
1238 break;
1239 case IW_AUX2_LVL:
1240 if (cp->type == AUDIO_MIXER_VALUE) {
1241 error = 0;
1242 if (cp->un.value.num_channels == 1) {
1243 vall = valr = cp->un.value.level[0];
1244 } else {
1245 vall = cp->un.value.level[0];
1246 valr = cp->un.value.level[1];
1247 }
1248 sc->sc_aux2.voll = vall;
1249 sc->sc_aux2.volr = valr;
1250 iw_mixer_line_level(sc, IW_AUX2, vall, valr);
1251 }
1252 break;
1253 case IW_LINE_IN_LVL:
1254 if (cp->type == AUDIO_MIXER_VALUE) {
1255 error = 0;
1256 if (cp->un.value.num_channels == 1) {
1257 vall = valr = cp->un.value.level[0];
1258 } else {
1259 vall = cp->un.value.level[0];
1260 valr = cp->un.value.level[1];
1261 }
1262 sc->sc_linein.voll = vall;
1263 sc->sc_linein.volr = valr;
1264 iw_mixer_line_level(sc, IW_LINE_IN, vall, valr);
1265 }
1266 break;
1267 case IW_LINE_OUT_LVL:
1268 if (cp->type == AUDIO_MIXER_VALUE) {
1269 error = 0;
1270 if (cp->un.value.num_channels == 1) {
1271 vall = valr = cp->un.value.level[0];
1272 } else {
1273 vall = cp->un.value.level[0];
1274 valr = cp->un.value.level[1];
1275 }
1276 sc->sc_lineout.voll = vall;
1277 sc->sc_lineout.volr = valr;
1278 iw_mixer_line_level(sc, IW_LINE_OUT, vall, valr);
1279 }
1280 break;
1281 case IW_REC_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_rec.voll = vall;
1291 sc->sc_rec.volr = valr;
1292 iw_mixer_line_level(sc, IW_REC, vall, valr);
1293 }
1294 break;
1295
1296 case IW_DAC_LVL:
1297 if (cp->type == AUDIO_MIXER_VALUE) {
1298 error = 0;
1299 if (cp->un.value.num_channels == 1) {
1300 vall = valr = cp->un.value.level[0];
1301 } else {
1302 vall = cp->un.value.level[0];
1303 valr = cp->un.value.level[1];
1304 }
1305 sc->sc_dac.voll = vall;
1306 sc->sc_dac.volr = valr;
1307 iw_mixer_line_level(sc, IW_DAC, vall, valr);
1308 }
1309 break;
1310
1311 case IW_LOOPBACK_LVL:
1312 if (cp->type == AUDIO_MIXER_VALUE) {
1313 error = 0;
1314 if (cp->un.value.num_channels != 1) {
1315 return EINVAL;
1316 } else {
1317 valr = vall = cp->un.value.level[0];
1318 }
1319 sc->sc_loopback.voll = vall;
1320 sc->sc_loopback.volr = valr;
1321 iw_mixer_line_level(sc, IW_LOOPBACK, vall, valr);
1322 }
1323 break;
1324
1325 case IW_MONO_IN_LVL:
1326 if (cp->type == AUDIO_MIXER_VALUE) {
1327 error = 0;
1328 if (cp->un.value.num_channels != 1) {
1329 return EINVAL;
1330 } else {
1331 valr = vall = cp->un.value.level[0];
1332 }
1333 sc->sc_monoin.voll = vall;
1334 sc->sc_monoin.volr = valr;
1335 iw_mixer_line_level(sc, IW_MONO_IN, vall, valr);
1336 }
1337 break;
1338 case IW_RECORD_SOURCE:
1339 error = 0;
1340 sc->sc_recsrcbits = cp->un.ord << 6;
1341 DPRINTF(("record source %d bits %x\n", cp->un.ord, sc->sc_recsrcbits));
1342 iw_mixer_line_level(sc, IW_REC, sc->sc_rec.voll, sc->sc_rec.volr);
1343 break;
1344 }
1345
1346 return error;
1347 }
1348
1349
1350 int
1351 iw_get_port(addr, cp)
1352 void *addr;
1353 mixer_ctrl_t *cp;
1354 {
1355 struct iw_softc *sc = addr;
1356
1357 int error = EINVAL;
1358
1359 switch (cp->dev) {
1360 case IW_MIC_IN_LVL:
1361 if (cp->type == AUDIO_MIXER_VALUE) {
1362 cp->un.value.num_channels = 2;
1363 cp->un.value.level[0] = sc->sc_mic.voll;
1364 cp->un.value.level[1] = sc->sc_mic.volr;
1365 error = 0;
1366 }
1367 break;
1368 case IW_AUX1_LVL:
1369 if (cp->type == AUDIO_MIXER_VALUE) {
1370 cp->un.value.num_channels = 2;
1371 cp->un.value.level[0] = sc->sc_aux1.voll;
1372 cp->un.value.level[1] = sc->sc_aux1.volr;
1373 error = 0;
1374 }
1375 break;
1376 case IW_AUX2_LVL:
1377 if (cp->type == AUDIO_MIXER_VALUE) {
1378 cp->un.value.num_channels = 2;
1379 cp->un.value.level[0] = sc->sc_aux2.voll;
1380 cp->un.value.level[1] = sc->sc_aux2.volr;
1381 error = 0;
1382 }
1383 break;
1384 case IW_LINE_OUT_LVL:
1385 if (cp->type == AUDIO_MIXER_VALUE) {
1386 cp->un.value.num_channels = 2;
1387 cp->un.value.level[0] = sc->sc_lineout.voll;
1388 cp->un.value.level[1] = sc->sc_lineout.volr;
1389 error = 0;
1390 }
1391 break;
1392 case IW_LINE_IN_LVL:
1393 if (cp->type == AUDIO_MIXER_VALUE) {
1394 cp->un.value.num_channels = 2;
1395 cp->un.value.level[0] = sc->sc_linein.voll;
1396 cp->un.value.level[1] = sc->sc_linein.volr;
1397 error = 0;
1398 }
1399 case IW_REC_LVL:
1400 if (cp->type == AUDIO_MIXER_VALUE) {
1401 cp->un.value.num_channels = 2;
1402 cp->un.value.level[0] = sc->sc_rec.voll;
1403 cp->un.value.level[1] = sc->sc_rec.volr;
1404 error = 0;
1405 }
1406 break;
1407
1408 case IW_DAC_LVL:
1409 if (cp->type == AUDIO_MIXER_VALUE) {
1410 cp->un.value.num_channels = 2;
1411 cp->un.value.level[0] = sc->sc_dac.voll;
1412 cp->un.value.level[1] = sc->sc_dac.volr;
1413 error = 0;
1414 }
1415 break;
1416
1417 case IW_LOOPBACK_LVL:
1418 if (cp->type == AUDIO_MIXER_VALUE) {
1419 cp->un.value.num_channels = 1;
1420 cp->un.value.level[0] = sc->sc_loopback.voll;
1421 error = 0;
1422 }
1423 break;
1424
1425 case IW_MONO_IN_LVL:
1426 if (cp->type == AUDIO_MIXER_VALUE) {
1427 cp->un.value.num_channels = 1;
1428 cp->un.value.level[0] = sc->sc_monoin.voll;
1429 error = 0;
1430 }
1431 break;
1432 case IW_RECORD_SOURCE:
1433 cp->un.ord = sc->sc_recsrcbits >> 6;
1434 error = 0;
1435 break;
1436 }
1437
1438 return error;
1439 }
1440
1441
1442
1443 int
1444 iw_query_devinfo(addr, dip)
1445 void *addr;
1446 mixer_devinfo_t *dip;
1447 {
1448
1449 switch (dip->index) {
1450 case IW_MIC_IN_LVL: /* Microphone */
1451 dip->type = AUDIO_MIXER_VALUE;
1452 dip->mixer_class = IW_INPUT_CLASS;
1453 dip->prev = AUDIO_MIXER_LAST;
1454 dip->next = AUDIO_MIXER_LAST;
1455 strcpy(dip->label.name, AudioNmicrophone);
1456 dip->un.v.num_channels = 2;
1457 strcpy(dip->un.v.units.name, AudioNvolume);
1458 break;
1459 case IW_AUX1_LVL:
1460 dip->type = AUDIO_MIXER_VALUE;
1461 dip->mixer_class = IW_INPUT_CLASS;
1462 dip->prev = AUDIO_MIXER_LAST;
1463 dip->next = AUDIO_MIXER_LAST;
1464 strcpy(dip->label.name, AudioNline);
1465 dip->un.v.num_channels = 2;
1466 strcpy(dip->un.v.units.name, AudioNvolume);
1467 break;
1468 case IW_AUX2_LVL:
1469 dip->type = AUDIO_MIXER_VALUE;
1470 dip->mixer_class = IW_INPUT_CLASS;
1471 dip->prev = AUDIO_MIXER_LAST;
1472 dip->next = AUDIO_MIXER_LAST;
1473 strcpy(dip->label.name, AudioNcd);
1474 dip->un.v.num_channels = 2;
1475 strcpy(dip->un.v.units.name, AudioNvolume);
1476 break;
1477 case IW_LINE_OUT_LVL:
1478 dip->type = AUDIO_MIXER_VALUE;
1479 dip->mixer_class = IW_OUTPUT_CLASS;
1480 dip->prev = AUDIO_MIXER_LAST;
1481 dip->next = AUDIO_MIXER_LAST;
1482 strcpy(dip->label.name, AudioNline);
1483 dip->un.v.num_channels = 2;
1484 strcpy(dip->un.v.units.name, AudioNvolume);
1485 break;
1486 case IW_DAC_LVL:
1487 dip->type = AUDIO_MIXER_VALUE;
1488 dip->mixer_class = IW_OUTPUT_CLASS;
1489 dip->prev = AUDIO_MIXER_LAST;
1490 dip->next = AUDIO_MIXER_LAST;
1491 strcpy(dip->label.name, AudioNdac);
1492 dip->un.v.num_channels = 2;
1493 strcpy(dip->un.v.units.name, AudioNvolume);
1494 break;
1495 case IW_LINE_IN_LVL:
1496 dip->type = AUDIO_MIXER_VALUE;
1497 dip->mixer_class = IW_INPUT_CLASS;
1498 dip->prev = AUDIO_MIXER_LAST;
1499 dip->next = AUDIO_MIXER_LAST;
1500 strcpy(dip->label.name, AudioNinput);
1501 dip->un.v.num_channels = 2;
1502 strcpy(dip->un.v.units.name, AudioNvolume);
1503 break;
1504 case IW_MONO_IN_LVL:
1505 dip->type = AUDIO_MIXER_VALUE;
1506 dip->mixer_class = IW_INPUT_CLASS;
1507 dip->prev = AUDIO_MIXER_LAST;
1508 dip->next = AUDIO_MIXER_LAST;
1509 strcpy(dip->label.name, AudioNmono);
1510 dip->un.v.num_channels = 1;
1511 strcpy(dip->un.v.units.name, AudioNvolume);
1512 break;
1513
1514 case IW_REC_LVL: /* record level */
1515 dip->type = AUDIO_MIXER_VALUE;
1516 dip->mixer_class = IW_RECORD_CLASS;
1517 dip->prev = AUDIO_MIXER_LAST;
1518 dip->next = AUDIO_MIXER_LAST;
1519 strcpy(dip->label.name, AudioNrecord);
1520 dip->un.v.num_channels = 2;
1521 strcpy(dip->un.v.units.name, AudioNvolume);
1522 break;
1523
1524 case IW_LOOPBACK_LVL:
1525 dip->type = AUDIO_MIXER_VALUE;
1526 dip->mixer_class = IW_RECORD_CLASS;
1527 dip->prev = AUDIO_MIXER_LAST;
1528 dip->next = AUDIO_MIXER_LAST;
1529 strcpy(dip->label.name, "filter");
1530 dip->un.v.num_channels = 1;
1531 strcpy(dip->un.v.units.name, AudioNvolume);
1532 break;
1533
1534 case IW_RECORD_SOURCE:
1535 dip->mixer_class = IW_RECORD_CLASS;
1536 dip->type = AUDIO_MIXER_ENUM;
1537 dip->prev = AUDIO_MIXER_LAST;
1538 dip->next = AUDIO_MIXER_LAST;
1539 strcpy(dip->label.name, AudioNsource);
1540 dip->un.e.num_mem = 4;
1541 strcpy(dip->un.e.member[0].label.name, AudioNline);
1542 dip->un.e.member[0].ord = IW_LINE_IN_SRC;
1543 strcpy(dip->un.e.member[1].label.name, "aux1");
1544 dip->un.e.member[1].ord = IW_AUX1_SRC;
1545 strcpy(dip->un.e.member[2].label.name, AudioNmicrophone);
1546 dip->un.e.member[2].ord = IW_MIC_IN_SRC;
1547 strcpy(dip->un.e.member[3].label.name, AudioNmixerout);
1548 dip->un.e.member[3].ord = IW_MIX_OUT_SRC;
1549 break;
1550 case IW_INPUT_CLASS:
1551 dip->type = AUDIO_MIXER_CLASS;
1552 dip->mixer_class = IW_INPUT_CLASS;
1553 dip->next = dip->prev = AUDIO_MIXER_LAST;
1554 strcpy(dip->label.name, AudioCinputs);
1555 break;
1556 case IW_OUTPUT_CLASS:
1557 dip->type = AUDIO_MIXER_CLASS;
1558 dip->mixer_class = IW_OUTPUT_CLASS;
1559 dip->next = dip->prev = AUDIO_MIXER_LAST;
1560 strcpy(dip->label.name, AudioCoutputs);
1561 break;
1562 case IW_RECORD_CLASS: /* record source class */
1563 dip->type = AUDIO_MIXER_CLASS;
1564 dip->mixer_class = IW_RECORD_CLASS;
1565 dip->next = dip->prev = AUDIO_MIXER_LAST;
1566 strcpy(dip->label.name, AudioCrecord);
1567 return 0;
1568 default:
1569 return ENXIO;
1570 }
1571 return 0;
1572 }
1573
1574
1575 void *
1576 iw_malloc(addr, direction, size, pool, flags)
1577 void *addr;
1578 int direction;
1579 size_t size;
1580 struct malloc_type *pool;
1581 int flags;
1582 {
1583 struct iw_softc *sc = addr;
1584 int drq;
1585
1586 if (direction == AUMODE_PLAY)
1587 drq = sc->sc_playdrq;
1588 else
1589 drq = sc->sc_recdrq;
1590 return (isa_malloc(sc->sc_ic, drq, size, pool, flags));
1591 }
1592
1593 void
1594 iw_free(addr, ptr, pool)
1595 void *addr;
1596 void *ptr;
1597 struct malloc_type *pool;
1598 {
1599 isa_free(ptr, pool);
1600 }
1601
1602 size_t
1603 iw_round_buffersize(addr, direction, size)
1604 void *addr;
1605 int direction;
1606 size_t size;
1607 {
1608 struct iw_softc *sc = addr;
1609 bus_size_t maxsize;
1610
1611 if (direction == AUMODE_PLAY)
1612 maxsize = sc->sc_play_maxsize;
1613 else
1614 maxsize = sc->sc_rec_maxsize;
1615
1616 if (size > maxsize)
1617 size = maxsize;
1618 return (size);
1619 }
1620
1621 paddr_t
1622 iw_mappage(addr, mem, off, prot)
1623 void *addr;
1624 void *mem;
1625 off_t off;
1626 int prot;
1627 {
1628 return isa_mappage(mem, off, prot);
1629 }
1630
1631 int
1632 iw_get_props(addr)
1633 void *addr;
1634 {
1635 struct iw_softc *sc = addr;
1636 return AUDIO_PROP_MMAP |
1637 (sc->sc_fullduplex ? AUDIO_PROP_FULLDUPLEX : 0);
1638 }
1639